XMLRPCMarshaller.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:20 CET 2004  XMLRPCMarshaller.hpp
00003 
00004                         XMLRPCMarshaller.hpp -  description
00005                            -------------------
00006     begin                : Mon January 19 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009 
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
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                 //   cout << "double: " << v;
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
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3