From 05ee7bef2d413a94523f951874d72338d25ff516 Mon Sep 17 00:00:00 2001 From: Chris Laurel Date: Wed, 8 Aug 2001 23:54:39 +0000 Subject: [PATCH] Added method to lookup a constellation by string. --- src/constellation.cpp | 23 ++++++++++++++++++++++- src/constellation.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/constellation.cpp b/src/constellation.cpp index 9e46162e9..21d1582f8 100644 --- a/src/constellation.cpp +++ b/src/constellation.cpp @@ -9,6 +9,7 @@ #include #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; diff --git a/src/constellation.h b/src/constellation.h index 4d3d96c0c..52b054a04 100644 --- a/src/constellation.h +++ b/src/constellation.h @@ -15,6 +15,7 @@ class Constellation { public: static Constellation *getConstellation(unsigned int); + static Constellation *getConstellation(const std::string&); std::string getName(); std::string getGenitive();