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
14template<class Type>
16
17/**
18 *
19 */
20INLINE ParamValueBase::
21ParamValueBase() {
22}
23
24/**
25 * Returns the type of the underlying value.
26 */
28get_value_type() const {
29 return TypeHandle::none();
30}
31
32/**
33 *
34 */
35INLINE ParamTypedRefCount::
36ParamTypedRefCount(const TypedReferenceCount *value) :
37 _value((TypedReferenceCount *)value)
38{
39}
40
41/**
42 * Retrieves the type of the value stored in the parameter.
43 */
45get_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 */
57get_value() const {
58 return _value;
59}
60
61/**
62 *
63 */
64template<class Type>
66ParamValue() {}
67
68/**
69 *
70 */
71template<class Type>
73ParamValue(const Type &value) :
74 _value(value)
75{
76}
77
78/**
79 *
80 */
81template<class Type>
84}
85
86/**
87 * Retrieves the type of the value stored in the parameter.
88 */
89template<class Type>
91get_value_type() const {
92 return get_type_handle(Type);
93}
94
95/**
96 * Changes the value stored in the parameter.
97 */
98template<class Type>
99INLINE void ParamValue<Type>::
100set_value(const Type &type) {
101 _value = type;
102 mark_bam_modified();
103}
104
105/**
106 * Retrieves the value stored in the parameter.
107 */
108template<class Type>
109INLINE const Type &ParamValue<Type>::
110get_value() const {
111 return _value;
112}
113
114/**
115 *
116 */
117template<class Type>
118INLINE void ParamValue<Type>::
119output(std::ostream &out) const {
120 out << _value;
121}
122
123/**
124 * Tells the BamReader how to create objects of type ParamValue.
125 */
126template<class 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 */
136template<class Type>
138write_datagram(BamWriter *manager, Datagram &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 */
148template<class Type>
150make_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 */
165template<class Type>
166INLINE void ParamValue<Type>::
167fillin(DatagramIterator &scan, BamReader *manager) {
168 TypedWritable::fillin(scan, manager);
169 generic_read_datagram(_value, scan);
170}
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
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
static WritableFactory * get_factory()
Returns the global WritableFactory for generating TypedWritable objects.
Definition: bamReader.I:177
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
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
get_value
Retrieves the value stored in the parameter.
Definition: paramValue.h:70
virtual TypeHandle get_value_type() const
Retrieves the type of the value stored in the parameter.
Definition: paramValue.I:45
virtual TypeHandle get_value_type() const
Returns the type of the underlying value.
Definition: paramValue.I:28
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:103
set_value
Changes the value stored in the parameter.
Definition: paramValue.h:115
virtual TypeHandle get_value_type() const
Retrieves the type of the value stored in the parameter.
Definition: paramValue.I:91
get_value
Retrieves the value stored in the parameter.
Definition: paramValue.h:115
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
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
Definition: paramValue.I:128
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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.