IBR-DTNSuite  0.8
ibrcommon/ibrcommon/data/File.h
Go to the documentation of this file.
00001 /*
00002  * File.h
00003  *
00004  *  Created on: 20.11.2009
00005  *      Author: morgenro
00006  */
00007 
00008 #ifndef IBRCOMMON_FILE_H_
00009 #define IBRCOMMON_FILE_H_
00010 
00011 //#define USE_FILE_LOCKING 1
00012 
00013 #include <iostream>
00014 #include <map>
00015 #include <vector>
00016 #include <list>
00017 #include <dirent.h>
00018 #include <stdio.h>
00019 #include <sys/types.h>
00020 #include <sys/stat.h>
00021 #include "ibrcommon/Exceptions.h"
00022 
00023 using namespace std;
00024 
00025 namespace ibrcommon
00026 {
00031         class File
00032         {
00033         public:
00037                 File();
00038 
00044                 File(const string path);
00045 
00049                 virtual ~File();
00050 
00056                 unsigned char getType() const;
00057 
00064                 int getFiles(list<File> &files) const;
00065 
00070                 bool isSystem() const;
00071 
00076                 bool isDirectory() const;
00077 
00082                 std::string getPath() const;
00083 
00088                 std::string getBasename() const;
00089 
00095                 int remove(bool recursive = false);
00096 
00102                 File get(string filename) const;
00103 
00108                 File getParent() const;
00109 
00114                 bool exists() const;
00115 
00119                 void update();
00120 
00125                 size_t size() const;
00126 
00130                 time_t lastaccess() const;
00131 
00135                 time_t lastmodify() const;
00136 
00140                 time_t laststatchange() const;
00141 
00146                 static void createDirectory(File &path);
00147 
00148                 bool operator==(const ibrcommon::File &other) const;
00149                 bool operator<(const ibrcommon::File &other) const;
00150 
00151         private:
00152                 File(const string path, const unsigned char t);
00153                 void resolveAbsolutePath();
00154                 void removeSlash();
00155                 string _path;
00156                 unsigned char _type;
00157         };
00158 
00162         class FileNotExistsException : public ibrcommon::IOException
00163         {
00164         public:
00165                 FileNotExistsException(ibrcommon::File f) throw() : IOException("The file " + f.getPath() + " does not exists.")
00166                 {
00167                 };
00168         };
00169 
00173         class TemporaryFile : public File
00174         {
00175         public:
00176                 TemporaryFile(const File &path, const std::string prefix = "file");
00177                 virtual ~TemporaryFile();
00178 
00179         private:
00180                 static std::string tmpname(const File &path, const std::string prefix);
00181         };
00182 }
00183 
00184 #endif /* FILE_H_ */