Ocean
Field0D.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_SCENEDESCRIPTION_FIELD_0D_H
9 #define META_OCEAN_SCENEDESCRIPTION_FIELD_0D_H
10 
15 
16 namespace Ocean
17 {
18 
19 namespace SceneDescription
20 {
21 
22 // Forward declaration.
23 template <typename T> class Field0D;
24 
25 /**
26  * Definition of a single field with boolean value.
27  * @ingroup scenedescription
28  */
30 
31 /**
32  * Definition of a single field with color value.
33  * @ingroup scenedescription
34  */
36 
37 /**
38  * Definition of a single field with float value.
39  * @ingroup scenedescription
40  */
42 
43 /**
44  * Definition of a single field with integer value.
45  * @ingroup scenedescription
46  */
48 
49 /**
50  * Definition of a single field with node value.
51  * @ingroup scenedescription
52  */
54 
55 /**
56  * Definition of a single field with 3x3 matrix value.
57  * @ingroup scenedescription
58  */
60 
61 /**
62  * Definition of a single field with 4x4 matrix value.
63  * @ingroup scenedescription
64  */
66 
67 /**
68  * Definition of a single field with rotation value.
69  * @ingroup scenedescription
70  */
72 
73 /**
74  * Definition of a single field with string value.
75  * @ingroup scenedescription
76  */
78 
79 /**
80  * Definition of a single field with time value.
81  * @ingroup scenedescription
82  */
84 
85 /**
86  * Definition of a single field with 2D vector value.
87  * @ingroup scenedescription
88  */
90 
91 /**
92  * Definition of a single field with 3D vector value.
93  * @ingroup scenedescription
94  */
96 
97 /**
98  * Definition of a single field with 4D vector value.
99  * @ingroup scenedescription
100  */
102 
103 /**
104  * This class implements all 0D fields (fields holding a single value only).
105  * @ingroup scenedescription
106  */
107 template <typename T>
108 class Field0D : public Field
109 {
110  public:
111 
112  /// Scalar type of this single field.
113  static constexpr Type fieldType = TypeMapper<T>::type();
114 
115  /// Dimension of this single field.
116  static constexpr unsigned int fieldDimension = 0u;
117 
118  public:
119 
120  /**
121  * Creates a new single value field with an undefined value.
122  */
123  Field0D() = default;
124 
125  /**
126  * Creates a new single value field by a given initialization value.
127  * The modification timestamp will be set to zero.
128  * @param value Initialization value
129  */
130  inline Field0D(const T& value);
131 
132  /**
133  * Creates a new single value field by a given initialization value and an explicit timestamp.
134  * @param value Initialization value
135  * @param timestamp Explicit field timestamp
136  */
137  inline Field0D(const T& value, const Timestamp timestamp);
138 
139  /**
140  * Returns the type of this field.
141  * @see Field::type().
142  */
143  Type type() const override;
144 
145  /**
146  * Returns the dimension of this field.
147  * @see Field::dimension().
148  */
149  unsigned int dimension() const override;
150 
151  /**
152  * Returns the value of this field.
153  * @return Field value
154  */
155  inline const T& value() const;
156 
157  /**
158  * Sets the value of this field and changes the modification timestamp to the current time.
159  * @param value Value to set
160  */
161  inline void setValue(const T& value);
162 
163  /**
164  * Sets the value of this field and defines an explicit modification timestamp.
165  * @param value Value to set
166  * @param timestamp Explicit modification timestamp
167  */
168  inline void setValue(const T& value, const Timestamp timestamp);
169 
170  /**
171  * Assigns a field to this field if both field have the identical field type
172  * @see Field::assignField().
173  */
174  bool assign(const Field& field) override;
175 
176  protected:
177 
178  /**
179  * Returns a new instance of this field.
180  * @see Field::copy().
181  */
182  Field* copy() const override;
183 
184  protected:
185 
186  /// Field (single) value.
188 };
189 
190 template <typename T>
191 inline Field0D<T>::Field0D(const T& value) :
192  value_(value)
193 {
194  // nothing to do here
195 }
196 
197 template <typename T>
198 inline Field0D<T>::Field0D(const T& value, const Timestamp timestamp) :
199  Field(timestamp),
200  value_(value)
201 {
202  // nothing to do here
203 }
204 
205 template <typename T>
207 {
208  return TypeMapper<T>::type();
209 }
210 
211 template <typename T>
212 unsigned int Field0D<T>::dimension() const
213 {
214  return 0u;
215 }
216 
217 template <typename T>
218 inline const T& Field0D<T>::value() const
219 {
220  return value_;
221 }
222 
223 template <typename T>
224 inline void Field0D<T>::setValue(const T& value)
225 {
226  value_ = value;
227  timestamp_.toNow();
228 }
229 
230 template <typename T>
231 inline void Field0D<T>::setValue(const T& value, const Timestamp timestamp)
232 {
233  value_ = value;
234  timestamp_ = timestamp;
235 }
236 
237 template <typename T>
239 {
240  return new Field0D<T>(value_);
241 }
242 
243 template <typename T>
244 bool Field0D<T>::assign(const Field& field)
245 {
246  if (fieldType != field.type() || fieldDimension != field.dimension())
247  {
248  return false;
249  }
250 
251  value_ = dynamic_cast<const Field0D<T>&>(field).value_;
252  timestamp_ = field.timestamp();
253 
254  return true;
255 }
256 
257 }
258 
259 }
260 
261 #endif // META_OCEAN_SCENEDESCRIPTION_FIELD_0D_H
Field0D()=default
Creates a new single value field with an undefined value.
const T & value() const
Returns the value of this field.
Definition: Field0D.h:218
T value_
Field (single) value.
Definition: Field0D.h:187
static constexpr unsigned int fieldDimension
Dimension of this single field.
Definition: Field0D.h:116
static constexpr Type fieldType
Scalar type of this single field.
Definition: Field0D.h:113
Field0D(const T &value, const Timestamp timestamp)
Creates a new single value field by a given initialization value and an explicit timestamp.
Definition: Field0D.h:198
Type type() const override
Returns the type of this field.
Definition: Field0D.h:206
Field0D(const T &value)
Creates a new single value field by a given initialization value.
Definition: Field0D.h:191
unsigned int dimension() const override
Returns the dimension of this field.
Definition: Field0D.h:212
Field * copy() const override
Returns a new instance of this field.
Definition: Field0D.h:238
void setValue(const T &value, const Timestamp timestamp)
Sets the value of this field and defines an explicit modification timestamp.
Definition: Field0D.h:231
bool assign(const Field &field) override
Assigns a field to this field if both field have the identical field type.
Definition: Field0D.h:244
void setValue(const T &value)
Sets the value of this field and changes the modification timestamp to the current time.
Definition: Field0D.h:224
This class is the base class for all scene description fields.
Definition: Field.h:36
Timestamp timestamp() const
Returns the most recent field modification timestamp.
Definition: Field.h:197
Type
Definition of scalar field types.
Definition: Field.h:43
virtual Type type() const =0
Returns the type of this field.
virtual unsigned int dimension() const =0
Returns the dimension of this field.
static constexpr Field::Type type()
Returns the scalar field type for this mapper object.
Definition: FieldTyper.h:37
This class implements a timestamp.
Definition: Timestamp.h:36
Field0D< int > SingleInt
Definition of a single field with integer value.
Definition: Field0D.h:47
Field0D< Scalar > SingleFloat
Definition of a single field with float value.
Definition: Field0D.h:41
Field0D< Rotation > SingleRotation
Definition of a single field with rotation value.
Definition: Field0D.h:71
Field0D< Vector2 > SingleVector2
Definition of a single field with 2D vector value.
Definition: Field0D.h:89
Field0D< std::string > SingleString
Definition of a single field with string value.
Definition: Field0D.h:77
Field0D< Vector4 > SingleVector4
Definition of a single field with 4D vector value.
Definition: Field0D.h:101
Field0D< RGBAColor > SingleColor
Definition of a single field with color value.
Definition: Field0D.h:35
Field0D< bool > SingleBool
Definition of a single field with boolean value.
Definition: Field0D.h:23
Field0D< Vector3 > SingleVector3
Definition of a single field with 3D vector value.
Definition: Field0D.h:95
Field0D< NodeRef > SingleNode
Definition of a single field with node value.
Definition: Field0D.h:53
Field0D< SquareMatrix3 > SingleMatrix3
Definition of a single field with 3x3 matrix value.
Definition: Field0D.h:59
Field0D< Timestamp > SingleTime
Definition of a single field with time value.
Definition: Field0D.h:83
Field0D< SquareMatrix4 > SingleMatrix4
Definition of a single field with 4x4 matrix value.
Definition: Field0D.h:65
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15