Eris  1.4.0
TypeService.h
1 #ifndef ERIS_TYPE_SERVICE_H
2 #define ERIS_TYPE_SERVICE_H
3 
4 #include <Atlas/Objects/ObjectsFwd.h>
5 
6 #include <sigc++/trackable.h>
7 #include <sigc++/signal.h>
8 
9 #include <unordered_map>
10 #include <set>
11 #include <string>
12 
13 namespace Eris {
14 
15 class Connection;
16 class TypeInfo;
17 
18 typedef TypeInfo* TypeInfoPtr;
19 typedef std::set<TypeInfoPtr> TypeInfoSet;
20 
24 class TypeService : virtual public sigc::trackable
25 {
26 public:
27  explicit TypeService(Connection *con);
28  virtual ~TypeService();
29 
30  void init();
31 
35  TypeInfoPtr getTypeByName(const std::string &tynm);
36 
39  TypeInfoPtr getTypeForAtlas(const Atlas::Objects::Root &obj);
40 
42  TypeInfoPtr findTypeByName(const std::string &tynm);
43 
45  sigc::signal<void, TypeInfoPtr> BoundType;
46 
48  sigc::signal<void, TypeInfoPtr> BadType;
49 
50  void handleOperation(const Atlas::Objects::Operation::RootOperation&);
51 
55  void sendRequest(const std::string& id);
56 
65  void setTypeProviderId(std::string id);
66 
67 protected:
68 
69  void recvTypeInfo(const Atlas::Objects::Root &atype);
70  void recvError(const Atlas::Objects::Operation::Get& get);
71  void recvTypeUpdate(const Atlas::Objects::Root &atype);
72 
73  TypeInfoPtr defineBuiltin(const std::string& name, TypeInfoPtr parent);
74 
75  typedef std::unordered_map<std::string, TypeInfoPtr> TypeInfoMap;
79  TypeInfoMap m_types;
80 
81  Connection* m_con;
82  bool m_inited;
83 
87  std::string m_type_provider_id;
88 };
89 
90 } // of namespace Eris
91 
92 #endif // of ERIS_TYPE_SERVICE_H
TypeInfoPtr getTypeByName(const std::string &tynm)
find the TypeInfo for the named type; this may involve a search, or a map lookup. ...
Definition: TypeService.cpp:62
TypeInfoPtr getTypeForAtlas(const Atlas::Objects::Root &obj)
retrive the TypeInfo for an object; this should be faster (hopefully constant time) since it can take...
Definition: TypeService.cpp:76
TypeInfoMap m_types
The easy bit : a simple map from &#39;string-id&#39; (e.g &#39;look&#39; or &#39;farmer&#39;) to the corresponding TypeInfo i...
Definition: TypeService.h:79
sigc::signal< void, TypeInfoPtr > BoundType
emitted when a new type is available and bound to it&#39;s parents
Definition: TypeService.h:45
Every Eris class and type lives inside the Eris namespace; certain utility functions live in the Util...
Definition: Account.cpp:34
Underlying Atlas connection, providing a send interface, and receive (dispatch) system.
Definition: Connection.h:36
void setTypeProviderId(std::string id)
Set another provider of type data than the connection.
Definition: TypeService.cpp:206
std::string m_type_provider_id
An optional type provider, to which requests for types are sent.
Definition: TypeService.h:87
void sendRequest(const std::string &id)
request the information about a type from the server.
Definition: TypeService.cpp:151
A service class querying and caching types.
Definition: TypeService.h:24
sigc::signal< void, TypeInfoPtr > BadType
emitted when a type is confirmed as being undefined
Definition: TypeService.h:48
TypeInfoPtr findTypeByName(const std::string &tynm)
Lookup the requested type, by name, and return NULL if it&#39;s unknown.
Definition: TypeService.cpp:54