~mardy/unity-scopes-api/clientid-1554040

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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2013 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
 */

#pragma once

#include <unity/scopes/ScopeMetadata.h>

namespace unity
{

namespace scopes
{

namespace testing
{

/// @cond

class ScopeMetadataBuilder
{
public:
    template<typename T>
    class Optional
    {
    public:
        inline Optional() = default;
        inline Optional(const T& t) : value(new T{t})
        {
        }

        inline operator bool() const
        {
            return value.get() != nullptr;
        }

        inline Optional<T>& operator=(const T& rhs)
        {
            if (*this)
                *value = rhs;
            else
                value.reset(new T{rhs});

            return *this;
        }

        inline Optional<T>& operator=(const Optional<T>& rhs)
        {
            if (rhs)
                *this = *rhs;
            else
                value.reset();

            return *this;
        }

        inline const T& operator*() const
        {
            return *value;
        }

    private:
        std::unique_ptr<T> value;
    };

    ScopeMetadataBuilder();
    ~ScopeMetadataBuilder();

    ScopeMetadataBuilder& scope_id(std::string const& value);
    ScopeMetadataBuilder& proxy(ScopeProxy const& value);
    ScopeMetadataBuilder& display_name(std::string const& value);
    ScopeMetadataBuilder& description(std::string const& value);
    ScopeMetadataBuilder& author(std::string const& value);
    ScopeMetadataBuilder& art(Optional<std::string> const& value);
    ScopeMetadataBuilder& icon(Optional<std::string> const& value);
    ScopeMetadataBuilder& search_hint(Optional<std::string> const& value);
    ScopeMetadataBuilder& hot_key(Optional<std::string> const& value);
    ScopeMetadataBuilder& invisible(Optional<bool> const& value);
    ScopeMetadataBuilder& appearance_attributes(Optional<VariantMap> const& value);
    ScopeMetadataBuilder& scope_directory(Optional<std::string> const& value);
    ScopeMetadataBuilder& results_ttl_type(Optional<ScopeMetadata::ResultsTtlType> const& value);
    ScopeMetadataBuilder& settings_definitions(Optional<VariantArray> const& value);
    ScopeMetadataBuilder& location_data_needed(Optional<bool> const& value);
    ScopeMetadataBuilder& child_scope_ids(Optional<std::vector<std::string>> const& value);
    ScopeMetadataBuilder& version(Optional<int> const& value);
    ScopeMetadataBuilder& keywords(Optional<std::set<std::string>> const& value);
    ScopeMetadataBuilder& is_aggregator(Optional<bool> const& value);

    ScopeMetadata operator()() const;

private:
    struct Private;
    std::unique_ptr<Private> p;
};

/// @endcond

} // namespace testing

} // namespace scopes

} // namespace unity