Panda3D
dataNodeTransmit.cxx
1 // Filename: dataNodeTransmit.cxx
2 // Created by: drose (11Mar02)
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 "dataNodeTransmit.h"
16 #include "bamReader.h"
17 #include "bamWriter.h"
18 
19 TypeHandle DataNodeTransmit::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: DataNodeTransmit::Destructor
23 // Access: Public, Virtual
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 DataNodeTransmit::
27 ~DataNodeTransmit() {
28 }
29 
30 ////////////////////////////////////////////////////////////////////
31 // Function: DataNodeTransmit::slot_data
32 // Access: Private
33 // Description: Ensures that the given index number exists in the
34 // data array.
35 ////////////////////////////////////////////////////////////////////
36 void DataNodeTransmit::
37 slot_data(int index) {
38  nassertv(index < 1000);
39  while (index >= (int)_data.size()) {
40  _data.push_back(EventParameter());
41  }
42 }
43 
44 ////////////////////////////////////////////////////////////////////
45 // Function: DataNodeTransmit::register_with_read_factory
46 // Access: Public, Static
47 // Description: Tells the BamReader how to create objects of type
48 // Lens.
49 ////////////////////////////////////////////////////////////////////
52  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
53 }
54 
55 ////////////////////////////////////////////////////////////////////
56 // Function: DataNodeTransmit::write_datagram
57 // Access: Public, Virtual
58 // Description: Writes the contents of this object to the datagram
59 // for shipping out to a Bam file.
60 ////////////////////////////////////////////////////////////////////
63  TypedWritable::write_datagram(manager, dg);
64 
65  dg.add_uint16(_data.size());
66  Data::const_iterator di;
67  for (di = _data.begin(); di != _data.end(); ++di) {
68  const EventParameter &param = (*di);
69  TypedWritableReferenceCount *ptr = param.get_ptr();
70  manager->write_pointer(dg, ptr);
71  }
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: DataNodeTransmit::complete_pointers
76 // Access: Public, Virtual
77 // Description: Receives an array of pointers, one for each time
78 // manager->read_pointer() was called in fillin().
79 // Returns the number of pointers processed.
80 ////////////////////////////////////////////////////////////////////
83  int pi = TypedWritable::complete_pointers(p_list, manager);
84 
85  Data::iterator di;
86  for (di = _data.begin(); di != _data.end(); ++di) {
87  (*di) = EventParameter(DCAST(TypedWritableReferenceCount, p_list[pi++]));
88  }
89 
90  return pi;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: DataNodeTransmit::make_from_bam
95 // Access: Protected, Static
96 // Description: This function is called by the BamReader's factory
97 // when a new object of type Lens is encountered
98 // in the Bam file. It should create the Lens
99 // and extract its information from the file.
100 ////////////////////////////////////////////////////////////////////
101 TypedWritable *DataNodeTransmit::
102 make_from_bam(const FactoryParams &params) {
104  DatagramIterator scan;
105  BamReader *manager;
106 
107  parse_params(params, scan, manager);
108  xmit->fillin(scan, manager);
109 
110  return xmit;
111 }
112 
113 ////////////////////////////////////////////////////////////////////
114 // Function: DataNodeTransmit::fillin
115 // Access: Protected
116 // Description: This internal function is called by make_from_bam to
117 // read in all of the relevant data from the BamFile for
118 // the new Lens.
119 ////////////////////////////////////////////////////////////////////
120 void DataNodeTransmit::
121 fillin(DatagramIterator &scan, BamReader *manager) {
122  TypedWritable::fillin(scan, manager);
123 
124  int num_params = scan.get_uint16();
125  _data.reserve(num_params);
126  for (int i = 0; i < num_params; i++) {
127  manager->read_pointer(scan);
128  _data.push_back(EventParameter());
129  }
130 }
An optional parameter associated with an event.
static void register_with_read_factory()
Tells the BamReader how to create objects of type Lens.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class&#39;s make_from_bam() method to read in all...
PN_uint16 get_uint16()
Extracts an unsigned 16-bit integer.
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
void add_uint16(PN_uint16 value)
Adds an unsigned 16-bit integer to the datagram.
Definition: datagram.I:181
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin()...
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
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
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
Encapsulates the data generated from (or sent into) any particular DataNode.
void write_pointer(Datagram &packet, const TypedWritable *dest)
The interface for writing a pointer to another object to a Bam file.
Definition: bamWriter.cxx:279
void read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:658