/* 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_MAGIC_NUMBER_O_VALUE_STREAM_HPP
#define NMM_MAGIC_NUMBER_O_VALUE_STREAM_HPP NMM_MAGIC_NUMBER_O_VALUE_STREAM_HPP

#include "nmm/nmm_prefix.hpp"

#include "OValueStream.hpp"
#include "GenericMagicNumber.hpp"

#include "visibility.hpp"

namespace NMM {
  
  class MagicNumberManager;
  
  /** Output value stream which uses magic numbers.
   * This value stream works with serialized data in binary format.
   * Magic numbers are used for representing type information and structure boundaries.
   *
   * @see MagicNumberOValueStream, MagicNumberManager
   */
  class DLLEXPORT MagicNumberOValueStream
    : public OValueStream,
      public GenericMagicNumber
  {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Default constructor.
     */
    MagicNumberOValueStream();

    /** Copy constructor.
     *
     * @param ov Value stream object to copy from
     */
    MagicNumberOValueStream(const MagicNumberOValueStream& ov);

    /** Virtual destructor.
     */
    virtual ~MagicNumberOValueStream();

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

    /** @name Serialization Operator
     */
    //@{

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_uint16& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_int16& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_uint32& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_int32& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_uint64& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
      virtual MagicNumberOValueStream& operator<<(const nmm_int64& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_bool& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
      virtual MagicNumberOValueStream& operator<<(const nmm_double& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_float& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_char& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual MagicNumberOValueStream& operator<<(const nmm_uchar& value);

    /** Output serialization operator.
     * This is the abstract output serialization operator for a basic type.
     * This implementation generates binary data with magic numbers.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual MagicNumberOValueStream& operator<<(const string& value);

    /** Write serialized data.
     * This method must be called after all data has been serialized.
     * It flushes written data internally.
     */
    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);
    //@}

    /** @name Type Information
     */
    //@{
    /** Begin writing structure elements.
     * This method begins serialization of attributes of a structure.
     *
     * @param type Type name of the structure
     * @param ns Type namespace of the structure
     */
    virtual void beginType(const string& type, const string& ns = "std");

    /** Begin writing structure elements.
     * This method begins serialization of attributes of a structure.
     *
     * @param type Type information if the structure
     */
    virtual void beginType(int type);

    /** End reading structure attributes.
     * This method ends serialization of attributes of a structure.
     */
    virtual void endType() ;

    /** Get the type name of this stream.
     * This method returns the type name of this stream object.
     *
     * @deprecated Use SerializedValue::getTypeInfo() instead
     */
    virtual const char* getOValueStreamType() const { return __o_value_stream_type; }
    //@}
  private:
    MagicNumberManager*     __magic_number_manager;          ///< Pointer to the MagicNumberManager
  public:
    static const char*      __o_value_stream_type;           ///< Value stream type name ("MagicNumberOValueStream")
  };

}

#include "nmm/nmm_suffix.hpp"

#endif
