Panda3D

Loading...
Searching...
No Matches
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 */
23DataNodeTransmit::
24~DataNodeTransmit() {
25}
26
27/**
28 * Ensures that the given index number exists in the data array.
29 */
30 void DataNodeTransmit::
31slot_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 */
41 void DataNodeTransmit::
42 register_with_read_factory() {
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 */
50 void DataNodeTransmit::
51 write_datagram(BamWriter *manager, Datagram &dg) {
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 */
67 int DataNodeTransmit::
68 complete_pointers(TypedWritable **p_list, BamReader *manager) {
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::
85make_from_bam(const FactoryParams &params) {
86 DataNodeTransmit *xmit = new DataNodeTransmit;
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::
101fillin(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}
bamReader.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
parse_params
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
bamWriter.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
BamReader
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition bamReader.h:110
BamReader::read_pointer
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition bamReader.cxx:610
BamReader::get_factory
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition bamReader.I:177
BamWriter::write_pointer
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
DataNodeTransmit
Encapsulates the data generated from (or sent into) any particular DataNode.
Definition dataNodeTransmit.h:32
DataNodeTransmit::register_with_read_factory
static void register_with_read_factory()
Tells the BamReader how to create objects of type Lens.
Definition dataNodeTransmit.cxx:42
DataNodeTransmit::complete_pointers
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition dataNodeTransmit.cxx:68
DataNodeTransmit::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition dataNodeTransmit.cxx:51
DatagramIterator
A class to retrieve the individual data elements previously stored in a Datagram.
Definition datagramIterator.h:30
DatagramIterator::get_uint16
uint16_t get_uint16()
Extracts an unsigned 16-bit integer.
Definition datagramIterator.I:145
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_uint16
void add_uint16(uint16_t value)
Adds an unsigned 16-bit integer to the datagram.
Definition datagram.I:85
EventParameter
An optional parameter associated with an event.
Definition eventParameter.h:35
EventParameter::get_ptr
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
Definition eventParameter.I:219
FactoryParams
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition factoryParams.h:36
Factory::register_factory
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
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedWritableReferenceCount
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
Definition typedWritableReferenceCount.h:31
TypedWritable
Base class for objects that can be written to and read from Bam files.
Definition typedWritable.h:35
TypedWritable::fillin
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...
Definition typedWritable.cxx:103
TypedWritable::write_datagram
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition typedWritable.cxx:54
TypedWritable::complete_pointers
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().
Definition typedWritable.cxx:81
dataNodeTransmit.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.