45 #ifndef TEUCHOS_SIMPLEOBJECTTABLE_HPP
46 #define TEUCHOS_SIMPLEOBJECTTABLE_HPP
68 int storeRCP(
const RCP<T> & robj);
70 int storeNew(T* obj,
bool owned =
true);
73 int storeCastedRCP(
const RCP<TOld> & robj_old);
75 int removeRCP(
int &index);
77 const RCP<T> getRCP(
int index);
96 SimpleObjectTable<T>::~SimpleObjectTable()
102 int SimpleObjectTable<T>::storeRCP(
const RCP<T> & robj)
104 robj.assert_not_null();
108 if (freedIndices.size() != 0) {
109 index = freedIndices.back();
110 freedIndices.pop_back();
111 tableOfObjects[index] = robj;
113 tableOfObjects.push_back(robj);
114 index = tableOfObjects.size() - 1;
121 int SimpleObjectTable<T>::storeNew(T* obj,
bool owned)
123 return storeRCP(
rcp(obj, owned));
127 template <
class TOld>
128 int SimpleObjectTable<T>::storeCastedRCP(
const RCP<TOld> & robj_old)
130 return storeRCP(rcp_dynamic_cast<T>(robj_old,
true));
134 int SimpleObjectTable<T>::removeRCP(
int &index)
136 if (tableOfObjects[index] == Teuchos::null) {
137 throw RangeError(
"Item has already been deleted from SimpleObjectTable.");
140 int cnt = tableOfObjects[index].strong_count();
142 tableOfObjects[index] = Teuchos::null;
143 freedIndices.push_back(index);
150 const RCP<T> SimpleObjectTable<T>::getRCP(
int index)
152 if (tableOfObjects[index] == Teuchos::null) {
153 throw RangeError(
"Item has already been deleted from SimpleObjectTable.");
156 return tableOfObjects[index];
160 void SimpleObjectTable<T>::purge()
162 int ocnt = tableOfObjects.size();
163 for (
int i=0; i<ocnt; i++) {
164 tableOfObjects[i] = Teuchos::null;
167 if (tableOfObjects.size() > 0)
168 tableOfObjects.erase(tableOfObjects.begin(), tableOfObjects.end());
169 if (freedIndices.size() > 0)
170 freedIndices.erase(freedIndices.begin(), freedIndices.end());
This class provides a central place to store objects.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Templated array class derived from the STL std::vector.
Smart reference counting pointer class for automatic garbage collection.
Reference-counted pointer class and non-member templated function implementations.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...