Bounded.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00029 #ifndef KEYVALUE_KEY_GENERIC_BOUNDED_H_
00030 #define KEYVALUE_KEY_GENERIC_BOUNDED_H_
00031
00032 #include "keyvalue/key/converter/StdSingle.h"
00033 #include "keyvalue/key/generic/bound/NoBound.h"
00034 #include "keyvalue/key/Traits.h"
00035
00036 namespace keyvalue {
00037 namespace key {
00038
00104 template<typename ElementType, template <typename> class Bound1,
00105 template <typename> class Bound2 = NoBound>
00106 class Bounded: public Traits<ElementType, StdSingle, NoMap> {
00107
00108 public:
00109
00118 Bounded(const string& name, const ElementType& bound1);
00119
00130 Bounded(const string& name, const ElementType& bound1,
00131 const ElementType& bound2);
00132
00140 void checkOutput(ElementType element) const;
00141
00142 private:
00143
00144 const Bound1<ElementType> bound1_;
00145 const Bound2<ElementType> bound2_;
00146
00147 };
00148
00149
00150
00151
00152
00153 template<typename ElementType, template <typename> class Bound1,
00154 template <typename> class Bound2>
00155 Bounded<ElementType, Bound1, Bound2>::Bounded(const string& name,
00156 const ElementType& bound1) : Bounded::Traits_(name), bound1_(bound1),
00157 bound2_() {
00158 }
00159
00160 template<typename ElementType, template <typename> class Bound1,
00161 template <typename> class Bound2>
00162 Bounded<ElementType, Bound1, Bound2>::Bounded(const string& name,
00163 const ElementType& bound1, const ElementType& bound2) :
00164 Key(name), bound1_(bound1), bound2_(bound2) {
00165 }
00166
00167
00168
00169
00170
00171 template<typename ElementType, template <typename> class Bound1,
00172 template <typename> class Bound2>
00173 void
00174 Bounded<ElementType, Bound1, Bound2>::checkOutput(const ElementType element)
00175 const {
00176
00177 if (!bound1_.check(element))
00178 throw RuntimeError() & "Value for key '" & Key::getName() & "' must "
00179 "be " & bound1_.getName() & " " & bound1_.getBound() & ". Got " &
00180 element & "!";
00181
00182 if (!bound2_.check(element))
00183 throw RuntimeError() & "Value for key '" & Key::getName() & "' must "
00184 "be " & bound2_.getName() & " " & bound2_.getBound() & ". Got " &
00185 element & "!";
00186 }
00187
00188 }
00189 }
00190
00191 #endif // KEYVALUE_KEY_GENERIC_BOUNDED_H_