My Project
Loading...
Searching...
No Matches
ActionResult.hpp
1/*
2 Copyright 2019 Equinor ASA.
3
4 This file is part of the Open Porous Media project (OPM).
5
6 OPM is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 OPM is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with OPM. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#ifndef ACTION_RESULT_HPP
21#define ACTION_RESULT_HPP
22
23#include <algorithm>
24#include <memory>
25#include <string>
26#include <vector>
27
28namespace Opm::Action {
29
67
68class Result
69{
70public:
78 template <typename T>
80 {
81 public:
86 using RandIt = typename std::vector<T>::const_iterator;
87
99 explicit ValueRange(RandIt first, RandIt last, bool isSorted = false)
100 : first_ { first }
101 , last_ { last }
102 , isSorted_ { isSorted }
103 {}
104
106 auto begin() const { return this->first_; }
107
109 auto end() const { return this->last_; }
110
112 auto empty() const { return this->begin() == this->end(); }
113
115 auto size() const { return std::distance(this->begin(), this->end()); }
116
120 std::vector<T> asVector() const
121 {
122 return { this->begin(), this->end() };
123 }
124
130 bool hasElement(const T& elem) const
131 {
132 return this->isSorted_
133 ? this->hasElementSorted(elem)
134 : this->hasElementUnsorted(elem);
135 }
136
137 private:
139 RandIt first_{};
140
142 RandIt last_{};
143
145 bool isSorted_{false};
146
152 bool hasElementSorted(const T& elem) const
153 {
154 return std::binary_search(this->begin(), this->end(), elem);
155 }
156
162 bool hasElementUnsorted(const T& elem) const
163 {
164 return std::find(this->begin(), this->end(), elem)
165 != this->end();
166 }
167 };
168
174 {
175 public:
181
187
193
198
205 MatchingEntities& operator=(const MatchingEntities& rhs);
206
214 MatchingEntities& operator=(MatchingEntities&& rhs);
215
218 ValueRange<std::string> wells() const;
219
225 bool hasWell(const std::string& well) const;
226
234 bool operator==(const MatchingEntities& that) const;
235
236 friend class Result;
237
238 private:
240 class Impl;
241
243 std::unique_ptr<Impl> pImpl_;
244
251 void addWell(const std::string& well);
252
259 void addWells(const std::vector<std::string>& wells);
260
268 void makeIntersection(const MatchingEntities& rhs);
269
277 void makeUnion(const MatchingEntities& rhs);
278
282 void clear();
283 };
284
290 explicit Result(bool result_arg);
291
295 Result(const Result& rhs);
296
301 Result(Result&& rhs);
302
307
313 Result& operator=(const Result& rhs);
314
321 Result& operator=(Result&& rhs);
322
330 Result& wells(const std::vector<std::string>& w);
331
336 bool conditionSatisfied() const;
337
350 Result& makeSetUnion(const Result& rhs);
351
365 Result& makeSetIntersection(const Result& rhs);
366
372 const MatchingEntities& matches() const;
373
380 bool operator==(const Result& that) const;
381
382private:
384 class Impl;
385
387 std::unique_ptr<Impl> pImpl_{};
388};
389
390} // Namespace Opm::Action
391
392#endif // ACTION_RESULT_HPP
Implementation of Action::Result.
Definition ActionResult.cpp:571
Implementation of Result::MatchingEntities.
Definition ActionResult.cpp:354
Container of matching entities.
Definition ActionResult.hpp:174
bool operator==(const MatchingEntities &that) const
Assignment operator.
Definition ActionResult.cpp:536
MatchingEntities()
Default constructor.
Definition ActionResult.cpp:496
Random access range of values.
Definition ActionResult.hpp:80
typename std::vector< T >::const_iterator RandIt
Random access iterator.
Definition ActionResult.hpp:86
auto begin() const
Beginning of value range's elements.
Definition ActionResult.hpp:106
bool hasElement(const T &elem) const
Element existence predicate.
Definition ActionResult.hpp:130
auto empty() const
Predicate for an empty value range.
Definition ActionResult.hpp:112
ValueRange(RandIt first, RandIt last, bool isSorted=false)
Constructor.
Definition ActionResult.hpp:99
auto size() const
Number of elements in the value range.
Definition ActionResult.hpp:115
std::vector< T > asVector() const
Convert value range to a std::vector.
Definition ActionResult.hpp:120
auto end() const
End of value range's elements.
Definition ActionResult.hpp:109
Class Action::Result holds the boolean result of a ACTIONX condition like.
Definition ActionResult.hpp:69
~Result()
Destructor.
bool operator==(const Result &that) const
Equality predicate.
Definition ActionResult.cpp:726
Result & makeSetUnion(const Result &rhs)
Assignment operator.
Definition ActionResult.cpp:707
const MatchingEntities & matches() const
Retrieve set of matching entities.
Definition ActionResult.cpp:721
Result & makeSetIntersection(const Result &rhs)
Incorporate another result set into the current set as if by set intersection.
Definition ActionResult.cpp:714