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<long long> &v)
174 doWrite( v,
"llong");
177 void CPFMarshaller<std::ostream>::introspect(Property<unsigned long long> &v)
179 doWrite( v,
"ullong");
182 void CPFMarshaller<std::ostream>::introspect(Property<float> &v)
184 (this->s)->precision(15);
185 doWrite( v,
"float");
188 void CPFMarshaller<std::ostream>::introspect(Property<double> &v)
190 (this->s)->precision(25);
191 doWrite( v,
"double");
195 void CPFMarshaller<std::ostream>::introspect(Property<std::string> &v)
197 doWrite( v,
"string");
201 void CPFMarshaller<std::ostream>::introspect(Property<PropertyBag> &b)
203 PropertyBag v = b.get();
204 *(this->s) <<indent<<
"<struct name=\""<<escape(b.getName())<<
"\" type=\""<< escape(v.getType())<<
"\">\n";
206 if ( !b.getDescription().empty() )
207 *(this->s) <<indent<<
"<description>" <<escape(b.getDescription()) <<
"</description>\n";
209 b.value().identify(
this);
211 indent = indent.substr(0, indent.length()-3);
212 *(this->s) <<indent<<
"</struct>\n";
215 CPFMarshaller<std::ostream>::CPFMarshaller(std::ostream &os)
216 : StreamProcessor<
std::ostream>(os), indent(
" ")
221 : StreamProcessor<
std::ostream>(mfile),
222 mfile(filename.c_str(),
std::fstream::out),
227 log(
Error) <<
"Could not open file for writing: "<<filename <<
endlog();
243 *(this->s) <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 244 <<
"<!DOCTYPE properties SYSTEM \"cpf.dtd\">\n";
245 *(this->s) <<
"<properties>\n";
249 *(this->s) <<
"</properties>\n";
void serialize(Archive &a, RTT::ConnPolicy &c, unsigned int)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
static Logger::LogFunction endlog()
CPFMarshaller(std::ostream &os)