00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #include <iostream>
00043
00044 #include <qgarlib/QgarApp.H>
00045 #include <qgarlib/QgarArgs.H>
00046
00047
00048
00049 using namespace std;
00050
00051
00052 namespace qgar
00053 {
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 const unsigned char
00064 QgarApp::_CODE_END = 100;
00065
00066
00067
00068
00069 const unsigned char
00070 QgarApp::_CODE_GUI = 101;
00071
00072
00073
00074
00075 const unsigned char
00076 QgarApp::_CODE_ERROR = 200;
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 QgarApp::QgarApp()
00087
00088 : _exit(false),
00089 _action(QGE_ACTION_NONE),
00090 _actionCnt(0)
00091
00092 {
00093
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 QgarApp::~QgarApp()
00105 {
00106
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 char*
00118 QgarApp::nextWord(char* aComLine, int* anIdx)
00119 {
00120 int idx;
00121
00122 for(int idx = *anIdx ; idx < (int)strlen(aComLine) ; ++idx)
00123 {
00124 if(aComLine[idx] == ' ')
00125 {
00126 break;
00127 }
00128 }
00129
00130 char* res = new char[idx - (*anIdx) + 1];
00131
00132 int kdx = 0;
00133
00134 for(int jdx = (*anIdx); jdx < idx; ++jdx, ++kdx)
00135 {
00136 res[kdx] = aComLine[jdx];
00137 }
00138 res[kdx + 1] = '\0';
00139
00140 (*anIdx) = idx + 1;
00141
00142 return(res);
00143 }
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 void
00154 QgarApp::nextCommand()
00155 {
00156 char command[64];
00157 cin.getline(command, 64, '\n');
00158
00159 if(strcmp(command, "EXIT") == 0)
00160 {
00161 _exit = true;
00162 return;
00163 }
00164
00165 int * pos2 = new int();
00166 *pos2 = 0;
00167
00168 char * cmd = nextWord(command, pos2);
00169
00170 if(strcmp(cmd, "SET") == 0)
00171 {
00172 _action = QGE_ACTION_SET;
00173 }
00174 else
00175 {
00176 return;
00177 }
00178
00179
00180 while(*pos2 < (int)strlen(command))
00181 {
00182 char * target = nextWord(command, pos2);
00183
00184 list<string>::iterator it;
00185
00186 bool ok = false;
00187
00188 for (it = _paramNameTab.begin(); it != _paramNameTab.end(); ++it)
00189 {
00190 const char * tmp2 = (*it).c_str();
00191 char * tmp = new char[strlen(tmp2) + 1];
00192
00193 int i = 1;
00194 int j;
00195
00196 for(j = 0; j < (int)strlen(tmp2); ++j)
00197 {
00198 tmp[j] = tmp2[i];
00199 ++i;
00200 }
00201
00202 tmp[j] = '\0';
00203
00204 if(strcmp(tmp, target) == 0)
00205 {
00206 ok = true;
00207 break;
00208 }
00209 delete[] tmp;
00210 }
00211
00212 if(!ok)
00213 {
00214 return;
00215 }
00216
00217 char* value = nextWord(command, pos2);
00218
00219 _value = value;
00220 setValue(target, value);
00221
00222 if(_action == QGE_ACTION_SET)
00223 {
00224 ++_actionCnt;
00225 }
00226 }
00227 }
00228
00229
00230
00231
00232 bool
00233 QgarApp::newValue(const char* aName)
00234 {
00235 if(_action == QGE_ACTION_SET)
00236 {
00237 string tmp("-");
00238 tmp += aName;
00239
00240 QgarArgs::QgarParam* param = _args.findParam(tmp.c_str());
00241
00242 if(param != 0)
00243 {
00244 return(param->newValue());
00245 }
00246 }
00247
00248 return false;
00249 }
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259 void
00260 QgarApp::addParameter(const char* aParamName,
00261 QgarArgs::QGEparamStatus aParamStatus,
00262 QgarArgs::QGEparamType aParamType,
00263 const char* aDescription,
00264 const char* anExtension,
00265 const char* aDefault)
00266 {
00267 if((aParamType >= QgarArgs::INT) && (aParamType <= QgarArgs::BOOL))
00268 {
00269 _paramNameTab.push_back(string(aParamName));
00270 }
00271
00272 _args.addParameter(aParamName,
00273 aParamStatus,
00274 aParamType,
00275 aDescription,
00276 anExtension,
00277 aDefault);
00278 }
00279
00280
00281
00282
00283 const char*
00284 QgarApp::getStringOption (const char* aFlag)
00285 {
00286 bool special = false;
00287
00288 int size = (int)strlen(aFlag);
00289 char tmp[size + 1];
00290
00291 int idx;
00292
00293 for(idx = 0; idx < size; ++idx)
00294 {
00295 tmp[idx] = aFlag[idx];
00296 }
00297
00298 tmp[idx] = '\0';
00299
00300 char _flag[strlen(tmp)];
00301
00302 int jdx = 0;
00303
00304 for(idx = 1; idx < (int)strlen(tmp); ++idx)
00305 {
00306 _flag[jdx] = tmp[idx];
00307 ++jdx;
00308 }
00309 _flag[jdx] = '\0';
00310
00311 if(_action == QGE_ACTION_SET)
00312 {
00313 if(_actionCnt > 0)
00314 {
00315 --_actionCnt;
00316 }
00317 else
00318 {
00319 _action = QGE_ACTION_NONE;
00320 }
00321
00322 special = true;
00323 }
00324
00325 const char* res = _args.getStringOption(aFlag, special);
00326
00327 return(res);
00328 }
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338 void
00339 QgarApp::showDialog()
00340 {
00341 cout << "Show slider";
00342
00343 list<string>::iterator it;
00344
00345
00346
00347 for (it = _paramNameTab.begin(); it != _paramNameTab.end(); ++it)
00348 {
00349 cout << ' ';
00350 QgarArgs::QgarParam* param = _args.findParam(it->c_str());
00351 param->printGUI(false);
00352 }
00353
00354 cout << std::endl;
00355 }
00356
00357
00358
00359
00360
00361 }