00001 #ifndef OBT_OPTION_ARG_H
00002 #define OBT_OPTION_ARG_H
00003
00004 #include "OBT.h"
00005 #include <exception>
00006 #include <string>
00007
00008 namespace OBT
00009 {
00010
00011 class OptionArgHandler ;
00012
00020 class OBT_API OptionArg
00021 {
00022 protected:
00024 OptionArg( const std::string& flagName, const std::string& helpMsg ) ;
00026 virtual ~OptionArg() ;
00027 public:
00030 virtual std::string getHelp() const { return _flagName + ": " + _helpMsg ; }
00033 std::string getName() const { return _flagName ; }
00036 bool isPresent() const { return _flag ; }
00039 virtual int nbPresent() const { return _flag ? 1 : 0 ; }
00041 virtual void reset() { _flag = false ; }
00049 static OptionArg& other() ;
00056 static std::string expandEnvVariable( const std::string& txt ) ;
00057 protected:
00060 bool _flag ;
00063 std::string _flagName ;
00066 std::string _helpMsg ;
00067 protected:
00069 virtual bool argMatch() { return peekArg() == _flagName ; }
00076 virtual bool parseArg() = 0 ;
00079
00080
00081 bool atLastArg() const ;
00083 std::string getNextArg() const ;
00085 std::string peekArg() const ;
00087 void moveNextArg() const ;
00089
00090
00091 void throwError( const std::string& msg ) const ;
00092 private:
00093
00094 std::string getArg( std::size_t pos ) const ;
00095
00096 friend class OBT::OptionArgHandler ;
00097
00098 OptionArgHandler* _handler ;
00099
00100 bool tryArg() ;
00101 } ;
00102
00103 }
00104 #endif // OBT_OPTION_ARG_H