Panda3D

fltInstanceDefinition.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 fltInstanceDefinition.cxx
10 * @author drose
11 * @date 2000-08-30
12 */
13
14 #include "fltInstanceDefinition.h"
15 #include "fltRecordReader.h"
16 #include "fltRecordWriter.h"
17
18 TypeHandle FltInstanceDefinition::_type_handle;
19
20 /**
21 *
22 */
23 FltInstanceDefinition::
24 FltInstanceDefinition(FltHeader *header) : FltBead(header) {
25 _instance_index = 0;
26 }
27
28 /**
29 * Fills in the information in this bead based on the information given in the
30 * indicated datagram, whose opcode has already been read. Returns true on
31 * success, false if the datagram is invalid.
32 */
33 bool FltInstanceDefinition::
34 extract_record(FltRecordReader &reader) {
35 if (!FltBead::extract_record(reader)) {
36 return false;
37 }
38
39 nassertr(reader.get_opcode() == FO_instance, false);
40 DatagramIterator &iterator = reader.get_iterator();
41
42 iterator.skip_bytes(2);
43 _instance_index = iterator.get_be_int16();
44
45 check_remaining_size(iterator);
46 return true;
47 }
48
49 /**
50 * Fills up the current record on the FltRecordWriter with data for this
51 * record, but does not advance the writer. Returns true on success, false if
52 * there is some error.
53 */
54 bool FltInstanceDefinition::
55 build_record(FltRecordWriter &writer) const {
56 if (!FltBead::build_record(writer)) {
57 return false;
58 }
59
60 writer.set_opcode(FO_instance);
61 Datagram &datagram = writer.update_datagram();
62
63 datagram.pad_bytes(2);
64 datagram.add_be_int16(_instance_index);
65
66 return true;
67 }
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition: datagramIterator.h:27
DatagramIterator::skip_bytes
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
Definition: datagramIterator.I:423
DatagramIterator::get_be_int16
int16_t get_be_int16()
Extracts a signed 16-bit big-endian integer.
Definition: datagramIterator.I:255
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
Datagram::add_be_int16
void add_be_int16(int16_t value)
Adds a signed 16-bit big-endian integer to the datagram.
Definition: datagram.I:145
Datagram::pad_bytes
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:99
FltBead
A base class for any of a broad family of flt records that represent particular beads in the hierarch...
Definition: fltBead.h:29
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
FltRecordReader::get_opcode
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
Definition: fltRecordReader.cxx:55
FltRecordReader::get_iterator
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
Definition: fltRecordReader.cxx:64
FltRecordWriter
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly.
Definition: fltRecordWriter.h:31
FltRecordWriter::set_opcode
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Definition: fltRecordWriter.cxx:47
FltRecordWriter::update_datagram
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
Definition: fltRecordWriter.cxx:66
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
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
fltInstanceDefinition.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
fltRecordReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
fltRecordWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.