libebml_ng
io.h
Go to the documentation of this file.
1 #ifndef EBML_NG_PARSING_IO_H
2 #define EBML_NG_PARSING_IO_H
3 
4 #include <memory>
5 
6 #include "libebml_ng/ebmlID_t.h"
7 #include "libebml_ng/io.h"
8 #include "libebml_ng/struct.h"
10 
11 namespace ebml {
32  class parseFile {
33  public:
34  parseFile(ioBase&);
36  parseFile(ioBase&, off_t);
37  parseFile(ioBase&, off_t, parseFile&);
38 
40  unsigned char ebmlIDWidth;
41  size_t dataSize;
42  unsigned char sizeWidth;
43  off_t offset;
44  off_t parentOffset = 0;
46 
47  off_t dataOffset() const;
48  off_t endOffset() const;
49  size_t read(char*) const;
50  size_t read(char*, size_t) const;
51  size_t read(char*, off_t, size_t) const;
52  off_t seek(off_t) const;
53  off_t tell() const;
54  size_t outerSize() const;
55 
66  template<typename T>
67  inline T unpack() const {
68  auto buffer_sp = std::make_unique<char[]>(this->dataSize);
69  auto buffer = buffer_sp.get();
70  this->read(buffer, 0, this->dataSize);
71  return ebml::unpack<T>(buffer, this->dataSize);
72  }
73 
74  protected:
75  // For use by parseFile::iterator, just initializes the member variables and seeks file to beginning of data.
76  parseFile(ioBase*, ebmlID_t, unsigned char, size_t, unsigned char, off_t);
77  parseFile(ioBase*, ebmlID_t, unsigned char, size_t, unsigned char, off_t, parseFile&);
78 
79  public:
89  class iterator {
90  public:
91  iterator(ioBase* file);
92  iterator(ioBase* file, off_t end);
93  iterator(ioBase* file, off_t start, off_t end);
94  iterator(ioBase* file, off_t end, parseFile&);
95  iterator(ioBase* file, off_t start, off_t end, parseFile&);
96 
99  // parseFile::iterator operator++(int); Postincrement not supported
100  bool atEnd();
101 
102  private:
103  // ioBase_sp _file;
104  ioBase* _file;
105  parseFile* _parent = nullptr;
106  off_t _startoffset;
107  off_t _endoffset;
108 
109  ebmlID_t _ebmlID;
110  unsigned char _ebmlIDWidth;
111  size_t _dataSize;
112  unsigned char _sizeWidth;
113  off_t _offset;
114 
115  };
116 
117  iterator begin() const;
118  private:
119  mutable ioBase* _file;
120 
121  friend class parseFile::iterator;
122  };
123 }
124 #endif
bool atEnd()
Definition: io.cpp:243
off_t offset
Definition: io.h:43
off_t endOffset() const
Definition: io.cpp:155
Represents a parsed EBML file segment.
Definition: io.h:32
size_t read(char *) const
Definition: io.cpp:100
off_t parentOffset
Definition: io.h:44
ebmlID_t ebmlID
Definition: io.h:39
Definition: basictypes.h:40
off_t tell() const
unsigned char sizeWidth
Definition: io.h:42
unsigned char ebmlIDWidth
Definition: io.h:40
parseFile * parent
Definition: io.h:45
Iterator class for parseFile.
Definition: io.h:89
iterator begin() const
Definition: io.cpp:140
parseFile operator*()
Definition: io.cpp:195
uint64_t ebmlID_t
Definition: ebmlID_t.h:7
parseFile::iterator & operator++()
Definition: io.cpp:224
parseFile(ioBase &)
Definition: io.cpp:40
iterator(ioBase *file)
Definition: io.cpp:173
size_t outerSize() const
Definition: io.cpp:16
Base class for file-like IO operations.
Definition: io.h:22
T unpack() const
Template method to unpack data from the element read from file.
Definition: io.h:67
off_t dataOffset() const
Definition: io.cpp:151
size_t dataSize
Definition: io.h:41
off_t seek(off_t) const
Definition: io.cpp:90