MAK Legion 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 
24  class SimulationDatabase;
25 
35  {
36  public:
37  static AttributeSetId setType(InstanceHandle id);
38 
39  //All derived classes must implement this function
40  //static AttributeSetId type();
41 
42  public:
46 
48  virtual ~WriteStateInstance();
49 
52 
54  WriteStateInstance& operator=(const WriteStateInstance& orig);
55 
57  bool isValid() const;
58 
60  InstanceHandle instanceHandle() const { return myInstanceHandle; }
61 
63  GlobalIdentifier globalId() const;
64 
66  AttributeSetId setType() const;
67 
69  template<typename DATA_TYPE>
70  DATA_TYPE data(AttributeIndex attributeId) const;
71 
73  template<typename DATA_TYPE>
74  const Span<DATA_TYPE> dataArray(AttributeIndex attributeIndex) const;
75 
76 
78  template<typename DATA_TYPE>
79  void setData(AttributeIndex attributeIndex, const DATA_TYPE& val);
80 
83  template<typename DATA_TYPE>
84  void setDataArray(AttributeIndex attributeIndex, const Span<DATA_TYPE>& val);
85 
86 
87 
89  template<typename DATA_TYPE>
90  void addDataArray(AttributeIndex attributeIndex, const Span<DATA_TYPE>& val);
91 
93  template<typename DATA_TYPE>
94  void removeDataArray(AttributeIndex attributeIndex, const Span<DATA_TYPE>& val);
95 
97  UInt32 dataArrayCount(AttributeIndex attributeIndex) const;
98  void setDataArrayCount(AttributeIndex attributeIndex, UInt32 count);
99 
101  virtual bool hasParent() const;
102  virtual Legion::InstanceHandle getParent() const;
103  virtual void setParent(const WriteStateInstance& val);
104 
105  template<typename COMP_TYPE>
106  COMP_TYPE findParent() const;
107 
109  virtual int extensionCount() const;
110  virtual void addExtension(WriteStateInstance& val);
111  virtual void removeExtension(WriteStateInstance& val);
112 
113  virtual Legion::InstanceHandle getExtension(int index) const;
114  virtual Legion::Span<Legion::InstanceHandle> extensions() const;
115  virtual void setExtensions(Legion::Span<Legion::InstanceHandle> val);
116 
117  //tries to find the component of a given type. If there is more than
118  //one component of that type, this gets the ordinal index component of that type
119  //from a list of only those component types.
120  //i.e findComponent<IffComponent>(2) will return the 3rd IffComponent attached to the entity if it exists
121  template<typename COMP_TYPE>
122  COMP_TYPE findTypeExtension(int index) const;
123 
124  //convince function for finding the count of a given type of component
125  template<typename COMP_TYPE>
126  int typeExtensionCount() const;
127 
128  template<typename COMP_TYPE>
129  std::vector<COMP_TYPE> getTypeExtensions() const;
130 
131  protected:
133  };
134 
135  template<typename COMP_TYPE>
137  {
138  Legion::InstanceHandle parentId = getParent();
139  if (COMP_TYPE::isType(parentId))
140  {
141  return COMP_TYPE(parentId); // create component interface
142  }
143 
144  return COMP_TYPE();
145  }
146 
147  template<typename COMP_TYPE>
148  COMP_TYPE WriteStateInstance::findTypeExtension(int index) const
149  {
150  int maxComponents = extensionCount();
151  int matchedCompCount = -1;
152  for (int i = 0; i < maxComponents; i++)
153  {
155  if (!COMP_TYPE::isType(compId))
156  {
157  continue;
158  }
159 
160  matchedCompCount++;
161  if (matchedCompCount == index)
162  {
163  return COMP_TYPE(compId); // create component interface
164  }
165  }
166 
167  return COMP_TYPE();
168  }
169 
170  template<typename COMP_TYPE>
172  {
173  int count = 0;
174  int maxComponents = extensionCount();
175  for (int i = 0; i < maxComponents; i++)
176  {
177  if (COMP_TYPE::isType(getExtension(i)))
178  {
179  count++;
180  }
181  }
182 
183  return count;
184  }
185 
186  template<typename COMP_TYPE>
187  std::vector<COMP_TYPE> WriteStateInstance::getTypeExtensions() const
188  {
189  std::vector<COMP_TYPE> ret;
190  int maxComponents = extensionCount();
191  for (int i = 0; i < maxComponents; i++)
192  {
194  if (COMP_TYPE::isType(compId))
195  {
196  ret.push_back(COMP_TYPE(compId));
197  }
198  }
199 
200  return ret;
201  }
202 }
203 
int typeExtensionCount() const
Definition: writeStateInstance.h:171
COMP_TYPE findParent() const
Definition: writeStateInstance.h:136
std::vector< COMP_TYPE > getTypeExtensions() const
Definition: writeStateInstance.h:187
COMP_TYPE findTypeExtension(int index) const
Definition: writeStateInstance.h:148
virtual Legion::InstanceHandle getParent() const
unsigned int UInt32
Definition: c_api.h:53
A span represents a contiguous array of objects in memory.
Definition: span.h:21
InstanceHandle myInstanceHandle
Definition: writeStateInstance.h:132
UInt32 AttributeSetId
Definition: readStateInstance.h:22
UInt64 GlobalIdentifier
a globally unique identifier
Definition: dataTypes.h:50
#define LEGION_DLL
Definition: legionDataStore/export.h:24
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:60
The WriteStateInstance is the base class of all write simulation object repository classes...
Definition: writeStateInstance.h:34
virtual Legion::InstanceHandle getExtension(int index) const
UInt64 InstanceHandle
Definition: readStateInstance.h:20
unsigned long long UInt64
Definition: c_api.h:55

Document ID: Generated on Mon Mar 8 15:11:30 EST 2021 from SVN revision 225633
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)