15 #include "cvsSourceDirectory.h" 16 #include "cvsSourceTree.h" 17 #include "string_utils.h" 28 const string &dirname) :
36 _depth = _parent->_depth + 1;
46 ~CVSSourceDirectory() {
47 Children::iterator ci;
48 for (ci = _children.begin(); ci != _children.end(); ++ci) {
106 string prefix, postfix;
107 while (a->_depth > b->_depth) {
113 while (b->_depth > a->_depth) {
114 postfix = b->_dirname +
"/" + postfix;
121 postfix = b->_dirname +
"/" + postfix;
128 string result = prefix + postfix;
129 nassertr(!result.empty(), string());
130 return result.substr(0, result.length() - 1);
141 return _children.size();
151 nassertr(n >= 0 && n < (
int)_children.size(), NULL);
164 if (relpath.empty()) {
168 size_t slash = relpath.find(
'/');
169 string first = relpath.substr(0, slash);
171 if (slash != string::npos) {
172 rest = relpath.substr(slash + 1);
175 if (first.empty() || first ==
".") {
178 }
else if (first ==
"..") {
179 if (_parent != NULL) {
187 Children::const_iterator ci;
188 for (ci = _children.begin(); ci != _children.end(); ++ci) {
189 if (cmp_nocase((*ci)->get_dirname(), first) == 0) {
190 return (*ci)->find_relpath(rest);
207 if (cmp_nocase(dirname, _dirname) == 0) {
211 Children::const_iterator ci;
212 for (ci = _children.begin(); ci != _children.end(); ++ci) {
234 vector_string contents;
236 nout <<
"Unable to scan directory " << directory <<
"\n";
240 vector_string::const_iterator fi;
241 for (fi = contents.begin(); fi != contents.end(); ++fi) {
242 const string &basename = (*fi);
245 Filename next_path(directory, basename);
246 Filename key(next_path, key_filename);
251 _children.push_back(subdir);
253 if (!subdir->
scan(next_path, key_filename)) {
CVSSourceDirectory * find_dirname(const string &dirname)
Returns the source directory that corresponds to the given local directory name, or NULL if there is ...
int get_num_children() const
Returns the number of subdirectories below this directory.
Filename get_root_fullpath()
Returns the full path from the root to the top of the source hierarchy.
CVSSourceDirectory * find_relpath(const string &relpath)
Returns the source directory that corresponds to the given relative path from this directory...
string get_dirname() const
Returns the local name of this particular directory.
Filename get_rel_to(const CVSSourceDirectory *other) const
Returns the relative path to the other directory from this one.
Filename get_path() const
Returns the relative pathname to this particular directory, as seen from the root of the tree...
Filename get_fullpath() const
Returns the full pathname to this particular directory.
This represents one particular directory in the hierarchy of source directory files.
The name of a file, such as a texture file or an Egg file.
This represents the root of the tree of source directory files.
void add_file(const string &basename, CVSSourceDirectory *dir)
Adds a new file to the set of known files.
bool scan_directory(vector_string &contents) const
Attempts to open the named filename as if it were a directory and looks for the non-hidden files with...
CVSSourceDirectory * get_child(int n) const
Returns the nth subdirectory below this directory.
bool scan(const Filename &directory, const string &key_filename)
Recursively scans the contents of the source directory.
bool exists() const
Returns true if the filename exists on the disk, false otherwise.