| 1 | /*
|
|---|
| 2 | * IndexSet.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Apr 24, 2011
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 | #ifndef INDEXSET_HPP_
|
|---|
| 9 | #define INDEXSET_HPP_
|
|---|
| 10 |
|
|---|
| 11 | // include config.h
|
|---|
| 12 | #ifdef HAVE_CONFIG_H
|
|---|
| 13 | #include <config.h>
|
|---|
| 14 | #endif
|
|---|
| 15 |
|
|---|
| 16 | // bug in boost/serialization 1.58. set.hpp needs serialization.hpp included before
|
|---|
| 17 | #include <boost/serialization/serialization.hpp>
|
|---|
| 18 |
|
|---|
| 19 | #include <boost/serialization/access.hpp>
|
|---|
| 20 | #include <boost/serialization/base_object.hpp>
|
|---|
| 21 | #include <boost/serialization/set.hpp>
|
|---|
| 22 | #include <boost/serialization/shared_ptr.hpp>
|
|---|
| 23 |
|
|---|
| 24 | #include <boost/shared_ptr.hpp>
|
|---|
| 25 | #include <set>
|
|---|
| 26 |
|
|---|
| 27 | //!> is the type of an index
|
|---|
| 28 | typedef size_t Index_t;
|
|---|
| 29 |
|
|---|
| 30 | /** This class represents a single set of indices along with functions to order them
|
|---|
| 31 | * and check whether one is contained in another.
|
|---|
| 32 | */
|
|---|
| 33 | class IndexSet : public std::set<Index_t>
|
|---|
| 34 | {
|
|---|
| 35 | public:
|
|---|
| 36 | //!> typedef for instance wrapped in share_ptr
|
|---|
| 37 | typedef boost::shared_ptr<IndexSet> ptr;
|
|---|
| 38 |
|
|---|
| 39 | IndexSet();
|
|---|
| 40 |
|
|---|
| 41 | ~IndexSet();
|
|---|
| 42 |
|
|---|
| 43 | // index set contain checks
|
|---|
| 44 | bool contains(const IndexSet &_indexset) const;
|
|---|
| 45 | bool contains(const Index_t _index) const;
|
|---|
| 46 |
|
|---|
| 47 | // comparison
|
|---|
| 48 | bool operator<(const IndexSet &b) const;
|
|---|
| 49 | bool operator>(const IndexSet &b) const;
|
|---|
| 50 | bool operator==(const IndexSet &b) const;
|
|---|
| 51 | bool operator!=(const IndexSet &b) const
|
|---|
| 52 | {
|
|---|
| 53 | return !(*this == b);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | private:
|
|---|
| 57 | friend class boost::serialization::access;
|
|---|
| 58 | // serialization
|
|---|
| 59 | template <typename Archive>
|
|---|
| 60 | void serialize(Archive& ar, const unsigned int version)
|
|---|
| 61 | {
|
|---|
| 62 | ar & boost::serialization::base_object< std::set<Index_t> >(*this);
|
|---|
| 63 | }
|
|---|
| 64 | };
|
|---|
| 65 |
|
|---|
| 66 | inline bool operator==(const IndexSet::ptr &a, const IndexSet::ptr &b)
|
|---|
| 67 | {
|
|---|
| 68 | return (*a == *b);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | inline bool operator!=(const IndexSet::ptr &a, const IndexSet::ptr &b)
|
|---|
| 72 | {
|
|---|
| 73 | return (*a != *b);
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | inline bool operator<(const IndexSet::ptr &a, const IndexSet::ptr &b)
|
|---|
| 77 | {
|
|---|
| 78 | return (*a < *b);
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | inline bool operator>(const IndexSet::ptr &a, const IndexSet::ptr &b)
|
|---|
| 82 | {
|
|---|
| 83 | return (*a > *b);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | std::ostream & operator<<(std::ostream &ost, const IndexSet &indexset);
|
|---|
| 87 |
|
|---|
| 88 | BOOST_SERIALIZATION_SHARED_PTR(IndexSet)
|
|---|
| 89 |
|
|---|
| 90 | #endif /* INDEXSET_HPP_ */
|
|---|