vtf-logo

constant.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__ads_Constant_h__)
00009 #define __ads_Constant_h__
00010 
00011 #include "../defs.h"
00012 
00013 #include <functional>
00014 
00015 BEGIN_NAMESPACE_ADS
00016 
00017 //-----------------------------------------------------------------------------
00021 // @{
00022 
00024 template<typename _Result>
00025 class GeneratorConstant {
00026   //
00027   // Public types.
00028   //
00029 public:
00030 
00032   typedef _Result result_type;
00033 
00034   //
00035   // Member data.
00036   //
00037 private:
00038 
00040   result_type _value;
00041 
00042   //--------------------------------------------------------------------------
00044 
00045 public:
00046 
00048   GeneratorConstant() :
00049     _value()
00050   {}
00051 
00053   GeneratorConstant(const result_type& x) :
00054     _value(x)
00055   {}
00056 
00058   //--------------------------------------------------------------------------
00060 
00061 public:
00062 
00064   void
00065   set(const result_type& x) {
00066     _value = x;
00067   }
00068 
00070   //--------------------------------------------------------------------------
00072 
00073 public:
00074 
00076   const result_type&
00077   operator()() const {
00078     return _value;
00079   }
00080 
00082 };
00083 
00084 
00086 template<>
00087 class GeneratorConstant<void> {
00088   //
00089   // Public types.
00090   //
00091 public:
00092 
00094   typedef void result_type;
00095 
00096   //--------------------------------------------------------------------------
00098 
00099 public:
00100 
00102   void
00103   set() {
00104   }
00105 
00107   //--------------------------------------------------------------------------
00109 
00110 public:
00111 
00113   void
00114   operator()() const {
00115   }
00116 
00118 };
00119 
00120 
00122 
00126 template<typename _Result>
00127 inline
00128 GeneratorConstant<_Result>
00129 constructGeneratorConstant(const _Result& x) {
00130   return GeneratorConstant<_Result>(x);
00131 }
00132 
00133 
00135 
00139 template<typename _Result>
00140 inline
00141 GeneratorConstant<_Result>
00142 constructGeneratorConstant() {
00143   return GeneratorConstant<_Result>();
00144 }
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00153 template<typename _Argument, typename _Result>
00154 class UnaryConstant : 
00155   public std::unary_function<_Argument,_Result> {
00156   //
00157   // Private types.
00158   //
00159 private:
00160 
00161   typedef std::unary_function<_Argument,_Result> Base;
00162 
00163   //
00164   // Public types.
00165   //
00166 public:
00167 
00169   typedef typename Base::argument_type argument_type;
00171   typedef typename Base::result_type result_type;
00172 
00173   //
00174   // Member data.
00175   //
00176 private:
00177 
00179   result_type _value;
00180 
00181   //--------------------------------------------------------------------------
00183 
00184 public:
00185 
00187   UnaryConstant() :
00188     _value()
00189   {}
00190 
00192   UnaryConstant(const result_type& x) :
00193     _value(x)
00194   {}
00195 
00197   //--------------------------------------------------------------------------
00199 
00200 public:
00201 
00203   void
00204   set(const result_type& x) {
00205     _value = x;
00206   }
00207 
00209   //--------------------------------------------------------------------------
00211 
00212 public:
00213 
00215   const result_type&
00216   operator()(const argument_type& x) const {
00217     return _value;
00218   }
00219 
00221 };
00222 
00223 
00225 
00229 template<typename _Argument, typename _Result>
00230 inline
00231 UnaryConstant<_Argument, _Result>
00232 constructUnaryConstant(const _Result& x) {
00233   return UnaryConstant<_Argument, _Result>(x);
00234 }
00235 
00237 
00241 template<typename _Argument, typename _Result>
00242 inline
00243 UnaryConstant<_Argument, _Result>
00244 constructUnaryConstant() {
00245   return UnaryConstant<_Argument, _Result>();
00246 }
00247 
00248 
00249 
00250 
00251 
00252 
00253 
00255 template<typename _FirstArgument, typename _SecondArgument, typename _Result>
00256 class BinaryConstant : 
00257   public std::binary_function<_FirstArgument,_SecondArgument,_Result> {
00258   //
00259   // Private types.
00260   //
00261 private:
00262 
00263   typedef std::binary_function<_FirstArgument,_SecondArgument,_Result> Base;
00264 
00265   //
00266   // Public types.
00267   //
00268 public:
00269 
00271   typedef typename Base::first_argument_type first_argument_type;
00273   typedef typename Base::second_argument_type second_argument_type;
00275   typedef typename Base::result_type result_type;
00276 
00277   //
00278   // Member data.
00279   //
00280 private:
00281 
00283   result_type _value;
00284 
00285   //--------------------------------------------------------------------------
00287 
00288 public:
00289 
00291   BinaryConstant() :
00292     _value()
00293   {}
00294 
00296   BinaryConstant(const result_type& x) :
00297     _value(x)
00298   {}
00299 
00301   //--------------------------------------------------------------------------
00303 
00304 public:
00305 
00307   void
00308   set(const result_type& x) {
00309     _value = x;
00310   }
00311 
00313   //--------------------------------------------------------------------------
00315 
00316 public:
00317 
00319   const result_type&
00320   operator()(const first_argument_type& x, 
00321              const second_argument_type& y) const {
00322     return _value;
00323   }
00324 
00326 };
00327 
00328 
00330 
00334 template<typename _FirstArgument, typename _SecondArgument, typename _Result>
00335 inline
00336 BinaryConstant<_FirstArgument, _SecondArgument, _Result>
00337 constructBinaryConstant(const _Result& x) {
00338   return BinaryConstant<_FirstArgument, _SecondArgument, _Result>(x);
00339 }
00340 
00341 
00343 
00347 template<typename _FirstArgument, typename _SecondArgument, typename _Result>
00348 inline
00349 BinaryConstant<_FirstArgument, _SecondArgument, _Result>
00350 constructBinaryConstant() {
00351   return BinaryConstant<_FirstArgument, _SecondArgument, _Result>();
00352 }
00353 
00354 // @}
00355 
00356 END_NAMESPACE_ADS
00357 
00358 #endif

Generated on Fri Aug 24 12:55:23 2007 for Algorithms and Data Structures Package by  doxygen 1.4.7