From 51cd6dbddffa15d94e14014cf01ac53cd5082308 Mon Sep 17 00:00:00 2001 From: Shuoliu Yang Date: Wed, 14 Aug 2024 21:52:40 +0800 Subject: [PATCH] remove ranges --- include/Layer/Config.hpp | 3 +-- src/Layer/Config.cpp | 35 +++++++++++++---------------------- src/Layer/StructModel.cpp | 9 ++++----- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/include/Layer/Config.hpp b/include/Layer/Config.hpp index 32493442..3983f5d2 100644 --- a/include/Layer/Config.hpp +++ b/include/Layer/Config.hpp @@ -36,7 +36,6 @@ FILE* getLogStream(const char* category); #include #define STD_FORMAT_SUPPORT #define STD_FORMAT(...) std::format(__VA_ARGS__) -#define STD_RANGES_SUPPORT #else #define STD_FORMAT(...) ((void)sizeof(__VA_ARGS__), std::string("")) #endif @@ -51,7 +50,7 @@ FILE* getLogStream(const char* category); auto UNI_NAME(s) = std::format(__VA_ARGS__); \ if (!UNI_NAME(s).empty()) \ { \ - fprintf(UNI_NAME(f), "[" STRINGIFY(label) "]:%s\n", UNI_NAME(s).c_str()); \ + fprintf(UNI_NAME(f), "[" STRINGIFY(label) "]:%s\n", UNI_NAME(s).c_str()); \ } \ } while (0); #else diff --git a/src/Layer/Config.cpp b/src/Layer/Config.cpp index 1edebdb3..12f48089 100644 --- a/src/Layer/Config.cpp +++ b/src/Layer/Config.cpp @@ -20,9 +20,6 @@ #include #include #include -#ifdef STD_RANGES_SUPPORT -#include -#endif #include #include #include @@ -42,32 +39,31 @@ std::vector> parse(const char* var * other categories streamed to file with name .log * stream can be 'stderr', 'stdout', 'null' or a file name */ - std::vector> result; -#ifdef STD_RANGES_SUPPORT - result.reserve(4); - std::string_view inputSV(var); - auto categoryStreamPairs = inputSV | std::views::split(';'); - for (auto&& pair : categoryStreamPairs) + std::vector> result; + std::string input(var); + size_t pos = 0; + while (pos < input.size()) { - std::vector categoryStream; - for (auto&& part : pair | std::views::split(':')) + size_t nextPos = input.find(';', pos); + if (nextPos == std::string::npos) { - categoryStream.emplace_back(&*part.begin(), std::ranges::distance(part)); + nextPos = input.size(); } - if (categoryStream.size() == 2) + std::string_view categoryStream(input.c_str() + pos, nextPos - pos); + size_t colonPos = categoryStream.find(':'); + if (colonPos != std::string::npos) { - result.emplace_back(categoryStream[0], categoryStream[1]); + result.emplace_back(categoryStream.substr(0, colonPos), categoryStream.substr(colonPos + 1)); } + pos = nextPos + 1; } -#endif return result; } struct ConfigVars { - std::once_flag flag; - + std::once_flag flag; std::vector> logConfigs; bool enableLog{ false }; ConfigVars() @@ -119,9 +115,6 @@ namespace VGG::layer FILE* getLogStream(const char* category) { -#ifndef STD_RANGES_SUPPORT - return nullptr; -#else if (!g_configVars.enableLog) { return nullptr; @@ -130,7 +123,6 @@ FILE* getLogStream(const char* category) { return stderr; } - namespace sv = std::views; auto it = g_categoryMap.find(category); if (it == g_categoryMap.end()) { @@ -183,7 +175,6 @@ FILE* getLogStream(const char* category) return it->second.get(); } return stderr; -#endif } } // namespace VGG::layer diff --git a/src/Layer/StructModel.cpp b/src/Layer/StructModel.cpp index 7116a0d0..5dd1565a 100644 --- a/src/Layer/StructModel.cpp +++ b/src/Layer/StructModel.cpp @@ -244,15 +244,14 @@ std::vector StructObject::getChildObjects() const objects.reserve(m->childObjects().size()); if (m->isFirstOnTop()) { - //for (const auto& c : *m | std::views::reverse) TODO rewrite this logic without std::views - for (const auto& c : *m) // TODO delete this temp line + for (auto it = m->childObjects().rbegin(); it != m->childObjects().rend(); ++it) { toType( - c.get(), + it->get(), [&](EModelObjectType objectType) - { objects.emplace_back(dispatchObject(objectType, c.get())); }, + { objects.emplace_back(dispatchObject(objectType, it->get())); }, [&](EModelShapeType shapeType) - { objects.emplace_back(dispatchObject(shapeType, c.get())); }); + { objects.emplace_back(dispatchObject(shapeType, it->get())); }); } } else