32 #ifndef GNC_OPTIONDB_P_HPP_ 33 #define GNC_OPTIONDB_P_HPP_ 52 using GncOptionVec = std::vector<GncOption>;
61 GncOptionVec m_options;
66 void foreach_option(std::function<
void(
GncOption&)> func);
67 void foreach_option(std::function<
void(
const GncOption&)> func)
const;
68 const std::string& get_name()
const noexcept {
return m_name; }
69 size_t get_num_options()
const noexcept {
return m_options.size(); }
71 void remove_option(
const char* name);
72 const GncOption* find_option(
const char* name)
const;
75 using GncOptionSectionPtr = std::shared_ptr<GncOptionSection>;
78 operator<(
const GncOptionSectionPtr& right,
const GncOptionSectionPtr& left)
80 return right->get_name() < left->get_name();
83 using GncOptionDBChangeCallback = void (*)(
void* user_data);
89 m_id{
id}, m_func{func}, m_data{data} {}
97 GncOptionDBChangeCallback m_func;
101 using GncCallbackVec = std::vector<GncOptionDBCallback>;
117 void foreach_section(std::function<
void(GncOptionSectionPtr&)> func)
119 for (
auto& section : m_sections)
122 void foreach_section(std::function<
void(
const GncOptionSectionPtr&)> func)
const 124 for (
auto& section : m_sections)
127 size_t num_sections()
const noexcept {
return m_sections.size(); }
128 bool get_changed()
const noexcept {
return m_dirty; }
129 void register_option(
const char* section,
GncOption&& option);
130 void register_option(
const char* section,
GncOption* option);
131 void unregister_option(
const char* section,
const char* name);
132 void set_default_section(
const char* section);
134 std::string lookup_string_option(
const char* section,
const char* name);
135 bool set_string_option(
const char* section,
const char* name,
const std::string& value)
137 return set_option<std::string>(section, name, value);
139 template <
typename ValueType>
140 bool set_option(
const char* section,
const char* name, ValueType value)
144 auto option{find_option(section, name)};
147 option->set_value(value);
150 catch(
const std::invalid_argument& err)
152 printf(
"Set Failed: %s\n", err.what());
157 void make_internal(
const char* section,
const char* name);
164 GncOption* find_option(
const std::string& section,
const char* name)
166 return const_cast<GncOption*
>(
static_cast<const GncOptionDB&
>(*this).find_option(section, name));
168 const GncOption* find_option(
const std::string& section,
const char* name)
const;
169 std::ostream& save_to_key_value(std::ostream& oss)
const noexcept;
170 std::istream& load_from_key_value(std::istream& iss);
171 void save_to_kvp(QofBook* book,
bool clear_book)
const noexcept;
172 void load_from_kvp(QofBook* book) noexcept;
173 std::ostream& save_option_key_value(std::ostream& oss,
174 const std::string& section,
175 const std::string& name)
const noexcept;
176 std::istream& load_option_key_value(std::istream& iss);
177 size_t register_callback(GncOptionDBChangeCallback,
void*);
178 void unregister_callback(
size_t);
179 void run_callbacks();
182 std::vector<GncOptionSectionPtr> m_sections;
183 bool m_dirty =
false;
184 GncCallbackVec m_callbacks{};
186 std::function<GncOptionUIItem*()> m_get_ui_value;
187 std::function<void(GncOptionUIItem*)> m_set_ui_value;
191 #endif // GNC_OPTIONDB_P_HPP_ Holds all of the options for a book, report, or stylesheet, organized by GncOptionSections.
Represents the public interface for an option.
C++ Public interface for individual options.
class GncOptionSection The upper-level classification implementation.
Tax Table programming interface.
Implementation templates and specializtions for GncOption values.
Business Invoice Interface.