43 #ifndef TEUCHOS_STRING_INDEXED_ORDERED_VALUE_OBJECT_CONTAINER_HPP 44 #define TEUCHOS_STRING_INDEXED_ORDERED_VALUE_OBJECT_CONTAINER_HPP 103 template<
class ObjType>
115 KeyObjectPair(
const std::string &key_in,
const ObjType &obj_in,
bool isActive_in =
true)
138 template<
class ObjType>
177 template<
class ObjType>
348 template<
class ObjType>
353 return ptrFromRef(getNonconstKeyAndObject(idx).second);
357 template<
class ObjType>
362 return ptrFromRef(getKeyAndObject(idx).second);
366 template<
class ObjType>
371 return getNonconstObjPtr(assertKeyGetOrdinal(key));
375 template<
class ObjType>
380 return getObjPtr(assertKeyGetOrdinal(key));
387 template<
class ObjType>
392 return Iterator(key_and_obj_array_.begin(), key_and_obj_array_.begin(),
393 key_and_obj_array_.end());
397 template<
class ObjType>
402 return Iterator(key_and_obj_array_.end(), key_and_obj_array_.begin(),
403 key_and_obj_array_.end());
407 template<
class ObjType>
412 return ConstIterator(key_and_obj_array_.begin(), key_and_obj_array_.begin(),
413 key_and_obj_array_.end());
417 template<
class ObjType>
422 return ConstIterator(key_and_obj_array_.end(), key_and_obj_array_.begin(),
423 key_and_obj_array_.end());
435 template<
class ObjType>
440 template<
class ObjType>
444 return key_to_idx_map_.size();
448 template<
class ObjType>
452 return key_and_obj_array_.size();
459 template<
class ObjType>
464 key_to_idx_map_t::const_iterator itr = key_to_idx_map_.find(key);
465 if (itr != key_to_idx_map_.end()) {
466 return itr->second.idx;
468 return getInvalidOrdinal();
472 template<
class ObjType>
477 typename key_to_idx_map_t::iterator obj_idx_itr = key_to_idx_map_.find(key);
478 if (obj_idx_itr != key_to_idx_map_.end()) {
480 const Ordinal obj_idx = obj_idx_itr->second.idx;
481 key_and_obj_array_[obj_idx].second = obj;
486 const Ordinal new_idx = key_and_obj_array_.size()-1;
487 key_to_idx_map_[key] = new_idx;
492 template<
class ObjType>
496 key_to_idx_map_.erase(key_and_obj.
first);
497 key_and_obj = key_and_obj_t::makeInvalid();
501 template<
class ObjType>
504 typename key_to_idx_map_t::iterator itr = key_to_idx_map_.find(key);
505 if (itr == key_to_idx_map_.end()) {
506 throwInvalidKeyError(getInvalidOrdinal(), key);
508 const Ordinal idx = itr->second.idx;
509 key_to_idx_map_.erase(itr);
510 key_and_obj_array_[idx] = key_and_obj_t::makeInvalid();
517 template<
class ObjType>
522 "Error, the ordinal index " << idx <<
" is invalid" 523 <<
" because it falls outside of the range of valid objects" 524 <<
" [0,"<<numStorage()-1<<
"]!");
528 template<
class ObjType>
532 assertOrdinalIndex(idx);
536 "Error, the ordinal index " << idx <<
" is invalid" 537 <<
" because the object has been deleted!");
542 template<
class ObjType>
546 assertOrdinalIndex(idx);
550 "Error, the ordinal index " << idx <<
" is invalid" 551 <<
" because the object has been deleted!");
556 template<
class ObjType>
559 const Ordinal idx,
const std::string &key)
const 562 "Error, the key '" << key <<
"' does not exist!");
566 template<
class ObjType>
570 const Ordinal idx = getObjOrdinalIndex(key);
571 throwInvalidKeyError(idx, key);
597 #endif // TEUCHOS_STRING_INDEXED_ORDERED_VALUE_OBJECT_CONTAINER_HPP const key_and_obj_t & getKeyAndObject(const Ordinal idx) const
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.
Ptr< const ObjType > getObjPtr(const Ordinal &idx) const
Get a const semi-persisting association with the stored object indexed by ordinal.
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.
bool operator()(const KeyObjectPair< ObjType > &key_and_obj) const
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.
InvalidKeyError(const std::string &what_arg)
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
void throwInvalidKeyError(const Ordinal idx, const std::string &key) const
ExceptionBase(const std::string &what_arg)
FilteredIterator< typename key_and_obj_array_t::const_iterator, SelectActive< ObjType > > ConstIterator
The const iterator type.
Ordinal numStorage() const
static KeyObjectPair< ObjType > makeInvalid()
ConstIterator begin() const
Ordinal numObjects() const
StringIndexedOrderedValueObjectContainer()
StringIndexedOrderedValueObjectContainerBase::Ordinal Ordinal
KeyObjectPair< ObjType > & operator=(const KeyObjectPair< ObjType > &kop)
Templated array class derived from the STL std::vector.
void assertOrdinalIndex(const Ordinal idx) const
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.
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.
Ordinal assertKeyGetOrdinal(const std::string &key) 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.
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.
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)