/* * IndexSetContainer.hpp * * Created on: Jul 3, 2012 * Author: heber */ #ifndef INDEXSETCONTAINER_HPP_ #define INDEXSETCONTAINER_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "IndexSet.hpp" #include "SortedVector.hpp" class IndexSetContainerTest; class KeySetsContainer; /** * As the IndexSet is supposed to appear in many maps and Containers as it may * be contained in other IndexSet's, we store it always as a shared_ptr. This * Container is then responsible that the ordering within the container still * allows for fast access due to sorted appearance not by order in memory but * order defined by IndexSet comparison operators. * */ //!> typedef for IndexSet instances stored in SortedVector class IndexSetContainer : public SortedVector { //!> grant unit test access to protected members of SortedVector friend class IndexSetContainerTest; public: //!> typedef for IndexSetContainer wrapped in shared_ptr typedef boost::shared_ptr ptr; /** Constructor from a sorted vector of instances. * * @param _container sorted vector of instances */ IndexSetContainer(const SortedVector::Container_t &_container); /** Constructor from an unsorted vector of instances. * * @param _container unsorted vector of instances */ IndexSetContainer(const std::vector &_container); /** Constructor from a single instance. * * @param _instance single instance */ IndexSetContainer(IndexSet::ptr &_instance); /** Conversion constructor from a KeySetConntainer. * * We create the super set of all found key sets and then each single set, * while always dropping indices equal to -1. * * @param _keysets keysets to turn into IndexSets */ explicit IndexSetContainer(const KeySetsContainer &_keysets); /** Sum up the number of IndexSets with indices less or equal to \a level. * * Sadly, we have to re-implement a binary search as size_t != IndexSet::ptr. * * @param level maximum set size * @return number of sets up till \a level */ size_t countSetsTillLevel(const size_t level) const; /** Getter to the super set. * * @return AllIndices */ const IndexSet::ptr getSuperSet() const { return AllIndices; } private: /** Helper function to create the super set out of a KeySetsContainer. * * @param _keysets keysets to construct super set for * @return super set created from all keysets in \a _keysets */ IndexSet::ptr createSuperSet(const KeySetsContainer &_keysets) const; /** Helper function to create the super set out of a vector of IndexSet's. * * @param _container container with IndexSet's to construct super set for * @return super set created from all IndexSet's in \a _container */ IndexSet::ptr createSuperSet(const std::vector &_container) const; /** Helper function to create the super set out of a vector of IndexSet's. * * @param _container container with IndexSet's to construct super set for * @return super set created from all IndexSet's in \a _container */ IndexSet::ptr createSuperSet(const std::vector &_container) const; //!> super set that contains all present index sets IndexSet::ptr AllIndices; }; inline IndexSetContainer::IndexSetContainer(const SortedVector::Container_t &_container) : SortedVector(_container), AllIndices(createSuperSet(_container)) {} inline IndexSetContainer::IndexSetContainer(const std::vector &_container) : SortedVector(_container), AllIndices(createSuperSet(_container)) {} inline IndexSetContainer::IndexSetContainer(IndexSet::ptr &_instance) : SortedVector(_instance), AllIndices(_instance) {} //!> typedef for IndexSet instance stored as shared_ptr in SortedVector typedef IndexSetContainer::T_ptr IndexSet_ptr; #endif /* INDEXSETCONTAINER_HPP_ */