| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- // Filename: cppFile.C
- // Created by: drose (11Nov99)
- //
- ////////////////////////////////////////////////////////////////////
- #include "cppFile.h"
- #include <ctype.h>
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- CPPFile::
- CPPFile(const Filename &filename, const Filename &filename_as_referenced,
- Source source) :
- _filename(filename), _filename_as_referenced(filename_as_referenced),
- _source(source)
- {
- _filename.set_text();
- _filename_as_referenced.set_text();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::Copy Constructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- CPPFile::
- CPPFile(const CPPFile ©) :
- _filename(copy._filename),
- _filename_as_referenced(copy._filename_as_referenced),
- _source(copy._source)
- {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::Copy Assignment Operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- void CPPFile::
- operator = (const CPPFile ©) {
- _filename = copy._filename;
- _filename_as_referenced = copy._filename_as_referenced;
- _source = copy._source;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::Destructor
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- CPPFile::
- ~CPPFile() {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::is_c_or_i_file
- // Access: Public
- // Description: Returns true if the file appears to be a C or C++
- // source code file based on its extension. That is,
- // returns true if the filename ends in .c, .C, .cc,
- // .cpp, or any of a series of likely extensions.
- ////////////////////////////////////////////////////////////////////
- bool CPPFile::
- is_c_or_i_file() const {
- return is_c_or_i_file(_filename);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::is_c_or_i_file
- // Access: Public, Static
- // Description: Returns true if the file appears to be a C or C++
- // source code file based on its extension. That is,
- // returns true if the filename ends in .c, .C, .cc,
- // .cpp, or any of a series of likely extensions.
- ////////////////////////////////////////////////////////////////////
- bool CPPFile::
- is_c_or_i_file(const Filename &filename) {
- string extension = filename.get_extension();
- // downcase the extension.
- for (string::iterator ei = extension.begin();
- ei != extension.end();
- ++ei) {
- (*ei) = tolower(*ei);
- }
-
- return (extension == "c" || extension == "cc" ||
- extension == "cpp" || extension == "c++" || extension == "cxx" ||
- extension == "i" || extension == "t");
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::is_c_file
- // Access: Public
- // Description: Returns true if the file appears to be a C or C++
- // source code file based on its extension. That is,
- // returns true if the filename ends in .c, .C, .cc,
- // .cpp, or any of a series of likely extensions.
- ////////////////////////////////////////////////////////////////////
- bool CPPFile::
- is_c_file() const {
- return is_c_file(_filename);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::is_c_file
- // Access: Public, Static
- // Description: Returns true if the file appears to be a C or C++
- // source code file based on its extension. That is,
- // returns true if the filename ends in .c, .C, .cc,
- // .cpp, or any of a series of likely extensions.
- ////////////////////////////////////////////////////////////////////
- bool CPPFile::
- is_c_file(const Filename &filename) {
- string extension = filename.get_extension();
- // downcase the extension.
- for (string::iterator ei = extension.begin();
- ei != extension.end();
- ++ei) {
- (*ei) = tolower(*ei);
- }
-
- return (extension == "c" || extension == "cc" ||
- extension == "cpp" || extension == "c++" || extension == "cxx");
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::replace_nearer
- // Access: Public
- // Description: If the other file is "nearer" than this file (in the
- // sense that a file in the local directory is nearer
- // than a file in the system directory, etc.), replaces
- // this file's information with that of the other.
- // Otherwise, does nothing.
- ////////////////////////////////////////////////////////////////////
- void CPPFile::
- replace_nearer(const CPPFile &other) {
- if ((int)_source > (int)other._source) {
- (*this) = other;
- }
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::Ordering Operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- bool CPPFile::
- operator < (const CPPFile &other) const {
- return _filename < other._filename;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::Equality Operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- bool CPPFile::
- operator == (const CPPFile &other) const {
- return _filename == other._filename;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::Inequality Operator
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- bool CPPFile::
- operator != (const CPPFile &other) const {
- return _filename != other._filename;
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::c_str
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- const char *CPPFile::
- c_str() const {
- return _filename.c_str();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: CPPFile::empty
- // Access: Public
- // Description:
- ////////////////////////////////////////////////////////////////////
- bool CPPFile::
- empty() const {
- return _filename.empty();
- }
|