CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

TiXmlAttribute Class Reference

#include <tinyxml.h>

Inheritance diagram for TiXmlAttribute:
TiXmlBase

List of all members.

Public Member Functions

double DoubleValue () const
 Return the value of this attribute, converted to a double.
int IntValue () const
 Return the value of this attribute, converted to an integer.
const char * Name () const
 Return the name of this attribute.
const TIXML_STRING & NameTStr () const
const TiXmlAttributeNext () const
 Get the next sibling attribute in the DOM. Returns null at end.
TiXmlAttributeNext ()
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.
void Print (FILE *cfile, int depth, TIXML_STRING *str) const
virtual void Print (FILE *cfile, int depth) const
int QueryDoubleValue (double *_value) const
 QueryDoubleValue examines the value string. See QueryIntValue().
int QueryIntValue (int *_value) const
void SetDocument (TiXmlDocument *doc)
void SetDoubleValue (double _value)
 Set the value from a double.
void SetIntValue (int _value)
 Set the value from an integer.
void SetName (const char *_name)
 Set the name of this attribute.
void SetName (const std::string &_name)
 STL std::string form.
void SetValue (const char *_value)
 Set the value.
void SetValue (const std::string &_value)
 STL std::string form.
 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 * Value () const
 Return the value of this attribute.
const std::string & ValueStr () const
 Return the value of this attribute.

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

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


Constructor & Destructor Documentation

TiXmlAttribute::TiXmlAttribute ( ) [inline]

Construct an empty attribute.

Definition at line 787 of file tinyxml.h.

References document, next, and prev.

                         : TiXmlBase()
        {
                document = 0;
                prev = next = 0;
        }
TiXmlAttribute::TiXmlAttribute ( const std::string &  _name,
const std::string &  _value 
) [inline]

std::string constructor.

Definition at line 795 of file tinyxml.h.

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

        {
                name = _name;
                value = _value;
                document = 0;
                prev = next = 0;
        }
TiXmlAttribute::TiXmlAttribute ( const char *  _name,
const char *  _value 
) [inline]

Construct an attribute with a name and value.

Definition at line 805 of file tinyxml.h.

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

        {
                name = _name;
                value = _value;
                document = 0;
                prev = next = 0;
        }
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 1283 of file tinyxml.cc.

References value.

{
        return atof (value.c_str ());
}
int TiXmlAttribute::IntValue ( ) const

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

Definition at line 1278 of file tinyxml.cc.

References value.

{
        return atoi (value.c_str ());
}
const char* TiXmlAttribute::Name ( ) const [inline]

Return the name of this attribute.

Definition at line 813 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 822 of file tinyxml.h.

References name.

Referenced by TiXmlElement::Parse().

{ return name; }
TiXmlAttribute* TiXmlAttribute::Next ( ) [inline]

Definition at line 852 of file tinyxml.h.

                               {
                return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() );
        }
const TiXmlAttribute * TiXmlAttribute::Next ( ) const

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

Definition at line 1176 of file tinyxml.cc.

References name, next, and value.

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

{
        // We are using knowledge of the sentinel. The sentinel
        // have a value or name.
        if ( next->value.empty() && next->name.empty() )
                return 0;
        return next;
}
bool TiXmlAttribute::operator< ( const TiXmlAttribute rhs) const [inline]

Definition at line 863 of file tinyxml.h.

References name.

{ return name < rhs.name; }
void TiXmlAttribute::operator= ( const TiXmlAttribute base) [private]
bool TiXmlAttribute::operator== ( const TiXmlAttribute rhs) const [inline]

Definition at line 862 of file tinyxml.h.

References name.

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

Definition at line 864 of file tinyxml.h.

References name.

{ return name > rhs.name; }
const char * TiXmlAttribute::Parse ( const char *  p,
TiXmlParsingData data,
TiXmlEncoding  encoding 
) [virtual]

Implements TiXmlBase.

Definition at line 1394 of file tinyxmlparser.cc.

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

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

{
        p = SkipWhiteSpace( p, encoding );
        if ( !p || !*p ) return 0;

//      int tabsize = 4;
//      if ( document )
//              tabsize = document->TabSize();

        if ( data )
        {
                data->Stamp( p, encoding );
                location = data->Cursor();
        }
        // Read the name, the '=' and the value.
        const char* pErr = p;
        p = ReadName( p, &name, encoding );
        if ( !p || !*p )
        {
                if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
                return 0;
        }
        p = SkipWhiteSpace( p, encoding );
        if ( !p || !*p || *p != '=' )
        {
                if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
                return 0;
        }

        ++p;    // skip '='
        p = SkipWhiteSpace( p, encoding );
        if ( !p || !*p )
        {
                if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
                return 0;
        }

        const char* end;
        const char SINGLE_QUOTE = '\'';
        const char DOUBLE_QUOTE = '\"';

        if ( *p == SINGLE_QUOTE )
        {
                ++p;
                end = "\'";             // single quote in string
                p = ReadText( p, &value, false, end, false, encoding );
        }
        else if ( *p == DOUBLE_QUOTE )
        {
                ++p;
                end = "\"";             // double quote in string
                p = ReadText( p, &value, false, end, false, encoding );
        }
        else
        {
                // All attribute values should be in single or double quotes.
                // But this is such a common error that the parser will try
                // its best, even without them.
                value = "";
                while (    p && *p                                                                                      // existence
                                && !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r'      // whitespace
                                && *p != '/' && *p != '>' )                                                     // tag end
                {
                        if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) {
                                // [ 1451649 ] Attribute values with trailing quotes not handled correctly
                                // We did not have an opening quote but seem to have a
                                // closing one. Give up and throw an error.
                                if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding );
                                return 0;
                        }
                        value += *p;
                        ++p;
                }
        }
        return p;
}
const TiXmlAttribute * TiXmlAttribute::Previous ( ) const

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

Definition at line 1196 of file tinyxml.cc.

References name, prev, and value.

{
        // We are using knowledge of the sentinel. The sentinel
        // have a value or name.
        if ( prev->value.empty() && prev->name.empty() )
                return 0;
        return prev;
}
TiXmlAttribute* TiXmlAttribute::Previous ( ) [inline]

Definition at line 858 of file tinyxml.h.

                                   {
                return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() );
        }
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 872 of file tinyxml.h.

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

                                                           {
                Print( cfile, depth, 0 );
        }
void TiXmlAttribute::Print ( FILE *  cfile,
int  depth,
TIXML_STRING *  str 
) const

Definition at line 1216 of file tinyxml.cc.

References TiXmlBase::EncodeString(), n, TIXML_STRING, v, and value.

{
        TIXML_STRING n, v;

        EncodeString( name, &n );
        EncodeString( value, &v );

        if (value.find ('\"') == TIXML_STRING::npos) {
                if ( cfile ) {
                fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() );
                }
                if ( str ) {
                        (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
                }
        }
        else {
                if ( cfile ) {
                fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() );
                }
                if ( str ) {
                        (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
                }
        }
}
int TiXmlAttribute::QueryDoubleValue ( double *  _value) const

QueryDoubleValue examines the value string. See QueryIntValue().

Definition at line 1249 of file tinyxml.cc.

References TIXML_SSCANF, TIXML_SUCCESS, TIXML_WRONG_TYPE, and value.

Referenced by TiXmlElement::QueryDoubleAttribute().

{
        if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 )
                return TIXML_SUCCESS;
        return TIXML_WRONG_TYPE;
}
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 1242 of file tinyxml.cc.

References TIXML_SSCANF, TIXML_SUCCESS, TIXML_WRONG_TYPE, and value.

Referenced by TiXmlElement::QueryIntAttribute().

{
        if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 )
                return TIXML_SUCCESS;
        return TIXML_WRONG_TYPE;
}
void TiXmlAttribute::SetDocument ( TiXmlDocument doc) [inline]

Definition at line 879 of file tinyxml.h.

References asciidump::doc, and document.

Referenced by TiXmlElement::Parse().

{ document = doc; }
void TiXmlAttribute::SetDoubleValue ( double  _value)

Set the value from a double.

Definition at line 1267 of file tinyxml.cc.

References SetValue().

{
        char buf [256];
        #if defined(TIXML_SNPRINTF)
                TIXML_SNPRINTF( buf, sizeof(buf), "%f", _value);
        #else
                sprintf (buf, "%f", _value);
        #endif
        SetValue (buf);
}
void TiXmlAttribute::SetIntValue ( int  _value)

Set the value from an integer.

Definition at line 1256 of file tinyxml.cc.

References SetValue().

{
        char buf [64];
        #if defined(TIXML_SNPRINTF)
                TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value);
        #else
                sprintf (buf, "%d", _value);
        #endif
        SetValue (buf);
}
void TiXmlAttribute::SetName ( const std::string &  _name) [inline]

STL std::string form.

Definition at line 845 of file tinyxml.h.

References name.

{ name = _name; }
void TiXmlAttribute::SetName ( const char *  _name) [inline]

Set the name of this attribute.

Definition at line 837 of file tinyxml.h.

References name.

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

STL std::string form.

Definition at line 847 of file tinyxml.h.

References value.

{ value = _value; }
void TiXmlAttribute::SetValue ( const char *  _value) [inline]

Set the value.

Definition at line 838 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 814 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 816 of file tinyxml.h.

References value.

Referenced by TiXmlElement::QueryValueAttribute().


Friends And Related Function Documentation

friend class TiXmlAttributeSet [friend]

Definition at line 783 of file tinyxml.h.


Member Data Documentation

Definition at line 885 of file tinyxml.h.

Referenced by SetDocument(), and TiXmlAttribute().

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