Leviathan  0.8.0.0
Leviathan game engine
Leviathan::EBMLElement Struct Reference

A basic EBML element. More...

Public Member Functions

 EBMLElement (const EBMLElement &other)=default
 
EBMLElementoperator= (const EBMLElement &other)=default
 
template<class T >
 EBMLElement (T &stream)
 Read from stream. More...
 
template<class T , class Callback >
int ReadChildElements (T &stream, Callback callback) const
 

Public Attributes

EBMLLIdentifierValue Identifier
 
EBMLLengthValue Length
 
size_t DataStart = -1
 

Detailed Description

A basic EBML element.

Definition at line 194 of file MatroskaParser.cpp.

Constructor & Destructor Documentation

◆ EBMLElement() [1/2]

Leviathan::EBMLElement::EBMLElement ( const EBMLElement other)
default

◆ EBMLElement() [2/2]

template<class T >
Leviathan::EBMLElement::EBMLElement ( T &  stream)
inline

Read from stream.

Definition at line 201 of file MatroskaParser.cpp.

201  : Identifier(stream), Length(stream)
202  {
203  if(stream.good())
204  DataStart = stream.tellg();
205  }
EBMLLIdentifierValue Identifier

Member Function Documentation

◆ operator=()

EBMLElement& Leviathan::EBMLElement::operator= ( const EBMLElement other)
default

◆ ReadChildElements()

template<class T , class Callback >
int Leviathan::EBMLElement::ReadChildElements ( T &  stream,
Callback  callback 
) const
inline

Definition at line 208 of file MatroskaParser.cpp.

209  {
210  stream.seekg(DataStart);
211 
212  if(!stream.good())
213  return -1;
214 
215  const auto dataEnd = DataStart + Length.Value;
216  int foundCount = 0;
217 
218  std::vector<uint8_t> dataBuffer;
219 
220  while(true) {
221 
222  EBMLElement childElement(stream);
223 
224  if(!stream.good())
225  return -1;
226 
227  auto readData = [&]() -> std::vector<uint8_t>& {
228  dataBuffer.resize(childElement.Length.Value);
229  stream.seekg(childElement.DataStart);
230  stream.read(reinterpret_cast<char*>(dataBuffer.data()), dataBuffer.size());
231 
232  return dataBuffer;
233  };
234 
235  const bool continueLoop = callback(childElement, readData);
236 
237  ++foundCount;
238 
239  // Jump past this element
240  const auto jumpPos = childElement.DataStart + childElement.Length.Value;
241 
242  if(jumpPos >= dataEnd)
243  break;
244 
245  stream.seekg(jumpPos);
246 
247  if(!continueLoop)
248  break;
249  }
250 
251  return foundCount;
252  }
A basic EBML element.
uint64_t Value
The contents of this value.

Member Data Documentation

◆ DataStart

size_t Leviathan::EBMLElement::DataStart = -1

Definition at line 256 of file MatroskaParser.cpp.

◆ Identifier

EBMLLIdentifierValue Leviathan::EBMLElement::Identifier

Definition at line 254 of file MatroskaParser.cpp.

◆ Length

EBMLLengthValue Leviathan::EBMLElement::Length

Definition at line 255 of file MatroskaParser.cpp.


The documentation for this struct was generated from the following file: