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
7a1f3177
Commit
7a1f3177
authored
Jul 14, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util/Cast: reimplement as template without macro
parent
f8da8b02
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
16 deletions
+33
-16
HttpdInternal.hxx
src/output/plugins/httpd/HttpdInternal.hxx
+4
-10
TagPool.cxx
src/tag/TagPool.cxx
+5
-2
Cast.hxx
src/util/Cast.hxx
+24
-4
No files found.
src/output/plugins/httpd/HttpdInternal.hxx
View file @
7a1f3177
...
...
@@ -152,19 +152,13 @@ public:
HttpdOutput
(
EventLoop
&
_loop
);
~
HttpdOutput
();
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#if defined(__clang__) || GCC_CHECK_VERSION(4,7)
constexpr
#endif
static
constexpr
HttpdOutput
*
Cast
(
AudioOutput
*
ao
)
{
return
ContainerCast
(
ao
,
HttpdOutput
,
base
);
static
HttpdOutput
*
Cast
(
AudioOutput
*
ao
)
{
return
&
ContainerCast
(
*
ao
,
&
HttpdOutput
::
base
);
}
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
using
DeferredMonitor
::
GetEventLoop
;
bool
Init
(
const
config_param
&
param
,
Error
&
error
);
...
...
src/tag/TagPool.cxx
View file @
7a1f3177
...
...
@@ -87,10 +87,13 @@ calc_hash(TagType type, const char *p)
return
hash
^
type
;
}
static
inline
constexpr
TagPoolSlot
*
#if defined(__clang__) || GCC_CHECK_VERSION(4,7)
constexpr
#endif
static
inline
TagPoolSlot
*
tag_item_to_slot
(
TagItem
*
item
)
{
return
ContainerCast
(
item
,
TagPoolSlot
,
item
);
return
&
ContainerCast
(
*
item
,
&
TagPoolSlot
::
item
);
}
static
inline
TagPoolSlot
**
...
...
src/util/Cast.hxx
View file @
7a1f3177
/*
* Copyright (C) 2013 Max Kellermann <max@duempel.org>
* Copyright (C) 2013
-2014
Max Kellermann <max@duempel.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
...
...
@@ -64,11 +64,31 @@ OffsetCast(const U *p, ptrdiff_t offset)
return
reinterpret_cast
<
const
T
*>
(
OffsetPointer
(
p
,
offset
));
}
template
<
class
C
,
class
A
>
static
constexpr
inline
ptrdiff_t
ContainerAttributeOffset
(
const
C
*
null_c
,
const
A
C
::*
p
)
{
return
ptrdiff_t
((
const
char
*
)
null_c
-
(
const
char
*
)
&
(
null_c
->*
p
));
}
template
<
class
C
,
class
A
>
static
constexpr
inline
ptrdiff_t
ContainerAttributeOffset
(
const
A
C
::*
p
)
{
return
ContainerAttributeOffset
<
C
,
A
>
(
nullptr
,
p
);
}
/**
* Cast the given pointer to a struct member to its parent structure.
*/
#define ContainerCast(p, container, attribute) \
OffsetCast<container, decltype(((container*)nullptr)->attribute)> \
((p), -ptrdiff_t(offsetof(container, attribute)))
template
<
class
C
,
class
A
>
#if defined(__clang__) || GCC_CHECK_VERSION(4,7)
constexpr
#endif
static
inline
C
&
ContainerCast
(
A
&
a
,
A
C
::*
member
)
{
return
*
OffsetCast
<
C
,
A
>
(
&
a
,
ContainerAttributeOffset
<
C
,
A
>
(
member
));
}
#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