SlideIO 2.0.0
Open-source library for reading of medical images
Loading...
Searching...
No Matches
refcounter.hpp
1// This file is part of slideio project.
2// It is subject to the license terms in the LICENSE file found in the top-level directory
3// of this distribution and at http://slideio.com/license.html.
4#pragma once
5#include "slideio/core/slideio_core_def.hpp"
6namespace slideio
7{
8 class SLIDEIO_CORE_EXPORTS RefCounter
9 {
10 public:
11 void increaseCounter() {
12 if (!m_counter)
13 initializeCounter();
14 ++m_counter;
15 }
16 void decreaseCounter() {
17 --m_counter;
18 if (!m_counter)
19 cleanCounter();
20 }
21 protected:
22 virtual void initializeCounter(){};
23 virtual void cleanCounter(){};
24 private:
25 int m_counter = 0;
26 };
27
28 class SLIDEIO_CORE_EXPORTS RefCounterGuard
29 {
30 public:
31 RefCounterGuard(RefCounter* counter) : m_counter(counter) {
32 m_counter->increaseCounter();
33 }
34 ~RefCounterGuard() {
35 m_counter->decreaseCounter();
36 }
37 RefCounter* m_counter;
38 };
39};
Definition: exceptions.hpp:12