Clang: Fix operator <

It is actually not used but have to be implemented because
QMetaType::registerComparators expect == and <.

Change-Id: Ia93e2e7bd856d1962b683482e42ace4136d9bf34
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
This commit is contained in:
Marco Bubke
2015-06-15 13:47:58 +02:00
parent 9f2ed3b9da
commit 2fc604e699
6 changed files with 78 additions and 5 deletions

View File

@@ -36,6 +36,10 @@
#include <ostream> #include <ostream>
#include <algorithm>
#include <container_common.h>
namespace CodeModelBackEnd { namespace CodeModelBackEnd {
RegisterProjectPartsForCodeCompletionCommand::RegisterProjectPartsForCodeCompletionCommand(const QVector<ProjectPartContainer> &projectContainers) RegisterProjectPartsForCodeCompletionCommand::RegisterProjectPartsForCodeCompletionCommand(const QVector<ProjectPartContainer> &projectContainers)
@@ -69,7 +73,7 @@ bool operator==(const RegisterProjectPartsForCodeCompletionCommand &first, const
bool operator<(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second) bool operator<(const RegisterProjectPartsForCodeCompletionCommand &first, const RegisterProjectPartsForCodeCompletionCommand &second)
{ {
return first.projectContainers_ < second.projectContainers_; return compareContainer(first.projectContainers_, second.projectContainers_);
} }
QDebug operator<<(QDebug debug, const RegisterProjectPartsForCodeCompletionCommand &command) QDebug operator<<(QDebug debug, const RegisterProjectPartsForCodeCompletionCommand &command)

View File

@@ -36,6 +36,8 @@
#include <ostream> #include <ostream>
#include <container_common.h>
namespace CodeModelBackEnd { namespace CodeModelBackEnd {
RegisterTranslationUnitForCodeCompletionCommand::RegisterTranslationUnitForCodeCompletionCommand(const QVector<FileContainer> &fileContainers) RegisterTranslationUnitForCodeCompletionCommand::RegisterTranslationUnitForCodeCompletionCommand(const QVector<FileContainer> &fileContainers)
@@ -69,7 +71,7 @@ bool operator==(const RegisterTranslationUnitForCodeCompletionCommand &first, co
bool operator<(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second) bool operator<(const RegisterTranslationUnitForCodeCompletionCommand &first, const RegisterTranslationUnitForCodeCompletionCommand &second)
{ {
return first.fileContainers_ < second.fileContainers_; return compareContainer(first.fileContainers_, second.fileContainers_);
} }
QDebug operator<<(QDebug debug, const RegisterTranslationUnitForCodeCompletionCommand &command) QDebug operator<<(QDebug debug, const RegisterTranslationUnitForCodeCompletionCommand &command)

View File

@@ -36,6 +36,8 @@
#include <ostream> #include <ostream>
#include <container_common.h>
namespace CodeModelBackEnd { namespace CodeModelBackEnd {
@@ -70,7 +72,7 @@ bool operator==(const UnregisterProjectPartsForCodeCompletionCommand &first, con
bool operator<(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second) bool operator<(const UnregisterProjectPartsForCodeCompletionCommand &first, const UnregisterProjectPartsForCodeCompletionCommand &second)
{ {
return first.filePaths_ < second.filePaths_; return compareContainer(first.filePaths_, second.filePaths_);
} }
QDebug operator<<(QDebug debug, const UnregisterProjectPartsForCodeCompletionCommand &command) QDebug operator<<(QDebug debug, const UnregisterProjectPartsForCodeCompletionCommand &command)

View File

@@ -38,6 +38,8 @@
#include <QDataStream> #include <QDataStream>
#include <container_common.h>
namespace CodeModelBackEnd { namespace CodeModelBackEnd {
@@ -72,7 +74,7 @@ bool operator==(const UnregisterTranslationUnitsForCodeCompletionCommand &first,
bool operator<(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second) bool operator<(const UnregisterTranslationUnitsForCodeCompletionCommand &first, const UnregisterTranslationUnitsForCodeCompletionCommand &second)
{ {
return first.fileContainers_ < second.fileContainers_; return compareContainer(first.fileContainers_, second.fileContainers_);
} }
QDebug operator<<(QDebug debug, const UnregisterTranslationUnitsForCodeCompletionCommand &command) QDebug operator<<(QDebug debug, const UnregisterTranslationUnitsForCodeCompletionCommand &command)

View File

@@ -67,6 +67,7 @@ HEADERS += $$PWD/codemodelbackendipc_global.h \
$$PWD/translationunitdoesnotexistcommand.h \ $$PWD/translationunitdoesnotexistcommand.h \
$$PWD/codecompletionchunk.h \ $$PWD/codecompletionchunk.h \
$$PWD/projectpartcontainer.h \ $$PWD/projectpartcontainer.h \
$$PWD/projectpartsdonotexistcommand.h $$PWD/projectpartsdonotexistcommand.h \
$$PWD/container_common.h
contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols contains(QT_CONFIG, reduce_exports):CONFIG += hide_symbols

View File

@@ -0,0 +1,62 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** 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 The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://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 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef CONTAINER_COMMON_H
#define CONTAINER_COMMON_H
namespace CodeModelBackEnd {
template <typename Container>
bool compareContainer(const Container &first, const Container &second)
{
if (first.size() != second.size())
return first.size() < second.size();
Container firstCopy = first;
Container secondCopy = second;
std::sort(firstCopy.begin(), firstCopy.end());
std::sort(secondCopy.begin(), secondCopy.end());
auto isProjectPartContainerSmaller = [] (decltype(*first.cbegin()) &firstElement,
decltype(*second.cbegin()) &secondElement) {
return firstElement < secondElement;
};
return std::equal(firstCopy.cbegin(),
firstCopy.cend(),
secondCopy.cbegin(),
isProjectPartContainerSmaller);
}
}
#endif // CONTAINER_COMMON_H