Plasma Engine  2.0
Loading...
Searching...
No Matches
plOpenDdlReader 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 plOpenDdlReader:

Public Member Functions

plResult ParseDocument (plStreamReader &inout_stream, plUInt32 uiFirstLineOffset=0, plLogInterface *pLog=plLog::GetThreadLocalLogSystem(), plUInt32 uiCacheSizeInKB=4)
 Parses the given document, returns PL_FAILURE if an unrecoverable parsing error was encountered.
 
const plOpenDdlReaderElementGetRootElement () const
 Every document has exactly one root element.
 
const plOpenDdlReaderElementFindElement (plStringView sGlobalName) const
 Searches for an element with a global name. NULL if there is no such element.
 
- Public Member Functions inherited from plOpenDdlParser
bool HadFatalParsingError () const
 Whether an error occurred during parsing that resulted in cancellation of further parsing.
 

Protected Member Functions

virtual void OnBeginObject (plStringView sType, plStringView 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 (plOpenDdlPrimitiveType type, plStringView 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 (plUInt32 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.
 
virtual void OnPrimitiveInt8 (plUInt32 count, const plInt8 *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 (plUInt32 count, const plInt16 *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 (plUInt32 count, const plInt32 *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 (plUInt32 count, const plInt64 *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 (plUInt32 count, const plUInt8 *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 (plUInt32 count, const plUInt16 *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 (plUInt32 count, const plUInt32 *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 (plUInt32 count, const plUInt64 *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 (plUInt32 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 (plUInt32 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 (plUInt32 count, const plStringView *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 (plStringView sMessage, bool bFatal, plUInt32 uiLine, plUInt32 uiColumn) override
 Called when something unexpected is encountered in the document.
 
plOpenDdlReaderElementCreateElement (plOpenDdlPrimitiveType type, plStringView sType, plStringView sName, bool bGlobalName)
 
plStringView CopyString (const plStringView &string)
 
void StorePrimitiveData (bool bThisIsAll, plUInt32 bytecount, const plUInt8 *pData)
 
void ClearDataChunks ()
 
plUInt8 * AllocateBytes (plUInt32 uiNumBytes)
 
- Protected Member Functions inherited from plOpenDdlParser
void SetLogInterface (plLogInterface *pLog)
 Sets an plLogInterface through which errors and warnings are reported.
 
void SetCacheSize (plUInt32 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.
 
void SetInputStream (plStreamReader &stream, plUInt32 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.
 
plResult 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 (plStringView sMessage, bool bFatal)
 Outputs that a parsing error was detected (via OnParsingError) and stops further parsing, if bFatal is set to true.
 

Protected Attributes

plHybridArray< plUInt8 *, 16 > m_DataChunks
 
plUInt8 * m_pCurrentChunk
 
plUInt32 m_uiBytesInChunkLeft
 
plDynamicArray< plUInt8 > m_TempCache
 
plDeque< plOpenDdlReaderElementm_Elements
 
plHybridArray< plOpenDdlReaderElement *, 16 > m_ObjectStack
 
plDeque< plStringm_Strings
 
plMap< plString, plOpenDdlReaderElement * > m_GlobalNames
 
- Protected Attributes inherited from plOpenDdlParser
plLogInterfacem_pLogInterface
 

Static Protected Attributes

static constexpr plUInt32 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

◆ OnBeginObject()

void plOpenDdlReader::OnBeginObject ( plStringView sType,
plStringView sName,
bool bGlobalName )
overrideprotectedvirtual

Called when a new object is encountered.

Implements plOpenDdlParser.

◆ OnBeginPrimitiveList()

void plOpenDdlReader::OnBeginPrimitiveList ( plOpenDdlPrimitiveType type,
plStringView sName,
bool bGlobalName )
overrideprotectedvirtual

Called when a new primitive object is encountered.

Implements plOpenDdlParser.

◆ OnEndObject()

void plOpenDdlReader::OnEndObject ( )
overrideprotectedvirtual

Called when the end of an object is encountered.

Implements plOpenDdlParser.

◆ OnEndPrimitiveList()

void plOpenDdlReader::OnEndPrimitiveList ( )
overrideprotectedvirtual

Called when the end of a primitive object is encountered.

Implements plOpenDdlParser.

◆ OnParsingError()

void plOpenDdlReader::OnParsingError ( plStringView sMessage,
bool bFatal,
plUInt32 uiLine,
plUInt32 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 plOpenDdlParser.

◆ OnPrimitiveBool()

void plOpenDdlReader::OnPrimitiveBool ( plUInt32 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 plOpenDdlParser.

◆ OnPrimitiveDouble()

void plOpenDdlReader::OnPrimitiveDouble ( plUInt32 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 plOpenDdlParser.

◆ OnPrimitiveFloat()

void plOpenDdlReader::OnPrimitiveFloat ( plUInt32 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 plOpenDdlParser.

◆ OnPrimitiveInt16()

void plOpenDdlReader::OnPrimitiveInt16 ( plUInt32 count,
const plInt16 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ OnPrimitiveInt32()

void plOpenDdlReader::OnPrimitiveInt32 ( plUInt32 count,
const plInt32 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ OnPrimitiveInt64()

void plOpenDdlReader::OnPrimitiveInt64 ( plUInt32 count,
const plInt64 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ OnPrimitiveInt8()

void plOpenDdlReader::OnPrimitiveInt8 ( plUInt32 count,
const plInt8 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ OnPrimitiveString()

void plOpenDdlReader::OnPrimitiveString ( plUInt32 count,
const plStringView * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ OnPrimitiveUInt16()

void plOpenDdlReader::OnPrimitiveUInt16 ( plUInt32 count,
const plUInt16 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ OnPrimitiveUInt32()

void plOpenDdlReader::OnPrimitiveUInt32 ( plUInt32 count,
const plUInt32 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ OnPrimitiveUInt64()

void plOpenDdlReader::OnPrimitiveUInt64 ( plUInt32 count,
const plUInt64 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ OnPrimitiveUInt8()

void plOpenDdlReader::OnPrimitiveUInt8 ( plUInt32 count,
const plUInt8 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements plOpenDdlParser.

◆ ParseDocument()

plResult plOpenDdlReader::ParseDocument ( plStreamReader & inout_stream,
plUInt32 uiFirstLineOffset = 0,
plLogInterface * pLog = plLog::GetThreadLocalLogSystem(),
plUInt32 uiCacheSizeInKB = 4 )

Parses the given document, returns PL_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: