|
DD4hep
1.30.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
49 while( i<(
int)str.length() )
51 unsigned char c = (
unsigned char) str[i];
54 && i < ( (
int)str.length() - 2 )
68 while ( i<(
int)str.length()-1 )
70 outString->append( str.c_str() + i, 1 );
107 #if defined(TIXML_SNPRINTF)
108 TIXML_SNPRINTF( buf,
sizeof(buf),
"&#x%02X;", (
unsigned) ( c & 0xff ) );
110 sprintf( buf,
"&#x%02X;", (
unsigned) ( c & 0xff ) );
115 outString->append( buf, (
int)strlen( buf ) );
122 *outString += (char) c;
218 if ( !beforeThis || beforeThis->
parent !=
this ) {
232 node->
next = beforeThis;
234 if ( beforeThis->
prev )
243 beforeThis->
prev = node;
250 if ( !afterThis || afterThis->
parent !=
this ) {
264 node->
prev = afterThis;
266 if ( afterThis->
next )
275 afterThis->
next = node;
282 if ( replaceThis->
parent !=
this )
292 if ( replaceThis->
next )
297 if ( replaceThis->
prev )
310 if ( removeThis->
parent !=
this )
316 if ( removeThis->
next )
321 if ( removeThis->
prev )
335 if ( strcmp( node->
Value(), _value ) == 0 )
347 if ( strcmp( node->
Value(), _value ) == 0 )
362 assert( previous->
parent ==
this );
376 assert( previous->
parent ==
this );
385 for ( node =
next; node; node = node->
next )
387 if ( strcmp( node->
Value(), _value ) == 0 )
397 for ( node =
prev; node; node = node->
prev )
399 if ( strcmp( node->
Value(), _value ) == 0 )
514 for( node =
this; node; node = node->
parent )
588 return node->
Value();
623 const std::string* s =
Attribute( name );
627 *i = atoi( s->c_str() );
657 const std::string* s =
Attribute( name );
661 *d = atof( s->c_str() );
715 #if defined(TIXML_SNPRINTF)
716 TIXML_SNPRINTF( buf,
sizeof(buf),
"%d", val );
718 sprintf( buf,
"%d", val );
727 std::ostringstream oss;
737 #if defined(TIXML_SNPRINTF)
738 TIXML_SNPRINTF( buf,
sizeof(buf),
"%f", val );
740 sprintf( buf,
"%f", val );
752 const char* _name = cname;
753 const char* _value = cvalue;
804 for ( i=0; i<depth; i++ ) {
805 fprintf( cfile,
" " );
808 fprintf( cfile,
"<%s",
value.c_str() );
813 fprintf( cfile,
" " );
814 attrib->
Print( cfile, depth );
824 fprintf( cfile,
" />" );
828 fprintf( cfile,
">" );
830 fprintf( cfile,
"</%s>",
value.c_str() );
834 fprintf( cfile,
">" );
840 fprintf( cfile,
"\n" );
842 node->
Print( cfile, depth+1 );
844 fprintf( cfile,
"\n" );
845 for( i=0; i<depth; ++i ) {
846 fprintf( cfile,
" " );
848 fprintf( cfile,
"</%s>",
value.c_str() );
863 attribute = attribute->
Next() )
881 if ( !node->Accept( visitor ) )
906 return childText->
Value();
924 value = documentName;
934 value = documentName;
987 FILE* file = fopen(
value.c_str (),
"rb" );
991 bool result =
LoadFile( file, encoding );
1016 fseek( file, 0, SEEK_END );
1017 length = ftell( file );
1018 fseek( file, 0, SEEK_SET );
1030 data.reserve( length );
1053 char* buf =
new char[ length+1 ];
1056 if ( fread( buf, length, 1, file ) != 1 ) {
1062 const char* lastPos = buf;
1063 const char* p = buf;
1067 assert( p < (buf+length) );
1071 data.append( lastPos, (p-lastPos+1) );
1074 assert( p <= (buf+length) );
1076 else if ( *p == 0xd ) {
1079 if ( (p-lastPos) > 0 ) {
1080 data.append( lastPos, p-lastPos );
1084 if ( *(p+1) == 0xa ) {
1088 assert( p <= (buf+length) );
1094 assert( p <= (buf+length) );
1103 data.append( lastPos, p-lastPos );
1108 Parse( data.c_str(), 0, encoding );
1120 FILE* fp = fopen( filename,
"w" );
1144 return (ferror(fp) == 0);
1179 node->
Print( cfile, depth );
1180 fprintf( cfile,
"\n" );
1191 if ( !node->Accept( visitor ) )
1246 if (
value.find (
'\"') == TIXML_STRING::npos) {
1248 fprintf (cfile,
"%s=\"%s\"", n.c_str(),
v.c_str() );
1251 (*str) += n; (*str) +=
"=\""; (*str) +=
v; (*str) +=
"\"";
1256 fprintf (cfile,
"%s='%s'", n.c_str(),
v.c_str() );
1259 (*str) += n; (*str) +=
"='"; (*str) +=
v; (*str) +=
"'";
1267 if ( sscanf(
value.c_str(),
"%d", ival ) == 1 )
1274 if ( sscanf(
value.c_str(),
"%lf", dval ) == 1 )
1282 #if defined(TIXML_SNPRINTF)
1283 TIXML_SNPRINTF(buf,
sizeof(buf),
"%d", _value);
1285 sprintf (buf,
"%d", _value);
1293 #if defined(TIXML_SNPRINTF)
1294 TIXML_SNPRINTF( buf,
sizeof(buf),
"%f", _value);
1296 sprintf (buf,
"%f", _value);
1303 return atoi (
value.c_str ());
1308 return atof (
value.c_str ());
1314 copy.CopyTo(
this );
1328 for (
int i=0; i<depth; i++ )
1330 fprintf( cfile,
" " );
1332 fprintf( cfile,
"<!--%s-->",
value.c_str() );
1344 return visitor->
Visit( *
this );
1366 fprintf( cfile,
"\n" );
1367 for ( i=0; i<depth; i++ ) {
1368 fprintf( cfile,
" " );
1370 fprintf( cfile,
"<![CDATA[%s]]>\n",
value.c_str() );
1376 fprintf( cfile,
"%s", buffer.c_str() );
1390 return visitor->
Visit( *
this );
1408 const char * _encoding,
1409 const char * _standalone )
1418 #ifdef TIXML_USE_STL
1420 const std::string& _encoding,
1421 const std::string& _standalone )
1434 copy.CopyTo(
this );
1441 copy.CopyTo(
this );
1447 if ( cfile ) fprintf( cfile,
"<?xml " );
1448 if ( str ) (*str) +=
"<?xml ";
1451 if ( cfile ) fprintf (cfile,
"version=\"%s\" ",
version.c_str ());
1452 if ( str ) { (*str) +=
"version=\""; (*str) +=
version; (*str) +=
"\" "; }
1455 if ( cfile ) fprintf (cfile,
"encoding=\"%s\" ",
encoding.c_str ());
1456 if ( str ) { (*str) +=
"encoding=\""; (*str) +=
encoding; (*str) +=
"\" "; }
1459 if ( cfile ) fprintf (cfile,
"standalone=\"%s\" ",
standalone.c_str ());
1460 if ( str ) { (*str) +=
"standalone=\""; (*str) +=
standalone; (*str) +=
"\" "; }
1462 if ( cfile ) fprintf( cfile,
"?>" );
1463 if ( str ) (*str) +=
"?>";
1479 return visitor->
Visit( *
this );
1497 for (
int i=0; i<depth; i++ )
1498 fprintf( cfile,
" " );
1499 fprintf( cfile,
"<%s>",
value.c_str() );
1511 return visitor->
Visit( *
this );
1543 #ifdef TIXML_USE_STL
1562 if ( node == removeMe )
1575 #ifdef TIXML_USE_STL
1580 if ( node->
name == name )
1604 if ( strcmp( node->
name.c_str(), name ) == 0 )
1622 #ifdef TIXML_USE_STL
1623 std::istream& operator>> (std::istream & in,
TiXmlNode & base)
1626 tag.reserve( 8 * 1000 );
1635 #ifdef TIXML_USE_STL
1641 out << printer.
Str();
1652 out.append( printer.
Str() );
1799 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