aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/libsmart/stdoptionaltestbench.cpp
blob: 69100720cbcf2d0e03b4712e228d5ea6e603f0bf (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "stdoptionaltestbench.h"

#include <iostream>

std::ostream &operator<<(std::ostream &str, const Integer &i)
{
    str << i.value();
    return str;
}

template <class T>
std::ostream &operator<<(std::ostream &str, const std::optional<T> &o)
{
    if (o.has_value())
        str << o.value();
    else
        str << "nullopt";
    return str;
}

StdOptionalTestBench::StdOptionalTestBench() = default;

std::optional<int> StdOptionalTestBench::optionalInt() const
{
    return m_optionalInt;
}

void StdOptionalTestBench::setOptionalInt(const std::optional<int> &i)
{
    std::cout << __FUNCTION__ << ' ' << i << '\n';
    m_optionalInt = i;
}

void StdOptionalTestBench::setOptionalIntValue(int i)
{
    std::cout << __FUNCTION__ << ' ' << i << '\n';
    m_optionalInt.emplace(i);
}

std::optional<Integer> StdOptionalTestBench::optionalInteger() const
{
    return m_optionalInteger;
}

void StdOptionalTestBench::setOptionalInteger(const std::optional<Integer> &s)
{
    std::cout << __FUNCTION__ << ' ' << s << '\n';
    m_optionalInteger = s;
}

void StdOptionalTestBench::setOptionalIntegerValue(Integer &s)
{
    std::cout << __FUNCTION__ << ' ' << s << '\n';
    m_optionalInteger.emplace(s);
}