// ---------------------------------------------------------------------------
// - Importer.hpp                                                            -
// - afnix:odc library - importer 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_IMPORTER_HPP
#define  AFNIX_IMPORTER_HPP

#ifndef  AFNIX_TABLE_HPP
#include "Table.hpp"
#endif

namespace afnix {

  /// The RecordImport class is a base class that permits to import data
  /// into a record. The base method operates with an input stream and
  /// attempts to read a literal. When read, the literal is added to the
  /// record until the stream is closed or the end-of-stream is reached.
  /// @author amaury darsch

  class RecordImport : public Object {
  protected:
    /// the importation record
    Record* p_ircd;

  public:
    /// create an empty importer
    RecordImport (void);

    /// create a importer with a record
    /// @param rcd the record to import into
    RecordImport (Record* rcd);

    /// destroy this importer
    ~RecordImport (void);

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

    /// @return the importation record
    virtual Record* getrcd (void) const;

    /// set the importation record
    /// @param rcd the importation record to set
    virtual void setrcd (Record* rcd);

    /// import cons data into the record
    /// @param cons the cons cell to use
    virtual void import (Cons* cons);

    /// import stream data into the record
    /// @param is the input stream to use
    virtual void import (Input* is);

    /// generate a new importer
    /// @param argv the argument vector
    static Object* mknew (Vector* argv);
 
    /// apply this importer with a set of arguments and a quark
    /// @param robj   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
    RecordImport (const RecordImport&);
    // make the assignment operator private
    RecordImport& operator = (const RecordImport&);
  };

  /// The Table class is a base class that permits to import data
  /// into a table. The base method operates with an input stream and
  /// attempts to build a cons cell that will be used as a table record.
  /// The importation operates as long as the stream is valid.
  /// @author amaury darsch

  class TableImport : public Object {
  protected:
    /// the importation table
    Table* p_itbl;

  public:
    /// create an empty importer
    TableImport (void);

    /// create a importer with a record
    /// @param tbl the table to import into
    TableImport (Table* tbl);

    /// destroy this importer
    ~TableImport (void);

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

    /// @return the importation table
    virtual Table* gettbl (void) const;

    /// set the importation table
    /// @param rcd the importation record to set
    virtual void settbl (Table* tbl);

    /// import cons data into the table
    /// @param cons the cons cell to use
    virtual void import (Cons* cons);

    /// import stream data into the table
    /// @param is the input stream to use
    virtual void import (Input* is);

    /// generate a new importer
    /// @param argv the argument vector
    static Object* mknew (Vector* argv);
 
    /// apply this importer with a set of arguments and a quark
    /// @param robj   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
    TableImport (const TableImport&);
    // make the assignment operator private
    TableImport& operator = (const TableImport&);
  };
}

#endif
