// ---------------------------------------------------------------------------
// - Literate.hpp                                                            -
// - afnix:txt library - transliterate object class definition               -
// ---------------------------------------------------------------------------
// - This program is free software;  you can redistribute it  and/or  modify -
// - it provided that this copyright notice is kept intact.                  -
// -                                                                         -
// - 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.  In no event shall -
// - the copyright holder be liable for any  direct, indirect, incidental or -
// - special damages arising in any way out of the use of this software.     -
// ---------------------------------------------------------------------------
// - copyright (c) 1999-2005 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  AFNIX_LITERATE_HPP
#define  AFNIX_LITERATE_HPP

#ifndef  AFNIX_INPUT_HPP
#include "Input.hpp"
#endif
 
namespace afnix {
  
  /// A Literate object is a special object that permits to perform 
  /// transliteration with an input stream. The transliteration process
  /// is a two steps process. The first step map a character into another
  /// one and the second step escape a character. To do so, the object
  /// maintains two tables. The first table is the mapping table and the
  /// second table is the escape table.
  /// @author amaury darsch

  class Literate : public Object {
  public:
    /// transliteration models
    enum t_model {
      NONE = 0, // no transliteration
      ASTR = 1  // afnix string escape
    };
      
  private:
    /// the mapping table
    char d_mapt[256];
    /// the escape character
    char d_escc;
    /// the escape table
    char d_esct[256];

  public:
    /// create a default literate
    Literate (void);

    /// create a literate with a escape character
    /// @param escc the escape character to use
    Literate (const char escc);

    /// create a literate with a model
    /// @param model the literate model description
    Literate (const t_model model);

    /// @return the class name
    String repr (void) const;

    /// reset this literate
    void reset (void);

    /// set a translation model
    /// @param model the model to set
    void setmodel (const t_model model);

    /// set a mapping character
    /// @param mapc the mapping character
    /// @param altc the alternate character
    void setmap (const char mapc, const char altc);

    /// @return a mapping character
    char getmap (const char mapc) const;

    /// set the escape character
    /// @param esc the escape character
    void setesc (const char esc);

    /// @return the escape character
    char getesc (void) const;

    /// set an escape mapping sequence
    /// @param escc the escaped character
    /// @param altc the alternate character
    void setemc (const char mapc, const char altc);

    /// @return an escaped mapping character
    char getemc (const char mapc) const;

    /// transliterate a string into another string
    /// @param s the string to transliterate
    String translate (const String& s) const;

    /// @return a literate character from a stream
    char read (Input& is) const;

    /// generate a new literate object in a generic way
    /// @param argv the argument vector
    static Object* mknew (Vector* argv);

    /// apply this literate with a set of arguments and a quark
    /// @param robj   the current runnable
    /// @param nset   the current nameset    
    /// @param quark  the quark to apply these arguments
    /// @param argv   the arguments to apply
    Object* apply (Runnable* robj, Nameset* nset, const long quark,
		   Vector* argv);

  private:
    // make the copy constructor private
    Literate (const Literate&);
    // make the assignement operator private
    Literate& operator = (const Literate&);
  };
}

#endif
