00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __BAM_READER_
00020 #define __BAM_READER_
00021
00022 #include "pandabase.h"
00023 #include "notify.h"
00024
00025 #include "typedWritable.h"
00026 #include "datagramGenerator.h"
00027 #include "datagramIterator.h"
00028 #include "bamReaderParam.h"
00029 #include "factory.h"
00030 #include "vector_int.h"
00031 #include "pset.h"
00032 #include "dcast.h"
00033
00034 #include <algorithm>
00035
00036 struct PipelineCyclerBase;
00037
00038
00039
00040 #define READ_PTA(Manager, source, Read_func, array) \
00041 { \
00042 void *t; \
00043 if ((t = Manager->get_pta(source)) == (void*)NULL) \
00044 { \
00045 array = Read_func(source); \
00046 Manager->register_pta(array.get_void_ptr()); \
00047 } \
00048 else \
00049 { \
00050 array.set_void_ptr(t); \
00051 } \
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088 class EXPCL_PANDA BamReader {
00089 public:
00090 typedef Factory<TypedWritable> WritableFactory;
00091 static BamReader *const Null;
00092 static WritableFactory *const NullFactory;
00093
00094
00095
00096 BamReader(DatagramGenerator *generator);
00097 ~BamReader();
00098
00099 bool init();
00100 TypedWritable *read_object();
00101 INLINE bool is_eof() const;
00102 bool resolve();
00103
00104 INLINE int get_file_major_ver() const;
00105 INLINE int get_file_minor_ver() const;
00106
00107 INLINE int get_current_major_ver() const;
00108 INLINE int get_current_minor_ver() const;
00109
00110 public:
00111
00112
00113 void read_pointer(DatagramIterator &scan);
00114 void read_pointers(DatagramIterator &scan, int count);
00115 void skip_pointer(DatagramIterator &scan);
00116
00117 void read_cdata(DatagramIterator &scan, PipelineCyclerBase &cycler);
00118
00119 void register_finalize(TypedWritable *whom);
00120
00121 typedef TypedWritable *(*ChangeThisFunc)(TypedWritable *object, BamReader *manager);
00122 void register_change_this(ChangeThisFunc func, TypedWritable *whom);
00123
00124 void finalize_now(TypedWritable *whom);
00125
00126 void *get_pta(DatagramIterator &scan);
00127 void register_pta(void *ptr);
00128
00129 TypeHandle read_handle(DatagramIterator &scan);
00130
00131
00132 public:
00133 INLINE static WritableFactory *get_factory();
00134 private:
00135 INLINE static void create_factory();
00136
00137 private:
00138 int p_read_object();
00139 bool resolve_object_pointers(TypedWritable *object, const vector_int &pointer_ids);
00140 bool resolve_cycler_pointers(PipelineCyclerBase *cycler, const vector_int &pointer_ids);
00141 void finalize();
00142
00143 private:
00144 static WritableFactory *_factory;
00145
00146 DatagramGenerator *_source;
00147
00148
00149
00150 typedef pmap<int, TypeHandle> IndexMap;
00151 IndexMap _index_map;
00152
00153
00154
00155 class CreatedObj {
00156 public:
00157 TypedWritable *_ptr;
00158 ChangeThisFunc _change_this;
00159 };
00160 typedef pmap<int, CreatedObj> CreatedObjs;
00161 CreatedObjs _created_objs;
00162
00163
00164
00165
00166 CreatedObjs::iterator _now_creating;
00167
00168
00169 PipelineCyclerBase *_reading_cycler;
00170
00171
00172
00173
00174
00175 typedef pmap<int, vector_int> ObjectPointers;
00176 ObjectPointers _object_pointers;
00177
00178
00179 typedef pmap<PipelineCyclerBase *, vector_int> CyclerPointers;
00180 CyclerPointers _cycler_pointers;
00181
00182
00183
00184
00185 int _num_extra_objects;
00186
00187
00188
00189 typedef pset<TypedWritable *> Finalize;
00190 Finalize _finalize_list;
00191
00192
00193
00194 typedef pmap<int, void *> PTAMap;
00195 PTAMap _pta_map;
00196 int _pta_id;
00197
00198
00199
00200
00201
00202 typedef pset<TypeHandle> NewTypes;
00203 static NewTypes _new_types;
00204
00205 int _file_major, _file_minor;
00206 static const int _cur_major;
00207 static const int _cur_minor;
00208 };
00209
00210 typedef BamReader::WritableFactory WritableFactory;
00211
00212
00213
00214
00215
00216 INLINE void
00217 parse_params(const FactoryParams ¶ms,
00218 DatagramIterator &scan, BamReader *&manager);
00219
00220 #include "bamReader.I"
00221
00222 #endif