MAK Legion 1.1 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 {
24 
25  class SimulationDatabase;
26 
34  class LEGION_DLL ReadStateInstance
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:
45  explicit ReadStateInstance(InstanceHandle instanceId);
46 
49 
51  ReadStateInstance& operator=(const ReadStateInstance& orig);
52 
54  virtual ~ReadStateInstance();
55 
57  virtual bool isValid() const;
58 
60  virtual InstanceHandle instanceHandle() const { return myInstanceHandle; }
61 
63  virtual GlobalIdentifier globalId() const;
64 
66  virtual AttributeSetId setType() const;
67 
69  DatabaseHandle database() const;
70 
72  template<typename DATA_TYPE>
73  DATA_TYPE data(AttributeIndex attributeIndex) const;
74 
76  template<typename DATA_TYPE>
77  const Span<DATA_TYPE> dataArray(AttributeIndex attributeIndex) const;
78 
80  virtual UInt32 dataArrayCount(AttributeIndex attributeIndex) const;
81 
83  virtual bool hasParent() const;
84  virtual Legion::InstanceHandle getParent() const;
85 
86  template<typename COMP_TYPE>
87  COMP_TYPE findParent() const;
88 
90  virtual int extensionCount() const;
91  virtual Legion::InstanceHandle getExtension(int index) const;
92  virtual Legion::Span<Legion::InstanceHandle> extensions() const;
93 
94  //tries to find the component of a given type. If there is more than
95  //one component of that type, this gets the ordinal index component of that type
96  //from a list of only those component types.
97  //i.e findComponent<IffComponent>(2) will return the 3rd IffComponent attached to the entity if it exists
98  template<typename COMP_TYPE>
99  COMP_TYPE findTypeExtension(int index) const;
100 
101  //convince function for finding the count of a given type of component
102  template<typename COMP_TYPE>
103  int typeExtensionCount() const;
104 
105  template<typename COMP_TYPE>
106  std::vector<COMP_TYPE> getTypeExtensions() const;
107 
108  protected:
110  };
111 
112  template<typename COMP_TYPE>
114  {
115  Legion::InstanceHandle parentId = getParent();
116  if (COMP_TYPE::isType(parentId))
117  {
118  return COMP_TYPE(parentId); // create component interface
119  }
120 
121  return COMP_TYPE();
122  }
123 
124  template<typename COMP_TYPE>
125  COMP_TYPE ReadStateInstance::findTypeExtension(int index) const
126  {
127  int maxComponents = extensionCount();
128  int matchedCompCount = -1;
129  for (int i = 0; i < maxComponents; i++)
130  {
132  if (!COMP_TYPE::isType(compId))
133  {
134  continue;
135  }
136 
137  matchedCompCount++;
138  if (matchedCompCount == index)
139  {
140  return COMP_TYPE(compId); // create component interface
141  }
142 
143  }
144 
145  return COMP_TYPE();
146  }
147 
148  template<typename COMP_TYPE>
150  {
151  int count = 0;
152  int maxComponents = extensionCount();
153  for (int i = 0; i < maxComponents; i++)
154  {
155  if (COMP_TYPE::isType(getExtension(i)))
156  {
157  count++;
158  }
159  }
160 
161  return count;
162  }
163 
164 
165  template<typename COMP_TYPE>
166  std::vector<COMP_TYPE> ReadStateInstance::getTypeExtensions() const
167  {
168  std::vector<COMP_TYPE> ret;
169  int maxComponents = extensionCount();
170  for (int i = 0; i < maxComponents; i++)
171  {
173  if (COMP_TYPE::isType(compId))
174  {
175  ret.push_back(COMP_TYPE(compId));
176  }
177  }
178 
179  return ret;
180  }
181 }
182 
virtual InstanceHandle instanceHandle() const
Get the instance ID of the simulation object that this state repository references.
Definition: readStateInstance.h:60
std::vector< COMP_TYPE > getTypeExtensions() const
Definition: readStateInstance.h:166
virtual int extensionCount() const
InstanceHandle myInstanceHandle
Definition: readStateInstance.h:109
UInt64 DatabaseHandle
Definition: readStateInstance.h:23
The ReadStateInstance is the base class of all read simulation object repository classes.
Definition: readStateInstance.h:34
A span represents a contiguous array of objects in memory.
Definition: span.h:22
UInt32 AttributeSetId
Definition: readStateInstance.h:22
UInt64 GlobalIdentifier
a globally unique identifier
Definition: dataTypes.h:50
COMP_TYPE findParent() const
Definition: readStateInstance.h:113
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:42
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:149
UInt64 InstanceHandle
Definition: readStateInstance.h:20
COMP_TYPE findTypeExtension(int index) const
Definition: readStateInstance.h:125

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)