Loading...
Searching...
No Matches
Parameter.h
// Copyright (C) 2009 Anders Logg
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN 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 Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
#ifndef __PARAMETER_H
#define __PARAMETER_H
#include <array>
#include <set>
#include <sstream>
#include <string>
#include <boost/blank.hpp>
#include <boost/variant.hpp>
namespace dolfin
{
class Parameter
{
public:
template<typename T>
Parameter(std::string key, T x) : _value(x), _access_count(0),
_change_count(0), _is_set(true), _key(key),
_description("missing description") { check_key(key); }
Parameter(std::string key, const char* x);
enum class Type { Bool, Int, Float, String };
Parameter(std::string key, Type ptype);
template<typename T>
Parameter(std::string key, T min, T max) : _value(T(0)),
_range(std::array<T, 2>({{min, max}})), _access_count(0), _change_count(0),
_is_set(false), _key(key), _description("missing description")
{ check_key(key); }
Parameter(std::string key, std::set<std::string> range) : _value(std::string("")),
_range(range), _access_count(0), _change_count(0), _is_set(false),
_key(key), _description("missing description") { check_key(key); }
Parameter(const Parameter&) = default;
Parameter(Parameter&&) = default;
virtual ~Parameter();
Parameter& operator= (const Parameter &) = default;
std::string key() const;
std::string description() const;
bool is_set() const;
void reset();
std::size_t access_count() const;
std::size_t change_count() const;
void set_range(int min_value, int max_value);
void set_range(double min_value, double max_value);
void set_range(std::set<std::string> range);
void get_range(int& min_value, int& max_value) const;
void get_range(double& min_value, double& max_value) const;
void get_range(std::set<std::string>& range) const;
const Parameter& operator= (int value);
const Parameter& operator= (double value);
const Parameter& operator= (std::string value);
const Parameter& operator= (const char* value);
const Parameter& operator= (bool value);
boost::variant<boost::blank, bool, int, double, std::string> value() const;
operator int() const;
operator std::size_t() const;
operator double() const;
operator std::string() const;
operator bool() const;
std::string type_str() const;
std::string value_str() const;
std::string range_str() const;
std::string str() const;
static void check_key(std::string key);
protected:
// Value (0: blank, 1: bool, 2: int, 3: double, 4: std::string)
boost::variant<boost::blank, bool, int, double, std::string> _value;
// Ranges (0: blank, 1: int, 2: double, 3: std::string)
boost::variant<boost::blank, std::array<int, 2>, std::array<double, 2>,
std::set<std::string>> _range;
// Access count
mutable std::size_t _access_count;
// Change count
std::size_t _change_count;
// Whether or not parameter has been set
bool _is_set;
// Parameter key
std::string _key;
// Parameter description
std::string _description;
};
}
#endif
dolfin::Parameter::Parameter
Parameter(std::string key, T x)
Definition Parameter.h:41
dolfin::Parameter::access_count
std::size_t access_count() const
Definition Parameter.cpp:80
dolfin::Parameter::description
std::string description() const
Definition Parameter.cpp:65
dolfin::Parameter::operator=
Parameter & operator=(const Parameter &)=default
Assignment operator.
dolfin::Parameter::key
std::string key() const
Definition Parameter.cpp:60
dolfin::Parameter::str
std::string str() const
Return short string description.
Definition Parameter.cpp:420
dolfin::Parameter::~Parameter
virtual ~Parameter()
Destructor.
Definition Parameter.cpp:55
dolfin::Parameter::check_key
static void check_key(std::string key)
Check that key name is allowed.
Definition Parameter.cpp:330
dolfin::Parameter::reset
void reset()
Reset the parameter to empty, so that is_set() returns false.
Definition Parameter.cpp:75
dolfin::Parameter::Parameter
Parameter(Parameter &&)=default
Move constructor.
dolfin::Parameter::string
operator std::string() const
Cast parameter to string.
Definition Parameter.cpp:304
dolfin::Parameter::Parameter
Parameter(std::string key, T min, T max)
Definition Parameter.h:66
dolfin::Parameter::is_set
bool is_set() const
Definition Parameter.cpp:70
dolfin::Parameter::range_str
std::string range_str() const
Return range string.
Definition Parameter.cpp:382
dolfin::Parameter::Type
Type
Enum for the parameter type.
Definition Parameter.h:54
dolfin::Parameter::value_str
std::string value_str() const
Return value string.
Definition Parameter.cpp:362
dolfin::Parameter::Parameter
Parameter(std::string key, std::set< std::string > range)
Create and unset string parameter with set of allowable strings.
Definition Parameter.h:72
dolfin::Parameter::set_range
void set_range(int min_value, int max_value)
Definition Parameter.cpp:90
dolfin::Parameter::change_count
std::size_t change_count() const
Definition Parameter.cpp:85
dolfin::Parameter::type_str
std::string type_str() const
Return value type string.
Definition Parameter.cpp:342
dolfin::Parameter::get_range
void get_range(int &min_value, int &max_value) const
Definition Parameter.cpp:129
dolfin::Parameter::value
boost::variant< boost::blank, bool, int, double, std::string > value() const
Return parameter value.
Definition Parameter.cpp:245
dolfin::Parameter::Parameter
Parameter(const Parameter &)=default
Copy constructor.
dolfin
Definition adapt.h:30