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