|September 8, 2008, 09:42||
On my spare time I'm working o
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693Rep Power: 21
On my spare time I'm working on a personal project and since my C++ knowledge is pretty bad I'm hoping that someone here might be able to help me.
I'd like to construct all my variables via a file.
All that is required as input is the filename.
The constructor (in the file) would look something like this.
typeName keyWord " string of data depending on typeName "
so to construct a scalar would look like this:
scalar a 1.0;
to construct a derived class like scalarList, or vector<scalar>, would be:
scalarList d ( 1.0 2.0 3.0 );
the variables will be constructed via a stream so Im thinking that the constructor ideally would use a call that would look something like this
file >> typeName >> name;
variable<typename> a = variable<typename>(name,file);
so depending on the value of typeName Id like the constructor to read the appropriate thing.
The problem here is that typeName is not a class, its just a string.
I dont want to do it by adding an if-statement for every implemented type.
Is this possible using templated or virtual functions or am I attacking the problem completely wrong?
|September 8, 2008, 11:38||
OpenFOAM of course parses its
Join Date: Mar 2009
Posts: 181Rep Power: 9
OpenFOAM of course parses its files; i.e. it goes through the file character-by-character constructing keywords until it recognises something. I'm not sure that that is what you are trying to do here.
What I think you want to do is to derive all "things" from some common base class Thing which has a virtual function Read (which will probably be overloaded in derived classes). When you are looping around reading in the list of things, everything will be a Thing and so will have the .Read() function available.
|Thread||Thread Starter||Forum||Replies||Last Post|
|general question||Madhukar Rapaka||FLUENT||1||June 28, 2006 08:03|
|General Question||vcoralic||OpenFOAM Running, Solving & CFD||0||June 13, 2006 04:24|
|General CFD question||hani||Main CFD Forum||0||March 13, 2003 08:27|
|General CFD Question||sam kashan||Main CFD Forum||15||June 18, 2002 09:21|
|general question||jay||Main CFD Forum||1||December 17, 1998 14:09|