Panda3D
|
00001 // Filename: bamCacheIndex.h 00002 // Created by: drose (19Jun06) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef BAMCACHEINDEX_H 00016 #define BAMCACHEINDEX_H 00017 00018 #include "pandabase.h" 00019 #include "bamCacheRecord.h" 00020 #include "pointerTo.h" 00021 #include "filename.h" 00022 #include "typedWritable.h" 00023 #include "linkedListNode.h" 00024 #include "pmap.h" 00025 #include "pvector.h" 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Class : BamCacheIndex 00029 // Description : This represents the in-memory index that records the 00030 // list of files stored in the BamCache. Since the 00031 // memory is also flushed to disk from time to time, 00032 // this class is a TypedWritable object. 00033 // 00034 // For the most part, this class is used only by the 00035 // BamCache class. 00036 //////////////////////////////////////////////////////////////////// 00037 class EXPCL_PANDA_PUTIL BamCacheIndex : public TypedWritable, public LinkedListNode { 00038 private: 00039 INLINE BamCacheIndex(); 00040 ~BamCacheIndex(); 00041 00042 public: 00043 void write(ostream &out, int indent_level = 0) const; 00044 00045 private: 00046 void process_new_records(); 00047 void release_records(); 00048 PT(BamCacheRecord) evict_old_file(); 00049 00050 bool add_record(BamCacheRecord *record); 00051 bool remove_record(const Filename &source_pathname); 00052 00053 private: 00054 typedef pmap<Filename, PT(BamCacheRecord) > Records; 00055 00056 Records _records; 00057 off_t _cache_size; 00058 00059 // This structure is a temporary container. It is only filled in 00060 // while reading from a bam file. 00061 typedef pvector< PT(BamCacheRecord) > RecordVector; 00062 RecordVector _record_vector; 00063 00064 public: 00065 static void register_with_read_factory(); 00066 virtual void write_datagram(BamWriter *manager, Datagram &dg); 00067 00068 protected: 00069 static TypedWritable *make_from_bam(const FactoryParams ¶ms); 00070 virtual int complete_pointers(TypedWritable **plist, BamReader *manager); 00071 void fillin(DatagramIterator &scan, BamReader *manager); 00072 00073 public: 00074 static TypeHandle get_class_type() { 00075 return _type_handle; 00076 } 00077 static void init_type() { 00078 TypedWritable::init_type(); 00079 register_type(_type_handle, "BamCacheIndex", 00080 TypedWritable::get_class_type()); 00081 } 00082 virtual TypeHandle get_type() const { 00083 return get_class_type(); 00084 } 00085 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00086 00087 private: 00088 static TypeHandle _type_handle; 00089 00090 friend class BamCache; 00091 }; 00092 00093 #include "bamCacheIndex.I" 00094 00095 #endif