diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-11-06 11:05:45 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2021-11-06 11:05:45 +0100 |
commit | dbd68011363b01f22ab85e11ad52a8e90da9611a (patch) | |
tree | 6d1bec44119ab3fa99ace9298f0ac3575fcdc15a /src/rebuild.cc | |
parent | 92cc25c10bcba1f14cbf28bd0298311b8e81a2ea (diff) |
Use std::source_location instead of __FILE__.
Diffstat (limited to 'src/rebuild.cc')
-rw-r--r-- | src/rebuild.cc | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/src/rebuild.cc b/src/rebuild.cc index a03f5e3..fc95b16 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -6,6 +6,7 @@ #include <iostream> #include <filesystem> #include <algorithm> +#include <source_location> #include "configure.h" #include "settings.h" @@ -16,9 +17,8 @@ std::array<BuildConfigurationEntry, 1024> configFiles; std::size_t numConfigFiles{0}; -// TODO: Use c++20 when ready, somehing like this: -//int reg(const std::source_location location = std::source_location::current()) -int reg(const char* location, std::vector<BuildConfiguration> (*cb)()) +int reg(std::vector<BuildConfiguration> (*cb)(), + const std::source_location location) { // NOTE: std::cout cannot be used here if(numConfigFiles >= configFiles.size()) @@ -28,13 +28,31 @@ int reg(const char* location, std::vector<BuildConfiguration> (*cb)()) exit(1); } - configFiles[numConfigFiles].file = location; + configFiles[numConfigFiles].file = location.file_name(); configFiles[numConfigFiles].cb = cb; ++numConfigFiles; return 0; } +int reg(const char* location) +{ + // NOTE: std::cout cannot be used here + if(numConfigFiles >= configFiles.size()) + { + fprintf(stderr, "Max %d build configurations currently supported.\n", + (int)configFiles.size()); + exit(1); + } + + configFiles[numConfigFiles].file = location; + configFiles[numConfigFiles].cb = + [](){ return std::vector<BuildConfiguration>{}; }; + ++numConfigFiles; + + return 0; +} + int unreg(const char* location) { std::size_t found{0}; @@ -78,9 +96,8 @@ int unreg(const char* location) std::array<ExternalConfigurationEntry, 1024> externalConfigFiles; std::size_t numExternalConfigFiles{0}; -// TODO: Use c++20 when ready, somehing like this: -//int reg(const std::source_location location = std::source_location::current()) -int reg(const char* location, std::vector<ExternalConfiguration> (*cb)()) +int reg(std::vector<ExternalConfiguration> (*cb)(), + const std::source_location location) { // NOTE: std::cout cannot be used here if(numExternalConfigFiles >= externalConfigFiles.size()) @@ -90,7 +107,7 @@ int reg(const char* location, std::vector<ExternalConfiguration> (*cb)()) exit(1); } - externalConfigFiles[numExternalConfigFiles].file = location; + externalConfigFiles[numExternalConfigFiles].file = location.file_name(); externalConfigFiles[numExternalConfigFiles].cb = cb; ++numExternalConfigFiles; |