delpi  0.0.1
DElta-complete LP solver
Loading...
Searching...
No Matches
OptionValue.hpp
1
15#pragma once
16
17#include <utility>
18
19namespace delpi {
20
31template <typename T>
33 public:
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;
68 return *this;
69 }
70
75 OptionValue &operator=(T &&value) {
76 value_ = std::move(value);
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;
96 }
97 }
98
105 void SetFromFile(const T &value) {
106 switch (type_) {
107 case Type::DEFAULT:
108 case Type::FROM_FILE:
109 value_ = value;
111 return;
112
114 case Type::FROM_CODE:
115 // No operation.
116 return;
117 }
118 }
119
120 private:
123};
124
125} // namespace delpi
OptionValue & operator=(T &&value)
Move-assign operator for T.
Type type_
Type of the value.
void SetFromCommandLine(const T &value)
Sets the value to value which is given by a command-line argument.
OptionValue(OptionValue &&) noexcept=default
Default move constructor.
void SetFromFile(const T &value)
Sets the value to value which is provided from a file.
OptionValue(const OptionValue &)=default
Default copy constructor.
Type
Type of the value.
@ FROM_FILE
Updated by a set-option/set-info in a file.
@ DEFAULT
Default value.
@ FROM_CODE
Explicitly updated from code.
@ FROM_COMMAND_LINE
Updated by a command-line argument.
OptionValue(T value)
Constructs an option value with value.
T value_
Value the class holds.
Global namespace for the delpi library.