2 // AircraftDirVisitorBase.hxx - helper to traverse a heirarchy containing
5 // Written by Curtis Olson, started August 1997.
7 // Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // General Public License for more details.
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifndef FG_MAIN_AIRCRAFT_DIR_VISITOR_HXX
25 #define FG_MAIN_AIRCRAFT_DIR_VISITOR_HXX
27 class AircraftDirVistorBase
38 AircraftDirVistorBase() :
44 VisitResult visitAircraftPaths()
46 const string_list& paths(globals->get_aircraft_paths());
47 string_list::const_iterator it = paths.begin();
48 for (; it != paths.end(); ++it) {
50 // additional aircraft-paths are supposed to specify the directory
51 // containing the 'Aircraft' dir (same structure as fg-root, so cross-
52 // aircraft resource paths can be resolved correctly). Some users omit
53 // this, so check for both.
58 VisitResult vr = visitDir(p, 0);
59 if (vr != VISIT_CONTINUE) {
62 } // of aircraft paths iteration
64 // if we reach this point, search the default location (always last)
65 SGPath rootAircraft(globals->get_fg_root());
66 rootAircraft.append("Aircraft");
67 return visitDir(rootAircraft, 0);
70 VisitResult visitPath(const SGPath& path, unsigned int depth)
79 VisitResult visitDir(const simgear::Dir& d, unsigned int depth)
82 SG_LOG(SG_GENERAL, SG_WARN, "visitDir: no such path:" << d.path());
83 return VISIT_CONTINUE;
86 if (depth >= _maxDepth) {
87 return VISIT_CONTINUE;
91 simgear::PathList setFiles(d.children(simgear::Dir::TYPE_FILE, "-set.xml"));
92 simgear::PathList::iterator p;
93 for (p = setFiles.begin(); p != setFiles.end(); ++p) {
95 // if we found a -set.xml at this level, don't recurse any deeper
97 VisitResult vr = visit(*p);
98 if (vr != VISIT_CONTINUE) {
101 } // of -set.xml iteration
104 return VISIT_CONTINUE;
107 simgear::PathList subdirs(d.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT));
108 for (p = subdirs.begin(); p != subdirs.end(); ++p) {
109 VisitResult vr = visitDir(*p, depth + 1);
110 if (vr != VISIT_CONTINUE) {
115 return VISIT_CONTINUE;
116 } // of visitDir method
118 virtual VisitResult visit(const SGPath& path) = 0;
121 unsigned int _maxDepth;
124 #endif // of FG_MAIN_AIRCRAFT_DIR_VISITOR_HXX