PushBackByteSink uses .append() when possible.

This commit is contained in:
Yury Melnichek 2011-08-08 20:23:59 +02:00 committed by Alex Zolotarev
parent 8cbab227ec
commit c2b6907ed6

View file

@ -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