name: Small implementation changes
Without these changes Boost.Python emits error when wrapping
Name::Components class.
Change-Id: I9dd33e7c089b647ea07c9754dcd14b4e3273208e
diff --git a/include/ndn-cpp/name.hpp b/include/ndn-cpp/name.hpp
index 192fa31..c4e7e5c 100644
--- a/include/ndn-cpp/name.hpp
+++ b/include/ndn-cpp/name.hpp
@@ -26,7 +26,7 @@
/**
* A Name::Component holds a read-only name component value.
*/
- class Component : private ConstBufferPtr
+ class Component
{
public:
/**
@@ -43,7 +43,7 @@
* @param value A blob with a pointer to an immutable array. The pointer is copied.
*/
Component(const ConstBufferPtr &buffer)
- : ConstBufferPtr (buffer)
+ : value_ (buffer)
{
}
@@ -52,7 +52,7 @@
* @param value The value byte array.
*/
Component(const Buffer& value)
- : ConstBufferPtr (new Buffer(value))
+ : value_ (new Buffer(value))
{
}
@@ -62,23 +62,23 @@
* @param valueLen Length of value.
*/
Component(const uint8_t *value, size_t valueLen)
- : ConstBufferPtr (new Buffer(value, valueLen))
+ : value_ (new Buffer(value, valueLen))
{
}
template<class InputIterator>
Component(InputIterator begin, InputIterator end)
- : ConstBufferPtr (new Buffer(begin, end))
+ : value_ (new Buffer(begin, end))
{
}
Component(const char *string)
- : ConstBufferPtr (new Buffer(string, ::strlen(string)))
+ : value_ (new Buffer(string, ::strlen(string)))
{
}
const Buffer&
- getValue() const { return **this; }
+ getValue() const { return *value_; }
/**
* Write this component value to result, escaping characters according to the NDN URI Scheme.
@@ -88,7 +88,7 @@
void
toEscapedString(std::ostream& result) const
{
- Name::toEscapedString(**this, result);
+ Name::toEscapedString(*value_, result);
}
/**
@@ -99,7 +99,7 @@
std::string
toEscapedString() const
{
- return Name::toEscapedString(**this);
+ return Name::toEscapedString(*value_);
}
/**
@@ -179,13 +179,13 @@
bool
equals(const Component& other) const
{
- return **this == *other;
+ return *value_ == *other.value_;
}
bool
empty() const
{
- return !*this || (*this)->empty();
+ return !value_ || value_->empty();
}
/**
@@ -250,6 +250,8 @@
*/
bool
operator > (const Component& other) const { return compare(other) > 0; }
+ private:
+ ConstBufferPtr value_;
};
/**
@@ -714,7 +716,10 @@
typedef std::vector<Component>::reference reference;
typedef std::vector<Component>::const_reference const_reference;
- typedef Component value_type;
+ typedef std::vector<Component>::difference_type difference_type;
+ typedef std::vector<Component>::size_type size_type;
+
+ typedef std::vector<Component>::value_type value_type;
/**
* Begin iterator (const).
@@ -773,6 +778,13 @@
std::ostream &
operator << (std::ostream &os, const Name &name);
+inline std::ostream &
+operator << (std::ostream &os, const Name::Component &component)
+{
+ component.toEscapedString(os);
+ return os;
+}
+
inline std::string
Name::toUri() const
{