Panda3D
Loading...
Searching...
No Matches
dSearchPath.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file dSearchPath.h
10 * @author drose
11 * @date 2000-07-01
12 */
13
14#ifndef PANDASEARCHPATH_H
15#define PANDASEARCHPATH_H
16
17#include "dtoolbase.h"
18
19#include "filename.h"
20#include "pvector.h"
21
22/**
23 * This class stores a list of directories that can be searched, in order, to
24 * locate a particular file. It is normally constructed by passing it a
25 * traditional searchpath-style string, e.g. a list of directory names
26 * delimited by spaces or colons, but it can also be built up explicitly.
27 */
28class EXPCL_DTOOL_DTOOLUTIL DSearchPath {
29PUBLISHED:
30 class EXPCL_DTOOL_DTOOLUTIL Results {
31 PUBLISHED:
32 Results();
33 Results(const Results &copy);
34 void operator = (const Results &copy);
35 ~Results();
36
37 void clear();
38 size_t get_num_files() const;
39 const Filename &get_file(size_t n) const;
40
41 INLINE Filename operator [] (size_t n) const;
42 INLINE size_t size() const;
43
44 void output(std::ostream &out) const;
45 void write(std::ostream &out, int indent_level = 0) const;
46
47 public:
48 void add_file(const Filename &file);
49
50 private:
51 typedef pvector<Filename> Files;
52 Files _files;
53 };
54
55 DSearchPath() = default;
56 DSearchPath(const std::string &path, const std::string &separator = std::string());
57 DSearchPath(const Filename &directory);
58 DSearchPath(const DSearchPath &copy) = default;
59 DSearchPath(DSearchPath &&from) = default;
60 ~DSearchPath() = default;
61
62 DSearchPath &operator = (const DSearchPath &copy) = default;
63 DSearchPath &operator = (DSearchPath &&from) = default;
64
65 void clear();
66 void append_directory(const Filename &directory);
67 void prepend_directory(const Filename &directory);
68 void append_path(const std::string &path,
69 const std::string &separator = std::string());
70 void append_path(const DSearchPath &path);
71 void prepend_path(const DSearchPath &path);
72
73 bool is_empty() const;
74 size_t get_num_directories() const;
75 const Filename &get_directory(size_t n) const;
76 MAKE_SEQ(get_directories, get_num_directories, get_directory);
77 MAKE_SEQ_PROPERTY(directories, get_num_directories, get_directory);
78
79 Filename find_file(const Filename &filename) const;
80 size_t find_all_files(const Filename &filename, Results &results) const;
81 INLINE Results find_all_files(const Filename &filename) const;
82
83 INLINE static Filename
84 search_path(const Filename &filename, const std::string &path,
85 const std::string &separator = std::string());
86
87 void output(std::ostream &out, const std::string &separator = std::string()) const;
88 void write(std::ostream &out, int indent_level = 0) const;
89
90private:
91 typedef pvector<Filename> Directories;
92 Directories _directories;
93};
94
95INLINE std::ostream &operator << (std::ostream &out, const DSearchPath &sp) {
96 sp.output(out);
97 return out;
98}
99
100#include "dSearchPath.I"
101
102#endif
void clear()
Removes all the files from the list.
const Filename & get_file(size_t n) const
Returns the nth file on the result list.
size_t size() const
Returns the num of filenames in the set.
Definition dSearchPath.I:28
void add_file(const Filename &file)
Adds a new file to the result list.
size_t get_num_files() const
Returns the number of files on the result list.
This class stores a list of directories that can be searched, in order, to locate a particular file.
Definition dSearchPath.h:28
Filename find_file(const Filename &filename) const
Searches all the directories in the search list for the indicated file, in order.
bool is_empty() const
Returns true if the search list is empty, false otherwise.
void append_path(const std::string &path, const std::string &separator=std::string())
Adds all of the directories listed in the search path to the end of the search list.
get_num_directories
Returns the number of directories on the search list.
Definition dSearchPath.h:76
size_t find_all_files(const Filename &filename, Results &results) const
Searches all the directories in the search list for the indicated file, in order.
void prepend_path(const DSearchPath &path)
Adds all of the directories listed in the search path to the beginning of the search list.
static Filename search_path(const Filename &filename, const std::string &path, const std::string &separator=std::string())
A quick-and-easy way to search a searchpath for a file when you don't feel like building or keeping a...
Definition dSearchPath.I:51
void prepend_directory(const Filename &directory)
Adds a new directory to the front of the search list.
void clear()
Removes all the directories from the search list.
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
get_directory
Returns the nth directory on the search list.
Definition dSearchPath.h:76
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.