linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #05034
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2749: add a setter method to GETSET that binds to rvalue refs and moves them (no copy)
------------------------------------------------------------
revno: 2749
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sun 2011-12-25 18:31:16 +0100
message:
add a setter method to GETSET that binds to rvalue refs and moves them (no copy)
modified:
dcpp/AdcCommand.h
dcpp/Download.h
dcpp/GetSet.h
dcpp/QueueManager.cpp
dcpp/UserConnectionListener.h
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'dcpp/AdcCommand.h'
--- dcpp/AdcCommand.h 2011-12-23 21:15:27 +0000
+++ dcpp/AdcCommand.h 2011-12-25 17:31:16 +0000
@@ -19,16 +19,18 @@
#ifndef DCPLUSPLUS_DCPP_ADC_COMMAND_H
#define DCPLUSPLUS_DCPP_ADC_COMMAND_H
+#include <string>
+
+#include "forward.h"
+#include "Exception.h"
#include "typedefs.h"
-#include "Exception.h"
-
namespace dcpp {
+using std::string;
+
STANDARD_EXCEPTION(ParseException);
-class CID;
-
class AdcCommand {
public:
template<uint32_t T>
=== modified file 'dcpp/Download.h'
--- dcpp/Download.h 2011-12-23 21:15:27 +0000
+++ dcpp/Download.h 2011-12-25 17:31:16 +0000
@@ -1,6 +1,8 @@
#ifndef DCPLUSPLUS_DCPP_DOWNLOAD_H_
#define DCPLUSPLUS_DCPP_DOWNLOAD_H_
+#include <string>
+
#include "forward.h"
#include "noexcept.h"
#include "Transfer.h"
@@ -10,6 +12,8 @@
namespace dcpp {
+using std::string;
+
/**
* Comes as an argument in the DownloadManagerListener functions.
* Use it to retrieve information about the ongoing transfer.
=== modified file 'dcpp/GetSet.h'
--- dcpp/GetSet.h 2011-12-23 21:25:19 +0000
+++ dcpp/GetSet.h 2011-12-25 17:31:16 +0000
@@ -19,14 +19,33 @@
#ifndef DCPLUSPLUS_DCPP_GET_SET_H
#define DCPLUSPLUS_DCPP_GET_SET_H
+/* adds a private member variable to a class and provides public member functions to access it:
+
+ - for small types, one getter function that retrieves a copy of the member variable.
+ - for small types, one setter function that assigns a copy of the value passed as parameter to
+ the member variable.
+
+ - for large types, one getter function that retrieves a const reference to the member variable.
+ - for large types, two setter functions:
+ * one setter function that binds to non-const rvalue references and moves the rvalue to the
+ member variable (no copy operation).
+ * one setter function that binds to the rest and assigns a copy of the value passed as
+ parameter to the member variable. */
+
#include <boost/mpl/if.hpp>
#include <type_traits>
-#define REF_OR_COPY(t) boost::mpl::if_c<std::is_class<t>::value, const t&, t>::type
-
-#define GETSET(type, name, name2) \
-private: type name; \
-public: REF_OR_COPY(type) get##name2() const { return name; } \
- void set##name2(REF_OR_COPY(type) name) { this->name = name; }
+#define GETSET(t, name, name2) \
+private: t name; \
+public: boost::mpl::if_c<std::is_class<t>::value, const t&, t>::type get##name2() const { return name; } \
+ \
+ template<typename GetSetT> typename std::enable_if<!std::is_class<GetSetT>::value, void>::type \
+ set##name2(GetSetT name) { this->name = name; } /* small type: simple setter that just copies */ \
+ \
+ template<typename GetSetT> typename std::enable_if<std::is_class<GetSetT>::value, void>::type \
+ set##name2(GetSetT&& name) { this->name = std::forward<GetSetT>(name); } /* large type: move the rvalue ref */ \
+ \
+ template<typename GetSetT> typename std::enable_if<std::is_class<GetSetT>::value, void>::type \
+ set##name2(const GetSetT& name) { this->name = name; } /* large type: copy the parameter */
#endif /* GETSET_H_ */
=== modified file 'dcpp/QueueManager.cpp'
--- dcpp/QueueManager.cpp 2011-12-22 22:14:45 +0000
+++ dcpp/QueueManager.cpp 2011-12-25 17:31:16 +0000
@@ -1087,7 +1087,7 @@
Lock l(cs);
delete aDownload->getFile();
- aDownload->setFile(0);
+ aDownload->setFile(nullptr);
if(aDownload->getType() == Transfer::TYPE_PARTIAL_LIST) {
QueueItem* q = fileQueue.find(aDownload->getPath());
=== modified file 'dcpp/UserConnectionListener.h'
--- dcpp/UserConnectionListener.h 2011-03-29 20:40:28 +0000
+++ dcpp/UserConnectionListener.h 2011-12-25 17:31:16 +0000
@@ -20,8 +20,8 @@
#define USERCONNECTIONLISTENER_H_
#include "forward.h"
-
#include "AdcCommand.h"
+#include "noexcept.h"
namespace dcpp {