Extend FGPositioned to allow mapping from a string to a type.
This commit is contained in:
parent
13ff5da4be
commit
04b30f322d
2 changed files with 41 additions and 2 deletions
|
@ -31,6 +31,8 @@
|
||||||
|
|
||||||
#include <simgear/math/sg_geodesy.hxx>
|
#include <simgear/math/sg_geodesy.hxx>
|
||||||
#include <simgear/timing/timestamp.hxx>
|
#include <simgear/timing/timestamp.hxx>
|
||||||
|
#include <simgear/debug/logstream.hxx>
|
||||||
|
#include <simgear/misc/strutils.hxx>
|
||||||
|
|
||||||
#include "positioned.hxx"
|
#include "positioned.hxx"
|
||||||
|
|
||||||
|
@ -470,6 +472,39 @@ FGPositioned::cart() const
|
||||||
return SGVec3d::fromGeod(mPosition);
|
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)
|
const char* FGPositioned::nameForType(Type aTy)
|
||||||
{
|
{
|
||||||
switch (aTy) {
|
switch (aTy) {
|
||||||
|
|
|
@ -188,10 +188,14 @@ public:
|
||||||
*/
|
*/
|
||||||
static List findClosestN(const SGGeod& aPos, unsigned int aN, double aCutoffNm, Filter* aFilter = NULL);
|
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);
|
static const char* nameForType(Type aTy);
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Add table
Reference in a new issue