00001 #ifndef GSGL_DATA_DIR_H 00002 #define GSGL_DATA_DIR_H 00003 00004 // 00005 // $Id: directory.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/list.hpp" 00039 #include "data/string.hpp" 00040 00041 namespace gsgl 00042 { 00043 00044 namespace data 00045 { 00046 template <typename T> class list; 00047 } 00048 00049 namespace io 00050 { 00051 00052 class file; 00053 00054 /// Represents a directory on disk. 00055 class DATA_API directory 00056 : public data_object, public data::comparable 00057 { 00058 gsgl::string name, full_path; 00059 00060 mutable data::list<file> files; 00061 mutable data::list<directory> dirs; 00062 public: 00063 directory(); 00064 directory(const string & name); 00065 ~directory(); 00066 00067 directory(const directory &); 00068 directory & operator= (const directory &); 00069 00070 virtual int compare(const comparable &) const; 00071 00072 /// \return The path that was given upon creation of the directory object. 00073 const gsgl::string & get_name() const; 00074 00075 /// \return The full (absolute) path of the directory. Guaranteed to end in a path separator. 00076 const gsgl::string & get_full_path() const; 00077 00078 /// \return A list of the files in the directory. 00079 const data::list<file> & get_files() const; 00080 00081 /// \return A list of subdirectories in the directory. 00082 const data::list<directory> & get_dirs() const; 00083 00084 /// Returns true if the particular directory exists. 00085 static bool exists(const gsgl::string & pathname); 00086 00087 static void create(const gsgl::string & pathname); 00088 00089 /// The system-dependent directory separator. 00090 static const gsgl::string SEPARATOR; 00091 00092 private: 00093 void get_paths(); 00094 }; // class directory 00095 00096 } // namespace io 00097 00098 } // namespace gsgl 00099 00100 #endif