name: Add Name::deepCopy to allow memory optimizations
Change-Id: I5c498d7524c497e8d7c8e2d89561ff51d1c64d35
Refs: #3618
diff --git a/src/name.cpp b/src/name.cpp
index 0e1b11c..ba6c146 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -64,6 +64,15 @@
construct(uri.c_str());
}
+Name
+Name::deepCopy() const
+{
+ Name copiedName(*this);
+ copiedName.m_nameBlock.resetWire();
+ copiedName.wireEncode(); // "compress" the underlying buffer
+ return copiedName;
+}
+
template<encoding::Tag TAG>
size_t
Name::wireEncode(EncodingImpl<TAG>& encoder) const
diff --git a/src/name.hpp b/src/name.hpp
index 57a1fde..986ef8f 100644
--- a/src/name.hpp
+++ b/src/name.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2015 Regents of the University of California.
+ * Copyright (c) 2013-2016 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -108,6 +108,12 @@
Name(const std::string& uri);
/**
+ * @brief Make a deep copy of the name, reallocating the underlying memory buffer
+ */
+ Name
+ deepCopy() const;
+
+ /**
* @brief Fast encoding or block size estimation
*/
template<encoding::Tag TAG>