Replace executor class with a template --- we've got closures, after all :)

This commit is contained in:
Christian Speckner 2016-11-13 00:10:40 +01:00
parent 208f630a3c
commit b874269065
4 changed files with 19 additions and 48 deletions

View File

@ -51,17 +51,4 @@ namespace TIA6502tsCore {
myIndices[address] = index; myIndices[address] = index;
} }
void DelayQueue::execute(Executor& executor) {
DelayQueueMember& currentMember = myMembers.at(myIndex);
for (auto&& entry : currentMember) {
executor(entry.address, entry.value);
myIndices[entry.address] = 0xFF;
}
currentMember.clear();
myIndex = (myIndex + 1) & myMembers.size();
}
} // namespace TIA6502tsCore } // namespace TIA6502tsCore

View File

@ -27,18 +27,6 @@ namespace TIA6502tsCore {
class DelayQueue { class DelayQueue {
public:
class Executor {
public:
virtual void operator()(uInt8 address, uInt8 value) = 0;
virtual ~Executor() = default;
};
public: public:
DelayQueue(uInt8 length, uInt8 size); DelayQueue(uInt8 length, uInt8 size);
@ -47,7 +35,7 @@ class DelayQueue {
void push(uInt8 address, uInt8 value, uInt8 delay); void push(uInt8 address, uInt8 value, uInt8 delay);
void execute(Executor& executor); template<class T> void execute(T executor);
private: private:
@ -67,6 +55,23 @@ class DelayQueue {
}; };
// ############################################################################
// Implementation
// ############################################################################
template<class T> void DelayQueue::execute(T executor) {
DelayQueueMember& currentMember = myMembers.at(myIndex);
for (auto&& entry : currentMember) {
executor(entry.address, entry.value);
myIndices[entry.address] = 0xFF;
}
currentMember.clear();
myIndex = (myIndex + 1) & myMembers.size();
}
} // namespace TIA6502tsCore } // namespace TIA6502tsCore
#endif // TIA_6502TS_CORE_DELAY_QUEUE #endif // TIA_6502TS_CORE_DELAY_QUEUE

View File

@ -28,28 +28,8 @@ namespace TIA6502tsCore {
mySound(sound), mySound(sound),
mySettings(settings), mySettings(settings),
myDelayQueue(10, 20) myDelayQueue(10, 20)
{
class DelayedWriteExecutor : public DelayQueue::Executor {
public:
DelayedWriteExecutor(TIA& tia) : myTia(tia)
{} {}
void operator()(uInt8 address, uInt8 value) override
{
myTia.delayedWrite(address, value);
}
private:
TIA& myTia;
};
myDelayQueueExecutor.reset(new DelayedWriteExecutor(*this));
}
// TODO: stub // TODO: stub
void TIA::reset() void TIA::reset()
{} {}

View File

@ -128,7 +128,6 @@ class TIA : public AbstractTIA {
Settings& mySettings; Settings& mySettings;
DelayQueue myDelayQueue; DelayQueue myDelayQueue;
unique_ptr<DelayQueue::Executor> myDelayQueueExecutor;
private: private: