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