name: select canonical vs alternate URI representation
refs #4777
Change-Id: Ic644593228bd155de9dcd7005e1b9dc5303a6e66
diff --git a/ndn-cxx/name.hpp b/ndn-cxx/name.hpp
index 18b1fc3..d1c9c8d 100644
--- a/ndn-cxx/name.hpp
+++ b/ndn-cxx/name.hpp
@@ -92,13 +92,19 @@
*/
Name(std::string uri);
+ /** @brief Write URI representation of the name to the output stream
+ * @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#ndn-uri-scheme
+ */
+ void
+ toUri(std::ostream& os, name::UriFormat format = name::UriFormat::DEFAULT) const;
+
/** @brief Get URI representation of the name
* @return URI representation; "ndn:" scheme identifier is not included
* @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#ndn-uri-scheme
* @note To print URI representation into a stream, it is more efficient to use ``os << name``.
*/
std::string
- toUri() const;
+ toUri(name::UriFormat format = name::UriFormat::DEFAULT) const;
/** @brief Check if this Name instance already has wire encoding
*/
@@ -636,6 +642,16 @@
return lhs.compare(rhs) >= 0;
}
+ /** @brief Print URI representation of a name
+ * @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#ndn-uri-scheme
+ */
+ friend std::ostream&
+ operator<<(std::ostream& os, const Name& name)
+ {
+ name.toUri(os);
+ return os;
+ }
+
public:
/** @brief Indicates "until the end" in getSubName() and compare().
*/
@@ -647,12 +663,6 @@
NDN_CXX_DECLARE_WIRE_ENCODE_INSTANTIATIONS(Name);
-/** @brief Print URI representation of a name
- * @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#ndn-uri-scheme
- */
-std::ostream&
-operator<<(std::ostream& os, const Name& name);
-
/** @brief Parse URI from stream as Name
* @sa https://named-data.net/doc/NDN-packet-spec/current/name.html#ndn-uri-scheme
*/