file.h

Go to the documentation of this file.
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 #ifndef ZORBA_FILE_H
00017 #define ZORBA_FILE_H
00018 
00019 #include <cstdio>
00020 
00021 #include <time.h>
00022 #include <string>
00023 
00024 #include <zorba/util/path.h>
00025 
00026 namespace zorba {
00027 
00028 class file : public filesystem_path
00029 {
00030 public:
00031   enum filetype {
00032     type_invalid,
00033     type_non_existent,
00034     type_directory,
00035     type_link,
00036     type_file,
00037     type_volume
00038   };
00039 
00040 #ifdef WIN32
00041   typedef __int64 file_size_t;
00042 #else
00043   typedef int64_t file_size_t;
00044 #endif
00045 
00046 protected:
00047   enum filetype type; 
00048 
00049 // file attributes
00050   file_size_t  size;          // size in bytes
00051 
00052   void do_stat ();
00053 
00054 public:
00055   file(const filesystem_path &path, int flags = 0);
00056 
00057 public: // common methods
00058   void set_path(std::string const& _path ) { *((filesystem_path *) this) = _path; }
00059   void set_filetype(enum filetype _type ) { type = _type ; }
00060   enum filetype get_filetype();
00061 
00062   bool is_directory() const { return (type==type_directory); }  
00063   bool is_file() const { return (type==type_file); }  
00064   bool is_link() const { return (type==type_link); }  
00065   bool is_volume() const { return (type==type_volume); }  
00066 
00067   bool is_invalid() const { return (type==type_invalid); }  
00068   bool exists() const { return (type!=type_non_existent && type!=type_invalid); }  
00069   static volatile void error(std::string const& location, std::string const& msg);
00070 
00071 public: // file methods
00072   void create();
00073   void remove(bool ignore = true);
00074   void rename(std::string const& newpath);
00075 
00076   file_size_t get_size() const        { return size; }
00077 
00078 public: // directory methods
00079   void mkdir();
00080   void deep_mkdir();
00081   void rmdir(bool ignore);
00082 #ifndef _WIN32_WCE
00083   void chdir();
00084 #endif
00085 
00086   bool is_empty() const { return (size == (file_size_t)0); }
00087 };
00088 
00089 
00090 } /* namespace zorba */
00091 #endif /* ZORBA_FILE_H */
00092 
00093 /*
00094  * Local variables:
00095  * mode: c++
00096  * End:
00097  */