Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/cppparser/cppFile.cxx

Go to the documentation of this file.
00001 // Filename: cppFile.cxx
00002 // Created by:  drose (11Nov99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 
00020 #include "cppFile.h"
00021 
00022 #include <ctype.h>
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: CPPFile::Constructor
00026 //       Access: Public
00027 //  Description:
00028 ////////////////////////////////////////////////////////////////////
00029 CPPFile::
00030 CPPFile(const Filename &filename, const Filename &filename_as_referenced,
00031         Source source) :
00032   _filename(filename), _filename_as_referenced(filename_as_referenced),
00033   _source(source)
00034 {
00035   _filename.set_text();
00036   _filename_as_referenced.set_text();
00037 }
00038 
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: CPPFile::Copy Constructor
00042 //       Access: Public
00043 //  Description:
00044 ////////////////////////////////////////////////////////////////////
00045 CPPFile::
00046 CPPFile(const CPPFile &copy) :
00047   _filename(copy._filename),
00048   _filename_as_referenced(copy._filename_as_referenced),
00049   _source(copy._source)
00050 {
00051 }
00052 
00053 ////////////////////////////////////////////////////////////////////
00054 //     Function: CPPFile::Copy Assignment Operator
00055 //       Access: Public
00056 //  Description:
00057 ////////////////////////////////////////////////////////////////////
00058 void CPPFile::
00059 operator = (const CPPFile &copy) {
00060   _filename = copy._filename;
00061   _filename_as_referenced = copy._filename_as_referenced;
00062   _source = copy._source;
00063 }
00064 
00065 ////////////////////////////////////////////////////////////////////
00066 //     Function: CPPFile::Destructor
00067 //       Access: Public
00068 //  Description:
00069 ////////////////////////////////////////////////////////////////////
00070 CPPFile::
00071 ~CPPFile() {
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: CPPFile::is_c_or_i_file
00076 //       Access: Public
00077 //  Description: Returns true if the file appears to be a C or C++
00078 //               source code file based on its extension.  That is,
00079 //               returns true if the filename ends in .c, .C, .cc,
00080 //               .cpp, or any of a series of likely extensions.
00081 ////////////////////////////////////////////////////////////////////
00082 bool CPPFile::
00083 is_c_or_i_file() const {
00084   return is_c_or_i_file(_filename);
00085 }
00086 
00087 ////////////////////////////////////////////////////////////////////
00088 //     Function: CPPFile::is_c_or_i_file
00089 //       Access: Public, Static
00090 //  Description: Returns true if the file appears to be a C or C++
00091 //               source code file based on its extension.  That is,
00092 //               returns true if the filename ends in .c, .C, .cc,
00093 //               .cpp, or any of a series of likely extensions.
00094 ////////////////////////////////////////////////////////////////////
00095 bool CPPFile::
00096 is_c_or_i_file(const Filename &filename) {
00097   string extension = filename.get_extension();
00098   // downcase the extension.
00099   for (string::iterator ei = extension.begin();
00100        ei != extension.end();
00101        ++ei) {
00102     (*ei) = tolower(*ei);
00103   }
00104 
00105   return (extension == "c" || extension == "cc" ||
00106           extension == "cpp" || extension == "c++" || extension == "cxx" ||
00107           extension == "i" || extension == "t");
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: CPPFile::is_c_file
00112 //       Access: Public
00113 //  Description: Returns true if the file appears to be a C or C++
00114 //               source code file based on its extension.  That is,
00115 //               returns true if the filename ends in .c, .C, .cc,
00116 //               .cpp, or any of a series of likely extensions.
00117 ////////////////////////////////////////////////////////////////////
00118 bool CPPFile::
00119 is_c_file() const {
00120   return is_c_file(_filename);
00121 }
00122 
00123 ////////////////////////////////////////////////////////////////////
00124 //     Function: CPPFile::is_c_file
00125 //       Access: Public, Static
00126 //  Description: Returns true if the file appears to be a C or C++
00127 //               source code file based on its extension.  That is,
00128 //               returns true if the filename ends in .c, .C, .cc,
00129 //               .cpp, or any of a series of likely extensions.
00130 ////////////////////////////////////////////////////////////////////
00131 bool CPPFile::
00132 is_c_file(const Filename &filename) {
00133   string extension = filename.get_extension();
00134   // downcase the extension.
00135   for (string::iterator ei = extension.begin();
00136        ei != extension.end();
00137        ++ei) {
00138     (*ei) = tolower(*ei);
00139   }
00140 
00141   return (extension == "c" || extension == "cc" ||
00142           extension == "cpp" || extension == "c++" || extension == "cxx");
00143 }
00144 
00145 ////////////////////////////////////////////////////////////////////
00146 //     Function: CPPFile::replace_nearer
00147 //       Access: Public
00148 //  Description: If the other file is "nearer" than this file (in the
00149 //               sense that a file in the local directory is nearer
00150 //               than a file in the system directory, etc.), replaces
00151 //               this file's information with that of the other.
00152 //               Otherwise, does nothing.
00153 ////////////////////////////////////////////////////////////////////
00154 void CPPFile::
00155 replace_nearer(const CPPFile &other) {
00156   if ((int)_source > (int)other._source) {
00157     (*this) = other;
00158   }
00159 }
00160 
00161 ////////////////////////////////////////////////////////////////////
00162 //     Function: CPPFile::Ordering Operator
00163 //       Access: Public
00164 //  Description:
00165 ////////////////////////////////////////////////////////////////////
00166 bool CPPFile::
00167 operator < (const CPPFile &other) const {
00168   return _filename < other._filename;
00169 }
00170 
00171 ////////////////////////////////////////////////////////////////////
00172 //     Function: CPPFile::Equality Operator
00173 //       Access: Public
00174 //  Description:
00175 ////////////////////////////////////////////////////////////////////
00176 bool CPPFile::
00177 operator == (const CPPFile &other) const {
00178   return _filename == other._filename;
00179 }
00180 
00181 ////////////////////////////////////////////////////////////////////
00182 //     Function: CPPFile::Inequality Operator
00183 //       Access: Public
00184 //  Description:
00185 ////////////////////////////////////////////////////////////////////
00186 bool CPPFile::
00187 operator != (const CPPFile &other) const {
00188   return _filename != other._filename;
00189 }
00190 
00191 ////////////////////////////////////////////////////////////////////
00192 //     Function: CPPFile::c_str
00193 //       Access: Public
00194 //  Description:
00195 ////////////////////////////////////////////////////////////////////
00196 const char *CPPFile::
00197 c_str() const {
00198   return _filename.c_str();
00199 }
00200 
00201 ////////////////////////////////////////////////////////////////////
00202 //     Function: CPPFile::empty
00203 //       Access: Public
00204 //  Description:
00205 ////////////////////////////////////////////////////////////////////
00206 bool CPPFile::
00207 empty() const {
00208   return _filename.empty();
00209 }

Generated on Thu May 1 22:12:51 2003 for DTool by doxygen1.3