43#ifndef TEUCHOS_STRING_INDEXED_ORDERED_VALUE_OBJECT_CONTAINER_HPP
44#define TEUCHOS_STRING_INDEXED_ORDERED_VALUE_OBJECT_CONTAINER_HPP
48#include "Teuchos_FilteredIterator.hpp"
105 template<
class ObjType>
127 isActive_ =
kop.isActive_;
140 template<
class ObjType>
179template<
class ObjType>
188 typedef std::deque<key_and_obj_t> key_and_obj_array_t;
190 typedef std::map<std::string, OrdinalIndex> key_to_idx_map_t;
296 key_and_obj_array_t key_and_obj_array_;
298 key_to_idx_map_t key_to_idx_map_;
325 void assertOrdinalIndex(
const Ordinal idx)
const;
334 void throwInvalidKeyError(
const Ordinal idx,
const std::string &key)
const;
337 Ordinal assertKeyGetOrdinal(
const std::string &key)
const;
350template<
class ObjType>
355 return ptrFromRef(getNonconstKeyAndObject(idx).second);
359template<
class ObjType>
364 return ptrFromRef(getKeyAndObject(idx).second);
368template<
class ObjType>
373 return getNonconstObjPtr(assertKeyGetOrdinal(key));
377template<
class ObjType>
382 return getObjPtr(assertKeyGetOrdinal(key));
389template<
class ObjType>
394 return Iterator(key_and_obj_array_.begin(), key_and_obj_array_.begin(),
395 key_and_obj_array_.end());
399template<
class ObjType>
404 return Iterator(key_and_obj_array_.end(), key_and_obj_array_.begin(),
405 key_and_obj_array_.end());
409template<
class ObjType>
414 return ConstIterator(key_and_obj_array_.begin(), key_and_obj_array_.begin(),
415 key_and_obj_array_.end());
419template<
class ObjType>
424 return ConstIterator(key_and_obj_array_.end(), key_and_obj_array_.begin(),
425 key_and_obj_array_.end());
437template<
class ObjType>
442template<
class ObjType>
446 return key_to_idx_map_.size();
450template<
class ObjType>
454 return key_and_obj_array_.size();
461template<
class ObjType>
466 key_to_idx_map_t::const_iterator
itr = key_to_idx_map_.find(key);
467 if (
itr != key_to_idx_map_.end()) {
468 return itr->second.idx;
470 return getInvalidOrdinal();
474template<
class ObjType>
479 typename key_to_idx_map_t::iterator
obj_idx_itr = key_to_idx_map_.find(key);
483 key_and_obj_array_[
obj_idx].second = obj;
489 key_to_idx_map_[key] =
new_idx;
494template<
class ObjType>
503template<
class ObjType>
506 typename key_to_idx_map_t::iterator
itr = key_to_idx_map_.find(key);
507 if (
itr == key_to_idx_map_.end()) {
508 throwInvalidKeyError(getInvalidOrdinal(), key);
511 key_to_idx_map_.erase(
itr);
512 key_and_obj_array_[idx] = key_and_obj_t::makeInvalid();
519template<
class ObjType>
523 InvalidOrdinalIndexError,
524 "Error, the ordinal index " << idx <<
" is invalid"
525 <<
" because it falls outside of the range of valid objects"
526 <<
" [0,"<<numStorage()-1<<
"]!");
530template<
class ObjType>
531typename StringIndexedOrderedValueObjectContainer<ObjType>::key_and_obj_t&
532StringIndexedOrderedValueObjectContainer<ObjType>::getNonconstKeyAndObject(
const Ordinal idx)
534 assertOrdinalIndex(idx);
535 key_and_obj_t &
key_and_obj = key_and_obj_array_[idx];
537 InvalidOrdinalIndexError,
538 "Error, the ordinal index " << idx <<
" is invalid"
539 <<
" because the object has been deleted!");
544template<
class ObjType>
545const typename StringIndexedOrderedValueObjectContainer<ObjType>::key_and_obj_t&
546StringIndexedOrderedValueObjectContainer<ObjType>::getKeyAndObject(
const Ordinal idx)
const
548 assertOrdinalIndex(idx);
549 const key_and_obj_t &
key_and_obj = key_and_obj_array_[idx];
551 InvalidOrdinalIndexError,
552 "Error, the ordinal index " << idx <<
" is invalid"
553 <<
" because the object has been deleted!");
558template<
class ObjType>
560StringIndexedOrderedValueObjectContainer<ObjType>::throwInvalidKeyError(
561 const Ordinal idx,
const std::string &key)
const
564 "Error, the key '" << key <<
"' does not exist!");
568template<
class ObjType>
570StringIndexedOrderedValueObjectContainer<ObjType>::assertKeyGetOrdinal(
const std::string &key)
const
572 const Ordinal idx = getObjOrdinalIndex(key);
573 throwInvalidKeyError(idx, key);
Templated array class derived from the STL std::vector.
Base exception class for Teuchos.
Smart reference counting pointer class for automatic garbage collection.
RCP(ENull null_arg=null)
Initialize RCP<T> to NULL.
Thrown if an invalid string is passed in.
Thrown if an invalid ordinal index is passed in.
A simple aggregate type to bind a key string and and objects value.
const std::string & first
KeyObjectPair< ObjType > & operator=(const KeyObjectPair< ObjType > &kop)
KeyObjectPair(const std::string &key_in, const ObjType &obj_in, bool isActive_in=true)
KeyObjectPair(const KeyObjectPair< ObjType > &kop)
static KeyObjectPair< ObjType > makeInvalid()
A safe ordinal index type that default initializes to a special value.
StringIndexedOrderedValueObjectContainerBase::Ordinal Ordinal
OrdinalIndex(const Ordinal idx_in)
Predicate for selecting active object entries in filtered iterator.
Base types for StringIndexedOrderedValueObjectContainer.
virtual ~StringIndexedOrderedValueObjectContainerBase()
Destructor.
static Ordinal getInvalidOrdinal()
Return the value for invalid ordinal.
Teuchos_Ordinal Ordinal
Ordinal used for the index.
String indexed ordered value-type object container class.
ConstIterator end() const
Ptr< const ObjType > getObjPtr(const std::string &key) const
Get a const semi-persisting association with the stored object indexed by string key.
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
FilteredIterator< typename key_and_obj_array_t::const_iterator, SelectActive< ObjType > > ConstIterator
The const iterator type.
Ordinal numObjects() const
FilteredIterator< typename key_and_obj_array_t::iterator, SelectActive< ObjType > > Iterator
The non-const iterator type.
void removeObj(const Ordinal &idx)
Remove an object given its ordinal index.
Ordinal numStorage() const
Ptr< ObjType > getNonconstObjPtr(const std::string &key)
Get a nonconst semi-persisting association with the stored object indexed by string key.
ConstIterator begin() const
Ptr< ObjType > getNonconstObjPtr(const Ordinal &idx)
Get a nonconst semi-persisting association with the stored object indexed by ordinal.
Ordinal setObj(const std::string &key, const ObjType &obj)
Set (or reset) object by value and return its ordinal index.
StringIndexedOrderedValueObjectContainerBase::Ordinal Ordinal
Ordinal used for the index.
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
void removeObj(const std::string &key)
Remove an object given its string key.
StringIndexedOrderedValueObjectContainer()
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos,...