Akonadi

attributefactory.h
1/*
2 SPDX-FileCopyrightText: 2007-2008 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akonadicore_export.h"
10#include "attribute.h"
11
12#include <memory>
13
14namespace Akonadi
15{
16class AttributeFactoryPrivate;
17
18/**
19 * @short Provides the functionality of registering and creating arbitrary
20 * entity attributes.
21 *
22 * This class provides the functionality of registering and creating arbitrary Attributes for Entity
23 * and its subclasses (e.g. Item and Collection).
24 *
25 * @code
26 *
27 * // register the type first
28 * Akonadi::AttributeFactory::registerAttribute<SecrecyAttribute>();
29 *
30 * ...
31 *
32 * // use it anywhere else in the application
33 * SecrecyAttribute *attr = Akonadi::AttributeFactory::createAttribute( "secrecy" );
34 *
35 * @endcode
36 *
37 * @author Volker Krause <vkrause@kde.org>
38 */
39class AKONADICORE_EXPORT AttributeFactory
40{
41public:
42 /// @cond PRIVATE
44 /// @endcond
45
46 /**
47 * Registers a custom attribute of type T.
48 * The same attribute cannot be registered more than once.
49 */
50 template<typename T>
51 inline static void registerAttribute()
52 {
53 static_assert(std::is_default_constructible<T>::value, "An Attribute must be default-constructible.");
54 AttributeFactory::self()->registerAttribute(std::unique_ptr<T>{new T{}});
55 }
56
57 /**
58 * Creates an entity attribute object of the given type.
59 * If the type has not been registered, creates a DefaultAttribute.
60 *
61 * @param type The attribute type.
62 */
63 static Attribute *createAttribute(const QByteArray &type);
64
65protected:
66 /// @cond PRIVATE
67 explicit AttributeFactory();
68
69private:
70 Q_DISABLE_COPY(AttributeFactory)
71 static AttributeFactory *self();
72 void registerAttribute(std::unique_ptr<Attribute> attribute);
73
74 const std::unique_ptr<AttributeFactoryPrivate> d;
75 /// @endcond
76};
77
78} // namespace Akonadi
Provides the functionality of registering and creating arbitrary entity attributes.
static void registerAttribute()
Registers a custom attribute of type T.
Provides interface for custom attributes for Entity.
Definition attribute.h:132
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:03:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.