/[resiprocate]/main/resip/dum/Handle.hxx
ViewVC logotype

Contents of /main/resip/dum/Handle.hxx

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:eol-style native
svn:mime-type text/plain

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27