Panda3D
 All Classes Functions Variables Enumerations
fltInstanceDefinition.cxx
1 // Filename: fltInstanceDefinition.cxx
2 // Created by: drose (30Aug00)
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 #include "fltInstanceDefinition.h"
16 #include "fltRecordReader.h"
17 #include "fltRecordWriter.h"
18 
19 TypeHandle FltInstanceDefinition::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: FltInstanceDefinition::Constructor
23 // Access: Public
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 FltInstanceDefinition::
27 FltInstanceDefinition(FltHeader *header) : FltBead(header) {
28  _instance_index = 0;
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: FltInstanceDefinition::extract_record
33 // Access: Protected, Virtual
34 // Description: Fills in the information in this bead based on the
35 // information given in the indicated datagram, whose
36 // opcode has already been read. Returns true on
37 // success, false if the datagram is invalid.
38 ////////////////////////////////////////////////////////////////////
39 bool FltInstanceDefinition::
40 extract_record(FltRecordReader &reader) {
41  if (!FltBead::extract_record(reader)) {
42  return false;
43  }
44 
45  nassertr(reader.get_opcode() == FO_instance, false);
46  DatagramIterator &iterator = reader.get_iterator();
47 
48  iterator.skip_bytes(2);
49  _instance_index = iterator.get_be_int16();
50 
51  check_remaining_size(iterator);
52  return true;
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: FltInstanceDefinition::build_record
57 // Access: Protected, Virtual
58 // Description: Fills up the current record on the FltRecordWriter with
59 // data for this record, but does not advance the
60 // writer. Returns true on success, false if there is
61 // some error.
62 ////////////////////////////////////////////////////////////////////
63 bool FltInstanceDefinition::
64 build_record(FltRecordWriter &writer) const {
65  if (!FltBead::build_record(writer)) {
66  return false;
67  }
68 
69  writer.set_opcode(FO_instance);
70  Datagram &datagram = writer.update_datagram();
71 
72  datagram.pad_bytes(2);
73  datagram.add_be_int16(_instance_index);
74 
75  return true;
76 }
This class writes a sequence of FltRecords to an ostream, handling opcode and size counts properly...
This class turns an istream into a sequence of FltRecords by reading a sequence of Datagrams and extr...
A base class for any of a broad family of flt records that represent particular beads in the hierarch...
Definition: fltBead.h:33
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
void pad_bytes(size_t size)
Adds the indicated number of zero bytes to the datagram.
Definition: datagram.cxx:111
This is the first bead in the file, the top of the bead hierarchy, and the primary interface to readi...
Definition: fltHeader.h:48
void skip_bytes(size_t size)
Skips over the indicated number of bytes in the datagram.
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
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A class to retrieve the individual data elements previously stored in a Datagram. ...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
void set_opcode(FltOpcode opcode)
Sets the opcode associated with the current record.
Datagram & update_datagram()
Returns a modifiable reference to the datagram associated with the current record.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
void add_be_int16(PN_int16 value)
Adds a signed 16-bit big-endian integer to the datagram.
Definition: datagram.I:255