aydarbiktimirov

Untitled

Apr 4th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <string>
  4.  
  5. namespace configuration
  6. {
  7.  
  8.     class interface
  9.     {
  10.  
  11.         public:
  12.             virtual ~interface()
  13.             {
  14.             }
  15.  
  16.             virtual std::string read(const std::string &) const = 0;
  17.             virtual interface &write(const std::string &, const std::string &) = 0;
  18.  
  19.             virtual bool is_set(const std::string &) const = 0;
  20.  
  21.             template<typename T>
  22.             T get(const std::string &) const;
  23.             template<typename T>
  24.             void set(const std::string &, const T &);
  25.  
  26.  
  27.     };
  28.  
  29.     template<typename T>
  30.     T interface::get(const std::string &name) const
  31.     {
  32.         return T(read(name));
  33.     }
  34.  
  35.     template<>
  36.     int interface::get(const std::string &) const
  37.     {
  38.         return 15;
  39.     }
  40.  
  41.     template<typename T>
  42.     void interface::set(const std::string &name, const T &value)
  43.     {
  44.         write(name, std::string(value));
  45.     }
  46.  
  47.     template<>
  48.     void interface::set(const std::string &name, const int &)
  49.     {
  50.         write(name, "15");
  51.     }
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment