replace implementation with a auto-create and propagating-const wrapper for smart pointers which auto delete the holded pointer on destruction
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@522 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
698214fb58
commit
147eca6930
6 changed files with 294 additions and 654 deletions
|
@ -12,11 +12,6 @@
|
||||||
#ifndef LOKI_PIMPL_H
|
#ifndef LOKI_PIMPL_H
|
||||||
#define LOKI_PIMPL_H
|
#define LOKI_PIMPL_H
|
||||||
|
|
||||||
#include <loki/TypeTraits.h>
|
|
||||||
#include <loki/SmartPtr.h>
|
|
||||||
#include <exception>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LOKI_INHERITED_PIMPL_NAME
|
#ifndef LOKI_INHERITED_PIMPL_NAME
|
||||||
#define LOKI_INHERITED_PIMPL_NAME d
|
#define LOKI_INHERITED_PIMPL_NAME d
|
||||||
|
@ -28,356 +23,147 @@
|
||||||
|
|
||||||
namespace Loki
|
namespace Loki
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//////////////////////////////////////////
|
||||||
|
// simple const propagating pointer
|
||||||
|
//////////////////////////////////////////
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct ConstPropPtr
|
||||||
|
{
|
||||||
|
explicit ConstPropPtr(T* p) : ptr_(p){}
|
||||||
|
~ConstPropPtr()
|
||||||
|
{
|
||||||
|
typedef char T_must_be_defined[sizeof(T) ? 1 : -1 ];
|
||||||
|
delete ptr_;
|
||||||
|
ptr_ = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
T* operator->() {return ptr_;}
|
||||||
|
T& operator*() {return *ptr_;}
|
||||||
|
const T* operator->() const {return ptr_;}
|
||||||
|
const T& operator*() const {return *ptr_;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ConstPropPtr();
|
||||||
|
ConstPropPtr(const ConstPropPtr&);
|
||||||
|
ConstPropPtr& operator=(const ConstPropPtr&);
|
||||||
|
T* ptr_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
|
// Pimpl
|
||||||
|
/////////////////////
|
||||||
|
|
||||||
|
template
|
||||||
|
<
|
||||||
|
class T,
|
||||||
|
typename Pointer = ConstPropPtr<T>
|
||||||
|
>
|
||||||
|
class Pimpl
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef T Impl;
|
||||||
|
|
||||||
|
Pimpl() : ptr_(new T)
|
||||||
|
{}
|
||||||
|
|
||||||
|
T* operator->()
|
||||||
|
{
|
||||||
|
return ptr_.operator->();
|
||||||
|
}
|
||||||
|
|
||||||
|
T& operator*()
|
||||||
|
{
|
||||||
|
return ptr_.operator*();
|
||||||
|
}
|
||||||
|
|
||||||
|
const T* operator->() const
|
||||||
|
{
|
||||||
|
return ptr_.operator->();
|
||||||
|
}
|
||||||
|
|
||||||
|
const T& operator*() const
|
||||||
|
{
|
||||||
|
return ptr_.operator*();
|
||||||
|
}
|
||||||
|
|
||||||
|
Pointer& wrapped()
|
||||||
|
{
|
||||||
|
return ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Pointer& wrapped() const
|
||||||
|
{
|
||||||
|
return ptr_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
Pimpl(const Pimpl&);
|
||||||
|
Pimpl& operator=(const Pimpl&);
|
||||||
|
|
||||||
|
Pointer ptr_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, typename Pointer = ConstPropPtr<T> >
|
||||||
|
struct PimplOwner
|
||||||
|
{
|
||||||
|
Pimpl<T,Pointer> LOKI_INHERITED_PIMPL_NAME;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////////////////////////////
|
||||||
// template for the implementations
|
// template for the implementations
|
||||||
/////////////////////
|
//////////////////////////////////////////
|
||||||
template<class T>
|
|
||||||
struct Impl;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// creation policies
|
|
||||||
/////////////////////
|
|
||||||
// hard coded creation preferred
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// destroy policies
|
|
||||||
/////////////////////
|
|
||||||
template<class T>
|
|
||||||
struct AutoDeletePimpl
|
|
||||||
{
|
|
||||||
static void Destroy(T ptr)
|
|
||||||
{
|
|
||||||
typedef char T_must_be_defined[
|
|
||||||
sizeof(typename TypeTraits<T>::PointeeType) ? 1 : -1 ];
|
|
||||||
delete ptr;
|
|
||||||
ptr = 0;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct DontDeletePimpl
|
struct ImplT;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, template<class> class Ptr = ConstPropPtr>
|
||||||
|
struct PimplT
|
||||||
{
|
{
|
||||||
static void Destroy(T)
|
typedef T Impl;
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// error handling
|
|
||||||
/////////////////////
|
|
||||||
template<class T>
|
|
||||||
struct ExceptionOnPimplError
|
|
||||||
{
|
|
||||||
struct Exception : public std::exception
|
|
||||||
{
|
|
||||||
const char* what() const throw() { return "error in loki/Pimpl.h"; }
|
|
||||||
};
|
|
||||||
|
|
||||||
static void PimplError()
|
|
||||||
{
|
|
||||||
throw Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct IgnorPimplError
|
|
||||||
{
|
|
||||||
static void PimplError()
|
|
||||||
{}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// Helper class AutoPtrHolder to manage pimpl lifetime
|
|
||||||
/////////////////////
|
|
||||||
|
|
||||||
namespace Private
|
|
||||||
{
|
|
||||||
// does not work with std::auto_ptr
|
|
||||||
template
|
|
||||||
<
|
|
||||||
class Impl,
|
|
||||||
class Ptr,
|
|
||||||
template<class> class Del
|
|
||||||
>
|
|
||||||
struct AutoPtrHolder
|
|
||||||
{
|
|
||||||
AutoPtrHolder() : ptr(Ptr())
|
|
||||||
{}
|
|
||||||
|
|
||||||
// defined in #include<loki/PimplDef.h>
|
|
||||||
~AutoPtrHolder();
|
|
||||||
|
|
||||||
|
|
||||||
Ptr Create()
|
|
||||||
{
|
|
||||||
ptr = Ptr( new Impl );
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ptr ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
// don't compile with std::auto_ptr
|
|
||||||
template<class Impl,template<class> class Del>
|
|
||||||
struct AutoPtrHolder<Impl,std::auto_ptr<Impl>,Del>{};
|
|
||||||
|
|
||||||
|
|
||||||
template
|
|
||||||
<
|
|
||||||
class Impl,
|
|
||||||
class Ptr,
|
|
||||||
template<class> class Del,
|
|
||||||
template<class> class ErrorPolicy = ExceptionOnPimplError
|
|
||||||
>
|
|
||||||
struct AutoPtrHolderChecked : AutoPtrHolder<Impl,Ptr,Del>
|
|
||||||
{
|
|
||||||
static bool init_;
|
|
||||||
|
|
||||||
AutoPtrHolderChecked()
|
|
||||||
{
|
|
||||||
init_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
operator T&()
|
|
||||||
{
|
|
||||||
// if this throws change the declaration order
|
|
||||||
// of the DeclaredRimpl construct
|
|
||||||
if(!init_)
|
|
||||||
ErrorPolicy<T>::PimplError();
|
|
||||||
AutoPtrHolder<Impl,Ptr,Del>::Create();
|
|
||||||
return *AutoPtrHolder<Impl,Ptr,Del>::ptr;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template
|
|
||||||
<
|
|
||||||
class Impl,
|
|
||||||
class Ptr,
|
|
||||||
template<class> class Del,
|
|
||||||
template<class> class Err
|
|
||||||
>
|
|
||||||
bool AutoPtrHolderChecked<Impl,Ptr,Del,Err>::init_ = false;
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct HavePtrHolder
|
|
||||||
{
|
|
||||||
T ptr;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// Pimpl usage policies
|
|
||||||
/////////////////////
|
|
||||||
|
|
||||||
template<class Impl, typename Ptr, template<class> class Del>
|
|
||||||
class InheritedPimpl : private
|
|
||||||
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
|
||||||
{
|
|
||||||
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Ptr LOKI_INHERITED_PIMPL_NAME;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
InheritedPimpl() : LOKI_INHERITED_PIMPL_NAME(PtrHolder::ptr.Create())
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
|
||||||
InheritedPimpl& operator=(const InheritedPimpl&);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class Impl, typename Ptr, template<class> class Del>
|
|
||||||
class DeclaredPimpl : private
|
|
||||||
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
|
||||||
{
|
|
||||||
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
|
||||||
|
|
||||||
#if defined(LOKI_DEFAULT_CONSTNESS)
|
|
||||||
typedef typename LOKI_DEFAULT_CONSTNESS<Ptr>::Type ConstPtr;
|
|
||||||
typedef typename LOKI_DEFAULT_CONSTNESS<Impl>::Type ConstImpl;
|
|
||||||
#else // default: enable
|
|
||||||
typedef const Ptr ConstPtr;
|
|
||||||
typedef const Impl ConstImpl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
Ptr operator->()
|
|
||||||
{
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
Impl& operator*()
|
|
||||||
{
|
|
||||||
return *ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstPtr operator->() const
|
|
||||||
{
|
|
||||||
return ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConstImpl& operator*() const
|
|
||||||
{
|
|
||||||
return *ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
DeclaredPimpl() : ptr(PtrHolder::ptr.Create())
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
|
||||||
DeclaredPimpl& operator=(const DeclaredPimpl&);
|
|
||||||
const Ptr ptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// Rimpl usage policies
|
|
||||||
/////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
template<class Impl, typename Ptr, template<class> class Del>
|
|
||||||
class InheritedRimpl : private
|
|
||||||
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
|
||||||
{
|
|
||||||
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Impl& LOKI_INHERITED_RIMPL_NAME;
|
|
||||||
|
|
||||||
protected:
|
|
||||||
InheritedRimpl() :
|
|
||||||
LOKI_INHERITED_RIMPL_NAME(*PtrHolder::ptr.Create())
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
|
||||||
InheritedRimpl& operator=(const InheritedRimpl&);
|
|
||||||
};
|
|
||||||
|
|
||||||
template<class Impl, typename PointerPolicy, template<class> class DeletePolicy>
|
|
||||||
class DeclaredRimpl : public Impl
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
DeclaredRimpl()
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// Wrapper for "pointer to implementation" alias pimpl.
|
|
||||||
// Impl: implementation class
|
|
||||||
// PointerTypePolicy: arbitrary pointer implementation
|
|
||||||
// DeletePolicy: delete implementation object on destruction of PtrImpl
|
|
||||||
// UsagePolicy: how to access the stored pointer, as pointer, checked, unchecked
|
|
||||||
/////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
template
|
|
||||||
<
|
|
||||||
class Impl,
|
|
||||||
class PointerPolicy = Impl*,
|
|
||||||
template<class> class DeletePolicy = AutoDeletePimpl,
|
|
||||||
template<class,class,template<class> class> class UsagePolicy = InheritedPimpl
|
|
||||||
>
|
|
||||||
class PtrImpl : public UsagePolicy<Impl,PointerPolicy,DeletePolicy>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
typedef Impl ImplType;
|
|
||||||
typedef PointerPolicy PointerType;
|
|
||||||
|
|
||||||
PtrImpl() : UsagePolicy<Impl,PointerPolicy,DeletePolicy>()
|
|
||||||
{}
|
|
||||||
|
|
||||||
private:
|
|
||||||
PtrImpl& operator=(const PtrImpl&);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
|
||||||
// Predefined convenience "templated typedef"
|
|
||||||
/////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct Pimpl
|
|
||||||
{
|
|
||||||
// declare pimpl
|
// declare pimpl
|
||||||
typedef PtrImpl
|
typedef Pimpl<ImplT<T>, Ptr<ImplT<T> > > Type;
|
||||||
<
|
|
||||||
Impl<T>,
|
|
||||||
Impl<T>*,
|
|
||||||
AutoDeletePimpl,
|
|
||||||
DeclaredPimpl
|
|
||||||
>
|
|
||||||
Type;
|
|
||||||
|
|
||||||
// inherit pimpl
|
// inherit pimpl
|
||||||
typedef PtrImpl
|
typedef PimplOwner<ImplT<T>, Ptr<ImplT<T> > > Owner;
|
||||||
<
|
};
|
||||||
Impl<T>,
|
|
||||||
Impl<T>*,
|
|
||||||
AutoDeletePimpl,
|
|
||||||
InheritedPimpl
|
|
||||||
>
|
|
||||||
Owner;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T, class UsedPimpl = typename PimplT<T>::Type >
|
||||||
struct Rimpl
|
struct RimplT
|
||||||
{
|
{
|
||||||
|
typedef typename UsedPimpl::Impl & Type;
|
||||||
|
|
||||||
// declare rimpl
|
class Owner
|
||||||
typedef PtrImpl
|
{
|
||||||
<
|
UsedPimpl pimpl;
|
||||||
Impl<T>,
|
|
||||||
Impl<T>*,
|
|
||||||
DontDeletePimpl,
|
|
||||||
DeclaredRimpl
|
|
||||||
>
|
|
||||||
Ptr;
|
|
||||||
|
|
||||||
// init declared rimpl
|
public:
|
||||||
typedef Private::AutoPtrHolderChecked
|
Owner() : LOKI_INHERITED_RIMPL_NAME(*pimpl)
|
||||||
<
|
{}
|
||||||
Ptr,
|
|
||||||
Ptr*,
|
|
||||||
AutoDeletePimpl
|
|
||||||
>
|
|
||||||
Init;
|
|
||||||
|
|
||||||
typedef Ptr & Type;
|
Type LOKI_INHERITED_RIMPL_NAME;
|
||||||
|
};
|
||||||
|
|
||||||
// inherit rimpl
|
|
||||||
typedef PtrImpl
|
|
||||||
<
|
|
||||||
Impl<T>,
|
|
||||||
Impl<T>*,
|
|
||||||
AutoDeletePimpl,
|
|
||||||
InheritedRimpl
|
|
||||||
>
|
|
||||||
Owner;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.15 2006/01/28 20:12:56 syntheticpp
|
||||||
|
// replace implementation with a auto-create and propagating-const wrapper for smart pointers which auto delete the holded pointer on destruction
|
||||||
|
//
|
||||||
// Revision 1.14 2006/01/26 14:28:59 syntheticpp
|
// Revision 1.14 2006/01/26 14:28:59 syntheticpp
|
||||||
// remove wrong 'typename'
|
// remove wrong 'typename'
|
||||||
//
|
//
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// The Loki Library
|
|
||||||
// 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 author makes no representations about the
|
|
||||||
// suitability of this software for any purpose. It is provided "as is"
|
|
||||||
// without express or implied warranty.
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
#ifndef LOKI_PIMPLDEF_H
|
|
||||||
#define LOKI_PIMPLDEF_H
|
|
||||||
|
|
||||||
namespace Loki
|
|
||||||
{
|
|
||||||
namespace Private
|
|
||||||
{
|
|
||||||
template
|
|
||||||
<
|
|
||||||
class Impl,
|
|
||||||
class Ptr,
|
|
||||||
template<class> class Del
|
|
||||||
>
|
|
||||||
AutoPtrHolder<Impl,Ptr,Del>::~AutoPtrHolder()
|
|
||||||
{
|
|
||||||
Del<Ptr>::Destroy( ptr );
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// $Log:
|
|
||||||
|
|
|
@ -226,10 +226,6 @@
|
||||||
RelativePath="..\..\include\loki\Pimpl.h"
|
RelativePath="..\..\include\loki\Pimpl.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath="..\..\include\loki\PimplDef.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\include\loki\SafeFormat.h"
|
RelativePath="..\..\include\loki\SafeFormat.h"
|
||||||
>
|
>
|
||||||
|
|
|
@ -24,19 +24,19 @@
|
||||||
#include "type2.h"
|
#include "type2.h"
|
||||||
|
|
||||||
#include <loki/SafeFormat.h>
|
#include <loki/SafeFormat.h>
|
||||||
#include <loki/PimplDef.h>
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Definition of Impl<A>
|
// Definition of ImplT<A>
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
namespace Loki // gcc!!
|
namespace Loki // gcc!!
|
||||||
{
|
{
|
||||||
template<>
|
template<>
|
||||||
struct Impl<A> : public SmallObject<> // inherit SmallObj for speed up
|
struct ImplT<A> : public SmallObject<> // inherit SmallObj for speed up
|
||||||
{
|
{
|
||||||
Impl() : data(0) {Printf("A created\n");}
|
ImplT() : data(0) {Printf("A created\n");}
|
||||||
~Impl(){Printf("A destroyed, data=%d\n")(data);}
|
~ImplT(){Printf("A destroyed, data=%d\n")(data);}
|
||||||
int data;
|
int data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -54,22 +54,22 @@ void A::foo()
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Definition of Impl<B>
|
// Definition of ImplT<B>
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
namespace Loki // gcc!!
|
namespace Loki // gcc!!
|
||||||
{
|
{
|
||||||
template<>
|
template<>
|
||||||
struct Impl<B> : public SmallObject<> // inherit SmallObj for speed up
|
struct ImplT<B> : public SmallObject<> // inherit SmallObj for speed up
|
||||||
{
|
{
|
||||||
Impl() : data(0) {Printf("B created\n");}
|
ImplT() : data(0) {Printf("B created\n");}
|
||||||
~Impl(){Printf("B destroyed, data=%d\n")(data);}
|
~ImplT(){Printf("B destroyed, data=%d\n")(data);}
|
||||||
int data;
|
int data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// class B definition
|
// class B definition
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
B::B() : Loki::Pimpl<B>::Owner()
|
B::B() : Loki::PimplT<B>::Owner()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void B::foo()
|
void B::foo()
|
||||||
|
@ -80,22 +80,22 @@ void B::foo()
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Definition of Impl<C>
|
// Definition of ImplT<C>
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
namespace Loki // gcc!!
|
namespace Loki // gcc!!
|
||||||
{
|
{
|
||||||
template<>
|
template<>
|
||||||
struct Impl<C> : public SmallObject<> // inherit SmallObj for speed up
|
struct ImplT<C> : public SmallObject<> // inherit SmallObj for speed up
|
||||||
{
|
{
|
||||||
Impl(): data(0) {Printf("C created\n");}
|
ImplT(): data(0) {Printf("C created\n");}
|
||||||
~Impl(){Printf("C destroyed, data=%d\n")(data);}
|
~ImplT(){Printf("C destroyed, data=%d\n")(data);}
|
||||||
int data;
|
int data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// class C definition
|
// class C definition
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
C::C() : d(rinit)
|
C::C() : p(), d(*p)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void C::foo()
|
void C::foo()
|
||||||
|
@ -106,22 +106,23 @@ void C::foo()
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Definition of Impl<D>
|
// Definition of ImplT<D>
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
namespace Loki // gcc!!
|
namespace Loki // gcc!!
|
||||||
{
|
{
|
||||||
template<>
|
template<>
|
||||||
struct Impl<D> : public SmallObject<> // inherit SmallObj for speed up
|
struct ImplT<D> : public SmallObject<> // inherit SmallObj for speed up
|
||||||
{
|
{
|
||||||
Impl(): data(0) {Printf("D created\n");}
|
ImplT(): data(0) {Printf("D created\n");}
|
||||||
~Impl(){Printf("D destroyed, data=%d\n")(data);}
|
~ImplT(){Printf("D destroyed, data=%d\n")(data);}
|
||||||
int data;
|
int data;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// class D definition
|
// class D definition
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
D::D() : Loki::Rimpl<D>::Owner()
|
D::D() : Loki::RimplT<D>::Owner()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void D::foo()
|
void D::foo()
|
||||||
|
@ -133,45 +134,11 @@ void D::foo()
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// main
|
// main
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
|
||||||
void test_more();
|
void test_more();
|
||||||
|
|
||||||
//#define MSVC_DETECT_MEMORY_LEAKS
|
|
||||||
#ifdef MSVC_DETECT_MEMORY_LEAKS
|
|
||||||
|
|
||||||
#include <crtdbg.h>
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
void heap_debug()
|
|
||||||
{
|
|
||||||
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
|
|
||||||
|
|
||||||
// Turn on leak-checking bit
|
|
||||||
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
|
|
||||||
|
|
||||||
//tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
|
|
||||||
|
|
||||||
// Turn off CRT block checking bit
|
|
||||||
tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
|
|
||||||
|
|
||||||
// Set flag to the new value
|
|
||||||
_CrtSetDbgFlag( tmpFlag );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
void heap_debug()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
heap_debug();
|
|
||||||
|
|
||||||
A* a = new A;
|
A* a = new A;
|
||||||
B* b = new B;
|
B* b = new B;
|
||||||
C* c = new C;
|
C* c = new C;
|
||||||
|
@ -200,15 +167,15 @@ int main()
|
||||||
////////////////////
|
////////////////////
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// Definition of Impl<E>
|
// Definition of ImplT<E>
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
namespace Loki // gcc!!
|
namespace Loki // gcc!!
|
||||||
{
|
{
|
||||||
template<>
|
template<>
|
||||||
struct Impl<E> : public SmallObject<> // inherit SmallObj for speed up
|
struct ImplT<E> : public SmallObject<> // inherit SmallObj for speed up
|
||||||
{
|
{
|
||||||
Impl() : data(0) {Printf("E created\n");}
|
ImplT() : data(0) {Printf("E created\n");}
|
||||||
~Impl(){Printf("E destroyed, data=%d\n")(data);}
|
~ImplT(){Printf("E destroyed, data=%d\n")(data);}
|
||||||
int data;
|
int data;
|
||||||
|
|
||||||
void foo() {Printf("E foo() \n");}
|
void foo() {Printf("E foo() \n");}
|
||||||
|
@ -223,43 +190,77 @@ P2::P2(){d->data = 2;}
|
||||||
P3::P3(){d->data = 3;}
|
P3::P3(){d->data = 3;}
|
||||||
P4::P4(){d->data = 4;}
|
P4::P4(){d->data = 4;}
|
||||||
P5::P5(){d->data = 5;}
|
P5::P5(){d->data = 5;}
|
||||||
P6::P6(){d->data = 6;}
|
|
||||||
|
PO1::PO1(){d->data = 6;}
|
||||||
|
PO2::PO2(){d->data = 7;}
|
||||||
|
PO3::PO3(){d->data = 8;}
|
||||||
|
PO4::PO4(){d->data = 9;}
|
||||||
|
PO5::PO5(){d->data = 10;}
|
||||||
|
|
||||||
void P1::f(){d->foo();}
|
void P1::f(){d->foo();}
|
||||||
void P2::f(){d->foo();}
|
void P2::f(){d->foo();}
|
||||||
void P3::f(){d->foo();}
|
void P3::f(){d->foo();}
|
||||||
void P4::f(){d->foo();}
|
void P4::f(){d->foo();}
|
||||||
void P5::f(){d->foo();}
|
void P5::f(){d->foo();}
|
||||||
void P6::f(){d->foo();}
|
|
||||||
|
void PO1::f(){d->foo();}
|
||||||
|
void PO2::f(){d->foo();}
|
||||||
|
void PO3::f(){d->foo();}
|
||||||
|
void PO4::f(){d->foo();}
|
||||||
|
void PO5::f(){d->foo();}
|
||||||
|
|
||||||
void P1::f()const{d->foo();}
|
void P1::f()const{d->foo();}
|
||||||
void P2::f()const{d->foo();}
|
void P2::f()const{d->foo();}
|
||||||
void P3::f()const{d->foo();}
|
void P3::f()const{d->foo();}
|
||||||
void P4::f()const{d->foo();}
|
void P4::f()const{d->foo();}
|
||||||
void P5::f()const{d->foo();}
|
void P5::f()const{d->foo();}
|
||||||
void P6::f()const{d->foo();}
|
|
||||||
|
void PO1::f()const{d->foo();}
|
||||||
|
void PO2::f()const{d->foo();}
|
||||||
|
void PO3::f()const{d->foo();}
|
||||||
|
void PO4::f()const{d->foo();}
|
||||||
|
void PO5::f()const{d->foo();}
|
||||||
|
|
||||||
|
|
||||||
R1::R1(){d.data = 11;}
|
|
||||||
R2::R2(){d.data = 22;}
|
|
||||||
R3::R3(){d.data = 33;}
|
R1::R1():d(*p){d.data = 11;}
|
||||||
R4::R4():d(rinit){d.data = 44;}
|
R2::R2():d(*p){d.data = 22;}
|
||||||
R5::R5():d(rinit){d.data = 55;}
|
R3::R3():d(*p){d.data = 33;}
|
||||||
R6::R6():d(rinit){d.data = 66;}
|
R4::R4():d(*p){d.data = 44;}
|
||||||
|
R5::R5():d(*p){d.data = 55;}
|
||||||
|
|
||||||
void R1::f(){d.foo();}
|
void R1::f(){d.foo();}
|
||||||
void R2::f(){d.foo();}
|
void R2::f(){d.foo();}
|
||||||
void R3::f(){d.foo();}
|
void R3::f(){d.foo();}
|
||||||
void R4::f(){d.foo();}
|
void R4::f(){d.foo();}
|
||||||
void R5::f(){d.foo();}
|
void R5::f(){d.foo();}
|
||||||
void R6::f(){d.foo();}
|
|
||||||
|
|
||||||
void R1::f()const{d.foo();}
|
void R1::f()const{d.foo();}
|
||||||
void R2::f()const{d.foo();}
|
void R2::f()const{d.foo();}
|
||||||
void R3::f()const{d.foo();}
|
void R3::f()const{d.foo();}
|
||||||
void R4::f()const{d.foo();}
|
void R4::f()const{d.foo();}
|
||||||
void R5::f()const{d.foo();}
|
void R5::f()const{d.foo();}
|
||||||
void R6::f()const{d.foo();}
|
|
||||||
|
|
||||||
|
|
||||||
|
RO1::RO1(){d.data = 66;}
|
||||||
|
RO2::RO2(){d.data = 77;}
|
||||||
|
RO3::RO3(){d.data = 88;}
|
||||||
|
RO4::RO4(){d.data = 99;}
|
||||||
|
RO5::RO5(){d.data = 1010;}
|
||||||
|
|
||||||
|
void RO1::f(){d.foo();}
|
||||||
|
void RO2::f(){d.foo();}
|
||||||
|
void RO3::f(){d.foo();}
|
||||||
|
void RO4::f(){d.foo();}
|
||||||
|
void RO5::f(){d.foo();}
|
||||||
|
|
||||||
|
void RO1::f()const{d.foo();}
|
||||||
|
void RO2::f()const{d.foo();}
|
||||||
|
void RO3::f()const{d.foo();}
|
||||||
|
void RO4::f()const{d.foo();}
|
||||||
|
void RO5::f()const{d.foo();}
|
||||||
|
|
||||||
|
|
||||||
void test_more()
|
void test_more()
|
||||||
|
@ -267,12 +268,16 @@ void test_more()
|
||||||
Loki::Printf("\n\nMore tests:\n");
|
Loki::Printf("\n\nMore tests:\n");
|
||||||
|
|
||||||
Loki::Printf("\nCreating Pimpls\n");
|
Loki::Printf("\nCreating Pimpls\n");
|
||||||
P1* p1 = new P1;
|
P1* p1 = new P1;
|
||||||
P2* p2 = new P2;
|
P2* p2 = new P2;
|
||||||
P3* p3 = new P3;
|
P3* p3 = new P3;
|
||||||
P4* p4 = new P4;
|
P4* p4 = new P4;
|
||||||
P5* p5 = new P5;
|
P5* p5 = new P5;
|
||||||
P6* p6 = new P6;
|
PO1* p6 = new PO1;
|
||||||
|
PO2* p7 = new PO2;
|
||||||
|
PO3* p8 = new PO3;
|
||||||
|
PO4* p9 = new PO4;
|
||||||
|
PO5* p10 = new PO5;
|
||||||
|
|
||||||
Loki::Printf("\nConst check\n");
|
Loki::Printf("\nConst check\n");
|
||||||
p1->f();
|
p1->f();
|
||||||
|
@ -280,7 +285,11 @@ void test_more()
|
||||||
p3->f();
|
p3->f();
|
||||||
p4->f();
|
p4->f();
|
||||||
p5->f();
|
p5->f();
|
||||||
p6->f();
|
p6->f();
|
||||||
|
p7->f();
|
||||||
|
p8->f();
|
||||||
|
p9->f();
|
||||||
|
p10->f();
|
||||||
|
|
||||||
Loki::Printf("\nDeleting Pimpls\n");
|
Loki::Printf("\nDeleting Pimpls\n");
|
||||||
delete p1;
|
delete p1;
|
||||||
|
@ -289,6 +298,11 @@ void test_more()
|
||||||
delete p4;
|
delete p4;
|
||||||
delete p5;
|
delete p5;
|
||||||
delete p6;
|
delete p6;
|
||||||
|
delete p7;
|
||||||
|
delete p8;
|
||||||
|
delete p9;
|
||||||
|
delete p10;
|
||||||
|
|
||||||
|
|
||||||
Loki::Printf("\nCreating Rimpls\n");
|
Loki::Printf("\nCreating Rimpls\n");
|
||||||
R1* r1 = new R1;
|
R1* r1 = new R1;
|
||||||
|
@ -296,15 +310,23 @@ void test_more()
|
||||||
R3* r3 = new R3;
|
R3* r3 = new R3;
|
||||||
R4* r4 = new R4;
|
R4* r4 = new R4;
|
||||||
R5* r5 = new R5;
|
R5* r5 = new R5;
|
||||||
R6* r6 = new R6;
|
|
||||||
|
|
||||||
Loki::Printf("\nConst check\n");
|
RO1* r6 = new RO1;
|
||||||
r1->f();
|
RO2* r7 = new RO2;
|
||||||
|
RO3* r8 = new RO3;
|
||||||
|
RO4* r9 = new RO4;
|
||||||
|
RO5* r10 = new RO5;
|
||||||
|
|
||||||
|
r1->f();
|
||||||
r2->f();
|
r2->f();
|
||||||
r3->f();
|
r3->f();
|
||||||
r4->f();
|
r4->f();
|
||||||
r5->f();
|
r5->f();
|
||||||
r6->f();
|
r6->f();
|
||||||
|
r7->f();
|
||||||
|
r8->f();
|
||||||
|
r9->f();
|
||||||
|
r10->f();
|
||||||
|
|
||||||
Loki::Printf("\nDeleting Rimpls\n");
|
Loki::Printf("\nDeleting Rimpls\n");
|
||||||
delete r1;
|
delete r1;
|
||||||
|
@ -313,14 +335,24 @@ void test_more()
|
||||||
delete r4;
|
delete r4;
|
||||||
delete r5;
|
delete r5;
|
||||||
delete r6;
|
delete r6;
|
||||||
|
delete r7;
|
||||||
|
delete r8;
|
||||||
|
delete r9;
|
||||||
|
delete r10;
|
||||||
|
|
||||||
Loki::Printf("\nCreating Pimpls\n");
|
|
||||||
|
Loki::Printf("\nCreating const Pimpls\n");
|
||||||
const P1* cp1 = new P1;
|
const P1* cp1 = new P1;
|
||||||
const P2* cp2 = new P2;
|
const P2* cp2 = new P2;
|
||||||
const P3* cp3 = new P3;
|
const P3* cp3 = new P3;
|
||||||
const P4* cp4 = new P4;
|
const P4* cp4 = new P4;
|
||||||
const P5* cp5 = new P5;
|
const P5* cp5 = new P5;
|
||||||
const P6* cp6 = new P6;
|
|
||||||
|
const PO1* cp6 = new PO1;
|
||||||
|
const PO2* cp7 = new PO2;
|
||||||
|
const PO3* cp8 = new PO3;
|
||||||
|
const PO4* cp9 = new PO4;
|
||||||
|
const PO5* cp10 = new PO5;
|
||||||
|
|
||||||
Loki::Printf("\nConst check\n");
|
Loki::Printf("\nConst check\n");
|
||||||
cp1->f();
|
cp1->f();
|
||||||
|
@ -329,38 +361,20 @@ void test_more()
|
||||||
cp4->f();
|
cp4->f();
|
||||||
cp5->f();
|
cp5->f();
|
||||||
cp6->f();
|
cp6->f();
|
||||||
|
cp7->f();
|
||||||
|
cp8->f();
|
||||||
|
cp9->f();
|
||||||
|
cp10->f();
|
||||||
|
|
||||||
Loki::Printf("\nDeleting Rimpls\n");
|
Loki::Printf("\nDeleting const Pimpls\n");
|
||||||
delete cp1;
|
delete cp1;
|
||||||
delete cp2;
|
delete cp2;
|
||||||
delete cp3;
|
delete cp3;
|
||||||
delete cp4;
|
delete cp4;
|
||||||
delete cp5;
|
delete cp5;
|
||||||
delete cp6;
|
delete cp6;
|
||||||
|
delete cp7;
|
||||||
|
delete cp8;
|
||||||
Loki::Printf("\nCreating Rimpls\n");
|
delete cp9;
|
||||||
const R1* cr1 = new R1;
|
delete cp10;
|
||||||
const R2* cr2 = new R2;
|
|
||||||
const R3* cr3 = new R3;
|
|
||||||
const R4* cr4 = new R4;
|
|
||||||
const R5* cr5 = new R5;
|
|
||||||
const R6* cr6 = new R6;
|
|
||||||
|
|
||||||
Loki::Printf("\nConst check\n");
|
|
||||||
cr1->f();
|
|
||||||
cr2->f();
|
|
||||||
cr3->f();
|
|
||||||
cr4->f();
|
|
||||||
cr5->f();
|
|
||||||
cr6->f();
|
|
||||||
|
|
||||||
Loki::Printf("\nDeleting Rimpls\n");
|
|
||||||
delete cr1;
|
|
||||||
delete cr2;
|
|
||||||
delete cr3;
|
|
||||||
delete cr4;
|
|
||||||
delete cr5;
|
|
||||||
delete cr6;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,9 +12,6 @@
|
||||||
|
|
||||||
// $Header:
|
// $Header:
|
||||||
|
|
||||||
//#define LOKI_DEFAULT_CONSTNESS DeepConstness //default
|
|
||||||
//#define LOKI_DEFAULT_CONSTNESS FlatConstness
|
|
||||||
|
|
||||||
#include <loki/Pimpl.h>
|
#include <loki/Pimpl.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,12 +19,11 @@
|
||||||
#ifdef TEST_WITH_BOOST
|
#ifdef TEST_WITH_BOOST
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <loki/SmartPtr.h>
|
#include <loki/SmartPtr.h>
|
||||||
#include <loki/SmallObj.h>
|
#include <loki/SmallObj.h>
|
||||||
|
|
||||||
using Loki::Pimpl;
|
using namespace Loki;
|
||||||
using Loki::Rimpl;
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// class A declaration
|
// class A declaration
|
||||||
|
@ -40,7 +36,7 @@ public:
|
||||||
void foo();
|
void foo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pimpl<A>::Type d;
|
PimplT<A>::Type d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,7 +44,7 @@ private:
|
||||||
// class B declaration
|
// class B declaration
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
|
||||||
class B : private Pimpl<B>::Owner
|
class B : private PimplT<B>::Owner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
B();
|
B();
|
||||||
|
@ -67,8 +63,8 @@ public:
|
||||||
void foo();
|
void foo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Rimpl<C>::Init rinit;
|
PimplT<C>::Type p;
|
||||||
Rimpl<C>::Type d;
|
RimplT<C>::Type d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,7 +72,7 @@ private:
|
||||||
// class D declaration
|
// class D declaration
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
|
||||||
class D : private Rimpl<D>::Owner
|
class D : private RimplT<D>::Owner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
D();
|
D();
|
||||||
|
@ -92,190 +88,78 @@ public:
|
||||||
|
|
||||||
struct E;
|
struct E;
|
||||||
|
|
||||||
|
typedef SmartPtr<ImplT<E> > LokiPtr;
|
||||||
|
typedef ConstPropPtr<ImplT<E> > CPropPtr;
|
||||||
|
typedef std::auto_ptr<ImplT<E> > StdAutoPtr;
|
||||||
|
|
||||||
|
#ifdef TEST_WITH_BOOST
|
||||||
|
typedef boost::shared_ptr<ImplT<E> > BoostPtr;
|
||||||
|
#else
|
||||||
|
typedef LokiPtr BoostPtr;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Pimpl
|
// Pimpl
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
typedef Pimpl<ImplT<E> > Pimpl1;
|
||||||
<
|
typedef Pimpl<ImplT<E>, CPropPtr> Pimpl2;
|
||||||
Loki::Impl<E>
|
typedef Pimpl<ImplT<E>, LokiPtr> Pimpl3;
|
||||||
>
|
typedef Pimpl<ImplT<E>, BoostPtr> Pimpl4;
|
||||||
Pimpl1;
|
typedef Pimpl<ImplT<E>, StdAutoPtr> Pimpl5;
|
||||||
|
|
||||||
|
struct P1 {Pimpl1 d; P1();void f();void f()const;};
|
||||||
|
struct P2 {Pimpl2 d; P2();void f();void f()const;};
|
||||||
|
struct P3 {Pimpl3 d; P3();void f();void f()const;};
|
||||||
|
struct P4 {Pimpl4 d; P4();void f();void f()const;};
|
||||||
|
struct P5 {Pimpl5 d; P5();void f();void f()const;};
|
||||||
|
|
||||||
|
|
||||||
|
// PimplOwner
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
typedef PimplOwner<ImplT<E> > PimplOwner1;
|
||||||
<
|
typedef PimplOwner<ImplT<E>, CPropPtr> PimplOwner2;
|
||||||
Loki::Impl<E>,
|
typedef PimplOwner<ImplT<E>, LokiPtr> PimplOwner3;
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
typedef PimplOwner<ImplT<E>, BoostPtr> PimplOwner4;
|
||||||
Loki::DontDeletePimpl
|
typedef PimplOwner<ImplT<E>, StdAutoPtr>PimplOwner5;
|
||||||
>
|
|
||||||
Pimpl2;
|
|
||||||
|
|
||||||
|
struct PO1 : private PimplOwner1 {PO1();void f();void f()const;};
|
||||||
|
struct PO2 : private PimplOwner2 {PO2();void f();void f()const;};
|
||||||
|
struct PO3 : private PimplOwner3 {PO3();void f();void f()const;};
|
||||||
|
struct PO4 : private PimplOwner4 {PO4();void f();void f()const;};
|
||||||
|
struct PO5 : private PimplOwner5 {PO5();void f();void f()const;};
|
||||||
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
#ifdef TEST_WITH_BOOST
|
|
||||||
boost::shared_ptr<Loki::Impl<E> >,
|
|
||||||
#else
|
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
|
||||||
#endif
|
|
||||||
Loki::DontDeletePimpl
|
|
||||||
>
|
|
||||||
Pimpl3;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
|
||||||
Loki::DontDeletePimpl,
|
|
||||||
Loki::DeclaredPimpl
|
|
||||||
>
|
|
||||||
Pimpl4;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
#ifdef TEST_WITH_BOOST
|
|
||||||
boost::shared_ptr<Loki::Impl<E> >,
|
|
||||||
#else
|
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
|
||||||
#endif
|
|
||||||
Loki::DontDeletePimpl,
|
|
||||||
Loki::DeclaredPimpl
|
|
||||||
>
|
|
||||||
Pimpl5;
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
Loki::Impl<E>*,
|
|
||||||
Loki::AutoDeletePimpl,
|
|
||||||
Loki::DeclaredPimpl
|
|
||||||
>
|
|
||||||
Pimpl6;
|
|
||||||
|
|
||||||
|
|
||||||
// Rimpl
|
// Rimpl
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
typedef RimplT<ImplT<E>,Pimpl1> Rimpl1;
|
||||||
<
|
typedef RimplT<ImplT<E>,Pimpl2> Rimpl2;
|
||||||
Loki::Impl<E>,
|
typedef RimplT<ImplT<E>,Pimpl3> Rimpl3;
|
||||||
Loki::Impl<E>*,
|
typedef RimplT<ImplT<E>,Pimpl4> Rimpl4;
|
||||||
Loki::AutoDeletePimpl,
|
typedef RimplT<ImplT<E>,Pimpl5> Rimpl5;
|
||||||
Loki::InheritedRimpl
|
|
||||||
|
|
||||||
>
|
struct R1 {Pimpl1 p; Rimpl1::Type d; R1();void f();void f()const;};
|
||||||
Rimpl1;
|
struct R2 {Pimpl2 p; Rimpl2::Type d; R2();void f();void f()const;};
|
||||||
|
struct R3 {Pimpl3 p; Rimpl3::Type d; R3();void f();void f()const;};
|
||||||
|
struct R4 {Pimpl4 p; Rimpl4::Type d; R4();void f();void f()const;};
|
||||||
|
struct R5 {Pimpl5 p; Rimpl5::Type d; R5();void f();void f()const;};
|
||||||
|
|
||||||
|
|
||||||
|
// RimplOwner
|
||||||
|
|
||||||
|
typedef RimplT<ImplT<E>,Pimpl1>::Owner RimplO1;
|
||||||
|
typedef RimplT<ImplT<E>,Pimpl2>::Owner RimplO2;
|
||||||
|
typedef RimplT<ImplT<E>,Pimpl3>::Owner RimplO3;
|
||||||
|
typedef RimplT<ImplT<E>,Pimpl4>::Owner RimplO4;
|
||||||
|
typedef RimplT<ImplT<E>,Pimpl5>::Owner RimplO5;
|
||||||
|
|
||||||
|
struct RO1 : private RimplO1 {RO1();void f();void f()const;};
|
||||||
|
struct RO2 : private RimplO2 {RO2();void f();void f()const;};
|
||||||
|
struct RO3 : private RimplO3 {RO3();void f();void f()const;};
|
||||||
|
struct RO4 : private RimplO4 {RO4();void f();void f()const;};
|
||||||
|
struct RO5 : private RimplO5 {RO5();void f();void f()const;};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
|
||||||
Loki::DontDeletePimpl,
|
|
||||||
Loki::InheritedRimpl
|
|
||||||
>
|
|
||||||
Rimpl2;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
#ifdef TEST_WITH_BOOST
|
|
||||||
boost::shared_ptr<Loki::Impl<E> >,
|
|
||||||
#else
|
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
|
||||||
#endif
|
|
||||||
Loki::DontDeletePimpl,
|
|
||||||
Loki::InheritedRimpl
|
|
||||||
>
|
|
||||||
Rimpl3;
|
|
||||||
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
Loki::Impl<E>*,
|
|
||||||
Loki::AutoDeletePimpl,
|
|
||||||
Loki::DeclaredRimpl
|
|
||||||
>
|
|
||||||
Rimpl4;
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
|
||||||
Loki::DontDeletePimpl,
|
|
||||||
Loki::DeclaredRimpl
|
|
||||||
>
|
|
||||||
Rimpl5;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
#ifdef TEST_WITH_BOOST
|
|
||||||
boost::shared_ptr<Loki::Impl<E> >,
|
|
||||||
#else
|
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
|
||||||
#endif
|
|
||||||
Loki::DontDeletePimpl,
|
|
||||||
Loki::DeclaredRimpl
|
|
||||||
>
|
|
||||||
Rimpl6;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef Loki::PtrImpl
|
|
||||||
<
|
|
||||||
Loki::Impl<E>,
|
|
||||||
|
|
||||||
//Loki::Impl<E>*,
|
|
||||||
Loki::SmartPtr<Loki::Impl<E> >,
|
|
||||||
//boost::shared_ptr<Loki::Impl<E> >,
|
|
||||||
|
|
||||||
//Loki::AutoDeletePimpl, // compiler error when used with smart pointers, this is o.k.
|
|
||||||
Loki::DontDeletePimpl,
|
|
||||||
|
|
||||||
Loki::DeclaredPimpl
|
|
||||||
//Loki::InheritedPimpl,
|
|
||||||
>
|
|
||||||
Pimpl8;
|
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
|
||||||
struct R
|
|
||||||
{
|
|
||||||
typedef Loki::Private::AutoPtrHolderChecked
|
|
||||||
<
|
|
||||||
T,
|
|
||||||
T*,
|
|
||||||
Loki::AutoDeletePimpl
|
|
||||||
>
|
|
||||||
Init;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct P1 : private Pimpl1 {P1();void f();void f()const;};
|
|
||||||
struct P2 : private Pimpl2 {P2();void f();void f()const;};
|
|
||||||
struct P3 : private Pimpl3 {P3();void f();void f()const;};
|
|
||||||
struct P4 {Pimpl4 d; P4();void f();void f()const;};
|
|
||||||
struct P5 {Pimpl5 d; P5();void f();void f()const;};
|
|
||||||
struct P6 {Pimpl6 d; P6();void f();void f()const;};
|
|
||||||
|
|
||||||
struct R1 : private Rimpl1 {R1();void f();void f()const;};
|
|
||||||
struct R2 : private Rimpl2 {R2();void f();void f()const;};
|
|
||||||
struct R3 : private Rimpl3 {R3();void f();void f()const;};
|
|
||||||
struct R4 {R<Rimpl4>::Init rinit; Rimpl4& d; R4();void f();void f()const;};
|
|
||||||
struct R5 {R<Rimpl5>::Init rinit; Rimpl5& d; R5();void f();void f()const;};
|
|
||||||
struct R6 {R<Rimpl6>::Init rinit; Rimpl6& d; R6();void f();void f()const;};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,6 @@
|
||||||
|
|
||||||
#include <loki/Pimpl.h>
|
#include <loki/Pimpl.h>
|
||||||
|
|
||||||
using Loki::Pimpl;
|
|
||||||
using Loki::Rimpl;
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// class A2 declaration
|
// class A2 declaration
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
@ -30,7 +26,7 @@ public:
|
||||||
void foo();
|
void foo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pimpl<A2>::Type d;
|
PimplT<A2> d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,7 +34,7 @@ private:
|
||||||
// class B2 declaration
|
// class B2 declaration
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
|
||||||
class B2 : private Pimpl<B2>::Owner
|
class B2 : private PimplT<B2>::Owner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
B2();
|
B2();
|
||||||
|
@ -46,6 +42,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
// class C2 declaration
|
// class C2 declaration
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
@ -57,8 +54,8 @@ public:
|
||||||
void foo();
|
void foo();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Rimpl<C2>::Init rint;
|
PimplT<C2>::Type rint;
|
||||||
Rimpl<C2>::Type d;
|
RimplT<C2>::Type d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,10 +63,9 @@ private:
|
||||||
// class D2 declaration
|
// class D2 declaration
|
||||||
/////////////////////////////////////////
|
/////////////////////////////////////////
|
||||||
|
|
||||||
class D2 : private Rimpl<D2>::Owner
|
class D2 : private RimplT<D2>::Owner
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
D2();
|
D2();
|
||||||
void foo();
|
void foo();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue