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