/* 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_ICLICVALUESTREAM_HPP_
#define _NMM_ICLICVALUESTREAM_HPP_

#include "nmm/nmm_prefix.hpp"

#include "nmm/comm/serialize/IValueStream.hpp"

#include "visibility.hpp"

namespace NMM {
class Event;

  /** Helper class to handle events and arguments read from graph description files.
   *  Eases the use of events with different types of arguments in ClicApplication.
   */

class DLLEXPORT IClicValueStream : public IValueStream {
public:
/** @name Constructor & Destructor
  */
//@{
/** Constructor
  */
  IClicValueStream();

  /** Copy constructor
  */
  IClicValueStream(const IClicValueStream&);
  
  /** Constructor
   *
   * @param event_key key of event
   * @param argument stack vector of event arguments
   */
  IClicValueStream(const string& event_key, const vector<string>& argument_stack );

/** Destructor
  */
  virtual ~IClicValueStream() {}

/** Virtual copy constructor
  */
  virtual IClicValueStream* copy() const ;
//@}

/** @name The operators
  */
//@{
    virtual IClicValueStream& operator>>(nmm_uint16&)       ;

    /** This method reads an int16 i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_int16&)        ; 

    /** This method reads an u_int32 i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_uint32&  )     ;

    /** This method reads an int32 i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_int32&  )       ;

    /** This method reads an u_int64 i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_uint64&  )     ;

    /** This method reads an int64 i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_int64&  )       ;

    /** This method reads a bool i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_bool&  )          ;

    /** This method reads a double i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_double& )        ;

    /** This method reads a float i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_float& )          ;

    /** This method reads a char i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_char& )         ;

    /** This method reads an unsigned char i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(nmm_uchar&)   ;

    /** This method reads a string i from the stream and returns a reference to the stream.
     */
    virtual IClicValueStream& operator>>(string&)         ;
//@}

/** @name Navigate through the attributes
  */
//@{
/** This method accesses the internal attributes of complex structure.
  */
  virtual bool goDown()    ;

/** This method leaves the internal attributes of complex structure.
  */
  virtual void goUp()      ;

/** This method returns true if no values are in the ValueStream.
  */
  virtual bool isEmpty()    const ;

/** This method reads all information from the next element
  */
  virtual bool nextElement() ;
//@}

/** @name Navigate through the attributes
  */
//@{
/** This method returns the current type information in a TypeInfo struct.
 *  @return current type information in a TypeInfo struct
  */
  virtual  const TypeInfo& getCurrentTypeInfo() const ;

/** This method returns the type name of the current element. The Stream must not be empty!
  * \sa isEmpty();
  * @return type name of the current element
  */
  virtual const string& getCurrentType() const ;

/** This method returns the namespace of the current element. The Stream must not be empty!
  * \sa isEmpty();
  * @return namespace of the current element
  */
  virtual const string& getCurrentNamespace() const ;

/** This method returns the type name of this IClicValueStream.
 * @return type name of this IClicValueStream
  */
  virtual const char* getIValueStreamType() const ;
//@}

  /** Copy current argument to buffer with length given threw arguments. 
   */
  virtual void readBuffer(char *, nmm_uint32);

  /** Copy current argument to buffer with length given threw arguments. 
   */
  virtual void readBuffer(unsigned char *, nmm_uint32);
  inline  const string& getEventKey() const { return __event_key; }

   /** Copy argument values from this IClicValueStream to event. 
   * @param event reference to event to copy argument values to    
   */
  void readEvent(Event& event);
private:
  void cutBlanks(string& s );
private:
  unsigned int          __current_pos;
  string                __event_key;
  vector< string >      __argument_stack;
  static const TypeInfo __empty_type_info;
  static const char*    __stream_type;
};


}

#include "nmm/nmm_suffix.hpp"

#endif // _NMM_IClicValueStream_HPP_


