// -*- C++ -*-
#ifndef RIIOCOMMON_H
#define RIIOCOMMON_H
/* Copyright 1996 
 * Mon Jun 22 10:30:10 1998  Brian Edward Smits  (bes@phoenix.cs.utah.edu)
 * 
 * RiIOCommon.H
 * 
 *	
 * 
 * $Id: RiIOCommon.H,v 1.2 1998/06/22 17:33:05 bes Exp $ 
 * 
 */
#ifndef RICOMMON_H
#include <RiCommon.H>
#endif

#ifndef RIVECTOR3_H
#include <RiVector3.H>
#endif

#ifndef RIVECTOR2_H
#include <RiVector2.H>
#endif

#include <iostream.h>
#include <rw/cstring.h>

inline unsigned RiHashString(const RWCString& str) {
    return str.hash();
}


/***************************************************************
CLASS
    RiIOWrite
     Encapsulate IO

DESCRIPTION
     Geared towards binary IO (output), with some generality allowed.
     The interface knows explicitly exactly how long each type is

****************************************************************/

class RiIOWrite {
  public:
    //// Destructor
    virtual ~RiIOWrite() {};
    // GROUP: Members
				//// 1 byte
    virtual bool WriteChar(char c) = 0;
				//// 1 byte
    virtual bool WriteUChar(unsigned char c) = 0;
				//// len bytes
    virtual bool WriteChars(char *s, int len) = 0;
				//// len bytes
    virtual bool WriteUChars(unsigned char *s, int len) = 0;
				//// 2 bytes
    virtual bool WriteUShort(int s) = 0;
				//// 4 bytes
    virtual bool WriteUInt(unsigned int i) = 0;
				//// 4 bytes
    virtual bool WriteInt(int i) = 0;
				//// 4 bytes
    virtual bool WriteReal(RiReal r) = 0;
				//// 2 * 4 bytes
    virtual bool WriteVector2(const RiVector2 &v) = 0;
				//// 3 * 4 bytes
    virtual bool WriteVector3(const RiVector3 &v) = 0;
};


/***************************************************************
CLASS
    RiIOWriteBinary
     <one line summary> 

DESCRIPTION
     <Detailed description with any warnings>

****************************************************************/

class RiIOWriteBinary : public RiIOWrite {
  public:
    // GROUP: Constructors and assignment
    //// Default Constructor
    RiIOWriteBinary(ostream &out);
    // GROUP: Members
				////
    virtual bool WriteChar(char c);
				////
    virtual bool WriteUChar(unsigned char c);
				////
    virtual bool WriteChars(char *s, int len);
				////
    virtual bool WriteUChars(unsigned char *s, int len);
				////
    virtual bool WriteUShort(int s);
				////
    virtual bool WriteUInt(unsigned int i);
				////
    virtual bool WriteInt(int i);
				////
    virtual bool WriteReal(RiReal r);
				////
    virtual bool WriteVector2(const RiVector2 &v);
				////
    virtual bool WriteVector3(const RiVector3 &v);
  private:
    ////Copy Constructor
    RiIOWriteBinary(const RiIOWriteBinary &);
    //// Assignment
    RiIOWriteBinary &operator=(const RiIOWriteBinary &);
				////
    ostream_withassign out;
};


/***************************************************************
CLASS
    RiIOWriteAscii
     <one line summary> 

DESCRIPTION
     <Detailed description with any warnings>

****************************************************************/

class RiIOWriteAscii : public RiIOWrite {
  public:
    // GROUP: Constructors and assignment
    //// Default Constructor
    RiIOWriteAscii(ostream &out);
    // GROUP: Members
				////
    virtual bool WriteChar(char c);
				////
    virtual bool WriteUChar(unsigned char c);
				////
    virtual bool WriteChars(char *s, int len);
				////
    virtual bool WriteUChars(unsigned char *s, int len);
				////
    virtual bool WriteUShort(int s);
				////
    virtual bool WriteUInt(unsigned int i);
				////
    virtual bool WriteInt(int i);
				////
    virtual bool WriteReal(RiReal r);
				////
    virtual bool WriteVector2(const RiVector2 &v);
				////
    virtual bool WriteVector3(const RiVector3 &v);
  private:
    ////Copy Constructor
    RiIOWriteAscii(const RiIOWriteAscii &);
    //// Assignment
    RiIOWriteAscii &operator=(const RiIOWriteAscii &);
				////
    ostream_withassign out;
};





/***************************************************************
CLASS
    RiIORead
     Encapsulate IO

DESCRIPTION
     Geared towards binary IO (input), with some generality allowed.
     The interface knows explicitly exactly how long each type is

****************************************************************/

class RiIORead {
  public:
    //// Destructor
    virtual ~RiIORead() {};
    // GROUP: Members
				//// 1 byte
    virtual bool ReadChar(char &c) = 0;
				//// 1 byte
    virtual bool ReadUChar(unsigned char &c) = 0;
				//// len bytes
    virtual bool ReadChars(char *s, int len) = 0;
				//// len bytes
    virtual bool ReadUChars(unsigned char *s, int len) = 0;
				//// 2 bytes
    virtual bool ReadUShort(int &s) = 0;
				//// 4 bytes
    virtual bool ReadUInt(unsigned int &i) = 0;
				//// 4 bytes
    virtual bool ReadInt(int &i) = 0;
				//// 4 bytes
    virtual bool ReadReal(RiReal &r) = 0;
				//// 2 * 4 bytes
    virtual bool ReadVector2(RiVector2 &v) = 0;
				//// 3 * 4 bytes
    virtual bool ReadVector3(RiVector3 &v) = 0;
};


/***************************************************************
CLASS
    RiIOReadBinary
     <one line summary> 

DESCRIPTION
     <Detailed description with any warnings>

****************************************************************/

class RiIOReadBinary : public RiIORead {
  public:
    // GROUP: Constructors and assignment
    //// Default Constructor
    RiIOReadBinary(istream &in);
    // GROUP: Members
				////
    virtual bool ReadChar(char &c);
				////
    virtual bool ReadUChar(unsigned char &c);
				////
    virtual bool ReadChars(char *s, int len);
				////
    virtual bool ReadUChars(unsigned char *s, int len);
				////
    virtual bool ReadUShort(int &s);
				////
    virtual bool ReadUInt(unsigned int &i);
				////
    virtual bool ReadInt(int &i);
				////
    virtual bool ReadReal(RiReal &r);
				////
    virtual bool ReadVector2(RiVector2 &v);
				////
    virtual bool ReadVector3(RiVector3 &v);
  private:
    ////Copy Constructor
    RiIOReadBinary(const RiIOReadBinary &);
    //// Assignment
    RiIOReadBinary &operator=(const RiIOReadBinary &);
				////
    istream_withassign in;
};


/***************************************************************
CLASS
    RiIOReadAscii
     <one line summary> 

DESCRIPTION
     <Detailed description with any warnings>

****************************************************************/

class RiIOReadAscii : public RiIORead {
  public:
    // GROUP: Constructors and assignment
    //// Default Constructor
    RiIOReadAscii(istream &in);
    // GROUP: Members
				////
    virtual bool ReadChar(char &c);
				////
    virtual bool ReadUChar(unsigned char &c);
				////
    virtual bool ReadChars(char *s, int len);
				////
    virtual bool ReadUChars(unsigned char *s, int len);
				////
    virtual bool ReadUShort(int &s);
				////
    virtual bool ReadUInt(unsigned int &i);
				////
    virtual bool ReadInt(int &i);
				////
    virtual bool ReadReal(RiReal &r);
				////
    virtual bool ReadVector2(RiVector2 &v);
				////
    virtual bool ReadVector3(RiVector3 &v);
  private:
    ////Copy Constructor
    RiIOReadAscii(const RiIOReadAscii &);
    //// Assignment
    RiIOReadAscii &operator=(const RiIOReadAscii &);
				////
    istream_withassign in;
};


#endif /* RIIOCOMMON_H */

