push 4f3e8a7446ee1ef84a8584a54c80e31f37761267
[tagua/yd.git] / src / variants.cpp
blob3f941ce20dd0d21c909279aabb3a0c565143515a
1 /*
2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@gmail.com>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 */
11 #include "variants.h"
12 #include "hlvariant/tagua_wrapped.h"
13 #include "hlvariant/chess/variant.h"
14 #include "hlvariant/crazyhouse/variant.h"
15 #include "hlvariant/dummy/variant.h"
16 #include "hlvariant/minichess5/variant.h"
17 #include "hlvariant/shogi/variant.h"
18 #include "hlvariant/minishogi/variant.h"
20 using namespace HLVariant;
22 template <typename Variant>
23 void register_variant(Variants* variants) {
24 variants->addFactory(
25 Variant::m_name,
26 new WrappedVariantFactory<Variant>);
30 Variants::Variants() {
31 register_variant<Chess::Variant>(this);
32 register_variant<Minichess5::Variant>(this);
33 register_variant<Crazyhouse::Variant>(this);
34 register_variant<Dummy::Variant>(this);
35 register_variant<Shogi::Variant>(this);
36 register_variant<MiniShogi::Variant>(this);
39 Variants& Variants::instance() {
40 static Variants inst;
41 return inst;
44 VariantPtr Variants::get(const QString& name) const {
45 Factories::const_iterator it = m_factories.find(name);
46 if (it != m_factories.end()) {
47 return VariantPtr(it->second->createVariant());
50 return VariantPtr();
53 void Variants::addFactory(const QString& name, VariantFactory* factory) {
54 m_factories[name] = factory;
55 std::cout << "added factory for variant " << name << std::endl;
58 QStringList Variants::all() const {
59 QStringList s;
60 for (Factories::const_iterator end = m_factories.end(), it = m_factories.begin(); it != end; ++it) {
61 s << it->first;
64 return s;