1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDECLARATIVETYPENAMECACHE_P_H
43 #define QDECLARATIVETYPENAMECACHE_P_H
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
56 #include <private/qdeclarativerefcount_p.h>
57 #include "qdeclarativecleanup_p.h"
58 #include "qdeclarativemetatype_p.h"
60 #include <private/qhashedstring_p.h>
62 #include <QtCore/qvector.h>
66 class QDeclarativeType;
67 class QDeclarativeEngine;
68 class QDeclarativeTypeNameCache : public QDeclarativeRefCount
71 QDeclarativeTypeNameCache();
72 virtual ~QDeclarativeTypeNameCache();
74 inline bool isEmpty() const;
76 void add(const QHashedString &name, int sciptIndex = -1, const QHashedString &nameSpace = QHashedString());
80 inline Result(const void *importNamespace);
81 inline Result(QDeclarativeType *type);
82 inline Result(int scriptIndex);
83 inline Result(const Result &);
85 inline bool isValid() const;
87 QDeclarativeType *type;
88 const void *importNamespace;
91 Result query(const QHashedStringRef &);
92 Result query(const QHashedStringRef &, const void *importNamespace);
93 Result query(const QHashedV8String &);
94 Result query(const QHashedV8String &, const void *importNamespace);
95 QDeclarativeMetaType::ModuleApiInstance *moduleApi(const void *importNamespace);
98 friend class QDeclarativeImports;
103 QDeclarativeMetaType::ModuleApiInstance *moduleApi;
104 QVector<QDeclarativeTypeModuleVersion> modules;
106 // Or, imported script
110 template<typename Key>
111 Result query(const QStringHash<Import> &imports, Key key)
113 Import *i = imports.value(key);
115 if (i->scriptIndex != -1) {
116 return Result(i->scriptIndex);
118 return Result(static_cast<const void *>(i));
125 template<typename Key>
126 Result typeSearch(const QVector<QDeclarativeTypeModuleVersion> &modules, Key key)
128 QVector<QDeclarativeTypeModuleVersion>::const_iterator end = modules.constEnd();
129 for (QVector<QDeclarativeTypeModuleVersion>::const_iterator it = modules.constBegin(); it != end; ++it) {
130 if (QDeclarativeType *type = it->type(key))
137 QStringHash<Import> m_namedImports;
138 QMap<const Import *, QStringHash<Import> > m_namespacedImports;
139 QVector<QDeclarativeTypeModuleVersion> m_anonymousImports;
141 QDeclarativeEngine *engine;
144 QDeclarativeTypeNameCache::Result::Result()
145 : type(0), importNamespace(0), scriptIndex(-1)
149 QDeclarativeTypeNameCache::Result::Result(const void *importNamespace)
150 : type(0), importNamespace(importNamespace), scriptIndex(-1)
154 QDeclarativeTypeNameCache::Result::Result(QDeclarativeType *type)
155 : type(type), importNamespace(0), scriptIndex(-1)
159 QDeclarativeTypeNameCache::Result::Result(int scriptIndex)
160 : type(0), importNamespace(0), scriptIndex(scriptIndex)
164 QDeclarativeTypeNameCache::Result::Result(const Result &o)
165 : type(o.type), importNamespace(o.importNamespace), scriptIndex(o.scriptIndex)
169 bool QDeclarativeTypeNameCache::Result::isValid() const
171 return type || importNamespace || scriptIndex != -1;
174 QDeclarativeTypeNameCache::Import::Import()
175 : moduleApi(0), scriptIndex(-1)
179 bool QDeclarativeTypeNameCache::isEmpty() const
181 return m_namedImports.isEmpty() && m_anonymousImports.isEmpty();
186 #endif // QDECLARATIVETYPENAMECACHE_P_H