Ice 3.7 C++98 API Reference
Loading...
Searching...
No Matches
Shared.h
Go to the documentation of this file.
1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#ifndef ICE_UTIL_SHARED_H
6#define ICE_UTIL_SHARED_H
7
8#include <IceUtil/Config.h>
9#include <IceUtil/Atomic.h>
10
11//
12// Base classes for reference counted types. The IceUtil::Handle
13// template can be used for smart pointers to types derived from these
14// bases.
15//
16// IceUtil::SimpleShared
17// =====================
18//
19// A non thread-safe base class for reference-counted types.
20//
21// IceUtil::Shared
22// ===============
23//
24// A thread-safe base class for reference-counted types.
25//
26namespace IceUtil
27{
28
30{
31public:
32
35
36 virtual ~SimpleShared();
37
39 {
40 return *this;
41 }
42
43 void __incRef()
44 {
45 assert(_ref >= 0);
46 ++_ref;
47 }
48
49 void __decRef()
50 {
51 assert(_ref > 0);
52 if(--_ref == 0)
53 {
54 if(!_noDelete)
55 {
56 delete this;
57 }
58 }
59 }
60
61 int __getRef() const
62 {
63 return _ref;
64 }
65
66 void __setNoDelete(bool b)
67 {
68 _noDelete = b;
69 }
70
71private:
72
73 int _ref;
74 bool _noDelete;
75};
76
78{
79public:
80
81 //
82 // Flag constant used by the Shared class. Derived classes
83 // such as GCObject define more flag constants.
84 //
85 static const unsigned char NoDelete;
86
88 Shared(const Shared&);
89
90 virtual ~Shared()
91 {
92 }
93
95 {
96 return *this;
97 }
98
99 virtual void __incRef();
100 virtual void __decRef();
101 virtual int __getRef() const;
102 virtual void __setNoDelete(bool);
103
104 void __setFlag(unsigned char flag)
105 {
106 _flags |= flag;
107 }
108
109 void __clearFlag(unsigned char flag)
110 {
111 _flags &= ~flag;
112 }
113
114 bool __hasFlag(unsigned char flag)
115 {
116 return (_flags & flag) > 0;
117 }
118
119protected:
120
121 IceUtilInternal::Atomic _ref;
122 unsigned char _flags;
123};
124
125}
126
127#endif
#define ICE_API
Definition Config.h:197
Shared & operator=(const Shared &)
Definition Shared.h:94
bool __hasFlag(unsigned char flag)
Definition Shared.h:114
virtual void __setNoDelete(bool)
virtual int __getRef() const
virtual void __decRef()
virtual void __incRef()
void __clearFlag(unsigned char flag)
Definition Shared.h:109
Shared(const Shared &)
unsigned char _flags
Definition Shared.h:122
IceUtilInternal::Atomic _ref
Definition Shared.h:121
void __setFlag(unsigned char flag)
Definition Shared.h:104
static const unsigned char NoDelete
Definition Shared.h:85
virtual ~Shared()
Definition Shared.h:90
void __setNoDelete(bool b)
Definition Shared.h:66
int __getRef() const
Definition Shared.h:61
void __incRef()
Definition Shared.h:43
SimpleShared(const SimpleShared &)
SimpleShared & operator=(const SimpleShared &)
Definition Shared.h:38
void __decRef()
Definition Shared.h:49
Definition Cond.h:39