Permalink
Browse files

Use ZName rather than string8 for property names.

  • Loading branch information...
1 parent bd8f89b commit 2400589751e1cb0d1e5705fe95b1a56ca4600b77 @ElectricMagic ElectricMagic committed May 20, 2012
Showing with 46 additions and 45 deletions.
  1. +19 −17 zoolib/ZVal_Any.cpp
  2. +27 −28 zoolib/ZVal_Any.h
View
36 zoolib/ZVal_Any.cpp
@@ -257,7 +257,8 @@ ZMap_Any::Rep::Rep(const Map_t& iMap)
// =================================================================================================
// MARK: - ZMap_Any
-static string8 spEmptyString;
+static ZMap_Any::Name_t spEmptyString;
+
static ZMap_Any::Map_t spEmptyMap;
ZMap_Any::ZMap_Any()
@@ -293,7 +294,7 @@ ZMap_Any::ZMap_Any(const ZNameVal& iNV)
ZMap_Any::ZMap_Any(const char* iName, const char* iVal)
{ this->Set(iName, iVal); }
-ZMap_Any::ZMap_Any(const string8& iName, const ZVal_Any& iVal)
+ZMap_Any::ZMap_Any(const Name_t& iName, const ZVal_Any& iVal)
{ this->Set(iName, iVal); }
int ZMap_Any::Compare(const ZMap_Any& iOther) const
@@ -346,7 +347,8 @@ int ZMap_Any::Compare(const ZMap_Any& iOther) const
if (iterOther != endOther)
{
// Other is not exhausted either, so we compare their current values.
- if (int compare = sCompare_T<string>(iterThis->first, iterOther->first))
+ if (int compare = sCompare_T(iterThis->first, iterOther->first))
+// if (int compare = sCompare_T<string>(iterThis->first, iterOther->first))
{
// The names are different.
return compare;
@@ -388,7 +390,7 @@ bool ZMap_Any::IsEmpty() const
void ZMap_Any::Clear()
{ fRep.Clear(); }
-ZVal_Any* ZMap_Any::PGetMutable(const string8& iName)
+ZVal_Any* ZMap_Any::PGetMutable(const Name_t& iName)
{
if (fRep)
{
@@ -408,7 +410,7 @@ ZVal_Any* ZMap_Any::PGetMutable(const Index_t& iIndex)
return nullptr;
}
-const ZVal_Any* ZMap_Any::PGet(const string8& iName) const
+const ZVal_Any* ZMap_Any::PGet(const Name_t& iName) const
{
if (fRep)
{
@@ -426,7 +428,7 @@ const ZVal_Any* ZMap_Any::PGet(const Index_t& iIndex) const
return nullptr;
}
-const ZQ<ZVal_Any> ZMap_Any::QGet(const string8& iName) const
+const ZQ<ZVal_Any> ZMap_Any::QGet(const Name_t& iName) const
{
if (const ZVal_Any* theVal = this->PGet(iName))
return *theVal;
@@ -440,7 +442,7 @@ const ZQ<ZVal_Any> ZMap_Any::QGet(const Index_t& iIndex) const
return null;
}
-const ZVal_Any ZMap_Any::DGet(const ZVal_Any& iDefault, const string8& iName) const
+const ZVal_Any ZMap_Any::DGet(const ZVal_Any& iDefault, const Name_t& iName) const
{
if (const ZVal_Any* theVal = this->PGet(iName))
return *theVal;
@@ -454,7 +456,7 @@ const ZVal_Any ZMap_Any::DGet(const ZVal_Any& iDefault, const Index_t& iIndex) c
return iDefault;
}
-const ZVal_Any& ZMap_Any::Get(const string8& iName) const
+const ZVal_Any& ZMap_Any::Get(const Name_t& iName) const
{
if (const ZVal_Any* theVal = this->PGet(iName))
return *theVal;
@@ -468,7 +470,7 @@ const ZVal_Any& ZMap_Any::Get(const Index_t& iIndex) const
return spVal_Null;
}
-ZMap_Any& ZMap_Any::Set(const string8& iName, const ZVal_Any& iVal)
+ZMap_Any& ZMap_Any::Set(const Name_t& iName, const ZVal_Any& iVal)
{
this->pTouch();
fRep->fMap[iName] = iVal;
@@ -483,7 +485,7 @@ ZMap_Any& ZMap_Any::Set(const Index_t& iIndex, const ZVal_Any& iVal)
return *this;
}
-ZMap_Any& ZMap_Any::Erase(const string8& iName)
+ZMap_Any& ZMap_Any::Erase(const Name_t& iName)
{
if (fRep)
{
@@ -501,7 +503,7 @@ ZMap_Any& ZMap_Any::Erase(const Index_t& iIndex)
return *this;
}
-ZVal_Any& ZMap_Any::Mutable(const string8& iName)
+ZVal_Any& ZMap_Any::Mutable(const Name_t& iName)
{
this->pTouch();
return fRep->fMap[iName];
@@ -521,14 +523,14 @@ ZMap_Any::Index_t ZMap_Any::End() const
return spEmptyMap.end();
}
-const string8& ZMap_Any::NameOf(const Index_t& iIndex) const
+const ZMap_Any::Name_t& ZMap_Any::NameOf(const Index_t& iIndex) const
{
if (fRep && iIndex != fRep->fMap.end())
return iIndex->first;
return spEmptyString;
}
-ZMap_Any::Index_t ZMap_Any::IndexOf(const string8& iName) const
+ZMap_Any::Index_t ZMap_Any::IndexOf(const Name_t& iName) const
{
if (fRep)
return fRep->fMap.find(iName);
@@ -545,10 +547,10 @@ ZMap_Any::Index_t ZMap_Any::IndexOf(const ZMap_Any& iOther, const Index_t& iOthe
ZMap_Any& ZMap_Any::Set(const ZNameVal& iNV)
{ return this->Set(iNV.first, iNV.second); }
-ZVal_Any& ZMap_Any::operator[](const string8& iName)
+ZVal_Any& ZMap_Any::operator[](const Name_t& iName)
{ return this->Mutable(iName); }
-const ZVal_Any& ZMap_Any::operator[](const string8& iName) const
+const ZVal_Any& ZMap_Any::operator[](const Name_t& iName) const
{
if (const ZVal_Any* theVal = this->PGet(iName))
return *theVal;
@@ -593,7 +595,7 @@ ZMap_Any::Map_t::iterator ZMap_Any::pTouch(const Index_t& iIndex)
}
else if (fRep->IsShared())
{
- const string theName = iIndex->first;
+ const Name_t theName = iIndex->first;
fRep = new Rep(fRep->fMap);
return fRep->fMap.find(theName);
}
@@ -640,7 +642,7 @@ ZMap_Any sAugmented(const ZMap_Any& iUnder, const ZMap_Any& iOver)
ZMap_Any result = iUnder;
for (ZMap_Any::Index_t ii = iOver.Begin(); ii != iOver.End(); ++ii)
{
- const string8& theName = iOver.NameOf(ii);
+ const ZMap_Any::Name_t& theName = iOver.NameOf(ii);
const ZVal_Any& theOverVal = iOver.Get(ii);
if (ZVal_Any* theResultVal = result.PGetMutable(theName))
{
View
55 zoolib/ZVal_Any.h
@@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "zoolib/ZCompat_unordered_map.h"
#include "zoolib/ZData_Any.h"
#include "zoolib/ZCompare_String.h" // For FastComparator_String
+#include "zoolib/ZName.h"
#include "zoolib/ZVal.h"
#include "zoolib/ZVal_T.h"
@@ -179,7 +180,7 @@ ZSeq_Any::ZSeq_Any(Iterator begin, Iterator end)
// =================================================================================================
// MARK: - ZNameVal
-typedef std::pair<string8, ZVal_Any> ZNameVal;
+typedef std::pair<ZName, ZVal_Any> ZNameVal;
// =================================================================================================
// MARK: - ZMap_Any
@@ -189,14 +190,12 @@ class ZMap_Any
class Rep;
public:
- #if 0 && ZCONFIG_SPI_Enabled(unordered_map)
- typedef unordered_map<string8, ZVal_Any> Map_t;
- #else
- typedef std::map<string8, ZVal_Any, FastComparator_String> Map_t;
- #endif
+ typedef ZName Name_t;
+
+ typedef std::map<Name_t, ZVal_Any> Map_t;
typedef Map_t::iterator Index_t;
- typedef ZVal_Any Val;
+ typedef ZVal_Any Val_t;
ZMap_Any();
ZMap_Any(const ZMap_Any& iOther);
@@ -208,7 +207,7 @@ class ZMap_Any
ZMap_Any(const ZNameVal& iNV);
ZMap_Any(const char* iName, const char* iVal);
- ZMap_Any(const string8& iName, const ZVal_Any& iVal);
+ ZMap_Any(const Name_t& iName, const ZVal_Any& iVal);
template <class Iterator>
ZMap_Any(Iterator begin, Iterator end);
@@ -220,23 +219,23 @@ class ZMap_Any
void Clear();
- ZVal_Any* PGetMutable(const string8& iName);
+ ZVal_Any* PGetMutable(const Name_t& iName);
ZVal_Any* PGetMutable(const Index_t& iIndex);
- const ZVal_Any* PGet(const string8& iName) const;
+ const ZVal_Any* PGet(const Name_t& iName) const;
const ZVal_Any* PGet(const Index_t& iIndex) const;
- const ZQ<ZVal_Any> QGet(const string8& iName) const;
+ const ZQ<ZVal_Any> QGet(const Name_t& iName) const;
const ZQ<ZVal_Any> QGet(const Index_t& iIndex) const;
- const ZVal_Any DGet(const ZVal_Any& iDefault, const string8& iName) const;
+ const ZVal_Any DGet(const ZVal_Any& iDefault, const Name_t& iName) const;
const ZVal_Any DGet(const ZVal_Any& iDefault, const Index_t& iIndex) const;
- const ZVal_Any& Get(const string8& iName) const;
+ const ZVal_Any& Get(const Name_t& iName) const;
const ZVal_Any& Get(const Index_t& iIndex) const;
template <class S>
- S* PGetMutable(const string8& iName)
+ S* PGetMutable(const Name_t& iName)
{
if (ZVal_Any* theVal = this->PGetMutable(iName))
return theVal->PGetMutable<S>();
@@ -252,7 +251,7 @@ class ZMap_Any
}
template <class S>
- const S* PGet(const string8& iName) const
+ const S* PGet(const Name_t& iName) const
{
if (const ZVal_Any* theVal = this->PGet(iName))
return theVal->PGet<S>();
@@ -268,7 +267,7 @@ class ZMap_Any
}
template <class S>
- const ZQ<S> QGet(const string8& iName) const
+ const ZQ<S> QGet(const Name_t& iName) const
{
if (const ZVal_Any* theVal = this->PGet(iName))
return theVal->QGet<S>();
@@ -284,7 +283,7 @@ class ZMap_Any
}
template <class S>
- const S DGet(const S& iDefault, const string8& iName) const
+ const S DGet(const S& iDefault, const Name_t& iName) const
{
if (const S* theVal = this->PGet<S>(iName))
return *theVal;
@@ -300,7 +299,7 @@ class ZMap_Any
}
template <class S>
- const S Get(const string8& iName) const
+ const S Get(const Name_t& iName) const
{
if (const S* theVal = this->PGet<S>(iName))
return *theVal;
@@ -315,29 +314,29 @@ class ZMap_Any
return S();
}
- ZMap_Any& Set(const string8& iName, const ZVal_Any& iVal);
+ ZMap_Any& Set(const Name_t& iName, const ZVal_Any& iVal);
ZMap_Any& Set(const Index_t& iIndex, const ZVal_Any& iVal);
template <class S>
- ZMap_Any& Set(const string8& iName, const S& iVal)
+ ZMap_Any& Set(const Name_t& iName, const S& iVal)
{ return this->Set(iName, ZVal_Any(iVal)); }
template <class S>
ZMap_Any& Set(const Index_t& iIndex, const S& iVal)
{ return this->Set(iIndex, ZVal_Any(iVal)); }
- ZMap_Any& Erase(const string8& iName);
+ ZMap_Any& Erase(const Name_t& iName);
ZMap_Any& Erase(const Index_t& iIndex);
// Our protocol
- ZVal_Any& Mutable(const string8& iName);
+ ZVal_Any& Mutable(const Name_t& iName);
template <class S>
- S& Mutable(const string8& iName)
+ S& Mutable(const Name_t& iName)
{ return this->Mutable(iName).Mutable<S>(); }
template <class S>
- S& DMutable(const S& iDefault, const string8& iName)
+ S& DMutable(const S& iDefault, const Name_t& iName)
{
if (S* theVal = this->PGetMutable<S>(iName))
return *theVal;
@@ -348,8 +347,8 @@ class ZMap_Any
Index_t Begin() const;
Index_t End() const;
- const string8& NameOf(const Index_t& iIndex) const;
- Index_t IndexOf(const string8& iName) const;
+ const Name_t& NameOf(const Index_t& iIndex) const;
+ Index_t IndexOf(const Name_t& iName) const;
Index_t IndexOf(const ZMap_Any& iOther, const Index_t& iOtherIndex) const;
@@ -361,8 +360,8 @@ class ZMap_Any
bool operator<(const ZMap_Any& r) const
{ return this->Compare(r) < 0; }
- ZVal_Any& operator[](const string8& iName);
- const ZVal_Any& operator[](const string8& iName) const;
+ ZVal_Any& operator[](const Name_t& iName);
+ const ZVal_Any& operator[](const Name_t& iName) const;
ZVal_Any& operator[](const Index_t& iIndex);
const ZVal_Any& operator[](const Index_t& iIndex) const;

0 comments on commit 2400589

Please sign in to comment.