/* 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_I_STREAM_HPP
#define NMM_STD_I_STREAM_HPP NMM_STD_I_STREAM_HPP

#include "nmm/nmm_prefix.hpp"

#include "IStream.hpp"

#include <istream>

#include "visibility.hpp"

namespace NMM {

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

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

    /** @name Serialization Operator
     */
    //@{
    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual  StdIStream& operator>>(nmm_uint16& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual  StdIStream& operator>>(nmm_int16& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual  StdIStream& operator>>(nmm_uint32& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual  StdIStream& operator>>(nmm_int32& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual  StdIStream& operator>>(nmm_uint64& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual  StdIStream& operator>>(nmm_int64& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual  StdIStream& operator>>(nmm_bool& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual  StdIStream& operator>>(nmm_double& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual  StdIStream& operator>>(nmm_float& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual  StdIStream& operator>>(nmm_char& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual  StdIStream& operator>>(nmm_uchar& value);

    /** Input serialization operator.
     * This is the input serialization operator for a basic type.
     * This implementation invokes the input operator of the standard input stream.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual  StdIStream& operator>>(string& value);
    //@}

    /** @name Buffer Reading
     */
    //@{
    /** Read raw data from this stream.
     * This method reads exactly the given number of raw bytes from the stream
     * and stores the read data in a buffer.
     *
     * @param buffer Pointer to buffer that stores the read data
     * @param size Number of bytes to read
     */
    virtual void readBuffer(char*, nmm_uint32 size)           ;

    /** Read raw data from this stream.
     * This method reads exactly the given number of raw bytes from the stream
     * and stores the read data in a buffer.
     *
     * @param buffer Pointer to buffer that stores the read data
     * @param size Number of bytes to read
     */
    virtual void readBuffer(unsigned char* buffer, nmm_uint32 size);
    //@}

    /** Check if this stream is empty.
     * This method checks if this stream contains no data to read.
     * If this method returns @c true, serialization operations will fail.
     *
     * @return @c true if this stream is empty, @c false otherwise
     */
    virtual bool isEmpty() const;
  private:
    std::istream *__stream;     ///< Pointer to standard stream
  };
  
}

#include "nmm/nmm_suffix.hpp"

#endif
