Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
0f85acf8
Commit
0f85acf8
authored
Dec 14, 2018
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move ScopedVector into namespace butil
parent
7318bee3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
14 deletions
+18
-14
scoped_vector.h
src/butil/memory/scoped_vector.h
+4
-0
scoped_vector_unittest.cc
test/scoped_vector_unittest.cc
+14
-14
No files found.
src/butil/memory/scoped_vector.h
View file @
0f85acf8
...
...
@@ -12,6 +12,8 @@
#include "butil/move.h"
#include "butil/stl_util.h"
namespace
butil
{
// ScopedVector wraps a vector deleting the elements from its
// destructor.
template
<
class
T
>
...
...
@@ -134,4 +136,6 @@ class ScopedVector {
std
::
vector
<
T
*>
v_
;
};
}
// namespace butil
#endif // BUTIL_MEMORY_SCOPED_VECTOR_H_
test/scoped_vector_unittest.cc
View file @
0f85acf8
...
...
@@ -113,7 +113,7 @@ TEST(ScopedVectorTest, LifeCycleWatcher) {
TEST
(
ScopedVectorTest
,
PopBack
)
{
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
push_back
(
watcher
.
NewLifeCycleObject
());
EXPECT_EQ
(
LC_CONSTRUCTED
,
watcher
.
life_cycle_state
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector
.
back
()));
...
...
@@ -125,7 +125,7 @@ TEST(ScopedVectorTest, PopBack) {
TEST
(
ScopedVectorTest
,
Clear
)
{
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
push_back
(
watcher
.
NewLifeCycleObject
());
EXPECT_EQ
(
LC_CONSTRUCTED
,
watcher
.
life_cycle_state
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector
.
back
()));
...
...
@@ -137,7 +137,7 @@ TEST(ScopedVectorTest, Clear) {
TEST
(
ScopedVectorTest
,
WeakClear
)
{
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
push_back
(
watcher
.
NewLifeCycleObject
());
EXPECT_EQ
(
LC_CONSTRUCTED
,
watcher
.
life_cycle_state
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector
.
back
()));
...
...
@@ -151,7 +151,7 @@ TEST(ScopedVectorTest, ResizeShrink) {
EXPECT_EQ
(
LC_INITIAL
,
first_watcher
.
life_cycle_state
());
LifeCycleWatcher
second_watcher
;
EXPECT_EQ
(
LC_INITIAL
,
second_watcher
.
life_cycle_state
());
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
push_back
(
first_watcher
.
NewLifeCycleObject
());
EXPECT_EQ
(
LC_CONSTRUCTED
,
first_watcher
.
life_cycle_state
());
...
...
@@ -176,7 +176,7 @@ TEST(ScopedVectorTest, ResizeShrink) {
TEST
(
ScopedVectorTest
,
ResizeGrow
)
{
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
push_back
(
watcher
.
NewLifeCycleObject
());
EXPECT_EQ
(
LC_CONSTRUCTED
,
watcher
.
life_cycle_state
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector
.
back
()));
...
...
@@ -195,7 +195,7 @@ TEST(ScopedVectorTest, Scope) {
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
{
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
push_back
(
watcher
.
NewLifeCycleObject
());
EXPECT_EQ
(
LC_CONSTRUCTED
,
watcher
.
life_cycle_state
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector
.
back
()));
...
...
@@ -207,12 +207,12 @@ TEST(ScopedVectorTest, MoveConstruct) {
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
{
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
push_back
(
watcher
.
NewLifeCycleObject
());
EXPECT_FALSE
(
scoped_vector
.
empty
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector
.
back
()));
ScopedVector
<
LifeCycleObject
>
scoped_vector_copy
(
scoped_vector
.
Pass
());
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector_copy
(
scoped_vector
.
Pass
());
EXPECT_TRUE
(
scoped_vector
.
empty
());
EXPECT_FALSE
(
scoped_vector_copy
.
empty
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector_copy
.
back
()));
...
...
@@ -226,9 +226,9 @@ TEST(ScopedVectorTest, MoveAssign) {
LifeCycleWatcher
watcher
;
EXPECT_EQ
(
LC_INITIAL
,
watcher
.
life_cycle_state
());
{
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
push_back
(
watcher
.
NewLifeCycleObject
());
ScopedVector
<
LifeCycleObject
>
scoped_vector_assign
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector_assign
;
EXPECT_FALSE
(
scoped_vector
.
empty
());
EXPECT_TRUE
(
watcher
.
IsWatching
(
scoped_vector
.
back
()));
...
...
@@ -261,18 +261,18 @@ class DeleteCounter {
};
template
<
typename
T
>
ScopedVector
<
T
>
PassThru
(
ScopedVector
<
T
>
scoper
)
{
butil
::
ScopedVector
<
T
>
PassThru
(
butil
::
ScopedVector
<
T
>
scoper
)
{
return
scoper
.
Pass
();
}
TEST
(
ScopedVectorTest
,
Passed
)
{
int
deletes
=
0
;
ScopedVector
<
DeleteCounter
>
deleter_vector
;
butil
::
ScopedVector
<
DeleteCounter
>
deleter_vector
;
deleter_vector
.
push_back
(
new
DeleteCounter
(
&
deletes
));
EXPECT_EQ
(
0
,
deletes
);
EXPECT_EQ
(
0
,
deletes
);
ScopedVector
<
DeleteCounter
>
result
=
deleter_vector
.
Pass
();
butil
::
ScopedVector
<
DeleteCounter
>
result
=
deleter_vector
.
Pass
();
EXPECT_EQ
(
0
,
deletes
);
result
.
clear
();
EXPECT_EQ
(
1
,
deletes
);
...
...
@@ -290,7 +290,7 @@ TEST(ScopedVectorTest, InsertRange) {
}
// Start scope for ScopedVector.
{
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
butil
::
ScopedVector
<
LifeCycleObject
>
scoped_vector
;
scoped_vector
.
insert
(
scoped_vector
.
end
(),
vec
.
begin
()
+
1
,
vec
.
begin
()
+
3
);
for
(
LifeCycleWatcher
*
it
=
watchers
;
it
!=
watchers
+
arraysize
(
watchers
);
++
it
)
...
...
Write
Preview
Markdown
is supported
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