-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. We use polymorphism to invoke the actual
+/// endgame function by calling its virtual operator().
+
+class Endgames {
+
+ template<typename T> using Map = std::map<Key, std::unique_ptr<T>>;
+
+ template<EndgameType E, typename T = EndgameBase<typename eg_fun<E>::type>>
+ void add(const std::string& code);
+
+ template<typename T, int I = std::is_same<T, EndgameBase<ScaleFactor>>::value>
+ Map<T>& map() { return std::get<I>(maps); }
+
+ std::pair<Map<EndgameBase<Value>>, Map<EndgameBase<ScaleFactor>>> maps;
+
+public:
+ Endgames();
+
+ template<typename T> T* probe(Key key, T** eg)
+ { return *eg = map<T>().count(key) ? map<T>()[key].get() : nullptr; }