File indexing completed on 2024-05-12 05:25:57
0001 /* 0002 * Copyright (C) 2014 Christian Mollekopf <chrigi_1@fastmail.fm> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 #pragma once 0021 0022 #include <QVariant> 0023 #include <QByteArray> 0024 #include <QHash> 0025 #include <QDebug> 0026 0027 namespace Sink { 0028 0029 namespace ApplicationDomain { 0030 0031 /** 0032 * This class has to be implemented by resources and can be used as generic interface to access the buffer properties 0033 */ 0034 class BufferAdaptor 0035 { 0036 public: 0037 virtual ~BufferAdaptor() 0038 { 0039 } 0040 virtual QVariant getProperty(const QByteArray &key) const 0041 { 0042 qFatal("Tried to get property: %s", key.data()); 0043 return QVariant(); 0044 } 0045 virtual void setProperty(const QByteArray &key, const QVariant &value) 0046 { 0047 qFatal("Tried to get property: %s", key.data()); 0048 } 0049 virtual QList<QByteArray> availableProperties() const 0050 { 0051 return QList<QByteArray>(); 0052 } 0053 }; 0054 0055 class MemoryBufferAdaptor : public BufferAdaptor 0056 { 0057 public: 0058 MemoryBufferAdaptor() : BufferAdaptor() 0059 { 0060 } 0061 0062 virtual ~MemoryBufferAdaptor() 0063 { 0064 } 0065 0066 virtual QVariant getProperty(const QByteArray &key) const 0067 { 0068 return mValues.value(key); 0069 } 0070 virtual void setProperty(const QByteArray &key, const QVariant &value) 0071 { 0072 if (value != mValues.value(key)) { 0073 mChanges << key; 0074 } 0075 mValues.insert(key, value); 0076 } 0077 0078 virtual QByteArrayList availableProperties() const 0079 { 0080 return mValues.keys(); 0081 } 0082 0083 void resetChangedProperties() 0084 { 0085 mChanges.clear(); 0086 } 0087 0088 QList<QByteArray> changedProperties() const 0089 { 0090 return mChanges; 0091 } 0092 private: 0093 QHash<QByteArray, QVariant> mValues; 0094 QList<QByteArray> mChanges; 0095 }; 0096 } 0097 }