diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2016-02-11 08:36:45 +0100 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2016-02-19 16:53:44 +0000 |
commit | 29c63530e02fd575b0943e2b052a2876f1a17f75 (patch) | |
tree | b062e4f7c3de01c57d300eb44fc372a13033d67a /src/render/backend/stringtoint.cpp | |
parent | 53103c7806d4eb1b62ef35fff33118c17d47adb5 (diff) |
Add StringToInt class
Change-Id: If2b559bbcf22116c0b8373c4bb63363b4adb478d
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render/backend/stringtoint.cpp')
-rw-r--r-- | src/render/backend/stringtoint.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/render/backend/stringtoint.cpp b/src/render/backend/stringtoint.cpp new file mode 100644 index 000000000..e8753c1bd --- /dev/null +++ b/src/render/backend/stringtoint.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "stringtoint_p.h" +#include <QMutex> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { + +namespace Render { + +namespace { + +QMutex mutex; + +} // anonymous + +QVector<QString> StringToInt::m_stringsArray = QVector<QString>(); + +int StringToInt::lookupId(const QString &str) +{ + QMutexLocker lock(&mutex); + const int idx = StringToInt::m_stringsArray.indexOf(str); + if (Q_UNLIKELY(idx < 0)) { + StringToInt::m_stringsArray.push_back(str); + return StringToInt::m_stringsArray.size() - 1; + } + return idx; +} + +QString StringToInt::lookupString(int idx) +{ + QMutexLocker lock(&mutex); + if (Q_LIKELY(StringToInt::m_stringsArray.size() > idx)) + return StringToInt::m_stringsArray.at(idx); + return QString(); +} + +} // Render + +} // Qt3DRender + +QT_END_NAMESPACE |