Panda3D

fltRecord.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 fltRecord.h
10 * @author drose
11 * @date 2000-08-24
12 */
13
14 #ifndef FLTRECORD_H
15 #define FLTRECORD_H
16
17 #include "pandatoolbase.h"
18
19 #include "fltOpcode.h"
20 #include "fltError.h"
21
22 #include "typedObject.h"
23 #include "typedReferenceCount.h"
24 #include "pointerTo.h"
25
26 class FltHeader;
27 class FltRecordReader;
28 class FltRecordWriter;
29 class DatagramIterator;
30
31 /**
32 * The base class for all kinds of records in a MultiGen OpenFlight file. A
33 * flt file consists of a hierarchy of "beads" of various kinds, each of which
34 * may be followed by n ancillary records, written sequentially to the file.
35 */
36 class FltRecord : public TypedReferenceCount {
37 public:
38 FltRecord(FltHeader *header);
39 virtual ~FltRecord();
40
41 int get_num_children() const;
42 FltRecord *get_child(int n) const;
43 void clear_children();
44 void add_child(FltRecord *child);
45
46 int get_num_subfaces() const;
47 FltRecord *get_subface(int n) const;
48 void clear_subfaces();
49 void add_subface(FltRecord *subface);
50
51 int get_num_extensions() const;
52 FltRecord *get_extension(int n) const;
53 void clear_extensions();
54 void add_extension(FltRecord *extension);
55
56 int get_num_ancillary() const;
57 FltRecord *get_ancillary(int n) const;
58 void clear_ancillary();
59 void add_ancillary(FltRecord *ancillary);
60
61 bool has_comment() const;
62 const std::string &get_comment() const;
63 void clear_comment();
64 void set_comment(const std::string &comment);
65
66 void check_remaining_size(const DatagramIterator &di,
67 const std::string &name = std::string()) const;
68
69 virtual void apply_converted_filenames();
70
71 virtual void output(std::ostream &out) const;
72 virtual void write(std::ostream &out, int indent_level = 0) const;
73
74 protected:
75 void write_children(std::ostream &out, int indent_level) const;
76
77 static bool is_ancillary(FltOpcode opcode);
78
79 FltRecord *create_new_record(FltOpcode opcode) const;
80 FltError read_record_and_children(FltRecordReader &reader);
81 virtual bool extract_record(FltRecordReader &reader);
82 virtual bool extract_ancillary(FltRecordReader &reader);
83
84 virtual FltError write_record_and_children(FltRecordWriter &writer) const;
85 virtual bool build_record(FltRecordWriter &writer) const;
86 virtual FltError write_ancillary(FltRecordWriter &writer) const;
87
88 protected:
89 FltHeader *_header;
90
91 private:
92 typedef pvector<PT(FltRecord)> Records;
93 Records _children;
94 Records _subfaces;
95 Records _extensions;
96 Records _ancillary;
97
98 std::string _comment;
99
100
101 public:
102 virtual TypeHandle get_type() const {
103 return get_class_type();
104 }
105 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
106 static TypeHandle get_class_type() {
107 return _type_handle;
108 }
109 static void init_type() {
110 TypedReferenceCount::init_type();
111 register_type(_type_handle, "FltRecord",
112 TypedReferenceCount::get_class_type());
113 }
114
115 private:
116 static TypeHandle _type_handle;
117 };
118
119 INLINE std::ostream &operator << (std::ostream &out, const FltRecord &record);
120
121 #include "fltRecord.I"
122
123 #endif
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
FltHeader
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:44
FltRecordReader
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
Definition: fltRecordReader.h:30
FltRecordWriter
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly.
Definition: fltRecordWriter.h:31
FltRecord
The base class for all kinds of records in a MultiGen OpenFlight file.
Definition: fltRecord.h:36
FltRecord::get_subface
FltRecord * get_subface(int n) const
Returns the nth subface of this record.
Definition: fltRecord.cxx:106
FltRecord::get_num_extensions
int get_num_extensions() const
Returns the number of extension attribute records for this object.
Definition: fltRecord.cxx:133
FltRecord::clear_extensions
void clear_extensions()
Removes all extensions from this record.
Definition: fltRecord.cxx:150
FltRecord::get_extension
FltRecord * get_extension(int n) const
Returns the nth extension of this record.
Definition: fltRecord.cxx:141
FltRecord::get_comment
const std::string & get_comment() const
Retrieves the comment for this record, or empty string if the record has no comment.
Definition: fltRecord.cxx:224
FltRecord::clear_subfaces
void clear_subfaces()
Removes all subfaces from this record.
Definition: fltRecord.cxx:115
FltRecord::add_child
void add_child(FltRecord *child)
Adds a new child to the end of the list of children for this record.
Definition: fltRecord.cxx:88
FltRecord::clear_comment
void clear_comment()
Removes the comment for this record.
Definition: fltRecord.cxx:232
FltRecord::get_child
FltRecord * get_child(int n) const
Returns the nth child of this record.
Definition: fltRecord.cxx:71
FltRecord::add_extension
void add_extension(FltRecord *extension)
Adds a new extension to the end of the list of extensions for this record.
Definition: fltRecord.cxx:159
FltRecord::get_num_ancillary
int get_num_ancillary() const
Returns the number of unsupported ancillary records of this record.
Definition: fltRecord.cxx:171
FltRecord::get_num_subfaces
int get_num_subfaces() const
Returns the number of subface records of this record.
Definition: fltRecord.cxx:98
FltRecord::output
virtual void output(std::ostream &out) const
Writes a quick one-line description of the record, but not its children.
Definition: fltRecord.cxx:294
FltRecord::get_ancillary
FltRecord * get_ancillary(int n) const
Returns the nth unsupported ancillary record of this record.
Definition: fltRecord.cxx:180
FltRecord::get_num_children
int get_num_children() const
Returns the number of child records of this record.
Definition: fltRecord.cxx:63
FltRecord::check_remaining_size
void check_remaining_size(const DatagramIterator &di, const std::string &name=std::string()) const
Checks that the iterator has no bytes left, as it should at the end of a successfully read record.
Definition: fltRecord.cxx:254
FltRecord::apply_converted_filenames
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:278
FltRecord::has_comment
bool has_comment() const
Returns true if this record has a nonempty comment, false otherwise.
Definition: fltRecord.cxx:215
FltRecord::add_ancillary
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:207
FltRecord::clear_children
void clear_children()
Removes all children from this record.
Definition: fltRecord.cxx:80
FltRecord::add_subface
void add_subface(FltRecord *subface)
Adds a new subface to the end of the list of subfaces for this record.
Definition: fltRecord.cxx:123
FltRecord::set_comment
void set_comment(const std::string &comment)
Changes the comment for this record.
Definition: fltRecord.cxx:240
FltRecord::clear_ancillary
void clear_ancillary()
Removes all unsupported ancillary records from this record.
Definition: fltRecord.cxx:190
FltRecord::write
virtual void write(std::ostream &out, int indent_level=0) const
Writes a multiple-line description of the record and all of its children.
Definition: fltRecord.cxx:304
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
TypedReferenceCount
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Definition: typedReferenceCount.h:31
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
fltError.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
fltOpcode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
fltRecord.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
typedObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.