Panda3D
|
00001 // Filename: bamCacheRecord.h 00002 // Created by: drose (08Jun06) 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 #ifndef BAMCACHERECORD_H 00016 #define BAMCACHERECORD_H 00017 00018 #include "pandabase.h" 00019 #include "typedWritableReferenceCount.h" 00020 #include "pointerTo.h" 00021 #include "linkedListNode.h" 00022 00023 class BamWriter; 00024 class BamReader; 00025 class Datagram; 00026 class DatagramIterator; 00027 class FactoryParams; 00028 class BamCacheRecord; 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Class : BamCacheRecord 00032 // Description : An instance of this class is written to the front of 00033 // a Bam or Txo file to make the file a cached instance 00034 // of some other loadable resource. This record 00035 // contains information needed to test the validity of 00036 // the cache. 00037 //////////////////////////////////////////////////////////////////// 00038 class EXPCL_PANDA_PUTIL BamCacheRecord : public TypedWritableReferenceCount, 00039 public LinkedListNode { 00040 private: 00041 BamCacheRecord(); 00042 BamCacheRecord(const Filename &source_pathname, 00043 const Filename &cache_filename); 00044 BamCacheRecord(const BamCacheRecord ©); 00045 00046 PUBLISHED: 00047 virtual ~BamCacheRecord(); 00048 00049 INLINE PT(BamCacheRecord) make_copy() const; 00050 00051 INLINE bool operator == (const BamCacheRecord &other) const; 00052 00053 INLINE const Filename &get_source_pathname() const; 00054 INLINE const Filename &get_cache_filename() const; 00055 INLINE time_t get_recorded_time() const; 00056 00057 INLINE int get_num_dependent_files() const; 00058 INLINE const Filename &get_dependent_pathname(int n) const; 00059 00060 bool dependents_unchanged() const; 00061 void clear_dependent_files(); 00062 void add_dependent_file(const Filename &pathname); 00063 00064 INLINE bool has_data() const; 00065 INLINE void clear_data(); 00066 INLINE TypedWritable *get_data() const; 00067 INLINE bool extract_data(TypedWritable *&ptr, ReferenceCount *&ref_ptr); 00068 INLINE void set_data(TypedWritable *ptr, ReferenceCount *ref_ptr); 00069 INLINE void set_data(TypedWritable *ptr, int dummy); 00070 00071 void output(ostream &out) const; 00072 void write(ostream &out, int indent_level = 0) const; 00073 00074 private: 00075 // This class is used to sort BamCacheRecords by access time. 00076 class SortByAccessTime { 00077 public: 00078 INLINE bool operator () (const BamCacheRecord *a, const BamCacheRecord *b) const; 00079 }; 00080 00081 static string format_timestamp(time_t timestamp); 00082 00083 Filename _source_pathname; 00084 Filename _cache_filename; 00085 time_t _recorded_time; 00086 off_t _record_size; // this is accurate only in the index file. 00087 00088 class DependentFile { 00089 public: 00090 Filename _pathname; 00091 time_t _timestamp; 00092 off_t _size; 00093 }; 00094 00095 typedef pvector<DependentFile> DependentFiles; 00096 DependentFiles _files; 00097 00098 // The following are not recorded to disk; they are preserved 00099 // in-memory only for the current session. 00100 Filename _cache_pathname; 00101 TypedWritable *_ptr; 00102 ReferenceCount *_ref_ptr; 00103 00104 // The following are not recorded to disk, nor even returned by the 00105 // BamCache interface. They are strictly meaningful to the 00106 // BamCacheRecords stored internally within the BamCache object. 00107 time_t _record_access_time; 00108 00109 public: 00110 static void register_with_read_factory(); 00111 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00112 00113 protected: 00114 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00115 void fillin(DatagramIterator &scan, BamReader *manager); 00116 00117 public: 00118 static TypeHandle get_class_type() { 00119 return _type_handle; 00120 } 00121 static void init_type() { 00122 TypedWritableReferenceCount::init_type(); 00123 register_type(_type_handle, "BamCacheRecord", 00124 TypedWritableReferenceCount::get_class_type()); 00125 } 00126 virtual TypeHandle get_type() const { 00127 return get_class_type(); 00128 } 00129 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00130 00131 private: 00132 static TypeHandle _type_handle; 00133 00134 friend class BamCache; 00135 friend class BamCacheIndex; 00136 friend class BamCacheRecord::SortByAccessTime; 00137 }; 00138 00139 INLINE ostream &operator << (ostream &out, const BamCacheRecord &record) { 00140 record.output(out); 00141 return out; 00142 } 00143 00144 #include "bamCacheRecord.I" 00145 00146 #endif