Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
maString.h
1 #pragma once
2 
4 #include "AttributeModifier.h"
5 
6 // ****************************************
7 // * maStringHeritage class
8 // * --------------------------------------
14 // ****************************************
15 
16 template<int notificationLevel>
17 class maStringHeritage : public CoreModifiableAttributeData<kstl::string>
18 {
19  DECLARE_ATTRIBUTE_HERITAGE(maStringHeritage, maStringHeritage, kstl::string, CoreModifiable::ATTRIBUTE_TYPE::STRING);
20 
21 public:
22 
23 
26  const char* c_str() const { return mValue.c_str(); }
27 
28  void* getRawValue() final { return (void*)mValue.data(); }
29  size_t MemorySize() const final { return mValue.size(); };
30 
31  // getValue overloads
32  virtual bool getValue(kstl::string& value) const override
33  {
34  kstl::string tmpValue = this->mValue;
35  CALL_GETMODIFIER(notificationLevel, tmpValue);
36  value = tmpValue;
37  return true;
38  }
39  virtual bool getValue(usString& value) const override
40  {
41  kstl::string tmpValue = this->mValue;
42  CALL_GETMODIFIER(notificationLevel, tmpValue);
43  value = tmpValue;
44  return true;
45  }
46  virtual bool getValue(void*& value) const override
47  {
48  value = (void*)&mValue;
49  return true;
50  }
51 
52  virtual bool getValue(float& value) const override
53  {
54  value = (float)atof(mValue.c_str());
55  return true;
56  }
57 
59 
60  // setValue overloads
61  virtual bool setValue(const char* value) override
62  {
63  if (this->isReadOnly())
64  return false;
65 
66  kstl::string tmpValue = value;
67  CALL_SETMODIFIER(notificationLevel, tmpValue);
68  this->mValue = tmpValue;
69  DO_NOTIFICATION(notificationLevel);
70  return true;
71  }
72  virtual bool setValue(const kstl::string& value) override
73  {
74  if (this->isReadOnly())
75  return false;
76 
77  kstl::string tmpValue = value;
78  CALL_SETMODIFIER(notificationLevel, tmpValue);
79  this->mValue = tmpValue;
80  DO_NOTIFICATION(notificationLevel);
81  return true;
82  }
83 
84 #undef DECLARE_SET_NUMERIC
85 #define DECLARE_SET_NUMERIC(type) virtual bool setValue(type value) override { \
86  if (this->isReadOnly())\
87  return false; \
88  kstl::string tmpValue = std::to_string(value); \
89  CALL_SETMODIFIER(notificationLevel, tmpValue); \
90  this->mValue = tmpValue; \
91  DO_NOTIFICATION(notificationLevel); \
92  return true; \
93 }
94 
95  EXPAND_MACRO_FOR_NUMERIC_TYPES(NOQUALIFIER, NOQUALIFIER, DECLARE_SET_NUMERIC);
96 
98 
99  // operators
100  auto& operator+=(const kstl::string& attribute)
101  {
102  kstl::string val;
103  getValue(val);
104  val += attribute;
105  setValue(val);
106  return *this;
107  }
108  auto& operator+=(const char* attribute)
109  {
110  *this += kstl::string{ attribute };
111  return *this;
112  }
114 
115 
116 
117 };
118 
119 
120 STATIC_ASSERT_NOTIF_LEVEL_SIZES(maStringHeritage);
121 
122 
124 
CoreModifiableAttribute::isReadOnly
virtual bool isReadOnly()
Read only attributes cannot be modified with setValue.
Definition: CoreModifiableAttribute.h:276
maStringHeritage
CoreModifiableAttributeData of string with different level of notification.
Definition: maString.h:17
maStringHeritage::c_str
const char * c_str() const
Definition: maString.h:26
CoreModifiableAttribute.h
Base template class for CoreModifiable attributes managing data.