I'd like to know:
1.) On line of code which says: "Production possibleExpansion(infile);", what is the nature of possibleExpansion(infile)? Is it a function? Is it an object of class Production?
2.) On line of code which says: "possibleExpansions.push_back(possibleExpansion);", what is the meaning of it?
#include "definition.h"
#include "random.h"
Definition::Definition(ifstream& infile)
{
string uselessText;
getline(infile, uselessText, '{');
infile >> nonterminal;
getline(infile, uselessText);
while (infile.peek() != '}') {
Production possibleExpansion(infile);
possibleExpansions.push_back(possibleExpansion);
}
getline(infile, uselessText, '}');
}
const Production& Definition::getRandomProduction() const
{
static RandomGenerator random;
int randomIndex = random.getRandomInteger(0, possibleExpansions.size() - 1);
return possibleExpansions[randomIndex];
}
Here is the Definition.cpp code:
#ifndef __definition__
#define __definition__
#include "production.h"
#include <vector>
using namespace std;
class Definition {
public:
Definition() {}
Definition(ifstream& infile);
const string& getNonterminal() const { return nonterminal; }
const Production& getRandomProduction() const;
private:
string nonterminal;
vector<Production> possibleExpansions;
};
#endif // ! __definition__