77#include < list>
88#include < memory>
99#include < session/config.hpp>
10+ #include < session/types.hpp>
1011#include < session/util.hpp>
1112#include < span>
1213#include < type_traits>
@@ -29,9 +30,6 @@ class bt_dict_consumer;
2930
3031namespace session ::config {
3132
32- template <typename T, typename ... U>
33- static constexpr bool is_one_of = (std::is_same_v<T, U> || ...);
34-
3533// / True for a dict_value direct subtype, but not scalar sub-subtypes.
3634template <typename T>
3735static constexpr bool is_dict_subtype = is_one_of<T, config::scalar, config::set, config::dict>;
@@ -436,12 +434,16 @@ class ConfigBase : public ConfigSig {
436434 // /
437435 // / Inputs:
438436 // / - `value` -- This will be assigned to the dict if it is missing
439- void insert_if_missing (config::scalar&& value) {
437+ //
438+ // / Ouputs:
439+ // / - `bool` -- True if the value was inserted, false otherwise
440+ bool insert_if_missing (config::scalar&& value) {
440441 if (!_conf.is_dirty ())
441442 if (auto current = get_clean<config::set>(); current && current->count (value))
442- return ;
443+ return false ;
443444
444445 get_dirty<config::set>().insert (std::move (value));
446+ return true ;
445447 }
446448
447449 // / API: base/ConfigBase::DictFieldProxy::set_erase_impl
@@ -450,28 +452,35 @@ class ConfigBase : public ConfigSig {
450452 // /
451453 // / Inputs:
452454 // / - `value` -- This will be deleted from the dict
453- void set_erase_impl (const config::scalar& value) {
455+ // /
456+ // / Outputs:
457+ // / - `bool` -- True if an element was erased, false otherwise
458+ bool set_erase_impl (const config::scalar& value) {
454459 if (!_conf.is_dirty ())
455460 if (auto current = get_clean<config::set>(); current && !current->count (value))
456- return ;
461+ return false ;
457462
458463 config::dict* data = &_conf.dirty ().data ();
459464
460465 for (const auto & key : _inter_keys) {
461466 auto it = data->find (key);
462467 data = it != data->end () ? std::get_if<config::dict>(&it->second ) : nullptr ;
463468 if (!data)
464- return ;
469+ return false ;
465470 }
466471
467472 auto it = data->find (_last_key);
468473 if (it == data->end ())
469- return ;
474+ return false ;
470475 auto & val = it->second ;
471- if (auto * current = std::get_if<config::set>(&val))
476+ bool result = false ;
477+ if (auto * current = std::get_if<config::set>(&val)) {
472478 current->erase (value);
473- else
479+ result = true ;
480+ } else {
474481 val.emplace <config::set>();
482+ }
483+ return result;
475484 }
476485
477486 public:
@@ -797,8 +806,8 @@ class ConfigBase : public ConfigSig {
797806 // /
798807 // / Inputs:
799808 // / - `value` -- The value to be set
800- void set_insert (std::string_view value) {
801- insert_if_missing (config::scalar{std::string{value}});
809+ bool set_insert (std::string_view value) {
810+ return insert_if_missing (config::scalar{std::string{value}});
802811 }
803812
804813 // / API: base/ConfigBase::DictFieldProxy::set_insert(int64_t)
@@ -808,7 +817,7 @@ class ConfigBase : public ConfigSig {
808817 // /
809818 // / Inputs:
810819 // / - `value` -- The value to be set
811- void set_insert (int64_t value) { insert_if_missing (config::scalar{value}); }
820+ bool set_insert (int64_t value) { return insert_if_missing (config::scalar{value}); }
812821
813822 // / API: base/ConfigBase::DictFieldProxy::set_erase(std::string_view)
814823 // /
@@ -818,8 +827,11 @@ class ConfigBase : public ConfigSig {
818827 // /
819828 // / Inputs:
820829 // / - `value` -- The value to be set
821- void set_erase (std::string_view value) {
822- set_erase_impl (config::scalar{std::string{value}});
830+ // /
831+ // / Outputs:
832+ // / - `bool` -- True if an element was erased, false otherwise
833+ bool set_erase (std::string_view value) {
834+ return set_erase_impl (config::scalar{std::string{value}});
823835 }
824836
825837 // / API: base/ConfigBase::DictFieldProxy::set_erase(int64_t)
@@ -830,7 +842,10 @@ class ConfigBase : public ConfigSig {
830842 // /
831843 // / Inputs:
832844 // / - `value` -- The value to be set
833- void set_erase (int64_t value) { set_erase_impl (scalar{value}); }
845+ // /
846+ // / Outputs:
847+ // / - `bool` -- True if an element was erased, false otherwise
848+ bool set_erase (int64_t value) { return set_erase_impl (scalar{value}); }
834849
835850 // / API: base/ConfigBase::DictFieldProxy::emplace
836851 // /
@@ -944,7 +959,7 @@ class ConfigBase : public ConfigSig {
944959 // / API: base/ConfigBase::load_key
945960 // /
946961 // / Called to load an ed25519 key for encryption; this is meant for use by single-ownership
947- // / config types, like UserProfile, but not shared config types (closed groups).
962+ // / config types, like UserProfile, but not shared config types (groups).
948963 // /
949964 // / Takes a binary string which is either the 32-byte seed, or 64-byte libsodium secret (which
950965 // / is just the seed and pubkey concatenated together), and then calls `key(...)` with the seed.
0 commit comments