Skip to content

Commit

Permalink
remove ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
yslib committed Aug 14, 2024
1 parent 6986ecb commit 51cd6db
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
3 changes: 1 addition & 2 deletions include/Layer/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ FILE* getLogStream(const char* category);
#include <format>
#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
Expand All @@ -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
Expand Down
35 changes: 13 additions & 22 deletions src/Layer/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#include <string>
#include <stdlib.h>
#include <cstring>
#ifdef STD_RANGES_SUPPORT
#include <ranges>
#endif
#include <unordered_map>
#include <iostream>
#include <algorithm>
Expand All @@ -42,32 +39,31 @@ std::vector<std::pair<std::string_view, std::string_view>> parse(const char* var
* other categories streamed to file with name <stream>.log
* stream can be 'stderr', 'stdout', 'null' or a file name
*/
std::vector<std::pair<std::string_view, std::string_view>> 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<std::pair<std::string_view, std::string_view>> result;
std::string input(var);
size_t pos = 0;
while (pos < input.size())
{
std::vector<std::string_view> 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<std::pair<std::string_view, std::string_view>> logConfigs;
bool enableLog{ false };
ConfigVars()
Expand Down Expand Up @@ -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;
Expand All @@ -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())
{
Expand Down Expand Up @@ -183,7 +175,6 @@ FILE* getLogStream(const char* category)
return it->second.get();
}
return stderr;
#endif
}

} // namespace VGG::layer
9 changes: 4 additions & 5 deletions src/Layer/StructModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,14 @@ std::vector<StructObject> 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
Expand Down

0 comments on commit 51cd6db

Please sign in to comment.