add parallel hashmaps optional submodule

v1
Brett 2023-07-29 02:03:28 -04:00
parent 7b7d9df67b
commit 21425cff55
6 changed files with 223 additions and 3 deletions

View File

@ -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/)

View File

@ -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)

View File

@ -19,6 +19,7 @@
namespace blt::nbt {
#ifndef HASHMAP
#define HASHMAP HASHMAP
template<typename K, typename V>
using HASHMAP = std::unordered_map<K, V>;
#endif

View File

@ -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 <vector>
#include <string>
#include <initializer_list>
#include <optional>
#include <unordered_map>
namespace blt::parser {
#ifndef HASHMAP
#define HASHMAP HASHMAP
template<typename K, typename V>
using HASHMAP = std::unordered_map<K, V>();
#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<std::string> names;
std::vector<std::string> flags;
void insertAndSort(const std::string& str);
public:
arg_vector() = default;
arg_vector(std::vector<std::string> args);
arg_vector(std::initializer_list<std::string> 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<std::string>& args);
arg_vector& operator=(std::vector<std::string>& args);
[[nodiscard]] inline std::vector<std::string>& getNames(){
return names;
}
[[nodiscard]] inline std::vector<std::string>& 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<std::string> 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

@ -0,0 +1 @@
Subproject commit 77cab8192a879e5d27188f97e8f2080dd7e36ca8

View File

@ -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 <blt/parse/argparse.h>
namespace blt::parser {
arg_vector::arg_vector(std::vector<std::string> args) {
for (auto& arg : args)
insertAndSort(arg);
}
arg_vector::arg_vector(std::initializer_list<std::string> 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<std::string>& args) {
for (auto& arg : args)
insertAndSort(arg);
return *this;
}
arg_vector& arg_vector::operator=(std::vector<std::string>& 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;
}
}