MIRA
RPCSignature.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_RPCSIGNATURE_H_
48 #define _MIRA_RPCSIGNATURE_H_
49 
50 #include <string>
51 
52 #ifndef Q_MOC_RUN
53 #include <boost/preprocessor/repetition.hpp>
54 #endif
55 
56 #include <platform/Typename.h>
57 #include <serialization/adapters/std/vector>
58 
59 namespace mira {
60 
62 
69 {
70  typedef std::string ReturnType;
71  typedef std::vector<std::string> ParameterTypes;
72 
74  RPCSignature(const std::string& iName) : name(iName) {}
75  RPCSignature(std::string&& iName) : name(std::move(iName)) {}
76 
77  bool operator<(const RPCSignature& rhs) const
78  {
79  int cmp = name.compare(rhs.name);
80  if(cmp<0)
81  return true;
82  else if(cmp>0)
83  return false;
84 
85  cmp = returnType.compare(rhs.returnType);
86  if(cmp<0)
87  return true;
88  else if(cmp>0)
89  return false;
90  // else return types are equal, so check parameters
91 
92  if(parameterTypes.size() < rhs.parameterTypes.size())
93  return true;
94  else if(parameterTypes.size() > rhs.parameterTypes.size())
95  return false;
96  // else number of params is equal, so check the params
97  // in lexicographical order
98  return parameterTypes < rhs.parameterTypes;
99  }
100 
101  bool operator==(const RPCSignature& rhs) const
102  {
103  return name == rhs.name &&
104  returnType == rhs.returnType &&
106  }
107 
108  friend std::ostream& operator<<(std::ostream& s, const RPCSignature& v)
109  {
110  s << v.returnType << " " <<
111  v.name << "(";
112  for(RPCSignature::ParameterTypes::const_iterator i=v.parameterTypes.begin();
113  i!=v.parameterTypes.end(); ++i)
114  {
115  if(i!=v.parameterTypes.begin())
116  s << ",";
117  s << *i;
118  }
119  s << ")";
120  return s;
121  }
122 
123 public:
124 
125  template <typename Reflector>
126  void reflect(Reflector& r)
127  {
128  r.member("Name", name, "Method name");
129  r.member("ReturnType", returnType, "Type of return value");
130  r.member("ParameterTypes", parameterTypes, "Vector with types of parameters");
131  }
132 
134  std::string name;
135 
138 
141 };
142 
143 
144 template <typename R, typename... ARGS>
145 RPCSignature makeRPCSignature(std::string name) {
146  RPCSignature r(std::move(name));
147  r.returnType = typeName<R>();
148  // the signature of an rpc consists of stripped/unqualified types
150  return r;
151 }
152 
154 
155 } // namespace
156 
157 #endif /* _MIRA_RPCSIGNATURE_H_ */
RPCSignature()
Definition: RPCSignature.h:73
ReturnType returnType
The return type of the method.
Definition: RPCSignature.h:137
bool operator==(const RPCSignature &rhs) const
Definition: RPCSignature.h:101
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
RPCSignature(const std::string &iName)
Definition: RPCSignature.h:74
STL namespace.
RPCSignature makeRPCSignature(std::string name)
Definition: RPCSignature.h:145
Get compiler and platform independent typenames.
bool operator<(const RPCSignature &rhs) const
Definition: RPCSignature.h:77
std::string ReturnType
Definition: RPCSignature.h:70
void reflect(Reflector &r)
Definition: RPCSignature.h:126
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
std::string name
The method&#39;s name.
Definition: RPCSignature.h:134
friend std::ostream & operator<<(std::ostream &s, const RPCSignature &v)
Definition: RPCSignature.h:108
std::vector< std::string > ParameterTypes
Definition: RPCSignature.h:71
Stores the signature of an RPC method including the methods name and its parameter types...
Definition: RPCSignature.h:68
RPCSignature(std::string &&iName)
Definition: RPCSignature.h:75
ParameterTypes parameterTypes
Vector of the type of each parameter.
Definition: RPCSignature.h:140