34 _record_access_time(0)
42 BamCacheRecord(
const Filename &source_pathname,
44 _source_pathname(source_pathname),
45 _cache_filename(cache_filename),
51 _record_access_time(0)
60 _source_pathname(copy._source_pathname),
61 _cache_filename(copy._cache_filename),
62 _recorded_time(copy._recorded_time),
63 _record_size(copy._record_size),
64 _source_timestamp(copy._source_timestamp),
67 _record_access_time(copy._record_access_time)
87 if (util_cat.is_debug()) {
89 <<
"Validating dependents for " << get_source_pathname() <<
"\n";
92 DependentFiles::const_iterator fi;
93 for (fi = _files.begin(); fi != _files.end(); ++fi) {
94 const DependentFile &dfile = (*fi);
96 if (file ==
nullptr) {
98 if (dfile._timestamp != 0) {
99 if (util_cat.is_debug()) {
101 << dfile._pathname <<
" does not exist.\n";
106 if (file->get_timestamp() != dfile._timestamp ||
107 file->get_file_size() != dfile._size) {
109 if (util_cat.is_debug()) {
111 << dfile._pathname <<
" has changed timestamp or size.\n";
118 if (util_cat.is_debug()) {
120 << dfile._pathname <<
" is unchanged.\n";
124 if (util_cat.is_debug()) {
126 <<
"Dependents valid.\n";
150 _files.push_back(DependentFile());
151 DependentFile &dfile = _files.back();
152 dfile._pathname = pathname;
156 if (file ==
nullptr) {
158 dfile._timestamp = 0;
162 dfile._timestamp = file->get_timestamp();
163 dfile._size = file->get_file_size();
165 if (dfile._pathname == _source_pathname) {
166 _source_timestamp = dfile._timestamp;
176 _files.push_back(DependentFile());
177 DependentFile &dfile = _files.back();
178 dfile._pathname = file->get_filename();
184 if (dfile._pathname == _source_pathname) {
185 _source_timestamp = dfile._timestamp;
192 void BamCacheRecord::
193 output(std::ostream &out)
const {
194 out <<
"BamCacheRecord " << get_source_pathname();
200 void BamCacheRecord::
201 write(std::ostream &out,
int indent_level)
const {
203 <<
"BamCacheRecord " << get_source_pathname() <<
"\n";
205 <<
"source " << format_timestamp(_source_timestamp) <<
"\n";
207 <<
"recorded " << format_timestamp(_recorded_time) <<
"\n";
210 << _files.size() <<
" dependent files.\n";
211 DependentFiles::const_iterator fi;
212 for (fi = _files.begin(); fi != _files.end(); ++fi) {
213 const DependentFile &dfile = (*fi);
214 indent(out, indent_level + 2)
215 << std::setw(10) << dfile._size <<
" " 216 << format_timestamp(dfile._timestamp) <<
" " 217 << dfile._pathname <<
"\n";
224 std::string BamCacheRecord::
225 format_timestamp(time_t timestamp) {
226 static const size_t buffer_size = 512;
227 char buffer[buffer_size];
229 if (timestamp == 0) {
231 return " (no date) ";
234 time_t now = time(
nullptr);
237 localtime_s(&atm, ×tamp);
239 localtime_r(×tamp, &atm);
242 if (timestamp > now || (now - timestamp > 86400 * 365)) {
245 strftime(buffer, buffer_size,
"%b %d %Y", &atm);
248 strftime(buffer, buffer_size,
"%b %d %H:%M", &atm);
275 DependentFiles::const_iterator fi;
276 for (fi = _files.begin(); fi != _files.end(); ++fi) {
277 const DependentFile &file = (*fi);
296 object->fillin(scan, manager);
305 void BamCacheRecord::
315 _files.reserve(num_files);
316 for (
unsigned int i = 0; i < num_files; ++i) {
317 _files.push_back(DependentFile());
318 DependentFile &file = _files.back();
325 if (file._pathname == _source_pathname) {
326 _source_timestamp = file._timestamp;
uint64_t get_uint64()
Extracts an unsigned 64-bit integer.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS's file system.
virtual std::streamsize get_file_size(std::istream *stream) const
Returns the current size on disk (or wherever it is) of the already-open file.
Base class for objects that can be written to and read from Bam files.
virtual time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
The abstract base class for a file or directory within the VirtualFileSystem.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std::string get_string()
Extracts a variable-length string.
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.
void add_uint32(uint32_t value)
Adds an unsigned 32-bit integer to the datagram.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function...
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
The name of a file, such as a texture file or an Egg file.
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
void add_string(const std::string &str)
Adds a variable-length string to the datagram.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
uint32_t get_uint32()
Extracts an unsigned 32-bit integer.
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
PointerTo< VirtualFile > get_file(const Filename &filename, bool status_only=false) const
Looks up the file by the indicated name in the file system.
static void register_with_read_factory()
Tells the BamReader how to create objects of type BamCacheRecord.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void make_absolute()
Converts the filename to a fully-qualified pathname from the root (if it is a relative pathname)...
void clear_dependent_files()
Empties the list of files that contribute to the data in this record.
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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...
A class to retrieve the individual data elements previously stored in a Datagram. ...
bool dependents_unchanged() const
Returns true if all of the dependent files are still the same as when the cache was recorded...
TypeHandle is the identifier used to differentiate C++ class types.
void add_uint64(uint64_t value)
Adds an unsigned 64-bit integer to the datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.