15 #include "bamCacheIndex.h" 16 #include "bamReader.h" 17 #include "bamWriter.h" 18 #include "config_util.h" 45 write(ostream &out,
int indent_level)
const {
46 indent(out, indent_level)
47 <<
"BamCacheIndex, " << _records.size() <<
" records:\n";
49 Records::const_iterator ri;
50 for (ri = _records.begin(); ri != _records.end(); ++ri) {
52 indent(out, indent_level + 2)
53 << setw(10) << record->_record_size <<
" " 54 << record->get_cache_filename() <<
" " 55 << record->get_source_pathname() <<
"\n";
58 indent(out, indent_level)
59 << setw(12) << _cache_size <<
" bytes total\n";
70 process_new_records() {
71 nassertv(_cache_size == 0);
76 rv.reserve(_records.size());
78 Records::const_iterator ri;
79 for (ri = _records.begin(); ri != _records.end(); ++ri) {
81 _cache_size += record->_record_size;
85 sort(rv.begin(), rv.end(), BamCacheRecord::SortByAccessTime());
88 RecordVector::const_iterator rvi;
89 for (rvi = rv.begin(); rvi != rv.end(); ++rvi) {
91 record->insert_before(
this);
106 Records::const_iterator ri;
107 for (ri = _records.begin(); ri != _records.end(); ++ri) {
109 record->_next = NULL;
110 record->_prev = NULL;
133 bool removed = remove_record(record->get_source_pathname());
134 nassertr(removed, NULL);
150 pair<Records::iterator, bool> result =
151 _records.insert(Records::value_type(record->get_source_pathname(), record));
152 if (!result.second) {
155 orig_record->remove_from_list();
156 if (*orig_record == *record) {
158 orig_record->insert_before(
this);
162 _cache_size -= orig_record->_record_size;
163 (*result.first).second = record;
165 record->insert_before(
this);
167 _cache_size += record->_record_size;
180 remove_record(
const Filename &source_pathname) {
181 Records::iterator ri = _records.find(source_pathname);
182 if (ri == _records.end()) {
188 record->remove_from_list();
189 _cache_size -= record->_record_size;
216 Records::const_iterator ri;
217 for (ri = _records.begin(); ri != _records.end(); ++ri) {
236 parse_params(params, scan, manager);
237 object->fillin(scan, manager);
253 RecordVector::iterator vi;
254 for (vi = _record_vector.begin(); vi != _record_vector.end(); ++vi) {
258 bool inserted = _records.insert(Records::value_type(record->get_source_pathname(), record)).second;
261 <<
"Multiple cache files defining " << record->get_source_pathname()
266 _record_vector.clear();
268 process_new_records();
285 _record_vector.reserve(num_records);
286 for (
int i = 0; i < num_records; ++i) {
287 _record_vector.push_back(NULL);
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
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.
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 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.
This represents the in-memory index that records the list of files stored in the BamCache.
The name of a file, such as a texture file or an Egg file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
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...
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
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.
static void register_with_read_factory()
Tells the BamReader how to create objects of type BamCacheRecord.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.