Ocean
Field.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_H
9 #define META_OCEAN_SCENEDESCRIPTION_FIELD_H
10 
13 
14 #include "ocean/base/ObjectRef.h"
15 #include "ocean/base/Timestamp.h"
16 
17 #include "ocean/math/RGBAColor.h"
18 #include "ocean/math/Rotation.h"
21 #include "ocean/math/Vector2.h"
22 #include "ocean/math/Vector3.h"
23 #include "ocean/math/Vector4.h"
24 
25 namespace Ocean
26 {
27 
28 namespace SceneDescription
29 {
30 
31 /**
32  * This class is the base class for all scene description fields.
33  * @ingroup scenedescription
34  */
35 class OCEAN_SCENEDESCRIPTION_EXPORT Field
36 {
37  public:
38 
39  /**
40  * Definition of scalar field types.
41  */
42  enum Type : uint32_t
43  {
44  /// Invalid field type.
45  TYPE_INVALID = 0u,
46  /// Field with a boolean value.
48  /// Field with a color value.
50  /// Field with a float value.
52  /// Field with an integer value.
54  /// Field with a 3x3 matrix as value.
56  /// Field with a 4x4 matrix as value.
58  /// Field with a node as value.
60  /// Field with a rotation value.
62  /// Field with a string value.
64  /// Field with a time value.
66  /// Field with a 2D vector as value.
68  /// Field with a 3D vector as value.
70  /// Field with a 4D vector as value.
71  TYPE_VECTOR4
72  };
73 
74  public:
75 
76  /**
77  * Destructs a field object.
78  */
79  inline virtual ~Field();
80 
81  /**
82  * Returns the most recent field modification timestamp.
83  * @return Field timestamp
84  */
85  inline Timestamp timestamp() const;
86 
87  /**
88  * Returns the type of this field.
89  * @return Field type
90  */
91  virtual Type type() const = 0;
92 
93  /**
94  * Returns the dimension of this field.
95  * @return Field dimension
96  */
97  virtual unsigned int dimension() const = 0;
98 
99  /**
100  * Returns whether this field is a 0D field.
101  * @return True, if so
102  */
103  inline bool is0D() const;
104 
105  /**
106  * Returns whether this field is a 1D field.
107  * @return True, if so
108  */
109  inline bool is1D() const;
110 
111  /**
112  * Returns whether this field has a given type.
113  * @param type Type to check
114  * @return True, if so
115  */
116  inline bool isType(const Type type) const;
117 
118  /**
119  * Returns whether this field has a given type and dimension.
120  * @param type Type to check
121  * @param dimension Dimension to check
122  * @return True, if so
123  */
124  inline bool isType(const Type type, const unsigned int dimension) const;
125 
126  /**
127  * Sets the field timestamp explicitly.
128  * @param timestamp Field timestamp to set
129  */
130  inline void setTimestamp(const Timestamp timestamp);
131 
132  /**
133  * Casts an unspecific field object to the real field object.
134  * @param field Unspecific field object
135  * @return Specified field object
136  */
137  template <typename T> static const T& cast(const Field& field);
138 
139  /**
140  * Returns a new instance of this field.
141  * @return Copy of this field
142  */
143  virtual Field* copy() const = 0;
144 
145  /**
146  * Assigns a field to this field if both field have the identical field type
147  * @param field Field to assign the value from
148  * @return True, if the field type was identical
149  */
150  virtual bool assign(const Field& field) = 0;
151 
152  /**
153  * Assigns a field to this field.
154  * The field value and field timestamp is copied only if the field types are identical.
155  * @param field Field to assign
156  * @return Reference to this object
157  */
158  inline Field& operator=(const Field& field);
159 
160  protected:
161 
162  /**
163  * Creates a new field.
164  * The field timestamp will be set to invalid.
165  */
166  Field() = default;
167 
168  /**
169  * Disabled copy constructor.
170  * @param field Object which would be copied
171  */
172  Field(const Field& field) = delete;
173 
174  /**
175  * Creates a new field with an explicit modification timestamp.
176  * @param timestamp Explicit field timestamp
177  */
178  inline explicit Field(const Timestamp timestamp);
179 
180  protected:
181 
182  /// Field timestamp.
184 };
185 
186 inline Field::Field(const Timestamp timestamp) :
187  timestamp_(timestamp)
188 {
189  // nothing to do here
190 }
191 
193 {
194  // nothing to do here
195 }
196 
198 {
199  return timestamp_;
200 }
201 
202 inline bool Field::is0D() const
203 {
204  return dimension() == 0;
205 }
206 
207 inline bool Field::is1D() const
208 {
209  return dimension() == 1;
210 }
211 
212 inline bool Field::isType(const Type checkType) const
213 {
214  return type() == checkType;
215 }
216 
217 inline bool Field::isType(const Type checkType, const unsigned int checkDimension) const
218 {
219  return isType(checkType) && dimension() == checkDimension;
220 }
221 
222 inline void Field::setTimestamp(const Timestamp timestamp)
223 {
225 }
226 
227 template <typename T>
228 const T& Field::cast(const Field& field)
229 {
230  ocean_assert(field.isType(T::fieldType, T::fieldDimension));
231 
232  return dynamic_cast<const T&>(field);
233 }
234 
235 inline Field& Field::operator=(const Field& field)
236 {
237  assign(field);
238  return *this;
239 }
240 
241 }
242 
243 }
244 
245 #endif // META_OCEAN_SCENEDESCRIPTION_FIELD_H
This class is the base class for all scene description fields.
Definition: Field.h:36
Timestamp timestamp_
Field timestamp.
Definition: Field.h:183
Timestamp timestamp() const
Returns the most recent field modification timestamp.
Definition: Field.h:197
virtual Field * copy() const =0
Returns a new instance of this field.
bool is0D() const
Returns whether this field is a 0D field.
Definition: Field.h:202
virtual bool assign(const Field &field)=0
Assigns a field to this field if both field have the identical field type.
Type
Definition of scalar field types.
Definition: Field.h:43
@ TYPE_MATRIX3
Field with a 3x3 matrix as value.
Definition: Field.h:55
@ TYPE_ROTATION
Field with a rotation value.
Definition: Field.h:61
@ TYPE_VECTOR3
Field with a 3D vector as value.
Definition: Field.h:69
@ TYPE_MATRIX4
Field with a 4x4 matrix as value.
Definition: Field.h:57
@ TYPE_INT
Field with an integer value.
Definition: Field.h:53
@ TYPE_BOOLEAN
Field with a boolean value.
Definition: Field.h:47
@ TYPE_COLOR
Field with a color value.
Definition: Field.h:49
@ TYPE_VECTOR2
Field with a 2D vector as value.
Definition: Field.h:67
@ TYPE_NODE
Field with a node as value.
Definition: Field.h:59
@ TYPE_FLOAT
Field with a float value.
Definition: Field.h:51
@ TYPE_TIME
Field with a time value.
Definition: Field.h:65
@ TYPE_STRING
Field with a string value.
Definition: Field.h:63
void setTimestamp(const Timestamp timestamp)
Sets the field timestamp explicitly.
Definition: Field.h:222
bool is1D() const
Returns whether this field is a 1D field.
Definition: Field.h:207
bool isType(const Type type) const
Returns whether this field has a given type.
Definition: Field.h:212
Field(const Field &field)=delete
Disabled copy constructor.
virtual Type type() const =0
Returns the type of this field.
Field()=default
Creates a new field.
virtual ~Field()
Destructs a field object.
Definition: Field.h:192
Field & operator=(const Field &field)
Assigns a field to this field.
Definition: Field.h:235
virtual unsigned int dimension() const =0
Returns the dimension of this field.
static const T & cast(const Field &field)
Casts an unspecific field object to the real field object.
Definition: Field.h:228
This class implements a timestamp.
Definition: Timestamp.h:36
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15