OCILIB (C and C++ Driver for Oracle)  4.7.3
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
ConcurrentList.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-2021 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 <algorithm>
24 
25 #include "ocilibcpp/core.hpp"
26 
27 // ReSharper disable CppClangTidyHicppUseEqualsDefault
28 // ReSharper disable CppClangTidyModernizeUseEqualsDefault
29 // ReSharper disable CppClangTidyHicppUseAuto
30 // ReSharper disable CppClangTidyModernizeUseAuto
31 
32 namespace ocilib
33 {
34  namespace core
35  {
36  template<class T>
37  ConcurrentList<T>::ConcurrentList() : _list()
38  {
39 
40  }
41 
42  template<class T>
43  ConcurrentList<T>::~ConcurrentList() noexcept
44  {
45  SILENT_CATCH(Clear())
46  }
47 
48  template<class T>
49  void ConcurrentList<T>::Add(T value)
50  {
51  Lock();
52  _list.push_back(value);
53  Unlock();
54  }
55 
56  template<class T>
57  void ConcurrentList<T>::Remove(T value)
58  {
59  Lock();
60  _list.remove(value);
61  Unlock();
62  }
63 
64  template<class T>
65  void ConcurrentList<T>::Clear()
66  {
67  Lock();
68  _list.clear();
69  Unlock();
70  }
71 
72  template<class T>
73  size_t ConcurrentList<T>::GetSize()
74  {
75  Lock();
76  const size_t size = _list.size();
77  Unlock();
78 
79  return size;
80  }
81 
82  template<class T>
83  bool ConcurrentList<T>::Exists(const T& value)
84  {
85  Lock();
86 
87  const bool res = std::find(_list.begin(), _list.end(), value) != _list.end();
88 
89  Unlock();
90 
91  return res;
92  }
93 
94  template<class T>
95  template<class P>
96  bool ConcurrentList<T>::FindIf(P predicate, T& value)
97  {
98  bool res = false;
99 
100  Lock();
101 
102  typename std::list<T>::iterator it = std::find_if(_list.begin(), _list.end(), predicate);
103 
104  if (it != _list.end())
105  {
106  value = *it;
107  res = true;
108  }
109 
110  Unlock();
111 
112  return res;
113  }
114 
115  template<class T>
116  template<class A>
117  void ConcurrentList<T>::ForEach(A action)
118  {
119  Lock();
120 
121  std::for_each(_list.begin(), _list.end(), action);
122 
123  Unlock();
124  }
125 
126  }
127 }
OCILIB ++ Namespace.