olp-cpp-sdk  1.22.0
Index.h
1 /*
2  * Copyright (C) 2019-2023 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 <map>
23 #include <memory>
24 #include <string>
25 #include <utility>
26 
27 #include <boost/optional.hpp>
28 
29 #include <olp/dataservice/write/DataServiceWriteApi.h>
30 
31 namespace olp {
32 namespace dataservice {
33 namespace write {
34 namespace model {
35 
36 typedef std::string IndexName;
37 
39 enum class DATASERVICE_WRITE_API IndexType {
41  String,
42 
44  Int,
45 
47  Bool,
48 
54  Heretile,
55 
62  TimeWindow,
63 
65  Unsupported
66 };
67 
69 class DATASERVICE_WRITE_API IndexValue {
70  public:
76  explicit IndexValue(IndexType type) : indexType_(type) {}
77 
79  IndexValue(const IndexValue&) = default;
80 
82  IndexValue(IndexValue&&) = default;
83 
86 
88  IndexValue& operator=(const IndexValue&) = default;
89 
91  virtual ~IndexValue() = default;
92 
98  IndexType getIndexType() const { return indexType_; }
99 
100  private:
101  IndexType indexType_{IndexType::Unsupported};
102 };
103 
105 class DATASERVICE_WRITE_API UnsupportedIndexValue final : public IndexValue {
106  public:
112  explicit UnsupportedIndexValue(IndexType type) : IndexValue(type) {}
113 };
114 
116 class DATASERVICE_WRITE_API BooleanIndexValue final : public IndexValue {
117  bool booleanValue_{false};
118 
119  public:
126  BooleanIndexValue(bool booleanValue, IndexType type) : IndexValue(type) {
127  booleanValue_ = std::move(booleanValue);
128  }
129 
135  const bool& GetValue() const { return booleanValue_; }
136 
142  bool& GetMutableValue() { return booleanValue_; }
143 
149  void SetValue(const bool& value) { this->booleanValue_ = value; }
150 };
151 
153 class DATASERVICE_WRITE_API IntIndexValue final : public IndexValue {
154  int64_t intValue_{0};
155 
156  public:
163  IntIndexValue(int64_t intValue, IndexType type) : IndexValue(type) {
164  intValue_ = std::move(intValue);
165  }
166 
172  const int64_t& GetValue() const { return intValue_; }
173 
179  int64_t& GetMutableValue() { return intValue_; }
180 
186  void SetValue(const int64_t& value) { this->intValue_ = value; }
187 };
188 
190 class DATASERVICE_WRITE_API StringIndexValue final : public IndexValue {
191  std::string stringValue_;
192 
193  public:
200  StringIndexValue(std::string stringValue, IndexType type)
201  : IndexValue(type), stringValue_{std::move(stringValue)} {}
202 
208  std::string GetValue() const { return stringValue_; }
209 
215  std::string& GetMutableValue() { return stringValue_; }
216 
222  void SetValue(const std::string& value) { this->stringValue_ = value; }
223 };
224 
226 class DATASERVICE_WRITE_API TimeWindowIndexValue final : public IndexValue {
227  int64_t timeWindowValue_{0};
228 
229  public:
236  TimeWindowIndexValue(int64_t timeWindowValue, IndexType type)
237  : IndexValue(type), timeWindowValue_{std::move(timeWindowValue)} {}
238 
244  const int64_t& GetValue() const { return timeWindowValue_; }
245 
252  int64_t& GetMutableValue() { return timeWindowValue_; }
253 
259  void SetValue(const int64_t& value) { this->timeWindowValue_ = value; }
260 };
261 
263 class DATASERVICE_WRITE_API HereTileIndexValue final : public IndexValue {
264  int64_t hereTileValue_{0};
265 
266  public:
273  HereTileIndexValue(int64_t hereTileValue, IndexType type)
274  : IndexValue(type), hereTileValue_{std::move(hereTileValue)} {}
275 
281  const int64_t& GetValue() const { return hereTileValue_; }
282 
289  int64_t& GetMutableValue() { return hereTileValue_; }
290 
296  void SetValue(const int64_t& value) { this->hereTileValue_ = value; }
297 };
298 
300 class DATASERVICE_WRITE_API EmptyIndexValue final : public IndexValue {
301  public:
307  explicit EmptyIndexValue(IndexType type) : IndexValue(type) {}
308 };
309 
311 class DATASERVICE_WRITE_API Index final {
312  public:
314  Index() = default;
315 
322  Index(std::string uuid,
323  std::map<IndexName, std::shared_ptr<IndexValue>> indexFields)
324  : id_(std::move(uuid)), indexFields_(std::move(indexFields)) {}
325 
326  private:
327  boost::optional<std::string> checksum_;
328  boost::optional<std::map<std::string, std::string>> metadata_;
329  boost::optional<int64_t> size_;
330  std::string id_;
331  std::map<IndexName, std::shared_ptr<IndexValue>> indexFields_;
332 
333  public:
339  const boost::optional<std::string>& GetCheckSum() const { return checksum_; }
340 
346  boost::optional<std::string>& GetMutableCheckSum() { return checksum_; }
347 
353  void SetCheckSum(const std::string& value) { this->checksum_ = value; }
354 
360  const boost::optional<std::map<std::string, std::string>>& GetMetadata()
361  const {
362  return metadata_;
363  }
364 
370  boost::optional<std::map<std::string, std::string>>& GetMutableMetadata() {
371  return metadata_;
372  }
373 
379  void SetMetadata(const std::map<std::string, std::string>& value) {
380  this->metadata_ = value;
381  }
382 
388  const std::string& GetId() const { return id_; }
389 
395  std::string& GetMutableId() { return id_; }
396 
402  void SetId(const std::string& value) { this->id_ = value; }
403 
409  const std::map<IndexName, std::shared_ptr<IndexValue>>& GetIndexFields()
410  const {
411  return indexFields_;
412  }
413 
419  std::map<IndexName, std::shared_ptr<IndexValue>>& GetMutableIndexFields() {
420  return indexFields_;
421  }
422 
429  const std::map<IndexName, std::shared_ptr<IndexValue>>& value) {
430  this->indexFields_ = value;
431  }
432 
438  const boost::optional<int64_t>& GetSize() const { return size_; }
439 
445  boost::optional<int64_t>& GetMutableSize() { return size_; }
446 
452  void SetSize(const int64_t& value) { this->size_ = value; }
453 };
454 
455 } // namespace model
456 } // namespace write
457 } // namespace dataservice
458 } // namespace olp
Represents the index layer of the boolean type.
Definition: Index.h:116
bool & GetMutableValue()
Gets a mutable reference to the boolean value of the index layer.
Definition: Index.h:142
BooleanIndexValue(bool booleanValue, IndexType type)
Creates the BooleanIndexValue instance.
Definition: Index.h:126
void SetValue(const bool &value)
Sets the boolean value.
Definition: Index.h:149
const bool & GetValue() const
Gets the boolean value of the index layer.
Definition: Index.h:135
Represents the index layer with an empty index value.
Definition: Index.h:300
EmptyIndexValue(IndexType type)
Creates the EmptyIndexValue instance.
Definition: Index.h:307
Represents the index layer of the HERE tile type.
Definition: Index.h:263
HereTileIndexValue(int64_t hereTileValue, IndexType type)
Creates the HereTileIndexValue instance.
Definition: Index.h:273
void SetValue(const int64_t &value)
Sets the HERE tile value.
Definition: Index.h:296
int64_t & GetMutableValue()
Gets a mutable reference to the HERE tile value of the index layer.
Definition: Index.h:289
const int64_t & GetValue() const
Gets the HERE tile value of the index layer.
Definition: Index.h:281
Represents values supported by the HERE platform index layer.
Definition: Index.h:69
IndexValue & operator=(IndexValue &&)=default
A default move assignment operator.
IndexValue(const IndexValue &)=default
A default copy constructor.
IndexValue(IndexType type)
Creates the IndexValue instance.
Definition: Index.h:76
IndexValue(IndexValue &&)=default
A default move constructor.
IndexType getIndexType() const
Gets the index value type.
Definition: Index.h:98
virtual ~IndexValue()=default
A default virtual destructor.
IndexValue & operator=(const IndexValue &)=default
A default copy assignment operator.
Represents the index layer.
Definition: Index.h:311
void SetIndexFields(const std::map< IndexName, std::shared_ptr< IndexValue >> &value)
Sets the index value type.
Definition: Index.h:428
void SetId(const std::string &value)
Sets the index layer ID.
Definition: Index.h:402
boost::optional< std::map< std::string, std::string > > & GetMutableMetadata()
Gets a mutable reference to the metadata of the index layer.
Definition: Index.h:370
boost::optional< int64_t > & GetMutableSize()
Gets a mutable reference to the size of the index layer.
Definition: Index.h:445
const boost::optional< int64_t > & GetSize() const
Gets the size of the index layer.
Definition: Index.h:438
Index()=default
A default constructor.
void SetCheckSum(const std::string &value)
Sets the checksum.
Definition: Index.h:353
const std::string & GetId() const
Gets the index layer ID.
Definition: Index.h:388
std::map< IndexName, std::shared_ptr< IndexValue > > & GetMutableIndexFields()
Gets a mutable reference to the index value type.
Definition: Index.h:419
boost::optional< std::string > & GetMutableCheckSum()
Gets a mutable reference to the checksum of the index layer.
Definition: Index.h:346
const std::map< IndexName, std::shared_ptr< IndexValue > > & GetIndexFields() const
Gets the index value type.
Definition: Index.h:409
void SetSize(const int64_t &value)
Sets the size of the index layer.
Definition: Index.h:452
std::string & GetMutableId()
Gets a mutable reference to the index layer ID.
Definition: Index.h:395
const boost::optional< std::string > & GetCheckSum() const
Gets the checksum of the index layer.
Definition: Index.h:339
void SetMetadata(const std::map< std::string, std::string > &value)
Sets the metadata of the index layer.
Definition: Index.h:379
const boost::optional< std::map< std::string, std::string > > & GetMetadata() const
Gets the metadata of the index layer.
Definition: Index.h:360
Index(std::string uuid, std::map< IndexName, std::shared_ptr< IndexValue >> indexFields)
Creates the Index insatnce.
Definition: Index.h:322
Represents the index layer of the integer type.
Definition: Index.h:153
IntIndexValue(int64_t intValue, IndexType type)
Creates the IntIndexValue instance.
Definition: Index.h:163
int64_t & GetMutableValue()
Gets a mutable reference to the integer value of the index layer.
Definition: Index.h:179
const int64_t & GetValue() const
Gets the integer value of the index layer.
Definition: Index.h:172
void SetValue(const int64_t &value)
Sets the integer value.
Definition: Index.h:186
Represents the index layer of the string type.
Definition: Index.h:190
std::string & GetMutableValue()
Gets a mutable reference to the string value of the index layer.
Definition: Index.h:215
std::string GetValue() const
Gets the string value of the index layer.
Definition: Index.h:208
void SetValue(const std::string &value)
Sets the string value.
Definition: Index.h:222
StringIndexValue(std::string stringValue, IndexType type)
Creates the StringIndexValue instance.
Definition: Index.h:200
Represents the index layer of the time window type.
Definition: Index.h:226
void SetValue(const int64_t &value)
Sets the time window value.
Definition: Index.h:259
const int64_t & GetValue() const
Gets the time vindow value of the index layer.
Definition: Index.h:244
TimeWindowIndexValue(int64_t timeWindowValue, IndexType type)
Creates the TimeWindowIndexValue instance.
Definition: Index.h:236
int64_t & GetMutableValue()
Gets a mutable reference to the time window value of the index layer.
Definition: Index.h:252
Represents values that are not supported by the index layer.
Definition: Index.h:105
UnsupportedIndexValue(IndexType type)
Creates the UnsupportedIndexValue instance.
Definition: Index.h:112
Rules all the other namespaces.
Definition: AppleSignInProperties.h:24