00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IBRCOMMON_FILE_H_
00009 #define IBRCOMMON_FILE_H_
00010
00011 #include <iostream>
00012 #include <map>
00013 #include <vector>
00014 #include <list>
00015 #include <dirent.h>
00016 #include <stdio.h>
00017 #include <sys/types.h>
00018 #include <sys/stat.h>
00019 #include "ibrcommon/Exceptions.h"
00020
00021 using namespace std;
00022
00023 namespace ibrcommon
00024 {
00025 class File
00026 {
00027 public:
00028 File();
00029 File(const string path);
00030 virtual ~File();
00031 unsigned char getType() const;
00032 int getFiles(list<File> &files);
00033
00034 bool isSystem() const;
00035 bool isDirectory() const;
00036 string getPath() const;
00037 int remove(bool recursive = false);
00038
00039 File get(string filename) const;
00040
00041 File getParent() const;
00042
00043 bool exists() const;
00044
00045 void update();
00046
00047 size_t size() const;
00048
00049 static void createDirectory(File &path);
00050
00051 private:
00052 File(const string path, const unsigned char t);
00053 void removeSlash();
00054 string _path;
00055 unsigned char _type;
00056 };
00057
00058 class FileNotExistsException : public ibrcommon::IOException
00059 {
00060 public:
00061 FileNotExistsException(ibrcommon::File f) throw() : IOException("The file " + f.getPath() + " does not exists.")
00062 {
00063 };
00064 };
00065
00066 class TemporaryFile : public File
00067 {
00068 public:
00069 TemporaryFile(const File &path, const std::string prefix = "file");
00070 virtual ~TemporaryFile();
00071
00072 private:
00073 static std::string tmpname(const File &path, const std::string prefix);
00074 };
00075 }
00076
00077 #endif