XMLRPCMarshaller.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 19 14:11:20 CET 2004 XMLRPCMarshallInterface.hpp
3 
4  XMLRPCMarshallInterface.hpp - description
5  -------------------
6  begin : Mon January 19 2004
7  copyright : (C) 2004 Peter Soetens
8  email : peter.soetens@mech.kuleuven.ac.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 #ifndef PI_PROPERTIES_XMLRPCSERIALIZER
39 #define PI_PROPERTIES_XMLRPCSERIALIZER
40 
41 #include <iostream>
42 #include <vector>
43 #include <map>
44 #include <string>
45 #include "../Property.hpp"
46 #include "../base/PropertyIntrospection.hpp"
47 #include "MarshallInterface.hpp"
48 #include "StreamProcessor.hpp"
49 
50 
51 namespace RTT
52 { namespace marsh {
53 
54  using namespace std;
55 
60  template<typename output_stream>
61  class XMLRPCMarshaller
62  : public MarshallInterface, public base::PropertyIntrospection,
63  public StreamProcessor<output_stream>
64  {
65  public:
66  XMLRPCMarshaller(output_stream &os) :
67  StreamProcessor<output_stream>(os)
68  {}
69 
70  virtual void serialize(const Property<bool> &v)
71  {
72  *(this->s) << "<name>" << v.getName() << "</name>"
73  << "<value><boolean>" << v.get() << "</boolean></value>\n";
74  }
75 
76  virtual void serialize(const Property<char> &v)
77  {
78  *(this->s) << "<name>" << v.getName() << "</name>"
79  << "<value><string>" << v.get() << "</string></value>\n";
80  }
81 
82  virtual void serialize(const Property<int> &v)
83  {
84  *(this->s) << "<name>" << v.getName() << "</name>"
85  << "<value><int>" << v.get() << "</int></value>\n";
86  }
87 
88  virtual void serialize(const Property<double> &v)
89  {
90  *(this->s) << "<name>" << v.getName() << "</name>"
91  << "<value><double>" << v.get() << "</double></value>\n";
92  }
93 
94  virtual void serialize(const Property<std::string> &v)
95  {
96  *(this->s) << "<name>" << v.getName() << "</name>"
97  << "<value><string>" << v.get() << "</string></value>\n";
98  }
99 
100  virtual void serialize(const PropertyBag &v)
101  {
102  *(this->s) << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
103  *(this->s) << "<xmlrpc>\n";
104 
105  for (
106  std::vector<base::PropertyBase*>::const_iterator i = v.getProperties().begin();
107  i != v.getProperties().end();
108  i++ )
109  {
110  (*i)->identify(this);
111  }
112  *(this->s) << "\n</xmlrpc>\n";
113  }
114  virtual void serialize(const Property<PropertyBag> &b)
115  {
116  // cout << "double: " << v;
117  *(this->s) <<"<struct><name>"<<b.getName()<<"</name>\n";
118  PropertyBag v = b.get();
119  for (
120  std::vector<base::PropertyBase*>::const_iterator i = v.getProperties().begin();
121  i != v.getProperties().end();
122  i++ )
123  {
124  *(this->s) <<"<member>\n";
125  (*i)->identify(this);
126  *(this->s) <<"</member>";
127  }
128  *(this->s) <<"</struct>\n";
129 
130  }
131 
132  virtual void introspect(const Property<bool> &v)
133  {
134  serialize(v);
135  }
136 
137  virtual void introspect(const Property<char> &v)
138  {
139  serialize(v);
140  }
141 
142  virtual void introspect(const Property<int> &v)
143  {
144  serialize(v);
145  }
146 
147  virtual void introspect(const Property<double> &v)
148  {
149  serialize(v);
150  }
151 
152  virtual void introspect(const Property<std::string> &v)
153  {
154  serialize(v);
155  }
156 
157  virtual void introspect(const Property<PropertyBag> &v)
158  {
159  serialize(v);
160  }
161  virtual void flush()
162  {}
163  };
164 }}
165 #endif
DataSourceType get() const
Definition: Property.hpp:246
virtual void serialize(const Property< double > &v)
Definition: mystd.hpp:163
virtual void introspect(const Property< bool > &v)
A container for holding references to properties.
Definition: PropertyBag.hpp:96
virtual void serialize(const Property< int > &v)
XMLRPCMarshaller(output_stream &os)
virtual void introspect(const Property< char > &v)
virtual void introspect(const Property< std::string > &v)
Properties & getProperties()
An interface for setting and getting a stream object. This can be a file, a string buffer...
virtual void serialize(const Property< bool > &v)
virtual void serialize(const Property< PropertyBag > &b)
virtual void serialize(const Property< char > &v)
virtual void serialize(const Property< std::string > &v)
const std::string & getName() const
void serialize(Archive &a, RTT::ConnPolicy &c, unsigned int)
virtual void introspect(const Property< double > &v)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
virtual void introspect(const Property< PropertyBag > &v)
virtual void introspect(const Property< int > &v)
virtual void serialize(const PropertyBag &v)


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:38