diff options
author | Yury Melnichek <melnichek@gmail.com> | 2011-01-29 03:18:40 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:11:11 +0300 |
commit | 15a14203c445567f8882af3f4ffb3884ae3760e2 (patch) | |
tree | d2a1850b9646e89df31b6539412caf75c7bd8b49 /coding/varint.hpp | |
parent | aba28f101e7f0b8dcb8ce175a1bdd340e2d1ba3a (diff) |
Add ReadVarUint64Array.
Diffstat (limited to 'coding/varint.hpp')
-rw-r--r-- | coding/varint.hpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/coding/varint.hpp b/coding/varint.hpp index afe0c5e28e..64b2191290 100644 --- a/coding/varint.hpp +++ b/coding/varint.hpp @@ -4,6 +4,7 @@ #include "../base/assert.hpp" #include "../base/base.hpp" #include "../base/exception.hpp" +#include "../base/stl_add.hpp" #include "../std/type_traits.hpp" @@ -215,8 +216,9 @@ private: size_t m_Remaining; }; -template <typename F, class WhileConditionT> -void const * ReadVarInt64Array(void const * pBeg, WhileConditionT whileCondition, F f) +template <typename ConverterT, typename F, class WhileConditionT> +inline void const * ReadVarInt64Array(void const * pBeg, WhileConditionT whileCondition, + F f, ConverterT converter) { uint8_t const * const pBegChar = static_cast<uint8_t const *>(pBeg); uint64_t res64 = 0; @@ -231,7 +233,7 @@ void const * ReadVarInt64Array(void const * pBeg, WhileConditionT whileCondition count32 += 7; if (!(t & 128)) { - f(ZigZagDecode((static_cast<uint64_t>(res32) << count64) + res64)); + f(converter((static_cast<uint64_t>(res32) << count64) + res64)); whileCondition.NextVarInt(); res64 = 0; res32 = 0; @@ -257,12 +259,26 @@ void const * ReadVarInt64Array(void const * pBeg, WhileConditionT whileCondition template <typename F> inline void const * ReadVarInt64Array(void const * pBeg, void const * pEnd, F f) { - return impl::ReadVarInt64Array(pBeg, impl::ReadVarInt64ArrayUntilBufferEnd(pEnd), f); + return impl::ReadVarInt64Array<int64_t (*)(uint64_t)>( + pBeg, impl::ReadVarInt64ArrayUntilBufferEnd(pEnd), f, &ZigZagDecode); +} + +template <typename F> inline +void const * ReadVarUint64Array(void const * pBeg, void const * pEnd, F f) +{ + return impl::ReadVarInt64Array(pBeg, impl::ReadVarInt64ArrayUntilBufferEnd(pEnd), f, IdFunctor()); } template <typename F> inline void const * ReadVarInt64Array(void const * pBeg, size_t count, F f) { - return impl::ReadVarInt64Array(pBeg, impl::ReadVarInt64ArrayGivenSize(count), f); + return impl::ReadVarInt64Array<int64_t (*)(uint64_t)>( + pBeg, impl::ReadVarInt64ArrayGivenSize(count), f, &ZigZagDecode); +} + +template <typename F> inline +void const * ReadVarUint64Array(void const * pBeg, size_t count, F f) +{ + return impl::ReadVarInt64Array(pBeg, impl::ReadVarInt64ArrayGivenSize(count), f, IdFunctor()); } |