Panda3D
paramValue.h
1 // Filename: paramValue.h
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 #ifndef PARAMVALUE_H
16 #define PARAMVALUE_H
17 
18 #include "pandabase.h"
19 
20 #include "typedef.h"
21 #include "typedObject.h"
22 #include "typedWritableReferenceCount.h"
23 #include "pointerTo.h"
24 #include "bamReader.h"
25 #include "bamWriter.h"
26 #include "luse.h"
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : ParamValueBase
30 // Description : A non-template base class of ParamValue (below),
31 // which serves mainly to define the placeholder for the
32 // virtual output function.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDA_PUTIL ParamValueBase : public TypedWritableReferenceCount {
35 public:
36  INLINE ParamValueBase();
37 
38 PUBLISHED:
39  virtual ~ParamValueBase();
40  INLINE virtual TypeHandle get_value_type() const;
41  virtual void output(ostream &out) const=0;
42 
43 public:
44  virtual TypeHandle get_type() const {
45  return get_class_type();
46  }
47  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
48  static TypeHandle get_class_type() {
49  return _type_handle;
50  }
51  static void init_type() {
52  TypedWritableReferenceCount::init_type();
53  register_type(_type_handle, "ParamValueBase",
54  TypedWritableReferenceCount::get_class_type());
55  }
56 
57 private:
58  static TypeHandle _type_handle;
59 };
60 
61 ////////////////////////////////////////////////////////////////////
62 // Class : ParamTypedRefCount
63 // Description : A class object for storing specifically objects of
64 // type TypedReferenceCount, which is different than
65 // TypedWritableReferenceCount.
66 ////////////////////////////////////////////////////////////////////
67 class EXPCL_PANDA_PUTIL ParamTypedRefCount : public ParamValueBase {
68 PUBLISHED:
69  INLINE ParamTypedRefCount(const TypedReferenceCount *value);
70  virtual ~ParamTypedRefCount();
71 
72  INLINE virtual TypeHandle get_value_type() const;
73  INLINE TypedReferenceCount *get_value() const;
74 
75  virtual void output(ostream &out) const;
76 
77 private:
78  PT(TypedReferenceCount) _value;
79 
80 public:
81  virtual TypeHandle get_type() const {
82  return get_class_type();
83  }
84  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
85  static TypeHandle get_class_type() {
86  return _type_handle;
87  }
88  static void init_type() {
89  ParamValueBase::init_type();
90  register_type(_type_handle, "ParamTypedRefCount",
91  ParamValueBase::get_class_type());
92  }
93 
94 private:
95  static TypeHandle _type_handle;
96 };
97 
98 ////////////////////////////////////////////////////////////////////
99 // Class : ParamValue
100 // Description : A handy class object for storing simple values (like
101 // integers or strings) passed along with an Event
102 // or to be used as a shader input.
103 // This is essentially just a wrapper around whatever
104 // data type you like, to make it a
105 // TypedWritableReferenceCount object which can be
106 // passed along inside an EventParameter or ShaderInput.
107 ////////////////////////////////////////////////////////////////////
108 template<class Type>
109 class ParamValue : public ParamValueBase {
110 protected:
111  INLINE ParamValue();
112 
113 PUBLISHED:
114  INLINE ParamValue(const Type &value);
115  INLINE virtual ~ParamValue();
116 
117  INLINE virtual TypeHandle get_value_type() const;
118  INLINE void set_value(const Type &value);
119  INLINE const Type &get_value() const;
120 
121  INLINE virtual void output(ostream &out) const;
122 
123 private:
124  Type _value;
125 
126 public:
127  INLINE static void register_with_read_factory();
128  INLINE virtual void write_datagram(BamWriter *manager, Datagram &dg);
129 
130 protected:
131  INLINE static TypedWritable *make_from_bam(const FactoryParams &params);
132  INLINE void fillin(DatagramIterator &scan, BamReader *manager);
133 
134 public:
135  static TypeHandle get_class_type() {
136  return _type_handle;
137  }
138  static void init_type(const string &type_name = "UndefinedParamValue") {
139  ParamValueBase::init_type();
140  _type_handle = register_dynamic_type
141  (type_name, ParamValueBase::get_class_type());
142  }
143  virtual TypeHandle get_type() const {
144  return get_class_type();
145  }
146  virtual TypeHandle force_init_type() {
147  // In this case, we can't do anything, since we don't have the
148  // class' type_name.
149  return get_class_type();
150  }
151 
152 private:
153  static TypeHandle _type_handle;
154 };
155 
156 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<std::string>);
157 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<std::wstring>);
158 
159 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase2d>);
160 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase2f>);
161 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase2i>);
162 
163 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase3d>);
164 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase3f>);
165 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase3i>);
166 
167 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase4d>);
168 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase4f>);
169 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LVecBase4i>);
170 
171 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix3d>);
172 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix3f>);
173 
174 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix4d>);
175 EXPORT_TEMPLATE_CLASS(EXPCL_PANDA_PUTIL, EXPTP_PANDA_PUTIL, ParamValue<LMatrix4f>);
176 
179 
183 
187 
191 
194 
197 
198 #ifdef STDFLOAT_DOUBLE
202 
205 #else
209 
212 #endif
213 
214 #include "paramValue.I"
215 
216 // Tell GCC that we'll take care of the instantiation explicitly here.
217 #ifdef __GNUC__
218 #pragma interface
219 #endif
220 
221 #endif
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
A class object for storing specifically objects of type TypedReferenceCount, which is different than ...
Definition: paramValue.h:67
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
A handy class object for storing simple values (like integers or strings) passed along with an Event ...
Definition: paramValue.h:109
A non-template base class of ParamValue (below), which serves mainly to define the placeholder for th...
Definition: paramValue.h:34
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
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
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