Panda3D
dSearchPath.h
1 // Filename: dSearchPath.h
2 // Created by: drose (01Jul00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PANDASEARCHPATH_H
16 #define PANDASEARCHPATH_H
17 
18 #include "dtoolbase.h"
19 
20 #include "filename.h"
21 #include "pvector.h"
22 
23 ///////////////////////////////////////////////////////////////////
24 // Class : DSearchPath
25 // Description : This class stores a list of directories that can be
26 // searched, in order, to locate a particular file. It
27 // is normally constructed by passing it a traditional
28 // searchpath-style string, e.g. a list of directory
29 // names delimited by spaces or colons, but it can also
30 // be built up explicitly.
31 ////////////////////////////////////////////////////////////////////
32 class EXPCL_DTOOL DSearchPath {
33 PUBLISHED:
34  class EXPCL_DTOOL Results {
35  PUBLISHED:
36  Results();
37  Results(const Results &copy);
38  void operator = (const Results &copy);
39  ~Results();
40 
41  void clear();
42  int get_num_files() const;
43  const Filename &get_file(int n) const;
44 
45  INLINE Filename operator [] (int n) const;
46  INLINE int size() const;
47 
48  void output(ostream &out) const;
49  void write(ostream &out, int indent_level = 0) const;
50 
51  public:
52  void add_file(const Filename &file);
53 
54  private:
55  typedef pvector<Filename> Files;
56  Files _files;
57  };
58 
59  DSearchPath();
60  DSearchPath(const string &path, const string &separator = string());
61  DSearchPath(const Filename &directory);
62  DSearchPath(const DSearchPath &copy);
63  void operator = (const DSearchPath &copy);
64  ~DSearchPath();
65 
66  void clear();
67  void append_directory(const Filename &directory);
68  void prepend_directory(const Filename &directory);
69  void append_path(const string &path,
70  const string &separator = string());
71  void append_path(const DSearchPath &path);
72  void prepend_path(const DSearchPath &path);
73 
74  bool is_empty() const;
75  int get_num_directories() const;
76  const Filename &get_directory(int n) const;
77  MAKE_SEQ(get_directories, get_num_directories, get_directory);
78 
79  Filename find_file(const Filename &filename) const;
80  int 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 string &path,
85  const string &separator = string());
86 
87  void output(ostream &out, const string &separator = string()) const;
88  void write(ostream &out, int indent_level = 0) const;
89 
90 private:
92  Directories _directories;
93 };
94 
95 INLINE ostream &operator << (ostream &out, const DSearchPath &sp) {
96  sp.output(out);
97  return out;
98 }
99 
100 #include "dSearchPath.I"
101 
102 #endif
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
This class stores a list of directories that can be searched, in order, to locate a particular file...
Definition: dSearchPath.h:32