From 081c3fb31f038bde0c175110a54f73d7c59c4918 Mon Sep 17 00:00:00 2001 From: syntheticpp Date: Mon, 16 Jan 2006 19:48:23 +0000 Subject: [PATCH] add error policy git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@485 7ec92016-0320-0410-acc4-a06ded1c099a --- include/loki/Pimpl.h | 46 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/include/loki/Pimpl.h b/include/loki/Pimpl.h index 5eaf956..407129c 100755 --- a/include/loki/Pimpl.h +++ b/include/loki/Pimpl.h @@ -14,7 +14,6 @@ #include -// $Header$ #ifndef LOKI_INHERITED_PIMPL_NAME #define LOKI_INHERITED_PIMPL_NAME d @@ -33,6 +32,8 @@ namespace Loki struct Impl; + + ///////////////////// // creation policies ///////////////////// @@ -61,6 +62,31 @@ namespace Loki {} }; + ///////////////////// + // error handling + ///////////////////// + template + struct ExceptionOnPimplError + { + struct Exception : public std::exception + { + const char* what() const throw() { return "error in loki/Pimpl.h"; } + }; + + static void PimplError() + { + throw Exception(); + } + + }; + + template + struct IgnorPimplError + { + static void PimplError() + {} + + }; ///////////////////// // Helper class AutoPtrHolder to manage pimpl lifetime @@ -98,9 +124,10 @@ namespace Loki < class Impl, class Ptr, - template class Del + template class Del, + template class ErrorPolicy = ExceptionOnPimplError > - struct AutoPtrHolderChecked //: AutoPtrHolder + struct AutoPtrHolderChecked { static bool init_; @@ -118,9 +145,10 @@ namespace Loki template operator T&() { + // if this throws change the declaration order + // of the DeclaredRimpl construct if(!init_) - // if this throws change the declaration order - throw 1; + ErrorPolicy::PimplError(); Create(); return *ptr; } @@ -138,9 +166,10 @@ namespace Loki < class Impl, class Ptr, - template class Del + template class Del, + template class Err > - bool AutoPtrHolderChecked::init_ = false; + bool AutoPtrHolderChecked::init_ = false; template @@ -335,6 +364,9 @@ namespace Loki #endif // $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 // Added cvs keywords. //