accessor methods support DateTime
This commit is contained in:
+43
-35
@@ -5,6 +5,8 @@
|
||||
#include <string>
|
||||
#include "RageFile.h"
|
||||
#include "RageLog.h"
|
||||
#include "RageUtil.h"
|
||||
#include "DateTime.h"
|
||||
|
||||
|
||||
static const TCHAR chXMLTagOpen = '<';
|
||||
@@ -633,22 +635,33 @@ bool XNode::GetXML( RageFile &f, LPDISP_OPT opt /*= &optDefault*/ )
|
||||
//--------------------------------------------------------
|
||||
// Coder Date Desc
|
||||
//========================================================
|
||||
void XNode::SetValue(int v)
|
||||
{
|
||||
value = ssprintf("%d",v);
|
||||
}
|
||||
void XNode::SetValue(float v)
|
||||
{
|
||||
value = ssprintf("%f",v);
|
||||
}
|
||||
void XNode::SetValue(bool v)
|
||||
{
|
||||
value = ssprintf("%d",v);
|
||||
}
|
||||
void XNode::SetValue(unsigned v)
|
||||
{
|
||||
value = ssprintf("%u",v);
|
||||
}
|
||||
void XNode::GetValue(CString &out) const { out = value; }
|
||||
void XNode::GetValue(int &out) const { out = atoi(value); }
|
||||
void XNode::GetValue(float &out) const { out = (float) atof(value); }
|
||||
void XNode::GetValue(bool &out) const { out = atoi(value) != 0; }
|
||||
void XNode::GetValue(unsigned &out) const { out = (unsigned)atoi(value) != 0; }
|
||||
void XNode::GetValue(DateTime &out) const { out.FromString( value ); }
|
||||
|
||||
void XAttr::GetValue(CString &out) const { out = value; }
|
||||
void XAttr::GetValue(int &out) const { out = atoi(value); }
|
||||
void XAttr::GetValue(float &out) const { out = (float) atof(value); }
|
||||
void XAttr::GetValue(bool &out) const { out = atoi(value) != 0; }
|
||||
void XAttr::GetValue(unsigned &out) const { out = (unsigned)atoi(value) != 0; }
|
||||
void XAttr::GetValue(DateTime &out) const { out.FromString( value ); }
|
||||
|
||||
//========================================================
|
||||
// Name : SetValue
|
||||
// Desc :
|
||||
// Param :
|
||||
// Return :
|
||||
//--------------------------------------------------------
|
||||
// Coder Date Desc
|
||||
//========================================================
|
||||
void XNode::SetValue(int v) { value = ssprintf("%d",v); }
|
||||
void XNode::SetValue(float v) { value = ssprintf("%f",v); }
|
||||
void XNode::SetValue(bool v) { value = ssprintf("%d",v); }
|
||||
void XNode::SetValue(unsigned v) { value = ssprintf("%u",v); }
|
||||
void XNode::SetValue(const DateTime &v) { value = v.GetString(); }
|
||||
|
||||
//========================================================
|
||||
// Name : GetAttr
|
||||
@@ -879,25 +892,11 @@ XNodes::iterator XNode::GetChildIterator( LPXNode node )
|
||||
// Coder Date Desc
|
||||
// bro 2002-10-29
|
||||
//========================================================
|
||||
LPXNode XNode::AppendChild( const char* name /*= NULL*/, const char* value /*= NULL*/ )
|
||||
{
|
||||
return AppendChild( CreateNode( name, value ) );
|
||||
}
|
||||
|
||||
LPXNode XNode::AppendChild( const char* name /*= NULL*/, float value /*= NULL*/ )
|
||||
{
|
||||
return AppendChild( name, ssprintf("%f",value) );
|
||||
}
|
||||
|
||||
LPXNode XNode::AppendChild( const char* name /*= NULL*/, int value /*= NULL*/ )
|
||||
{
|
||||
return AppendChild( name, ssprintf("%d",value) );
|
||||
}
|
||||
|
||||
LPXNode XNode::AppendChild( const char* name /*= NULL*/, unsigned value /*= NULL*/ )
|
||||
{
|
||||
return AppendChild( name, ssprintf("%u",value) );
|
||||
}
|
||||
LPXNode XNode::AppendChild( const char* name, const char* value ) { XNode *p = new XNode; p->name = name; p->value = value; return AppendChild( p ); }
|
||||
LPXNode XNode::AppendChild( const char* name, float value ) { XNode *p = new XNode; p->name = name; p->SetValue( value ); return AppendChild( p ); }
|
||||
LPXNode XNode::AppendChild( const char* name, int value ) { XNode *p = new XNode; p->name = name; p->SetValue( value ); return AppendChild( p ); }
|
||||
LPXNode XNode::AppendChild( const char* name, unsigned value ) { XNode *p = new XNode; p->name = name; p->SetValue( value ); return AppendChild( p ); }
|
||||
LPXNode XNode::AppendChild( const char* name, const DateTime &value ) { XNode *p = new XNode; p->name = name; p->SetValue( value ); return AppendChild( p ); }
|
||||
|
||||
//========================================================
|
||||
// Name : AppendChild
|
||||
@@ -1275,3 +1274,12 @@ bool XNode::SaveToFile( CString sFile, LPDISP_OPT opt )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool XIsEmptyString( const char* str )
|
||||
{
|
||||
CString s(str);
|
||||
TrimLeft( s );
|
||||
TrimRight( s );
|
||||
|
||||
return ( s.empty() || s == "" );
|
||||
}
|
||||
|
||||
+20
-19
@@ -20,7 +20,8 @@
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <vector>
|
||||
#include <RageUtil.h>
|
||||
struct DateTime;
|
||||
class RageFile;
|
||||
|
||||
struct XAttr;
|
||||
typedef XAttr* LPXAttr;
|
||||
@@ -104,11 +105,12 @@ struct XAttr
|
||||
{
|
||||
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; }
|
||||
void GetValue(unsigned &out) const { sscanf(value,"%u",&out); }
|
||||
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;
|
||||
|
||||
XNode* parent;
|
||||
|
||||
@@ -122,15 +124,17 @@ struct XNode
|
||||
// name and value
|
||||
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; }
|
||||
void GetValue(unsigned &out) const { out = (unsigned)atoi(value) != 0; }
|
||||
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
|
||||
LPXNode parent; // parent node
|
||||
@@ -154,6 +158,7 @@ struct XNode
|
||||
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; }
|
||||
XAttrs GetAttrs( const char* name );
|
||||
|
||||
// in one level child nodes
|
||||
@@ -165,6 +170,7 @@ struct XNode
|
||||
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; }
|
||||
XNodes GetChilds( const char* name );
|
||||
XNodes GetChilds();
|
||||
|
||||
@@ -180,6 +186,7 @@ struct XNode
|
||||
LPXNode AppendChild( const char* name, float value );
|
||||
LPXNode AppendChild( const char* name, int value );
|
||||
LPXNode AppendChild( const char* name, unsigned value );
|
||||
LPXNode AppendChild( const char* name, const DateTime &value );
|
||||
LPXNode AppendChild( LPXNode node );
|
||||
bool RemoveChild( LPXNode node );
|
||||
LPXNode DetachChild( LPXNode node );
|
||||
@@ -192,6 +199,7 @@ struct XNode
|
||||
LPXAttr AppendAttr( const char* name, float value );
|
||||
LPXAttr AppendAttr( const char* name, int value );
|
||||
LPXAttr AppendAttr( const char* name, unsigned value );
|
||||
LPXAttr AppendAttr( const char* name, const DateTime &value );
|
||||
LPXAttr AppendAttr( LPXAttr attr );
|
||||
bool RemoveAttr( LPXAttr attr );
|
||||
LPXAttr DetachAttr( LPXAttr attr );
|
||||
@@ -211,13 +219,6 @@ inline long XStr2Int( const char* str, long default_value = 0 )
|
||||
return str ? atol(str) : default_value;
|
||||
}
|
||||
|
||||
inline bool XIsEmptyString( const char* str )
|
||||
{
|
||||
CString s(str);
|
||||
TrimLeft( s );
|
||||
TrimRight( s );
|
||||
|
||||
return ( s.empty() || s == "" );
|
||||
}
|
||||
bool XIsEmptyString( const char* str );
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user