replace tabs
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@480 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
47e962d64b
commit
c69cdedf2e
2 changed files with 70 additions and 70 deletions
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
namespace Loki
|
namespace Loki
|
||||||
{
|
{
|
||||||
/////////////////////
|
/////////////////////
|
||||||
// template for the implementations
|
// template for the implementations
|
||||||
/////////////////////
|
/////////////////////
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -45,12 +45,12 @@ namespace Loki
|
||||||
struct AutoDeletePimpl
|
struct AutoDeletePimpl
|
||||||
{
|
{
|
||||||
static void Destroy(T ptr)
|
static void Destroy(T ptr)
|
||||||
{
|
{
|
||||||
typedef char T_must_be_defined[
|
typedef char T_must_be_defined[
|
||||||
sizeof(typename TypeTraits<T>::PointeeType) ? 1 : -1 ];
|
sizeof(typename TypeTraits<T>::PointeeType) ? 1 : -1 ];
|
||||||
delete ptr;
|
delete ptr;
|
||||||
ptr = 0;
|
ptr = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -65,41 +65,41 @@ namespace Loki
|
||||||
// Helper class AutoPtrHolder to manage pimpl lifetime
|
// Helper class AutoPtrHolder to manage pimpl lifetime
|
||||||
/////////////////////
|
/////////////////////
|
||||||
|
|
||||||
namespace Private
|
namespace Private
|
||||||
|
|
||||||
{
|
{
|
||||||
template
|
template
|
||||||
<
|
<
|
||||||
class Impl,
|
class Impl,
|
||||||
class Ptr,
|
class Ptr,
|
||||||
template<class> class Del
|
template<class> class Del
|
||||||
>
|
>
|
||||||
struct AutoPtrHolder
|
struct AutoPtrHolder
|
||||||
{
|
{
|
||||||
AutoPtrHolder() //: ptr(Ptr()) this owerwrites the pointer to PtrImpl
|
AutoPtrHolder() //: ptr(Ptr()) this owerwrites the pointer to PtrImpl
|
||||||
{} // when using DeclaredRimpl!!
|
{} // when using DeclaredRimpl!!
|
||||||
|
|
||||||
~AutoPtrHolder()
|
~AutoPtrHolder()
|
||||||
{
|
{
|
||||||
// delete automatically by the delete policy
|
// delete automatically by the delete policy
|
||||||
Del<Ptr>::Destroy( ptr );
|
Del<Ptr>::Destroy( ptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
operator T&()
|
operator T&()
|
||||||
{
|
{
|
||||||
Create();
|
Create();
|
||||||
return *ptr;
|
return *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr Create()
|
Ptr Create()
|
||||||
{
|
{
|
||||||
ptr = Ptr( new Impl );
|
ptr = Ptr( new Impl );
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr ptr;
|
Ptr ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
struct HavePtrHolder
|
struct HavePtrHolder
|
||||||
|
@ -116,7 +116,7 @@ namespace Loki
|
||||||
|
|
||||||
template<class Impl, typename Ptr, template<class> class Del>
|
template<class Impl, typename Ptr, template<class> class Del>
|
||||||
class InheritedPimpl : private
|
class InheritedPimpl : private
|
||||||
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
||||||
{
|
{
|
||||||
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
||||||
|
|
||||||
|
@ -127,13 +127,13 @@ namespace Loki
|
||||||
InheritedPimpl() : LOKI_INHERITED_PIMPL_NAME(PtrHolder::ptr.Create())
|
InheritedPimpl() : LOKI_INHERITED_PIMPL_NAME(PtrHolder::ptr.Create())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
InheritedPimpl& operator=(const InheritedPimpl&);
|
InheritedPimpl& operator=(const InheritedPimpl&);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Impl, typename Ptr, template<class> class Del>
|
template<class Impl, typename Ptr, template<class> class Del>
|
||||||
class DeclaredPimpl : private
|
class DeclaredPimpl : private
|
||||||
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
||||||
{
|
{
|
||||||
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
||||||
|
|
||||||
|
@ -149,11 +149,11 @@ namespace Loki
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DeclaredPimpl() : ptr(PtrHolder::ptr.Create())
|
DeclaredPimpl() : ptr(PtrHolder::ptr.Create())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DeclaredPimpl& operator=(const DeclaredPimpl&);
|
DeclaredPimpl& operator=(const DeclaredPimpl&);
|
||||||
const Ptr ptr;
|
const Ptr ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ namespace Loki
|
||||||
|
|
||||||
template<class Impl, typename Ptr, template<class> class Del>
|
template<class Impl, typename Ptr, template<class> class Del>
|
||||||
class InheritedRimpl : private
|
class InheritedRimpl : private
|
||||||
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> >
|
||||||
{
|
{
|
||||||
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
typedef Private::HavePtrHolder<Private::AutoPtrHolder<Impl,Ptr,Del> > PtrHolder;
|
||||||
|
|
||||||
|
@ -215,8 +215,8 @@ namespace Loki
|
||||||
PtrImpl() : UsagePolicy<Impl,PointerPolicy,DeletePolicy>()
|
PtrImpl() : UsagePolicy<Impl,PointerPolicy,DeletePolicy>()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PtrImpl& operator=(const PtrImpl&);
|
PtrImpl& operator=(const PtrImpl&);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -229,7 +229,7 @@ namespace Loki
|
||||||
template<class T>
|
template<class T>
|
||||||
struct Pimpl
|
struct Pimpl
|
||||||
{
|
{
|
||||||
// declare pimpl
|
// declare pimpl
|
||||||
typedef PtrImpl
|
typedef PtrImpl
|
||||||
<
|
<
|
||||||
Impl<T>,
|
Impl<T>,
|
||||||
|
@ -239,7 +239,7 @@ namespace Loki
|
||||||
>
|
>
|
||||||
Type;
|
Type;
|
||||||
|
|
||||||
// inherit pimpl
|
// inherit pimpl
|
||||||
typedef PtrImpl
|
typedef PtrImpl
|
||||||
<
|
<
|
||||||
Impl<T>,
|
Impl<T>,
|
||||||
|
@ -255,7 +255,7 @@ namespace Loki
|
||||||
struct Rimpl
|
struct Rimpl
|
||||||
{
|
{
|
||||||
|
|
||||||
// declare rimpl
|
// declare rimpl
|
||||||
typedef PtrImpl
|
typedef PtrImpl
|
||||||
<
|
<
|
||||||
Impl<T>,
|
Impl<T>,
|
||||||
|
@ -265,8 +265,8 @@ namespace Loki
|
||||||
>
|
>
|
||||||
Type;
|
Type;
|
||||||
|
|
||||||
// init declared rimpl
|
// init declared rimpl
|
||||||
typedef Private::AutoPtrHolder
|
typedef Private::AutoPtrHolder
|
||||||
<
|
<
|
||||||
Type,
|
Type,
|
||||||
Type*,
|
Type*,
|
||||||
|
@ -275,7 +275,7 @@ namespace Loki
|
||||||
Init;
|
Init;
|
||||||
|
|
||||||
|
|
||||||
// ingerit rimpl
|
// ingerit rimpl
|
||||||
typedef PtrImpl
|
typedef PtrImpl
|
||||||
<
|
<
|
||||||
Impl<T>,
|
Impl<T>,
|
||||||
|
|
|
@ -143,18 +143,18 @@ void test_more();
|
||||||
|
|
||||||
void heap_debug()
|
void heap_debug()
|
||||||
{
|
{
|
||||||
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
|
int tmpFlag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG );
|
||||||
|
|
||||||
// Turn on leak-checking bit
|
// Turn on leak-checking bit
|
||||||
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
|
tmpFlag |= _CRTDBG_LEAK_CHECK_DF;
|
||||||
|
|
||||||
//tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
|
//tmpFlag |= _CRTDBG_CHECK_ALWAYS_DF;
|
||||||
|
|
||||||
// Turn off CRT block checking bit
|
// Turn off CRT block checking bit
|
||||||
tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
|
tmpFlag &= ~_CRTDBG_CHECK_CRT_DF;
|
||||||
|
|
||||||
// Set flag to the new value
|
// Set flag to the new value
|
||||||
_CrtSetDbgFlag( tmpFlag );
|
_CrtSetDbgFlag( tmpFlag );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ void heap_debug()
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
heap_debug();
|
heap_debug();
|
||||||
|
|
||||||
A* a = new A;
|
A* a = new A;
|
||||||
B* b = new B;
|
B* b = new B;
|
||||||
|
@ -219,15 +219,15 @@ 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;
|
P6* p6 = new P6;
|
||||||
|
|
||||||
Loki::Printf("\nCreating Rimpls\n");
|
Loki::Printf("\nCreating Rimpls\n");
|
||||||
R1* r1 = new R1;
|
R1* r1 = new R1;
|
||||||
R2* r2 = new R2;
|
R2* r2 = new R2;
|
||||||
R3* r3 = new R3;
|
R3* r3 = new R3;
|
||||||
|
@ -236,16 +236,16 @@ void test_more()
|
||||||
R6* r6 = new R6;
|
R6* r6 = new R6;
|
||||||
|
|
||||||
|
|
||||||
Loki::Printf("\nDeleting Pimpls\n");
|
Loki::Printf("\nDeleting Pimpls\n");
|
||||||
delete p1;
|
delete p1;
|
||||||
delete p2;
|
delete p2;
|
||||||
delete p3;
|
delete p3;
|
||||||
delete p4;
|
delete p4;
|
||||||
delete p5;
|
delete p5;
|
||||||
delete p6;
|
delete p6;
|
||||||
|
|
||||||
Loki::Printf("\nDeleting Rimpls\n");
|
Loki::Printf("\nDeleting Rimpls\n");
|
||||||
delete r1;
|
delete r1;
|
||||||
delete r2;
|
delete r2;
|
||||||
delete r3;
|
delete r3;
|
||||||
delete r4;
|
delete r4;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue