Added method to lookup a constellation by string.

This commit is contained in:
Chris Laurel 2001-08-08 23:54:39 +00:00
parent 364ce6cc91
commit 05ee7bef2d
2 changed files with 23 additions and 1 deletions

View file

@ -9,6 +9,7 @@
#include <iostream>
#include "celestia.h"
#include "util.h"
#include "constellation.h"
using namespace std;
@ -121,7 +122,7 @@ Constellation::Constellation(char *_name, char *_genitive, char *_abbrev)
abbrev = string(_abbrev);
}
Constellation *Constellation::getConstellation(unsigned int n)
Constellation* Constellation::getConstellation(unsigned int n)
{
if (constellations == NULL)
initialize();
@ -133,6 +134,26 @@ Constellation *Constellation::getConstellation(unsigned int n)
return constellations[n];
}
Constellation* Constellation::getConstellation(const string& name)
{
if (constellations == NULL)
initialize();
for (unsigned int i = 0;
i < sizeof(constellationInfo) / sizeof(constellationInfo[0]);
i++)
{
if (compareIgnoringCase(name, constellationInfo[i].abbr) == 0 ||
compareIgnoringCase(name, constellationInfo[i].gen) == 0 ||
compareIgnoringCase(name, constellationInfo[i].name) == 0)
{
return constellations[i];
}
}
return NULL;
}
string Constellation::getName()
{
return name;

View file

@ -15,6 +15,7 @@ class Constellation
{
public:
static Constellation *getConstellation(unsigned int);
static Constellation *getConstellation(const std::string&);
std::string getName();
std::string getGenitive();