From c59303b5456edacb413aa884a1efdf992b717ed7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 13 Mar 2022 18:32:17 +0000 Subject: Don't take string_view by reference --- libadhocutil/ctf-impl/printf-compat.h | 4 ++-- libadhocutil/factory.h | 4 ++-- libadhocutil/factory.impl.h | 4 ++-- libadhocutil/nagios.cpp | 7 +++---- libadhocutil/nagios.h | 5 ++--- libadhocutil/plugins.cpp | 10 +++++----- libadhocutil/plugins.h | 24 ++++++++++++------------ libadhocutil/plugins.impl.h | 18 +++++++++--------- libadhocutil/unittests/testCurl.cpp | 2 +- libadhocutil/unittests/testPluginsRuntime.cpp | 12 ++++++------ 10 files changed, 44 insertions(+), 46 deletions(-) diff --git a/libadhocutil/ctf-impl/printf-compat.h b/libadhocutil/ctf-impl/printf-compat.h index b2004fb..a24c620 100644 --- a/libadhocutil/ctf-impl/printf-compat.h +++ b/libadhocutil/ctf-impl/printf-compat.h @@ -178,13 +178,13 @@ namespace AdHoc { StreamWriterT('.', '*', 's') { template static inline void - write(stream & s, int l, const std::string_view & p, const Pn &... pn) + write(stream & s, int l, const std::string_view p, const Pn &... pn) { return write(s, static_cast(l), p, pn...); } template static inline void - write(stream & s, size_t l, const std::string_view & p, const Pn &... pn) + write(stream & s, size_t l, const std::string_view p, const Pn &... pn) { s << p.substr(0, l); s.copyfmt(std::ios(nullptr)); diff --git a/libadhocutil/factory.h b/libadhocutil/factory.h index 748fc4a..806e02d 100644 --- a/libadhocutil/factory.h +++ b/libadhocutil/factory.h @@ -37,13 +37,13 @@ namespace AdHoc { * Helper to get the factory for a specific implementation. * @param name The name of the implementation. */ - [[nodiscard]] static std::shared_ptr get(const std::string_view & name); + [[nodiscard]] static std::shared_ptr get(const std::string_view name); /** * Helper to create a new instance from a specific factory. * @param name The name of the implementation. * @param p The parameters to pass to the constructor. */ - [[nodiscard]] static std::shared_ptr createNew(const std::string_view & name, const Params &... p); + [[nodiscard]] static std::shared_ptr createNew(const std::string_view name, const Params &... p); }; } diff --git a/libadhocutil/factory.impl.h b/libadhocutil/factory.impl.h index 074deea..38b0aab 100644 --- a/libadhocutil/factory.impl.h +++ b/libadhocutil/factory.impl.h @@ -8,14 +8,14 @@ namespace AdHoc { template std::shared_ptr> - Factory::get(const std::string_view & name) + Factory::get(const std::string_view name) { return PluginManager::getDefault()->get(name)->implementation(); } template std::shared_ptr - Factory::createNew(const std::string_view & name, const Params &... p) + Factory::createNew(const std::string_view name, const Params &... p) { return get(name)->create(p...); } diff --git a/libadhocutil/nagios.cpp b/libadhocutil/nagios.cpp index 4350c35..a995a13 100644 --- a/libadhocutil/nagios.cpp +++ b/libadhocutil/nagios.cpp @@ -11,8 +11,7 @@ namespace AdHoc { /// LCOV_EXCL_START (calls real Nagios) bool - submitNagiosPassiveServiceCheck( - const std::string_view & svc, NagiosStatusCode code, const std::string_view & output) + submitNagiosPassiveServiceCheck(const std::string_view svc, NagiosStatusCode code, const std::string_view output) { std::ofstream command_file("/var/nagios/rw/nagios.cmd"); return submitNagiosPassiveServiceCheck(command_file, svc, code, output); @@ -20,8 +19,8 @@ namespace AdHoc { /// LCOV_EXCL_STOP bool - submitNagiosPassiveServiceCheck(std::ostream & command_file, const std::string_view & svc, NagiosStatusCode code, - const std::string_view & output) + submitNagiosPassiveServiceCheck(std::ostream & command_file, const std::string_view svc, NagiosStatusCode code, + const std::string_view output) { if (command_file.good()) { struct utsname buf { diff --git a/libadhocutil/nagios.h b/libadhocutil/nagios.h index cbe02d9..2518e89 100644 --- a/libadhocutil/nagios.h +++ b/libadhocutil/nagios.h @@ -13,8 +13,7 @@ namespace AdHoc { Unknown = 3, }; + DLL_PUBLIC bool submitNagiosPassiveServiceCheck(const std::string_view, NagiosStatusCode, const std::string_view); DLL_PUBLIC bool submitNagiosPassiveServiceCheck( - const std::string_view &, NagiosStatusCode, const std::string_view &); - DLL_PUBLIC bool submitNagiosPassiveServiceCheck( - std::ostream &, const std::string_view &, NagiosStatusCode, const std::string_view &); + std::ostream &, const std::string_view, NagiosStatusCode, const std::string_view); } diff --git a/libadhocutil/plugins.cpp b/libadhocutil/plugins.cpp index 000e86d..aeef27e 100644 --- a/libadhocutil/plugins.cpp +++ b/libadhocutil/plugins.cpp @@ -38,10 +38,10 @@ namespace AdHoc { AbstractPluginImplementation::~AbstractPluginImplementation() = default; - Plugin::Plugin(const std::string_view & n, const std::string_view & f, int l) : name(n), filename(f), lineno(l) { } + Plugin::Plugin(const std::string_view n, const std::string_view f, int l) : name(n), filename(f), lineno(l) { } AdHocFormatter(NoSuchPluginExceptionMsg, "No such plugin: %? of type %?"); - NoSuchPluginException::NoSuchPluginException(const std::string_view & n, const std::type_info & t) : + NoSuchPluginException::NoSuchPluginException(const std::string_view n, const std::type_info & t) : std::runtime_error(NoSuchPluginExceptionMsg::get(n, t)) { } @@ -60,7 +60,7 @@ namespace AdHoc { } AdHocFormatter(LoadLibraryExceptionMsg, "Failed to load library [%?]; %?"); - LoadLibraryException::LoadLibraryException(const std::string_view & f, const std::string_view & msg) : + LoadLibraryException::LoadLibraryException(const std::string_view f, const std::string_view msg) : std::runtime_error(LoadLibraryExceptionMsg::get(f, msg)) { } @@ -106,14 +106,14 @@ namespace AdHoc { } void - PluginManager::remove(const std::string_view & n, const std::type_info & t) + PluginManager::remove(const std::string_view n, const std::type_info & t) { auto r = plugins->get<2>().equal_range(std::make_tuple(n, std::cref(t))); plugins->get<2>().erase(r.first, r.second); } PluginPtr - PluginManager::get(const std::string_view & n, const std::type_info & t) const + PluginManager::get(const std::string_view n, const std::type_info & t) const { auto r = plugins->get<2>().equal_range(std::make_tuple(n, std::cref(t))); if (r.first == r.second) { diff --git a/libadhocutil/plugins.h b/libadhocutil/plugins.h index 4f2ff84..7ae5bba 100644 --- a/libadhocutil/plugins.h +++ b/libadhocutil/plugins.h @@ -24,7 +24,7 @@ namespace AdHoc { class NoSuchPluginException : public std::runtime_error { public: /// Constructor taking name and type of plugin requested. - NoSuchPluginException(const std::string_view &, const std::type_info &); + NoSuchPluginException(const std::string_view, const std::type_info &); }; /// Base class for all plugin implementations. @@ -40,7 +40,7 @@ namespace AdHoc { class DLL_PUBLIC Plugin { public: /// Constructor taking name, filename and line of install. - Plugin(const std::string_view &, const std::string_view &, int); + Plugin(const std::string_view, const std::string_view, int); /// Standard move/copy support SPECIAL_MEMBERS_DELETE(Plugin); virtual ~Plugin() = default; @@ -78,7 +78,7 @@ namespace AdHoc { class LoadLibraryException : public std::runtime_error { public: /// Constuctor taking syscall error details. - LoadLibraryException(const std::string_view & f, const std::string_view & msg); + LoadLibraryException(const std::string_view f, const std::string_view msg); }; template @@ -86,7 +86,7 @@ namespace AdHoc { class DLL_PUBLIC PluginOf : public Plugin { public: /// Constructor taking an instance and name, filename and line of install for Plugin. - PluginOf(std::shared_ptr t, const std::string_view & n, const std::string_view & f, int l); + PluginOf(std::shared_ptr t, const std::string_view n, const std::string_view f, int l); /// Get the type of this plugin. [[nodiscard]] const std::type_info & type() const override; @@ -105,7 +105,7 @@ namespace AdHoc { /// Callback definition to resolve a plugin type and name to a potential library /// containing an implementation. using PluginResolver - = std::function(const std::type_info &, const std::string_view &)>; + = std::function(const std::type_info &, const std::string_view)>; PluginManager(); virtual ~PluginManager(); @@ -116,9 +116,9 @@ namespace AdHoc { /// Install a plugin. void add(const PluginPtr &); /// Uninstall a plugin. - void remove(const std::string_view &, const std::type_info &); + void remove(const std::string_view, const std::type_info &); /// Get a specific plugin. - [[nodiscard]] PluginPtr get(const std::string_view &, const std::type_info &) const; + [[nodiscard]] PluginPtr get(const std::string_view, const std::type_info &) const; /// Get all plugins. [[nodiscard]] std::set getAll() const; /// Get all plugins of a specific type. @@ -132,7 +132,7 @@ namespace AdHoc { * @param l Line number. */ template - void add(const std::shared_ptr & i, const std::string_view & n, const std::string_view & f, int l); + void add(const std::shared_ptr & i, const std::string_view n, const std::string_view f, int l); /** * Create and install a plugin @@ -146,7 +146,7 @@ namespace AdHoc { */ template void - create(const std::string_view & n, const std::string_view & f, int l, const Args &... args) + create(const std::string_view n, const std::string_view f, int l, const Args &... args) { add(std::make_shared(args...), n, f, l); } @@ -155,19 +155,19 @@ namespace AdHoc { * Uninstall a plugin. * @param n Name of plugin. */ - template void remove(const std::string_view & n); + template void remove(const std::string_view n); /** * Get a specific plugin. * @param n Name of plugin. */ - template [[nodiscard]] std::shared_ptr> get(const std::string_view & n) const; + template [[nodiscard]] std::shared_ptr> get(const std::string_view n) const; /** * Get the implementation from specific plugin. * @param n Name of plugin. */ - template [[nodiscard]] std::shared_ptr getImplementation(const std::string_view & n) const; + template [[nodiscard]] std::shared_ptr getImplementation(const std::string_view n) const; /** * Get all plugins of a given time. diff --git a/libadhocutil/plugins.impl.h b/libadhocutil/plugins.impl.h index becd149..772d37a 100644 --- a/libadhocutil/plugins.impl.h +++ b/libadhocutil/plugins.impl.h @@ -10,7 +10,7 @@ namespace AdHoc { template - PluginOf::PluginOf(std::shared_ptr t, const std::string_view & n, const std::string_view & f, int l) : + PluginOf::PluginOf(std::shared_ptr t, const std::string_view n, const std::string_view f, int l) : Plugin(n, f, l), impl(std::move(t)) { } @@ -40,28 +40,28 @@ namespace AdHoc { template void - PluginManager::add(const std::shared_ptr & i, const std::string_view & n, const std::string_view & f, int l) + PluginManager::add(const std::shared_ptr & i, const std::string_view n, const std::string_view f, int l) { add(std::make_shared>(i, n, f, l)); } template void - PluginManager::remove(const std::string_view & n) + PluginManager::remove(const std::string_view n) { remove(n, typeid(T)); } template std::shared_ptr> - PluginManager::get(const std::string_view & n) const + PluginManager::get(const std::string_view n) const { return std::dynamic_pointer_cast>(get(n, typeid(T))); } template std::shared_ptr - PluginManager::getImplementation(const std::string_view & n) const + PluginManager::getImplementation(const std::string_view n) const { return std::static_pointer_cast(get(n)->implementation()); } @@ -97,12 +97,12 @@ namespace AdHoc { #define INSTANTIATEPLUGINOF(...) \ template class AdHoc::PluginOf<__VA_ARGS__>; \ template DLL_PUBLIC void AdHoc::PluginManager::add<__VA_ARGS__>( \ - const std::shared_ptr<__VA_ARGS__> &, const std::string_view &, const std::string_view &, int); \ - template DLL_PUBLIC void AdHoc::PluginManager::remove<__VA_ARGS__>(const std::string_view &); \ + const std::shared_ptr<__VA_ARGS__> &, const std::string_view, const std::string_view, int); \ + template DLL_PUBLIC void AdHoc::PluginManager::remove<__VA_ARGS__>(const std::string_view); \ template DLL_PUBLIC std::shared_ptr> AdHoc::PluginManager::get<__VA_ARGS__>( \ - const std::string_view &) const; \ + const std::string_view) const; \ template DLL_PUBLIC std::shared_ptr<__VA_ARGS__> AdHoc::PluginManager::getImplementation<__VA_ARGS__>( \ - const std::string_view &) const; \ + const std::string_view) const; \ template DLL_PUBLIC std::set>> \ AdHoc::PluginManager::getAll<__VA_ARGS__>() const; \ template DLL_PUBLIC void AdHoc::PluginManager::addResolver<__VA_ARGS__>( \ diff --git a/libadhocutil/unittests/testCurl.cpp b/libadhocutil/unittests/testCurl.cpp index c60c242..b07c774 100644 --- a/libadhocutil/unittests/testCurl.cpp +++ b/libadhocutil/unittests/testCurl.cpp @@ -26,7 +26,7 @@ discard(void *, size_t sz, size_t nm, void *) } AdHocFormatter(FileUrl, "file://%?/%?"); -const auto urlGen = [](const std::string_view & url) { +const auto urlGen = [](const std::string_view url) { return FileUrl::get(rootDir.string(), url); }; diff --git a/libadhocutil/unittests/testPluginsRuntime.cpp b/libadhocutil/unittests/testPluginsRuntime.cpp index 9b3279d..9730c5b 100644 --- a/libadhocutil/unittests/testPluginsRuntime.cpp +++ b/libadhocutil/unittests/testPluginsRuntime.cpp @@ -23,9 +23,9 @@ struct GetLibPath { }; BOOST_TEST_GLOBAL_FIXTURE(GetLibPath); -static std::optional nullResolver(const std::type_info &, const std::string_view &); -static std::optional badResolver(const std::type_info &, const std::string_view &); -static std::optional goodResolver(const std::type_info &, const std::string_view &); +static std::optional nullResolver(const std::type_info &, const std::string_view); +static std::optional badResolver(const std::type_info &, const std::string_view); +static std::optional goodResolver(const std::type_info &, const std::string_view); BOOST_AUTO_TEST_CASE(ready) { @@ -48,19 +48,19 @@ BOOST_AUTO_TEST_CASE(loadAndUnloadlib) } std::optional -nullResolver(const std::type_info &, const std::string_view &) +nullResolver(const std::type_info &, const std::string_view) { return {}; } std::optional -badResolver(const std::type_info &, const std::string_view &) +badResolver(const std::type_info &, const std::string_view) { return std::string("dontexist"); } std::optional -goodResolver(const std::type_info & t, const std::string_view & n) +goodResolver(const std::type_info & t, const std::string_view n) { BOOST_REQUIRE_EQUAL(typeid(BaseThing), t); BOOST_REQUIRE_EQUAL("ImplOfThing", n); -- cgit v1.2.3