Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LEFEBVREJP email
radix
Commits
5ebc61b3
Commit
5ebc61b3
authored
Oct 19, 2018
by
LEFEBVREJP email
Browse files
Adding support for unsigned short data type in eafstream.
parent
b4cb677e
Pipeline
#16465
passed with stages
in 15 minutes and 48 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
radixio/eafstream.cc
View file @
5ebc61b3
...
...
@@ -50,6 +50,16 @@ eafstream &eafstream::operator>>(short &value)
value
=
readShort
();
return
*
this
;
}
// short
/**
* Operator overload for read unsigned short
* @param value unsigned short reference to be populated
* @return
*/
eafstream
&
eafstream
::
operator
>>
(
unsigned
short
&
value
)
{
value
=
readUShort
();
return
*
this
;
}
// short
/**
* Operator overload for read int
* @param value int reference to be populated
...
...
@@ -210,6 +220,50 @@ void eafstream::writeShort(short var)
mBytesWritten
+=
short_size
;
}
/**
* \brief read a unsigned short integer from the offset in the file, accounting
* for endianness \return unsigned integer value .
*
*/
unsigned
short
eafstream
::
readUShort
()
{
unsigned
short
var
=
0
;
this
->
read
((
char
*
)(
&
var
),
short_size
);
if
(
this
->
bad
()
||
this
->
eof
())
{
std
::
stringstream
ss
;
ss
<<
"Error, reading unsigned short from file at offset."
<<
this
->
tellg
();
std
::
cout
<<
ss
.
str
()
<<
std
::
endl
;
throw
std
::
logic_error
(
ss
.
str
());
}
if
(
mReverseBytes
==
true
)
{
var
=
reverse_ushort_bytes
(
var
);
}
// increment bytes read
mBytesRead
+=
short_size
;
return
var
;
}
// readShort
void
eafstream
::
writeUShort
(
unsigned
short
var
)
{
if
(
mReverseBytes
==
true
)
{
var
=
reverse_ushort_bytes
(
var
);
}
this
->
write
((
char
*
)(
&
var
),
short_size
);
if
(
this
->
bad
()
||
this
->
eof
())
{
std
::
stringstream
ss
;
ss
<<
"Error, writing unsigned short to file at offset."
<<
this
->
tellg
();
std
::
cout
<<
ss
.
str
()
<<
std
::
endl
;
throw
std
::
logic_error
(
ss
.
str
());
}
mBytesWritten
+=
short_size
;
}
/**
* \brief read an integer from the offset in the file, accounting for
* endianness \return integer value or -1 on error.
...
...
radixio/eafstream.hh
View file @
5ebc61b3
...
...
@@ -45,6 +45,12 @@ class RADIX_PUBLIC eafstream : public std::fstream
*/
short
readShort
();
void
writeShort
(
short
var
);
/**
* \brief read a unsigned short integer from the file, accounting for
* endianness \return unsigned short value or -1 on error.
*/
unsigned
short
readUShort
();
void
writeUShort
(
unsigned
short
var
);
/**
* \brief read an integer from the file, accounting for endianness
* \return integer value or -1 on error.
...
...
@@ -132,6 +138,7 @@ class RADIX_PUBLIC eafstream : public std::fstream
int
footer
()
const
;
eafstream
&
operator
>>
(
short
&
value
);
eafstream
&
operator
>>
(
unsigned
short
&
value
);
eafstream
&
operator
>>
(
int
&
value
);
eafstream
&
operator
>>
(
float
&
value
);
eafstream
&
operator
>>
(
double
&
value
);
...
...
radixio/endian.cc
View file @
5ebc61b3
...
...
@@ -44,7 +44,18 @@ short reverse_short_bytes(short value)
short
returnVal
;
reverse_bytes
((
char
*
)
&
value
,
(
void
*
)
&
returnVal
,
sizeof
(
short
));
return
returnVal
;
}
// reverse_int_bytes
}
// reverse_short_bytes
/*!
* Reverses the bytes of an unsigned short
* */
unsigned
short
reverse_ushort_bytes
(
unsigned
short
value
)
{
unsigned
short
returnVal
;
reverse_bytes
((
char
*
)
&
value
,
(
void
*
)
&
returnVal
,
sizeof
(
short
));
return
returnVal
;
}
// reverse_ushort_bytes
/*!
* Reverses the bytes of an integer
* */
...
...
radixio/endian.hh
View file @
5ebc61b3
...
...
@@ -11,6 +11,7 @@ namespace radix
{
void
RADIX_PUBLIC
reverse_bytes
(
char
*
original
,
void
*
returnVal
,
int
length
);
short
RADIX_PUBLIC
reverse_short_bytes
(
short
value
);
unsigned
short
RADIX_PUBLIC
reverse_ushort_bytes
(
unsigned
short
value
);
int
RADIX_PUBLIC
reverse_int_bytes
(
int
value
);
void
RADIX_PUBLIC
reverse_array_int_bytes
(
int
*
array
,
int
size
);
void
RADIX_PUBLIC
reverse_array_float_bytes
(
float
*
array
,
int
size
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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