Commit f435eadd authored by Francois Gygi's avatar Francois Gygi
Browse files

Define byte_t type, avoid conflict with std::byte

parent 61224598
......@@ -63,18 +63,19 @@ Base64Transcoder::Base64Transcoder()
}
////////////////////////////////////////////////////////////////////////////////
int Base64Transcoder::encode(int nbytes, const byte* const from, char* const to)
int Base64Transcoder::encode(int nbytes, const byte_t* const from,
char* const to)
{
const byte* fptr = from;
const byte_t* fptr = from;
char* tptr = to;
int n3 = nbytes / 3; // number of groups of three bytes
while ( n3-- > 0 )
{
byte ig0 = *fptr++;
byte ig1 = *fptr++;
byte ig2 = *fptr++;
byte_t ig0 = *fptr++;
byte_t ig1 = *fptr++;
byte_t ig2 = *fptr++;
*tptr++ = etable[ig0 >> 2];
*tptr++ = etable[((ig0 & 3) << 4) | (ig1 >> 4)];
......@@ -86,9 +87,9 @@ int Base64Transcoder::encode(int nbytes, const byte* const from, char* const to)
if ( nr == 2 )
{
byte ig0 = *fptr++;
byte ig1 = *fptr++;
byte ig2 = 0;
byte_t ig0 = *fptr++;
byte_t ig1 = *fptr++;
byte_t ig2 = 0;
*tptr++ = etable[ig0 >> 2];
*tptr++ = etable[((ig0 & 3) << 4) | (ig1 >> 4)];
......@@ -97,8 +98,8 @@ int Base64Transcoder::encode(int nbytes, const byte* const from, char* const to)
}
else if ( nr == 1 )
{
byte ig0 = *fptr++;
byte ig1 = 0;
byte_t ig0 = *fptr++;
byte_t ig1 = 0;
*tptr++ = etable[ig0 >> 2];
*tptr++ = etable[((ig0 & 3) << 4) | (ig1 >> 4)];
......@@ -111,7 +112,7 @@ int Base64Transcoder::encode(int nbytes, const byte* const from, char* const to)
////////////////////////////////////////////////////////////////////////////////
int Base64Transcoder::decode(const int nchars, const char* const from,
byte* const to)
byte_t* const to)
{
// Decode Base64 chars in array "from" into bytes in array "to"
// White space and new lines are skipped
......@@ -120,11 +121,11 @@ int Base64Transcoder::decode(const int nchars, const char* const from,
// nchars: number of chars in array "from"
// the number of bytes successfully translated is returned
byte a2,a3,b0,b1,b2,b3;
byte_t a2,a3,b0,b1,b2,b3;
int c;
const char* fptr = from;
const char* const fptr_end = from+nchars+1;
byte* tptr = to;
byte_t* tptr = to;
while ( fptr < fptr_end-4 )
{
......@@ -142,8 +143,8 @@ int Base64Transcoder::decode(const int nchars, const char* const from,
#endif
break;
}
// a0 = (byte) c;
b0 = (byte) dtable[c];
// a0 = (byte_t) c;
b0 = (byte_t) dtable[c];
do
{
......@@ -158,8 +159,8 @@ int Base64Transcoder::decode(const int nchars, const char* const from,
#endif
break;
}
// a1 = (byte) c;
b1 = (byte) dtable[c];
// a1 = (byte_t) c;
b1 = (byte_t) dtable[c];
do
{
......@@ -174,8 +175,8 @@ int Base64Transcoder::decode(const int nchars, const char* const from,
#endif
break;
}
a2 = (byte) c;
b2 = (byte) dtable[c];
a2 = (byte_t) c;
b2 = (byte_t) dtable[c];
do
{
......@@ -190,8 +191,8 @@ int Base64Transcoder::decode(const int nchars, const char* const from,
#endif
break;
}
a3 = (byte) c;
b3 = (byte) dtable[c];
a3 = (byte_t) c;
b3 = (byte_t) dtable[c];
if ((b0|b1|b2|b3) & 0x80)
{
......
......@@ -23,18 +23,18 @@
#include <cstdio>
#include <string>
typedef unsigned char byte;
typedef unsigned char byte_t;
class Base64Transcoder
{
char etable[64]; // encode table
byte dtable[256]; // decode table
byte_t dtable[256]; // decode table
public:
Base64Transcoder();
int encode(int nbytes, const byte* const from, char* const to);
int decode(int nchars, const char* const from, byte* const to);
int encode(int nbytes, const byte_t* const from, char* const to);
int decode(int nchars, const char* const from, byte_t* const to);
void byteswap_double(size_t n, double* const x);
void byteswap_int(size_t n, int* const x);
int print(int nchars, const char* const buf, std::ostream& o);
......
......@@ -187,10 +187,10 @@ void Function3d::print(ostream& os) const
vector<double> tmpval(val);
xcdr.byteswap_double(tmpval.size(),&tmpval[0]);
// transform tmpval to base64 encoding
xcdr.encode(nbytes, (byte *) &tmpval[0], wbuf);
xcdr.encode(nbytes, (byte_t *) &tmpval[0], wbuf);
#else
// transform val to base64 encoding
xcdr.encode(nbytes, (byte *) &val[0], wbuf);
xcdr.encode(nbytes, (byte_t *) &val[0], wbuf);
#endif
os <<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
......
......@@ -202,7 +202,7 @@ void Function3dHandler::endElement(const XMLCh* const uri,
Timer tm;
tm.start();
Base64Transcoder xcdr;
size_t nbytes = xcdr.decode(buf_.size(),buf_.data(),(byte*)&f_.val[0]);
size_t nbytes = xcdr.decode(buf_.size(),buf_.data(),(byte_t*)&f_.val[0]);
assert(nbytes==f_.val.size()*sizeof(double));
buf_.clear();
#if PLT_BIG_ENDIAN
......
......@@ -1504,7 +1504,7 @@ void SlaterDet::print(ostream& os, string encoding, double weight, int ispin,
int outlen = xcdr.nchars(nbytes);
char* b = new char[outlen];
assert(b!=0);
xcdr.encode(nbytes,(byte*) &wftmpr[0],b);
xcdr.encode(nbytes,(byte_t*) &wftmpr[0],b);
// Note: optional x0,y0,z0 attributes not used, default is zero
os << "<grid_function type=\"" << element_type << "\""
<< " nx=\"" << ft.np0()
......@@ -1769,7 +1769,7 @@ void SlaterDet::str(string& sdstr, string encoding, double weight,
int outlen = xcdr.nchars(nbytes);
char* b = new char[outlen];
assert(b!=0);
xcdr.encode(nbytes,(byte*) &tmpr[0],b);
xcdr.encode(nbytes,(byte_t*) &tmpr[0],b);
// Note: optional x0,y0,z0 attributes not used, default is zero
if ( ctxt_.myrow() == 0 )
{
......
......@@ -1038,7 +1038,7 @@ int XMLGFPreprocessor::process(const char* const uri,
<< endl;
#endif
int nbytes = xcdr.decode(nchars,buf.data()+seg_start[iseg],
(byte*)&dbuf[iseg][0]);
(byte_t*)&dbuf[iseg][0]);
#if DEBUG
cout << rctxt.mype() << ": iseg=" << iseg << " nbytes=" << nbytes
<< endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment