Apache Ignite C++
mutable_cache_entry.h
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 #ifndef _IGNITE_CACHE_MUTABLE_CACHE_ENTRY
19 #define _IGNITE_CACHE_MUTABLE_CACHE_ENTRY
20 
21 #include <ignite/common/common.h>
23 
24 namespace ignite
25 {
26  namespace cache
27  {
37  template<typename K, typename V>
39  {
40  public:
45  key(),
46  val(),
47  exists(false)
48  {
49  // No-op.
50  }
51 
57  MutableCacheEntry(const K& key) :
58  key(key),
59  val(),
60  exists(false)
61  {
62  // No-op.
63  }
64 
71  MutableCacheEntry(const K& key, const V& val) :
72  key(key),
73  val(val),
74  exists(true)
75  {
76  // No-op.
77  }
78 
85  key(other.key),
86  val(other.val),
87  exists(other.exists)
88  {
89  // No-op.
90  }
91 
99  {
100  if (this != &other)
101  {
102  key = other.key;
103  val = other.val;
104  exists = other.exists;
105  }
106 
107  return *this;
108  }
109 
116  bool IsExists() const
117  {
118  return exists;
119  }
120 
124  void Remove()
125  {
126  exists = false;
127  }
128 
134  const K& GetKey() const
135  {
136  return key;
137  }
138 
144  const V& GetValue() const
145  {
146  return val;
147  }
148 
156  void SetValue(const V& val)
157  {
158  this->val = val;
159 
160  exists = true;
161  }
162 
163  private:
165  K key;
166 
168  V val;
169 
171  bool exists;
172  };
173  }
174 }
175 
176 #endif //_IGNITE_CACHE_MUTABLE_CACHE_ENTRY
MutableCacheEntry(const K &key)
Constructor for non-existing entry.
Definition: mutable_cache_entry.h:57
Mutable representation of CacheEntry class template.
Definition: mutable_cache_entry.h:38
MutableCacheEntry & operator=(const MutableCacheEntry &other)
Assignment operator.
Definition: mutable_cache_entry.h:98
void Remove()
Removes the entry from the Cache.
Definition: mutable_cache_entry.h:124
MutableCacheEntry(const MutableCacheEntry &other)
Copy constructor.
Definition: mutable_cache_entry.h:84
MutableCacheEntry()
Default constructor.
Definition: mutable_cache_entry.h:44
bool IsExists() const
Check whether cache entry exists in cache.
Definition: mutable_cache_entry.h:116
const K & GetKey() const
Get key.
Definition: mutable_cache_entry.h:134
Declares ignite::cache::CacheEntry class.
const V & GetValue() const
Get value.
Definition: mutable_cache_entry.h:144
void SetValue(const V &val)
Sets or replaces the value associated with the key.
Definition: mutable_cache_entry.h:156
Apache Ignite API.
Definition: cache.h:48
MutableCacheEntry(const K &key, const V &val)
Constructor for existing entry.
Definition: mutable_cache_entry.h:71