fix bugs in constructors; C++ does not support Java like recursive construction
diff --git a/include/ccnx-pco.h b/include/ccnx-pco.h
index 72a7289..7956dad 100644
--- a/include/ccnx-pco.h
+++ b/include/ccnx-pco.h
@@ -25,6 +25,10 @@
Name
name() const;
+private:
+ void
+ init(const unsigned char *data, size_t len);
+
protected:
ccn_parsed_ContentObject m_pco;
ccn_indexbuf *m_comps;
diff --git a/src/ccnx-closure.cpp b/src/ccnx-closure.cpp
index 5b30244..a4c378c 100644
--- a/src/ccnx-closure.cpp
+++ b/src/ccnx-closure.cpp
@@ -3,15 +3,17 @@
namespace Ccnx {
Closure::Closure(int retry, const DataCallback &dataCallback, const TimeoutCallback &timeoutCallback)
- : m_retry(retry), m_timeoutCallback(NULL)
+ : m_retry(retry), m_timeoutCallback(NULL), m_dataCallback(NULL)
{
m_timeoutCallback = new TimeoutCallback (timeoutCallback);
m_dataCallback = new DataCallback (dataCallback);
}
Closure::Closure(const Closure &other)
+ :m_retry(other.m_retry), m_timeoutCallback(NULL), m_dataCallback(NULL)
{
- Closure(other.m_retry, *(other.m_dataCallback), *(other.m_timeoutCallback));
+ m_timeoutCallback = new TimeoutCallback(*(other.m_timeoutCallback));
+ m_dataCallback = new DataCallback(*(other.m_dataCallback));
}
Closure::~Closure ()
diff --git a/src/ccnx-pco.cpp b/src/ccnx-pco.cpp
index dce3bcb..af10c7a 100644
--- a/src/ccnx-pco.cpp
+++ b/src/ccnx-pco.cpp
@@ -2,8 +2,8 @@
namespace Ccnx {
-ParsedContentObject::ParsedContentObject(const unsigned char *data, size_t len)
- : m_comps(NULL)
+void
+ParsedContentObject::init(const unsigned char *data, size_t len)
{
m_comps = ccn_indexbuf_create();
int res = ccn_parse_ContentObject(data, len, &m_pco, m_comps);
@@ -14,14 +14,22 @@
readRaw(m_bytes, data, len);
}
-ParsedContentObject::ParsedContentObject(const Bytes &bytes)
+ParsedContentObject::ParsedContentObject(const unsigned char *data, size_t len)
+ : m_comps(NULL)
{
- ParsedContentObject(head(bytes), bytes.size());
+ init(data, len);
+}
+
+ParsedContentObject::ParsedContentObject(const Bytes &bytes)
+ : m_comps(NULL)
+{
+ init(head(bytes), bytes.size());
}
ParsedContentObject::ParsedContentObject(const ParsedContentObject &other)
+ : m_comps(NULL)
{
- ParsedContentObject(other.m_bytes);
+ init(head(other.m_bytes), other.m_bytes.size());
}
ParsedContentObject::~ParsedContentObject()