From 430ad3b0afe3f098616124e21f8b197ea62ff9ed Mon Sep 17 00:00:00 2001 From: stripe2933 Date: Sun, 3 Sep 2023 10:48:18 +0900 Subject: [PATCH] =?UTF-8?q?Move=20Subdivide=20method=20implementations=20o?= =?UTF-8?q?f=20CopyElements,=20FillElements,=20FillIds=20and=20CopyIndices?= =?UTF-8?q?=20to=20below=20the=20declarations=20for=20C++=20=E2=89=A5=2020?= =?UTF-8?q?=20compatibility.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/rapidobj/rapidobj.hpp | 115 +++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 52 deletions(-) diff --git a/include/rapidobj/rapidobj.hpp b/include/rapidobj/rapidobj.hpp index 4c02b07..bd29a18 100755 --- a/include/rapidobj/rapidobj.hpp +++ b/include/rapidobj/rapidobj.hpp @@ -4590,10 +4590,6 @@ using FillFloats = FillElements; using FillMaterialIds = FillIds; using FillSmoothingGroupIds = FillIds; -using MergeTask = - std::variant; -using MergeTasks = std::vector; - template struct CopyElements final { CopyElements(T* dst, const T* src, size_t size) noexcept : m_dst(dst), m_src(src), m_size(size) {} @@ -4610,18 +4606,7 @@ struct CopyElements final { return rapidobj_errc::Success; } - auto Subdivide(size_t num) const noexcept - { - auto begin = size_t{ 0 }; - auto tasks = MergeTasks(); - tasks.reserve(num); - for (size_t i = 0; i != num; ++i) { - auto end = (1 + i) * m_size / num; - tasks.push_back(CopyElements(m_dst + begin, m_src + begin, end - begin)); - begin = end; - } - return tasks; - } + inline auto Subdivide(size_t num) const noexcept; private: T* m_dst{}; @@ -4645,18 +4630,7 @@ struct FillElements final { return rapidobj_errc::Success; } - auto Subdivide(size_t num) const noexcept - { - auto begin = size_t{ 0 }; - auto tasks = MergeTasks(); - tasks.reserve(num); - for (size_t i = 0; i != num; ++i) { - auto end = (1 + i) * m_size / num; - tasks.push_back(FillElements(m_dst + begin, m_value, end - begin)); - begin = end; - } - return tasks; - } + inline auto Subdivide(size_t num) const noexcept; private: T* m_dst{}; @@ -4701,18 +4675,7 @@ struct FillIds final { return rapidobj_errc::Success; } - auto Subdivide(size_t num) const noexcept - { - auto begin = size_t{ 0 }; - auto tasks = MergeTasks(); - tasks.reserve(num); - for (size_t i = 0; i != num; ++i) { - auto end = (1 + i) * m_size / num; - tasks.push_back(FillIds(m_dst + begin, *m_src, end - begin, m_start + begin)); - begin = end; - } - return tasks; - } + inline auto Subdivide(size_t num) const noexcept; private: T* m_dst{}; @@ -4777,18 +4740,7 @@ struct CopyIndices final { return rapidobj_errc::Success; } - auto Subdivide(size_t num) const noexcept - { - auto begin = size_t{ 0 }; - auto tasks = MergeTasks(); - tasks.reserve(num); - for (size_t i = 0; i != num; ++i) { - auto end = (1 + i) * m_size / num; - tasks.push_back(CopyIndices(m_dst + begin, m_src + begin, m_offset_flags, end - begin, m_offset, m_count)); - begin = end; - } - return tasks; - } + inline auto Subdivide(size_t num) const noexcept; private: Index* m_dst{}; @@ -4799,6 +4751,65 @@ struct CopyIndices final { AttributeInfo m_count{}; }; +using MergeTask = + std::variant; +using MergeTasks = std::vector; + +template +auto CopyElements::Subdivide(size_t num) const noexcept +{ + auto begin = size_t{ 0 }; + auto tasks = MergeTasks(); + tasks.reserve(num); + for (size_t i = 0; i != num; ++i) { + auto end = (1 + i) * m_size / num; + tasks.push_back(CopyElements(m_dst + begin, m_src + begin, end - begin)); + begin = end; + } + return tasks; +} + +template +auto FillElements::Subdivide(size_t num) const noexcept +{ + auto begin = size_t{ 0 }; + auto tasks = MergeTasks(); + tasks.reserve(num); + for (size_t i = 0; i != num; ++i) { + auto end = (1 + i) * m_size / num; + tasks.push_back(FillElements(m_dst + begin, m_value, end - begin)); + begin = end; + } + return tasks; +} + +template +auto FillIds::Subdivide(size_t num) const noexcept +{ + auto begin = size_t{ 0 }; + auto tasks = MergeTasks(); + tasks.reserve(num); + for (size_t i = 0; i != num; ++i) { + auto end = (1 + i) * m_size / num; + tasks.push_back(FillIds(m_dst + begin, *m_src, end - begin, m_start + begin)); + begin = end; + } + return tasks; +} + +auto CopyIndices::Subdivide(size_t num) const noexcept +{ + auto begin = size_t{ 0 }; + auto tasks = MergeTasks(); + tasks.reserve(num); + for (size_t i = 0; i != num; ++i) { + auto end = (1 + i) * m_size / num; + tasks.push_back(CopyIndices(m_dst + begin, m_src + begin, m_offset_flags, end - begin, m_offset, m_count)); + begin = end; + } + return tasks; +} + struct Reader { struct ReadResult final { std::size_t bytes_read;