Bounded.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *
00003  * Copyright (C) 2009-2010 Cassio Neri Moreira
00004  *
00005  * This file is part of the KeyValue library.
00006  *
00007  * The KeyValue library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or (at
00010  * your option) any later version.
00011  *
00012  * The KeyValue library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00015  * Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with KeyValue. If not, see <http://www.gnu.org/licenses/>.
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 }; // class Bounded
00148 
00149 /*--------------------------------------------------------------------------
00150  * Bounded()
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  * checkOutput()
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 } // namespace key
00189 } // namespace keyvalue
00190 
00191 #endif // KEYVALUE_KEY_GENERIC_BOUNDED_H_

Generated on Sat Mar 20 15:08:29 2010 for KeyValue by  doxygen 1.6.1