name: New method to get "successor" of a name
Change-Id: I41a53e64994970121766bc92cd9dd4796ba5fcfb
refs #1677
diff --git a/src/name.hpp b/src/name.hpp
index 9c33528..7522a19 100644
--- a/src/name.hpp
+++ b/src/name.hpp
@@ -303,6 +303,15 @@
}
/**
+ * @brief get the successor of a name
+ * successor of a name is defined that its last component is
+ * advanced next possible value of last component of original name
+ * @return a new name
+ */
+ Name
+ getSuccessor() const;
+
+ /**
* Check if this name has the same component count and components as the given name.
* @param name The Name to check.
* @return true if the names are equal, otherwise false.
@@ -661,6 +670,19 @@
return result;
}
+inline Name
+Name::getSuccessor() const
+{
+ if (empty()) {
+ static uint8_t firstValue[] = { 0 };
+ Name firstName;
+ firstName.append(firstValue, 1);
+ return firstName;
+ }
+
+ return getPrefix(-1).append(get(-1).getSuccessor());
+}
+
inline bool
Name::equals(const Name& name) const
{