YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
ref.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <yaclib/log.hpp>
4
5#include <cstddef>
6
7namespace yaclib {
8
9/**
10 * Reference counting interface
11 */
12class IRef {
13 public:
14 /**
15 * Increments reference counter
16 */
17 virtual void IncRef() noexcept {
18 }
19
20 /**
21 * Decrements reference counter
22 */
23 virtual void DecRef() noexcept {
24 }
25
26 // The base implementations are ok only if the object
27 // is not actually reference counted
28 // If you need GetRef() then you must implement it all
29 virtual std::size_t GetRef() noexcept { // LCOV_EXCL_LINE
30 YACLIB_PURE_VIRTUAL(); // LCOV_EXCL_LINE
31 return -1; // LCOV_EXCL_LINE
32 } // LCOV_EXCL_LINE
33
34 virtual ~IRef() noexcept = default;
35};
36
37} // namespace yaclib
Reference counting interface.
Definition ref.hpp:12
virtual ~IRef() noexcept=default
virtual void IncRef() noexcept
Increments reference counter.
Definition ref.hpp:17
virtual void DecRef() noexcept
Decrements reference counter.
Definition ref.hpp:23
virtual std::size_t GetRef() noexcept
Definition ref.hpp:29
#define YACLIB_PURE_VIRTUAL()
Definition log.hpp:86
Contract< V, E > MakeContract()
Creates related future and promise.
Definition contract.hpp:25