Orocos1Marshaller.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:20 CET 2004  Orocos1Marshaller.hpp
00003 
00004                         Orocos1Marshaller.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_OROCOS1_MARSHALLER
00039 #define PI_PROPERTIES_OROCOS1_MARSHALLER
00040 
00041 #include "../Property.hpp"
00042 #include "../PropertyIntrospection.hpp"
00043 
00044 #include <sstream>
00045 
00046 namespace RTT
00047 {
00048 
00053     template<typename output_stream>
00054     class Orocos1Marshaller
00055         : public Marshaller,
00056           protected PropertyIntrospection
00057     {
00058     protected:
00059         output_stream &_os;
00060 
00061         virtual void introspect(PropertyBase* pb)
00062         {
00063             PropertyIntrospection::introspect( pb );
00064         }
00065 
00066         virtual void introspect(Property<bool> &v)
00067         {
00068 
00069             _os << v.getName()
00070                 <<":1>"
00071                 << v.get() << ";";
00072         }
00073 
00074         virtual void introspect(Property<char> &v)
00075         {
00076             _os << v.getName()
00077                 <<":1>"
00078                 << v.get() << ";";
00079         }
00080 
00081         virtual void introspect(Property<int> &v)
00082         {
00083             std::stringstream buffer;
00084             std::string s;
00085             buffer << v.get();
00086             buffer >> s;
00087             _os << v.getName()
00088                 <<":"<<s.size() << ">"
00089                 << s << ";";
00090         }
00091 
00092         virtual void introspect(Property<unsigned int> &v)
00093         {
00094             std::stringstream buffer;
00095             std::string s;
00096             buffer << v.get();
00097             buffer >> s;
00098             _os << v.getName()
00099                 <<":"<<s.size() << ">"
00100                 << s << ";";
00101         }
00102 
00103         virtual void introspect(Property<double> &v)
00104         {
00105             std::stringstream buffer;
00106             std::string s;
00107             buffer << v.get();
00108             buffer >> s;
00109             _os << v.getName()
00110                 <<":" << s.size() << ">"
00111                 << s << ";";
00112         }
00113         virtual void introspect(Property<std::string> &v)
00114         {
00115             _os << v.getName()
00116                 <<":"<<v.get().size() << ">"
00117                 << v.get() << ";";
00118         }
00119 
00120         virtual void introspect(Property<PropertyBag> &v)
00121         {
00122             //   cout << "double: " << v;
00123             _os << v.getName();
00124             serialize(v.get());
00125         }
00126 
00127     public:
00128         Orocos1Marshaller(output_stream &os) :
00129             _os(os)
00130         {}
00131 
00132         virtual void flush() { _os.flush(); }
00133 
00134         virtual void serialize(const PropertyBag &v)
00135         {
00136             _os <<"{";
00137 
00138             v.identify(this);
00139 
00140             _os <<"}";
00141         }
00142 
00143         virtual void serialize(PropertyBase* b)
00144         {
00145             b->identify(this);
00146         }
00147     };
00148 }
00149 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3