summaryrefslogtreecommitdiff
path: root/src/plugins/cppcheck/cppchecktextmarkmanager.cpp
blob: 04bfc82eb457e78b56731b40099406e758206db9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (C) 2018 Sergey Morozov
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "cppchecktextmarkmanager.h"

#include "cppcheckdiagnostic.h"
#include "cppchecktextmark.h"

#include <utils/algorithm.h>

namespace Cppcheck::Internal {

CppcheckTextMarkManager::CppcheckTextMarkManager() = default;

CppcheckTextMarkManager::~CppcheckTextMarkManager() = default;

void CppcheckTextMarkManager::add(const Diagnostic &diagnostic)
{
    std::vector<MarkPtr> &fileMarks = m_marks[diagnostic.fileName];
    if (Utils::contains(fileMarks, [diagnostic](const MarkPtr &mark) {return *mark == diagnostic;}))
        return;

    fileMarks.push_back(std::make_unique<CppcheckTextMark>(diagnostic));
}

void CppcheckTextMarkManager::clearFiles(const Utils::FilePaths &files)
{
    if (m_marks.empty())
        return;

    if (!files.empty()) {
        for (const Utils::FilePath &file : files)
            m_marks.erase(file);
    } else {
        m_marks.clear();
    }
}

} // Cppcheck::Internal