MAK Legion API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
readStateInstance.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 {
23 
24  class SimulationDatabase;
25 
34  {
35  public:
36  static AttributeSetId setType(InstanceHandle id);
37 
38  //All derived classes must implement this function
39  //static AttributeSetId type();
40 
41  public:
45 
48 
50  ReadStateInstance& operator=(const ReadStateInstance& orig);
51 
53  virtual ~ReadStateInstance();
54 
56  virtual bool isValid() const;
57 
59  virtual InstanceHandle instanceHandle() const { return myInstanceHandle; }
60 
62  virtual GlobalIdentifier globalId() const;
63 
65  virtual AttributeSetId setType() const;
66 
68  template<typename DATA_TYPE>
69  DATA_TYPE data(AttributeIndex attributeIndex) const;
70 
72  template<typename DATA_TYPE>
73  const Span<DATA_TYPE> dataArray(AttributeIndex attributeIndex) const;
74 
76  virtual UInt32 dataArrayCount(AttributeIndex attributeIndex) const;
77 
79  virtual bool hasParent() const;
80  virtual Legion::InstanceHandle getParent() const;
81 
82  template<typename COMP_TYPE>
83  COMP_TYPE findParent() const;
84 
86  virtual int extensionCount() const;
87  virtual Legion::InstanceHandle getExtension(int index) const;
88  virtual Legion::Span<Legion::InstanceHandle> extensions() const;
89 
90  //tries to find the component of a given type. If there is more than
91  //one component of that type, this gets the ordinal index component of that type
92  //from a list of only those component types.
93  //i.e findComponent<IffComponent>(2) will return the 3rd IffComponent attached to the entity if it exists
94  template<typename COMP_TYPE>
95  COMP_TYPE findTypeExtension(int index) const;
96 
97  //convince function for finding the count of a given type of component
98  template<typename COMP_TYPE>
99  int typeExtensionCount() const;
100 
101  template<typename COMP_TYPE>
102  std::vector<COMP_TYPE> getTypeExtensions() const;
103 
104  protected:
106  };
107 
108  template<typename COMP_TYPE>
110  {
111  Legion::InstanceHandle parentId = getParent();
112  if (COMP_TYPE::isType(parentId))
113  {
114  return COMP_TYPE(parentId); // create component interface
115  }
116 
117  return COMP_TYPE();
118  }
119 
120  template<typename COMP_TYPE>
121  COMP_TYPE ReadStateInstance::findTypeExtension(int index) const
122  {
123  int maxComponents = extensionCount();
124  int matchedCompCount = -1;
125  for (int i = 0; i < maxComponents; i++)
126  {
128  if (!COMP_TYPE::isType(compId))
129  {
130  continue;
131  }
132 
133  matchedCompCount++;
134  if (matchedCompCount == index)
135  {
136  return COMP_TYPE(compId); // create component interface
137  }
138 
139  }
140 
141  return COMP_TYPE();
142  }
143 
144  template<typename COMP_TYPE>
146  {
147  int count = 0;
148  int maxComponents = extensionCount();
149  for (int i = 0; i < maxComponents; i++)
150  {
151  if (COMP_TYPE::isType(getExtension(i)))
152  {
153  count++;
154  }
155  }
156 
157  return count;
158  }
159 
160 
161  template<typename COMP_TYPE>
162  std::vector<COMP_TYPE> ReadStateInstance::getTypeExtensions() const
163  {
164  std::vector<COMP_TYPE> ret;
165  int maxComponents = extensionCount();
166  for (int i = 0; i < maxComponents; i++)
167  {
169  if (COMP_TYPE::isType(compId))
170  {
171  ret.push_back(COMP_TYPE(compId));
172  }
173  }
174 
175  return ret;
176  }
177 }
178 
virtual InstanceHandle instanceHandle() const
Get the instance ID of the simulation object that this state repository references.
Definition: readStateInstance.h:59
std::vector< COMP_TYPE > getTypeExtensions() const
Definition: readStateInstance.h:162
virtual int extensionCount() const
InstanceHandle myInstanceHandle
Definition: readStateInstance.h:105
The ReadStateInstance is the base class of all read simulation object repository classes.
Definition: readStateInstance.h:33
A span represents a contiguous array of objects in memory.
Definition: span.h:21
UInt32 AttributeSetId
Definition: readStateInstance.h:22
UInt64 GlobalIdentifier
a globally unique identifier
Definition: dataTypes.h:50
COMP_TYPE findParent() const
Definition: readStateInstance.h:109
#define LEGION_DLL
Definition: legionDataStore/export.h:24
UInt32 AttributeIndex
Definition: readStateInstance.h:21
unsigned int UInt32
Definition: dataTypes.h:44
The SimulationDatabase stores all data for the simulation. It also owns the event, control, and view managers.
Definition: simulationDatabase.h:39
virtual Legion::InstanceHandle getParent() const
unsigned long long UInt64
Definition: dataTypes.h:46
virtual Legion::InstanceHandle getExtension(int index) const
int typeExtensionCount() const
Definition: readStateInstance.h:145
UInt64 InstanceHandle
Definition: readStateInstance.h:20
COMP_TYPE findTypeExtension(int index) const
Definition: readStateInstance.h:121

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)