43 #ifndef TEUCHOS_STRING_INDEXED_ORDERED_VALUE_OBJECT_CONTAINER_HPP
44 #define TEUCHOS_STRING_INDEXED_ORDERED_VALUE_OBJECT_CONTAINER_HPP
105 template<
class ObjType>
117 KeyObjectPair(
const std::string &key_in,
const ObjType &obj_in,
bool isActive_in =
true)
140 template<
class ObjType>
179 template<
class ObjType>
350 template<
class ObjType>
355 return ptrFromRef(getNonconstKeyAndObject(idx).second);
359 template<
class ObjType>
364 return ptrFromRef(getKeyAndObject(idx).second);
368 template<
class ObjType>
373 return getNonconstObjPtr(assertKeyGetOrdinal(key));
377 template<
class ObjType>
382 return getObjPtr(assertKeyGetOrdinal(key));
389 template<
class ObjType>
394 return Iterator(key_and_obj_array_.begin(), key_and_obj_array_.begin(),
395 key_and_obj_array_.end());
399 template<
class ObjType>
404 return Iterator(key_and_obj_array_.end(), key_and_obj_array_.begin(),
405 key_and_obj_array_.end());
409 template<
class ObjType>
414 return ConstIterator(key_and_obj_array_.begin(), key_and_obj_array_.begin(),
415 key_and_obj_array_.end());
419 template<
class ObjType>
424 return ConstIterator(key_and_obj_array_.end(), key_and_obj_array_.begin(),
425 key_and_obj_array_.end());
437 template<
class ObjType>
442 template<
class ObjType>
446 return key_to_idx_map_.size();
450 template<
class ObjType>
454 return key_and_obj_array_.size();
461 template<
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();
474 template<
class ObjType>
479 typename key_to_idx_map_t::iterator obj_idx_itr = key_to_idx_map_.find(key);
480 if (obj_idx_itr != key_to_idx_map_.end()) {
482 const Ordinal obj_idx = obj_idx_itr->second.idx;
483 key_and_obj_array_[obj_idx].second = obj;
488 const Ordinal new_idx = key_and_obj_array_.size()-1;
489 key_to_idx_map_[key] = new_idx;
494 template<
class ObjType>
498 key_to_idx_map_.erase(key_and_obj.
first);
499 key_and_obj = key_and_obj_t::makeInvalid();
503 template<
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);
510 const Ordinal idx = itr->second.idx;
511 key_to_idx_map_.erase(itr);
512 key_and_obj_array_[idx] = key_and_obj_t::makeInvalid();
519 template<
class ObjType>
524 "Error, the ordinal index " << idx <<
" is invalid"
525 <<
" because it falls outside of the range of valid objects"
526 <<
" [0,"<<numStorage()-1<<
"]!");
530 template<
class ObjType>
534 assertOrdinalIndex(idx);
538 "Error, the ordinal index " << idx <<
" is invalid"
539 <<
" because the object has been deleted!");
544 template<
class ObjType>
548 assertOrdinalIndex(idx);
552 "Error, the ordinal index " << idx <<
" is invalid"
553 <<
" because the object has been deleted!");
558 template<
class ObjType>
561 const Ordinal idx,
const std::string &key)
const
564 "Error, the key '" << key <<
"' does not exist!");
568 template<
class ObjType>
572 const Ordinal idx = getObjOrdinalIndex(key);
573 throwInvalidKeyError(idx, key);
599 #endif // TEUCHOS_STRING_INDEXED_ORDERED_VALUE_OBJECT_CONTAINER_HPP
std::map< std::string, OrdinalIndex > key_to_idx_map_t
C++ Standard Library compatable filtered iterator.
Ordinal getObjOrdinalIndex(const std::string &key) const
Get the ordinal index given the string key.
FilteredIterator< typename key_and_obj_array_t::iterator, SelectActive< ObjType > > Iterator
The non-const iterator type.
key_and_obj_array_t key_and_obj_array_
Stories objects contiguously along with key strings.
String indexed ordered value-type object container class.
A simple aggregate type to bind a key string and and objects value.
std::deque< key_and_obj_t > key_and_obj_array_t
A safe ordinal index type that default initializes to a special value.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
InvalidOrdinalIndexError(const std::string &what_arg)
StringIndexedOrderedValueObjectContainerBase::Ordinal Ordinal
Ordinal used for the index.
Ordinal assertKeyGetOrdinal(const std::string &key) const
InvalidKeyError(const std::string &what_arg)
void assertOrdinalIndex(const Ordinal idx) const
KeyObjectPair(const KeyObjectPair< ObjType > &kop)
ConstIterator end() const
Thrown if an invalid string is passed in.
KeyObjectPair(const std::string &key_in, const ObjType &obj_in, bool isActive_in=true)
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
ExceptionBase(const std::string &what_arg)
FilteredIterator< typename key_and_obj_array_t::const_iterator, SelectActive< ObjType > > ConstIterator
The const iterator type.
static KeyObjectPair< ObjType > makeInvalid()
bool operator()(const KeyObjectPair< ObjType > &key_and_obj) const
StringIndexedOrderedValueObjectContainer()
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
StringIndexedOrderedValueObjectContainerBase::Ordinal Ordinal
KeyObjectPair< ObjType > & operator=(const KeyObjectPair< ObjType > &kop)
Templated array class derived from the STL std::vector.
const std::string & first
Ordinal setObj(const std::string &key, const ObjType &obj)
Set (or reset) object by value and return its ordinal index.
virtual ~StringIndexedOrderedValueObjectContainerBase()
Destructor.
Ordinal numStorage() const
ConstIterator begin() const
key_to_idx_map_t key_to_idx_map_
Provides lookups of key -> ordinal index into above array.
Predicate for selecting active object entries in filtered iterator.
const key_and_obj_t & getKeyAndObject(const Ordinal idx) const
key_and_obj_t & getNonconstKeyAndObject(const Ordinal idx)
void removeObj(const Ordinal &idx)
Remove an object given its ordinal index.
Base exception class for Teuchos.
Ordinal numObjects() const
Ptr< ObjType > getNonconstObjPtr(const Ordinal &idx)
Get a nonconst semi-persisting association with the stored object indexed by ordinal.
Teuchos_Ordinal Ordinal
Ordinal used for the index.
void throwInvalidKeyError(const Ordinal idx, const std::string &key) const
static Ordinal getInvalidOrdinal()
Return the value for invalid ordinal.
Base types for StringIndexedOrderedValueObjectContainer.
KeyObjectPair< ObjType > key_and_obj_t
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
Thrown if an invalid ordinal index is passed in.
OrdinalIndex(const Ordinal idx_in)