VR-Forces 5.0.2 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 {
16  {
18  {}
19 
21  : mySubordinates(orig.mySubordinates)
22  {
23  }
24 
26  {
27  mySubordinates = rhs.mySubordinates;
28 
29  return *this;
30  }
31 
32  DEFINE_ACCESSOR_MUTATOR(std::vector<DtUUID>, subordinates, Subordinates);
33  void addSubordinate(const DtUUID& uuid, int index = -1)
34  {
35  if (index == -1)
36  {
37  mySubordinates.push_back(uuid);
38  }
39  else
40  {
41  if (index >= mySubordinates.size())
42  {
43  while (mySubordinates.size() <= index)
44  {
45  mySubordinates.push_back(DtUUID::nullUUID());
46  }
47  }
48 
49  mySubordinates[index] = uuid;
50  }
51  };
52  bool removeSubordinate(const DtUUID& uuid)
53  {
54  std::vector<DtUUID>::iterator iter = mySubordinates.begin();
55  std::vector<DtUUID>::iterator end = mySubordinates.end();
56 
57  while (iter != end)
58  {
59  if (*iter == uuid)
60  {
61  mySubordinates.erase(iter);
62  return true;
63  }
64 
65  ++iter;
66  }
67 
68  return false;
69  }
70 
71  void removeAllSubordinates() { mySubordinates.clear(); };
72  bool hasSubordinate(const DtUUID& uuid) const
73  {
74  std::vector<DtUUID>::const_iterator iter = mySubordinates.begin();
75  std::vector<DtUUID>::const_iterator end = mySubordinates.end();
76 
77  while (iter != end)
78  {
79  if (*iter == uuid)
80  {
81  return true;
82  }
83 
84  ++iter;
85  }
86 
87  return false;
88  }
89 
90  const DtUUID& firstSubordinate() const
91  {
92  if (mySubordinates.size())
93  {
94  return mySubordinates[0];
95  }
96 
97  return DtUUID::nullUUID();
98  }
99 
100  const DtUUID& lastSubordinate() const
101  {
102  if (mySubordinates.size())
103  {
104  return mySubordinates[mySubordinates.size() - 1];
105  }
106 
107  return DtUUID::nullUUID();
108  }
109 
110  protected:
111  std::vector<DtUUID> mySubordinates;
112  };
113 
117  {
118  public:
120 
122  : DtFrameStateInterface(storage)
123  {
124  }
125 
126  UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(std::vector<DtUUID>, subordinates, Subordinates)
127  UNDEFINED_METHOD(void, addSubordinate, const DtUUID&, int index = -1)
128  UNDEFINED_METHOD(bool, removeSubordinate, const DtUUID&)
129  UNDEFINED_METHOD(void, removeAllSubordinates)
130  UNDEFINED_RETURNREF_ACCESSOR(DtUUID, firstSubordinate)
131  UNDEFINED_RETURNREF_ACCESSOR(DtUUID, lastSubordinate)
132  virtual int numSubordinates() const { throw DtUnimplementedMethod("The int numSubordinates() const is undefined for this class."); };
133  virtual bool hasSubordinate(const DtUUID&) const { throw DtUnimplementedMethod("The bool hasSubordinate(const DtUUID&) const is undefined for this class."); };
134 
135  mutable boost::signals2::signal<void (const DtFrameStateInterface*, const std::vector<DtUUID>& oldSubordinates, const std::vector<DtUUID>& newSubordinates)> signal_subordinatesChanged;
136  };
137 
140  {
141  public:
143 
145  const DtSubordinateManagerStateComponentData& frameState() const { return myData; };
147 
148  int numSubordinates() const;
149  const DtUUID& firstSubordinate() const;
150  const DtUUID& lastSubordinate() const;
151  const std::vector<DtUUID>& subordinates() const;
152  void setSubordinates(const std::vector<DtUUID>&);
153  void addSubordinate(const DtUUID&, int index = -1);
154  bool removeSubordinate(const DtUUID&);
155  bool hasSubordinate(const DtUUID&) const;
156  void removeAllSubordinates();
157 
159  virtual void makeWritable() {};
160 
162  virtual void makeReadOnly() {};
163 
164  protected:
166  };
167 
170  {
171  public:
173 
175  const DtSubordinateManagerStateComponentData& frameState() const { return myData; };
176 
177  const DtUUID& firstSubordinate() const;
178  const DtUUID& lastSubordinate() const;
179  int numSubordinates() const;
180  const std::vector<DtUUID>& subordinates() const;
181  bool hasSubordinate(const DtUUID&) const;
182 
183  protected:
186  {
187  myData = data;
188  }
189 
190  protected:
192  };
193 
197  {
198  public:
200 
201  bool isDoubleBuffered() { return true; };
202  const DtFrameStateInterface* currentFrameState() const { return &myCurrentFrameState; }
203  virtual DtFrameStateInterface* nextFrameState() { return &myNextFrameState; };
204  virtual const DtFrameStateInterface* nextFrameState() const { return &myNextFrameState; };
205 
206  void updateDataStorage();
207 
209  {
210  myCurrentFrameState.updateStateData(sd);
211  myNextFrameState.updateStateData(sd);
212  }
213 
214  virtual void aboutToBeDeleted() override
215  {
217  myCurrentFrameState.aboutToBeDeleted();
218  myNextFrameState.aboutToBeDeleted();
219  }
220 
221  protected:
224  std::vector<DtUUID> mySubordinates;
225  };
226 
230 }
UUID is a unique ID wrapper class.
Definition: rwUUID.h:229
Definition: stateDataTypes.h:23
DtSubordinateManagerStateComponentCurrentFrame myCurrentFrameState
Definition: subordinateManagerStateComponent.h:222
bool hasSubordinate(const DtUUID &uuid) const
Definition: subordinateManagerStateComponent.h:72
#define UNDEFINED_METHOD(Type, Method,...)
Definition: doubleBufferedDataStorage.h:68
2) Define the next frame class. This will be used for write access.
Definition: subordinateManagerStateComponent.h:139
DtSubordinateManagerStateComponentData myData
Definition: subordinateManagerStateComponent.h:191
virtual const DtFrameStateInterface * nextFrameState() const
Definition: subordinateManagerStateComponent.h:204
DtSubordinateManagerStateComponentData & operator=(const DtSubordinateManagerStateComponentData &rhs)
Definition: subordinateManagerStateComponent.h:25
Definition: stateComponent.h:257
const DtSubordinateManagerStateComponentData & frameState() const
Current frame state only can access current frame buffers. This ensures thread safety.
Definition: subordinateManagerStateComponent.h:175
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:145
std::vector< DtUUID > mySubordinates
Definition: subordinateManagerStateComponent.h:224
const DtFrameStateInterface * currentFrameState() const
Definition: subordinateManagerStateComponent.h:202
virtual DtFrameStateInterface * nextFrameState()
Definition: subordinateManagerStateComponent.h:203
Contains the DtUUID class declaration.
#define UNDEFINED_RETURNREF_ACCESSOR(ReturnType, Member)
Definition: doubleBufferedDataStorage.h:34
void advanceFrame(const DtSubordinateManagerStateComponentData &data)
Definition: subordinateManagerStateComponent.h:185
const DtUUID & lastSubordinate() const
Definition: subordinateManagerStateComponent.h:100
void addSubordinate(const DtUUID &uuid, int index=-1)
Definition: subordinateManagerStateComponent.h:33
static const DtUUID & nullUUID()
void updateStateData(DtStateData *sd)
Implement to update data storage to the new state data.
Definition: subordinateManagerStateComponent.h:208
The overall structure of the DtStateData mechanism is: The DtStateData contains a list of double buff...
Definition: stateData.h:336
Definition: subordinateManagerStateComponent.h:15
#define DEFINE_STATE_COMPONENT_TYPE(CreatedComponent)
Definition: stateComponent.h:219
Subclass from this to indicate that this will be a double buffered state component.
Definition: stateComponent.h:370
DtSubordinateManagerStateComponentData(const DtSubordinateManagerStateComponentData &orig)
Definition: subordinateManagerStateComponent.h:20
virtual void aboutToBeDeleted()
bool isDoubleBuffered()
Definition: subordinateManagerStateComponent.h:201
4) Define the state component that will contain the wrappers to the next and current frame states tha...
Definition: subordinateManagerStateComponent.h:196
#define UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(Type, Member, Set)
Definition: doubleBufferedDataStorage.h:57
#define DEFINE_ACCESSOR_MUTATOR(ReturnType, Accessor, Mutator)
Definition: doubleBufferedDataStorage.h:23
const DtUUID & firstSubordinate() const
Definition: subordinateManagerStateComponent.h:90
3) Define the current frame class. This will be used for read access.
Definition: subordinateManagerStateComponent.h:169
DtSubordinateManagerStateComponentData()
Definition: subordinateManagerStateComponent.h:17
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:116
#define DT_DLL_vrfStateData
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfStateDataDefines.h:26
DtSubordinateManagerStateComponentNextFrame myNextFrameState
Definition: subordinateManagerStateComponent.h:223
DtSubordinateManagerStateComponentData & frameState()
Definition: subordinateManagerStateComponent.h:146
virtual void aboutToBeDeleted() override
Definition: subordinateManagerStateComponent.h:214
Contains the DtStateComponent class declaration.
virtual void makeWritable()
Override to make component writable.
Definition: subordinateManagerStateComponent.h:159
bool removeSubordinate(const DtUUID &uuid)
Definition: subordinateManagerStateComponent.h:52
This is a simple base class that will be used to return a pointer to current or next frame state...
Definition: stateComponent.h:282
DtStateComponentCreator< DtSubordinateManagerStateComponentImplementation > DtSubordinateManagerStateComponentCreator
5) Define the creator. This will need to be registered with the REGISTER_STATE_COMPONENT macro in the...
Definition: subordinateManagerStateComponent.h:229
std::vector< DtUUID > mySubordinates
Definition: subordinateManagerStateComponent.h:111
void removeAllSubordinates()
Definition: subordinateManagerStateComponent.h:71

Document ID: Generated on Sun Dec 4 20:22:03 EST 2022 from SVN revision 249613
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)