|
phdMesh Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* phdMesh : Parallel Heterogneous Dynamic unstructured Mesh */ 00003 /* Copyright (2007) Sandia Corporation */ 00004 /* */ 00005 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */ 00006 /* license for use of this work by or on behalf of the U.S. Government. */ 00007 /* */ 00008 /* This library is free software; you can redistribute it and/or modify */ 00009 /* it under the terms of the GNU Lesser General Public License as */ 00010 /* published by the Free Software Foundation; either version 2.1 of the */ 00011 /* License, or (at your option) any later version. */ 00012 /* */ 00013 /* This library is distributed in the hope that it will be useful, */ 00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ 00016 /* Lesser General Public License for more details. */ 00017 /* */ 00018 /* You should have received a copy of the GNU Lesser General Public */ 00019 /* License along with this library; if not, write to the Free Software */ 00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 */ 00021 /* USA */ 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 // Inlined template methods have casting. 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 } // namespace phdmesh 00159 00160 #endif /* DOXYGEN_COMPILE */ 00161 00162 #endif /* util_CSet_hpp */ 00163 00164
1.7.4