Application.h++
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __ccxx_Application_hxx
00024 #define __ccxx_Application_hxx
00025
00026 #include <commonc++/Common.h++>
00027 #include <commonc++/String.h++>
00028
00029 #include <cstddef>
00030
00031 namespace ccxx {
00032
00043 class COMMONCPP_API Application
00044 {
00045 private:
00046
00047 class CommandOption
00048 {
00049 friend class Application;
00050
00051 protected:
00052
00053 char _opt;
00054 String _longOpt;
00055 bool _hasArg;
00056 String _argName;
00057 String _argDesc;
00058
00059 CommandOption(char opt, const String &longOpt, const String &argName,
00060 const String &argDesc);
00061
00062 inline bool hasOpt() const
00063 { return(_opt != NUL); }
00064
00065 inline bool hasLongOpt() const
00066 { return(! _longOpt.isNull()); }
00067
00068 inline char getOpt() const
00069 { return (_opt); }
00070
00071 inline String getLongOpt() const
00072 { return(_longOpt); }
00073
00074 inline bool hasArg() const { return(_hasArg); }
00075
00076 inline const String& getArgDesc() const { return(_argDesc); }
00077 inline const String& getArgName() const { return(_argName); }
00078 };
00079
00080 class CommandOptionList;
00081
00082 public:
00083
00096 Application(int argc, char **argv, const String &version = "0.0",
00097 const String &compileDate = "",
00098 const String &compileTime = "");
00099
00102 virtual ~Application();
00103
00104 protected:
00105
00117 virtual void shutdown();
00118
00145 bool registerOption(char opt, const String &longOpt,
00146 const String &argName, const String &desc);
00147
00161 bool parseOptions(int argc, char **argv, int& index);
00162
00183 virtual bool processOption(char opt, const String &longOpt,
00184 const char *arg = NULL);
00185
00188 virtual void printUsage();
00189
00194 void printError(const char *message, ...);
00195
00196 String _version;
00197 String _compileDate;
00198 String _compileTime;
00199 CommandOptionList *_options;
00200 int _numLongOpts;
00201
00202 private:
00203
00204 void buildUsageText();
00205 void doShutdown();
00206
00207 bool _argsParsed;
00208 bool _useStyles;
00209 String _helpText;
00210 String _optString;
00211
00212 static Application *_instance;
00213
00214 static void _sighandler(int sig);
00215 };
00216
00217 };
00218
00219 #endif // __ccxx_Application_hxx
00220
00221