/* 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_I_VALUE_STREAM_HPP
#define NMM_I_VALUE_STREAM_HPP NMM_I_VALUE_STREAM_HPP

#include "nmm/nmm_prefix.hpp"

#include "IStream.hpp"
#include "visibility.hpp"

#include <string>

namespace NMM {

  class Value;
  class TypeInfo;

  /** An input value stream.
   * A value stream is a stream extended for type-safe serialization.
   * It stores type information along with serialized data and has additional support for
   * serializing structures and polymorphic types.
   *
   * This is an abstract class which defines the interface of a value stream.
   * All extended features of a value stream must be implemented in subclasses.
   */
  class DLLEXPORT IValueStream
    : public IStream
  {
  public:
    /** @name Constructor & Destructor
     */
    //@{
    /** Default constructor.
     */
    IValueStream();

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

    /** Virtual destructor.
     */
    virtual ~IValueStream() {}

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

    /** @name Serialization Operator
     */
    //@{
    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
      virtual IValueStream& operator>>(nmm_uint16& value)       = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual IValueStream& operator>>(nmm_int16& value)         = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual IValueStream& operator>>(nmm_uint32& value)     = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual IValueStream& operator>>(nmm_int32& value)       = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual IValueStream& operator>>(nmm_uint64& value)     = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual IValueStream& operator>>(nmm_int64& value)       = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual IValueStream& operator>>(nmm_bool& value)          = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual IValueStream& operator>>(nmm_double& value)         = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this 
     */
    virtual IValueStream& operator>>(nmm_float& value)          = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual IValueStream& operator>>(nmm_char& value)           = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual IValueStream& operator>>(nmm_uchar& value)   = 0;

    /** Input serialization operator.
     * This is the abstract input serialization operator for a basic type.
     * It must be implemented by subclasses.
     * Subclass implementations must have covariant return types.
     *
     * @param value Reference to variable to be serialized
     * @return *this
     */
    virtual IValueStream& operator>>(string& value)          = 0;
    //@}

    /** @name Type Information
     */
    //@{
    /** Begin reading structure attributes.
     * This method begins serialization of attributes of a structure.
     * If the current element is not a structure, then this method fails.
     *
     * @return @c true if this method succeeded, @c false otherwise
     */
    virtual bool goDown()    = 0;

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

    /** Skip current element.
     * This method skips the current element which would be serialized.
     * It should be used if an element is of the wrong type.
     * It is also used by implementations of serialization operations and goDown()/goUp()
     * in subclasses after serializing an element.
     *
     * @return @c true if the next element is valid, @c false otherwise
     */
    virtual bool nextElement() = 0;

    /** Get the type of the current element.
     * This method gets the type information for the type of the current element.
     * It should be used before serializing an element to check if the element has the correct type.
     *
     * @return Type information for type of current element
     */
    virtual  const TypeInfo& getCurrentTypeInfo() const = 0;

    /** Get the type of the current element.
     * This method gets the type name for the type of the current element.
     *
     * @return Type name for type of current element
     */
    virtual const string& getCurrentType() const = 0;

    /** Get the type of the current element.
     * This method gets the type namespace for the type of the current element.
     *
     * @return Type namespace for type of current element
     */
    virtual const string& getCurrentNamespace() const = 0;

    /** 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* getIValueStreamType() const = 0;
    //@}
  protected:
    /** Subclass constructor.
     * This constructor must be used by subclasses when initializing the base class.
     * Every subclass must also define this subclass constructor as a protected constructor.
     *
     * @param ti Type information for this object
     */
    IValueStream(const TypeInfo& ti);
  };
  
}

#include "nmm/nmm_suffix.hpp"

#endif
