Panda3D
configVariableSearchPath.h
1 // Filename: configVariableSearchPath.h
2 // Created by: drose (21Oct04)
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 CONFIGVARIABLESEARCHPATH_H
16 #define CONFIGVARIABLESEARCHPATH_H
17 
18 #include "dtoolbase.h"
19 #include "configVariableBase.h"
20 #include "dSearchPath.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : ConfigVariableSearchPath
24 // Description : This is similar to a ConfigVariableList, but it
25 // returns its list as a DSearchPath, as a list of
26 // directories.
27 //
28 // You may locally append directories to the end of the
29 // search path with the methods here, or prepend them to
30 // the beginning. Use these methods to make adjustments
31 // to the path; do not attempt to directly modify the
32 // const DSearchPath object returned by get_value().
33 //
34 // Unlike other ConfigVariable types, local changes
35 // (made by calling append_directory() and
36 // prepend_directory()) are specific to this particular
37 // instance of the ConfigVariableSearchPath. A separate
38 // instance of the same variable, created by using the
39 // same name to the constructor, will not reflect the
40 // local changes.
41 ////////////////////////////////////////////////////////////////////
42 class EXPCL_DTOOLCONFIG ConfigVariableSearchPath : public ConfigVariableBase {
43 PUBLISHED:
44  INLINE ConfigVariableSearchPath(const string &name,
45  const string &description = string(),
46  int flags = 0);
47  INLINE ConfigVariableSearchPath(const string &name,
48  const DSearchPath &default_value,
49  const string &description,
50  int flags = 0);
51  INLINE ConfigVariableSearchPath(const string &name,
52  const string &default_value,
53  const string &description,
54  int flags = 0);
55  INLINE ~ConfigVariableSearchPath();
56 
57  INLINE operator const DSearchPath & () const;
58  INLINE const DSearchPath &get_value() const;
59  INLINE const DSearchPath &get_default_value() const;
60 
61  INLINE bool clear_local_value();
62 
63  INLINE void clear();
64  INLINE void append_directory(const Filename &directory);
65  INLINE void prepend_directory(const Filename &directory);
66  INLINE void append_path(const string &path,
67  const string &separator = string());
68  INLINE void append_path(const DSearchPath &path);
69  INLINE void prepend_path(const DSearchPath &path);
70 
71  INLINE bool is_empty() const;
72  INLINE int get_num_directories() const;
73  INLINE const Filename &get_directory(int n) const;
74  MAKE_SEQ(get_directories, get_num_directories, get_directory);
75 
76  INLINE Filename find_file(const Filename &filename) const;
77  INLINE int find_all_files(const Filename &filename,
78  DSearchPath::Results &results) const;
79  INLINE DSearchPath::Results find_all_files(const Filename &filename) const;
80 
81  INLINE void output(ostream &out) const;
82  INLINE void write(ostream &out) const;
83 
84 private:
85  void reload_search_path();
86 
87  DSearchPath _default_value;
88  DSearchPath _prefix, _postfix;
89 
90  AtomicAdjust::Integer _local_modified;
91  DSearchPath _cache;
92 };
93 
94 INLINE ostream &operator << (ostream &out, const ConfigVariableSearchPath &variable);
95 
96 #include "configVariableSearchPath.I"
97 
98 #endif
This is similar to a ConfigVariableList, but it returns its list as a DSearchPath, as a list of directories.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
bool clear_local_value()
Removes the local value defined for this variable, and allows its value to be once again retrieved fr...
This class stores a list of directories that can be searched, in order, to locate a particular file...
Definition: dSearchPath.h:32
This class is the base class for both ConfigVariableList and ConfigVariable (and hence for all of the...