Kigs Framework  Doc version 0.8
Open source multi purpose Rapid Application Development framework
maCoreItem.h
Go to the documentation of this file.
1 #ifndef _MACOREITEM_H
2 #define _MACOREITEM_H
3 
5 #include "CoreItem.h"
6 #include "AttributeModifier.h"
7 #include "SmartPointer.h"
8 
9 
10 
11 class maCoreItemValue
12 {
13 public:
14  CoreItemSP item=nullptr;
15  kstl::string ref_file="";
16 
17  void InitWithJSON(const kstl::string& currentval, CoreModifiable* owner);
18  bool ExportToString(kstl::string& value) const;
19 
20 };
21 
22 
23 // ****************************************
24 // * maCoreItemHeritage class
25 // * --------------------------------------
32 // ****************************************
33 template<int notificationLevel>
34 class maCoreItemHeritage : public CoreModifiableAttributeData<maCoreItemValue>
35 {
36  DECLARE_ATTRIBUTE_HERITAGE_NO_ASSIGN(maCoreItemHeritage, maCoreItemHeritage, maCoreItemValue, CoreModifiable::ATTRIBUTE_TYPE::COREITEM);
37 
38 public:
39 
41  maCoreItemHeritage(CoreModifiable& owner, bool isInitAttribute, KigsID ID, kstl::string value) : CoreModifiableAttributeData(owner, isInitAttribute, ID )
42  {
43  if (value != "")
44  {
45  mValue.InitWithJSON(value, &owner);
46  }
47  }
48 
49  // getValue overloads
50 
51  virtual bool getValue(bool& value) const override { if (!mValue.item.isNil()) { value = (bool)(*mValue.item.get()); return true; } return false; }
52  virtual bool getValue(int& value) const override { if (!mValue.item.isNil()) { value = (int)(*mValue.item.get()); return true; } return false; }
53  virtual bool getValue(unsigned int& value) const override { if (!mValue.item.isNil()) { value = (unsigned int)(*mValue.item.get()); return true; } return false; }
54  virtual bool getValue(kfloat& value) const override { if (!mValue.item.isNil()) { value = (kfloat)(*mValue.item.get()); return true; } return false; }
55  virtual bool getValue(kstl::string& value) const override
56  {
57  if (!mValue.item.isNil())
58  {
59  return mValue.ExportToString(value);
60  }
61  return false;
62  }
63  virtual bool getValue(CoreItem*& value) const override
64  {
65  value = (CoreItem*)mValue.item.get();
66  return true;
67  }
68  virtual bool getValue(void*& value) const override { value = (void*)mValue.item.get(); return true; }
69 
71 
72  // setValue overloads
73  virtual bool setValue(const char* value) override
74  {
75  if (this->isReadOnly())
76  return false;
77 
78  mValue.InitWithJSON(value, this->mOwner);
79  DO_NOTIFICATION(notificationLevel);
80  return true;
81  }
82  virtual bool setValue(const kstl::string& value) override
83  {
84  if (this->isReadOnly())
85  return false;
86 
87  mValue.InitWithJSON(value, this->mOwner);
88  DO_NOTIFICATION(notificationLevel);
89  return true;
90  }
91  virtual bool setValue(CoreItem* value) override
92  {
93  if (this->isReadOnly())
94  return false;
95 
96  if (mValue.item != value)
97  {
98  mValue.item = CoreItemSP(value, GetRefTag{});
99  mValue.ref_file = "";
100  DO_NOTIFICATION(notificationLevel);
101  }
102  return true;
103  }
104 
106  operator CoreItem*() { return mValue.item.get(); }
108  operator CoreItem&() { return (*mValue.item.get()); }
110  CoreItem& ref() { return (*mValue.item.get()); }
112  const CoreItem& const_ref() { return (*mValue.item.get()); }
113  const kstl::string& getRefFile() { return mValue.ref_file; }
114 
115 
116 };
117 
118 // ****************************************
119 // * maCoreItem class
120 // * --------------------------------------
127 // ****************************************
128 
129 using maCoreItem = maCoreItemHeritage<0>;
130 
131 #endif //_MACOREITEM_H
CoreModifiableAttribute::isReadOnly
virtual bool isReadOnly()
Read only attributes cannot be modified with setValue.
Definition: CoreModifiableAttribute.h:276
CoreItem.h
SmartPointer class to manage CoreItem.
CoreModifiable
Base class for Kigs framework objects. CoreModifiable class manage a list of attributes supporting re...
Definition: CoreModifiable.h:400
GetRefTag
Definition: SmartPointer.h:9
CoreModifiableAttribute.h
Base template class for CoreModifiable attributes managing data.