OGRE  1.12.13
Object-Oriented Graphics Rendering Engine
Ogre::CPreprocessor Class Reference

This is a simplistic C/C++-like preprocessor. More...

#include <OgreGLSLPreprocessor.h>

Public Member Functions

 CPreprocessor ()
 Create an empty preprocessor object. More...
 
virtual ~CPreprocessor ()
 Destroy the preprocessor object. More...
 
void Define (const char *iMacroName, size_t iMacroNameLen)
 Define a symbolical macro. More...
 
void Define (const char *iMacroName, size_t iMacroNameLen, const char *iMacroValue, size_t iMacroValueLen)
 Define a macro without parameters. More...
 
char * Parse (const char *iSource, size_t iLength, size_t &oLength)
 Parse the input string and return a newly-allocated output string. More...
 
bool Undef (const char *iMacroName, size_t iMacroNameLen)
 Undefine a macro. More...
 

Detailed Description

This is a simplistic C/C++-like preprocessor.

It takes an non-zero-terminated string on input and outputs a non-zero-terminated string buffer.

This preprocessor was designed specifically for GLSL shaders, so if you want to use it for other purposes you might want to check if the feature set it provides is enough for you.

Here's a list of supported features:

  • Fast memory allocation-less operation (mostly).
  • Line continuation (backslash-newline) is swallowed.
  • Line numeration is fully preserved by inserting empty lines where required. This is crucial if, say, GLSL compiler reports you an error with a line number.
  • #define: Parametrized and non-parametrized macros. Invoking a macro with less arguments than it takes assignes empty values to missing arguments.
  • #undef: Forget defined macros
  • #ifdef / #ifndef / #else / #endif: Conditional suppression of parts of code.
  • #if: Supports numeric expression of any complexity, also supports the defined() pseudo-function.

Constructor & Destructor Documentation

◆ CPreprocessor()

Ogre::CPreprocessor::CPreprocessor ( )

Create an empty preprocessor object.

◆ ~CPreprocessor()

virtual Ogre::CPreprocessor::~CPreprocessor ( )
virtual

Destroy the preprocessor object.

Member Function Documentation

◆ Define() [1/2]

void Ogre::CPreprocessor::Define ( const char *  iMacroName,
size_t  iMacroNameLen,
const char *  iMacroValue,
size_t  iMacroValueLen 
)

Define a macro without parameters.

Parameters
iMacroNameThe name of the defined macro
iMacroNameLenThe length of the name of the defined macro
iMacroValueThe value of the defined macro
iMacroValueLenThe length of the value of the defined macro

◆ Define() [2/2]

void Ogre::CPreprocessor::Define ( const char *  iMacroName,
size_t  iMacroNameLen 
)

Define a symbolical macro.

Parameters
iMacroNameThe name of the defined macro
iMacroNameLenThe length of the name of the defined macro

◆ Undef()

bool Ogre::CPreprocessor::Undef ( const char *  iMacroName,
size_t  iMacroNameLen 
)

Undefine a macro.

Parameters
iMacroNameThe name of the macro to undefine
iMacroNameLenThe length of the name of the macro to undefine
Returns
true if the macro has been undefined, false if macro doesn't exist

◆ Parse()

char* Ogre::CPreprocessor::Parse ( const char *  iSource,
size_t  iLength,
size_t &  oLength 
)

Parse the input string and return a newly-allocated output string.

Note
The returned preprocessed string is NOT zero-terminated (just like the input string).
Parameters
iSourceThe source text
iLengthThe length of the source text in characters
oLengthThe length of the output string.
Returns
The output from preprocessor, allocated with malloc(). The parser can actually allocate more than needed for performance reasons, but this should not be a problem unless you will want to store the returned pointer for long time in which case you might want to realloc() it. If an error has been encountered, the function returns NULL. In some cases the function may return an unallocated address that's inside the source buffer. You must free() the result string only if the returned address is not inside the source text.

The documentation for this class was generated from the following file: