copy functions take and return shared_ptrs

This commit is contained in:
woodser
2019-07-29 15:19:51 -04:00
parent 835e04e785
commit ede2ba0c96
4 changed files with 78 additions and 144 deletions
+4 -20
View File
@@ -175,16 +175,8 @@ namespace monero {
// ------------------------------- MONERO TX --------------------------------
MoneroTx::MoneroTx() {
}
MoneroTx::MoneroTx(const MoneroTx& tx) {
throw runtime_error("MoneroTx deep copy constructor not implemented");
}
shared_ptr<MoneroTx> MoneroTx::copy() const {
return make_shared<MoneroTx>(*this);
shared_ptr<MoneroTx> MoneroTx::copy(const shared_ptr<MoneroTx>& self) const {
throw runtime_error("MoneroTx::copy() not implemented");
}
boost::property_tree::ptree MoneroTx::toPropertyTree() const {
@@ -378,16 +370,8 @@ namespace monero {
// ------------------------------ MONERO OUTPUT -----------------------------
MoneroOutput::MoneroOutput() {
}
MoneroOutput::MoneroOutput(const MoneroOutput& output) {
throw runtime_error("MoneroOutput deep copy not implemented");
}
shared_ptr<MoneroOutput> MoneroOutput::copy() const {
return make_shared<MoneroOutput>(*this);
shared_ptr<MoneroOutput> MoneroOutput::copy(const shared_ptr<MoneroOutput>& self) const {
throw runtime_error("MoneroOutput::copy() not implemented");
}
boost::property_tree::ptree MoneroOutput::toPropertyTree() const {
+2 -6
View File
@@ -192,9 +192,7 @@ namespace monero {
boost::optional<string> maxUsedBlockId;
vector<string> signatures;
MoneroTx(); // default constructor
MoneroTx(const MoneroTx& tx); // deep copy constructor
shared_ptr<MoneroTx> copy() const;
shared_ptr<MoneroTx> copy(const shared_ptr<MoneroTx>& self) const;
boost::property_tree::ptree toPropertyTree() const;
virtual void merge(const shared_ptr<MoneroTx>& self, const shared_ptr<MoneroTx>& other);
boost::optional<uint64_t> getHeight() const;
@@ -222,9 +220,7 @@ namespace monero {
vector<uint32_t> ringOutputIndices;
boost::optional<string> stealthPublicKey;
MoneroOutput();
MoneroOutput(const MoneroOutput& output); // deep copy constructor
shared_ptr<MoneroOutput> copy() const;
shared_ptr<MoneroOutput> copy(const shared_ptr<MoneroOutput>& self) const;
boost::property_tree::ptree toPropertyTree() const;
virtual void merge(const shared_ptr<MoneroOutput>& self, const shared_ptr<MoneroOutput>& other);
};
+51 -94
View File
@@ -105,13 +105,13 @@ namespace monero {
// --------------------------- MONERO TX WALLET -----------------------------
MoneroTxWallet::MoneroTxWallet() {
shared_ptr<MoneroTxWallet> MoneroTxWallet::copy(const shared_ptr<MoneroTx>& self) const {
throw runtime_error("MoneroOutputWallet::copy(tx) not implemented");
};
}
MoneroTxWallet::MoneroTxWallet(const MoneroTxWallet& tx) {
throw runtime_error("MoneroTxWallet deepy copy constructor not implemented");
}
shared_ptr<MoneroTxWallet> MoneroTxWallet::copy(const shared_ptr<MoneroTxWallet>& self) const {
throw runtime_error("MoneroTxWallet::copy(txWallet) not implemented");
};
boost::property_tree::ptree MoneroTxWallet::toPropertyTree() const {
boost::property_tree::ptree node = MoneroTx::toPropertyTree();
@@ -161,36 +161,17 @@ namespace monero {
// -------------------------- MONERO TX REQUEST -----------------------------
MoneroTxRequest::MoneroTxRequest() {
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTx>& self) const {
throw runtime_error("MoneroOutputWallet::copy(tx) not implemented");
};
}
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTxWallet>& self) const {
throw runtime_error("MoneroTxRequest::copy(txWallet) not implemented");
};
MoneroTxRequest::MoneroTxRequest(const MoneroTxRequest& req) {
// super(req);
// isOutgoing = req.isOutgoing;
// isIncoming = req.isIncoming;
// if (req.txIds != null) txIds = new ArrayList<String>(req.txIds);
// hasPaymentId = req.hasPaymentId;
// height = req.height;
// minHeight = req.minHeight;
// maxHeight = req.maxHeight;
// includeOutputs = req.includeOutputs;
// if (req.transferRequest != boost::none) {
// transferRequest = shared_ptr<MoneroTransferRequest>(req.transferRequest);
//
// transferRequest = new MoneroTransferRequest(req.transferRequest);
// if (req.transferRequest.getTxRequest() == req) transferRequest.setTxRequest(this);
// }
// if (req.outputRequest != boost::none) {
// outputRequest = new MoneroOutputRequest(req.outputRequest);
// if (req.outputRequest.getTxRequest() == req) outputRequest.setTxRequest(this) ;
// }
throw runtime_error("MoneroTxRequest deep copy constructor not implemented");
}
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy() const {
return make_shared<MoneroTxRequest>(*this);
}
shared_ptr<MoneroTxRequest> MoneroTxRequest::copy(const shared_ptr<MoneroTxRequest>& self) const {
throw runtime_error("MoneroTxRequest::copy(txRequest) not implemented");
};
boost::property_tree::ptree MoneroTxRequest::toPropertyTree() const {
boost::property_tree::ptree node = MoneroTxWallet::toPropertyTree();
@@ -269,17 +250,9 @@ namespace monero {
// ---------------------------- MONERO TRANSFER -----------------------------
MoneroTransfer::MoneroTransfer() {
}
MoneroTransfer::MoneroTransfer(const MoneroTransfer& transfer) {
throw runtime_error("MoneroTransfer deep copy constructor not implemented");
}
shared_ptr<MoneroTransfer> MoneroTransfer::copy() const {
throw runtime_error("Subclass must implement");
}
// shared_ptr<MoneroTransfer> MoneroTransfer::copy(const shared_ptr<MoneroTransfer>& self) const {
// throw runtime_error("MoneroTransfer::copy() not implemented");
// };
boost::property_tree::ptree MoneroTransfer::toPropertyTree() const {
boost::property_tree::ptree node;
@@ -315,17 +288,13 @@ namespace monero {
// ----------------------- MONERO INCOMING TRANSFER -------------------------
MoneroIncomingTransfer::MoneroIncomingTransfer() {
shared_ptr<MoneroIncomingTransfer> MoneroIncomingTransfer::copy(const shared_ptr<MoneroTransfer>& self) const {
throw runtime_error("MoneroIncomingTransfer::copy(transfer) not implemented");
};
}
MoneroIncomingTransfer::MoneroIncomingTransfer(const MoneroIncomingTransfer& transfer) {
throw runtime_error("MoneroIncomingTransfer deepy copy not implemented");
}
shared_ptr<MoneroIncomingTransfer> MoneroIncomingTransfer::copy() const {
return make_shared<MoneroIncomingTransfer>(*this);
}
shared_ptr<MoneroIncomingTransfer> MoneroIncomingTransfer::copy(const shared_ptr<MoneroIncomingTransfer>& self) const {
throw runtime_error("MoneroIncomingTransfer::copy(inTransfer) not implemented");
};
boost::optional<bool> MoneroIncomingTransfer::getIsIncoming() const { return true; }
@@ -349,17 +318,13 @@ namespace monero {
// ----------------------- MONERO OUTGOING TRANSFER -------------------------
MoneroOutgoingTransfer::MoneroOutgoingTransfer() {
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy(const shared_ptr<MoneroTransfer>& self) const {
throw runtime_error("MoneroOutgoingTransfer::copy(transfer) not implemented");
};
}
MoneroOutgoingTransfer::MoneroOutgoingTransfer(const MoneroOutgoingTransfer& transfer) {
throw runtime_error("MoneroOutgoingTransfer deep copy not implemented");
}
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy() const {
return make_shared<MoneroOutgoingTransfer>(*this);
}
shared_ptr<MoneroOutgoingTransfer> MoneroOutgoingTransfer::copy(const shared_ptr<MoneroOutgoingTransfer>& self) const {
throw runtime_error("MoneroOutgoingTransfer::copy(outTransfer) not implemented");
};
boost::optional<bool> MoneroOutgoingTransfer::getIsIncoming() const { return false; }
@@ -385,17 +350,13 @@ namespace monero {
// ----------------------- MONERO TRANSFER REQUEST --------------------------
MoneroTransferRequest::MoneroTransferRequest() {
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy(const shared_ptr<MoneroTransfer>& self) const {
throw runtime_error("MoneroTransferRequest::copy(transfer) not implemented");
};
}
MoneroTransferRequest::MoneroTransferRequest(const MoneroTransferRequest& request) {
throw runtime_error("MoneroTransferRequet deep copy not implemented");
}
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy() const {
return make_shared<MoneroTransferRequest>(*this);
}
shared_ptr<MoneroTransferRequest> MoneroTransferRequest::copy(const shared_ptr<MoneroTransferRequest>& self) const {
throw runtime_error("MoneroTransferRequest::copy(request) not implemented");
};
boost::optional<bool> MoneroTransferRequest::getIsIncoming() const { return isIncoming; }
@@ -485,17 +446,13 @@ namespace monero {
// ------------------------- MONERO OUTPUT WALLET ---------------------------
MoneroOutputWallet::MoneroOutputWallet() {
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy(const shared_ptr<MoneroOutput>& self) const {
throw runtime_error("MoneroOutputWallet::copy(output) not implemented");
};
}
MoneroOutputWallet::MoneroOutputWallet(const MoneroOutputWallet& output) {
throw runtime_error("MoneroOutputWallet deep copy constructor not implemented");
}
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy() const {
return make_shared<MoneroOutputWallet>(*this);
}
shared_ptr<MoneroOutputWallet> MoneroOutputWallet::copy(const shared_ptr<MoneroOutputWallet>& self) const {
throw runtime_error("MoneroOutputWallet::copy(outputWallet) not implemented");
};
boost::property_tree::ptree MoneroOutputWallet::toPropertyTree() const {
boost::property_tree::ptree node = MoneroOutput::toPropertyTree();
@@ -517,17 +474,17 @@ namespace monero {
// ------------------------ MONERO OUTPUT REQUEST ---------------------------
MoneroOutputRequest::MoneroOutputRequest() {
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutput>& self) const {
throw runtime_error("MoneroOutputRequest::copy(output) not implemented");
};
}
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutputWallet>& self) const {
throw runtime_error("MoneroOutputRequest::copy(outputWallet) not implemented");
};
MoneroOutputRequest::MoneroOutputRequest(const MoneroOutputRequest& request) {
throw runtime_error("MonerOutputRequest deep copy not implemented");
}
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy() const {
return make_shared<MoneroOutputRequest>(*this);
}
shared_ptr<MoneroOutputRequest> MoneroOutputRequest::copy(const shared_ptr<MoneroOutputRequest>& self) const {
throw runtime_error("MoneroOutputRequest::copy(outputRequest) not implemented");
};
boost::property_tree::ptree MoneroOutputRequest::toPropertyTree() const {
boost::property_tree::ptree node = MoneroOutputWallet::toPropertyTree();
+21 -24
View File
@@ -147,10 +147,10 @@ namespace monero {
boost::optional<uint32_t> accountIndex;
boost::optional<uint32_t> numSuggestedConfirmations;
MoneroTransfer();
MoneroTransfer(const MoneroTransfer& transfer); // deep copy constructor
virtual boost::optional<bool> getIsIncoming() const = 0; // derived class must implement
shared_ptr<MoneroTransfer> copy() const; // not virtual in order for subclasses to return shared_ptr of derived types
shared_ptr<MoneroTransfer> copy(const shared_ptr<MoneroTransfer>& self) const { // not virtual in order for subclasses to return shared_ptr of derived types
throw runtime_error("Subclasses must implement");
};
boost::optional<bool> getIsOutgoing() const {
if (getIsIncoming() == boost::none) return boost::none;
return !(*getIsIncoming());
@@ -166,9 +166,8 @@ namespace monero {
boost::optional<uint32_t> subaddressIndex;
boost::optional<string> address;
MoneroIncomingTransfer();
MoneroIncomingTransfer(const MoneroIncomingTransfer& transfer); // deep copy constructor
shared_ptr<MoneroIncomingTransfer> copy() const;
shared_ptr<MoneroIncomingTransfer> copy(const shared_ptr<MoneroTransfer>& self) const;
shared_ptr<MoneroIncomingTransfer> copy(const shared_ptr<MoneroIncomingTransfer>& self) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other);
@@ -183,9 +182,8 @@ namespace monero {
vector<string> addresses;
vector<shared_ptr<MoneroDestination>> destinations;
MoneroOutgoingTransfer();
MoneroOutgoingTransfer(const MoneroOutgoingTransfer& transfer);
shared_ptr<MoneroOutgoingTransfer> copy() const;
shared_ptr<MoneroOutgoingTransfer> copy(const shared_ptr<MoneroTransfer>& self) const;
shared_ptr<MoneroOutgoingTransfer> copy(const shared_ptr<MoneroOutgoingTransfer>& self) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroTransfer>& self, const shared_ptr<MoneroTransfer>& other);
@@ -207,9 +205,8 @@ namespace monero {
boost::optional<bool> hasDestinations;
boost::optional<shared_ptr<MoneroTxRequest>> txRequest;
MoneroTransferRequest();
MoneroTransferRequest(const MoneroTransferRequest& request);
shared_ptr<MoneroTransferRequest> copy() const;
shared_ptr<MoneroTransferRequest> copy(const shared_ptr<MoneroTransfer>& self) const;
shared_ptr<MoneroTransferRequest> copy(const shared_ptr<MoneroTransferRequest>& self) const;
boost::optional<bool> getIsIncoming() const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroTransfer* transfer) const;
@@ -225,9 +222,8 @@ namespace monero {
boost::optional<bool> isUnlocked;
boost::optional<bool> isFrozen;
MoneroOutputWallet();
MoneroOutputWallet(const MoneroOutputWallet& output); // deep copy constructor
shared_ptr<MoneroOutputWallet> copy() const;
shared_ptr<MoneroOutputWallet> copy(const shared_ptr<MoneroOutput>& self) const;
shared_ptr<MoneroOutputWallet> copy(const shared_ptr<MoneroOutputWallet>& self) const;
boost::property_tree::ptree toPropertyTree() const;
void merge(const shared_ptr<MoneroOutput>& self, const shared_ptr<MoneroOutput>& other);
void merge(const shared_ptr<MoneroOutputWallet>& self, const shared_ptr<MoneroOutputWallet>& other);
@@ -243,9 +239,10 @@ namespace monero {
vector<uint32_t> subaddressIndices;
boost::optional<shared_ptr<MoneroTxRequest>> txRequest;
MoneroOutputRequest();
MoneroOutputRequest(const MoneroOutputRequest& request); // deep copy constructor
shared_ptr<MoneroOutputRequest> copy() const;
// TODO: necessary to override all super classes?
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutput>& self) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutputWallet>& self) const;
shared_ptr<MoneroOutputRequest> copy(const shared_ptr<MoneroOutputRequest>& self) const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroOutputWallet* output) const;
};
@@ -258,9 +255,8 @@ namespace monero {
boost::optional<shared_ptr<MoneroOutgoingTransfer>> outgoingTransfer;
boost::optional<string> note;
MoneroTxWallet();
MoneroTxWallet(const MoneroTxWallet& tx);
shared_ptr<MoneroTxWallet> copy() const;
shared_ptr<MoneroTxWallet> copy(const shared_ptr<MoneroTx>& self) const;
shared_ptr<MoneroTxWallet> copy(const shared_ptr<MoneroTxWallet>& self) const;
bool getIsIncoming() const;
bool getIsOutgoing() const;
boost::property_tree::ptree toPropertyTree() const;
@@ -286,9 +282,10 @@ namespace monero {
boost::optional<shared_ptr<MoneroTransferRequest>> transferRequest;
boost::optional<shared_ptr<MoneroOutputRequest>> outputRequest;
MoneroTxRequest();
MoneroTxRequest(const MoneroTxRequest& req);
shared_ptr<MoneroTxRequest> copy() const;
// TODO: necessary to override all super classes?
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTx>& self) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTxWallet>& self) const;
shared_ptr<MoneroTxRequest> copy(const shared_ptr<MoneroTxRequest>& self) const;
boost::property_tree::ptree toPropertyTree() const;
bool meetsCriteria(MoneroTxWallet* tx) const;
};