-template<EndgameType>
-struct ScalingFunction : public EndgameScalingFunctionBase {
- typedef EndgameScalingFunctionBase Base;
- explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
- ScaleFactor apply(const Position&) const;
+
+/// Endgames class stores in two std::map the pointers to endgame evaluation
+/// and scaling base objects. Then we use polymorphism to invoke the actual
+/// endgame function calling its operator() that is virtual.
+
+class Endgames {
+
+ typedef std::map<Key, EndgameBase<eg_fun<0>::type>*> M1;
+ typedef std::map<Key, EndgameBase<eg_fun<1>::type>*> M2;
+
+ M1 m1;
+ M2 m2;
+
+ M1& map(M1::mapped_type) { return m1; }
+ M2& map(M2::mapped_type) { return m2; }
+
+ template<EndgameType E> void add(const std::string& code);
+
+public:
+ Endgames();
+ ~Endgames();
+
+ template<typename T> T probe(Key key, T& eg)
+ { return eg = map(eg).count(key) ? map(eg)[key] : NULL; }