Initial import of the CDE 2.1.30 sources from the Open Group.
This commit is contained in:
61
cde/programs/nsgmls/Owner.h
Normal file
61
cde/programs/nsgmls/Owner.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/* $XConsortium: Owner.h /main/3 1996/08/13 14:30:51 mgreess $ */
|
||||
// Copyright (c) 1994 James Clark
|
||||
// See the file COPYING for copying permission.
|
||||
|
||||
#ifndef Owner_INCLUDED
|
||||
#define Owner_INCLUDED 1
|
||||
|
||||
// A pointer that owns the object pointed to.
|
||||
// T must be of class type.
|
||||
// This is coded so that T need not yet have been defined.
|
||||
|
||||
#ifdef SP_NAMESPACE
|
||||
namespace SP_NAMESPACE {
|
||||
#endif
|
||||
|
||||
template<class T>
|
||||
class Owner {
|
||||
public:
|
||||
Owner() : p_(0) { }
|
||||
Owner(T *p) : p_(p) { }
|
||||
~Owner();
|
||||
void operator=(T *p) {
|
||||
if (p_) del();
|
||||
p_ = p;
|
||||
}
|
||||
operator int() const { return p_ != 0; }
|
||||
T *pointer() const { return p_; }
|
||||
T *operator->() const { return p_; }
|
||||
T &operator*() const { return *p_; }
|
||||
void swap(Owner<T> &x) {
|
||||
T *tem = p_;
|
||||
p_ = x.p_;
|
||||
x.p_ = tem;
|
||||
}
|
||||
T *extract() {
|
||||
T *tem = p_;
|
||||
p_ = 0;
|
||||
return tem;
|
||||
}
|
||||
void clear() {
|
||||
if (p_) {
|
||||
del();
|
||||
p_ = 0;
|
||||
}
|
||||
}
|
||||
private:
|
||||
Owner(const Owner<T> &) {}
|
||||
void operator=(const Owner<T> &) {}
|
||||
void del();
|
||||
T *p_;
|
||||
};
|
||||
|
||||
#ifdef SP_NAMESPACE
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* not Owner_INCLUDED */
|
||||
|
||||
#ifdef SP_DEFINE_TEMPLATES
|
||||
#include "Owner.C"
|
||||
#endif
|
||||
Reference in New Issue
Block a user