Eris  1.4.0
TypeInfo.h
1 #ifndef ERIS_TYPE_INFO_H
2 #define ERIS_TYPE_INFO_H
3 
4 #include "Types.h"
5 #include "TypeService.h"
6 #include <Atlas/Message/Element.h>
7 
8 #include <sigc++/trackable.h>
9 
10 #include <map>
11 #include <string>
12 
13 namespace Eris {
14 
31 class TypeInfo : virtual public sigc::trackable
32 {
33 public:
37  bool isA(TypeInfoPtr ti);
38 
42  inline bool isBound() const;
43 
47  void refresh();
48 
52  bool hasUnresolvedChildren() const;
53 
58  void resolveChildren();
59 
60 // operators
62  bool operator==(const TypeInfo &x) const;
63 
65  bool operator<(const TypeInfo &x) const;
66 
67 // accessors
69  const std::string& getName() const;
70 
72  const std::string& getObjType() const;
73 
78  const TypeInfoSet & getChildren() const;
79 
84  const TypeInfoPtr & getParent() const;
85 
91  const Atlas::Message::MapType& getAttributes() const;
92 
100  const Atlas::Message::Element* getAttribute(const std::string& attributeName) const;
101 
106  sigc::signal<void, const std::string&, const Atlas::Message::Element&> AttributeChanges;
107 
108 
114  void setAttribute(const std::string& attributeName, const Atlas::Message::Element& element);
115 
120  const Atlas::Message::ListType& getEntities() const;
121 
122 
123 protected:
124  friend class TypeService;
125  friend class TypeBoundRedispatch;
126 
128  TypeInfo(const std::string &id, TypeService*);
129 
131  TypeInfo(const Atlas::Objects::Root &atype, TypeService*);
132 
133  void validateBind();
134 
136  void processTypeData(const Atlas::Objects::Root& atype);
137 
141  sigc::signal<void> Bound;
142 
143 
150  void onAttributeChanges(const std::string& attributeName, const Atlas::Message::Element& element);
151 
152 private:
153  void setParent(TypeInfoPtr tp);
154  void addChild(TypeInfoPtr tp);
155 
157  void addAncestor(TypeInfoPtr tp);
158 
164  void extractDefaultAttributes(const Atlas::Objects::Root& atype);
165 
167  TypeInfoPtr m_parent;
169  TypeInfoSet m_children;
170 
172  TypeInfoSet m_ancestors;
173 
174  bool m_bound;
175  const std::string m_name;
176  std::string m_objType;
177 
178  StringSet m_unresolvedChildren;
179 
180  TypeService* m_typeService;
181 
185  Atlas::Message::MapType m_attributes;
186 
187  /*
188  * @brief If the type is an archetype, the entities will be defined here.
189  */
190  Atlas::Message::ListType m_entities;
191 
192 };
193 
194 inline const Atlas::Message::MapType& TypeInfo::getAttributes() const
195 {
196  return m_attributes;
197 }
198 
199 inline bool TypeInfo::isBound() const
200 {
201  return m_bound;
202 }
203 
204 inline const std::string& TypeInfo::getName() const
205 {
206  return m_name;
207 }
208 
209 inline const std::string& TypeInfo::getObjType() const {
210  return m_objType;
211 }
212 
213 inline const TypeInfoSet & TypeInfo::getChildren() const
214 {
215  return m_children;
216 }
217 
218 inline const TypeInfoPtr & TypeInfo::getParent() const
219 {
220  return m_parent;
221 }
222 
223 inline const Atlas::Message::ListType& TypeInfo::getEntities() const
224 {
225  return m_entities;
226 }
227 
228 
229 } // of Eris namespace
230 
231 #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:141
void processTypeData(const Atlas::Objects::Root &atype)
process the INFO data
Definition: TypeInfo.cpp:80
bool isA(TypeInfoPtr ti)
Test whether this type inherits (directly or indirectly) from the specific class. ...
Definition: TypeInfo.cpp:46
const TypeInfoSet & getChildren() const
Gets the currently resolved child TypeInfo instances.
Definition: TypeInfo.h:213
The representation of an Atlas type (i.e a class or operation definition).
Definition: TypeInfo.h:31
bool hasUnresolvedChildren() const
Test if there are child types of the type, which have not yet been retrieved from the server...
Definition: TypeInfo.cpp:60
bool operator<(const TypeInfo &x) const
efficent ordering of type (uses type ids if possible)
Definition: TypeInfo.cpp:161
TypeInfo(const std::string &id, TypeService *)
forward constructor, when data is not available
Definition: TypeInfo.cpp:23
const Atlas::Message::ListType & getEntities() const
Gets a list of entities, if the type is an Archetype.
Definition: TypeInfo.h:223
Definition: TypeBoundRedispatch.h:13
Every Eris class and type lives inside the Eris namespace; certain utility functions live in the Util...
Definition: Account.cpp:34
bool operator==(const TypeInfo &x) const
efficent comparisom of types (uses type ids if possible)
Definition: TypeInfo.cpp:153
const TypeInfoPtr & getParent() const
Gets the currently resolved parent TypeInfo instances.
Definition: TypeInfo.h:218
bool isBound() const
Check the bound flag for this node; if false then recursivley check parents until an authorative is f...
Definition: TypeInfo.h:199
const std::string & getName() const
the unique type name (matches the Atlas type)
Definition: TypeInfo.h:204
void onAttributeChanges(const std::string &attributeName, const Atlas::Message::Element &element)
Called before the AttributeChanges signal is emitted.
Definition: TypeInfo.cpp:282
void refresh()
Request update to the type info from the server.
Definition: TypeInfo.cpp:294
A service class querying and caching types.
Definition: TypeService.h:24
const Atlas::Message::MapType & getAttributes() const
Gets the default attributes for this entity type.
Definition: TypeInfo.h:194
const std::string & getObjType() const
the object type of this Type or Archetype
Definition: TypeInfo.h:209
sigc::signal< void, const std::string &, const Atlas::Message::Element & > AttributeChanges
Emitted before an attribute changes.
Definition: TypeInfo.h:106
const Atlas::Message::Element * getAttribute(const std::string &attributeName) const
Gets the value of the named attribute.
Definition: TypeInfo.cpp:251
void setAttribute(const std::string &attributeName, const Atlas::Message::Element &element)
Sets an attribute.
Definition: TypeInfo.cpp:270
void resolveChildren()
Retrive all child types from the server.
Definition: TypeInfo.cpp:65