Panda3D
 All Classes Functions Variables Enumerations
paramNodePath.cxx
1 // Filename: paramNodePath.cxx
2 // Created by: rdb (25Feb15)
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 "paramNodePath.h"
16 #include "dcast.h"
17 #include "pandaNode.h"
18 
19 TypeHandle ParamNodePath::_type_handle;
20 
21 ////////////////////////////////////////////////////////////////////
22 // Function: ParamNodePath::output
23 // Access: Published, Virtual
24 // Description:
25 ////////////////////////////////////////////////////////////////////
26 void ParamNodePath::
27 output(ostream &out) const {
28  out << "node path " << _node_path;
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function: ParamNodePath::register_with_read_factory
33 // Access: Public, Static
34 // Description: Tells the BamReader how to create objects of type
35 // ParamValue.
36 ////////////////////////////////////////////////////////////////////
37 void ParamNodePath::
39  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function: ParamNodePath::write_datagram
44 // Access: Public, Virtual
45 // Description: Writes the contents of this object to the datagram
46 // for shipping out to a Bam file.
47 ////////////////////////////////////////////////////////////////////
48 void ParamNodePath::
50  ParamValueBase::write_datagram(manager, dg);
51 
52  // We can't store a NodePath, so we store a pointer to the
53  // underlying node, and pray that there is an unambiguous path
54  // from the root to it.
55  if (_node_path.is_empty()) {
56  manager->write_pointer(dg, NULL);
57  } else {
58  manager->write_pointer(dg, _node_path.node());
59  }
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: ParamNodePath::complete_pointers
64 // Access: Public, Virtual
65 // Description: Receives an array of pointers, one for each time
66 // manager->read_pointer() was called in fillin().
67 // Returns the number of pointers processed.
68 ////////////////////////////////////////////////////////////////////
71  int pi = ParamValueBase::complete_pointers(p_list, manager);
72  _node_path = NodePath(DCAST(PandaNode, p_list[pi++]));
73 
74  return pi;
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: ParamNodePath::make_from_bam
79 // Access: Protected, Static
80 // Description: This function is called by the BamReader's factory
81 // when a new object of type ParamValue is encountered
82 // in the Bam file. It should create the ParamValue
83 // and extract its information from the file.
84 ////////////////////////////////////////////////////////////////////
85 TypedWritable *ParamNodePath::
86 make_from_bam(const FactoryParams &params) {
87  ParamNodePath *param = new ParamNodePath;
88  DatagramIterator scan;
89  BamReader *manager;
90 
91  parse_params(params, scan, manager);
92  param->fillin(scan, manager);
93 
94  return param;
95 }
96 
97 ////////////////////////////////////////////////////////////////////
98 // Function: ParamNodePath::fillin
99 // Access: Protected
100 // Description: This internal function is called by make_from_bam to
101 // read in all of the relevant data from the BamFile for
102 // the new ParamValue.
103 ////////////////////////////////////////////////////////////////////
104 void ParamNodePath::
105 fillin(DatagramIterator &scan, BamReader *manager) {
106  ParamValueBase::fillin(scan, manager);
107  manager->read_pointer(scan);
108 }
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:72
A class object for storing a NodePath as a parameter.
Definition: paramNodePath.h:26
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
PandaNode * node() const
Returns the referenced node of the path.
Definition: nodePath.I:284
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...
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-&gt;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
void register_factory(TypeHandle handle, CreateFunc *func)
Registers a new kind of thing the Factory will be able to create.
Definition: factory.I:90
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:213
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
bool is_empty() const
Returns true if the NodePath contains no nodes.
Definition: nodePath.I:236
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
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:165
virtual int complete_pointers(TypedWritable **plist, BamReader *manager)
Receives an array of pointers, one for each time manager-&gt;read_pointer() was called in fillin()...
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:652