Panda3D
dataNodeTransmit.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 dataNodeTransmit.cxx
10  * @author drose
11  * @date 2002-03-11
12  */
13 
14 #include "dataNodeTransmit.h"
15 #include "bamReader.h"
16 #include "bamWriter.h"
17 
18 TypeHandle DataNodeTransmit::_type_handle;
19 
20 /**
21  *
22  */
23 DataNodeTransmit::
24 ~DataNodeTransmit() {
25 }
26 
27 /**
28  * Ensures that the given index number exists in the data array.
29  */
30 void DataNodeTransmit::
31 slot_data(int index) {
32  nassertv(index < 1000);
33  while (index >= (int)_data.size()) {
34  _data.push_back(EventParameter());
35  }
36 }
37 
38 /**
39  * Tells the BamReader how to create objects of type Lens.
40  */
43  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
44 }
45 
46 /**
47  * Writes the contents of this object to the datagram for shipping out to a
48  * Bam file.
49  */
52  TypedWritable::write_datagram(manager, dg);
53 
54  dg.add_uint16(_data.size());
55  Data::const_iterator di;
56  for (di = _data.begin(); di != _data.end(); ++di) {
57  const EventParameter &param = (*di);
58  TypedWritableReferenceCount *ptr = param.get_ptr();
59  manager->write_pointer(dg, ptr);
60  }
61 }
62 
63 /**
64  * Receives an array of pointers, one for each time manager->read_pointer()
65  * was called in fillin(). Returns the number of pointers processed.
66  */
69  int pi = TypedWritable::complete_pointers(p_list, manager);
70 
71  Data::iterator di;
72  for (di = _data.begin(); di != _data.end(); ++di) {
73  (*di) = EventParameter(DCAST(TypedWritableReferenceCount, p_list[pi++]));
74  }
75 
76  return pi;
77 }
78 
79 /**
80  * This function is called by the BamReader's factory when a new object of
81  * type Lens is encountered in the Bam file. It should create the Lens and
82  * extract its information from the file.
83  */
84 TypedWritable *DataNodeTransmit::
85 make_from_bam(const FactoryParams &params) {
87  DatagramIterator scan;
88  BamReader *manager;
89 
90  parse_params(params, scan, manager);
91  xmit->fillin(scan, manager);
92 
93  return xmit;
94 }
95 
96 /**
97  * This internal function is called by make_from_bam to read in all of the
98  * relevant data from the BamFile for the new Lens.
99  */
100 void DataNodeTransmit::
101 fillin(DatagramIterator &scan, BamReader *manager) {
102  TypedWritable::fillin(scan, manager);
103 
104  int num_params = scan.get_uint16();
105  _data.reserve(num_params);
106  for (int i = 0; i < num_params; i++) {
107  manager->read_pointer(scan);
108  _data.push_back(EventParameter());
109  }
110 }
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:110
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is intended to be called by each class's make_from_bam() method to read in all...
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
void parse_params(const FactoryParams &params, DatagramIterator &scan, BamReader *&manager)
Takes in a FactoryParams, passed from a WritableFactory into any TypedWritable's make function,...
Definition: bamReader.I:275
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
Definition: datagram.I:85
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:36
void register_factory(TypeHandle handle, CreateFunc *func, void *user_data=nullptr)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:73
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
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:81
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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:317