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
00022
00023
00024
00025
00026
00027
00035 #ifndef KEYVALUE_KEY_GENERIC_BOUNDED_H_
00036 #define KEYVALUE_KEY_GENERIC_BOUNDED_H_
00037
00038 #include "keyvalue/key/converter/StdSingle.h"
00039 #include "keyvalue/key/generic/bound/NoBound.h"
00040 #include "keyvalue/key/Traits.h"
00041
00042 namespace keyvalue {
00043 namespace key {
00044
00106 template <typename ElementType, template <typename> class Bound1,
00107 template <typename> class Bound2 = NoBound>
00108 class Bounded: public Traits<ElementType, StdSingle> {
00109
00110 public:
00111
00120 Bounded(const string& name, const ElementType& bound1);
00121
00132 Bounded(const string& name, const ElementType& bound1,
00133 const ElementType& bound2);
00134
00142 void checkOutput(ElementType element) const;
00143
00144 private:
00145
00146 const Bound1<ElementType> bound1_;
00147 const Bound2<ElementType> bound2_;
00148
00149 };
00150
00151
00152
00153
00154
00155 template <typename ElementType, template <typename> class Bound1,
00156 template <typename> class Bound2>
00157 Bounded<ElementType, Bound1, Bound2>::Bounded(const string& name,
00158 const ElementType& bound1) :
00159 Bounded::Traits_(name),
00160 bound1_(bound1),
00161 bound2_() {
00162 }
00163
00164 template <typename ElementType, template <typename> class Bound1,
00165 template <typename> class Bound2>
00166 Bounded<ElementType, Bound1, Bound2>::Bounded(const string& name,
00167 const ElementType& bound1, const ElementType& bound2) :
00168 Bounded::Traits_(name),
00169 bound1_(bound1),
00170 bound2_(bound2) {
00171 }
00172
00173
00174
00175
00176
00177 template <typename ElementType, template <typename> class Bound1,
00178 template <typename> class Bound2>
00179 void
00180 Bounded<ElementType, Bound1, Bound2>::checkOutput(const ElementType element)
00181 const {
00182
00183 if (!bound1_.check(element))
00184 throw RuntimeError() & "Value for key '" & Key::getName() & "' must "
00185 "be " & bound1_.getName() & " " & bound1_.getBound() & ". Got " &
00186 element & "!";
00187
00188 if (!bound2_.check(element))
00189 throw RuntimeError() & "Value for key '" & Key::getName() & "' must "
00190 "be " & bound2_.getName() & " " & bound2_.getBound() & ". Got " &
00191 element & "!";
00192 }
00193
00194 }
00195 }
00196
00197 #endif // KEYVALUE_KEY_GENERIC_BOUNDED_H_