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  #define NX_TEST_STORAGE_PLUGIN_API __declspec(dllexport)
10  #pragma warning(disable: 4251) //< Disable warnings "... needs to have dll-interface...".
11  #pragma warning(disable: 4275) //< Disable warnings "... non dll-interface class...".
12 #else
13  #define NX_TEST_STORAGE_PLUGIN_API /*empty*/
14 #endif
15 
16 template <typename P>
18 {
19 public:
21  : m_count(1)
22  {}
23 
24  int pAddRef() const { return ++m_count; }
25 
26  int pReleaseRef() const
27  {
28  int new_count = --m_count;
29  if (new_count <= 0)
30  delete static_cast<const P*>(this);
31 
32  return new_count;
33  }
34 private:
35  mutable std::atomic<int> m_count;
36 };
Definition: common.h:17