GridGain C++
mutable_cache_entry.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 GridGain Systems, Inc. and Contributors.
3  *
4  * Licensed under the GridGain Community Edition License (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  * https://www.gridgain.com/products/software/community-edition/gridgain-community-edition-license
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 
22 #ifndef _IGNITE_CACHE_MUTABLE_CACHE_ENTRY
23 #define _IGNITE_CACHE_MUTABLE_CACHE_ENTRY
24 
25 namespace ignite
26 {
27  namespace cache
28  {
38  template<typename K, typename V>
40  {
41  public:
46  key(),
47  val(),
48  exists(false)
49  {
50  // No-op.
51  }
52 
58  MutableCacheEntry(const K& key) :
59  key(key),
60  val(),
61  exists(false)
62  {
63  // No-op.
64  }
65 
72  MutableCacheEntry(const K& key, const V& val) :
73  key(key),
74  val(val),
75  exists(true)
76  {
77  // No-op.
78  }
79 
86  key(other.key),
87  val(other.val),
88  exists(other.exists)
89  {
90  // No-op.
91  }
92 
100  {
101  if (this != &other)
102  {
103  key = other.key;
104  val = other.val;
105  exists = other.exists;
106  }
107 
108  return *this;
109  }
110 
117  bool IsExists() const
118  {
119  return exists;
120  }
121 
125  void Remove()
126  {
127  exists = false;
128  }
129 
135  const K& GetKey() const
136  {
137  return key;
138  }
139 
145  const V& GetValue() const
146  {
147  return val;
148  }
149 
157  void SetValue(const V& val)
158  {
159  this->val = val;
160 
161  exists = true;
162  }
163 
164  private:
166  K key;
167 
169  V val;
170 
172  bool exists;
173  };
174  }
175 }
176 
177 #endif //_IGNITE_CACHE_MUTABLE_CACHE_ENTRY
ignite::cache::MutableCacheEntry::MutableCacheEntry
MutableCacheEntry()
Default constructor.
Definition: mutable_cache_entry.h:45
ignite
Ignite API.
Definition: cache.h:47
ignite::cache::MutableCacheEntry::MutableCacheEntry
MutableCacheEntry(const K &key, const V &val)
Constructor for existing entry.
Definition: mutable_cache_entry.h:72
ignite::cache::MutableCacheEntry::operator=
MutableCacheEntry & operator=(const MutableCacheEntry &other)
Assignment operator.
Definition: mutable_cache_entry.h:99
ignite::cache::MutableCacheEntry::MutableCacheEntry
MutableCacheEntry(const K &key)
Constructor for non-existing entry.
Definition: mutable_cache_entry.h:58
ignite::cache::MutableCacheEntry::IsExists
bool IsExists() const
Check whether cache entry exists in cache.
Definition: mutable_cache_entry.h:117
ignite::cache::MutableCacheEntry::SetValue
void SetValue(const V &val)
Sets or replaces the value associated with the key.
Definition: mutable_cache_entry.h:157
ignite::cache::MutableCacheEntry
Mutable representation of CacheEntry class template.
Definition: mutable_cache_entry.h:39
ignite::cache::MutableCacheEntry::Remove
void Remove()
Removes the entry from the Cache.
Definition: mutable_cache_entry.h:125
ignite::cache::MutableCacheEntry::MutableCacheEntry
MutableCacheEntry(const MutableCacheEntry &other)
Copy constructor.
Definition: mutable_cache_entry.h:85
ignite::cache::MutableCacheEntry::GetKey
const K & GetKey() const
Get key.
Definition: mutable_cache_entry.h:135
ignite::cache::MutableCacheEntry::GetValue
const V & GetValue() const
Get value.
Definition: mutable_cache_entry.h:145