+Endgames::~Endgames() {
+
+ for (EFMap::const_iterator it = map<EF>().begin(); it != map<EF>().end(); ++it)
+ delete it->second;
+
+ for (SFMap::const_iterator it = map<SF>().begin(); it != map<SF>().end(); ++it)
+ delete it->second;
+}
+
+template<typename T, EndgameType E>
+void Endgames::add(const string& keyCode) {
+
+ typedef Endgame<T, E> EG;
+ typedef typename EG::Base B;
+ typedef std::map<Key, B*> M;
+
+ const_cast<M&>(map<B>()).insert(std::pair<Key, B*>(mat_key(keyCode), new EG(WHITE)));
+ const_cast<M&>(map<B>()).insert(std::pair<Key, B*>(mat_key(swap_colors(keyCode)), new EG(BLACK)));
+}
+
+template<typename T>
+EndgameBase<T>* Endgames::get(Key key) const {
+
+ typedef EndgameBase<T> E;
+ typename std::map<Key, E*>::const_iterator it = map<E>().find(key);
+ return it != map<E>().end() ? it->second : NULL;
+}
+
+// Explicit template instantiations
+template EF* Endgames::get<Value>(Key key) const;
+template SF* Endgames::get<ScaleFactor>(Key key) const;