15 #include "bamCacheRecord.h" 16 #include "bamReader.h" 17 #include "bamWriter.h" 18 #include "virtualFileSystem.h" 19 #include "virtualFile.h" 21 #include "config_util.h" 37 _record_access_time(0)
47 BamCacheRecord(
const Filename &source_pathname,
49 _source_pathname(source_pathname),
50 _cache_filename(cache_filename),
56 _record_access_time(0)
68 _source_pathname(copy._source_pathname),
69 _cache_filename(copy._cache_filename),
70 _recorded_time(copy._recorded_time),
71 _record_size(copy._record_size),
72 _source_timestamp(copy._source_timestamp),
75 _record_access_time(copy._record_access_time)
100 if (util_cat.is_debug()) {
102 <<
"Validating dependents for " << get_source_pathname() <<
"\n";
105 DependentFiles::const_iterator fi;
106 for (fi = _files.begin(); fi != _files.end(); ++fi) {
107 const DependentFile &dfile = (*fi);
111 if (dfile._timestamp != 0) {
112 if (util_cat.is_debug()) {
114 << dfile._pathname <<
" does not exist.\n";
119 if (file->get_timestamp() != dfile._timestamp ||
120 file->get_file_size() != dfile._size) {
122 if (util_cat.is_debug()) {
124 << dfile._pathname <<
" has changed timestamp or size.\n";
131 if (util_cat.is_debug()) {
133 << dfile._pathname <<
" is unchanged.\n";
137 if (util_cat.is_debug()) {
139 <<
"Dependents valid.\n";
170 _files.push_back(DependentFile());
171 DependentFile &dfile = _files.back();
172 dfile._pathname = pathname;
178 dfile._timestamp = 0;
182 dfile._timestamp = file->get_timestamp();
183 dfile._size = file->get_file_size();
185 if (dfile._pathname == _source_pathname) {
186 _source_timestamp = dfile._timestamp;
196 void BamCacheRecord::
197 output(ostream &out)
const {
198 out <<
"BamCacheRecord " << get_source_pathname();
206 void BamCacheRecord::
207 write(ostream &out,
int indent_level)
const {
208 indent(out, indent_level)
209 <<
"BamCacheRecord " << get_source_pathname() <<
"\n";
210 indent(out, indent_level)
211 <<
"source " << format_timestamp(_source_timestamp) <<
"\n";
212 indent(out, indent_level)
213 <<
"recorded " << format_timestamp(_recorded_time) <<
"\n";
215 indent(out, indent_level)
216 << _files.size() <<
" dependent files.\n";
217 DependentFiles::const_iterator fi;
218 for (fi = _files.begin(); fi != _files.end(); ++fi) {
219 const DependentFile &dfile = (*fi);
220 indent(out, indent_level + 2)
221 << setw(10) << dfile._size <<
" " 222 << format_timestamp(dfile._timestamp) <<
" " 223 << dfile._pathname <<
"\n";
233 string BamCacheRecord::
234 format_timestamp(time_t timestamp) {
235 static const size_t buffer_size = 512;
236 char buffer[buffer_size];
238 if (timestamp == 0) {
240 return " (no date) ";
243 time_t now = time(NULL);
244 struct tm *tm_p = localtime(×tamp);
246 if (timestamp > now || (now - timestamp > 86400 * 365)) {
249 strftime(buffer, buffer_size,
"%b %d %Y", tm_p);
252 strftime(buffer, buffer_size,
"%b %d %H:%M", tm_p);
284 DependentFiles::const_iterator fi;
285 for (fi = _files.begin(); fi != _files.end(); ++fi) {
286 const DependentFile &file = (*fi);
307 parse_params(params, scan, manager);
308 object->fillin(scan, manager);
320 void BamCacheRecord::
330 _files.reserve(num_files);
331 for (
unsigned int i = 0; i < num_files; ++i) {
332 _files.push_back(DependentFile());
333 DependentFile &file = _files.back();
340 if (file._pathname == _source_pathname) {
341 _source_timestamp = file._timestamp;
void add_string(const string &str)
Adds a variable-length string to the datagram.
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.
Base class for objects that can be written to and read from Bam files.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
PN_uint32 get_uint32()
Extracts an unsigned 32-bit integer.
The abstract base class for a file or directory within the VirtualFileSystem.
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...
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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 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...
void add_uint64(PN_uint64 value)
Adds an unsigned 64-bit integer to the datagram.
static VirtualFileSystem * get_global_ptr()
Returns the default global VirtualFileSystem.
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
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.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
void add_uint32(PN_uint32 value)
Adds an unsigned 32-bit integer to the datagram.
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.
PN_uint64 get_uint64()
Extracts an unsigned 64-bit integer.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...