Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
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
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
328860c8
Commit
328860c8
authored
Mar 15, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/CircularBuffer: add method GetSpace()
parent
89ac1118
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
0 deletions
+22
-0
CircularBuffer.hxx
src/util/CircularBuffer.hxx
+12
-0
TestCircularBuffer.hxx
test/TestCircularBuffer.hxx
+10
-0
No files found.
src/util/CircularBuffer.hxx
View file @
328860c8
...
...
@@ -108,6 +108,18 @@ public:
}
/**
* Returns the number of elements that can be added to this
* buffer.
*/
constexpr
size_type
GetSpace
()
const
{
/* space = capacity - size - 1 */
return
(
head
<=
tail
?
capacity
-
tail
+
head
:
head
-
tail
)
-
1
;
}
/**
* Prepares writing. Returns a buffer range which may be written.
* When you are finished, call Append().
*/
...
...
test/TestCircularBuffer.hxx
View file @
328860c8
...
...
@@ -33,6 +33,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
0
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
7
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Write
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
&
data
[
0
],
buffer
.
Write
().
data
);
...
...
@@ -45,6 +46,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
1
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
6
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
1
),
buffer
.
Read
().
size
);
CPPUNIT_ASSERT_EQUAL
(
&
data
[
0
],
buffer
.
Read
().
data
);
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Write
().
IsEmpty
());
...
...
@@ -58,6 +60,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
7
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
0
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
7
),
buffer
.
Read
().
size
);
CPPUNIT_ASSERT_EQUAL
(
&
data
[
0
],
buffer
.
Read
().
data
);
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
Write
().
IsEmpty
());
...
...
@@ -69,6 +72,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
6
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
1
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
6
),
buffer
.
Read
().
size
);
CPPUNIT_ASSERT_EQUAL
(
&
data
[
1
],
buffer
.
Read
().
data
);
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Write
().
IsEmpty
());
...
...
@@ -83,6 +87,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
7
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
0
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
7
),
buffer
.
Read
().
size
);
CPPUNIT_ASSERT_EQUAL
(
&
data
[
1
],
buffer
.
Read
().
data
);
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
Write
().
IsEmpty
());
...
...
@@ -94,6 +99,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
4
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
3
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
4
),
buffer
.
Read
().
size
);
CPPUNIT_ASSERT_EQUAL
(
&
data
[
4
],
buffer
.
Read
().
data
);
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Write
().
IsEmpty
());
...
...
@@ -107,6 +113,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
6
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
1
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
4
),
buffer
.
Read
().
size
);
CPPUNIT_ASSERT_EQUAL
(
&
data
[
4
],
buffer
.
Read
().
data
);
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Write
().
IsEmpty
());
...
...
@@ -120,6 +127,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
7
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
0
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
4
),
buffer
.
Read
().
size
);
CPPUNIT_ASSERT_EQUAL
(
&
data
[
4
],
buffer
.
Read
().
data
);
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
Write
().
IsEmpty
());
...
...
@@ -131,6 +139,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
3
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
4
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
3
),
buffer
.
Read
().
size
);
CPPUNIT_ASSERT_EQUAL
(
&
data
[
0
],
buffer
.
Read
().
data
);
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Write
().
IsEmpty
());
...
...
@@ -145,6 +154,7 @@ public:
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
IsFull
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
0
),
buffer
.
GetSize
());
CPPUNIT_ASSERT_EQUAL
(
size_t
(
7
),
buffer
.
GetSpace
());
CPPUNIT_ASSERT_EQUAL
(
true
,
buffer
.
Read
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
false
,
buffer
.
Write
().
IsEmpty
());
CPPUNIT_ASSERT_EQUAL
(
&
data
[
3
],
buffer
.
Write
().
data
);
...
...
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