forked from organicmaps/organicmaps-tmp
PushBackByteSink uses .append() when possible.
This commit is contained in:
parent
8cbab227ec
commit
c2b6907ed6
1 changed files with 26 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue