// -*- c++ -*-

/*
 * Jakelib2 - General purpose C++ library
 * Copyright (C) 2001 Florian Wolff  (florian@donuz.de)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * $Id: Writer.h,v 1.14 2003/09/13 10:29:03 florian Exp $
 */

#ifndef INCLUDE_JAKELIB2_IO_WRITER_H
# define INCLUDE_JAKELIB2_IO_WRITER_H


namespace jakelib {
  namespace lang {
    class Synchronizeable;
  }

  namespace io {

    /**
     * @brief This abstract class forms the base of the hierarchy of classes that 
     * write output as a stream of chars.
     *
     * It provides a common set of methods
     * for writing chars to stream. Subclasses implement and/or extend these
     * methods to write chars in a particular manner or to a particular 
     * destination such as a file on disk or network connection.
     *
     * @class Writer
     * @version $Id: Writer.h,v 1.14 2003/09/13 10:29:03 florian Exp $
     * @author Florian 'Overflo' Wolff (florian@donuz.de)
     */
    class Writer : public jakelib::lang::Object
    {
    public:

      Writer();

      Writer(jakelib::lang::Synchronizeable* lock);

      /**
       * Writes the specified string.
       *
       * A newline is not added automatically.
       */
      virtual void write(jakelib::lang::String* str);

      /**
       * Writes the specified C-style string.
       */
      virtual void write(char* str);

      /**
       * Writes the specified character (\c jchar).
       */
      virtual void write(jint c);

      /**
       * Writes a number of characters to the output stream.
       *
       * @param buf The array containg the characters to be written.
       * @param offset The Offset in the \a buf array.
       * @param len The number of characters to be written.
       */
      virtual void write(jchar* buf, int offset, int len) = 0;

      /**
       * Flushes and closes the underlaying output stream.
       */
      virtual void close() = 0;

      /**
       * Flushes the underlaying output stream.
       */
      virtual void flush() = 0;

    protected:

      /** The Object on which to synchronize */
      jakelib::lang::Synchronizeable* lock;

      JAKELIB_DECLARE_CLASS(Writer);
    };

  }
}
#endif

