00001 // Filename: multifile.I 00002 // Created by: mike (09Jan97) 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: Multifile::get_multifile_name 00022 // Access: Published 00023 // Description: Returns the filename of the Multifile, if it is 00024 // available. 00025 //////////////////////////////////////////////////////////////////// 00026 INLINE const Filename &Multifile:: 00027 get_multifile_name() const { 00028 return _multifile_name; 00029 } 00030 00031 //////////////////////////////////////////////////////////////////// 00032 // Function: Multifile::is_read_valid 00033 // Access: Published 00034 // Description: Returns true if the Multifile has been opened for 00035 // read mode and there have been no errors, and 00036 // individual Subfile contents may be extracted. 00037 //////////////////////////////////////////////////////////////////// 00038 INLINE bool Multifile:: 00039 is_read_valid() const { 00040 return (_read != (istream *)NULL && !_read->fail()); 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: Multifile::is_write_valid 00045 // Access: Published 00046 // Description: Returns true if the Multifile has been opened for 00047 // write mode and there have been no errors, and 00048 // Subfiles may be added or removed from the Multifile. 00049 //////////////////////////////////////////////////////////////////// 00050 INLINE bool Multifile:: 00051 is_write_valid() const { 00052 return (_write != (ostream *)NULL && !_write->fail()); 00053 } 00054 00055 //////////////////////////////////////////////////////////////////// 00056 // Function: Multifile::needs_repack 00057 // Access: Published 00058 // Description: Returns true if the Multifile index is suboptimal and 00059 // should be repacked. Call repack() to achieve this. 00060 //////////////////////////////////////////////////////////////////// 00061 INLINE bool Multifile:: 00062 needs_repack() const { 00063 return _needs_repack || (_scale_factor != _new_scale_factor); 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: Multifile::get_scale_factor 00068 // Access: Published 00069 // Description: Returns the internal scale factor for this Multifile. 00070 // See set_scale_factor(). 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE size_t Multifile:: 00073 get_scale_factor() const { 00074 return _new_scale_factor; 00075 } 00076 00077 //////////////////////////////////////////////////////////////////// 00078 // Function: Multifile::read_subfile 00079 // Access: Published 00080 // Description: Returns a string that contains the entire contents of 00081 // the indicated subfile. 00082 //////////////////////////////////////////////////////////////////// 00083 INLINE string Multifile:: 00084 read_subfile(int index) { 00085 string result; 00086 read_subfile(index, result); 00087 return result; 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: Multifile::word_to_streampos 00092 // Access: Private 00093 // Description: Converts a size_t address read from the file to 00094 // a streampos byte address within the file. 00095 //////////////////////////////////////////////////////////////////// 00096 INLINE streampos Multifile:: 00097 word_to_streampos(size_t word) const { 00098 return (streampos)word * (streampos)_scale_factor; 00099 } 00100 00101 //////////////////////////////////////////////////////////////////// 00102 // Function: Multifile::streampos_to_word 00103 // Access: Private 00104 // Description: Converts a streampos byte address within the file to 00105 // a size_t value suitable for writing to the file. 00106 //////////////////////////////////////////////////////////////////// 00107 INLINE size_t Multifile:: 00108 streampos_to_word(streampos fpos) const { 00109 return (size_t)((fpos + (streampos)_scale_factor - (streampos)1) / (streampos)_scale_factor); 00110 } 00111 00112 //////////////////////////////////////////////////////////////////// 00113 // Function: Multifile::normalize_streampos 00114 // Access: Private 00115 // Description: Rounds the streampos byte address up to the next 00116 // multiple of _scale_factor. Only multiples of 00117 // _scale_factor may be written to the file. 00118 //////////////////////////////////////////////////////////////////// 00119 INLINE streampos Multifile:: 00120 normalize_streampos(streampos fpos) const { 00121 return word_to_streampos(streampos_to_word(fpos)); 00122 } 00123 00124 //////////////////////////////////////////////////////////////////// 00125 // Function: Multifile::Subfile::Constructor 00126 // Access: Public 00127 // Description: 00128 //////////////////////////////////////////////////////////////////// 00129 INLINE Multifile::Subfile:: 00130 Subfile() { 00131 _index_start = 0; 00132 _data_start = 0; 00133 _data_length = 0; 00134 _source = (istream *)NULL; 00135 _flags = 0; 00136 _compression_level = 0; 00137 } 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: Multifile::Subfile::operator < 00141 // Access: Public 00142 // Description: 00143 //////////////////////////////////////////////////////////////////// 00144 INLINE bool Multifile::Subfile:: 00145 operator < (const Multifile::Subfile &other) const { 00146 return _name < other._name; 00147 } 00148 00149 //////////////////////////////////////////////////////////////////// 00150 // Function: Multifile::Subfile::is_deleted 00151 // Access: Public 00152 // Description: Returns true if the Subfile indicates it has been 00153 // deleted (removed from the index), false otherwise. 00154 // This should never be true of Subfiles that currently 00155 // appear in either the _subfiles or _new_subfiles 00156 // lists. 00157 //////////////////////////////////////////////////////////////////// 00158 INLINE bool Multifile::Subfile:: 00159 is_deleted() const { 00160 return (_flags & SF_deleted) != 0; 00161 } 00162 00163 //////////////////////////////////////////////////////////////////// 00164 // Function: Multifile::Subfile::is_index_invalid 00165 // Access: Public 00166 // Description: Returns true if there was some problem reading the 00167 // index record for this Subfile from the Multifile. 00168 //////////////////////////////////////////////////////////////////// 00169 INLINE bool Multifile::Subfile:: 00170 is_index_invalid() const { 00171 return (_flags & SF_index_invalid) != 0; 00172 } 00173 00174 //////////////////////////////////////////////////////////////////// 00175 // Function: Multifile::Subfile::is_data_invalid 00176 // Access: Public 00177 // Description: Returns true if there was some problem reading the 00178 // data contents of this Subfile, particularly when 00179 // copying into the Multifile. 00180 //////////////////////////////////////////////////////////////////// 00181 INLINE bool Multifile::Subfile:: 00182 is_data_invalid() const { 00183 return (_flags & SF_data_invalid) != 0; 00184 }