Panda3D
paramValue.I
1 // Filename: paramValue.I
2 // Created by: drose (08Feb99)
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 
16 template<class Type>
17 TypeHandle ParamValue<Type>::_type_handle;
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: ParamValueBase::Constructor
21 // Access: Public
22 // Description:
23 ////////////////////////////////////////////////////////////////////
24 INLINE ParamValueBase::
25 ParamValueBase() {
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: ParamValueBase::get_value_type
30 // Access: Published, Virtual
31 // Description: Returns the type of the underlying value.
32 ////////////////////////////////////////////////////////////////////
34 get_value_type() const {
35  return TypeHandle::none();
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: ParamTypedRefCount::Constructor
40 // Access: Published
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 INLINE ParamTypedRefCount::
44 ParamTypedRefCount(const TypedReferenceCount *value) :
45  _value((TypedReferenceCount *)value)
46 {
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: ParamTypedRefCount::get_value_type
51 // Access: Published
52 // Description: Retrieves the type of the value stored in the
53 // parameter.
54 ////////////////////////////////////////////////////////////////////
56 get_value_type() const {
57  if (_value == NULL) {
58  return TypeHandle::none();
59  } else {
60  return _value->get_type();
61  }
62 }
63 
64 ////////////////////////////////////////////////////////////////////
65 // Function: ParamTypedRefCount::get_value
66 // Access: Published
67 // Description: Retrieves the value stored in the parameter.
68 ////////////////////////////////////////////////////////////////////
70 get_value() const {
71  return _value;
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: ParamValue::Constructor
76 // Access: Protected
77 // Description:
78 ////////////////////////////////////////////////////////////////////
79 template<class Type>
80 INLINE ParamValue<Type>::
81 ParamValue() {}
82 
83 ////////////////////////////////////////////////////////////////////
84 // Function: ParamValue::Constructor
85 // Access: Public
86 // Description:
87 ////////////////////////////////////////////////////////////////////
88 template<class Type>
89 INLINE ParamValue<Type>::
90 ParamValue(const Type &value) :
91  _value(value)
92 {
93 }
94 
95 ////////////////////////////////////////////////////////////////////
96 // Function: ParamValue::Destructor
97 // Access: Public, Virtual
98 // Description:
99 ////////////////////////////////////////////////////////////////////
100 template<class Type>
101 INLINE ParamValue<Type>::
102 ~ParamValue() {
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: ParamValue::get_value_type
107 // Access: Public, Virtual
108 // Description: Retrieves the type of the value stored in the
109 // parameter.
110 ////////////////////////////////////////////////////////////////////
111 template<class Type>
113 get_value_type() const {
114  return get_type_handle(Type);
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: ParamValue::set_value
119 // Access: Public, Virtual
120 // Description: Changes the value stored in the parameter.
121 ////////////////////////////////////////////////////////////////////
122 template<class Type>
123 INLINE void ParamValue<Type>::
124 set_value(const Type &type) {
125  _value = type;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: ParamValue::get_value
131 // Access: Public
132 // Description: Retrieves the value stored in the parameter.
133 ////////////////////////////////////////////////////////////////////
134 template<class Type>
135 INLINE const Type &ParamValue<Type>::
136 get_value() const {
137  return _value;
138 }
139 
140 ////////////////////////////////////////////////////////////////////
141 // Function: ParamValue::output
142 // Access: Public, Virtual
143 // Description:
144 ////////////////////////////////////////////////////////////////////
145 template<class Type>
146 INLINE void ParamValue<Type>::
147 output(ostream &out) const {
148  out << _value;
149 }
150 
151 ////////////////////////////////////////////////////////////////////
152 // Function: ParamValue::register_with_read_factory
153 // Access: Public, Static
154 // Description: Tells the BamReader how to create objects of type
155 // ParamValue.
156 ////////////////////////////////////////////////////////////////////
157 template<class Type>
158 INLINE void ParamValue<Type>::
160  BamReader::get_factory()->register_factory(get_class_type(), make_from_bam);
161 }
162 
163 ////////////////////////////////////////////////////////////////////
164 // Function: ParamValue::write_datagram
165 // Access: Public, Virtual
166 // Description: Writes the contents of this object to the datagram
167 // for shipping out to a Bam file.
168 ////////////////////////////////////////////////////////////////////
169 template<class Type>
170 INLINE void ParamValue<Type>::
172  TypedWritable::write_datagram(manager, dg);
173  generic_write_datagram(dg, _value);
174 }
175 
176 ////////////////////////////////////////////////////////////////////
177 // Function: ParamValue::make_from_bam
178 // Access: Protected, Static
179 // Description: This function is called by the BamReader's factory
180 // when a new object of type ParamValue is encountered
181 // in the Bam file. It should create the ParamValue
182 // and extract its information from the file.
183 ////////////////////////////////////////////////////////////////////
184 template<class Type>
186 make_from_bam(const FactoryParams &params) {
188  DatagramIterator scan;
189  BamReader *manager;
190 
191  parse_params(params, scan, manager);
192  esv->fillin(scan, manager);
193 
194  return esv;
195 }
196 
197 ////////////////////////////////////////////////////////////////////
198 // Function: ParamValue::fillin
199 // Access: Protected
200 // Description: This internal function is called by make_from_bam to
201 // read in all of the relevant data from the BamFile for
202 // the new ParamValue.
203 ////////////////////////////////////////////////////////////////////
204 template<class Type>
205 INLINE void ParamValue<Type>::
206 fillin(DatagramIterator &scan, BamReader *manager) {
207  TypedWritable::fillin(scan, manager);
208  generic_read_datagram(_value, scan);
209 }
static TypeHandle none()
Returns a special zero-valued TypeHandle that is used to indicate no type.
Definition: typeHandle.I:274
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
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:171
void set_value(const Type &value)
Changes the value stored in the parameter.
Definition: paramValue.I:124
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
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:73
virtual TypeHandle get_value_type() const
Retrieves the type of the value stored in the parameter.
Definition: paramValue.I:113
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:109
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 TypeHandle get_value_type() const
Retrieves the type of the value stored in the parameter.
Definition: paramValue.I:56
virtual TypeHandle get_value_type() const
Returns the type of the underlying value.
Definition: paramValue.I:34
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
const Type & get_value() const
Retrieves the value stored in the parameter.
Definition: paramValue.I:136
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
TypedReferenceCount * get_value() const
Retrieves the value stored in the parameter.
Definition: paramValue.I:70
static void register_with_read_factory()
Tells the BamReader how to create objects of type ParamValue.
Definition: paramValue.I:159
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
void mark_bam_modified()
Increments the bam_modified counter, so that this object will be invalidated and retransmitted on any...
Definition: typedWritable.I:54