Move the Name.cpp
diff --git a/ndn-cpp/fields/name-component.cc b/ndn-cpp/fields/name-component.cc
deleted file mode 100644
index ecc87b1..0000000
--- a/ndn-cpp/fields/name-component.cc
+++ /dev/null
@@ -1,170 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#include "name-component.h"
-
-#include "ndn-cpp/error.h"
-#include "ndn-cpp/helpers/uri.h"
-
-using namespace std;
-
-namespace ndn
-{
-namespace name
-{
-
-Component::Component ()
-{
-}
-
-Component::Component (const std::string &uri)
-{
- try
- {
- Uri::fromEscaped (uri.begin (), uri.end (), back_inserter (*this));
- }
- catch (error::Uri &err)
- {
- // re-throwing different exception
- BOOST_THROW_EXCEPTION (error::name::Component ()
- << error::msg (uri)
- << error::pos (error::get_pos (err)));
- }
-}
-
-Component::Component (std::string::const_iterator begin, std::string::const_iterator end)
-{
- try
- {
- Uri::fromEscaped (begin, end, back_inserter (*this));
- }
- catch (error::Uri &err)
- {
- // re-throwing different exception
- BOOST_THROW_EXCEPTION (error::name::Component ()
- << error::msg (string (begin, end))
- << error::pos (error::get_pos (err)));
- }
-}
-
-Component::Component (const void *buf, size_t length)
-{
- copy (static_cast<const char*> (buf),
- static_cast<const char*> (buf)+length,
- back_inserter (*this));
-}
-
-int
-Component::compare (const Component &other) const
-{
- if (size () < other.size ())
- return -1;
-
- if (size () > other.size ())
- return +1;
-
- // now we know that sizes are equal
-
- pair<const_iterator, const_iterator> diff = mismatch (begin (), end (), other.begin ());
- if (diff.first == end ()) // components are actually equal
- return 0;
-
- return (std::lexicographical_compare (diff.first, end (), diff.second, other.end ())) ? -1 : +1;
-}
-
-Component
-Component::fromNumber (uint64_t number)
-{
- Component comp;
- while (number > 0)
- {
- comp.push_back (static_cast<unsigned char> (number & 0xFF));
- number >>= 8;
- }
- std::reverse (comp.begin (), comp.end ());
- return comp;
-}
-
-Component
-Component::fromNumberWithMarker (uint64_t number, unsigned char marker)
-{
- Component comp;
- comp.push_back (marker);
-
- while (number > 0)
- {
- comp.push_back (static_cast<unsigned char> (number & 0xFF));
- number >>= 8;
- }
-
- std::reverse (comp.begin () + 1, comp.end ());
- return comp;
-}
-
-std::string
-Component::toBlob () const
-{
- return std::string (begin (), end ());
-}
-
-void
-Component::toBlob (std::ostream &os) const
-{
- os.write (buf (), size ());
-}
-
-std::string
-Component::toUri () const
-{
- ostringstream os;
- toUri (os);
- return os.str ();
-}
-
-void
-Component::toUri (std::ostream &os) const
-{
- Uri::toEscaped (begin (), end (), ostream_iterator<char> (os));
-}
-
-uint64_t
-Component::toNumber () const
-{
- uint64_t ret = 0;
- for (const_iterator i = begin (); i != end (); i++)
- {
- ret <<= 8;
- ret |= static_cast<unsigned char> (*i);
- }
- return ret;
-}
-
-uint64_t
-Component::toNumberWithMarker (unsigned char marker) const
-{
- if (empty () ||
- static_cast<unsigned char> (*(begin ())) != marker)
- {
- BOOST_THROW_EXCEPTION (error::name::Component ()
- << error::msg ("Name component does not have required marker [" + toUri () + "]"));
- }
-
- uint64_t ret = 0;
- for (const_iterator i = begin () + 1; i != end (); i++)
- {
- ret <<= 8;
- ret |= static_cast<unsigned char> (*i);
- }
- return ret;
-}
-
-
-} // name
-} // ndn
diff --git a/ndn-cpp/fields/name-component.h b/ndn-cpp/fields/name-component.h
deleted file mode 100644
index 0bcf862..0000000
--- a/ndn-cpp/fields/name-component.h
+++ /dev/null
@@ -1,282 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- */
-
-#ifndef NDN_NAME_COMPONENT_H
-#define NDN_NAME_COMPONENT_H
-
-#include <string>
-#include <vector>
-
-#include "blob.h"
-#include <stdint.h>
-
-namespace ndn {
-
-namespace name {
-
-/**
- * @brief Class to representing binary blob of NDN name component
- *
- * This class is based on std::vector<char> and just provides several helpers
- * to work with name components, as well as operator to apply canonical
- * ordering on name components
- */
-class Component : public Blob
-{
-public:
- /**
- * @brief Default constructor an empty exclude
- */
- Component ();
-
- /**
- * @brief Create component from URI encoded string
- * @param uri URI encoded name component (convert escaped with % characters)
- */
- Component (const std::string &uri);
-
- /**
- * @brief Create component from URI encoded string, with string specified by a pair of iterators
- * @param begin begin iterator pointing to the URI encoded name
- * @param end end iterator
- */
- Component (std::string::const_iterator begin, std::string::const_iterator end);
-
- /**
- * @brief Create component using a binary blob
- * @param buf pointer to first byte of binary blob to store as a name component
- * @param length length of the binary blob
- */
- Component (const void *buf, size_t length);
-
- /**
- * @brief Apply canonical ordering on component comparison
- * @return 0 They compare equal
- * <0 If *this comes before other in the canonical ordering
- * >0 If *this comes after in the canonical ordering
- *
- * @see http://www.ccnx.org/releases/latest/doc/technical/CanonicalOrder.html
- */
- int
- compare (const Component &other) const;
-
- /**
- * @brief Apply canonical ordering on component comparison (less or equal)
- *
- * @see http://www.ccnx.org/releases/latest/doc/technical/CanonicalOrder.html
- */
- inline bool
- operator <= (const Component &other) const;
-
- /**
- * @brief Apply canonical ordering on component comparison (less)
- *
- * @see http://www.ccnx.org/releases/latest/doc/technical/CanonicalOrder.html
- */
- inline bool
- operator < (const Component &other) const;
-
- /**
- * @brief Apply canonical ordering on component comparison (greater or equal)
- *
- * @see http://www.ccnx.org/releases/latest/doc/technical/CanonicalOrder.html
- */
- inline bool
- operator >= (const Component &other) const;
-
- /**
- * @brief Apply canonical ordering on component comparison (greater)
- *
- * @see http://www.ccnx.org/releases/latest/doc/technical/CanonicalOrder.html
- */
- inline bool
- operator > (const Component &other) const;
-
- ////////////////////////////////////
- // Component construction helpers //
- ////////////////////////////////////
-
- /**
- * @brief Create network-ordered numeric component
- *
- * @param number number to be encoded and added as a component
- *
- * Number is encoded and added in network order. Tail zero-bytes are not included.
- * For example, if the number is 1, then 1-byte binary blob will be added 0x01.
- * If the number is 256, then 2 binary blob will be added: 0x01 0x01
- *
- * If the number is zero, an empty component will be created
- */
- static Component
- fromNumber (uint64_t number);
-
- /**
- * @brief Create network-ordered numeric component to the name with marker
- *
- * @param number number to be encoded and added as a component
- * @param marker byte marker, specified by the desired naming convention
- *
- * Currently defined naming conventions of the marker:
- * - 0x00 sequence number
- * - 0xC1 control number
- * - 0xFB block id
- * - 0xFD version number
- *
- * This version is almost exactly as appendNumber, with exception that it adds initial marker.
- * The number is formatted in the exactly the same way.
- *
- * @see fromNumber
- */
- static Component
- fromNumberWithMarker (uint64_t number, unsigned char marker);
-
- //////////////////////////////////////////////////////////////////////////////////
- // helpers
- //////////////////////////////////////////////////////////////////////////////////
-
- /**
- * @brief Convert binary blob name component to std::string (no conversion is made)
- * @param comp name component to be converted
- * @see asUriString
- */
- std::string
- toBlob () const;
-
- /**
- * @brief Write blob of the name component to the specified output stream
- * @param os output stream
- */
- void
- toBlob (std::ostream &os) const;
-
- /**
- * @brief Convert binary blob name component to std::string, escaping all non-printable characters in URI format
- * @param comp name component to be converted
- * @see asString
- */
- std::string
- toUri () const;
-
- /**
- * @brief Write name as URI to the specified output stream
- * @param os output stream
- */
- void
- toUri (std::ostream &os) const;
-
- /**
- * @brief Convert binary blob name component (network-ordered number) to number
- * @param comp name component to be converted
- */
- uint64_t
- toNumber () const;
-
- /**
- * @brief Convert binary blob name component (network-ordered number) to number, using appropriate marker from the naming convention
- * @param comp name component to be converted
- * @param marker required marker from the naming convention
- *
- * If the required marker does not exist, an exception will be thrown
- */
- uint64_t
- toNumberWithMarker (unsigned char marker) const;
-
- /**
- * @brief Convert binary blob name component, assuming sequence number naming convention (marker = 0x00)
- * @param comp name component to be converted
- * @see asNumberWithMarker
- */
- inline uint64_t
- toSeqNum () const;
-
- /**
- * @brief Convert binary blob name component, assuming control number naming convention (marker = 0xC1)
- * @param comp name component to be converted
- * @see asNumberWithMarker
- */
- inline uint64_t
- toControlNum () const;
-
- /**
- * @brief Convert binary blob name component, assuming block ID naming convention (marker = 0xFB)
- * @param comp name component to be converted
- * @see asNumberWithMarker
- */
- inline uint64_t
- toBlkId () const;
-
- /**
- * @brief Convert binary blob name component, assuming time-stamping version naming convention (marker = 0xFD)
- * @param comp name component to be converted
- * @see asNumberWithMarker
- */
- inline uint64_t
- toVersion () const;
-};
-
-bool
-Component::operator <= (const Component &other) const
-{
- return (compare (other) <= 0);
-}
-
-bool
-Component::operator < (const Component &other) const
-{
- return (compare (other) < 0);
-}
-
-bool
-Component::operator >= (const Component &other) const
-{
- return (compare (other) >= 0);
-}
-
-bool
-Component::operator > (const Component &other) const
-{
- return (compare (other) > 0);
-}
-
-inline uint64_t
-Component::toSeqNum () const
-{
- return toNumberWithMarker (0x00);
-}
-
-inline uint64_t
-Component::toControlNum () const
-{
- return toNumberWithMarker (0xC1);
-}
-
-inline uint64_t
-Component::toBlkId () const
-{
- return toNumberWithMarker (0xFB);
-}
-
-inline uint64_t
-Component::toVersion () const
-{
- return toNumberWithMarker (0xFD);
-}
-
-/**
- * @brief Stream output operator (output in escaped URI format)
- */
-std::ostream&
-operator <<(std::ostream &os, const Component &name);
-
-} // name
-
-} // ndn
-
-#endif // NDN_EXCLUDE_H
diff --git a/ndn-cpp/fields/name.cc b/ndn-cpp/fields/name.cc
deleted file mode 100644
index d3e2ec6..0000000
--- a/ndn-cpp/fields/name.cc
+++ /dev/null
@@ -1,264 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- * Zhenkai Zhu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Zhenkai Zhu <zhenkai@cs.ucla.edu>
- */
-
-#include "name.h"
-
-#include "ndn-cpp/error.h"
-#include <boost/algorithm/string.hpp>
-
-#include <ctype.h>
-
-using namespace std;
-
-namespace ndn
-{
-
-///////////////////////////////////////////////////////////////////////////////
-// CONSTRUCTORS //
-///////////////////////////////////////////////////////////////////////////////
-
-Name::Name ()
-{
-}
-
-Name::Name (const string &uri)
-{
- string::const_iterator i = uri.begin ();
- string::const_iterator end = uri.end ();
-
- string::const_iterator firstSlash = std::find (i, end, '/');
- if (firstSlash == end)
- {
- BOOST_THROW_EXCEPTION (error::Name ()
- << error::msg ("Name should include at least one slash (did you forget to specify initial /?)"));
- }
-
- if (firstSlash != i)
- {
- string schema (i, firstSlash);
- if (*schema.rbegin () != ':')
- {
- BOOST_THROW_EXCEPTION (error::Name ()
- << error::msg ("First component of the name does not start with a slash (did you forget to specify initial /?)"));
- }
-
- i = firstSlash;
-
- if (!boost::iequals (schema, "ccnx:") &&
- !boost::iequals (schema, "ndn:"))
- {
- BOOST_THROW_EXCEPTION (error::Name ()
- << error::msg ("URI schema is not supported (only ccnx: or ndn: is allowed)")
- << error::msg (schema));
- }
- }
-
- string::const_iterator secondSlash = i;
- secondSlash ++;
- if (secondSlash != end && *secondSlash == '/')
- {
- // The authority component (the part after the initial "//" in the familiar http and ftp URI schemes) is present,
- // but it is not relevant to NDN name.
- // skipping it
- secondSlash ++;
- i = std::find (secondSlash, end, '/');
- }
-
- if (i == end)
- {
- BOOST_THROW_EXCEPTION (error::Name ()
- << error::msg ("Invalid URI")
- << error::msg (uri));
- }
-
- while (i != end)
- {
- // skip any extra slashes
- while (i != end && *i == '/')
- {
- i ++;
- }
- if (i == end)
- break;
-
- string::const_iterator endOfComponent = std::find (i, end, '/');
- append (name::Component (i, endOfComponent));
-
- i = endOfComponent;
- }
-}
-
-Name::Name (const Name &other)
-{
- m_comps = other.m_comps;
-}
-
-Name &
-Name::operator= (const Name &other)
-{
- m_comps = other.m_comps;
- return *this;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// SETTERS //
-///////////////////////////////////////////////////////////////////////////////
-
-Name &
-Name::appendVersion (uint64_t version/* = Name::nversion*/)
-{
- if (version != Name::nversion)
- return appendNumberWithMarker (version, 0xFD);
- else
- {
- TimeInterval now = time::NowUnixTimestamp ();
- version = (now.total_seconds () << 12) | (0xFFF & (now.fractional_seconds () / 244 /*( 1000,000 microseconds / 4096.0 resolution = last 12 bits)*/));
- return appendNumberWithMarker (version, 0xFD);
- }
-}
-
-
-///////////////////////////////////////////////////////////////////////////////
-// GETTERS //
-///////////////////////////////////////////////////////////////////////////////
-
-const name::Component &
-Name::get (int index) const
-{
- if (index < 0)
- {
- index = size () - (-index);
- }
-
- if (static_cast<unsigned int> (index) >= size ())
- {
- BOOST_THROW_EXCEPTION (error::Name ()
- << error::msg ("Index out of range")
- << error::pos (index));
- }
- return m_comps [index];
-}
-
-name::Component &
-Name::get (int index)
-{
- if (index < 0)
- {
- index = size () - (-index);
- }
-
- if (static_cast<unsigned int> (index) >= size())
- {
- BOOST_THROW_EXCEPTION (error::Name ()
- << error::msg ("Index out of range")
- << error::pos (index));
- }
- return m_comps [index];
-}
-
-
-/////
-///// Static helpers to convert name component to appropriate value
-/////
-
-
-Name
-Name::getSubName (size_t pos/* = 0*/, size_t len/* = Name::npos*/) const
-{
- Name retval;
-
- if (len == npos)
- {
- len = size () - pos;
- }
-
- if (pos + len > size ())
- {
- BOOST_THROW_EXCEPTION (error::Name ()
- << error::msg ("getSubName parameter out of range")
- << error::pos (pos)
- << error::pos (len));
- }
-
- for (size_t i = pos; i < pos + len; i++)
- {
- retval.append (get (i));
- }
-
- return retval;
-}
-
-Name
-Name::operator+ (const Name &name) const
-{
- Name newName;
- newName
- .append (*this)
- .append (name);
-
- return newName;
-}
-
-std::string
-Name::toUri () const
-{
- ostringstream os;
- toUri (os);
- return os.str ();
-}
-
-void
-Name::toUri (std::ostream &os) const
-{
- for (Name::const_iterator comp = begin (); comp != end (); comp++)
- {
- os << "/";
- comp->toUri (os);
- }
- if (size () == 0)
- os << "/";
-}
-
-// ostream &
-// operator << (ostream &os, const Name &name)
-// {
-// for (Name::const_iterator comp = name.begin (); comp != name.end (); comp++)
-// {
-// os << "/" << *comp;
-// }
-// if (name.size () == 0)
-// os << "/";
-// return os;
-// }
-
-int
-Name::compare (const Name &name) const
-{
- Name::const_iterator i = this->begin ();
- Name::const_iterator j = name.begin ();
-
- for (; i != this->end () && j != name.end (); i++, j++)
- {
- int res = i->compare (*j);
- if (res == 0)
- continue;
- else
- return res;
- }
-
- if (i == this->end () && j == name.end ())
- return 0; // prefixes are equal
-
- return (i == this->end ()) ? -1 : +1;
-}
-
-} // ndn
diff --git a/ndn-cpp/fields/name.h b/ndn-cpp/fields/name.h
deleted file mode 100644
index f45f694..0000000
--- a/ndn-cpp/fields/name.h
+++ /dev/null
@@ -1,635 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/*
- * Copyright (c) 2013, Regents of the University of California
- * Alexander Afanasyev
- * Zhenkai Zhu
- *
- * BSD license, See the LICENSE file for more information
- *
- * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
- * Zhenkai Zhu <zhenkai@cs.ucla.edu>
- */
-
-#ifndef NDN_NAME_HXX
-#define NDN_NAME_HXX
-
-#include "ndn-cpp/fields/name-component.h"
-#include "ndn-cpp/common.h"
-
-namespace ndn {
-
-/**
- * @brief Class for NDN Name
- */
-class Name
-{
-public:
- typedef std::vector<name::Component>::iterator iterator;
- typedef std::vector<name::Component>::const_iterator const_iterator;
- typedef std::vector<name::Component>::reverse_iterator reverse_iterator;
- typedef std::vector<name::Component>::const_reverse_iterator const_reverse_iterator;
- typedef std::vector<name::Component>::reference reference;
- typedef std::vector<name::Component>::const_reference const_reference;
-
- typedef name::Component partial_type;
-
- ///////////////////////////////////////////////////////////////////////////////
- // CONSTRUCTORS //
- ///////////////////////////////////////////////////////////////////////////////
-
- /**
- * @brief Default constructor to create an empty name (zero components, or "/")
- */
- Name ();
-
- /**
- * @brief Copy constructor
- *
- * @param other reference to a NDN name object
- */
- Name (const Name &other);
-
- /**
- * @brief Create a name from URL string
- *
- * @param url URI-represented name
- */
- Name (const std::string &url);
-
- /**
- * @brief Create a name from a container of elements [begin, end)
- *
- * @param begin begin iterator of the container
- * @param end end iterator of the container
- */
- template<class Iterator>
- Name (Iterator begin, Iterator end);
-
- /**
- * @brief Assignment operator
- */
- Name &
- operator= (const Name &other);
-
-
- ///////////////////////////////////////////////////////////////////////////////
- // SETTERS //
- ///////////////////////////////////////////////////////////////////////////////
-
- /**
- * @brief Append a binary blob as a name component
- *
- * @param comp a binary blob
- * @returns reference to self (to allow chaining of append methods)
- */
- inline Name &
- append (const name::Component &comp);
-
- /**
- * @brief Append a binary blob as a name component
- * @param comp a binary blob
- *
- * This version is a little bit more efficient, since it swaps contents of comp and newly added component
- *
- * Attention!!! This method has an intended side effect: content of comp becomes empty
- */
- inline Name &
- appendBySwap (name::Component &comp);
-
- /**
- * @brief Append components a container of elements [begin, end)
- *
- * @param begin begin iterator of the container
- * @param end end iterator of the container
- * @returns reference to self (to allow chaining of append methods)
- */
- template<class Iterator>
- inline Name &
- append (Iterator begin, Iterator end);
-
- /**
- * @brief Append components from another ndn::Name object
- *
- * @param comp reference to Name object
- * @returns reference to self (to allow chaining of append methods)
- */
- inline Name &
- append (const Name &comp);
-
- /**
- * @brief Append a string as a name component
- *
- * @param compStr a string
- * @returns reference to self (to allow chaining of append methods)
- *
- * No conversions will be done to the string. The string is included in raw form,
- * without any leading '\0' symbols.
- */
- inline Name &
- append (const std::string &compStr);
-
- /**
- * @brief Append a binary blob as a name component
- *
- * @param buf pointer to the first byte of the binary blob
- * @param size length of the binary blob
- * @returns reference to self (to allow chaining of append methods)
- */
- inline Name &
- append (const void *buf, size_t size);
-
- /**
- * @brief Append network-ordered numeric component to the name
- *
- * @param number number to be encoded and added as a component
- *
- * Number is encoded and added in network order. Tail zero-bytes are not included.
- * For example, if the number is 1, then 1-byte binary blob will be added 0x01.
- * If the number is 256, then 2 binary blob will be added: 0x01 0x01
- *
- * If the number is zero, an empty component will be added
- */
- inline Name &
- appendNumber (uint64_t number);
-
- /**
- * @brief Append network-ordered numeric component to the name with marker
- *
- * @param number number to be encoded and added as a component
- * @param marker byte marker, specified by the desired naming convention
- *
- * Currently defined naming conventions of the marker:
- * - 0x00 sequence number
- * - 0xC1 control number
- * - 0xFB block id
- * - 0xFD version number
- *
- * This version is almost exactly as appendNumber, with exception that it adds initial marker.
- * The number is formatted in the exactly the same way.
- *
- * @see appendNumber
- */
- inline Name &
- appendNumberWithMarker (uint64_t number, unsigned char marker);
-
- /**
- * @brief Helper method to add sequence number to the name (marker = 0x00)
- * @param seqno sequence number
- * @see appendNumberWithMarker
- */
- inline Name &
- appendSeqNum (uint64_t seqno);
-
- /**
- * @brief Helper method to add control number to the name (marker = 0xC1)
- * @param control control number
- * @see appendNumberWithMarker
- */
- inline Name &
- appendControlNum (uint64_t control);
-
- /**
- * @brief Helper method to add block ID to the name (marker = 0xFB)
- * @param blkid block ID
- * @see appendNumberWithMarker
- */
- inline Name &
- appendBlkId (uint64_t blkid);
-
- /**
- * @brief Helper method to add version to the name (marker = 0xFD)
- * @param version fully formatted version in a desired format (e.g., timestamp).
- * If version is Name::nversion, then the version number is automatically
- * assigned based on UTC timestamp
- * @see appendNumberWithMarker
- */
- Name &
- appendVersion (uint64_t version = Name::nversion);
-
- ///////////////////////////////////////////////////////////////////////////////
- // GETTERS //
- ///////////////////////////////////////////////////////////////////////////////
-
- /**
- * @brief Get number of the name components
- * @return number of name components
- */
- inline size_t
- size () const;
-
- /**
- * @brief Get binary blob of name component
- * @param index index of the name component. If less than 0, then getting component from the back:
- * get(-1) getting the last component, get(-2) is getting second component from back, etc.
- * @returns const reference to binary blob of the requested name component
- *
- * If index is out of range, an exception will be thrown
- */
- const name::Component &
- get (int index) const;
-
- /**
- * @brief Get binary blob of name component
- * @param index index of the name component. If less than 0, then getting component from the back
- * @returns reference to binary blob of the requested name component
- *
- * If index is out of range, an exception will be thrown
- */
- name::Component &
- get (int index);
-
- /////
- ///// Iterator interface to name components
- /////
- inline Name::const_iterator
- begin () const; ///< @brief Begin iterator (const)
-
- inline Name::iterator
- begin (); ///< @brief Begin iterator
-
- inline Name::const_iterator
- end () const; ///< @brief End iterator (const)
-
- inline Name::iterator
- end (); ///< @brief End iterator
-
- inline Name::const_reverse_iterator
- rbegin () const; ///< @brief Reverse begin iterator (const)
-
- inline Name::reverse_iterator
- rbegin (); ///< @brief Reverse begin iterator
-
- inline Name::const_reverse_iterator
- rend () const; ///< @brief Reverse end iterator (const)
-
- inline Name::reverse_iterator
- rend (); ///< @brief Reverse end iterator
-
-
- /////
- ///// Static helpers to convert name component to appropriate value
- /////
-
- /**
- * @brief Get a new name, constructed as a subset of components
- * @param pos Position of the first component to be copied to the subname
- * @param len Number of components to be copied. Value Name::npos indicates that all components till the end of the name.
- */
- Name
- getSubName (size_t pos = 0, size_t len = npos) const;
-
- /**
- * @brief Get prefix of the name
- * @param len length of the prefix
- * @param skip number of components to skip from beginning of the name
- */
- inline Name
- getPrefix (size_t len, size_t skip = 0) const;
-
- /**
- * @brief Get postfix of the name
- * @param len length of the postfix
- * @param skip number of components to skip from end of the name
- */
- inline Name
- getPostfix (size_t len, size_t skip = 0) const;
-
- /**
- * @brief Get text representation of the name (URI)
- */
- std::string
- toUri () const;
-
- /**
- * @brief Write name as URI to the specified output stream
- * @param os output stream
- */
- void
- toUri (std::ostream &os) const;
-
- /////////////////////////////////////////////////
- // Helpers and compatibility wrappers
- /////////////////////////////////////////////////
-
- /**
- * @brief Compare two names, using canonical ordering for each component
- * @return 0 They compare equal
- * <0 If *this comes before other in the canonical ordering
- * >0 If *this comes after in the canonical ordering
- */
- int
- compare (const Name &name) const;
-
- /**
- * @brief Check if to Name objects are equal (have the same number of components with the same binary data)
- */
- inline bool
- operator == (const Name &name) const;
-
- /**
- * @brief Check if two Name objects are not equal
- */
- inline bool
- operator != (const Name &name) const;
-
- /**
- * @brief Less or equal comparison of two name objects
- */
- inline bool
- operator <= (const Name &name) const;
-
- /**
- * @brief Less comparison of two name objects
- */
- inline bool
- operator < (const Name &name) const;
-
- /**
- * @brief Great or equal comparison of two name objects
- */
- inline bool
- operator >= (const Name &name) const;
-
- /**
- * @brief Great comparison of two name objects
- */
- inline bool
- operator > (const Name &name) const;
-
- /**
- * @brief Operator [] to simplify access to name components
- * @see get
- */
- inline name::Component &
- operator [] (int index);
-
- /**
- * @brief Operator [] to simplify access to name components
- * @see get
- */
- inline const name::Component &
- operator [] (int index) const;
-
- /**
- * @brief Create a new Name object, by copying components from first and second name
- */
- Name
- operator + (const Name &name) const;
-
- /**
- * @brief A wrapper for append method
- */
- template<class T>
- inline void
- push_back (const T &comp);
-
-public:
- // Data Members (public):
- /// Value returned by various member functions when they fail.
- const static size_t npos = static_cast<size_t> (-1);
- const static uint64_t nversion = static_cast<uint64_t> (-1);
-
-private:
- std::vector<name::Component> m_comps;
-};
-
-inline std::ostream &
-operator << (std::ostream &os, const Name &name)
-{
- name.toUri (os);
- return os;
-}
-
-
-/////////////////////////////////////////////////////////////////////////////////////
-// Definition of inline methods
-/////////////////////////////////////////////////////////////////////////////////////
-
-template<class Iterator>
-Name::Name (Iterator begin, Iterator end)
-{
- append (begin, end);
-}
-
-inline Name &
-Name::append (const name::Component &comp)
-{
- if (comp.size () != 0)
- m_comps.push_back (comp);
- return *this;
-}
-
-inline Name &
-Name::appendBySwap (name::Component &comp)
-{
- if (comp.size () != 0)
- {
- Name::iterator newComp = m_comps.insert (end (), name::Component ());
- newComp->swap (comp);
- }
- return *this;
-}
-
-template<class Iterator>
-inline Name &
-Name::append (Iterator begin, Iterator end)
-{
- for (Iterator i = begin; i != end; i++)
- {
- append (*i);
- }
- return *this;
-}
-
-Name &
-Name::append (const Name &comp)
-{
- if (this == &comp)
- {
- // have to double-copy if the object is self, otherwise results very frustrating (because we use vector...)
- return append (Name (comp.begin (), comp.end ()));
- }
- return append (comp.begin (), comp.end ());
-}
-
-Name &
-Name::append (const std::string &compStr)
-{
- name::Component comp (compStr);
- return appendBySwap (comp);
-}
-
-Name &
-Name::append (const void *buf, size_t size)
-{
- name::Component comp (buf, size);
- return appendBySwap (comp);
-}
-
-Name &
-Name::appendNumber (uint64_t number)
-{
- name::Component comp;
- name::Component::fromNumber (number).swap (comp);
- return appendBySwap (comp);
-}
-
-Name &
-Name::appendNumberWithMarker (uint64_t number, unsigned char marker)
-{
- name::Component comp;
- name::Component::fromNumberWithMarker (number, marker).swap (comp);
- return appendBySwap (comp);
-}
-
-inline Name &
-Name::appendSeqNum (uint64_t seqno)
-{
- return appendNumberWithMarker (seqno, 0x00);
-}
-
-inline Name &
-Name::appendControlNum (uint64_t control)
-{
- return appendNumberWithMarker (control, 0xC1);
-}
-
-inline Name &
-Name::appendBlkId (uint64_t blkid)
-{
- return appendNumberWithMarker (blkid, 0xFB);
-}
-
-inline size_t
-Name::size () const
-{
- return m_comps.size ();
-}
-
-/////
-///// Iterator interface to name components
-/////
-inline Name::const_iterator
-Name::begin () const
-{
- return m_comps.begin ();
-}
-
-inline Name::iterator
-Name::begin ()
-{
- return m_comps.begin ();
-}
-
-inline Name::const_iterator
-Name::end () const
-{
- return m_comps.end ();
-}
-
-inline Name::iterator
-Name::end ()
-{
- return m_comps.end ();
-}
-
-inline Name::const_reverse_iterator
-Name::rbegin () const
-{
- return m_comps.rbegin ();
-}
-
-inline Name::reverse_iterator
-Name::rbegin ()
-{
- return m_comps.rbegin ();
-}
-
-inline Name::const_reverse_iterator
-Name::rend () const
-{
- return m_comps.rend ();
-}
-
-
-inline Name::reverse_iterator
-Name::rend ()
-{
- return m_comps.rend ();
-}
-
-
-//// helpers
-
-
-inline Name
-Name::getPrefix (size_t len, size_t skip/* = 0*/) const
-{
- return getSubName (skip, len);
-}
-
-inline Name
-Name::getPostfix (size_t len, size_t skip/* = 0*/) const
-{
- return getSubName (size () - len - skip, len);
-}
-
-
-template<class T>
-inline void
-Name::push_back (const T &comp)
-{
- append (comp);
-}
-
-inline bool
-Name::operator ==(const Name &name) const
-{
- return (compare (name) == 0);
-}
-
-inline bool
-Name::operator !=(const Name &name) const
-{
- return (compare (name) != 0);
-}
-
-inline bool
-Name::operator <= (const Name &name) const
-{
- return (compare (name) <= 0);
-}
-
-inline bool
-Name::operator < (const Name &name) const
-{
- return (compare (name) < 0);
-}
-
-inline bool
-Name::operator >= (const Name &name) const
-{
- return (compare (name) >= 0);
-}
-
-inline bool
-Name::operator > (const Name &name) const
-{
- return (compare (name) > 0);
-}
-
-inline name::Component &
-Name::operator [] (int index)
-{
- return get (index);
-}
-
-inline const name::Component &
-Name::operator [] (int index) const
-{
- return get (index);
-}
-
-} // ndn
-
-#endif