From b87833b701a02fa960fab3fdb40d0b2d2c49a80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Mon, 22 Aug 2022 03:23:12 +0200 Subject: Change initialization style. Because I don't want to have to remember what classes have initializer_list overloads. --- c/data.cpp | 4 ++-- c/data.h | 12 ++++++------ c/debug.cpp | 4 ++-- c/main.cpp | 6 +++--- c/test.cpp | 42 +++++++++++++++++++++--------------------- c/wcharptr.cpp | 2 +- c/win.cpp | 8 ++++---- c/win.h | 4 ++-- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/c/data.cpp b/c/data.cpp index e260209..58fcde7 100644 --- a/c/data.cpp +++ b/c/data.cpp @@ -16,7 +16,7 @@ struct InternetFile INTERNET_OPEN_TYPE_DIRECT, nullptr, nullptr, /*INTERNET_FLAG_ASYNC*/0); if (!hi) - throw Win32Error{}; + throw Win32Error(); hiUrl = InternetOpenUrl(hi, url, nullptr, 0, INTERNET_FLAG_NO_UI, 0); @@ -39,7 +39,7 @@ struct InternetFile if (InternetReadFile(hiUrl, buf, cb, &cbRead)) return cbRead; else - throw InternetError{}; + throw InternetError(); } HINTERNET hi; diff --git a/c/data.h b/c/data.h index 23c9e5f..14e8920 100644 --- a/c/data.h +++ b/c/data.h @@ -62,7 +62,7 @@ struct CfgA /* Variable template for obtaining the version of a given struct. */ template -constexpr inline unsigned char Version = T{}.version; +constexpr inline unsigned char Version = T().version; template constexpr inline bool HasVersion = false; @@ -79,7 +79,7 @@ struct FileView static FileView Initialized(const wchar_t* filename, size_t c, size_t cInit = 0) { bool bExisting = GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES; - FileView fv{filename, c}; + FileView fv(filename, c); /* If file didn't exist, initialize it with defaults. */ if (!bExisting) { @@ -101,9 +101,9 @@ struct FileView hf = CreateFile(filename, GENERIC_READ|GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr); if (hf == INVALID_HANDLE_VALUE) - throw Win32Error{}; + throw Win32Error(); } else - throw Win32Error{}; + throw Win32Error(); } LARGE_INTEGER cbMap; @@ -111,11 +111,11 @@ struct FileView hm = CreateFileMapping(hf, nullptr, PAGE_READWRITE, cbMap.HighPart, cbMap.LowPart, nullptr); if (!hm) - throw Win32Error{}; + throw Win32Error(); view = reinterpret_cast(MapViewOfFile(hm, FILE_MAP_ALL_ACCESS, 0, 0, 0)); if (!view) - throw Win32Error{}; + throw Win32Error(); } ~FileView() diff --git a/c/debug.cpp b/c/debug.cpp index a7f7595..e8a9d6e 100644 --- a/c/debug.cpp +++ b/c/debug.cpp @@ -19,13 +19,13 @@ Benchmark::Benchmark(const char* const name, const int id, const int avgmax) { if (!freq) { if (!QueryPerformanceFrequency(&liFreq)) - throw Win32Error{}; + throw Win32Error(); freq = liFreq.QuadPart; } LARGE_INTEGER liTicks; if (!QueryPerformanceCounter(&liTicks)) - throw Win32Error{}; + throw Win32Error(); ticks = liTicks.QuadPart; } diff --git a/c/main.cpp b/c/main.cpp index 0e6c839..e3e2f82 100644 --- a/c/main.cpp +++ b/c/main.cpp @@ -59,8 +59,8 @@ DlvDragger g_dragDlv; /* File views. */ FileView g_fvCfg = FileView::Initialized(L"cfg.dat", 1); CfgA& g_cfg = g_fvCfg.At(0); -FileView g_fvElv{L"elvdata.dat", g_cfg.cEp+128u}; -FileView g_fvDlv{L"dlvdata.dat", g_cfg.cEp+128u}; +FileView g_fvElv(L"elvdata.dat", g_cfg.cEp+128u); +FileView g_fvDlv(L"dlvdata.dat", g_cfg.cEp+128u); /* Optional Windows functions. */ BOOL (*IsThemeActive)(); @@ -473,7 +473,7 @@ void WaitFor(void (*f)(bool*)) * shared boolean value to true. */ bDone = false; bActive = true; - std::thread{f, &bDone}.detach(); + std::thread(f, &bDone).detach(); SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), reinterpret_cast(L".")); Prefer(iTimer = SetTimer(nullptr, -1, 500, proc)); } diff --git a/c/test.cpp b/c/test.cpp index 7d6b3ed..a649f23 100644 --- a/c/test.cpp +++ b/c/test.cpp @@ -64,7 +64,7 @@ TESTS /* Write two ElvDataA structs to disk. */ { - FileView fv{L"tmp.dat", 2}; + FileView fv(L"tmp.dat", 2); memcpy(fv+0, &e1_0, sizeof(e1_0)); memcpy(fv+1, &e2_0, sizeof(e2_0)); } @@ -72,7 +72,7 @@ TESTS /* Read first ElvDataA struct from disk using * ElvDataA-typed FileView. */ { - FileView fv{L"tmp.dat", 2}; + FileView fv(L"tmp.dat", 2); const ElvDataA& e1 = *fv; if (e1.version != 'a') FAIL("version is different"); @@ -93,7 +93,7 @@ TESTS /* Read second ElvDataA struct from disk using * unsigned char-typed FileView. */ { - FileView fv{L"tmp.dat", 2*sizeof(ElvDataA)}; + FileView fv(L"tmp.dat", 2*sizeof(ElvDataA)); ElvDataA& e2 = *reinterpret_cast(&fv.At(sizeof(ElvDataA))); if (e2_0.rating != e2.rating) FAIL("rating is different (%d/%d)", e2_0.rating, e2.rating); @@ -118,7 +118,7 @@ TESTS return; { - FileView fv{L"tmp.dat", g_cfg.cEp+128u}; + FileView fv(L"tmp.dat", g_cfg.cEp+128u); ElvDataA* p = fv; for (int iEp = 1; iEp <= cEp; iEp++) { @@ -129,7 +129,7 @@ TESTS } } { - FileView fv{L"tmp.dat", g_cfg.cEp+128u}; + FileView fv(L"tmp.dat", g_cfg.cEp+128u); ElvDataA& e = fv.At(9); if (wcscmp(e.title, L"Pro Soccer Player Blackmail Case") != 0) FAIL("title is not correct"); @@ -141,12 +141,12 @@ TESTS { CfgA cfg_0; { - FileView fv{L"tmp.dat", 1}; + FileView fv(L"tmp.dat", 1); Wcscpy(cfg_0.url, L"https://animixplay.to/v1/detective-conan/ep"); memcpy(fv, &cfg_0, sizeof(cfg_0)); } { - FileView fv{L"tmp.dat", 1}; + FileView fv(L"tmp.dat", 1); const CfgA& cfg = fv.At(0); if (cfg_0.bViewWatched != cfg.bViewWatched) FAIL("bViewWatched is different"); @@ -158,7 +158,7 @@ TESTS // TEST(MigrateCfg) // { - // FileView fva{L"cfga.dat", 1}; + // FileView fva(L"cfga.dat", 1); // FileView fvb = FileView::Initialized(L"cfgb.dat", 1); // fvb->bViewWatched = fva->bViewWatched; // fvb->bViewTVOriginal = fva->bViewTVOriginal; @@ -178,7 +178,7 @@ TESTS return; { - FileView fv{L"tmp.dat", g_cfg.cEp+128u}; + FileView fv(L"tmp.dat", g_cfg.cEp+128u); DlvDataA* p = fv; for (int iEp = 1; iEp <= cEp; iEp++) { @@ -189,7 +189,7 @@ TESTS } } { - FileView fv{L"tmp.dat", g_cfg.cEp+128u}; + FileView fv(L"tmp.dat", g_cfg.cEp+128u); DlvDataA& e = fv.At(9); if (wcscmp(e.date, L"March 11, 1996") != 0) FAIL("date is not correct"); @@ -224,23 +224,23 @@ TESTS TEST(Fetch) { bool bDone = false; - std::thread{WaitFetchData, &bDone}.detach(); + std::thread(WaitFetchData, &bDone).detach(); } }; int RunTests() { const Test tests[] = { - StrcpyWithSmallerDestination{}, - //EpisodeDataFromWeb{}, - //EpisodeDataFromProlog{}, - //IO{}, - //MigrateElvDataFromPrologToDisk{}, - //SampleConfigurationToDisk{}, - //MigrateCfg{} - //MigrateDlvDataFromPrologToDisk{}, - //DownloadDataViaProlog{}, - //Fetch{}, + StrcpyWithSmallerDestination(), + //EpisodeDataFromWeb(), + //EpisodeDataFromProlog(), + //IO(), + //MigrateElvDataFromPrologToDisk(), + //SampleConfigurationToDisk(), + //MigrateCfg() + //MigrateDlvDataFromPrologToDisk(), + //DownloadDataViaProlog(), + //Fetch(), }; printf("Results (%llu tests):\n", sizeof(tests)/sizeof(*tests)); diff --git a/c/wcharptr.cpp b/c/wcharptr.cpp index f7cb948..f659767 100644 --- a/c/wcharptr.cpp +++ b/c/wcharptr.cpp @@ -11,7 +11,7 @@ WcharPtr WcharPtr::FromNarrow(const char* const src, const int cp) wchar_t* dst = new wchar_t[cchWide]; if (!MultiByteToWideChar(cp, 0, src, cchNarrow, dst, cchWide)) { delete dst; - throw Win32Error{}; + throw Win32Error(); } return dst; } diff --git a/c/win.cpp b/c/win.cpp index 601f82c..548c951 100644 --- a/c/win.cpp +++ b/c/win.cpp @@ -170,7 +170,7 @@ const wchar_t* Win32Error::What() const noexcept InternetError::InternetError(DWORD codeSystem) { if (codeSystem != ERROR_INTERNET_EXTENDED_ERROR) - throw Win32Error{codeSystem}; + throw Win32Error(codeSystem); DWORD len, cch; InternetGetLastResponseInfo(&code, nullptr, &len); @@ -178,12 +178,12 @@ InternetError::InternetError(DWORD codeSystem) cch = len+1; m_szMsg = new char[cch]; if (!InternetGetLastResponseInfoA(&code, m_szMsg, &cch)) - throw Win32Error{}; + throw Win32Error(); cch = len+1; m_wszMsg = new wchar_t[cch]; if (!InternetGetLastResponseInfo(&code, m_wszMsg, &len)) - throw Win32Error{}; + throw Win32Error(); } InternetError::~InternetError() @@ -216,7 +216,7 @@ Library::Library(const wchar_t* const lib) { m_hModule = LoadLibrary(lib); if (!m_hModule) - throw Win32Error{}; + throw Win32Error(); } Library::~Library() diff --git a/c/win.h b/c/win.h index f5bda59..06de198 100644 --- a/c/win.h +++ b/c/win.h @@ -74,7 +74,7 @@ T* Library::GetProcAddress(const char* const szProc) noexcept template inline T Require(const T x) { - if (!x) throw Win32Error{}; + if (!x) throw Win32Error(); return x; } @@ -83,7 +83,7 @@ template inline T Prefer(const T x) { if (!x) { - EBMessageBox(Win32Error{}.What(), L"System Error", MB_ICONWARNING); + EBMessageBox(Win32Error().What(), L"System Error", MB_ICONWARNING); return (T)0; } return x; -- cgit v1.2.3