/usr/include/gammaray/core/metaproperty.h is in gammaray-dev 2.7.0-1ubuntu8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | /*
metaproperty.h
This file is part of GammaRay, the Qt application inspection and
manipulation tool.
Copyright (C) 2011-2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
Author: Volker Krause <volker.krause@kdab.com>
Licensees holding valid commercial KDAB GammaRay licenses may use this file in
accordance with GammaRay Commercial License Agreement provided with the Software.
Contact info@kdab.com if any conditions of this licensing are not clear to you.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GAMMARAY_METAPROPERTY_H
#define GAMMARAY_METAPROPERTY_H
#include "gammaray_core_export.h"
#include <QVariant>
namespace GammaRay {
class MetaObject;
/** @brief Introspectable adaptor to non-QObject properties. */
class GAMMARAY_CORE_EXPORT MetaProperty
{
public:
explicit MetaProperty(const char *name);
virtual ~MetaProperty();
/// User-readable name of that property
const char *name() const;
/// Current value of the property for object @p object.
virtual QVariant value(void *object) const = 0;
/// Returns @c true if this property is read-only.
virtual bool isReadOnly() const = 0;
/// Allows changing the property value, assuming it's not read-only, for the instance @p object.
virtual void setValue(void *object, const QVariant &value);
/// Returns the name of the data type of this property.
virtual const char *typeName() const = 0;
/// Returns the class this property belongs to.
MetaObject *metaObject() const;
private:
Q_DISABLE_COPY(MetaProperty)
friend class MetaObject;
void setMetaObject(MetaObject *om);
MetaObject *m_class;
const char *m_name;
};
///@cond internal
namespace detail {
template<typename T>
struct strip_const_ref {
typedef T type;
};
template<typename T>
struct strip_const_ref<const T &> {
typedef T type;
};
}
///@endcond
/** @brief Template-ed implementation of MetaProperty for member properties. */
template<typename Class, typename GetterReturnType, typename SetterArgType = GetterReturnType>
class MetaPropertyImpl : public MetaProperty
{
private:
typedef typename detail::strip_const_ref<GetterReturnType>::type ValueType;
public:
inline MetaPropertyImpl(
const char *name, GetterReturnType(Class::*getter)() const,
void(Class::*setter)(SetterArgType) = nullptr)
: MetaProperty(name)
, m_getter(getter)
, m_setter(setter)
{
}
bool isReadOnly() const override
{
return m_setter == nullptr;
}
QVariant value(void *object) const override
{
Q_ASSERT(object);
Q_ASSERT(m_getter);
const ValueType v = (static_cast<Class *>(object)->*(m_getter))();
return QVariant::fromValue(v);
}
void setValue(void *object, const QVariant &value) override
{
if (isReadOnly())
return;
Q_ASSERT(object);
Q_ASSERT(m_setter);
(static_cast<Class *>(object)->*(m_setter))(value.value<ValueType>());
}
const char *typeName() const override
{
return QMetaType::typeName(qMetaTypeId<ValueType>());
}
private:
GetterReturnType (Class::*m_getter)() const;
void (Class::*m_setter)(SetterArgType);
};
/** @brief Template-ed implementation of MetaProperty for static properties. */
template<typename Class, typename GetterReturnType>
class MetaStaticPropertyImpl : public MetaProperty
{
private:
typedef typename detail::strip_const_ref<GetterReturnType>::type ValueType;
public:
inline MetaStaticPropertyImpl(const char *name, GetterReturnType(*getter)())
: MetaProperty(name)
, m_getter(getter)
{
}
bool isReadOnly() const override
{
return true;
}
QVariant value(void *object) const override
{
Q_UNUSED(object);
Q_ASSERT(m_getter);
const ValueType v = m_getter();
return QVariant::fromValue(v);
}
const char *typeName() const override
{
return QMetaType::typeName(qMetaTypeId<ValueType>());
}
private:
GetterReturnType (*m_getter)();
};
}
#endif
|