VMware VMware GemFire Native C++ Reference 10.4.3
Loading...
Searching...
No Matches
CacheableKey.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
20#ifndef GEODE_CACHEABLEKEY_H_
21#define GEODE_CACHEABLEKEY_H_
22
23#include <functional>
24#include <unordered_map>
25#include <unordered_set>
26
27#include "Serializable.hpp"
28#include "internal/functional.hpp"
29#include "internal/geode_globals.hpp"
30
35namespace apache {
36namespace geode {
37namespace client {
38
40class APACHE_GEODE_EXPORT CacheableKey : public virtual Cacheable {
41 protected:
42 CacheableKey() = default;
43 ~CacheableKey() noexcept override = default;
44
45 public:
47 virtual bool operator==(const CacheableKey& other) const = 0;
48
50 virtual int32_t hashcode() const = 0;
51
58 template <class _T>
59 static std::shared_ptr<CacheableKey> create(_T value);
60
61 template <class _T>
62 inline static std::shared_ptr<CacheableKey> create(
63 const std::shared_ptr<_T>& value) {
64 return value;
65 }
66
67 struct hash {
68 inline std::size_t operator()(const CacheableKey& s) const {
69 return s.hashcode();
70 }
71
72 inline std::size_t operator()(const CacheableKey*& s) const {
73 return s->hashcode();
74 }
75
76 inline std::size_t operator()(
77 const std::shared_ptr<CacheableKey>& s) const {
78 return s->hashcode();
79 }
80 };
81
82 struct equal_to {
83 inline bool operator()(const CacheableKey& lhs,
84 const CacheableKey& rhs) const {
85 return lhs == rhs;
86 }
87
88 inline bool operator()(const CacheableKey*& lhs,
89 const CacheableKey*& rhs) const {
90 return (*lhs) == (*rhs);
91 }
92
93 inline bool operator()(const std::shared_ptr<CacheableKey>& lhs,
94 const std::shared_ptr<CacheableKey>& rhs) const {
95 return (*lhs) == (*rhs);
96 }
97 };
98
99 private:
100 // Never defined.
101 CacheableKey(const CacheableKey& other);
102 void operator=(const CacheableKey& other);
103};
104
105using apache::geode::client::internal::dereference_equal_to;
106using apache::geode::client::internal::dereference_hash;
107
108using HashMapOfCacheable =
109 std::unordered_map<std::shared_ptr<CacheableKey>,
110 std::shared_ptr<Cacheable>,
111 dereference_hash<std::shared_ptr<CacheableKey>>,
112 dereference_equal_to<std::shared_ptr<CacheableKey>>>;
113
114using HashSetOfCacheableKey =
115 std::unordered_set<std::shared_ptr<CacheableKey>,
116 dereference_hash<std::shared_ptr<CacheableKey>>,
117 dereference_equal_to<std::shared_ptr<CacheableKey>>>;
118
119} // namespace client
120} // namespace geode
121} // namespace apache
122
123namespace std {
124
125template <>
126struct hash<apache::geode::client::CacheableKey> {
127 typedef apache::geode::client::CacheableKey argument_type;
128 typedef size_t result_type;
129 result_type operator()(const argument_type& val) const {
130 return val.hashcode();
131 }
132};
133
134} // namespace std
135
136#endif // GEODE_CACHEABLEKEY_H_
Represents a cacheable key.
Definition CacheableKey.hpp:40
virtual bool operator==(const CacheableKey &other) const =0
return true if this key matches other.
static std::shared_ptr< CacheableKey > create(_T value)
Factory method that creates the key type that matches the type of value.
virtual int32_t hashcode() const =0
return the hashcode for this key.
This base class is the superclass of all user objects in the cache that can be serialized.
Definition Serializable.hpp:53

Apache Geode C++ Cache API Documentation