From f764da51766f5a5c2500fadc294846c4619d03c3 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Sat, 2 Jan 2021 12:44:35 -0800 Subject: [PATCH] Replaced _countof / ARRAYSIZE with std::size --- DDSView/ddsview.cpp | 16 ++++++++-------- DirectXTex/BC.h | 1 - DirectXTex/BC6HBC7.cpp | 10 +++++----- DirectXTex/DirectXTexConvert.cpp | 14 +++++++------- DirectXTex/DirectXTexP.h | 1 + DirectXTex/DirectXTexUtil.cpp | 6 +++--- DirectXTex/DirectXTexWIC.cpp | 2 +- DirectXTex/scoped.h | 3 ++- Texassemble/AnimatedGif.cpp | 2 +- Texassemble/texassemble.cpp | 2 +- Texconv/texconv.cpp | 4 ++-- Texdiag/texdiag.cpp | 2 +- WICTextureLoader/WICTextureLoader11.cpp | 4 ++-- WICTextureLoader/WICTextureLoader12.cpp | 4 ++-- WICTextureLoader/WICTextureLoader9.cpp | 4 ++-- 15 files changed, 38 insertions(+), 37 deletions(-) diff --git a/DDSView/ddsview.cpp b/DDSView/ddsview.cpp index 0938957..7c84424 100644 --- a/DDSView/ddsview.cpp +++ b/DDSView/ddsview.cpp @@ -347,7 +347,7 @@ HRESULT InitDevice( const TexMetadata& mdata ) D3D_DRIVER_TYPE_WARP, D3D_DRIVER_TYPE_REFERENCE, }; - UINT numDriverTypes = ARRAYSIZE( driverTypes ); + constexpr UINT numDriverTypes = static_cast(std::size(driverTypes)); D3D_FEATURE_LEVEL featureLevels[] = { @@ -355,7 +355,7 @@ HRESULT InitDevice( const TexMetadata& mdata ) D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, }; - UINT numFeatureLevels = ARRAYSIZE( featureLevels ); + constexpr UINT numFeatureLevels = static_cast(std::size(featureLevels)); DXGI_SWAP_CHAIN_DESC sd = {}; sd.BufferCount = 1; @@ -444,7 +444,7 @@ HRESULT InitDevice( const TexMetadata& mdata ) { "POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, sizeof(XMFLOAT4), D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; - UINT numElements = ARRAYSIZE( layout ); + constexpr UINT numElements = static_cast(std::size(layout)); // Create the input layout hr = g_pd3dDevice->CreateInputLayout( layout, numElements, g_VS, sizeof(g_VS), &g_pVertexLayout ); @@ -574,17 +574,17 @@ HRESULT InitDevice( const TexMetadata& mdata ) if ( isCubeMap ) { - nverts = _countof(verticesCube); + nverts = static_cast(std::size(verticesCube)); InitData.pSysMem = verticesCube; } else if ( is1D ) { - nverts = _countof(vertices1D); + nverts = static_cast(std::size(vertices1D)); InitData.pSysMem = vertices1D; } else { - nverts = _countof(vertices); + nverts = static_cast(std::size(vertices)); InitData.pSysMem = vertices; } @@ -627,12 +627,12 @@ HRESULT InitDevice( const TexMetadata& mdata ) if ( isCubeMap ) { - g_iIndices = _countof(indicesCube); + g_iIndices = static_cast(std::size(indicesCube)); InitData.pSysMem = indicesCube; } else { - g_iIndices = _countof(indices); + g_iIndices = static_cast(std::size(indices)); InitData.pSysMem = indices; } diff --git a/DirectXTex/BC.h b/DirectXTex/BC.h index 7fb8969..f4c8e6e 100644 --- a/DirectXTex/BC.h +++ b/DirectXTex/BC.h @@ -11,7 +11,6 @@ #pragma once -#include #include #include diff --git a/DirectXTex/BC6HBC7.cpp b/DirectXTex/BC6HBC7.cpp index c26dba1..831aed8 100644 --- a/DirectXTex/BC6HBC7.cpp +++ b/DirectXTex/BC6HBC7.cpp @@ -1660,12 +1660,12 @@ void D3DX_BC6H::Decode(bool bSigned, HDRColorA* pOut) const noexcept if (ms_aModeToInfo[uMode] >= 0) { - assert(static_cast(ms_aModeToInfo[uMode]) < _countof(ms_aInfo)); - _Analysis_assume_(ms_aModeToInfo[uMode] < _countof(ms_aInfo)); + assert(static_cast(ms_aModeToInfo[uMode]) < std::size(ms_aInfo)); + _Analysis_assume_(ms_aModeToInfo[uMode] < std::size(ms_aInfo)); const ModeDescriptor* desc = ms_aDesc[ms_aModeToInfo[uMode]]; - assert(static_cast(ms_aModeToInfo[uMode]) < _countof(ms_aDesc)); - _Analysis_assume_(ms_aModeToInfo[uMode] < _countof(ms_aDesc)); + assert(static_cast(ms_aModeToInfo[uMode]) < std::size(ms_aDesc)); + _Analysis_assume_(ms_aModeToInfo[uMode] < std::size(ms_aDesc)); const ModeInfo& info = ms_aInfo[ms_aModeToInfo[uMode]]; INTEndPntPair aEndPts[BC6H_MAX_REGIONS] = {}; @@ -1811,7 +1811,7 @@ void D3DX_BC6H::Encode(bool bSigned, const HDRColorA* const pIn) noexcept EncodeParams EP(pIn, bSigned); - for (EP.uMode = 0; EP.uMode < ARRAYSIZE(ms_aInfo) && EP.fBestErr > 0; ++EP.uMode) + for (EP.uMode = 0; EP.uMode < std::size(ms_aInfo) && EP.fBestErr > 0; ++EP.uMode) { const uint8_t uShapes = ms_aInfo[EP.uMode].uPartitions ? 32u : 1u; // Number of rough cases to look at. reasonable values of this are 1, uShapes/4, and uShapes diff --git a/DirectXTex/DirectXTexConvert.cpp b/DirectXTex/DirectXTexConvert.cpp index b42e97b..b443cb8 100644 --- a/DirectXTex/DirectXTexConvert.cpp +++ b/DirectXTex/DirectXTexConvert.cpp @@ -2988,9 +2988,9 @@ uint32_t DirectX::_GetConvertFlags(DXGI_FORMAT format) noexcept { #ifdef _DEBUG // Ensure conversion table is in ascending order - assert(_countof(g_ConvertTable) > 0); + assert(std::size(g_ConvertTable) > 0); DXGI_FORMAT lastvalue = g_ConvertTable[0].format; - for (size_t index = 1; index < _countof(g_ConvertTable); ++index) + for (size_t index = 1; index < std::size(g_ConvertTable); ++index) { assert(g_ConvertTable[index].format > lastvalue); lastvalue = g_ConvertTable[index].format; @@ -2998,7 +2998,7 @@ uint32_t DirectX::_GetConvertFlags(DXGI_FORMAT format) noexcept #endif ConvertData key = { format, 0, 0 }; - auto in = reinterpret_cast(bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), + auto in = reinterpret_cast(bsearch_s(&key, g_ConvertTable, std::size(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); return (in) ? in->flags : 0; } @@ -3020,9 +3020,9 @@ void DirectX::_ConvertScanline( #ifdef _DEBUG // Ensure conversion table is in ascending order - assert(_countof(g_ConvertTable) > 0); + assert(std::size(g_ConvertTable) > 0); DXGI_FORMAT lastvalue = g_ConvertTable[0].format; - for (size_t index = 1; index < _countof(g_ConvertTable); ++index) + for (size_t index = 1; index < std::size(g_ConvertTable); ++index) { assert(g_ConvertTable[index].format > lastvalue); lastvalue = g_ConvertTable[index].format; @@ -3032,10 +3032,10 @@ void DirectX::_ConvertScanline( // Determine conversion details about source and dest formats ConvertData key = { inFormat, 0, 0 }; auto in = reinterpret_cast( - bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); + bsearch_s(&key, g_ConvertTable, std::size(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); key.format = outFormat; auto out = reinterpret_cast( - bsearch_s(&key, g_ConvertTable, _countof(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); + bsearch_s(&key, g_ConvertTable, std::size(g_ConvertTable), sizeof(ConvertData), ConvertCompare, nullptr)); if (!in || !out) { assert(false); diff --git a/DirectXTex/DirectXTexP.h b/DirectXTex/DirectXTexP.h index 06c9136..714d0e2 100644 --- a/DirectXTex/DirectXTexP.h +++ b/DirectXTex/DirectXTexP.h @@ -114,6 +114,7 @@ #include #include #include +#include #include #include diff --git a/DirectXTex/DirectXTexUtil.cpp b/DirectXTex/DirectXTexUtil.cpp index 6f4e549..2d6d369 100644 --- a/DirectXTex/DirectXTexUtil.cpp +++ b/DirectXTex/DirectXTexUtil.cpp @@ -123,7 +123,7 @@ namespace _Use_decl_annotations_ DXGI_FORMAT DirectX::_WICToDXGI(const GUID& guid) noexcept { - for (size_t i = 0; i < _countof(g_WICFormats); ++i) + for (size_t i = 0; i < std::size(g_WICFormats); ++i) { if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0) return g_WICFormats[i].format; @@ -186,7 +186,7 @@ bool DirectX::_DXGIToWIC(DXGI_FORMAT format, GUID& guid, bool ignoreRGBvsBGR) no #endif default: - for (size_t i = 0; i < _countof(g_WICFormats); ++i) + for (size_t i = 0; i < std::size(g_WICFormats); ++i) { if (g_WICFormats[i].format == format) { @@ -205,7 +205,7 @@ TEX_FILTER_FLAGS DirectX::_CheckWICColorSpace(_In_ const GUID& sourceGUID, _In_ { TEX_FILTER_FLAGS srgb = TEX_FILTER_DEFAULT; - for (size_t i = 0; i < _countof(g_WICFormats); ++i) + for (size_t i = 0; i < std::size(g_WICFormats); ++i) { if (memcmp(&g_WICFormats[i].wic, &sourceGUID, sizeof(GUID)) == 0) { diff --git a/DirectXTex/DirectXTexWIC.cpp b/DirectXTex/DirectXTexWIC.cpp index 1a51db5..06b3990 100644 --- a/DirectXTex/DirectXTexWIC.cpp +++ b/DirectXTex/DirectXTexWIC.cpp @@ -200,7 +200,7 @@ namespace } else { - for (size_t i = 0; i < _countof(g_WICConvert); ++i) + for (size_t i = 0; i < std::size(g_WICConvert); ++i) { if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) { diff --git a/DirectXTex/scoped.h b/DirectXTex/scoped.h index 9d8832d..5b5cfcf 100644 --- a/DirectXTex/scoped.h +++ b/DirectXTex/scoped.h @@ -9,8 +9,9 @@ #pragma once -#include +#include #include + #include //--------------------------------------------------------------------------------- diff --git a/Texassemble/AnimatedGif.cpp b/Texassemble/AnimatedGif.cpp index f3bb558..441071a 100644 --- a/Texassemble/AnimatedGif.cpp +++ b/Texassemble/AnimatedGif.cpp @@ -156,7 +156,7 @@ HRESULT LoadAnimatedGif(const wchar_t* szFile, std::vectorGetColors(_countof(rgbColors), rgbColors, &actualColors); + hr = palette->GetColors(static_cast(std::size(rgbColors)), rgbColors, &actualColors); if (FAILED(hr)) return hr; } diff --git a/Texassemble/texassemble.cpp b/Texassemble/texassemble.cpp index 9fd5819..db96c61 100644 --- a/Texassemble/texassemble.cpp +++ b/Texassemble/texassemble.cpp @@ -564,7 +564,7 @@ namespace wchar_t version[32] = {}; wchar_t appName[_MAX_PATH] = {}; - if (GetModuleFileNameW(nullptr, appName, _countof(appName))) + if (GetModuleFileNameW(nullptr, appName, static_cast(std::size(appName)))) { DWORD size = GetFileVersionInfoSizeW(appName, nullptr); if (size > 0) diff --git a/Texconv/texconv.cpp b/Texconv/texconv.cpp index 814588f..b82d202 100644 --- a/Texconv/texconv.cpp +++ b/Texconv/texconv.cpp @@ -701,7 +701,7 @@ namespace wchar_t version[32] = {}; wchar_t appName[_MAX_PATH] = {}; - if (GetModuleFileNameW(nullptr, appName, _countof(appName))) + if (GetModuleFileNameW(nullptr, appName, static_cast(std::size(appName)))) { DWORD size = GetFileVersionInfoSizeW(appName, nullptr); if (size > 0) @@ -919,7 +919,7 @@ namespace D3D_FEATURE_LEVEL fl; HRESULT hr = s_DynamicD3D11CreateDevice(pAdapter.Get(), (pAdapter) ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE, - nullptr, createDeviceFlags, featureLevels, _countof(featureLevels), + nullptr, createDeviceFlags, featureLevels, static_cast(std::size(featureLevels)), D3D11_SDK_VERSION, pDevice, &fl, nullptr); if (SUCCEEDED(hr)) { diff --git a/Texdiag/texdiag.cpp b/Texdiag/texdiag.cpp index 6242bdf..15328d1 100644 --- a/Texdiag/texdiag.cpp +++ b/Texdiag/texdiag.cpp @@ -525,7 +525,7 @@ namespace wchar_t version[32] = {}; wchar_t appName[_MAX_PATH] = {}; - if (GetModuleFileNameW(nullptr, appName, _countof(appName))) + if (GetModuleFileNameW(nullptr, appName, static_cast(std::size(appName)))) { DWORD size = GetFileVersionInfoSizeW(appName, nullptr); if (size > 0) diff --git a/WICTextureLoader/WICTextureLoader11.cpp b/WICTextureLoader/WICTextureLoader11.cpp index 5b686bd..3dbe281 100644 --- a/WICTextureLoader/WICTextureLoader11.cpp +++ b/WICTextureLoader/WICTextureLoader11.cpp @@ -230,7 +230,7 @@ namespace //--------------------------------------------------------------------------------- DXGI_FORMAT _WICToDXGI(const GUID& guid) noexcept { - for (size_t i = 0; i < _countof(g_WICFormats); ++i) + for (size_t i = 0; i < std::size(g_WICFormats); ++i) { if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0) return g_WICFormats[i].format; @@ -465,7 +465,7 @@ namespace } else { - for (size_t i = 0; i < _countof(g_WICConvert); ++i) + for (size_t i = 0; i < std::size(g_WICConvert); ++i) { if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) { diff --git a/WICTextureLoader/WICTextureLoader12.cpp b/WICTextureLoader/WICTextureLoader12.cpp index 83e49a3..3a072ff 100644 --- a/WICTextureLoader/WICTextureLoader12.cpp +++ b/WICTextureLoader/WICTextureLoader12.cpp @@ -247,7 +247,7 @@ namespace //--------------------------------------------------------------------------------- DXGI_FORMAT _WICToDXGI(const GUID& guid) noexcept { - for (size_t i = 0; i < _countof(g_WICFormats); ++i) + for (size_t i = 0; i < std::size(g_WICFormats); ++i) { if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0) return g_WICFormats[i].format; @@ -393,7 +393,7 @@ namespace DXGI_FORMAT format = _WICToDXGI(pixelFormat); if (format == DXGI_FORMAT_UNKNOWN) { - for (size_t i = 0; i < _countof(g_WICConvert); ++i) + for (size_t i = 0; i < std::size(g_WICConvert); ++i) { if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) { diff --git a/WICTextureLoader/WICTextureLoader9.cpp b/WICTextureLoader/WICTextureLoader9.cpp index a939da9..af812dc 100644 --- a/WICTextureLoader/WICTextureLoader9.cpp +++ b/WICTextureLoader/WICTextureLoader9.cpp @@ -214,7 +214,7 @@ namespace //--------------------------------------------------------------------------------- D3DFORMAT _WICToD3D9(const GUID& guid) noexcept { - for (size_t i = 0; i < _countof(g_WICFormats); ++i) + for (size_t i = 0; i < std::size(g_WICFormats); ++i) { if (memcmp(&g_WICFormats[i].wic, &guid, sizeof(GUID)) == 0) return g_WICFormats[i].format; @@ -331,7 +331,7 @@ namespace D3DFORMAT format = _WICToD3D9(pixelFormat); if (format == D3DFMT_UNKNOWN) { - for (size_t i = 0; i < _countof(g_WICConvert); ++i) + for (size_t i = 0; i < std::size(g_WICConvert); ++i) { if (memcmp(&g_WICConvert[i].source, &pixelFormat, sizeof(WICPixelFormatGUID)) == 0) {