cppFile.cxx 7.0 KB

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