encoding: move Block methods to .cpp
refs #1694
Change-Id: I2fd7cc529093f06da676d7aa67519b1b73f1c9d2
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index 32016f8..4ec1d6b 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -433,6 +433,129 @@
begin, end);
}
+Block::operator boost::asio::const_buffer() const
+{
+ return boost::asio::const_buffer(wire(), size());
+}
+
+bool
+Block::empty() const
+{
+ return m_type == std::numeric_limits<uint32_t>::max();
+}
+
+bool
+Block::hasWire() const
+{
+ return m_buffer && (m_begin != m_end);
+}
+
+Buffer::const_iterator
+Block::begin() const
+{
+ if (!hasWire())
+ throw Error("Underlying wire buffer is empty");
+
+ return m_begin;
+}
+
+Buffer::const_iterator
+Block::end() const
+{
+ if (!hasWire())
+ throw Error("Underlying wire buffer is empty");
+
+ return m_end;
+}
+
+const uint8_t*
+Block::wire() const
+{
+ if (!hasWire())
+ throw Error("(Block::wire) Underlying wire buffer is empty");
+
+ return &*m_begin;
+}
+
+size_t
+Block::size() const
+{
+ if (hasWire() || hasValue()) {
+ return m_size;
+ }
+ else
+ throw Error("Block size cannot be determined (undefined block size)");
+}
+
+bool
+Block::hasValue() const
+{
+ return static_cast<bool>(m_buffer);
+}
+
+const uint8_t*
+Block::value() const
+{
+ if (!hasValue())
+ return 0;
+
+ return &*m_value_begin;
+}
+
+size_t
+Block::value_size() const
+{
+ if (!hasValue())
+ return 0;
+
+ return m_value_end - m_value_begin;
+}
+
+Block::element_iterator
+Block::erase(Block::element_iterator position)
+{
+ resetWire();
+ return m_subBlocks.erase(position);
+}
+
+Block::element_iterator
+Block::erase(Block::element_iterator first, Block::element_iterator last)
+{
+ resetWire();
+ return m_subBlocks.erase(first, last);
+}
+
+void
+Block::push_back(const Block& element)
+{
+ resetWire();
+ m_subBlocks.push_back(element);
+}
+
+Block::element_const_iterator
+Block::elements_begin() const
+{
+ return m_subBlocks.begin();
+}
+
+Block::element_const_iterator
+Block::elements_end() const
+{
+ return m_subBlocks.end();
+}
+
+size_t
+Block::elements_size() const
+{
+ return m_subBlocks.size();
+}
+
+bool
+Block::operator!=(const Block& other) const
+{
+ return !this->operator==(other);
+}
+
bool
Block::operator==(const Block& other) const
{
@@ -440,9 +563,4 @@
std::equal(this->begin(), this->end(), other.begin());
}
-Block::operator boost::asio::const_buffer() const
-{
- return boost::asio::const_buffer(wire(), size());
-}
-
} // namespace ndn