rheolef
6.3
Main Page
Namespaces
Classes
Files
Examples
File List
File Members
skit
plib2
index_set.h
Go to the documentation of this file.
1
#ifndef _RHEOLEF_INDEX_SET_H
2
#define _RHEOLEF_INDEX_SET_H
3
// wrapper for std::set<size_t>: union as a+b and a += b and others goodies
4
// motivation: this class is usefull for array<index_set,M> to send/receive variable-sized
5
// array<index_set,M> is used by the geo class to manage connectivity
6
#include "rheolef/distributed.h"
7
#include "rheolef/pretty_name.h"
8
#include "rheolef/container_traits.h"
9
10
#include <boost/serialization/set.hpp>
11
#include <boost/serialization/base_object.hpp>
12
namespace
rheolef {
13
28
class
index_set
:
public
std::set<std::size_t> {
29
public
:
30
31
32
typedef
std::set<std::size_t>
base
;
33
typedef
std::size_t
value_type
;
34
typedef
std::size_t
size_type
;
35
36
37
index_set
();
38
index_set
(
const
index_set
& x);
39
index_set
&
operator=
(
const
index_set
& x);
40
template
<
int
N>
41
index_set
&
operator=
(
size_type
x[
N
]);
42
void
clear
();
43
44
45
void
insert
(
size_type
dis_i);
// a := a union {dis_i}
46
index_set
&
operator+=
(
size_type
dis_i);
// idem
47
index_set
&
operator+=
(
const
index_set
& b);
// a := a union b
48
49
void
inplace_union
(
const
index_set
& b);
50
void
inplace_intersection
(
const
index_set
& b);
51
52
friend
void
set_union
(
const
index_set
& a,
const
index_set
& b,
index_set
& c);
53
friend
void
set_intersection
(
const
index_set
& a,
const
index_set
& b,
index_set
& c);
54
55
56
friend
std::istream&
operator>>
(std::istream& is,
index_set
& x);
57
friend
std::ostream&
operator<<
(std::ostream& os,
const
index_set
& x);
58
59
60
template
<
class
Archive>
61
void
serialize
(Archive& ar,
const
unsigned
int
version);
62
};
63
@end
code
64
65
template
<
class
T>
66
struct
index_set_add_op
: std::binary_function<T,T,T> {
67
T&
operator()
(T& x,
const
T& y)
const
{
return
x += y; }
68
T&
operator()
(T& x,
const
typename
T::value_type& y)
const
{
return
x += y; }
69
};
70
// for boost mpi and array<index_set>:
71
template
<>
struct
default_set_op
<
index_set
> {
72
typedef
index_set_add_op<index_set>
type
;
73
};
74
template
<>
struct
is_container
<
index_set
> : boost::mpl::true_ {
75
typedef
boost::mpl::true_
type
;
76
};
77
#ifdef _RHEOLEF_HAVE_MPI
78
template
<>
struct
is_container_of_mpi_datatype
<
index_set
> : boost::mpl::true_ {
79
typedef
boost::mpl::true_
type
;
80
};
81
#endif // _RHEOLEF_HAVE_MPI
82
inline
83
index_set::index_set
()
84
:
base
()
85
{
86
}
87
template
<
int
N>
88
index_set
&
89
index_set::operator=
(
size_t
x[
N
])
90
{
91
base::clear
();
92
for
(
size_t
* iter = &(x[0]), *last = &(x[0])+N; iter != last; iter++) {
93
base::insert
(*iter);
94
}
95
return
*
this
;
96
}
97
inline
98
void
99
index_set::clear
()
100
{
101
base::clear
();
102
}
103
inline
104
void
105
index_set::insert
(
size_type
dis_i)
106
{
107
base::insert
(dis_i);
108
}
109
inline
110
index_set
&
111
index_set::operator+=
(
size_type
dis_i)
112
{
113
base::insert
(dis_i);
114
return
*
this
;
115
}
116
template
<
class
Archive>
117
void
118
index_set::serialize
(Archive& ar,
const
unsigned
int
version)
119
{
120
ar & boost::serialization::base_object<base>(*this);
121
}
122
123
}
// namespace rheolef
124
#endif // _RHEOLEF_INDEX_SET_H
125