/[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 4598 - (show annotations) (download)
Wed May 11 22:53:07 2005 UTC (14 years, 8 months ago) by derek
File size: 4355 byte(s)
set svn:eol-style to LF
1 #if !defined(RESIP_HANDLE_HXX)
2 #define RESIP_HANDLE_HXX
3
4 #include <iosfwd>
5 #include "resiprocate/dum/Handled.hxx"
6 #include "resiprocate/dum/HandleManager.hxx"
7 #include "resiprocate/dum/HandleException.hxx"
8
9 namespace resip
10 {
11
12 template <class T>
13 class Handle
14 {
15 public:
16 Handle(HandleManager& ham, Handled::Id id) : mHam(&ham), mId(id)
17 {
18 }
19
20 Handle() : mHam(0)
21 {
22 }
23
24 bool isValid() const
25 {
26 if (!mHam)
27 {
28 return false;
29 }
30 else
31 {
32 return mHam->isValidHandle(mId);
33 }
34 }
35
36 // throws if not found
37 T* get()
38 {
39 if (!mHam)
40 {
41 //assert(0);
42 throw HandleException("Reference to unitialized handle.", __FILE__, __LINE__);
43 }
44 return static_cast<T*>(mHam->getHandled(mId));
45 }
46
47 const T* get() const
48 {
49 if (!mHam)
50 {
51 //assert(0);
52 throw HandleException("Reference to unitialized handle.", __FILE__, __LINE__);
53 }
54 return static_cast<T*>(mHam->getHandled(mId));
55 }
56
57 T* operator->()
58 {
59 return get();
60 }
61
62 const T* operator->() const
63 {
64 return get();
65 }
66
67 T& operator*()
68 {
69 return *get();
70 }
71
72 const T& operator*() const
73 {
74 return *get();
75 }
76
77
78 Handled::Id getId() const
79 {
80 return mId;
81 }
82
83 static Handle<T> NotValid()
84 {
85 static Handle<T> notValid;
86 return notValid;
87 }
88
89 bool operator==(const Handle<T>& other)
90 {
91 return mId == other.mId;
92 }
93
94
95 protected:
96 Handle(HandleManager& ham, Handled* handled) : mHam(&ham), mId(mHam->create(this))
97 {
98 }
99
100 //for invalid handles
101
102 private:
103 HandleManager* mHam;
104
105 protected:
106 Handled::Id mId;
107
108 friend class Handled;
109 };
110
111 }
112
113 #endif
114
115 /* ====================================================================
116 * The Vovida Software License, Version 1.0
117 *
118 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
119 *
120 * Redistribution and use in source and binary forms, with or without
121 * modification, are permitted provided that the following conditions
122 * are met:
123 *
124 * 1. Redistributions of source code must retain the above copyright
125 * notice, this list of conditions and the following disclaimer.
126 *
127 * 2. Redistributions in binary form must reproduce the above copyright
128 * notice, this list of conditions and the following disclaimer in
129 * the documentation and/or other materials provided with the
130 * distribution.
131 *
132 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
133 * and "Vovida Open Communication Application Library (VOCAL)" must
134 * not be used to endorse or promote products derived from this
135 * software without prior written permission. For written
136 * permission, please contact vocal@vovida.org.
137 *
138 * 4. Products derived from this software may not be called "VOCAL", nor
139 * may "VOCAL" appear in their name, without prior written
140 * permission of Vovida Networks, Inc.
141 *
142 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
143 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
144 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
145 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
146 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
147 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
148 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
149 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
150 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
151 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
152 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
153 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
154 * DAMAGE.
155 *
156 * ====================================================================
157 *
158 * This software consists of voluntary contributions made by Vovida
159 * Networks, Inc. and many individuals on behalf of Vovida Networks,
160 * Inc. For more information on Vovida Networks, Inc., please see
161 * <http://www.vovida.org/>.
162 *
163 */

Properties

Name Value
svn:eol-style LF

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27