]> git.mxchange.org Git - flightgear.git/commitdiff
Extend FGPositioned to allow mapping from a string to a type.
authorjmt <jmt>
Sat, 26 Sep 2009 11:46:42 +0000 (11:46 +0000)
committerTim Moore <timoore@redhat.com>
Mon, 28 Sep 2009 22:01:47 +0000 (00:01 +0200)
src/Navaids/positioned.cxx
src/Navaids/positioned.hxx

index f43e4b82f2eb9ced5192bf31837cbac1a3633f54..6324578c36013a03a728c9712fb2d8e946981d6a 100644 (file)
@@ -31,6 +31,8 @@
 
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/timing/timestamp.hxx>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/misc/strutils.hxx>
 
 #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) {
index 93e4f6bbfee60ddf4da6ad03c54377bd1cb9e016..4d1f6081fbb32252dde13bac5a38a6d2d47278ef 100644 (file)
@@ -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: