FEDRA emulsion software from the OPERA Collaboration
TiXmlAttribute Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlAttribute:
Collaboration diagram for TiXmlAttribute:

Public Member Functions

double DoubleValue () const
 Return the value of this attribute, converted to a double. More...
 
int IntValue () const
 Return the value of this attribute, converted to an integer. More...
 
const char * Name () const
 Return the name of this attribute. More...
 
const TIXML_STRINGNameTStr () const
 
TiXmlAttributeNext ()
 
const TiXmlAttributeNext () const
 Get the next sibling attribute in the DOM. Returns null at end. More...
 
bool operator< (const TiXmlAttribute &rhs) const
 
bool operator== (const TiXmlAttribute &rhs) const
 
bool operator> (const TiXmlAttribute &rhs) const
 
virtual const char * Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)
 
TiXmlAttributePrevious ()
 
const TiXmlAttributePrevious () const
 Get the previous sibling attribute in the DOM. Returns null at beginning. More...
 
virtual void Print (FILE *cfile, int depth) const
 
void Print (FILE *cfile, int depth, TIXML_STRING *str) const
 
int QueryDoubleValue (double *_value) const
 QueryDoubleValue examines the value string. See QueryIntValue(). More...
 
int QueryIntValue (int *_value) const
 
void SetDocument (TiXmlDocument *doc)
 
void SetDoubleValue (double _value)
 Set the value from a double. More...
 
void SetIntValue (int _value)
 Set the value from an integer. More...
 
void SetName (const char *_name)
 Set the name of this attribute. More...
 
void SetValue (const char *_value)
 Set the value. More...
 
 TiXmlAttribute ()
 Construct an empty attribute. More...
 
 TiXmlAttribute (const char *_name, const char *_value)
 Construct an attribute with a name and value. More...
 
const char * Value () const
 Return the value of this attribute. More...
 
- Public Member Functions inherited from TiXmlBase
int Column () const
 See Row() More...
 
voidGetUserData ()
 Get a pointer to arbitrary user data. More...
 
const voidGetUserData () const
 Get a pointer to arbitrary user data. More...
 
virtual const char * Parse (const char *p, TiXmlParsingData *data, TiXmlEncoding encoding)=0
 
virtual void Print (FILE *cfile, int depth) const =0
 
int Row () const
 
void SetUserData (void *user)
 Set a pointer to arbitrary user data. More...
 
 TiXmlBase ()
 
virtual ~TiXmlBase ()
 

Private Member Functions

void operator= (const TiXmlAttribute &base)
 
 TiXmlAttribute (const TiXmlAttribute &)
 

Private Attributes

TiXmlDocumentdocument
 
TIXML_STRING name
 
TiXmlAttributenext
 
TiXmlAttributeprev
 
TIXML_STRING value
 

Friends

class TiXmlAttributeSet
 

Additional Inherited Members

- Public Types inherited from TiXmlBase
enum  {
  TIXML_NO_ERROR = 0 , TIXML_ERROR , TIXML_ERROR_OPENING_FILE , TIXML_ERROR_PARSING_ELEMENT ,
  TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME , TIXML_ERROR_READING_ELEMENT_VALUE , TIXML_ERROR_READING_ATTRIBUTES , TIXML_ERROR_PARSING_EMPTY ,
  TIXML_ERROR_READING_END_TAG , TIXML_ERROR_PARSING_UNKNOWN , TIXML_ERROR_PARSING_COMMENT , TIXML_ERROR_PARSING_DECLARATION ,
  TIXML_ERROR_DOCUMENT_EMPTY , TIXML_ERROR_EMBEDDED_NULL , TIXML_ERROR_PARSING_CDATA , TIXML_ERROR_DOCUMENT_TOP_ONLY ,
  TIXML_ERROR_STRING_COUNT
}
 
- Static Public Member Functions inherited from TiXmlBase
static void EncodeString (const TIXML_STRING &str, TIXML_STRING *out)
 
static bool IsWhiteSpaceCondensed ()
 Return the current white space setting. More...
 
static void SetCondenseWhiteSpace (bool condense)
 
- Static Public Attributes inherited from TiXmlBase
static const int utf8ByteTable [256]
 
- Static Protected Member Functions inherited from TiXmlBase
static void ConvertUTF32ToUTF8 (unsigned long input, char *output, int *length)
 
static const char * GetChar (const char *p, char *_value, int *length, TiXmlEncoding encoding)
 
static const char * GetEntity (const char *in, char *value, int *length, TiXmlEncoding encoding)
 
static int IsAlpha (unsigned char anyByte, TiXmlEncoding encoding)
 
static int IsAlphaNum (unsigned char anyByte, TiXmlEncoding encoding)
 
static bool IsWhiteSpace (char c)
 
static bool IsWhiteSpace (int c)
 
static const char * ReadName (const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
 
static const char * ReadText (const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
 
static const char * SkipWhiteSpace (const char *, TiXmlEncoding encoding)
 
static bool StringEqual (const char *p, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
 
static int ToLower (int v, TiXmlEncoding encoding)
 
- Protected Attributes inherited from TiXmlBase
TiXmlCursor location
 
voiduserData
 Field containing a generic user pointer. More...
 
- Static Protected Attributes inherited from TiXmlBase
static const char * errorString [TIXML_ERROR_STRING_COUNT]
 

Detailed Description

An attribute is a name-value pair. Elements have an arbitrary number of attributes, each with a unique name.

Note
The attributes are not TiXmlNodes, since they are not part of the tinyXML document object model. There are other suggested ways to look at this problem.

Constructor & Destructor Documentation

◆ TiXmlAttribute() [1/3]

TiXmlAttribute::TiXmlAttribute ( )
inline

Construct an empty attribute.

785 : TiXmlBase()
786 {
787 document = 0;
788 prev = next = 0;
789 }
TiXmlAttribute * prev
Definition: tinyxml.h:886
TiXmlDocument * document
Definition: tinyxml.h:883
TiXmlAttribute * next
Definition: tinyxml.h:887
TiXmlBase()
Definition: tinyxml.h:201

◆ TiXmlAttribute() [2/3]

TiXmlAttribute::TiXmlAttribute ( const char *  _name,
const char *  _value 
)
inline

Construct an attribute with a name and value.

804 {
805 name = _name;
806 value = _value;
807 document = 0;
808 prev = next = 0;
809 }
TIXML_STRING value
Definition: tinyxml.h:885
TIXML_STRING name
Definition: tinyxml.h:884

◆ TiXmlAttribute() [3/3]

TiXmlAttribute::TiXmlAttribute ( const TiXmlAttribute )
private

Member Function Documentation

◆ DoubleValue()

double TiXmlAttribute::DoubleValue ( ) const

Return the value of this attribute, converted to a double.

1278{
1279 return atof (value.c_str ());
1280}

◆ IntValue()

int TiXmlAttribute::IntValue ( ) const

Return the value of this attribute, converted to an integer.

1273{
1274 return atoi (value.c_str ());
1275}

◆ Name()

const char * TiXmlAttribute::Name ( ) const
inline

Return the name of this attribute.

◆ NameTStr()

const TIXML_STRING & TiXmlAttribute::NameTStr ( ) const
inline
820{ return name; }

◆ Next() [1/2]

TiXmlAttribute * TiXmlAttribute::Next ( )
inline
850 {
851 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
852 }
Definition: tinyxml.h:780

◆ Next() [2/2]

const TiXmlAttribute * TiXmlAttribute::Next ( ) const

Get the next sibling attribute in the DOM. Returns null at end.

1171{
1172 // We are using knowledge of the sentinel. The sentinel
1173 // have a value or name.
1174 if ( next->value.empty() && next->name.empty() )
1175 return 0;
1176 return next;
1177}

◆ operator<()

bool TiXmlAttribute::operator< ( const TiXmlAttribute rhs) const
inline
861{ return name < rhs.name; }

◆ operator=()

void TiXmlAttribute::operator= ( const TiXmlAttribute base)
private

◆ operator==()

bool TiXmlAttribute::operator== ( const TiXmlAttribute rhs) const
inline
860{ return rhs.name == name; }

◆ operator>()

bool TiXmlAttribute::operator> ( const TiXmlAttribute rhs) const
inline
862{ return name > rhs.name; }

◆ Parse()

const char * TiXmlAttribute::Parse ( const char *  p,
TiXmlParsingData data,
TiXmlEncoding  encoding 
)
virtual

Implements TiXmlBase.

1393{
1394 p = SkipWhiteSpace( p, encoding );
1395 if ( !p || !*p ) return 0;
1396
1397 if ( data )
1398 {
1399 data->Stamp( p, encoding );
1400 location = data->Cursor();
1401 }
1402 // Read the name, the '=' and the value.
1403 const char* pErr = p;
1404 p = ReadName( p, &name, encoding );
1405 if ( !p || !*p )
1406 {
1407 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
1408 return 0;
1409 }
1410 p = SkipWhiteSpace( p, encoding );
1411 if ( !p || !*p || *p != '=' )
1412 {
1413 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
1414 return 0;
1415 }
1416
1417 ++p; // skip '='
1418 p = SkipWhiteSpace( p, encoding );
1419 if ( !p || !*p )
1420 {
1421 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
1422 return 0;
1423 }
1424
1425 const char* end;
1426 const char SINGLE_QUOTE = '\'';
1427 const char DOUBLE_QUOTE = '\"';
1428
1429 if ( *p == SINGLE_QUOTE )
1430 {
1431 ++p;
1432 end = "\'"; // single quote in string
1433 p = ReadText( p, &value, false, end, false, encoding );
1434 }
1435 else if ( *p == DOUBLE_QUOTE )
1436 {
1437 ++p;
1438 end = "\""; // double quote in string
1439 p = ReadText( p, &value, false, end, false, encoding );
1440 }
1441 else
1442 {
1443 // All attribute values should be in single or double quotes.
1444 // But this is such a common error that the parser will try
1445 // its best, even without them.
1446 value = "";
1447 while ( p && *p // existence
1448 && !IsWhiteSpace( *p ) // whitespace
1449 && *p != '/' && *p != '>' ) // tag end
1450 {
1451 if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
1452 // [ 1451649 ] Attribute values with trailing quotes not handled correctly
1453 // We did not have an opening quote but seem to have a
1454 // closing one. Give up and throw an error.
1455 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
1456 return 0;
1457 }
1458 value += *p;
1459 ++p;
1460 }
1461 }
1462 return p;
1463}
TiXmlCursor location
Definition: tinyxml.h:373
static const char * ReadName(const char *p, TIXML_STRING *name, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:401
@ TIXML_ERROR_READING_ATTRIBUTES
Definition: tinyxml.h:272
static const char * ReadText(const char *in, TIXML_STRING *text, bool ignoreWhiteSpace, const char *endTag, bool ignoreCase, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:574
static const char * SkipWhiteSpace(const char *, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:314
static bool IsWhiteSpace(char c)
Definition: tinyxml.h:290
void SetError(int err, const char *errorLocation, TiXmlParsingData *prevData, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:798
void Stamp(const char *now, TiXmlEncoding encoding)
Definition: tinyxmlparser.cpp:196
const TiXmlCursor & Cursor() const
Definition: tinyxmlparser.cpp:177
p
Definition: testBGReduction_AllMethods.C:8

◆ Previous() [1/2]

TiXmlAttribute * TiXmlAttribute::Previous ( )
inline
856 {
857 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
858 }

◆ Previous() [2/2]

const TiXmlAttribute * TiXmlAttribute::Previous ( ) const

Get the previous sibling attribute in the DOM. Returns null at beginning.

1191{
1192 // We are using knowledge of the sentinel. The sentinel
1193 // have a value or name.
1194 if ( prev->value.empty() && prev->name.empty() )
1195 return 0;
1196 return prev;
1197}

◆ Print() [1/2]

virtual void TiXmlAttribute::Print ( FILE *  cfile,
int  depth 
) const
inlinevirtual

All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.) Either or both cfile and str can be null.

This is a formatted print, and will insert tabs and newlines.

(For an unformatted stream, use the << operator.)

Implements TiXmlBase.

870 {
871 Print( cfile, depth, 0 );
872 }
virtual void Print(FILE *cfile, int depth) const
Definition: tinyxml.h:870

◆ Print() [2/2]

void TiXmlAttribute::Print ( FILE *  cfile,
int  depth,
TIXML_STRING str 
) const
1211{
1212 TIXML_STRING n, v;
1213
1214 EncodeString( name, &n );
1215 EncodeString( value, &v );
1216
1217 if (value.find ('\"') == TIXML_STRING::npos) {
1218 if ( cfile ) {
1219 fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
1220 }
1221 if ( str ) {
1222 (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
1223 }
1224 }
1225 else {
1226 if ( cfile ) {
1227 fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() );
1228 }
1229 if ( str ) {
1230 (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
1231 }
1232 }
1233}
static void EncodeString(const TIXML_STRING &str, TIXML_STRING *out)
Definition: tinyxml.cpp:52
#define TIXML_STRING
Definition: tinyxml.h:53

◆ QueryDoubleValue()

int TiXmlAttribute::QueryDoubleValue ( double *  _value) const

QueryDoubleValue examines the value string. See QueryIntValue().

1244{
1245 if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 )
1246 return TIXML_SUCCESS;
1247 return TIXML_WRONG_TYPE;
1248}
@ TIXML_WRONG_TYPE
Definition: tinyxml.h:158
@ TIXML_SUCCESS
Definition: tinyxml.h:156
#define TIXML_SSCANF
Definition: tinyxml.h:79

◆ QueryIntValue()

int TiXmlAttribute::QueryIntValue ( int *  _value) const

QueryIntValue examines the value string. It is an alternative to the IntValue() method with richer error checking. If the value is an integer, it is stored in 'value' and the call returns TIXML_SUCCESS. If it is not an integer, it returns TIXML_WRONG_TYPE.

A specialized but useful call. Note that for success it returns 0, which is the opposite of almost all other TinyXml calls.

1237{
1238 if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 )
1239 return TIXML_SUCCESS;
1240 return TIXML_WRONG_TYPE;
1241}

◆ SetDocument()

void TiXmlAttribute::SetDocument ( TiXmlDocument doc)
inline
877{ document = doc; }

◆ SetDoubleValue()

void TiXmlAttribute::SetDoubleValue ( double  _value)

Set the value from a double.

1262{
1263 char buf [256];
1264 #if defined(TIXML_SNPRINTF)
1265 TIXML_SNPRINTF( buf, sizeof(buf), "%g", _value);
1266 #else
1267 sprintf (buf, "%g", _value);
1268 #endif
1269 SetValue (buf);
1270}
void SetValue(const char *_value)
Set the value.
Definition: tinyxml.h:836
#define TIXML_SNPRINTF
Definition: tinyxml.h:78

◆ SetIntValue()

void TiXmlAttribute::SetIntValue ( int  _value)

Set the value from an integer.

1251{
1252 char buf [64];
1253 #if defined(TIXML_SNPRINTF)
1254 TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
1255 #else
1256 sprintf (buf, "%d", _value);
1257 #endif
1258 SetValue (buf);
1259}

◆ SetName()

void TiXmlAttribute::SetName ( const char *  _name)
inline

Set the name of this attribute.

◆ SetValue()

void TiXmlAttribute::SetValue ( const char *  _value)
inline

Set the value.

◆ Value()

const char * TiXmlAttribute::Value ( ) const
inline

Return the value of this attribute.

Friends And Related Function Documentation

◆ TiXmlAttributeSet

friend class TiXmlAttributeSet
friend

Member Data Documentation

◆ document

TiXmlDocument* TiXmlAttribute::document
private

◆ name

TIXML_STRING TiXmlAttribute::name
private

◆ next

TiXmlAttribute* TiXmlAttribute::next
private

◆ prev

TiXmlAttribute* TiXmlAttribute::prev
private

◆ value

TIXML_STRING TiXmlAttribute::value
private

The documentation for this class was generated from the following files: