From: <ag...@us...> - 2011-12-14 20:46:01
|
Revision: 2641 http://zoolib.svn.sourceforge.net/zoolib/?rev=2641&view=rev Author: agreen Date: 2011-12-14 20:45:55 +0000 (Wed, 14 Dec 2011) Log Message: ----------- Comment. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZQ.h Modified: trunk/zoolib/source/cxx/zoolib/ZQ.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZQ.h 2011-12-14 20:45:21 UTC (rev 2640) +++ trunk/zoolib/source/cxx/zoolib/ZQ.h 2011-12-14 20:45:55 UTC (rev 2641) @@ -34,8 +34,9 @@ #pragma mark * ZQ // The 'Q' stands for 'Questionable', 'Queryable', 'Quibble' or perhaps 'Quib' -// c.f. Haskell's Data.Maybe, Scala's Option. +// c.f. Haskell's 'Data.Maybe', Scala's 'Option'. + template <class T, bool Sense = true> class ZQ { @@ -86,60 +87,61 @@ ZQ& operator=(const ZQ& iOther) { - if (this != &iOther) + if (fHasValue) { - if (fHasValue) + if (iOther.fHasValue) { - if (iOther.fHasValue) - { - sAssignFromVoidStar_T<T>(fBytes, iOther.fBytes); - } - else - { - fHasValue = false; - sDtor_T<T>(fBytes); - } + sAssignFromVoidStar_T<T>(fBytes, iOther.fBytes); } - else if (iOther.fHasValue) + else { - sCtorFromVoidStar_T<T>(fBytes, iOther.fBytes); - fHasValue = true; + fHasValue = false; + sDtor_T<T>(fBytes); } } + else if (iOther.fHasValue) + { + sCtorFromVoidStar_T<T>(fBytes, iOther.fBytes); + fHasValue = true; + } return *this; } // ----------------- - ZQ(const ZQ<T,!Sense>& iOther) - : fHasValue(iOther.fHasValue) + template <class OtherT, bool OtherSense> + ZQ(const ZQ<OtherT, OtherSense>& iOther) { - if (fHasValue) - sCtorFromVoidStar_T<T>(fBytes, iOther.fBytes); + if (const OtherT* theOther = iOther.PGet()) + { + sCtor_T<T,OtherT>(fBytes, *theOther); + fHasValue = true; + } + else + { + fHasValue = false; + } } - ZQ& operator=(const ZQ<T,!Sense>& iOther) + template <class OtherT, bool OtherSense> + ZQ& operator=(const ZQ<OtherT, OtherSense>& iOther) { - if (this != &iOther) + if (fHasValue) { - if (fHasValue) + if (const OtherT* theOther = iOther.PGet()) { - if (iOther.fHasValue) - { - sAssignFromVoidStar_T<T>(fBytes, iOther.fBytes); - } - else - { - fHasValue = false; - sDtor_T<T>(fBytes); - } + sAssign_T<T>(fBytes, *theOther); } - else if (iOther.fHasValue) + else { - sCtorFromVoidStar_T<T>(fBytes, iOther.fBytes); - fHasValue = true; - } + fHasValue = false; + sDtor_T<T>(fBytes); + } } + else if (const OtherT* theOther = iOther.PGet()) + { + sCtor_T<T,OtherT>(fBytes, *theOther); + } return *this; } @@ -285,8 +287,8 @@ { if (fHasValue) { + fHasValue = false; sDtor_T<T>(fBytes); - fHasValue = false; } sCtor_T<T>(fBytes); @@ -302,8 +304,6 @@ #endif bool fHasValue; - - friend class ZQ<T, !Sense>; }; // ================================================================================================= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |