Move ScopedSwap template out of pp-engine.cpp and into the utils lib.

Change-Id: I9370da5f3159f6d8ad9ee9f8fe949f66eb235592
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Erik Verbruggen
2014-03-13 14:37:22 +01:00
parent eee94667e6
commit 6a514c8be6
4 changed files with 74 additions and 23 deletions

View File

@@ -54,6 +54,8 @@
#include <cplusplus/Token.h>
#include <cplusplus/Literals.h>
#include <utils/scopedswap.h>
#include <QDebug>
#include <QList>
#include <QDate>
@@ -72,6 +74,8 @@
#include <deque>
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<typename _T>
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<bool> ScopedBoolSwap;
static bool same(const char *a, const char *b, int size)
{
return strncmp(a, b, size) == 0;