dlinear  0.0.1
Delta-complete SMT solver for linear programming
Loading...
Searching...
No Matches
OptionValue.hpp
1
16#pragma once
17
18#include <iostream>
19#include <utility>
20
21namespace dlinear {
22
34template <typename T>
36 public:
42 enum class Type {
43 DEFAULT,
44 FROM_FILE,
46 FROM_CODE,
47 };
48
53 explicit OptionValue(T value) : value_{std::move(value)}, type_{Type::DEFAULT} {}
54
56 OptionValue(const OptionValue &) = default;
57
59 OptionValue(OptionValue &&) noexcept = default;
60
62 OptionValue &operator=(const OptionValue &) = default;
63
65 OptionValue &operator=(OptionValue &&) noexcept = default;
66
68 ~OptionValue() = default;
69
74 OptionValue &operator=(const T &value) {
75 value_ = value;
77 return *this;
78 }
79
84 OptionValue &operator=(T &&value) {
85 value_ = std::move(value);
87 return *this;
88 }
89
91 const T &get() const { return value_; }
92 const T &operator*() const { return value_; }
93
101 void SetFromCommandLine(const T &value) {
102 if (type_ != Type::FROM_CODE) {
103 value_ = value;
105 }
106 }
107
114 void SetFromFile(const T &value) {
115 switch (type_) {
116 case Type::DEFAULT:
117 case Type::FROM_FILE:
118 value_ = value;
120 return;
121
123 case Type::FROM_CODE:
124 // No operation.
125 return;
126 }
127 }
128
129 friend std::ostream &operator<<(std::ostream &os, Type type) {
130 switch (type) {
132 return os << "DEFAULT";
134 return os << "FROM_FILE";
136 return os << "FROM_COMMAND_LINE";
138 return os << "FROM_CODE";
139 }
140 }
141
142 private:
145};
146
147} // namespace dlinear
Represents an optional value in dLinear.
Type
Type of the value.
@ FROM_FILE
Updated by a set-option/set-info in a file.
@ FROM_CODE
Explicitly updated from code.
@ FROM_COMMAND_LINE
Updated by a command-line argument.
void SetFromFile(const T &value)
Sets the value to value which is provided from a file.
Type type_
Type of the value.
OptionValue & operator=(T &&value)
Move-assign operator for T.
OptionValue(OptionValue &&) noexcept=default
Default move constructor.
T value_
Value the class holds.
const T & get() const
Get read-only access to the internal stored value of the optional value.
void SetFromCommandLine(const T &value)
Sets the value to value which is given by a command-line argument.
OptionValue(const OptionValue &)=default
Default copy constructor.
OptionValue(T value)
Constructs an option value with value.
Global namespace for the dlinear library.
STL namespace.