From f26e0fec64eed03279704e851b11c1654ea2c63c Mon Sep 17 00:00:00 2001 From: Marco Costalba Date: Sun, 8 Aug 2010 12:38:30 +0100 Subject: [PATCH] Usual material.cpp small touches No functional change. Signed-off-by: Marco Costalba --- src/material.cpp | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/material.cpp b/src/material.cpp index 0d38c37d..e19b0c9e 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -57,6 +57,8 @@ namespace { typedef EndgameEvaluationFunctionBase EF; typedef EndgameScalingFunctionBase SF; + typedef map EFMap; + typedef map SFMap; // Endgame evaluation and scaling functions accessed direcly and not through // the function maps because correspond to more then one material hash key. @@ -113,21 +115,17 @@ private: static Key buildKey(const string& keyCode); static const string swapColors(const string& keyCode); - // Here we store two maps, for evaluate and scaling functions - pair, map > maps; + // Here we store two maps, for evaluate and scaling functions... + pair maps; - // Maps accessing functions returning const and non-const references - template const map& get() const { return maps.first; } - template map& get() { return maps.first; } + // ...and here is the accessing template function + template const map& get() const; }; // Explicit specializations of a member function shall be declared in // the namespace of which the class template is a member. -template<> const map& -EndgameFunctions::get() const { return maps.second; } - -template<> map& -EndgameFunctions::get() { return maps.second; } +template<> const EFMap& EndgameFunctions::get() const { return maps.first; } +template<> const SFMap& EndgameFunctions::get() const { return maps.second; } //// @@ -380,11 +378,11 @@ EndgameFunctions::EndgameFunctions() { EndgameFunctions::~EndgameFunctions() { - for (map::iterator it = maps.first.begin(); it != maps.first.end(); ++it) - delete (*it).second; + for (EFMap::const_iterator it = maps.first.begin(); it != maps.first.end(); ++it) + delete it->second; - for (map::iterator it = maps.second.begin(); it != maps.second.end(); ++it) - delete (*it).second; + for (SFMap::const_iterator it = maps.second.begin(); it != maps.second.end(); ++it) + delete it->second; } Key EndgameFunctions::buildKey(const string& keyCode) { @@ -419,14 +417,15 @@ template void EndgameFunctions::add(const string& keyCode) { typedef typename T::Base F; + typedef map M; - get().insert(pair(buildKey(keyCode), new T(WHITE))); - get().insert(pair(buildKey(swapColors(keyCode)), new T(BLACK))); + const_cast(get()).insert(pair(buildKey(keyCode), new T(WHITE))); + const_cast(get()).insert(pair(buildKey(swapColors(keyCode)), new T(BLACK))); } template T* EndgameFunctions::get(Key key) const { - typename map::const_iterator it(get().find(key)); - return (it != get().end() ? it->second : NULL); + typename map::const_iterator it = get().find(key); + return it != get().end() ? it->second : NULL; } -- 2.39.2