Panda3D
paramValue.h
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.h
10  * @author drose
11  * @date 1999-02-08
12  */
13 
14 #ifndef PARAMVALUE_H
15 #define PARAMVALUE_H
16 
17 #include "pandabase.h"
18 
19 #include "typedef.h"
20 #include "typedObject.h"
22 #include "pointerTo.h"
23 #include "bamReader.h"
24 #include "bamWriter.h"
25 #include "luse.h"
26 
27 /**
28  * A non-template base class of ParamValue (below), which serves mainly to
29  * define the placeholder for the virtual output function.
30  */
31 class EXPCL_PANDA_PUTIL ParamValueBase : public TypedWritableReferenceCount {
32 public:
33  INLINE ParamValueBase();
34 
35 PUBLISHED:
36  virtual ~ParamValueBase();
37  INLINE virtual TypeHandle get_value_type() const;
38  virtual void output(std::ostream &out) const=0;
39 
40 public:
41  virtual TypeHandle get_type() const {
42  return get_class_type();
43  }
44  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
45  static TypeHandle get_class_type() {
46  return _type_handle;
47  }
48  static void init_type() {
49  TypedWritableReferenceCount::init_type();
50  register_type(_type_handle, "ParamValueBase",
51  TypedWritableReferenceCount::get_class_type());
52  }
53 
54 private:
55  static TypeHandle _type_handle;
56 };
57 
58 /**
59  * A class object for storing specifically objects of type
60  * TypedReferenceCount, which is different than TypedWritableReferenceCount.
61  */
62 class EXPCL_PANDA_PUTIL ParamTypedRefCount : public ParamValueBase {
63 PUBLISHED:
64  INLINE ParamTypedRefCount(const TypedReferenceCount *value);
65  virtual ~ParamTypedRefCount();
66 
67  INLINE virtual TypeHandle get_value_type() const;
68  INLINE TypedReferenceCount *get_value() const;
69 
70  MAKE_PROPERTY(value, get_value);
71 
72  virtual void output(std::ostream &out) const;
73 
74 private:
75  PT(TypedReferenceCount) _value;
76 
77 public:
78  virtual TypeHandle get_type() const {
79  return get_class_type();
80  }
81  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
82  static TypeHandle get_class_type() {
83  return _type_handle;
84  }
85  static void init_type() {
86  ParamValueBase::init_type();
87  register_type(_type_handle, "ParamTypedRefCount",
88  ParamValueBase::get_class_type());
89  }
90 
91 private:
92  static TypeHandle _type_handle;
93 };
94 
95 /**
96  * A handy class object for storing simple values (like integers or strings)
97  * passed along with an Event or to be used as a shader input. This is
98  * essentially just a wrapper around whatever data type you like, to make it a
99  * TypedWritableReferenceCount object which can be passed along inside an
100  * EventParameter or ShaderInput.
101  */
102 template<class Type>
103 class ParamValue : public ParamValueBase {
104 protected:
105  INLINE ParamValue();
106 
107 PUBLISHED:
108  INLINE ParamValue(const Type &value);
109  INLINE virtual ~ParamValue();
110 
111  INLINE virtual TypeHandle get_value_type() const;
112  INLINE void set_value(const Type &value);
113  INLINE const Type &get_value() const;
114 
115  MAKE_PROPERTY(value, get_value, set_value);
116 
117  INLINE virtual void output(std::ostream &out) const;
118 
119 private:
120  Type _value;
121 
122 public:
123  INLINE static void register_with_read_factory();
124  INLINE virtual void write_datagram(BamWriter *manager, Datagram &dg);
125 
126 protected:
127  INLINE static TypedWritable *make_from_bam(const FactoryParams &params);
128  INLINE void fillin(DatagramIterator &scan, BamReader *manager);
129 
130 public:
131  static TypeHandle get_class_type() {
132  return _type_handle;
133  }
134  static void init_type(const std::string &type_name = "UndefinedParamValue") {
135  ParamValueBase::init_type();
136  _type_handle = register_dynamic_type
137  (type_name, ParamValueBase::get_class_type());
138  }
139  virtual TypeHandle get_type() const {
140  return get_class_type();
141  }
142  virtual TypeHandle force_init_type() {
143  // In this case, we can't do anything, since we don't have the class'
144  // type_name.
145  return get_class_type();
146  }
147 
148 private:
149  static TypeHandle _type_handle;
150 };
151 
152 #include "paramValue.I"
153 
154 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<std::string>);
155 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<std::wstring>);
156 
157 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase2d>);
158 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase2f>);
159 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase2i>);
160 
161 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase3d>);
162 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase3f>);
163 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase3i>);
164 
165 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase4d>);
166 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase4f>);
167 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase4i>);
168 
169 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix3d>);
170 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix3f>);
171 
172 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix4d>);
173 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix4f>);
174 
177 
181 
185 
189 
192 
195 
196 #ifdef STDFLOAT_DOUBLE
200 
203 #else
207 
210 #endif
211 
212 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
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
A class object for storing specifically objects of type TypedReferenceCount, which is different than ...
Definition: paramValue.h:62
A non-template base class of ParamValue (below), which serves mainly to define the placeholder for th...
Definition: paramValue.h:31
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.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
TypeHandle register_dynamic_type(const std::string &name)
This is essentially similar to register_type(), except that it doesn't store a reference to any TypeH...
Definition: register_type.I:73
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.