Panda3D

Loading...
Searching...
No Matches
pathReplace.I
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 pathReplace.I
10 * @author drose
11 * @date 2003-02-07
12 */
13
14/**
15 * Resets the error flag to the no-error state. had_error() will return false
16 * until a new error is generated.
17 */
18INLINE void PathReplace::
19 clear_error() {
20 _error_flag = false;
21}
22
23/**
24 * Returns true if an error was detected since the last call to clear_error(),
25 * false otherwise.
26 */
27INLINE bool PathReplace::
28 had_error() const {
29 return _error_flag;
30}
31
32/**
33 * Removes all the patterns from the specification.
34 */
35INLINE void PathReplace::
36 clear() {
37 clear_error();
38 _entries.clear();
39}
40
41/**
42 * Adds the indicated original/replace pattern to the specification. If a
43 * filename is encountered whose initial prefix matches the indicated
44 * orig_prefix, that prefix will be replaced with replacement_prefix.
45 */
46INLINE void PathReplace::
47 add_pattern(const std::string &orig_prefix, const std::string &replacement_prefix) {
48 _entries.push_back(Entry(orig_prefix, replacement_prefix));
49}
50
51/**
52 * Returns the number of original/replace patterns that have been added.
53 */
54INLINE int PathReplace::
55 get_num_patterns() const {
56 return _entries.size();
57}
58
59/**
60 * Returns the original prefix associated with the nth pattern.
61 */
62INLINE const std::string &PathReplace::
63 get_orig_prefix(int n) const {
64 nassertr(n >= 0 && n < (int)_entries.size(), _entries[0]._orig_prefix);
65 return _entries[n]._orig_prefix;
66}
67
68/**
69 * Returns the replacement prefix associated with the nth pattern.
70 */
71INLINE const std::string &PathReplace::
72 get_replacement_prefix(int n) const {
73 nassertr(n >= 0 && n < (int)_entries.size(), _entries[0]._replacement_prefix);
74 return _entries[n]._replacement_prefix;
75}
76
77/**
78 * Returns true if the PathReplace object specifies no action, or false if
79 * convert_path() may do something.
80 */
81INLINE bool PathReplace::
82 is_empty() const {
83 return (_entries.empty() && _path.is_empty() && _path_store == PS_keep);
84}
85
86/**
87 * Calls match_path() followed by store_path(), to replace the initial prefix
88 * and then convert the file for storing, as the user indicated.
89 */
90INLINE Filename PathReplace::
91 convert_path(const Filename &orig_filename, const DSearchPath &additional_path) {
92 Filename fullpath, outpath;
93 full_convert_path(orig_filename, additional_path, fullpath, outpath);
94 return outpath;
95}
96
97/**
98 *
99 */
100INLINE PathReplace::Component::
101Component(const std::string &component) :
102 _orig_prefix(component),
103 _double_star(component == "**")
104{
105}
106
107/**
108 *
109 */
110INLINE PathReplace::Component::
111Component(const PathReplace::Component &copy) :
112 _orig_prefix(copy._orig_prefix),
113 _double_star(copy._double_star)
114{
115}
116
117/**
118 *
119 */
120INLINE void PathReplace::Component::
121operator = (const PathReplace::Component &copy) {
122 _orig_prefix = copy._orig_prefix;
123 _double_star = copy._double_star;
124}
125
126/**
127 *
128 */
129INLINE PathReplace::Entry::
130Entry(const PathReplace::Entry &copy) :
131 _orig_prefix(copy._orig_prefix),
132 _orig_components(copy._orig_components),
133 _is_local(copy._is_local),
134 _replacement_prefix(copy._replacement_prefix)
135{
136}
137
138/**
139 *
140 */
141INLINE void PathReplace::Entry::
142operator = (const PathReplace::Entry &copy) {
143 _orig_prefix = copy._orig_prefix;
144 _orig_components = copy._orig_components;
145 _is_local = copy._is_local;
146 _replacement_prefix = copy._replacement_prefix;
147}
DSearchPath
This class stores a list of directories that can be searched, in order, to locate a particular file.
Definition dSearchPath.h:28
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
PathReplace::get_orig_prefix
const std::string & get_orig_prefix(int n) const
Returns the original prefix associated with the nth pattern.
Definition pathReplace.I:63
PathReplace::full_convert_path
void full_convert_path(const Filename &orig_filename, const DSearchPath &additional_path, Filename &resolved_path, Filename &output_path)
Converts the input path into two different forms: A resolved path, and an output path.
Definition pathReplace.cxx:198
PathReplace::convert_path
Filename convert_path(const Filename &orig_filename, const DSearchPath &additional_path=DSearchPath())
Calls match_path() followed by store_path(), to replace the initial prefix and then convert the file ...
Definition pathReplace.I:91
PathReplace::is_empty
bool is_empty() const
Returns true if the PathReplace object specifies no action, or false if convert_path() may do somethi...
Definition pathReplace.I:82
PathReplace::add_pattern
void add_pattern(const std::string &orig_prefix, const std::string &replacement_prefix)
Adds the indicated original/replace pattern to the specification.
Definition pathReplace.I:47
PathReplace::had_error
bool had_error() const
Returns true if an error was detected since the last call to clear_error(), false otherwise.
Definition pathReplace.I:28
PathReplace::clear
void clear()
Removes all the patterns from the specification.
Definition pathReplace.I:36
PathReplace::get_num_patterns
int get_num_patterns() const
Returns the number of original/replace patterns that have been added.
Definition pathReplace.I:55
PathReplace::clear_error
void clear_error()
Resets the error flag to the no-error state.
Definition pathReplace.I:19
PathReplace::get_replacement_prefix
const std::string & get_replacement_prefix(int n) const
Returns the replacement prefix associated with the nth pattern.
Definition pathReplace.I:72