ESyS-Particle  2.3.4
SetPy.hpp
Go to the documentation of this file.
1 // //
3 // Copyright (c) 2003-2017 by The University of Queensland //
4 // Centre for Geoscience Computing //
5 // http://earth.uq.edu.au/centre-geoscience-computing //
6 // //
7 // Primary Business: Brisbane, Queensland, Australia //
8 // Licensed under the Open Software License version 3.0 //
9 // http://www.apache.org/licenses/LICENSE-2.0 //
10 // //
12 
14 #include <algorithm>
15 
16 namespace esys
17 {
18  namespace lsm
19  {
20  template <typename TE, typename TC>
22  {
23  }
24 
25  template <typename TE, typename TC>
26  SetPy<TE,TC>::SetPy(const SetPy &set) : Inherited(set)
27  {
28  }
29 
30  template <typename TE, typename TC>
32  {
33  }
34 
35  template <typename TE, typename TC>
36  SetPy<TE,TC>::SetPy(boost::python::object &iterable)
37  : Inherited()
38  {
39  bpu::PythonIterIterator<TE> it(iterable);
40  while (it.hasNext())
41  {
42  this->insert(it.next());
43  }
44  }
45 
46  template <typename TE, typename TC>
48  {
49  SetPy resultSet;
50  std::set_union(
51  this->begin(),
52  this->end(),
53  set.begin(),
54  set.end(),
55  InsertIterator(resultSet, resultSet.begin())
56  );
57  return resultSet;
58  }
59 
60  template <typename TE, typename TC>
62  {
63  SetPy resultSet;
64  std::set_difference(
65  this->begin(),
66  this->end(),
67  set.begin(),
68  set.end(),
69  InsertIterator(resultSet, resultSet.begin())
70  );
71  return resultSet;
72  }
73 
74  template <typename TE, typename TC>
76  {
77  SetPy resultSet;
78  std::set_intersection(
79  this->begin(),
80  this->end(),
81  set.begin(),
82  set.end(),
83  InsertIterator(resultSet, resultSet.begin())
84  );
85  return resultSet;
86  }
87 
88  template <typename TE, typename TC>
89  boost::python::tuple
91  {
92  return boost::python::make_tuple(boost::python::list(s));
93  }
94 
95  template <typename TE, typename TC>
96  boost::python::class_<SetPy<TE,TC> >
98  const std::string &pyClassName,
99  const std::string &pyClassDocString
100  )
101  {
102  return
103  boost::python::class_<SetPy<TE,TC> >(
104  pyClassName.c_str(),
105  pyClassDocString.c_str(),
106  boost::python::init<>()
107  )
108  .def(
109  boost::python::init<const SetPy<TE,TC> &>(
110  (boost::python::arg("iterable"))
111  )
112  )
113  .def(
114  boost::python::init<boost::python::object &>(
115  (boost::python::arg("iterable")),
116  (
117  std::string() +
118  "Constructs set of elements from specifed sequence.\n" +
119  "@type iterable: iterable\n" +
120  "@kwarg iterable: copy and insert elements from C{iterable}" +
121  " into this set.\n"
122  ).c_str()
123  )
124  )
125  .def(
126  "union",
128  (boost::python::arg("set")),
129  (
130  std::string() +
131  "Returns new set which is the union of this set and C{set}.\n" +
132  "@type set: " + pyClassName + "\n" +
133  "@kwarg set: Set with which union is performed.\n" +
134  "@rtype: " + pyClassName + "\n"
135  "@return: new set which is the union of two sets."
136  ).c_str()
137  )
138  .def(
139  "difference",
141  (boost::python::arg("set")),
142  (
143  std::string() +
144  "Returns new set which contains elements of this set not " +
145  " contained in the specified C{set}.\n" +
146  "@type set: " + pyClassName + "\n" +
147  "@kwarg set: Set with which difference is performed.\n" +
148  "@rtype: " + pyClassName + "\n"
149  "@return: new set which is the difference of two sets."
150  ).c_str()
151  )
152  .def(
153  "intersection",
155  (boost::python::arg("set")),
156  (
157  std::string() +
158  "Returns new set which contains elements common to this set " +
159  " and the specified C{set}.\n" +
160  "@type set: " + pyClassName + "\n" +
161  "@kwarg set: Set with which intersection is performed.\n" +
162  "@rtype: " + pyClassName + "\n"
163  "@return: new set which is the intersection of two sets."
164  ).c_str()
165  )
166  .def(
167  "__iter__",
168  boost::python::iterator<
169  SetPy,
170  boost::python::return_internal_reference<>
171  >()
172  )
173  .def(
174  "__len__",
175  &SetPy::size
176  )
177  .def(
178  boost::python::self == boost::python::self
179  )
180  .def_pickle(typename SetPy::PickleSuite())
181  ;
182  }
183  }
184 }
esys::lsm::bpu::PythonIterIterator::hasNext
bool hasNext() const
Definition: PythonIterIterator.hpp:32
esys::lsm::SetPy::SetPy
SetPy()
Definition: SetPy.hpp:21
esys::lsm::SetPy::Inherited
std::set< TmplElem, TmplCompare > Inherited
Definition: SetPy.h:28
PythonIterIterator.h
esys
Definition: CheckPointable.cpp:17
esys::lsm::SetPy::getIntersection
SetPy getIntersection(const SetPy &set) const
Definition: SetPy.hpp:75
esys::lsm::SetPy::getDifference
SetPy getDifference(const SetPy &set) const
Definition: SetPy.hpp:61
esys::lsm::SetPy::PickleSuite::getinitargs
static boost::python::tuple getinitargs(SetPy const &s)
Definition: SetPy.hpp:90
esys::lsm::SetPy::getUnion
SetPy getUnion(const SetPy &set) const
Definition: SetPy.hpp:47
esys::lsm::SetPy::exportSet
static boost::python::class_< SetPy > exportSet(const std::string &pyClassName, const std::string &pyClassDocString)
Definition: SetPy.hpp:97
esys::lsm::SetPy::PickleSuite
Definition: SetPy.h:31
esys::lsm::SetPy
Definition: SetPy.h:26
esys::lsm::bpu::PythonIterIterator
Definition: PythonIterIterator.h:28
esys::lsm::bpu::PythonIterIterator::next
value_type next()
Definition: PythonIterIterator.hpp:38
esys::lsm::SetPy::InsertIterator
std::insert_iterator< SetPy > InsertIterator
Definition: SetPy.h:59