Panda3D
bamCacheRecord.h
1 // Filename: bamCacheRecord.h
2 // Created by: drose (08Jun06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef BAMCACHERECORD_H
16 #define BAMCACHERECORD_H
17 
18 #include "pandabase.h"
19 #include "typedWritableReferenceCount.h"
20 #include "pointerTo.h"
21 #include "linkedListNode.h"
22 
23 class BamWriter;
24 class BamReader;
25 class Datagram;
26 class DatagramIterator;
27 class FactoryParams;
28 class BamCacheRecord;
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : BamCacheRecord
32 // Description : An instance of this class is written to the front of
33 // a Bam or Txo file to make the file a cached instance
34 // of some other loadable resource. This record
35 // contains information needed to test the validity of
36 // the cache.
37 ////////////////////////////////////////////////////////////////////
38 class EXPCL_PANDA_PUTIL BamCacheRecord : public TypedWritableReferenceCount,
39  public LinkedListNode {
40 private:
42  BamCacheRecord(const Filename &source_pathname,
43  const Filename &cache_filename);
44  BamCacheRecord(const BamCacheRecord &copy);
45 
46 PUBLISHED:
47  virtual ~BamCacheRecord();
48 
49  INLINE PT(BamCacheRecord) make_copy() const;
50 
51  INLINE bool operator == (const BamCacheRecord &other) const;
52 
53  INLINE const Filename &get_source_pathname() const;
54  INLINE const Filename &get_cache_filename() const;
55  INLINE time_t get_source_timestamp() const;
56  INLINE time_t get_recorded_time() const;
57 
58  INLINE int get_num_dependent_files() const;
59  INLINE const Filename &get_dependent_pathname(int n) const;
60 
61  bool dependents_unchanged() const;
62  void clear_dependent_files();
63  void add_dependent_file(const Filename &pathname);
64 
65  INLINE bool has_data() const;
66  INLINE void clear_data();
67  INLINE TypedWritable *get_data() const;
68  INLINE bool extract_data(TypedWritable *&ptr, ReferenceCount *&ref_ptr);
69  INLINE void set_data(TypedWritable *ptr, ReferenceCount *ref_ptr);
70  INLINE void set_data(TypedWritable *ptr, int dummy);
71 
72  void output(ostream &out) const;
73  void write(ostream &out, int indent_level = 0) const;
74 
75 private:
76  // This class is used to sort BamCacheRecords by access time.
77  class SortByAccessTime {
78  public:
79  INLINE bool operator () (const BamCacheRecord *a, const BamCacheRecord *b) const;
80  };
81 
82  static string format_timestamp(time_t timestamp);
83 
84  Filename _source_pathname;
85  Filename _cache_filename;
86  time_t _recorded_time;
87  streamsize _record_size; // this is accurate only in the index file.
88  time_t _source_timestamp; // Not record to the cache file.
89 
90  class DependentFile {
91  public:
92  Filename _pathname;
93  time_t _timestamp;
94  streamsize _size;
95  };
96 
98  DependentFiles _files;
99 
100  // The following are not recorded to disk; they are preserved
101  // in-memory only for the current session.
102  Filename _cache_pathname;
103  TypedWritable *_ptr;
104  ReferenceCount *_ref_ptr;
105 
106  // The following are not recorded to disk, nor even returned by the
107  // BamCache interface. They are strictly meaningful to the
108  // BamCacheRecords stored internally within the BamCache object.
109  time_t _record_access_time;
110 
111 public:
112  static void register_with_read_factory();
113  virtual void write_datagram(BamWriter *manager, Datagram &dg);
114 
115 protected:
116  static TypedWritable *make_from_bam(const FactoryParams &params);
117  void fillin(DatagramIterator &scan, BamReader *manager);
118 
119 public:
120  static TypeHandle get_class_type() {
121  return _type_handle;
122  }
123  static void init_type() {
124  TypedWritableReferenceCount::init_type();
125  register_type(_type_handle, "BamCacheRecord",
126  TypedWritableReferenceCount::get_class_type());
127  }
128  virtual TypeHandle get_type() const {
129  return get_class_type();
130  }
131  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
132 
133 private:
134  static TypeHandle _type_handle;
135 
136  friend class BamCache;
137  friend class BamCacheIndex;
138  friend class BamCacheRecord::SortByAccessTime;
139 };
140 
141 INLINE ostream &operator << (ostream &out, const BamCacheRecord &record) {
142  record.output(out);
143  return out;
144 }
145 
146 #include "bamCacheRecord.I"
147 
148 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This class maintains a cache of Bam and/or Txo objects generated from model files and texture images ...
Definition: bamCache.h:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This just stores the pointers to implement a doubly-linked list of some kind of object.
This represents the in-memory index that records the list of files stored in the BamCache.
Definition: bamCacheIndex.h:37
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
A base class for all things that want to be reference-counted.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43