16 #include <unordered_map>
61 : MRecord{Record}, MGenericCommands{GenericCommandsCapacity},
62 MAllocateDependency{std::move(AllocateDependency)} {}
65 if (MGenericCommands.empty())
66 return iterator{*
this, beginHostAccessor()};
68 return iterator{*
this, MGenericCommands.begin()};
74 if (MGenericCommands.empty())
85 bool push_back(value_type Cmd, EnqueueListT &ToEnqueue);
90 size_t remove(value_type Cmd);
92 std::vector<value_type> toVector()
const;
95 return MGenericCommands.capacity();
99 return MGenericCommands;
103 return MHostAccessorCommands;
107 template <
bool IsConst,
typename T>
struct Iterator;
109 template <
typename T>
struct Iterator<true, T> {
110 using type =
typename T::const_iterator;
113 template <
typename T>
struct Iterator<false, T> {
114 using type =
typename T::iterator;
117 using HostAccessorCommandSingleXRefT =
118 typename HostAccessorCommandsT::iterator;
119 using HostAccessorCommandsXRefT =
120 std::unordered_map<EmptyCommand *, HostAccessorCommandSingleXRefT>;
122 MemObjRecord *MRecord;
123 GenericCommandsT MGenericCommands;
124 HostAccessorCommandsT MHostAccessorCommands;
125 HostAccessorCommandsXRefT MHostAccessorCommandsXRef;
127 AllocateDependencyF MAllocateDependency;
129 bool addGenericCommand(value_type Cmd, EnqueueListT &ToEnqueue);
130 bool addHostAccessorCommand(EmptyCommand *Cmd, EnqueueListT &ToEnqueue);
133 void insertHostAccessorCommand(EmptyCommand *Cmd);
135 size_t eraseHostAccessorCommand(EmptyCommand *Cmd);
137 typename Iterator<false, HostAccessorCommandsT>::type beginHostAccessor() {
138 return MHostAccessorCommands.begin();
141 typename Iterator<true, HostAccessorCommandsT>::type
142 beginHostAccessor()
const {
143 return MHostAccessorCommands.begin();
146 typename Iterator<false, HostAccessorCommandsT>::type endHostAccessor() {
147 return MHostAccessorCommands.end();
150 typename Iterator<true, HostAccessorCommandsT>::type endHostAccessor()
const {
151 return MHostAccessorCommands.end();
158 template <
bool IsConst,
typename T>
struct Ref;
159 template <
typename T>
struct Ref<true, T> {
using type =
const T &; };
160 template <
typename T>
struct Ref<false, T> {
using type = T &; };
162 template <
bool IsConst,
typename T>
struct Ptr;
163 template <
typename T>
struct Ptr<true, T> {
using type =
const T *; };
164 template <
typename T>
struct Ptr<false, T> {
using type = T *; };
169 template <
bool IsConst>
class IteratorT {
171 using HostT =
typename Ref<IsConst, LeavesCollection>::type;
172 using GCItT =
typename Iterator<IsConst, GenericCommandsT>::type;
173 using HACItT =
typename Iterator<IsConst, HostAccessorCommandsT>::type;
180 bool MGenericIsActive;
183 : MHost(
Host), MGCIt(GCIt), MHACIt(HACIt),
184 MGenericIsActive(GenericIsActive) {}
195 : MHost{Other.MHost}, MGCIt(Other.MGCIt), MHACIt(Other.MHACIt),
196 MGenericIsActive(Other.MGenericIsActive) {}
199 : MHost{Other.MHost}, MGCIt(std::move(Other.MGCIt)),
200 MHACIt(std::move(Other.MHACIt)),
201 MGenericIsActive(Other.MGenericIsActive) {}
205 return &MHost == &Rhs.MHost && MGenericIsActive == Rhs.MGenericIsActive &&
206 ((MGenericIsActive && MGCIt == Rhs.MGCIt) ||
207 (!MGenericIsActive && MHACIt == Rhs.MHACIt));
211 return &MHost != &Rhs.MHost || MGenericIsActive != Rhs.MGenericIsActive ||
212 ((MGenericIsActive && MGCIt != Rhs.MGCIt) ||
213 (!MGenericIsActive && MHACIt != Rhs.MHACIt));
231 if (MGenericIsActive && MGCIt != MHost.MGenericCommands.end())
234 if (!MGenericIsActive && MHACIt != MHost.endHostAccessor())
244 if (MGenericIsActive) {
247 if (MGCIt == MHost.MGenericCommands.end()) {
248 MGenericIsActive =
false;
249 MHACIt = MHost.MHostAccessorCommands.begin();
256 assert(MGCIt == MHost.MGenericCommands.end());
258 if (MHACIt == MHost.endHostAccessor())