Arguments.h

00001 #include <string>
00002 
00003 namespace qtgui
00004 {
00005 
00006 /*
00007  * I go ahead and pollute my applicaton's namespace.
00008  * This is okay, since I am creating an application and
00009  * am not creating an api.  If this was an api I'd have 
00010  * used another inner-namespace called something like impl 
00011  * and then polluted that instead to keep my outter namespace
00012  * clean.
00013  */
00014 using namespace std;
00015 
00020 class Arguments
00021 {
00022     private:
00023 
00028         static Arguments *m_instance;
00029         
00041         void privateSetArguments(int argc, char *args[])
00042         {
00043             /*
00044              * Iterate over the arguments
00045              * and set them 
00046              */
00047             for(int i = 1; i < argc; ++i)
00048             {
00049                 //get string of the argument
00050                 string argument(args[i]);
00051                 
00052                 if(m_currentArgument == NO_ARG)
00053                 {
00054                     if(argument == "-aimlSchema" || 
00055                        argument == "-as")
00056                     {
00057                         m_currentArgument = AIML_SCHEMA;                    
00058                     } 
00059                     else if(argument == "-botSchema" ||
00060                             argument == "-bs")
00061                     {
00062                         m_currentArgument = BOT_SCHEMA; 
00063                     }
00064                     else if(argument == "-commonSchema" || 
00065                             argument == "-cs")
00066                     {
00067                         m_currentArgument = COMMON_SCHEMA;
00068                     }
00069                     else if(argument == "-configurationDirectory" || 
00070                             argument == "-cd")
00071                     {
00072                         m_currentArgument = CONFIGURATION;
00073                     }
00074                     else if(argument == "-aimlDirectory" || 
00075                             argument == "-ad")
00076                     {
00077                         m_currentArgument = AIML;   
00078                     }
00079                     else if(argument == "-resourcesDirectory" ||
00080                             argument == "-rd")
00081                     {
00082                         m_currentArgument = RESOURCES;
00083                     }
00084                     else if(argument == "-help" || 
00085                             argument == "-h" || 
00086                             argument == "/?" ||
00087                             argument == "--help")
00088                     {
00089                         /*
00090                          * Display help and exit
00091                          */
00092                         cout << endl << endl
00093                              << "[console.exe help]" << endl
00094                              << "------------------" << endl << endl
00095                              << "Available switches:" << endl << endl
00096                              << "[-aimlSchema or -as]" << endl 
00097                              << "    AIML Schema Path (default is ../../resources/schema/AIML.xsd)" << endl << endl
00098                              << "[-botSchema or -bs] " << endl 
00099                              << "    Bot Schema Path (default is ../resources/schema/bot-configuration.xsd)" << endl << endl
00100                              << "[-commonSchema or -cs] " << endl
00101                              << "    Common Schema Path (default is ../resources/schema/common-types.xsd)" << endl << endl
00102                              << "[-configurationDirectory or -cd] " << endl
00103                              << "    Configuration directory (default is ../../conf)" << endl << endl
00104                              << "[-aimlDirectory or -ad] " << endl
00105                              << "    AIML directory with *.aiml files (default is ../../aiml/annotated_alice)" << endl << endl
00106                              << "[-resourcesDirectory or -rd] " << endl
00107                              << "    AIML directory with resource files (default is ../../resources)" << endl << endl
00108                              << endl;
00109                         exit(0);
00110                     }
00111                     else
00112                     {
00113                         cout << 
00114                             "[Illegal argument of " +
00115                             string(args[i]) +
00116                             " found]" 
00117                             << endl;
00118                     }
00119                 }
00120                 else
00121                 {
00122                     /*
00123                      * We already encountered the switch, 
00124                      * now we just need to set the argument
00125                      */
00126                     if(m_currentArgument == AIML)
00127                     {
00128                         m_aimlDirectory = argument;
00129                     }
00130                     else if(m_currentArgument == AIML_SCHEMA)
00131                     {
00132                         m_aimlSchemaPath = argument;
00133                     }
00134                     else if(m_currentArgument == BOT_SCHEMA)
00135                     {
00136                         m_botConfigurationSchemaPath = argument;
00137                     }
00138                     else if(m_currentArgument == COMMON_SCHEMA)
00139                     {
00140                         m_commonTypesSchemaPath = argument;
00141                     }
00142                     else if(m_currentArgument == CONFIGURATION)
00143                     {
00144                         m_configurationDirectory = argument;
00145                     }
00146                     else if(m_currentArgument == RESOURCES)
00147                     {
00148                         m_resourcesDirectory = argument;
00149                     }
00150                     else
00151                     {
00152                         cout << "Programmer error "
00153                                 "this should not be reached"
00154                              << endl;
00155                     }
00156 
00157                     m_currentArgument = NO_ARG;
00158                 }
00159             }
00160         }
00161 
00172         Arguments()
00173             : m_aimlSchemaPath("../../resources/schema/AIML.xsd"),
00174               m_commonTypesSchemaPath("../resources/schema/common-types.xsd"),
00175               m_botConfigurationSchemaPath("../resources/schema/bot-configuration.xsd"),
00176               m_configurationDirectory("../../conf"),
00177               m_aimlDirectory("../../aiml/annotated_alice"),
00178               m_currentArgument(NO_ARG),
00179               m_resourcesDirectory("../../resources")
00180         { }
00181 
00182     public:
00183 
00195         static void setArguments(int argc, char *args[])
00196         {
00197             if(m_instance == 0)
00198             {
00199                 m_instance = new Arguments();
00200             }
00201 
00202             m_instance->privateSetArguments(argc, args); 
00203         }
00204         
00212         static Arguments *getInstance()
00213         {
00214             if(m_instance == 0)
00215             {
00216                 m_instance = new Arguments();
00217             }
00218 
00219             return m_instance;
00220         }
00221         
00230         string getConfigurationDirectory() const
00231         {
00232             return m_configurationDirectory;
00233         }
00234         
00242         string getAimlDirectory() const
00243         {
00244             return m_aimlDirectory;
00245         }
00246 
00254         string getAimlSchemaPath() const
00255         {
00256             return m_aimlSchemaPath;
00257         }
00258 
00266         string getCommonTypesSchemaPath() const
00267         {
00268             return m_commonTypesSchemaPath;
00269         }
00270 
00278         string getBotConfigurationSchemaPath() const
00279         {
00280             return m_botConfigurationSchemaPath;
00281         }
00282         
00288         string getResourcesDirectory() const
00289         {
00290             return m_resourcesDirectory;
00291         }
00296         enum arguments{ NO_ARG, AIML, AIML_SCHEMA, 
00297                         COMMON_SCHEMA, BOT_SCHEMA,
00298                         RESOURCES, CONFIGURATION};
00302         arguments m_currentArgument;
00303 
00314         string m_configurationDirectory;
00315 
00323         string m_aimlDirectory;
00324         
00332         string m_aimlSchemaPath;
00333 
00342         string m_commonTypesSchemaPath;
00343         
00352         string m_botConfigurationSchemaPath;
00353         
00360         string m_resourcesDirectory;
00361 };
00362 
00363 } //end of qtgui namespace

Generated on Fri Sep 1 17:35:42 2006 for RebeccaAIML by  doxygen 1.4.5