VR-Engage  2.3
Loading...
Searching...
No Matches
vrfTaskEntityScript.h
Go to the documentation of this file.
1/*********************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*********************************************************************************/
5
6//! \file vrfTaskEntityScript.h
7//! \brief Defines message classes for entity script task operations
8//!
9//! This file contains classes for entity script task messages in the VREngage system.
10//! These messages are used to execute scripts on entities and set entity attributes
11//! through a flexible attribute system supporting multiple data types. The message
12//! system enables communication between different components of the VREngage system
13//! to control entity behavior through scripts.
14
15#pragma once
16
19
20#include "vreMessages/export.h"
21
22#include <vlpi/entityIdentifier.h>
23
24class DtRwLocationReference;
25
26namespace makVre
27{
28
29//! \brief Message for executing a script on an entity with arbitrary attributes
30//!
31//! This class represents a message for executing a script on a specific entity
32//! with a set of named attributes. It supports multiple attribute types including
33//! boolean, integer, double, string, vector, entity identifier, and location reference. Attributes
34//! are added to the message using the templated addAttribute method, which
35//! automatically determines the appropriate attribute type based on the template
36//! parameter.
37//!
38//! The message contains the entity identifier, script name, and a list of attributes
39//! that are passed to the script when it is executed.
41{
42public:
43 //! \brief Enumeration of supported attribute data types
44 //!
45 //! This enumeration defines the data types that can be used for attributes
46 //! in scripted entity task messages.
48 {
49 BOOL, //!< Boolean value
50 INT, //!< Integer value
51 DOUBLE, //!< Double-precision floating point value
52 STRING, //!< String value
53 VECTOR, //!< Vector value (vlVector)
54 ENTITY_ID, //!< Entity identifier (DtEntityIdentifier)
55 LOCATION_REFERENCE //!< Location reference value (DtRwLocationReference)
56 };
57
58 //! \brief Base structure for script attributes
59 //!
60 //! This structure serves as the base for all attribute types, containing
61 //! the attribute name and type information. Specific attribute types
62 //! derive from this base structure and add a typed value field.
64 {
65 //! \brief Name of the attribute
66 std::string name;
67
68 //! \brief Type of the attribute
70 };
71
72 //! \brief Templated structure for typed script attributes
73 //! \tparam T Data type of the attribute value
74 //!
75 //! This templated structure derives from BaseAttribute and adds a typed value
76 //! field. It is used to store attributes of different data types in a type-safe
77 //! manner.
78 template <typename T>
79 struct Attribute : public BaseAttribute
80 {
81 //! \brief Value of the attribute
83 };
84
85 //! \brief Virtual destructor
86 //!
87 //! Cleans up resources used by the message, including allocated attribute objects.
89
90 //! \name Message Creation Methods
91 //! @{
92
93 //! \brief Creates a new instance of this message type as a DtVreMessage
94 //! \return Pointer to a newly created message
95 //!
96 //! This static method is used by the message factory to create instances
97 //! of this message type. It returns a base message pointer that must be
98 //! cast to the appropriate type by the caller.
100
101 //! \brief Creates a new instance of this message type
102 //! \return Pointer to a newly created message of this specific type
103 //!
104 //! This static method creates a new instance of this message type and
105 //! returns a pointer to the specific message type, avoiding the need for
106 //! casting by the caller.
108 //! @}
109
110 static const std::string& theType();
112
113 //! \brief Get the name of the message type
114 virtual const std::string& type() const override;
115 virtual const makVre::DtVreMessageId& messageId() const override;
116
117 //! \brief Gets the entity identifier for this message
118 //! \return Entity identifier of the target entity
119 //!
120 //! This method returns the entity identifier of the target entity for this message.
121 //! The entity identifier specifies which entity the script should be executed on.
122 virtual DtEntityIdentifier getEntityId() const;
123
124 //! \brief Sets the entity identifier for this message
125 //! \param val Entity identifier of the target entity
126 //!
127 //! This method sets the entity identifier of the target entity for this message.
128 //! The entity identifier specifies which entity the script should be executed on.
129 virtual void setEntityId(const DtEntityIdentifier& val);
130
131 //! \brief Gets the script name for this message
132 //! \return Name of the script to execute
133 //!
134 //! This method returns the name of the script that should be executed on the target entity.
135 virtual std::string getScriptName() const;
136
137 //! \brief Sets the script name for this message
138 //! \param script Name of the script to execute
139 //!
140 //! This method sets the name of the script that should be executed on the target entity.
141 virtual void setScriptName(const std::string& script);
142
143 //! \brief Gets the number of attributes in this message
144 //! \return Number of attributes
145 //!
146 //! This method returns the number of attributes that have been added to this message.
147 virtual int getAttributeCount() const;
148
149 //! \brief Gets an attribute at the specified index
150 //! \param i Index of the attribute to retrieve (0-based)
151 //! \return Pointer to the base attribute structure
152 //!
153 //! This method returns a pointer to the base attribute structure at the specified index.
154 //! The returned pointer must be cast to the appropriate Attribute<T> type to access
155 //! the value field.
157
158 //! \brief Adds an attribute to this message
159 //! \tparam T Data type of the attribute value
160 //! \param name Name of the attribute
161 //! \param data Value of the attribute
162 //!
163 //! This templated method adds an attribute with the specified name and value to this message.
164 //! The attribute type is automatically determined based on the template parameter type.
165 //! Supported types include bool, int, double, std::string, vlVector,
166 //! DtEntityIdentifier, and DtRwLocationReference.
167 template <typename T>
168 void addAttribute(const std::string& name, T data);
169
170 //! \brief Gets the total size of the serialized message in bytes
171 //! \return Size of the message in bytes
172 //!
173 //! This method calculates the total size of the message when serialized,
174 //! including the base message header and all attributes.
175 //! It overrides the base class implementation to include the size of the
176 //! entity ID, script name, and attributes.
177 virtual int messageSize() const override;
178
179 //! \brief Decodes a serialized message
180 //! \param buffer Pointer to the buffer containing the serialized message
181 //! \param length Length of the buffer in bytes
182 //! \return Pointer to a newly created message instance
183 //!
184 //! This static method deserializes a message from the provided buffer and
185 //! creates a new message instance with the deserialized data. It is used by
186 //! the message factory to create messages from received network data.
187 static makVre::DtVreMessage* decode(char* buffer, int length);
188
189protected:
190 //! \brief Static message ID for this message type
191 //!
192 //! This static member holds the unique identifier for this message type.
194
195 //! \brief Serializes the message to a stream writer
196 //! \param writer Reference to the stream writer
197 //!
198 //! This method writes the message data to the stream writer, including the
199 //! entity ID, script name, and all attributes. It overrides the base class
200 //! implementation to include the specific data for this message type.
201 virtual void serialize(DtStreamWriter& writer) const override;
202
203 //! \brief Deserializes the message from a stream reader
204 //! \param reader Reference to the stream reader
205 //!
206 //! This method reads the message data from the stream reader, including the
207 //! entity ID, script name, and all attributes. It overrides the base class
208 //! implementation to include the specific data for this message type.
209 virtual void deserialize(DtStreamReader& reader) override;
210
211 //! \brief Protected constructor
212 //!
213 //! Initializes a new message with default values. This constructor is protected
214 //! to enforce the use of the static create() method for creating new instances.
216
217 //! \brief Gets the attribute type for a template parameter type
218 //! \tparam T Data type of the attribute value
219 //! \return Attribute type enumeration value corresponding to the template parameter type
220 //!
221 //! This templated method determines the appropriate attribute type enumeration value
222 //! for a given template parameter type. Specialized implementations exist for
223 //! bool, int, double, std::string, vlVector, DtEntityIdentifier,
224 //! and DtRwLocationReference.
225 template <typename T>
227
228 //! \brief Entity identifier of the target entity
229 DtEntityIdentifier myEntityId;
230
231 //! \brief Name of the script to execute
232 std::string myScriptName;
233
234 //! \brief Type definition for the list of attributes
235 using AttributeList = std::vector<BaseAttribute*>;
236
237 //! \brief List of attributes for this message
239};
240
241//! \brief Implementation of the addAttribute template method
242//! \tparam T Data type of the attribute value
243//! \param name Name of the attribute
244//! \param data Value of the attribute
245//!
246//! This method creates a new Attribute object with the specified name and value,
247//! determines the attribute type using the getType template method, and adds the
248//! attribute to the message's attribute list.
249template <typename T>
250void VrfScriptedEntityTaskMessage::addAttribute(const std::string& name, T data)
251{
253 attr->type = getType<T>();
254 attr->name = name;
255 attr->value = data;
256
257 myAttributes.push_back(attr);
258};
259
260template <>
265
266//! \brief Message for setting entity attributes through a script
267//!
268//! This class extends VrfScriptedEntityTaskMessage to specifically represent
269//! a message for setting entity attributes through a script. It uses the same
270//! attribute system as the base class but with a specific message type and ID.
271//! This specialization allows for targeted message routing and handling of
272//! entity attribute setting operations.
274{
275public:
276 //! \brief Virtual destructor
277 //!
278 //! Cleans up resources used by the message. The base class destructor
279 //! handles cleanup of the attribute objects.
281
282 static const std::string& theType();
284
285 //! \brief Get the name of the message type
286 virtual const std::string& type() const override;
287 virtual const makVre::DtVreMessageId& messageId() const override;
288
289 //! \brief Creates a new instance of this message type as a DtVreMessage
290 //! \return Pointer to a newly created message
291 //!
292 //! This static method is used by the message factory to create instances
293 //! of this message type. It returns a base message pointer that must be
294 //! cast to the appropriate type by the caller.
296
297 //! \brief Creates a new instance of this message type
298 //! \return Pointer to a newly created message of this specific type
299 //!
300 //! This static method creates a new instance of this message type and
301 //! returns a pointer to the specific message type, avoiding the need for
302 //! casting by the caller.
304
305protected:
306 //! \brief Protected constructor
307 //!
308 //! Initializes a new message with default values. This constructor is protected
309 //! to enforce the use of the static create() method for creating new instances.
311
312 //! \brief Static message ID for this message type
313 //!
314 //! This static member holds the unique identifier for this message type.
316};
317
318} // namespace makVre
Reader class for decoding values from a byte array.
Definition byteStream.h:43
Writer class for encoding values into a byte array.
Definition byteStream.h:166
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
DtVreMessage()
Default constructor.
Message identifier class for the VREngage messaging system.
Definition vreMessageId.h:35
virtual ~VrfScriptedEntitySetMessage() override
Virtual destructor.
static VrfScriptedEntitySetMessage * create()
Creates a new instance of this message type.
static makVre::DtVreMessageId theMessageId
Static message ID for this message type.
Definition vrfTaskEntityScript.h:315
static DtVreMessage * creator()
Creates a new instance of this message type as a DtVreMessage.
virtual const std::string & type() const override
Get the name of the message type.
static const std::string & theType()
virtual const makVre::DtVreMessageId & messageId() const override
Gets the message ID object.
VrfScriptedEntitySetMessage()
Protected constructor.
static const makVre::DtVreMessageId & theId()
AttributeList myAttributes
List of attributes for this message.
Definition vrfTaskEntityScript.h:238
AttrType getType()
Gets the attribute type for a template parameter type.
AttrType
Enumeration of supported attribute data types.
Definition vrfTaskEntityScript.h:48
@ LOCATION_REFERENCE
Location reference value (DtRwLocationReference)
Definition vrfTaskEntityScript.h:55
@ VECTOR
Vector value (vlVector)
Definition vrfTaskEntityScript.h:53
@ DOUBLE
Double-precision floating point value.
Definition vrfTaskEntityScript.h:51
@ STRING
String value.
Definition vrfTaskEntityScript.h:52
@ INT
Integer value.
Definition vrfTaskEntityScript.h:50
@ ENTITY_ID
Entity identifier (DtEntityIdentifier)
Definition vrfTaskEntityScript.h:54
@ BOOL
Boolean value.
Definition vrfTaskEntityScript.h:49
std::string myScriptName
Name of the script to execute.
Definition vrfTaskEntityScript.h:232
static makVre::DtVreMessage * decode(char *buffer, int length)
Decodes a serialized message.
DtEntityIdentifier myEntityId
Entity identifier of the target entity.
Definition vrfTaskEntityScript.h:229
void addAttribute(const std::string &name, T data)
Adds an attribute to this message.
Definition vrfTaskEntityScript.h:250
virtual void setEntityId(const DtEntityIdentifier &val)
Sets the entity identifier for this message.
virtual int getAttributeCount() const
Gets the number of attributes in this message.
virtual DtEntityIdentifier getEntityId() const
Gets the entity identifier for this message.
virtual int messageSize() const override
Gets the total size of the serialized message in bytes.
static const makVre::DtVreMessageId & theId()
std::vector< BaseAttribute * > AttributeList
Type definition for the list of attributes.
Definition vrfTaskEntityScript.h:235
BaseAttribute * getAttribute(int i)
Gets an attribute at the specified index.
virtual void deserialize(DtStreamReader &reader) override
Deserializes the message from a stream reader.
virtual void serialize(DtStreamWriter &writer) const override
Serializes the message to a stream writer.
virtual void setScriptName(const std::string &script)
Sets the script name for this message.
static makVre::DtVreMessageId theMessageId
Static message ID for this message type.
Definition vrfTaskEntityScript.h:193
static VrfScriptedEntityTaskMessage * create()
Creates a new instance of this message type.
virtual const std::string & type() const override
Get the name of the message type.
virtual std::string getScriptName() const
Gets the script name for this message.
virtual ~VrfScriptedEntityTaskMessage() override
Virtual destructor.
static const std::string & theType()
virtual const makVre::DtVreMessageId & messageId() const override
Gets the message ID object.
static DtVreMessage * creator()
Creates a new instance of this message type as a DtVreMessage.
VrfScriptedEntityTaskMessage()
Protected constructor.
Defines export macros for the VREngage Messages library.
#define VREMESSAGES_DLL
Export/import macro for non-Windows platforms.
Definition export.h:39
!
Definition glsVreMessageUtil.h:50
Templated structure for typed script attributes.
Definition vrfTaskEntityScript.h:80
T value
Value of the attribute.
Definition vrfTaskEntityScript.h:82
Base structure for script attributes.
Definition vrfTaskEntityScript.h:64
AttrType type
Type of the attribute.
Definition vrfTaskEntityScript.h:69
std::string name
Name of the attribute.
Definition vrfTaskEntityScript.h:66
Defines the base class for all VREngage messages.
Defines message identifier class for the VREngage messaging system.