CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Running, Solving & CFD (
-   -   Macros TypeName() , ClassName(), defineTypeNameAndDebug()... (

jaswi March 23, 2009 08:01

Macros TypeName() , ClassName(), defineTypeNameAndDebug()...
Dear Forum Users

Greetings to Everybody....

I have some doubt about how the macros ClassName, TypeName and defineTypeNameAndDebug have been defined. Here is what I have found...

1st the Macro ClassName("TypeNameString");


    static const char* typeName_() { return TypeNameString; }        \
    static const ::Foam::word typeName;                                      \
    static int debug

Based on its call in primitiveMesh - ClassName("primitiveMesh"), it does 3 things:
  • declare and define an inline function "typeName_()" , which simply returns the TypeNameString i.e. primitiveMesh;
  • declare a static constant variable of type word in the global namespace (some please confirm this , as I am not sure)
  • declare an integer variable for the debug flag (used later in another macro)
Now the defineTypeNameAndDebug(Type, DebugSwitch)


              const ::Foam::word Type::typeName            \
                (                                                          \
                  Type::typeName_()                                \
                );                                                        \
int Type::debug(                                                      \
                ::Foam::debug::debugSwitch                      \
                  (                                                        \
                  Type::typeName_(),                              \
                  DebugSwitch                                        \
                  )                                                        \

Based on its call, again in class primitiveMesh -
it will call two functions , namely:

  • typeName()
substituting for the primitiveMesh, this inline function will read

const ::Foam::word primitiveMesh::typeName         

It will ultimately return the string "primitiveMesh"
  • debug()

int primitiveMesh::debug(                                         

this is basically a call to the function debugSwitch() defined in the nameSpace debug. The arguments are clear i.e. String returned by the function typeName_() and the integer value 0

The problematic Macro is the macro TypeName(TypeNameString)

defined in the typeInfo.H, it reads:


ClassName(TypeNameString);                                \
virtual const word& type() const { return typeName; }

This macro first invokes the macro ClassName and further implements an inline virtual function type(). If we substitute for the macro ClassName and expand the macro for the class polyMesh i.e TypeName("polyMesh") , it reads:

static const char* typeName_() { return polyMesh; }        \
static const ::Foam::word typeName;                                      \
static int debug;
virtual const word& type() const { return typeName; }

The question is related to this function type(). It returns the static const variable typeName declared in the macro ClassName. But where does the initialization of this keyword takes place.

Please share it with the forum if anybody knows about this.

Thanks for the attention


All times are GMT -4. The time now is 06:59.