13 #ifndef TEUCHOS_SIMPLEOBJECTTABLE_HPP
14 #define TEUCHOS_SIMPLEOBJECTTABLE_HPP
36 int storeRCP(
const RCP<T> & robj);
38 int storeNew(T* obj,
bool owned =
true);
41 int storeCastedRCP(
const RCP<TOld> & robj_old);
43 int removeRCP(
int &index);
45 const RCP<T> getRCP(
int index);
64 SimpleObjectTable<T>::~SimpleObjectTable()
70 int SimpleObjectTable<T>::storeRCP(
const RCP<T> & robj)
72 robj.assert_not_null();
76 if (freedIndices.size() != 0) {
77 index = freedIndices.back();
78 freedIndices.pop_back();
79 tableOfObjects[index] = robj;
81 tableOfObjects.push_back(robj);
82 index = tableOfObjects.size() - 1;
89 int SimpleObjectTable<T>::storeNew(T* obj,
bool owned)
91 return storeRCP(
rcp(obj, owned));
96 int SimpleObjectTable<T>::storeCastedRCP(
const RCP<TOld> & robj_old)
98 return storeRCP(rcp_dynamic_cast<T>(robj_old,
true));
102 int SimpleObjectTable<T>::removeRCP(
int &index)
104 if (tableOfObjects[index] == Teuchos::null) {
105 throw RangeError(
"Item has already been deleted from SimpleObjectTable.");
108 int cnt = tableOfObjects[index].strong_count();
110 tableOfObjects[index] = Teuchos::null;
111 freedIndices.push_back(index);
118 const RCP<T> SimpleObjectTable<T>::getRCP(
int index)
120 if (tableOfObjects[index] == Teuchos::null) {
121 throw RangeError(
"Item has already been deleted from SimpleObjectTable.");
124 return tableOfObjects[index];
128 void SimpleObjectTable<T>::purge()
130 int ocnt = tableOfObjects.size();
131 for (
int i=0; i<ocnt; i++) {
132 tableOfObjects[i] = Teuchos::null;
135 if (tableOfObjects.size() > 0)
136 tableOfObjects.erase(tableOfObjects.begin(), tableOfObjects.end());
137 if (freedIndices.size() > 0)
138 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...