OGRE-Next: Ogre::CPreprocessor Class Reference

| OGRE-Next 3.0.0 Object-Oriented Graphics Rendering Engine

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Static Public Attributes | List of all members
Ogre::CPreprocessor Class Reference

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

`#include <OgreGLSLESPreprocessor.h>`

## Public Types
typedef void(* | ErrorHandlerFunc) (void *iData, int iLine, const char *iError, const char *iToken, size_t iTokenLen)
| An error handler function type.
typedef void(* | ErrorHandlerFunc) (void *iData, int iLine, const char *iError, const char *iToken, size_t iTokenLen)
| An error handler function type.

## Public Member Functions
| CPreprocessor ()
| Create an empty preprocessor object.
| CPreprocessor ()
| Create an empty preprocessor object.
virtual | ~CPreprocessor ()
| Destroy the preprocessor object.
virtual | ~CPreprocessor ()
| Destroy the preprocessor object.
void | Define (const char *iMacroName, size_t iMacroNameLen, const char *iMacroValue, size_t iMacroValueLen)
| Define a macro without parameters.
void | Define (const char *iMacroName, size_t iMacroNameLen, const char *iMacroValue, size_t iMacroValueLen)
| Define a macro without parameters.
void | Define (const char *iMacroName, size_t iMacroNameLen, long iMacroValue)
| Define a numerical macro.
void | Define (const char *iMacroName, size_t iMacroNameLen, long iMacroValue)
| Define a numerical macro.
char * | Parse (const char *iSource, size_t iLength, size_t &oLength)
| Parse the input string and return a newly-allocated output string.
char * | Parse (const char *iSource, size_t iLength, size_t &oLength)
| Parse the input string and return a newly-allocated output string.
bool | ParsePreamble (const char *iSource, size_t iLength)
| Parse the input string as a preamble (i.e.
bool | Undef (const char *iMacroName, size_t iMacroNameLen)
| Undefine a macro.
bool | Undef (const char *iMacroName, size_t iMacroNameLen)
| Undefine a macro.

## Public Attributes
void * | ErrorData
| User-specific storage, passed to Error()

## Static Public Attributes
static ErrorHandlerFunc | ErrorHandler
| A pointer to the preprocessor's error handler.

## 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 assigns 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.

## Member Typedef Documentation

## ◆ ErrorHandlerFunc [1/2]

typedef void(* Ogre::CPreprocessor::ErrorHandlerFunc) (void *iData, int iLine, const char *iError, const char *iToken, size_t iTokenLen)

An error handler function type.

The default implementation just drops a note to stderr and then the parser ends, returning NULL.

Parameters

  iData | User-specific pointer from the corresponding CPreprocessor object.
  iLine | The line at which the error happened.
  iError | The error string.
  iToken | If not NULL contains the erroneous token
  iTokenLen | The length of iToken. iToken is never zero-terminated!

## ◆ ErrorHandlerFunc [2/2]

typedef void(* Ogre::CPreprocessor::ErrorHandlerFunc) (void *iData, int iLine, const char *iError, const char *iToken, size_t iTokenLen)

An error handler function type.

The default implementation just drops a note to stderr and then the parser ends, returning NULL.

Parameters

  iData | User-specific pointer from the corresponding CPreprocessor object.
  iLine | The line at which the error happened.
  iError | The error string.
  iToken | If not NULL contains the erroneous token
  iTokenLen | The length of iToken. iToken is never zero-terminated!

## Constructor & Destructor Documentation

## ◆ CPreprocessor() [1/2]

Ogre::CPreprocessor::CPreprocessor | ( |  | ) |

Create an empty preprocessor object.

## ◆ ~CPreprocessor() [1/2]

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

Destroy the preprocessor object.

## ◆ CPreprocessor() [2/2]

Ogre::CPreprocessor::CPreprocessor | ( |  | ) |
| inline

Create an empty preprocessor object.

## ◆ ~CPreprocessor() [2/2]

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

Destroy the preprocessor object.

## Member Function Documentation

## ◆ Define() [1/4]

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

Define a macro without parameters.

Parameters

  iMacroName | The name of the defined macro
  iMacroNameLen | The length of the name of the defined macro
  iMacroValue | The value of the defined macro
  iMacroValueLen | The length of the value of the defined macro

## ◆ Define() [2/4]

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

Define a macro without parameters.

Parameters

  iMacroName | The name of the defined macro
  iMacroNameLen | The length of the name of the defined macro
  iMacroValue | The value of the defined macro
  iMacroValueLen | The length of the value of the defined macro

## ◆ Define() [3/4]

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

Define a numerical macro.

Parameters

  iMacroName | The name of the defined macro
  iMacroNameLen | The length of the name of the defined macro
  iMacroValue | The value of the defined macro

## ◆ Define() [4/4]

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

Define a numerical macro.

Parameters

  iMacroName | The name of the defined macro
  iMacroNameLen | The length of the name of the defined macro
  iMacroValue | The value of the defined macro

## ◆ Parse() [1/2]

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

  iSource | The source text
  iLength | The length of the source text in characters
  oLength | The 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.

## ◆ Parse() [2/2]

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

  iSource | The source text
  iLength | The length of the source text in characters
  oLength | The 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.

## ◆ ParsePreamble()

bool Ogre::CPreprocessor::ParsePreamble | ( | const char * | iSource,
|  | size_t | iLength )

Parse the input string as a preamble (i.e.

to define a lot of enums).

Parameters

  iSource | The source text containing preamble macros.
  iLength | The length of iSource text in characters.

Returns
  False on errors. True on success.

## ◆ Undef() [1/2]

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

Undefine a macro.

Parameters

  iMacroName | The name of the macro to undefine
  iMacroNameLen | The length of the name of the macro to undefine

Returns
  true if the macro has been undefined, false if macro doesn't exist

## ◆ Undef() [2/2]

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

Undefine a macro.

Parameters

  iMacroName | The name of the macro to undefine
  iMacroNameLen | The length of the name of the macro to undefine

Returns
  true if the macro has been undefined, false if macro doesn't exist

## Member Data Documentation

## ◆ ErrorData

void * Ogre::CPreprocessor::ErrorData

User-specific storage, passed to Error()

## ◆ ErrorHandler

static ErrorHandlerFunc Ogre::CPreprocessor::ErrorHandler
| static

A pointer to the preprocessor's error handler.

You can assign the address of your own function to this variable and implement your own error handling (e.g. throwing an exception etc).

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

- OgreGLSLPreprocessor.h
- OgreGLSLESPreprocessor.h