RSB  0.7.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Converter.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of the RSB project
4  *
5  * Copyright (C) 2010 by Sebastian Wrede <swrede at techfak dot uni-bielefeld dot de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
27 #pragma once
28 
29 #include <set>
30 #include <string>
31 #include <utility>
32 
33 #include <boost/shared_ptr.hpp>
34 
35 #include <rsc/runtime/Printable.h>
36 #include <rsc/runtime/TypeStringTools.h>
37 
38 #include "../Event.h"
39 
40 #include "rsb/rsbexports.h"
41 
42 namespace rsb {
43 namespace converter {
44 
45 #define RSB_TYPE_TAG(T) (reinterpret_cast<T*> (0))
46 
52 template<class WireType>
53 class Converter: public rsc::runtime::Printable {
54 public:
55 
56  virtual ~Converter() {
57  }
58 
67  virtual std::string
68  serialize(const AnnotatedData& data, WireType& wire) = 0;
69 
78  virtual AnnotatedData deserialize(const std::string& wireSchema,
79  const WireType& wire) = 0;
80 
86  virtual std::string getDataType() const {
87  return dataType;
88  }
89 
97  virtual std::string getWireSchema() const {
98  return wireSchema;
99  }
100 
101  typedef boost::shared_ptr<Converter<WireType> > Ptr;
102 
103 protected:
104 
113  Converter(const std::string& dataType, const std::string& wireSchema, bool dummy = true) :
114  dataType(dataType), wireSchema(wireSchema) {
115  ((void) dummy);
116  }
117 
128  template<typename DataType>
129  Converter(const std::string& wireSchema, const DataType* /*unused*/= 0) :
130  dataType(rsc::runtime::typeName<DataType>()), wireSchema(wireSchema) {
131  }
132 
133 private:
134 
135  std::string dataType;
136  std::string wireSchema;
137 
138  std::string getClassName() const {
139  return rsc::runtime::typeName(*this);
140  }
141 
142  void printContents(std::ostream& stream) const {
143  stream << "wireType = " << rsc::runtime::typeName<WireType>()
144  << ", wireSchema = " << this->wireSchema
145  << ", dataType = " << this->dataType;
146  }
147 };
148 
149 #if defined(_WIN32)
150 RSB_EXPIMP template class RSB_EXPORT Converter<std::string>;
151 #endif
152 
153 }
154 }