UniValue: prefer .size() to .count(), to harmonize w/ existing tree

pull/6121/head
Jeff Garzik 10 years ago committed by Jonas Schnelli
parent dbd8550231
commit efc7883772

@ -346,7 +346,7 @@ static void MutateTxSign(CMutableTransaction& tx, const string& flagStr)
UniValue keysObj = registers["privatekeys"]; UniValue keysObj = registers["privatekeys"];
fGivenKeys = true; fGivenKeys = true;
for (unsigned int kidx = 0; kidx < keysObj.count(); kidx++) { for (unsigned int kidx = 0; kidx < keysObj.size(); kidx++) {
if (!keysObj[kidx].isStr()) if (!keysObj[kidx].isStr())
throw runtime_error("privatekey not a string"); throw runtime_error("privatekey not a string");
CBitcoinSecret vchSecret; CBitcoinSecret vchSecret;
@ -363,7 +363,7 @@ static void MutateTxSign(CMutableTransaction& tx, const string& flagStr)
throw runtime_error("prevtxs register variable must be set."); throw runtime_error("prevtxs register variable must be set.");
UniValue prevtxsObj = registers["prevtxs"]; UniValue prevtxsObj = registers["prevtxs"];
{ {
for (unsigned int previdx = 0; previdx < prevtxsObj.count(); previdx++) { for (unsigned int previdx = 0; previdx < prevtxsObj.size(); previdx++) {
UniValue prevOut = prevtxsObj[previdx]; UniValue prevOut = prevtxsObj[previdx];
if (!prevOut.isObject()) if (!prevOut.isObject())
throw runtime_error("expected prevtxs internal object"); throw runtime_error("expected prevtxs internal object");

@ -72,13 +72,13 @@ BOOST_AUTO_TEST_CASE(univalue_set)
BOOST_CHECK(v.setObject()); BOOST_CHECK(v.setObject());
BOOST_CHECK(v.isObject()); BOOST_CHECK(v.isObject());
BOOST_CHECK_EQUAL(v.count(), 0); BOOST_CHECK_EQUAL(v.size(), 0);
BOOST_CHECK_EQUAL(v.getType(), UniValue::VOBJ); BOOST_CHECK_EQUAL(v.getType(), UniValue::VOBJ);
BOOST_CHECK(v.empty()); BOOST_CHECK(v.empty());
BOOST_CHECK(v.setArray()); BOOST_CHECK(v.setArray());
BOOST_CHECK(v.isArray()); BOOST_CHECK(v.isArray());
BOOST_CHECK_EQUAL(v.count(), 0); BOOST_CHECK_EQUAL(v.size(), 0);
BOOST_CHECK(v.setStr("zum")); BOOST_CHECK(v.setStr("zum"));
BOOST_CHECK(v.isStr()); BOOST_CHECK(v.isStr());
@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(univalue_array)
BOOST_CHECK(arr.push_backV(vec)); BOOST_CHECK(arr.push_backV(vec));
BOOST_CHECK_EQUAL(arr.empty(), false); BOOST_CHECK_EQUAL(arr.empty(), false);
BOOST_CHECK_EQUAL(arr.count(), 5); BOOST_CHECK_EQUAL(arr.size(), 5);
BOOST_CHECK_EQUAL(arr[0].getValStr(), "1023"); BOOST_CHECK_EQUAL(arr[0].getValStr(), "1023");
BOOST_CHECK_EQUAL(arr[1].getValStr(), "zippy"); BOOST_CHECK_EQUAL(arr[1].getValStr(), "zippy");
@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(univalue_array)
arr.clear(); arr.clear();
BOOST_CHECK(arr.empty()); BOOST_CHECK(arr.empty());
BOOST_CHECK_EQUAL(arr.count(), 0); BOOST_CHECK_EQUAL(arr.size(), 0);
} }
BOOST_AUTO_TEST_CASE(univalue_object) BOOST_AUTO_TEST_CASE(univalue_object)
@ -197,7 +197,7 @@ BOOST_AUTO_TEST_CASE(univalue_object)
BOOST_CHECK(obj.pushKVs(obj2)); BOOST_CHECK(obj.pushKVs(obj2));
BOOST_CHECK_EQUAL(obj.empty(), false); BOOST_CHECK_EQUAL(obj.empty(), false);
BOOST_CHECK_EQUAL(obj.count(), 9); BOOST_CHECK_EQUAL(obj.size(), 9);
BOOST_CHECK_EQUAL(obj["age"].getValStr(), "100"); BOOST_CHECK_EQUAL(obj["age"].getValStr(), "100");
BOOST_CHECK_EQUAL(obj["first"].getValStr(), "John"); BOOST_CHECK_EQUAL(obj["first"].getValStr(), "John");
@ -240,7 +240,7 @@ BOOST_AUTO_TEST_CASE(univalue_object)
obj.clear(); obj.clear();
BOOST_CHECK(obj.empty()); BOOST_CHECK(obj.empty());
BOOST_CHECK_EQUAL(obj.count(), 0); BOOST_CHECK_EQUAL(obj.size(), 0);
} }
static const char *json1 = static const char *json1 =
@ -255,13 +255,13 @@ BOOST_AUTO_TEST_CASE(univalue_readwrite)
BOOST_CHECK(v.read(strJson1)); BOOST_CHECK(v.read(strJson1));
BOOST_CHECK(v.isArray()); BOOST_CHECK(v.isArray());
BOOST_CHECK_EQUAL(v.count(), 2); BOOST_CHECK_EQUAL(v.size(), 2);
BOOST_CHECK_EQUAL(v[0].getValStr(), "1.1"); BOOST_CHECK_EQUAL(v[0].getValStr(), "1.1");
UniValue obj = v[1]; UniValue obj = v[1];
BOOST_CHECK(obj.isObject()); BOOST_CHECK(obj.isObject());
BOOST_CHECK_EQUAL(obj.count(), 3); BOOST_CHECK_EQUAL(obj.size(), 3);
BOOST_CHECK(obj["key1"].isStr()); BOOST_CHECK(obj["key1"].isStr());
BOOST_CHECK_EQUAL(obj["key1"].getValStr(), "str"); BOOST_CHECK_EQUAL(obj["key1"].getValStr(), "str");

@ -58,7 +58,7 @@ public:
std::string getValStr() const { return val; } std::string getValStr() const { return val; }
bool empty() const { return (values.size() == 0); } bool empty() const { return (values.size() == 0); }
size_t count() const { return values.size(); } size_t size() const { return values.size(); }
bool getBool() const { return isTrue(); } bool getBool() const { return isTrue(); }
bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes); bool checkObject(const std::map<std::string,UniValue::VType>& memberTypes);

Loading…
Cancel
Save