OBT::TiXmlAttribute Class Reference

An attribute is a name-value pair. More...

#include <OBTtinyxml.h>

Inheritance diagram for OBT::TiXmlAttribute:
[legend]
Collaboration diagram for OBT::TiXmlAttribute:
[legend]

List of all members.

Public Member Functions

 TiXmlAttribute ()
 Construct an empty attribute.
 TiXmlAttribute (const char *_name, const char *_value)
 Construct an attribute with a name and value.
const char * Name () const
 Return the name of this attribute.
const char * Value () const
 Return the value of this attribute.
int IntValue () const
 Return the value of this attribute, converted to an integer.
double DoubleValue () const
 Return the value of this attribute, converted to a double.
const TIXML_STRING & NameTStr () const
int QueryIntValue (int *_value) const
 QueryIntValue examines the value string.
int QueryDoubleValue (double *_value) const
 QueryDoubleValue examines the value string. See QueryIntValue().
void SetName (const char *_name)
 Set the name of this attribute.
void setValue (const char *_value)
 Set the value.
void SetIntValue (int _value)
 Set the value from an integer.
void SetDoubleValue (double _value)
 Set the value from a double.
const TiXmlAttributeNext () const
 Get the next sibling attribute in the DOM. Returns null at end.
TiXmlAttributeNext ()
const TiXmlAttributePrevious () const
 Get the previous sibling attribute in the DOM. Returns null at beginning.
TiXmlAttributePrevious ()
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)
virtual void Print (FILE *cfile, int depth) const
 All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.
void Print (FILE *cfile, int depth, TIXML_STRING *str) const
void SetDocument (TiXmlDocument *doc)
 TiXmlAttribute ()
 Construct an empty attribute.
 TiXmlAttribute (const char *_name, const char *_value)
 Construct an attribute with a name and value.
const char * Name () const
 Return the name of this attribute.
const char * Value () const
 Return the value of this attribute.
int IntValue () const
 Return the value of this attribute, converted to an integer.
double DoubleValue () const
 Return the value of this attribute, converted to a double.
const TIXML_STRING & NameTStr () const
int QueryIntValue (int *_value) const
 QueryIntValue examines the value string.
int QueryDoubleValue (double *_value) const
 QueryDoubleValue examines the value string. See QueryIntValue().
void SetName (const char *_name)
 Set the name of this attribute.
void SetValue (const char *_value)
 Set the value.
void SetIntValue (int _value)
 Set the value from an integer.
void SetDoubleValue (double _value)
 Set the value from a double.
const TiXmlAttributeNext () const
 Get the next sibling attribute in the DOM. Returns null at end.
TiXmlAttributeNext ()
const TiXmlAttributePrevious () const
 Get the previous sibling attribute in the DOM. Returns null at beginning.
TiXmlAttributePrevious ()
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)
virtual void Print (FILE *cfile, int depth) const
 All TinyXml classes can print themselves to a filestream or the string class (TiXmlString in non-STL mode, std::string in STL mode.
void Print (FILE *cfile, int depth, TIXML_STRING *str) const
void SetDocument (TiXmlDocument *doc)

Private Member Functions

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

Private Attributes

TiXmlDocumentdocument
TIXML_STRING name
TIXML_STRING value
TiXmlAttributeprev
TiXmlAttributenext

Friends

class TiXmlAttributeSet

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.

Definition at line 787 of file OBTtinyxml.h.


Constructor & Destructor Documentation

OBT::TiXmlAttribute::TiXmlAttribute (  )  [inline]

Construct an empty attribute.

Definition at line 793 of file OBTtinyxml.h.

00793                          : TiXmlBase()
00794         {
00795                 document = 0;
00796                 prev = next = 0;
00797         }

OBT::TiXmlAttribute::TiXmlAttribute ( const char *  _name,
const char *  _value 
) [inline]

Construct an attribute with a name and value.

Definition at line 811 of file OBTtinyxml.h.

00812         {
00813                 name = _name;
00814                 value = _value;
00815                 document = 0;
00816                 prev = next = 0;
00817         }

OBT::TiXmlAttribute::TiXmlAttribute ( const TiXmlAttribute  )  [private]
OBT::TiXmlAttribute::TiXmlAttribute (  )  [inline]

Construct an empty attribute.

Definition at line 792 of file tiny/OBTtinyxml.h.

References document, next, and prev.

00792                          : TiXmlBase()
00793         {
00794                 document = 0;
00795                 prev = next = 0;
00796         }

OBT::TiXmlAttribute::TiXmlAttribute ( const char *  _name,
const char *  _value 
) [inline]

Construct an attribute with a name and value.

Definition at line 810 of file tiny/OBTtinyxml.h.

References document, name, next, prev, and value.

00811         {
00812                 name = _name;
00813                 value = _value;
00814                 document = 0;
00815                 prev = next = 0;
00816         }

OBT::TiXmlAttribute::TiXmlAttribute ( const TiXmlAttribute  )  [private]

Member Function Documentation

double OBT::TiXmlAttribute::DoubleValue (  )  const

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

double OBT::TiXmlAttribute::DoubleValue (  )  const

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

Definition at line 1283 of file OBTtinyxml.cpp.

References value.

01284 {
01285         return atof (value.c_str ());
01286 }

int OBT::TiXmlAttribute::IntValue (  )  const

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

int OBT::TiXmlAttribute::IntValue (  )  const

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

Definition at line 1278 of file OBTtinyxml.cpp.

References value.

01279 {
01280         return atoi (value.c_str ());
01281 }

const char* OBT::TiXmlAttribute::Name (  )  const [inline]

Return the name of this attribute.

Definition at line 818 of file tiny/OBTtinyxml.h.

References name.

const char* OBT::TiXmlAttribute::Name (  )  const [inline]

Return the name of this attribute.

Definition at line 819 of file OBTtinyxml.h.

Referenced by OBT::TiXmlAttributeSet::Add(), OBT::TiXmlElement::CopyTo(), and OBT::TiXmlElement::Parse().

const TIXML_STRING& OBT::TiXmlAttribute::NameTStr (  )  const [inline]

Definition at line 827 of file tiny/OBTtinyxml.h.

References name.

00827 { return name; }

const TIXML_STRING& OBT::TiXmlAttribute::NameTStr (  )  const [inline]

Definition at line 828 of file OBTtinyxml.h.

Referenced by OBT::TiXmlElement::Parse().

00828 { return name; }

TiXmlAttribute* OBT::TiXmlAttribute::Next (  )  [inline]

Definition at line 857 of file tiny/OBTtinyxml.h.

00857                                {
00858                 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); 
00859         }

const TiXmlAttribute* OBT::TiXmlAttribute::Next (  )  const

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

TiXmlAttribute* OBT::TiXmlAttribute::Next (  )  [inline]

Definition at line 858 of file OBTtinyxml.h.

00858                                {
00859                 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); 
00860         }

const TiXmlAttribute * OBT::TiXmlAttribute::Next (  )  const

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

Definition at line 1176 of file OBTtinyxml.cpp.

References name, next, and value.

Referenced by OBT::TiXmlElement::CopyTo(), OBT::TiXmlElement::Print(), and OBT::TiXmlPrinter::VisitEnter().

01177 {
01178         // We are using knowledge of the sentinel. The sentinel
01179         // have a value or name.
01180         if ( next->value.empty() && next->name.empty() )
01181                 return 0;
01182         return next;
01183 }

bool OBT::TiXmlAttribute::operator< ( const TiXmlAttribute rhs  )  const [inline]

Definition at line 868 of file tiny/OBTtinyxml.h.

References name.

00868 { return name < rhs.name; }

bool OBT::TiXmlAttribute::operator< ( const TiXmlAttribute rhs  )  const [inline]

Definition at line 869 of file OBTtinyxml.h.

References name.

00869 { return name < rhs.name; }

void OBT::TiXmlAttribute::operator= ( const TiXmlAttribute base  )  [private]

Reimplemented from OBT::TiXmlBase.

void OBT::TiXmlAttribute::operator= ( const TiXmlAttribute base  )  [private]

Reimplemented from OBT::TiXmlBase.

bool OBT::TiXmlAttribute::operator== ( const TiXmlAttribute rhs  )  const [inline]

Definition at line 867 of file tiny/OBTtinyxml.h.

References name.

00867 { return rhs.name == name; }

bool OBT::TiXmlAttribute::operator== ( const TiXmlAttribute rhs  )  const [inline]

Definition at line 868 of file OBTtinyxml.h.

References name.

00868 { return rhs.name == name; }

bool OBT::TiXmlAttribute::operator> ( const TiXmlAttribute rhs  )  const [inline]

Definition at line 869 of file tiny/OBTtinyxml.h.

References name.

00869 { return name > rhs.name; }

bool OBT::TiXmlAttribute::operator> ( const TiXmlAttribute rhs  )  const [inline]

Definition at line 870 of file OBTtinyxml.h.

References name.

00870 { return name > rhs.name; }

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

Implements OBT::TiXmlBase.

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

Implements OBT::TiXmlBase.

Definition at line 1391 of file OBTtinyxmlparser.cpp.

References OBT::TiXmlParsingData::Cursor(), OBT::TiXmlBase::IsWhiteSpace(), OBT::TiXmlBase::location, name, OBT::TiXmlBase::ReadName(), OBT::TiXmlBase::ReadText(), OBT::TiXmlDocument::SetError(), OBT::TiXmlBase::SkipWhiteSpace(), OBT::TiXmlParsingData::Stamp(), OBT::TiXmlBase::TIXML_ERROR_READING_ATTRIBUTES, and value.

Referenced by OBT::TiXmlDeclaration::Parse(), and OBT::TiXmlElement::Parse().

01392 {
01393         p = SkipWhiteSpace( p, encoding );
01394         if ( !p || !*p ) return 0;
01395 
01396 //      int tabsize = 4;
01397 //      if ( document )
01398 //              tabsize = document->TabSize();
01399 
01400         if ( data )
01401         {
01402                 data->Stamp( p, encoding );
01403                 location = data->Cursor();
01404         }
01405         // Read the name, the '=' and the value.
01406         const char* pErr = p;
01407         p = ReadName( p, &name, encoding );
01408         if ( !p || !*p )
01409         {
01410                 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
01411                 return 0;
01412         }
01413         p = SkipWhiteSpace( p, encoding );
01414         if ( !p || !*p || *p != '=' )
01415         {
01416                 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
01417                 return 0;
01418         }
01419 
01420         ++p;    // skip '='
01421         p = SkipWhiteSpace( p, encoding );
01422         if ( !p || !*p )
01423         {
01424                 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
01425                 return 0;
01426         }
01427         
01428         const char* end;
01429         const char SINGLE_QUOTE = '\'';
01430         const char DOUBLE_QUOTE = '\"';
01431 
01432         if ( *p == SINGLE_QUOTE )
01433         {
01434                 ++p;
01435                 end = "\'";             // single quote in string
01436                 p = ReadText( p, &value, false, end, false, encoding );
01437         }
01438         else if ( *p == DOUBLE_QUOTE )
01439         {
01440                 ++p;
01441                 end = "\"";             // double quote in string
01442                 p = ReadText( p, &value, false, end, false, encoding );
01443         }
01444         else
01445         {
01446                 // All attribute values should be in single or double quotes.
01447                 // But this is such a common error that the parser will try
01448                 // its best, even without them.
01449                 value = "";
01450                 while (    p && *p                                                                                      // existence
01451                                 && !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r'      // whitespace
01452                                 && *p != '/' && *p != '>' )                                                     // tag end
01453                 {
01454                         if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
01455                                 // [ 1451649 ] Attribute values with trailing quotes not handled correctly
01456                                 // We did not have an opening quote but seem to have a 
01457                                 // closing one. Give up and throw an error.
01458                                 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
01459                                 return 0;
01460                         }
01461                         value += *p;
01462                         ++p;
01463                 }
01464         }
01465         return p;
01466 }

TiXmlAttribute* OBT::TiXmlAttribute::Previous (  )  [inline]

Definition at line 863 of file tiny/OBTtinyxml.h.

00863                                    {
00864                 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); 
00865         }

const TiXmlAttribute* OBT::TiXmlAttribute::Previous (  )  const

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

TiXmlAttribute* OBT::TiXmlAttribute::Previous (  )  [inline]

Definition at line 864 of file OBTtinyxml.h.

00864                                    {
00865                 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); 
00866         }

const TiXmlAttribute * OBT::TiXmlAttribute::Previous (  )  const

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

Definition at line 1196 of file OBTtinyxml.cpp.

References name, prev, and value.

01197 {
01198         // We are using knowledge of the sentinel. The sentinel
01199         // have a value or name.
01200         if ( prev->value.empty() && prev->name.empty() )
01201                 return 0;
01202         return prev;
01203 }

void OBT::TiXmlAttribute::Print ( FILE *  cfile,
int  depth,
TIXML_STRING *  str 
) const
virtual void OBT::TiXmlAttribute::Print ( FILE *  cfile,
int  depth 
) const [inline, virtual]

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 OBT::TiXmlBase.

Definition at line 877 of file tiny/OBTtinyxml.h.

References Print().

00877                                                            {
00878                 Print( cfile, depth, 0 );
00879         }

void OBT::TiXmlAttribute::Print ( FILE *  cfile,
int  depth,
TIXML_STRING *  str 
) const

Definition at line 1216 of file OBTtinyxml.cpp.

References OBT::TiXmlBase::EncodeString(), TIXML_STRING, and value.

01217 {
01218         TIXML_STRING n, v;
01219 
01220         EncodeString( name, &n );
01221         EncodeString( value, &v );
01222 
01223         if (value.find ('\"') == TIXML_STRING::npos) {
01224                 if ( cfile ) {
01225                 fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
01226                 }
01227                 if ( str ) {
01228                         (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
01229                 }
01230         }
01231         else {
01232                 if ( cfile ) {
01233                 fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() );
01234                 }
01235                 if ( str ) {
01236                         (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
01237                 }
01238         }
01239 }

virtual void OBT::TiXmlAttribute::Print ( FILE *  cfile,
int  depth 
) const [inline, virtual]

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 OBT::TiXmlBase.

Definition at line 878 of file OBTtinyxml.h.

Referenced by Print(), and OBT::TiXmlDocument::Print().

00878                                                            {
00879                 Print( cfile, depth, 0 );
00880         }

int OBT::TiXmlAttribute::QueryDoubleValue ( double *  _value  )  const

QueryDoubleValue examines the value string. See QueryIntValue().

int OBT::TiXmlAttribute::QueryDoubleValue ( double *  _value  )  const

QueryDoubleValue examines the value string. See QueryIntValue().

Definition at line 1249 of file OBTtinyxml.cpp.

References TIXML_SSCANF, OBT::TIXML_SUCCESS, OBT::TIXML_WRONG_TYPE, and value.

Referenced by OBT::TiXmlElement::QueryDoubleAttribute().

01250 {
01251         if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 )
01252                 return TIXML_SUCCESS;
01253         return TIXML_WRONG_TYPE;
01254 }

int OBT::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.

int OBT::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.

Definition at line 1242 of file OBTtinyxml.cpp.

References TIXML_SSCANF, OBT::TIXML_SUCCESS, OBT::TIXML_WRONG_TYPE, and value.

Referenced by OBT::TiXmlElement::QueryIntAttribute().

01243 {
01244         if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 )
01245                 return TIXML_SUCCESS;
01246         return TIXML_WRONG_TYPE;
01247 }

void OBT::TiXmlAttribute::SetDocument ( TiXmlDocument doc  )  [inline]

Definition at line 884 of file tiny/OBTtinyxml.h.

References document.

00884 { document = doc; }

void OBT::TiXmlAttribute::SetDocument ( TiXmlDocument doc  )  [inline]

Definition at line 885 of file OBTtinyxml.h.

Referenced by OBT::TiXmlElement::Parse().

00885 { document = doc; }

void OBT::TiXmlAttribute::SetDoubleValue ( double  _value  ) 

Set the value from a double.

void OBT::TiXmlAttribute::SetDoubleValue ( double  _value  ) 

Set the value from a double.

Definition at line 1267 of file OBTtinyxml.cpp.

References setValue().

01268 {
01269         char buf [256];
01270         #if defined(TIXML_SNPRINTF)             
01271                 TIXML_SNPRINTF( buf, sizeof(buf), "%lf", _value);
01272         #else
01273                 sprintf (buf, "%lf", _value);
01274         #endif
01275         setValue (buf);
01276 }

void OBT::TiXmlAttribute::SetIntValue ( int  _value  ) 

Set the value from an integer.

void OBT::TiXmlAttribute::SetIntValue ( int  _value  ) 

Set the value from an integer.

Definition at line 1256 of file OBTtinyxml.cpp.

References setValue().

01257 {
01258         char buf [64];
01259         #if defined(TIXML_SNPRINTF)             
01260                 TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
01261         #else
01262                 sprintf (buf, "%d", _value);
01263         #endif
01264         setValue (buf);
01265 }

void OBT::TiXmlAttribute::SetName ( const char *  _name  )  [inline]

Set the name of this attribute.

Definition at line 842 of file tiny/OBTtinyxml.h.

References name.

void OBT::TiXmlAttribute::SetName ( const char *  _name  )  [inline]

Set the name of this attribute.

Definition at line 843 of file OBTtinyxml.h.

void OBT::TiXmlAttribute::SetValue ( const char *  _value  )  [inline]

Set the value.

Definition at line 843 of file tiny/OBTtinyxml.h.

References value.

void OBT::TiXmlAttribute::setValue ( const char *  _value  )  [inline]

Set the value.

Definition at line 844 of file OBTtinyxml.h.

Referenced by OBT::TiXmlElement::Parse(), OBT::TiXmlElement::SetAttribute(), SetDoubleValue(), and SetIntValue().

const char* OBT::TiXmlAttribute::Value (  )  const [inline]

Return the value of this attribute.

Definition at line 819 of file tiny/OBTtinyxml.h.

References value.

const char* OBT::TiXmlAttribute::Value (  )  const [inline]

Return the value of this attribute.

Definition at line 820 of file OBTtinyxml.h.

Referenced by OBT::TiXmlElement::Attribute(), OBT::TiXmlElement::CopyTo(), OBT::TiXmlDeclaration::Parse(), and OBT::TiXmlElement::Parse().


Friends And Related Function Documentation

Definition at line 789 of file OBTtinyxml.h.


Member Data Documentation

Definition at line 891 of file OBTtinyxml.h.

Referenced by SetDocument(), and TiXmlAttribute().

TIXML_STRING OBT::TiXmlAttribute::name [private]
TIXML_STRING OBT::TiXmlAttribute::value [private]

Generated on 1 Jan 2010 for OBT by  doxygen 1.6.1