config/{Block,Data,Param}: add concept checks to With()
This commit is contained in:
parent
a196d1ddf2
commit
3733bc57b7
|
@ -1,9 +1,9 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_CONFIG_BLOCK_HXX
|
||||
#define MPD_CONFIG_BLOCK_HXX
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
@ -45,7 +45,7 @@ struct BlockParam {
|
|||
* Invoke a function with the configured value; if the
|
||||
* function throws, call ThrowWithNested().
|
||||
*/
|
||||
template<typename F>
|
||||
template<std::regular_invocable<const char *> F>
|
||||
auto With(F &&f) const {
|
||||
try {
|
||||
return f(value.c_str());
|
||||
|
@ -130,5 +130,3 @@ struct ConfigBlock {
|
|||
[[noreturn]]
|
||||
void ThrowWithNested() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_CONFIG_DATA_HXX
|
||||
#define MPD_CONFIG_DATA_HXX
|
||||
#pragma once
|
||||
|
||||
#include "Option.hxx"
|
||||
#include "Param.hxx"
|
||||
|
@ -10,6 +9,7 @@
|
|||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <concepts>
|
||||
#include <forward_list>
|
||||
|
||||
class AllocatedPath;
|
||||
|
@ -36,7 +36,7 @@ struct ConfigData {
|
|||
return list.empty() ? nullptr : &list.front();
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
template<std::regular_invocable<const char *> F>
|
||||
auto With(ConfigOption option, F &&f) const {
|
||||
const auto *param = GetParam(option);
|
||||
return param != nullptr
|
||||
|
@ -113,7 +113,7 @@ struct ConfigData {
|
|||
* Exceptions thrown by the function will be nested in one
|
||||
* that specifies the location of the block.
|
||||
*/
|
||||
template<typename F>
|
||||
template<std::regular_invocable<const ConfigBlock &> F>
|
||||
void WithEach(ConfigBlockOption option, F &&f) const {
|
||||
for (const auto &block : GetBlockList(option)) {
|
||||
block.SetUsed();
|
||||
|
@ -126,5 +126,3 @@ struct ConfigData {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_CONFIG_PARAM_HXX
|
||||
#define MPD_CONFIG_PARAM_HXX
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include <string>
|
||||
|
||||
class AllocatedPath;
|
||||
|
@ -53,7 +53,7 @@ struct ConfigParam {
|
|||
* Invoke a function with the configured value; if the
|
||||
* function throws, call ThrowWithNested().
|
||||
*/
|
||||
template<typename F>
|
||||
template<std::regular_invocable<const char *> F>
|
||||
auto With(F &&f) const {
|
||||
try {
|
||||
return f(value.c_str());
|
||||
|
@ -62,5 +62,3 @@ struct ConfigParam {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue