Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increases warning levels #10

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ install(TARGETS FairyCam

set_target_properties(FairyCam PROPERTIES PUBLIC_HEADER "${HEADERS}")

target_compile_options(FairyCam PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wconversion -pedantic-errors -Wsign-conversion>
$<$<CXX_COMPILER_ID:MSVC>:
/W4>)

include(GNUInstallDirs)
install(TARGETS FairyCam
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
14 changes: 9 additions & 5 deletions src/DirectoryCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class DirectoryCamera
public:
DirectoryCamera() : DirectoryCamera(Options{}) {}
DirectoryCamera(Options opts) : m_opts{std::move(opts)} {}
bool open(int idx, int apiPreference, const std::vector<int> &params)
bool open([[maybe_unused]] int idx, [[maybe_unused]] int apiPreference,
[[maybe_unused]] const std::vector<int> &params)
{
if (!std::filesystem::is_directory(m_opts.dir))
return false;
Expand All @@ -51,7 +52,7 @@ class DirectoryCamera

return std::filesystem::exists(m_file);
}
bool retrieve(cv::OutputArray image, int flag = 0)
bool retrieve(cv::OutputArray image, [[maybe_unused]] int flag = 0)
{
auto mat = cv::imread(m_file.string());
image.assign(mat);
Expand All @@ -66,9 +67,12 @@ class DirectoryCamera
}
return retrieve(image);
}
bool set(int propId, double value) { return false; }
double get(int propId) const { return -1.0; }
void setExceptionMode(bool enable) {}
bool set([[maybe_unused]] int propId, [[maybe_unused]] double value)
{
return false;
}
double get([[maybe_unused]] int propId) const { return -1.0; }
void setExceptionMode([[maybe_unused]] bool enable) {}
bool getExceptionMode() const { return false; }
DirectoryCamera &operator>>(CV_OUT cv::Mat &image)
{
Expand Down
8 changes: 5 additions & 3 deletions src/DirectoryTriggerCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ DirectoryTriggerCamera::DirectoryTriggerCamera(Options opts)

DirectoryTriggerCamera::~DirectoryTriggerCamera() { release(); }

bool DirectoryTriggerCamera::open(int idx, int apiPreference,
const std::vector<int> &params)
bool DirectoryTriggerCamera::open(
[[maybe_unused]] int idx, [[maybe_unused]] int apiPreference,
[[maybe_unused]] const std::vector<int> &params)
{
if (!std::filesystem::is_directory(d->m_opts.dir))
return false;
Expand Down Expand Up @@ -79,7 +80,8 @@ bool DirectoryTriggerCamera::grab()
return d->m_msg != nullptr;
}

bool DirectoryTriggerCamera::retrieve(cv::OutputArray image, int flag)
bool DirectoryTriggerCamera::retrieve(cv::OutputArray image,
[[maybe_unused]] int flag)
{
if (!isOpened())
return false;
Expand Down
9 changes: 6 additions & 3 deletions src/DirectoryTriggerCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ class DirectoryTriggerCamera
bool grab();
bool retrieve(cv::OutputArray image, int flag = 0);
bool read(cv::OutputArray image);
bool set(int propId, double value) { return false; }
double get(int propId) const { return -1.0; }
void setExceptionMode(bool enable) {}
bool set([[maybe_unused]] int propId, [[maybe_unused]] double value)
{
return false;
}
double get([[maybe_unused]] int propId) const { return -1.0; }
void setExceptionMode([[maybe_unused]] bool enable) {}
bool getExceptionMode() const { return false; }
DirectoryTriggerCamera &operator>>(cv::Mat &image)
{
Expand Down
2 changes: 1 addition & 1 deletion src/FileCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bool FileCamera::grab()
return std::filesystem::exists(*m_current);
}

bool FileCamera::retrieve(cv::OutputArray image, int flag)
bool FileCamera::retrieve(cv::OutputArray image, [[maybe_unused]] int flag)
{
if (!m_is_open || m_current == m_opts.files.cend())
return false;
Expand Down
12 changes: 8 additions & 4 deletions src/FileCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class FileCamera
m_next{m_opts.files.cend()}
{
}
bool open(int idx, int apiPreference, const std::vector<int> &params)
bool open([[maybe_unused]] int idx, [[maybe_unused]] int apiPreference,
[[maybe_unused]] const std::vector<int> &params)
{
m_is_open = true;
m_next = m_opts.files.cbegin();
Expand All @@ -47,9 +48,12 @@ class FileCamera
bool grab();
bool retrieve(cv::OutputArray image, int flag = 0);
bool read(cv::OutputArray image);
bool set(int propId, double value) { return false; }
double get(int propId) const { return -1.0; }
void setExceptionMode(bool enable) {}
bool set([[maybe_unused]] int propId, [[maybe_unused]] double value)
{
return false;
}
double get([[maybe_unused]] int propId) const { return -1.0; }
void setExceptionMode([[maybe_unused]] bool enable) {}
bool getExceptionMode() const { return false; }
FileCamera &operator>>(CV_OUT cv::Mat &image)
{
Expand Down
7 changes: 4 additions & 3 deletions src/HttpCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ HttpCamera::HttpCamera(Options opts) : d(std::make_unique<Impl>(opts)) {}

HttpCamera::~HttpCamera() { release(); }

bool HttpCamera::open(int idx, int apiPreference,
const std::vector<int> &params)
bool HttpCamera::open([[maybe_unused]] int idx,
[[maybe_unused]] int apiPreference,
[[maybe_unused]] const std::vector<int> &params)
{
d->m_srv.start();
d->m_started = true;
Expand Down Expand Up @@ -151,7 +152,7 @@ bool HttpCamera::grab()
return d->m_msg != nullptr;
}

bool HttpCamera::retrieve(cv::OutputArray image, int flag)
bool HttpCamera::retrieve(cv::OutputArray image, [[maybe_unused]] int flag)
{
if (d->m_msg == nullptr)
return false;
Expand Down
11 changes: 7 additions & 4 deletions src/HttpCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HttpCamera
public:
struct Options
{
uint32_t port = 5001;
uint16_t port = 5001;
int grabTimeOutMs = 10000;
};

Expand All @@ -25,9 +25,12 @@ class HttpCamera
bool grab();
bool retrieve(cv::OutputArray image, int flag = 0);
bool read(cv::OutputArray image);
bool set(int propId, double value) { return false; }
double get(int propId) const noexcept { return -1.0; }
void setExceptionMode(bool enable) {}
bool set([[maybe_unused]] int propId, [[maybe_unused]] double value)
{
return false;
}
double get([[maybe_unused]] int propId) const noexcept { return -1.0; }
void setExceptionMode([[maybe_unused]] bool enable) {}
bool getExceptionMode() const noexcept { return false; }
HttpCamera &operator>>(cv::Mat &image)
{
Expand Down
2 changes: 1 addition & 1 deletion src/MemoryCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bool MemoryCamera::grab()
return !m_current->empty();
}

bool MemoryCamera::retrieve(cv::OutputArray image, int flag)
bool MemoryCamera::retrieve(cv::OutputArray image,[[maybe_unused]] int flag)
{
if (!m_is_open || m_current == m_opts.images.cend())
return false;
Expand Down
12 changes: 8 additions & 4 deletions src/MemoryCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class MemoryCamera
m_next{m_opts.images.cend()}
{
}
bool open(int idx, int apiPreference, const std::vector<int> &params)
bool open([[maybe_unused]] int idx, [[maybe_unused]] int apiPreference,
[[maybe_unused]] const std::vector<int> &params)
{
m_is_open = true;
m_next = m_opts.images.cbegin();
Expand All @@ -47,9 +48,12 @@ class MemoryCamera
bool grab();
bool retrieve(cv::OutputArray image, int flag = 0);
bool read(cv::OutputArray image);
bool set(int propId, double value) { return false; }
double get(int propId) const { return -1.0; }
void setExceptionMode(bool enable) {}
bool set([[maybe_unused]] int propId, [[maybe_unused]] double value)
{
return false;
}
double get([[maybe_unused]] int propId) const { return -1.0; }
void setExceptionMode([[maybe_unused]] bool enable) {}
bool getExceptionMode() const { return false; }
MemoryCamera &operator>>(CV_OUT cv::Mat &image)
{
Expand Down
8 changes: 4 additions & 4 deletions src/chaos/BernoulliSequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class BernoulliSequence : public Sequence
{
}

BernoulliSequence(int seed, Options opts)
BernoulliSequence(unsigned seed, Options opts)
: m_is_open{std::move(opts.isOpen)},
m_retrieve{std::move(opts.retrieve)}, m_grab{std::move(opts.grab)}
{
Expand All @@ -74,11 +74,11 @@ class BernoulliSequence : public Sequence
private:
struct Probas
{
std::binomial_distribution<> fail;
std::discrete_distribution<> exception_distribution;
std::binomial_distribution<unsigned> fail;
std::discrete_distribution<unsigned> exception_distribution;
std::vector<std::function<void()>> exceptions;
Probas(Fail &&f)
: fail{std::binomial_distribution<>{1, f.probability}},
: fail{std::binomial_distribution<unsigned>{1, f.probability}},
exception_distribution{std::begin(f.weights),
std::end(f.weights)},
exceptions{std::move(f.exceptions)}
Expand Down
17 changes: 12 additions & 5 deletions src/chaos/ChaosCamera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class ChaosCamera
m_error_sequence{std::make_unique<SeqT>(std::move(seq))}
{
}
bool open(int idx, int apiPreference, const std::vector<int> &params)
bool open([[maybe_unused]] int idx, [[maybe_unused]] int apiPreference,
[[maybe_unused]] const std::vector<int> &params)
{
if (!checkIsOpen())
return false;
Expand All @@ -97,7 +98,7 @@ class ChaosCamera
}
return true;
}
bool retrieve(cv::OutputArray image, int flag = 0)
bool retrieve(cv::OutputArray image, [[maybe_unused]] int flag = 0)
{
if (!isOpened())
return false;
Expand All @@ -117,9 +118,15 @@ class ChaosCamera
return false;
return retrieve(image);
}
bool set(int propId, double value) { return false; }
double get(int propId) const { return -1.0; }
void setExceptionMode(bool enable) noexcept { m_active_exception = enable; }
bool set([[maybe_unused]] int propId, [[maybe_unused]] double value)
{
return false;
}
double get([[maybe_unused]] int propId) const { return -1.0; }
void setExceptionMode([[maybe_unused]] bool enable) noexcept
{
m_active_exception = enable;
}
bool getExceptionMode() const noexcept { return m_active_exception; }
ChaosCamera &operator>>(CV_OUT cv::Mat &image)
{
Expand Down
6 changes: 6 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ target_link_libraries(Tests PRIVATE Poco::Foundation Poco::Net doctest FairyCam)
target_compile_definitions(Tests PRIVATE "TEST_DATA=\"${CMAKE_CURRENT_SOURCE_DIR}/data/\"")
target_compile_features(Tests PUBLIC cxx_std_20)

target_compile_options(Tests PRIVATE
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wconversion -pedantic-errors -Wsign-conversion>
$<$<CXX_COMPILER_ID:MSVC>:
/W4>)

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_link_libraries(Tests PUBLIC -fsanitize=address,undefined)
endif()
Expand Down
4 changes: 2 additions & 2 deletions tests/HttpCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import FairyCam;

using namespace FairyCam;

uint getPort()
uint16_t getPort()
{
static uint port = 5000;
static uint16_t port = 5000;
return port++;
}

Expand Down
Loading