Sierra Toolkit Version of the Day
WriterParser.hpp
00001 #ifndef STK_UTIL_Diag_WriterParser_h
00002 #define STK_UTIL_Diag_WriterParser_h
00003 
00004 namespace stk {
00005 namespace diag {
00006 
00007 
00008 typedef unsigned long OptionMask;
00009 
00015 struct OptionDescription
00016 {
00021   virtual ~OptionDescription()
00022   {}
00023 
00034   virtual std::ostream &describe(std::ostream &os) const = 0;
00035 };
00036 
00037 
00044 struct Option : public OptionDescription
00045 {
00050   Option()
00051     : m_name(""),
00052       m_envName(""),
00053       m_description(""),
00054       m_value(""),
00055       m_subOptionDescription(0)
00056   {}
00057 
00078   Option(const std::string &name, const std::string &env_name, const std::string &value = std::string(),
00079          const std::string &description = "No description available",
00080          const OptionDescription *sub_option_description = 0)
00081     : m_name(name),
00082       m_envName(env_name),
00083       m_description(description),
00084       m_value(value),
00085       m_subOptionDescription(sub_option_description)
00086   {}
00087 
00095   Option(const Option &option)
00096     : m_name(option.m_name),
00097       m_envName(option.m_envName),
00098       m_description(option.m_description),
00099       m_value(option.m_value),
00100       m_subOptionDescription(option.m_subOptionDescription)
00101   {}
00102 
00103 
00111   Option &operator=(const Option &option)
00112   {
00113     m_name = option.m_name;
00114     m_envName = option.m_envName;
00115     m_description = option.m_description;
00116     m_value = option.m_value;
00117     m_subOptionDescription = option.m_subOptionDescription;
00118     return *this;
00119   }
00120 
00125   virtual ~Option()
00126   {}
00127 
00128   const std::string &getName() const {
00129     return m_name;
00130   }
00131 
00132   const std::string &getValue() const {
00133     return m_value;
00134   }
00135 
00146   virtual std::ostream &describe(std::ostream &os) const;
00147 
00148   operator std::string &() {
00149     return m_value;
00150   }
00151 
00152   std::string      m_name;      
00153   std::string      m_envName;    
00154   std::string      m_description;    
00155   std::string      m_value;    
00156   const OptionDescription *  m_subOptionDescription;  
00157 };
00158 
00159 
00164 struct OptionMaskName
00165 {
00170   OptionMaskName()
00171     : m_name(""),
00172       m_mask(0),
00173       m_description("")
00174   {}
00175 
00183   OptionMaskName(const std::string &name, const OptionMask &mask, const std::string &description = "No description available")
00184     : m_name(name),
00185       m_mask(mask),
00186       m_description(description)
00187   {}
00188 
00193   virtual ~OptionMaskName()
00194   {}
00195 
00202   bool operator<(const OptionMaskName &o) const {
00203     return m_name < o.m_name;
00204   }
00205 
00212   virtual std::ostream &describe(std::ostream &os) const;
00213 
00214   std::string    m_name;
00215   OptionMask    m_mask;
00216   std::string    m_description;
00217 };
00218 
00219 
00224 class OptionMaskNameMap: public std::map<std::string, OptionMaskName>
00225 {
00226 public:
00234   void mask(const std::string &name, const OptionMask l_mask, const std::string &description) {
00235     iterator it = find(name);
00236     if (it == end())
00237       insert(std::make_pair(name, OptionMaskName(name, l_mask, description)));
00238     else {
00239       (*it).second.m_mask = l_mask;
00240       (*it).second.m_description = description;
00241     }
00242   }
00243 };
00244 
00245 
00255 class OptionMaskParser : public OptionDescription
00256 {
00257 public:
00258   typedef OptionMask Mask;    
00259 
00260 public:
00265   OptionMaskParser()
00266     : m_optionMaskNameMap(),
00267       m_optionMask(0),
00268       m_status(true)
00269   {}
00270 
00275   virtual ~OptionMaskParser()
00276   {}
00277 
00278   const OptionMaskNameMap &getOptionMaskNameMap() const {
00279     return m_optionMaskNameMap;
00280   }
00281 
00289   virtual Mask parse(const char *mask) const;
00290 
00300   virtual void parseArg(const std::string &name, const std::string &arg) const;
00301 
00312   Mask &operator[](const std::string &name) {
00313     return m_optionMaskNameMap[name].m_mask;
00314   }
00315 
00329   void mask(const std::string &name, const Mask l_mask, const std::string &description) {
00330     m_optionMaskNameMap.mask(name, l_mask, description);
00331   }
00332 
00339   std::ostream &describe(std::ostream &os) const;
00340 
00341 protected:
00342   OptionMaskNameMap    m_optionMaskNameMap;  
00343   mutable OptionMask    m_optionMask;    
00344   mutable bool      m_status;    
00345 };
00346 
00347 
00352 
00357 class WriterParser : public OptionMaskParser
00358 {
00359 public:
00365   typedef OptionMaskParser::Mask  Mask;
00366 
00367 public:
00373   WriterParser();
00374 
00385   Mask parse(const char *mask_string) const;
00386 
00397   virtual void parseArg(const std::string &name, const std::string &arg) const;
00398 };
00399 
00403 
00404 } // namespace diag
00405 } // namespace stk
00406 
00407 #endif // STK_UTIL_Diag_WriterParser_h
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends