Panda3D
paramNodePath.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 paramNodePath.cxx
10  * @author rdb
11  * @date 2015-02-25
12  */
13 
14 #include "paramNodePath.h"
15 #include "dcast.h"
16 #include "pandaNode.h"
17 
18 TypeHandle ParamNodePath::_type_handle;
19 
20 /**
21  *
22  */
23 void ParamNodePath::
24 output(std::ostream &out) const {
25  out << "node path " << _node_path;
26 }
27 
28 /**
29  * Tells the BamReader how to create objects of type ParamValue.
30  */
31 void ParamNodePath::
33  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
34 }
35 
36 /**
37  * Writes the contents of this object to the datagram for shipping out to a
38  * Bam file.
39  */
40 void ParamNodePath::
42  ParamValueBase::write_datagram(manager, dg);
43 
44  if (manager->get_file_minor_ver() < 40) {
45  // Before bam 6.40, we did not support writing NodePaths. Instaed, we
46  // write the PandaNode pointer and pray there is an unambiguous path.
47  if (_node_path.is_empty()) {
48  manager->write_pointer(dg, nullptr);
49  } else {
50  manager->write_pointer(dg, _node_path.node());
51  }
52  } else {
53  _node_path.write_datagram(manager, dg);
54  }
55 }
56 
57 /**
58  * Receives an array of pointers, one for each time manager->read_pointer()
59  * was called in fillin(). Returns the number of pointers processed.
60  */
63  int pi = ParamValueBase::complete_pointers(p_list, manager);
64 
65  if (manager->get_file_minor_ver() >= 40) {
66  pi += _node_path.complete_pointers(p_list + pi, manager);
67  } else {
68  _node_path = NodePath(DCAST(PandaNode, p_list[pi++]));
69  }
70 
71  return pi;
72 }
73 
74 /**
75  * This function is called by the BamReader's factory when a new object of
76  * type ParamValue is encountered in the Bam file. It should create the
77  * ParamValue and extract its information from the file.
78  */
79 TypedWritable *ParamNodePath::
80 make_from_bam(const FactoryParams &params) {
81  ParamNodePath *param = new ParamNodePath;
82  DatagramIterator scan;
83  BamReader *manager;
84 
85  parse_params(params, scan, manager);
86  param->fillin(scan, manager);
87 
88  return param;
89 }
90 
91 /**
92  * This internal function is called by make_from_bam to read in all of the
93  * relevant data from the BamFile for the new ParamValue.
94  */
95 void ParamNodePath::
96 fillin(DatagramIterator &scan, BamReader *manager) {
97  ParamValueBase::fillin(scan, manager);
98 
99  if (manager->get_file_minor_ver() >= 40) {
100  _node_path.fillin(scan, manager);
101  } else {
102  manager->read_pointer(scan);
103  }
104 }
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 basic node of the scene graph or data graph.
Definition: pandaNode.h:64
A class object for storing a NodePath as a parameter.
Definition: paramNodePath.h:24
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition: nodePath.I:188
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being written.
Definition: bamWriter.I:59
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.
int get_file_minor_ver() const
Returns the minor version number of the Bam file currently being read.
Definition: bamReader.I:83
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
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().
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
PandaNode * node() const
Returns the referenced node of the path.
Definition: nodePath.I:227
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
bool read_pointer(DatagramIterator &scan)
The interface for reading a pointer to another object from a Bam file.
Definition: bamReader.cxx:610
int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
Definition: nodePath.cxx:6753
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
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager->read_pointer() was called in fillin().
void write_datagram(BamWriter *manager, Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: nodePath.cxx:6702
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
void fillin(DatagramIterator &scan, BamReader *manager)
This internal function is called by make_from_bam to read in all of the relevant data from the BamFil...
Definition: nodePath.cxx:6813