source: Sophya/trunk/SophyaExt/JThreadsC++/JTCSrc/JTC/Handle.h@ 1016

Last change on this file since 1016 was 1016, checked in by ansari, 25 years ago

Creation du module JThreadsC++, importation du code des classes
de Thread a la Java de Object Oriented Concepts Inc - Reza 19/5/2000

File size: 2.1 KB
Line 
1// **********************************************************************
2//
3// Copyright (c) 2000
4// Object Oriented Concepts, Inc.
5// Billerica, MA, USA
6//
7// All Rights Reserved
8//
9// **********************************************************************
10
11#ifndef JTC_HANDLE_H
12#define JTC_HANDLE_H
13
14//
15// Provide some handy typedefs.
16//
17template <class T> class JTCHandleT;
18
19class JTCThread;
20typedef JTCHandleT<JTCThread> JTCThreadHandle;
21
22class JTCThreadGroup;
23typedef JTCHandleT<JTCThreadGroup> JTCThreadGroupHandle;
24
25class JTCRunnable;
26typedef JTCHandleT<JTCRunnable> JTCRunnableHandle;
27
28//
29// JTCRefCount class. This is a base class to be used in conjunction
30// with the JTCHandleT class.
31//
32class JTCRefCount
33{
34public:
35 int _jtc_refCount_;
36 JTCMutex refMutex_;
37
38 JTCRefCount()
39 : _jtc_refCount_(0)
40 {
41 }
42
43 virtual ~JTCRefCount()
44 {
45 }
46};
47
48//
49// This class is a handle to a reference counted object. This ensures
50// that the object is deleted when it is no longer referenced.
51//
52template <class T>
53class JTCHandleT
54{
55 T* tg_; // Referenced object
56
57public:
58
59 //
60 // Constructors.
61 //
62 JTCHandleT(T* tg = 0);
63 JTCHandleT(const JTCHandleT<T>& rhs);
64
65 //
66 // Destructor. Deletes object when reference count drops to
67 // zero.
68 //
69 ~JTCHandleT();
70
71 //
72 // Assignment operator.
73 //
74 JTCHandleT<T>& operator=(const JTCHandleT<T>& rhs);
75
76 //
77 // Equality and inequality.
78 //
79 bool operator==(const JTCHandleT<T>& rhs) const
80 { return tg_ == rhs.tg_; }
81 bool operator!=(const JTCHandleT<T>& rhs) const
82 { return tg_ != rhs.tg_; }
83
84 //
85 // Logical not operator. Are we referring to a valid Thread?
86 //
87 bool operator!() const { return tg_ == 0; }
88 operator bool() const { return tg_ != 0; }
89
90 //
91 // Make access to the Thread intuitive.
92 //
93 T* operator->() const { return tg_; }
94 T* get() const { return tg_; }
95 T& operator*() { return *tg_; }
96
97 void _jtc_deref();
98};
99
100#if defined(HAVE_NO_EXPLICIT_TEMPLATES) && !defined(HAVE_PRAGMA_DEFINE)
101# include "JTC/HandleI.h"
102#endif
103
104#endif
Note: See TracBrowser for help on using the repository browser.