projectpart.cpp 4.16 KB
Newer Older
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
/****************************************************************************
**
** 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 Digia.  For licensing terms and
** conditions see http://www.qt.io/licensing.  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, 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.
**
****************************************************************************/

#include "projectpart.h"

Marco Bubke's avatar
Marco Bubke committed
33
#include <projectpartcontainer.h>
34
35
36

#include <utf8stringvector.h>

Marco Bubke's avatar
Marco Bubke committed
37
#include <cstring>
38

39
namespace ClangBackEnd {
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

class ProjectPartData {
public:
    ProjectPartData(const Utf8String &projectPartId);
    ~ProjectPartData();

public:
    void clearArguments();

public:
    time_point lastChangeTimePoint;
    std::vector<const char*> arguments;
    Utf8String projectPartId;
};

void ProjectPartData::clearArguments()
{
    for (auto argument : arguments)
        delete [] argument;

    arguments.clear();
}

ProjectPartData::ProjectPartData(const Utf8String &projectPartId)
    : lastChangeTimePoint(std::chrono::steady_clock::now()),
      projectPartId(projectPartId)
{
}

ProjectPartData::~ProjectPartData()
{
    clearArguments();
}

ProjectPart::ProjectPart(const Utf8String &projectPartId)
    : d(std::make_shared<ProjectPartData>(projectPartId))
{
}

ProjectPart::ProjectPart(const ProjectPartContainer &projectContainer)
    : d(std::make_shared<ProjectPartData>(projectContainer.projectPartId()))
{
    setArguments(projectContainer.arguments());
}

ProjectPart::~ProjectPart() = default;
ProjectPart::ProjectPart(const ProjectPart &) = default;
87
ProjectPart &ProjectPart::operator=(const ProjectPart &) = default;
88
89
90
91
92
93

ProjectPart::ProjectPart(ProjectPart &&other)
    : d(std::move(other.d))
{
}

94
ProjectPart &ProjectPart::operator=(ProjectPart &&other)
95
96
97
98
99
100
{
    d = std::move(other.d);

    return *this;
}

101
void ProjectPart::clear()
102
103
{
    d->projectPartId.clear();
104
105
    d->clearArguments();
    updateLastChangeTimePoint();
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
}

const Utf8String &ProjectPart::projectPartId() const
{
    return d->projectPartId;
}

static const char *strdup(const Utf8String &utf8String)
{
    char *cxArgument = new char[utf8String.byteSize() + 1];
    std::memcpy(cxArgument, utf8String.constData(), utf8String.byteSize() + 1);

    return cxArgument;
}

void ProjectPart::setArguments(const Utf8StringVector &arguments)
{
    d->clearArguments();
    d->arguments.resize(arguments.size());
    std::transform(arguments.cbegin(), arguments.cend(), d->arguments.begin(), strdup);
    updateLastChangeTimePoint();
}

const std::vector<const char*> &ProjectPart::arguments() const
{
    return d->arguments;
}

int ProjectPart::argumentCount() const
{
    return d->arguments.size();
}

const char * const *ProjectPart::cxArguments() const
{
    return arguments().data();
}

const time_point &ProjectPart::lastChangeTimePoint() const
{
    return d->lastChangeTimePoint;
}

void ProjectPart::updateLastChangeTimePoint()
{
    d->lastChangeTimePoint = std::chrono::steady_clock::now();
}

154
bool operator==(const ProjectPart &first, const ProjectPart &second)
155
156
157
158
{
    return first.projectPartId() == second.projectPartId();
}

159
} // namespace ClangBackEnd
160