Arguments.h

00001 #ifndef QTGUI_ARGUMENTS_H
00002 #define QTGUI_ARGUMENTS_H
00003 
00004 /*
00005  * RebeccaAIML, Artificial Intelligence Markup Language 
00006  * C++ api and engine.
00007  *
00008  * Copyright (C) 2005,2006,2007 Frank Hassanabad
00009  *
00010  * This file is part of RebeccaAIML.
00011  *
00012  * RebeccaAIML is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 3 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * RebeccaAIML is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00024  */
00025 
00026 #include <string>
00027 #include <iostream>
00028 
00029 namespace qtgui
00030 {
00031 
00032 /*
00033  * I go ahead and pollute my applicaton's namespace.
00034  * This is okay, since I am creating an application and
00035  * am not creating an api.  If this was an api I'd have 
00036  * used another inner-namespace called something like impl 
00037  * and then polluted that instead to keep my outter namespace
00038  * clean.
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              * Iterate over the arguments
00071              * and set them 
00072              */
00073             for(int i = 1; i < argc; ++i)
00074             {
00075                 //get string of the argument
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                          * Display help and exit
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                      * We already encountered the switch, 
00150                      * now we just need to set the argument
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 } //end of qtgui namespace
00390 
00391 #endif

Generated on Mon Aug 27 12:26:58 2007 for RebeccaAIML by  doxygen 1.5.3