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> {
160 using type =
const T &;
162 template <
typename T>
struct Ref<false, T> {
166 template <
bool IsConst,
typename T>
struct Ptr;
167 template <
typename T>
struct Ptr<true,
T> {
168 using type =
const T *;
170 template <
typename T>
struct Ptr<false, T> {
177 template <
bool IsConst>
class IteratorT {
179 using HostT =
typename Ref<IsConst, LeavesCollection>::type;
180 using GCItT =
typename Iterator<IsConst, GenericCommandsT>::type;
181 using HACItT =
typename Iterator<IsConst, HostAccessorCommandsT>::type;
188 bool MGenericIsActive;
191 : MHost(
Host), MGCIt(GCIt), MHACIt(HACIt),
192 MGenericIsActive(GenericIsActive) {}
203 : MHost{Other.MHost}, MGCIt(Other.MGCIt), MHACIt(Other.MHACIt),
204 MGenericIsActive(Other.MGenericIsActive) {}
207 : MHost{Other.MHost}, MGCIt(std::move(Other.MGCIt)),
208 MHACIt(std::move(Other.MHACIt)),
209 MGenericIsActive(Other.MGenericIsActive) {}
213 return &MHost == &Rhs.MHost && MGenericIsActive == Rhs.MGenericIsActive &&
214 ((MGenericIsActive && MGCIt == Rhs.MGCIt) ||
215 (!MGenericIsActive && MHACIt == Rhs.MHACIt));
219 return &MHost != &Rhs.MHost || MGenericIsActive != Rhs.MGenericIsActive ||
220 ((MGenericIsActive && MGCIt != Rhs.MGCIt) ||
221 (!MGenericIsActive && MHACIt != Rhs.MHACIt));
239 if (MGenericIsActive && MGCIt != MHost.MGenericCommands.end())
242 if (!MGenericIsActive && MHACIt != MHost.endHostAccessor())
252 if (MGenericIsActive) {
255 if (MGCIt == MHost.MGenericCommands.end()) {
256 MGenericIsActive =
false;
257 MHACIt = MHost.MHostAccessorCommands.begin();
264 assert(MGCIt == MHost.MGenericCommands.end());
266 if (MHACIt == MHost.endHostAccessor())