Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Merge pull request #42 from jgarzik/2017-remove-pair
Browse files Browse the repository at this point in the history
Remove std::pair related wrappers
  • Loading branch information
jgarzik authored Nov 12, 2019
2 parents 2f21cb7 + 884d719 commit d6715ee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 82 deletions.
69 changes: 0 additions & 69 deletions include/univalue.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include <map>
#include <cassert>

#include <utility> // std::pair

class UniValue {
public:
enum VType { VNULL, VOBJ, VARR, VSTR, VNUM, VBOOL, };
Expand Down Expand Up @@ -129,76 +127,9 @@ class UniValue {
const UniValue& get_array() const;

enum VType type() const { return getType(); }
bool push_back(std::pair<std::string,UniValue> pear) {
return pushKV(pear.first, pear.second);
}
friend const UniValue& find_value( const UniValue& obj, const std::string& name);
};

//
// The following were added for compatibility with json_spirit.
// Most duplicate other methods, and should be removed.
//
static inline std::pair<std::string,UniValue> Pair(const char *cKey, const char *cVal)
{
std::string key(cKey);
UniValue uVal(cVal);
return std::make_pair(key, uVal);
}

static inline std::pair<std::string,UniValue> Pair(const char *cKey, std::string strVal)
{
std::string key(cKey);
UniValue uVal(strVal);
return std::make_pair(key, uVal);
}

static inline std::pair<std::string,UniValue> Pair(const char *cKey, uint64_t u64Val)
{
std::string key(cKey);
UniValue uVal(u64Val);
return std::make_pair(key, uVal);
}

static inline std::pair<std::string,UniValue> Pair(const char *cKey, int64_t i64Val)
{
std::string key(cKey);
UniValue uVal(i64Val);
return std::make_pair(key, uVal);
}

static inline std::pair<std::string,UniValue> Pair(const char *cKey, bool iVal)
{
std::string key(cKey);
UniValue uVal(iVal);
return std::make_pair(key, uVal);
}

static inline std::pair<std::string,UniValue> Pair(const char *cKey, int iVal)
{
std::string key(cKey);
UniValue uVal(iVal);
return std::make_pair(key, uVal);
}

static inline std::pair<std::string,UniValue> Pair(const char *cKey, double dVal)
{
std::string key(cKey);
UniValue uVal(dVal);
return std::make_pair(key, uVal);
}

static inline std::pair<std::string,UniValue> Pair(const char *cKey, const UniValue& uVal)
{
std::string key(cKey);
return std::make_pair(key, uVal);
}

static inline std::pair<std::string,UniValue> Pair(std::string key, const UniValue& uVal)
{
return std::make_pair(key, uVal);
}

enum jtokentype {
JTOK_ERR = -1,
JTOK_NONE = 0, // eof
Expand Down
26 changes: 13 additions & 13 deletions test/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#define BOOST_CHECK_NO_THROW(stmt) { \
try { \
(stmt); \
} catch (...) { \
assert(0); \
} \
} catch (...) { \
assert(0); \
} \
}

BOOST_FIXTURE_TEST_SUITE(univalue_tests, BasicTestingSetup)
Expand Down Expand Up @@ -266,11 +266,11 @@ BOOST_AUTO_TEST_CASE(univalue_object)
strKey = "temperature";
BOOST_CHECK(obj.pushKV(strKey, (double) 90.012));

strKey = "moon";
BOOST_CHECK(obj.pushKV(strKey, true));
strKey = "booleanF";
BOOST_CHECK(obj.pushKV(strKey, (bool) false));

strKey = "spoon";
BOOST_CHECK(obj.pushKV(strKey, false));
strKey = "booleanT";
BOOST_CHECK(obj.pushKV(strKey, (bool) true));

UniValue obj2(UniValue::VOBJ);
BOOST_CHECK(obj2.pushKV("cat1", 9000));
Expand All @@ -288,10 +288,10 @@ BOOST_AUTO_TEST_CASE(univalue_object)
BOOST_CHECK_EQUAL(obj["time"].getValStr(), "3600");
BOOST_CHECK_EQUAL(obj["calories"].getValStr(), "12");
BOOST_CHECK_EQUAL(obj["temperature"].getValStr(), "90.012");
BOOST_CHECK_EQUAL(obj["moon"].getValStr(), "1");
BOOST_CHECK_EQUAL(obj["spoon"].getValStr(), "");
BOOST_CHECK_EQUAL(obj["cat1"].getValStr(), "9000");
BOOST_CHECK_EQUAL(obj["cat2"].getValStr(), "12345");
BOOST_CHECK_EQUAL(obj["booleanF"].getValStr(), "");
BOOST_CHECK_EQUAL(obj["booleanT"].getValStr(), "1");

BOOST_CHECK_EQUAL(obj["nyuknyuknyuk"].getValStr(), "");

Expand All @@ -302,10 +302,10 @@ BOOST_AUTO_TEST_CASE(univalue_object)
BOOST_CHECK(obj.exists("time"));
BOOST_CHECK(obj.exists("calories"));
BOOST_CHECK(obj.exists("temperature"));
BOOST_CHECK(obj.exists("moon"));
BOOST_CHECK(obj.exists("spoon"));
BOOST_CHECK(obj.exists("cat1"));
BOOST_CHECK(obj.exists("cat2"));
BOOST_CHECK(obj.exists("booleanF"));
BOOST_CHECK(obj.exists("booleanT"));

BOOST_CHECK(!obj.exists("nyuknyuknyuk"));

Expand All @@ -317,10 +317,10 @@ BOOST_AUTO_TEST_CASE(univalue_object)
objTypes["time"] = UniValue::VNUM;
objTypes["calories"] = UniValue::VNUM;
objTypes["temperature"] = UniValue::VNUM;
objTypes["moon"] = UniValue::VBOOL;
objTypes["spoon"] = UniValue::VBOOL;
objTypes["cat1"] = UniValue::VNUM;
objTypes["cat2"] = UniValue::VNUM;
objTypes["booleanF"] = UniValue::VBOOL;
objTypes["booleanT"] = UniValue::VBOOL;
BOOST_CHECK(obj.checkObject(objTypes));

objTypes["cat2"] = UniValue::VSTR;
Expand Down

0 comments on commit d6715ee

Please sign in to comment.