New css schema object for constructing property values from strings
[kworship.git] / kworship / css / KwCssSchema.h
blob2bfec66178ba21cf0f8c8c5e9a169ab010646348
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 #ifndef _KwCssSchema_h_
21 #define _KwCssSchema_h_
23 /**
24 * @file KwCssSchema.h
25 * @brief Schema of styles.
26 * @author James Hogan <james@albanarts.com>
29 #include "KwCssScope.h"
31 #include <QString>
32 #include <QHash>
34 #include <iostream>
35 /// Schema of styles.
36 class KwCssSchema
38 public:
41 * Constructors + destructor
44 /// Default constructor
45 KwCssSchema()
50 * Main interface
53 /// Register a new property.
54 template <typename T>
55 void registerProperty(const QString& name)
57 m_constructors[name] = &KwCssConstruct<T>;
60 /// Construct from an unprocessed string and a style name.
61 KwCssAbstractStyle* construct(const QString& name, const KwCssUnprocessed& value) const
63 KwCssAbstractStyle* result = 0;
64 if (m_constructors.contains(name))
66 result = m_constructors[name](value);
68 if (0 == result)
70 result = new KwCssStyle<KwCssUnprocessed>(value);
72 return result;
75 private:
78 * Variables
81 /// Constructor function.
82 typedef KwCssAbstractStyle* Constructor(const KwCssUnprocessed& value);
83 /// Hash of style names to constructors.
84 QHash<QString, Constructor*> m_constructors;
87 #endif // _KwCssSchema_h_