Checker.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  * If you modify this library, or any covered work, by linking or combining
00021  * it with Excel (or a modified version of that program), containing parts
00022  * covered by the terms of End-User License Agreement for Microsoft
00023  * Software, the licensors of KeyValue grant you additional permission to
00024  * convey the resulting work.
00025  *
00026  **************************************************************************/
00027 
00034 #ifndef KEYVALUE_KEY_CHECKER_H_
00035 #define KEYVALUE_KEY_CHECKER_H_
00036 
00037 #include "keyvalue/value/Single.h"
00038 #include "keyvalue/value/Vector.h"
00039 #include "keyvalue/value/Matrix.h"
00040 
00041 namespace keyvalue {
00042 namespace key {
00043 
00072 #if DOXYGEN
00073 template <typename ConverterType,
00074   typename InputType = typename ConverterType::InputType_>
00075 class Checker {};
00076 #endif
00077 
00078 template <typename ConverterType,
00079   typename InputType = typename ConverterType::InputType_>
00080 class Checker;
00081 
00088 template <typename ConverterType>
00089 class Checker<ConverterType, value::Single> {
00090 
00091 public:
00092 
00093   typedef typename ConverterType::OutputType_ OutputType_;
00094 
00100   void
00101   checkInput(const value::Single& input) const;
00102 
00112   void
00113   checkSoFar(const ConverterType& container) const;
00114 
00120   void
00121   checkOutput(const OutputType_& output) const;
00122 
00123 private :
00124 
00130   virtual string
00131   getName() const = 0;
00132 
00133 };
00134 
00135 /*--------------------------------------------------------------------------
00136  * checkInput()
00137  *------------------------------------------------------------------------*/
00138 
00139 template <typename ConverterType>
00140 void
00141 Checker<ConverterType, value::Single>::checkInput(const value::Single&
00142   /* input */) const {
00143 }
00144 
00145 /*--------------------------------------------------------------------------
00146  * checkSoFar()
00147  *------------------------------------------------------------------------*/
00148 
00149 template <typename ConverterType>
00150 void
00151 Checker<ConverterType, value::Single>::checkSoFar(const ConverterType&
00152   /* container */) const {
00153 }
00154 
00155 /*--------------------------------------------------------------------------
00156  * checkOutput()
00157  *------------------------------------------------------------------------*/
00158 
00159 template <typename ConverterType>
00160 void
00161 Checker<ConverterType, value::Single>::checkOutput(const OutputType_&
00162   /* output */) const {
00163 }
00164 
00171 template <typename ConverterType>
00172 class Checker<ConverterType, value::Vector> {
00173 
00174 public:
00175 
00176   typedef typename ConverterType::OutputType_ OutputType_;
00177 
00185   void
00186   checkInput(const value::Vector& input) const;
00187 
00193   void
00194   checkSoFar(const ConverterType& container) const;
00195 
00201   void
00202   checkOutput(const OutputType_& output) const;
00203 
00204 private:
00205 
00211   virtual string
00212   getName() const = 0;
00213 
00219   virtual void
00220   checkSize(size_t size) const;
00221 
00222 };
00223 
00224 /*--------------------------------------------------------------------------
00225  * checkInput()
00226  *------------------------------------------------------------------------*/
00227 
00228 template <typename ConverterType>
00229 void
00230 Checker<ConverterType, value::Vector>::checkInput(const value::Vector&
00231   input) const {
00232   this->checkSize(input.getSize());
00233 }
00234 
00235 /*--------------------------------------------------------------------------
00236  * checkSoFar()
00237  *------------------------------------------------------------------------*/
00238 
00239 template <typename ConverterType>
00240 void
00241 Checker<ConverterType, value::Vector>::checkSoFar(const ConverterType&
00242   /* ConverterType */) const {
00243 }
00244 
00245 /*--------------------------------------------------------------------------
00246  * checkOutput()
00247  *------------------------------------------------------------------------*/
00248 
00249 template <typename ConverterType>
00250 void
00251 Checker<ConverterType, value::Vector>::checkOutput(const OutputType_&
00252   /* output*/) const {
00253 }
00254 
00255 /*--------------------------------------------------------------------------
00256  * checkSize()
00257  *------------------------------------------------------------------------*/
00258 
00259 template <typename ConverterType>
00260 void
00261 Checker<ConverterType, value::Vector>::checkSize(const size_t /* size */)
00262   const {
00263 }
00264 
00271 template <typename ConverterType>
00272 class Checker<ConverterType, value::Matrix> {
00273 
00274 public:
00275 
00276   typedef typename ConverterType::OutputType_ OutputType_;
00277 
00285   void
00286   checkInput(const value::Matrix& input) const;
00287 
00293   void
00294   checkSoFar(const ConverterType& container) const;
00295 
00301   void
00302   checkOutput(const OutputType_& output) const;
00303 
00304 private:
00305 
00311   virtual string
00312   getName() const = 0;
00313 
00320   virtual void
00321   checkSize(size_t nRows, size_t nCols) const;
00322 
00323 };
00324 
00325 /*--------------------------------------------------------------------------
00326  * checkInput()
00327  *------------------------------------------------------------------------*/
00328 
00329 template <typename ConverterType>
00330 void
00331 Checker<ConverterType, value::Matrix>::checkInput(const value::Matrix&
00332   input) const {
00333   this->checkSize(input.getNRows(), input.getNCols());
00334 }
00335 
00336 /*--------------------------------------------------------------------------
00337  * checkSoFar()
00338  *------------------------------------------------------------------------*/
00339 
00340 template <typename ConverterType>
00341 void
00342 Checker<ConverterType, value::Matrix>::checkSoFar(const ConverterType&
00343   /* ConverterType */) const {
00344 }
00345 
00346 /*--------------------------------------------------------------------------
00347  * checkOutput()
00348  *------------------------------------------------------------------------*/
00349 
00350 template <typename ConverterType>
00351 void
00352 Checker<ConverterType, value::Matrix>::checkOutput(const OutputType_&
00353   /* output*/) const {
00354 }
00355 
00356 /*--------------------------------------------------------------------------
00357  * checkSize()
00358  *------------------------------------------------------------------------*/
00359 
00360 template <typename ConverterType>
00361 void
00362 Checker<ConverterType, value::Matrix>::checkSize(const size_t /* nRows */,
00363   const size_t /* nCols */) const {
00364 }
00365 
00366 } // namespace key
00367 } // namespace keyvalue
00368 
00369 #endif // KEYVALUE_KEY_CHECKER_H_