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