MAK Legion 1.1 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
writeStateInstance.h
Go to the documentation of this file.
1 /*********************************************************************************
2 ** Copyright (c) 2020 MAK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************************/
5 
8 
9 #pragma once
10 
11 #include "legionDataStore/export.h"
13 #include "legionDataStore/span.h"
14 
15 #include <string>
16 #include <vector>
17 
18 namespace Legion
19 {
20  typedef UInt64 InstanceHandle;
21  typedef UInt32 AttributeIndex;
22  typedef UInt32 AttributeSetId;
23  typedef UInt64 DatabaseHandle;
24 
25  class SimulationDatabase;
26 
35  class LEGION_DLL WriteStateInstance
36  {
37  public:
38  static AttributeSetId setType(InstanceHandle id);
39 
40  //All derived classes must implement this function
41  //static AttributeSetId type();
42 
43  public:
46  explicit WriteStateInstance(InstanceHandle instanceId);
47 
49  virtual ~WriteStateInstance();
50 
53 
55  WriteStateInstance& operator=(const WriteStateInstance& orig);
56 
58  void destroy();
59 
61  bool isValid() const;
62 
64  InstanceHandle instanceHandle() const { return myInstanceHandle; }
65 
67  GlobalIdentifier globalId() const;
68 
70  AttributeSetId setType() const;
71 
73  DatabaseHandle database() const;
74 
76  template<typename DATA_TYPE>
77  DATA_TYPE data(AttributeIndex attributeId) const;
78 
80  template<typename DATA_TYPE>
81  const Span<DATA_TYPE> dataArray(AttributeIndex attributeIndex) const;
82 
83 
85  template<typename DATA_TYPE>
86  void setData(AttributeIndex attributeIndex, const DATA_TYPE& val);
87 
90  template<typename DATA_TYPE>
91  void setDataArray(AttributeIndex attributeIndex, const Span<DATA_TYPE>& val);
92 
93 
94 
96  template<typename DATA_TYPE>
97  void addDataArray(AttributeIndex attributeIndex, const Span<DATA_TYPE>& val);
98 
100  template<typename DATA_TYPE>
101  void removeDataArray(AttributeIndex attributeIndex, const Span<DATA_TYPE>& val);
102 
104  UInt32 dataArrayCount(AttributeIndex attributeIndex) const;
105  void setDataArrayCount(AttributeIndex attributeIndex, UInt32 count);
106 
108  virtual bool hasParent() const;
109  virtual Legion::InstanceHandle getParent() const;
110  virtual void setParent(const WriteStateInstance& val);
111 
112  template<typename COMP_TYPE>
113  COMP_TYPE findParent() const;
114 
116  virtual int extensionCount() const;
117  virtual void addExtension(WriteStateInstance& val);
118  virtual void removeExtension(WriteStateInstance& val);
119 
120  virtual Legion::InstanceHandle getExtension(int index) const;
121  virtual Legion::Span<Legion::InstanceHandle> extensions() const;
122  virtual void setExtensions(Legion::Span<Legion::InstanceHandle> val);
123 
124  //tries to find the component of a given type. If there is more than
125  //one component of that type, this gets the ordinal index component of that type
126  //from a list of only those component types.
127  //i.e findComponent<IffComponent>(2) will return the 3rd IffComponent attached to the entity if it exists
128  template<typename COMP_TYPE>
129  COMP_TYPE findTypeExtension(int index) const;
130 
131  //convince function for finding the count of a given type of component
132  template<typename COMP_TYPE>
133  int typeExtensionCount() const;
134 
135  template<typename COMP_TYPE>
136  std::vector<COMP_TYPE> getTypeExtensions() const;
137 
138  protected:
140  };
141 
142  template<typename COMP_TYPE>
144  {
145  Legion::InstanceHandle parentId = getParent();
146  if (COMP_TYPE::isType(parentId))
147  {
148  return COMP_TYPE(parentId); // create component interface
149  }
150 
151  return COMP_TYPE();
152  }
153 
154  template<typename COMP_TYPE>
155  COMP_TYPE WriteStateInstance::findTypeExtension(int index) const
156  {
157  int maxComponents = extensionCount();
158  int matchedCompCount = -1;
159  for (int i = 0; i < maxComponents; i++)
160  {
162  if (!COMP_TYPE::isType(compId))
163  {
164  continue;
165  }
166 
167  matchedCompCount++;
168  if (matchedCompCount == index)
169  {
170  return COMP_TYPE(compId); // create component interface
171  }
172  }
173 
174  return COMP_TYPE();
175  }
176 
177  template<typename COMP_TYPE>
179  {
180  int count = 0;
181  int maxComponents = extensionCount();
182  for (int i = 0; i < maxComponents; i++)
183  {
184  if (COMP_TYPE::isType(getExtension(i)))
185  {
186  count++;
187  }
188  }
189 
190  return count;
191  }
192 
193  template<typename COMP_TYPE>
194  std::vector<COMP_TYPE> WriteStateInstance::getTypeExtensions() const
195  {
196  std::vector<COMP_TYPE> ret;
197  int maxComponents = extensionCount();
198  for (int i = 0; i < maxComponents; i++)
199  {
201  if (COMP_TYPE::isType(compId))
202  {
203  ret.push_back(COMP_TYPE(compId));
204  }
205  }
206 
207  return ret;
208  }
209 }
210 
int typeExtensionCount() const
Definition: writeStateInstance.h:178
COMP_TYPE findParent() const
Definition: writeStateInstance.h:143
std::vector< COMP_TYPE > getTypeExtensions() const
Definition: writeStateInstance.h:194
COMP_TYPE findTypeExtension(int index) const
Definition: writeStateInstance.h:155
virtual Legion::InstanceHandle getParent() const
unsigned int UInt32
Definition: c_api.h:54
UInt64 DatabaseHandle
Definition: readStateInstance.h:23
A span represents a contiguous array of objects in memory.
Definition: span.h:22
InstanceHandle myInstanceHandle
Definition: writeStateInstance.h:139
UInt32 AttributeSetId
Definition: readStateInstance.h:22
UInt64 GlobalIdentifier
a globally unique identifier
Definition: dataTypes.h:50
UInt32 AttributeIndex
Definition: readStateInstance.h:21
virtual int extensionCount() const
Array of extension repositories, e.g. EmbeddedSystem and other features.
unsigned int UInt32
Definition: dataTypes.h:44
InstanceHandle instanceHandle() const
Get the instance ID of the simulation object that this state repository references.
Definition: writeStateInstance.h:64
The WriteStateInstance is the base class of all write simulation object repository classes...
Definition: writeStateInstance.h:35
virtual Legion::InstanceHandle getExtension(int index) const
UInt64 InstanceHandle
Definition: readStateInstance.h:20
unsigned long long UInt64
Definition: c_api.h:56

Document ID: Generated on Wed May 26 15:17:05 EDT 2021 from SVN revision 229676
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)