Remove GncOptionWrapper.

Move the GncOptions into the GncOptionDB. This works with tests but
might not with real reports.
pull/1191/head
John Ralls 7 years ago
parent 2ee0edaa16
commit cf0b1da4fa

@ -48,8 +48,7 @@ GncOptionDB::register_option(const char* section, GncOption&& option)
GncOptionVec{}));
db_section = std::prev(m_sections.end());
}
auto wrapper = std::make_shared<GncOptionWrapper>(option, nullptr);
db_section->second.emplace_back(wrapper);
db_section->second.emplace_back(std::move(option));
}
void
@ -66,9 +65,9 @@ GncOptionDB::unregister_option(const char* section, const char* name)
db_section->second.erase(
std::remove_if(
db_section->second.begin(), db_section->second.end(),
[name](GncOptionWrapperPtr option) -> bool
[name](const GncOption& option) -> bool
{
return option->m_option.get_name() == std::string{name};
return option.get_name() == std::string{name};
}));
}
}
@ -91,13 +90,13 @@ GncOptionDB::lookup_option(const char* section, const char* name) const
return SCM_BOOL_F;
auto db_opt = std::find_if(
db_section->second.begin(), db_section->second.end(),
[name](GncOptionWrapperPtr option) -> bool
[name](const GncOption& option) -> bool
{
return option->m_option.get_name() == std::string{name};
return option.get_name() == std::string{name};
});
if (db_opt == db_section->second.end() || !*db_opt)
if (db_opt == db_section->second.end())
return SCM_BOOL_F;
return (*db_opt)->m_option.get_scm_value();
return db_opt->get_scm_value();
}
static const std::string empty_string;
@ -114,13 +113,13 @@ GncOptionDB::lookup_string_option(const char* section, const char* name) const
return empty_string;
auto db_opt = std::find_if(
db_section->second.begin(), db_section->second.end(),
[name](GncOptionWrapperPtr option) -> bool
[name](const GncOption& option) -> bool
{
return option->m_option.get_name() == std::string{name};
return option.get_name() == std::string{name};
});
if (db_opt == db_section->second.end() || !*db_opt)
if (db_opt == db_section->second.end())
return empty_string;
return (*db_opt)->m_option.get_value<std::string>();
return db_opt->get_value<std::string>();
}
bool

@ -27,16 +27,8 @@
#include "gnc-option.hpp"
class GncOptionDB;
struct GncOptionWrapper
{
GncOptionWrapper(const GncOption& opt, void* ptr) : m_option{opt}, m_widget{ptr} {}
GncOptionWrapper(GncOption&& opt, void* ptr) : m_option{opt}, m_widget{ptr} {}
GncOption m_option;
void* m_widget; /* Don't want widget code in libgnucash! GObject closure?*/
};
using GncOptionWrapperPtr = std::shared_ptr<GncOptionWrapper>;
using GncOptionVec = std::vector<GncOptionWrapperPtr>;
using GncOptionVec = std::vector<GncOption>;
using GncOptionSection = std::pair<std::string, GncOptionVec>;
using GncOptionSectionPtr = std::shared_ptr<const GncOptionSection>;
class GncOptionDB

@ -12,7 +12,7 @@ extern "C" SCM scm_init_sw_gnc_optiondb_module(void);
%include <std_string.i>
%ignore OptionClassifier;
%ignore OptionUIItem;
%ignore GncOption;
%ignore GncOptionWrapper;
%include "gnc-optiondb.hpp"

Loading…
Cancel
Save