Panda3D
|
00001 // Filename: fltRecord.h 00002 // Created by: drose (24Aug00) 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 FLTRECORD_H 00016 #define FLTRECORD_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "fltOpcode.h" 00021 #include "fltError.h" 00022 00023 #include "typedObject.h" 00024 #include "typedReferenceCount.h" 00025 #include "pointerTo.h" 00026 00027 class FltHeader; 00028 class FltRecordReader; 00029 class FltRecordWriter; 00030 class DatagramIterator; 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Class : FltRecord 00034 // Description : The base class for all kinds of records in a MultiGen 00035 // OpenFlight file. A flt file consists of a hierarchy 00036 // of "beads" of various kinds, each of which may be 00037 // followed by n ancillary records, written sequentially 00038 // to the file. 00039 //////////////////////////////////////////////////////////////////// 00040 class FltRecord : public TypedReferenceCount { 00041 public: 00042 FltRecord(FltHeader *header); 00043 virtual ~FltRecord(); 00044 00045 int get_num_children() const; 00046 FltRecord *get_child(int n) const; 00047 void clear_children(); 00048 void add_child(FltRecord *child); 00049 00050 int get_num_subfaces() const; 00051 FltRecord *get_subface(int n) const; 00052 void clear_subfaces(); 00053 void add_subface(FltRecord *subface); 00054 00055 int get_num_extensions() const; 00056 FltRecord *get_extension(int n) const; 00057 void clear_extensions(); 00058 void add_extension(FltRecord *extension); 00059 00060 int get_num_ancillary() const; 00061 FltRecord *get_ancillary(int n) const; 00062 void clear_ancillary(); 00063 void add_ancillary(FltRecord *ancillary); 00064 00065 bool has_comment() const; 00066 const string &get_comment() const; 00067 void clear_comment(); 00068 void set_comment(const string &comment); 00069 00070 void check_remaining_size(const DatagramIterator &di, 00071 const string &name = string()) const; 00072 00073 virtual void apply_converted_filenames(); 00074 00075 virtual void output(ostream &out) const; 00076 virtual void write(ostream &out, int indent_level = 0) const; 00077 00078 protected: 00079 void write_children(ostream &out, int indent_level) const; 00080 00081 static bool is_ancillary(FltOpcode opcode); 00082 00083 FltRecord *create_new_record(FltOpcode opcode) const; 00084 FltError read_record_and_children(FltRecordReader &reader); 00085 virtual bool extract_record(FltRecordReader &reader); 00086 virtual bool extract_ancillary(FltRecordReader &reader); 00087 00088 virtual FltError write_record_and_children(FltRecordWriter &writer) const; 00089 virtual bool build_record(FltRecordWriter &writer) const; 00090 virtual FltError write_ancillary(FltRecordWriter &writer) const; 00091 00092 protected: 00093 FltHeader *_header; 00094 00095 private: 00096 typedef pvector<PT(FltRecord)> Records; 00097 Records _children; 00098 Records _subfaces; 00099 Records _extensions; 00100 Records _ancillary; 00101 00102 string _comment; 00103 00104 00105 public: 00106 virtual TypeHandle get_type() const { 00107 return get_class_type(); 00108 } 00109 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00110 static TypeHandle get_class_type() { 00111 return _type_handle; 00112 } 00113 static void init_type() { 00114 TypedReferenceCount::init_type(); 00115 register_type(_type_handle, "FltRecord", 00116 TypedReferenceCount::get_class_type()); 00117 } 00118 00119 private: 00120 static TypeHandle _type_handle; 00121 }; 00122 00123 INLINE ostream &operator << (ostream &out, const FltRecord &record); 00124 00125 #include "fltRecord.I" 00126 00127 #endif 00128 00129