CDataStream.C
//-----------------------------------------------------------------------------
// $Header$
//
// COOL Program Library
// Copyright (C) CERES collaboration, 1996
//
// Implementation of class ...
//
//-----------------------------------------------------------------------------
#include "CDataStream.h"
// Cifstream::Cifstream() {}
// Cifstream::~Cifstream() {}
// Cifstream::Cifstream(const Cifstream &) {;}
// Cifstream & Cifstream::operator = (const Cifstream &) { return *this; }
void Cifstream::read(char * buffer, int nBytes)
{
// assuming buffer is big enough....
ifstream::read(buffer, nBytes);
#ifdef ARCH_IS_LITTLE_ENDIAN
// now we need to do some byte-swapping. assume all reading
// is done in multiples of 4 Bytes (true at present)
int index=0;
char *pbuf = buffer;
for (index=0; index<nBytes/4; index++) {
reverse4Bytes(pbuf);
pbuf+=4;
}
#endif
}
void Cofstream::write(char * buffer, int nBytes)
{
#ifdef ARCH_IS_LITTLE_ENDIAN
// now we need to do some byte-swapping. assume all reading
// is done in multiples of 4 Bytes (true at present)
int index=0;
char *pbuf = buffer;
for (index=0; index<nBytes/4; index++) {
reverse4Bytes(pbuf);
pbuf+=4;
}
#endif
ofstream::write((const char *)buffer, nBytes);
}
// define global function here....
void reverse4Bytes(char buf[4])
{
#ifdef ARCH_IS_LITTLE_ENDIAN
char c;
c = buf[0];
buf[0] = buf[3];
buf[3] = c;
c = buf[1];
buf[1] = buf[2];
buf[2] = c;
#endif
}