filemanager.cpp

Go to the documentation of this file.
00001 //---------------------------------------------------
00002 //              File:filemanager.cpp                 
00003 //---------------------------------------------------
00004 
00005 #ifndef PARAMETERSINCLUDED
00006 #include "parameters.cpp"
00007 #endif
00008 
00009 #define FILEMANAGERINCLUDED
00010 
00011 using namespace std;
00012 
00013 #include<iostream>
00014 #include<cstdio>
00015 #include<cstring>
00016 #include<cstdlib>
00017 #include<string>
00018 #include<vector>
00019 #include<iterator>
00020 #include<unistd.h>
00021 
00022 class filemanager
00023 {
00024   protected: 
00025             vector<string> filelist;
00026 
00027   public: 
00028           filemanager() {
00029           }
00030 
00031           ~filemanager()
00032            {
00033              vector<string>::iterator  j=filelist.begin();
00034              for(j=filelist.begin();j!=filelist.end();j++)
00035                remove((*j).c_str());
00036            }
00037 
00038 
00039           string newTempFile(void) 
00040           {
00041             string path; int fd;
00042             char nametemplate[MAXPATH];      //requirement of mkstemp()
00043             strcpy(nametemplate,"tmp/VoX.XXXXXX");
00044             if ((fd=mkstemp(nametemplate))==-1 ) 
00045             {
00046               perror("error making temporary filename");
00047               abort();
00048             }
00049             else 
00050             {
00051              close(fd); 
00052             }
00053             path=(string)nametemplate;
00054             filelist.push_back(path);
00055             return path;
00056           }
00057 
00058 
00059           int checkTempFile(string path) 
00060           {
00061             vector<string>::iterator j;   
00062             for(j=filelist.begin();j!=filelist.end();j++)
00063             {     
00064               if(path==(*j))
00065               {  
00066                 return 1;
00067               }
00068             }
00069             return 0;
00070           }
00071 
00072 
00073           int delTempFile(string path) 
00074           {      
00075             int retval=0;
00076             vector<string>::iterator  j=filelist.begin();
00077             for(j=filelist.begin();j!=filelist.end();j++)
00078             {
00079               if(path==(*j)) 
00080               {
00081                 retval=remove((*j).c_str());
00082                 filelist.erase(j);         //check whether it works on not
00083                 return 1;
00084               }
00085             }
00086             return 0;
00087           }
00088 
00089 
00090           int makePerm(string dest, string src)
00091           {
00092             if(checkTempFile(src)==1)
00093             {             
00094               rename(dest.c_str(),src.c_str());            
00095               delTempFile(src);                       
00096               return 1;
00097             }
00098             return 0;
00099           }
00100 }filemgr;

Best viewed on Get Firefox!. Generated on Mon Mar 28 22:09:09 2005 for VoX by  doxygen 1.4.2 . This project hosted by SourceForge.net Logo .