File indexing completed on 2024-05-12 15:57:03
0001 /* 0002 * SPDX-FileCopyrightText: 2019 Tusooa Zhu <tusooa@vista.aero> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KIS_NEW_ON_COPY_H_ 0008 #define KIS_NEW_ON_COPY_H_ 0009 0010 /** 0011 * This class wraps around some type T that is not copiable. 0012 * When the copy-constructor or assignment of KisNewOnCopy<T> is called, 0013 * it default-constructs an instance of T. 0014 */ 0015 template<typename T> 0016 class KisNewOnCopy 0017 { 0018 public: 0019 KisNewOnCopy() : instance() {} 0020 KisNewOnCopy(const KisNewOnCopy &) : instance() {} 0021 0022 // KisNewOnCopy &operator=(const KisNewOnCopy &) { return *this; } 0023 0024 const T *data() const { return &instance; } 0025 const T *constData() { return &instance; } 0026 T *data() { return &instance; } 0027 const T *operator->() const { return &instance; } 0028 T *operator->() { return &instance; } 0029 0030 private: 0031 T instance; 0032 }; 0033 0034 #endif