XmlFile.h
Go to the documentation of this file.00001
#ifndef XmlFile_H
00002
#define XmlFile_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00021
00022
#include <map>
00023
struct DateTime;
00024
class RageFileBasic;
00025
00026
struct XAttr;
00027 typedef multimap<CString,XAttr*>
XAttrs;
00028
struct XNode;
00029 typedef multimap<CString,XNode*>
XNodes;
00030
00031 #define FOREACH_Attr( pNode, Var ) \
00032
XAttrs::iterator Var##Iter; \
00033
XAttr *Var = NULL; \
00034
for( Var##Iter = (pNode)->m_attrs.begin(), Var = Var##Iter->second; \
00035
Var##Iter != (pNode)->m_attrs.end(); \
00036
++Var##Iter, Var = Var##Iter->second )
00037
00038 #define FOREACH_CONST_Attr( pNode, Var ) \
00039
XAttrs::const_iterator Var##Iter; \
00040
const XAttr *Var = NULL; \
00041
for( Var##Iter = (pNode)->m_attrs.begin(), Var = Var##Iter->second; \
00042
Var##Iter != (pNode)->m_attrs.end(); \
00043
++Var##Iter, Var = Var##Iter->second )
00044
00045 #define FOREACH_Child( pNode, Var ) \
00046
XNodes::iterator Var##Iter; \
00047
XNode *Var = NULL; \
00048
for( Var##Iter = (pNode)->m_childs.begin(), Var = Var##Iter->second; \
00049
Var##Iter != (pNode)->m_childs.end(); \
00050
++Var##Iter, Var = Var##Iter->second )
00051
00052 #define FOREACH_CONST_Child( pNode, Var ) \
00053
XNodes::const_iterator Var##Iter; \
00054
const XNode *Var = NULL; \
00055
for( Var##Iter = (pNode)->m_childs.begin(), Var = Var##Iter->second; \
00056
Var##Iter != (pNode)->m_childs.end(); \
00057
++Var##Iter, Var = Var##Iter->second )
00058
00059
00060
00061 struct XENTITY
00062 {
00063 char entity;
00064 char ref[10];
00065 int ref_len;
00066 };
00067
00068 struct XENTITYS :
public vector<XENTITY>
00069 {
00070
XENTITY *
GetEntity(
int entity );
00071
XENTITY *GetEntity(
char* entity );
00072
int GetEntityCount(
const char* str );
00073
int Ref2Entity(
const char* estr,
char* str,
int strlen );
00074
int Entity2Ref(
const char* str,
char* estr,
int estrlen );
00075
CString Ref2Entity(
const char* estr );
00076
CString Entity2Ref(
const char* str );
00077
00078 XENTITYS(){};
00079
XENTITYS(
XENTITY *entities,
int count );
00080 };
00081 extern XENTITYS entityDefault;
00082
CString XRef2Entity(
const char* estr );
00083
CString XEntity2Ref(
const char* str );
00084
00085 enum PCODE
00086 {
00087
PIE_PARSE_WELFORMED = 0,
00088
PIE_ALONE_NOT_CLOSED,
00089
PIE_NOT_CLOSED,
00090
PIE_NOT_NESTED,
00091
PIE_ATTR_NO_VALUE,
00092
PIE_READ_ERROR
00093 };
00094
00095
00096 struct PARSEINFO
00097 {
00098 bool trim_value;
00099 bool entity_value;
00100 XENTITYS *
entitys;
00101 char escape_value;
00102
00103 char*
xml;
00104 bool erorr_occur;
00105 char*
error_pointer;
00106 PCODE error_code;
00107 CString error_string;
00108
00109 PARSEINFO() {
trim_value =
true;
entity_value =
true;
entitys = &
entityDefault;
xml = NULL;
erorr_occur =
false;
error_pointer = NULL;
error_code =
PIE_PARSE_WELFORMED;
escape_value = 0; }
00110 };
00111 extern PARSEINFO piDefault;
00112
00113
00114 struct DISP_OPT
00115 {
00116 bool newline;
00117 bool reference_value;
00118 XENTITYS *
entitys;
00119 CString stylesheet;
00120 bool write_tabs;
00121
00122 int tab_base;
00123 DISP_OPT()
00124 {
00125
newline =
true;
00126
reference_value =
true;
00127
entitys = &
entityDefault;
00128
stylesheet =
"";
00129
write_tabs =
true;
00130
tab_base = 0;
00131 }
00132 };
00133 extern DISP_OPT optDefault;
00134
00135
00136 struct XAttr
00137 {
00138 CString m_sName;
00139 CString m_sValue;
00140
void GetValue(CString &out)
const;
00141
void GetValue(
int &out)
const;
00142
void GetValue(
float &out)
const;
00143
void GetValue(
bool &out)
const;
00144
void GetValue(
unsigned &out)
const;
00145
void GetValue(
DateTime &out)
const;
00146
00147
bool GetXML(
RageFileBasic &f,
DISP_OPT *opt = &optDefault );
00148 };
00149
00150
00151 struct XNode
00152 {
00153 CString m_sName;
00154 CString m_sValue;
00155
void GetValue(CString &out)
const;
00156
void GetValue(
int &out)
const;
00157
void GetValue(
float &out)
const;
00158
void GetValue(
bool &out)
const;
00159
void GetValue(
unsigned &out)
const;
00160
void GetValue(
DateTime &out)
const;
00161
void SetValue(
int v);
00162
void SetValue(
float v);
00163
void SetValue(
bool v);
00164
void SetValue(
unsigned v);
00165
void SetValue(
const DateTime &v);
00166
00167
00168 XNodes m_childs;
00169 XAttrs m_attrs;
00170
00171
00172
char*
Load(
const char* pszXml,
PARSEINFO *pi = &piDefault );
00173
char*
LoadAttributes(
const char* pszAttrs,
PARSEINFO *pi = &piDefault );
00174
bool GetXML(
RageFileBasic &f,
DISP_OPT *opt = &optDefault );
00175
00176
bool LoadFromFile(
const CString &sFile,
PARSEINFO *pi = &piDefault );
00177
bool LoadFromFile(
RageFileBasic &f,
PARSEINFO *pi = &piDefault );
00178
bool SaveToFile(
const CString &sFile,
DISP_OPT *opt = &optDefault );
00179
bool SaveToFile(
RageFileBasic &f,
DISP_OPT *opt = &optDefault );
00180
00181
00182
const XAttr *
GetAttr(
const char* attrname )
const;
00183
XAttr *GetAttr(
const char* attrname );
00184
const char*
GetAttrValue(
const char* attrname );
00185 bool GetAttrValue(
const char* name,CString &out)
const {
const XAttr* pAttr=GetAttr(
name);
if(pAttr==NULL)
return false; pAttr->
GetValue(out);
return true; }
00186 bool GetAttrValue(
const char* name,
int &out)
const {
const XAttr* pAttr=GetAttr(
name);
if(pAttr==NULL)
return false; pAttr->
GetValue(out);
return true; }
00187 bool GetAttrValue(
const char* name,
float &out)
const {
const XAttr* pAttr=GetAttr(
name);
if(pAttr==NULL)
return false; pAttr->
GetValue(out);
return true; }
00188 bool GetAttrValue(
const char* name,
bool &out)
const {
const XAttr* pAttr=GetAttr(
name);
if(pAttr==NULL)
return false; pAttr->
GetValue(out);
return true; }
00189 bool GetAttrValue(
const char* name,
unsigned &out)
const {
const XAttr* pAttr=GetAttr(
name);
if(pAttr==NULL)
return false; pAttr->
GetValue(out);
return true; }
00190 bool GetAttrValue(
const char* name,
DateTime &out)
const {
const XAttr* pAttr=GetAttr(
name);
if(pAttr==NULL)
return false; pAttr->
GetValue(out);
return true; }
00191
00192
00193
const XNode *GetChild(
const char* m_sName )
const;
00194
XNode *GetChild(
const char* m_sName );
00195
const char* GetChildValue(
const char* m_sName );
00196 bool GetChildValue(
const char* name,CString &out)
const {
const XNode* pChild=GetChild(
name);
if(pChild==NULL)
return false; pChild->
GetValue(out);
return true; }
00197 bool GetChildValue(
const char* name,
int &out)
const {
const XNode* pChild=GetChild(
name);
if(pChild==NULL)
return false; pChild->
GetValue(out);
return true; }
00198 bool GetChildValue(
const char* name,
float &out)
const {
const XNode* pChild=GetChild(
name);
if(pChild==NULL)
return false; pChild->
GetValue(out);
return true; }
00199 bool GetChildValue(
const char* name,
bool &out)
const {
const XNode* pChild=GetChild(
name);
if(pChild==NULL)
return false; pChild->
GetValue(out);
return true; }
00200 bool GetChildValue(
const char* name,
unsigned &out)
const{
const XNode* pChild=GetChild(
name);
if(pChild==NULL)
return false; pChild->
GetValue(out);
return true; }
00201 bool GetChildValue(
const char* name,
DateTime &out)
const{
const XNode* pChild=GetChild(
name);
if(pChild==NULL)
return false; pChild->
GetValue(out);
return true; }
00202
00203
XAttr *GetChildAttr(
const char* name,
const char* attrname );
00204
const char* GetChildAttrValue(
const char* name,
const char* attrname );
00205
00206
00207
int GetChildCount();
00208
XNode *AppendChild(
const char* m_sName = NULL,
const char* value = NULL );
00209
XNode *AppendChild(
const char* m_sName,
float value );
00210
XNode *AppendChild(
const char* m_sName,
int value );
00211
XNode *AppendChild(
const char* m_sName,
unsigned value );
00212
XNode *AppendChild(
const char* m_sName,
const DateTime &value );
00213
XNode *AppendChild(
XNode *node );
00214
bool RemoveChild(
XNode *node );
00215
00216
XAttr *AppendAttr(
const char* m_sName = NULL,
const char* value = NULL );
00217
XAttr *AppendAttr(
const char* m_sName,
float value );
00218
XAttr *AppendAttr(
const char* m_sName,
int value );
00219
XAttr *AppendAttr(
const char* m_sName,
unsigned value );
00220
XAttr *AppendAttr(
const char* m_sName,
const DateTime &value );
00221
XAttr *AppendAttr(
XAttr *attr );
00222
bool RemoveAttr(
XAttr *attr );
00223
00224
00225
void SetAttrValue(
const char* m_sName,
const char* value );
00226
00227 XNode() { }
00228
~XNode();
00229
00230
void Clear();
00231 };
00232
00233
00234 inline long XStr2Int(
const char* str,
long default_value = 0 )
00235 {
00236
return str ? atol(str) : default_value;
00237 }
00238
00239
bool XIsEmptyString(
const char* str );
00240
00241
#endif
Generated on Thu Jan 27 20:57:34 2005 for StepMania by
1.3.7