42 #ifndef TEUCHOS_SIMPLE_OBJECT_DB_HPP
43 #define TEUCHOS_SIMPLE_OBJECT_DB_HPP
47 #include "Teuchos_ConstNonconstObjectContainer.hpp"
129 template <
class TOld>
197 void validateIndex(
const int index)
const;
200 int storeObjectImpl(
const RCP<T2> &robj);
202 void removeObjImpl(
const int index);
228 return tableOfObjects_.size();
235 return freedIndices_.size();
242 return tableSize() - numFreeIndexes();
249 return storeObjectImpl(obj);
256 return storeObjectImpl(obj);
261 template <
class TOld>
264 return storeNonconstObj(rcp_dynamic_cast<T>(robj_old,
true));
271 validateIndex(index);
272 removeObjImpl(index);
279 validateIndex(index);
280 const RCP<T> obj = tableOfObjects_[index].getNonconstObj();
281 removeObjImpl(index);
289 validateIndex(index);
290 const RCP<const T> obj = tableOfObjects_[index].getConstObj();
291 removeObjImpl(index);
299 const int index_in = index;
300 validateIndex(index);
301 const int cnt = tableOfObjects_[index_in].count();
302 removeObjImpl(index_in);
311 validateIndex(index);
312 return tableOfObjects_[index].getNonconstObj();
319 validateIndex(index);
320 return tableOfObjects_[index].getConstObj();
327 validateIndex(index);
328 return tableOfObjects_[index].getNonconstObj().ptr();
335 validateIndex(index);
336 return tableOfObjects_[index].getConstObj().ptr();
357 !(0 <= index && index < as<int>(tableOfObjects_.size())),
359 "Error, the object index = " << index <<
" falls outside of the range"
360 <<
" of valid objects [0,"<<tableOfObjects_.size()<<
"]");
361 const RCP<const T> &obj = tableOfObjects_[index].getConstObj();
363 "Error, the object at index "<<index<<
" of type "
370 int SimpleObjectDB<T>::storeObjectImpl(
const RCP<T2> & robj)
372 robj.assert_not_null();
376 if (freedIndices_.size() != 0) {
377 index = freedIndices_.back();
378 freedIndices_.pop_back();
379 tableOfObjects_[index].initialize(robj);
381 tableOfObjects_.push_back(robj);
382 index = tableOfObjects_.size() - 1;
390 void SimpleObjectDB<T>::removeObjImpl(
const int index)
392 tableOfObjects_[index] = null;
393 freedIndices_.push_back(index);
400 #endif // TEUCHOS_SIMPLE_OBJECT_DB_HPP
Null reference error exception class.
Simple object object database.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
RCP< const T > getConstObjRCP(const int index) const
Get an object (const persisting association).
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
RCP< T > removeNonconstObj(const int index)
int storeNonconstObj(const RCP< T > &obj)
Store a non-const object.
RCP< T > getNonconstObjRCP(const int index)
Get an object (nonconst persisting association).
int removeRCP(int &index)
Remove an indexed object from the table.
Ptr< T > getNonconstObjPtr(const int index)
Get an object (nonconst semi-persisting association).
SimpleObjectDB()
Construct an empty DB.
int numObjects() const
Return number of non-null stored objects.
void removeObj(const int index)
Remove a stored object without returning it.
Ptr< const T > getConstObjPtr(const int index) const
Get an object (const semi-persisting association).
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
RCP< SimpleObjectDB< T > > createSimpleObjectDB()
Nonmember constructor.
friend void swap(Array< T2 > &a1, Array< T2 > &a2)
int tableSize() const
Return the current size of the table.
Templated array class derived from the STL std::vector.
Default traits class that just returns typeid(T).name().
int numFreeIndexes() const
Return number of free indexes.
int storeCastedNonconstObj(const RCP< TOld > &robj_old)
Performs an rcp_dynamic_cast<>() to store the obejct.
RCP< const T > removeConstObj(const int index)
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
Smart reference counting pointer class for automatic garbage collection.
Range error exception class.
Definition of Teuchos::as, for conversions between types.
int storeConstObj(const RCP< const T > &obj)
Store a const object.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...
void purge()
Clear out all storage.