rename SmartPtr-ByRef and ScopeGuard-ByRefHolder into RefToValue and move it to loki/RefToValue.h

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@530 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2006-02-14 11:54:46 +00:00
parent 56ccba6d09
commit 1cd7d08d7c
3 changed files with 81 additions and 47 deletions

70
include/loki/RefToValue.h Executable file
View file

@ -0,0 +1,70 @@
////////////////////////////////////////////////////////////////////////////////
// The Loki Library
// Copyright (c) 2006 Richard Sposato
// Copyright (c) 2006 Peter Kümmel
// Permission to use, copy, modify, distribute and sell this software for any
// purpose is hereby granted without fee, provided that the above copyright
// notice appear in all copies and that both that copyright notice and this
// permission notice appear in supporting documentation.
// The authors make no representations about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
////////////////////////////////////////////////////////////////////////////////
#ifndef LOKI_REFTOVALUE_H
#define LOKI_REFTOVALUE_H
namespace Loki
{
////////////////////////////////////////////////////////////////////////////////
/// \class RefToValue
///
/// \ingroup SmartPointerGroup
/// Transports a reference as a value
/// Serves to implement the Colvin/Gibbons trick for SmartPtr/ScopeGuard
////////////////////////////////////////////////////////////////////////////////
template <class T>
class RefToValue
{
public:
RefToValue(T& ref) : ref_(ref)
{}
RefToValue(const RefToValue& rhs) : ref_(rhs.ref_)
{}
operator T& () const
{
return ref_;
}
private:
// Disable - not implemented
RefToValue();
RefToValue& operator=(const RefToValue&);
T& ref_;
};
////////////////////////////////////////////////////////////////////////////////
/// \function ByRef
///
/// \ingroup SmartPointerGroup
/// RefToValue creator.
////////////////////////////////////////////////////////////////////////////////
template <class T>
inline RefToValue<T> ByRef(T& t)
{
return RefToValue<T>(t);
}
}
#endif //LOKI_REFTOVALUE_H

View file

@ -22,30 +22,6 @@
namespace Loki
{
template <class T>
class RefHolder
{
T& ref_;
public:
RefHolder(T& ref) : ref_(ref)
{}
operator T& () const
{
return ref_;
}
private:
// Disable assignment - not implemented
RefHolder& operator=(const RefHolder&);
};
template <class T>
inline RefHolder<T> ByRef(T& t)
{
return RefHolder<T>(t);
}
class ScopeGuardImplBase
{
ScopeGuardImplBase& operator =(const ScopeGuardImplBase&);
@ -385,6 +361,9 @@ namespace Loki
#endif //LOKI_SCOPEGUARD_H_
// $Log$
// Revision 1.5 2006/02/14 11:54:46 syntheticpp
// rename SmartPtr-ByRef and ScopeGuard-ByRefHolder into RefToValue and move it to loki/RefToValue.h
//
// Revision 1.4 2006/01/16 19:05:09 rich_sposato
// Added cvs keywords.
//

View file

@ -34,6 +34,8 @@
#include "SmallObj.h"
#include "TypeManip.h"
#include "static_check.h"
#include "RefToValue.h"
#include <functional>
#include <stdexcept>
#include <cassert>
@ -820,26 +822,6 @@ namespace Loki
{}
};
////////////////////////////////////////////////////////////////////////////////
/// \class ByRef
///
/// \ingroup SmartPointerGroup
/// Transports a reference as a value
/// Serves to implement the Colvin/Gibbons trick for SmartPtr
////////////////////////////////////////////////////////////////////////////////
template <class T>
class ByRef
{
public:
ByRef(T& v) : value_(v) {}
operator T&() { return value_; }
// gcc doesn't like this:
// operator const T&() const { return value_; }
private:
ByRef& operator=(const ByRef &);
T& value_;
};
////////////////////////////////////////////////////////////////////////////////
/// \class DontPropagateConst
@ -1017,12 +999,12 @@ namespace Loki
: SP(rhs), OP(rhs), KP(rhs), CP(rhs)
{ GetImplRef(*this) = OP::Clone(GetImplRef(rhs)); }
SmartPtr(ByRef<SmartPtr> rhs)
SmartPtr(RefToValue<SmartPtr> rhs)
: SP(rhs), OP(rhs), KP(rhs), CP(rhs)
{}
operator ByRef<SmartPtr>()
{ return ByRef<SmartPtr>(*this); }
operator RefToValue<SmartPtr>()
{ return RefToValue<SmartPtr>(*this); }
SmartPtr& operator=(CopyArg& rhs)
{
@ -1449,6 +1431,9 @@ namespace std
#endif // SMARTPTR_INC_
// $Log$
// Revision 1.16 2006/02/14 11:54:46 syntheticpp
// rename SmartPtr-ByRef and ScopeGuard-ByRefHolder into RefToValue and move it to loki/RefToValue.h
//
// Revision 1.15 2006/02/08 18:12:29 rich_sposato
// Fixed bug 1425890. Last SmartPtr in linked chain NULLs its prev & next
// pointers to prevent infinite recursion. Added asserts.