Panda3D
Loading...
Searching...
No Matches
bamCacheRecord.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file bamCacheRecord.h
10 * @author drose
11 * @date 2006-06-08
12 */
13
14#ifndef BAMCACHERECORD_H
15#define BAMCACHERECORD_H
16
17#include "pandabase.h"
19#include "pointerTo.h"
20#include "linkedListNode.h"
21
22class BamWriter;
23class BamReader;
24class Datagram;
26class FactoryParams;
27class BamCacheRecord;
28class VirtualFile;
29
30/**
31 * An instance of this class is written to the front of a Bam or Txo file to
32 * make the file a cached instance of some other loadable resource. This
33 * record contains information needed to test the validity of the cache.
34 */
35class EXPCL_PANDA_PUTIL BamCacheRecord : public TypedWritableReferenceCount,
36 public LinkedListNode {
37private:
38 BamCacheRecord();
39 BamCacheRecord(const Filename &source_pathname,
40 const Filename &cache_filename);
41 BamCacheRecord(const BamCacheRecord &copy);
42
43PUBLISHED:
44 virtual ~BamCacheRecord();
45
46 INLINE PT(BamCacheRecord) make_copy() const;
47
48 INLINE bool operator == (const BamCacheRecord &other) const;
49
50 INLINE const Filename &get_source_pathname() const;
51 INLINE const Filename &get_cache_filename() const;
52 INLINE time_t get_source_timestamp() const;
53 INLINE time_t get_recorded_time() const;
54
55 MAKE_PROPERTY(source_pathname, get_source_pathname);
56 MAKE_PROPERTY(cache_filename, get_cache_filename);
57 MAKE_PROPERTY(source_timestamp, get_source_timestamp);
58 MAKE_PROPERTY(recorded_time, get_recorded_time);
59
60 INLINE int get_num_dependent_files() const;
61 INLINE const Filename &get_dependent_pathname(int n) const;
62
63 bool dependents_unchanged() const;
65 void add_dependent_file(const Filename &pathname);
66 void add_dependent_file(const VirtualFile *file);
67
68 INLINE bool has_data() const;
69 INLINE void clear_data();
70 INLINE TypedWritable *get_data() const;
71 INLINE bool extract_data(TypedWritable *&ptr, ReferenceCount *&ref_ptr);
72 INLINE void set_data(TypedWritable *ptr, ReferenceCount *ref_ptr);
73 INLINE void set_data(TypedWritable *ptr);
74 INLINE void set_data(TypedWritableReferenceCount *ptr);
75 INLINE void set_data(TypedWritable *ptr, int dummy);
76
77 MAKE_PROPERTY2(data, has_data, get_data, set_data, clear_data);
78
79 void output(std::ostream &out) const;
80 void write(std::ostream &out, int indent_level = 0) const;
81
82private:
83 // This class is used to sort BamCacheRecords by access time.
84 class SortByAccessTime {
85 public:
86 INLINE bool operator () (const BamCacheRecord *a, const BamCacheRecord *b) const;
87 };
88
89 static std::string format_timestamp(time_t timestamp);
90
91 Filename _source_pathname;
92 Filename _cache_filename;
93 time_t _recorded_time;
94 std::streamsize _record_size; // this is accurate only in the index file.
95 time_t _source_timestamp; // Not record to the cache file.
96
97 class DependentFile {
98 public:
99 Filename _pathname;
100 time_t _timestamp;
101 std::streamsize _size;
102 };
103
104 typedef pvector<DependentFile> DependentFiles;
105 DependentFiles _files;
106
107 // The following are not recorded to disk; they are preserved in-memory only
108 // for the current session.
109 Filename _cache_pathname;
110 TypedWritable *_ptr;
111 ReferenceCount *_ref_ptr;
112
113 // The following are not recorded to disk, nor even returned by the BamCache
114 // interface. They are strictly meaningful to the BamCacheRecords stored
115 // internally within the BamCache object.
116 time_t _record_access_time;
117
118public:
119 static void register_with_read_factory();
120 virtual void write_datagram(BamWriter *manager, Datagram &dg);
121
122protected:
123 static TypedWritable *make_from_bam(const FactoryParams &params);
124 void fillin(DatagramIterator &scan, BamReader *manager);
125
126public:
127 static TypeHandle get_class_type() {
128 return _type_handle;
129 }
130 static void init_type() {
131 TypedWritableReferenceCount::init_type();
132 register_type(_type_handle, "BamCacheRecord",
133 TypedWritableReferenceCount::get_class_type());
134 }
135 virtual TypeHandle get_type() const {
136 return get_class_type();
137 }
138 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
139
140private:
141 static TypeHandle _type_handle;
142
143 friend class BamCache;
144 friend class BamCacheIndex;
145 friend class BamCacheRecord::SortByAccessTime;
146};
147
148INLINE std::ostream &operator << (std::ostream &out, const BamCacheRecord &record) {
149 record.output(out);
150 return out;
151}
152
153#include "bamCacheRecord.I"
154
155#endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
void add_dependent_file(const Filename &pathname)
Adds the indicated file to the list of files that will be loaded to generate the data in this record.
get_data
Returns a pointer to the data stored in the record, or NULL if there is no data.
bool extract_data(TypedWritable *&ptr, ReferenceCount *&ref_ptr)
Fills ptr and ref_ptr with the two different-typed pointers to the same object, the data stored withi...
set_data
Stores a new data object on the record.
void clear_dependent_files()
Empties the list of files that contribute to the data in this record.
bool dependents_unchanged() const
Returns true if all of the dependent files are still the same as when the cache was recorded,...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
The abstract base class for a file or directory within the VirtualFileSystem.
Definition virtualFile.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.