Change NameComponent to Name::Component inner class.
diff --git a/ndn-cpp/Name.cpp b/ndn-cpp/Name.cpp
index 63a0c4f..cdcbd61 100644
--- a/ndn-cpp/Name.cpp
+++ b/ndn-cpp/Name.cpp
@@ -147,7 +147,7 @@
return result.str();
}
-bool NameComponent::setFromEscapedString(const char *first, const char *last)
+bool Name::Component::setFromEscapedString(const char *first, const char *last)
{
string trimmedString(first, last);
trim(trimmedString);
@@ -217,7 +217,7 @@
if (iComponentEnd == string::npos)
iComponentEnd = uri.size();
- components_.push_back(NameComponent());
+ components_.push_back(Component());
if (!components_[components_.size() - 1].setFromEscapedString(&uri[iComponentStart], &uri[iComponentEnd]))
// Ignore the illegal component. This also gets rid of a trailing '/'.
components_.pop_back();
diff --git a/ndn-cpp/Name.hpp b/ndn-cpp/Name.hpp
index 302800e..588aa2d 100644
--- a/ndn-cpp/Name.hpp
+++ b/ndn-cpp/Name.hpp
@@ -12,64 +12,64 @@
#include "encoding/BinaryXMLWireFormat.hpp"
namespace ndn {
-
-class NameComponent {
-public:
- /**
- * Create a new NameComponent with an empty value.
- */
- NameComponent()
- {
- }
-
- /**
- * Create a new NameComponent, copying the given value.
- * @param value The value byte array.
- */
- NameComponent(const std::vector<unsigned char> &value)
- : value_(value)
- {
- }
-
- /**
- * Create a new NameComponent, copying the given value.
- * @param value Pointer to the value byte array.
- * @param valueLen Length of value.
- */
- NameComponent(unsigned char *value, unsigned int valueLen)
- : value_(value, value + valueLen)
- {
- }
-
- /**
- * Set the componentStruct to point to this component, without copying any memory.
- * WARNING: The resulting pointer in componentStruct is invalid after a further use of this object which could reallocate memory.
- * @param componentStruct The C ndn_NameComponent struct to receive the pointer.
- */
- void get(struct ndn_NameComponent &componentStruct) const
- {
- componentStruct.value = (unsigned char *)&value_[0];
- componentStruct.valueLength = value_.size();
- }
-
- /**
- * Set this component value by decoding the escapedString between first and last according to the NDN URI Scheme.
- * If the escaped string is "", "." or ".." then return false, which means this component value was not changed, and
- * the component should be skipped in a URI name.
- * @param first Pointer to the beginning of the escaped string
- * @param last Pointer to the first character past the end of the escaped string
- * @return True for success, false if escapedString is not a valid escaped component.
- */
- bool setFromEscapedString(const char *first, const char *last);
-
- const std::vector<unsigned char> &getValue() const { return value_; }
-
-private:
- std::vector<unsigned char> value_;
-};
-
+
class Name {
public:
+ class Component {
+ public:
+ /**
+ * Create a new Name::Component with an empty value.
+ */
+ Component()
+ {
+ }
+
+ /**
+ * Create a new Name::Component, copying the given value.
+ * @param value The value byte array.
+ */
+ Component(const std::vector<unsigned char> &value)
+ : value_(value)
+ {
+ }
+
+ /**
+ * Create a new Name::Component, copying the given value.
+ * @param value Pointer to the value byte array.
+ * @param valueLen Length of value.
+ */
+ Component(unsigned char *value, unsigned int valueLen)
+ : value_(value, value + valueLen)
+ {
+ }
+
+ /**
+ * Set the componentStruct to point to this component, without copying any memory.
+ * WARNING: The resulting pointer in componentStruct is invalid after a further use of this object which could reallocate memory.
+ * @param componentStruct The C ndn_NameComponent struct to receive the pointer.
+ */
+ void get(struct ndn_NameComponent &componentStruct) const
+ {
+ componentStruct.value = (unsigned char *)&value_[0];
+ componentStruct.valueLength = value_.size();
+ }
+
+ /**
+ * Set this component value by decoding the escapedString between first and last according to the NDN URI Scheme.
+ * If the escaped string is "", "." or ".." then return false, which means this component value was not changed, and
+ * the component should be skipped in a URI name.
+ * @param first Pointer to the beginning of the escaped string
+ * @param last Pointer to the first character past the end of the escaped string
+ * @return True for success, false if escapedString is not a valid escaped component.
+ */
+ bool setFromEscapedString(const char *first, const char *last);
+
+ const std::vector<unsigned char> &getValue() const { return value_; }
+
+ private:
+ std::vector<unsigned char> value_;
+ };
+
/**
* Create a new Name with no components.
*/
@@ -78,9 +78,9 @@
/**
* Create a new Name, copying the name components.
- * @param components A vector of NameComponent
+ * @param components A vector of Component
*/
- Name(const std::vector<NameComponent> &components)
+ Name(const std::vector<Component> &components)
: components_(components)
{
}
@@ -90,6 +90,7 @@
* @param uri The URI string.
*/
Name(const char *uri);
+
/**
* Set the nameStruct to point to the components in this name, without copying any memory.
* WARNING: The resulting pointers in nameStruct are invalid after a further use of this object which could reallocate memory.
@@ -107,7 +108,7 @@
* Add a new component, copying from value of length valueLength.
*/
void addComponent(unsigned char *value, unsigned int valueLength) {
- components_.push_back(NameComponent(value, valueLength));
+ components_.push_back(Component(value, valueLength));
}
/**
@@ -125,7 +126,7 @@
return components_.size();
}
- const NameComponent &getComponent(unsigned int i) const { return components_[i]; }
+ const Component &getComponent(unsigned int i) const { return components_[i]; }
/**
* Encode this name as a URI.
@@ -134,7 +135,7 @@
std::string to_uri() const;
private:
- std::vector<NameComponent> components_;
+ std::vector<Component> components_;
};
}