См. документацию.00001 #include <string>
00002
00003 #include "BaseConfigFile.h"
00004
00005
00006
00007 #include <stdio.h>
00008 string BaseConfigFile::xfCharToStr(xfChar* str){
00009
00010
00011 wstring ws = str;
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 string sss(ws.begin(), ws.end());
00030 return sss;
00031 }
00032
00033 long int BaseConfigFile::xfCharToInt(xfChar* str){
00034 return xfDecToInt(str);
00035 }
00036
00037 long int BaseConfigFile::getAttrInt(xfNode* node, long int defval){
00038 if(node==NULL){return defval;}
00039 return xfCharToInt(xfGet(node));
00040 }
00041
00042 string BaseConfigFile::getAttrString(xfNode* node, string defval){
00043 if(node==NULL){return defval;}
00044 return xfCharToStr(xfGet(node));
00045 }
00046
00047 BaseConfigFile::BaseConfigFile(char* filename){
00048 xfStart();
00049 conf=xfCreate();
00050
00051 int r = xfReadFile(conf,filename);
00052
00053 if (r) {
00054 if (r == XFE_IO) printf("xflib_conf: cannot open file '%s'\n",filename);
00055 if (r == XFE_MEMORY) printf("xflib_conf: not enough memory\n");
00056 if (r == XFE_FORMAT) {
00057 printf("xflib_conf: error parsing file '%s': %S (line %ld col %ld)\n",
00058 filename,xfGetError(conf),xfGetErrorLine(conf),xfGetErrorCol(conf));
00059 }
00060 xfDestroy(conf);
00061 exit(1);
00062 }
00063 root=xfEnter(conf->root,L"conf");
00064 moduledata_node=xfEnter(root,L"module_data");
00065 }
00066
00067 xfNode* BaseConfigFile::getMofuleAttribute(wstring modulename, wstring attr){
00068 xfNode* moduleN= xfEnter(moduledata_node,const_cast<xfChar*>(modulename.c_str()));
00069 if (moduleN==NULL){return NULL;}
00070 return xfEnter(moduleN,const_cast<xfChar*>(attr.c_str()));
00071 }
00072
00073 string BaseConfigFile::getModuleAttributeString(wstring modulename, wstring attr, string defval){
00074 return getAttrString(getMofuleAttribute(modulename,attr),defval);
00075 }
00076
00077 long int BaseConfigFile::getModuleAttributeInt(wstring modulename, wstring attr,long int defval){
00078 return getAttrInt(getMofuleAttribute(modulename,attr),defval);
00079 }
00080
00081 BaseConfigFile::~BaseConfigFile(){
00082 xfDestroy(conf);
00083 xfStop();
00084 }