Remove homemade optional - use std::optional

This commit is contained in:
Joakim Hove
2020-10-01 08:07:18 +02:00
parent 26f91f0ce0
commit 6dc84b67df
10 changed files with 8 additions and 209 deletions

View File

@@ -22,7 +22,6 @@
#define OPM_PARSER_ECLIPSE_GRID_HPP
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/MinpvMode.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/PinchMode.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/GridDims.hpp>
@@ -32,6 +31,7 @@
#include <array>
#include <memory>
#include <optional>
#include <vector>
namespace Opm {
@@ -194,7 +194,7 @@ namespace Opm {
private:
std::vector<double> m_minpvVector;
MinpvMode::ModeEnum m_minpvMode;
Value<double> m_pinch;
std::optional<double> m_pinch;
PinchMode::ModeEnum m_pinchoutMode;
PinchMode::ModeEnum m_multzMode;
PinchMode::ModeEnum m_pinchGapMode;

View File

@@ -23,7 +23,6 @@
#include <opm/parser/eclipse/EclipseState/Grid/FieldPropsManager.hpp>
#include <opm/parser/eclipse/EclipseState/Grid/FaceDir.hpp>
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
namespace Opm {

View File

@@ -30,7 +30,6 @@
#include <optional>
#include <opm/parser/eclipse/Parser/ParseContext.hpp>
#include <opm/parser/eclipse/EclipseState/Util/Value.hpp>
namespace Opm {

View File

@@ -1,111 +0,0 @@
/*
Copyright 2014 Statoil 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 OPM_VALUE_HPP
#define OPM_VALUE_HPP
#include <stdexcept>
#include <string>
/*
The simple class Value<T> keeps track of a named scalar variable;
the purpose of this class is to keep strick track of whether the
value has been assigned or not. Will throw an exception if trying to
use an unitialized value.
*/
namespace Opm {
template <typename T>
class Value {
private:
std::string m_name;
bool m_initialized = false;
T m_value;
public:
Value() = default;
explicit Value(const std::string& name) :
m_name( name ),
m_initialized( false )
{ }
Value(const std::string& name ,T value) :
m_name( name )
{
setValue( value );
}
bool hasValue() const {
return m_initialized;
}
T getValue() const {
if (m_initialized)
return m_value;
else
throw std::logic_error("The value has: " + m_name + " has not been initialized");
}
void setValue( T value ) {
m_initialized = true;
m_value = value;
}
/**
Will return true if both value instances have been initialized
to the same value; or none of the values have been
initialized. Does not compare names.
*/
bool equal( const Value<T>& other) const {
if (m_initialized == other.m_initialized) {
if (m_initialized) {
if (m_value == other.m_value)
return true; // Have been initialized to same value
else
return false;
} else
return true; // Both undefined
} else
return false;
}
bool operator==( const Value& rhs ) const {
return this->equal( rhs );
}
bool operator!=( const Value& rhs ) const {
return !(*this == rhs );
}
};
}
#endif