1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| map<string, my_struct> Configuration::readLossesFromFile()
{
myConfigurationHash.clear();
ifstream fin("configuration.txt");
if(fin)
{
while(!fin.fail())
{
string line;
getline(fin, line);
if(fin.fail())
break;
if(tokens.size()!=3)
{
clog<<"Incomplete line: ignored"<<endl;
continue;
}
if(tokens[1]=="string")
{
my_struct b;
b.type=TYPE_STRING;
b.str=tokens[2];
myConfigurationHash[tokens[0]]=b;
cout<<"STRING: \""<<tokens[0]<<"\" : \""<<b.str<<"\""<<endl;
}
else if(tokens[1]=="int")
{
my_struct b;
b.type=TYPE_INT;
b.i=atoi(tokens[2].c_str());
myConfigurationHash[tokens[0]]=b;
cout<<"INT: \""<<tokens[0]<<"\" : "<<b.i<<endl;
}
else if(tokens[1]=="float")
{
my_struct b;
b.type=TYPE_FLOAT;
b.f=atof(tokens[2].c_str());
myConfigurationHash[tokens[0]]=b;
cout<<"FLOAT: \""<<tokens[0]<<"\" : "<<b.f<<endl;
}
else
{
clog<<"Unknown type: "<<tokens[1]<<endl;
}
}
}
return myConfigurationHash;
} |