2
0

ppDirectoryTree.cxx 7.1 KB

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