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

RTS wiki tutorial question

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 5, 2018, 18:46
Default RTS wiki tutorial question
  #1
New Member
 
Clint
Join Date: Sep 2015
Posts: 10
Rep Power: 10
cdunn6754 is on a distinguished road
I have been using the wiki page on RTS

https://openfoamwiki.net/index.php/O...tion_mechanism

to help work through some things. It's been very helpful but I have been stuck trying to figure out one of the code snippets for a few days now without much luck. Here is the code in question

Code:
 template<class DerivedType>
class addMrConstructorToTable
{
public:
 
    static Base New ( const dictionary& dict)
    {
        return Base(new DerivedType (dict));
    }
 
    addMrConstructorToTable
    (
        const word& lookup = DerivedType::typeName
    )
    {
        constructMrConstructorTables();
        MrConstructorTablePtr_->insert(lookup, New);
    }
 
    ~addMrConstructorToTable()
    {
        destroyMrConstructorTables();
    }
};
It is the subclass that must be added to the Base class. In the text it says that calling the constructor of the 'addMrConstructorToTable' subclass should populate the static derived constructor pointer hash table (mrConstructorTable in the example) with at function pointer to the constructor of the derivedType that addMrConstructorToTable is templated upon. I see how the addMrConstructorToTable constructor

Code:
    addMrConstructorToTable::addMrConstructorToTable
    (
        const word& lookup = DerivedType::typeName
    )
    {
        constructMrConstructorTables();
        MrConstructorTablePtr_->insert(lookup, New);
    }
would do as expected provided that New was a function pointer. So finally my question is what is this addMrConstructorToTable::New function doing? Is it even a function? When it's called in the insert function call it doesn't even have it's parameter.

Is it adding a pointer to the addMrConstructorToTable::New() function itself to the hash table by not passing the argument list in the insert call? In that case I still don't understand how a function pointer to the desired derived constructor is being returned when we later access the hash table to create a DerivedType object.

Code:
return Base(new DerivedType (dict));
It seems like it is instantiating a DerivedType object with 'new' and casting the pointer to that new object to Base? That is still not the construction function pointer I was be expecting.
cdunn6754 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 3D Bifurcating Artery tutorial - no wall shear seen 9aul FLUENT 0 January 15, 2018 18:20
[Tutorials] New Dakota - OpenFOAM Coupling Tutorial Tobi OpenFOAM Community Contributions 0 October 9, 2016 17:19
WIKI MRFSimpleFoam Tutorial baoaero OpenFOAM Running, Solving & CFD 2 September 17, 2013 21:05
[Virtualization] OpenFOAM oriented tutorial on using VMware Player - support thread wyldckat OpenFOAM Installation 2 July 11, 2012 16:01
A question on the first tutorial example bcavityb athlonshi OpenFOAM Running, Solving & CFD 7 October 23, 2008 11:28


All times are GMT -4. The time now is 16:30.