add error policy
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@485 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
4703b740b7
commit
081c3fb31f
1 changed files with 39 additions and 7 deletions
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
#include <loki/TypeTraits.h>
|
#include <loki/TypeTraits.h>
|
||||||
|
|
||||||
// $Header$
|
|
||||||
|
|
||||||
#ifndef LOKI_INHERITED_PIMPL_NAME
|
#ifndef LOKI_INHERITED_PIMPL_NAME
|
||||||
#define LOKI_INHERITED_PIMPL_NAME d
|
#define LOKI_INHERITED_PIMPL_NAME d
|
||||||
|
@ -33,6 +32,8 @@ namespace Loki
|
||||||
struct Impl;
|
struct Impl;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
// creation policies
|
// creation policies
|
||||||
/////////////////////
|
/////////////////////
|
||||||
|
@ -61,6 +62,31 @@ namespace Loki
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/////////////////////
|
||||||
|
// 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
|
// Helper class AutoPtrHolder to manage pimpl lifetime
|
||||||
|
@ -98,9 +124,10 @@ namespace Loki
|
||||||
<
|
<
|
||||||
class Impl,
|
class Impl,
|
||||||
class Ptr,
|
class Ptr,
|
||||||
template<class> class Del
|
template<class> class Del,
|
||||||
|
template<class> class ErrorPolicy = ExceptionOnPimplError
|
||||||
>
|
>
|
||||||
struct AutoPtrHolderChecked //: AutoPtrHolder<Impl,Ptr,Del>
|
struct AutoPtrHolderChecked
|
||||||
{
|
{
|
||||||
static bool init_;
|
static bool init_;
|
||||||
|
|
||||||
|
@ -118,9 +145,10 @@ namespace Loki
|
||||||
template<class T>
|
template<class T>
|
||||||
operator T&()
|
operator T&()
|
||||||
{
|
{
|
||||||
if(!init_)
|
|
||||||
// if this throws change the declaration order
|
// if this throws change the declaration order
|
||||||
throw 1;
|
// of the DeclaredRimpl construct
|
||||||
|
if(!init_)
|
||||||
|
ErrorPolicy<T>::PimplError();
|
||||||
Create();
|
Create();
|
||||||
return *ptr;
|
return *ptr;
|
||||||
}
|
}
|
||||||
|
@ -138,9 +166,10 @@ namespace Loki
|
||||||
<
|
<
|
||||||
class Impl,
|
class Impl,
|
||||||
class Ptr,
|
class Ptr,
|
||||||
template<class> class Del
|
template<class> class Del,
|
||||||
|
template<class> class Err
|
||||||
>
|
>
|
||||||
bool AutoPtrHolderChecked<Impl,Ptr,Del>::init_ = false;
|
bool AutoPtrHolderChecked<Impl,Ptr,Del,Err>::init_ = false;
|
||||||
|
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -335,6 +364,9 @@ namespace Loki
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// $Log$
|
// $Log$
|
||||||
|
// Revision 1.7 2006/01/16 19:48:23 syntheticpp
|
||||||
|
// add error policy
|
||||||
|
//
|
||||||
// Revision 1.6 2006/01/16 19:05:09 rich_sposato
|
// Revision 1.6 2006/01/16 19:05:09 rich_sposato
|
||||||
// Added cvs keywords.
|
// Added cvs keywords.
|
||||||
//
|
//
|
||||||
|
|
Loading…
Add table
Reference in a new issue