libqi-api  release-2.5.3-2016-11-18
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
typeinterface.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2013 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QITYPE_DETAIL_TYPEINTERFACE_HPP_
8 #define _QITYPE_DETAIL_TYPEINTERFACE_HPP_
9 
10 #include <typeinfo>
11 #include <string>
12 #include <qi/api.hpp>
13 #include <qi/signature.hpp>
14 
15 /* A lot of class are found in this headers... to kill circular dependencies.
16  Futhermore we need that all "default template" types are registered (included)
17  when type.hpp is used. (for typeOf to works reliably)
18 */
19 
20 
21 #ifdef _MSC_VER
22 # pragma warning( push )
23 # pragma warning( disable: 4251 )
24 #endif
25 
26 namespace qi {
27 
28 
33  {
34  public:
35  TypeInfo();
37  TypeInfo(const std::type_info& info);
39  TypeInfo(const std::string& ti);
40 
41  std::string asString() const;
42  std::string asDemangledString() const;
43 
44  //TODO: DIE
45  const char* asCString() const;
46 
47  bool operator==(const TypeInfo& b) const;
48  bool operator!=(const TypeInfo& b) const;
49  bool operator<(const TypeInfo& b) const;
50 
51  private:
52  const std::type_info* stdInfo;
53  // C4251
54  std::string customInfo;
55  };
56 
117  {
118  public:
120  virtual const TypeInfo& info() =0;
121 
128  virtual void* initializeStorage(void* ptr=0)=0;
129 
139  // Use a pointer and not a reference to avoid the case where the compiler makes a copy on the stack
140  virtual void* ptrFromStorage(void**)=0;
141 
143  virtual void* clone(void*)=0;
145  virtual void destroy(void*)=0;
146 
153  virtual TypeKind kind();
154 
160  virtual bool less(void* a, void* b) = 0;
161 
162  //TODO: DIE
163  inline const char* infoString() { return info().asCString(); } // for easy gdb access
164 
174  qi::Signature signature(void* storage=0, bool resolveDynamic = false);
175 
177  static TypeInterface* fromSignature(const qi::Signature& sig);
178  };
179 
181  QI_API TypeInterface* getType(const std::type_info& type);
182 
184  QI_API bool registerType(const std::type_info& typeId, TypeInterface* type);
185 
188  template<typename T> TypeInterface* typeOf();
189 
191  template<typename T> TypeInterface* typeOf(const T& v)
192  {
193  return typeOf<T>();
194  }
195 
198  QI_API void registerStruct(TypeInterface* type);
200  QI_API TypeInterface* getRegisteredStruct(const qi::Signature& s);
201 }
202 
203 
204 #ifdef _MSC_VER
205 # pragma warning( pop )
206 #endif
207 
208 #endif // _QITYPE_DETAIL_TYPEINTERFACE_HPP_
void destroy()
Stop and flush the logging system.
#define QI_API
Definition: api.hpp:33
dll import/export and compiler message
bool registerType(const std::type_info &typeId, TypeInterface *type)
Runtime Type factory setter.
TypeInterface * getType(const std::type_info &type)
Runtime Type factory getter. Used by typeOf<T>()
bool operator==(const Signature &lhs, const Signature &rhs)
TypeInterface * getRegisteredStruct(const qi::Signature &s)
const char * infoString()
void registerStruct(TypeInterface *type)
TypeInterface * typeOf()
Definition: type.hxx:94
TypeKind
Definition: fwd.hpp:53
bool operator<(const AnyReference &a, const AnyReference &b)
bool operator!=(const Signature &lhs, const Signature &rhs)
Definition: signature.hpp:154