CrystalSpace

Public API Reference

cstool/tokenlist.h File Reference

Token list helper macros. More...

#include "csplugincommon/shader/shaderprogram.tok"
#include <CS_TOKEN_ITEM_FILE>

Go to the source code of this file.

Defines

Token list helper macros

The macros here provide an easy way to automatically build a token list useful for e.g.

parsers. The list of tokens have to be declared in an external file, with each token the argument to a 'CS_TOKEN_LIST_TOKEN()' invocation. The name of the file (full path!) has to be put in a macro named CS_TOKEN_ITEM_FILE. Optionally, the name of the function to initialize the token table can be set via CS_INIT_TOKEN_TABLE_NAME; the default is 'InitTokenTable'. In addition to invoking the initialization function to populate the string hash, an enumeration is also created. Elements of the enumeration are named XMLTOKEN_FOO (where 'FOO' represents the argument to CS_TOKEN_LIST_TOKEN()). If you prefer a prefix other than 'XMLTOKEN_', define CS_TOKEN_LIST_TOKEN_PREFIX with the prefix of your choice. As a convenience, in addition to entries for each CS_TOKEN_LIST_TOKEN invocation, a final item is added to the enumeration with the name provided by CS_TOKEN_LIST_TOKEN_LAST. If you do not #define this macro, then the name XMLTOKEN_TOKEN_COUNT is given to the last item in the enumeration. This value will equate to the count of items in the enumeration (not including this automatically added item).

Note that the client defines CS_TOKEN_ITEM_FILE, CS_INIT_TOKEN_TABLE_NAME, CS_TOKEN_LIST_TOKEN_PREFIX, and CS_TOKEN_LIST_TOKEN_LAST, and they will not be undefined by this file; hence, if you want to build multiple token lists, you may redefine those macros and include <cstool/tokenlist.h> again.

The code generated by the macros has a dependency on csString, thus the <csutil/csstring.h> header must be included in files that use the token list helpers.

Example (from a real-world use): fire.tok:

 CS_TOKEN_LIST_TOKEN(PALETTE)
 ... 

fire.h:

 #include <csutil/csstring.h>

 class csFireLoader
 {
   csStringHash tokens;
 #define CS_TOKEN_ITEM_FILE "plugins/proctex/standard/fire.tok"
 #include "cstool/tokenlist.h"
   ...
 };

fire.cpp:

 csFireLoader::csFireLoader(iBase *p)
 {
   InitTokenTable (tokens);
 // ...
 }

 csPtr<iBase> csFireLoader::Parse (iDocumentNode* node, 
                                     iLoaderContext* ldr_context,
                                     iBase* context)
 {
 // ...
   csStringID id = tokens.Request (child->GetValue ());
   switch (id)
   {
     case XMLTOKEN_PALETTE:
       // ...
       break;
   }
 // ...
 }


#define CS_TOKEN_LIST_PASTE(X, Y)   CS_TOKEN_LIST_PASTE1(X,Y)
 A token list entry.
#define CS_TOKEN_LIST_PASTE1(X, Y)   X ## Y
 A token list entry.
#define CS_TOKEN_LIST_TOKEN(X)
 A token list entry.
#define CS_TOKEN_LIST_TOKEN(X)   CS_TOKEN_LIST_PASTE(CS_TOKEN_LIST_TOKEN_PREFIX,X),
 A token list entry.
#define CS_TOKEN_LIST_TOKEN_FINAL(X)   CS_TOKEN_LIST_PASTE(CS_TOKEN_LIST_TOKEN_PREFIX,X)
 A token list entry.
#define CS_TOKEN_LIST_TOKEN_LAST   TOKEN_COUNT
 Name for the "token count" enumeration value.
#define CS_TOKEN_LIST_TOKEN_LAST_DEFAULT
 A token list entry.
#define CS_TOKEN_LIST_TOKEN_PREFIX   XMLTOKEN_
 Prefix for the generated enumeration value.
#define CS_TOKEN_LIST_TOKEN_PREFIX_DEFAULT
 A token list entry.

Token list helper macros

The macros here provide an easy way to automatically build a token list useful for e.g.

parsers. The list of tokens have to be declared in an external file, with each token the argument to a 'CS_TOKEN_LIST_TOKEN()' invocation. The name of the file (full path!) has to be put in a macro named CS_TOKEN_ITEM_FILE. Optionally, the name of the function to initialize the token table can be set via CS_INIT_TOKEN_TABLE_NAME; the default is 'InitTokenTable'. In addition to invoking the initialization function to populate the string hash, an enumeration is also created. Elements of the enumeration are named XMLTOKEN_FOO (where 'FOO' represents the argument to CS_TOKEN_LIST_TOKEN()). If you prefer a prefix other than 'XMLTOKEN_', define CS_TOKEN_LIST_TOKEN_PREFIX with the prefix of your choice. As a convenience, in addition to entries for each CS_TOKEN_LIST_TOKEN invocation, a final item is added to the enumeration with the name provided by CS_TOKEN_LIST_TOKEN_LAST. If you do not #define this macro, then the name XMLTOKEN_TOKEN_COUNT is given to the last item in the enumeration. This value will equate to the count of items in the enumeration (not including this automatically added item).

Note that the client defines CS_TOKEN_ITEM_FILE, CS_INIT_TOKEN_TABLE_NAME, CS_TOKEN_LIST_TOKEN_PREFIX, and CS_TOKEN_LIST_TOKEN_LAST, and they will not be undefined by this file; hence, if you want to build multiple token lists, you may redefine those macros and include <cstool/tokenlist.h> again.

The code generated by the macros has a dependency on csString, thus the <csutil/csstring.h> header must be included in files that use the token list helpers.

Example (from a real-world use): fire.tok:

 CS_TOKEN_LIST_TOKEN(PALETTE)
 ... 

fire.h:

 #include <csutil/csstring.h>

 class csFireLoader
 {
   csStringHash tokens;
 #define CS_TOKEN_ITEM_FILE "plugins/proctex/standard/fire.tok"
 #include "cstool/tokenlist.h"
   ...
 };

fire.cpp:

 csFireLoader::csFireLoader(iBase *p)
 {
   InitTokenTable (tokens);
 // ...
 }

 csPtr<iBase> csFireLoader::Parse (iDocumentNode* node, 
                                     iLoaderContext* ldr_context,
                                     iBase* context)
 {
 // ...
   csStringID id = tokens.Request (child->GetValue ());
   switch (id)
   {
     case XMLTOKEN_PALETTE:
       // ...
       break;
   }
 // ...
 }


#define CS_INIT_TOKEN_TABLE_NAME   InitTokenTable
 Name of the token table initialization method.
#define CS_INIT_TOKEN_TABLE_NAME_DEFAULT
 Name of the token table initialization method.
#define CS_TOKEN_LIST_PASTE(X, Y)   CS_TOKEN_LIST_PASTE1(X,Y)
 Name of the token table initialization method.
#define CS_TOKEN_LIST_PASTE1(X, Y)   X ## Y
 Name of the token table initialization method.
#define CS_TOKEN_LIST_TOKEN(X)
 A token list entry.
#define CS_TOKEN_LIST_TOKEN(X)   CS_TOKEN_LIST_PASTE(CS_TOKEN_LIST_TOKEN_PREFIX,X),
 A token list entry.
#define CS_TOKEN_LIST_TOKEN_FINAL(X)   CS_TOKEN_LIST_PASTE(CS_TOKEN_LIST_TOKEN_PREFIX,X)
 Name of the token table initialization method.
#define CS_TOKEN_LIST_TOKEN_LAST   TOKEN_COUNT
 Name for the "token count" enumeration value.
#define CS_TOKEN_LIST_TOKEN_LAST_DEFAULT
 Name of the token table initialization method.
#define CS_TOKEN_LIST_TOKEN_PREFIX   XMLTOKEN_
 Prefix for the generated enumeration value.
#define CS_TOKEN_LIST_TOKEN_PREFIX_DEFAULT
 Name of the token table initialization method.
enum  
 

Name of the token table initialization method.

More...
static void CS_INIT_TOKEN_TABLE_NAME (csStringHash &t)
 Name of the token table initialization method.

Detailed Description

Token list helper macros.

Definition in file tokenlist.h.


Generated for Crystal Space 2.1 by doxygen 1.6.1