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

A general C question

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 8, 2008, 10:42
Default On my spare time I'm working o
  #1
Super Moderator
 
niklas's Avatar
 
Niklas Nordin
Join Date: Mar 2009
Location: Stockholm, Sweden
Posts: 693
Rep Power: 29
niklas will become famous soon enoughniklas will become famous soon enough
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

ifstream file;
string name;
string typeName;

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?

N
niklas is offline   Reply With Quote

Old   September 8, 2008, 12:38
Default OpenFOAM of course parses its
  #2
Senior Member
 
Gavin Tabor
Join Date: Mar 2009
Posts: 181
Rep Power: 17
grtabor is on a distinguished road
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.

Gavin
grtabor 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
general question Madhukar Rapaka FLUENT 1 June 28, 2006 09:03
General Question vcoralic OpenFOAM Running, Solving & CFD 0 June 13, 2006 05: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 10:21
general question jay Main CFD Forum 1 December 17, 1998 14:09


All times are GMT -4. The time now is 04:19.