VR-Forces 5.0.1 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  mySubordinates.resize(index + 1);
44  }
45 
46  mySubordinates[index] = uuid;
47  }
48  };
49  bool removeSubordinate(const DtUUID& uuid)
50  {
51  std::vector<DtUUID>::iterator iter = mySubordinates.begin();
52  std::vector<DtUUID>::iterator end = mySubordinates.end();
53 
54  while (iter != end)
55  {
56  if (*iter == uuid)
57  {
58  mySubordinates.erase(iter);
59  return true;
60  }
61 
62  ++iter;
63  }
64 
65  return false;
66  }
67 
68  void removeAllSubordinates() { mySubordinates.clear(); };
69  bool hasSubordinate(const DtUUID& uuid) const
70  {
71  std::vector<DtUUID>::const_iterator iter = mySubordinates.begin();
72  std::vector<DtUUID>::const_iterator end = mySubordinates.end();
73 
74  while (iter != end)
75  {
76  if (*iter == uuid)
77  {
78  return true;
79  }
80 
81  ++iter;
82  }
83 
84  return false;
85  }
86 
87  const DtUUID& firstSubordinate() const
88  {
89  if (mySubordinates.size())
90  {
91  return mySubordinates[0];
92  }
93 
94  return DtUUID::nullUUID();
95  }
96 
97  const DtUUID& lastSubordinate() const
98  {
99  if (mySubordinates.size())
100  {
101  return mySubordinates[mySubordinates.size() - 1];
102  }
103 
104  return DtUUID::nullUUID();
105  }
106 
107  protected:
108  std::vector<DtUUID> mySubordinates;
109  };
110 
114  {
115  public:
117 
119  : DtFrameStateInterface(storage)
120  {
121  }
122 
123  UNDEFINED_RETURNREF_ACCESSOR_MUTATOR(std::vector<DtUUID>, subordinates, Subordinates)
124  UNDEFINED_METHOD(void, addSubordinate, const DtUUID&, int index = -1)
125  UNDEFINED_METHOD(bool, removeSubordinate, const DtUUID&)
126  UNDEFINED_METHOD(void, removeAllSubordinates)
127  UNDEFINED_RETURNREF_ACCESSOR(DtUUID, firstSubordinate)
128  UNDEFINED_RETURNREF_ACCESSOR(DtUUID, lastSubordinate)
129  virtual int numSubordinates() const { throw DtUnimplementedMethod("The int numSubordinates() const is undefined for this class."); };
130  virtual bool hasSubordinate(const DtUUID&) const { throw DtUnimplementedMethod("The bool hasSubordinate(const DtUUID&) const is undefined for this class."); };
131 
132  mutable boost::signals2::signal<void (const DtFrameStateInterface*, const std::vector<DtUUID>& oldSubordinates, const std::vector<DtUUID>& newSubordinates)> signal_subordinatesChanged;
133  };
134 
137  {
138  public:
140 
142  const DtSubordinateManagerStateComponentData& frameState() const { return myData; };
144 
145  int numSubordinates() const;
146  const DtUUID& firstSubordinate() const;
147  const DtUUID& lastSubordinate() const;
148  const std::vector<DtUUID>& subordinates() const;
149  void setSubordinates(const std::vector<DtUUID>&);
150  void addSubordinate(const DtUUID&, int index = -1);
151  bool removeSubordinate(const DtUUID&);
152  bool hasSubordinate(const DtUUID&) const;
153  void removeAllSubordinates();
154 
156  virtual void makeWritable() {};
157 
159  virtual void makeReadOnly() {};
160 
161  protected:
163  };
164 
167  {
168  public:
170 
172  const DtSubordinateManagerStateComponentData& frameState() const { return myData; };
173 
174  const DtUUID& firstSubordinate() const;
175  const DtUUID& lastSubordinate() const;
176  int numSubordinates() const;
177  const std::vector<DtUUID>& subordinates() const;
178  bool hasSubordinate(const DtUUID&) const;
179 
180  protected:
183  {
184  myData = data;
185  }
186 
187  protected:
189  };
190 
194  {
195  public:
197 
198  bool isDoubleBuffered() { return true; };
199  const DtFrameStateInterface* currentFrameState() const { return &myCurrentFrameState; }
200  virtual DtFrameStateInterface* nextFrameState() { return &myNextFrameState; };
201  virtual const DtFrameStateInterface* nextFrameState() const { return &myNextFrameState; };
202 
203  void updateDataStorage();
204 
206  {
207  myCurrentFrameState.updateStateData(sd);
208  myNextFrameState.updateStateData(sd);
209  }
210 
211  virtual void aboutToBeDeleted() override
212  {
214  myCurrentFrameState.aboutToBeDeleted();
215  myNextFrameState.aboutToBeDeleted();
216  }
217 
218  protected:
221  std::vector<DtUUID> mySubordinates;
222  };
223 
227 }
UUID is a unique ID wrapper class.
Definition: rwUUID.h:226
Definition: stateDataTypes.h:23
DtSubordinateManagerStateComponentCurrentFrame myCurrentFrameState
Definition: subordinateManagerStateComponent.h:219
bool hasSubordinate(const DtUUID &uuid) const
Definition: subordinateManagerStateComponent.h:69
#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:136
DtSubordinateManagerStateComponentData myData
Definition: subordinateManagerStateComponent.h:188
virtual const DtFrameStateInterface * nextFrameState() const
Definition: subordinateManagerStateComponent.h:201
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:172
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:142
std::vector< DtUUID > mySubordinates
Definition: subordinateManagerStateComponent.h:221
const DtFrameStateInterface * currentFrameState() const
Definition: subordinateManagerStateComponent.h:199
virtual DtFrameStateInterface * nextFrameState()
Definition: subordinateManagerStateComponent.h:200
Contains the DtUUID class declaration.
#define UNDEFINED_RETURNREF_ACCESSOR(ReturnType, Member)
Definition: doubleBufferedDataStorage.h:34
void advanceFrame(const DtSubordinateManagerStateComponentData &data)
Definition: subordinateManagerStateComponent.h:182
const DtUUID & lastSubordinate() const
Definition: subordinateManagerStateComponent.h:97
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:205
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:365
DtSubordinateManagerStateComponentData(const DtSubordinateManagerStateComponentData &orig)
Definition: subordinateManagerStateComponent.h:20
virtual void aboutToBeDeleted()
bool isDoubleBuffered()
Definition: subordinateManagerStateComponent.h:198
4) Define the state component that will contain the wrappers to the next and current frame states tha...
Definition: subordinateManagerStateComponent.h:193
#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:87
3) Define the current frame class. This will be used for read access.
Definition: subordinateManagerStateComponent.h:166
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:113
#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:220
DtSubordinateManagerStateComponentData & frameState()
Definition: subordinateManagerStateComponent.h:143
virtual void aboutToBeDeleted() override
Definition: subordinateManagerStateComponent.h:211
Contains the DtStateComponent class declaration.
virtual void makeWritable()
Override to make component writable.
Definition: subordinateManagerStateComponent.h:156
bool removeSubordinate(const DtUUID &uuid)
Definition: subordinateManagerStateComponent.h:49
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:226
std::vector< DtUUID > mySubordinates
Definition: subordinateManagerStateComponent.h:108
void removeAllSubordinates()
Definition: subordinateManagerStateComponent.h:68

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)