From 6a514c8be60793d08a6caa3cdae53f7a91b9ac54 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 13 Mar 2014 14:37:22 +0100 Subject: [PATCH] Move ScopedSwap template out of pp-engine.cpp and into the utils lib. Change-Id: I9370da5f3159f6d8ad9ee9f8fe949f66eb235592 Reviewed-by: Nikolai Kosjar Reviewed-by: Orgad Shaneh --- src/libs/cplusplus/pp-engine.cpp | 26 ++----------- src/libs/utils/scopedswap.h | 67 ++++++++++++++++++++++++++++++++ src/libs/utils/utils-lib.pri | 3 +- src/libs/utils/utils.qbs | 1 + 4 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 src/libs/utils/scopedswap.h diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 4681ef65a9f..94fbd8496be 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -54,6 +54,8 @@ #include #include +#include + #include #include #include @@ -72,6 +74,8 @@ #include +using namespace Utils; + namespace { enum { MAX_TOKEN_EXPANSION_COUNT = 5000, @@ -80,28 +84,6 @@ enum { } namespace { -/// RAII object to save a value, and restore it when the scope is left. -template -class ScopedSwap -{ - _T oldValue; - _T &ref; - -public: - ScopedSwap(_T &var, _T newValue) - : oldValue(newValue) - , ref(var) - { - std::swap(ref, oldValue); - } - - ~ScopedSwap() - { - std::swap(ref, oldValue); - } -}; -typedef ScopedSwap ScopedBoolSwap; - static bool same(const char *a, const char *b, int size) { return strncmp(a, b, size) == 0; diff --git a/src/libs/utils/scopedswap.h b/src/libs/utils/scopedswap.h new file mode 100644 index 00000000000..08bf4969b34 --- /dev/null +++ b/src/libs/utils/scopedswap.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of Qt Creator. +** +** 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 Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +****************************************************************************/ + +#ifndef SCOPEDSWAP_H +#define SCOPEDSWAP_H + +#if !(__cplusplus > 199711L || __GXX_EXPERIMENTAL_CXX0X__ || _MSC_VER >= 1600 || defined( _LIBCPP_VERSION )) || \ + (defined(__GNUC_LIBSTD__) && ((__GNUC_LIBSTD__-0) * 100 + __GNUC_LIBSTD_MINOR__-0 <= 402)) +# include +#else // C++11 +# include +#endif + + +namespace Utils { +/// RAII object to save a value, and restore it when the scope is left. +template +class ScopedSwap +{ + T oldValue; + T &ref; + +public: + ScopedSwap(T &var, T newValue) + : oldValue(newValue) + , ref(var) + { + std::swap(ref, oldValue); + } + + ~ScopedSwap() + { + std::swap(ref, oldValue); + } +}; + +typedef ScopedSwap ScopedBoolSwap; + +} // Utils namespace + +#endif // SCOPEDSWAP_H diff --git a/src/libs/utils/utils-lib.pri b/src/libs/utils/utils-lib.pri index d79a4303ddc..c60a14f6df8 100644 --- a/src/libs/utils/utils-lib.pri +++ b/src/libs/utils/utils-lib.pri @@ -182,7 +182,8 @@ HEADERS += \ $$PWD/logging.h \ $$PWD/winutils.h \ $$PWD/itemviews.h \ - $$PWD/treeviewcombobox.h + $$PWD/treeviewcombobox.h \ + $$PWD/scopedswap.h FORMS += $$PWD/filewizardpage.ui \ $$PWD/projectintropage.ui \ diff --git a/src/libs/utils/utils.qbs b/src/libs/utils/utils.qbs index c80f13e6b7f..0f2a9d13c2f 100644 --- a/src/libs/utils/utils.qbs +++ b/src/libs/utils/utils.qbs @@ -152,6 +152,7 @@ QtcLibrary { "savedaction.h", "savefile.cpp", "savefile.h", + "scopedswap.h", "settingsselector.cpp", "settingsselector.h", "settingsutils.h",