70 std::stack< std::pair<PropertyBag*, Property<PropertyBag>*> >
bag_stack;
72 enum Tag { TAG_STRUCT, TAG_SIMPLE, TAG_SEQUENCE, TAG_PROPERTIES, TAG_DESCRIPTION,
TAG_VALUE, TAG_UNKNOWN};
88 bag_stack.push(std::make_pair(&bag, dummy));
93 switch ( tag_stack.top() )
96 if ( type ==
"boolean" )
98 if ( value_string ==
"1" || value_string ==
"true")
99 bag_stack.top().first->ownProperty
101 else if ( value_string ==
"0" || value_string ==
"false")
102 bag_stack.top().first->ownProperty
105 log(
Error)<<
"Wrong value for property '"+type+
"'." \
106 " Value should contain '0' or '1', got '"+ value_string +
"'." <<
endlog();
110 else if ( type ==
"char" ) {
111 if ( value_string.length() > 1 ) {
112 log(
Error) <<
"Wrong value for property '"+type+
"'." \
113 " Value should contain a single character, got '"+ value_string +
"'." <<
endlog();
117 bag_stack.top().first->ownProperty
118 (
new Property<char>( name, description, value_string.empty() ?
'\0' : value_string[0] ) );
120 else if ( type ==
"uchar" || type ==
"octet" ) {
121 if ( value_string.length() > 1 ) {
122 log(
Error) <<
"Wrong value for property '"+type+
"'." \
123 " Value should contain a single unsigned character, got '"+ value_string +
"'." <<
endlog();
127 bag_stack.top().first->ownProperty
130 else if ( type ==
"long" || type ==
"short")
132 if (type ==
"short") {
133 log(
Warning) <<
"Use type='long' instead of type='short' for Property '"<< name <<
"', since 16bit integers are not supported." <<
endlog();
134 log(
Warning) <<
"Future versions of RTT will no longer map XML 'short' to C++ 'int' but to C++ 'short' Property objects." <<
endlog();
137 if ( sscanf(value_string.c_str(),
"%d", &v) == 1)
138 bag_stack.top().first->ownProperty(
new Property<int>( name, description, v ) );
140 log(
Error) <<
"Wrong value for property '"+type+
"'." \
141 " Value should contain an integer value, got '"+ value_string +
"'." <<
endlog();
145 else if ( type ==
"ulong" || type ==
"ushort")
147 if (type ==
"ushort") {
148 log(
Warning) <<
"Use type='ulong' instead of type='ushort' for Property '"<< name <<
"', since 16bit integers are not supported." <<
endlog();
149 log(
Warning) <<
"Future versions of RTT will no longer map XML 'ushort' to C++ 'unsigned int' but to C++ 'unsigned short' Property objects." <<
endlog();
152 if ( sscanf(value_string.c_str(),
"%u", &v) == 1)
155 log(
Error) <<
"Wrong value for property '"+type+
"'." \
156 " Value should contain an integer value, got '"+ value_string +
"'." <<
endlog();
160 else if ( type ==
"llong")
163 if ( sscanf(value_string.c_str(),
"%lld", &v) == 1)
166 log(
Error) <<
"Wrong value for property '"+type+
"'." \
167 " Value should contain an integer value, got '"+ value_string +
"'." <<
endlog();
171 else if ( type ==
"ullong")
173 unsigned long long v;
174 if ( sscanf(value_string.c_str(),
"%llu", &v) == 1)
177 log(
Error) <<
"Wrong value for property '"+type+
"'." \
178 " Value should contain an integer value, got '"+ value_string +
"'." <<
endlog();
182 else if ( type ==
"double")
185 if ( sscanf(value_string.c_str(),
"%lf", &v) == 1 )
186 bag_stack.top().first->ownProperty
189 log(
Error) <<
"Wrong value for property '"+type+
"'." \
190 " Value should contain a double value, got '"+ value_string +
"'." <<
endlog();
194 else if ( type ==
"float")
197 if ( sscanf(value_string.c_str(),
"%f", &v) == 1 )
198 bag_stack.top().first->ownProperty
201 log(
Error) <<
"Wrong value for property '"+type+
"'." \
202 " Value should contain a float value, got '"+ value_string +
"'." <<
endlog();
206 else if ( type ==
"string")
207 bag_stack.top().first->ownProperty
210 log(
Error)<<
"Unknown type \""<<type<<
"\" for for tag simple"<<
endlog();
214 value_string.clear();
224 bag_stack.top().first->ownProperty( prop );
234 case TAG_DESCRIPTION:
236 if ( tag_stack.top() == TAG_STRUCT ) {
256 std::string ln = localname;
258 if ( ln ==
"properties" )
259 tag_stack.push( TAG_PROPERTIES );
261 if ( ln ==
"simple" )
263 tag_stack.push( TAG_SIMPLE );
268 std::string an = attributes->
Name();
271 name = attributes->
Value();
273 else if ( an ==
"type")
275 type = attributes->
Value();
277 attributes = attributes->
Next();
281 if ( ln ==
"struct" || ln ==
"sequence")
287 std::string an = attributes->
Name();
290 name = attributes->
Value();
292 else if ( an ==
"type")
294 type = attributes->
Value();
296 attributes = attributes->
Next();
298 if ( ln ==
"struct" )
299 tag_stack.push( TAG_STRUCT );
301 tag_stack.push( TAG_SEQUENCE );
309 bag_stack.push(std::make_pair( &(prop->
value()), prop));
312 if ( ln ==
"description")
313 tag_stack.push( TAG_DESCRIPTION );
316 tag_stack.push( TAG_VALUE );
319 tag_stack.push( TAG_UNKNOWN );
325 switch ( tag_stack.top() )
327 case TAG_DESCRIPTION:
332 value_string = chars;;
350 int t = pParent->
Type();
354 case TiXmlNode::ELEMENT:
361 if ( this->populateBag( pChild ) ==
false){
368 if ( this->endElement() ==
false )
372 case TiXmlNode::TEXT:
373 pText = pParent->
ToText();
374 this->characters( pText->
Value() );
378 case TiXmlNode::DECLARATION:
379 case TiXmlNode::COMMENT:
380 case TiXmlNode::UNKNOWN:
381 case TiXmlNode::DOCUMENT:
389 using namespace detail;
393 D(
const std::string& f) : doc( f.c_str() ), loadOkay(false) {}
398 TinyDemarshaller::TinyDemarshaller(
const std::string& filename )
426 if ( ! propHandle.
Node() ) {
427 log(
Error) <<
"No <properties> element found in document!"<<
endlog();
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
const char * Name() const
Return the name of this attribute.
bool populateBag(TiXmlNode *pParent)
const char * Value() const
Return the value of this attribute.
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
const TiXmlAttribute * FirstAttribute() const
Access the first attribute in this element.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
std::stack< Tag > tag_stack
const char * ErrorDesc() const
Contains a textual (english) description of the error if one occurs.
A container for holding references to properties.
Tiny2CPFHandler(PropertyBag &b)
TiXmlNode * Node() const
Return the handle as a TiXmlNode. This may return null.
std::stack< std::pair< PropertyBag *, Property< PropertyBag > * > > bag_stack
void characters(const char *chars)
virtual bool deserialize(PropertyBag &v)
A TinyXML demarshaller for extracting properties and property bags from a Component Property File (CP...
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
const char * Value() const
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
void startElement(const char *localname, const TiXmlAttribute *attributes)
static Logger::LogFunction endlog()
void setDescription(const std::string &desc)