Loading...
Searching...
No Matches
ActionResult.hpp
/*
Copyright 2019 Equinor ASA.
This file is part of the Open Porous Media project (OPM).
OPM 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 3 of the License, or
(at your option) any later version.
OPM 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 OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ACTION_RESULT_HPP
#define ACTION_RESULT_HPP
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
namespace Opm::Action {
class Result
{
public:
template <typename T>
class ValueRange
{
public:
using RandIt = typename std::vector<T>::const_iterator;
explicit ValueRange(RandIt first, RandIt last, bool isSorted = false)
: first_ { first }
, last_ { last }
, isSorted_ { isSorted }
{}
auto begin() const { return this->first_; }
auto end() const { return this->last_; }
auto empty() const { return this->begin() == this->end(); }
auto size() const { return std::distance(this->begin(), this->end()); }
std::vector<T> asVector() const
{
return { this->begin(), this->end() };
}
bool hasElement(const T& elem) const
{
return this->isSorted_
? this->hasElementSorted(elem)
: this->hasElementUnsorted(elem);
}
private:
RandIt first_{};
RandIt last_{};
bool isSorted_{false};
bool hasElementSorted(const T& elem) const
{
return std::binary_search(this->begin(), this->end(), elem);
}
bool hasElementUnsorted(const T& elem) const
{
return std::find(this->begin(), this->end(), elem)
!= this->end();
}
};
class MatchingEntities
{
public:
MatchingEntities();
MatchingEntities(const MatchingEntities& rhs);
MatchingEntities(MatchingEntities&& rhs);
~MatchingEntities();
MatchingEntities& operator=(const MatchingEntities& that);
MatchingEntities& operator=(MatchingEntities&& rhs);
ValueRange<std::string> wells() const;
bool hasWell(const std::string& well) const;
bool operator==(const MatchingEntities& that) const;
friend class Result;
private:
class Impl;
std::unique_ptr<Impl> pImpl_;
void addWell(const std::string& well);
void addWells(const std::vector<std::string>& wells);
void makeIntersection(const MatchingEntities& rhs);
void makeUnion(const MatchingEntities& rhs);
void clear();
};
explicit Result(bool result_arg);
Result(const Result& rhs);
Result(Result&& rhs);
~Result();
Result& operator=(const Result& rhs);
Result& operator=(Result&& rhs);
Result& wells(const std::vector<std::string>& w);
bool conditionSatisfied() const;
Result& makeSetUnion(const Result& rhs);
Result& makeSetIntersection(const Result& rhs);
const MatchingEntities& matches() const;
bool operator==(const Result& that) const;
private:
class Impl;
std::unique_ptr<Impl> pImpl_; // No in-class initializer to workaround nvcc issue
};
} // Namespace Opm::Action
#endif // ACTION_RESULT_HPP
Opm::Action::Result::Impl
Implementation of Action::Result.
Definition ActionResult.cpp:571
Opm::Action::Result::MatchingEntities::Impl
Implementation of Result::MatchingEntities.
Definition ActionResult.cpp:354
Opm::Action::Result::MatchingEntities
Container of matching entities.
Definition ActionResult.hpp:174
Opm::Action::Result::MatchingEntities::operator==
bool operator==(const MatchingEntities &that) const
Equality predicate.
Definition ActionResult.cpp:536
Opm::Action::Result::MatchingEntities::MatchingEntities
MatchingEntities()
Default constructor.
Definition ActionResult.cpp:496
Opm::Action::Result::MatchingEntities::hasWell
bool hasWell(const std::string &well) const
Whether or not named well is in the list of matching entities.
Definition ActionResult.cpp:531
Opm::Action::Result::MatchingEntities::wells
ValueRange< std::string > wells() const
Assignment operator.
Definition ActionResult.cpp:526
Opm::Action::Result::MatchingEntities::~MatchingEntities
~MatchingEntities()
Destructor.
Opm::Action::Result::ValueRange
Random access range of values.
Definition ActionResult.hpp:80
Opm::Action::Result::ValueRange::RandIt
typename std::vector< T >::const_iterator RandIt
Random access iterator.
Definition ActionResult.hpp:86
Opm::Action::Result::ValueRange::begin
auto begin() const
Beginning of value range's elements.
Definition ActionResult.hpp:106
Opm::Action::Result::ValueRange::hasElement
bool hasElement(const T &elem) const
Element existence predicate.
Definition ActionResult.hpp:130
Opm::Action::Result::ValueRange::empty
auto empty() const
Predicate for an empty value range.
Definition ActionResult.hpp:112
Opm::Action::Result::ValueRange::ValueRange
ValueRange(RandIt first, RandIt last, bool isSorted=false)
Constructor.
Definition ActionResult.hpp:99
Opm::Action::Result::ValueRange::size
auto size() const
Number of elements in the value range.
Definition ActionResult.hpp:115
Opm::Action::Result::ValueRange::asVector
std::vector< T > asVector() const
Convert value range to a std::vector.
Definition ActionResult.hpp:120
Opm::Action::Result::ValueRange::end
auto end() const
End of value range's elements.
Definition ActionResult.hpp:109
Opm::Action::Result::wells
Result & wells(const std::vector< std::string > &w)
Assignment operator.
Definition ActionResult.cpp:695
Opm::Action::Result::~Result
~Result()
Destructor.
Opm::Action::Result::operator==
bool operator==(const Result &that) const
Equality predicate.
Definition ActionResult.cpp:726
Opm::Action::Result::makeSetUnion
Result & makeSetUnion(const Result &rhs)
Incorporate another result set into the current set as if by set union.
Definition ActionResult.cpp:707
Opm::Action::Result::Result
Result(bool result_arg)
Constructor.
Definition ActionResult.cpp:666
Opm::Action::Result::matches
const MatchingEntities & matches() const
Retrieve set of matching entities.
Definition ActionResult.cpp:721
Opm::Action::Result::makeSetIntersection
Result & makeSetIntersection(const Result &rhs)
Incorporate another result set into the current set as if by set intersection.
Definition ActionResult.cpp:714
Opm::Action::Result::conditionSatisfied
bool conditionSatisfied() const
Predicate for whether or not the result set represents a 'true' value.
Definition ActionResult.cpp:701