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 #include <platform/Typename.h>
53 #include <serialization/adapters/std/vector>
54 
55 namespace mira {
56 
58 
65 {
66  typedef std::string ReturnType;
67  typedef std::vector<std::string> ParameterTypes;
68 
70  RPCSignature(const std::string& iName) : name(iName) {}
71  RPCSignature(std::string&& iName) : name(std::move(iName)) {}
72 
73  bool operator<(const RPCSignature& rhs) const
74  {
75  int cmp = name.compare(rhs.name);
76  if(cmp<0)
77  return true;
78  else if(cmp>0)
79  return false;
80 
81  cmp = returnType.compare(rhs.returnType);
82  if(cmp<0)
83  return true;
84  else if(cmp>0)
85  return false;
86  // else return types are equal, so check parameters
87 
88  if(parameterTypes.size() < rhs.parameterTypes.size())
89  return true;
90  else if(parameterTypes.size() > rhs.parameterTypes.size())
91  return false;
92  // else number of params is equal, so check the params
93  // in lexicographical order
94  return parameterTypes < rhs.parameterTypes;
95  }
96 
97  bool operator==(const RPCSignature& rhs) const
98  {
99  return name == rhs.name &&
100  returnType == rhs.returnType &&
102  }
103 
104  friend std::ostream& operator<<(std::ostream& s, const RPCSignature& v)
105  {
106  s << v.returnType << " " <<
107  v.name << "(";
108  for(RPCSignature::ParameterTypes::const_iterator i=v.parameterTypes.begin();
109  i!=v.parameterTypes.end(); ++i)
110  {
111  if(i!=v.parameterTypes.begin())
112  s << ",";
113  s << *i;
114  }
115  s << ")";
116  return s;
117  }
118 
119 public:
120 
121  template <typename Reflector>
122  void reflect(Reflector& r)
123  {
124  r.member("Name", name, "Method name");
125  r.member("ReturnType", returnType, "Type of return value");
126  r.member("ParameterTypes", parameterTypes, "Vector with types of parameters");
127  }
128 
130  std::string name;
131 
134 
137 };
138 
139 
140 template <typename R, typename... ARGS>
141 RPCSignature makeRPCSignature(std::string name) {
142  RPCSignature r(std::move(name));
143  r.returnType = typeName<R>();
144  // the signature of an rpc consists of stripped/unqualified types
146  return r;
147 }
148 
150 
151 } // namespace
152 
153 #endif /* _MIRA_RPCSIGNATURE_H_ */
RPCSignature()
Definition: RPCSignature.h:69
ReturnType returnType
The return type of the method.
Definition: RPCSignature.h:133
bool operator==(const RPCSignature &rhs) const
Definition: RPCSignature.h:97
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
RPCSignature(const std::string &iName)
Definition: RPCSignature.h:70
STL namespace.
RPCSignature makeRPCSignature(std::string name)
Definition: RPCSignature.h:141
Get compiler and platform independent typenames.
bool operator<(const RPCSignature &rhs) const
Definition: RPCSignature.h:73
std::string ReturnType
Definition: RPCSignature.h:66
void reflect(Reflector &r)
Definition: RPCSignature.h:122
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:130
friend std::ostream & operator<<(std::ostream &s, const RPCSignature &v)
Definition: RPCSignature.h:104
std::vector< std::string > ParameterTypes
Definition: RPCSignature.h:67
Stores the signature of an RPC method including the methods name and its parameter types...
Definition: RPCSignature.h:64
RPCSignature(std::string &&iName)
Definition: RPCSignature.h:71
ParameterTypes parameterTypes
Vector of the type of each parameter.
Definition: RPCSignature.h:136