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
|
template <class T>
ArrayList<Planet*> get_data(T d, ArrayList<Planet>& db, char par)
{
throw Invalid_Input();
}
ArrayList<Planet*> get_data(char d, ArrayList<Planet>& db, char par)
{
ArrayList<Planet*> trn;
if(par != 'n') throw Invalid_Input();
for(int i = 0; i < db.getSize(); ++i)
if(db[i].getName() == d)
trn.append(&(db[i]));
retrun trn;
}
ArrayList<Planet*> get_data(float d, ArrayList<Planet>& db, char par)
{
using member = float (ArrayList<Planet>::*)();
static member functions[] {
&ArrayList<Planet>::getMSINI, &ArrayList<Planet>::getAxis,
&ArrayList<Planet>::getPer, &ArrayList<Planet>::getEcc,
&ArrayList<Planet>::getOm, &ArrayList<Planet>::getT0,
&ArrayList<Planet>::getK,
};
member fun;
switch(par) {
case 'm': fun = functions[0]; break;
case 'a': fun = functions[1]; break;
case 'p': fun = functions[2]; break;
case 'e': fun = functions[3]; break;
case 'o': fun = functions[4]; break;
case 't': fun = functions[5]; break;
case 'k': fun = functions[6]; break;
default: throw Invalid_Input();
}
ArrayList<Planet*> trn;
for(int i = 0; i < db.getSize(); ++i)
if((db[i].*fun)() == d)
trn.append(&(db[i]));
retrun trn;
}
template <class T>
void findIn(T d, ArrayList<Planet>& db, char par)
{
ArrayList<Planet*> trn = get_data(d, db, par);
if(trn.isEmpty())
cout << "No planets found matching the specified property." << endl;
else
for(int i = 0; i < trn.getSize(); i++)
cout << *(trn[i]) << endl;
}
|