diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bec728..eb69df3 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.0) -project(BLT VERSION 0.7.0) +project(BLT VERSION 0.8.0) set(CMAKE_CXX_STANDARD 20) @@ -9,6 +9,7 @@ option(ENABLE_TSAN "Enable the thread data race sanitizer" OFF) option(BUILD_STD "Build the BLT standard utilities." ON) option(BUILD_PROFILING "Build the BLT profiler extension" ON) option(BUILD_NBT "Build the BLT NBT + eNBT extension" ON) +option(BUILD_PARSE "Build the BLT parsers" ON) option(BUILD_TESTS "Build the BLT test set" OFF) option(BLT_DISABLE_LOGGING "Disable blt::logging (all macros and will safely disable logging function!)" OFF) option(BLT_DISABLE_TRACE "Disable blt::logging BLT_TRACE macro" OFF) @@ -38,6 +39,12 @@ else() set(NBT_FILES "") endif() +if(${BUILD_PARSE}) + file(GLOB_RECURSE PARSE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/blt/parse/*.cpp") +else() + set(PARSE_FILES "") +endif() + #include zlib if the user has it. find_package(ZLIB QUIET) @@ -55,7 +62,7 @@ message("Profiler Files ${PROFILING_FILES}") message("Source: ${CMAKE_SOURCE_DIR}") message("Current Source: ${CMAKE_CURRENT_SOURCE_DIR}") -add_library(BLT ${STD_FILES} ${PROFILING_FILES} ${NBT_FILES}) +add_library(BLT ${STD_FILES} ${PROFILING_FILES} ${NBT_FILES} ${PARSE_FILES}) target_include_directories(BLT PUBLIC include/) target_include_directories(BLT PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/config/) diff --git a/README.md b/README.md index 874ab2a..7428d83 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# **BLT v0.6.1a** +# **BLT v0.8.0a** A C++20 common utilities library to make thing easy! ![Icon](icon_large.png) diff --git a/include/blt/nbt/nbt.h b/include/blt/nbt/nbt.h index 7448432..5c8a4d5 100755 --- a/include/blt/nbt/nbt.h +++ b/include/blt/nbt/nbt.h @@ -19,6 +19,7 @@ namespace blt::nbt { #ifndef HASHMAP + #define HASHMAP HASHMAP template using HASHMAP = std::unordered_map; #endif diff --git a/include/blt/parse/argparse.h b/include/blt/parse/argparse.h new file mode 100644 index 0000000..8669099 --- /dev/null +++ b/include/blt/parse/argparse.h @@ -0,0 +1,114 @@ +/* + * Created by Brett on 28/07/23. + * Licensed under GNU General Public License V3.0 + * See LICENSE file for license detail + */ + +#ifndef BLT_TESTS_ARGPARSE_H +#define BLT_TESTS_ARGPARSE_H + +#include +#include +#include +#include +#include + +namespace blt::parser { + +#ifndef HASHMAP + #define HASHMAP HASHMAP + template + using HASHMAP = std::unordered_map(); +#endif + + enum class arg_action { + STORE, + STORE_CONST, + STORE_TRUE, + STORE_FALSE, + APPEND, + APPEND_CONST, + COUNT, + HELP, + VERSION, + EXTEND + }; + + class arg_t { + private: + + public: + + }; + + class arg_vector { + private: + std::vector names; + std::vector flags; + + void insertAndSort(const std::string& str); + public: + arg_vector() = default; + arg_vector(std::vector args); + arg_vector(std::initializer_list args); + arg_vector(const std::string& arg); + arg_vector(const char* arg); + + arg_vector& operator=(const std::string& arg); + arg_vector& operator=(const char* arg); + arg_vector& operator=(std::initializer_list& args); + arg_vector& operator=(std::vector& args); + + [[nodiscard]] inline std::vector& getNames(){ + return names; + } + [[nodiscard]] inline std::vector& getFlags(){ + return flags; + } + }; + + class arg_nargs { + private: + static constexpr int UNKNOWN = 0x1; + static constexpr int ALL = 0x2; + static constexpr int ALL_REQUIRED = 0x4; + int args = 0; + int flags = 0; + void decode(char c); + public: + arg_nargs() = default; + arg_nargs(int args): args(args) {} + arg_nargs(char c); + arg_nargs(std::string s); + arg_nargs(const char* s); + arg_nargs& operator=(const std::string& s); + arg_nargs& operator=(const char* s); + arg_nargs& operator=(char c); + arg_nargs& operator=(int args); + }; + + struct args_properties { + private: + public: + arg_vector a_flags; + arg_action a_action; + arg_nargs a_nargs; + std::optional a_const; + std::string a_default; + std::string a_def; + std::string a_help; + std::string a_metavar; + bool a_required = false; + }; + + class argparse { + private: + + public: + argparse() = default; + + }; + +} + +#endif //BLT_TESTS_ARGPARSE_H diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap new file mode 160000 index 0000000..77cab81 --- /dev/null +++ b/libraries/parallel-hashmap @@ -0,0 +1 @@ +Subproject commit 77cab8192a879e5d27188f97e8f2080dd7e36ca8 diff --git a/src/blt/parse/argparse.cpp b/src/blt/parse/argparse.cpp new file mode 100644 index 0000000..b535e6d --- /dev/null +++ b/src/blt/parse/argparse.cpp @@ -0,0 +1,97 @@ +/* + * Created by Brett on 28/07/23. + * Licensed under GNU General Public License V3.0 + * See LICENSE file for license detail + */ +#include + +namespace blt::parser { + + arg_vector::arg_vector(std::vector args) { + for (auto& arg : args) + insertAndSort(arg); + } + + arg_vector::arg_vector(std::initializer_list args) { + for (auto& arg : args) + insertAndSort(arg); + } + + arg_vector::arg_vector(const std::string& arg) { + insertAndSort(arg); + } + + arg_vector::arg_vector(const char* arg) { + insertAndSort(arg); + } + + arg_vector& arg_vector::operator=(const std::string& arg) { + insertAndSort(arg); + return *this; + } + + arg_vector& arg_vector::operator=(const char* arg) { + insertAndSort(arg); + return *this; + } + + arg_vector& arg_vector::operator=(std::initializer_list& args) { + for (auto& arg : args) + insertAndSort(arg); + return *this; + } + + arg_vector& arg_vector::operator=(std::vector& args) { + for (auto& arg : args) + insertAndSort(arg); + return *this; + } + + void arg_vector::insertAndSort(const std::string& str) { + if (str.starts_with('-')) + flags.push_back(str); + else + names.push_back(str); + } + + arg_nargs::arg_nargs(char c) { + decode(c); + } + + arg_nargs::arg_nargs(std::string s) { + decode(s[0]); + } + + arg_nargs::arg_nargs(const char* s) { + decode(*s); + } + + arg_nargs& arg_nargs::operator=(const std::string& s) { + decode(s[0]); + return *this; + } + + arg_nargs& arg_nargs::operator=(char c) { + decode(c); + return *this; + } + + arg_nargs& arg_nargs::operator=(int a) { + args = a; + return *this; + } + + arg_nargs& arg_nargs::operator=(const char* s) { + decode(*s); + return *this; + } + + void arg_nargs::decode(char c) { + if (c == '?') + flags |= UNKNOWN; + if (c == '+') + flags |= ALL_REQUIRED; + if (c == '*') + flags |= ALL; + } +} \ No newline at end of file