00001 #ifndef QTGUI_ARGUMENTS_H
00002 #define QTGUI_ARGUMENTS_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <string>
00027 #include <iostream>
00028
00029 namespace qtgui
00030 {
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 using namespace std;
00041
00046 class Arguments
00047 {
00048 private:
00049
00054 static Arguments *m_instance;
00055
00067 void privateSetArguments(int argc, char *args[])
00068 {
00069
00070
00071
00072
00073 for(int i = 1; i < argc; ++i)
00074 {
00075
00076 string argument(args[i]);
00077
00078 if(m_currentArgument == NO_ARG)
00079 {
00080 if(argument == "-aimlSchema" ||
00081 argument == "-as")
00082 {
00083 m_currentArgument = AIML_SCHEMA;
00084 }
00085 else if(argument == "-botSchema" ||
00086 argument == "-bs")
00087 {
00088 m_currentArgument = BOT_SCHEMA;
00089 }
00090 else if(argument == "-commonSchema" ||
00091 argument == "-cs")
00092 {
00093 m_currentArgument = COMMON_SCHEMA;
00094 }
00095 else if(argument == "-configurationDirectory" ||
00096 argument == "-cd")
00097 {
00098 m_currentArgument = CONFIGURATION;
00099 }
00100 else if(argument == "-aimlDirectory" ||
00101 argument == "-ad")
00102 {
00103 m_currentArgument = AIML;
00104 }
00105 else if(argument == "-resourcesDirectory" ||
00106 argument == "-rd")
00107 {
00108 m_currentArgument = RESOURCES;
00109 }
00110 else if(argument == "-help" ||
00111 argument == "-h" ||
00112 argument == "/?" ||
00113 argument == "--help")
00114 {
00115
00116
00117
00118 cout << endl << endl
00119 << "[console.exe help]" << endl
00120 << "------------------" << endl << endl
00121 << "Available switches:" << endl << endl
00122 << "[-aimlSchema or -as]" << endl
00123 << " AIML Schema Path (default is ../../resources/schema/AIML.xsd)" << endl << endl
00124 << "[-botSchema or -bs] " << endl
00125 << " Bot Schema Path (default is ../../resources/schema/bot-configuration.xsd)" << endl << endl
00126 << "[-commonSchema or -cs] " << endl
00127 << " Common Schema Path (default is ../../resources/schema/common-types.xsd)" << endl << endl
00128 << "[-configurationDirectory or -cd] " << endl
00129 << " Configuration directory (default is ../../conf)" << endl << endl
00130 << "[-aimlDirectory or -ad] " << endl
00131 << " AIML directory with *.aiml files (default is ../../aiml/annotated_alice)" << endl << endl
00132 << "[-resourcesDirectory or -rd] " << endl
00133 << " AIML directory with resource files (default is ../../resources)" << endl << endl
00134 << endl;
00135 exit(0);
00136 }
00137 else
00138 {
00139 cout <<
00140 "[Illegal argument of " +
00141 string(args[i]) +
00142 " found]"
00143 << endl;
00144 }
00145 }
00146 else
00147 {
00148
00149
00150
00151
00152 if(m_currentArgument == AIML)
00153 {
00154 m_aimlDirectory = argument;
00155 }
00156 else if(m_currentArgument == AIML_SCHEMA)
00157 {
00158 m_aimlSchemaPath = argument;
00159 }
00160 else if(m_currentArgument == BOT_SCHEMA)
00161 {
00162 m_botConfigurationSchemaPath = argument;
00163 }
00164 else if(m_currentArgument == COMMON_SCHEMA)
00165 {
00166 m_commonTypesSchemaPath = argument;
00167 }
00168 else if(m_currentArgument == CONFIGURATION)
00169 {
00170 m_configurationDirectory = argument;
00171 }
00172 else if(m_currentArgument == RESOURCES)
00173 {
00174 m_resourcesDirectory = argument;
00175 }
00176 else
00177 {
00178 cout << "Programmer error "
00179 "this should not be reached"
00180 << endl;
00181 }
00182
00183 m_currentArgument = NO_ARG;
00184 }
00185 }
00186 }
00187
00198 Arguments()
00199 : m_aimlSchemaPath("../../resources/schema/AIML.xsd"),
00200 m_commonTypesSchemaPath("../../resources/schema/common-types.xsd"),
00201 m_botConfigurationSchemaPath("../../resources/schema/bot-configuration.xsd"),
00202 m_configurationDirectory("../../conf"),
00203 m_aimlDirectory("../../aiml/annotated_alice"),
00204 m_currentArgument(NO_ARG),
00205 m_resourcesDirectory("../../resources")
00206 { }
00207
00208 public:
00209
00221 static void setArguments(int argc, char *args[])
00222 {
00223 if(m_instance == 0)
00224 {
00225 m_instance = new Arguments();
00226 }
00227
00228 m_instance->privateSetArguments(argc, args);
00229 }
00230
00238 static Arguments *getInstance()
00239 {
00240 if(m_instance == 0)
00241 {
00242 m_instance = new Arguments();
00243 }
00244
00245 return m_instance;
00246 }
00247
00256 string getConfigurationDirectory() const
00257 {
00258 return m_configurationDirectory;
00259 }
00260
00268 string getAimlDirectory() const
00269 {
00270 return m_aimlDirectory;
00271 }
00272
00280 string getAimlSchemaPath() const
00281 {
00282 return m_aimlSchemaPath;
00283 }
00284
00292 string getCommonTypesSchemaPath() const
00293 {
00294 return m_commonTypesSchemaPath;
00295 }
00296
00304 string getBotConfigurationSchemaPath() const
00305 {
00306 return m_botConfigurationSchemaPath;
00307 }
00308
00314 string getResourcesDirectory() const
00315 {
00316 return m_resourcesDirectory;
00317 }
00322 enum arguments{ NO_ARG, AIML, AIML_SCHEMA,
00323 COMMON_SCHEMA, BOT_SCHEMA,
00324 RESOURCES, CONFIGURATION};
00328 arguments m_currentArgument;
00329
00340 string m_configurationDirectory;
00341
00349 string m_aimlDirectory;
00350
00358 string m_aimlSchemaPath;
00359
00368 string m_commonTypesSchemaPath;
00369
00378 string m_botConfigurationSchemaPath;
00379
00386 string m_resourcesDirectory;
00387 };
00388
00389 }
00390
00391 #endif