40 write(std::ostream &out,
int indent_level)
const {
42 <<
"BamCacheIndex, " << _records.size() <<
" records:\n";
44 Records::const_iterator ri;
45 for (ri = _records.begin(); ri != _records.end(); ++ri) {
47 indent(out, indent_level + 2)
48 << std::setw(10) << record->_record_size <<
" " 49 << record->get_cache_filename() <<
" " 50 << record->get_source_pathname() <<
"\n";
54 << std::setw(12) << _cache_size <<
" bytes total\n";
62 process_new_records() {
63 nassertv(_cache_size == 0);
67 rv.reserve(_records.size());
69 Records::const_iterator ri;
70 for (ri = _records.begin(); ri != _records.end(); ++ri) {
72 _cache_size += record->_record_size;
76 sort(rv.begin(), rv.end(), BamCacheRecord::SortByAccessTime());
79 RecordVector::const_iterator rvi;
80 for (rvi = rv.begin(); rvi != rv.end(); ++rvi) {
82 record->insert_before(
this);
94 Records::const_iterator ri;
95 for (ri = _records.begin(); ri != _records.end(); ++ri) {
97 record->_next =
nullptr;
98 record->_prev =
nullptr;
118 bool removed = remove_record(record->get_source_pathname());
119 nassertr(removed,
nullptr);
132 std::pair<Records::iterator, bool> result =
133 _records.insert(Records::value_type(record->get_source_pathname(), record));
134 if (!result.second) {
137 orig_record->remove_from_list();
138 if (*orig_record == *record) {
140 orig_record->insert_before(
this);
144 _cache_size -= orig_record->_record_size;
145 (*result.first).second = record;
147 record->insert_before(
this);
149 _cache_size += record->_record_size;
159 remove_record(
const Filename &source_pathname) {
160 Records::iterator ri = _records.find(source_pathname);
161 if (ri == _records.end()) {
167 record->remove_from_list();
168 _cache_size -= record->_record_size;
190 Records::const_iterator ri;
191 for (ri = _records.begin(); ri != _records.end(); ++ri) {
208 object->fillin(scan, manager);
221 RecordVector::iterator vi;
222 for (vi = _record_vector.begin(); vi != _record_vector.end(); ++vi) {
226 bool inserted = _records.insert(Records::value_type(record->get_source_pathname(), record)).second;
229 <<
"Multiple cache files defining " << record->get_source_pathname()
234 _record_vector.clear();
236 process_new_records();
250 _record_vector.reserve(num_records);
251 for (
int i = 0; i < num_records; ++i) {
252 _record_vector.push_back(
nullptr);
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 ...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
This represents the in-memory index that records the list of files stored in the BamCache.
void parse_params(const FactoryParams ¶ms, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
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...
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
static void register_with_read_factory()
Tells the BamReader how to create objects of type BamCacheRecord.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 ...
PT(BamCacheRecord) BamCacheIndex
Evicts an old file from the cache.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.