Part of token class in OpenFOAM
This study comes from the following codes:
1 | Istream& iss = coalParcels.composition().coeffDict().lookup("phases"); |
These codes are what I add in to the createCloud.H in the coalChemistryFoam folder. the iss is actually a reference to a ITstream object returned by function lookup() defined in dictionary.C:
1 | Foam::ITstream& Foam::dictionary::lookup |
We would like to see how this firstToken is initialized in the token class. This firstToken object takes an Istream object as an input parameter. As mentioned before, this object is actually a ITstream object. The ITstream class as its name indicates is a class takes care of Input token stream. Let’s go into the code now.
1 | token firstToken(iss); |
This will call the constructor of the token class defined in tokenIO.C:
1 | Foam::token::token(Istream& is) |
Here the is is Istream reference object. In the Istream class, there is pure virtual function called read() :
1 | //- Return next token from stream |
The *this object here is of course a token class object. As ITstream is a subclass of Istream, and the ITstream class redefine the function read to read a token object.
1 | Foam::Istream& Foam::ITstream::read(token& t) |
In the first if loop, the Istream::getBack(t) is called:
1 | bool Foam::Istream::getBack(token& t) |
As the putBack_ is defined as false in the Istream constructor and not changed:
1 | Istream |
This if loop will not be conducted. In the next loop, the tokenIndex_ is originally defined as 0 and not changed in the ITstream constructor.