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& 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> value);
93 
94  ScopeMetadata operator()() const;
95 
96 private:
97  struct Private;
98  std::unique_ptr<Private> p;
99 };
100 
102 
103 } // namespace testing
104 
105 } // namespace scopes
106 
107 } // namespace unity
108 
109 
110 #endif
std::shared_ptr< Scope > ScopeProxy
Convenience type definition.
Definition: ScopeProxyFwd.h:35