OCILIB (C and C++ Driver for Oracle)  4.7.6
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
HandleStore.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 namespace ocilib
26 {
27  namespace core
28  {
29  inline HandleStore::HandleStore(SynchronizationGuard* guard)
30  {
31  _handles.SetGuard(guard);
32  }
33 
34  template <class T>
35  T HandleStore::Get(AnyPointer ptr)
36  {
37  return dynamic_cast<T>(_handles.Get(ptr));
38  }
39 
40  template <class T>
41  void HandleStore::Set(AnyPointer ptr, T handle)
42  {
43  if (handle)
44  {
45  _handles.Set(ptr, handle);
46  }
47  else
48  {
49  _handles.Remove(ptr);
50  }
51  }
52 
53  inline HandleStore& HandleStore::GetStoreForHandle(Handle* handle)
54  {
55  HandleStore* store = handle ? handle->GetStore() : nullptr;
56 
57  return store ? *store : GetDefaultStore();
58  }
59 
60  inline HandleStore& HandleStore::GetDefaultStore()
61  {
62  static SynchronizationGuard guard(SynchronizationMode::Unsafe);
63  static HandleStore store(&guard);
64 
65  return store;
66  }
67 
68  }
69 }
OCILIB ++ Namespace.
void * AnyPointer
Alias for the generic void pointer.
Definition: config.hpp:129