This is not a complete review, but rather an elaboration on a single point already made. Having multiple ways of sorting things is not a bad idea, but there are better ways of doing it. Here are three different ways to do that which, I think, are successively better.
Use a lambda
As @glampert already said, your sort routines would be better expressed as a lambda:
void Universe::sort_x() {
std::sort(vPlanet.begin(), vPlanet.end(),
[](const Planet &a, const Planet &b){
return a.x < b.x;
});
}
However, it's a bit messy to have to write that out for each member variable of Planet, so that leads to the next way to do it:
Use a macro
#define sort_on(x) sort_##x() { std::sort(vPlanet.begin(), vPlanet.end(), [](const Planet &a, const Planet &b){ return a.x < b.x; }); }
void Universe::sort_on(x)
void Universe::sort_on(y)
void Universe::sort_on(z)
void Universe::sort_on(Mlvl)
void Universe::sort_on(Dlvl)
void Universe::sort_on(Plvl)
void Universe::sort_on(Clvl)
Now all of the member functions are defined but it's still somewhat readable. It's still a bit unfortunate, though because it means Universe has to have intimate knowledge of and access to internal members of Planet. This is generally a red flag telling you that there may be something wrong with the class design.
Implement comparisons in the Planet class
You could have the comparison implementations as static members of the Planet class.
static bool byX(const Planet &a, const Planet &b) { return a.x < b.x; };
// etc.
Then you could have an enum within Planet:
enum sortby { X, Y, Z, MLVL, CLVL, DLVL, PLVL };
Then have a function which takes this enum as an argument and returns the appropriate function pointer.
static bool (*sorter(sortby field))(const Planet &a, const Planet &b) {
switch (field) {
case Y:
return byY;
break;
case Z:
return byZ;
break;
// all of the other cases
default:
return byX;
}
}
Then instead of having multiple sort functions in Universe, you would just have one:
void Universe::sort(Planet::sortby field) {
std::sort(vPlanet.begin(), vPlanet.end(),
Planet::sorter(field));
}