/usr/include/Wt/Dbo/weak_ptr is in libwtdbo-dev 3.3.0-1build1.
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 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2012 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WT_DBO_DBO_WEAK_PTR_H_
#define WT_DBO_DBO_WEAK_PTR_H_
#include <Wt/Dbo/ptr>
#include <Wt/Dbo/Session>
namespace Wt {
namespace Dbo {
/*! \class weak_ptr Wt/Dbo/weak_ptr Wt/Dbo/weak_ptr
* \brief A weak pointer for a database object.
*
* A weak_ptr has similar API and capabilities as a ptr, but does not
* actually store a reference to the object itself. Instead, it uses
* a query to retrieve the object.
*
* It is used only to implement a OneToOne relation:
* - class A hasOne class B object, in a weak_ptr
* - class B belongsTo a class A object, in a ptr
*
* This cannot be implemented using two plain ptr's because otherwise
* a cycle would be created which interferes with the count-based
* shared pointer implementation of ptr.
*
* Only in a OneToOne relation, the required querying logic for the
* weak_ptr to function properly is provided by the hasOne() call, and thus
* a weak_ptr cannot be used outside of a OneToOne relation.
*
* The weak_ptr has almost the same capabilities as a ptr, except that
* it does not provide a dereference operator (*).
*
* It's important to realize that reading a weak_ptr results in a
* query, and thus you may want to first convert the weak_ptr into a
* plain ptr when needing multiple operations.
*
* \ingroup dbo
*/
template <class C>
class weak_ptr
{
public:
typedef C pointed;
class accessor
{
public:
accessor(const ptr<C>& p);
const C *operator->() const;
const C& operator*() const;
operator const C*() const;
private:
ptr<C> p_;
};
class mutator
{
public:
mutator(const ptr<C>& p);
~mutator();
C *operator->() const;
C& operator*() const;
operator C*() const;
private:
ptr<C> p_;
};
/*! \brief Creates a new weak pointer.
*
* The ptr does not point to anything.
*/
weak_ptr();
/*! \brief Copy constructor.
*/
weak_ptr(const weak_ptr<C>& other);
/*! \brief Sets the value.
*
* This is assigns a new value, and:
* \code
* p.reset(obj);
* \endcode
* is equivalent to:
* \code
* p = Wt::Dbo::ptr<T>(obj);
* \endcode
*
* Since this needs to query the previous value, you should have an
* active transaction.
*/
void reset(C *obj = 0);
/*! \brief Assignment operator.
*
* Since this needs to query the previous value, you should have an
* active transaction.
*/
weak_ptr<C>& operator= (const weak_ptr<C>& other);
/*! \brief Assignment operator.
*
* Since this needs to query the previous value, you should have an
* active transaction.
*/
weak_ptr<C>& operator= (const ptr<C>& other);
#ifdef DOXYGEN_ONLY
/*! \brief Dereference operator.
*
* Note that this operator returns a const copy of the referenced
* object. Use modify() to get a non-const reference.
*
* Since this needs to query the value, you should have an active
* transaction.
*/
const C *operator->() const;
/*! \brief Dereference operator, for writing.
*
* Returns the underlying object (or, rather, a proxy for it) with
* the intention to modify it. The proxy object will mark the object
* as dirty from its destructor. An involved modification should
* therefore preferably be implemented as a separate method or
* function to make sure that the object is marked as dirty after the
* whole modification:
* \code
* weak_ptr<A> a = ...;
* a.modify()->doSomething();
* \endcode
*
* Since this needs to query the value, you should have an active
* transaction.
*/
C *modify() const;
#else
accessor operator->() const;
mutator modify() const;
#endif // DOXYGEN_ONLY
/*! \brief Comparison operator.
*
* Two pointers are equal if and only if they reference the same
* database object.
*
* Since this needs to query the value, you should have an active
* transaction.
*/
bool operator== (const weak_ptr<C>& other) const;
/*! \brief Comparison operator.
*
* Two pointers are equal if and only if they reference the same
* database object.
*
* Since this needs to query the value, you should have an active
* transaction.
*/
bool operator== (const ptr<C>& other) const;
/*! \brief Comparison operator.
*
* Two pointers are equal if and only if they reference the same
* database object.
*
* Since this needs to query the value, you should have an active
* transaction.
*/
bool operator!= (const weak_ptr<C>& other) const;
/*! \brief Comparison operator.
*
* Two pointers are equal if and only if they reference the same
* database object.
*
* Since this needs to query the value, you should have an active
* transaction.
*/
bool operator!= (const ptr<C>& other) const;
/*! \brief Checks for null.
*
* Returns true if the pointer is pointing to a non-null object.
*
* Since this needs to query the value, you should have an active
* transaction.
*/
operator bool() const;
/*! \brief Casting operator to a ptr.
*
* Returns the value as a plain ptr.
*
* Since this needs to query the value, you should have an active
* transaction.
*/
operator ptr<C>() const;
/*! \brief Promotes to a ptr.
*
* Returns the value as a plain ptr.
*
* Since this needs to query the value, you should have an active
* transaction.
*
* This is equivalent to lock() or the ptr<C> cast operator.
*/
ptr<C> query() const;
/*! \brief Promotes to a ptr.
*
* Returns the value as a plain ptr.
*
* Since this needs to query the value, you should have an active
* transaction.
*
* This is equivalent to query() or the ptr<C> cast operator.
*/
ptr<C> lock() const;
/*! \brief Returns the object id.
*
* Since this needs to query the value, you should have an active
* transaction.
*/
typename dbo_traits<C>::IdType id() const;
private:
collection< ptr<C> > collection_;
void setRelationData(MetaDboBase *dbo, const std::string *sql,
Session::SetInfo *info);
friend class DboAction;
friend class SaveBaseAction;
friend class SetReciproceAction;
};
}
}
#endif // WT_DBO_DBO_WEAK_PTR_H_
|