TableHeaderMarshaller.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jan 19 14:11:20 CET 2004 TableHeaderMarshaller.hpp
3 
4  TableHeaderMarshaller.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_TABLEHEADER_SERIALIZER
39 #define PI_PROPERTIES_TABLEHEADER_SERIALIZER
40 
41 #include <rtt/Property.hpp>
44 
45 namespace RTT
46 {
54  template<typename o_stream>
56  : public marsh::MarshallInterface, public marsh::StreamProcessor<o_stream>
57  {
58  int level;
59  int line;
60  std::vector<std::string> header;
61  public:
62  typedef o_stream output_stream;
63  typedef o_stream OutputStream;
64 
65  TableHeaderMarshaller(output_stream &os) :
66  marsh::StreamProcessor<o_stream>(os), level(0), line(1)
67  {
68  // sits ready for storing next column aligning.
69  header.push_back(std::string(""));
70  }
71 
73 
74  virtual void serialize(base::PropertyBase* v)
75  {
76  Property<PropertyBag>* bag = dynamic_cast< Property<PropertyBag>* >( v );
77  if ( bag )
78  this->serialize( *bag );
79  else
80  store( v->getName() );
81  }
82 
83 
84  virtual void serialize(const PropertyBag &v)
85  {
86  // A Bag has no name
87  //
88 
89  //*s <<"| Data Set <"<<v.getType()<<"> containing :"<< std::endl <<"| ";
90  //++line;
91  /*
92  for (
93  PropertyBag::const_iterator i = v.getProperties().begin();
94  i != v.getProperties().end();
95  i++ )
96  {
97  // *s << (*i)->getName() <<" | ";
98  store( (*i)->getName() );
99  }
100  */
101  ++level;
102  //++line;
103  //*s << " |"<<std::endl;
104  for (
106  i != v.getProperties().end();
107  i++ )
108  {
109 
110  this->serialize(*i);
111  }
112  --level;
113  //*s << " |"<<std::endl;
114  }
115 
119  int store(const std::string& s)
120  {
121  if ( line == int(header.size()) )
122  {
123  // next line
124  header.push_back(std::string(""));
125  }
126  header[line-1] += std::string(" | ") + s;
127 
128  return header[line-1].length();
129  }
130 
131  virtual void serialize(const Property<PropertyBag> &v)
132  {
133  if ( line == int(header.size() ) )
134  header.push_back(std::string(""));
138  if ( int(header[line-1].length()) - int(header[line].length()) > 0 )
139  {
140  // add separator
141  header[line] += std::string(" | ");
142  // pad further if necessary.
143  if ( int(header[line-1].length()) - int(header[line].length()) > 0 )
144  header[line] += std::string( header[line-1].length() - header[line].length() ,' ');
145  }
146 
151  std::string name = v.getName();
152  if ( v.value().getType() != "type_less")
153  name+= std::string(" <") + v.value().getType() + std::string(">");
154  store( name ) ;
155 
159  line++;
160  if ( v.value().getProperties().empty() )
161  store( std::string("<empty>") );
162  else
163  serialize(v.value());
164  line--;
165 
169  if ( int(header[line].length()) - int(header[line -1].length()) > 0)
170  header[line-1] += std::string( header[line].length() - header[line-1].length(), ' ');
171  }
172 
173  virtual void flush()
174  {
175  for (std::vector<std::string>::iterator it = header.begin(); it != header.end(); ++it)
176  if ( !it->empty())
177  *this->s << *it <<std::string(" |")<<std::endl;
178  // TODO : buffer for formatting and flush here.
179  level = 0;
180  line = 1;
181  header.clear();
182  header.push_back(std::string(""));
183  }
184  };
185 }
186 #endif
virtual void serialize(base::PropertyBase *v)
virtual void serialize(const PropertyBag &v)
int store(const std::string &s)
Properties & getProperties()
Properties::const_iterator const_iterator
TableHeaderMarshaller(output_stream &os)
virtual void serialize(const Property< PropertyBag > &v)
const std::string & getName() const
std::vector< std::string > header


ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27