Panda3D
 All Classes Functions Variables Enumerations
bamCacheIndex.h
1 // Filename: bamCacheIndex.h
2 // Created by: drose (19Jun06)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef BAMCACHEINDEX_H
16 #define BAMCACHEINDEX_H
17 
18 #include "pandabase.h"
19 #include "bamCacheRecord.h"
20 #include "pointerTo.h"
21 #include "filename.h"
22 #include "typedWritable.h"
23 #include "linkedListNode.h"
24 #include "pmap.h"
25 #include "pvector.h"
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : BamCacheIndex
29 // Description : This represents the in-memory index that records the
30 // list of files stored in the BamCache. Since the
31 // memory is also flushed to disk from time to time,
32 // this class is a TypedWritable object.
33 //
34 // For the most part, this class is used only by the
35 // BamCache class.
36 ////////////////////////////////////////////////////////////////////
37 class EXPCL_PANDA_PUTIL BamCacheIndex : public TypedWritable, public LinkedListNode {
38 private:
39  INLINE BamCacheIndex();
40  ~BamCacheIndex();
41 
42 public:
43  void write(ostream &out, int indent_level = 0) const;
44 
45 private:
46  void process_new_records();
47  void release_records();
48  PT(BamCacheRecord) evict_old_file();
49 
50  bool add_record(BamCacheRecord *record);
51  bool remove_record(const Filename &source_pathname);
52 
53 private:
55 
56  Records _records;
57  streamsize _cache_size;
58 
59  // This structure is a temporary container. It is only filled in
60  // while reading from a bam file.
62  RecordVector _record_vector;
63 
64 public:
65  static void register_with_read_factory();
66  virtual void write_datagram(BamWriter *manager, Datagram &dg);
67 
68 protected:
69  static TypedWritable *make_from_bam(const FactoryParams &params);
70  virtual int complete_pointers(TypedWritable **plist, BamReader *manager);
71  void fillin(DatagramIterator &scan, BamReader *manager);
72 
73 public:
74  static TypeHandle get_class_type() {
75  return _type_handle;
76  }
77  static void init_type() {
78  TypedWritable::init_type();
79  register_type(_type_handle, "BamCacheIndex",
80  TypedWritable::get_class_type());
81  }
82  virtual TypeHandle get_type() const {
83  return get_class_type();
84  }
85  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
86 
87 private:
88  static TypeHandle _type_handle;
89 
90  friend class BamCache;
91 };
92 
93 #include "bamCacheIndex.I"
94 
95 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
This class maintains a cache of Bam and/or Txo objects generated from model files and texture images ...
Definition: bamCache.h:47
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
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 just stores the pointers to implement a doubly-linked list of some kind of object.
This represents the in-memory index that records the list of files stored in the BamCache.
Definition: bamCacheIndex.h:37
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
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...
Definition: factoryParams.h:40
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43