Panda3D
Loading...
Searching...
No Matches
fltBeadID.cxx
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 fltBeadID.cxx
10 * @author drose
11 * @date 2000-08-24
12 */
13
14#include "fltBeadID.h"
15#include "fltRecordReader.h"
16#include "fltRecordWriter.h"
17
18TypeHandle FltBeadID::_type_handle;
19
20/**
21 *
22 */
23FltBeadID::
24FltBeadID(FltHeader *header) : FltBead(header) {
25}
26
27/**
28 * Returns the id (name) of this particular bead. Each MultiGen bead will
29 * have a unique name.
30 */
31const std::string &FltBeadID::
32get_id() const {
33 return _id;
34}
35
36/**
37 * Changes the id (name) of this particular bead. This should be a name that
38 * is unique to this bead.
39 */
41set_id(const std::string &id) {
42 _id = id;
43}
44
45/**
46 * Writes a quick one-line description of the record, but not its children.
47 * This is a human-readable description, primarily for debugging; to write a
48 * flt file, use FltHeader::write_flt().
49 */
51output(std::ostream &out) const {
52 out << get_type();
53 if (!_id.empty()) {
54 out << " " << _id;
55 }
56}
57
58/**
59 * Fills in the information in this bead based on the information given in the
60 * indicated datagram, whose opcode has already been read. Returns true on
61 * success, false if the datagram is invalid.
62 */
63bool FltBeadID::
64extract_record(FltRecordReader &reader) {
65 if (!FltBead::extract_record(reader)) {
66 return false;
67 }
68
69 _id = reader.get_iterator().get_fixed_string(8);
70 return true;
71}
72
73/**
74 * Checks whether the given bead, which follows this bead sequentially in the
75 * file, is an ancillary record of this bead. If it is, extracts the relevant
76 * information and returns true; otherwise, leaves it alone and returns false.
77 */
78bool FltBeadID::
79extract_ancillary(FltRecordReader &reader) {
80 if (reader.get_opcode() == FO_long_id) {
81 DatagramIterator &di = reader.get_iterator();
83 return true;
84 }
85
86 return FltBead::extract_ancillary(reader);
87}
88
89/**
90 * Fills up the current record on the FltRecordWriter with data for this
91 * record, but does not advance the writer. Returns true on success, false if
92 * there is some error.
93 */
94bool FltBeadID::
95build_record(FltRecordWriter &writer) const {
96 if (!FltBead::build_record(writer)) {
97 return false;
98 }
99
100 writer.update_datagram().add_fixed_string(_id.substr(0, 7), 8);
101 return true;
102}
103
104/**
105 * Writes whatever ancillary records are required for this record. Returns
106 * FE_ok on success, or something else if there is some error.
107 */
108FltError FltBeadID::
109write_ancillary(FltRecordWriter &writer) const {
110 if (_id.length() > 7) {
111 Datagram dc;
112
113 // Although the manual mentions nothing of this, it is essential that the
114 // length of the record be a multiple of 4 bytes.
115 dc.add_fixed_string(_id, (_id.length() + 3) & ~3);
116
117 FltError result = writer.write_record(FO_long_id, dc);
118 if (result != FE_ok) {
119 return result;
120 }
121 }
122
123 return FltBead::write_ancillary(writer);
124}
A class to retrieve the individual data elements previously stored in a Datagram.
std::string get_fixed_string(size_t size)
Extracts a fixed-length string.
size_t get_remaining_size() const
Return the bytes left in the datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
void add_fixed_string(const std::string &str, size_t size)
Adds a fixed-length string to the datagram.
Definition datagram.I:263
virtual void output(std::ostream &out) const
Writes a quick one-line description of the record, but not its children.
Definition fltBeadID.cxx:51
const std::string & get_id() const
Returns the id (name) of this particular bead.
Definition fltBeadID.cxx:32
void set_id(const std::string &id)
Changes the id (name) of this particular bead.
Definition fltBeadID.cxx:41
A base class for any of a broad family of flt records that represent particular beads in the hierarch...
Definition fltBead.h:29
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition fltHeader.h:44
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly.
FltError write_record(FltOpcode opcode, const Datagram &datagram=Datagram())
A convenience function to quickly write a simple record that consists of an opcode and possibly a dat...
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.