The first commit is supposed to go upstream.
The second commit shows how we could use this to clean up the code substantially. (140 lines removed)
The first commit is supposed to go upstream.
The second commit shows how we could use this to clean up the code substantially. (140 lines removed)
173 | @@ -174,6 +174,15 @@ class UniValue { 174 | const UniValue& get_obj() const; 175 | const UniValue& get_array() const; 176 | 177 | + bool get(bool default_value) const { return isNull() ? default_value : get_bool(); } 178 | + const std::string& get(const std::string& default_value) const { return isNull() ? default_value : get_str(); }
std::string get(const std::string& default_value) const { return isNull() ? default_value : get_str(); }
This will need to return a copy. Otherwise we'll get memory issues.
get_str() also returns a const std::string&, so it should be ok, no?
Its the textbook example from https://youtu.be/lkgszkPnV8g?t=845 ;)
Huh... that looks like a bug in the C++ spec, tbh. Anyway, fixed.
Its the textbook example from youtu.be/lkgszkPnV8g?t=845 ;)
Thanks for the good video link :+1:
Yup cool stuff.
Also similar to #20017
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
29 | - if (inputs_in.isNull()) { 30 | - inputs = UniValue::VARR; 31 | - } else { 32 | - inputs = inputs_in.get_array(); 33 | - } 34 | + UniValue inputs = inputs_in.get(UniValue(UniValue::VARR));
@MarcoFalke @practicalswift I assume this is also broken?
179 | + const std::string get(const char* default_value) const { return isNull() ? default_value : get_str(); } 180 | + int get(int default_value) const { return isNull() ? default_value : get_int(); } 181 | + int64_t get(int64_t default_value) const { return isNull() ? default_value : get_int64(); } 182 | + uint64_t get(uint64_t default_value) const { return isNull() ? default_value : (uint64_t)get_int64(); } 183 | + double get(double default_value) const { return isNull() ? default_value : get_real(); } 184 | + const UniValue& get(const UniValue& default_value) const { return isNull() ? default_value : default_value.isArray() ? get_array() : get_obj(); }
@MarcoFalke @practicalswift Specifically, is this line broken? I would hate to return a copy of the entire UniValue here.