OCILIB (C and C++ Driver for Oracle)  4.7.6
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
ConcurrentMap.hpp
1 /*
2  * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI)
3  *
4  * Website: http://www.ocilib.net
5  *
6  * Copyright (c) 2007-2023 Vincent ROGIER <vince.rogier@ocilib.net>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 
23 #include "ocilibcpp/core.hpp"
24 
25 // ReSharper disable CppClangTidyHicppUseEqualsDefault
26 // ReSharper disable CppClangTidyModernizeUseEqualsDefault
27 
28 namespace ocilib
29 {
30  namespace core
31  {
32  template<class K, class V>
33  ConcurrentMap<K, V>::ConcurrentMap()
34  {
35 
36  }
37 
38  template<class K, class V>
39  ConcurrentMap<K, V>::~ConcurrentMap() noexcept
40  {
41  SILENT_CATCH(Clear());
42  }
43 
44  template<class K, class V>
45  void ConcurrentMap<K, V>::Remove(K key)
46  {
47  Acquire();
48  _map.erase(key);
49  Release();
50  }
51 
52  template<class K, class V>
53  V ConcurrentMap<K, V>::Get(K key)
54  {
55  V value = 0;
56 
57  Acquire();
58  typename std::map< K, V >::const_iterator it = _map.find(key);
59  if (it != _map.end())
60  {
61  value = it->second;
62  }
63  Release();
64 
65  return value;
66  }
67 
68  template<class K, class V>
69  void ConcurrentMap<K, V>::Set(K key, V value)
70  {
71  Acquire();
72  _map[key] = value;
73  Release();
74  }
75 
76  template<class K, class V>
77  void ConcurrentMap<K, V>::Clear()
78  {
79  Acquire();
80  _map.clear();
81  Release();
82  }
83 
84  template<class K, class V>
85  size_t ConcurrentMap<K, V>::GetSize()
86  {
87  Acquire();
88  const size_t size = _map.size();
89  Release();
90 
91  return size;
92  }
93 
94  }
95 }
OCILIB ++ Namespace.