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};
73 std::stack<Tag> tag_stack;
79 std::string description;
81 std::string value_string;
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->add
101 else if ( value_string ==
"0" || value_string ==
"false")
102 bag_stack.top().first->add
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->add
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->add
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->add(
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 ==
"double")
163 if ( sscanf(value_string.c_str(),
"%lf", &v) == 1 )
164 bag_stack.top().first->add
167 log(
Error) <<
"Wrong value for property '"+type+
"'." \
168 " Value should contain a double value, got '"+ value_string +
"'." << endlog();
172 else if ( type ==
"float")
175 if ( sscanf(value_string.c_str(),
"%f", &v) == 1 )
176 bag_stack.top().first->add
179 log(
Error) <<
"Wrong value for property '"+type+
"'." \
180 " Value should contain a float value, got '"+ value_string +
"'." << endlog();
184 else if ( type ==
"string")
185 bag_stack.top().first->add
188 log(
Error)<<
"Unknown type \""<<type<<
"\" for for tag simple"<<endlog();
192 value_string.clear();
202 bag_stack.top().first->add( prop );
212 case TAG_DESCRIPTION:
214 if ( tag_stack.top() == TAG_STRUCT ) {
216 bag_stack.top().second->setDescription(description);
234 std::string ln = localname;
236 if ( ln ==
"properties" )
237 tag_stack.push( TAG_PROPERTIES );
239 if ( ln ==
"simple" )
241 tag_stack.push( TAG_SIMPLE );
246 std::string an = attributes->
Name();
249 name = attributes->
Value();
251 else if ( an ==
"type")
253 type = attributes->
Value();
255 attributes = attributes->
Next();
259 if ( ln ==
"struct" || ln ==
"sequence")
265 std::string an = attributes->
Name();
268 name = attributes->
Value();
270 else if ( an ==
"type")
272 type = attributes->
Value();
274 attributes = attributes->
Next();
276 if ( ln ==
"struct" )
277 tag_stack.push( TAG_STRUCT );
279 tag_stack.push( TAG_SEQUENCE );
287 bag_stack.push(std::make_pair( &(prop->
value()), prop));
290 if ( ln ==
"description")
291 tag_stack.push( TAG_DESCRIPTION );
294 tag_stack.push( TAG_VALUE );
296 log(
Warning) <<
"Unrecognised XML tag :"<< ln <<
": ignoring." << endlog();
297 tag_stack.push( TAG_UNKNOWN );
303 switch ( tag_stack.top() )
305 case TAG_DESCRIPTION:
310 value_string = chars;;
328 int t = pParent->
Type();
332 case TiXmlNode::ELEMENT:
339 if ( this->populateBag( pChild ) ==
false){
340 log(
Error)<<
"Error in element at line "<<pChild->
Row() << endlog();
346 if ( this->endElement() ==
false )
350 case TiXmlNode::TEXT:
351 pText = pParent->
ToText();
352 this->characters( pText->
Value() );
356 case TiXmlNode::DECLARATION:
357 case TiXmlNode::COMMENT:
358 case TiXmlNode::UNKNOWN:
359 case TiXmlNode::DOCUMENT:
367 using namespace detail;
371 D(
const std::string& f) : doc( f.c_str() ), loadOkay(false) {}
376 TinyDemarshaller::TinyDemarshaller(
const std::string& filename )
383 log(
Error) <<
"Could not load " << filename <<
" Error: "<< d->
doc.
ErrorDesc() << endlog();
404 if ( ! propHandle.
Node() ) {
405 log(
Error) <<
"No <properties> element found in document!"<< endlog();
A TiXmlHandle is a class that wraps a node pointer with null checks; this is an incredibly useful thi...
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.
int Type() const
Query the type (as an enumerated value, above) of this node.
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.
An attribute is a name-value pair.
Always the top level node.
TiXmlHandle FirstChildElement() const
Return a handle to the first child element.
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.
reference_t value()
Access to the value of the Property.
void characters(const char *chars)
A property represents a named value of any type with a description.
The parent class for everything in the Document Object Model.
virtual bool deserialize(PropertyBag &v)
Deserialize data to a property bag.
void deleteProperties(PropertyBag &target)
This function iterates over a PropertyBag and deletes all Property objects in it without recursion...
Notify the Logger in which 'module' the message occured.
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)
Load a file using the current document value.
const char * Value() const
The meaning of 'value' changes for the specific type of TiXmlNode.
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
void startElement(const char *localname, const TiXmlAttribute *attributes)
int Row() const
Return the position, in the original source file, of this node or attribute.