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
3e5ce3c9
Commit
3e5ce3c9
authored
Sep 21, 2017
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/{Const,Writable}Buffer: add static method FromVoidFloor()
parent
e5c9b4cd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
ConstBuffer.hxx
src/util/ConstBuffer.hxx
+11
-3
WritableBuffer.hxx
src/util/WritableBuffer.hxx
+11
-3
No files found.
src/util/ConstBuffer.hxx
View file @
3e5ce3c9
...
...
@@ -125,6 +125,16 @@ struct ConstBuffer {
}
/**
* Cast a ConstBuffer<void> to a ConstBuffer<T>, rounding down
* to the next multiple of T's size.
*/
static
constexpr
ConstBuffer
<
T
>
FromVoidFloor
(
ConstBuffer
<
void
>
other
)
{
static_assert
(
sizeof
(
T
)
>
0
,
"Empty base type"
);
return
ConstBuffer
<
T
>
(
pointer_type
(
other
.
data
),
other
.
size
/
sizeof
(
T
));
}
/**
* Cast a ConstBuffer<void> to a ConstBuffer<T>. A "void"
* buffer records its size in bytes, and when casting to "T",
* the assertion below ensures that the size is a multiple of
...
...
@@ -134,12 +144,10 @@ struct ConstBuffer {
constexpr
#endif
static
ConstBuffer
<
T
>
FromVoid
(
ConstBuffer
<
void
>
other
)
{
static_assert
(
sizeof
(
T
)
>
0
,
"Empty base type"
);
#ifndef NDEBUG
assert
(
other
.
size
%
sizeof
(
T
)
==
0
);
#endif
return
ConstBuffer
<
T
>
(
pointer_type
(
other
.
data
),
other
.
size
/
sizeof
(
T
));
return
FromVoidFloor
(
other
);
}
constexpr
ConstBuffer
<
void
>
ToVoid
()
const
{
...
...
src/util/WritableBuffer.hxx
View file @
3e5ce3c9
...
...
@@ -119,6 +119,16 @@ struct WritableBuffer {
}
/**
* Cast a WritableBuffer<void> to a WritableBuffer<T>,
* rounding down to the next multiple of T's size.
*/
static
constexpr
WritableBuffer
<
T
>
FromVoidFloor
(
WritableBuffer
<
void
>
other
)
{
static_assert
(
sizeof
(
T
)
>
0
,
"Empty base type"
);
return
WritableBuffer
<
T
>
(
pointer_type
(
other
.
data
),
other
.
size
/
sizeof
(
T
));
}
/**
* Cast a WritableBuffer<void> to a WritableBuffer<T>. A "void"
* buffer records its size in bytes, and when casting to "T",
* the assertion below ensures that the size is a multiple of
...
...
@@ -128,12 +138,10 @@ struct WritableBuffer {
constexpr
#endif
static
WritableBuffer
<
T
>
FromVoid
(
WritableBuffer
<
void
>
other
)
{
static_assert
(
sizeof
(
T
)
>
0
,
"Empty base type"
);
#ifndef NDEBUG
assert
(
other
.
size
%
sizeof
(
T
)
==
0
);
#endif
return
WritableBuffer
<
T
>
(
pointer_type
(
other
.
data
),
other
.
size
/
sizeof
(
T
));
return
FromVoidFloor
(
other
);
}
constexpr
WritableBuffer
<
void
>
ToVoid
()
const
{
...
...
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