 |
DD4hep
1.31.0
Detector Description Toolkit for High Energy Physics
|
Go to the documentation of this file. 1 #ifndef DDCORE_SRC_XML_TINYXML_INL_H
2 #define DDCORE_SRC_XML_TINYXML_INL_H
47 while( i<(
int)str.length() )
49 unsigned char c = (
unsigned char) str[i];
52 && i < ( (
int)str.length() - 2 )
66 while ( i<(
int)str.length()-1 )
68 outString->append( str.c_str() + i, 1 );
105 #if defined(TIXML_SNPRINTF)
106 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
108 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
113 outString->append( buf, (
int)strlen( buf ) );
120 *outString += (char) c;
216 if ( !beforeThis || beforeThis->
parent !=
this ) {
230 node->
next = beforeThis;
232 if ( beforeThis->
prev )
241 beforeThis->
prev = node;
248 if ( !afterThis || afterThis->
parent !=
this ) {
262 node->
prev = afterThis;
264 if ( afterThis->
next )
273 afterThis->
next = node;
280 if ( replaceThis->
parent !=
this )
290 if ( replaceThis->
next )
295 if ( replaceThis->
prev )
308 if ( removeThis->
parent !=
this )
314 if ( removeThis->
next )
319 if ( removeThis->
prev )
333 if ( strcmp( node->
Value(), _value ) == 0 )
345 if ( strcmp( node->
Value(), _value ) == 0 )
360 assert( previous->
parent ==
this );
374 assert( previous->
parent ==
this );
383 for ( node =
next; node; node = node->
next )
385 if ( strcmp( node->
Value(), _value ) == 0 )
395 for ( node =
prev; node; node = node->
prev )
397 if ( strcmp( node->
Value(), _value ) == 0 )
512 for( node =
this; node; node = node->
parent )
586 return node->
Value();
621 const std::string* s =
Attribute( name );
625 *i = atoi( s->c_str() );
655 const std::string* s =
Attribute( name );
659 *d = atof( s->c_str() );
713 #if defined(TIXML_SNPRINTF)
714 TIXML_SNPRINTF( buf,
sizeof(buf),
"%d", val );
716 sprintf( buf,
"%d", val );
725 std::ostringstream oss;
735 #if defined(TIXML_SNPRINTF)
736 TIXML_SNPRINTF( buf,
sizeof(buf),
"%f", val );
738 sprintf( buf,
"%f", val );
750 const char* _name = cname;
751 const char* _value = cvalue;
802 for ( i=0; i<depth; i++ ) {
803 fprintf( cfile,
" " );
806 fprintf( cfile,
"<%s",
value.c_str() );
811 fprintf( cfile,
" " );
812 attrib->
Print( cfile, depth );
822 fprintf( cfile,
" />" );
826 fprintf( cfile,
">" );
828 fprintf( cfile,
"</%s>",
value.c_str() );
832 fprintf( cfile,
">" );
838 fprintf( cfile,
"\n" );
840 node->
Print( cfile, depth+1 );
842 fprintf( cfile,
"\n" );
843 for( i=0; i<depth; ++i ) {
844 fprintf( cfile,
" " );
846 fprintf( cfile,
"</%s>",
value.c_str() );
861 attribute = attribute->
Next() )
879 if ( !node->Accept( visitor ) )
904 return childText->
Value();
922 value = documentName;
932 value = documentName;
985 FILE* file = fopen(
value.c_str (),
"rb" );
989 bool result =
LoadFile( file, encoding );
1014 fseek( file, 0, SEEK_END );
1015 length = ftell( file );
1016 fseek( file, 0, SEEK_SET );
1028 data.reserve( length );
1051 char* buf =
new char[ length+1 ];
1054 if ( fread( buf, length, 1, file ) != 1 ) {
1060 const char* lastPos = buf;
1061 const char* p = buf;
1065 assert( p < (buf+length) );
1069 data.append( lastPos, (p-lastPos+1) );
1072 assert( p <= (buf+length) );
1074 else if ( *p == 0xd ) {
1077 if ( (p-lastPos) > 0 ) {
1078 data.append( lastPos, p-lastPos );
1082 if ( *(p+1) == 0xa ) {
1086 assert( p <= (buf+length) );
1092 assert( p <= (buf+length) );
1101 data.append( lastPos, p-lastPos );
1106 Parse( data.c_str(), 0, encoding );
1118 FILE* fp = fopen( filename,
"w" );
1142 return (ferror(fp) == 0);
1177 node->
Print( cfile, depth );
1178 fprintf( cfile,
"\n" );
1189 if ( !node->Accept( visitor ) )
1244 if (
value.find (
'\"') == TIXML_STRING::npos) {
1246 fprintf (cfile,
"%s=\"%s\"", n.c_str(),
v.c_str() );
1249 (*str) += n; (*str) +=
"=\""; (*str) +=
v; (*str) +=
"\"";
1254 fprintf (cfile,
"%s='%s'", n.c_str(),
v.c_str() );
1257 (*str) += n; (*str) +=
"='"; (*str) +=
v; (*str) +=
"'";
1265 if ( sscanf(
value.c_str(),
"%d", ival ) == 1 )
1272 if ( sscanf(
value.c_str(),
"%lf", dval ) == 1 )
1280 #if defined(TIXML_SNPRINTF)
1281 TIXML_SNPRINTF(buf,
sizeof(buf),
"%d", _value);
1283 sprintf (buf,
"%d", _value);
1291 #if defined(TIXML_SNPRINTF)
1292 TIXML_SNPRINTF( buf,
sizeof(buf),
"%f", _value);
1294 sprintf (buf,
"%f", _value);
1301 return atoi (
value.c_str ());
1306 return atof (
value.c_str ());
1312 copy.CopyTo(
this );
1326 for (
int i=0; i<depth; i++ )
1328 fprintf( cfile,
" " );
1330 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1342 return visitor->
Visit( *
this );
1364 fprintf( cfile,
"\n" );
1365 for ( i=0; i<depth; i++ ) {
1366 fprintf( cfile,
" " );
1368 fprintf( cfile,
"<![CDATA[%s]]>\n",
value.c_str() );
1374 fprintf( cfile,
"%s", buffer.c_str() );
1388 return visitor->
Visit( *
this );
1406 const char * _encoding,
1407 const char * _standalone )
1416 #ifdef TIXML_USE_STL
1418 const std::string& _encoding,
1419 const std::string& _standalone )
1432 copy.CopyTo(
this );
1439 copy.CopyTo(
this );
1445 if ( cfile ) fprintf( cfile,
"<?xml " );
1446 if ( str ) (*str) +=
"<?xml ";
1449 if ( cfile ) fprintf (cfile,
"version=\"%s\" ",
version.c_str ());
1450 if ( str ) { (*str) +=
"version=\""; (*str) +=
version; (*str) +=
"\" "; }
1453 if ( cfile ) fprintf (cfile,
"encoding=\"%s\" ",
encoding.c_str ());
1454 if ( str ) { (*str) +=
"encoding=\""; (*str) +=
encoding; (*str) +=
"\" "; }
1457 if ( cfile ) fprintf (cfile,
"standalone=\"%s\" ",
standalone.c_str ());
1458 if ( str ) { (*str) +=
"standalone=\""; (*str) +=
standalone; (*str) +=
"\" "; }
1460 if ( cfile ) fprintf( cfile,
"?>" );
1461 if ( str ) (*str) +=
"?>";
1477 return visitor->
Visit( *
this );
1495 for (
int i=0; i<depth; i++ )
1496 fprintf( cfile,
" " );
1497 fprintf( cfile,
"<%s>",
value.c_str() );
1509 return visitor->
Visit( *
this );
1541 #ifdef TIXML_USE_STL
1560 if ( node == removeMe )
1573 #ifdef TIXML_USE_STL
1578 if ( node->
name == name )
1602 if ( strcmp( node->
name.c_str(), name ) == 0 )
1620 #ifdef TIXML_USE_STL
1621 std::istream& operator>> (std::istream & in,
TiXmlNode & base)
1624 tag.reserve( 8 * 1000 );
1633 #ifdef TIXML_USE_STL
1639 out << printer.
Str();
1650 out.append( printer.
Str() );
1797 for(
const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->
Next() )
TiXmlAttributeSet attributeSet
TinyXML class. See http://www.grinninglizard.com/tinyxml.
const TiXmlNode * LastChild() const
virtual const char * Parse(const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
virtual bool Accept(TiXmlVisitor *content) const override
TinyXML class. See http://www.grinninglizard.com/tinyxml.
const char * Attribute(const char *name) const
int IntValue() const
Return the value of this attribute, converted to an integer.
const TiXmlAttribute * Previous() const
Get the previous sibling attribute in the DOM. Returns null at beginning.
TinyXML class. See http://www.grinninglizard.com/tinyxml.
virtual TiXmlNode * Clone() const override
[internal use] Creates a new Element and returns it.
virtual void Print(FILE *cfile, int depth) const override
const std::string & Str()
Return the result.
TiXmlHandle_t Child(const char *value, int index) const
virtual bool Accept(TiXmlVisitor *visitor) const override
void CopyTo(TiXmlText *target) const
void SetDoubleAttribute(const char *name, double value)
virtual bool Visit(const TiXmlDeclaration &)
Visit a declaration.
TiXmlNode * ReplaceChild(TiXmlNode *replaceThis, const TiXmlNode &withThis)
TiXmlText(const char *initValue)
TiXmlHandle_t(TiXmlNode *_node)
Create a handle from any node (at any depth of the tree.) This can be a null pointer.
const std::string & ValueStr() const
Return the value of this attribute.
void CopyTo(TiXmlUnknown *target) const
const TiXmlNode * NextSibling() const
Navigate to a sibling node.
const TiXmlNode * FirstChild() const
The first child of this node. Will be null if there are no children.
virtual const TiXmlElement * ToElement() const
Cast to a more defined type. Will return null if not of the requested type.
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
void CopyTo(TiXmlDeclaration *target) const
TiXmlNode * LinkEndChild(TiXmlNode *addThis)
void operator=(const TiXmlElement &base)
void CopyTo(TiXmlNode *target) const
friend class TiXmlElement
const TiXmlNode * PreviousSibling() const
Navigate to a sibling node.
virtual const TiXmlDocument * ToDocument() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlDocument * GetDocument() const
virtual const char * Parse(const char *p, TiXmlParsingData *data=0, TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING) override
const char * Value() const
Return the value of this attribute.
TiXmlDeclaration()
Construct an empty declaration.
TiXmlHandle_t FirstChildElement() const
Return a handle to the first child element.
virtual TiXmlNode * Clone() const override
Creates a copy of this Declaration and returns it.
virtual bool VisitEnter(const TiXmlDocument &doc) override
Visit a document.
virtual bool Accept(TiXmlVisitor *content) const override
@ TIXML_ERROR_DOCUMENT_TOP_ONLY
virtual bool Accept(TiXmlVisitor *visitor) const override
void Clear()
Delete all the children of this node. Does not affect 'this'.
virtual TiXmlNode * Clone() const override
void SetValue(const char *_value)
Set the value.
virtual void Print(FILE *cfile, int depth) const override
static void PutString(const TIXML_STRING &str, TIXML_STRING *out)
virtual bool VisitExit(const TiXmlDocument &doc) override
Visit a document.
virtual bool Accept(TiXmlVisitor *content) const override
bool SaveFile() const
Save a file using the current document value. Returns true if successful.
virtual TiXmlNode * Clone() const =0
TinyXML class. See http://www.grinninglizard.com/tinyxml.
const TiXmlElement * NextSiblingElement() const
void RemoveAttribute(const char *name)
int QueryDoubleAttribute(const char *name, double *_value) const
QueryDoubleAttribute examines the attribute - see QueryIntAttribute().
void operator=(const TiXmlDeclaration ©)
int QueryDoubleValue(double *_value) const
QueryDoubleValue examines the value string. See QueryIntValue().
TinyXML class. See http://www.grinninglizard.com/tinyxml.
const unsigned char TIXML_UTF_LEAD_1
int QueryIntValue(int *_value) const
void CopyTo(TiXmlElement *target) const
void SetAttribute(const char *name, const char *_value)
virtual TiXmlNode * Clone() const override
Creates a new Element and returns it - the returned element is a copy.
const TiXmlElement * PreviousSiblingElement() const
virtual void Print(FILE *cfile, int depth) const override
TinyXML class. See http://www.grinninglizard.com/tinyxml.
virtual bool VisitEnter(const TiXmlDocument &)
Visit a document.
TiXmlHandle_t ChildElement(const char *value, int index) const
const TiXmlAttribute * Next() const
Get the next sibling attribute in the DOM. Returns null at end.
double DoubleValue() const
Return the value of this attribute, converted to a double.
const unsigned char TIXML_UTF_LEAD_0
TinyXML class. See http://www.grinninglizard.com/tinyxml.
TiXmlNode * InsertBeforeChild(TiXmlNode *beforeThis, const TiXmlNode &addThis)
const TiXmlEncoding TIXML_DEFAULT_ENCODING
void SetIntValue(int _value)
Set the value from an integer.
static Entity entity[NUM_ENTITY]
const TiXmlAttribute * Find(const char *_name) const
virtual void StreamIn(std::istream *in, TIXML_STRING *tag)=0
TiXmlNode * InsertEndChild(const TiXmlNode &addThis)
@ TIXML_ERROR_OPENING_FILE
bool CDATA() const
Queries whether this represents text using a CDATA section.
virtual TiXmlNode * Clone() const override
Creates a copy of this Unknown and returns it.
void CopyTo(TiXmlDocument *target) const
virtual void Print(FILE *cfile, int depth) const =0
virtual bool VisitExit(const TiXmlDocument &)
Visit a document.
static bool condenseWhiteSpace
const TiXmlElement * FirstChildElement() const
Convenience function to get through elements.
virtual void Print(FILE *cfile, int depth) const override
const TiXmlAttribute * First() const
const unsigned char TIXML_UTF_LEAD_2
virtual void Print(FILE *cfile, int depth, TIXML_STRING *str) const
TinyXML class. See http://www.grinninglizard.com/tinyxml.
const char * Value() const
@ TIXML_ERROR_OUT_OF_MEMORY
void operator=(const TiXmlDocument ©)
@ TIXML_ERROR_DOCUMENT_EMPTY
void Add(TiXmlAttribute *attribute)
void SetDoubleValue(double _value)
Set the value from a double.
bool LoadFile(TiXmlEncoding encoding=TIXML_DEFAULT_ENCODING)
bool RemoveChild(TiXmlNode *removeThis)
Delete a child of this node.
int QueryIntAttribute(const char *name, int *_value) const
void SetValue(const char *_value)
virtual bool Visit(const TiXmlDeclaration &declaration) override
Visit a declaration.
TinyXML class. See http://www.grinninglizard.com/tinyxml.
void Remove(TiXmlAttribute *attribute)
void * userData
Field containing a generic user pointer.
const char * Name() const
Return the name of this attribute.
virtual bool Accept(TiXmlVisitor *visitor) const =0
virtual const TiXmlText * ToText() const
Cast to a more defined type. Will return null if not of the requested type.
const TiXmlNode * NextSibling(const std::string &_value) const
STL std::string form.
TiXmlNode * InsertAfterChild(TiXmlNode *afterThis, const TiXmlNode &addThis)
const char * GetText() const
TinyXML class. See http://www.grinninglizard.com/tinyxml.
TinyXML class. See http://www.grinninglizard.com/tinyxml.
TiXmlHandle_t FirstChild() const
Return a handle to the first child node.
TiXmlDocument()
Create an empty document, that has no name.
const TiXmlNode * IterateChildren(const TiXmlNode *previous) const
std::ostream & operator<<(std::ostream &s, const dd4hep::Delta &data)
print alignment delta object