Data: add a copy constructor and assignment operator to clone the signature pointer.
diff --git a/include/ndn-cpp/data.hpp b/include/ndn-cpp/data.hpp
index 0b40c74..d9b8fc1 100644
--- a/include/ndn-cpp/data.hpp
+++ b/include/ndn-cpp/data.hpp
@@ -137,9 +137,22 @@
Data(const Name& name);
/**
+ * The copy constructor: Create a deep copy of the given data object, including a clone of the signature object.
+ * @param data The data object to copy.
+ */
+ Data(const Data& data);
+
+ /**
* The virtual destructor.
*/
- virtual ~Data() {}
+ virtual ~Data();
+
+ /**
+ * The assignment operator: Copy fields and make a clone of the signature.
+ * @param data The other object to copy from.
+ * @return A reference to this object.
+ */
+ Data& operator=(const Data& data);
/**
* Encode this Data for a particular wire format. Also, set the wireEncoding field to the encoded result.
diff --git a/ndn-cpp/data.cpp b/ndn-cpp/data.cpp
index 6b2f570..62cdf3b 100644
--- a/ndn-cpp/data.cpp
+++ b/ndn-cpp/data.cpp
@@ -11,6 +11,7 @@
#include "c/data.h"
using namespace std;
+using namespace ndn::ptr_lib;
namespace ndn {
@@ -46,6 +47,32 @@
{
}
+Data::Data(const Data& data)
+: name_(data.name_), metaInfo_(data.metaInfo_), content_(data.content_), wireEncoding_(data.wireEncoding_)
+{
+ if (data.signature_)
+ signature_ = data.signature_->clone();
+}
+
+Data::~Data()
+{
+}
+
+Data& Data::operator=(const Data& data)
+{
+ if (data.signature_)
+ signature_ = data.signature_->clone();
+ else
+ signature_ = shared_ptr<Signature>();
+
+ name_ = data.name_;
+ metaInfo_ = data.metaInfo_;
+ content_ = data.content_;
+ wireEncoding_ = data.wireEncoding_;
+
+ return *this;
+}
+
void
Data::get(struct ndn_Data& dataStruct) const
{
diff --git a/tests/test-encode-decode-data.cpp b/tests/test-encode-decode-data.cpp
index 078e31c..a123cd8 100644
--- a/tests/test-encode-decode-data.cpp
+++ b/tests/test-encode-decode-data.cpp
@@ -18,8 +18,8 @@
using namespace std;
using namespace ndn;
-using namespace ptr_lib;
-using namespace func_lib;
+using namespace ndn::ptr_lib;
+using namespace ndn::func_lib;
#if NDN_CPP_HAVE_STD_FUNCTION
// In the std library, the placeholders are in a different namespace than boost.
using namespace func_lib::placeholders;
diff --git a/tests/test-get-async.cpp b/tests/test-get-async.cpp
index 9cdf28a..d59d611 100644
--- a/tests/test-get-async.cpp
+++ b/tests/test-get-async.cpp
@@ -11,8 +11,8 @@
using namespace std;
using namespace ndn;
-using namespace ptr_lib;
-using namespace func_lib;
+using namespace ndn::ptr_lib;
+using namespace ndn::func_lib;
#if NDN_CPP_HAVE_STD_FUNCTION
// In the std library, the placeholders are in a different namespace than boost.
using namespace func_lib::placeholders;