nx_storage_sdk  1.0
Storage SDK
common.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2 
3 #pragma once
4 
5 #include <atomic>
6 
7 // TODO: Used to link the unit test with the plugin. Rewrite.
8 #if defined(_WIN32)
9  #pragma warning(disable: 4251) //< Disable warnings "... needs to have dll-interface...".
10  #pragma warning(disable: 4275) //< Disable warnings "... non dll-interface class...".
11 #endif
12 
13 template <typename P>
15 {
16 public:
18  : m_count(1)
19  {}
20 
21  int pAddRef() const { return ++m_count; }
22 
23  int pReleaseRef() const
24  {
25  int new_count = --m_count;
26  if (new_count <= 0)
27  delete static_cast<const P*>(this);
28 
29  return new_count;
30  }
31 private:
32  mutable std::atomic<int> m_count;
33 };
Definition: common.h:14