/* Network-Integrated Multimedia Middleware (NMM)
 * http://www.motama.com/nmm.html
 *  
 * Copyright (C) 2006-2007
 * Motama GmbH, Saarbruecken, Germany
 * http://www.motama.com
 *  
 * This file is part of NMM. 
 * 
 * NMM 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; only version 2 of the License.      
 * 
 * NMM 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 should have received a copy of the GNU General Public License 
 * along with NMM; if not, write to the Free Software Foundation,    
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

#ifndef NMM_STD_O_STREAM_HPP
#define NMM_STD_O_STREAM_HPP NMM_STD_O_STREAM_HPP

#include "nmm/nmm_prefix.hpp"

#include "OStream.hpp"

#include <ostream>

#include "visibility.hpp"

namespace NMM {

  /** Standard output stream.
   * This class is an output stream which wraps a standard C++ output stream.
   *
   * @see StdIStream
   */
  class DLLEXPORT StdOStream : public OStream {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Default constructor.
     * The given standard output stream is stored by reference. It must not be destroyed
     * as long as this stream is using it.
     *
     * @param os Pointer to standard outputstream
     */
    StdOStream(std::ostream* os) ;

    /** Virtual copy constructor.
     *
     * @return A copy of this object which has the same type
     */
    virtual StdOStream* copy() const;

    /** Destructor
     */
    virtual ~StdOStream() ;
    //@}

    /** @name Operator
     */
    //@{
    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual StdOStream& operator<<(const nmm_uint16& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual StdOStream& operator<<(const nmm_int16& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual StdOStream& operator<<(const nmm_uint32& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual StdOStream& operator<<(const nmm_int32& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual StdOStream& operator<<(const nmm_uint64& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual StdOStream& operator<<(const nmm_int64& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual StdOStream& operator<<(const nmm_bool& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual StdOStream& operator<<(const nmm_double& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual StdOStream& operator<<(const nmm_float& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual StdOStream& operator<<(const nmm_char& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual StdOStream& operator<<(const nmm_uchar& value);

    /** Output serialization operator.
     * This is the output serialization operator for a basic type.
     * This implementation invokes the output operator of the standard output stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual StdOStream& operator<<(const string& value);

    /** This method must be called if no other values are written.
     */
    virtual void writeData();
    //@}

    /** @name Buffer Writing
     */
    //@{
    /** Write raw data to this stream.
     * This method writes the given number of raw bytes from the buffer to the stream.
     *
     * @param buffer Pointer to buffer that stores the data to be written
     * @param size Number of bytes to write
     */
    virtual void writeBuffer(const char* buffer, nmm_uint32 size);

    /** Write raw data to this stream.
     * This method writes the given number of raw bytes from the buffer to the stream.
     *
     * @param buffer Pointer to buffer that stores the data to be written
     * @param size Number of bytes to write
     */
    virtual void writeBuffer(const unsigned char* buffer, nmm_uint32 size);
    //@}
  private:
    std::ostream * __stream;           ///< Pointer to standard stream
    char __fin;                        ///< Delimiter character
  };
  
}

#include "nmm/nmm_suffix.hpp"

#endif
