mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add GncOption accessors for Classifier strings.
This commit is contained in:
parent
01fcae6ac8
commit
01dc70cc60
@ -198,6 +198,7 @@ class GncOption
|
||||
public:
|
||||
template <typename OptionType>
|
||||
GncOption(OptionType option) : m_option{option} {}
|
||||
|
||||
template <typename ValueType> ValueType get_value() const
|
||||
{
|
||||
return boost::apply_visitor(GetValueVisitor<ValueType>(), m_option);
|
||||
@ -218,6 +219,22 @@ public:
|
||||
{
|
||||
boost::apply_visitor(SetValueVisitor<ValueType>(value), m_option);
|
||||
}
|
||||
const std::string& get_section() const
|
||||
{
|
||||
return boost::apply_visitor(GetSectionVisitor(), m_option);
|
||||
}
|
||||
const std::string& get_name() const
|
||||
{
|
||||
return boost::apply_visitor(GetNameVisitor(), m_option);
|
||||
}
|
||||
const std::string& get_key() const
|
||||
{
|
||||
return boost::apply_visitor(GetKeyVisitor(), m_option);
|
||||
}
|
||||
const std::string& get_docstring() const
|
||||
{
|
||||
return boost::apply_visitor(GetDocstringVisitor(), m_option);
|
||||
}
|
||||
private:
|
||||
template <typename ValueType>
|
||||
struct GetValueVisitor : public boost::static_visitor<ValueType>
|
||||
@ -277,6 +294,35 @@ private:
|
||||
return option.get_scm_default_value();
|
||||
}
|
||||
};
|
||||
struct GetSectionVisitor : public boost::static_visitor<const std::string&>
|
||||
{
|
||||
template <class OptionType>
|
||||
const std::string& operator()(OptionType& option) const {
|
||||
return option.m_section;
|
||||
}
|
||||
};
|
||||
struct GetNameVisitor : public boost::static_visitor<const std::string&>
|
||||
{
|
||||
template <class OptionType>
|
||||
const std::string& operator()(OptionType& option) const {
|
||||
return option.m_name;
|
||||
}
|
||||
};
|
||||
struct GetKeyVisitor : public boost::static_visitor<const std::string&>
|
||||
{
|
||||
template <class OptionType>
|
||||
const std::string& operator()(OptionType& option) const {
|
||||
return option.m_sort_tag;
|
||||
}
|
||||
};
|
||||
struct GetDocstringVisitor :
|
||||
public boost::static_visitor<const std::string&>
|
||||
{
|
||||
template <class OptionType>
|
||||
const std::string& operator()(OptionType& option) const {
|
||||
return option.m_doc_string;
|
||||
}
|
||||
};
|
||||
GncOptionVariant m_option;
|
||||
};
|
||||
|
||||
|
@ -42,6 +42,16 @@ TEST(GncOption, test_text_ctor)
|
||||
});
|
||||
}
|
||||
|
||||
TEST(GncOption, test_string_classifier_getters)
|
||||
{
|
||||
auto option = gnc_make_string_option("foo", "bar", "baz", "Phony Option",
|
||||
std::string{"waldo"});
|
||||
EXPECT_STREQ("foo", option.get_section().c_str());
|
||||
EXPECT_STREQ("bar", option.get_name().c_str());
|
||||
EXPECT_STREQ("baz", option.get_key().c_str());
|
||||
EXPECT_STREQ("Phony Option", option.get_docstring().c_str());
|
||||
}
|
||||
|
||||
TEST(GncOption, test_string_default_value)
|
||||
{
|
||||
auto option = gnc_make_string_option("foo", "bar", "baz", "Phony Option",
|
||||
|
Loading…
Reference in New Issue
Block a user