mirror of
https://github.com/wownero/wownero-cpp.git
synced 2026-10-20 00:28:41 +02:00
MoneroUtils toPropertyTree(vector<T> || vector<shared_pr<T>>) with
template restriction (duck typing?)
This commit is contained in:
@@ -24,7 +24,8 @@ namespace monero {
|
||||
cout << "MoneroBlock::toPropertyTree(block)" << endl;
|
||||
boost::property_tree::ptree node;
|
||||
if (height != boost::none) node.put("height", *height); // TODO: finish this, add txs
|
||||
//node.add_child("txs", toPropertyTree(txs)); // TODO: txs is vector<shared_ptr<MoneroTx>> so need to handle
|
||||
cout << "We should be adding " << txs.size() << " txs" << endl;
|
||||
node.add_child("txs", MoneroUtils::toPropertyTree(txs)); // TODO: txs is vector<shared_ptr<MoneroTx>> so need to handle
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace monero {
|
||||
|
||||
/**
|
||||
* Base struct which can be serialized.
|
||||
*
|
||||
* TODO: move this to MoneroUtils?
|
||||
*/
|
||||
struct SerializableStruct {
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "cryptonote_basic/cryptonote_format_utils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
using namespace cryptonote;
|
||||
using namespace MoneroUtils;
|
||||
|
||||
|
||||
+11
-11
@@ -12,7 +12,6 @@
|
||||
namespace MoneroUtils
|
||||
{
|
||||
using namespace std;
|
||||
using namespace boost;
|
||||
using namespace cryptonote;
|
||||
|
||||
void jsonToBinary(const std::string &json, std::string &bin);
|
||||
@@ -63,7 +62,17 @@ namespace MoneroUtils
|
||||
string serialize(const boost::property_tree::ptree& node);
|
||||
|
||||
// // TODO: template implementation here, could move to MoneroUtils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
|
||||
template <class SerializableStruct> boost::property_tree::ptree toPropertyTree(const vector<SerializableStruct> types) {
|
||||
template <class T> boost::property_tree::ptree toPropertyTree(const vector<shared_ptr<T>> types) {
|
||||
cout << "toPropertyTree(types)" << endl;
|
||||
boost::property_tree::ptree typeNodes;
|
||||
for (const auto& type : types) {
|
||||
typeNodes.push_back(std::make_pair("", type->toPropertyTree()));
|
||||
}
|
||||
return typeNodes;
|
||||
}
|
||||
|
||||
// // TODO: template implementation here, could move to MoneroUtils.hpp per https://stackoverflow.com/questions/3040480/c-template-function-compiles-in-header-but-not-implementation
|
||||
template <class T> boost::property_tree::ptree toPropertyTree(const vector<T> types) {
|
||||
cout << "toPropertyTree(types)" << endl;
|
||||
boost::property_tree::ptree typeNodes;
|
||||
for (const auto& type : types) {
|
||||
@@ -72,15 +81,6 @@ namespace MoneroUtils
|
||||
return typeNodes;
|
||||
}
|
||||
|
||||
// template <class T*> boost::property_tree::ptree toPropertyTree(const vector<T*> types) {
|
||||
// cout << "toPropertyTree(types*)" << endl;
|
||||
// boost::property_tree::ptree typeNodes;
|
||||
// for (const auto& type : types) {
|
||||
// typeNodes.push_back(std::make_pair("", toPropertyTree(type)));
|
||||
// }
|
||||
// return typeNodes;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Modified from core_rpc_server.cpp to return a string.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user