21 #define STDCOMPILER_EXCEPTION_WORKAROUND
77 virtual bool Name(
const char *szName) {
return true; }
78 virtual void NameEnd(
bool fBreak =
false) { }
88 virtual bool Default(
const char *szName) {
return true; }
91 virtual int NameCount(
const char *szName =
nullptr) { assert(
false);
return 0; }
124 virtual void DWord(int32_t &rInt) = 0;
125 virtual void DWord(uint32_t &rInt) = 0;
126 virtual void Word(int16_t &rShort) = 0;
127 virtual void Word(uint16_t &rShort) = 0;
128 virtual void Byte(int8_t &rByte) = 0;
129 virtual void Byte(uint8_t &rByte) = 0;
161 template <
class T>
void Value(
const T &rStruct) { rStruct.CompileFunc(
this); }
173 template <
class T>
inline void Compile(T &&rStruct)
178 template <
class T>
inline void Decompile(
const T &rStruct)
235 #ifdef STDCOMPILER_EXCEPTION_WORKAROUND
237 if (fFailSafe) { fFail =
true;
return; }
240 va_list args; va_start(args, szMessage);
243 void excEOF(
const char *szMessage =
"EOF", ...)
246 va_list args; va_start(args, szMessage);
252 va_list args; va_start(args, szMessage);
259 #ifdef STDCOMPILER_EXCEPTION_WORKAROUND
260 bool fFailSafe{
false}, fFail{
false};
262 void beginFailSafe() { fFailSafe =
true; fFail =
false; }
263 bool endFailSafe() { fFailSafe =
false;
return !fFail; }
266 template <
class T>
bool ValueSafe(
const T &rStruct) { rStruct.CompileFunc(
this);
return true; }
267 template <
class T>
bool ValueSafe(T &rStruct) {
CompileFunc(rStruct,
this);
return true; }
269 bool ValueSafe(int32_t &rInt) { beginFailSafe();
DWord(rInt);
return endFailSafe(); }
270 bool ValueSafe(uint32_t &rInt) { beginFailSafe();
DWord(rInt);
return endFailSafe(); }
271 bool ValueSafe(int16_t &rInt) { beginFailSafe();
Word(rInt);
return endFailSafe(); }
272 bool ValueSafe(uint16_t &rInt) { beginFailSafe();
Word(rInt);
return endFailSafe(); }
273 bool ValueSafe(int8_t &rInt) { beginFailSafe();
Byte(rInt);
return endFailSafe(); }
274 bool ValueSafe(uint8_t &rInt) { beginFailSafe();
Byte(rInt);
return endFailSafe(); }
275 bool ValueSafe(
bool &rBool) { beginFailSafe();
Boolean(rBool);
return endFailSafe(); }
281 typedef void (*
WarnCBT)(
void *,
const char *,
const char *);
283 void Warn(
const char *szWarning, ...);
289 void *pWarnData{
nullptr};
311 rStruct.CompileFunc(pComp);
327 std::unique_ptr<T> temp(
new T);
330 pStruct = temp.release();
333 template <
class T,
typename ... P>
341 std::unique_ptr<T> temp(
new T);
344 pStruct = temp.release();
347 template <
class T,
class ContextT>
356 std::unique_ptr<T> temp(
new T(rCtx));
359 pStruct = temp.release();
362 template <
class T,
class ContextT,
class P>
371 std::unique_ptr<T> temp(
new T(rCtx));
374 pStruct = temp.release();
378 template <
class CompT,
class StructT>
382 Compiler.setInput(SrcBuf.getRef());
383 Compiler.Compile(TargetStruct);
385 template <
class CompT,
class StructT>
388 StructT *pStruct =
nullptr;
392 template <
class CompT,
class StructT>
395 StructT *pStruct =
nullptr;
399 template <
class CompT,
class StructT>
403 Compiler.Decompile(SrcStruct);
404 return Compiler.getOutput();
420 bool Name(
const char *szName)
override {
return false; }
421 int NameCount(
const char *szName =
nullptr)
override {
return 0; }
424 void DWord(int32_t &rInt)
override { }
425 void DWord(uint32_t &rInt)
override { }
426 void Word(int16_t &rShort)
override { }
427 void Word(uint16_t &rShort)
override { }
428 void Byte(int8_t &rByte)
override { }
429 void Byte(uint8_t &rByte)
override { }
456 void DWord(int32_t &rInt)
override;
457 void DWord(uint32_t &rInt)
override;
458 void Word(int16_t &rShort)
override;
459 void Word(uint16_t &rShort)
override;
460 void Byte(int8_t &rByte)
override;
461 void Byte(uint8_t &rByte)
override;
462 void Boolean(
bool &rBool)
override;
470 void Begin()
override;
480 template <
class T>
void WriteValue(
const T &rValue);
497 void DWord(int32_t &rInt)
override;
498 void DWord(uint32_t &rInt)
override;
499 void Word(int16_t &rShort)
override;
500 void Word(uint16_t &rShort)
override;
501 void Byte(int8_t &rByte)
override;
502 void Byte(uint8_t &rByte)
override;
503 void Boolean(
bool &rBool)
override;
514 void Begin()
override;
526 template <
class T>
void ReadValue(T &rValue);
569 bool Name(
const char *szName)
override;
570 void NameEnd(
bool fBreak =
false)
override;
576 void DWord(int32_t &rInt)
override;
577 void DWord(uint32_t &rInt)
override;
578 void Word(int16_t &rShort)
override;
579 void Word(uint16_t &rShort)
override;
580 void Byte(int8_t &rByte)
override;
581 void Byte(uint8_t &rByte)
override;
582 void Boolean(
bool &rBool)
override;
591 void Begin()
override;
615 void WriteEscaped(
const char *szString,
const char *pEnd);
637 bool Name(
const char *szName)
override;
638 void NameEnd(
bool fBreak =
false)
override;
647 int NameCount(
const char *szName =
nullptr)
override;
650 void DWord(int32_t &rInt)
override;
651 void DWord(uint32_t &rInt)
override;
652 void Word(int16_t &rShort)
override;
653 void Word(uint16_t &rShort)
override;
654 void Byte(int8_t &rByte)
override;
655 void Byte(uint8_t &rByte)
override;
656 void Boolean(
bool &rBool)
override;
667 void Begin()
override;
730 uint32_t getLineNumberOfPos(
const char *pos)
const;
731 mutable std::vector<const char *> lineBreaks;
736 template <
class CompT,
class StructT>
737 bool CompileFromBuf_Log(StructT &&TargetStruct,
const typename CompT::InT &SrcBuf,
const char *szName)
741 CompileFromBuf<CompT>(TargetStruct, SrcBuf);
754 template <
class CompT,
class StructT>
760 Compiler.setInput(SrcBuf.getRef());
762 Compiler.Compile(TargetStruct);
775 template <
class CompT,
class StructT>
778 if (!pOut)
return false;
781 pOut->Take(DecompileToBuf<CompT>(TargetStruct));
bool LogF(const char *strMessage,...)
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
StdStrBuf FormatStringV(const char *szFmt, va_list args)
StructT * CompileFromBufToNewNamed(const typename CompT::InT &SrcBuf, const char *szName)
void CompileNewFuncCtx(T *&pStruct, StdCompiler *pComp, const ContextT &rCtx)
bool DecompileToBuf_Log(StructT &&TargetStruct, typename CompT::OutT *pOut, const char *szName)
StructT * CompileFromBufToNew(const typename CompT::InT &SrcBuf)
void CompileFunc(T &rStruct, StdCompiler *pComp)
bool CompileFromBuf_LogWarn(StructT &&TargetStruct, const typename CompT::InT &SrcBuf, const char *szName)
void CompileNewFunc(T *&pStruct, StdCompiler *pComp)
bool CompileFromBuf_Log(StructT &&TargetStruct, const typename CompT::InT &SrcBuf, const char *szName)
void StdCompilerWarnCallback(void *pData, const char *szPosition, const char *szError)
CompT::OutT DecompileToBuf(const StructT &SrcStruct)
void CompileFromBuf(StructT &&TargetStruct, const typename CompT::InT &SrcBuf)
void ReadValue(T &rValue)
void DWord(int32_t &rInt) override
void Raw(void *pData, size_t iSize, RawCompileType eType=RCT_Escaped) override
StdStrBuf getPosition() const override
void Byte(int8_t &rByte) override
void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped) override
void Word(int16_t &rShort) override
size_t getRemainingBytes()
bool isDeserializer() override
void Character(char &rChar) override
void Boolean(bool &rBool) override
void DWord(int32_t &rInt) override
void BeginSecond() override
void Boolean(bool &rBool) override
void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped) override
bool isDoublePass() override
void Byte(int8_t &rByte) override
void WriteValue(const T &rValue)
void WriteData(const void *pData, size_t iSize)
void Character(char &rChar) override
void Raw(void *pData, size_t iSize, RawCompileType eType=RCT_Escaped) override
void Word(int16_t &rShort) override
virtual void String(std::string &str, RawCompileType type=RCT_Escaped)=0
virtual void String(char **pszString, RawCompileType eType=RCT_Escaped)=0
void Decompile(const T &rStruct)
void Value(int16_t &rInt)
virtual void Raw(void *pData, size_t iSize, RawCompileType eType=RCT_Escaped)=0
virtual bool Separator(Sep eSep=SEP_SEP)
virtual void BeginSecond()
static bool IsStringEnd(char c, RawCompileType eType)
virtual void Character(char &rChar)=0
static char SeparatorToChar(Sep eSep)
virtual bool Default(const char *szName)
void Value(uint32_t &rInt)
void excCorrupt(const char *szMessage,...)
virtual void Word(int16_t &rShort)=0
virtual void NoSeparator()
void Value(const T &rStruct)
virtual void NameEnd(bool fBreak=false)
virtual ~StdCompiler()=default
virtual void Byte(int8_t &rByte)=0
virtual bool isDoublePass()
virtual void DWord(uint32_t &rInt)=0
void Value(uint16_t &rInt)
virtual StdStrBuf getPosition() const
void Value(int32_t &rInt)
virtual bool FollowName(const char *szName)
void Value(uint8_t &rInt)
void DoCompilation(T &rStruct)
void(* WarnCBT)(void *, const char *, const char *)
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0
virtual void DWord(int32_t &rInt)=0
void excNotFound(const char *szMessage,...)
void Warn(const char *szWarning,...)
virtual bool isDeserializer()
virtual void Byte(uint8_t &rByte)=0
virtual int NameCount(const char *szName=nullptr)
void Compile(T &&rStruct)
virtual const char * GetNameByIndex(size_t idx) const
virtual bool isRegistry()
virtual void Word(uint16_t &rShort)=0
virtual void setRuntimeWritesAllowed(int32_t iChange)
virtual void Boolean(bool &rBool)=0
virtual bool Name(const char *szName)
void setWarnCallback(WarnCBT pnWarnCB, void *pData)
void excEOF(const char *szMessage="EOF",...)
bool Name(const char *szName) override
StdStrBuf getPosition() const override
size_t GetStringLength(RawCompileType eTyped)
void Raw(void *pData, size_t iSize, RawCompileType eType=RCT_Escaped) override
bool hasNaming() override
StdCopyStrBuf NotFoundName
const char * GetNameByIndex(size_t idx) const override
void notFound(const char *szWhat)
void setInput(const InT &In)
void FreeNameNode(NameNode *pNode)
bool isDeserializer() override
int NameCount(const char *szName=nullptr) override
void Byte(int8_t &rByte) override
void NameEnd(bool fBreak=false) override
void Word(int16_t &rShort) override
bool Separator(Sep eSep) override
~StdCompilerINIRead() override
StdBuf ReadString(size_t iLength, RawCompileType eTyped, bool fAppendNull=true)
void Character(char &rChar) override
void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped) override
void DWord(int32_t &rInt) override
void NoSeparator() override
bool TestStringEnd(RawCompileType eType)
bool FollowName(const char *szName) override
void Boolean(bool &rBool) override
void PutName(bool fSection)
void Boolean(bool &rBool) override
void NameEnd(bool fBreak=false) override
void WriteIndent(bool fSectionName)
void Byte(int8_t &rByte) override
bool Name(const char *szName) override
void Word(int16_t &rShort) override
void Raw(void *pData, size_t iSize, RawCompileType eType=RCT_Escaped) override
void DWord(int32_t &rInt) override
bool Separator(Sep eSep) override
void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped) override
void Character(char &rChar) override
void WriteEscaped(const char *szString, const char *pEnd)
bool hasNaming() override
void StringN(const char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)
void Byte(int8_t &rByte) override
void Raw(void *pData, size_t iSize, RawCompileType eType=RCT_Escaped) override
bool Name(const char *szName) override
bool hasNaming() override
void Boolean(bool &rBool) override
void DWord(int32_t &rInt) override
void String(std::string &str, RawCompileType eType=RCT_Escaped) override
void Word(uint16_t &rShort) override
int NameCount(const char *szName=nullptr) override
void DWord(uint32_t &rInt) override
void Byte(uint8_t &rByte) override
void Character(char &rChar) override
void Word(int16_t &rShort) override
void String(char **pszString, RawCompileType eType=RCT_Escaped) override
bool isDeserializer() override
void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped) override
void Ref(const char *pnData)
const char * getData() const
Exception(StdStrBuf Pos, StdStrBuf Msg)
NameNode(NameNode *pParent=nullptr)