Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
maUSString.h
1 #ifndef _MAUSSTRING_H
2 #define _MAUSSTRING_H
3 
5 #include "usString.h"
6 #include "AttributeModifier.h"
7 
8 // ****************************************
9 // * maUSStringHeritage class
10 // * --------------------------------------
16 // ****************************************
17 template<int notificationLevel>
18 class maUSStringHeritage : public CoreModifiableAttributeData<usString>
19 {
20  DECLARE_ATTRIBUTE_HERITAGE(maUSStringHeritage, maUSStringHeritage, usString, CoreModifiable::ATTRIBUTE_TYPE::USSTRING);
21 
22 public:
23 
25  maUSStringHeritage(CoreModifiable& owner, bool isInitAttribute, KigsID ID, const kstl::string& value ) : CoreModifiableAttributeData<usString>(owner, isInitAttribute, ID)
26  {
27  mValue = usString{ value };
28  }
29 
30  void* getRawValue() final { return (void*)mValue.us_str(); }
31  size_t MemorySize() const final { return mValue.length()*sizeof(u16); };
32 
34  virtual bool getValue(kstl::string& value) const override
35  {
36  usString copy(mValue);
37  value = copy.ToString();
38  return true;
39  }
40  virtual bool getValue(usString& value) const override
41  {
42  value = mValue;
43  return true;
44  }
45  virtual bool getValue(void*& value) const override
46  {
47  value = (void*)&mValue;
48  return true;
49  }
51 
53  virtual bool setValue(const char* value) override
54  {
55  if (this->isReadOnly())
56  return false;
57 
58  mValue = usString(value);
59 
60  DO_NOTIFICATION(notificationLevel);
61 
62  return true;
63  }
64  virtual bool setValue(const kstl::string& value) override
65  {
66  if (this->isReadOnly())
67  return false;
68 
69  mValue = value;
70 
71  DO_NOTIFICATION(notificationLevel);
72 
73  return false;
74  }
75  virtual bool setValue(const unsigned short* value) override
76  {
77  if (this->isReadOnly())
78  return false;
79 
80  mValue = value;
81  DO_NOTIFICATION(notificationLevel);
82 
83  return true;
84  }
85  virtual bool setValue(const usString& value) override
86  {
87  if (this->isReadOnly())
88  return false;
89 
90  mValue = value;
91  DO_NOTIFICATION(notificationLevel);
92  return true;
93  }
94 
95  virtual bool setValue(const UTF8Char* value) override
96  {
97  if (this->isReadOnly())
98  return false;
99 
100  mValue = value;
101 
102  DO_NOTIFICATION(notificationLevel);
103 
104  return false;
105  }
106 
107 #undef DECLARE_SET_NUMERIC
108 #define DECLARE_SET_NUMERIC(type) virtual bool setValue(type value) override { \
109  if (this->isReadOnly())\
110  return false; \
111  usString tmpValue = std::to_string(value); \
112  CALL_SETMODIFIER(notificationLevel, tmpValue); \
113  this->mValue = tmpValue; \
114  DO_NOTIFICATION(notificationLevel); \
115  return true; \
116 }
117 
118  EXPAND_MACRO_FOR_NUMERIC_TYPES(NOQUALIFIER, NOQUALIFIER, DECLARE_SET_NUMERIC);
119 
120 
122 
124  // Assign
125  auto& operator=(const unsigned short* attribute)
126  {
127  mValue = attribute;
128  return *this;
129  }
130  auto& operator=(kstl::string& attribute)
131  {
132  mValue = attribute;
133  return *this;
134  }
135  /*auto& operator=(const char* attribute)
136  {
137  mValue = attribute;
138  return *this;
139  }*/
140 
141  // Comparison
142  bool operator==(const usString& L_value) const
143  {
144  return (mValue == L_value);
145  }
146  bool operator==(unsigned short* L_value) const
147  {
148  return (mValue == L_value);
149  }
150  bool operator!=(const usString& L_value) const
151  {
152  return (mValue != L_value);
153  }
154  bool operator!=(unsigned short* L_value) const
155  {
156  return (mValue != L_value);
157  }
158 
159  // Append
160  auto& operator+=(const usString& value)
161  {
162  mValue += value;
163  return *this;
164  }
165  auto& operator+=(unsigned short* value)
166  {
167  mValue += value;
168  return *this;
169  }
170  auto& operator+=(const CoreModifiableAttribute& value)
171  {
172  usString L_tmp = usString("");
173  if(value.getValue(L_tmp))
174  mValue += L_tmp;
175  return *this;
176  }
178 
180  const unsigned short* us_str() const { return mValue.us_str(); }
181  kstl::string ToString() { return mValue.ToString(); }
182  void strcpywUtoC(char * _Dest, const unsigned short * src) { mValue.strcpywUtoC(_Dest, src); }
183  kstl::vector<usString> SplitByCharacter(unsigned short value) const { return mValue.SplitByCharacter(value); }
184  unsigned int strlen() const { return mValue.strlen(); }
185 
186 };
187 
188 
190 
191 
192 
193 #endif //_MAUSSTRING_H
CoreModifiableAttribute::isReadOnly
virtual bool isReadOnly()
Read only attributes cannot be modified with setValue.
Definition: CoreModifiableAttribute.h:276
maUSStringHeritage::operator=
auto & operator=(const unsigned short *attribute)
operators
Definition: maUSString.h:125
maUSStringHeritage::us_str
const unsigned short * us_str() const
return a const unsigned short* pointer on internal value
Definition: maUSString.h:180
maUSStringHeritage::maUSStringHeritage
maUSStringHeritage(CoreModifiable &owner, bool isInitAttribute, KigsID ID, const kstl::string &value)
Extra constructors.
Definition: maUSString.h:25
CoreModifiable
Base class for Kigs framework objects. CoreModifiable class manage a list of attributes supporting re...
Definition: CoreModifiable.h:480
maUSStringHeritage
CoreModifiableAttributeData of usstring with different level of notification.
Definition: maUSString.h:18
maUSStringHeritage::getValue
virtual bool getValue(kstl::string &value) const override
getValue overloads
Definition: maUSString.h:34
maUSStringHeritage::setValue
virtual bool setValue(const char *value) override
setValue overloads
Definition: maUSString.h:53
CoreModifiableAttribute.h
Base template class for CoreModifiable attributes managing data.
CoreModifiableAttribute
Base class for all CoreModifiableAttribute . This class is just composed of virtual methods.
Definition: CoreModifiableAttribute.h:145