00001 // Filename: virtualFileSystem.I 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 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: VirtualFileSystem::exists 00022 // Access: Published 00023 // Description: Convenience function; returns true if the named file 00024 // exists. 00025 //////////////////////////////////////////////////////////////////// 00026 INLINE bool VirtualFileSystem:: 00027 exists(const Filename &filename) const { 00028 return get_file(filename) != (VirtualFile *)NULL; 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: VirtualFileSystem::is_directory 00033 // Access: Published 00034 // Description: Convenience function; returns true if the named file 00035 // exists and is a directory. 00036 //////////////////////////////////////////////////////////////////// 00037 INLINE bool VirtualFileSystem:: 00038 is_directory(const Filename &filename) const { 00039 PT(VirtualFile) file = get_file(filename); 00040 return (file != (VirtualFile *)NULL && file->is_directory()); 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: VirtualFileSystem::is_regular_file 00045 // Access: Published 00046 // Description: Convenience function; returns true if the named file 00047 // exists and is a regular file. 00048 //////////////////////////////////////////////////////////////////// 00049 INLINE bool VirtualFileSystem:: 00050 is_regular_file(const Filename &filename) const { 00051 PT(VirtualFile) file = get_file(filename); 00052 return (file != (VirtualFile *)NULL && file->is_regular_file()); 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: VirtualFileSystem::ls 00057 // Access: Published 00058 // Description: Convenience function; lists the files within the 00059 // indicated directory. This accepts a string instead 00060 // of a Filename purely for programmer convenience at 00061 // the Python prompt. 00062 //////////////////////////////////////////////////////////////////// 00063 INLINE void VirtualFileSystem:: 00064 ls(const string &filename) const { 00065 PT(VirtualFile) file = get_file(filename); 00066 if (file == (VirtualFile *)NULL) { 00067 express_cat.info() 00068 << "Not found: " << filename << "\n"; 00069 } else { 00070 file->ls(); 00071 } 00072 } 00073 00074 //////////////////////////////////////////////////////////////////// 00075 // Function: VirtualFileSystem::ls_all 00076 // Access: Published 00077 // Description: Convenience function; lists the files within the 00078 // indicated directory, and all files below, 00079 // recursively. This accepts a string instead of a 00080 // Filename purely for programmer convenience at the 00081 // Python prompt. 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE void VirtualFileSystem:: 00084 ls_all(const string &filename) const { 00085 PT(VirtualFile) file = get_file(filename); 00086 if (file == (VirtualFile *)NULL) { 00087 express_cat.info() 00088 << "Not found: " << filename << "\n"; 00089 } else { 00090 file->ls_all(); 00091 } 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: VirtualFileSystem::read_file 00096 // Access: Published 00097 // Description: Convenience function; returns the entire contents of 00098 // the indicated file as a string. 00099 //////////////////////////////////////////////////////////////////// 00100 INLINE string VirtualFileSystem:: 00101 read_file(const Filename &filename) const { 00102 string result; 00103 bool okflag = read_file(filename, result); 00104 nassertr(okflag, string()); 00105 return result; 00106 } 00107 00108 //////////////////////////////////////////////////////////////////// 00109 // Function: VirtualFileSystem::open_read_file 00110 // Access: Published 00111 // Description: Convenience function; returns a newly allocated 00112 // istream if the file exists and can be read, or NULL 00113 // otherwise. Does not return an invalid istream. 00114 //////////////////////////////////////////////////////////////////// 00115 INLINE istream *VirtualFileSystem:: 00116 open_read_file(const Filename &filename) const { 00117 PT(VirtualFile) file = get_file(filename); 00118 if (file == (VirtualFile *)NULL) { 00119 return NULL; 00120 } 00121 istream *str = file->open_read_file(); 00122 if (str != (istream *)NULL && str->fail()) { 00123 delete str; 00124 str = (istream *)NULL; 00125 } 00126 return str; 00127 } 00128 00129 //////////////////////////////////////////////////////////////////// 00130 // Function: VirtualFileSystem::read_file 00131 // Access: Public 00132 // Description: Convenience function; fills the string up with the 00133 // data from the indicated file, if it exists and can be 00134 // read. Returns true on success, false otherwise. 00135 //////////////////////////////////////////////////////////////////// 00136 INLINE bool VirtualFileSystem:: 00137 read_file(const Filename &filename, string &result) const { 00138 PT(VirtualFile) file = get_file(filename); 00139 return (file != (VirtualFile *)NULL && file->read_file(result)); 00140 }