10 #ifndef STK_UTIL_UTIL_TypeListMap_h 11 #define STK_UTIL_UTIL_TypeListMap_h 19 #include <stk_util/util/TypeList.hpp> 40 template<
typename T>
class TypeListMapValue ;
43 class TypeListMapValue<T const &>
48 typedef TypeListMapValue<T const &>
SelfType ;
49 typedef T
const & const_reference_type ;
50 typedef T
const & reference_type ;
52 TypeListMapValue() : x(0) {}
53 TypeListMapValue( SelfType
const & v ) : x( v.x ) {}
54 explicit TypeListMapValue( T
const & v ) : x( & v ) {}
56 SelfType & operator = ( SelfType
const & v ) { x = v.x ;
return *this ; }
57 SelfType & operator = ( T
const & v ) { x = &v ;
return *this ; }
59 operator T
const & ()
const {
return *x ; }
60 T
const &
get()
const {
return *x ; }
64 class TypeListMapValue<T&>
69 typedef TypeListMapValue<T&> SelfType ;
70 typedef T & const_reference_type ;
71 typedef T & reference_type ;
73 TypeListMapValue() : x(0) {}
74 TypeListMapValue(
const SelfType & v ) : x( v.x ) {}
75 explicit TypeListMapValue( T & v ) : x( & v ) {}
77 SelfType & operator = ( SelfType
const & v ) { x = v.x ;
return *this ; }
78 SelfType & operator = ( T & v ) { x = &v ;
return *this ; }
80 operator T & ()
const {
return *x ; }
81 T &
get()
const {
return *x ; }
85 class TypeListMapValue<T const>
90 typedef TypeListMapValue<T> SelfType ;
91 typedef T
const & const_reference_type ;
92 typedef T
const & reference_type ;
95 TypeListMapValue( SelfType
const & v ) : x( v.x ) {}
96 explicit TypeListMapValue( T
const & v ) : x( v ) {}
98 SelfType & operator = ( SelfType
const & v ) { x = v.x ;
return *this ; }
99 SelfType & operator = ( T
const & v ) { x = v ;
return *this ; }
101 operator T
const & ()
const {
return x ; }
102 T
const &
get()
const {
return x ; }
106 class TypeListMapValue
111 typedef TypeListMapValue<T> SelfType ;
112 typedef T
const & const_reference_type ;
113 typedef T & reference_type ;
115 TypeListMapValue() {}
116 TypeListMapValue( SelfType
const & v ) : x( v.x ) {}
117 explicit TypeListMapValue( T
const & v ) : x( v ) {}
119 SelfType & operator = ( SelfType
const & v ) { x = v.x ;
return *this ; }
120 SelfType & operator = ( T
const & v ) { x = v ;
return *this ; }
122 operator T
const & ()
const {
return x ; }
123 T
const &
get()
const {
return x ; }
129 class TypeListMap<TypeListEnd> {};
131 template<
typename Tail>
132 class TypeListMap< TypeList<TypeListEnd,Tail> > {};
134 template<
class ListType>
135 class TypeListMap :
public TypeListMap<typename ListType::TypeListTail>
138 template<
typename U>
friend class TypeListMap ;
140 typedef typename ListType::TypeListTail TailType ;
141 typedef typename ListType::TypeListValue TagType ;
142 typedef typename TagType::type type ;
143 TypeListMapValue<type> m_value ;
147 typedef TypeListMap<ListType> SelfType ;
152 typename TypeListMapValue<typename Tag::type>::const_reference_type
155 typedef typename TypeListMember<ListType,Tag>::list_type MemberListType ;
156 return ((TypeListMap<MemberListType>
const &) *
this).m_value.get();
161 set(
typename TypeListMapValue<typename Tag::type>::const_reference_type v )
163 typedef typename TypeListMember<ListType,Tag>::list_type MemberListType ;
164 ((TypeListMap<MemberListType> &) *
this).m_value.operator=( v );
169 TypeListMap<TailType> &
operator <<
170 (
typename TypeListMapValue<type>::const_reference_type v )
171 { m_value = v ;
return *this ; }
173 TypeListMap<TailType>
const &
operator >>
174 (
typename TypeListMapValue<type>::reference_type v )
const 175 { v = m_value ;
return *this ; }
179 void copy( TypeListMap<TypeListEnd>
const & ) {}
181 template<
class ListB>
182 void copy( TypeListMap<TypeList<TypeListEnd,ListB> >
const & b ) {}
184 template<
class ListB>
185 void copy( TypeListMap<ListB>
const & b )
187 typedef typename ListB::TypeListValue TagB ;
188 typedef typename ListB::TypeListTail TailB ;
189 this->
template set<TagB>( b.template get<TagB>() );
190 copy( (TypeListMap<TailB>
const &) b );
199 TypeListMap(
const SelfType & m )
200 : TypeListMap<TailType>( m ), m_value( m.m_value ) {}
202 SelfType & operator = (
const SelfType & m )
204 TypeListMap<TailType>::operator=( m );
205 m_value = m.m_value ;
215 #endif // STK_UTIL_UTIL_TypeListMap_h