XII Release 0.1.0
Loading...
Searching...
No Matches
xiiOpenDdlReader 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 xiiOpenDdlReader:
[legend]

Public Member Functions

xiiResult ParseDocument (xiiStreamReader &ref_stream, xiiUInt32 uiFirstLineOffset=0, xiiLogInterface *pLog=xiiLog::GetThreadLocalLogSystem(), xiiUInt32 uiCacheSizeInKB=4)
 Parses the given document, returns XII_FAILURE if an unrecoverable parsing error was encountered.
 
const xiiOpenDdlReaderElementGetRootElement () const
 Every document has exactly one root element.
 
const xiiOpenDdlReaderElementFindElement (xiiStringView sGlobalName) const
 Searches for an element with a global name. NULL if there is no such element.
 
- Public Member Functions inherited from xiiOpenDdlParser
bool HadFatalParsingError () const
 Whether an error occurred during parsing that resulted in cancellation of further parsing.
 

Protected Member Functions

virtual void OnBeginObject (xiiStringView sType, xiiStringView 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 (xiiOpenDdlPrimitiveType type, xiiStringView 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 (xiiUInt32 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 (xiiUInt32 count, const xiiInt8 *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 (xiiUInt32 count, const xiiInt16 *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 (xiiUInt32 count, const xiiInt32 *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 (xiiUInt32 count, const xiiInt64 *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 (xiiUInt32 count, const xiiUInt8 *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 (xiiUInt32 count, const xiiUInt16 *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 (xiiUInt32 count, const xiiUInt32 *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 (xiiUInt32 count, const xiiUInt64 *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 (xiiUInt32 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 (xiiUInt32 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 (xiiUInt32 count, const xiiStringView *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 (xiiStringView sMessage, bool bFatal, xiiUInt32 uiLine, xiiUInt32 uiColumn) override
 Called when something unexpected is encountered in the document.
 
xiiOpenDdlReaderElementCreateElement (xiiOpenDdlPrimitiveType type, xiiStringView sType, xiiStringView sName, bool bGlobalName)
 
xiiStringView CopyString (const xiiStringView &string)
 
void StorePrimitiveData (bool bThisIsAll, xiiUInt32 bytecount, const xiiUInt8 *pData)
 
void ClearDataChunks ()
 
xiiUInt8 * AllocateBytes (xiiUInt32 uiNumBytes)
 
- Protected Member Functions inherited from xiiOpenDdlParser
void SetLogInterface (xiiLogInterface *pLog)
 Sets a xiiLogInterface through which errors and warnings are reported.
 
void SetCacheSize (xiiUInt32 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 (xiiStreamReader &stream, xiiUInt32 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.
 
xiiResult 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 (xiiStringView sMessage, bool bFatal)
 Outputs that a parsing error was detected (via OnParsingError) and stops further parsing, if bFatal is set to true.
 

Protected Attributes

xiiHybridArray< xiiUInt8 *, 16 > m_DataChunks
 
xiiUInt8 * m_pCurrentChunk
 
xiiUInt32 m_uiBytesInChunkLeft
 
xiiDynamicArray< xiiUInt8 > m_TempCache
 
xiiDeque< xiiOpenDdlReaderElementm_Elements
 
xiiHybridArray< xiiOpenDdlReaderElement *, 16 > m_ObjectStack
 
xiiDeque< xiiStringm_Strings
 
xiiMap< xiiString, xiiOpenDdlReaderElement * > m_GlobalNames
 
- Protected Attributes inherited from xiiOpenDdlParser
xiiLogInterfacem_pLogInterface
 

Static Protected Attributes

static constexpr xiiUInt32 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 xiiOpenDdlReader::OnBeginObject ( xiiStringView sType,
xiiStringView sName,
bool bGlobalName )
overrideprotectedvirtual

Called when a new object is encountered.

Implements xiiOpenDdlParser.

◆ OnBeginPrimitiveList()

void xiiOpenDdlReader::OnBeginPrimitiveList ( xiiOpenDdlPrimitiveType type,
xiiStringView sName,
bool bGlobalName )
overrideprotectedvirtual

Called when a new primitive object is encountered.

Implements xiiOpenDdlParser.

◆ OnEndObject()

void xiiOpenDdlReader::OnEndObject ( )
overrideprotectedvirtual

Called when the end of an object is encountered.

Implements xiiOpenDdlParser.

◆ OnEndPrimitiveList()

void xiiOpenDdlReader::OnEndPrimitiveList ( )
overrideprotectedvirtual

Called when the end of a primitive object is encountered.

Implements xiiOpenDdlParser.

◆ OnParsingError()

void xiiOpenDdlReader::OnParsingError ( xiiStringView sMessage,
bool bFatal,
xiiUInt32 uiLine,
xiiUInt32 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 xiiOpenDdlParser.

◆ OnPrimitiveBool()

void xiiOpenDdlReader::OnPrimitiveBool ( xiiUInt32 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 xiiOpenDdlParser.

◆ OnPrimitiveDouble()

void xiiOpenDdlReader::OnPrimitiveDouble ( xiiUInt32 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 xiiOpenDdlParser.

◆ OnPrimitiveFloat()

void xiiOpenDdlReader::OnPrimitiveFloat ( xiiUInt32 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 xiiOpenDdlParser.

◆ OnPrimitiveInt16()

void xiiOpenDdlReader::OnPrimitiveInt16 ( xiiUInt32 count,
const xiiInt16 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ OnPrimitiveInt32()

void xiiOpenDdlReader::OnPrimitiveInt32 ( xiiUInt32 count,
const xiiInt32 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ OnPrimitiveInt64()

void xiiOpenDdlReader::OnPrimitiveInt64 ( xiiUInt32 count,
const xiiInt64 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ OnPrimitiveInt8()

void xiiOpenDdlReader::OnPrimitiveInt8 ( xiiUInt32 count,
const xiiInt8 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ OnPrimitiveString()

void xiiOpenDdlReader::OnPrimitiveString ( xiiUInt32 count,
const xiiStringView * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ OnPrimitiveUInt16()

void xiiOpenDdlReader::OnPrimitiveUInt16 ( xiiUInt32 count,
const xiiUInt16 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ OnPrimitiveUInt32()

void xiiOpenDdlReader::OnPrimitiveUInt32 ( xiiUInt32 count,
const xiiUInt32 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ OnPrimitiveUInt64()

void xiiOpenDdlReader::OnPrimitiveUInt64 ( xiiUInt32 count,
const xiiUInt64 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ OnPrimitiveUInt8()

void xiiOpenDdlReader::OnPrimitiveUInt8 ( xiiUInt32 count,
const xiiUInt8 * pData,
bool bThisIsAll )
overrideprotectedvirtual

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

Implements xiiOpenDdlParser.

◆ ParseDocument()

xiiResult xiiOpenDdlReader::ParseDocument ( xiiStreamReader & ref_stream,
xiiUInt32 uiFirstLineOffset = 0,
xiiLogInterface * pLog = xiiLog::GetThreadLocalLogSystem(),
xiiUInt32 uiCacheSizeInKB = 4 )

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