add better accessors for attributes

This commit is contained in:
Glenn Maynard
2004-02-22 05:12:23 +00:00
parent 721f29c458
commit 0188f51f4e
2 changed files with 23 additions and 0 deletions
+14
View File
@@ -650,6 +650,20 @@ CString _tagXMLNode::GetXML( LPDISP_OPT opt /*= &optDefault*/ )
// Coder Date Desc
// bro 2002-10-29
//========================================================
const LPXAttr _tagXMLNode::GetAttr( LPCTSTR attrname ) const
{
for( unsigned i = 0 ; i < attrs.size(); i++ )
{
LPXAttr attr = attrs[i];
if( attr )
{
if( attr->name == attrname )
return attr;
}
}
return NULL;
}
LPXAttr _tagXMLNode::GetAttr( LPCTSTR attrname )
{
for( unsigned i = 0 ; i < attrs.size(); i++ )
+9
View File
@@ -111,6 +111,10 @@ typedef struct _tagXMLAttr
{
CString name;
CString value;
void GetValue(CString &out) const { out = value; }
void GetValue(int &out) const { out = atoi(value); }
void GetValue(float &out) const { out = (float) atof(value); }
void GetValue(bool &out) const { out = atoi(value) != 0; }
_tagXMLNode* parent;
@@ -142,8 +146,13 @@ typedef struct _tagXMLNode
bool SaveToFile( CString sFile, LPDISP_OPT opt = &optDefault );
// in own attribute list
const LPXAttr GetAttr( LPCTSTR attrname ) const;
LPXAttr GetAttr( LPCTSTR attrname );
LPCTSTR GetAttrValue( LPCTSTR attrname );
bool GetAttrValue(LPCTSTR name,CString &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue(LPCTSTR name,int &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue(LPCTSTR name,float &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
bool GetAttrValue(LPCTSTR name,bool &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; }
XAttrs GetAttrs( LPCTSTR name );
// in one level child nodes