aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/result.cpp
blob: 222c70bdf80aa75b89e84d7dc15b062b46a48405 (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
40
41
42
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "result.h"

#include "utilstr.h"

namespace Utils {

const Result Result::Ok;

Result::Result(bool success, const QString &errorString)
{
    if (!success)
        m_error = errorString;
}

Result::Result(const expected_str<void> &res)
{
    if (!res)
        m_error = res.error();
}

Result::~Result() = default;

Result Result::Error(const QString &errorString)
{
    return Result(errorString);
}

Result Result::Error(SpecialError specialError)
{
    switch (specialError) {
    case Unimplemented:
        return Error(Tr::tr("Not implemented"));
    case Assert:
        return Error(Tr::tr("Internal error"));
    }
    return Error(Tr::tr("Internal error"));
}

} // Utils