copy constructor for CcnxCharbuf
diff --git a/include/ccnx-name.h b/include/ccnx-name.h
index 7c5447b..d652008 100644
--- a/include/ccnx-name.h
+++ b/include/ccnx-name.h
@@ -15,6 +15,7 @@
public:
CcnxCharbuf();
CcnxCharbuf(ccn_charbuf *buf);
+ CcnxCharbuf(const CcnxCharbuf &other);
~CcnxCharbuf();
// expose internal data structure, use with caution!!
@@ -22,6 +23,9 @@
getBuf() { return m_buf; }
static CcnxCharbufPtr Null;
+private:
+ void init(ccn_charbuf *buf);
+
protected:
ccn_charbuf *m_buf;
};
diff --git a/src/ccnx-name.cpp b/src/ccnx-name.cpp
index 748410f..05df5b3 100644
--- a/src/ccnx-name.cpp
+++ b/src/ccnx-name.cpp
@@ -6,6 +6,18 @@
namespace Ccnx{
CcnxCharbufPtr CcnxCharbuf::Null;
+void
+CcnxCharbuf::init(ccn_charbuf *buf)
+{
+ if (buf != NULL)
+ {
+ m_buf = ccn_charbuf_create();
+ ccn_charbuf_reserve(m_buf, buf->length);
+ memcpy(m_buf->buf, buf->buf, buf->length);
+ m_buf->length = buf->length;
+ }
+}
+
CcnxCharbuf::CcnxCharbuf()
: m_buf(NULL)
{
@@ -15,13 +27,13 @@
CcnxCharbuf::CcnxCharbuf(ccn_charbuf *buf)
: m_buf(NULL)
{
- if (buf != NULL)
- {
- m_buf = ccn_charbuf_create();
- ccn_charbuf_reserve(m_buf, buf->length);
- memcpy(m_buf->buf, buf->buf, buf->length);
- m_buf->length = buf->length;
- }
+ init(buf);
+}
+
+CcnxCharbuf::CcnxCharbuf(const CcnxCharbuf &other)
+ : m_buf (NULL)
+{
+ init(other.m_buf);
}
CcnxCharbuf::~CcnxCharbuf()