name: Deprecation of Name::set methods, move constructors to .cpp, and documentation update

Change-Id: Icc68cad2854130fbf99c7af3378516dce0585279
Refs: #2505
diff --git a/src/name.cpp b/src/name.cpp
index 9b49fc8..c388064 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -43,6 +43,27 @@
 
 const size_t Name::npos = std::numeric_limits<size_t>::max();
 
+Name::Name()
+  : m_nameBlock(tlv::Name)
+{
+}
+
+Name::Name(const Block& wire)
+{
+  m_nameBlock = wire;
+  m_nameBlock.parse();
+}
+
+Name::Name(const char* uri)
+{
+  construct(uri);
+}
+
+Name::Name(const std::string& uri)
+{
+  construct(uri.c_str());
+}
+
 template<encoding::Tag TAG>
 size_t
 Name::wireEncode(EncodingImpl<TAG>& encoder) const
@@ -94,7 +115,7 @@
 }
 
 void
-Name::set(const char* uriOrig)
+Name::construct(const char* uriOrig)
 {
   clear();
 
@@ -150,6 +171,18 @@
   }
 }
 
+void
+Name::set(const char* uri)
+{
+  *this = std::move(Name(uri));
+}
+
+void
+Name::set(const std::string& uri)
+{
+  *this = std::move(Name(uri));
+}
+
 std::string
 Name::toUri() const
 {
@@ -338,7 +371,7 @@
 {
   std::string inputString;
   is >> inputString;
-  name.set(inputString);
+  name = std::move(Name(inputString));
 
   return is;
 }
diff --git a/src/name.hpp b/src/name.hpp
index bd6e02b..cf8318f 100644
--- a/src/name.hpp
+++ b/src/name.hpp
@@ -34,7 +34,7 @@
 namespace ndn {
 
 /**
- * A Name holds an array of Name::Component and represents an NDN name.
+ * @brief A Name holds an array of name::Component and represents an NDN name
  */
 class Name : public enable_shared_from_this<Name>
 {
@@ -70,12 +70,9 @@
   typedef component_container::size_type       size_type;
 
   /**
-   * Create a new Name with no components.
+   * @brief Create a new Name with no components.
    */
-  Name()
-    : m_nameBlock(tlv::Name)
-  {
-  }
+  Name();
 
   /**
    * @brief Create Name object from wire block
@@ -87,29 +84,19 @@
    * @endcode
    */
   explicit
-  Name(const Block& wire)
-  {
-    m_nameBlock = wire;
-    m_nameBlock.parse();
-  }
+  Name(const Block& wire);
 
   /**
-   * Parse the uri according to the NDN URI Scheme and create the name with the components.
-   * @param uri The URI string.
+   * @brief Create name from @p uri (NDN URI scheme)
+   * @param uri The null-terminated URI string
    */
-  Name(const char* uri)
-  {
-    set(uri);
-  }
+  Name(const char* uri);
 
   /**
-   * Parse the uri according to the NDN URI Scheme and create the name with the components.
-   * @param uri The URI string.
+   * @brief Create name from @p uri (NDN URI scheme)
+   * @param uri The URI string
    */
-  Name(const std::string& uri)
-  {
-    set(uri.c_str());
-  }
+  Name(const std::string& uri);
 
   /**
    * @brief Fast encoding or block size estimation
@@ -131,24 +118,21 @@
   hasWire() const;
 
   /**
-   * Parse the uri according to the NDN URI Scheme and set the name with the components.
-   * @param uri The null-terminated URI string.
+   * @deprecated Use appropriate constructor
    */
+  DEPRECATED(
   void
-  set(const char* uri);
+  set(const char* uri));
 
   /**
-   * Parse the uri according to the NDN URI Scheme and set the name with the components.
-   * @param uri The URI string.
+   * @deprecated Use appropriate constructor
    */
+  DEPRECATED(
   void
-  set(const std::string& uri)
-  {
-    set(uri.c_str());
-  }
+  set(const std::string& uri));
 
   /**
-   * Append a new component, copying from value of length valueLength.
+   * @brief Append a new component, copying from value of length valueLength.
    * @return This name so that you can chain calls to append.
    */
   Name&
@@ -175,6 +159,9 @@
     return *this;
   }
 
+  /**
+   * @brief Append component @p value
+   */
   Name&
   append(const Component& value)
   {
@@ -601,6 +588,10 @@
     return const_reverse_iterator(begin());
   }
 
+private:
+  void
+  construct(const char* uri);
+
 public:
   /** \brief indicates "until the end" in getSubName and compare
    */
diff --git a/tests/unit-tests/name.t.cpp b/tests/unit-tests/name.t.cpp
index c9030c0..6271c7a 100644
--- a/tests/unit-tests/name.t.cpp
+++ b/tests/unit-tests/name.t.cpp
@@ -164,7 +164,7 @@
   BOOST_CHECK(nameEncoded == nameBlock);
 
   Name name2;
-  BOOST_REQUIRE_NO_THROW(name2.set(nameUri));
+  BOOST_REQUIRE_NO_THROW(name2 = std::move(Name(nameUri)));
   Block name2Encoded = name2.wireEncode();
   BOOST_CHECK(name2Encoded == nameBlock);
 }
diff --git a/tests/unit-tests/security/identity-fixture.cpp b/tests/unit-tests/security/identity-fixture.cpp
index de67085..36f9c0b 100644
--- a/tests/unit-tests/security/identity-fixture.cpp
+++ b/tests/unit-tests/security/identity-fixture.cpp
@@ -55,7 +55,7 @@
       m_hasOldDefaultIdentity = false;
     }
 
-    m_newIdentity.set("/ndn-cxx-test-identity");
+    m_newIdentity = "/ndn-cxx-test-identity";
     m_newIdentity.appendVersion();
 
     // create the new identity and self-signed certificate