00001 /* 00002 * This file is part of the ToolBox. 00003 * Copyright Thomas Jacob. 00004 * 00005 * READ README.TXT BEFORE USE!! 00006 */ 00007 00008 00009 #ifndef __TOOLBOX_COMMANDLINE_H 00010 #define __TOOLBOX_COMMANDLINE_H 00011 00012 00013 namespace toolbox 00014 { 00022 class CommandLine 00023 { 00024 private: 00025 00029 class Option 00030 { 00031 friend CommandLine; 00032 00033 private: 00034 00038 int expectedParameters; 00039 00043 bool found; 00044 00048 String name; 00049 00053 ArrayList<String> parameters; 00054 00059 Option(const String & name); 00060 }; 00061 00062 private: 00063 00064 #ifdef _TOOLBOX_TEST 00065 00068 static int instanceCount; 00069 #endif 00070 00075 StringKeyHashMap<Option> options; 00076 00080 ArrayList<String> parameters; 00081 00086 String programName; 00087 00088 public: 00089 00093 CommandLine(); 00094 00098 ~CommandLine(); 00099 00107 void declareOption(const String & name, int expectedParameters); 00108 00120 const ArrayList<String> * getOptionParameters(const String & name) const; 00121 00125 const ArrayList<String> & getParameters() const; 00126 00131 const String & getProgramName() const; 00132 00138 bool hasOption(const String & name) const; 00139 00146 void readFrom(int argc, const char ** argv); 00147 00152 void readFromDefault(); 00153 00154 #ifdef _TOOLBOX_TEST 00155 00161 static void runTestSuite(int * performedTests, int * failedTests); 00162 #endif 00163 }; 00164 } 00165 00166 00167 #endif