/**********************************************************************
 *
 *   FreeDoko a Doppelkopf-Game
 *    
 *   Copyright (C) 2001-2004  by Diether Knof and Borg Enders
 *
 *   This program is free software; you can redistribute it and/or 
 *   modify it under the terms of the GNU General Public License as 
 *   published by the Free Software Foundation; either version 2 of 
 *   the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details. 
 *   You can find this license in the file 'gpl.txt'.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *   MA  02111-1307  USA
 *
 *  Contact:
 *    Diether Knof dknof@gmx.de
 *    Borg Enders  borg@borgsoft.de
 *
 *********************************************************************/

#ifndef CLASS_TRANSLATOR_HEADER
#define CLASS_TRANSLATOR_HEADER

#include "constants.h"

#include "../basistypes.h"

#include "../card/card.h"

#include "../party/rule.h"
#include "../game/game.h"
#include "../player/player.h"
#include "../player/aiconfig.h"

/**
 **
 ** The translator
 ** * supports recursive translations
 ** * can be used independent, just remove all FreeDoko-specific conversions
 **   (should only be in this file)
 **
 ** @author	Diether Knof
 **
 **/
class Translator {
  public:
#include "translation.h"
    friend class Translation;

  public:
    static vector<string> directories;
    static vector<string> names;

    static void dir_scan();
    static void dir_scan(string const& dirname);

  public:

    Translator();

    ~Translator();

    string const& name() const;
    string const& token() const;

    // no argument
    Translation operator()(string const& text) const
    { return Translation(this, text); }

    // one argument
    Translation operator()(char const* const text,
			   int const i) const
    { return Translation(this, text, i); }

    Translation operator()(char const* const text,
			   unsigned const u) const
    { return Translation(this, text, u); }

    Translation operator()(char const* const text,
			   string const s) const
    { return Translation(this, text, s); }

    Translation operator()(char const* const text,
			   Translation const t) const
    { return Translation(this, text, t); }

    // two arguments

    // first: string
    Translation operator()(char const* const text,
			   string const& s0,
			   int const i1) const
    { return Translation(this, text, s0, i1); }

    Translation operator()(char const* const text,
			   string const& s0,
			   unsigned const u1) const
    { return Translation(this, text, s0, u1); }

    Translation operator()(char const* const text,
			   string const& s0,
			   string const& s1) const
    { return Translation(this, text, s0, s1); }

    Translation operator()(char const* const text,
			   string const& s0,
			   Translation const& t1) const
    { return Translation(this, text, s0, t1); }

    // first: Translation
    Translation operator()(char const* const text,
			   Translation const& t0,
			   int const i1) const
    { return Translation(this, text, t0, i1); }

    Translation operator()(char const* const text,
			   Translation const& t0,
			   unsigned const u1) const
    { return Translation(this, text, t0, u1); }

    Translation operator()(char const* const text,
			   Translation const& t0,
			   string const& s1) const
    { return Translation(this, text, t0, s1); }

    Translation operator()(char const* const text,
			   Translation const& t0,
			   Translation const& t1) const
    { return Translation(this, text, t0, t1); }

    // three arguments

    // first: string

    Translation operator()(char const* const text,
			   string const& s0,
			   string const& s1,
			   string const& s2) const
    { return Translation(this, text, s0, s1, s2); }

    Translation operator()(char const* const text,
			   string const& s0,
			   Translation const& t1,
			   Translation const& t2) const
    { return Translation(this, text, s0, t1, t2); }




    // other conversions

    Translation operator()(Card::Value const& value) const
    { return Translation(this, ::name(value)); }
    Translation operator()(Card::TColor const& tcolor) const
    { return Translation(this, ::name(tcolor)); }
    Translation operator()(Card const& card) const
    { return Translation(this, ::name(card)); }

    Translation operator()(Rule::TypeBool const& type) const
    { return Translation(this, ::name(type)); }
    Translation operator()(Rule::TypeUnsigned const& type) const
    { return Translation(this, ::name(type)); }

    Translation operator()(Team const& team) const
    { return Translation(this, ::name(team)); }
    Translation operator()(GameType const& game_type) const
    { return Translation(this, ::name(game_type)); }
    Translation operator()(Announcement const& announcement) const
    { return Translation(this, ::name(announcement)); }
    Translation operator()(MarriageSelector const& marriage_selector) const
    { return Translation(this, ::name(marriage_selector)); }
    Translation operator()(Specialpoint const& special_point) const
    { return Translation(this, ::name(special_point)); }

    Translation operator()(Player::Type const& type) const
    { return Translation(this, ::name(type)); }
    Translation operator()(AiType const& aitype) const
    { return Translation(this, ::name(aitype)); }

    bool contains(string const& text) const;

    void load();
    void load(string filename);
    void update();

  protected:
    string translate(Translation const& translation) const;
    string expand(Translation const& translation) const;

  private:
    string name_;
    map<string, string> translation_;

  private: // not to be used
    Translator(Translator const&);
    Translator& operator=(Translator const&);
}; // class Translator


Translator::Translation operator+(Translator::Translation const& translation,
				  Translator::Translation const& translation);
Translator::Translation operator+(Translator::Translation const& translation,
				  string const& text);
Translator::Translation operator+(string const& text,
				  Translator::Translation const& translation);

bool operator==(Translator::Translation const& translation,
		Translator::Translation const& translation);
bool operator==(Translator::Translation const& translation,
		string const& text);
bool operator==(string const& text,
		Translator::Translation const& translation);

ostream& operator<<(ostream& ostr, Translator::Translation const& translation);

extern Translator translator;

#endif // #ifndef CLASS_TRANSLATOR_HEADER
