00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #ifndef util_CSet_hpp
00029 #define util_CSet_hpp
00030
00031 #include <typeinfo>
00032 #include <vector>
00033
00034 namespace phdmesh {
00035
00036
00040 class CSet {
00041 public:
00042
00046 template<class T> const T * get() const ;
00047
00062 template<class T>
00063 const T * insert_with_delete( const T * );
00064
00079 template<class T>
00080 const T * insert_no_delete( const T * );
00081
00086 template<class T> bool remove( const T * );
00087
00088
00089
00090 ~CSet();
00091 CSet();
00092
00093 private:
00094
00095 typedef void (*DeleteFunction)(void *);
00096
00097 typedef std::pair< const std::type_info * , DeleteFunction > Manager ;
00098
00099 const void * p_get( const std::type_info & ) const ;
00100
00101 const void * p_insert( const Manager & , const void * );
00102
00103 bool p_remove( const std::type_info & , const void * );
00104
00105 std::vector< Manager > m_manager ;
00106 std::vector< const void * > m_value ;
00107
00108 CSet( const CSet & );
00109 CSet & operator = ( const CSet & );
00110 };
00111
00112 }
00113
00114
00115
00116
00117 #ifndef DOXYGEN_COMPILE
00118
00119
00120
00121 namespace phdmesh {
00122
00123 namespace {
00124 template<class T>
00125 void cset_member_delete( void * v ) { delete reinterpret_cast<T*>( v ); }
00126 }
00127
00128 template<class T>
00129 inline
00130 const T * CSet::get() const
00131 { return (const T*) p_get( typeid(T) ); }
00132
00133 template<class T>
00134 inline
00135 const T * CSet::insert_with_delete( const T * arg_value )
00136 {
00137 Manager m ;
00138 m.first = & typeid(T);
00139 m.second = & cset_member_delete<T> ;
00140 return (const T *) p_insert( m , arg_value );
00141 }
00142
00143 template<class T>
00144 inline
00145 const T * CSet::insert_no_delete( const T * arg_value )
00146 {
00147 Manager m ;
00148 m.first = & typeid(T);
00149 m.second = NULL ;
00150 return (const T *) p_insert( m , arg_value );
00151 }
00152
00153 template<class T>
00154 inline
00155 bool CSet::remove( const T * arg_value )
00156 { return p_remove( typeid(T) , arg_value ); }
00157
00158 }
00159
00160 #endif
00161
00162 #endif
00163
00164