- 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
signature.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 _QI_SIGNATURE_HPP_
8 #define _QI_SIGNATURE_HPP_
9
10 #include <qi/api.hpp>
11 #include <string>
12 #include <vector>
13 #include <list>
14 #include <map>
15 #include <sstream>
16 #include <boost/shared_ptr.hpp>
17
18 #ifdef _MSC_VER
19 # pragma warning( push )
20 # pragma warning( disable: 4251 )
21 #endif
22
23 namespace qi {
24
25 QI_API std::vector<std::string> signatureSplit(const std::string &fullSignature);
26
27 class SignaturePrivate;
28
29 class AnyReference;
30 class AnyValue;
31 class TypeInterface;
32 class Signature;
33 QI_API qi::Signature makeTupleSignature(const std::vector<qi::AnyReference>& vgv,
34 bool resolveDynamic = false,
35 const std::string &name = std::string(),
36 const std::vector<std::string>& names = std::vector<std::string>());
37 QI_API qi::Signature makeTupleSignature(const std::vector<TypeInterface*>& vgv,
38 const std::string &name = std::string(),
39 const std::vector<std::string>& names = std::vector<std::string>());
40
41 QI_API qi::Signature makeTupleSignature(const qi::Signature &element);
42 QI_API qi::Signature makeListSignature(const qi::Signature &element);
43 QI_API qi::Signature makeVarArgsSignature(const qi::Signature &element);
44 QI_API qi::Signature makeKwArgsSignature(const qi::Signature &element);
45 QI_API qi::Signature makeMapSignature(const qi::Signature &key, const qi::Signature &value);
46 QI_API qi::Signature makeOptionalSignature(const qi::Signature& value);
47
48 /* Represent the serialisation signature of a Type.
49 * pseudo-grammar:
50 * root: element
51 * element: signature annotation.opt
52 * sinature:
53 * | primitive // in bcCwWiIlLfdsmro, see Type
54 * | [element]
55 * | {elementelement}
56 * | (elementsequence)
57 * elementsequence: a list of 1 or more elements
58 * annotation.opt: empty or <annotation>
59 * annotation: may contain arbitrary content except \0
60 and must balance all (), {}, [] and <> within
61 * for tuple annotation has the following form: "<TupleName,elementName0,...,elementName1>"
62 */
63 class Signature;
64 using SignatureVector = std::vector<Signature>;
65
66 class QI_API Signature {
67 protected:
68 Signature(const std::string &signature, size_t begin, size_t end);
69 friend class SignaturePrivate;
70
71 public:
72 Signature();
73 Signature(const char *signature);
74 Signature(const std::string &signature);
75
76 bool isValid() const;
77
78 bool hasChildren() const;
79
80 const SignatureVector& children() const;
81
82 //TODO use the type than "network type"
83 enum Type {
84 // Used only for empty containers when Dynamic resolution is used.
85 Type_None = '_',
86 Type_Bool = 'b',
87
88 Type_Int8 = 'c',
89 Type_UInt8 = 'C',
90
91 Type_Void = 'v',
92
93 Type_Int16 = 'w',
94 Type_UInt16 = 'W',
95
96 Type_Int32 = 'i',
97 Type_UInt32 = 'I',
98
99 Type_Int64 = 'l',
100 Type_UInt64 = 'L',
101
102 Type_Float = 'f',
103 Type_Double = 'd',
104
105 Type_String = 's',
106 Type_List = '[',
107 Type_List_End = ']',
108
109 Type_Map = '{',
110 Type_Map_End = '}',
111
112 Type_Tuple = '(',
113 Type_Tuple_End= ')',
114
115 Type_Dynamic = 'm',
116
117 Type_Raw = 'r',
118
119 //This type should not be used, it's will be removed when we get ride of legacy void *.
120 Type_Pointer = '*',
121
122 Type_Object = 'o',
123 Type_VarArgs = '#',
124 Type_KwArgs = '~',
125
126 Type_Optional = '+',
127
128 Type_Unknown = 'X',
129 };
130
131 Type type() const;
132 std::string annotation() const;
133
138 AnyValue toData() const;
139 std::string toPrettySignature() const;
140 const std::string& toString() const;
141
146 float isConvertibleTo(const Signature& b) const;
147
148 static Signature fromType(Type t);
149 protected:
150 // C4251
151 boost::shared_ptr<SignaturePrivate> _p;
152
153 friend QI_API bool operator==(const Signature &lhs, const Signature &rhs);
154 };
155
156
157 QI_API inline bool operator!=(const Signature &lhs, const Signature &rhs)
158 { return !(lhs == rhs); }
159 QI_API bool operator==(const Signature &lhs, const Signature &rhs);
160
161 }
162
163 extern "C" QI_API char* signature_to_json(const char* sig);
164
165 #ifdef _MSC_VER
166 # pragma warning( pop )
167 #endif
168
169 #endif // _QITYPE_SIGNATURE_HPP_
qi::makeOptionalSignature
qi::Signature makeOptionalSignature(const qi::Signature &value)
qi::AnyValue
Definition: anyvalue.hpp:19
QI_API
#define QI_API
Definition: api.hpp:33
qi::Signature::Type
Type
Definition: signature.hpp:83
qi::Signature
Definition: signature.hpp:66
api.hpp
dll import/export and compiler message
signature_to_json
char * signature_to_json(const char *sig)
qi::operator==
bool operator==(const Signature &lhs, const Signature &rhs)
qi::makeListSignature
qi::Signature makeListSignature(const qi::Signature &element)
qi::signatureSplit
std::vector< std::string > signatureSplit(const std::string &fullSignature)
qi::Signature::_p
boost::shared_ptr< SignaturePrivate > _p
Definition: signature.hpp:151
qi::makeTupleSignature
qi::Signature makeTupleSignature(const std::vector< qi::AnyReference > &vgv, bool resolveDynamic=false, const std::string &name=std::string(), const std::vector< std::string > &names=std::vector< std::string >())
qi::log::env::QI_DEFAULT_LOGHANDLER::name
char const *const name
qi::makeMapSignature
qi::Signature makeMapSignature(const qi::Signature &key, const qi::Signature &value)
qi::operator!=
bool operator!=(const Signature &lhs, const Signature &rhs)
Definition: signature.hpp:157
qi::SignatureVector
std::vector< Signature > SignatureVector
Definition: signature.hpp:64
qi::makeKwArgsSignature
qi::Signature makeKwArgsSignature(const qi::Signature &element)
qi::makeVarArgsSignature
qi::Signature makeVarArgsSignature(const qi::Signature &element)