Slice Tools
  • Home
  • SourceForge Page


  • libFoundation
  • Home
  • Class Hierarchy
  • Class List
  • Class Members
  • Examples


  • SourceForge.net Logo
     

    OptionResult.hh

    Go to the documentation of this file.
    00001 // $Id: OptionResult.hh,v 1.1 2005/07/29 02:55:15 mschatz Exp $
    00002 
    00005 
    00006 #ifndef OPTIONRESULT_HH
    00007 #define OPTIONRESULT_HH 1
    00008 
    00009 #include <string>
    00010 #include <map>
    00011 #include "Exceptions.hh"
    00012 
    00014 
    00016 class OptionResult
    00017 {
    00018 public:
    00019   OptionResult(const std::string & optionHelp);
    00020   virtual ~OptionResult();
    00021 
    00022   void addNameOrAlias(const std::string & name, bool hasNegation);
    00023   void verifyType(char optionType);
    00024 
    00025   std::string getName() const;
    00026   std::string getNextAlias();
    00027 
    00028   void resetAliasIter();
    00029   bool isNegation(const std::string & name);
    00030 
    00031   int has_arg();
    00032   void setHas_arg(int has_arg);
    00033 
    00035   virtual void setVal(const std::string & name, 
    00036                       const std::string & val) = 0;
    00037 
    00038   int resultSet(const std::string & name);
    00039   std::string getRawValue() const;
    00040 
    00041   void printHelp(bool isStandardOption);
    00043   virtual void writeDefault() = 0;
    00044 
    00045 protected:
    00046   void incrementCount(const std::string & name);
    00047   void validateArgumentCount(const std::string & name,
    00048                              const std::string & val);
    00050   char m_type;
    00052   std::string m_rawval;
    00053 
    00054 private:
    00056   int m_has_arg;
    00058   std::string m_name;
    00059 
    00061   std::string m_optionHelp;
    00062 
    00064   int m_resultSet;
    00066   int m_negationSet;
    00067 
    00069   std::map<std::string, bool> m_aliases;
    00071   std::map<std::string, bool>::const_iterator m_aliasesIter;
    00072 };
    00073 
    00074 
    00075 
    00077 class IntOptionResult : public OptionResult
    00078 {
    00079 public:
    00080   IntOptionResult(const std::string & optionHelp,
    00081                   int * result);
    00082   ~IntOptionResult();
    00083 
    00084   void writeDefault();
    00085   void setVal(const std::string & name,
    00086               const std::string & val);
    00087 
    00088 private:
    00089   int * m_result;
    00090 };
    00091 
    00092 
    00094 class FloatOptionResult : public OptionResult
    00095 {
    00096 public:
    00097   FloatOptionResult(const std::string & optionHelp,
    00098                     float * result);
    00099   ~FloatOptionResult();
    00100 
    00101   void writeDefault();
    00102   void setVal(const std::string & name,
    00103               const std::string & val);
    00104 
    00105 private:
    00106   float * m_result;
    00107 };
    00108 
    00109 
    00111 class StringOptionResult : public OptionResult
    00112 {
    00113 public:
    00114   StringOptionResult(const std::string & optionHelp,
    00115                      std::string * result);
    00116   ~StringOptionResult();
    00117 
    00118   void writeDefault();
    00119   void setVal(const std::string & name,
    00120               const std::string & val);
    00121 
    00122 private:
    00123   std::string * m_result;
    00124 };
    00125 
    00126 
    00127 #endif