Add various helper filters, to make use of type-ranges, and reduce the need
to down-cast in filter implementations.
This commit is contained in:
parent
2d852024c6
commit
c9e8112a81
8 changed files with 61 additions and 47 deletions
|
@ -249,13 +249,9 @@ FGAirport::HardSurfaceFilter::HardSurfaceFilter(double minLengthFt) :
|
|||
{
|
||||
}
|
||||
|
||||
bool FGAirport::HardSurfaceFilter::pass(FGPositioned* aPos) const
|
||||
bool FGAirport::HardSurfaceFilter::passAirport(FGAirport* aApt) const
|
||||
{
|
||||
if (aPos->type() != AIRPORT) {
|
||||
return false; // exclude seaports and heliports as well, we need a runways
|
||||
}
|
||||
|
||||
return static_cast<FGAirport*>(aPos)->hasHardRunwayOfLengthFt(mMinLengthFt);
|
||||
return aApt->hasHardRunwayOfLengthFt(mMinLengthFt);
|
||||
}
|
||||
|
||||
FGAirport* FGAirport::findByIdent(const std::string& aIdent)
|
||||
|
|
|
@ -104,17 +104,32 @@ public:
|
|||
{
|
||||
public:
|
||||
virtual bool pass(FGPositioned* aPos) const {
|
||||
Type ty(aPos->type());
|
||||
return (ty >= AIRPORT) && (ty <= SEAPORT);
|
||||
return passAirport(static_cast<FGAirport*>(aPos));
|
||||
}
|
||||
|
||||
virtual Type minType() const {
|
||||
return AIRPORT;
|
||||
}
|
||||
|
||||
virtual Type maxType() const {
|
||||
return SEAPORT;
|
||||
}
|
||||
|
||||
virtual bool passAirport(FGAirport* aApt) const {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class HardSurfaceFilter : public Filter
|
||||
class HardSurfaceFilter : public AirportFilter
|
||||
{
|
||||
public:
|
||||
HardSurfaceFilter(double minLengthFt);
|
||||
|
||||
virtual bool pass(FGPositioned* aPos) const;
|
||||
virtual bool passAirport(FGAirport* aApt) const;
|
||||
|
||||
virtual Type maxType() const {
|
||||
return AIRPORT;
|
||||
}
|
||||
private:
|
||||
double mMinLengthFt;
|
||||
};
|
||||
|
|
|
@ -40,17 +40,12 @@
|
|||
|
||||
using std::sort;
|
||||
|
||||
class AirportWithMetar : public FGPositioned::Filter
|
||||
class AirportWithMetar : public FGAirport::AirportFilter
|
||||
{
|
||||
public:
|
||||
virtual bool pass(FGPositioned* aPos) const
|
||||
virtual bool passAirport(FGAirport* aApt) const
|
||||
{
|
||||
if ((aPos->type() < FGPositioned::AIRPORT) || (aPos->type() > FGPositioned::SEAPORT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FGAirport* apt = static_cast<FGAirport*>(aPos);
|
||||
return apt->getMetar();
|
||||
return aApt->getMetar();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -250,11 +250,15 @@ static bool check_beacon_range( const SGGeod& pos,
|
|||
|
||||
class BeaconFilter : public FGPositioned::Filter
|
||||
{
|
||||
public:
|
||||
virtual bool pass(FGPositioned* aPos) const
|
||||
{
|
||||
return (aPos->type() >= FGPositioned::OM) && (aPos->type() <= FGPositioned::IM);
|
||||
public:
|
||||
virtual FGPositioned::Type minType() const {
|
||||
return FGPositioned::OM;
|
||||
}
|
||||
|
||||
virtual FGPositioned::Type maxType() const {
|
||||
return FGPositioned::IM;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Update current nav/adf radio stations based on current postition
|
||||
|
|
|
@ -4254,13 +4254,9 @@ MK_VIII::Mode6Handler::test_airport (const FGAirport *airport)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool MK_VIII::Mode6Handler::AirportFilter::pass(FGPositioned* a) const
|
||||
bool MK_VIII::Mode6Handler::AirportFilter::passAirport(FGAirport* a) const
|
||||
{
|
||||
if (a->type() != FGPositioned::AIRPORT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ok = self->test_airport(static_cast<FGAirport*>(a));
|
||||
bool ok = self->test_airport(a);
|
||||
return ok;
|
||||
}
|
||||
|
||||
|
@ -4497,14 +4493,9 @@ MK_VIII::TCFHandler::select_runway (const FGAirport *airport)
|
|||
return _runway;
|
||||
}
|
||||
|
||||
bool MK_VIII::TCFHandler::AirportFilter::pass(FGPositioned* aPos) const
|
||||
bool MK_VIII::TCFHandler::AirportFilter::passAirport(FGAirport* aApt) const
|
||||
{
|
||||
if (aPos->type() != FGPositioned::AIRPORT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FGAirport* apt = static_cast<FGAirport*>(aPos);
|
||||
return apt->hasHardRunwayOfLengthFt(mk->conf.runway_database);
|
||||
return aApt->hasHardRunwayOfLengthFt(mk->conf.runway_database);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1505,13 +1505,17 @@ private:
|
|||
unsigned int get_bank_angle_alerts ();
|
||||
void update_bank_angle ();
|
||||
|
||||
class AirportFilter : public FGPositioned::Filter
|
||||
class AirportFilter : public FGAirport::AirportFilter
|
||||
{
|
||||
public:
|
||||
AirportFilter(Mode6Handler *s)
|
||||
: self(s) {}
|
||||
|
||||
virtual bool pass(FGPositioned *a) const;
|
||||
virtual bool passAirport(FGAirport *a) const;
|
||||
|
||||
virtual FGPositioned::Type maxType() const {
|
||||
return FGPositioned::AIRPORT;
|
||||
}
|
||||
|
||||
private:
|
||||
Mode6Handler* self;
|
||||
|
@ -1578,14 +1582,17 @@ private:
|
|||
bool is_tcf ();
|
||||
bool is_rfcf ();
|
||||
|
||||
class AirportFilter : public FGPositioned::Filter
|
||||
class AirportFilter : public FGAirport::AirportFilter
|
||||
{
|
||||
public:
|
||||
AirportFilter(MK_VIII *device)
|
||||
: mk(device) {}
|
||||
|
||||
virtual bool pass(FGPositioned *a) const;
|
||||
virtual bool passAirport(FGAirport *a) const;
|
||||
|
||||
virtual FGPositioned::Type maxType() const {
|
||||
return FGPositioned::AIRPORT;
|
||||
}
|
||||
private:
|
||||
MK_VIII* mk;
|
||||
};
|
||||
|
|
|
@ -74,9 +74,12 @@ FGNavRecord *FGNavList::findByFreq( double freq, const SGGeod& position)
|
|||
class VORNDBFilter : public FGPositioned::Filter
|
||||
{
|
||||
public:
|
||||
virtual bool pass(FGPositioned* aPos) const
|
||||
{
|
||||
return (aPos->type() == FGPositioned::VOR) || (aPos->type() == FGPositioned::NDB);
|
||||
virtual FGPositioned::Type minType() const {
|
||||
return FGPositioned::VOR;
|
||||
}
|
||||
|
||||
virtual FGPositioned::Type maxType() const {
|
||||
return FGPositioned::NDB;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -497,19 +497,22 @@ static naRef f_geodinfo(naContext c, naRef me, int argc, naRef* args)
|
|||
#undef HASHSET
|
||||
}
|
||||
|
||||
class AirportInfoFilter : public FGPositioned::Filter
|
||||
class AirportInfoFilter : public FGAirport::AirportFilter
|
||||
{
|
||||
public:
|
||||
AirportInfoFilter() :
|
||||
type(FGPositioned::AIRPORT)
|
||||
{ }
|
||||
|
||||
virtual bool pass(FGPositioned* aPos) const
|
||||
{
|
||||
return (aPos->type() == type);
|
||||
virtual FGPositioned::Type minType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
FGPositioned::Type type;
|
||||
virtual FGPositioned::Type maxType() const {
|
||||
return type;
|
||||
}
|
||||
|
||||
FGPositioned::Type type;
|
||||
};
|
||||
|
||||
// Returns data hash for particular or nearest airport of a <type>, or nil
|
||||
|
|
Loading…
Add table
Reference in a new issue