Skip to content

Commit 025c6ca

Browse files
author
MacroFake
committed
Squashed 'src/univalue/' changes from 6c19d050a9..de4f73ddca
de4f73ddca Merge bitcoin-core/univalue-subtree#36: Drop overloaded members 076c051488 Drop overloaded members 06265321de Merge bitcoin-core/univalue-subtree#35: Remove get_int/get_int64 in favor of getInt<> 462c503aa4 Remove get_int/get_int64 in favor of getInt<> 68c8f5532d Merge bitcoin-core/univalue-subtree#34: doc: remove TODO 297c53a5ee doc: remove TODO git-subtree-dir: src/univalue git-subtree-split: de4f73ddca40487179e9ed08c6f6aa745d6cbba3
1 parent f403531 commit 025c6ca

File tree

3 files changed

+15
-76
lines changed

3 files changed

+15
-76
lines changed

TODO

Lines changed: 0 additions & 10 deletions
This file was deleted.

include/univalue.h

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -83,66 +83,10 @@ class UniValue {
8383
bool isObject() const { return (typ == VOBJ); }
8484

8585
bool push_back(const UniValue& val);
86-
bool push_back(const std::string& val_) {
87-
UniValue tmpVal(VSTR, val_);
88-
return push_back(tmpVal);
89-
}
90-
bool push_back(const char *val_) {
91-
std::string s(val_);
92-
return push_back(s);
93-
}
94-
bool push_back(uint64_t val_) {
95-
UniValue tmpVal(val_);
96-
return push_back(tmpVal);
97-
}
98-
bool push_back(int64_t val_) {
99-
UniValue tmpVal(val_);
100-
return push_back(tmpVal);
101-
}
102-
bool push_back(bool val_) {
103-
UniValue tmpVal(val_);
104-
return push_back(tmpVal);
105-
}
106-
bool push_back(int val_) {
107-
UniValue tmpVal(val_);
108-
return push_back(tmpVal);
109-
}
110-
bool push_back(double val_) {
111-
UniValue tmpVal(val_);
112-
return push_back(tmpVal);
113-
}
11486
bool push_backV(const std::vector<UniValue>& vec);
11587

11688
void __pushKV(const std::string& key, const UniValue& val);
11789
bool pushKV(const std::string& key, const UniValue& val);
118-
bool pushKV(const std::string& key, const std::string& val_) {
119-
UniValue tmpVal(VSTR, val_);
120-
return pushKV(key, tmpVal);
121-
}
122-
bool pushKV(const std::string& key, const char *val_) {
123-
std::string _val(val_);
124-
return pushKV(key, _val);
125-
}
126-
bool pushKV(const std::string& key, int64_t val_) {
127-
UniValue tmpVal(val_);
128-
return pushKV(key, tmpVal);
129-
}
130-
bool pushKV(const std::string& key, uint64_t val_) {
131-
UniValue tmpVal(val_);
132-
return pushKV(key, tmpVal);
133-
}
134-
bool pushKV(const std::string& key, bool val_) {
135-
UniValue tmpVal(val_);
136-
return pushKV(key, tmpVal);
137-
}
138-
bool pushKV(const std::string& key, int val_) {
139-
UniValue tmpVal((int64_t)val_);
140-
return pushKV(key, tmpVal);
141-
}
142-
bool pushKV(const std::string& key, double val_) {
143-
UniValue tmpVal(val_);
144-
return pushKV(key, tmpVal);
145-
}
14690
bool pushKVs(const UniValue& obj);
14791

14892
std::string write(unsigned int prettyIndent = 0,
@@ -185,8 +129,6 @@ class UniValue {
185129
}
186130
bool get_bool() const;
187131
const std::string& get_str() const;
188-
auto get_int() const { return getInt<int>(); };
189-
auto get_int64() const { return getInt<int64_t>(); };
190132
double get_real() const;
191133
const UniValue& get_obj() const;
192134
const UniValue& get_array() const;

test/object.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,30 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
9292
BOOST_CHECK(v1.isNum());
9393
BOOST_CHECK_THROW(v1.get_bool(), std::runtime_error);
9494

95+
{
96+
UniValue v_negative;
97+
BOOST_CHECK(v_negative.setNumStr("-1"));
98+
BOOST_CHECK_THROW(v_negative.getInt<uint8_t>(), std::runtime_error);
99+
BOOST_CHECK_EQUAL(v_negative.getInt<int8_t>(), -1);
100+
}
101+
95102
UniValue v2;
96103
BOOST_CHECK(v2.setBool(true));
97104
BOOST_CHECK_EQUAL(v2.get_bool(), true);
98-
BOOST_CHECK_THROW(v2.get_int(), std::runtime_error);
105+
BOOST_CHECK_THROW(v2.getInt<int>(), std::runtime_error);
99106

100107
UniValue v3;
101108
BOOST_CHECK(v3.setNumStr("32482348723847471234"));
102-
BOOST_CHECK_THROW(v3.get_int64(), std::runtime_error);
109+
BOOST_CHECK_THROW(v3.getInt<int64_t>(), std::runtime_error);
103110
BOOST_CHECK(v3.setNumStr("1000"));
104-
BOOST_CHECK_EQUAL(v3.get_int64(), 1000);
111+
BOOST_CHECK_EQUAL(v3.getInt<int64_t>(), 1000);
105112

106113
UniValue v4;
107114
BOOST_CHECK(v4.setNumStr("2147483648"));
108-
BOOST_CHECK_EQUAL(v4.get_int64(), 2147483648);
109-
BOOST_CHECK_THROW(v4.get_int(), std::runtime_error);
115+
BOOST_CHECK_EQUAL(v4.getInt<int64_t>(), 2147483648);
116+
BOOST_CHECK_THROW(v4.getInt<int>(), std::runtime_error);
110117
BOOST_CHECK(v4.setNumStr("1000"));
111-
BOOST_CHECK_EQUAL(v4.get_int(), 1000);
118+
BOOST_CHECK_EQUAL(v4.getInt<int>(), 1000);
112119
BOOST_CHECK_THROW(v4.get_str(), std::runtime_error);
113120
BOOST_CHECK_EQUAL(v4.get_real(), 1000);
114121
BOOST_CHECK_THROW(v4.get_array(), std::runtime_error);
@@ -120,10 +127,10 @@ BOOST_AUTO_TEST_CASE(univalue_typecheck)
120127
BOOST_CHECK(v5.read("[true, 10]"));
121128
BOOST_CHECK_NO_THROW(v5.get_array());
122129
std::vector<UniValue> vals = v5.getValues();
123-
BOOST_CHECK_THROW(vals[0].get_int(), std::runtime_error);
130+
BOOST_CHECK_THROW(vals[0].getInt<int>(), std::runtime_error);
124131
BOOST_CHECK_EQUAL(vals[0].get_bool(), true);
125132

126-
BOOST_CHECK_EQUAL(vals[1].get_int(), 10);
133+
BOOST_CHECK_EQUAL(vals[1].getInt<int>(), 10);
127134
BOOST_CHECK_THROW(vals[1].get_bool(), std::runtime_error);
128135
}
129136

0 commit comments

Comments
 (0)