From ede2ba0c96d588a059c651bce79ce34627a68b5c Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 29 Jul 2019 15:19:51 -0400 Subject: [PATCH] copy functions take and return shared_ptrs --- src/daemon/MoneroDaemonModel.cpp | 24 +---- src/daemon/MoneroDaemonModel.h | 8 +- src/wallet/MoneroWalletModel.cpp | 145 +++++++++++-------------------- src/wallet/MoneroWalletModel.h | 45 +++++----- 4 files changed, 78 insertions(+), 144 deletions(-) diff --git a/src/daemon/MoneroDaemonModel.cpp b/src/daemon/MoneroDaemonModel.cpp index b44a91c..c66b020 100644 --- a/src/daemon/MoneroDaemonModel.cpp +++ b/src/daemon/MoneroDaemonModel.cpp @@ -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::copy() const { - return make_shared(*this); + shared_ptr MoneroTx::copy(const shared_ptr& 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::copy() const { - return make_shared(*this); + shared_ptr MoneroOutput::copy(const shared_ptr& self) const { + throw runtime_error("MoneroOutput::copy() not implemented"); } boost::property_tree::ptree MoneroOutput::toPropertyTree() const { diff --git a/src/daemon/MoneroDaemonModel.h b/src/daemon/MoneroDaemonModel.h index bf9a794..3c4d498 100644 --- a/src/daemon/MoneroDaemonModel.h +++ b/src/daemon/MoneroDaemonModel.h @@ -192,9 +192,7 @@ namespace monero { boost::optional maxUsedBlockId; vector signatures; - MoneroTx(); // default constructor - MoneroTx(const MoneroTx& tx); // deep copy constructor - shared_ptr copy() const; + shared_ptr copy(const shared_ptr& self) const; boost::property_tree::ptree toPropertyTree() const; virtual void merge(const shared_ptr& self, const shared_ptr& other); boost::optional getHeight() const; @@ -222,9 +220,7 @@ namespace monero { vector ringOutputIndices; boost::optional stealthPublicKey; - MoneroOutput(); - MoneroOutput(const MoneroOutput& output); // deep copy constructor - shared_ptr copy() const; + shared_ptr copy(const shared_ptr& self) const; boost::property_tree::ptree toPropertyTree() const; virtual void merge(const shared_ptr& self, const shared_ptr& other); }; diff --git a/src/wallet/MoneroWalletModel.cpp b/src/wallet/MoneroWalletModel.cpp index e60ecd5..6694dc6 100644 --- a/src/wallet/MoneroWalletModel.cpp +++ b/src/wallet/MoneroWalletModel.cpp @@ -105,13 +105,13 @@ namespace monero { // --------------------------- MONERO TX WALLET ----------------------------- - MoneroTxWallet::MoneroTxWallet() { + shared_ptr MoneroTxWallet::copy(const shared_ptr& 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::copy(const shared_ptr& 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::copy(const shared_ptr& self) const { + throw runtime_error("MoneroOutputWallet::copy(tx) not implemented"); + }; - } + shared_ptr MoneroTxRequest::copy(const shared_ptr& 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(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(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::copy() const { - return make_shared(*this); - } + shared_ptr MoneroTxRequest::copy(const shared_ptr& 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::copy() const { - throw runtime_error("Subclass must implement"); - } +// shared_ptr MoneroTransfer::copy(const shared_ptr& 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::copy(const shared_ptr& 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::copy() const { - return make_shared(*this); - } + shared_ptr MoneroIncomingTransfer::copy(const shared_ptr& self) const { + throw runtime_error("MoneroIncomingTransfer::copy(inTransfer) not implemented"); + }; boost::optional MoneroIncomingTransfer::getIsIncoming() const { return true; } @@ -349,17 +318,13 @@ namespace monero { // ----------------------- MONERO OUTGOING TRANSFER ------------------------- - MoneroOutgoingTransfer::MoneroOutgoingTransfer() { + shared_ptr MoneroOutgoingTransfer::copy(const shared_ptr& 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::copy() const { - return make_shared(*this); - } + shared_ptr MoneroOutgoingTransfer::copy(const shared_ptr& self) const { + throw runtime_error("MoneroOutgoingTransfer::copy(outTransfer) not implemented"); + }; boost::optional MoneroOutgoingTransfer::getIsIncoming() const { return false; } @@ -385,17 +350,13 @@ namespace monero { // ----------------------- MONERO TRANSFER REQUEST -------------------------- - MoneroTransferRequest::MoneroTransferRequest() { + shared_ptr MoneroTransferRequest::copy(const shared_ptr& 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::copy() const { - return make_shared(*this); - } + shared_ptr MoneroTransferRequest::copy(const shared_ptr& self) const { + throw runtime_error("MoneroTransferRequest::copy(request) not implemented"); + }; boost::optional MoneroTransferRequest::getIsIncoming() const { return isIncoming; } @@ -485,17 +446,13 @@ namespace monero { // ------------------------- MONERO OUTPUT WALLET --------------------------- - MoneroOutputWallet::MoneroOutputWallet() { + shared_ptr MoneroOutputWallet::copy(const shared_ptr& 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::copy() const { - return make_shared(*this); - } + shared_ptr MoneroOutputWallet::copy(const shared_ptr& 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::copy(const shared_ptr& self) const { + throw runtime_error("MoneroOutputRequest::copy(output) not implemented"); + }; - } + shared_ptr MoneroOutputRequest::copy(const shared_ptr& 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::copy() const { - return make_shared(*this); - } + shared_ptr MoneroOutputRequest::copy(const shared_ptr& self) const { + throw runtime_error("MoneroOutputRequest::copy(outputRequest) not implemented"); + }; boost::property_tree::ptree MoneroOutputRequest::toPropertyTree() const { boost::property_tree::ptree node = MoneroOutputWallet::toPropertyTree(); diff --git a/src/wallet/MoneroWalletModel.h b/src/wallet/MoneroWalletModel.h index 2f15d35..a8fea09 100644 --- a/src/wallet/MoneroWalletModel.h +++ b/src/wallet/MoneroWalletModel.h @@ -147,10 +147,10 @@ namespace monero { boost::optional accountIndex; boost::optional numSuggestedConfirmations; - MoneroTransfer(); - MoneroTransfer(const MoneroTransfer& transfer); // deep copy constructor virtual boost::optional getIsIncoming() const = 0; // derived class must implement - shared_ptr copy() const; // not virtual in order for subclasses to return shared_ptr of derived types + shared_ptr copy(const shared_ptr& self) const { // not virtual in order for subclasses to return shared_ptr of derived types + throw runtime_error("Subclasses must implement"); + }; boost::optional getIsOutgoing() const { if (getIsIncoming() == boost::none) return boost::none; return !(*getIsIncoming()); @@ -166,9 +166,8 @@ namespace monero { boost::optional subaddressIndex; boost::optional address; - MoneroIncomingTransfer(); - MoneroIncomingTransfer(const MoneroIncomingTransfer& transfer); // deep copy constructor - shared_ptr copy() const; + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; boost::optional getIsIncoming() const; boost::property_tree::ptree toPropertyTree() const; void merge(const shared_ptr& self, const shared_ptr& other); @@ -183,9 +182,8 @@ namespace monero { vector addresses; vector> destinations; - MoneroOutgoingTransfer(); - MoneroOutgoingTransfer(const MoneroOutgoingTransfer& transfer); - shared_ptr copy() const; + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; boost::optional getIsIncoming() const; boost::property_tree::ptree toPropertyTree() const; void merge(const shared_ptr& self, const shared_ptr& other); @@ -207,9 +205,8 @@ namespace monero { boost::optional hasDestinations; boost::optional> txRequest; - MoneroTransferRequest(); - MoneroTransferRequest(const MoneroTransferRequest& request); - shared_ptr copy() const; + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; boost::optional getIsIncoming() const; boost::property_tree::ptree toPropertyTree() const; bool meetsCriteria(MoneroTransfer* transfer) const; @@ -225,9 +222,8 @@ namespace monero { boost::optional isUnlocked; boost::optional isFrozen; - MoneroOutputWallet(); - MoneroOutputWallet(const MoneroOutputWallet& output); // deep copy constructor - shared_ptr copy() const; + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; boost::property_tree::ptree toPropertyTree() const; void merge(const shared_ptr& self, const shared_ptr& other); void merge(const shared_ptr& self, const shared_ptr& other); @@ -243,9 +239,10 @@ namespace monero { vector subaddressIndices; boost::optional> txRequest; - MoneroOutputRequest(); - MoneroOutputRequest(const MoneroOutputRequest& request); // deep copy constructor - shared_ptr copy() const; + // TODO: necessary to override all super classes? + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; boost::property_tree::ptree toPropertyTree() const; bool meetsCriteria(MoneroOutputWallet* output) const; }; @@ -258,9 +255,8 @@ namespace monero { boost::optional> outgoingTransfer; boost::optional note; - MoneroTxWallet(); - MoneroTxWallet(const MoneroTxWallet& tx); - shared_ptr copy() const; + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; bool getIsIncoming() const; bool getIsOutgoing() const; boost::property_tree::ptree toPropertyTree() const; @@ -286,9 +282,10 @@ namespace monero { boost::optional> transferRequest; boost::optional> outputRequest; - MoneroTxRequest(); - MoneroTxRequest(const MoneroTxRequest& req); - shared_ptr copy() const; + // TODO: necessary to override all super classes? + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; + shared_ptr copy(const shared_ptr& self) const; boost::property_tree::ptree toPropertyTree() const; bool meetsCriteria(MoneroTxWallet* tx) const; };