Panda3D
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  */
28 class EXPCL_DTOOL_DTOOLUTIL DSearchPath {
29 PUBLISHED:
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 
90 private:
92  Directories _directories;
93 };
94 
95 INLINE 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
This class stores a list of directories that can be searched, in order, to locate a particular file.
Definition: dSearchPath.h:28
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
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.