00001 /* 00002 * Copyright 2006-2008 The FLWOR Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef ZORBA_FILE_H 00018 #define ZORBA_FILE_H 00019 00020 #ifndef WIN32 00021 #include <stdint.h> 00022 #endif 00023 00024 #include <cstdio> 00025 #include <string> 00026 #include <time.h> 00027 00028 #include <zorba/config.h> 00029 #include <zorba/file.h> 00030 #include <zorba/util/path.h> 00031 00032 namespace zorba { 00033 00034 class ZORBA_DLL_PUBLIC file : public filesystem_path 00035 { 00036 public: 00037 00038 enum filetype { 00039 type_invalid, 00040 type_non_existent, 00041 type_directory, 00042 type_link, 00043 type_file, 00044 type_volume, 00045 type_other 00046 }; 00047 00048 typedef zorba::File::FileSize_t file_size_t; 00049 00050 protected: 00051 filetype type; 00052 00053 // file attributes 00054 file_size_t size; // size in bytes 00055 00056 void do_stat(); 00057 00058 public: 00059 file(const filesystem_path &path, int flags = 0); 00060 00061 public: // common methods 00062 void set_path(std::string const& _path ) { *((filesystem_path *) this) = _path; } 00063 void set_filetype(enum filetype _type ) { type = _type ; } 00064 enum filetype get_filetype(); 00065 00066 bool is_directory() const { return (type==type_directory); } 00067 bool is_file() const { return (type==type_file); } 00068 bool is_link() const { return (type==type_link); } 00069 bool is_volume() const { return (type==type_volume); } 00070 00071 bool is_invalid() const { return (type==type_invalid); } 00072 bool exists() const { return (type!=type_non_existent && type!=type_invalid); } 00073 00074 time_t lastModified(); 00075 00076 public: // file methods 00077 void create(); 00078 void remove(bool ignore = true); 00079 void rename(std::string const& newpath); 00080 00081 file_size_t get_size() const { return size; } 00082 00083 public: // directory methods 00084 void mkdir(); 00085 void deep_mkdir(); 00086 void rmdir(bool ignore = true); 00087 #ifndef _WIN32_WCE 00088 void chdir(); 00089 #endif 00090 00091 bool is_empty() const { return (size == (file_size_t)0); } 00092 }; 00093 00094 00095 } // namespace zorba 00096 #endif /* ZORBA_FILE_H */ 00097 /* 00098 * Local variables: 00099 * mode: c++ 00100 * End: 00101 */ 00102 /* vim:set et sw=2 ts=2: */