1 // CmdLineParser.cpp: implementation of the CSettingsParser class.
\r
3 //////////////////////////////////////////////////////////////////////
\r
6 #include "settings.h"
\r
8 //////////////////////////////////////////////////////////////////////
\r
9 // Construction/Destruction
\r
10 //////////////////////////////////////////////////////////////////////
\r
12 CSettingsManager::CSettingsManager()
\r
15 CreateStandardSettings();
\r
18 CSettingsManager::~CSettingsManager()
\r
20 DestroyStandardSettings();
\r
23 void CSettingsManager::RegisterVariable(std::string &name, CMMPointer<BaseDator> &var)
\r
25 settingMap[name]=var;
\r
28 void CSettingsManager::SetVariable(std::string &name, std::string &value, int bias)
\r
30 if(!settingMap[name])return; //setting doesn't exist
\r
31 if(settingMap[name]->hasMultipleValues())
\r
33 std::list<std::string> valueList;
\r
36 //check for semicolon-seperated values
\r
37 if(value.find(';')!=-1)
\r
39 //split the string into semicolor-seperated chunks
\r
41 while((last=value.find(';',first))!=-1)
\r
43 valueList.push_back(value.substr(first,last-first));
\r
46 valueList.push_back(value.substr(first));
\r
48 valueList.push_back(value);
\r
51 for(std::list<std::string>::iterator it=valueList.begin(); it!=valueList.end(); it++)
\r
55 (*settingMap[name])+=(*it);
\r
58 (*settingMap[name])-=(*it);
\r
60 (*settingMap[name])=(*it);
\r
64 //just assign the value
\r
65 (*settingMap[name])=value;
\r
69 void CSettingsManager::ParseSetting(std::string str)
\r
71 int bias=0; std::string name, value;
\r
73 if((str[0]=='+')||(str[0]=='-'))
\r
75 bias=((str[0]=='+')*2)-1; //+ maps to 1*2-1=1, - maps to 0*2-1=-1
\r
76 str=str.substr(1); //remove the first character from the string
\r
79 int eqPos=str.find('=');
\r
82 //there's an = sign in there
\r
83 //so split either side of it
\r
84 name=str.substr(0,eqPos);
\r
85 value=str.substr(eqPos+1);
\r
87 //there's no equal sign
\r
88 //we use the bias to construct a boolean value
\r
89 //so that flags can be +flag (mapping to flag=1) or -flag (mapping to flag=0)
\r
92 sprintf_s(szBuf,5,"%i",(bias+1)/2);
\r
96 SetVariable(name,value,bias);
\r
99 void CSettingsManager::ParseFile(std::string filename)
\r
101 std::ifstream in(filename.c_str());
\r
102 if(!in.is_open())return; //couldn't open
\r
106 in.getline(szBuf,1024);
\r
107 ParseSetting(szBuf);
\r
111 #define SETTING(type, target, var, name) target=new Dator<type>(var); RegisterVariable(std::string(name),CMMPointer<BaseDator>(target));
\r
112 #define LIST(type, target, var, name) target=new ListDator<type>(var); RegisterVariable(std::string(name),CMMPointer<BaseDator>(target));
\r
114 void CSettingsManager::CreateStandardSettings()
\r
116 SETTING(int, CVideoUpdate::screenWidth, CVideoUpdate::scrWidth, "screenX" );
\r
117 SETTING(int, CVideoUpdate::screenHeight, CVideoUpdate::scrHeight, "screenY" );
\r
118 SETTING(int, CVideoUpdate::screenBPP, CVideoUpdate::scrBPP, "screenBPP" );
\r
121 void CSettingsManager::DestroyStandardSettings()
\r
123 CVideoUpdate::screenWidth = 0;
\r
124 CVideoUpdate::screenHeight = 0;
\r
125 CVideoUpdate::screenBPP = 0;
\r