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
7fb9bebd
Commit
7fb9bebd
authored
Apr 24, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/{Const,Writable}Buffer: add front(), back(), pop_{front,back}(), shift()
parent
3b8a9dd6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
0 deletions
+118
-0
ConstBuffer.hxx
src/util/ConstBuffer.hxx
+59
-0
WritableBuffer.hxx
src/util/WritableBuffer.hxx
+59
-0
No files found.
src/util/ConstBuffer.hxx
View file @
7fb9bebd
...
...
@@ -164,6 +164,65 @@ struct ConstBuffer {
return
data
[
i
];
}
/**
* Returns a reference to the first element. Buffer must not
* be empty.
*/
#ifdef NDEBUG
constexpr
#endif
reference_type
front
()
const
{
#ifndef NDEBUG
assert
(
!
IsEmpty
());
#endif
return
data
[
0
];
}
/**
* Returns a reference to the last element. Buffer must not
* be empty.
*/
#ifdef NDEBUG
constexpr
#endif
reference_type
back
()
const
{
#ifndef NDEBUG
assert
(
!
IsEmpty
());
#endif
return
data
[
size
-
1
];
}
/**
* Remove the first element (by moving the head pointer, does
* not actually modify the buffer). Buffer must not be empty.
*/
void
pop_front
()
{
assert
(
!
IsEmpty
());
++
data
;
--
size
;
}
/**
* Remove the last element (by moving the tail pointer, does
* not actually modify the buffer). Buffer must not be empty.
*/
void
pop_back
()
{
assert
(
!
IsEmpty
());
--
size
;
}
/**
* Remove the first element and return a reference to it.
* Buffer must not be empty.
*/
reference_type
shift
()
{
reference_type
result
=
front
();
pop_front
();
return
result
;
}
};
#endif
src/util/WritableBuffer.hxx
View file @
7fb9bebd
...
...
@@ -158,6 +158,65 @@ struct WritableBuffer {
return
data
[
i
];
}
/**
* Returns a reference to the first element. Buffer must not
* be empty.
*/
#ifdef NDEBUG
constexpr
#endif
reference_type
front
()
const
{
#ifndef NDEBUG
assert
(
!
IsEmpty
());
#endif
return
data
[
0
];
}
/**
* Returns a reference to the last element. Buffer must not
* be empty.
*/
#ifdef NDEBUG
constexpr
#endif
reference_type
back
()
const
{
#ifndef NDEBUG
assert
(
!
IsEmpty
());
#endif
return
data
[
size
-
1
];
}
/**
* Remove the first element (by moving the head pointer, does
* not actually modify the buffer). Buffer must not be empty.
*/
void
pop_front
()
{
assert
(
!
IsEmpty
());
++
data
;
--
size
;
}
/**
* Remove the last element (by moving the tail pointer, does
* not actually modify the buffer). Buffer must not be empty.
*/
void
pop_back
()
{
assert
(
!
IsEmpty
());
--
size
;
}
/**
* Remove the first element and return a reference to it.
* Buffer must not be empty.
*/
reference_type
shift
()
{
reference_type
result
=
front
();
pop_front
();
return
result
;
}
};
#endif
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