xmlTiny::TiXmlAttribute Class Reference

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

#include <OBTtinyxml.h>

Inheritance diagram for xmlTiny::TiXmlAttribute:

Inheritance graph
[legend]
Collaboration diagram for xmlTiny::TiXmlAttribute:

Collaboration graph
[legend]

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
 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.
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
 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)

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 785 of file tiny/tmp/OBTtinyxml.h.


Constructor & Destructor Documentation

xmlTiny::TiXmlAttribute::TiXmlAttribute (  )  [inline]

Construct an empty attribute.

Definition at line 791 of file tiny/tmp/OBTtinyxml.h.

References document, next, and prev.

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

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

std::string constructor.

Definition at line 799 of file tiny/tmp/OBTtinyxml.h.

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

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

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

Construct an attribute with a name and value.

Definition at line 809 of file tiny/tmp/OBTtinyxml.h.

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

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

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


Member Function Documentation

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

Return the name of this attribute.

Definition at line 817 of file tiny/tmp/OBTtinyxml.h.

References name.

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

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

Return the value of this attribute.

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

References value.

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

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

Return the value of this attribute.

Definition at line 820 of file tiny/tmp/OBTtinyxml.h.

References value.

Referenced by xmlTiny::TiXmlElement::QueryValueAttribute().

int xmlTiny::TiXmlAttribute::IntValue (  )  const

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

Definition at line 1279 of file tiny/tmp/OBTtinyxml.cpp.

References value.

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

double xmlTiny::TiXmlAttribute::DoubleValue (  )  const

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

Definition at line 1284 of file tiny/tmp/OBTtinyxml.cpp.

References value.

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

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

Definition at line 826 of file tiny/tmp/OBTtinyxml.h.

References name.

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

00826 { return name; }

int xmlTiny::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 1243 of file tiny/tmp/OBTtinyxml.cpp.

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

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

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

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

QueryDoubleValue examines the value string. See QueryIntValue().

Definition at line 1250 of file tiny/tmp/OBTtinyxml.cpp.

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

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

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

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

Set the name of this attribute.

Definition at line 841 of file tiny/tmp/OBTtinyxml.h.

References name.

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

Set the value.

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

References value.

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

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

Set the value from an integer.

Definition at line 1257 of file tiny/tmp/OBTtinyxml.cpp.

References SetValue().

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

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

Set the value from a double.

Definition at line 1268 of file tiny/tmp/OBTtinyxml.cpp.

References SetValue().

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

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

STL std::string form.

Definition at line 849 of file tiny/tmp/OBTtinyxml.h.

00849 { name = _name; }       

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

STL std::string form.

Definition at line 851 of file tiny/tmp/OBTtinyxml.h.

00851 { value = _value; }

const TiXmlAttribute * xmlTiny::TiXmlAttribute::Next (  )  const

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

Definition at line 1177 of file tiny/tmp/OBTtinyxml.cpp.

References name, next, and value.

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

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

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

Definition at line 856 of file tiny/tmp/OBTtinyxml.h.

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

const TiXmlAttribute * xmlTiny::TiXmlAttribute::Previous (  )  const

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

Definition at line 1197 of file tiny/tmp/OBTtinyxml.cpp.

References name, prev, and value.

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

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

Definition at line 862 of file tiny/tmp/OBTtinyxml.h.

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

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

Definition at line 866 of file tiny/tmp/OBTtinyxml.h.

References name.

00866 { return rhs.name == name; }

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

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

References name.

00867 { return name < rhs.name; }

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

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

References name.

00868 { return name > rhs.name; }

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

Implements xmlTiny::TiXmlBase.

Definition at line 1391 of file tiny/tmp/OBTtinyxmlparser.cpp.

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

Referenced by xmlTiny::TiXmlDeclaration::Parse(), and xmlTiny::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 }

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

Definition at line 876 of file tiny/tmp/OBTtinyxml.h.

Referenced by xmlTiny::TiXmlDocument::Print().

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

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

Definition at line 1217 of file tiny/tmp/OBTtinyxml.cpp.

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

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

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

Definition at line 883 of file tiny/tmp/OBTtinyxml.h.

References document.

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

00883 { document = doc; }

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


Friends And Related Function Documentation

friend class TiXmlAttributeSet [friend]

Definition at line 787 of file tiny/tmp/OBTtinyxml.h.


Member Data Documentation

TiXmlDocument* xmlTiny::TiXmlAttribute::document [private]

Definition at line 889 of file tiny/tmp/OBTtinyxml.h.

Referenced by SetDocument(), and TiXmlAttribute().

TIXML_STRING xmlTiny::TiXmlAttribute::name [private]

Definition at line 890 of file tiny/tmp/OBTtinyxml.h.

Referenced by xmlTiny::TiXmlAttributeSet::Find(), Name(), NameTStr(), Next(), operator<(), operator==(), operator>(), Parse(), Previous(), SetName(), and TiXmlAttribute().

TIXML_STRING xmlTiny::TiXmlAttribute::value [private]

Definition at line 891 of file tiny/tmp/OBTtinyxml.h.

Referenced by DoubleValue(), IntValue(), Next(), Parse(), Previous(), Print(), QueryDoubleValue(), QueryIntValue(), SetValue(), TiXmlAttribute(), Value(), and ValueStr().

TiXmlAttribute* xmlTiny::TiXmlAttribute::prev [private]

Definition at line 892 of file tiny/tmp/OBTtinyxml.h.

Referenced by xmlTiny::TiXmlAttributeSet::Add(), xmlTiny::TiXmlAttributeSet::Last(), Previous(), xmlTiny::TiXmlAttributeSet::Remove(), TiXmlAttribute(), xmlTiny::TiXmlAttributeSet::TiXmlAttributeSet(), and xmlTiny::TiXmlAttributeSet::~TiXmlAttributeSet().

TiXmlAttribute* xmlTiny::TiXmlAttribute::next [private]

Definition at line 893 of file tiny/tmp/OBTtinyxml.h.

Referenced by xmlTiny::TiXmlAttributeSet::Add(), xmlTiny::TiXmlAttributeSet::Find(), xmlTiny::TiXmlAttributeSet::First(), Next(), xmlTiny::TiXmlAttributeSet::Remove(), TiXmlAttribute(), xmlTiny::TiXmlAttributeSet::TiXmlAttributeSet(), and xmlTiny::TiXmlAttributeSet::~TiXmlAttributeSet().


Generated on Wed Oct 1 11:34:25 2008 for OBT by  doxygen 1.5.3