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 {
00029 class File
00030 {
00031 public:
00035 File();
00036
00042 File(const string path);
00043
00047 virtual ~File();
00048
00054 unsigned char getType() const;
00055
00062 int getFiles(list<File> &files);
00063
00068 bool isSystem() const;
00069
00074 bool isDirectory() const;
00075
00080 std::string getPath() const;
00081
00087 int remove(bool recursive = false);
00088
00094 File get(string filename) const;
00095
00100 File getParent() const;
00101
00106 bool exists() const;
00107
00111 void update();
00112
00117 size_t size() const;
00118
00123 static void createDirectory(File &path);
00124
00125 private:
00126 File(const string path, const unsigned char t);
00127 void removeSlash();
00128 string _path;
00129 unsigned char _type;
00130 };
00131
00135 class FileNotExistsException : public ibrcommon::IOException
00136 {
00137 public:
00138 FileNotExistsException(ibrcommon::File f) throw() : IOException("The file " + f.getPath() + " does not exists.")
00139 {
00140 };
00141 };
00142
00146 class TemporaryFile : public File
00147 {
00148 public:
00149 TemporaryFile(const File &path, const std::string prefix = "file");
00150 virtual ~TemporaryFile();
00151
00152 private:
00153 static std::string tmpname(const File &path, const std::string prefix);
00154 };
00155 }
00156
00157 #endif