- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

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 <boost/optional.hpp>
11 #include <boost/type_index.hpp>
12 #include <string>
13 #include <qi/api.hpp>
14 #include <qi/signature.hpp>
15 #include <qi/type/fwd.hpp>
16
17 /* A lot of class are found in this headers... to kill circular dependencies.
18 Futhermore we need that all "default template" types are registered (included)
19 when type.hpp is used. (for typeOf to works reliably)
20 */
21
22
23 #ifdef _MSC_VER
24 # pragma warning( push )
25 # pragma warning( disable: 4251 )
26 #endif
27
28 namespace qi {
29
30 using TypeIndex = boost::typeindex::type_index;
31
32 template<typename T>
33 TypeIndex typeId() {
34 return boost::typeindex::type_id<T>();
35 }
36
37 template<typename T>
38 TypeIndex typeIdRuntime(const T& val) {
39 return boost::typeindex::type_id_runtime(val);
40 }
41
45 class QI_API TypeInfo
46 {
47 public:
48 TypeInfo();
50 TypeInfo(const TypeIndex& index);
52 TypeInfo(const std::string& ti);
53
54 std::string asString() const;
55 std::string asDemangledString() const;
56
57 //TODO: DIE
58 const char* asCString() const;
59
60 bool operator==(const TypeInfo& b) const;
61 bool operator!=(const TypeInfo& b) const;
62 bool operator<(const TypeInfo& b) const;
63
64 private:
65 boost::optional<TypeIndex> typeIndex;
66 // C4251
67 std::string customInfo;
68 };
69
129 class QI_API TypeInterface
130 {
131 public:
132 virtual ~TypeInterface() = default;
133
135 virtual const TypeInfo& info() = 0;
136
143 virtual void* initializeStorage(void* ptr = nullptr) = 0;
144
154 // Use a pointer and not a reference to avoid the case where the compiler makes a copy on the stack
155 virtual void* ptrFromStorage(void**) = 0;
156
158 virtual void* clone(void*) = 0;
160 virtual void destroy(void*) = 0;
161
168 virtual TypeKind kind();
169
175 virtual bool less(void* a, void* b) = 0;
176
177 //TODO: DIE
178 inline const char* infoString() { return info().asCString(); } // for easy gdb access
179
189 qi::Signature signature(void* storage = nullptr, bool resolveDynamic = false);
190
192 static TypeInterface* fromSignature(const qi::Signature& sig);
193 };
194
196 QI_API TypeInterface* getType(const TypeIndex& typeId);
197
199 QI_API bool registerType(const TypeIndex& typeId, TypeInterface* type);
200
203 template<typename T> TypeInterface* typeOf();
204
206 template<typename T> TypeInterface* typeOf(const T&)
207 {
208 return typeOf<T>();
209 }
210
213 QI_API void registerStruct(TypeInterface* type);
215 QI_API TypeInterface* getRegisteredStruct(const qi::Signature& s);
216 }
217
218
219 #ifdef _MSC_VER
220 # pragma warning( pop )
221 #endif
222
223 #endif // _QITYPE_DETAIL_TYPEINTERFACE_HPP_
qi::typeId
TypeIndex typeId()
Definition: typeinterface.hpp:33
qi::log::destroy
void destroy()
Stop and flush the logging system.
QI_API
#define QI_API
Definition: api.hpp:33
qi::registerType
bool registerType(const TypeIndex &typeId, TypeInterface *type)
Runtime Type factory setter.
qi::getType
TypeInterface * getType(const TypeIndex &typeId)
Runtime Type factory getter. Used by typeOf<T>()
qi::Signature
Definition: signature.hpp:66
fwd.hpp
api.hpp
dll import/export and compiler message
qi::TypeInfo
Definition: typeinterface.hpp:45
qi::typeIdRuntime
TypeIndex typeIdRuntime(const T &val)
Definition: typeinterface.hpp:38
qi::TypeInterface
Definition: typeinterface.hpp:129
signature.hpp
qi::operator==
bool operator==(const Signature &lhs, const Signature &rhs)
qi::getRegisteredStruct
TypeInterface * getRegisteredStruct(const qi::Signature &s)
qi::TypeInterface::infoString
const char * infoString()
Definition: typeinterface.hpp:178
qi::registerStruct
void registerStruct(TypeInterface *type)
qi::typeOf
TypeInterface * typeOf()
Definition: type.hxx:94
qi::TypeKind
TypeKind
Definition: fwd.hpp:54
qi::TypeIndex
boost::typeindex::type_index TypeIndex
Definition: typeinterface.hpp:30
qi::operator<
bool operator<(const AnyReference &a, const AnyReference &b)
qi::operator!=
bool operator!=(const Signature &lhs, const Signature &rhs)
Definition: signature.hpp:157