Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/virtualFileSystem.h

Go to the documentation of this file.
00001 // Filename: virtualFileSystem.h
00002 // Created by:  drose (03Aug02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef VIRTUALFILESYSTEM_H
00020 #define VIRTUALFILESYSTEM_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "virtualFile.h"
00025 #include "filename.h"
00026 #include "dSearchPath.h"
00027 #include "pointerTo.h"
00028 #include "pmap.h"
00029 #include "config_express.h"
00030 
00031 class Multifile;
00032 class VirtualFileMount;
00033 class VirtualFileComposite;
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //       Class : VirtualFileSystem
00037 // Description : A hierarchy of directories and files that appears to
00038 //               be one continuous file system, even though the files
00039 //               may originate from several different sources that may
00040 //               not be related to the actual OS's file system.
00041 //
00042 //               For instance, a VirtualFileSystem can transparently
00043 //               mount one or more Multifiles as their own
00044 //               subdirectory hierarchies.
00045 ////////////////////////////////////////////////////////////////////
00046 class EXPCL_PANDAEXPRESS VirtualFileSystem {
00047 PUBLISHED:
00048   VirtualFileSystem();
00049   ~VirtualFileSystem();
00050 
00051   enum MountFlags {
00052     MF_owns_pointer   = 0x0001,
00053     MF_read_only      = 0x0002,
00054   };
00055 
00056   bool mount(Multifile *multifile, const string &mount_point, int flags);
00057   bool mount(const Filename &physical_filename, const string &mount_point, int flags);
00058   int unmount(Multifile *multifile);
00059   int unmount(const Filename &physical_filename);
00060   int unmount_point(const string &mount_point);
00061   int unmount_all();
00062 
00063   bool chdir(const string &new_directory);
00064   const Filename &get_cwd() const;
00065 
00066   PT(VirtualFile) get_file(const Filename &filename) const;
00067   PT(VirtualFile) find_file(const Filename &filename, 
00068                             const DSearchPath &searchpath) const;
00069   bool resolve_filename(Filename &filename, const DSearchPath &searchpath,
00070                         const string &default_extension = string()) const;
00071   int find_all_files(const Filename &filename, const DSearchPath &searchpath,
00072                      DSearchPath::Results &results) const;
00073 
00074   INLINE bool exists(const Filename &filename) const;
00075   INLINE bool is_directory(const Filename &filename) const;
00076   INLINE bool is_regular_file(const Filename &filename) const;
00077 
00078   INLINE void ls(const string &filename) const;
00079   INLINE void ls_all(const string &filename) const;
00080 
00081   void write(ostream &out) const;
00082 
00083   static VirtualFileSystem *get_global_ptr();
00084 
00085   INLINE string read_file(const Filename &filename) const;
00086   INLINE istream *open_read_file(const Filename &filename) const;
00087 
00088 public:
00089   INLINE bool read_file(const Filename &filename, string &result) const;
00090 
00091   void scan_mount_points(vector_string &names, const Filename &path) const;
00092 
00093 private:
00094   Filename normalize_mount_point(const string &mount_point) const;
00095   bool found_match(PT(VirtualFile) &found_file, VirtualFileComposite *&composite_file,
00096                    VirtualFileMount *mount, const string &local_filename) const;
00097 
00098   typedef pvector<VirtualFileMount *> Mounts;
00099   Mounts _mounts;
00100   Filename _cwd;
00101 
00102   static VirtualFileSystem *_global_ptr;
00103 };
00104 
00105 #include "virtualFileSystem.I"
00106 
00107 #endif

Generated on Fri May 2 00:38:51 2003 for Panda by doxygen1.3