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