// ---------------------------------------------------------------------------
// - Serial.hpp                                                              -
// - standard object library - serializable object abstract 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-2006 amaury darsch                                   -
// ---------------------------------------------------------------------------

#ifndef  AFNIX_SERIAL_HPP
#define  AFNIX_SERIAL_HPP

#ifndef  AFNIX_OBJECT_HPP
#include "Object.hpp"
#endif

namespace afnix {

  /// The Serial class is an abstract class that defines the object 
  /// interface for serialization. An object serialization is performed 
  /// with the "wrstream" virtual method. The deserialization is performed
  /// with the "rdstream" virtual method.
  /// @author amaury darsch

  class Serial : public virtual Object {
  public:
    /// the default serial constructor prototype
    typedef Serial* (*t_genser) (void);

  public:
    /// @return the object serial code
    virtual t_byte serialid (void) const;

    /// serialize an object to an output stream
    /// @param os the output stream to write
    virtual void wrstream (class Output& os) const;

    /// deserialize an object from an input stream
    /// @param is the input steam to read in
    virtual void rdstream (class Input& is);

    /// serialize an object with its serial id
    /// @param os the output stream to write
    virtual void serialize (class Output& os) const;

    /// write a nil id to an output stream
    /// serialize an object to an output stream
    static void wrnilid (class Output& os);

    // register a deserialize callback
    static t_byte setsid (const t_byte sid, t_genser cbk);

    /// @return a serial object by serial id
    static Serial* getserial (const t_byte sid);

    /// @return an object by deserialization
    static Object* deserialize (class Input& is);
  };
}

#endif
