10#ifndef TEUCHOS_SIMPLE_OBJECT_DB_HPP
11#define TEUCHOS_SIMPLE_OBJECT_DB_HPP
15#include "Teuchos_ConstNonconstObjectContainer.hpp"
162 tableOfObjects_t tableOfObjects_;
163 freedIndices_t freedIndices_;
165 void validateIndex(
const int index)
const;
168 int storeObjectImpl(
const RCP<T2> &robj);
170 void removeObjImpl(
const int index);
196 return tableOfObjects_.size();
203 return freedIndices_.size();
217 return storeObjectImpl(obj);
224 return storeObjectImpl(obj);
239 validateIndex(index);
240 removeObjImpl(index);
247 validateIndex(index);
248 const RCP<T> obj = tableOfObjects_[index].getNonconstObj();
249 removeObjImpl(index);
257 validateIndex(index);
258 const RCP<const T> obj = tableOfObjects_[index].getConstObj();
259 removeObjImpl(index);
267 const int index_in = index;
268 validateIndex(index);
269 const int cnt = tableOfObjects_[index_in].count();
270 removeObjImpl(index_in);
279 validateIndex(index);
280#ifdef TEUCHOS_IMPL_GCC_12_NONNULL_WORKAROUND
281 return tableOfObjects_.at(index).getNonconstObj();
283 return tableOfObjects_[index].getNonconstObj();
291 validateIndex(index);
292#ifdef TEUCHOS_IMPL_GCC_12_NONNULL_WORKAROUND
293 return tableOfObjects_.at(index).getConstObj();
295 return tableOfObjects_[index].getConstObj();
303 validateIndex(index);
304#ifdef TEUCHOS_IMPL_GCC_12_NONNULL_WORKAROUND
305 return tableOfObjects_.at(index).getNonconstObj().ptr();
307 return tableOfObjects_[index].getNonconstObj().ptr();
315 validateIndex(index);
316#ifdef TEUCHOS_IMPL_GCC_12_NONNULL_WORKAROUND
317 return tableOfObjects_.at(index).getConstObj().ptr();
319 return tableOfObjects_[index].getConstObj().ptr();
328 tableOfObjects_t().swap(tableOfObjects_);
329 freedIndices_t().swap(freedIndices_);
337void SimpleObjectDB<T>::validateIndex(
const int index)
const
341 !(0 <= index && index <
as<int>(tableOfObjects_.size())),
343 "Error, the object index = " << index <<
" falls outside of the range"
344 <<
" of valid objects [0,"<<tableOfObjects_.size()<<
"]");
345 const RCP<const T> &obj = tableOfObjects_[index].getConstObj();
347 "Error, the object at index "<<index<<
" of type "
354int SimpleObjectDB<T>::storeObjectImpl(
const RCP<T2> & robj)
356 robj.assert_not_null();
360 if (freedIndices_.size() != 0) {
361 index = freedIndices_.back();
362 freedIndices_.pop_back();
363 tableOfObjects_[index].initialize(robj);
365 tableOfObjects_.push_back(robj);
366 index = tableOfObjects_.size() - 1;
374void SimpleObjectDB<T>::removeObjImpl(
const int index)
376 tableOfObjects_[index] = null;
377 freedIndices_.push_back(index);
Templated array class derived from the STL std::vector.
Definition of Teuchos::as, for conversions between types.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes.
Null reference error exception class.
Simple wrapper class for raw pointers to single objects where no persisting relationship exists.
Smart reference counting pointer class for automatic garbage collection.
RCP< T2 > rcp_dynamic_cast(const RCP< T1 > &p1, bool throw_on_fail=false)
Dynamic cast of underlying RCP type from T1* to T2*.
Range error exception class.
Simple object object database.
int storeCastedNonconstObj(const RCP< TOld > &robj_old)
Performs an rcp_dynamic_cast<>() to store the obejct.
int removeRCP(int &index)
Remove an indexed object from the table.
RCP< const T > removeConstObj(const int index)
int storeNonconstObj(const RCP< T > &obj)
Store a non-const object.
void purge()
Clear out all storage.
RCP< T > removeNonconstObj(const int index)
void removeObj(const int index)
Remove a stored object without returning it.
SimpleObjectDB()
Construct an empty DB.
int storeConstObj(const RCP< const T > &obj)
Store a const object.
int numFreeIndexes() const
Return number of free indexes.
int tableSize() const
Return the current size of the table.
int numObjects() const
Return number of non-null stored objects.
Ptr< T > getNonconstObjPtr(const int index)
Get an object (nonconst semi-persisting association).
RCP< T > getNonconstObjRCP(const int index)
Get an object (nonconst persisting association).
RCP< const T > getConstObjRCP(const int index) const
Get an object (const persisting association).
Ptr< const T > getConstObjPtr(const int index) const
Get an object (const semi-persisting association).
static std::string name()
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
RCP< SimpleObjectDB< T > > createSimpleObjectDB()
Nonmember constructor.