Panda3D
 All Classes Functions Variables Enumerations
bamCacheRecord.I
00001 // Filename: bamCacheRecord.I
00002 // Created by:  drose (09Jun06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: BamCacheRecord::make_copy
00018 //       Access: Published
00019 //  Description: Returns a duplicate of the BamCacheRecord.  The
00020 //               duplicate will not have a data pointer set, even
00021 //               though one may have been assigned to the original via
00022 //               set_data().
00023 ////////////////////////////////////////////////////////////////////
00024 INLINE PT(BamCacheRecord) BamCacheRecord::
00025 make_copy() const {
00026   return new BamCacheRecord(*this);
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: BamCacheRecord::operator == 
00031 //       Access: Published
00032 //  Description: Returns true if the record matches the other record
00033 //               in those attributes which get written to disk.  Does
00034 //               not compare the data pointer.
00035 ////////////////////////////////////////////////////////////////////
00036 INLINE bool BamCacheRecord::
00037 operator == (const BamCacheRecord &other) const {
00038   return (_source_pathname == other._source_pathname &&
00039           _cache_filename == other._cache_filename &&
00040           _recorded_time == other._recorded_time &&
00041           _record_size == other._record_size);
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: BamCacheRecord::get_source_pathname
00046 //       Access: Published
00047 //  Description: Returns the full pathname to the source file that
00048 //               originally generated this cache request.  In some
00049 //               cases, for instance in the case of a of a multipage
00050 //               texture like "cube_#.png", this may not not a true
00051 //               filename on disk.
00052 ////////////////////////////////////////////////////////////////////
00053 INLINE const Filename &BamCacheRecord::
00054 get_source_pathname() const {
00055   return _source_pathname;
00056 }
00057 
00058 ////////////////////////////////////////////////////////////////////
00059 //     Function: BamCacheRecord::get_cache_filename
00060 //       Access: Published
00061 //  Description: Returns the name of the cache file as hashed from the
00062 //               source_pathname.  This will be relative to the root
00063 //               of the cache directory, and it will not include any
00064 //               suffixes that may be appended to resolve hash
00065 //               conflicts.
00066 ////////////////////////////////////////////////////////////////////
00067 INLINE const Filename &BamCacheRecord::
00068 get_cache_filename() const {
00069   return _cache_filename;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: BamCacheRecord::get_recorded_time
00074 //       Access: Published
00075 //  Description: Returns the time at which this particular record was
00076 //               recorded or updated.
00077 ////////////////////////////////////////////////////////////////////
00078 INLINE time_t BamCacheRecord::
00079 get_recorded_time() const {
00080   return _recorded_time;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: BamCacheRecord::get_num_dependent_files
00085 //       Access: Published
00086 //  Description: Returns the number of source files that contribute to
00087 //               the cache.
00088 ////////////////////////////////////////////////////////////////////
00089 INLINE int BamCacheRecord::
00090 get_num_dependent_files() const {
00091   return _files.size();
00092 }
00093 
00094 ////////////////////////////////////////////////////////////////////
00095 //     Function: BamCacheRecord::get_dependent_pathname
00096 //       Access: Published
00097 //  Description: Returns the full pathname of the nth source files
00098 //               that contributes to the cache.
00099 ////////////////////////////////////////////////////////////////////
00100 INLINE const Filename &BamCacheRecord::
00101 get_dependent_pathname(int n) const {
00102   nassertr(n >= 0 && n < (int)_files.size(), _files[0]._pathname);
00103   return _files[n]._pathname;
00104 }
00105 
00106 ////////////////////////////////////////////////////////////////////
00107 //     Function: BamCacheRecord::has_data
00108 //       Access: Published
00109 //  Description: Returns true if this cache record has an in-memory
00110 //               data object associated--that is, the object stored in
00111 //               the cache.
00112 ////////////////////////////////////////////////////////////////////
00113 INLINE bool BamCacheRecord::
00114 has_data() const {
00115   return (_ptr != (TypedWritable *)NULL);
00116 }
00117 
00118 ////////////////////////////////////////////////////////////////////
00119 //     Function: BamCacheRecord::clear_data
00120 //       Access: Published
00121 //  Description: Removes the in-memory data object associated with
00122 //               this record, if any.  This does not affect the
00123 //               on-disk representation of the record.
00124 ////////////////////////////////////////////////////////////////////
00125 INLINE void BamCacheRecord::
00126 clear_data() {
00127   if (_ref_ptr != NULL) {
00128     unref_delete(_ref_ptr);
00129   }
00130 
00131   _ptr = NULL;
00132   _ref_ptr = NULL;
00133 }
00134 
00135 ////////////////////////////////////////////////////////////////////
00136 //     Function: BamCacheRecord::get_data
00137 //       Access: Published
00138 //  Description: Returns a pointer to the data stored in the
00139 //               record, or NULL if there is no data.  The pointer is
00140 //               not removed from the record.
00141 ////////////////////////////////////////////////////////////////////
00142 INLINE TypedWritable *BamCacheRecord::
00143 get_data() const {
00144   return _ptr;
00145 }
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: BamCacheRecord::extract_data
00149 //       Access: Published
00150 //  Description: Fills ptr and ref_ptr with the two different-typed
00151 //               pointers to the same object, the data stored within
00152 //               this record.  This transfers ownership of the data
00153 //               pointer; the caller will be responsible for managing
00154 //               the reference counts on this object subsequently.
00155 //
00156 //               Returns true if the record contained any data (and
00157 //               the pointers have been filled), false if it didn't
00158 //               (and the pointers are NULL).
00159 ////////////////////////////////////////////////////////////////////
00160 INLINE bool BamCacheRecord::
00161 extract_data(TypedWritable *&ptr, ReferenceCount *&ref_ptr) {
00162   ptr = _ptr;
00163   ref_ptr = _ref_ptr;
00164   clear_data();
00165   return (ptr != (TypedWritable *)NULL);
00166 }
00167 
00168 ////////////////////////////////////////////////////////////////////
00169 //     Function: BamCacheRecord::set_data
00170 //       Access: Published
00171 //  Description: Stores a new data object on the record.  You should
00172 //               pass the same pointer twice, to both parameters; this
00173 //               allows the C++ typecasting to automatically convert
00174 //               the pointer into both a TypedWritable and a
00175 //               ReferenceCount pointer, so that the BamCacheRecord
00176 //               object can reliably manage the reference counts.
00177 //
00178 //               You may pass 0 or NULL as the second parameter.  If
00179 //               you do this, the BamCacheRecord will not manage the
00180 //               object's reference count; it will be up to you to
00181 //               ensure the object is not deleted during the lifetime
00182 //               of the BamCacheRecord object.
00183 ////////////////////////////////////////////////////////////////////
00184 INLINE void BamCacheRecord::
00185 set_data(TypedWritable *ptr, ReferenceCount *ref_ptr) {
00186   if (_ptr != ptr) {
00187     clear_data();
00188     _ptr = ptr;
00189     _ref_ptr = ref_ptr;
00190     if (_ref_ptr != NULL) {
00191       _ref_ptr->ref();
00192     }
00193   }
00194 }
00195 
00196 ////////////////////////////////////////////////////////////////////
00197 //     Function: BamCacheRecord::set_data
00198 //       Access: Published
00199 //  Description: This variant on set_data() is provided just to allow
00200 //               Python code to pass a 0 as the second parameter.
00201 ////////////////////////////////////////////////////////////////////
00202 INLINE void BamCacheRecord::
00203 set_data(TypedWritable *ptr, int dummy) {
00204   nassertv(dummy == 0);
00205   set_data(ptr, (ReferenceCount *)NULL);
00206 }
00207 
00208 ////////////////////////////////////////////////////////////////////
00209 //     Function: BamCacheRecord::SortByAccessTime::operator ()
00210 //       Access: Public
00211 //  Description: Returns true if a sorts before b, false otherwise.
00212 ////////////////////////////////////////////////////////////////////
00213 INLINE bool BamCacheRecord::SortByAccessTime::
00214 operator () (const BamCacheRecord *a, const BamCacheRecord *b) const {
00215   return (a->_record_access_time < b->_record_access_time);
00216 }
 All Classes Functions Variables Enumerations