Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
909af644
Commit
909af644
authored
9 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Added comparison operators to ByteArray
parent
cce80246
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
common/ByteArray.cpp
+47
-0
47 additions, 0 deletions
common/ByteArray.cpp
common/ByteArray.hpp
+22
-1
22 additions, 1 deletion
common/ByteArray.hpp
common/ByteArrayTest.cpp
+60
-0
60 additions, 0 deletions
common/ByteArrayTest.cpp
with
129 additions
and
1 deletion
common/ByteArray.cpp
+
47
−
0
View file @
909af644
...
...
@@ -18,6 +18,8 @@
#include
"common/ByteArray.hpp"
#include
<ostream>
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
...
...
@@ -85,6 +87,34 @@ cta::ByteArray &cta::ByteArray::operator=(const ByteArray &rhs) {
return
*
this
;
}
//------------------------------------------------------------------------------
// operator==
//------------------------------------------------------------------------------
bool
cta
::
ByteArray
::
operator
==
(
const
ByteArray
&
rhs
)
const
{
if
(
this
==
&
rhs
)
{
return
true
;
}
if
(
m_size
!=
rhs
.
m_size
)
{
return
false
;
}
for
(
uint32_t
i
=
0
;
i
<
m_size
;
i
++
)
{
if
(
m_bytes
[
i
]
!=
rhs
.
m_bytes
[
i
])
{
return
false
;
}
}
return
true
;
}
//------------------------------------------------------------------------------
// operator!=
//------------------------------------------------------------------------------
bool
cta
::
ByteArray
::
operator
!=
(
const
ByteArray
&
rhs
)
const
{
return
!
operator
==
(
rhs
);
}
//------------------------------------------------------------------------------
// getSize
//------------------------------------------------------------------------------
...
...
@@ -98,3 +128,20 @@ uint32_t cta::ByteArray::getSize() const throw() {
const
uint8_t
*
cta
::
ByteArray
::
getBytes
()
const
throw
()
{
return
m_bytes
;
}
//------------------------------------------------------------------------------
// operator<<
//------------------------------------------------------------------------------
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
cta
::
ByteArray
&
obj
)
{
os
<<
"{"
;
const
auto
size
=
obj
.
getSize
();
const
auto
bytes
=
obj
.
getBytes
();
for
(
uint32_t
i
=
0
;
i
<
size
;
i
++
)
{
os
<<
bytes
[
i
];
}
os
<<
"}"
;
return
os
;
}
This diff is collapsed.
Click to expand it.
common/ByteArray.hpp
+
22
−
1
View file @
909af644
...
...
@@ -86,6 +86,22 @@ public:
*/
ByteArray
&
operator
=
(
const
ByteArray
&
rhs
);
/**
* Returns true if the specified right-hand side is equal to this object.
*
* @param rhs The object on the right-hand side of the == operator.
* @return True if the specified right-hand side is equal to this object.
*/
bool
operator
==
(
const
ByteArray
&
rhs
)
const
;
/**
* Returns true if the specified right-hand side is not euqal to this object.
*
* @param rhs The object on the right-hand side of the != operator.
* @return True if the specified right-hand side is not equal to this object.
*/
bool
operator
!=
(
const
ByteArray
&
rhs
)
const
;
/**
* Returns the size of the array in bytes.
*
...
...
@@ -101,7 +117,7 @@ public:
* @return The contents of the array of bytes or NULL if the array is empty.
*/
const
uint8_t
*
getBytes
()
const
throw
();
private
:
/**
...
...
@@ -117,3 +133,8 @@ private:
};
// class ByteArray
}
// namespace cta
/**
* Output stream operator for the cta::ByteArray class.
*/
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
cta
::
ByteArray
&
obj
);
This diff is collapsed.
Click to expand it.
common/ByteArrayTest.cpp
+
60
−
0
View file @
909af644
...
...
@@ -146,4 +146,64 @@ TEST_F(cta_ByteArrayTest, assignment_operator) {
ASSERT_NE
(
byteArray1
.
getBytes
(),
byteArray2
.
getBytes
());
}
TEST_F
(
cta_ByteArrayTest
,
equality_operator_eq
)
{
using
namespace
cta
;
const
uint32_t
arraySize1
=
4
;
const
uint8_t
bytes1
[
4
]
=
{
10
,
20
,
30
,
40
};
const
ByteArray
byteArray1
(
arraySize1
,
bytes1
);
ASSERT_EQ
(
arraySize1
,
byteArray1
.
getSize
());
ASSERT_EQ
((
uint8_t
)
10
,
byteArray1
.
getBytes
()[
0
]);
ASSERT_EQ
((
uint8_t
)
20
,
byteArray1
.
getBytes
()[
1
]);
ASSERT_EQ
((
uint8_t
)
30
,
byteArray1
.
getBytes
()[
2
]);
ASSERT_EQ
((
uint8_t
)
40
,
byteArray1
.
getBytes
()[
3
]);
const
uint32_t
arraySize2
=
4
;
const
uint8_t
bytes2
[
4
]
=
{
10
,
20
,
30
,
40
};
ByteArray
byteArray2
(
arraySize2
,
bytes2
);
ASSERT_EQ
(
arraySize2
,
byteArray2
.
getSize
());
ASSERT_EQ
((
uint8_t
)
10
,
byteArray2
.
getBytes
()[
0
]);
ASSERT_EQ
((
uint8_t
)
20
,
byteArray2
.
getBytes
()[
1
]);
ASSERT_EQ
((
uint8_t
)
30
,
byteArray2
.
getBytes
()[
2
]);
ASSERT_EQ
((
uint8_t
)
40
,
byteArray2
.
getBytes
()[
3
]);
ASSERT_EQ
(
byteArray1
,
byteArray2
);
}
TEST_F
(
cta_ByteArrayTest
,
equality_operator_ne
)
{
using
namespace
cta
;
const
uint32_t
arraySize1
=
4
;
const
uint8_t
bytes1
[
4
]
=
{
10
,
20
,
30
,
40
};
const
ByteArray
byteArray1
(
arraySize1
,
bytes1
);
ASSERT_EQ
(
arraySize1
,
byteArray1
.
getSize
());
ASSERT_EQ
((
uint8_t
)
10
,
byteArray1
.
getBytes
()[
0
]);
ASSERT_EQ
((
uint8_t
)
20
,
byteArray1
.
getBytes
()[
1
]);
ASSERT_EQ
((
uint8_t
)
30
,
byteArray1
.
getBytes
()[
2
]);
ASSERT_EQ
((
uint8_t
)
40
,
byteArray1
.
getBytes
()[
3
]);
const
uint32_t
arraySize2
=
10
;
const
uint8_t
bytes2
[
10
]
=
{
10
,
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
};
ByteArray
byteArray2
(
arraySize2
,
bytes2
);
ASSERT_EQ
(
arraySize2
,
byteArray2
.
getSize
());
ASSERT_EQ
((
uint8_t
)
10
,
byteArray2
.
getBytes
()[
0
]);
ASSERT_EQ
(
(
uint8_t
)
9
,
byteArray2
.
getBytes
()[
1
]);
ASSERT_EQ
(
(
uint8_t
)
8
,
byteArray2
.
getBytes
()[
2
]);
ASSERT_EQ
(
(
uint8_t
)
7
,
byteArray2
.
getBytes
()[
3
]);
ASSERT_EQ
(
(
uint8_t
)
6
,
byteArray2
.
getBytes
()[
4
]);
ASSERT_EQ
(
(
uint8_t
)
5
,
byteArray2
.
getBytes
()[
5
]);
ASSERT_EQ
(
(
uint8_t
)
4
,
byteArray2
.
getBytes
()[
6
]);
ASSERT_EQ
(
(
uint8_t
)
3
,
byteArray2
.
getBytes
()[
7
]);
ASSERT_EQ
(
(
uint8_t
)
2
,
byteArray2
.
getBytes
()[
8
]);
ASSERT_EQ
(
(
uint8_t
)
1
,
byteArray2
.
getBytes
()[
9
]);
ASSERT_NE
(
byteArray1
,
byteArray2
);
}
}
// namespace unitTests
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment