Initial porting to the new component API.
[tagua/yd.git] / src / variants.cpp
blob17fa8565f22e4d0eaf9a489e63f8182fa62a6b5c
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 <core/variant.h>
14 Variant* chess_variant_factory();
16 Variants::Variants() {
17 addFactory("Chess", &chess_variant_factory);
20 Variants& Variants::instance() {
21 static Variants inst;
22 return inst;
25 Variant* Variants::get(const QString& name) const {
26 VariantFactory* factory = m_factories.find(name)->second;
27 return (*factory)();
30 void Variants::addFactory(const QString& name, VariantFactory* factory) {
31 m_factories[name] = factory;
34 QStringList Variants::all() const {
35 QStringList s;
36 for (Factories::const_iterator end = m_factories.end(), it = m_factories.begin(); it != end; ++it) {
37 s << it->first;
40 return s;