Use std::forward and rvalue references to simplify SharedMemory.Allocate invocations with reference arguments

This commit is contained in:
StrikerX3 2019-01-17 22:38:50 -02:00
parent 3bf2988b34
commit 068dcfce27
9 changed files with 10 additions and 10 deletions

View file

@ -35,7 +35,7 @@ public:
* otherwise the existing memory block is reused.
*/
template<class T, typename... Args>
T* Allocate(Args... args) {
T* Allocate(Args&&... args) {
// Invoke destructor from previous data structure
if (m_dtor != nullptr) {
m_dtor(*this);
@ -52,7 +52,7 @@ public:
// Update destructor to new data structure and call constructor
m_dtor = [](SharedMemory& u) { ((T*)u.m_memory)->~T(); };
return new(m_memory) T(args...);
return new(m_memory) T(std::forward<Args>(args)...);
}
/*!

View file

@ -28,7 +28,7 @@ public:
IdentifyDevice(ATADevice& device);
virtual ~IdentifyDevice() override;
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<IdentifyDevice, ATADevice&>(device); }
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<IdentifyDevice>(device); }
protected:
bool HasMoreData() override;

View file

@ -28,7 +28,7 @@ public:
IdentifyPacketDevice(ATADevice& device);
virtual ~IdentifyPacketDevice() override;
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<IdentifyPacketDevice, ATADevice&>(device); }
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<IdentifyPacketDevice>(device); }
protected:
bool HasMoreData() override;

View file

@ -28,7 +28,7 @@ public:
InitializeDeviceParameters(ATADevice& device);
virtual ~InitializeDeviceParameters() override;
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<InitializeDeviceParameters, ATADevice&>(device); }
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<InitializeDeviceParameters>(device); }
protected:
bool ExecuteImpl() override;

View file

@ -28,7 +28,7 @@ public:
Packet(ATADevice& device);
virtual ~Packet() override;
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<Packet, ATADevice&>(device); }
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<Packet>(device); }
};
}

View file

@ -28,7 +28,7 @@ public:
ReadDMA(ATADevice& device);
virtual ~ReadDMA() override;
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<ReadDMA, ATADevice&>(device); }
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<ReadDMA>(device); }
};
}

View file

@ -28,7 +28,7 @@ public:
SecurityUnlock(ATADevice& device);
virtual ~SecurityUnlock() override;
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<SecurityUnlock, ATADevice&>(device); }
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<SecurityUnlock>(device); }
protected:
bool Initialize() override;

View file

@ -28,7 +28,7 @@ public:
SetFeatures(ATADevice& device);
virtual ~SetFeatures() override;
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<SetFeatures, ATADevice&>(device); }
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<SetFeatures>(device); }
protected:
bool ExecuteImpl() override;

View file

@ -28,7 +28,7 @@ public:
WriteDMA(ATADevice& device);
virtual ~WriteDMA() override;
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<WriteDMA, ATADevice&>(device); }
static IATACommand *Factory(SharedMemory& sharedMemory, ATADevice& device) { return sharedMemory.Allocate<WriteDMA>(device); }
};
}