Main Page   Class Hierarchy   Compound List   File List   Compound Members  

Path.cpp

00001 /********************************************************************
00002 ** Copyright (C) 2000 SOMELib Project
00003 **
00004 ** This library is free software; you can redistribute it and/or
00005 ** modify it under the terms of the GNU Library General Public
00006 ** License as published by the Free Software Foundation; either
00007 ** version 2 of the License, or (at your option) any later version.
00008 **
00009 ** This library is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 ** Library General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU Library General Public
00015 ** License along with this library; if not, write to the
00016 ** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017 ** Boston, MA  02111-1307, USA.
00018 **
00019 *******************************************************************/
00020 
00021 #include "Path.h"
00022 #include "PathDriver.h"
00023 #include "some_algo.h"
00024 
00025 SOME::Path::iterator SOME::Path::begin()
00026 {
00027     return file_list.begin();
00028 }
00029 SOME::Path::iterator SOME::Path::end()
00030 {
00031     return file_list.end();
00032 }
00033 SOME::Path::size_type SOME::Path::size()
00034 {
00035     return file_list.size();
00036 }
00037 
00038 SOME::Path::Path()
00039 {
00040     delimit=pdriver.getDelimit();
00041 }
00042 
00043 SOME::Path::Path( std::string path )
00044 {
00045     delimit=pdriver.getDelimit();
00046     set(path);
00047 }
00048 
00049 SOME::Path::Path( const char * path )
00050 {
00051     delimit=pdriver.getDelimit();
00052     set(string(path));
00053 }
00054 
00055 bool SOME::Path::isFile()
00056 {
00057     return isfile;
00058 }
00059 
00060 bool SOME::Path::isDir()
00061 {
00062     return isdir;
00063 }
00064 
00065 void SOME::Path::operator=( std::string path )
00066 {
00067     set(path);
00068 }
00069 
00070 void SOME::Path::operator=( const char * path )
00071 {
00072     set(string(path));
00073 }
00074 
00075 void SOME::Path::set( std::string path )
00076 {
00077     xppath=path;
00078 
00079     ppath = parsePath( path );
00080 
00081     pdriver.checkPath( ppath, isdir, isfile );
00082 
00083     if(isfile)
00084     {
00085         file_list.push_back( ppath );
00086     }
00087     else if(isdir)
00088     {
00089         //do nothing
00090         //pdriver.enumDirectory( ppath, file_list );
00091     }
00092 
00093 
00094     else
00095     {
00096         //regular expression
00097         std::string::size_type i = path.rfind(delimit);
00098         if(i==std::string::npos)
00099         {
00100             pdriver.enumDirectory( "", file_list );
00101             regex_remove(file_list.begin(), file_list.end(), file_list, path);
00102         }
00103         else
00104         {
00105             pdriver.enumDirectory( path.substr(0, i),file_list );
00106             regex_remove(file_list.begin(), file_list.end(), file_list, path.substr(i+1));
00107         }
00108     }
00109 
00110 }
00111 
00112 std::string SOME::Path::parsePath( std::string path )
00113 {
00114     if(delimit!="/")
00115         while (int pos = path.find(delimit,0)!=std::string::npos)
00116             path.replace(pos, 1, delimit);
00117 
00118 
00119     return path;
00120 }

Generated at Fri Dec 8 14:24:48 2000 for SOMELib by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000