ezEngine  Release 25.03
ezOpenDdlReader Class Reference

An OpenDDL reader parses an entire DDL document and creates an in-memory representation of the document 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 the given document, returns EZ_FAILURE if an unrecoverable parsing error was encountered. More...
 
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 data for a primitive type is available. More than one value may be reported at a time. More...
 
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. More...
 
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)
 Data is returned in larger chunks, to reduce the number of function calls. The cache size determines the maximum chunk size per primitive type. More...
 
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 ()
 Call this to parse the next piece of the document. This may trigger a callback through which data is returned. More...
 
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

An OpenDDL reader parses an entire DDL document and creates an in-memory representation of the document structure.

Member Function Documentation

◆ 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 data for a primitive type is available. More than one value may be reported at a time.

Todo:
Currently not supported

Implements ezOpenDdlParser.

◆ ParseDocument()

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

Parses the given document, returns EZ_FAILURE if an unrecoverable parsing error was encountered.

Parameters
streamis the input data.
uiFirstLineOffsetallows to adjust the reported line numbers in error messages, in case the given stream represents a sub-section of a larger file.
pLogis used for outputting details about parsing errors. If nullptr is given, no details are logged.
uiCacheSizeInKBis the internal cache size that the parser uses. If the parsed documents contain primitives lists with several thousand elements in a single list, increasing the cache size can improve performance, but typically this doesn't need to be adjusted.

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