/***************************************************************
 * PrDataOutput.h
 *
 * This class provides Data Output methods.
 *
 ****************************************************************/

/*
 * modification history
 *----------------------
 *
 * 02/14/98: K.C. Chang: created.
 */

#ifndef _PrDataOutput_h
#define _PrDataOutput_h

#include "PrGlobalDefn.h"
#include "PrNetworkDefn.h"

#define PR_DATAOUTPUT_OK    1
#define PR_DATAOUTPUT_ERROR 0

class PrSocket;

class PrDataOutput
{
public:
  PrDataOutput( PrSocket *socket, int bufferSize = PR_NETWORK_BUFFER_SIZE );
  ~PrDataOutput();

  int flag() { return flag_; }

  // number of data bytes
  int flush( int type );

  int bufferSize( int nbytes );

  // returns nbytes

  int writeChar( char *data, int num ) { return Pack(data,num,1); }
  int writeShort( short *data, int num ) { return Pack((char *)data,num,2); }
  int writeInt( int *data, int num ) { return Pack((char *)data,num,4); }
  int writeLong( long *data, int num ) { return Pack((char *)data,num,4); }
  int writeFloat( float *data, int num ) { return Pack((char *)data,num,4); }
  int writeDouble( double *data, int num ) { return Pack((char *)data,num,8); }

private:
  int flag_;
  int socketFD_;
  char *buffer_;
  int bufferSize_;
  int byteCounter_;
  int endian_;

  int Init(int nbytes);
  int InitByteCounter();

  int Send();
  int Endian();

  void Pack1B( char *text, char data );
  void Pack2B( char *text, short data );
  void Pack4B( char *text, long data );
  void Pack8B( char *text, double data );

  int Pack( char *data, int num, int size );

  // copy is not allowed
  PrDataOutput( const PrDataOutput & ) {}
};

#endif // _PrDataOutput_h



