/usr/include/barry18/barry/vsmartptr.h is in libbarry-dev 0.18.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | ///
/// \file vsmartptr.h
/// Smart pointer that accepts custom 'free' functions.
///
/*
Copyright (C) 2006-2013, Net Direct Inc. (http://www.netdirect.ca/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License in the COPYING file at the
root directory of this project for more details.
*/
#ifndef __BARRY_VSMARTPTR_H__
#define __BARRY_VSMARTPTR_H__
namespace Barry {
//
// vSmartPtr
//
/// A special smart pointer for variables that have their own
/// special 'free' functions. Behaves like std::auto_ptr<>
/// in that only one object at a time owns the pointer,
/// and destruction frees it by calling the given FreeFunc.
///
template <class T, class FT, void (*FreeFunc)(FT *pt)>
class vSmartPtr
{
mutable T *m_pt;
public:
vSmartPtr() : m_pt(0) {}
vSmartPtr(T *pt) : m_pt(pt) {}
vSmartPtr(const vSmartPtr &sp) : m_pt(sp.m_pt)
{
sp.m_pt = 0;
}
~vSmartPtr()
{
reset();
}
vSmartPtr& operator=(T *pt)
{
reset(pt);
return *this;
}
vSmartPtr& operator=(const vSmartPtr &sp)
{
reset(sp.release());
return *this;
}
// Some non-standard APIs used by Barry
T* Extract()
{
return this->release();
}
T* Get()
{
return this->get();
}
// std::auto_ptr<> style API
T* get()
{
return m_pt;
}
T* release()
{
T *rp = m_pt;
m_pt = 0;
return rp;
}
void reset(T *new_obj = 0)
{
if( m_pt )
FreeFunc(m_pt);
m_pt = new_obj;
}
};
//
// vLateSmartPtr
//
/// Variation of the above smart pointer that allows the user to
/// assign a free function after construction, in the case of
/// dlopen()'d frees.
///
template <class T, class FreeFuncPtrT>
class vLateSmartPtr
{
mutable T *m_pt;
FreeFuncPtrT m_FreeFuncPtr;
public:
explicit vLateSmartPtr(FreeFuncPtrT freefunc = 0)
: m_pt(0)
, m_FreeFuncPtr(freefunc)
{
}
vLateSmartPtr(T *pt, FreeFuncPtrT freefunc = 0)
: m_pt(pt)
, m_FreeFuncPtr(freefunc)
{
}
vLateSmartPtr(const vLateSmartPtr &sp)
: m_pt(sp.m_pt)
, m_FreeFuncPtr(sp.m_FreeFuncPtr)
{
sp.m_pt = 0;
}
~vLateSmartPtr()
{
reset();
}
void SetFreeFunc(FreeFuncPtrT freefunc)
{
m_FreeFuncPtr = freefunc;
}
vLateSmartPtr& operator=(T *pt)
{
reset(pt);
return *this;
}
vLateSmartPtr& operator=(const vLateSmartPtr &sp)
{
reset(sp.release());
m_FreeFuncPtr = sp.m_FreeFuncPtr;
return *this;
}
// Some non-standard APIs used by Barry
T* Extract()
{
return this->release();
}
T* Get()
{
return this->get();
}
// std::auto_ptr<> style API
T* get()
{
return m_pt;
}
T* release()
{
T *rp = m_pt;
m_pt = 0;
return rp;
}
void reset(T *new_obj = 0)
{
// don't check for null m_FreeFuncPtr, since
// that should be an obvious crash and requires fixing
if( m_pt )
(*m_FreeFuncPtr)(m_pt);
m_pt = new_obj;
}
};
/*
Example usage:
typedef vSmartPtr<b_VFormatAttribute, b_VFormatAttribute, &b_vformat_attribute_free> vAttrPtr;
typedef vSmartPtr<b_VFormatParam, b_VFormatParam, &b_vformat_attribute_param_free> vParamPtr;
typedef vSmartPtr<char, void, &g_free> gStringPtr;
*/
} // namespace Barry
#endif
|