summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
Diffstat (limited to 'compat')
-rw-r--r--compat/camera-names.cpp33
-rw-r--r--compat/macros.hpp2
-rw-r--r--compat/math.hpp6
-rw-r--r--compat/qhash.hpp3
4 files changed, 17 insertions, 27 deletions
diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp
index 23649d38..246d76ee 100644
--- a/compat/camera-names.cpp
+++ b/compat/camera-names.cpp
@@ -1,9 +1,9 @@
#include "camera-names.hpp"
#ifdef _WIN32
+# include <cwchar>
# define NO_DSHOW_STRSAFE
# include <dshow.h>
-# include <cwchar>
#elif defined(__unix) || defined(__linux) || defined(__APPLE__)
# include <unistd.h>
#endif
@@ -13,6 +13,7 @@
# include <sys/ioctl.h>
# include <linux/videodev2.h>
# include <cerrno>
+# include <cstring>
#endif
#include <QDebug>
@@ -29,7 +30,7 @@ int camera_name_to_index(const QString &name)
QList<QString> get_camera_names()
{
QList<QString> ret;
-#if defined(_WIN32)
+#ifdef _WIN32
// Create the System Device Enumerator.
HRESULT hr;
CoInitialize(nullptr);
@@ -54,23 +55,16 @@ QList<QString> get_camera_names()
hr = pMoniker->BindToStorage(nullptr, nullptr, IID_IPropertyBag, (void **)&pPropBag);
if (SUCCEEDED(hr)) {
// To retrieve the filter's friendly name, do the following:
- VARIANT varName;
- VariantInit(&varName);
- hr = pPropBag->Read(L"FriendlyName", &varName, nullptr);
+ VARIANT var;
+ VariantInit(&var);
+ hr = pPropBag->Read(L"FriendlyName", &var, nullptr);
if (SUCCEEDED(hr))
{
// Display the name in your UI somehow.
- QString str((QChar*)varName.bstrVal, int(std::wcslen(varName.bstrVal)));
+ QString str((QChar*)var.bstrVal, int(std::wcslen(var.bstrVal)));
ret.append(str);
}
- VariantClear(&varName);
-
- ////// To create an instance of the filter, do the following:
- ////IBaseFilter *pFilter;
- ////hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
- //// (void**)&pFilter);
- // Now add the filter to the graph.
- //Remember to release pFilter later.
+ VariantClear(&var);
pPropBag->Release();
}
pMoniker->Release();
@@ -82,14 +76,11 @@ QList<QString> get_camera_names()
pSysDevEnum->Release();
#endif
+
#ifdef __linux
for (int i = 0; i < 16; i++) {
- char buf[128];
- sprintf(buf, "/dev/video%d", i);
- if (access(buf, F_OK) == 0)
- ret.append(buf);
- else
- continue;
+ char buf[32];
+ snprintf(buf, sizeof(buf), "/dev/video%d", i);
if (access(buf, R_OK | W_OK) == 0) {
int fd = open(buf, O_RDONLY);
@@ -102,7 +93,7 @@ QList<QString> get_camera_names()
close(fd);
continue;
}
- ret[ret.size()-1] = reinterpret_cast<const char*>(video_cap.card);
+ ret.append(QString{(const char*)video_cap.card});
close(fd);
}
}
diff --git a/compat/macros.hpp b/compat/macros.hpp
index 3c93ee13..42d5d649 100644
--- a/compat/macros.hpp
+++ b/compat/macros.hpp
@@ -85,7 +85,7 @@ using to_const_lvalue_reference_t = remove_cvref_t<t> const&;
template<typename t>
using cv_qualified = std::conditional_t<std::is_fundamental_v<std::decay_t<t>>,
std::decay_t<t>,
- std::add_lvalue_reference_t<std::add_const_t<std::remove_reference_t<t>>>>;
+ std::add_lvalue_reference_t<std::add_const_t<remove_cvref_t<t>>>>;
template<bool>
[[deprecated]] constexpr cc_forceinline void static_warn() {}
diff --git a/compat/math.hpp b/compat/math.hpp
index eae1435e..04a6e08d 100644
--- a/compat/math.hpp
+++ b/compat/math.hpp
@@ -53,10 +53,10 @@ inline auto clamp(const t& val, const u& min, const w& max)
return ::util_detail::clamp<std::decay_t<tp>, tp>::clamp_(val, min, max);
}
-template<typename t>
-inline auto iround(t val) -> std::enable_if_t<!std::is_integral_v<std::decay_t<t>>, t>
+template<typename t, typename integral_type = int>
+inline auto iround(t val) -> std::enable_if_t<!std::is_integral_v<std::decay_t<t>>, integral_type>
{
- return (int) std::round(val);
+ return static_cast<integral_type>(std::round(val));
}
template<typename t>
diff --git a/compat/qhash.hpp b/compat/qhash.hpp
index a9685007..ba569285 100644
--- a/compat/qhash.hpp
+++ b/compat/qhash.hpp
@@ -1,13 +1,12 @@
#pragma once
-#include <functional>
#include <QString>
#include <QHashFunctions>
namespace std {
template<> struct hash<QString>
{
- inline unsigned operator()(const QString& value) const
+ constexpr unsigned operator()(const QString& value) const
{
return qHash(value);
}