CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Macros TypeName() , ClassName(), defineTypeNameAndDebug()...

Register Blogs Community New Posts Updated Threads Search

Like Tree6Likes
  • 3 Post By jaswi
  • 3 Post By Rvadrabade

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 23, 2009, 07:01
Default Macros TypeName() , ClassName(), defineTypeNameAndDebug()...
  #1
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 18
jaswi is on a distinguished road
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");

Code:
    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)

Code:
               const ::Foam::word Type::typeName            \
                (                                                           \
                  Type::typeName_()                                \
                );                                                         \
                                                                            \
int Type::debug(                                                      \
                ::Foam::debug::debugSwitch                      \
                  (                                                         \
                   Type::typeName_(),                               \
                   DebugSwitch                                         \
                   )                                                         \
                );
Based on its call, again in class primitiveMesh -
defineTypeNameAndDebug(primitiveMesh,0);
it will call two functions , namely:

  • typeName()
substituting for the primitiveMesh, this inline function will read
Code:
  
const ::Foam::word primitiveMesh::typeName          
                       ( 
                         primitiveMesh::typeName_() 
                       );
It will ultimately return the string "primitiveMesh"
  • debug()
Code:
int primitiveMesh::debug(                                           
                ::Foam::debug::debugSwitch                     
                  (                                                         
                   primitiveMesh::typeName_(),   
                   DebugSwitch                                         
                   )                                                        
                );
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:

Code:
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:
Code:
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

Regards
Jaswi

Last edited by jaswi; March 23, 2009 at 13:50. Reason: The question was not well formulated initially
jaswi is offline   Reply With Quote

Old   March 22, 2020, 09:58
Default Macros and typeName initialization
  #2
Member
 
Rahul Vadrabade
Join Date: Apr 2018
Posts: 46
Rep Power: 8
Rvadrabade is on a distinguished road
This is too old thread but i was reading same topic which comes in advanced category. Though for the completeness of thread here is answer which might be beneficial for future readers.

As typeName is a static variable hence it is required to initialize outside class.

It is initialized in defineTypeNameAndDebug(Type, DebugSwitch) macro at

const ::Foam::word primitiveMesh::typeName(primitiveMesh::typeName_() );
Michael@UW, reverseila and yueyun like this.
Rvadrabade is offline   Reply With Quote

Old   June 15, 2020, 10:52
Default
  #3
Senior Member
 
Join Date: Jan 2019
Posts: 125
Blog Entries: 1
Rep Power: 0
Michael@UW is on a distinguished road
Quote:
Originally Posted by Rvadrabade View Post
This is too old thread but i was reading same topic which comes in advanced category. Though for the completeness of thread here is answer which might be beneficial for future readers.

As typeName is a static variable hence it is required to initialize outside class.

It is initialized in defineTypeNameAndDebug(Type, DebugSwitch) macro at

const ::Foam::word primitiveMesh::typeName(primitiveMesh::typeName_() );
Thanks for the explanation.

Can you explain also why some class uses ClassName() while some TypeName() in header files?
Michael@UW is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with macros F_ID and C_ID Jack Martinez FLUENT 0 August 19, 2007 08:27
Problems with Airpak - Copy Macros, diffuser Nelson FLUENT 0 May 20, 2007 22:56
What are UDF macros C_T_S , C_T_AP,...???? Asghari FLUENT 0 January 28, 2007 10:54
udf error in some macros Asghari FLUENT 0 August 7, 2006 01:10
Orientation of Face Variable Macros hirokata FLUENT 0 February 17, 2006 00:12


All times are GMT -4. The time now is 15:09.