delpi
0.0.1
DElta-complete LP solver
Toggle main menu visibility
Loading...
Searching...
No Matches
OptionValue.hpp
1
15
#pragma once
16
17
#include <utility>
18
19
namespace
delpi
{
20
31
template
<
typename
T>
32
class
OptionValue
{
33
public
:
39
enum class
Type
{
40
DEFAULT
,
41
FROM_FILE
,
42
FROM_COMMAND_LINE
,
43
FROM_CODE
,
44
};
45
50
explicit
OptionValue
(T value) :
value_
{std::move(value)},
type_
{
Type
::
DEFAULT
} {}
51
53
OptionValue
(
const
OptionValue
&) =
default
;
55
OptionValue
(
OptionValue
&&) noexcept = default;
57
OptionValue
&operator=(const
OptionValue
&) = default;
59
OptionValue
&operator=(
OptionValue
&&) noexcept = default;
60
65
OptionValue
&operator=(const T &value) {
66
value_
= value;
67
type_
=
Type::FROM_CODE
;
68
return
*
this
;
69
}
70
75
OptionValue
&
operator=
(T &&value) {
76
value_
= std::move(value);
77
type_
=
Type::FROM_CODE
;
78
return
*
this
;
79
}
80
82
const
T &get()
const
{
return
value_
; }
83
const
T &operator*()
const
{
return
value_
; }
84
92
void
SetFromCommandLine
(
const
T &value) {
93
if
(
type_
!=
Type::FROM_CODE
) {
94
value_
= value;
95
type_
=
Type::FROM_COMMAND_LINE
;
96
}
97
}
98
105
void
SetFromFile
(
const
T &value) {
106
switch
(
type_
) {
107
case
Type::DEFAULT
:
108
case
Type::FROM_FILE
:
109
value_
= value;
110
type_
=
Type::FROM_FILE
;
111
return
;
112
113
case
Type::FROM_COMMAND_LINE
:
114
case
Type::FROM_CODE
:
115
// No operation.
116
return
;
117
}
118
}
119
120
private
:
121
T
value_
;
122
Type
type_
;
123
};
124
125
}
// namespace delpi
delpi::OptionValue::operator=
OptionValue & operator=(T &&value)
Move-assign operator for T.
Definition
OptionValue.hpp:75
delpi::OptionValue::type_
Type type_
Type of the value.
Definition
OptionValue.hpp:122
delpi::OptionValue::SetFromCommandLine
void SetFromCommandLine(const T &value)
Sets the value to value which is given by a command-line argument.
Definition
OptionValue.hpp:92
delpi::OptionValue::OptionValue
OptionValue(OptionValue &&) noexcept=default
Default move constructor.
delpi::OptionValue::SetFromFile
void SetFromFile(const T &value)
Sets the value to value which is provided from a file.
Definition
OptionValue.hpp:105
delpi::OptionValue::OptionValue
OptionValue(const OptionValue &)=default
Default copy constructor.
delpi::OptionValue::Type
Type
Type of the value.
Definition
OptionValue.hpp:39
delpi::OptionValue::Type::FROM_FILE
@ FROM_FILE
Updated by a set-option/set-info in a file.
Definition
OptionValue.hpp:41
delpi::OptionValue::Type::DEFAULT
@ DEFAULT
Default value.
Definition
OptionValue.hpp:40
delpi::OptionValue::Type::FROM_CODE
@ FROM_CODE
Explicitly updated from code.
Definition
OptionValue.hpp:43
delpi::OptionValue::Type::FROM_COMMAND_LINE
@ FROM_COMMAND_LINE
Updated by a command-line argument.
Definition
OptionValue.hpp:42
delpi::OptionValue::OptionValue
OptionValue(T value)
Constructs an option value with value.
Definition
OptionValue.hpp:50
delpi::OptionValue::value_
T value_
Value the class holds.
Definition
OptionValue.hpp:121
delpi
Global namespace for the delpi library.
delpi
util
OptionValue.hpp
Generated by
1.17.0