reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
Handle.hxx
Go to the documentation of this file.
1#if !defined(RESIP_HANDLE_HXX)
2#define RESIP_HANDLE_HXX
3
4#include <iosfwd>
5#include "rutil/ResipAssert.h"
9
10namespace resip
11{
12
13template <class T>
14class 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
59 {
60 return get();
61 }
62
63 const T* operator->() const
64 {
65 return get();
66 }
67
69 {
70 return *get();
71 }
72
73 const T& operator*() const
74 {
75 return *get();
76 }
77
78
80 {
81 return mId;
82 }
83
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 bool operator!=(const Handle<T>& other)
96 {
97 return (mHam != other.mHam) || (mId != other.mId);
98 }
99
100 // !nash! to be able to use Handle in Set or Map container
101 bool operator<(const Handle<T>& other) const
102 {
103 resip_assert(mHam);
104 resip_assert(other.mHam);
105 return mId < other.mId;
106 }
107
108 private:
109 HandleManager* mHam;
110
111 protected:
113
114 friend class Handled;
115};
116
117}
118
119#endif
120
121/* ====================================================================
122 * The Vovida Software License, Version 1.0
123 *
124 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
125 *
126 * Redistribution and use in source and binary forms, with or without
127 * modification, are permitted provided that the following conditions
128 * are met:
129 *
130 * 1. Redistributions of source code must retain the above copyright
131 * notice, this list of conditions and the following disclaimer.
132 *
133 * 2. Redistributions in binary form must reproduce the above copyright
134 * notice, this list of conditions and the following disclaimer in
135 * the documentation and/or other materials provided with the
136 * distribution.
137 *
138 * 3. The names "VOCAL", "Vovida Open Communication Application Library",
139 * and "Vovida Open Communication Application Library (VOCAL)" must
140 * not be used to endorse or promote products derived from this
141 * software without prior written permission. For written
142 * permission, please contact vocal@vovida.org.
143 *
144 * 4. Products derived from this software may not be called "VOCAL", nor
145 * may "VOCAL" appear in their name, without prior written
146 * permission of Vovida Networks, Inc.
147 *
148 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
149 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
150 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
151 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
152 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
153 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
154 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
155 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
156 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
157 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
158 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
159 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
160 * DAMAGE.
161 *
162 * ====================================================================
163 *
164 * This software consists of voluntary contributions made by Vovida
165 * Networks, Inc. and many individuals on behalf of Vovida Networks,
166 * Inc. For more information on Vovida Networks, Inc., please see
167 * <http://www.vovida.org/>.
168 *
169 */
#define resip_assert(x)
This file needs to work for both C and C++ code.
bool isValidHandle(Handled::Id) const
Handled * getHandled(Handled::Id) const
const T & operator*() const
Definition Handle.hxx:73
bool isValid() const
Definition Handle.hxx:25
bool operator!=(const Handle< T > &other)
Definition Handle.hxx:95
static Handle< T > NotValid()
Definition Handle.hxx:84
const T * operator->() const
Definition Handle.hxx:63
T & operator*()
Definition Handle.hxx:68
T * operator->()
Definition Handle.hxx:58
bool operator==(const Handle< T > &other)
Definition Handle.hxx:90
const T * get() const
Definition Handle.hxx:48
bool operator<(const Handle< T > &other) const
Definition Handle.hxx:101
Handle(HandleManager &ham, Handled::Id id)
Definition Handle.hxx:17
Handled::Id getId() const
Definition Handle.hxx:79
Handled::Id mId
Definition Handle.hxx:112
unsigned long Id
Definition Handled.hxx:15
dcm! – add UnusedChecking(_enum) below;