OpenClonk
StdCompiler.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  StdCompiler
 
struct  StdCompiler::Exception
 
class  StdCompiler::NotFoundException
 
class  StdCompiler::EOFException
 
class  StdCompiler::CorruptException
 
class  StdCompilerNull
 
class  StdCompilerBinWrite
 
class  StdCompilerBinRead
 
class  StdCompilerINIWrite
 
struct  StdCompilerINIWrite::Naming
 
class  StdCompilerINIRead
 
struct  StdCompilerINIRead::NameNode
 

Functions

template<class T >
void CompileFunc (T &rStruct, StdCompiler *pComp)
 
void CompileFunc (std::string &s, StdCompiler *comp)
 
template<class T >
void CompileNewFunc (T *&pStruct, StdCompiler *pComp)
 
template<class T , typename ... P>
void CompileNewFunc (T *&pStruct, StdCompiler *pComp, P &&... pars)
 
template<class T , class ContextT >
void CompileNewFuncCtx (T *&pStruct, StdCompiler *pComp, const ContextT &rCtx)
 
template<class T , class ContextT , class P >
void CompileNewFuncCtx (T *&pStruct, StdCompiler *pComp, const ContextT &rCtx, const P &rPar)
 
template<class CompT , class StructT >
void CompileFromBuf (StructT &&TargetStruct, const typename CompT::InT &SrcBuf)
 
template<class CompT , class StructT >
StructT * CompileFromBufToNew (const typename CompT::InT &SrcBuf)
 
template<class CompT , class StructT >
StructT * CompileFromBufToNewNamed (const typename CompT::InT &SrcBuf, const char *szName)
 
template<class CompT , class StructT >
CompT::OutT DecompileToBuf (const StructT &SrcStruct)
 
void StdCompilerWarnCallback (void *pData, const char *szPosition, const char *szError)
 
template<class CompT , class StructT >
bool CompileFromBuf_Log (StructT &&TargetStruct, const typename CompT::InT &SrcBuf, const char *szName)
 
template<class CompT , class StructT >
bool CompileFromBuf_LogWarn (StructT &&TargetStruct, const typename CompT::InT &SrcBuf, const char *szName)
 
template<class CompT , class StructT >
bool DecompileToBuf_Log (StructT &&TargetStruct, typename CompT::OutT *pOut, const char *szName)
 

Class Documentation

◆ StdCompilerINIWrite::Naming

struct StdCompilerINIWrite::Naming

Definition at line 600 of file StdCompiler.h.

Collaboration diagram for StdCompilerINIWrite::Naming:
[legend]
Class Members
StdStrBuf Name
Naming * Parent

Function Documentation

◆ CompileFromBuf()

template<class CompT , class StructT >
void CompileFromBuf ( StructT &&  TargetStruct,
const typename CompT::InT &  SrcBuf 
)

Definition at line 379 of file StdCompiler.h.

380 {
381  CompT Compiler;
382  Compiler.setInput(SrcBuf.getRef());
383  Compiler.Compile(TargetStruct);
384 }

◆ CompileFromBuf_Log()

template<class CompT , class StructT >
bool CompileFromBuf_Log ( StructT &&  TargetStruct,
const typename CompT::InT &  SrcBuf,
const char *  szName 
)

Definition at line 737 of file StdCompiler.h.

738 {
739  try
740  {
741  CompileFromBuf<CompT>(TargetStruct, SrcBuf);
742  return true;
743  }
744  catch (StdCompiler::Exception *pExc)
745  {
746  if (!pExc->Pos.getLength())
747  LogF("ERROR: %s (in %s)", pExc->Msg.getData(), szName);
748  else
749  LogF("ERROR: %s (in %s, %s)", pExc->Msg.getData(), pExc->Pos.getData(), szName);
750  delete pExc;
751  return false;
752  }
753 }
bool LogF(const char *strMessage,...)
Definition: C4Log.cpp:262
const char * getData() const
Definition: StdBuf.h:442
size_t getLength() const
Definition: StdBuf.h:445

References StdStrBuf::getData(), StdStrBuf::getLength(), LogF(), StdCompiler::Exception::Msg, and StdCompiler::Exception::Pos.

Here is the call graph for this function:

◆ CompileFromBuf_LogWarn()

template<class CompT , class StructT >
bool CompileFromBuf_LogWarn ( StructT &&  TargetStruct,
const typename CompT::InT &  SrcBuf,
const char *  szName 
)

Definition at line 755 of file StdCompiler.h.

756 {
757  try
758  {
759  CompT Compiler;
760  Compiler.setInput(SrcBuf.getRef());
761  Compiler.setWarnCallback(StdCompilerWarnCallback, reinterpret_cast<void *>(const_cast<char *>(szName)));
762  Compiler.Compile(TargetStruct);
763  return true;
764  }
765  catch (StdCompiler::Exception *pExc)
766  {
767  if (!pExc->Pos.getLength())
768  LogF("ERROR: %s (in %s)", pExc->Msg.getData(), szName);
769  else
770  LogF("ERROR: %s (in %s, %s)", pExc->Msg.getData(), pExc->Pos.getData(), szName);
771  delete pExc;
772  return false;
773  }
774 }
void StdCompilerWarnCallback(void *pData, const char *szPosition, const char *szError)

References StdStrBuf::getData(), StdStrBuf::getLength(), LogF(), StdCompiler::Exception::Msg, StdCompiler::Exception::Pos, and StdCompilerWarnCallback().

Here is the call graph for this function:

◆ CompileFromBufToNew()

template<class CompT , class StructT >
StructT* CompileFromBufToNew ( const typename CompT::InT &  SrcBuf)

Definition at line 386 of file StdCompiler.h.

387 {
388  StructT *pStruct = nullptr;
389  CompileFromBuf<CompT>(mkPtrAdaptNoNull(pStruct), SrcBuf);
390  return pStruct;
391 }
StdPtrAdapt< T > mkPtrAdaptNoNull(T *&rpObj)
Definition: StdAdaptors.h:638

References mkPtrAdaptNoNull().

Here is the call graph for this function:

◆ CompileFromBufToNewNamed()

template<class CompT , class StructT >
StructT* CompileFromBufToNewNamed ( const typename CompT::InT &  SrcBuf,
const char *  szName 
)

Definition at line 393 of file StdCompiler.h.

394 {
395  StructT *pStruct = nullptr;
396  CompileFromBuf<CompT>(mkNamingAdapt(mkPtrAdaptNoNull(pStruct), szName), SrcBuf);
397  return pStruct;
398 }
StdNamingAdapt< T > mkNamingAdapt(T &&rValue, const char *szName)
Definition: StdAdaptors.h:92

References mkNamingAdapt(), and mkPtrAdaptNoNull().

Here is the call graph for this function:

◆ CompileFunc() [1/2]

void CompileFunc ( std::string &  s,
StdCompiler comp 
)
inline

Definition at line 314 of file StdCompiler.h.

315 {
316  comp->String(s);
317 }
#define s
virtual void String(char *szString, size_t iMaxLength, RawCompileType eType=RCT_Escaped)=0

References s, and StdCompiler::String().

Here is the call graph for this function:

◆ CompileFunc() [2/2]

template<class T >
void CompileFunc ( T &  rStruct,
StdCompiler pComp 
)
inline

Definition at line 301 of file StdCompiler.h.

302 {
303  // If the compiler doesn't like this line, you tried to compile
304  // something the compiler doesn't know how to handle.
305  // Possible reasons:
306  // a) You are compiling a class/structure without a CompileFunc
307  // (you may add a specialization of this function, too)
308  // b) You are trying to compile a pointer. Use a PtrAdapt instead.
309  // c) You are trying to compile a simple value that has no
310  // fixed representation (float, int). Use safe types instead.
311  rStruct.CompileFunc(pComp);
312 }

Referenced by StdCompiler::Value().

Here is the caller graph for this function:

◆ CompileNewFunc() [1/2]

template<class T >
void CompileNewFunc ( T *&  pStruct,
StdCompiler pComp 
)

Definition at line 320 of file StdCompiler.h.

321 {
322  // Create new object.
323  // If this line doesn't compile, you either have to
324  // a) Define a standard constructor for T
325  // b) Specialize this function to do whatever the correct
326  // behaviour is to construct the object from compiler data
327  std::unique_ptr<T> temp(new T); // exception-safety
328  // Compile
329  pComp->Value(*temp);
330  pStruct = temp.release();
331 }
void Value(const T &rStruct)
Definition: StdCompiler.h:161

References StdCompiler::Value().

Referenced by StdPtrAdaptCompileNewFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileNewFunc() [2/2]

template<class T , typename ... P>
void CompileNewFunc ( T *&  pStruct,
StdCompiler pComp,
P &&...  pars 
)

Definition at line 334 of file StdCompiler.h.

335 {
336  // Create new object.
337  // If this line doesn't compile, you either have to
338  // a) Define a standard constructor for T
339  // b) Specialize this function to do whatever the correct
340  // behaviour is to construct the object from compiler data
341  std::unique_ptr<T> temp(new T); // exception-safety
342  // Compile
343  pComp->Value(mkParAdapt(*temp, std::forward<P>(pars)...));
344  pStruct = temp.release();
345 }
StdParameterAdapt< T, P > mkParAdapt(T &&rObj, P &&rPar)
Definition: StdAdaptors.h:490

References mkParAdapt(), and StdCompiler::Value().

Here is the call graph for this function:

◆ CompileNewFuncCtx() [1/2]

template<class T , class ContextT >
void CompileNewFuncCtx ( T *&  pStruct,
StdCompiler pComp,
const ContextT &  rCtx 
)

Definition at line 348 of file StdCompiler.h.

349 {
350  // Create new object.
351  // If this line doesn't compile, you either have to
352  // a) Define an appropriate constructor for T
353  // b) Specialize this function to do whatever the correct
354  // behaviour is to construct the object from compiler data
355  // and context
356  std::unique_ptr<T> temp(new T(rCtx)); // exception-safety
357  // Compile
358  pComp->Value(*temp);
359  pStruct = temp.release();
360 }

References StdCompiler::Value().

Referenced by StdPtrAdaptCompileNewFunc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CompileNewFuncCtx() [2/2]

template<class T , class ContextT , class P >
void CompileNewFuncCtx ( T *&  pStruct,
StdCompiler pComp,
const ContextT &  rCtx,
const P &  rPar 
)

Definition at line 363 of file StdCompiler.h.

364 {
365  // Create new object.
366  // If this line doesn't compile, you either have to
367  // a) Define an appropriate constructor for T
368  // b) Specialize this function to do whatever the correct
369  // behaviour is to construct the object from compiler data
370  // and context
371  std::unique_ptr<T> temp(new T(rCtx)); // exception-safety
372  // Compile
373  pComp->Value(mkParAdapt(*temp, rPar));
374  pStruct = temp.release();
375 }

References mkParAdapt(), and StdCompiler::Value().

Here is the call graph for this function:

◆ DecompileToBuf()

template<class CompT , class StructT >
CompT::OutT DecompileToBuf ( const StructT &  SrcStruct)

Definition at line 400 of file StdCompiler.h.

401 {
402  CompT Compiler;
403  Compiler.Decompile(SrcStruct);
404  return Compiler.getOutput();
405 }

◆ DecompileToBuf_Log()

template<class CompT , class StructT >
bool DecompileToBuf_Log ( StructT &&  TargetStruct,
typename CompT::OutT *  pOut,
const char *  szName 
)

Definition at line 776 of file StdCompiler.h.

777 {
778  if (!pOut) return false;
779  try
780  {
781  pOut->Take(DecompileToBuf<CompT>(TargetStruct));
782  return true;
783  }
784  catch (StdCompiler::Exception *pExc)
785  {
786  LogF("ERROR: %s (in %s)", pExc->Msg.getData(), szName);
787  delete pExc;
788  return false;
789  }
790 }

References StdStrBuf::getData(), LogF(), and StdCompiler::Exception::Msg.

Here is the call graph for this function:

◆ StdCompilerWarnCallback()

void StdCompilerWarnCallback ( void *  pData,
const char *  szPosition,
const char *  szError 
)

Definition at line 1036 of file StdCompiler.cpp.

1037 {
1038  const char *szName = reinterpret_cast<const char *>(pData);
1039  if (!szPosition || !*szPosition)
1040  DebugLogF("WARNING: %s (in %s)", szError, szName);
1041  else
1042  DebugLogF("WARNING: %s (in %s, %s)", szError, szPosition, szName);
1043 }
bool DebugLogF(const char *strMessage ...)
Definition: C4Log.cpp:290

References DebugLogF().

Referenced by CompileFromBuf_LogWarn().

Here is the call graph for this function:
Here is the caller graph for this function: