-template<EndgameType>
-struct ScalingFunction : public EndgameScalingFunctionBase {
- typedef EndgameScalingFunctionBase Base;
- explicit ScalingFunction(Color c) : EndgameScalingFunctionBase(c) {}
- ScaleFactor apply(const Position&) const;
+
+/// The Endgames class stores the pointers to endgame evaluation and scaling
+/// base objects in two std::map typedefs. We then use polymorphism to invoke
+/// the actual endgame function by calling its virtual operator().
+
+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; }