From 8e6d4ee5b8e5fb2a2bbf80c86a7aac6286333667 Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 3 Dec 2024 16:19:32 +0000 Subject: [PATCH] Lint Signed-off-by: Michael Carroll Signed-off-by: William Woodall --- .../resource_retriever/memory_resource.hpp | 7 ++++-- .../plugins/curl_retriever.hpp | 4 +++- .../plugins/filesystem_retriever.hpp | 4 +++- .../plugins/retriever_plugin.hpp | 2 +- .../src/plugins/curl_retriever.cpp | 22 ++++++++++--------- .../src/plugins/filesystem_retriever.cpp | 10 ++++----- .../src/plugins/retriever_plugin.cpp | 2 +- resource_retriever/src/retriever.cpp | 13 +++++------ resource_retriever/test/test.cpp | 22 +++++++++++-------- 9 files changed, 49 insertions(+), 37 deletions(-) diff --git a/resource_retriever/include/resource_retriever/memory_resource.hpp b/resource_retriever/include/resource_retriever/memory_resource.hpp index 4aa271e..f02a2e3 100644 --- a/resource_retriever/include/resource_retriever/memory_resource.hpp +++ b/resource_retriever/include/resource_retriever/memory_resource.hpp @@ -43,8 +43,11 @@ namespace resource_retriever */ struct RESOURCE_RETRIEVER_PUBLIC MemoryResource { - explicit MemoryResource(std::string url_in, std::string expanded_url_in, std::vector data_in): - url(std::move(url_in)), + explicit MemoryResource( + std::string url_in, + std::string expanded_url_in, + std::vector data_in) + :url(std::move(url_in)), expanded_url(std::move(expanded_url_in)), data(std::move(data_in)) { diff --git a/resource_retriever/include/resource_retriever/plugins/curl_retriever.hpp b/resource_retriever/include/resource_retriever/plugins/curl_retriever.hpp index 5da7b23..9be1a79 100644 --- a/resource_retriever/include/resource_retriever/plugins/curl_retriever.hpp +++ b/resource_retriever/include/resource_retriever/plugins/curl_retriever.hpp @@ -29,6 +29,8 @@ #ifndef RESOURCE_RETRIEVER__PLUGINS__CURL_RETRIEVER_HPP_ #define RESOURCE_RETRIEVER__PLUGINS__CURL_RETRIEVER_HPP_ +#include + #include "resource_retriever/plugins/retriever_plugin.hpp" #include "resource_retriever/visibility_control.hpp" @@ -37,7 +39,7 @@ using CURL = void; namespace resource_retriever::plugins { -class RESOURCE_RETRIEVER_PUBLIC CurlRetriever: public RetrieverPlugin +class RESOURCE_RETRIEVER_PUBLIC CurlRetriever : public RetrieverPlugin { public: CurlRetriever(); diff --git a/resource_retriever/include/resource_retriever/plugins/filesystem_retriever.hpp b/resource_retriever/include/resource_retriever/plugins/filesystem_retriever.hpp index d1248d5..ec424f9 100644 --- a/resource_retriever/include/resource_retriever/plugins/filesystem_retriever.hpp +++ b/resource_retriever/include/resource_retriever/plugins/filesystem_retriever.hpp @@ -29,13 +29,15 @@ #ifndef RESOURCE_RETRIEVER__PLUGINS__FILESYSTEM_RETRIEVER_HPP_ #define RESOURCE_RETRIEVER__PLUGINS__FILESYSTEM_RETRIEVER_HPP_ +#include + #include "resource_retriever/plugins/retriever_plugin.hpp" #include "resource_retriever/visibility_control.hpp" namespace resource_retriever::plugins { -class RESOURCE_RETRIEVER_PUBLIC FilesystemRetriever: public RetrieverPlugin +class RESOURCE_RETRIEVER_PUBLIC FilesystemRetriever : public RetrieverPlugin { public: FilesystemRetriever(); diff --git a/resource_retriever/include/resource_retriever/plugins/retriever_plugin.hpp b/resource_retriever/include/resource_retriever/plugins/retriever_plugin.hpp index 91f1d54..e2b6967 100644 --- a/resource_retriever/include/resource_retriever/plugins/retriever_plugin.hpp +++ b/resource_retriever/include/resource_retriever/plugins/retriever_plugin.hpp @@ -36,7 +36,7 @@ namespace resource_retriever::plugins { -std::string expand_package_url(const std::string & url); +std::string expand_package_url(const std::string & url); std::string escape_spaces(const std::string & url); class RESOURCE_RETRIEVER_PUBLIC RetrieverPlugin diff --git a/resource_retriever/src/plugins/curl_retriever.cpp b/resource_retriever/src/plugins/curl_retriever.cpp index 431651f..47a6cc0 100644 --- a/resource_retriever/src/plugins/curl_retriever.cpp +++ b/resource_retriever/src/plugins/curl_retriever.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -49,7 +50,7 @@ class CURLStaticInit { CURLcode ret = curl_global_init(CURL_GLOBAL_ALL); if (ret != 0) { - fprintf(stderr, "Error initializing libcurl! retcode = %d", ret); + std::cerr << "Error initializing libcurl! retcode = " << ret; } else { initialized_ = true; } @@ -85,11 +86,11 @@ size_t curlWriteFunc(void * buffer, size_t size, size_t nmemb, void * userp) return size * nmemb; } -CurlRetriever::CurlRetriever(): - curl_handle_(curl_easy_init()) +CurlRetriever::CurlRetriever() +:curl_handle_(curl_easy_init()) { - } + CurlRetriever::~CurlRetriever() { if (curl_handle_ != nullptr) { @@ -108,16 +109,17 @@ CurlRetriever & CurlRetriever::operator=(CurlRetriever && other) noexcept return *this; } -std::string CurlRetriever::name() { +std::string CurlRetriever::name() +{ return "resource_retriever::plugins::CurlRetriever"; } bool CurlRetriever::can_handle(const std::string & url) { - return (url.find("package://") == 0 || - url.find("file://") == 0 || - url.find("http://") == 0 || - url.find("https://") == 0); + return url.find("package://") == 0 || + url.find("file://") == 0 || + url.find("http://") == 0 || + url.find("https://") == 0; } MemoryResourcePtr CurlRetriever::get(const std::string & url) @@ -126,7 +128,7 @@ MemoryResourcePtr CurlRetriever::get(const std::string & url) auto mod_url = url; try { mod_url = expand_package_url(mod_url); - } catch (const resource_retriever::Exception &e) { + } catch (const resource_retriever::Exception & e) { return nullptr; } diff --git a/resource_retriever/src/plugins/filesystem_retriever.cpp b/resource_retriever/src/plugins/filesystem_retriever.cpp index 98349ac..5d90d9e 100644 --- a/resource_retriever/src/plugins/filesystem_retriever.cpp +++ b/resource_retriever/src/plugins/filesystem_retriever.cpp @@ -45,7 +45,8 @@ FilesystemRetriever::FilesystemRetriever() = default; FilesystemRetriever::~FilesystemRetriever() = default; -std::string FilesystemRetriever::name() { +std::string FilesystemRetriever::name() +{ return "resource_retriever::plugins::FilesystemRetriever"; } @@ -60,12 +61,11 @@ MemoryResourcePtr FilesystemRetriever::get(const std::string & url) auto mod_url = url; try { mod_url = expand_package_url(mod_url); - } catch (const resource_retriever::Exception &e) { + } catch (const resource_retriever::Exception & e) { return nullptr; } - if (mod_url.find("file://") == 0) - { + if (mod_url.find("file://") == 0) { mod_url = mod_url.substr(7); } @@ -80,7 +80,7 @@ MemoryResourcePtr FilesystemRetriever::get(const std::string & url) // Create the vector and read the file std::vector data(fileSize); - file.read(reinterpret_cast(data.data()), fileSize); + file.read(reinterpret_cast(data.data()), fileSize); file.close(); res = std::make_shared(url, mod_url, data); } diff --git a/resource_retriever/src/plugins/retriever_plugin.cpp b/resource_retriever/src/plugins/retriever_plugin.cpp index 908704c..d4260ad 100644 --- a/resource_retriever/src/plugins/retriever_plugin.cpp +++ b/resource_retriever/src/plugins/retriever_plugin.cpp @@ -82,7 +82,7 @@ std::string expand_package_url(const std::string & url) mod_url = "file://" + package_path + mod_url; } return mod_url; -}; +} RetrieverPlugin::RetrieverPlugin() = default; diff --git a/resource_retriever/src/retriever.cpp b/resource_retriever/src/retriever.cpp index aae79bd..f521d6a 100644 --- a/resource_retriever/src/retriever.cpp +++ b/resource_retriever/src/retriever.cpp @@ -50,8 +50,8 @@ RetrieverVec default_plugins() }; } -Retriever::Retriever(RetrieverVec plugins): - plugins(std::move(plugins)) +Retriever::Retriever(RetrieverVec plugins) +:plugins(std::move(plugins)) { } @@ -59,14 +59,13 @@ Retriever::~Retriever() = default; MemoryResourcePtr Retriever::get(const std::string & url) { - for (auto & plugin : plugins) - { - if (plugin->can_handle(url)) - { + for (auto & plugin : plugins) { + if (plugin->can_handle(url)) { auto res = plugin->get(url); - if (res != nullptr) + if (res != nullptr) { return res; + } } } return nullptr; diff --git a/resource_retriever/test/test.cpp b/resource_retriever/test/test.cpp index b4b6233..4593b95 100644 --- a/resource_retriever/test/test.cpp +++ b/resource_retriever/test/test.cpp @@ -79,22 +79,26 @@ TEST(Retriever, invalidFiles) EXPECT_EQ(nullptr, r.get("package:///test.xml")); } -class TestRetrieverPlugin: public resource_retriever::plugins::RetrieverPlugin +class TestRetrieverPlugin : public resource_retriever::plugins::RetrieverPlugin { public: - TestRetrieverPlugin() = default; - ~TestRetrieverPlugin() override = default; + TestRetrieverPlugin() = default; + ~TestRetrieverPlugin() override = default; - std::string name() override { - return "TestRetrieverPlugin"; - } + std::string name() override + { + return "TestRetrieverPlugin"; + } - bool can_handle(const std::string & url) override { + bool can_handle(const std::string & url) override + { return url.find("test://") == 0; } - resource_retriever::MemoryResourcePtr get(const std::string & url) override { - return std::make_shared(url, url, std::vector{0, 1, 2, 3, 4, 5}); + resource_retriever::MemoryResourcePtr get(const std::string & url) override + { + return std::make_shared( + url, url, std::vector{0, 1, 2, 3, 4, 5}); } };