-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathocDirectoryTree.cxx
More file actions
205 lines (180 loc) · 7.25 KB
/
Copy pathocDirectoryTree.cxx
File metadata and controls
205 lines (180 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Filename: ocDirectoryTree.cxx
// Created by: frang (03June04)
//
////////////////////////////////////////////////////////////////////
#include "ocDirectoryTree.h"
#include "ocDirectory.h"
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
OCDirectoryTree::
OCDirectoryTree() {
_root = new OCDirectory(this);
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
OCDirectoryTree::
~OCDirectoryTree() {
delete _root;
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::scan_source
// Access: Public
// Description: Reads in the complete hierarchy of source files,
// beginning at the current directory.
////////////////////////////////////////////////////////////////////
bool OCDirectoryTree::
scan_source(OCNamedScopes *named_scopes) {
if (!_root->r_scan("")) {
return false;
}
if (!_root->read_source_file("", named_scopes)) {
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::scan_depends
// Access: Public
// Description: Reads in the depends file and the dependency cache
// for each source file, and than sorts the files into
// dependency order.
////////////////////////////////////////////////////////////////////
bool OCDirectoryTree::
scan_depends(OCNamedScopes *named_scopes) {
if (!_root->read_depends_file(named_scopes)) {
return false;
}
if (!_root->scan_depends_cache(named_scopes)) {
return false;
}
if (!_root->resolve_dependencies()) {
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::count_source_files
// Access: Public
// Description: Returns the number of directories within the tree
// that actually have a Sources.pp file that was read.
////////////////////////////////////////////////////////////////////
int OCDirectoryTree::
count_source_files() const {
return _root->count_source_files();
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::get_root
// Access: Public
// Description: Returns the root directory of the tree.
////////////////////////////////////////////////////////////////////
OCDirectory *OCDirectoryTree::
get_root() const {
return _root;
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::get_complete_tree
// Access: Public
// Description: Returns a single string listing the relative path
// from the source root to each source directory in the
// tree, delimited by spaces.
////////////////////////////////////////////////////////////////////
string OCDirectoryTree::
get_complete_tree() const {
return _root->get_complete_subtree();
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::find_dirname
// Access: Public
// Description: Searches for the a source directory with the
// matching dirname. This is just the name of the
// directory itself, not the relative path to the
// directory.
////////////////////////////////////////////////////////////////////
OCDirectory *OCDirectoryTree::
find_dirname(const string &dirname) const {
Dirnames::const_iterator di;
di = _dirnames.find(dirname);
if (di != _dirnames.end()) {
return (*di).second;
}
// No such dirname; too bad.
return (OCDirectory *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::find_dependable_file
// Access: Public
// Description: Returns a OCDependableFile object corresponding to
// the named filename, searching all of the known source
// subdirectories. This can only find files marked by a
// previous call to get_dependable_file() with is_header
// set to true. Unlike
// get_dependable_file_by_pathname() or
// OCDirectory::get_dependable_file(), this does not
// create an entry if it does not exist; instead, it
// returns NULL if no matching file can be found.
////////////////////////////////////////////////////////////////////
OCDependableFile *OCDirectoryTree::
find_dependable_file(const string &filename) const {
Dependables::const_iterator di;
di = _dependables.find(filename);
if (di != _dependables.end()) {
return (*di).second;
}
return (OCDependableFile *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::get_dependable_file_by_pathname
// Access: Public
// Description: Given a dirname/filename for a particular dependable
// filename, return (or create and return) the
// corresponding OCDirectoryTree. This is different
// from find_dependable_file() in that an explicit
// dirname is given, and the entry will be created if
// it does not already exist. However, if the directory
// name does not exist, nothing is created, and NULL is
// returned.
////////////////////////////////////////////////////////////////////
OCDependableFile *OCDirectoryTree::
get_dependable_file_by_dirpath(const string &dirpath, bool is_header) {
// Start a the lowest level directory and work our way up to the top
size_t slash = dirpath.find_last_of('/');
while (slash != string::npos) {
string dirname = dirpath.substr(0, slash);
string filename = dirpath.substr(slash + 1);
OCDirectory * dir = find_dirname(dirname);
if (dir != (OCDirectory *)NULL) {
return dir->get_dependable_file(filename, is_header);
}
slash = dirname.find_last_of('/');
}
// No valid directory name.
return (OCDependableFile *)NULL;
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::read_file_dependencies
// Access: Public
// Description: Before processing the source files, makes a pass and
// reads in all of the dependency cache files so we'll
// have a heads-up on which files depend on the others.
////////////////////////////////////////////////////////////////////
void OCDirectoryTree::
read_file_dependencies(const string &cache_filename) {
_root->read_file_dependencies(cache_filename);
}
////////////////////////////////////////////////////////////////////
// Function: OCDirectoryTree::update_file_dependencies
// Access: Public
// Description: After all source processing has completed, makes one
// more pass through the directory hierarchy and writes
// out the inter-file dependency cache.
////////////////////////////////////////////////////////////////////
void OCDirectoryTree::
update_file_dependencies(const string &cache_filename) {
_root->update_file_dependencies(cache_filename);
}