Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

base.FileSystem.h

00001 /*----------------------------------------------------------------------------
00002   SWORD 2000 - Software With Objects for Rapid Development
00003   Copyright (C) 2003 David Jobet
00004   ----------------------------------------------------------------------------
00005   SWORD is free software; you can redistribute it and/or modify
00006   it under the terms of the GNU Lesser General Public License as published by
00007   the Free Software Foundation; either version 2 of the License, or
00008   (at your option) any later version.
00009 
00010   SWORD is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013   GNU Lesser General Public License for more details.
00014 
00015   You should have received a copy of the GNU Lesser General Public License
00016   along with SWORD; if not, write to the Free Software
00017   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018   --------------------------------------------------------------------------*/
00019 #ifndef _SWORD_BASE_FILESYSTEM_
00020 #define _SWORD_BASE_FILESYSTEM_
00021 
00022 #include "sword/streams.File.h"
00023 #include <vector>
00024 
00025 namespace sword {
00026 
00027         class SWORDDECL FileSystem {
00028         public:
00029                 FileSystem(const std::string& path);
00030                 FileSystem(const File& file);
00031                 FileSystem();
00032 
00033                 void chdir(const std::string& path);
00034                 void chdir(const File& file);
00035 
00036                 void mkdir(const std::string& path) const;
00037                 void mkdir(const File& path) const;
00038                 static void remove(const std::string& path);
00039                 static void remove(const File& path);
00040                 static void removeFile(const std::string& path);
00041                 static void removeFile(const File& path);
00042                 static void removeDirectory(const std::string& path);
00043                 static void removeDirectory(const File& path);
00044 
00045                 // --- Different ways of accessing a disk file
00046 
00047                 enum Mode
00048                 {
00049                         // File reading modes
00050                         open           = 1,       // Open an existing file (the file *must* exist)
00051                         openOrCreate   = 2,       // Open a file or create it empty if it was not there
00052 
00053                         // File writing modes
00054                         create         = 3,       // Create a new file (there *must not* be a file already there)
00055                         createAlways   = 4,       // Create a new file always (if there is already one, truncate it)
00056                         append         = 5,       // Append to a file (there *must* be a file already there)
00057                         appendOrCreate = 6,       // Append to a file or create it if it was not there
00058 
00059                         // File reading and writing additional options (hints)
00060                         inherit        = 0x0100,  // Child process will inherit it
00061                         random         = 0x0200,  // Will do only random access
00062                         sequential     = 0x0400   // Will do only sequential access
00063                 };
00064 
00065                 // --- exceptions
00066                 class RemoveException : public Exception {};
00067                 class MkdirException : public Exception {};
00068 
00069                 class const_iterator
00070                 {
00071                 public :
00072                         const_iterator(const FileSystem *fileSystem, int index = 0);
00073                         const_iterator(const const_iterator &it);
00074 
00075                         ~const_iterator();
00076 
00077                         const File &operator *()  const;
00078                         const File *operator ->() const;
00079                         bool operator ==(const const_iterator &it) const;
00080                         bool operator !=(const const_iterator &it) const;
00081                         const_iterator &operator ++();
00082                         const_iterator &operator --();
00083 
00084                 private :
00085                         const FileSystem *fileSystem_;
00086                 int index_;
00087                 };
00088                 friend class const_iterator;
00089 
00090                 const_iterator begin() const;
00091                 const_iterator end() const;
00092 
00093         private:
00094                 File current_;
00095                 mutable word nbLiveIterator_;
00096                 mutable std::vector<File> cache_;
00097 
00098                 static void mkdir_   (const std::string &path);
00099                 void cacheFiles_() const;
00100         };
00101 
00102 } // namespace sword
00103 
00104 #include "sword.private/base.FileSystem.inl"
00105 
00106 #endif // _SWORD_BASE_FILESYSTEM_
00107 

Generated on Tue Dec 23 20:08:56 2003 for SWORD by doxygen1.3-rc2