Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: William Woodall <[email protected]>
  • Loading branch information
mjcarroll authored and wjwwood committed Dec 17, 2024
1 parent ec62146 commit 8e6d4ee
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t> data_in):
url(std::move(url_in)),
explicit MemoryResource(
std::string url_in,
std::string expanded_url_in,
std::vector<uint8_t> data_in)
:url(std::move(url_in)),
expanded_url(std::move(expanded_url_in)),
data(std::move(data_in))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#ifndef RESOURCE_RETRIEVER__PLUGINS__CURL_RETRIEVER_HPP_
#define RESOURCE_RETRIEVER__PLUGINS__CURL_RETRIEVER_HPP_

#include <string>

#include "resource_retriever/plugins/retriever_plugin.hpp"
#include "resource_retriever/visibility_control.hpp"

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
#ifndef RESOURCE_RETRIEVER__PLUGINS__FILESYSTEM_RETRIEVER_HPP_
#define RESOURCE_RETRIEVER__PLUGINS__FILESYSTEM_RETRIEVER_HPP_

#include <string>

#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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 12 additions & 10 deletions resource_retriever/src/plugins/curl_retriever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include <array>
#include <cstring>
#include <iostream>
#include <memory>
#include <string>
#include <utility>
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down
10 changes: 5 additions & 5 deletions resource_retriever/src/plugins/filesystem_retriever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ FilesystemRetriever::FilesystemRetriever() = default;

FilesystemRetriever::~FilesystemRetriever() = default;

std::string FilesystemRetriever::name() {
std::string FilesystemRetriever::name()
{
return "resource_retriever::plugins::FilesystemRetriever";
}

Expand All @@ -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);
}

Expand All @@ -80,7 +80,7 @@ MemoryResourcePtr FilesystemRetriever::get(const std::string & url)

// Create the vector and read the file
std::vector<uint8_t> data(fileSize);
file.read(reinterpret_cast<char*>(data.data()), fileSize);
file.read(reinterpret_cast<char *>(data.data()), fileSize);
file.close();
res = std::make_shared<MemoryResource>(url, mod_url, data);
}
Expand Down
2 changes: 1 addition & 1 deletion resource_retriever/src/plugins/retriever_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 6 additions & 7 deletions resource_retriever/src/retriever.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,22 @@ RetrieverVec default_plugins()
};
}

Retriever::Retriever(RetrieverVec plugins):
plugins(std::move(plugins))
Retriever::Retriever(RetrieverVec plugins)
:plugins(std::move(plugins))
{
}

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;
Expand Down
22 changes: 13 additions & 9 deletions resource_retriever/test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<resource_retriever::MemoryResource>(url, url, std::vector<uint8_t>{0, 1, 2, 3, 4, 5});
resource_retriever::MemoryResourcePtr get(const std::string & url) override
{
return std::make_shared<resource_retriever::MemoryResource>(
url, url, std::vector<uint8_t>{0, 1, 2, 3, 4, 5});
}
};

Expand Down

0 comments on commit 8e6d4ee

Please sign in to comment.