1/*
2 Copyright (c) 2007 - 2008 Volker Krause <vkrause@kde.org>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#ifndef AKONADI_ATTRIBUTEFACTORY_H
21#define AKONADI_ATTRIBUTEFACTORY_H
22
23#include <akonadi/attribute.h>
24
25namespace Akonadi {
26
27/**
28 * @short Provides the functionality of registering and creating arbitrary
29 * entity attributes.
30 *
31 * This class provides the functionality of registering and creating arbitrary Attributes for Entity
32 * and its subclasses (e.g. Item and Collection).
33 *
34 * @code
35 *
36 * // register the type first
37 * Akonadi::AttributeFactory::registerAttribute<SecrecyAttribute>();
38 *
39 * ...
40 *
41 * // use it anywhere else in the application
42 * SecrecyAttribute *attr = Akonadi::AttributeFactory::createAttribute( "secrecy" );
43 *
44 * @endcode
45 *
46 * @author Volker Krause <vkrause@kde.org>
47 */
48class AKONADI_EXPORT AttributeFactory
49{
50public:
51 //@cond PRIVATE
52 ~AttributeFactory();
53 //@endcond
54
55 /**
56 * Registers a custom attribute of type T.
57 * The same attribute cannot be registered more than once.
58 */
59 template <typename T> inline static void registerAttribute()
60 {
61 AttributeFactory::self()->registerAttribute(new T);
62 }
63
64 /**
65 * Creates an entity attribute object of the given type.
66 * If the type has not been registered, creates a DefaultAttribute.
67 *
68 * @param type The attribute type.
69 */
70 static Attribute *createAttribute(const QByteArray &type);
71
72protected:
73 //@cond PRIVATE
74 AttributeFactory();
75
76private:
77 static AttributeFactory *self();
78 void registerAttribute(Attribute *attribute);
79
80 class Private;
81 Private *const d;
82 //@endcond
83};
84
85}
86
87#endif
88