[146c26d] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2011-2012 University of Bonn. All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * IndexSet.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Apr 24, 2011
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include "CodePatterns/MemDebug.hpp"
|
---|
| 36 |
|
---|
| 37 | #include "IndexSet.hpp"
|
---|
| 38 |
|
---|
| 39 | #include <boost/foreach.hpp>
|
---|
| 40 |
|
---|
| 41 | /** Constructor for class IndexSet.
|
---|
| 42 | *
|
---|
| 43 | */
|
---|
| 44 | IndexSet::IndexSet()
|
---|
| 45 | {}
|
---|
| 46 |
|
---|
| 47 | /** Destructor for class IndexSet.
|
---|
| 48 | *
|
---|
| 49 | */
|
---|
| 50 | IndexSet::~IndexSet()
|
---|
| 51 | {
|
---|
| 52 | clear();
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /** Operator for output to std::ostream operator of an IndexSet.
|
---|
| 56 | * @param ost output stream
|
---|
| 57 | * @param indexset index set to output
|
---|
| 58 | * @return ost output stream
|
---|
| 59 | */
|
---|
| 60 | std::ostream & operator<<(std::ostream &ost, const IndexSet &indexset)
|
---|
| 61 | {
|
---|
| 62 | ost << "{ ";
|
---|
| 63 | for (IndexSet::const_iterator iter = indexset.begin();
|
---|
| 64 | iter != indexset.end();
|
---|
| 65 | ++iter)
|
---|
| 66 | ost << *iter << " ";
|
---|
| 67 | ost << "}";
|
---|
| 68 | return ost;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | /** Checks whether each index of _IndexSet is contained in this subspace:Indices.
|
---|
| 72 | *
|
---|
| 73 | * @param _indexset index set to check
|
---|
| 74 | * @return true - _index is contained, false - at least index is not contained
|
---|
| 75 | */
|
---|
| 76 | bool IndexSet::contains(const IndexSet &_indexset) const
|
---|
| 77 | {
|
---|
| 78 | BOOST_FOREACH(size_t index, _indexset) {
|
---|
| 79 | if (!contains(index)) { // index not present, then not contained
|
---|
| 80 | return false;
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | return true;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /** Checks whether index is contained in this IndexSet.
|
---|
| 87 | *
|
---|
| 88 | * @param _index index to check
|
---|
| 89 | * @return true - _index is contained, false - at least index is not contained
|
---|
| 90 | */
|
---|
| 91 | bool IndexSet::contains(const Index_t _index) const
|
---|
| 92 | {
|
---|
| 93 | const_iterator iter = find(_index);
|
---|
| 94 | if (iter == end()) { // index not present, then not contained
|
---|
| 95 | return false;
|
---|
| 96 | } else {
|
---|
| 97 | return true;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | bool IndexSet::operator<(const IndexSet &b) const
|
---|
| 102 | {
|
---|
| 103 | if (size() < b.size()) {
|
---|
| 104 | return true;
|
---|
| 105 | } else if (size() > b.size()) {
|
---|
| 106 | return false;
|
---|
| 107 | } else {
|
---|
| 108 | const_iterator this_iter = begin();
|
---|
| 109 | const_iterator b_iter = b.begin();
|
---|
| 110 | for (;(this_iter != end()) && (b_iter != b.end());
|
---|
| 111 | ++this_iter, ++b_iter) {
|
---|
| 112 | if (*this_iter < *b_iter) {
|
---|
| 113 | return true;
|
---|
| 114 | } else if (*this_iter > *b_iter) {
|
---|
| 115 | return false;
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
| 118 | return false;
|
---|
| 119 | }
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 | bool IndexSet::operator>(const IndexSet &b) const
|
---|
| 123 | {
|
---|
| 124 | if (size() > b.size()) {
|
---|
| 125 | return true;
|
---|
| 126 | } else if (size() < b.size()) {
|
---|
| 127 | return false;
|
---|
| 128 | } else {
|
---|
| 129 | const_iterator this_iter = begin();
|
---|
| 130 | const_iterator b_iter = b.begin();
|
---|
| 131 | for (;(this_iter != end()) && (b_iter != b.end());
|
---|
| 132 | ++this_iter, ++b_iter) {
|
---|
| 133 | if (*this_iter > *b_iter) {
|
---|
| 134 | return true;
|
---|
| 135 | } else if (*this_iter < *b_iter) {
|
---|
| 136 | return false;
|
---|
| 137 | }
|
---|
| 138 | }
|
---|
| 139 | return false;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 | bool IndexSet::operator==(const IndexSet &b) const
|
---|
| 144 | {
|
---|
| 145 | if (size() != b.size()) {
|
---|
| 146 | return false;
|
---|
| 147 | } else {
|
---|
| 148 | const_iterator this_iter = begin();
|
---|
| 149 | const_iterator b_iter = b.begin();
|
---|
| 150 | for (;(this_iter != end()) && (b_iter != b.end());
|
---|
| 151 | ++this_iter, ++b_iter) {
|
---|
| 152 | if (*this_iter != *b_iter) {
|
---|
| 153 | return false;
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 | return true;
|
---|
| 157 | }
|
---|
| 158 | }
|
---|
| 159 |
|
---|