Unity Scopes API
SearchMetadata.h
1 /*
2  * Copyright (C) 2014 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: Pawel Stolowski <pawel.stolowski@canonical.com>
17  */
18 
19 #pragma once
20 
21 #include <unity/scopes/QueryMetadata.h>
22 #include <unity/scopes/Location.h>
23 #include <unity/scopes/Variant.h>
24 #include <unity/util/DefinesPtrs.h>
25 
26 #include <set>
27 
28 namespace unity
29 {
30 
31 namespace scopes
32 {
33 
34 namespace internal
35 {
36 
37 class SearchMetadataImpl;
38 
39 }
40 
46 {
47 public:
49  UNITY_DEFINES_PTRS(SearchMetadata);
51 
57  SearchMetadata(std::string const& locale, std::string const& form_factor);
58 
65  SearchMetadata(int cardinality, std::string const& locale, std::string const& form_factor);
66 
70  //{@
71  SearchMetadata(SearchMetadata const& other);
73 
74  SearchMetadata& operator=(SearchMetadata const& other);
75  SearchMetadata& operator=(SearchMetadata&&);
77 
79  ~SearchMetadata();
81 
86  void set_cardinality(int cardinality);
87 
92  int cardinality() const;
93 
98  void set_location(Location const& location);
99 
105  Location location() const;
106 
111  bool has_location() const;
112 
118  void remove_location();
119 
124  void set_aggregated_keywords(std::set<std::string> const& aggregated_keywords);
125 
130  std::set<std::string> aggregated_keywords() const;
131 
136  bool is_aggregated() const;
137 
144  void set_hint(std::string const& key, Variant const& value);
145 
152  VariantMap hints() const;
153 
159  bool contains_hint(std::string const& key) const;
160 
170  Variant& operator[](std::string const& key);
171 
181  Variant const& operator[](std::string const& key) const;
182 
183 private:
184  SearchMetadata(internal::SearchMetadataImpl* impl);
185  friend class internal::SearchMetadataImpl;
186 };
187 
188 } // namespace scopes
189 
190 } // namespace unity
VariantMap hints() const
Get all hints.
Definition: SearchMetadata.cpp:117
std::string form_factor() const
Get the form factor string.
Definition: QueryMetadata.cpp:61
Location location() const
Get location.
Definition: SearchMetadata.cpp:82
bool is_aggregated() const
Check if this search request originated from an aggregator scope.
Definition: SearchMetadata.cpp:107
Simple variant class that can hold an integer, boolean, string, double, dictionary, array or null value.
Definition: Variant.h:57
void set_aggregated_keywords(std::set< std::string > const &aggregated_keywords)
Set the list of scope keywords used to initiate this search request.
Definition: SearchMetadata.cpp:97
std::string locale() const
Get the locale string.
Definition: QueryMetadata.cpp:56
std::set< std::string > aggregated_keywords() const
Get the list of scope keywords used to initiate this search request.
Definition: SearchMetadata.cpp:102
Metadata passed with search requests.
Definition: SearchMetadata.h:45
void set_location(Location const &location)
Set location.
Definition: SearchMetadata.cpp:77
SearchMetadata(std::string const &locale, std::string const &form_factor)
Create SearchMetadata with the given locale and form factor.
Definition: SearchMetadata.cpp:29
void set_hint(std::string const &key, Variant const &value)
Sets a hint.
Definition: SearchMetadata.cpp:112
void remove_location()
Remove location data entirely.
Definition: SearchMetadata.cpp:92
Top-level namespace for all things Unity-related.
Definition: Version.h:49
int cardinality() const
Get cardinality.
Definition: SearchMetadata.cpp:72
std::map< std::string, Variant > VariantMap
A dictionary of (string, Variant) pairs.
Definition: Variant.h:38
Definition: ActionMetadata.h:31
bool contains_hint(std::string const &key) const
Check if this SearchMetadata has a hint.
Definition: SearchMetadata.cpp:133
Base class for extra metadata passed to scopes as a part of a request.
Definition: QueryMetadata.h:41
void set_cardinality(int cardinality)
Set cardinality.
Definition: SearchMetadata.cpp:67
bool has_location() const
Does the SearchMetadata have a location.
Definition: SearchMetadata.cpp:87
Variant & operator[](std::string const &key)
Returns a reference to a hint.
Definition: SearchMetadata.cpp:122
Holds location attributes such as latitude, longitude, etc.
Definition: Location.h:39