From 9cca4ffd9987352e43119d9c4dea0ce84c2c448f Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 5 Oct 2018 15:59:58 +0200 Subject: silly busywork --- compat/camera-names.cpp | 33 ++++++++++++--------------------- compat/macros.hpp | 2 +- compat/math.hpp | 6 +++--- compat/qhash.hpp | 3 +-- 4 files changed, 17 insertions(+), 27 deletions(-) (limited to 'compat') 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 # define NO_DSHOW_STRSAFE # include -# include #elif defined(__unix) || defined(__linux) || defined(__APPLE__) # include #endif @@ -13,6 +13,7 @@ # include # include # include +# include #endif #include @@ -29,7 +30,7 @@ int camera_name_to_index(const QString &name) QList get_camera_names() { QList ret; -#if defined(_WIN32) +#ifdef _WIN32 // Create the System Device Enumerator. HRESULT hr; CoInitialize(nullptr); @@ -54,23 +55,16 @@ QList 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 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 get_camera_names() close(fd); continue; } - ret[ret.size()-1] = reinterpret_cast(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 const&; template using cv_qualified = std::conditional_t>, std::decay_t, - std::add_lvalue_reference_t>>>; + std::add_lvalue_reference_t>>>; template [[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, tp>::clamp_(val, min, max); } -template -inline auto iround(t val) -> std::enable_if_t>, t> +template +inline auto iround(t val) -> std::enable_if_t>, integral_type> { - return (int) std::round(val); + return static_cast(std::round(val)); } template 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 #include #include namespace std { template<> struct hash { - inline unsigned operator()(const QString& value) const + constexpr unsigned operator()(const QString& value) const { return qHash(value); } -- cgit v1.2.3