Files
qt6-migration-pipeline/Lts/Common/LtsScriptTimeline/temporary_pointer_vector.h
T

51 lines
675 B
C++
Executable File

#pragma once
#include <QVector>
#include <QDebug>
namespace LtsScriptTimeline
{
template <typename T>
class TemporaryPointerVector : public QVector<T>
{
static_assert(std::is_pointer<T>::value, "Type must be of pointer type");
public:
TemporaryPointerVector() = default;
explicit TemporaryPointerVector(const QVector<T> &other)
{
discard();
this->append(other);
}
~TemporaryPointerVector()
{
discard();
}
void setDiscardable(bool discardable)
{
m_discard = discardable;
}
private:
bool m_discard = true;
void discard()
{
if (m_discard)
qDeleteAll(this->begin(), this->end());
this->clear();
}
};
}