TiXmlAttribute Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlAttribute:
TiXmlBase

List of all members.

Public Member Functions

 TiXmlAttribute ()
 Construct an empty attribute.
 TiXmlAttribute (const std::string &_name, const std::string &_value)
 std::string constructor.
 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.
const std::string & ValueStr () 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
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.
void SetName (const std::string &_name)
 STL std::string form.
void SetValue (const std::string &_value)
 STL std::string form.
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
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)

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 777 of file tinyxml.h.


Constructor & Destructor Documentation

TiXmlAttribute::TiXmlAttribute (  )  [inline]

Construct an empty attribute.

Definition at line 783 of file tinyxml.h.

References document, next, and prev.

00783                          : TiXmlBase()
00784         {
00785                 document = 0;
00786                 prev = next = 0;
00787         }

TiXmlAttribute::TiXmlAttribute ( const std::string &  _name,
const std::string &  _value 
) [inline]

std::string constructor.

Definition at line 791 of file tinyxml.h.

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

00792         {
00793                 name = _name;
00794                 value = _value;
00795                 document = 0;
00796                 prev = next = 0;
00797         }

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

Construct an attribute with a name and value.

Definition at line 801 of file tinyxml.h.

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

00802         {
00803                 name = _name;
00804                 value = _value;
00805                 document = 0;
00806                 prev = next = 0;
00807         }

TiXmlAttribute::TiXmlAttribute ( const TiXmlAttribute  )  [private]

Member Function Documentation

double TiXmlAttribute::DoubleValue (  )  const

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

Definition at line 1263 of file tinyxml.cpp.

References value.

01264 {
01265         return atof (value.c_str ());
01266 }

int TiXmlAttribute::IntValue (  )  const

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

Definition at line 1258 of file tinyxml.cpp.

References value.

01259 {
01260         return atoi (value.c_str ());
01261 }

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

Return the name of this attribute.

Definition at line 809 of file tinyxml.h.

References name.

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

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

Definition at line 818 of file tinyxml.h.

References name.

Referenced by TiXmlElement::Parse().

00818 { return name; }

TiXmlAttribute* TiXmlAttribute::Next (  )  [inline]

Definition at line 848 of file tinyxml.h.

00848                                {
00849                 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); 
00850         }

const TiXmlAttribute * TiXmlAttribute::Next (  )  const

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

Definition at line 1156 of file tinyxml.cpp.

References name, next, and value.

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

01157 {
01158         // We are using knowledge of the sentinel. The sentinel
01159         // have a value or name.
01160         if ( next->value.empty() && next->name.empty() )
01161                 return 0;
01162         return next;
01163 }

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

Definition at line 859 of file tinyxml.h.

References name.

00859 { return name < rhs.name; }

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

Reimplemented from TiXmlBase.

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

Definition at line 858 of file tinyxml.h.

References name.

00858 { return rhs.name == name; }

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

Definition at line 860 of file tinyxml.h.

References name.

00860 { return name > rhs.name; }

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

Implements TiXmlBase.

Definition at line 1357 of file tinyxmlparser.cpp.

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

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

01358 {
01359         p = SkipWhiteSpace( p, encoding );
01360         if ( !p || !*p ) return 0;
01361 
01362 //      int tabsize = 4;
01363 //      if ( document )
01364 //              tabsize = document->TabSize();
01365 
01366         if ( data )
01367         {
01368                 data->Stamp( p, encoding );
01369                 location = data->Cursor();
01370         }
01371         // Read the name, the '=' and the value.
01372         const char* pErr = p;
01373         p = ReadName( p, &name, encoding );
01374         if ( !p || !*p )
01375         {
01376                 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
01377                 return 0;
01378         }
01379         p = SkipWhiteSpace( p, encoding );
01380         if ( !p || !*p || *p != '=' )
01381         {
01382                 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
01383                 return 0;
01384         }
01385 
01386         ++p;    // skip '='
01387         p = SkipWhiteSpace( p, encoding );
01388         if ( !p || !*p )
01389         {
01390                 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
01391                 return 0;
01392         }
01393         
01394         const char* end;
01395         const char SINGLE_QUOTE = '\'';
01396         const char DOUBLE_QUOTE = '\"';
01397 
01398         if ( *p == SINGLE_QUOTE )
01399         {
01400                 ++p;
01401                 end = "\'";             // single quote in string
01402                 p = ReadText( p, &value, false, end, false, encoding );
01403         }
01404         else if ( *p == DOUBLE_QUOTE )
01405         {
01406                 ++p;
01407                 end = "\"";             // double quote in string
01408                 p = ReadText( p, &value, false, end, false, encoding );
01409         }
01410         else
01411         {
01412                 // All attribute values should be in single or double quotes.
01413                 // But this is such a common error that the parser will try
01414                 // its best, even without them.
01415                 value = "";
01416                 while (    p && *p                                                                                      // existence
01417                                 && !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r'      // whitespace
01418                                 && *p != '/' && *p != '>' )                                                     // tag end
01419                 {
01420                         if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
01421                                 // [ 1451649 ] Attribute values with trailing quotes not handled correctly
01422                                 // We did not have an opening quote but seem to have a 
01423                                 // closing one. Give up and throw an error.
01424                                 if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
01425                                 return 0;
01426                         }
01427                         value += *p;
01428                         ++p;
01429                 }
01430         }
01431         return p;
01432 }

TiXmlAttribute* TiXmlAttribute::Previous (  )  [inline]

Definition at line 854 of file tinyxml.h.

00854                                    {
00855                 return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); 
00856         }

const TiXmlAttribute * TiXmlAttribute::Previous (  )  const

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

Definition at line 1176 of file tinyxml.cpp.

References name, prev, and value.

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

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

Definition at line 1196 of file tinyxml.cpp.

References n, TiXmlBase::PutString(), TIXML_STRING, and value.

01197 {
01198         TIXML_STRING n, v;
01199 
01200         PutString( name, &n );
01201         PutString( value, &v );
01202 
01203         if (value.find ('\"') == TIXML_STRING::npos) {
01204                 if ( cfile ) {
01205                 fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
01206                 }
01207                 if ( str ) {
01208                         (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
01209                 }
01210         }
01211         else {
01212                 if ( cfile ) {
01213                 fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() );
01214                 }
01215                 if ( str ) {
01216                         (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
01217                 }
01218         }
01219 }

virtual void 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 TiXmlBase.

Definition at line 868 of file tinyxml.h.

Referenced by TiXmlDocument::Print(), and TiXmlPrinter::VisitEnter().

00868                                                            {
00869                 Print( cfile, depth, 0 );
00870         }

int TiXmlAttribute::QueryDoubleValue ( double *  _value  )  const

QueryDoubleValue examines the value string. See QueryIntValue().

Definition at line 1229 of file tinyxml.cpp.

References TIXML_SUCCESS, TIXML_WRONG_TYPE, and value.

Referenced by TiXmlElement::QueryDoubleAttribute().

01230 {
01231         if ( sscanf( value.c_str(), "%lf", dval ) == 1 )
01232                 return TIXML_SUCCESS;
01233         return TIXML_WRONG_TYPE;
01234 }

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.

Definition at line 1222 of file tinyxml.cpp.

References TIXML_SUCCESS, TIXML_WRONG_TYPE, and value.

Referenced by TiXmlElement::QueryIntAttribute().

01223 {
01224         if ( sscanf( value.c_str(), "%d", ival ) == 1 )
01225                 return TIXML_SUCCESS;
01226         return TIXML_WRONG_TYPE;
01227 }

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

Definition at line 875 of file tinyxml.h.

References document.

Referenced by TiXmlElement::Parse().

00875 { document = doc; }

void TiXmlAttribute::SetDoubleValue ( double  _value  ) 

Set the value from a double.

Definition at line 1247 of file tinyxml.cpp.

References SetValue().

01248 {
01249         char buf [256];
01250         #if defined(TIXML_SNPRINTF)             
01251                 TIXML_SNPRINTF( buf, sizeof(buf), "%f", _value);
01252         #else
01253                 sprintf (buf, "%f", _value);
01254         #endif
01255         SetValue (buf);
01256 }

void TiXmlAttribute::SetIntValue ( int  _value  ) 

Set the value from an integer.

Definition at line 1236 of file tinyxml.cpp.

References SetValue().

01237 {
01238         char buf [64];
01239         #if defined(TIXML_SNPRINTF)             
01240                 TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
01241         #else
01242                 sprintf (buf, "%d", _value);
01243         #endif
01244         SetValue (buf);
01245 }

void TiXmlAttribute::SetName ( const std::string &  _name  )  [inline]

STL std::string form.

Definition at line 841 of file tinyxml.h.

00841 { name = _name; }       

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

Set the name of this attribute.

Definition at line 833 of file tinyxml.h.

References name.

void TiXmlAttribute::SetValue ( const std::string &  _value  )  [inline]

STL std::string form.

Definition at line 843 of file tinyxml.h.

00843 { value = _value; }

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

Set the value.

Definition at line 834 of file tinyxml.h.

References value.

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

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

Return the value of this attribute.

Definition at line 810 of file tinyxml.h.

References value.

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

const std::string& TiXmlAttribute::ValueStr (  )  const [inline]

Return the value of this attribute.

Definition at line 812 of file tinyxml.h.

References value.

Referenced by TiXmlElement::QueryValueAttribute().


Friends And Related Function Documentation

friend class TiXmlAttributeSet [friend]

Definition at line 779 of file tinyxml.h.


Member Data Documentation

Definition at line 881 of file tinyxml.h.

Referenced by Parse(), SetDocument(), and TiXmlAttribute().

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

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

Generated on 16 Apr 2018 for loon by  doxygen 1.6.1