Hi, I have a problem in creating my main function. I have following classes:
1- SolarCalculation
2- TemperatureInputs
3- Params
In a way that I want to access some variables from an XML file to assign my variables in SolarCalculation class:
class TemperatureInputs
{
private:
Params* pm;
public:
TemperatureInputs(std::string XmlFilename);
~TemperatureInputs(){};
Params* getPM(){ return pm; }
};
class Params
{
public:
int get_starttime()
{
std::pair<std::string, std::string> stringpair = Temporal_Domain[0]->GetAttributes(0);
this->EatDoubleQuote(stringpair.second);
return atoi(stringpair.second.c_str());
}
private:
std::vector<Node*> Temporal_Domain;
};
class SolarCalculation
{
public:
SolarCalculation(TemperatureInputs* input);
SolarCalculation() {};
~SolarCalculation() {};
void SolarConst();
};
SolarCalculation::SolarCalculation(TemperatureInputs* input)
{
Params* pm = inp->getPM();
startYear = pm->get_starttime();
}
void SolarCalculation::SolarConst()
{
/* convert to radians */
double lat_deg = startYear;
}
/* In the main, I want to get access the startYear using the SolarConst() function but I have a problem. */
int main()
{
SolarCalculation SolarCal;
SolarCal.SolarConst();
}
Would you guide me about the general procedure for such issues, I have lots of variables I have to read in from the XML file in this way, but the constructor and/or the functions are not well organized!!
I want to access some variables from an XML file to assign my variables in SolarCalculation class
To read in data from the file you can try overloading the extraction operator (>>) for the SolarCalculation class to read the relevant data directly into SolarCalculation objects and then store these objects in a container such as std::vector<SolarCalculation> for further use by the rest of your program. However your exact requirements will be determined by the pattern of the data file and the corresponding class
Writing into xml file is easy: just write tags and values.
To read from xml you need a xml-parser library. Most parsers are either DOM or SAX. DOM occupy more memory and slower for big files, but easier to use.