meta-info: Reducing use of inline methods
Change-Id: I6630d6bdd8d7277b86e7d8adaaff67762975cf13
diff --git a/src/data.cpp b/src/data.cpp
index 77fc3c9..0a2e3fb 100644
--- a/src/data.cpp
+++ b/src/data.cpp
@@ -20,6 +20,7 @@
*/
#include "data.hpp"
+#include "encoding/block-helpers.hpp"
#include "util/crypto.hpp"
namespace ndn {
diff --git a/src/management/nfd-local-control-header.hpp b/src/management/nfd-local-control-header.hpp
index 71509ba..6a6803e 100644
--- a/src/management/nfd-local-control-header.hpp
+++ b/src/management/nfd-local-control-header.hpp
@@ -24,6 +24,7 @@
#include "../encoding/encoding-buffer.hpp"
#include "../encoding/tlv-nfd.hpp"
+#include "../encoding/block-helpers.hpp"
namespace ndn {
namespace nfd {
diff --git a/src/meta-info.cpp b/src/meta-info.cpp
new file mode 100644
index 0000000..d829ed3
--- /dev/null
+++ b/src/meta-info.cpp
@@ -0,0 +1,182 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2014 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#include "meta-info.hpp"
+#include "encoding/block-helpers.hpp"
+#include "encoding/encoding-buffer.hpp"
+#include "util/time.hpp"
+
+namespace ndn {
+
+MetaInfo::MetaInfo()
+ : m_type(TYPE_DEFAULT)
+ , m_freshnessPeriod(-1)
+{
+}
+
+MetaInfo::MetaInfo(const Block& block)
+{
+ wireDecode(block);
+}
+
+MetaInfo&
+MetaInfo::setType(uint32_t type)
+{
+ m_wire.reset();
+ m_type = type;
+ return *this;
+}
+
+MetaInfo&
+MetaInfo::setFreshnessPeriod(const time::milliseconds& freshnessPeriod)
+{
+ m_wire.reset();
+ m_freshnessPeriod = freshnessPeriod;
+ return *this;
+}
+
+MetaInfo&
+MetaInfo::setFinalBlockId(const name::Component& finalBlockId)
+{
+ m_wire.reset();
+ m_finalBlockId = finalBlockId;
+ return *this;
+}
+
+template<bool T>
+size_t
+MetaInfo::wireEncode(EncodingImpl<T>& blk) const
+{
+ // MetaInfo ::= META-INFO-TYPE TLV-LENGTH
+ // ContentType?
+ // FreshnessPeriod?
+ // FinalBlockId?
+
+ size_t totalLength = 0;
+
+ // FinalBlockId
+ if (!m_finalBlockId.empty())
+ {
+ totalLength += prependNestedBlock(blk, tlv::FinalBlockId, m_finalBlockId);
+ }
+
+ // FreshnessPeriod
+ if (m_freshnessPeriod >= time::milliseconds::zero())
+ {
+ totalLength += prependNonNegativeIntegerBlock(blk, tlv::FreshnessPeriod,
+ m_freshnessPeriod.count());
+ }
+
+ // ContentType
+ if (m_type != TYPE_DEFAULT)
+ {
+ totalLength += prependNonNegativeIntegerBlock(blk, tlv::ContentType, m_type);
+ }
+
+ totalLength += blk.prependVarNumber(totalLength);
+ totalLength += blk.prependVarNumber(tlv::MetaInfo);
+ return totalLength;
+}
+
+template size_t
+MetaInfo::wireEncode<true>(EncodingImpl<true>& block) const;
+
+template size_t
+MetaInfo::wireEncode<false>(EncodingImpl<false>& block) const;
+
+const Block&
+MetaInfo::wireEncode() const
+{
+ if (m_wire.hasWire())
+ return m_wire;
+
+ EncodingEstimator estimator;
+ size_t estimatedSize = wireEncode(estimator);
+
+ EncodingBuffer buffer(estimatedSize, 0);
+ wireEncode(buffer);
+
+ m_wire = buffer.block();
+ return m_wire;
+}
+
+void
+MetaInfo::wireDecode(const Block& wire)
+{
+ m_wire = wire;
+ m_wire.parse();
+
+ // MetaInfo ::= META-INFO-TYPE TLV-LENGTH
+ // ContentType?
+ // FreshnessPeriod?
+
+ // ContentType
+ Block::element_const_iterator val = m_wire.find(tlv::ContentType);
+ if (val != m_wire.elements().end())
+ {
+ m_type = readNonNegativeInteger(*val);
+ }
+ else
+ m_type = TYPE_DEFAULT;
+
+ // FreshnessPeriod
+ val = m_wire.find(tlv::FreshnessPeriod);
+ if (val != m_wire.elements().end())
+ {
+ m_freshnessPeriod = time::milliseconds(readNonNegativeInteger(*val));
+ }
+ else
+ m_freshnessPeriod = time::milliseconds::min();
+
+ // FinalBlockId
+ val = m_wire.find(tlv::FinalBlockId);
+ if (val != m_wire.elements().end())
+ {
+ m_finalBlockId = val->blockFromValue();
+ if (m_finalBlockId.type() != tlv::NameComponent)
+ {
+ /// @todo May or may not throw exception later...
+ m_finalBlockId.reset();
+ }
+ }
+ else
+ m_finalBlockId.reset();
+}
+
+std::ostream&
+operator<<(std::ostream& os, const MetaInfo& info)
+{
+ // ContentType
+ os << "ContentType: " << info.getType();
+
+ // FreshnessPeriod
+ if (info.getFreshnessPeriod() >= time::milliseconds::zero()) {
+ os << ", FreshnessPeriod: " << info.getFreshnessPeriod();
+ }
+
+ if (!info.getFinalBlockId().empty()) {
+ os << ", FinalBlockId: ";
+ info.getFinalBlockId().toUri(os);
+ }
+ return os;
+}
+
+} // namespace ndn
diff --git a/src/meta-info.hpp b/src/meta-info.hpp
index ed5605d..9958ba3 100644
--- a/src/meta-info.hpp
+++ b/src/meta-info.hpp
@@ -23,9 +23,10 @@
#define NDN_META_INFO_HPP
#include "common.hpp"
-#include "encoding/block-helpers.hpp"
+#include "encoding/block.hpp"
#include "encoding/encoding-buffer.hpp"
#include "util/time.hpp"
+#include "name-component.hpp"
namespace ndn {
@@ -41,19 +42,13 @@
TYPE_KEY = 2
};
- MetaInfo()
- : m_type(TYPE_DEFAULT)
- , m_freshnessPeriod(-1)
- {
- }
+ MetaInfo();
/**
* @brief Create from wire encoding
*/
- MetaInfo(const Block& block)
- {
- wireDecode(block);
- }
+ explicit
+ MetaInfo(const Block& block);
template<bool T>
size_t
@@ -69,59 +64,29 @@
// Getters/setters
uint32_t
- getType() const
- {
- return m_type;
- }
+ getType() const;
MetaInfo&
- setType(uint32_t type)
- {
- m_wire.reset();
- m_type = type;
- return *this;
- }
+ setType(uint32_t type);
const time::milliseconds&
- getFreshnessPeriod() const
- {
- return m_freshnessPeriod;
- }
+ getFreshnessPeriod() const;
MetaInfo&
- setFreshnessPeriod(const time::milliseconds& freshnessPeriod)
- {
- m_wire.reset();
- m_freshnessPeriod = freshnessPeriod;
- return *this;
- }
+ setFreshnessPeriod(const time::milliseconds& freshnessPeriod);
const name::Component&
- getFinalBlockId() const
- {
- return m_finalBlockId;
- }
+ getFinalBlockId() const;
MetaInfo&
- setFinalBlockId(const name::Component& finalBlockId)
- {
- m_wire.reset();
- m_finalBlockId = finalBlockId;
- return *this;
- }
+ setFinalBlockId(const name::Component& finalBlockId);
public: // EqualityComparable concept
bool
- operator==(const MetaInfo& other) const
- {
- return wireEncode() == other.wireEncode();
- }
+ operator==(const MetaInfo& other) const;
bool
- operator!=(const MetaInfo& other) const
- {
- return !(*this == other);
- }
+ operator!=(const MetaInfo& other) const;
private:
uint32_t m_type;
@@ -131,116 +96,39 @@
mutable Block m_wire;
};
-template<bool T>
-inline size_t
-MetaInfo::wireEncode(EncodingImpl<T>& blk) const
+std::ostream&
+operator<<(std::ostream& os, const MetaInfo& info);
+
+/////////////////////////////////////////////////////////////////////////
+
+inline uint32_t
+MetaInfo::getType() const
{
- // MetaInfo ::= META-INFO-TYPE TLV-LENGTH
- // ContentType?
- // FreshnessPeriod?
- // FinalBlockId?
-
- size_t totalLength = 0;
-
- // FinalBlockId
- if (!m_finalBlockId.empty())
- {
- totalLength += prependNestedBlock(blk, tlv::FinalBlockId, m_finalBlockId);
- }
-
- // FreshnessPeriod
- if (m_freshnessPeriod >= time::milliseconds::zero())
- {
- totalLength += prependNonNegativeIntegerBlock(blk, tlv::FreshnessPeriod,
- m_freshnessPeriod.count());
- }
-
- // ContentType
- if (m_type != TYPE_DEFAULT)
- {
- totalLength += prependNonNegativeIntegerBlock(blk, tlv::ContentType, m_type);
- }
-
- totalLength += blk.prependVarNumber(totalLength);
- totalLength += blk.prependVarNumber(tlv::MetaInfo);
- return totalLength;
+ return m_type;
}
-inline const Block&
-MetaInfo::wireEncode() const
+inline const time::milliseconds&
+MetaInfo::getFreshnessPeriod() const
{
- if (m_wire.hasWire())
- return m_wire;
-
- EncodingEstimator estimator;
- size_t estimatedSize = wireEncode(estimator);
-
- EncodingBuffer buffer(estimatedSize, 0);
- wireEncode(buffer);
-
- m_wire = buffer.block();
- return m_wire;
+ return m_freshnessPeriod;
}
-inline void
-MetaInfo::wireDecode(const Block& wire)
+inline const name::Component&
+MetaInfo::getFinalBlockId() const
{
- m_wire = wire;
- m_wire.parse();
-
- // MetaInfo ::= META-INFO-TYPE TLV-LENGTH
- // ContentType?
- // FreshnessPeriod?
-
- // ContentType
- Block::element_const_iterator val = m_wire.find(tlv::ContentType);
- if (val != m_wire.elements().end())
- {
- m_type = readNonNegativeInteger(*val);
- }
- else
- m_type = TYPE_DEFAULT;
-
- // FreshnessPeriod
- val = m_wire.find(tlv::FreshnessPeriod);
- if (val != m_wire.elements().end())
- {
- m_freshnessPeriod = time::milliseconds(readNonNegativeInteger(*val));
- }
- else
- m_freshnessPeriod = time::milliseconds::min();
-
- // FinalBlockId
- val = m_wire.find(tlv::FinalBlockId);
- if (val != m_wire.elements().end())
- {
- m_finalBlockId = val->blockFromValue();
- if (m_finalBlockId.type() != tlv::NameComponent)
- {
- /// @todo May or may not throw exception later...
- m_finalBlockId.reset();
- }
- }
- else
- m_finalBlockId.reset();
+ return m_finalBlockId;
}
-inline std::ostream&
-operator<<(std::ostream& os, const MetaInfo& info)
+inline bool
+MetaInfo::operator==(const MetaInfo& other) const
{
- // ContentType
- os << "ContentType: " << info.getType();
+ return wireEncode() == other.wireEncode();
+}
- // FreshnessPeriod
- if (info.getFreshnessPeriod() >= time::milliseconds::zero()) {
- os << ", FreshnessPeriod: " << info.getFreshnessPeriod();
- }
-
- if (!info.getFinalBlockId().empty()) {
- os << ", FinalBlockId: ";
- info.getFinalBlockId().toUri(os);
- }
- return os;
+inline bool
+MetaInfo::operator!=(const MetaInfo& other) const
+{
+ return !(*this == other);
}
} // namespace ndn