Sierra Toolkit  Version of the Day
CSet.hpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #ifndef stk_util_util_CSet_hpp
10 #define stk_util_util_CSet_hpp
11 
12 #include <typeinfo>
13 #include <vector>
14 
15 namespace stk_classic {
16 
17 //----------------------------------------------------------------------
51 class CSet {
52 public:
53 
55  template<class T> const T * get() const ;
56 
60  template<class T> const T * insert_with_delete( const T *);
61 
65  template<class T> const T * insert_no_delete( const T * );
66 
70  template<class T> bool remove( const T * );
71 
72  //--------------------------------
73 
74  ~CSet();
75  CSet();
76 
77 private:
78 
79  typedef void (*DeleteFunction)(void *);
80 
81  typedef std::pair< const std::type_info * , DeleteFunction > Manager ;
82 
83  const void * p_get( const std::type_info & ) const ;
84 
85  const void * p_insert( const Manager & , const void * );
86 
87  bool p_remove( const std::type_info & , const void * );
88 
89  std::vector< Manager > m_manager ;
90  std::vector< const void * > m_value ;
91 
92  CSet( const CSet & );
93  CSet & operator = ( const CSet & );
94 };
95 
96 } // namespace stk_classic
97 
98 //----------------------------------------------------------------------
99 //----------------------------------------------------------------------
100 // Inlined template methods have casting.
101 
102 #ifndef DOXYGEN_COMPILE
103 
104 namespace stk_classic {
105 
106 namespace {
107 template<class T>
108 void cset_member_delete( void * v ) { delete reinterpret_cast<T*>( v ); }
109 }
110 
111 template<class T>
112 inline
113 const T * CSet::get() const
114 { return (const T*) p_get( typeid(T) ); }
115 
116 template<class T>
117 inline
118 const T * CSet::insert_with_delete( const T * arg_value)
119 {
120  Manager m ;
121  m.first = & typeid(T);
122  m.second = & cset_member_delete<T> ;
123 
124  return (const T *) p_insert( m , arg_value );
125 }
126 
127 template<class T>
128 inline
129 const T * CSet::insert_no_delete( const T * arg_value)
130 {
131  Manager m ;
132  m.first = & typeid(T);
133  m.second = 0 ;
134 
135  return (const T *) p_insert( m , arg_value );
136 }
137 
138 template<class T>
139 inline
140 bool CSet::remove( const T * arg_value )
141 { return p_remove( typeid(T) , arg_value ); }
142 
143 } // namespace stk_classic
144 
145 #endif /* DOXYGEN_COMPILE */
146 
147 #endif // stk_util_util_CSet_hpp
const T * insert_no_delete(const T *)
const T * get() const
bool remove(const T *)
const T * insert_with_delete(const T *)
Sierra Toolkit.
Set of entities of arbitrary types.
Definition: CSet.hpp:51