In common.h, remove Ptr. In interest.h, etc. typedef InterestPtr and ConstInterestPtr, etc.
We will centralize and allow these to be typedef as boost::shared_ptr
or std::shared_ptr.
diff --git a/ndn-cpp/common.h b/ndn-cpp/common.h
index e45f067..30b705a 100644
--- a/ndn-cpp/common.h
+++ b/ndn-cpp/common.h
@@ -19,27 +19,6 @@
namespace ndn
{
-template<class T>
-struct Ptr : public boost::shared_ptr<T>
-{
- Ptr () { }
- Ptr (boost::shared_ptr<T> ptr) : boost::shared_ptr<T>(ptr) { }
- Ptr (T *ptr) : boost::shared_ptr<T>(ptr) { }
-
- template<class Y>
- Ptr & operator = (boost::shared_ptr<Y> ptr)
- {
- boost::static_pointer_cast<T> (ptr).swap (*this);
- // *this = boost::static_pointer_cast<T> (ptr);
- return *this;
- }
-
- operator Ptr<const T> () const { return *this; }
-
- static Ptr
- Create () { return boost::make_shared<T> (); }
-};
-
typedef boost::posix_time::ptime Time;
typedef boost::posix_time::time_duration TimeInterval;
@@ -97,6 +76,7 @@
typedef std::vector<std::string>Comps;
typedef boost::shared_ptr<Bytes> BytesPtr;
+typedef boost::shared_ptr<const Bytes> ConstBytesPtr;
inline
const unsigned char *
diff --git a/ndn-cpp/data.h b/ndn-cpp/data.h
index 212dfbd..3264e4d 100644
--- a/ndn-cpp/data.h
+++ b/ndn-cpp/data.h
@@ -61,13 +61,13 @@
/**
* @brief Get const smart pointer to signature object
*/
- inline Ptr<const Signature>
+ inline ConstSignaturePtr
getSignature () const;
/**
* @brief Get smart pointer to signature object
*/
- inline Ptr<Signature>
+ inline SignaturePtr
getSignature ();
/**
@@ -75,7 +75,7 @@
* @param signature smart pointer to a signature object
*/
inline void
- setSignature (Ptr<Signature> sigature);
+ setSignature (SignaturePtr sigature);
/**
* @brief Get const reference to content object (content info + actual content)
@@ -126,10 +126,10 @@
private:
Name m_name;
- Ptr<Signature> m_signature; // signature with its parameters "binds" name and content
+ SignaturePtr m_signature; // signature with its parameters "binds" name and content
Content m_content;
- Ptr<SignedBlob> m_wire;
+ SignedBlobPtr m_wire;
};
inline Data &
@@ -151,20 +151,20 @@
return m_name;
}
-inline Ptr<const Signature>
+inline ConstSignaturePtr
Data::getSignature () const
{
return m_signature;
}
-inline Ptr<Signature>
+inline SignaturePtr
Data::getSignature ()
{
return m_signature;
}
inline void
-Data::setSignature (Ptr<Signature> signature)
+Data::setSignature (SignaturePtr signature)
{
m_signature = signature;
}
diff --git a/ndn-cpp/fields/blob.h b/ndn-cpp/fields/blob.h
index 85fd71b..ce0d667 100644
--- a/ndn-cpp/fields/blob.h
+++ b/ndn-cpp/fields/blob.h
@@ -15,9 +15,14 @@
#include <vector>
#include <cstddef>
+#include <boost/shared_ptr.hpp>
namespace ndn {
+class Blob;
+typedef boost::shared_ptr<Blob> BlobPtr;
+typedef boost::shared_ptr<const Blob> ConstBlobPtr;
+
/**
* @brief Class representing a general-use binary blob
*/
diff --git a/ndn-cpp/fields/name.h b/ndn-cpp/fields/name.h
index 18e2412..a356f8f 100644
--- a/ndn-cpp/fields/name.h
+++ b/ndn-cpp/fields/name.h
@@ -18,6 +18,10 @@
namespace ndn {
+class Name;
+typedef boost::shared_ptr<Name> NamePtr;
+typedef boost::shared_ptr<const Name> ConstNamePtr;
+
/**
* @brief Class for NDN Name
*/
@@ -393,8 +397,6 @@
std::vector<name::Component> m_comps;
};
-typedef boost::shared_ptr<Name> NamePtr;
-
inline std::ostream &
operator << (std::ostream &os, const Name &name)
{
diff --git a/ndn-cpp/fields/signature.h b/ndn-cpp/fields/signature.h
index a9fb39a..1368663 100644
--- a/ndn-cpp/fields/signature.h
+++ b/ndn-cpp/fields/signature.h
@@ -12,11 +12,16 @@
#define NDN_SIGNATURE_H
#include <iostream>
+#include <boost/shared_ptr.hpp>
namespace ndn {
namespace wire { class Base; }
+class Signature;
+typedef boost::shared_ptr<Signature> SignaturePtr;
+typedef boost::shared_ptr<const Signature> ConstSignaturePtr;
+
/**
* @brief Pure virtual class providing an interface to work with signatures for NDN data packets
*/
diff --git a/ndn-cpp/fields/signed-blob.h b/ndn-cpp/fields/signed-blob.h
index 2686977..fd5bf90 100644
--- a/ndn-cpp/fields/signed-blob.h
+++ b/ndn-cpp/fields/signed-blob.h
@@ -17,6 +17,10 @@
namespace ndn {
+class SignedBlob;
+typedef boost::shared_ptr<SignedBlob> SignedBlobPtr;
+typedef boost::shared_ptr<const SignedBlob> ConstSignedBlobPtr;
+
/**
* @brief Class representing a blob, which has a signed portion (e.g., bytes of DATA packet)
*/
@@ -92,7 +96,6 @@
return m_signedEnd - m_signedBegin;
}
-
} // ndn
#endif // NDN_SIGNED_BLOB_H
diff --git a/ndn-cpp/helpers/hash.h b/ndn-cpp/helpers/hash.h
index 1652f2b..8ac23fa 100644
--- a/ndn-cpp/helpers/hash.h
+++ b/ndn-cpp/helpers/hash.h
@@ -25,6 +25,7 @@
class Hash;
typedef boost::shared_ptr<Hash> HashPtr;
+typedef boost::shared_ptr<const Hash> ConstHashPtr;
class Hash
{
diff --git a/ndn-cpp/interest.h b/ndn-cpp/interest.h
index d929efa..1596b6d 100644
--- a/ndn-cpp/interest.h
+++ b/ndn-cpp/interest.h
@@ -20,6 +20,10 @@
namespace ndn {
+class Interest;
+typedef boost::shared_ptr<Interest> InterestPtr;
+typedef boost::shared_ptr<const Interest> ConstInterestPtr;
+
/**
* @brief Class abstracting operations with Interests (constructing and getting access to Interest fields)
*/
@@ -293,11 +297,9 @@
Hash m_publisherPublicKeyDigest;
Exclude m_exclude;
- Ptr<Blob> m_wire;
+ BlobPtr m_wire;
};
-typedef boost::shared_ptr<Interest> InterestPtr;
-
namespace Error
{
/**
diff --git a/test/test-boost-header-only.cpp b/test/test-boost-header-only.cpp
index ebc8553..03f3efa 100644
--- a/test/test-boost-header-only.cpp
+++ b/test/test-boost-header-only.cpp
@@ -19,17 +19,17 @@
*
*/
int main(int argc, char** argv) {
- Interest interest;
- interest.setName(Name("/test"));
- interest.setMinSuffixComponents(2);
- interest.setMaxSuffixComponents(2);
- interest.setInterestLifetime(boost::posix_time::seconds(10));
- interest.setScope(Interest::SCOPE_LOCAL_CCND);
- interest.setAnswerOriginKind(Interest::AOK_STALE);
- interest.setChildSelector(Interest::CHILD_RIGHT);
+ InterestPtr interest(new Interest());
+ interest->setName(Name("/test"));
+ interest->setMinSuffixComponents(2);
+ interest->setMaxSuffixComponents(2);
+ interest->setInterestLifetime(boost::posix_time::seconds(10));
+ interest->setScope(Interest::SCOPE_LOCAL_CCND);
+ interest->setAnswerOriginKind(Interest::AOK_STALE);
+ interest->setChildSelector(Interest::CHILD_RIGHT);
// i.setPublisherPublicKeyDigest(?);
ostringstream binary;
- wire::Ccnb::appendInterest(binary, interest);
+ wire::Ccnb::appendInterest(binary, *interest);
cout << binary.str().size();
return 0;