From: jmt Date: Sat, 26 Sep 2009 11:46:42 +0000 (+0000) Subject: Extend FGPositioned to allow mapping from a string to a type. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=04b30f322de856c9993f328e15cb9a0509be65c9;hp=13ff5da4becb2f53ceb68c997e5942b1849d2c0a;p=flightgear.git Extend FGPositioned to allow mapping from a string to a type. --- diff --git a/src/Navaids/positioned.cxx b/src/Navaids/positioned.cxx index f43e4b82f..6324578c3 100644 --- a/src/Navaids/positioned.cxx +++ b/src/Navaids/positioned.cxx @@ -31,6 +31,8 @@ #include #include +#include +#include #include "positioned.hxx" @@ -470,6 +472,39 @@ FGPositioned::cart() const return SGVec3d::fromGeod(mPosition); } +FGPositioned::Type FGPositioned::typeFromName(const std::string& aName) +{ + typedef struct { + const char* _name; + Type _ty; + } NameTypeEntry; + + const NameTypeEntry names[] = { + {"airport", AIRPORT}, + {"vor", VOR}, + {"ndb", NDB}, + {"wpt", WAYPOINT}, + {"fix", FIX}, + {"tacan", TACAN}, + {"dme", DME}, + // aliases + {"waypoint", WAYPOINT}, + + {NULL, INVALID} + }; + + std::string lowerName(simgear::strutils::convertToLowerCase(aName)); + + for (const NameTypeEntry* n = names; (n->_name != NULL); ++n) { + if (::strcmp(n->_name, lowerName.c_str()) == 0) { + return n->_ty; + } + } + + SG_LOG(SG_GENERAL, SG_WARN, "FGPositioned::typeFromName: couldn't match:" << aName); + return INVALID; +} + const char* FGPositioned::nameForType(Type aTy) { switch (aTy) { diff --git a/src/Navaids/positioned.hxx b/src/Navaids/positioned.hxx index 93e4f6bbf..4d1f6081f 100644 --- a/src/Navaids/positioned.hxx +++ b/src/Navaids/positioned.hxx @@ -188,10 +188,14 @@ public: */ static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL); - + /** + * Map a candidate type string to a real type. Returns INVALID if the string + * does not correspond to a defined type. + */ + static Type typeFromName(const std::string& aName); /** - * Debug helper, map a type to a human-readable string + * Map a type to a human-readable string */ static const char* nameForType(Type aTy); protected: