generic_spec.h

Go to the documentation of this file.
00001 
00012 #ifndef GENERIC_SPEC_H
00013 #define GENERIC_SPEC_H
00014 
00015 #include <stdexcept>
00016 #include <string>
00017 #include <sstream>
00018 
00019 #include "string_manip.h"
00020 
00021 
00026 template <class T>
00027 class generic_spec
00028 {
00029 public:
00033     generic_spec();
00034 
00038     void set(std::string const &);
00039 
00041     bool is_set() const {
00042         return !is_all;
00043     }
00044 
00046     T const value() const {
00047         if (!is_all)
00048             return data;
00049         throw std::out_of_range("generic_spec holds no value");
00050     }
00051 
00053     bool match(T const & rhs) const {
00054         return rhs == data;
00055     }
00056 
00058     bool match(generic_spec<T> const & rhs) const {
00059         return is_all || rhs.is_all || rhs.data == data;
00060     }
00061 
00062 private:
00063     T data;
00064     bool is_all;
00065 };
00066 
00067 
00068 template <class T>
00069 generic_spec<T>::generic_spec()
00070     :
00071     data(T()),
00072     is_all(true)
00073 {
00074 }
00075 
00076 
00077 template <class T>
00078 void generic_spec<T>::set(std::string const & str)
00079 {
00080     if (str == "all") {
00081         is_all = true;
00082         return;
00083     }
00084 
00085     is_all = false;
00086     data = op_lexical_cast<T>(str);
00087 }
00088 
00089 
00094 template <>
00095 void generic_spec<std::string>::set(std::string const & str);
00096 
00097 #endif /* !GENERIC_SPEC_H */

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1