olp-cpp-sdk  1.22.0
TileRequest.h
1 /*
2  * Copyright (C) 2020 HERE Europe B.V.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  * License-Filename: LICENSE
18  */
19 
20 #pragma once
21 
22 #include <sstream>
23 #include <string>
24 #include <utility>
25 
26 #include <olp/core/geo/tiling/TileKey.h>
27 #include <olp/core/thread/TaskScheduler.h>
28 #include <olp/dataservice/read/FetchOptions.h>
29 #include <boost/optional.hpp>
30 
31 namespace olp {
32 namespace dataservice {
33 namespace read {
34 
42 class DATASERVICE_READ_API TileRequest final {
43  public:
54  inline const boost::optional<std::string>& GetBillingTag() const {
55  return billing_tag_;
56  }
57 
67  inline TileRequest& WithBillingTag(boost::optional<std::string> tag) {
68  billing_tag_ = std::move(tag);
69  return *this;
70  }
71 
82  inline TileRequest& WithBillingTag(std::string tag) {
83  billing_tag_ = std::move(tag);
84  return *this;
85  }
86 
94  inline TileRequest& WithTileKey(geo::TileKey tile_key) {
95  tile_key_ = std::move(tile_key);
96  return *this;
97  }
98 
104  inline const geo::TileKey& GetTileKey() const { return tile_key_; }
105 
114  inline FetchOptions GetFetchOption() const { return fetch_option_; }
115 
126  inline TileRequest& WithFetchOption(FetchOptions fetch_option) {
127  fetch_option_ = fetch_option;
128  return *this;
129  }
130 
138  inline uint32_t GetPriority() const { return priority_; }
139 
147  inline TileRequest& WithPriority(uint32_t priority) {
148  priority_ = priority;
149  return *this;
150  }
151 
159  inline std::string CreateKey(const std::string& layer_id) const {
160  std::stringstream out;
161  out << layer_id << "[" << GetTileKey().ToHereTile() << "]";
162  if (GetBillingTag()) {
163  out << "$" << GetBillingTag().get();
164  }
165  out << "^" << GetFetchOption();
166  return out.str();
167  }
168 
169  private:
170  boost::optional<std::string> billing_tag_;
171  geo::TileKey tile_key_;
172  FetchOptions fetch_option_{OnlineIfNotFound};
173  uint32_t priority_{thread::NORMAL};
174 };
175 
176 } // namespace read
177 } // namespace dataservice
178 } // namespace olp
Encapsulates the fields required to request tile for the given key.
Definition: TileRequest.h:42
TileRequest & WithBillingTag(boost::optional< std::string > tag)
Sets the billing tag for the request.
Definition: TileRequest.h:67
TileRequest & WithBillingTag(std::string tag)
Sets the billing tag for the request.
Definition: TileRequest.h:82
TileRequest & WithPriority(uint32_t priority)
Sets the priority of the request.
Definition: TileRequest.h:147
TileRequest & WithTileKey(geo::TileKey tile_key)
Sets the tile key for the request.
Definition: TileRequest.h:94
const geo::TileKey & GetTileKey() const
Gets a tile key value.
Definition: TileRequest.h:104
std::string CreateKey(const std::string &layer_id) const
Creates a readable format for the request.
Definition: TileRequest.h:159
const boost::optional< std::string > & GetBillingTag() const
Gets the billing tag to group billing records together.
Definition: TileRequest.h:54
FetchOptions GetFetchOption() const
Gets the fetch option that controls how requests are handled.
Definition: TileRequest.h:114
uint32_t GetPriority() const
Gets the request priority.
Definition: TileRequest.h:138
TileRequest & WithFetchOption(FetchOptions fetch_option)
Sets the fetch option that you can use to set the source from which data should be fetched.
Definition: TileRequest.h:126
Addresses a tile in a quadtree.
Definition: TileKey.h:63
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24