ISIS Core Library 0.7.2 (api 3.0.0)

/scr/tee1/isis/lib/Core/CoreUtils/types.cpp

Go to the documentation of this file.
00001 //
00002 // C++ Implementation: types
00003 //
00004 // Description:
00005 //
00006 //
00007 // Author: Enrico Reimer<reimer@cbs.mpg.de>, (C) 2009
00008 //
00009 // Copyright: See COPYING file that comes with this distribution
00010 //
00011 //
00012 
00014 
00015 #ifdef _MSC_VER
00016 #pragma warning(disable:4800 4996)
00017 #endif
00018 
00019 #include "value.hpp"
00020 #include "../DataStorage/valuearray.hpp"
00021 #include "types.hpp"
00022 #include <complex>
00023 #include <boost/date_time/posix_time/posix_time.hpp>
00024 #include <boost/mpl/for_each.hpp>
00025 #include <boost/foreach.hpp>
00026 
00027 namespace isis
00028 {
00029 namespace util
00030 {
00031 
00032 /*
00033  * Define types for the Value<>-System here.
00034  * There must be a streaming output available for every type used here.
00035  * template<typename charT, typename traits,typename TYPE > basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits> &out,const TYPE& s)
00036  */
00037 
00038 
00039 #define DEF_TYPE(TYPE,NAME)  \
00040     template<> const char Value<TYPE>::m_typeName[]=#NAME
00041 
00042 DEF_TYPE( bool, boolean );
00043 
00044 DEF_TYPE( int8_t, s8bit );
00045 DEF_TYPE( uint8_t, u8bit );
00046 
00047 DEF_TYPE( int16_t, s16bit );
00048 DEF_TYPE( uint16_t, u16bit );
00049 
00050 DEF_TYPE( int32_t, s32bit );
00051 DEF_TYPE( uint32_t, u32bit );
00052 
00053 DEF_TYPE( int64_t, s64bit );
00054 DEF_TYPE( uint64_t, u64bit );
00055 
00056 DEF_TYPE( float, float );
00057 DEF_TYPE( double, double );
00058 
00059 DEF_TYPE( color24, color24 );
00060 DEF_TYPE( color48, color48 );
00061 
00062 DEF_TYPE( fvector3, fvector3 );
00063 DEF_TYPE( fvector4, fvector4 );
00064 DEF_TYPE( dvector3, dvector3 );
00065 DEF_TYPE( dvector4, dvector4 );
00066 DEF_TYPE( ivector4, ivector4 );
00067 
00068 DEF_TYPE( ilist, list<int32_t> );
00069 DEF_TYPE( dlist, list<double> );
00070 DEF_TYPE( slist, list<string> );
00071 
00072 DEF_TYPE( std::complex<float>, complex<float> );
00073 DEF_TYPE( std::complex<double>, complex<double> );
00074 
00075 DEF_TYPE( std::string, string );
00076 DEF_TYPE( Selection, selection );
00077 DEF_TYPE( boost::posix_time::ptime, timestamp );
00078 DEF_TYPE( boost::gregorian::date, date );
00079 
00080 API_EXCLUDE_BEGIN
00081 namespace _internal
00082 {
00083 struct type_lister {
00084     std::map< unsigned short, std::string > &m_map;
00085     bool m_withValues, m_withValueArrays;
00086     type_lister( std::map< unsigned short, std::string > &map, bool withValues, bool withValueArrays ): m_map( map ), m_withValues( withValues ), m_withValueArrays( withValueArrays ) {}
00087     template<typename SRC> void operator()( SRC ) {//will be called by the mpl::for_each
00088         if( m_withValues )m_map.insert( std::make_pair( util::Value<SRC>::staticID, util::Value<SRC>::staticName() ) );
00089 
00090         if( m_withValueArrays )m_map.insert( std::make_pair( data::ValueArray<SRC>::staticID, data::ValueArray<SRC>::staticName() ) );
00091     }
00092 };
00093 
00094 }
00095 API_EXCLUDE_END
00096 
00097 std::map< unsigned short, std::string > getTypeMap( bool withValues, bool withValueArrays )
00098 {
00099     std::map< unsigned short, std::string > ret;
00100     boost::mpl::for_each<_internal::types>( _internal::type_lister( ret, withValues, withValueArrays ) );
00101     return ret;
00102 }
00103 
00104 std::map< std::string, unsigned short > getTransposedTypeMap( bool withValues, bool withValueArrays )
00105 {
00106     typedef std::map< std::string, unsigned short> transposedMapType;
00107     typedef std::map< unsigned short, std::string > mapType;
00108     transposedMapType ret;
00109     BOOST_FOREACH( mapType::const_reference ref, util::getTypeMap( withValues, withValueArrays ) ) {
00110         ret[ref.second] = ref.first;
00111     }
00112     return ret;
00113 }
00114 
00115 }
00116 }
00117