#ifndef _RHEOLEF_INDEX_SET_H #define _RHEOLEF_INDEX_SET_H /// /// This file is part of Rheolef. /// /// Copyright (C) 2000-2009 Pierre Saramito /// /// Rheolef is free software; you can redistribute it and/or modify /// it under the terms of the GNU General Public License as published by /// the Free Software Foundation; either version 2 of the License, or /// (at your option) any later version. /// /// Rheolef is distributed in the hope that it will be useful, /// but WITHOUT ANY WARRANTY; without even the implied warranty of /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /// GNU General Public License for more details. /// /// You should have received a copy of the GNU General Public License /// along with Rheolef; if not, write to the Free Software /// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA /// /// ========================================================================= #include "rheolef/distributed.h" #include "rheolef/pretty_name.h" #include "rheolef/array.h" // for is_container_of_mpi_datatype ; TODO: move #include #include #ifdef TO_CLEAN #include #include #include #include #include #endif // TO_CLEAN namespace rheolef { /*Class:index_set NAME: index_set - a set of indexes (@PACKAGE@-@VERSION@) SYNOPSYS: A class for: l = @{1,3,...9@} i.e. a wrapper for STL @code{set} with some assignment operators, such as l1 += l2. This class is suitable for use with the @code{array} class, as @code{array} (@pxref{array class}). AUTHOR: Pierre.Saramito@imag.fr DATE: date: 23 march 2011 End: */ // { public: // typedefs: typedef std::set base; typedef std::size_t value_type; typedef std::size_t size_type; // allocators: index_set (); index_set (const index_set& x); index_set& operator= (const index_set& x); template index_set& operator= (size_type x[N]); void clear (); // basic algebra: void insert (size_type dis_i); // a := a union {dis_i} index_set& operator+= (size_type dis_i); // idem index_set& operator+= (const index_set& b); // a := a union b // a := a union b void inplace_union (const index_set& b); void inplace_intersection (const index_set& b); // c := a union b friend void set_union (const index_set& a, const index_set& b, index_set& c); friend void set_intersection (const index_set& a, const index_set& b, index_set& c); // io: friend std::istream& operator>> (std::istream& is, index_set& x); friend std::ostream& operator<< (std::ostream& os, const index_set& x); // boost mpi: template void serialize (Archive& ar, const unsigned int version); }; //>verbatim: // for boost mpi and array: template <> struct is_container_of_mpi_datatype : boost::mpl::true_ { typedef boost::mpl::true_ type; }; // operator += for array::assembly template struct index_set_add_op : std::binary_function { T1& operator()(T1& x, const T2& y) const { x += y; return x; } }; // ------------------------------------------------------------------- // inlined // ------------------------------------------------------------------- inline index_set::index_set() : base() { } template index_set& index_set::operator= (size_t x[N]) { base::clear(); for (size_t* iter = &(x[0]), *last = &(x[0])+N; iter != last; iter++) { base::insert (*iter); } return *this; } inline void index_set::clear () { base::clear(); } inline void index_set::insert (size_type dis_i) { base::insert (dis_i); } inline index_set& index_set::operator+= (size_type dis_i) { base::insert (dis_i); return *this; } template void index_set::serialize (Archive& ar, const unsigned int version) { ar & boost::serialization::base_object(*this); } } // namespace rheolef #endif // _RHEOLEF_INDEX_SET_H