Files
compute-runtime/shared/test/unit_test/helpers/variable_backup.h
Filip Hazubski 486f25d224 Add comparison operator to VariableBackup
Related-To: NEO-5233

Signed-off-by: Filip Hazubski <filip.hazubski@intel.com>
2020-11-06 12:56:15 +01:00

39 lines
740 B
C++

/*
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
template <typename T>
class VariableBackup {
public:
VariableBackup(T *ptr) : pValue(ptr) {
oldValue = *ptr;
}
VariableBackup(T *ptr, T &&newValue) : pValue(ptr) {
oldValue = *ptr;
*pValue = newValue;
}
VariableBackup(T *ptr, T &newValue) : pValue(ptr) {
oldValue = *ptr;
*pValue = newValue;
}
~VariableBackup() {
*pValue = oldValue;
}
void operator=(const T &val) {
*pValue = val;
}
template <typename T2>
bool operator==(const T2 &val) const {
return *pValue == val;
}
private:
T oldValue;
T *pValue;
};