opm-common
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
203 MatchingEntities& operator=(const MatchingEntities& that);
204
212 MatchingEntities& operator=(MatchingEntities&& rhs);
213
217
223 bool hasWell(const std::string& well) const;
224
232 bool operator==(const MatchingEntities& that) const;
233
234 friend class Result;
235
236 private:
238 class Impl;
239
241 std::unique_ptr<Impl> pImpl_;
242
249 void addWell(const std::string& well);
250
257 void addWells(const std::vector<std::string>& wells);
258
266 void makeIntersection(const MatchingEntities& rhs);
267
275 void makeUnion(const MatchingEntities& rhs);
276
280 void clear();
281 };
282
288 explicit Result(bool result_arg);
289
293 Result(const Result& rhs);
294
299 Result(Result&& rhs);
300
305
311 Result& operator=(const Result& rhs);
312
319 Result& operator=(Result&& rhs);
320
328 Result& wells(const std::vector<std::string>& w);
329
334 bool conditionSatisfied() const;
335
348 Result& makeSetUnion(const Result& rhs);
349
363 Result& makeSetIntersection(const Result& rhs);
364
370 const MatchingEntities& matches() const;
371
378 bool operator==(const Result& that) const;
379
380private:
382 class Impl;
383
385 std::unique_ptr<Impl> pImpl_; // No in-class initializer to workaround nvcc issue
386};
387
388} // Namespace Opm::Action
389
390#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
Equality predicate.
Definition ActionResult.cpp:536
MatchingEntities()
Default constructor.
Definition ActionResult.cpp:496
bool hasWell(const std::string &well) const
Whether or not named well is in the list of matching entities.
Definition ActionResult.cpp:531
ValueRange< std::string > wells() const
Assignment operator.
Definition ActionResult.cpp:526
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
Result & wells(const std::vector< std::string > &w)
Assignment operator.
Definition ActionResult.cpp:695
~Result()
Destructor.
bool operator==(const Result &that) const
Equality predicate.
Definition ActionResult.cpp:726
Result & makeSetUnion(const Result &rhs)
Incorporate another result set into the current set as if by set union.
Definition ActionResult.cpp:707
Result(bool result_arg)
Constructor.
Definition ActionResult.cpp:666
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
bool conditionSatisfied() const
Predicate for whether or not the result set represents a 'true' value.
Definition ActionResult.cpp:701