15 #include "dSearchPath.h" 26 DSearchPath::Results::
35 DSearchPath::Results::
46 void DSearchPath::Results::
56 DSearchPath::Results::
87 assert(n >= 0 && n < (
int)_files.size());
98 _files.push_back(file);
106 void DSearchPath::Results::
107 output(ostream &out)
const {
109 if (!_files.empty()) {
110 Files::const_iterator fi = _files.begin();
113 while (fi != _files.end()) {
114 out <<
", " << (*fi);
126 void DSearchPath::Results::
127 write(ostream &out,
int indent_level)
const {
128 Files::const_iterator fi;
129 for (fi = _files.begin(); fi != _files.end(); ++fi) {
130 for (
int i = 0; i < indent_level; ++i) {
133 out << (*fi) <<
"\n";
152 DSearchPath(
const string &path,
const string &separator) {
173 _directories(copy._directories)
184 _directories = copy._directories;
203 _directories.clear();
213 _directories.push_back(directory);
223 _directories.insert(_directories.begin(), directory);
234 string pathsep = separator;
235 if (pathsep.empty()) {
236 pathsep = DEFAULT_PATHSEP;
239 if (pathsep.empty()) {
244 while (p < path.length()) {
245 size_t q = path.find_first_of(pathsep, p);
246 if (q == string::npos) {
266 copy(path._directories.begin(), path._directories.end(),
267 back_inserter(_directories));
278 if (!path._directories.empty()) {
280 copy(_directories.begin(), _directories.end(),
281 back_inserter(new_directories));
282 _directories.swap(new_directories);
294 return _directories.empty();
304 return _directories.size();
314 assert(n >= 0 && n < (
int)_directories.size());
315 return _directories[n];
329 if (_directories.empty()) {
337 Directories::const_iterator di;
338 for (di = _directories.begin(); di != _directories.end(); ++di) {
377 if (_directories.empty()) {
385 Directories::const_iterator di;
386 for (di = _directories.begin(); di != _directories.end(); ++di) {
414 output(ostream &out,
const string &separator)
const {
415 string pathsep = separator;
416 if (pathsep.empty()) {
417 pathsep = DEFAULT_PATHSEP;
418 if (!pathsep.empty()) {
419 pathsep = pathsep[0];
423 if (!_directories.empty()) {
424 Directories::const_iterator di = _directories.begin();
427 while (di != _directories.end()) {
428 out << pathsep << (*di);
440 write(ostream &out,
int indent_level)
const {
441 Directories::const_iterator di;
442 for (di = _directories.begin(); di != _directories.end(); ++di) {
443 for (
int i = 0; i < indent_level; ++i) {
446 out << (*di) <<
"\n";
void clear()
Removes all the directories from the search list.
int get_num_files() const
Returns the number of files on the result list.
bool is_empty() const
Returns true if the search list is empty, false otherwise.
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
void prepend_path(const DSearchPath &path)
Adds all of the directories listed in the search path to the beginning of the search list...
bool is_fully_qualified() const
Returns true if the filename is fully qualified, e.g.
void append_path(const string &path, const string &separator=string())
Adds all of the directories listed in the search path to the end of the search list.
int get_num_directories() const
Returns the number of directories on the search list.
const Filename & get_directory(int n) const
Returns the nth directory on the search list.
The name of a file, such as a texture file or an Egg file.
bool is_local() const
Returns true if the filename is local, e.g.
int find_all_files(const Filename &filename, Results &results) const
Searches all the directories in the search list for the indicated file, in order. ...
DSearchPath()
Creates an empty search path.
This class stores a list of directories that can be searched, in order, to locate a particular file...
void prepend_directory(const Filename &directory)
Adds a new directory to the front of the search list.
const Filename & get_file(int n) const
Returns the nth file on the result list.
bool exists() const
Returns true if the filename exists on the disk, false otherwise.
void add_file(const Filename &file)
Adds a new file to the result list.
void clear()
Removes all the files from the list.
Filename find_file(const Filename &filename) const
Searches all the directories in the search list for the indicated file, in order. ...
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).