From: <ag...@us...> - 2012-02-01 18:04:19
|
Revision: 2706 http://zoolib.svn.sourceforge.net/zoolib/?rev=2706&view=rev Author: agreen Date: 2012-02-01 18:04:08 +0000 (Wed, 01 Feb 2012) Log Message: ----------- Make InPlace and Reffed entities more distinct in their names, both being prefixed with Holder_ made them seem more alike than they are. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZAny.cpp trunk/zoolib/source/cxx/zoolib/ZAny.h Modified: trunk/zoolib/source/cxx/zoolib/ZAny.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZAny.cpp 2012-02-01 16:47:16 UTC (rev 2705) +++ trunk/zoolib/source/cxx/zoolib/ZAny.cpp 2012-02-01 18:04:08 UTC (rev 2706) @@ -28,31 +28,29 @@ inline static const std::type_info* spPODTypeInfo(const void* iPtr) { return (const std::type_info*)(((intptr_t)iPtr) ^ 1); } -inline ZAny::Holder_InPlace& ZAny::pAsInPlace() - { return *sFetch_T<Holder_InPlace>(&fDistinguisher); } +inline ZAny::InPlace& ZAny::pAsInPlace() + { return *sFetch_T<InPlace>(&fDistinguisher); } -inline const ZAny::Holder_InPlace& ZAny::pAsInPlace() const - { return *sFetch_T<Holder_InPlace>(&fDistinguisher); } +inline const ZAny::InPlace& ZAny::pAsInPlace() const + { return *sFetch_T<InPlace>(&fDistinguisher); } -inline ZRef<ZAny::Holder_Counted>& ZAny::pAsCounted() - { return *sFetch_T<ZRef<Holder_Counted> >(&fPayload); } +inline ZRef<ZAny::Reffed>& ZAny::pAsReffed() + { return *sFetch_T<ZRef<Reffed> >(&fPayload); } -inline const ZRef<ZAny::Holder_Counted>& ZAny::pAsCounted() const - { return *sFetch_T<ZRef<Holder_Counted> >(&fPayload); } +inline const ZRef<ZAny::Reffed>& ZAny::pAsReffed() const + { return *sFetch_T<ZRef<Reffed> >(&fPayload); } const std::type_info& ZAny::Type() const { - if (spIsPOD(fDistinguisher)) + if (fDistinguisher) { - return *spPODTypeInfo(fDistinguisher); - } - else if (fDistinguisher) - { + if (spIsPOD(fDistinguisher)) + return *spPODTypeInfo(fDistinguisher); return pAsInPlace().Type(); } - else if (const ZRef<Holder_Counted>& theHolderRef = pAsCounted()) + else if (const ZRef<Reffed>& theReffed = pAsReffed()) { - return theHolderRef->Type(); + return theReffed->Type(); } else { @@ -62,19 +60,17 @@ void* ZAny::VoidStar() { - if (spIsPOD(fDistinguisher)) + if (fDistinguisher) { - return &fPayload; - } - else if (fDistinguisher) - { + if (spIsPOD(fDistinguisher)) + return &fPayload; return pAsInPlace().VoidStar(); } - else if (ZRef<Holder_Counted>& theHolderRef = pAsCounted()) + else if (ZRef<Reffed>& theReffed = pAsReffed()) { - if (theHolderRef->IsShared()) - theHolderRef = theHolderRef->Clone(); - return theHolderRef->VoidStar(); + if (theReffed->IsShared()) + theReffed = theReffed->Clone(); + return theReffed->VoidStar(); } else { @@ -84,17 +80,15 @@ const void* ZAny::ConstVoidStar() const { - if (spIsPOD(fDistinguisher)) + if (fDistinguisher) { - return &fPayload; - } - else if (fDistinguisher) - { + if (spIsPOD(fDistinguisher)) + return &fPayload; return pAsInPlace().ConstVoidStar(); } - else if (const ZRef<Holder_Counted>& theHolderRef = pAsCounted()) + else if (const ZRef<Reffed>& theReffed = pAsReffed()) { - return theHolderRef->VoidStar(); + return theReffed->VoidStar(); } else { @@ -113,7 +107,7 @@ } else { - pAsCounted().swap(ioOther.pAsCounted()); + pAsReffed().swap(ioOther.pAsReffed()); } } @@ -122,40 +116,40 @@ void ZAny::Clear() { - if (spIsPOD(fDistinguisher)) + if (fDistinguisher) { + if (not spIsPOD(fDistinguisher)) + sDtor_T<InPlace>(&fDistinguisher); fDistinguisher = 0; } - else if (fDistinguisher) - { - sDtor_T<Holder_InPlace>(&fDistinguisher); - fDistinguisher = 0; - } else { - sDtor_T<ZRef<Holder_Counted> >(&fPayload); + sDtor_T<ZRef<Reffed> >(&fPayload); } fPayload.fAsPtr = 0; } void* ZAny::pGetMutable(const std::type_info& iTypeInfo) { - if (spIsPOD(fDistinguisher)) + if (fDistinguisher) { - if (iTypeInfo == *spPODTypeInfo(fDistinguisher)) - return &fPayload; + if (spIsPOD(fDistinguisher)) + { + if (iTypeInfo == *spPODTypeInfo(fDistinguisher)) + return &fPayload; + } + else + { + return pAsInPlace().VoidStarIf(iTypeInfo); + } } - else if (fDistinguisher) + else if (ZRef<Reffed>& theReffed = pAsReffed()) { - return pAsInPlace().VoidStarIf(iTypeInfo); - } - else if (ZRef<Holder_Counted>& theHolderRef = pAsCounted()) - { - if (theHolderRef->Type() == iTypeInfo) + if (theReffed->Type() == iTypeInfo) { - if (theHolderRef->IsShared()) - theHolderRef = theHolderRef->Clone(); - return theHolderRef->VoidStar(); + if (theReffed->IsShared()) + theReffed = theReffed->Clone(); + return theReffed->VoidStar(); } } @@ -164,24 +158,27 @@ const void* ZAny::pGet(const std::type_info& iTypeInfo) const { - if (spIsPOD(fDistinguisher)) + if (fDistinguisher) { - if (iTypeInfo == *spPODTypeInfo(fDistinguisher)) - return &fPayload; + if (spIsPOD(fDistinguisher)) + { + if (iTypeInfo == *spPODTypeInfo(fDistinguisher)) + return &fPayload; + } + else + { + return pAsInPlace().ConstVoidStarIf(iTypeInfo); + } } - else if (fDistinguisher) + else if (const ZRef<Reffed>& theReffed = pAsReffed()) { - return pAsInPlace().ConstVoidStarIf(iTypeInfo); + return theReffed->VoidStarIf(iTypeInfo); } - else if (const ZRef<Holder_Counted>& theHolderRef = pAsCounted()) - { - return theHolderRef->VoidStarIf(iTypeInfo); - } return 0; } -void ZAny::pCtor_Complex(const ZAny& iOther) +void ZAny::pCtor_NonPOD(const ZAny& iOther) { if (iOther.fDistinguisher) { @@ -190,16 +187,16 @@ else { fDistinguisher = 0; - sCtor_T<ZRef<Holder_Counted> >(&fPayload, iOther.pAsCounted()); + sCtor_T<ZRef<Reffed> >(&fPayload, iOther.pAsReffed()); } } -void ZAny::pDtor_Complex() +void ZAny::pDtor_NonPOD() { if (fDistinguisher) - sDtor_T<Holder_InPlace>(&fDistinguisher); + sDtor_T<InPlace>(&fDistinguisher); else - sDtor_T<ZRef<Holder_Counted> >(&fPayload); + sDtor_T<ZRef<Reffed> >(&fPayload); } } // namespace ZooLib Modified: trunk/zoolib/source/cxx/zoolib/ZAny.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZAny.h 2012-02-01 16:47:16 UTC (rev 2705) +++ trunk/zoolib/source/cxx/zoolib/ZAny.h 2012-02-01 18:04:08 UTC (rev 2706) @@ -155,10 +155,10 @@ private: // ----------------- - class Holder_InPlace + class InPlace { public: - virtual ~Holder_InPlace() {} + virtual ~InPlace() {} virtual void CtorInto(void* iOther) const = 0; @@ -174,18 +174,18 @@ // ----------------- template<typename S> - class Holder_InPlace_T : public Holder_InPlace + class InPlace_T : public InPlace { public: - Holder_InPlace_T() {} + InPlace_T() {} template <class P0> - Holder_InPlace_T(const P0& iP0) : fValue(iP0) {} + InPlace_T(const P0& iP0) : fValue(iP0) {} template <class P0, class P1> - Holder_InPlace_T(const P0& iP0, const P1& iP1) : fValue(iP0, iP1) {} + InPlace_T(const P0& iP0, const P1& iP1) : fValue(iP0, iP1) {} - virtual void CtorInto(void* iOther) const { sCtor_T<Holder_InPlace_T>(iOther, fValue); } + virtual void CtorInto(void* iOther) const { sCtor_T<InPlace_T>(iOther, fValue); } virtual const std::type_info& Type() const { return typeid(S); } @@ -210,11 +210,11 @@ // ----------------- - class Holder_Counted : public ZCountedWithoutFinalize + class Reffed : public ZCountedWithoutFinalize { public: virtual const std::type_info& Type() const = 0; - virtual Holder_Counted* Clone() const = 0; + virtual Reffed* Clone() const = 0; virtual void* VoidStar() = 0; virtual void* VoidStarIf(const std::type_info& iTI) = 0; }; @@ -222,19 +222,19 @@ // ----------------- template<typename S> - class Holder_Counted_T : public Holder_Counted + class Reffed_T : public Reffed { public: - Holder_Counted_T() {} + Reffed_T() {} template <class P0> - Holder_Counted_T(const P0& iP0) : fValue(iP0) {} + Reffed_T(const P0& iP0) : fValue(iP0) {} template <class P0, class P1> - Holder_Counted_T(const P0& iP0, const P1& iP1) : fValue(iP0, iP1) {} + Reffed_T(const P0& iP0, const P1& iP1) : fValue(iP0, iP1) {} virtual const std::type_info& Type() const { return typeid(S); } - virtual Holder_Counted* Clone() const { return new Holder_Counted_T(fValue); } + virtual Reffed* Clone() const { return new Reffed_T(fValue); } virtual void* VoidStar() { return &fValue; } virtual void* VoidStarIf(const std::type_info& iTI) { @@ -248,11 +248,11 @@ // ----------------- - Holder_InPlace& pAsInPlace(); - const Holder_InPlace& pAsInPlace() const; + InPlace& pAsInPlace(); + const InPlace& pAsInPlace() const; - ZRef<Holder_Counted>& pAsCounted(); - const ZRef<Holder_Counted>& pAsCounted() const; + ZRef<Reffed>& pAsReffed(); + const ZRef<Reffed>& pAsReffed() const; // ----------------- @@ -260,10 +260,10 @@ const void* pGet(const std::type_info& iTypeInfo) const; void pCtor(const ZAny& iOther); - void pCtor_Complex(const ZAny& iOther); + void pCtor_NonPOD(const ZAny& iOther); void pDtor(); - void pDtor_Complex(); + void pDtor_NonPOD(); static bool spIsPOD(const void* iPtr); @@ -274,12 +274,12 @@ { if (ZAnyTraits<S>::eAllowInPlace && sizeof(S) <= sizeof(fPayload)) { - sCtor_T<Holder_InPlace_T<S> >(&fDistinguisher, iP0, iP1); + sCtor_T<InPlace_T<S> >(&fDistinguisher, iP0, iP1); } else { fDistinguisher = 0; - sCtor_T<ZRef<Holder_Counted> >(&fPayload, new Holder_Counted_T<S>(iP0, iP1)); + sCtor_T<ZRef<Reffed> >(&fPayload, new Reffed_T<S>(iP0, iP1)); } } @@ -287,7 +287,7 @@ void pCtor_Counted_T(const P0& iP0, const P1& iP1) { fDistinguisher = 0; - sCtor_T<ZRef<Holder_Counted> >(&fPayload, new Holder_Counted_T<S>(iP0, iP1)); + sCtor_T<ZRef<Reffed> >(&fPayload, new Reffed_T<S>(iP0, iP1)); } template <class S, class P0> @@ -306,13 +306,13 @@ #endif else { - sCtor_T<Holder_InPlace_T<S> >(&fDistinguisher, iP0); + sCtor_T<InPlace_T<S> >(&fDistinguisher, iP0); } } else { fDistinguisher = 0; - sCtor_T<ZRef<Holder_Counted> >(&fPayload, new Holder_Counted_T<S>(iP0)); + sCtor_T<ZRef<Reffed> >(&fPayload, new Reffed_T<S>(iP0)); } } @@ -320,7 +320,7 @@ void pCtor_Counted_T(const P0& iP0) { fDistinguisher = 0; - sCtor_T<ZRef<Holder_Counted> >(&fPayload, new Holder_Counted_T<S>(iP0)); + sCtor_T<ZRef<Reffed> >(&fPayload, new Reffed_T<S>(iP0)); } // ----------------- @@ -341,15 +341,15 @@ #endif else { - return sCtor_T<Holder_InPlace_T<S> >(&fDistinguisher, iP0)->fValue; + return sCtor_T<InPlace_T<S> >(&fDistinguisher, iP0)->fValue; } } else { fDistinguisher = 0; - Holder_Counted_T<S>* theHolder = new Holder_Counted_T<S>(iP0); - sCtor_T<ZRef<Holder_Counted> >(&fPayload, theHolder); - return theHolder->fValue; + Reffed_T<S>* theReffed = new Reffed_T<S>(iP0); + sCtor_T<ZRef<Reffed> >(&fPayload, theReffed); + return theReffed->fValue; } } @@ -369,32 +369,33 @@ #endif else { - return sCtor_T<Holder_InPlace_T<S> >(&fDistinguisher)->fValue; + return sCtor_T<InPlace_T<S> >(&fDistinguisher)->fValue; } } else { fDistinguisher = 0; - Holder_Counted_T<S>* theHolder = new Holder_Counted_T<S>; - sCtor_T<ZRef<Holder_Counted> >(&fPayload, theHolder); - return theHolder->fValue; + Reffed_T<S>* theReffed = new Reffed_T<S>; + sCtor_T<ZRef<Reffed> >(&fPayload, theReffed); + return theReffed->fValue; } } // ----------------- // There are three situations, distinguished by the value in fDistinguisher. - // 1. It's null. fPayload.fAsPtr points to an instance of a Holder_Counted subclass. If - // fPayload.fAsPtr is also null then this is itself a null object. + // 1. It's null. fPayload.fAsPtr points to an instance of a Reffed subclass. If + // fPayload.fAsPtr is also null then the ZAny is itself a null object. // 2. LSB is set. With an unset LSB it points to a typeid, and fPayload holds a POD value. - // 3. LSB is unset. It's the vptr of a Holder_InPlace, the fields of the object itself + // 3. LSB is unset. It's the vptr of an InPlace, the fields of the object itself // spilling over into fPayload. void* fDistinguisher; union { - // This union provides space for a refcounted pointer to a Holder_Counted, space + // This union provides space for a refcounted pointer to a Reffed, space // for the most common in-place values, and makes some values legible in a debugger. + // It has it's own name so that sizeof has something on which to operate. void* fAsPtr; bool fAsBool; @@ -423,14 +424,14 @@ } else { - pCtor_Complex(iOther); + pCtor_NonPOD(iOther); } } inline void ZAny::pDtor() { if (not spIsPOD(fDistinguisher)) - pDtor_Complex(); + pDtor_NonPOD(); } // ================================================================================================= @@ -450,7 +451,7 @@ inline ZAny& ZAny::operator=(const ZAny& iOther) { - if (this != & iOther) + if (this != &iOther) { pDtor(); pCtor(iOther); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |