proj home

Files   Classes   Functions   Hierarchy  

compilationfile.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 using namespace std;
00003 
00004 #include <compilationfile.h>
00005 #include <print.h>
00006 
00007 uint compilationfile::filenamelengthmax = 40;
00008 
00009 void compilationfile::print() const
00010 {
00011   cout << SHOW(filename) << endl;
00012   cout << SHOW(path) << endl;
00013   cout << SHOW(ft) << endl;
00014   cout << SHOW(component()) << endl;
00015   cout << SHOW(extension()) << endl;
00016 
00017   cout << SHOW(isheader()) << endl;
00018   cout << SHOW(issource()) << endl;
00019   cout << SHOW(isobj()) << endl;
00020 
00021   cout << "includes: ";
00022   for (uint i=0; i<includes.size(); ++i)
00023   {
00024     if (includes[i]==0)
00025       continue;
00026 
00027     cout << " " << includes[i]->filename;
00028   }
00029   cout << endl;
00030 }
00031 
00032 void compilationfile::clear()
00033 {
00034   filename="";
00035   path="";
00036   ft=unknown;
00037 
00038   linkheader=0;
00039   linksource=0;
00040   linkobj=0;
00041 }
00042 
00043 compilationfile::compilationfile(stringc & fullfilename)
00044 {
00045   clear();
00046 
00047   assert( fullfilename.length()>0 );
00048 
00049   string::size_type pos2 = fullfilename.rfind("/");
00050   filename = fullfilename.substr(pos2+1);
00051 
00052   path = fullfilename.substr(0,pos2+1);
00053 
00054   determinefiletype();
00055 
00056   // Maximum number of characters for hash.
00057   assert(filename.length() <= filenamelengthmax);
00058 }
00059 
00060 compilationfile::compilationfile
00061 (
00062   stringc & path_,
00063   stringc & filename_
00064 )
00065 {
00066   clear();
00067 
00068   filename=filename_;
00069   path=path_;
00070 
00071   determinefiletype();
00072 
00073   // Maximum number of characters for hash.
00074   assert(filename.length() <= filenamelengthmax);
00075 }
00076 
00077 compilationfile::compilationfile
00078 (
00079   stringc & path_,
00080   stringc & filename_,
00081   filetype ft_
00082 )
00083 {
00084   clear();
00085 
00086   filename=filename_;
00087   path=path_;
00088   ft=ft_;
00089 
00090   // Maximum number of characters for hash.
00091   assert(filename.length() <= filenamelengthmax);
00092 }
00093 
00094 stringc compilationfile::extension() const
00095 {
00096   assert( filename.length()>0 );
00097 
00098   string::size_type pos = filename.rfind(".");
00099   string s1 = filename.substr(pos);
00100 
00101   return s1;
00102 }
00103 
00104 stringc compilationfile::component() const
00105 {
00106   assert( filename.length()>0 );
00107 
00108   string::size_type pos3 = filename.rfind(".");
00109   string s1 = filename.substr(0,pos3);
00110 
00111   return s1;
00112 }
00113 
00114 void compilationfile::determinefiletype()
00115 {
00116   string ext=extension();
00117 
00118   if (ext==".h")
00119     ft=header;
00120   if (ext==".cpp")
00121     ft=source;
00122   if (ext==".o")
00123     ft=obj;
00124 }
00125 
00126 boolc compilationfile::isheader() const
00127 {
00128   return (ft==header);
00129 };
00130 
00131 boolc compilationfile::issource() const
00132 {
00133   return (ft==source);
00134 };
00135 
00136 boolc compilationfile::isobj() const
00137 {
00138   return (ft==obj);
00139 };
00140 
00141 boolc compilationfile::includesvalid() const
00142 {
00143 
00144 //cout << SHOW(this) << " " << filename << endl;
00145 
00146 /*
00147 {
00148 for (uint i=0; i<includes.size(); ++i)
00149   //cout << i << ":" <<  includes[i] << " " << includes[i]->filename << endl;
00150   cout << i << ":" <<  includes[i] << " "; 
00151 cout << endl;
00152 }
00153 */
00154 
00155 
00156   uint imax=includes.size();
00157   for (uint i=0; i<imax; ++i)
00158   {
00159     if (includes[i]==0)
00160       return false;
00161 
00162     for (uint k=i+1; k<imax; ++k)
00163     {
00164       if (includes[i]==includes[k])
00165       {
00166 cout << SHOW(this) << " " << filename << endl;
00167 cout << i << "," << k << ":" << SHOW3(includes[i]);
00168 cout << endl;
00169 this->print();
00170 
00171 //cout << " " << includes[i]->filename << endl;
00172 //for (uint i=0; i<includes.size(); ++i)
00173 //  { cout << includes[i]->print(); }
00174         return false;
00175       }
00176     }
00177   }
00178 
00179   return true;
00180 }
00181 
00182 boolc compilationfile::includesadd(compilationfile* cf)
00183 {
00184   assertreturnfalse(cf);
00185   //assert(cf);
00186 
00187 //  if (cf==this)
00188 //    return false;
00189 
00190   uint imax=includes.size();
00191   for ( uint i=0; i<imax; ++i)
00192   {
00193     if (includes[i]==cf)
00194       return false;
00195     if (includes[i]->filename==cf->filename)
00196       return false;
00197   }
00198 
00199   includes.push_back(cf);
00200 includesvalid();
00201   return true;
00202 }
00203 
00204 
00205 
00206 
00207 
00208 

Generated on Fri Mar 4 00:49:28 2011 for Chelton Evans Source by  doxygen 1.5.8