diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 91f3adce5d..f197df7d3a 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -1,8 +1,5 @@ #include "global.h" #include "XmlFile.h" -#include -#include -#include #include "RageFile.h" #include "RageLog.h" #include "RageUtil.h" @@ -11,6 +8,10 @@ #include "arch/Dialog/Dialog.h" #include "RageFileDriverMemory.h" +static inline long XStr2Int( const char* str, long default_value = 0 ) +{ + return str ? atol(str) : default_value; +} static const char chXMLTagOpen = '<'; static const char chXMLTagClose = '>'; @@ -42,18 +43,18 @@ static char* tcsskip( const char* psz ) // Name : tcsechr // Desc : similar with strchr with escape process // Param : escape - will be escape character -static char* tcsechr( const char* psz, int ch, int escape ) +static const char* tcsechr( const char* pch, int ch, char escape ) { - char* pch = (char*)psz; - char* prev_escape = NULL; + bool bInEscape = false; while( pch && *pch ) { - if( *pch == escape && prev_escape == NULL ) - prev_escape = pch; + if( *pch == escape && !bInEscape ) + bInEscape = true; else { - prev_escape = NULL; - if( *pch == ch ) return (char*)pch; + bInEscape = false; + if( *pch == ch ) + return pch; } pch++; } @@ -62,19 +63,17 @@ static char* tcsechr( const char* psz, int ch, int escape ) // Desc : similar with strlen with escape process // Param : escape - will be escape character -static int tcselen( int escape, const char *start, const char *end ) +static int tcselen( char escape, const char *start, const char *end ) { int len = 0; - if( end == NULL ) - end = (char*) sizeof(long); - const char *prev_escape = NULL; + bool bInEscape = false; while( start && *start && start= psz && isspace(end[-1]) ) + end--; } + int len = end - psz; - if( len <= 0 ) return; + if( len <= 0 ) + return; + if( escape ) { len = tcselen( escape, psz, end ); @@ -179,14 +183,8 @@ void XNode::Clear() // Param : pszAttrs - xml of attributes // pi = parser information // Return : advanced string pointer. (error return NULL) -//-------------------------------------------------------- -// Coder Date Desc -// bro 2002-10-29 -//======================================================== -char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault*/) +const char* XNode::LoadAttributes( const char* xml, PARSEINFO *pi /*= &piDefault*/) { - char* xml = (char*)pszAttrs; - while( xml && *xml ) { xml = tcsskip( xml ); @@ -199,7 +197,7 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault* return xml; // XML Attr Name - char* pEnd = strpbrk( xml, " =" ); + const char* pEnd = strpbrk( xml, " =" ); if( pEnd == NULL ) { // error @@ -278,16 +276,10 @@ char* XNode::LoadAttributes( const char* pszAttrs, PARSEINFO *pi /*= &piDefault* // Param : pszXml - plain xml text // pi = parser information // Return : advanced string pointer (error return NULL) -//-------------------------------------------------------- -// Coder Date Desc -// bro 2002-10-29 -//======================================================== -char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ ) +const char* XNode::Load( const char* xml, PARSEINFO *pi /*= &piDefault*/ ) { Clear(); - char* xml = (char*)pszXml; - // < xml = strchr( xml, chXMLTagOpen ); if( xml == NULL ) @@ -325,7 +317,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ ) // XML Node Tag Name Open xml++; - char* pTagEnd = strpbrk( xml, " \t\r\n/>" ); + const char* pTagEnd = strpbrk( xml, " \t\r\n/>" ); SetString( xml, pTagEnd, &m_sName ); xml = pTagEnd; @@ -345,20 +337,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ ) if( *xml == chXMLDash ) xml++; - if( *xml == chXMLTagClose ) - { - // well-formed tag - ++xml; - - // UGLY: We want to ignore all XML meta tags. So, since the Node we - // just loaded is a meta tag, then Load ourself again using the rest - // of the file until we reach a non-meta tag. - if( !m_sName.empty() && (m_sName[0] == chXMLQuestion || m_sName[0] == chXMLExclamation) ) - xml = Load( xml, pi ); - - return xml; - } - else + if( *xml != chXMLTagClose ) { // error: if( !pi->error_occur ) @@ -366,22 +345,84 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ ) pi->error_occur = true; pi->error_pointer = xml; pi->error_code = PIE_ALONE_NOT_CLOSED; - pi->error_string = ("Element must be closed."); + pi->error_string = "Element must be closed."; } - // not wel-formed tag + + // ill-formed tag return NULL; } + + // well-formed tag + ++xml; + + // UGLY: We want to ignore all XML meta tags. So, since the Node we + // just loaded is a meta tag, then Load ourself again using the rest + // of the file until we reach a non-meta tag. + if( !m_sName.empty() && (m_sName[0] == chXMLQuestion || m_sName[0] == chXMLExclamation) ) + xml = Load( xml, pi ); + + return xml; } - else + // open/close tag ... // ^- current pointer + if( XIsEmptyString( m_sValue ) ) { - // text value EֵѴ. - //if( this->m_sValue.empty() || this->m_sValue == ("") ) - if( XIsEmptyString( m_sValue ) ) + // Text Value + const char* pEnd = tcsechr( ++xml, chXMLTagOpen, chXMLEscape ); + if( pEnd == NULL ) { - // Text Value - char* pEnd = tcsechr( ++xml, chXMLTagOpen, chXMLEscape ); + if( !pi->error_occur ) + { + pi->error_occur = true; + pi->error_pointer = xml; + pi->error_code = PIE_NOT_CLOSED; + pi->error_string = ssprintf( "%s must be closed with ", m_sName.c_str(), m_sName.c_str() ); + } + // error cos not exist CloseTag + return NULL; + } + + bool trim = pi->trim_value; + char escape = pi->escape_value; + SetString( xml, pEnd, &m_sValue, trim, escape ); + + xml = pEnd; + // TEXTVALUE reference + if( pi->entity_value && pi->entitys ) + m_sValue = pi->entitys->Ref2Entity(m_sValue); + } + + // generate child nodes + while( xml && *xml ) + { + XNode *node = new XNode; + + xml = node->Load( xml,pi ); + if( !node->m_sName.empty() ) + { + DEBUG_ASSERT( node->m_sName.size() ); + m_childs.insert( make_pair(node->m_sName, node) ); + } + else + { + delete node; + } + + // open/close tag ... + // ^- current pointer + // CloseTag case + if( xml && *xml && *(xml+1) && *xml == chXMLTagOpen && *(xml+1) == chXMLTagPre ) + { + // + xml+=2; // C + + xml = tcsskip( xml ); + if( xml == NULL ) + return NULL; + + CString closename; + const char* pEnd = strpbrk( xml, " >" ); if( pEnd == NULL ) { if( !pi->error_occur ) @@ -389,120 +430,61 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ ) pi->error_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_CLOSED; - pi->error_string = ssprintf( "%s must be closed with ", m_sName.c_str(), m_sName.c_str() ); + pi->error_string = ssprintf( "it must be closed with ", m_sName.c_str() ); } - // error cos not exist CloseTag + // error return NULL; } - - bool trim = pi->trim_value; - char escape = pi->escape_value; - //SetString( xml, pEnd, &m_sValue, trim, chXMLEscape ); - SetString( xml, pEnd, &m_sValue, trim, escape ); - - xml = pEnd; - // TEXTVALUE reference - if( pi->entity_value && pi->entitys ) - m_sValue = pi->entitys->Ref2Entity(m_sValue); - } - - // generate child nodes - while( xml && *xml ) - { - XNode *node = new XNode; - - xml = node->Load( xml,pi ); - if( !node->m_sName.empty() ) + SetString( xml, pEnd, &closename ); + if( closename == this->m_sName ) { - DEBUG_ASSERT( node->m_sName.size() ); - m_childs.insert( make_pair(node->m_sName, node) ); + // wel-formed open/close + xml = pEnd+1; + // return '>' or ' ' after pointer + return xml; } else { - delete node; + xml = pEnd+1; + // not welformed open/close + if( !pi->error_occur ) + { + pi->error_occur = true; + pi->error_pointer = xml; + pi->error_code = PIE_NOT_NESTED; + pi->error_string = ssprintf( "'<%s> ... ' is not well-formed.", m_sName.c_str(), closename.c_str() ); + + } + return NULL; } - - // open/close tag ... - // ^- current pointer - // CloseTag case - if( xml && *xml && *(xml+1) && *xml == chXMLTagOpen && *(xml+1) == chXMLTagPre ) + } + else // Alone child Tag Loaded + { + if( xml && XIsEmptyString( m_sValue ) && *xml !=chXMLTagOpen ) { - // - xml+=2; // C - - xml = tcsskip( xml ); - if( xml == NULL ) - return NULL; - - CString closename; - char* pEnd = strpbrk( xml, " >" ); + // Text Value + const char* pEnd = tcsechr( xml, chXMLTagOpen, chXMLEscape ); if( pEnd == NULL ) { - if( !pi->error_occur ) + // error cos not exist CloseTag + if( !pi->error_occur ) { pi->error_occur = true; pi->error_pointer = xml; pi->error_code = PIE_NOT_CLOSED; pi->error_string = ssprintf( "it must be closed with ", m_sName.c_str() ); } - // error return NULL; } - SetString( xml, pEnd, &closename ); - if( closename == this->m_sName ) - { - // wel-formed open/close - xml = pEnd+1; - // return '>' or ' ' after pointer - return xml; - } - else - { - xml = pEnd+1; - // not welformed open/close - if( !pi->error_occur ) - { - pi->error_occur = true; - pi->error_pointer = xml; - pi->error_code = PIE_NOT_NESTED; - pi->error_string = ssprintf( "'<%s> ... ' is not well-formed.", m_sName.c_str(), closename.c_str() ); - - } - return NULL; - } - } - else // Alone child Tag Loaded - // else ؾϴEƾϴEǽɰ. - { - //if( xml && this->m_sValue.empty() && *xml !=chXMLTagOpen ) - if( xml && XIsEmptyString( m_sValue ) && *xml !=chXMLTagOpen ) - { - // Text Value - char* pEnd = tcsechr( xml, chXMLTagOpen, chXMLEscape ); - if( pEnd == NULL ) - { - // error cos not exist CloseTag - if( !pi->error_occur ) - { - pi->error_occur = true; - pi->error_pointer = xml; - pi->error_code = PIE_NOT_CLOSED; - pi->error_string = ssprintf( "it must be closed with ", m_sName.c_str() ); - } - return NULL; - } - - bool trim = pi->trim_value; - char escape = pi->escape_value; - //SetString( xml, pEnd, &m_sValue, trim, chXMLEscape ); - SetString( xml, pEnd, &m_sValue, trim, escape ); + bool trim = pi->trim_value; + char escape = pi->escape_value; + SetString( xml, pEnd, &m_sValue, trim, escape ); - xml = pEnd; - //TEXTVALUE - if( pi->entity_value && pi->entitys ) - m_sValue = pi->entitys->Ref2Entity(m_sValue); - } + xml = pEnd; + //TEXTVALUE + if( pi->entity_value && pi->entitys ) + m_sValue = pi->entitys->Ref2Entity(m_sValue); } } } @@ -524,9 +506,8 @@ bool XNode::GetXML( RageFileBasic &f, DISP_OPT *opt ) const // tab if( opt && opt->newline ) { - if( opt && opt->newline ) - if( f.Write("\r\n") == -1 ) - return false; + if( f.Write("\r\n") == -1 ) + return false; if( opt->write_tabs ) for( int i = 0 ; i < opt->tab_base ; i++) if( f.Write("\t") == -1 ) @@ -614,27 +595,27 @@ CString XNode::GetXML() const return f.GetString(); } -void XNode::GetValue(CString &out) const { out = m_sValue; } -void XNode::GetValue(int &out) const { out = atoi(m_sValue); } -void XNode::GetValue(float &out) const { out = strtof(m_sValue, NULL); } -void XNode::GetValue(bool &out) const { out = atoi(m_sValue) != 0; } -void XNode::GetValue(unsigned &out) const { out = 0; sscanf(m_sValue,"%u",&out); } -void XNode::GetValue(DateTime &out) const { out.FromString( m_sValue ); } +void XNode::GetValue( CString &out ) const { out = m_sValue; } +void XNode::GetValue( int &out ) const { out = atoi(m_sValue); } +void XNode::GetValue( float &out ) const { out = strtof(m_sValue, NULL); } +void XNode::GetValue( bool &out ) const { out = atoi(m_sValue) != 0; } +void XNode::GetValue( unsigned &out ) const { out = 0; sscanf(m_sValue,"%u",&out); } +void XNode::GetValue( DateTime &out ) const { out.FromString( m_sValue ); } -void XAttr::GetValue(CString &out) const { out = m_sValue; } -void XAttr::GetValue(int &out) const { out = atoi(m_sValue); } -void XAttr::GetValue(float &out) const { out = strtof(m_sValue, NULL); } -void XAttr::GetValue(bool &out) const { out = atoi(m_sValue) != 0; } -void XAttr::GetValue(unsigned &out) const { out = 0; sscanf(m_sValue,"%u",&out); } -void XAttr::GetValue(DateTime &out) const { out.FromString( m_sValue ); } +void XAttr::GetValue( CString &out ) const { out = m_sValue; } +void XAttr::GetValue( int &out ) const { out = atoi(m_sValue); } +void XAttr::GetValue( float &out ) const { out = strtof(m_sValue, NULL); } +void XAttr::GetValue( bool &out ) const { out = atoi(m_sValue) != 0; } +void XAttr::GetValue( unsigned &out ) const { out = 0; sscanf(m_sValue,"%u",&out); } +void XAttr::GetValue( DateTime &out ) const { out.FromString( m_sValue ); } -void XNode::SetValue(int v) { m_sValue = ssprintf("%d",v); } -void XNode::SetValue(float v) { m_sValue = ssprintf("%f",v); } -void XNode::SetValue(bool v) { m_sValue = ssprintf("%d",v); } -void XNode::SetValue(unsigned v) { m_sValue = ssprintf("%u",v); } -void XNode::SetValue(const DateTime &v) { m_sValue = v.GetString(); } +void XNode::SetValue( int v ) { m_sValue = ssprintf("%d",v); } +void XNode::SetValue( float v ) { m_sValue = ssprintf("%f",v); } +void XNode::SetValue( bool v ) { m_sValue = ssprintf("%d",v); } +void XNode::SetValue( unsigned v ) { m_sValue = ssprintf("%u",v); } +void XNode::SetValue( const DateTime &v ) { m_sValue = v.GetString(); } -const XAttr *XNode::GetAttr( const char* attrname ) const +const XAttr *XNode::GetAttr( const CString &attrname ) const { multimap::const_iterator it = m_attrs.find( attrname ); if( it != m_attrs.end() ) @@ -645,7 +626,7 @@ const XAttr *XNode::GetAttr( const char* attrname ) const return NULL; } -XAttr *XNode::GetAttr( const char* attrname ) +XAttr *XNode::GetAttr( const CString &attrname ) { multimap::iterator it = m_attrs.find( attrname ); if( it != m_attrs.end() ) @@ -657,7 +638,7 @@ XAttr *XNode::GetAttr( const char* attrname ) } // Desc : get attribute with attribute name, return its value -const char* XNode::GetAttrValue( const char* attrname ) +const char* XNode::GetAttrValue( const CString &attrname ) { XAttr *attr = GetAttr( attrname ); return attr ? (const char*)attr->m_sValue : NULL; @@ -665,7 +646,7 @@ const char* XNode::GetAttrValue( const char* attrname ) // get child node count -int XNode::GetChildCount() +int XNode::GetChildCount() const { return m_childs.size(); } @@ -807,12 +788,12 @@ XENTITY *XENTITYS::GetEntity( int entity ) return NULL; } -XENTITY *XENTITYS::GetEntity( char* entity ) +XENTITY *XENTITYS::GetEntity( const char* entity ) { for( unsigned i = 0 ; i < size(); i ++ ) { - char* ref = (char*)at(i).ref; - char* ps = entity; + const char* ref = at(i).ref; + const char* ps = entity; while( ref && *ref ) if( *ref++ != *ps++ ) break; @@ -825,17 +806,16 @@ XENTITY *XENTITYS::GetEntity( char* entity ) int XENTITYS::GetEntityCount( const char* str ) { int nCount = 0; - char* ps = (char*)str; - while( ps && *ps ) - if( GetEntity( *ps++ ) ) nCount ++; + while( str && *str ) + if( GetEntity(*str++) ) + ++nCount; return nCount; } -int XENTITYS::Ref2Entity( const char* estr, char* str, int strlen ) +int XENTITYS::Ref2Entity( const char* pes, char* str, int len ) { - char* pes = (char*)estr; char* ps = str; - char* ps_end = ps+strlen; + char* ps_end = ps+len; while( pes && *pes && ps < ps_end ) { XENTITY *ent = GetEntity( pes ); @@ -855,9 +835,8 @@ int XENTITYS::Ref2Entity( const char* estr, char* str, int strlen ) return ps-str; } -int XENTITYS::Entity2Ref( const char* str, char* estr, int estrlen ) +int XENTITYS::Entity2Ref( const char* ps, char* estr, int estrlen ) { - char* ps = (char*)str; char* pes = (char*)estr; char* pes_end = pes+estrlen; while( ps && *ps && pes < pes_end ) @@ -866,7 +845,7 @@ int XENTITYS::Entity2Ref( const char* str, char* estr, int estrlen ) if( ent ) { // copy entity string - char* ref = (char*)ent->ref; + const char* ref = ent->ref; while( ref && *ref ) *pes++ = *ref++; } @@ -907,8 +886,7 @@ CString XENTITYS::Entity2Ref( const char* str ) int len = strlen(str) + nEntityCount*10 ; //char* sbuf = s.GetBufferSetLength( len+1 ); char* szTemp = new char[len+1]; - if( szTemp ) - Entity2Ref( str, szTemp, len ); + Entity2Ref( str, szTemp, len ); s = szTemp; delete [] szTemp; } diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index 00e85f6ebb..0144e0e30b 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -68,7 +68,7 @@ struct XENTITY struct XENTITYS : public vector { XENTITY *GetEntity( int entity ); - XENTITY *GetEntity( char* entity ); + XENTITY *GetEntity( const char* entity ); int GetEntityCount( const char* str ); int Ref2Entity( const char* estr, char* str, int strlen ); int Entity2Ref( const char* str, char* estr, int estrlen ); @@ -102,7 +102,7 @@ struct PARSEINFO char* xml; // [get] xml source bool error_occur; // [get] is occurance of error? - char* error_pointer; // [get] error position of xml source + const char* error_pointer; // [get] error position of xml source PCODE error_code; // [get] error code CString error_string; // [get] error string @@ -135,12 +135,12 @@ struct XAttr { CString m_sName; // a duplicate of the m_sName in the parent's map CString m_sValue; - void GetValue(CString &out) const; - void GetValue(int &out) const; - void GetValue(float &out) const; - void GetValue(bool &out) const; - void GetValue(unsigned &out) const; - void GetValue(DateTime &out) const; + void GetValue( CString &out ) const; + void GetValue( int &out ) const; + void GetValue( float &out ) const; + void GetValue( bool &out ) const; + void GetValue( unsigned &out ) const; + void GetValue( DateTime &out ) const; bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const; }; @@ -150,25 +150,24 @@ struct XNode { CString m_sName; // a duplicate of the m_sName in the parent's map CString m_sValue; - void GetValue(CString &out) const; - void GetValue(int &out) const; - void GetValue(float &out) const; - void GetValue(bool &out) const; - void GetValue(unsigned &out) const; - void GetValue(DateTime &out) const; - void SetValue(int v); - void SetValue(float v); - void SetValue(bool v); - void SetValue(unsigned v); - void SetValue(const DateTime &v); - - // internal variables XNodes m_childs; // child node XAttrs m_attrs; // attributes + void GetValue( CString &out ) const; + void GetValue( int &out ) const; + void GetValue( float &out ) const; + void GetValue( bool &out ) const; + void GetValue( unsigned &out ) const; + void GetValue( DateTime &out ) const; + void SetValue( int v ); + void SetValue( float v ); + void SetValue( bool v ); + void SetValue( unsigned v ); + void SetValue( const DateTime &v ); + // Load/Save XML - char* Load( const char* pszXml, PARSEINFO *pi ); - char* LoadAttributes( const char* pszAttrs, PARSEINFO *pi ); + const char *Load( const char* pszXml, PARSEINFO *pi ); + const char *LoadAttributes( const char* pszAttrs, PARSEINFO *pi ); bool GetXML( RageFileBasic &f, DISP_OPT *opt ) const; CString GetXML() const; @@ -178,47 +177,47 @@ struct XNode bool SaveToFile( RageFileBasic &f, DISP_OPT *opt ) const; // in own attribute list - const XAttr *GetAttr( const char* attrname ) const; - XAttr *GetAttr( const char* attrname ); - const char* GetAttrValue( const char* attrname ); - bool GetAttrValue(const char* name,CString &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } - bool GetAttrValue(const char* name,int &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } - bool GetAttrValue(const char* name,float &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } - bool GetAttrValue(const char* name,bool &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } - bool GetAttrValue(const char* name,unsigned &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } - bool GetAttrValue(const char* name,DateTime &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } + const XAttr *GetAttr( const CString &attrname ) const; + XAttr *GetAttr( const CString &attrname ); + const char* GetAttrValue( const CString &attrname ); + bool GetAttrValue( const char* name, CString &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } + bool GetAttrValue( const char* name, int &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } + bool GetAttrValue( const char* name, float &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } + bool GetAttrValue( const char* name, bool &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } + bool GetAttrValue( const char* name, unsigned &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } + bool GetAttrValue( const char* name, DateTime &out ) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } // in one level child nodes const XNode *GetChild( const char* m_sName ) const; XNode *GetChild( const char* m_sName ); const char* GetChildValue( const char* m_sName ); - bool GetChildValue(const char* name,CString &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue(const char* name,int &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue(const char* name,float &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue(const char* name,bool &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue(const char* name,unsigned &out) const{ const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } - bool GetChildValue(const char* name,DateTime &out) const{ const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const char* name, CString &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const char* name, int &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const char* name, float &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const char* name, bool &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const char* name, unsigned &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue( const char* name, DateTime &out ) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } XAttr *GetChildAttr( const char* name, const char* attrname ); const char* GetChildAttrValue( const char* name, const char* attrname ); // modify DOM - int GetChildCount(); - XNode *AppendChild( const char* m_sName = NULL, const char* value = NULL ); - XNode *AppendChild( const char* m_sName, float value ); - XNode *AppendChild( const char* m_sName, int value ); - XNode *AppendChild( const char* m_sName, unsigned value ); - XNode *AppendChild( const char* m_sName, const DateTime &value ); - XNode *AppendChild( XNode *node ); - bool RemoveChild( XNode *node ); + int GetChildCount() const; + XNode *AppendChild( const char* m_sName = NULL, const char* value = NULL ); + XNode *AppendChild( const char* m_sName, float value ); + XNode *AppendChild( const char* m_sName, int value ); + XNode *AppendChild( const char* m_sName, unsigned value ); + XNode *AppendChild( const char* m_sName, const DateTime &value ); + XNode *AppendChild( XNode *node ); + bool RemoveChild( XNode *node ); XAttr *AppendAttr( const char* m_sName = NULL, const char* value = NULL ); XAttr *AppendAttr( const char* m_sName, float value ); XAttr *AppendAttr( const char* m_sName, int value ); XAttr *AppendAttr( const char* m_sName, unsigned value ); XAttr *AppendAttr( const char* m_sName, const DateTime &value ); - XAttr *AppendAttr( XAttr *attr ); - bool RemoveAttr( XAttr *attr ); + XAttr *AppendAttr( XAttr *attr ); + bool RemoveAttr( XAttr *attr ); // creates the attribute if it doesn't already exist void SetAttrValue( const char* m_sName, const char* value ); @@ -229,10 +228,4 @@ struct XNode void Clear(); }; -// Helper Funtion -inline long XStr2Int( const char* str, long default_value = 0 ) -{ - return str ? atol(str) : default_value; -} - #endif