Skip to content

Commit ed544a8

Browse files
committed
Make debug bitstreams seekable
1 parent 0f44630 commit ed544a8

File tree

4 files changed

+93
-7
lines changed

4 files changed

+93
-7
lines changed

src/bitstream/DebugInputBitStream.hpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ limitations under the License.
1919

2020
#include "../InputBitStream.hpp"
2121
#include "../OutputStream.hpp"
22+
#include "../Seekable.hpp"
2223

2324

24-
namespace kanzi
25-
{
25+
namespace kanzi {
2626

27-
class DebugInputBitStream : public InputBitStream
27+
#if defined(WIN32) || defined(_WIN32)
28+
class DebugInputBitStream FINAL : public InputBitStream
29+
#else
30+
class DebugInputBitStream FINAL : public InputBitStream, public Seekable
31+
#endif
2832
{
2933
private:
3034
InputBitStream& _delegate;
@@ -75,8 +79,47 @@ namespace kanzi
7579
void setMark(bool mark) { _mark = mark; }
7680

7781
bool mark() const { return _mark; }
82+
83+
#if !defined(WIN32) && !defined(_WIN32)
84+
int64 tell();
85+
86+
bool seek(int64 pos);
87+
#endif
7888
};
7989

90+
#if !defined(WIN32) && !defined(_WIN32)
91+
// Return a position at the byte boundary
92+
inline int64 DebugInputBitStream::tell()
93+
{
94+
#ifdef NO_RTTI
95+
throw std::ios_base::failure("Not supported");
96+
#else
97+
Seekable* seekable = dynamic_cast<Seekable*>(&_delegate);
98+
99+
if (seekable == nullptr)
100+
throw std::ios_base::failure("The stream is not seekable");
101+
102+
return seekable->tell();
103+
#endif
104+
}
105+
106+
// Only support a new position at the byte boundary (pos & 7 == 0)
107+
#ifdef NO_RTTI
108+
inline bool DebugInputBitStream::seek(int64)
109+
{
110+
throw std::ios_base::failure("Not supported");
111+
#else
112+
inline bool DebugInputBitStream::seek(int64 pos)
113+
{
114+
Seekable* seekable = dynamic_cast<Seekable*>(&_delegate);
115+
116+
if (seekable == nullptr)
117+
throw std::ios_base::failure("The stream is not seekable");
118+
119+
return seekable->seek(pos);
120+
#endif
121+
}
122+
#endif
80123
}
81124
#endif
82125

src/bitstream/DebugOutputBitStream.hpp

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ limitations under the License.
1919

2020
#include "../OutputBitStream.hpp"
2121
#include "../OutputStream.hpp"
22-
22+
#include "../Seekable.hpp"
2323

2424
namespace kanzi
2525
{
2626

27-
class DebugOutputBitStream : public OutputBitStream
27+
#if defined(WIN32) || defined(_WIN32)
28+
class DebugOutputBitStream FINAL : public OutputBitStream
29+
#else
30+
class DebugOutputBitStream FINAL : public OutputBitStream, public Seekable
31+
#endif
2832
{
2933
private:
3034
OutputBitStream& _delegate;
@@ -71,8 +75,47 @@ namespace kanzi
7175
void setMark(bool mark) { _mark = mark; }
7276

7377
bool mark() const { return _mark; }
78+
79+
#if !defined(WIN32) && !defined(_WIN32)
80+
int64 tell();
81+
82+
bool seek(int64 pos);
83+
#endif
7484
};
7585

86+
#if !defined(WIN32) && !defined(_WIN32) // Return a position at the byte boundary
87+
inline int64 DebugOutputBitStream::tell()
88+
{
89+
#ifdef NO_RTTI
90+
throw std::ios_base::failure("Not supported");
91+
#else
92+
Seekable* seekable = dynamic_cast<Seekable*>(&_delegate);
93+
94+
if (seekable == nullptr)
95+
throw std::ios_base::failure("The stream is not seekable");
96+
97+
return seekable->tell();
98+
#endif
99+
}
100+
101+
// Only support a new position at the byte boundary (pos & 7 == 0)
102+
#ifdef NO_RTTI
103+
inline bool DebugOutputBitStream::seek(int64)
104+
{
105+
throw std::ios_base::failure("Not supported");
106+
#else
107+
inline bool DebugOutputBitStream::seek(int64 pos)
108+
{
109+
Seekable* seekable = dynamic_cast<Seekable*>(&_delegate);
110+
111+
if (seekable == nullptr)
112+
throw std::ios_base::failure("The stream is not seekable");
113+
114+
return seekable->seek(pos);
115+
#endif
116+
}
117+
#endif
118+
76119
}
77120
#endif
78121

src/bitstream/DefaultInputBitStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace kanzi {
3030
#if defined(WIN32) || defined(_WIN32)
3131
class DefaultInputBitStream FINAL : public InputBitStream
3232
#else
33-
class DefaultInputBitStream FINAL : public InputBitStream, Seekable
33+
class DefaultInputBitStream FINAL : public InputBitStream, public Seekable
3434
#endif
3535
{
3636
private:

src/bitstream/DefaultOutputBitStream.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace kanzi
3131
#if defined(WIN32) || defined(_WIN32)
3232
class DefaultOutputBitStream FINAL : public OutputBitStream
3333
#else
34-
class DefaultOutputBitStream FINAL : public OutputBitStream, Seekable
34+
class DefaultOutputBitStream FINAL : public OutputBitStream, public Seekable
3535
#endif
3636
{
3737
private:

0 commit comments

Comments
 (0)