40 #include "../rtt-config.h" 45 using namespace detail;
47 void CPFMarshaller<std::ostream>::doWrite(
const Property<T> &v,
const std::string& type )
49 *(this->s) <<indent <<
"<simple ";
50 if ( !v.getName().empty() )
51 *(this->s) <<
"name=\"" << this->escape( v.getName() ) <<
"\" ";
52 *(this->s) <<
"type=\""<< type <<
"\">";
53 if ( !v.getDescription().empty() )
54 *(this->s) <<
"<description>"<< this->escape( v.getDescription() ) <<
"</description>";
55 *(this->s) <<
"<value>" << v.
get() <<
"</value></simple>\n";
58 void CPFMarshaller<std::ostream>::doWrite(
const Property<std::string> &v,
const std::string& type )
60 *(this->s) <<indent <<
"<simple ";
61 if ( !v.getName().empty() )
62 *(this->s) <<
"name=\"" << this->escape( v.getName() ) <<
"\" ";
63 *(this->s) <<
"type=\""<< type <<
"\">";
64 if ( !v.getDescription().empty() )
65 *(this->s) <<
"<description>"<< this->escape( v.getDescription() ) <<
"</description>";
66 *(this->s) <<
"<value>" << this->escape( v.get() ) <<
"</value></simple>\n";
70 void CPFMarshaller<std::ostream>::doWrite(
const Property<char> &v,
const std::string& type )
72 *(this->s) <<indent <<
"<simple ";
73 if ( !v.getName().empty() )
74 *(this->s) <<
"name=\"" << this->escape( v.getName() ) <<
"\" ";
75 *(this->s) <<
"type=\""<< type <<
"\">";
76 if ( !v.getDescription().empty() )
77 *(this->s) <<
"<description>"<< this->escape( v.getDescription() ) <<
"</description>";
78 if ( v.get() ==
'\0' )
79 *(this->s)<<
"<value></value></simple>\n";
81 std::string toescape(1, v.get());
82 *(this->s) <<
"<value>" << this->escape( toescape ) <<
"</value></simple>\n";
87 std::string CPFMarshaller<std::ostream>::escape(std::string s)
89 std::string::size_type n=0;
91 while ((n = s.find(
"&",n)) != s.npos) {
92 s.replace(n, 1, std::string(
"&"));
97 while ((n = s.find(
"<",n)) != s.npos) {
98 s.replace(n, 1, std::string(
"<"));
103 while ((n = s.find(
">",n)) != s.npos) {
104 s.replace(n, 1, std::string(
">"));
113 void CPFMarshaller<std::ostream>::introspect(PropertyBase* pb)
115 if (
dynamic_cast<Property<unsigned char>*
>(pb) )
116 return introspect( *
static_cast<Property<unsigned char>*
>(pb) );
117 if (
dynamic_cast<Property<float>*
>(pb) )
118 return introspect( *
static_cast<Property<float>*
>(pb) );
127 log(
Error) <<
"Couldn't write "<< pb->getName() <<
" to XML file because the " << pb->getType() <<
" type is not supported by the CPF format." <<endlog();
128 log(
Error) <<
"If your type is a C++ struct or sequence, you can register it with a type info object." <<endlog();
129 log(
Error) <<
"We only support these primitive types: boolean|char|double|float|long|octet|string|ulong." <<endlog();
133 void CPFMarshaller<std::ostream>::introspect(Property<bool> &v)
135 doWrite( v,
"boolean");
139 void CPFMarshaller<std::ostream>::introspect(Property<char> &v)
144 void CPFMarshaller<std::ostream>::introspect(Property<unsigned char> &v)
146 doWrite( v,
"octet");
150 void CPFMarshaller<std::ostream>::introspect(Property<int> &v)
156 void CPFMarshaller<std::ostream>::introspect(Property<unsigned int> &v)
158 doWrite( v,
"ulong");
161 void CPFMarshaller<std::ostream>::introspect(Property<short> &v)
163 doWrite( v,
"short");
167 void CPFMarshaller<std::ostream>::introspect(Property<unsigned short> &v)
169 doWrite( v,
"ushort");
172 void CPFMarshaller<std::ostream>::introspect(Property<float> &v)
174 (this->s)->precision(15);
175 doWrite( v,
"float");
178 void CPFMarshaller<std::ostream>::introspect(Property<double> &v)
180 (this->s)->precision(25);
181 doWrite( v,
"double");
185 void CPFMarshaller<std::ostream>::introspect(Property<std::string> &v)
187 doWrite( v,
"string");
191 void CPFMarshaller<std::ostream>::introspect(Property<PropertyBag> &b)
193 PropertyBag v = b.get();
194 *(this->s) <<indent<<
"<struct name=\""<<escape(b.getName())<<
"\" type=\""<< escape(v.getType())<<
"\">\n";
196 if ( !b.getDescription().empty() )
197 *(this->s) <<indent<<
"<description>" <<escape(b.getDescription()) <<
"</description>\n";
199 b.value().identify(
this);
201 indent = indent.substr(0, indent.length()-3);
202 *(this->s) <<indent<<
"</struct>\n";
205 CPFMarshaller<std::ostream>::CPFMarshaller(std::ostream &os)
206 : StreamProcessor<
std::ostream>(os), indent(
" ")
211 : StreamProcessor<
std::ostream>(mfile),
212 mfile(filename.c_str(),
std::fstream::out),
217 log(
Error) <<
"Could not open file for writing: "<<filename <<endlog();
233 *(this->s) <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 234 <<
"<!DOCTYPE properties SYSTEM \"cpf.dtd\">\n";
235 *(this->s) <<
"<properties>\n";
239 *(this->s) <<
"</properties>\n";
void serialize(Archive &a, RTT::ConnPolicy &c, unsigned int)
Serializes RTT::ConnPolicy objects.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
CPFMarshaller(std::ostream &os)
Construct a CPFMarshaller from a stream.
virtual void flush()
Flush all buffers, write footers.