Panda3D
fltRecord.h
1 // Filename: fltRecord.h
2 // Created by: drose (24Aug00)
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 FLTRECORD_H
16 #define FLTRECORD_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "fltOpcode.h"
21 #include "fltError.h"
22 
23 #include "typedObject.h"
24 #include "typedReferenceCount.h"
25 #include "pointerTo.h"
26 
27 class FltHeader;
28 class FltRecordReader;
29 class FltRecordWriter;
30 class DatagramIterator;
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : FltRecord
34 // Description : The base class for all kinds of records in a MultiGen
35 // OpenFlight file. A flt file consists of a hierarchy
36 // of "beads" of various kinds, each of which may be
37 // followed by n ancillary records, written sequentially
38 // to the file.
39 ////////////////////////////////////////////////////////////////////
41 public:
42  FltRecord(FltHeader *header);
43  virtual ~FltRecord();
44 
45  int get_num_children() const;
46  FltRecord *get_child(int n) const;
47  void clear_children();
48  void add_child(FltRecord *child);
49 
50  int get_num_subfaces() const;
51  FltRecord *get_subface(int n) const;
52  void clear_subfaces();
53  void add_subface(FltRecord *subface);
54 
55  int get_num_extensions() const;
56  FltRecord *get_extension(int n) const;
57  void clear_extensions();
58  void add_extension(FltRecord *extension);
59 
60  int get_num_ancillary() const;
61  FltRecord *get_ancillary(int n) const;
62  void clear_ancillary();
63  void add_ancillary(FltRecord *ancillary);
64 
65  bool has_comment() const;
66  const string &get_comment() const;
67  void clear_comment();
68  void set_comment(const string &comment);
69 
70  void check_remaining_size(const DatagramIterator &di,
71  const string &name = string()) const;
72 
73  virtual void apply_converted_filenames();
74 
75  virtual void output(ostream &out) const;
76  virtual void write(ostream &out, int indent_level = 0) const;
77 
78 protected:
79  void write_children(ostream &out, int indent_level) const;
80 
81  static bool is_ancillary(FltOpcode opcode);
82 
83  FltRecord *create_new_record(FltOpcode opcode) const;
84  FltError read_record_and_children(FltRecordReader &reader);
85  virtual bool extract_record(FltRecordReader &reader);
86  virtual bool extract_ancillary(FltRecordReader &reader);
87 
88  virtual FltError write_record_and_children(FltRecordWriter &writer) const;
89  virtual bool build_record(FltRecordWriter &writer) const;
90  virtual FltError write_ancillary(FltRecordWriter &writer) const;
91 
92 protected:
93  FltHeader *_header;
94 
95 private:
97  Records _children;
98  Records _subfaces;
99  Records _extensions;
100  Records _ancillary;
101 
102  string _comment;
103 
104 
105 public:
106  virtual TypeHandle get_type() const {
107  return get_class_type();
108  }
109  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
110  static TypeHandle get_class_type() {
111  return _type_handle;
112  }
113  static void init_type() {
114  TypedReferenceCount::init_type();
115  register_type(_type_handle, "FltRecord",
116  TypedReferenceCount::get_class_type());
117  }
118 
119 private:
120  static TypeHandle _type_handle;
121 };
122 
123 INLINE ostream &operator << (ostream &out, const FltRecord &record);
124 
125 #include "fltRecord.I"
126 
127 #endif
128 
129 
void clear_comment()
Removes the comment for this record.
Definition: fltRecord.cxx:285
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly...
void clear_ancillary()
Removes all unsupported ancillary records from this record.
Definition: fltRecord.cxx:231
void clear_extensions()
Removes all extensions from this record.
Definition: fltRecord.cxx:181
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
void set_comment(const string &comment)
Changes the comment for this record.
Definition: fltRecord.cxx:295
FltRecord * get_ancillary(int n) const
Returns the nth unsupported ancillary record of this record.
Definition: fltRecord.cxx:219
int get_num_children() const
Returns the number of child records of this record.
Definition: fltRecord.cxx:70
FltRecord * get_extension(int n) const
Returns the nth extension of this record.
Definition: fltRecord.cxx:170
virtual void apply_converted_filenames()
Walks the hierarchy at this record and below and copies the _converted_filename record into the _orig...
Definition: fltRecord.cxx:340
void check_remaining_size(const DatagramIterator &di, const string &name=string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record...
Definition: fltRecord.cxx:313
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
void add_child(FltRecord *child)
Adds a new child to the end of the list of children for this record.
Definition: fltRecord.cxx:102
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:48
bool has_comment() const
Returns true if this record has a nonempty comment, false otherwise.
Definition: fltRecord.cxx:264
FltRecord * get_subface(int n) const
Returns the nth subface of this record.
Definition: fltRecord.cxx:125
virtual void output(ostream &out) const
Writes a quick one-line description of the record, but not its children.
Definition: fltRecord.cxx:359
const string & get_comment() const
Retrieves the comment for this record, or empty string if the record has no comment.
Definition: fltRecord.cxx:275
The base class for all kinds of records in a MultiGen OpenFlight file.
Definition: fltRecord.h:40
FltRecord * get_child(int n) const
Returns the nth child of this record.
Definition: fltRecord.cxx:80
void add_extension(FltRecord *extension)
Adds a new extension to the end of the list of extensions for this record.
Definition: fltRecord.cxx:193
void add_subface(FltRecord *subface)
Adds a new subface to the end of the list of subfaces for this record.
Definition: fltRecord.cxx:147
A class to retrieve the individual data elements previously stored in a Datagram. ...
void add_ancillary(FltRecord *ancillary)
Adds a new unsupported ancillary record to the end of the list of ancillary records for this record...
Definition: fltRecord.cxx:253
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
int get_num_ancillary() const
Returns the number of unsupported ancillary records of this record.
Definition: fltRecord.cxx:208
void clear_children()
Removes all children from this record.
Definition: fltRecord.cxx:91
void clear_subfaces()
Removes all subfaces from this record.
Definition: fltRecord.cxx:136
int get_num_subfaces() const
Returns the number of subface records of this record.
Definition: fltRecord.cxx:115
virtual void write(ostream &out, int indent_level=0) const
Writes a multiple-line description of the record and all of its children.
Definition: fltRecord.cxx:372
int get_num_extensions() const
Returns the number of extension attribute records for this object.
Definition: fltRecord.cxx:160