Tapkee
implementations.hpp
Go to the documentation of this file.
1 
30 #ifndef FORMATTING_IMPLEMENTATIONS_H_
31 #define FORMATTING_IMPLEMENTATIONS_H_
32 
33 namespace formatting
34 {
36  static unsigned int default_precision = 9;
37 
38  namespace internal
39  {
41  {
42  public:
44  virtual std::string representation() const = 0;
45  };
46 
47  template <typename T>
50  {
51  public:
52  ValueWrapperImplementation(const T& value) :
53  value_(value) { }
54  virtual std::string representation() const
55  {
56  std::stringstream string_stream;
57  string_stream << std::setprecision(default_precision) << value_;
58  return string_stream.str();
59  }
60  private:
61  const T value_;
62  };
63 
64  template <>
65  class ValueWrapperImplementation<const char*> :
67  {
68  public:
69  ValueWrapperImplementation(const char* value) :
70  value_(value) { }
71  virtual std::string representation() const
72  {
73  return std::string(value_);
74  }
75  private:
76  const char* value_;
77  };
78 
79  template <>
82  {
83  public:
85  value_(value) { }
86  virtual std::string representation() const
87  {
88  return value_ ? "true" : "false";
89  }
90  private:
91  bool value_;
92  };
93 
94  template <>
97  {
98  public:
99  ValueWrapperImplementation(const std::string& value) :
100  value_(value) { }
101  virtual std::string representation() const
102  {
103  return value_;
104  }
105  private:
106  const std::string value_;
107  };
108 
109  template <typename T>
112  {
113  public:
114  ValueWrapperImplementation(const T* value) :
115  value_(value) { }
116  virtual std::string representation() const
117  {
118  std::stringstream string_stream;
119  string_stream << *value_;
120  return string_stream.str();
121  }
122  private:
123  const T* value_;
124  };
125  }
126 }
127 #endif
STL namespace.
static unsigned int default_precision