ezEngine Release 26.3
Loading...
Searching...
No Matches
ezOpenDdlReader Class Reference

Parses OpenDDL documents into an in-memory tree structure. More...

#include <OpenDdlReader.h>

Inheritance diagram for ezOpenDdlReader:

Public Member Functions

ezResult ParseDocument (ezStreamReader &inout_stream, ezUInt32 uiFirstLineOffset=0, ezLogInterface *pLog=ezLog::GetThreadLocalLogSystem(), ezUInt32 uiCacheSizeInKB=4)
 Parses an OpenDDL document from a stream.
 
const ezOpenDdlReaderElementGetRootElement () const
 Every document has exactly one root element.
 
const ezOpenDdlReaderElementFindElement (ezStringView sGlobalName) const
 Searches for an element with a global name. NULL if there is no such element.
 
- Public Member Functions inherited from ezOpenDdlParser
bool HadFatalParsingError () const
 Whether an error occurred during parsing that resulted in cancellation of further parsing.
 

Protected Member Functions

virtual void OnBeginObject (ezStringView sType, ezStringView sName, bool bGlobalName) override
 Called when a new object is encountered.
 
virtual void OnEndObject () override
 Called when the end of an object is encountered.
 
virtual void OnBeginPrimitiveList (ezOpenDdlPrimitiveType type, ezStringView sName, bool bGlobalName) override
 Called when a new primitive object is encountered.
 
virtual void OnEndPrimitiveList () override
 Called when the end of a primitive object is encountered.
 
virtual void OnPrimitiveBool (ezUInt32 count, const bool *pData, bool bThisIsAll) override
 Called when boolean primitive data is available.
 
virtual void OnPrimitiveInt8 (ezUInt32 count, const ezInt8 *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveInt16 (ezUInt32 count, const ezInt16 *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveInt32 (ezUInt32 count, const ezInt32 *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveInt64 (ezUInt32 count, const ezInt64 *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveUInt8 (ezUInt32 count, const ezUInt8 *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveUInt16 (ezUInt32 count, const ezUInt16 *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveUInt32 (ezUInt32 count, const ezUInt32 *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveUInt64 (ezUInt32 count, const ezUInt64 *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveFloat (ezUInt32 count, const float *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveDouble (ezUInt32 count, const double *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnPrimitiveString (ezUInt32 count, const ezStringView *pData, bool bThisIsAll) override
 Called when data for a primitive type is available. More than one value may be reported at a time.
 
virtual void OnParsingError (ezStringView sMessage, bool bFatal, ezUInt32 uiLine, ezUInt32 uiColumn) override
 Called when something unexpected is encountered in the document.
 
ezOpenDdlReaderElementCreateElement (ezOpenDdlPrimitiveType type, ezStringView sType, ezStringView sName, bool bGlobalName)
 
ezStringView CopyString (const ezStringView &string)
 
void StorePrimitiveData (bool bThisIsAll, ezUInt32 bytecount, const ezUInt8 *pData)
 
void ClearDataChunks ()
 
ezUInt8 * AllocateBytes (ezUInt32 uiNumBytes)
 
- Protected Member Functions inherited from ezOpenDdlParser
void SetLogInterface (ezLogInterface *pLog)
 Sets an ezLogInterface through which errors and warnings are reported.
 
void SetCacheSize (ezUInt32 uiSizeInKB)
 Sets the internal cache size for batching primitive data callbacks.
 
void SetInputStream (ezStreamReader &stream, ezUInt32 uiFirstLineOffset=0)
 Configures the parser to read from the given stream. This can only be called once on a parser instance.
 
bool ContinueParsing ()
 Parses the next portion of the document and triggers appropriate callbacks.
 
ezResult ParseAll ()
 Calls ContinueParsing() in a loop until that returns false.
 
void SkipRestOfObject ()
 Skips the rest of the currently open object. No OnEndObject() call will be done for this object either.
 
void StopParsing ()
 Can be used to prevent parsing the rest of the document.
 
void ParsingError (ezStringView sMessage, bool bFatal)
 Outputs that a parsing error was detected (via OnParsingError) and stops further parsing, if bFatal is set to true.
 

Protected Attributes

ezHybridArray< ezUInt8 *, 16 > m_DataChunks
 
ezUInt8 * m_pCurrentChunk
 
ezUInt32 m_uiBytesInChunkLeft
 
ezDynamicArray< ezUInt8 > m_TempCache
 
ezDeque< ezOpenDdlReaderElementm_Elements
 
ezHybridArray< ezOpenDdlReaderElement *, 16 > m_ObjectStack
 
ezDeque< ezStringm_Strings
 
ezMap< ezString, ezOpenDdlReaderElement * > m_GlobalNames
 
- Protected Attributes inherited from ezOpenDdlParser
ezLogInterfacem_pLogInterface
 

Static Protected Attributes

static constexpr ezUInt32 s_uiChunkSize = 1000 * 4
 

Detailed Description

Parses OpenDDL documents into an in-memory tree structure.

OpenDDL (Open Data Description Language) is a text format for describing structured data. This reader parses an entire DDL document and creates a tree of ezOpenDdlReaderElement objects that can be traversed to extract data. The parser handles both custom object types and primitive data arrays. All parsed data remains valid until the reader is destroyed. Use FindElement() to locate elements by global name, or traverse the tree starting from GetRootElement().

Member Function Documentation

◆ OnBeginObject()

void ezOpenDdlReader::OnBeginObject ( ezStringView  sType,
ezStringView  sName,
bool  bGlobalName 
)
overrideprotectedvirtual

Called when a new object is encountered.

Implements ezOpenDdlParser.

◆ OnBeginPrimitiveList()

void ezOpenDdlReader::OnBeginPrimitiveList ( ezOpenDdlPrimitiveType  type,
ezStringView  sName,
bool  bGlobalName 
)
overrideprotectedvirtual

Called when a new primitive object is encountered.

Implements ezOpenDdlParser.

◆ OnEndObject()

void ezOpenDdlReader::OnEndObject ( )
overrideprotectedvirtual

Called when the end of an object is encountered.

Implements ezOpenDdlParser.

◆ OnEndPrimitiveList()

void ezOpenDdlReader::OnEndPrimitiveList ( )
overrideprotectedvirtual

Called when the end of a primitive object is encountered.

Implements ezOpenDdlParser.

◆ OnParsingError()

void ezOpenDdlReader::OnParsingError ( ezStringView  sMessage,
bool  bFatal,
ezUInt32  uiLine,
ezUInt32  uiColumn 
)
overrideprotectedvirtual

Called when something unexpected is encountered in the document.

The error message describes what was expected and what was encountered. If bFatal is true, the error has left the parser in an unrecoverable state and thus it will not continue parsing. In that case client code will need to clean up it's open state, as no further callbacks will be called. If bFatal is false, the document is not entirely valid, but the parser is still able to continue.

Reimplemented from ezOpenDdlParser.

◆ OnPrimitiveBool()

void ezOpenDdlReader::OnPrimitiveBool ( ezUInt32  count,
const bool *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when boolean primitive data is available.

Todo:
Currently not supported

Multiple values may be reported at once for efficiency. bThisIsAll indicates if this is the final batch for the current primitive list. Implementations should accumulate data if bThisIsAll is false.

Implements ezOpenDdlParser.

◆ OnPrimitiveDouble()

void ezOpenDdlReader::OnPrimitiveDouble ( ezUInt32  count,
const double *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveFloat()

void ezOpenDdlReader::OnPrimitiveFloat ( ezUInt32  count,
const float *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveInt16()

void ezOpenDdlReader::OnPrimitiveInt16 ( ezUInt32  count,
const ezInt16 *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveInt32()

void ezOpenDdlReader::OnPrimitiveInt32 ( ezUInt32  count,
const ezInt32 *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveInt64()

void ezOpenDdlReader::OnPrimitiveInt64 ( ezUInt32  count,
const ezInt64 *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveInt8()

void ezOpenDdlReader::OnPrimitiveInt8 ( ezUInt32  count,
const ezInt8 *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveString()

void ezOpenDdlReader::OnPrimitiveString ( ezUInt32  count,
const ezStringView pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveUInt16()

void ezOpenDdlReader::OnPrimitiveUInt16 ( ezUInt32  count,
const ezUInt16 *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveUInt32()

void ezOpenDdlReader::OnPrimitiveUInt32 ( ezUInt32  count,
const ezUInt32 *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveUInt64()

void ezOpenDdlReader::OnPrimitiveUInt64 ( ezUInt32  count,
const ezUInt64 *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ OnPrimitiveUInt8()

void ezOpenDdlReader::OnPrimitiveUInt8 ( ezUInt32  count,
const ezUInt8 *  pData,
bool  bThisIsAll 
)
overrideprotectedvirtual

Called when data for a primitive type is available. More than one value may be reported at a time.

Implements ezOpenDdlParser.

◆ ParseDocument()

ezResult ezOpenDdlReader::ParseDocument ( ezStreamReader inout_stream,
ezUInt32  uiFirstLineOffset = 0,
ezLogInterface pLog = ezLog::GetThreadLocalLogSystem(),
ezUInt32  uiCacheSizeInKB = 4 
)

Parses an OpenDDL document from a stream.

Returns EZ_FAILURE if an unrecoverable parsing error was encountered. The parsed element tree can be accessed via GetRootElement() after successful parsing. All previous parse results are cleared before parsing begins.

Parameters
streamInput data stream containing OpenDDL text
uiFirstLineOffsetLine number offset for error reporting (useful for sub-documents)
pLogInterface for outputting parsing error details (nullptr disables logging)
uiCacheSizeInKBInternal cache size - increase for documents with large primitive arrays

The documentation for this class was generated from the following files: