/[resiprocate]/branches/b-identity-0505/dum/Handle.hxx
ViewVC logotype

Contents of /branches/b-identity-0505/dum/Handle.hxx

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3267 - (show annotations) (download)
Tue Aug 17 23:50:49 2004 UTC (15 years, 5 months ago) by jason
Original Path: main/sip/resiprocate/dum/Handle.hxx
File size: 1488 byte(s)


1 #if !defined(RESIP_HANDLE_HXX)
2 #define RESIP_HANDLE_HXX
3
4 #include "resiprocate/dum/Handled.hxx"
5 #include "resiprocate/dum/HandleManager.hxx"
6 #include "resiprocate/dum/HandleException.hxx"
7
8 namespace resip
9 {
10
11 template <class T>
12 class Handle
13 {
14 public:
15 Handle(HandleManager& ham, Handled::Id id) : mHam(&ham), mId(id)
16 {
17 }
18
19 Handle() : mHam(0)
20 {
21 }
22
23 bool isValid() const
24 {
25 if (!mHam)
26 {
27 return false;
28 }
29 else
30 {
31 return mHam->isValidHandle(mId);
32 }
33 }
34
35 // throws if not found
36 T* get()
37 {
38 if (!mHam)
39 {
40 //assert(0);
41 throw HandleException("Reference to unitialized handle.", __FILE__, __LINE__);
42 }
43 return static_cast<T*>(mHam->getHandled(mId));
44 }
45
46 T* operator->()
47 {
48 return get();
49 }
50
51 Handled::Id getId() const
52 {
53 return mId;
54 }
55
56 static Handle<T> NotValid()
57 {
58 static Handle<T> notValid;
59 return notValid;
60 }
61
62 bool operator==(const Handle<T>& other)
63 {
64 return mId == other.mId;
65 }
66
67
68 protected:
69 Handle(HandleManager& ham, Handled* handled) : mHam(&ham), mId(mHam->create(this))
70 {
71 }
72
73 //for invalid handles
74
75 private:
76 HandleManager* mHam;
77
78 protected:
79 Handled::Id mId;
80
81 friend class Handled;
82 };
83
84 }
85
86 #endif

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27