cppFile.cxx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // Filename: cppFile.C
  2. // Created by: drose (11Nov99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #include "cppFile.h"
  6. #include <ctype.h>
  7. ////////////////////////////////////////////////////////////////////
  8. // Function: CPPFile::Constructor
  9. // Access: Public
  10. // Description:
  11. ////////////////////////////////////////////////////////////////////
  12. CPPFile::
  13. CPPFile(const Filename &filename, const Filename &filename_as_referenced,
  14. Source source) :
  15. _filename(filename), _filename_as_referenced(filename_as_referenced),
  16. _source(source)
  17. {
  18. _filename.set_text();
  19. _filename_as_referenced.set_text();
  20. }
  21. ////////////////////////////////////////////////////////////////////
  22. // Function: CPPFile::Copy Constructor
  23. // Access: Public
  24. // Description:
  25. ////////////////////////////////////////////////////////////////////
  26. CPPFile::
  27. CPPFile(const CPPFile &copy) :
  28. _filename(copy._filename),
  29. _filename_as_referenced(copy._filename_as_referenced),
  30. _source(copy._source)
  31. {
  32. }
  33. ////////////////////////////////////////////////////////////////////
  34. // Function: CPPFile::Copy Assignment Operator
  35. // Access: Public
  36. // Description:
  37. ////////////////////////////////////////////////////////////////////
  38. void CPPFile::
  39. operator = (const CPPFile &copy) {
  40. _filename = copy._filename;
  41. _filename_as_referenced = copy._filename_as_referenced;
  42. _source = copy._source;
  43. }
  44. ////////////////////////////////////////////////////////////////////
  45. // Function: CPPFile::Destructor
  46. // Access: Public
  47. // Description:
  48. ////////////////////////////////////////////////////////////////////
  49. CPPFile::
  50. ~CPPFile() {
  51. }
  52. ////////////////////////////////////////////////////////////////////
  53. // Function: CPPFile::is_c_or_i_file
  54. // Access: Public
  55. // Description: Returns true if the file appears to be a C or C++
  56. // source code file based on its extension. That is,
  57. // returns true if the filename ends in .c, .C, .cc,
  58. // .cpp, or any of a series of likely extensions.
  59. ////////////////////////////////////////////////////////////////////
  60. bool CPPFile::
  61. is_c_or_i_file() const {
  62. return is_c_or_i_file(_filename);
  63. }
  64. ////////////////////////////////////////////////////////////////////
  65. // Function: CPPFile::is_c_or_i_file
  66. // Access: Public, Static
  67. // Description: Returns true if the file appears to be a C or C++
  68. // source code file based on its extension. That is,
  69. // returns true if the filename ends in .c, .C, .cc,
  70. // .cpp, or any of a series of likely extensions.
  71. ////////////////////////////////////////////////////////////////////
  72. bool CPPFile::
  73. is_c_or_i_file(const Filename &filename) {
  74. string extension = filename.get_extension();
  75. // downcase the extension.
  76. for (string::iterator ei = extension.begin();
  77. ei != extension.end();
  78. ++ei) {
  79. (*ei) = tolower(*ei);
  80. }
  81. return (extension == "c" || extension == "cc" ||
  82. extension == "cpp" || extension == "c++" || extension == "cxx" ||
  83. extension == "i" || extension == "t");
  84. }
  85. ////////////////////////////////////////////////////////////////////
  86. // Function: CPPFile::is_c_file
  87. // Access: Public
  88. // Description: Returns true if the file appears to be a C or C++
  89. // source code file based on its extension. That is,
  90. // returns true if the filename ends in .c, .C, .cc,
  91. // .cpp, or any of a series of likely extensions.
  92. ////////////////////////////////////////////////////////////////////
  93. bool CPPFile::
  94. is_c_file() const {
  95. return is_c_file(_filename);
  96. }
  97. ////////////////////////////////////////////////////////////////////
  98. // Function: CPPFile::is_c_file
  99. // Access: Public, Static
  100. // Description: Returns true if the file appears to be a C or C++
  101. // source code file based on its extension. That is,
  102. // returns true if the filename ends in .c, .C, .cc,
  103. // .cpp, or any of a series of likely extensions.
  104. ////////////////////////////////////////////////////////////////////
  105. bool CPPFile::
  106. is_c_file(const Filename &filename) {
  107. string extension = filename.get_extension();
  108. // downcase the extension.
  109. for (string::iterator ei = extension.begin();
  110. ei != extension.end();
  111. ++ei) {
  112. (*ei) = tolower(*ei);
  113. }
  114. return (extension == "c" || extension == "cc" ||
  115. extension == "cpp" || extension == "c++" || extension == "cxx");
  116. }
  117. ////////////////////////////////////////////////////////////////////
  118. // Function: CPPFile::replace_nearer
  119. // Access: Public
  120. // Description: If the other file is "nearer" than this file (in the
  121. // sense that a file in the local directory is nearer
  122. // than a file in the system directory, etc.), replaces
  123. // this file's information with that of the other.
  124. // Otherwise, does nothing.
  125. ////////////////////////////////////////////////////////////////////
  126. void CPPFile::
  127. replace_nearer(const CPPFile &other) {
  128. if ((int)_source > (int)other._source) {
  129. (*this) = other;
  130. }
  131. }
  132. ////////////////////////////////////////////////////////////////////
  133. // Function: CPPFile::Ordering Operator
  134. // Access: Public
  135. // Description:
  136. ////////////////////////////////////////////////////////////////////
  137. bool CPPFile::
  138. operator < (const CPPFile &other) const {
  139. return _filename < other._filename;
  140. }
  141. ////////////////////////////////////////////////////////////////////
  142. // Function: CPPFile::Equality Operator
  143. // Access: Public
  144. // Description:
  145. ////////////////////////////////////////////////////////////////////
  146. bool CPPFile::
  147. operator == (const CPPFile &other) const {
  148. return _filename == other._filename;
  149. }
  150. ////////////////////////////////////////////////////////////////////
  151. // Function: CPPFile::Inequality Operator
  152. // Access: Public
  153. // Description:
  154. ////////////////////////////////////////////////////////////////////
  155. bool CPPFile::
  156. operator != (const CPPFile &other) const {
  157. return _filename != other._filename;
  158. }
  159. ////////////////////////////////////////////////////////////////////
  160. // Function: CPPFile::c_str
  161. // Access: Public
  162. // Description:
  163. ////////////////////////////////////////////////////////////////////
  164. const char *CPPFile::
  165. c_str() const {
  166. return _filename.c_str();
  167. }
  168. ////////////////////////////////////////////////////////////////////
  169. // Function: CPPFile::empty
  170. // Access: Public
  171. // Description:
  172. ////////////////////////////////////////////////////////////////////
  173. bool CPPFile::
  174. empty() const {
  175. return _filename.empty();
  176. }