[C++options] Remove GncOptionValue<SCM>.

No longer needed.
This commit is contained in:
John Ralls 2022-03-21 14:08:06 -07:00
parent f4bfd9df3e
commit 4fe83c3b32
9 changed files with 10 additions and 172 deletions

View File

@ -725,35 +725,6 @@ GncOptionValue<ValueType>::deserialize(const std::string& str) noexcept
return true;
}
template <> void
GncOptionValue<SCM>::set_value(SCM new_value)
{
if (m_value)
scm_gc_unprotect_object(m_value);
m_value = new_value;
scm_gc_protect_object(m_value);
}
template <> void
GncOptionValue<SCM>::set_default_value(SCM new_value)
{
if (m_value)
scm_gc_unprotect_object(m_value);
if (m_default_value)
scm_gc_unprotect_object(m_default_value);
m_value = m_default_value = new_value;
scm_gc_protect_object(m_value);
scm_gc_protect_object(m_default_value);
}
template <> void
GncOptionValue<SCM>::reset_default_value()
{
if (m_value)
scm_gc_unprotect_object(m_value);
m_value = m_default_value;
scm_gc_protect_object(m_value);
}
std::string
GncOptionAccountListValue::serialize() const noexcept
{
@ -947,7 +918,6 @@ template GncOptionValue<size_t>::GncOptionValue(const GncOptionValue<size_t>&);
template GncOptionValue<GncOptionAccountList>::GncOptionValue(const GncOptionValue<GncOptionAccountList>&);
template GncOptionValue<GncMultichoiceOptionIndexVec>::GncOptionValue(const GncOptionValue<GncMultichoiceOptionIndexVec>&);
template GncOptionValue<GncOptionReportPlacementVec>::GncOptionValue(const GncOptionValue<GncOptionReportPlacementVec>&);
template GncOptionValue<SCM>::GncOptionValue(const GncOptionValue<SCM>&);
template void GncOptionValue<bool>::set_value(bool);
template void GncOptionValue<int>::set_value(int);
template void GncOptionValue<int64_t>::set_value(int64_t);
@ -999,7 +969,6 @@ template std::string GncOptionValue<const char*>::serialize() const noexcept;
template std::string GncOptionValue<std::string>::serialize() const noexcept;
template std::string GncOptionValue<const QofQuery*>::serialize() const noexcept;
template std::string GncOptionValue<const GncOwner*>::serialize() const noexcept;
template std::string GncOptionValue<SCM>::serialize() const noexcept;
template std::string GncOptionValue<GncOptionReportPlacementVec>::serialize() const noexcept;
template std::string GncOptionRangeValue<int>::serialize() const noexcept;
template std::string GncOptionRangeValue<double>::serialize() const noexcept;
@ -1012,7 +981,6 @@ template bool GncOptionValue<const char*>::deserialize(const std::string&) noexc
template bool GncOptionValue<std::string>::deserialize(const std::string&) noexcept;
template bool GncOptionValue<const QofQuery*>::deserialize(const std::string&) noexcept;
template bool GncOptionValue<const GncOwner*>::deserialize(const std::string&) noexcept;
template bool GncOptionValue<SCM>::deserialize(const std::string&) noexcept;
template bool GncOptionValue<GncOptionReportPlacementVec>::deserialize(const std::string&) noexcept;
template bool GncOptionRangeValue<int>::deserialize(const std::string&) noexcept;
template bool GncOptionRangeValue<double>::deserialize(const std::string&) noexcept;

View File

@ -93,38 +93,16 @@ public:
ValueType value,
GncOptionUIType ui_type = GncOptionUIType::INTERNAL) :
OptionClassifier{section, name, key, doc_string},
m_ui_type(ui_type), m_value{value}, m_default_value{value} {
if constexpr(std::is_same_v<std::decay_t<ValueType>, SCM>) {
if (value) {
scm_gc_protect_object(m_value);
scm_gc_protect_object(m_default_value);
}
}
}
m_ui_type(ui_type), m_value{value}, m_default_value{value} { }
GncOptionValue<ValueType>(const GncOptionValue<ValueType>& from) :
OptionClassifier{from.m_section, from.m_name, from.m_sort_tag,
from.m_doc_string},
m_ui_type(from.get_ui_type()), m_value{from.get_value()},
m_default_value{from.get_default_value()}
{
if constexpr(std::is_same_v<std::decay_t<ValueType>, SCM>) {
if (m_value)
scm_gc_protect_object(m_value);
if (m_default_value)
scm_gc_protect_object(m_default_value);
}
}
m_default_value{from.get_default_value()}{}
GncOptionValue<ValueType>(GncOptionValue<ValueType>&&) = default;
GncOptionValue<ValueType>& operator=(const GncOptionValue<ValueType>&) = default;
GncOptionValue<ValueType>& operator=(GncOptionValue<ValueType>&&) = default;
~GncOptionValue<ValueType>() {
if constexpr(std::is_same_v<std::decay_t<ValueType>, SCM>) {
if (m_value)
scm_gc_unprotect_object(m_value);
if (m_default_value)
scm_gc_unprotect_object(m_default_value);
}
}
~GncOptionValue<ValueType>() = default;
ValueType get_value() const { return m_value; }
ValueType get_default_value() const { return m_default_value; }
void set_value(ValueType new_value);
@ -297,8 +275,7 @@ template<class OptType,
std::istream& operator>>(std::istream& iss, OptType& opt)
{
std::decay_t<decltype(opt.get_value())> value;
if constexpr (std::is_same_v<std::decay_t<decltype(opt.get_value())>, SCM> ||
std::is_same_v<std::decay_t<decltype(opt.get_value())>, const _gncOwner*> ||
if constexpr (std::is_same_v<std::decay_t<decltype(opt.get_value())>, const _gncOwner*> ||
std::is_same_v<std::decay_t<decltype(opt.get_value())>, const _QofQuery*>)
return iss;
else

View File

@ -433,16 +433,6 @@ GncOption::in_stream(std::istream& iss)
}, *m_option);
}
GncOption*
gnc_make_SCM_option(const char* section, const char* name,
const char* key, const char* doc_string,
SCM value, GncOptionUIType ui_type)
{
return new GncOption(section, name, key, doc_string,
reinterpret_cast<SCM>(value), ui_type);
}
/* We must instantiate all of the templates we need here because we don't expose
* the template implementation in the public header.
*/
@ -460,8 +450,6 @@ template GncOption::GncOption(const char*, const char*, const char*,
// const char*, double, GncOptionUIType);
template GncOption::GncOption(const char*, const char*, const char*,
const char*, std::string, GncOptionUIType);
template GncOption::GncOption(const char*, const char*, const char*,
const char*, SCM, GncOptionUIType);
template GncOption::GncOption(const char*, const char*, const char*,
const char*, const QofQuery*, GncOptionUIType);
template GncOption::GncOption(const char*, const char*, const char*,
@ -480,7 +468,6 @@ template const Account* GncOption::get_value<const Account*>() const;
template RelativeDatePeriod GncOption::get_value<RelativeDatePeriod>() const;
template GncOptionAccountList GncOption::get_value<GncOptionAccountList>() const;
template GncMultichoiceOptionIndexVec GncOption::get_value<GncMultichoiceOptionIndexVec>() const;
template SCM GncOption::get_value<SCM>() const;
template GncOptionReportPlacementVec GncOption::get_value<GncOptionReportPlacementVec>() const;
template bool GncOption::get_default_value<bool>() const;
@ -495,7 +482,6 @@ template const Account* GncOption::get_default_value<const Account*>() const;
template RelativeDatePeriod GncOption::get_default_value<RelativeDatePeriod>() const;
template GncOptionAccountList GncOption::get_default_value<GncOptionAccountList>() const;
template GncMultichoiceOptionIndexVec GncOption::get_default_value<GncMultichoiceOptionIndexVec>() const;
template SCM GncOption::get_default_value<SCM>() const;
template GncOptionReportPlacementVec GncOption::get_default_value<GncOptionReportPlacementVec>() const;
template void GncOption::set_value(bool);
@ -512,7 +498,6 @@ template void GncOption::set_value(RelativeDatePeriod);
template void GncOption::set_value(size_t);
template void GncOption::set_value(GncOptionAccountList);
template void GncOption::set_value(GncMultichoiceOptionIndexVec);
template void GncOption::set_value(SCM);
template void GncOption::set_value(GncOptionReportPlacementVec);
template void GncOption::set_default_value(bool);
@ -528,7 +513,6 @@ template void GncOption::set_default_value(RelativeDatePeriod);
template void GncOption::set_default_value(size_t);
template void GncOption::set_default_value(GncOptionAccountList);
template void GncOption::set_default_value(GncMultichoiceOptionIndexVec);
template void GncOption::set_default_value(SCM);
template void GncOption::set_default_value(GncOptionReportPlacementVec);
template void GncOption::get_limits(double&, double&, double&) const noexcept;

View File

@ -104,7 +104,6 @@ using GncOptionVariant = std::variant<GncOptionValue<std::string>,
GncOptionQofInstanceValue,
GncOptionValue<const QofQuery*>,
GncOptionValue<const GncOwner*>,
GncOptionValue<SCM>,
GncOptionValue<GncOptionReportPlacementVec>,
GncOptionAccountListValue,
GncOptionAccountSelValue,
@ -256,14 +255,6 @@ gnc_make_option(const char* section, const char* name,
return new GncOption(section, name, key, doc_string, value, ui_type);
}
/**
* Free function wrapping GncOption's constructor using an SCM value.
* To work around SWIG_Guile's typedef of SCM to unsigned long
*/
GncOption* gnc_make_SCM_option(const char* section, const char* name,
const char* key, const char* doc_string,
SCM value, GncOptionUIType ui_type);
#endif //GNC_OPTION_HPP_
/** @}

View File

@ -831,16 +831,6 @@ gnc_register_owner_option(GncOptionDB* db, const char* section,
db->register_option(section, std::move(option));
}
void
gnc_register_internal_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, SCM value)
{
GncOption option{section, name, key, doc_string, value,
GncOptionUIType::INTERNAL};
db->register_option(section, std::move(option));
}
void
gnc_register_invoice_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
@ -1249,22 +1239,6 @@ gnc_option_db_lookup_qofinstance_value(GncOptionDB* odb, const char* section,
return option->get_value<const QofInstance*>();
}
SCM
gnc_option_db_lookup_scm_value(GncOptionDB* odb, const char* section,
const char* name)
{
auto option{odb->find_option(section, name)};
return option->get_value<SCM>();
}
void
gnc_option_db_set_scm_value(GncOptionDB* odb, const char* section,
const char* name, SCM value)
{
auto option{odb->find_option(section, name)};
option->set_value(value);
}
// Force creation of templates
template void gnc_register_number_range_option(GncOptionDBPtr& db,
const char* section, const char* name,

View File

@ -166,31 +166,6 @@ const QofInstance* gnc_option_db_lookup_qofinstance_value(GncOptionDB*,
const char*,
const char*);
/**
* Retrieve the GList* value of an option in the GncOptionDB
*
* @param odb the GncOptionDB
* @param section the section in which the option is stored
* @param name the option name
* @return the GList* of the value or nullptr if the option isn't found
* or if its value isn't a string.
*/
SCM gnc_option_db_lookup_scm_value(GncOptionDB*, const char*, const char*);
/**
* Set the GList* value of an option in the GncOptionDB.
*
* The value will not be saved if the option is not in the GncOptionDB or if the
* type of the option isn't string or text.
*
* @param odb the GncOptionDB
* @param section the section in which the option is stored
* @param name the option name
* @param value the value to be stored in the option.
*/
void gnc_option_db_set_scm_value(GncOptionDB*, const char*,
const char*, SCM);
#ifdef __cplusplus
}
#endif

View File

@ -571,35 +571,6 @@ inline void gnc_register_color_option(GncOptionDBPtr& db, const char* section,
gnc_register_color_option(db.get(), section, name, key, doc_string, value);
}
/**
* Create a new internal string option and register it in the options database.
*
* Internal options are used for passing state data in some reports. As the name
* suggests they do not create UI elements in options dialogs.
* @param db A GncOptionDB* for calling from C. Caller retains ownership.
* @param section The database section for the option.
* @param name The option name.
* @param doc_string A description of the option. This will be used in tooltips and should be marked for translation.
* @param value The initial and default value for the option.
*/
void gnc_register_internal_option(GncOptionDB* db, const char* section,
const char* name, const char* key,
const char* doc_string, SCM value);
/**
* As above but takes a const GncOptionDBPtr& (const std::unique_ptr<GncOptionDB>&) for calling from C++.
*/
inline void gnc_register_internal_option(GncOptionDBPtr& db,
const char* section, const char* name,
const char* key,
const char* doc_string,
SCM value)
{
gnc_register_internal_option(db.get(), section, name, key,
doc_string, value);
}
void gnc_register_internal_option(GncOptionDBPtr& db,
const char* section, const char* name,
const char* key,

View File

@ -1243,13 +1243,6 @@ inline SCM return_scm_value(ValueType value)
return scm_simple_format(SCM_BOOL_F, plain_format_str,
scm_val);
}
if constexpr (is_same_decayed_v<decltype(option),
GncOptionValue<SCM>>)
{
auto scm_val{scm_list_1(return_scm_value(option.get_value()))};
return scm_simple_format(SCM_BOOL_F, ticked_format_str,
scm_val);
}
if constexpr (is_same_decayed_v<decltype(option),
GncOptionValue<GncOptionReportPlacementVec>>)
{

View File

@ -270,8 +270,13 @@
(GncOptionUIType-INTERNAL)))
((string? default) (gnc-make-string-option section name key desc default
(GncOptionUIType-INTERNAL)))
((procedure? default)
(format #t "gnc:make-internal-option passed procedure resolving to ~a~%" (default))
(gnc-make-bool-option section name key desc #f (GncOptionUIType-INTERNAL)))
(else
(gnc-make-SCM-option section name key desc default type)))))
(format #t "gnc:make-internal-option passed something unknown that looks like ~a~%" default)
(gnc-make-bool-option section name key desc #f (GncOptionUIType-INTERNAL))))))
(define-public (gnc:make-owner-option section name key docstring getter validator owner-type)
(issue-deprecation-warning "gnc:make-owner-option is deprecated. Make and register the option in one command with gnc-register-owner-option.")
(let* ((ui-type (cond