CodePorting.Translator Cs2Cpp
CodePorting.Translator.Cs2Cpp.Framework
refcount.h
1
3#ifndef _refcount_h_
4#define _refcount_h_
5
6#include "defines.h"
7
8#include <atomic>
9#include <system/diagnostics/debug.h>
10
11#include "system/details/makeobject_leakage_detector.h"
12
13namespace System { namespace Detail {
14
16class RefCount
17{
18public:
21 inline RefCount(int value = 0)
22 : m_count(value)
23 {}
26 inline int operator ++ ()
27 {
28 return ++m_count;
29 }
30
33 inline int operator -- ()
34 {
35 const int result = --m_count;
36 return result;
37 }
38
42 inline int operator -= (int diff)
43 {
44 return m_count -= diff;
45 }
46
48 inline int get() const
49 {
50#ifdef ASPOSE_NO_ATOMIC_REFCOUNT
51 return m_count;
52#else
53 return m_count.load();
54#endif
55 }
56
58 inline operator int() const
59 {
60 return get();
61 }
62
66 inline RefCount& operator = (int value)
67 {
68#ifdef ASPOSE_NO_ATOMIC_REFCOUNT
69 m_count = value;
70#else
71 m_count.store(value);
72#endif
73 return *this;
74 }
75
79 inline bool operator == (int value) const
80 {
81 return get() == value;
82 }
83
84private:
85#ifdef ASPOSE_NO_ATOMIC_REFCOUNT
87 int volatile m_count;
88#else
90 std::atomic<int> m_count;
91#endif
92
93 // Explicitly deleting
94 RefCount(const RefCount&) = delete;
95 RefCount& operator = (const RefCount&) = delete;
96};
97
98
99} } // System::Detail
100
105inline bool operator == (int value, const System::Detail::RefCount &rc)
106{
107 return rc == value;
108}
109
110
111#endif
Definition: db_command.h:9
bool operator==(ArraySegment< T > a, ArraySegment< T > b)
Definition: array_segment.h:151