Make Name::Component use a Blob.
diff --git a/ndn-cpp/name.cpp b/ndn-cpp/name.cpp
index 488fcd5..dedbfd1 100644
--- a/ndn-cpp/name.cpp
+++ b/ndn-cpp/name.cpp
@@ -113,35 +113,32 @@
if (component.size() <= 2)
// Zero, one or two periods is illegal. Ignore this component.
return false;
- else {
+ else
// Remove 3 periods.
- value_.clear();
- value_.insert(value_.begin(), component.begin() + 3, component.end());
- }
+ value_ = Blob((const unsigned char *)&component[3], component.size() - 3);
}
- else {
- value_.clear();
- value_.insert(value_.begin(), component.begin(), component.end());
- }
+ else
+ value_ = Blob((const unsigned char *)&component[0], component.size());
return true;
}
void Name::Component::setSegment(unsigned long segment)
{
- value_.clear();
+ ptr_lib::shared_ptr<vector<unsigned char> > value;
// Add the leading zero.
- value_.push_back(0);
+ value->push_back(0);
// First encode in little endian.
while (segment != 0) {
- value_.push_back(segment & 0xff);
+ value->push_back(segment & 0xff);
segment >>= 8;
}
// Make it big endian.
- reverse(value_.begin() + 1, value_.end());
+ reverse(value->begin() + 1, value->end());
+ value_ = value;
}
void Name::set(const char *uri_cstr)
diff --git a/ndn-cpp/name.hpp b/ndn-cpp/name.hpp
index f43a924..41811f5 100644
--- a/ndn-cpp/name.hpp
+++ b/ndn-cpp/name.hpp
@@ -11,6 +11,7 @@
#include <sstream>
#include "c/name.h"
#include "encoding/binary-xml-wire-format.hpp"
+#include "util/blob.hpp"
namespace ndn {
@@ -40,7 +41,7 @@
* @param valueLen Length of value.
*/
Component(const unsigned char *value, unsigned int valueLen)
- : value_(value, value + valueLen)
+ : value_(value, valueLen)
{
}
@@ -53,7 +54,7 @@
{
componentStruct.valueLength = value_.size();
if (value_.size() > 0)
- componentStruct.value = (unsigned char *)&value_[0];
+ componentStruct.value = (unsigned char*)value_.buf();
}
/**
@@ -66,7 +67,7 @@
*/
bool setFromEscapedString(const char *first, const char *last);
- const std::vector<unsigned char>& getValue() const { return value_; }
+ const std::vector<unsigned char>& getValue() const { return (*value_); }
/**
* Set this component to the encoded segment number.
@@ -75,7 +76,7 @@
void setSegment(unsigned long segment);
private:
- std::vector<unsigned char> value_;
+ Blob value_;
};
/**