Unity Scopes API
ScopeMetadataBuilder.h
1 /*
2  * Copyright (C) 2013 Canonical Ltd
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License version 3 as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #pragma once
20 
21 #include <unity/scopes/ScopeMetadata.h>
22 
23 namespace unity
24 {
25 
26 namespace scopes
27 {
28 
29 namespace testing
30 {
31 
33 
34 class ScopeMetadataBuilder
35 {
36 public:
37  template<typename T>
38  class Optional
39  {
40  public:
41  inline Optional() = default;
42  inline Optional(const T& t) : value(new T{t})
43  {
44  }
45 
46  inline operator bool() const
47  {
48  return value.get() != nullptr;
49  }
50 
51  inline Optional<T>& operator=(const T& rhs)
52  {
53  if (*this)
54  *value = rhs;
55  else
56  value.reset(new T{rhs});
57 
58  return *this;
59  }
60 
61  inline Optional<T>& operator=(const Optional<T>& rhs)
62  {
63  if (rhs)
64  *this = *rhs;
65  else
66  value.reset();
67 
68  return *this;
69  }
70 
71  inline const T& operator*() const
72  {
73  return *value;
74  }
75 
76  private:
77  std::unique_ptr<T> value;
78  };
79 
80  ScopeMetadataBuilder();
81  ~ScopeMetadataBuilder();
82 
83  ScopeMetadataBuilder& scope_id(std::string const& value);
84  ScopeMetadataBuilder& proxy(ScopeProxy const& value);
85  ScopeMetadataBuilder& display_name(std::string const& value);
86  ScopeMetadataBuilder& description(std::string const& value);
87  ScopeMetadataBuilder& author(std::string const& value);
88  ScopeMetadataBuilder& art(Optional<std::string> const& value);
89  ScopeMetadataBuilder& icon(Optional<std::string> const& value);
90  ScopeMetadataBuilder& search_hint(Optional<std::string> const& value);
91  ScopeMetadataBuilder& hot_key(Optional<std::string> const& value);
92  ScopeMetadataBuilder& invisible(Optional<bool> const& value);
93  ScopeMetadataBuilder& appearance_attributes(Optional<VariantMap> const& value);
94  ScopeMetadataBuilder& scope_directory(Optional<std::string> const& value);
95  ScopeMetadataBuilder& results_ttl_type(Optional<ScopeMetadata::ResultsTtlType> const& value);
96  ScopeMetadataBuilder& settings_definitions(Optional<VariantArray> const& value);
97  ScopeMetadataBuilder& location_data_needed(Optional<bool> const& value);
98  ScopeMetadataBuilder& child_scope_ids(Optional<std::vector<std::string>> const& value);
99  ScopeMetadataBuilder& version(Optional<int> const& value);
100  ScopeMetadataBuilder& keywords(Optional<std::set<std::string>> const& value);
101  ScopeMetadataBuilder& is_aggregator(Optional<bool> const& value);
102 
103  ScopeMetadata operator()() const;
104 
105 private:
106  struct Private;
107  std::unique_ptr<Private> p;
108 };
109 
111 
112 } // namespace testing
113 
114 } // namespace scopes
115 
116 } // namespace unity
std::shared_ptr< Scope > ScopeProxy
Convenience type definition.
Definition: ScopeProxyFwd.h:34
Definition: OnlineAccountClient.h:39
Top-level namespace for all things Unity-related.
Definition: Version.h:49