From: <ag...@us...> - 2012-01-28 18:13:42
|
Revision: 2693 http://zoolib.svn.sourceforge.net/zoolib/?rev=2693&view=rev Author: agreen Date: 2012-01-28 18:13:35 +0000 (Sat, 28 Jan 2012) Log Message: ----------- Add Mutable -- returns a non-const ref to a value of the type, whatever was already there if that's possible, otherwise a default-initialized value. Modified Paths: -------------- trunk/zoolib/source/cxx/zoolib/ZVal_Any.cpp trunk/zoolib/source/cxx/zoolib/ZVal_Any.h Modified: trunk/zoolib/source/cxx/zoolib/ZVal_Any.cpp =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZVal_Any.cpp 2012-01-28 18:11:49 UTC (rev 2692) +++ trunk/zoolib/source/cxx/zoolib/ZVal_Any.cpp 2012-01-28 18:13:35 UTC (rev 2693) @@ -94,6 +94,13 @@ ZVal_Any ZVal_Any::Get(const string8& iName) const { return this->GetMap().Get(iName); } +ZVal_Any& ZVal_Any::Mutable(const string8& iName) + { + if (ZMap_Any* asMap = this->PGetMutable<ZMap_Any>()) + return asMap->Mutable(iName); + return this->Mutable<ZMap_Any>().Mutable(iName); + } + ZVal_Any* ZVal_Any::PGetMutable(size_t iIndex) { if (ZSeq_Any* asSeq = this->PGetMutable<ZSeq_Any>()) @@ -539,6 +546,12 @@ return *this; } +ZVal_Any& ZMap_Any::Mutable(const string8& iName) + { + this->pTouch(); + return fRep->fMap[iName]; + } + ZMap_Any::Index_t ZMap_Any::Begin() const { if (fRep) Modified: trunk/zoolib/source/cxx/zoolib/ZVal_Any.h =================================================================== --- trunk/zoolib/source/cxx/zoolib/ZVal_Any.h 2012-01-28 18:11:49 UTC (rev 2692) +++ trunk/zoolib/source/cxx/zoolib/ZVal_Any.h 2012-01-28 18:13:35 UTC (rev 2693) @@ -148,11 +148,13 @@ using ZAny::DGet; using ZAny::Get; using ZAny::Set; + using ZAny::Mutable; // Shortcut access to values in an enclosed Map. ZVal_Any* PGetMutable(const string8& iName); const ZVal_Any* PGet(const string8& iName) const; ZVal_Any Get(const string8& iName) const; + ZVal_Any& Mutable(const string8& iName); template <class S> S* PGetMutable(const string8& iName) @@ -178,6 +180,10 @@ S Get(const string8& iName) const { return this->Get(iName).Get<S>(); } + template <class S> + S& Mutable(const string8& iName) const + { return this->Mutable(iName).Mutable<S>(); } + // Shortcut access to values in an enclosed Seq. ZVal_Any* PGetMutable(size_t iIndex); const ZVal_Any* PGet(size_t iIndex) const; @@ -497,6 +503,8 @@ ZMap_Any& Erase(const Index_t& iIndex); // Our protocol + ZVal_Any& Mutable(const string8& iName); + Index_t Begin() const; Index_t End() const; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |