Unity Scopes API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 Lesser GNU 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 #ifndef UNITY_SCOPES_TESTING_SCOPEMETADATA_BUILDER_H
20 #define UNITY_SCOPES_TESTING_SCOPEMETADATA_BUILDER_H
21 
22 #include <unity/scopes/ScopeMetadata.h>
23 
24 namespace unity
25 {
26 
27 namespace scopes
28 {
29 
30 namespace testing
31 {
32 
34 
35 class ScopeMetadataBuilder
36 {
37 public:
38  template<typename T>
39  class Optional
40  {
41  public:
42  inline Optional() = default;
43  inline Optional(const T& t) : value(new T{t})
44  {
45  }
46 
47  inline operator bool() const
48  {
49  return value.get() != nullptr;
50  }
51 
52  inline Optional<T>& operator=(const T& rhs)
53  {
54  if (*this)
55  *value = rhs;
56  else
57  value.reset(new T{rhs});
58 
59  return *this;
60  }
61 
62  inline Optional<T>& operator=(const Optional<T>& rhs)
63  {
64  if (rhs)
65  *this = *rhs;
66  else
67  value.reset();
68 
69  return *this;
70  }
71 
72  inline const T& operator*() const
73  {
74  return *value;
75  }
76 
77  private:
78  std::unique_ptr<T> value;
79  };
80 
81  ScopeMetadataBuilder();
82  ~ScopeMetadataBuilder();
83 
84  ScopeMetadataBuilder& scope_id(std::string const& value);
85  ScopeMetadataBuilder& proxy(ScopeProxy const& value);
86  ScopeMetadataBuilder& display_name(std::string const& value);
87  ScopeMetadataBuilder& description(std::string const& value);
88  ScopeMetadataBuilder& author(std::string const& value);
89  ScopeMetadataBuilder& art(Optional<std::string> const& value);
90  ScopeMetadataBuilder& icon(Optional<std::string> const& value);
91  ScopeMetadataBuilder& search_hint(Optional<std::string> const& value);
92  ScopeMetadataBuilder& hot_key(Optional<std::string> const& value);
93  ScopeMetadataBuilder& invisible(Optional<bool> const& value);
94  ScopeMetadataBuilder& appearance_attributes(Optional<VariantMap> const& value);
95  ScopeMetadataBuilder& scope_directory(Optional<std::string> const& value);
96  ScopeMetadataBuilder& results_ttl_type(Optional<ScopeMetadata::ResultsTtlType> const& value);
97 
98  ScopeMetadata operator()() const;
99 
100 private:
101  struct Private;
102  std::unique_ptr<Private> p;
103 };
104 
106 
107 } // namespace testing
108 
109 } // namespace scopes
110 
111 } // namespace unity
112 
113 
114 #endif
std::shared_ptr< Scope > ScopeProxy
Convenience type definition.
Definition: ScopeProxyFwd.h:35
Definition: ScopeBase.h:73
Top-level namespace for all things Unity-related.
Definition: Version.h:50