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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3267 - (hide 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 jason 2941 #if !defined(RESIP_HANDLE_HXX)
2     #define RESIP_HANDLE_HXX
3    
4     #include "resiprocate/dum/Handled.hxx"
5     #include "resiprocate/dum/HandleManager.hxx"
6 derek 3089 #include "resiprocate/dum/HandleException.hxx"
7 jason 2941
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 derek 2983 Handle() : mHam(0)
20     {
21     }
22    
23 jason 2941 bool isValid() const
24     {
25 derek 3006 if (!mHam)
26     {
27     return false;
28     }
29     else
30     {
31     return mHam->isValidHandle(mId);
32     }
33 jason 2941 }
34    
35     // throws if not found
36     T* get()
37     {
38 derek 3089 if (!mHam)
39     {
40 jason 3267 //assert(0);
41 derek 3089 throw HandleException("Reference to unitialized handle.", __FILE__, __LINE__);
42     }
43 jason 2941 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 derek 2965 static Handle<T> NotValid()
57     {
58     static Handle<T> notValid;
59     return notValid;
60     }
61    
62 jason 3267 bool operator==(const Handle<T>& other)
63     {
64     return mId == other.mId;
65     }
66    
67 derek 2965
68 jason 2941 protected:
69     Handle(HandleManager& ham, Handled* handled) : mHam(&ham), mId(mHam->create(this))
70     {
71     }
72    
73 derek 2965 //for invalid handles
74    
75 jason 2941 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