10 #ifndef TEUCHOS_SIMPLE_OBJECT_DB_HPP
11 #define TEUCHOS_SIMPLE_OBJECT_DB_HPP
196 return tableOfObjects_.size();
203 return freedIndices_.size();
210 return tableSize() - numFreeIndexes();
217 return storeObjectImpl(obj);
224 return storeObjectImpl(obj);
229 template <
class TOld>
232 return storeNonconstObj(rcp_dynamic_cast<T>(robj_old,
true));
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 return tableOfObjects_[index].getNonconstObj();
287 validateIndex(index);
288 return tableOfObjects_[index].getConstObj();
295 validateIndex(index);
296 return tableOfObjects_[index].getNonconstObj().ptr();
303 validateIndex(index);
304 return tableOfObjects_[index].getConstObj().ptr();
325 !(0 <= index && index < as<int>(tableOfObjects_.size())),
327 "Error, the object index = " << index <<
" falls outside of the range"
328 <<
" of valid objects [0,"<<tableOfObjects_.size()<<
"]");
329 const RCP<const T> &obj = tableOfObjects_[index].getConstObj();
331 "Error, the object at index "<<index<<
" of type "
344 if (freedIndices_.size() != 0) {
345 index = freedIndices_.back();
346 freedIndices_.pop_back();
347 tableOfObjects_[index].initialize(robj);
349 tableOfObjects_.push_back(robj);
350 index = tableOfObjects_.size() - 1;
360 tableOfObjects_[index] =
null;
361 freedIndices_.push_back(index);
368 #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)
void validateIndex(const int index) const
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.
freedIndices_t freedIndices_
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.
Array< int > freedIndices_t
friend void swap(Array< T2 > &a1, Array< T2 > &a2)
int tableSize() const
Return the current size of the table.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
void removeObjImpl(const int index)
const RCP< T > & assert_not_null() const
Throws NullReferenceError if this->get()==NULL, otherwise returns reference to *this.
Templated array class derived from the STL std::vector.
Array< ConstNonconstObjectContainer< T > > tableOfObjects_t
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)
Smart reference counting pointer class for automatic garbage collection.
Range error exception class.
Definition of Teuchos::as, for conversions between types.
int storeObjectImpl(const RCP< T2 > &robj)
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...
tableOfObjects_t tableOfObjects_
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...
void purge()
Clear out all storage.