00001 #ifndef GSGL_DATA_FILE_H 00002 #define GSGL_DATA_FILE_H 00003 00004 // 00005 // $Id: file.hpp 2 2008-03-01 20:58:50Z kulibali $ 00006 // 00007 // Copyright (c) 2008, The Periapsis Project. All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions are 00011 // met: 00012 // 00013 // * Redistributions of source code must retain the above copyright notice, 00014 // this list of conditions and the following disclaimer. 00015 // 00016 // * Redistributions in binary form must reproduce the above copyright 00017 // notice, this list of conditions and the following disclaimer in the 00018 // documentation and/or other materials provided with the distribution. 00019 // 00020 // * Neither the name of the The Periapsis Project nor the names of its 00021 // contributors may be used to endorse or promote products derived from 00022 // this software without specific prior written permission. 00023 // 00024 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 00025 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 00026 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 00027 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 00028 // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00030 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 00037 #include "data/data.hpp" 00038 #include "data/string.hpp" 00039 #include "data/fstream.hpp" 00040 #include "data/directory.hpp" 00041 00042 namespace gsgl 00043 { 00044 00045 namespace io 00046 { 00047 00048 extern DATA_API const gsgl::index_t MAX_PATH_SIZE; 00049 00050 /// Represents a file on disk. 00051 /// \todo Implement file information. 00052 class DATA_API file 00053 : public data_object 00054 { 00055 string name; 00056 string base_name; 00057 string dir_name; 00058 string full_path; 00059 00060 directory dir; 00061 public: 00062 file(); 00063 file(const gsgl::string & fname); 00064 ~file(); 00065 00066 file(const file & f); 00067 file & operator= (const file & f); 00068 00069 bool operator== (const file & f) const; 00070 bool operator!= (const file & f) const; 00071 00072 /// Returns a pointer to a stream opened on the file. Calling code must delete the stream. 00073 gsgl::io::ft_stream *open_text(gsgl::flags_t mode = FILE_OPEN_READ); 00074 00075 /// Returns a pointer to a stream opened on a file. Calling code must delete the stream. 00076 //static gsgl::io::ft_stream *open_text(const gsgl::string & fname, unsigned int mode = FILE_OPEN_READ); 00077 00078 /// Returns the name that the file was initialized with. 00079 const string & get_name() const; 00080 00081 /// Returns the name without any path information. 00082 const string & get_base_name() const; 00083 00084 /// Returns the name of the file's parent directory. Guaranteed to end in a path separator. 00085 const string & get_dir_name() const; 00086 00087 /// Returns the full path name of the file. 00088 const string & get_full_path() const; 00089 00090 /// Returns the directory in which the file resides. 00091 const directory & get_directory() const; 00092 00093 /// Returns the full path name of the file. 00094 static string get_full_path(const gsgl::string & fname); 00095 00096 /// Returns true if the file exists. 00097 static bool exists(const gsgl::string & fname); 00098 00099 /// Delete a file on disk. 00100 static void remove(const gsgl::string & fname); 00101 00102 /// Copy a file. 00103 static void copy(const gsgl::string & src_path, const gsgl::string & dest_path); 00104 }; // class file 00105 00106 } // namespace io 00107 00108 } // namespace gsgl 00109 00110 #endif