Panda3D
paramValue.I
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 paramValue.I
10  * @author drose
11  * @date 1999-02-08
12  */
13 
14 template<class Type>
16 
17 /**
18  *
19  */
20 INLINE ParamValueBase::
21 ParamValueBase() {
22 }
23 
24 /**
25  * Returns the type of the underlying value.
26  */
28 get_value_type() const {
29  return TypeHandle::none();
30 }
31 
32 /**
33  *
34  */
35 INLINE ParamTypedRefCount::
36 ParamTypedRefCount(const TypedReferenceCount *value) :
37  _value((TypedReferenceCount *)value)
38 {
39 }
40 
41 /**
42  * Retrieves the type of the value stored in the parameter.
43  */
45 get_value_type() const {
46  if (_value == nullptr) {
47  return TypeHandle::none();
48  } else {
49  return _value->get_type();
50  }
51 }
52 
53 /**
54  * Retrieves the value stored in the parameter.
55  */
56 INLINE TypedReferenceCount *ParamTypedRefCount::
57 get_value() const {
58  return _value;
59 }
60 
61 /**
62  *
63  */
64 template<class Type>
65 INLINE ParamValue<Type>::
66 ParamValue() {}
67 
68 /**
69  *
70  */
71 template<class Type>
72 INLINE ParamValue<Type>::
73 ParamValue(const Type &value) :
74  _value(value)
75 {
76 }
77 
78 /**
79  *
80  */
81 template<class Type>
82 INLINE ParamValue<Type>::
83 ~ParamValue() {
84 }
85 
86 /**
87  * Retrieves the type of the value stored in the parameter.
88  */
89 template<class Type>
91 get_value_type() const {
92  return get_type_handle(Type);
93 }
94 
95 /**
96  * Changes the value stored in the parameter.
97  */
98 template<class Type>
99 INLINE void ParamValue<Type>::
100 set_value(const Type &type) {
101  _value = type;
102  mark_bam_modified();
103 }
104 
105 /**
106  * Retrieves the value stored in the parameter.
107  */
108 template<class Type>
109 INLINE const Type &ParamValue<Type>::
110 get_value() const {
111  return _value;
112 }
113 
114 /**
115  *
116  */
117 template<class Type>
118 INLINE void ParamValue<Type>::
119 output(std::ostream &out) const {
120  out << _value;
121 }
122 
123 /**
124  * Tells the BamReader how to create objects of type ParamValue.
125  */
126 template<class Type>
127 INLINE void ParamValue<Type>::
129  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
130 }
131 
132 /**
133  * Writes the contents of this object to the datagram for shipping out to a
134  * Bam file.
135  */
136 template<class Type>
137 INLINE void ParamValue<Type>::
139  TypedWritable::write_datagram(manager, dg);
140  generic_write_datagram(dg, _value);
141 }
142 
143 /**
144  * This function is called by the BamReader's factory when a new object of
145  * type ParamValue is encountered in the Bam file. It should create the
146  * ParamValue and extract its information from the file.
147  */
148 template<class Type>
150 make_from_bam(const FactoryParams &params) {
152  DatagramIterator scan;
153  BamReader *manager;
154 
155  parse_params(params, scan, manager);
156  esv->fillin(scan, manager);
157 
158  return esv;
159 }
160 
161 /**
162  * This internal function is called by make_from_bam to read in all of the
163  * relevant data from the BamFile for the new ParamValue.
164  */
165 template<class Type>
166 INLINE void ParamValue<Type>::
167 fillin(DatagramIterator &scan, BamReader *manager) {
168  TypedWritable::fillin(scan, manager);
169  generic_read_datagram(_value, scan);
170 }
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
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: paramValue.I:138
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
virtual TypeHandle get_value_type() const
Retrieves the type of the value stored in the parameter.
Definition: paramValue.I:91
set_value
Changes the value stored in the parameter.
Definition: paramValue.h:115
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:103
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.
virtual TypeHandle get_value_type() const
Retrieves the type of the value stored in the parameter.
Definition: paramValue.I:45
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 TypeHandle get_value_type() const
Returns the type of the underlying value.
Definition: paramValue.I:28
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
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
Definition: paramValue.I:128
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