XMLRPCMarshaller.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef PI_PROPERTIES_XMLRPCSERIALIZER
00039 #define PI_PROPERTIES_XMLRPCSERIALIZER
00040
00041 #include <iostream>
00042 #include <vector>
00043 #include <map>
00044 #include <string>
00045 #include "../Property.hpp"
00046 #include "../PropertyIntrospection.hpp"
00047 #include "../Marshaller.hpp"
00048 #include "StreamProcessor.hpp"
00049
00050
00051 namespace RTT
00052 {
00053 using namespace std;
00054
00059 template<typename output_stream>
00060 class XMLRPCMarshaller
00061 : public Marshaller, public PropertyIntrospection,
00062 public StreamProcessor<output_stream>
00063 {
00064 public:
00065 XMLRPCMarshaller(output_stream &os) :
00066 StreamProcessor<output_stream>(os)
00067 {}
00068
00069 virtual void serialize(const Property<bool> &v)
00070 {
00071 *(this->s) << "<name>" << v.getName() << "</name>"
00072 << "<value><boolean>" << v.get() << "</boolean></value>\n";
00073 }
00074
00075 virtual void serialize(const Property<char> &v)
00076 {
00077 *(this->s) << "<name>" << v.getName() << "</name>"
00078 << "<value><string>" << v.get() << "</string></value>\n";
00079 }
00080
00081 virtual void serialize(const Property<int> &v)
00082 {
00083 *(this->s) << "<name>" << v.getName() << "</name>"
00084 << "<value><int>" << v.get() << "</int></value>\n";
00085 }
00086
00087 virtual void serialize(const Property<double> &v)
00088 {
00089 *(this->s) << "<name>" << v.getName() << "</name>"
00090 << "<value><double>" << v.get() << "</double></value>\n";
00091 }
00092
00093 virtual void serialize(const Property<std::string> &v)
00094 {
00095 *(this->s) << "<name>" << v.getName() << "</name>"
00096 << "<value><string>" << v.get() << "</string></value>\n";
00097 }
00098
00099 virtual void serialize(const PropertyBag &v)
00100 {
00101 *(this->s) << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
00102 *(this->s) << "<xmlrpc>\n";
00103
00104 for (
00105 std::vector<PropertyBase*>::const_iterator i = v.getProperties().begin();
00106 i != v.getProperties().end();
00107 i++ )
00108 {
00109 (*i)->identify(this);
00110 }
00111 *(this->s) << "\n</xmlrpc>\n";
00112 }
00113 virtual void serialize(const Property<PropertyBag> &b)
00114 {
00115
00116 *(this->s) <<"<struct><name>"<<b.getName()<<"</name>\n";
00117 PropertyBag v = b.get();
00118 for (
00119 std::vector<PropertyBase*>::const_iterator i = v.getProperties().begin();
00120 i != v.getProperties().end();
00121 i++ )
00122 {
00123 *(this->s) <<"<member>\n";
00124 (*i)->identify(this);
00125 *(this->s) <<"</member>";
00126 }
00127 *(this->s) <<"</struct>\n";
00128
00129 }
00130
00131 virtual void introspect(const Property<bool> &v)
00132 {
00133 serialize(v);
00134 }
00135
00136 virtual void introspect(const Property<char> &v)
00137 {
00138 serialize(v);
00139 }
00140
00141 virtual void introspect(const Property<int> &v)
00142 {
00143 serialize(v);
00144 }
00145
00146 virtual void introspect(const Property<double> &v)
00147 {
00148 serialize(v);
00149 }
00150
00151 virtual void introspect(const Property<std::string> &v)
00152 {
00153 serialize(v);
00154 }
00155
00156 virtual void introspect(const Property<PropertyBag> &v)
00157 {
00158 serialize(v);
00159 }
00160 virtual void flush()
00161 {}
00162 };
00163 }
00164 #endif