diff options
author | Yury Melnichek <melnichek@malinovka.local> | 2011-08-08 22:23:59 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:21:30 +0300 |
commit | c2b6907ed61a2f1db22b1b374b8103efd0017289 (patch) | |
tree | 007f502548a1ea126e68fe2bdde1208d08d65d25 /coding/byte_stream.hpp | |
parent | 8cbab227ec96fb59ff0d516de8cc590ef0aa507c (diff) |
PushBackByteSink uses .append() when possible.
Diffstat (limited to 'coding/byte_stream.hpp')
-rw-r--r-- | coding/byte_stream.hpp | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/coding/byte_stream.hpp b/coding/byte_stream.hpp index 9ce9f747f0..1e9a494d14 100644 --- a/coding/byte_stream.hpp +++ b/coding/byte_stream.hpp @@ -33,11 +33,33 @@ private: const unsigned char * m_p; }; -// TODO: Separate sink and rich write interface. -template <class TStorage = vector<unsigned char> > class PushBackByteSink +template <class StorageT> class PushBackByteSink { public: - explicit PushBackByteSink(TStorage & storage) + explicit PushBackByteSink(StorageT & storage) + : m_Storage(storage)//, m_InitialStorageSize(storage.size()) + { + } + + void Write(void const * p, size_t size) + { + // assume input buffer as buffer of bytes + unsigned char const * pp = static_cast<unsigned char const *>(p); + m_Storage.append(pp, pp + size); + } + + size_t Pos() const + { + return m_Storage.size(); + } +private: + StorageT & m_Storage; +}; + +template <typename T> class PushBackByteSink<vector<T> > +{ +public: + explicit PushBackByteSink(vector<T> & storage) : m_Storage(storage)//, m_InitialStorageSize(storage.size()) { } @@ -54,7 +76,7 @@ public: return m_Storage.size(); } private: - TStorage & m_Storage; + vector<T> & m_Storage; }; class CountingSink |