ZeusBase-Library  2.0.4
XObject.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch)
3  *****************************************************************************
4  * Project : Zeus Base Library
5  * Module : XObject
6  * Package : Zeus.ZeusBase.System
7  * Author : Benjamin Hadorn
8  * Date : 27.12.2011
9  * System : Zeus-Framework
10  *****************************************************************************
11  * Licence: *
12  * This library is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU Lesser General Public License as *
14  * published by the Free Software Foundation; either version *
15  * 2.1 of the License, or (at your option) any later version. *
16  * *
17  * This library is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU Lesser General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU Lesser General Public *
23  * License along with this library; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
25  *****************************************************************************/
26 
27 /*****************************************************************************
28  * Changes:
29  * 27.12.2011 bha: created zeus 2.0
30  *****************************************************************************/
31 
32 #ifndef XObjectH
33 #define XObjectH
34 
39 
41 
42 class TCriticalSection;
43 class TXMemberCollection;
44 
45 /***************************************************************************/
48 /***************************************************************************/
50 {
51  public:
52  TXObject(IXMLNode& rNode);
53 
54  virtual TString getXMLStream() const;
55  virtual TString getCodeModule() const;
56 
57  //Methods of IXObject
58  virtual void MQUALIFIER getName(IString& rName)const;
59  virtual void MQUALIFIER getClassName(IString& rName)const;
60  virtual Uint MQUALIFIER getID()const;
61  virtual Retval MQUALIFIER addChild(IXObject& rChild);
62  virtual Retval MQUALIFIER deleteChild(Int iIndex, bool bDoFreeze=false);
63  virtual Retval MQUALIFIER removeChild(IXObject& rChild, bool bDoFreeze=false);
64  virtual Int MQUALIFIER getChildCount()const;
65  virtual Retval MQUALIFIER getChild(Int iIndex, IXObject*& rpChild);
66  virtual Retval MQUALIFIER getChildByName(const IString& rName, IXObject*& rpChild);
67  virtual Retval MQUALIFIER getChildrenByName(const IString& name, IXObjectCollection*& pObjects);
68  virtual Retval MQUALIFIER getParent(IXObject*& rpParent)const;
69  virtual Retval MQUALIFIER setParent(IXObject* pParent);
70  virtual Retval MQUALIFIER getXMLNode(IXMLNode*& rpNode) const;
71  virtual Retval MQUALIFIER setChild(IXObject& rChild);
72  virtual Retval MQUALIFIER getObject(const IString& rPath, IXObject*& rpObj);
73  virtual Retval MQUALIFIER getObjects(const IString& rPath, IXObjectCollection*& pObjects);
74  virtual Retval MQUALIFIER getRootObject(IXObject*& rpObj);
75  virtual bool MQUALIFIER canCreateChildren()const;
76  virtual bool MQUALIFIER freeze();
77  virtual bool MQUALIFIER unfreeze();
78  virtual bool MQUALIFIER isFrozen()const;
79  virtual void MQUALIFIER setTreeLock(ICriticalSection* pSection);
80  virtual void MQUALIFIER lockTree();
81  virtual void MQUALIFIER unlockTree();
82  virtual Retval MQUALIFIER onExecute(ISimpleCommand& rCommand, Uint uiMode);
83  virtual void MQUALIFIER onBroadCast(ISimpleCommand& rMessage);
84  virtual Retval MQUALIFIER insertChild(Int iIndex, IXObject& rChild);
85  virtual Int MQUALIFIER indexOfChild(IXObject& rChild);
86  virtual Retval MQUALIFIER createChildObject(const IString& rName,
87  const IString& rClassName,
88  const IString& rCodeModule,
89  IXObject*& rpChild);
90  virtual Retval MQUALIFIER createChildObjectCustom(const IString& rName,
91  const IString& rClassName,
92  const IString& rCodeModule,
93  const IStringList& rList,
94  IXObject*& rpChild);
95  virtual Retval MQUALIFIER getCastedObject(const IString& rPath,
96  const InterfaceID& rInterfaceID,
97  IZUnknown*& rpObj);
98  virtual Retval MQUALIFIER readIntAttribute(const IString& rName, Int& rValue, Int iDefault = 0) const;
99  virtual Retval MQUALIFIER readUintAttribute(const IString& rName, Uint& rValue, Uint uiDefault = 0) const;
100  virtual Retval MQUALIFIER readFloatAttribute(const IString& rName, Float& rValue, Float fDefault = 0) const;
101  virtual Retval MQUALIFIER readStringAttribute(const IString& rName, IString& rValue) const;
102  virtual Retval MQUALIFIER readTimevalAttribute(const IString& rstrName, Timeval& rtmValue, Timeval rtmDefault = 0) const;
103  virtual Retval MQUALIFIER readBoolAttribute(const IString& rstrName, bool& rbValue, bool bDefault = false) const;
104  virtual Retval MQUALIFIER storeIntAttribute(const IString& rName, const Int& rValue);
105  virtual Retval MQUALIFIER storeUintAttribute(const IString& rName, const Uint& rValue);
106  virtual Retval MQUALIFIER storeFloatAttribute(const IString& rName, const Float& rValue);
107  virtual Retval MQUALIFIER storeStringAttribute(const IString& rName, const IString& rValue);
108  virtual Retval MQUALIFIER storeTimevalAttribute(const IString& rstrName, const Timeval& rtmValue);
109  virtual Retval MQUALIFIER storeBoolAttribute(const IString& rstrName, const bool& rbValue);
110  virtual Int MQUALIFIER getMemberCount() const;
111  virtual Retval MQUALIFIER getMemberVariable(Int iIndex, IXMemberVariable*& rpMember) const;
112  virtual Retval MQUALIFIER getMemberVariableByName(const IString& rName, IXMemberVariable*& rpMember) const;
113  virtual Retval MQUALIFIER addNewMemberVariable(const IString& rName, IXMemberVariable::EVariableType eType);
114  virtual Retval MQUALIFIER removeMemberVariable(const IString& rName);
115  virtual Retval MQUALIFIER getMemberObjectReference(const IString& rName, IXObject*& rpRef);
116  virtual Retval MQUALIFIER getMemberXMLNode(const IString& rName, IXMLNode*& rpNode) const;
117  virtual Retval MQUALIFIER readMemberVariable(const IString& rName, IZVariant& rValue) const;
118  virtual Retval MQUALIFIER storeMemberVariable(const IString& rName, const IZVariant& rValue);
119  virtual void MQUALIFIER resetMemberVariables();
120 
121 
122  //Methods of IZUnknown
124 
125  //Methods of TZObject
126  virtual void setObjName(const TString& rName);
127 
128 
129  protected:
136 
137  TXObject();
138  virtual ~TXObject();
139 
140  virtual void onChildAdded(IXObject& /*rChild*/){};
141  virtual void onChildDeleted(IXObject& /*rChild*/){};
142 
143  void freezeChildren();
144  void unfreezeChildren();
145 
146  private:
148  TSingleLinkedList<IXObject*> m_lstChildren;
150  IXObject* m_pParent;
152  bool m_bFrozen;
154  TCriticalSection& m_rLock;
155 
156  void expandMembers() const;
157 
159  //DEPRECATED METHODS.
160  protected:
161  //Methods to read a persistent value
162  inline Retval readAttribute(TString strName, TString& rValue) const { return readStringAttribute(strName, rValue); }
163  inline Retval readAttribute(TString strName, Int& rValue) const { return readIntAttribute(strName, rValue); }
164  inline Retval readAttribute(TString strName, Uint& rValue) const { return readUintAttribute(strName, rValue); }
165  inline Retval readAttribute(TString strName, Float& rValue) const { return readFloatAttribute(strName, rValue); }
166 
167  //Methods to write a persistent value
168  inline Retval storeAttribute(TString strName, TString strValue) { return storeStringAttribute(strName, strValue); }
169  inline Retval storeAttribute(TString strName, Int iValue) { return storeIntAttribute(strName, iValue); }
170  inline Retval storeAttribute(TString strName, Uint uiValue) { return storeUintAttribute(strName, uiValue); }
171  inline Retval storeAttribute(TString strName, Float fValue) { return storeFloatAttribute(strName, fValue); }
173 
174 };
175 
176 //INLINE METHODS
177 /***************************************************************************/
180 /***************************************************************************/
181 inline void MQUALIFIER TXObject::getName(IString& rName)const
182 {
183  rName.assignStr(TZObject::getObjName());
184 }
185 
186 /***************************************************************************/
189 /***************************************************************************/
190 inline Int MQUALIFIER TXObject::getChildCount() const
191 {
192  return m_lstChildren.getCount();
193 }
194 
195 /***************************************************************************/
198 /***************************************************************************/
199 inline bool MQUALIFIER TXObject::canCreateChildren() const
200 {
201  return true;
202 }
203 
204 /***************************************************************************/
207 /***************************************************************************/
208 inline bool MQUALIFIER TXObject::isFrozen() const
209 {
210  return m_bFrozen;
211 }
212 
213 /***************************************************************************/
216 /***************************************************************************/
217 inline Retval MQUALIFIER TXObject::onExecute(ISimpleCommand& /*rCommand*/, Uint /*uiMode*/)
218 {
219  return RET_REQUEST_FAILED;
220 }
221 
222 /***************************************************************************/
225 /***************************************************************************/
226 inline Retval MQUALIFIER TXObject::setParent(IXObject* parent)
227 {
228  m_pParent = parent; //To not allocate a reference, because of circularity
229  return RET_NOERROR;
230 }
231 
232 /***************************************************************************/
235 /***************************************************************************/
236 inline Int MQUALIFIER TXObject::indexOfChild(IXObject& rChild)
237 {
238  return this->m_lstChildren.indexOf(&rChild);
239 }
240 
241 
242 /***************************************************************************/
245 /***************************************************************************/
246 inline void TXObject::setObjName(const TString& /*name*/)
247 {
248  //Can not change the node name
249 }
250 
252 #endif
Definition: ZObject.h:57
#define END_NAMESPACE_Zeus
Definition: PlatformDefines.hpp:96
#define RET_NOERROR
Definition: RetvalDefines.hpp:40
#define zeusbase_class
Definition: PlatformDefines.hpp:165
Definition: IZVariant.hpp:57
Definition: IXObjectCollection.hpp:52
Definition: PlatformDefines.hpp:327
Definition: ICriticalSection.hpp:48
Definition: XMemberVariable.h:110
#define MQUALIFIER
Definition: LinuxPlatform.hpp:64
Retval storeAttribute(TString strName, Int iValue)
Definition: XObject.h:169
Definition: IList.hpp:57
#define BEGIN_NAMESPACE_Zeus
Definition: PlatformDefines.hpp:95
Retval storeAttribute(TString strName, Uint uiValue)
Definition: XObject.h:170
virtual void onChildAdded(IXObject &)
Definition: XObject.h:140
Retval readAttribute(TString strName, Int &rValue) const
Definition: XObject.h:163
Definition: XObject.h:49
EVariableType
Definition: IXMemberVariable.hpp:64
virtual void MQUALIFIER assignStr(const IString &rInstr)=0
virtual void onChildDeleted(IXObject &)
Definition: XObject.h:141
Definition: String.h:113
#define RET_REQUEST_FAILED
Definition: RetvalDefines.hpp:55
Retval storeAttribute(TString strName, TString strValue)
Definition: XObject.h:168
Retval readAttribute(TString strName, TString &rValue) const
Definition: XObject.h:162
IXMLNode * m_pNode
XML Node. This variable must be a pointer because of TXLoaderObject. The pointer is always valid...
Definition: XObject.h:131
Retval readAttribute(TString strName, Float &rValue) const
Definition: XObject.h:165
Definition: SingleLinkedList.hpp:47
Definition: IXMemberVariable.hpp:55
Definition: CriticalSection.h:52
TXMemberCollection * m_pMemberVariables
X-Object member variables.
Definition: XObject.h:135
Retval readAttribute(TString strName, Uint &rValue) const
Definition: XObject.h:164
Definition: IXObject.hpp:64
Definition: ISimpleCommand.hpp:54
ICriticalSection * m_pTreeLock
Lock of the data and object tree.
Definition: XObject.h:133
Definition: IZUnknown.hpp:65
Retval storeAttribute(TString strName, Float fValue)
Definition: XObject.h:171
Definition: IXMLNode.hpp:55
#define MEMORY_MANAGER_DECL
Definition: IZUnknownImplHelper.hpp:44
Definition: IString.hpp:48


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Tue Sep 13 2016 22:30:53