33 #ifndef GNC_OPTION_HPP_ 34 #define GNC_OPTION_HPP_ 44 #include "gnc-option-ui.hpp" 50 using GncOptionUIItemPtr = std::unique_ptr<GncOptionUIItem>;
51 #ifndef SWIG //SWIG pulls in GncOwner from swig-engine. 67 using GncOptionReportPlacement = std::tuple<uint32_t, uint32_t, uint32_t>;
68 using GncOptionReportPlacementVec = std::vector<GncOptionReportPlacement>;
72 static constexpr
bool value =
73 std::is_base_of_v<OptionClassifier, std::decay_t<T>>;
76 template <
typename T>
inline constexpr
bool 79 template <
typename T,
typename U>
82 static constexpr
bool value = std::is_same_v<std::decay_t<T>,
86 template <
typename T,
typename U>
inline constexpr
bool 92 static constexpr
bool value =
93 (is_same_decayed_v<T, GncOptionRangeValue<int>> ||
94 is_same_decayed_v<T, GncOptionRangeValue<double>>);
97 template <
typename T>
inline constexpr
bool 101 using GncOptionVariant = std::variant<GncOptionValue<std::string>,
116 using GncOptionVariantPtr = std::unique_ptr<GncOptionVariant>;
118 enum class GncOptionMultichoiceKeyType
134 template <
typename OptionType,
135 typename std::enable_if_t<is_OptionClassifier_v<OptionType>,
139 m_option{std::make_unique<GncOptionVariant>(option)} {}
140 template <
typename ValueType,
141 typename std::enable_if_t<!is_OptionClassifier_v<ValueType>,
143 GncOption(
const char* section,
const char* name,
144 const char* key,
const char* doc_string,
147 template <
typename ValueType>
void set_value(ValueType value);
148 template <
typename ValueType>
void set_default_value(ValueType value);
149 template <
typename ValueType> ValueType get_default_value()
const;
150 template <
typename ValueType> ValueType get_value()
const;
151 void reset_default_value();
153 const std::string& get_section()
const;
154 const std::string& get_name()
const;
155 const std::string& get_key()
const;
156 const std::string& get_docstring()
const;
157 void set_ui_item(GncOptionUIItemPtr&& ui_elem);
159 void set_ui_item_selectable(
bool)
const noexcept;
161 void set_ui_item_from_option();
162 void set_option_from_ui_item();
163 void make_internal();
164 bool is_changed()
const noexcept;
170 template <
typename ValueType>
void get_limits(ValueType&, ValueType&,
171 ValueType&)
const noexcept;
173 template <
typename ValueType>
bool validate(ValueType value)
const;
184 bool is_alternate()
const noexcept;
185 void set_alternate(
bool) noexcept;
199 std::istream&
in_stream(std::istream& iss);
200 friend GncOptionVariant& swig_get_option(
GncOption*);
203 inline static const std::string c_empty_string{
""};
204 GncOptionVariantPtr m_option;
205 GncOptionUIItemPtr m_ui_item{
nullptr};
211 return right.get_key() < left.get_key();
222 operator>>(std::istream& iss,
GncOption& opt)
228 output_color_value(std::ostream& oss,
const std::string& value)
231 oss << std::fixed << std::showpoint << std::setprecision(1);
232 auto len{value.length() > 8 ? 8 : value.length()};
233 for (
size_t i{}; i < len; i += 2)
235 oss << static_cast<float>(stoi(value.substr(i, 2),
nullptr, 16));
252 const char* key,
const char* doc_string,
255 return new GncOption(section, name, key, doc_string, value, ui_type);
258 #endif //GNC_OPTION_HPP_ bool is_multiselect() const noexcept
std::ostream & operator<<(std::ostream &ostr, RelativeDatePeriod per)
Add the display string to the provided std::ostream.
std::size_t num_permissible_values() const
Implemented only for GncOptionMultiselectValue.
The generic option-value class.
bool deserialize(const std::string &str)
Set the option's value from a character sequence.
A legal date value is a pair of either a RelativeDatePeriod, the absolute flag and a time64...
const char * permissible_value(std::size_t index) const
Implemented only for GncOptionMultiselectValue.
std::size_t permissible_value_index(const char *value) const
Implemented only for GncOptionMultiselectValue.
const char * permissible_value_name(std::size_t index) const
Implemented only for GncOptionMultiselectValue.
Represents the public interface for an option.
Set one or more accounts on which to report, optionally restricted to certain account types...
This class is the parent of all option implmentations.
bool validate(ValueType value) const
Not implemented for GncOptionValue.
Multichoice options have a vector of valid options (GncMultichoiceOptionChoices) and validate the sel...
std::string serialize() const
Get a string suitable for storage representing the option's value.
class GncOptionCommodityValue Commodities are stored with their namespace and mnemonic instead of the...
Used for numeric ranges and plot sizes.
Holds a pointer to the UI item which will control the option and an enum representing the type of the...
GncOption * gnc_make_option(const char *section, const char *name, const char *key, const char *doc_string, ValueType value, GncOptionUIType ui_type)
Free function wrapping GncOption's constructor.
void get_limits(ValueType &, ValueType &, ValueType &) const noexcept
Implemented only for GncOptionNumericRange.
GncOptionUIType
Used by GncOptionClassifier to indicate to dialog-options what control should be displayed for the op...
std::istream & in_stream(std::istream &iss)
Set the option's value from an input stream.
GList * account_type_list() const noexcept
Implemented only for GncOptionAccountListValue.
Relative date enumeration and manipulation functions.