VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
subordinateManagerStateComponent.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
11 #include <vrfutil/rwUUID.h>
12 
13 namespace makVrf
14 {
17  {
20  {}
21 
25  : mySubordinates(orig.mySubordinates)
26  {
27  }
28 
33  {
34  mySubordinates = rhs.mySubordinates;
35 
36  return *this;
37  }
38 
40  DEFINE_ACCESSOR_MUTATOR(std::vector<DtUUID>, subordinates, Subordinates);
44  void addSubordinate(const DtUUID& uuid, int index = -1)
45  {
46  if (index == -1)
47  {
48  mySubordinates.push_back(uuid);
49  }
50  else
51  {
52  if (index >= mySubordinates.size())
53  {
54  while (mySubordinates.size() <= index)
55  {
56  mySubordinates.push_back(DtUUID::nullUUID());
57  }
58  }
59 
60  mySubordinates[index] = uuid;
61  }
62  };
66  bool removeSubordinate(const DtUUID& uuid)
67  {
68  std::vector<DtUUID>::iterator iter = mySubordinates.begin();
69  std::vector<DtUUID>::iterator end = mySubordinates.end();
70 
71  while (iter != end)
72  {
73  if (*iter == uuid)
74  {
75  mySubordinates.erase(iter);
76  return true;
77  }
78 
79  ++iter;
80  }
81 
82  return false;
83  }
84 
86  void removeAllSubordinates() { mySubordinates.clear(); };
90  bool hasSubordinate(const DtUUID& uuid) const
91  {
92  std::vector<DtUUID>::const_iterator iter = mySubordinates.begin();
93  std::vector<DtUUID>::const_iterator end = mySubordinates.end();
94 
95  while (iter != end)
96  {
97  if (*iter == uuid)
98  {
99  return true;
100  }
101 
102  ++iter;
103  }
104 
105  return false;
106  }
107 
110  const DtUUID& firstSubordinate() const
111  {
112  if (mySubordinates.size())
113  {
114  return mySubordinates[0];
115  }
116 
117  return DtUUID::nullUUID();
118  }
119 
122  const DtUUID& lastSubordinate() const
123  {
124  if (mySubordinates.size())
125  {
126  return mySubordinates[mySubordinates.size() - 1];
127  }
128 
129  return DtUUID::nullUUID();
130  }
131 
132  protected:
134  std::vector<DtUUID> mySubordinates{};
135  };
136 
140  {
141  public:
143 
144 
147  : DtFrameStateInterface(storage)
148  {
149  }
150 
151  UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(std::vector<DtUUID>, subordinates, Subordinates)
152  UNDEFINED_METHOD(void, addSubordinate, const DtUUID&, int index = -1)
153  UNDEFINED_METHOD(bool, removeSubordinate, const DtUUID&)
154  UNDEFINED_METHOD(void, removeAllSubordinates)
155  UNDEFINED_RETURNREF_ACCESSOR(DtUUID, firstSubordinate)
156  UNDEFINED_RETURNREF_ACCESSOR(DtUUID, lastSubordinate)
159  virtual int numSubordinates() const { throw DtUnimplementedMethod("The int numSubordinates() const is undefined for this class."); };
163  virtual int indexOfSubordinate(const DtUUID&) const { throw DtUnimplementedMethod("The int indexOfSubordinate(const DtUUID&) const is undefined for this class."); };
167  virtual bool hasSubordinate(const DtUUID&) const { throw DtUnimplementedMethod("The bool hasSubordinate(const DtUUID&) const is undefined for this class."); };
168 
170  mutable boost::signals2::signal<void (const DtFrameStateInterface*, const std::vector<DtUUID>& oldSubordinates, const std::vector<DtUUID>& newSubordinates)> signal_subordinatesChanged{};
171  };
172 
175  {
176  public:
180 
182  const DtSubordinateManagerStateComponentData& frameState() const { return myData; };
184 
186  virtual int numSubordinates() const override;
189  virtual int indexOfSubordinate(const DtUUID&) const override;
191  virtual const DtUUID& firstSubordinate() const override;
193  virtual const DtUUID& lastSubordinate() const override;
195  virtual const std::vector<DtUUID>& subordinates() const override;
198  virtual void setSubordinates(const std::vector<DtUUID>&) override;
201  virtual void addSubordinate(const DtUUID&, int index = -1) override;
204  virtual bool removeSubordinate(const DtUUID&) override;
207  virtual bool hasSubordinate(const DtUUID&) const override;
209  virtual void removeAllSubordinates() override;
210 
212  virtual void makeWritable() override {};
213 
215  virtual void makeReadOnly() override {};
216 
217  protected:
220  };
221 
224  {
225  public:
229 
231  const DtSubordinateManagerStateComponentData& frameState() const { return myData; };
232 
234  virtual const DtUUID& firstSubordinate() const override;
236  virtual const DtUUID& lastSubordinate() const override;
238  virtual int numSubordinates() const override;
241  virtual int indexOfSubordinate(const DtUUID&) const override;
243  virtual const std::vector<DtUUID>& subordinates() const override;
246  virtual bool hasSubordinate(const DtUUID&) const override;
247 
248  protected:
253  {
254  myData = data;
255  }
256 
257  protected:
260  };
261 
265  {
266  public:
270 
273  bool isDoubleBuffered() { return true; };
276  virtual const DtFrameStateInterface* currentFrameState() const override { return &myCurrentFrameState; }
279  virtual DtFrameStateInterface* nextFrameState() override { return &myNextFrameState; };
282  virtual const DtFrameStateInterface* nextFrameState() const override { return &myNextFrameState; };
283 
285  virtual void updateDataStorage() override;
286 
289  virtual void updateStateData(DtStateData* sd) override
290  {
291  myCurrentFrameState.updateStateData(sd);
292  myNextFrameState.updateStateData(sd);
293  }
294 
296  virtual void aboutToBeDeleted() override
297  {
299  myCurrentFrameState.aboutToBeDeleted();
300  myNextFrameState.aboutToBeDeleted();
301  }
302 
303  protected:
309  std::vector<DtUUID> mySubordinates;
310  };
311 
315 }
UUID is a unique ID wrapper class.
Definition: uuid.h:59
Exception thrown when a required method has not been implemented.
Definition: stateDataTypes.h:30
virtual int indexOfSubordinate(const DtUUID &) const
Returns the zero-based index of the specified subordinate UUID, or -1 if not found.
Definition: subordinateManagerStateComponent.h:163
DtSubordinateManagerStateComponentCurrentFrame myCurrentFrameState
The current (read) frame state.
Definition: subordinateManagerStateComponent.h:305
bool hasSubordinate(const DtUUID &uuid) const
Checks whether the specified UUID is present in the subordinate list.
Definition: subordinateManagerStateComponent.h:90
#define UNDEFINED_METHOD(Type, Method,...)
Defines a virtual non-const method with variadic parameters that throws DtUnimplementedMethod, requiring an override in a derived class.
Definition: doubleBufferedDataStorage.h:138
2) Define the next frame class. This will be used for write access.
Definition: subordinateManagerStateComponent.h:174
DtSubordinateManagerStateComponentData myData
Current frame subordinate manager data storage.
Definition: subordinateManagerStateComponent.h:259
DtSubordinateManagerStateComponentData & operator=(const DtSubordinateManagerStateComponentData &rhs)
Assignment operator.
Definition: subordinateManagerStateComponent.h:32
Default creator implementation for a state component type. T_StateComponent is the concrete component...
Definition: stateComponent.h:326
const DtSubordinateManagerStateComponentData & frameState() const
Current frame state only can access current frame buffers. This ensures thread safety.
Definition: subordinateManagerStateComponent.h:231
const DtSubordinateManagerStateComponentData & frameState() const
Next frame access write access. Ensure this is only used in a single thread (i.e.a controller thread)...
Definition: subordinateManagerStateComponent.h:182
std::vector< DtUUID > mySubordinates
Cached copy of the last-published subordinate list, used to detect changes for signal emission...
Definition: subordinateManagerStateComponent.h:309
Contains the DtUUID class declaration.
#define UNDEFINED_RETURNREF_ACCESSOR(ReturnType, Member)
Defines a virtual const reference accessor that throws DtUnimplementedMethod, marking the method as r...
Definition: doubleBufferedDataStorage.h:60
void advanceFrame(const DtSubordinateManagerStateComponentData &data)
Advances the current frame by copying state from the given data snapshot.
Definition: subordinateManagerStateComponent.h:252
const DtUUID & lastSubordinate() const
Returns the UUID of the last subordinate, or a null UUID if the list is empty.
Definition: subordinateManagerStateComponent.h:122
virtual void makeWritable() override
Override to make component writable.
Definition: subordinateManagerStateComponent.h:212
void addSubordinate(const DtUUID &uuid, int index=-1)
Adds a subordinate UUID to the list, optionally at a specific index.
Definition: subordinateManagerStateComponent.h:44
static const DtUUID & nullUUID()
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:513
Plain data container for subordinate manager state, storing the ordered list of subordinate entity UU...
Definition: subordinateManagerStateComponent.h:16
#define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent)
Macro to define all required static and virtual state component type methods. Place in the public sec...
Definition: stateComponent.h:272
virtual bool hasSubordinate(const DtUUID &) const
Returns whether the given UUID is present in the subordinate list.
Definition: subordinateManagerStateComponent.h:167
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:489
DtSubordinateManagerStateComponentData(const DtSubordinateManagerStateComponentData &orig)
Copy constructor.
Definition: subordinateManagerStateComponent.h:24
virtual void aboutToBeDeleted()
Called when the component is about to be deleted; emits signal_stateComponentAboutToBeDeleted.
bool isDoubleBuffered()
Returns true, indicating this component uses double-buffered storage.
Definition: subordinateManagerStateComponent.h:273
4) Define the state component that will contain the wrappers to the next and current frame states tha...
Definition: subordinateManagerStateComponent.h:264
virtual const DtFrameStateInterface * currentFrameState() const override
Returns a const pointer to the current frame state.
Definition: subordinateManagerStateComponent.h:276
#define UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(Type, Member, Set)
Defines an undefined virtual const-reference accessor and an undefined virtual setter, both throwing DtUnimplementedMethod and requiring overrides in a derived class.
Definition: doubleBufferedDataStorage.h:112
#define DEFINE_ACCESSOR_MUTATOR(ReturnType, Accessor, Mutator)
Defines a const reference accessor and an inline setter for a member variable.
Definition: doubleBufferedDataStorage.h:37
virtual DtFrameStateInterface * nextFrameState() override
Returns a pointer to the next frame state for write access.
Definition: subordinateManagerStateComponent.h:279
virtual void updateStateData(DtStateData *sd) override
Updates both frame states to reference the new state data storage.
Definition: subordinateManagerStateComponent.h:289
const DtUUID & firstSubordinate() const
Returns the UUID of the first subordinate, or a null UUID if the list is empty.
Definition: subordinateManagerStateComponent.h:110
3) Define the current frame class. This will be used for read access.
Definition: subordinateManagerStateComponent.h:223
DtSubordinateManagerStateComponentData()
Default constructor.
Definition: subordinateManagerStateComponent.h:19
1) Define the interface class that will be used to represent the next and curent frames. The UNDEFINED_ macros are convenience macros that will define methods that throw exceptions (until they are implemented)
Definition: subordinateManagerStateComponent.h:139
#define DT_DLL_vrfStateData
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfStateDataDefines.h:29
DtSubordinateManagerStateComponentNextFrame myNextFrameState
The next (write) frame state.
Definition: subordinateManagerStateComponent.h:307
DtSubordinateManagerStateComponentData & frameState()
Definition: subordinateManagerStateComponent.h:183
virtual void aboutToBeDeleted() override
Notifies both frame states that this component is about to be destroyed.
Definition: subordinateManagerStateComponent.h:296
Contains the DtStateComponent class declaration.
virtual const DtFrameStateInterface * nextFrameState() const override
Returns a const pointer to the next frame state.
Definition: subordinateManagerStateComponent.h:282
bool removeSubordinate(const DtUUID &uuid)
Removes the first occurrence of the given subordinate UUID from the list.
Definition: subordinateManagerStateComponent.h:66
Base interface for accessing current or next frame state in a double-buffered state component...
Definition: stateComponent.h:354
DtStateComponentCreator< DtSubordinateManagerStateComponentImplementation > DtSubordinateManagerStateComponentCreator
5) Define the creator. This will need to be registered with the REGISTER_STATE_COMPONENT macro in the...
Definition: subordinateManagerStateComponent.h:314
std::vector< DtUUID > mySubordinates
Ordered list of subordinate entity UUIDs.
Definition: subordinateManagerStateComponent.h:134
void removeAllSubordinates()
Removes all subordinates from the list.
Definition: subordinateManagerStateComponent.h:86

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)