Plasma Engine  2.0
Loading...
Searching...
No Matches
OpenDdlReader.h
1#pragma once
2
3#include <Foundation/Basics.h>
4#include <Foundation/Containers/Deque.h>
5#include <Foundation/Containers/Map.h>
6#include <Foundation/IO/OpenDdlParser.h>
7#include <Foundation/Logging/Log.h>
8
10class PL_FOUNDATION_DLL plOpenDdlReaderElement
11{
12public:
13 PL_DECLARE_POD_TYPE();
14
16 PL_ALWAYS_INLINE bool IsCustomType() const { return m_PrimitiveType == plOpenDdlPrimitiveType::Custom; } // [tested]
17
19 PL_ALWAYS_INLINE bool IsCustomType(plStringView sTypeName) const
20 {
21 return m_PrimitiveType == plOpenDdlPrimitiveType::Custom && m_sCustomType == sTypeName;
22 }
23
25 PL_ALWAYS_INLINE plStringView GetCustomType() const { return m_sCustomType; } // [tested]
26
28 PL_ALWAYS_INLINE bool HasName() const { return !m_sName.IsEmpty(); } // [tested]
29
31 PL_ALWAYS_INLINE plStringView GetName() const { return m_sName; } // [tested]
32
34 PL_ALWAYS_INLINE bool IsNameGlobal() const { return (m_uiNumChildElements & PL_BIT(31)) != 0; } // [tested]
35
37 plUInt32 GetNumChildObjects() const; // [tested]
38
40 PL_ALWAYS_INLINE const plOpenDdlReaderElement* GetFirstChild() const
41 {
42 return reinterpret_cast<const plOpenDdlReaderElement*>(m_pFirstChild);
43 } // [tested]
44
46 PL_ALWAYS_INLINE const plOpenDdlReaderElement* GetSibling() const { return m_pSiblingElement; } // [tested]
47
49 plUInt32 GetNumPrimitives() const; // [tested]
50
52 PL_ALWAYS_INLINE plOpenDdlPrimitiveType GetPrimitivesType() const { return m_PrimitiveType; } // [tested]
53
56 bool HasPrimitives(plOpenDdlPrimitiveType type, plUInt32 uiMinNumberOfPrimitives = 1) const;
57
59 PL_ALWAYS_INLINE const bool* GetPrimitivesBool() const { return reinterpret_cast<const bool*>(m_pFirstChild); } // [tested]
60
62 PL_ALWAYS_INLINE const plInt8* GetPrimitivesInt8() const { return reinterpret_cast<const plInt8*>(m_pFirstChild); } // [tested]
63
65 PL_ALWAYS_INLINE const plInt16* GetPrimitivesInt16() const { return reinterpret_cast<const plInt16*>(m_pFirstChild); } // [tested]
66
68 PL_ALWAYS_INLINE const plInt32* GetPrimitivesInt32() const { return reinterpret_cast<const plInt32*>(m_pFirstChild); } // [tested]
69
71 PL_ALWAYS_INLINE const plInt64* GetPrimitivesInt64() const { return reinterpret_cast<const plInt64*>(m_pFirstChild); } // [tested]
72
74 PL_ALWAYS_INLINE const plUInt8* GetPrimitivesUInt8() const { return reinterpret_cast<const plUInt8*>(m_pFirstChild); } // [tested]
75
77 PL_ALWAYS_INLINE const plUInt16* GetPrimitivesUInt16() const { return reinterpret_cast<const plUInt16*>(m_pFirstChild); } // [tested]
78
80 PL_ALWAYS_INLINE const plUInt32* GetPrimitivesUInt32() const { return reinterpret_cast<const plUInt32*>(m_pFirstChild); } // [tested]
81
83 PL_ALWAYS_INLINE const plUInt64* GetPrimitivesUInt64() const { return reinterpret_cast<const plUInt64*>(m_pFirstChild); } // [tested]
84
86 PL_ALWAYS_INLINE const float* GetPrimitivesFloat() const { return reinterpret_cast<const float*>(m_pFirstChild); } // [tested]
87
89 PL_ALWAYS_INLINE const double* GetPrimitivesDouble() const { return reinterpret_cast<const double*>(m_pFirstChild); } // [tested]
90
92 PL_ALWAYS_INLINE const plStringView* GetPrimitivesString() const { return reinterpret_cast<const plStringView*>(m_pFirstChild); } // [tested]
93
96 const plOpenDdlReaderElement* FindChild(plStringView sName) const; // [tested]
97
99 const plOpenDdlReaderElement* FindChildOfType(plOpenDdlPrimitiveType type, plStringView sName, plUInt32 uiMinNumberOfPrimitives = 1) const;
100
102 const plOpenDdlReaderElement* FindChildOfType(plStringView sType, plStringView sName = nullptr) const;
103
104private:
105 friend class plOpenDdlReader;
106
107 plOpenDdlPrimitiveType m_PrimitiveType = plOpenDdlPrimitiveType::Custom;
108 plUInt32 m_uiNumChildElements = 0;
109 const void* m_pFirstChild = nullptr;
110 const plOpenDdlReaderElement* m_pLastChild = nullptr;
111 plStringView m_sCustomType;
112 plStringView m_sName;
113 const plOpenDdlReaderElement* m_pSiblingElement = nullptr;
114};
115
117class PL_FOUNDATION_DLL plOpenDdlReader : public plOpenDdlParser
118{
119public:
122
130 plResult ParseDocument(plStreamReader& inout_stream, plUInt32 uiFirstLineOffset = 0, plLogInterface* pLog = plLog::GetThreadLocalLogSystem(),
131 plUInt32 uiCacheSizeInKB = 4); // [tested]
132
134 const plOpenDdlReaderElement* GetRootElement() const; // [tested]
135
137 const plOpenDdlReaderElement* FindElement(plStringView sGlobalName) const; // [tested]
138
139protected:
140 virtual void OnBeginObject(plStringView sType, plStringView sName, bool bGlobalName) override;
141 virtual void OnEndObject() override;
142
143 virtual void OnBeginPrimitiveList(plOpenDdlPrimitiveType type, plStringView sName, bool bGlobalName) override;
144 virtual void OnEndPrimitiveList() override;
145
146 virtual void OnPrimitiveBool(plUInt32 count, const bool* pData, bool bThisIsAll) override;
147
148 virtual void OnPrimitiveInt8(plUInt32 count, const plInt8* pData, bool bThisIsAll) override;
149 virtual void OnPrimitiveInt16(plUInt32 count, const plInt16* pData, bool bThisIsAll) override;
150 virtual void OnPrimitiveInt32(plUInt32 count, const plInt32* pData, bool bThisIsAll) override;
151 virtual void OnPrimitiveInt64(plUInt32 count, const plInt64* pData, bool bThisIsAll) override;
152
153 virtual void OnPrimitiveUInt8(plUInt32 count, const plUInt8* pData, bool bThisIsAll) override;
154 virtual void OnPrimitiveUInt16(plUInt32 count, const plUInt16* pData, bool bThisIsAll) override;
155 virtual void OnPrimitiveUInt32(plUInt32 count, const plUInt32* pData, bool bThisIsAll) override;
156 virtual void OnPrimitiveUInt64(plUInt32 count, const plUInt64* pData, bool bThisIsAll) override;
157
158 virtual void OnPrimitiveFloat(plUInt32 count, const float* pData, bool bThisIsAll) override;
159 virtual void OnPrimitiveDouble(plUInt32 count, const double* pData, bool bThisIsAll) override;
160
161 virtual void OnPrimitiveString(plUInt32 count, const plStringView* pData, bool bThisIsAll) override;
162
163 virtual void OnParsingError(plStringView sMessage, bool bFatal, plUInt32 uiLine, plUInt32 uiColumn) override;
164
165protected:
166 plOpenDdlReaderElement* CreateElement(plOpenDdlPrimitiveType type, plStringView sType, plStringView sName, bool bGlobalName);
167 plStringView CopyString(const plStringView& string);
168 void StorePrimitiveData(bool bThisIsAll, plUInt32 bytecount, const plUInt8* pData);
169
170 void ClearDataChunks();
171 plUInt8* AllocateBytes(plUInt32 uiNumBytes);
172
173 static constexpr plUInt32 s_uiChunkSize = 1000 * 4; // 4 KiB
174
175 plHybridArray<plUInt8*, 16> m_DataChunks;
176 plUInt8* m_pCurrentChunk;
177 plUInt32 m_uiBytesInChunkLeft;
178
179 plDynamicArray<plUInt8> m_TempCache;
180
183
184 plDeque<plString> m_Strings;
185
187};
Definition Deque.h:270
Definition DynamicArray.h:81
A hybrid array uses in-place storage to handle the first few elements without any allocation....
Definition HybridArray.h:12
static plLogInterface * GetThreadLocalLogSystem()
Returns the currently set default logging system, or a thread local instance of plGlobalLog,...
Definition Log.cpp:345
Base class for all logging classes.
Definition Log.h:77
Definition Map.h:408
A low level parser for the OpenDDL format. It can incrementally parse the structure,...
Definition OpenDdlParser.h:35
Represents a single 'object' in a DDL document, e.g. either a custom type or a primitives list.
Definition OpenDdlReader.h:11
PL_ALWAYS_INLINE const plOpenDdlReaderElement * GetSibling() const
If the parent is a custom type element, the next child after this is returned.
Definition OpenDdlReader.h:46
PL_ALWAYS_INLINE const plInt64 * GetPrimitivesInt64() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:71
PL_ALWAYS_INLINE const plInt8 * GetPrimitivesInt8() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:62
PL_ALWAYS_INLINE const plStringView * GetPrimitivesString() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:92
PL_ALWAYS_INLINE const plUInt8 * GetPrimitivesUInt8() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:74
PL_ALWAYS_INLINE const plUInt32 * GetPrimitivesUInt32() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:80
PL_ALWAYS_INLINE const double * GetPrimitivesDouble() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:89
PL_ALWAYS_INLINE bool IsCustomType() const
Whether this is a custom object type that typically contains sub-elements.
Definition OpenDdlReader.h:16
PL_ALWAYS_INLINE const bool * GetPrimitivesBool() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:59
PL_ALWAYS_INLINE const plUInt16 * GetPrimitivesUInt16() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:77
PL_ALWAYS_INLINE const plUInt64 * GetPrimitivesUInt64() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:83
PL_ALWAYS_INLINE plStringView GetName() const
Returns the name of the object.
Definition OpenDdlReader.h:31
PL_ALWAYS_INLINE bool HasName() const
Whether the name of the object is non-empty.
Definition OpenDdlReader.h:28
PL_ALWAYS_INLINE const plOpenDdlReaderElement * GetFirstChild() const
If this is a custom type element, the returned pointer is to the first child element.
Definition OpenDdlReader.h:40
PL_ALWAYS_INLINE bool IsNameGlobal() const
Returns whether the element name is a global or a local name.
Definition OpenDdlReader.h:34
PL_ALWAYS_INLINE plStringView GetCustomType() const
Returns the string for the custom type name.
Definition OpenDdlReader.h:25
PL_ALWAYS_INLINE plOpenDdlPrimitiveType GetPrimitivesType() const
For non-custom types this returns the type of primitive that is stored at this element.
Definition OpenDdlReader.h:52
PL_ALWAYS_INLINE const plInt16 * GetPrimitivesInt16() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:65
PL_ALWAYS_INLINE const float * GetPrimitivesFloat() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:86
PL_ALWAYS_INLINE bool IsCustomType(plStringView sTypeName) const
Whether this is a custom object type of the requested type.
Definition OpenDdlReader.h:19
PL_ALWAYS_INLINE const plInt32 * GetPrimitivesInt32() const
Returns a pointer to the primitive data cast to a specific type. Only valid if GetPrimitivesType() ac...
Definition OpenDdlReader.h:68
An OpenDDL reader parses an entire DDL document and creates an in-memory representation of the docume...
Definition OpenDdlReader.h:118
Interface for binary in (read) streams.
Definition Stream.h:22
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54