Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
qbox
qbox-public
Commits
f435eadd
Commit
f435eadd
authored
Mar 25, 2022
by
Francois Gygi
Browse files
Define byte_t type, avoid conflict with std::byte
parent
61224598
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/Base64Transcoder.cpp
View file @
f435eadd
...
...
@@ -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
)
{
...
...
src/Base64Transcoder.h
View file @
f435eadd
...
...
@@ -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
);
...
...
src/Function3d.cpp
View file @
f435eadd
...
...
@@ -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
"
...
...
src/Function3dHandler.cpp
View file @
f435eadd
...
...
@@ -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
...
...
src/SlaterDet.cpp
View file @
f435eadd
...
...
@@ -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
)
{
...
...
src/XMLGFPreprocessor.cpp
View file @
f435eadd
...
...
@@ -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
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment