|
Sierra Toolkit
Version of the Day
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright 2005 Sandia Corporation. */ 00003 /* Under the terms of Contract DE-AC04-94AL85000, there is a */ 00004 /* non-exclusive license for use of this work by or on behalf */ 00005 /* of the U.S. Government. Export of this program may require */ 00006 /* a license from the United States Government. */ 00007 /*--------------------------------------------------------------------*/ 00008 00009 00010 #ifndef STK_UTIL_UTIL_TypeListMap_h 00011 #define STK_UTIL_UTIL_TypeListMap_h 00012 00019 #include <stk_util/util/TypeList.hpp> 00020 00026 namespace sierra { 00027 00036 template< class ListType > class TypeListMap ; 00037 00038 //---------------------------------------------------------------------- 00039 00040 template<typename T> class TypeListMapValue ; 00041 00042 template<typename T> 00043 class TypeListMapValue<T const &> 00044 { 00045 private: 00046 T const * x ; 00047 public: 00048 typedef TypeListMapValue<T const &> SelfType ; 00049 typedef T const & const_reference_type ; 00050 typedef T const & reference_type ; 00051 00052 TypeListMapValue() : x(0) {} 00053 TypeListMapValue( SelfType const & v ) : x( v.x ) {} 00054 explicit TypeListMapValue( T const & v ) : x( & v ) {} 00055 00056 SelfType & operator = ( SelfType const & v ) { x = v.x ; return *this ; } 00057 SelfType & operator = ( T const & v ) { x = &v ; return *this ; } 00058 00059 operator T const & () const { return *x ; } 00060 T const & get() const { return *x ; } 00061 }; 00062 00063 template<typename T> 00064 class TypeListMapValue<T&> 00065 { 00066 private: 00067 T * x ; 00068 public: 00069 typedef TypeListMapValue<T&> SelfType ; 00070 typedef T & const_reference_type ; 00071 typedef T & reference_type ; 00072 00073 TypeListMapValue() : x(0) {} 00074 TypeListMapValue( const SelfType & v ) : x( v.x ) {} 00075 explicit TypeListMapValue( T & v ) : x( & v ) {} 00076 00077 SelfType & operator = ( SelfType const & v ) { x = v.x ; return *this ; } 00078 SelfType & operator = ( T & v ) { x = &v ; return *this ; } 00079 00080 operator T & () const { return *x ; } 00081 T & get() const { return *x ; } 00082 }; 00083 00084 template<typename T> 00085 class TypeListMapValue<T const> 00086 { 00087 private: 00088 T x ; 00089 public: 00090 typedef TypeListMapValue<T> SelfType ; 00091 typedef T const & const_reference_type ; 00092 typedef T const & reference_type ; 00093 00094 TypeListMapValue() {} 00095 TypeListMapValue( SelfType const & v ) : x( v.x ) {} 00096 explicit TypeListMapValue( T const & v ) : x( v ) {} 00097 00098 SelfType & operator = ( SelfType const & v ) { x = v.x ; return *this ; } 00099 SelfType & operator = ( T const & v ) { x = v ; return *this ; } 00100 00101 operator T const & () const { return x ; } 00102 T const & get() const { return x ; } 00103 }; 00104 00105 template<typename T> 00106 class TypeListMapValue 00107 { 00108 private: 00109 T x ; 00110 public: 00111 typedef TypeListMapValue<T> SelfType ; 00112 typedef T const & const_reference_type ; 00113 typedef T & reference_type ; 00114 00115 TypeListMapValue() {} 00116 TypeListMapValue( SelfType const & v ) : x( v.x ) {} 00117 explicit TypeListMapValue( T const & v ) : x( v ) {} 00118 00119 SelfType & operator = ( SelfType const & v ) { x = v.x ; return *this ; } 00120 SelfType & operator = ( T const & v ) { x = v ; return *this ; } 00121 00122 operator T const & () const { return x ; } 00123 T const & get() const { return x ; } 00124 }; 00125 00126 //---------------------------------------------------------------------- 00127 00128 template<> 00129 class TypeListMap<TypeListEnd> {}; 00130 00131 template<typename Tail> 00132 class TypeListMap< TypeList<TypeListEnd,Tail> > {}; 00133 00134 template<class ListType> 00135 class TypeListMap : public TypeListMap<typename ListType::TypeListTail> 00136 { 00137 private: 00138 template<typename U> friend class TypeListMap ; 00139 00140 typedef typename ListType::TypeListTail TailType ; 00141 typedef typename ListType::TypeListValue TagType ; 00142 typedef typename TagType::type type ; 00143 TypeListMapValue<type> m_value ; 00144 00145 public: 00146 00147 typedef TypeListMap<ListType> SelfType ; 00148 00149 //---------- 00150 00151 template<class Tag> 00152 typename TypeListMapValue<typename Tag::type>::const_reference_type 00153 get() const 00154 { 00155 typedef typename TypeListMember<ListType,Tag>::list_type MemberListType ; 00156 return ((TypeListMap<MemberListType> const &) *this).m_value.get(); 00157 } 00158 00159 template<class Tag> 00160 void 00161 set( typename TypeListMapValue<typename Tag::type>::const_reference_type v ) 00162 { 00163 typedef typename TypeListMember<ListType,Tag>::list_type MemberListType ; 00164 ((TypeListMap<MemberListType> &) *this).m_value.operator=( v ); 00165 } 00166 00167 //---------- 00168 00169 TypeListMap<TailType> & operator << 00170 ( typename TypeListMapValue<type>::const_reference_type v ) 00171 { m_value = v ; return *this ; } 00172 00173 TypeListMap<TailType> const & operator >> 00174 ( typename TypeListMapValue<type>::reference_type v ) const 00175 { v = m_value ; return *this ; } 00176 00177 //---------- 00178 00179 void copy( TypeListMap<TypeListEnd> const & ) {} 00180 00181 template<class ListB> 00182 void copy( TypeListMap<TypeList<TypeListEnd,ListB> > const & b ) {} 00183 00184 template<class ListB> 00185 void copy( TypeListMap<ListB> const & b ) 00186 { 00187 typedef typename ListB::TypeListValue TagB ; 00188 typedef typename ListB::TypeListTail TailB ; 00189 this->template set<TagB>( b.template get<TagB>() ); 00190 copy( (TypeListMap<TailB> const &) b ); 00191 } 00192 00193 //---------- 00194 00195 ~TypeListMap() {} 00196 00197 TypeListMap() {} 00198 00199 TypeListMap( const SelfType & m ) 00200 : TypeListMap<TailType>( m ), m_value( m.m_value ) {} 00201 00202 SelfType & operator = ( const SelfType & m ) 00203 { 00204 TypeListMap<TailType>::operator=( m ); 00205 m_value = m.m_value ; 00206 return *this ; 00207 } 00208 }; 00209 00210 //---------------------------------------------------------------------- 00211 //---------------------------------------------------------------------- 00212 00213 } 00214 00215 #endif // STK_UTIL_UTIL_TypeListMap_h