eris  1.4.0
A WorldForge client library.
TypeInfo.h
1 #ifndef ERIS_TYPE_INFO_H
2 #define ERIS_TYPE_INFO_H
3 
4 #include "Types.h"
5 #include <Atlas/Message/Element.h>
6 #include <Atlas/Objects/Root.h>
7 
8 #include <sigc++/trackable.h>
9 #include <sigc++/signal.h>
10 
11 #include <map>
12 #include <string>
13 
14 namespace Eris {
15 
32 class TypeInfo : virtual public sigc::trackable
33 {
34 public:
38  bool isA(TypeInfo* ti) const;
39 
44  bool isA(const std::string& typeName) const;
45 
49  inline bool isBound() const;
50 
54  void refresh();
55 
59  bool hasUnresolvedChildren() const;
60 
65  void resolveChildren();
66 
67 // operators
69  bool operator==(const TypeInfo &x) const;
70 
72  bool operator<(const TypeInfo &x) const;
73 
74 // accessors
76  const std::string& getName() const;
77 
79  const std::string& getObjType() const;
80 
85  const std::set<TypeInfo*> & getChildren() const;
86 
91  const TypeInfo* getParent() const;
93 
99  const Atlas::Message::MapType& getProperties() const;
100 
108  const Atlas::Message::Element* getProperty(const std::string& propertyName) const;
109 
114  sigc::signal<void, const std::string&, const Atlas::Message::Element&> PropertyChanges;
115 
121  void setProperty(const std::string& propertyName, const Atlas::Message::Element& element);
122 
127  const Atlas::Message::ListType& getEntities() const;
128 
129  TypeService& getTypeService();
130 
131  const TypeService& getTypeService() const;
132 
133 
134 protected:
135  friend class TypeService;
136  friend class TypeBoundRedispatch;
137 
139  TypeInfo(std::string id, TypeService&);
140 
142  TypeInfo(const Atlas::Objects::Root &atype, TypeService&);
143 
144  void validateBind();
145 
147  void processTypeData(const Atlas::Objects::Root& atype);
148 
152  sigc::signal<void> Bound;
153 
154 
163  void onPropertyChanges(const std::string& propertyName, const Atlas::Message::Element& element);
164 
165 private:
166  void setParent(TypeInfo* tp);
167  void addChild(TypeInfo* tp);
168 
170  void addAncestor(TypeInfo* tp);
171 
177  void extractDefaultProperties(const Atlas::Objects::Root& atype);
178 
180  TypeInfo* m_parent;
182  std::set<TypeInfo*> m_children;
183 
185  std::set<TypeInfo*> m_ancestors;
186 
187  bool m_bound;
188  const std::string m_name;
189  std::string m_objType;
190 
191  std::set<std::string> m_unresolvedChildren;
192 
193  TypeService& m_typeService;
194 
198  Atlas::Message::MapType m_properties;
199 
200  /*
201  * @brief If the type is an archetype, the entities will be defined here.
202  */
203  Atlas::Message::ListType m_entities;
204 
205 };
206 
207 inline const Atlas::Message::MapType& TypeInfo::getProperties() const
208 {
209  return m_properties;
210 }
211 
212 inline bool TypeInfo::isBound() const
213 {
214  return m_bound;
215 }
216 
217 inline const std::string& TypeInfo::getName() const
218 {
219  return m_name;
220 }
221 
222 inline const std::string& TypeInfo::getObjType() const {
223  return m_objType;
224 }
225 
226 inline const std::set<TypeInfo*> & TypeInfo::getChildren() const
227 {
228  return m_children;
229 }
230 
231 inline const TypeInfo* TypeInfo::getParent() const
232 {
233  return m_parent;
234 }
235 
237 {
238  return m_parent;
239 }
240 
241 inline const Atlas::Message::ListType& TypeInfo::getEntities() const
242 {
243  return m_entities;
244 }
245 
246 inline TypeService& TypeInfo::getTypeService()
247 {
248  return m_typeService;
249 }
250 
251 inline const TypeService& TypeInfo::getTypeService() const
252 {
253  return m_typeService;
254 }
255 
256 
257 } // of Eris namespace
258 
259 #endif
sigc::signal< void > Bound
Emitted when the type is bound, i.e there is an unbroken graph of TypeInfo instances through every an...
Definition: TypeInfo.h:152
void processTypeData(const Atlas::Objects::Root &atype)
process the INFO data
Definition: TypeInfo.cpp:96
const Atlas::Message::MapType & getProperties() const
Gets the default properties for this entity type. Note that the map returned does not include inherit...
Definition: TypeInfo.h:207
The representation of an Atlas type (i.e a class or operation definition). This class supports effice...
Definition: TypeInfo.h:32
bool hasUnresolvedChildren() const
Test if there are child types of the type, which have not yet been retrieved from the server...
Definition: TypeInfo.cpp:76
sigc::signal< void, const std::string &, const Atlas::Message::Element & > PropertyChanges
Emitted before an property changes. The first parameter is the name of the property, and the second is the actual property.
Definition: TypeInfo.h:114
bool operator<(const TypeInfo &x) const
efficent ordering of type (uses type ids if possible)
Definition: TypeInfo.cpp:179
void setProperty(const std::string &propertyName, const Atlas::Message::Element &element)
Sets a property.
Definition: TypeInfo.cpp:277
const Atlas::Message::ListType & getEntities() const
Gets a list of entities, if the type is an Archetype.
Definition: TypeInfo.h:241
Definition: Account.cpp:33
bool operator==(const TypeInfo &x) const
efficent comparisom of types (uses type ids if possible)
Definition: TypeInfo.cpp:171
const std::set< TypeInfo * > & getChildren() const
Gets the currently resolved child TypeInfo instances.
Definition: TypeInfo.h:226
bool isBound() const
Check the bound flag for this node; if false then recursivley check parents until an authorative is f...
Definition: TypeInfo.h:212
const std::string & getName() const
the unique type name (matches the Atlas type)
Definition: TypeInfo.h:217
bool isA(TypeInfo *ti) const
Test whether this type inherits (directly or indirectly) from the specific class. If this type is not...
Definition: TypeInfo.cpp:48
void refresh()
Request update to the type info from the server.
Definition: TypeInfo.cpp:300
TypeInfo(std::string id, TypeService &)
forward constructor, when data is not available
Definition: TypeInfo.cpp:24
const std::string & getObjType() const
the object type of this Type or Archetype
Definition: TypeInfo.h:222
void onPropertyChanges(const std::string &propertyName, const Atlas::Message::Element &element)
Called before the PropertyChanges signal is emitted. This call is made before an property is changed...
Definition: TypeInfo.cpp:288
const Atlas::Message::Element * getProperty(const std::string &propertyName) const
Gets the value of the named property. This method will search through both this instance and all of i...
Definition: TypeInfo.cpp:259
void resolveChildren()
Retrive all child types from the server. This will log an error and do nothing if no unresolved child...
Definition: TypeInfo.cpp:81
const TypeInfo * getParent() const
Gets the currently resolved parent TypeInfo instances.
Definition: TypeInfo.h:231