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

panda/src/express/virtualFileSimple.cxx

Go to the documentation of this file.
00001 // Filename: virtualFileSimple.cxx
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 #include "virtualFileSimple.h"
00020 
00021 TypeHandle VirtualFileSimple::_type_handle;
00022 
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //     Function: VirtualFileSimple::get_file_system
00026 //       Access: Published, Virtual
00027 //  Description: Returns the VirtualFileSystem this file is associated
00028 //               with.
00029 ////////////////////////////////////////////////////////////////////
00030 VirtualFileSystem *VirtualFileSimple::
00031 get_file_system() const {
00032   return _mount->get_file_system();
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: VirtualFileSimple::get_filename
00037 //       Access: Published, Virtual
00038 //  Description: Returns the full pathname to this file within the
00039 //               virtual file system.
00040 ////////////////////////////////////////////////////////////////////
00041 Filename VirtualFileSimple::
00042 get_filename() const {
00043   string mount_point = _mount->get_mount_point();
00044   if (_local_filename.empty()) {
00045     if (mount_point.empty()) {
00046       return "/";
00047     } else {
00048       return string("/") + mount_point;
00049     }
00050 
00051   } else {
00052     if (mount_point.empty()) {
00053       return string("/") + _local_filename.get_fullpath();
00054     } else {
00055       return string("/") + mount_point + string("/") + _local_filename.get_fullpath();
00056     }
00057   }
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: VirtualFileSimple::is_directory
00062 //       Access: Published, Virtual
00063 //  Description: Returns true if this file represents a directory (and
00064 //               scan_directory() may be called), false otherwise.
00065 ////////////////////////////////////////////////////////////////////
00066 bool VirtualFileSimple::
00067 is_directory() const {
00068   return _mount->is_directory(_local_filename);
00069 }
00070 
00071 ////////////////////////////////////////////////////////////////////
00072 //     Function: VirtualFileSimple::is_regular_file
00073 //       Access: Published, Virtual
00074 //  Description: Returns true if this file represents a regular file
00075 //               (and read_file() may be called), false otherwise.
00076 ////////////////////////////////////////////////////////////////////
00077 bool VirtualFileSimple::
00078 is_regular_file() const {
00079   return _mount->is_regular_file(_local_filename);
00080 }
00081 
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: VirtualFileSimple::open_read_file
00084 //       Access: Published, Virtual
00085 //  Description: Opens the file for reading.  Returns a newly
00086 //               allocated istream on success (which you should
00087 //               eventually delete when you are done reading).
00088 //               Returns NULL on failure.
00089 ////////////////////////////////////////////////////////////////////
00090 istream *VirtualFileSimple::
00091 open_read_file() const {
00092   return _mount->open_read_file(_local_filename);
00093 }
00094 
00095 ////////////////////////////////////////////////////////////////////
00096 //     Function: VirtualFileSimple::scan_local_directory
00097 //       Access: Protected, Virtual
00098 //  Description: Fills file_list up with the list of files that are
00099 //               within this directory, excluding those whose
00100 //               basenames are listed in mount_points.  Returns true
00101 //               if successful, false if the file is not a directory
00102 //               or the directory cannot be read.
00103 ////////////////////////////////////////////////////////////////////
00104 bool VirtualFileSimple::
00105 scan_local_directory(VirtualFileList *file_list, 
00106                      const ov_set<string> &mount_points) const {
00107   vector_string names;
00108   if (!_mount->scan_directory(names, _local_filename)) {
00109     return false;
00110   }
00111 
00112   // Now the scan above gave us a list of basenames.  Turn these back
00113   // into VirtualFile pointers.
00114 
00115   // Each of the files returned by the mount will be just a simple
00116   // file within the same mount tree, unless it is shadowed by a
00117   // mount point listed in mount_points.
00118 
00119   vector_string::const_iterator ni;
00120   for (ni = names.begin(); ni != names.end(); ++ni) {
00121     const string &basename = (*ni);
00122     if (mount_points.find(basename) == mount_points.end()) {
00123       Filename filename(_local_filename, basename);
00124       VirtualFileSimple *file = new VirtualFileSimple(_mount, filename);
00125       file_list->add_file(file);
00126     }
00127   }
00128   
00129   return true;
00130 }

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