summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-06-26 22:25:22 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-06-26 23:05:21 +0200
commitd65936200a2756e6619a109fa6fa673b91df802e (patch)
tree80b6b6fc7ba9023cbe47290b8ae1bc5468a19bb1 /compat
parent4046773c41ee3c0f65840828ab983cfd13451c85 (diff)
modernize C++ syntax
No visible changes (hopefully).
Diffstat (limited to 'compat')
-rw-r--r--compat/camera-names.cpp12
-rw-r--r--compat/correlation-calibrator.cpp8
-rw-r--r--compat/macros.hpp20
-rw-r--r--compat/shm.cpp4
-rw-r--r--compat/timer.cpp2
-rw-r--r--compat/timer.hpp2
6 files changed, 23 insertions, 25 deletions
diff --git a/compat/camera-names.cpp b/compat/camera-names.cpp
index 22dcdd8f..c88bae75 100644
--- a/compat/camera-names.cpp
+++ b/compat/camera-names.cpp
@@ -33,30 +33,30 @@ OTR_COMPAT_EXPORT QList<QString> get_camera_names()
// Create the System Device Enumerator.
HRESULT hr;
CoInitialize(nullptr);
- ICreateDevEnum *pSysDevEnum = NULL;
- hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
+ ICreateDevEnum *pSysDevEnum = nullptr;
+ hr = CoCreateInstance(CLSID_SystemDeviceEnum, nullptr, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)&pSysDevEnum);
if (FAILED(hr))
{
qDebug() << "failed CLSID_SystemDeviceEnum" << hr;
return ret;
}
// Obtain a class enumerator for the video compressor category.
- IEnumMoniker *pEnumCat = NULL;
+ IEnumMoniker *pEnumCat = nullptr;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnumCat, 0);
if (hr == S_OK) {
// Enumerate the monikers.
- IMoniker *pMoniker = NULL;
+ IMoniker *pMoniker = nullptr;
ULONG cFetched;
while (pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
IPropertyBag *pPropBag;
- hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void **)&pPropBag);
+ 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, 0);
+ hr = pPropBag->Read(L"FriendlyName", &varName, nullptr);
if (SUCCEEDED(hr))
{
// Display the name in your UI somehow.
diff --git a/compat/correlation-calibrator.cpp b/compat/correlation-calibrator.cpp
index 949f10ae..70455818 100644
--- a/compat/correlation-calibrator.cpp
+++ b/compat/correlation-calibrator.cpp
@@ -49,7 +49,7 @@ static constexpr wchar_t const* const names[6] {
L"yaw", L"pitch", L"roll",
};
-bool correlation_calibrator::check_buckets(const vec6 &data)
+bool correlation_calibrator::check_buckets(const vec6& data)
{
bool ret = false;
unsigned pos[6];
@@ -63,7 +63,7 @@ bool correlation_calibrator::check_buckets(const vec6 &data)
{
once_only(qDebug() << "idx" << k
<< "bucket" << (int)pos[k]
- << "outside bounds" << nbuckets[k]);;
+ << "outside bounds" << nbuckets[k]);
return false;
}
@@ -135,8 +135,8 @@ mat66 correlation_calibrator::get_coefficients() const
#if defined DEBUG_PRINT
fwprintf(stderr, L"v:change-of h:due-to\n");
fwprintf(stderr, L"%10s ", L"");
- for (unsigned k = 0; k < 6; k++)
- fwprintf(stderr, L"%10s", names[k]);
+ for (wchar_t const* k : names)
+ fwprintf(stderr, L"%10s", k);
fwprintf(stderr, L"\n");
for (unsigned i = 0; i < 6; i++)
diff --git a/compat/macros.hpp b/compat/macros.hpp
index 761da0b1..61c49975 100644
--- a/compat/macros.hpp
+++ b/compat/macros.hpp
@@ -2,21 +2,17 @@
#if defined _MSC_VER
# define cc_noinline __declspec(noinline)
-#elif defined __GNUG__
-# define cc_noinline __attribute__((noinline))
#else
-# define cc_noinline
+# define cc_noinline __attribute__((noinline))
#endif
#if defined _MSC_VER
# define cc_forceinline __forceinline
#else
-# define cc_forceinline __attribute__((always_inline, gnu_inline)) inline
+# define cc_forceinline __attribute__((always_inline))
#endif
-#ifdef Q_CREATOR_RUN
-# define cc_warn_unused_result
-#elif defined _MSC_VER
+#if defined _MSC_VER
# define cc_warn_unused_result _Check_return_
#else
# define cc_warn_unused_result __attribute__((warn_unused_result))
@@ -40,15 +36,17 @@
#if !defined PP_CAT
# define PP_CAT(x,y) PP_CAT1(x,y)
-# define PP_CAT1(x,y) x##y
+# define PP_CAT1(x,y) PP_CAT2(x,y)
+# define PP_CAT2(x,y) x ## y
#endif
-#define once_only(...) do { static bool once__ = false; if (!once__) { once__ = true; __VA_ARGS__; } } while(false)
-
#if defined __cplusplus
// from now only C++
+//#define once_only(...) do { static bool once__ = false; if (!once__) { once__ = true; __VA_ARGS__; } } while(false)
+#define once_only(expr) ([&] { static decltype(auto) ret___1132 = (expr); return ret___1132; }())
+
#include <type_traits>
template<typename t>
@@ -66,7 +64,7 @@ constexpr cc_forceinline void static_warn<true>() {}
static_warn<(cond)>(); \
#define progn(...) (([&] { __VA_ARGS__ })())
-#define prog1(x, ...) (([&] { auto _ret1324 = (x); do { __VA_ARGS__; } while (0); return _ret1324; })())
+#define prog1(x, ...) (([&] { decltype(auto) ret1324 = (x); __VA_ARGS__; return ret1324; })())
// end c++-only macros
#endif
diff --git a/compat/shm.cpp b/compat/shm.cpp
index 0f44d8bc..791cb303 100644
--- a/compat/shm.cpp
+++ b/compat/shm.cpp
@@ -10,7 +10,7 @@
#if defined _WIN32
#include <cstring>
-#include <stdio.h>
+#include <cstdio>
#include <accctrl.h>
#include <aclapi.h>
@@ -131,7 +131,7 @@ bool shm_wrapper::success()
#ifndef _WIN32
return mem != (void*) -1;
#else
- return mem != NULL;
+ return mem != nullptr;
#endif
}
diff --git a/compat/timer.cpp b/compat/timer.cpp
index 0e7fb362..dc9808b1 100644
--- a/compat/timer.cpp
+++ b/compat/timer.cpp
@@ -82,7 +82,7 @@ static void otr_clock_gettime(timespec* ts)
(void) QueryPerformanceCounter(&d);
using ll = long long;
- const ll part = ll(std::roundl((d.QuadPart * 1000000000.L) / ll(freq.QuadPart)));
+ const auto part = ll(std::roundl((d.QuadPart * 1000000000.L) / ll(freq.QuadPart)));
using t_s = decltype(ts->tv_sec);
using t_ns = decltype(ts->tv_nsec);
diff --git a/compat/timer.hpp b/compat/timer.hpp
index fb14145d..26e612b0 100644
--- a/compat/timer.hpp
+++ b/compat/timer.hpp
@@ -33,7 +33,7 @@ struct OTR_COMPAT_EXPORT Timer final
double elapsed_ms() const;
double elapsed_seconds() const;
private:
- struct timespec state;
+ struct timespec state {};
static void gettime(struct timespec* state);
time_type conv_nsecs(const struct timespec& cur) const;
using ns = time_units::ns;