DGtal 0.3.0

CInteger.h

Go to the documentation of this file.
00001 
00017 #pragma once
00018 
00031 #if defined(CInteger_RECURSES)
00032 #error Recursive header files inclusion detected in CInteger.h
00033 #else // defined(CInteger_RECURSES)
00034 
00035 #define CInteger_RECURSES
00036 
00037 #if !defined CInteger_h
00038 
00039 #define CInteger_h
00040 
00042 // Inclusions
00043 #include <iostream>
00044 #include "boost/concept_check.hpp"
00045 #include "DGtal/utils/ConceptUtils.h"
00046 #include "DGtal/base/Common.h"
00047 #include "DGtal/kernel/IntegerTraits.h"
00049 
00050 namespace DGtal
00051 {
00052 
00054   // class CInteger
00109   template <typename T>
00110   struct CInteger : boost::Assignable<T>, boost::EqualityComparable<T>
00111   {
00112     // ----------------------- Concept checks ------------------------------
00113   public:
00114     BOOST_CONCEPT_USAGE(CInteger)
00115     {
00116       T x( 0 ); // require constructor from built-in integer.
00117       T y( 1 ); // require constructor from built-in integer.
00118       x = x + y;
00119       x = x - y;
00120       ConceptUtils::sameType( myX, ++x );
00121       ConceptUtils::sameType( myX, --x );
00122       ConceptUtils::sameType( myX, IntegerTraits<T>::ZERO );
00123       ConceptUtils::sameType( myX, IntegerTraits<T>::ONE );
00124       
00125       // @todo x+y with short is promoted to int. We should use some
00126       // verification with possible promoting.
00127       //
00128       // @note T(x+y) is required (instead of 'x+y') because of
00129       // gmpxx. Indeed, x+y returns an expression template in GMP and
00130       // thus cannot be of type T.
00131       ConceptUtils::sameType( myX, T(x-y) );
00132       ConceptUtils::sameType( myX, T(x+y) );
00133       
00134     }
00135       
00136     // ------------------------- Private Datas --------------------------------
00137   private:
00138     T myX;
00139     typename IntegerTraits<T>::IsUnsigned myIsUnsigned;
00140     typename IntegerTraits<T>::IsUnsigned myIsSigned;
00141     typename IntegerTraits<T>::IsBounded myIsBounded;
00142     typename IntegerTraits<T>::SignedVersion mySignedVersion;
00143     typename IntegerTraits<T>::UnsignedVersion myUnsignedVersion;
00144     typename IntegerTraits<T>::ReturnType myReturnType;
00145 
00146     // ------------------------- Internals ------------------------------------
00147   private:
00148     
00149   }; // end of concept CInteger
00150   
00151 } // namespace DGtal
00152 
00153 
00155 // Includes inline functions.
00156 #include "DGtal/kernel/CInteger.ih"
00157 
00158 //                                                                           //
00160 
00161 #endif // !defined CInteger_h
00162 
00163 #undef CInteger_RECURSES
00164 #endif // else defined(CInteger_RECURSES)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines