| 60 | template <class StreamBuf, template <class T> class TypeTraits, bool IsMutable> |
| 61 | template <std::size_t Alignment> |
| 62 | inline |
| 63 | size_t |
| 64 | ByteStream<StreamBuf, TypeTraits, IsMutable>::seek(std::ptrdiff_t inOffset, |
| 65 | std::ios_base::seekdir inDir) { |
| 66 | |
| 67 | BOOST_STATIC_ASSERT_MSG( |
| 68 | (Alignment & (Alignment - 1)) == 0 && Alignment > 0, |
| 69 | "Alignment must be a power of 2."); |
| 70 | madlib_assert( |
| 71 | reinterpret_cast<uint64_t>(this->ptr()) % Alignment == 0, |
| 72 | std::logic_error("ByteString improperly aligned for " |
| 73 | "alignment request in seek().")); |
| 74 | |
| 75 | size_t newPos = |
| 76 | inDir == std::ios_base::beg |
| 77 | ? 0 |
| 78 | : (inDir == std::ios_base::cur |
| 79 | ? this->tell() |
| 80 | : this->size()); |
| 81 | |
| 82 | if (inOffset >= 0) |
| 83 | newPos += static_cast<size_t>(inOffset); |
| 84 | else if (static_cast<size_t>(-inOffset) > newPos) |
| 85 | newPos = 0; |
| 86 | else |
| 87 | newPos -= static_cast<size_t>(-inOffset); |
| 88 | newPos = ((newPos - 1) & ~(Alignment - 1)) + Alignment; |
| 89 | |
| 90 | return this->seek(newPos); |
| 91 | } |
| 92 | |
| 93 | template <class StreamBuf, template <class T> class TypeTraits, bool IsMutable> |
| 94 | inline |