VR-Engage  2.2
Loading...
Searching...
No Matches
attributeProviderComponent.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file attributeProviderComponent.h
7//! \ingroup vreVrfmodel
8//! \brief Component for providing system attributes to simulation objects
9//!
10//! This file defines the DtAttributeProviderComponent class which provides a lightweight
11//! mechanism to add system attributes to simulation objects through component configuration.
12
13#pragma once
14
15#include "vreVrfmodel/export.h"
16
17#include <vrfobjcore/simComponent.h>
18
19namespace makVre
20{
21const char DtAttributeProviderComponentType[] = "attribute-provider-component";
22
23//! \brief Component for providing system attributes in a lightweight manner
24//!
25//! The DtAttributeProviderComponent exists to provide system attributes in a lightweight component.
26//! This class does all its work in the init() function, so it should be configured with
27//! is-enabled False, so its tick function is never called.
28//! See vrfobjcore/componentSystem.h for information on system attributes.
29class VREVRFMODEL_DLL DtAttributeProviderComponent : public DtSimComponent
30{
31public:
32 //! \brief Helper class used for registering the attribute
33 //!
34 //! In init(), creates one for each attribute key value pair in the descriptor.
36 {
37 public:
38 //! \brief Static provider function used in attribute registration
39 //! \param usr Pointer to the DtAttributeProvider instance
40 //! \return Reader/writer object for the attribute value
41 static DtReaderWriter* provide(void* usr) { return ((DtAttributeProvider*)usr)->value(); }
42
43 //! \brief Creates a reader/writer object for the attribute value
44 //! \return New DtRwString containing the attribute value
45 virtual DtReaderWriter* value() { return new DtRwString(myValue); }
46
47 //! \brief The attribute key
48 DtRwString myKey;
49
50 //! \brief The attribute value
51 DtRwString myValue;
52 };
53
54private:
55 //! \brief Default constructor (not implemented)
56 //!
57 //! Default constructor is private and not implemented to prevent
58 //! creation of instances without proper initialization.
60
61 //! \brief Copy constructor (not implemented)
62 //!
63 //! Copy constructor is private and not implemented to prevent
64 //! copy construction.
66
67 //! \brief Assignment operator (not implemented)
68 //! \return Reference to this object
69 //!
70 //! Assignment operator is private and not implemented to prevent
71 //! assignment.
73
74public:
75 //! \brief Constructor
76 //! \param name The name of this component
77 //! \param owner The local object that owns this component
78 //! \param simManager The simulation services manager
79 //! \param desc Optional component descriptor
80 //! \param parentRegistry Optional parent registry for reader/writer functionality
81 //!
82 //! Creates a new attribute provider component with the specified parameters.
83 DtAttributeProviderComponent(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
84 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
85
86 //! \brief Virtual destructor
87 //!
88 //! Cleans up resources used by the attribute provider component.
90
91 //! \brief Initializes the component
92 //! \return True if initialization is successful, false otherwise
93 //!
94 //! Gets attributes to add from descriptor and installs a new
95 //! DtAttributeProvider for each one.
96 virtual bool init() override;
97
98 //! \brief Gets the type identifier for this component
99 //! \return String identifying the component type (DtAttributeProviderComponentType)
100 //!
101 //! Implements the DtSimComponent::type() method to return the
102 //! type identifier for this component.
103 virtual const char* type() const override;
104
105 //! \brief Factory method to create a new instance of this component
106 //! \param name The name for the new component
107 //! \param owner The local object that will own this component
108 //! \param simManager The simulation services manager
109 //! \param desc Optional component descriptor
110 //! \param parentRegistry Optional parent registry for reader/writer functionality
111 //! \return Pointer to the newly created component
112 //!
113 //! Static factory method used by the component creation system to instantiate
114 //! new instances of this component type.
115 static DtSimComponent* creator(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
116 DtComponentDescriptor* desc, DtReaderWriterRegistry* parentRegistry);
117
118protected:
119 //! \brief Collection of attribute providers
120 //!
121 //! A provider is created for each key-value pair in the descriptor.
122 //! These are registered with the system via addAttributeProviderFunction.
123 std::vector<DtAttributeProvider*> myProviders;
124};
125} // namespace makVre
Helper class used for registering the attribute.
Definition attributeProviderComponent.h:36
static DtReaderWriter * provide(void *usr)
Static provider function used in attribute registration.
Definition attributeProviderComponent.h:41
virtual DtReaderWriter * value()
Creates a reader/writer object for the attribute value.
Definition attributeProviderComponent.h:45
DtRwString myValue
The attribute value.
Definition attributeProviderComponent.h:51
DtRwString myKey
The attribute key.
Definition attributeProviderComponent.h:48
const DtAttributeProviderComponent & operator=(const DtAttributeProviderComponent &orig)
Assignment operator (not implemented)
static DtSimComponent * creator(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc, DtReaderWriterRegistry *parentRegistry)
Factory method to create a new instance of this component.
std::vector< DtAttributeProvider * > myProviders
Collection of attribute providers.
Definition attributeProviderComponent.h:123
DtAttributeProviderComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
virtual const char * type() const override
Gets the type identifier for this component.
DtAttributeProviderComponent()
Default constructor (not implemented)
virtual bool init() override
Initializes the component.
DtAttributeProviderComponent(const DtAttributeProviderComponent &orig)
Copy constructor (not implemented)
virtual ~DtAttributeProviderComponent() override
Virtual destructor.
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
const char DtAttributeProviderComponentType[]
Definition attributeProviderComponent.h:21