Compare commits
4 Commits
0febd6e8aa
...
620a16574d
Author | SHA1 | Date |
---|---|---|
Brett | 620a16574d | |
Brett | 147c46a1a4 | |
Brett | 79900dbf1a | |
Brett | 94e10e7674 |
|
@ -1,4 +1,4 @@
|
||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.5)
|
||||||
project(BLT VERSION 0.8.0)
|
project(BLT VERSION 0.8.0)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
@ -45,8 +45,9 @@ else()
|
||||||
set(PARSE_FILES "")
|
set(PARSE_FILES "")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(EXISTS libraries/parallel-hashmap)
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap)
|
||||||
include_directories(libraries/parallel-hashmap)
|
message("Found Parallel Hashmaps")
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
#include zlib if the user has it.
|
#include zlib if the user has it.
|
||||||
|
@ -73,9 +74,9 @@ target_include_directories(BLT PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/config/)
|
||||||
if(${ZLIB_FOUND})
|
if(${ZLIB_FOUND})
|
||||||
target_link_libraries(BLT PUBLIC ZLIB::ZLIB)
|
target_link_libraries(BLT PUBLIC ZLIB::ZLIB)
|
||||||
endif()
|
endif()
|
||||||
if(EXISTS ${CMAKE_SOURCE_DIR}/libraries/parallel-hashmap)
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap)
|
||||||
message("Including phmap")
|
message("Including phmap")
|
||||||
target_include_directories(BLT PUBLIC libraries/parallel-hashmap)
|
target_include_directories(BLT PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/libraries/parallel-hashmap)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
|
|
|
@ -17,27 +17,7 @@
|
||||||
#include "blt/std/filesystem.h"
|
#include "blt/std/filesystem.h"
|
||||||
#include "blt/std/logging.h"
|
#include "blt/std/logging.h"
|
||||||
|
|
||||||
#ifndef HASHMAP
|
#include <blt/std/hashmap.h>
|
||||||
#if defined __has_include && __has_include(<parallel_hashmap/phmap.h>)
|
|
||||||
#define HASHMAP HASHMAP
|
|
||||||
#include <parallel_hashmap/phmap.h>
|
|
||||||
#include <parallel_hashmap/phmap_fwd_decl.h>
|
|
||||||
template<typename K, typename V>
|
|
||||||
using HASHMAP = phmap::flat_hash_map<K, V>();
|
|
||||||
template<typename K>
|
|
||||||
using HASHSET = phmap::flat_hash_set<K>();
|
|
||||||
#else
|
|
||||||
#define HASHMAP HASHMAP
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
template<typename K, typename V>
|
|
||||||
using HASHMAP = std::unordered_map<K, V>();
|
|
||||||
|
|
||||||
template<typename K>
|
|
||||||
using HASHSET = std::unordered_set<K>();
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace blt::nbt {
|
namespace blt::nbt {
|
||||||
|
|
||||||
|
|
|
@ -11,30 +11,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <blt/std/hashmap.h>
|
||||||
#ifndef HASHMAP
|
|
||||||
#if defined __has_include && __has_include(<parallel_hashmap/phmap.h>)
|
|
||||||
#define HASHMAP HASHMAP
|
|
||||||
|
|
||||||
#include <parallel_hashmap/phmap.h>
|
|
||||||
#include <parallel_hashmap/phmap_fwd_decl.h>
|
|
||||||
|
|
||||||
template<typename K, typename V>
|
|
||||||
using HASHMAP = phmap::flat_hash_map<K, V>();
|
|
||||||
template<typename K>
|
|
||||||
using HASHSET = phmap::flat_hash_set<K>();
|
|
||||||
#else
|
|
||||||
#define HASHMAP HASHMAP
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
template<typename K, typename V>
|
|
||||||
using HASHMAP = std::unordered_map<K, V>();
|
|
||||||
|
|
||||||
template<typename K>
|
|
||||||
using HASHSET = std::unordered_set<K>();
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace blt::parser {
|
namespace blt::parser {
|
||||||
|
|
||||||
|
@ -135,13 +112,13 @@ namespace blt::parser {
|
||||||
private:
|
private:
|
||||||
public:
|
public:
|
||||||
arg_vector a_flags;
|
arg_vector a_flags;
|
||||||
arg_action a_action;
|
arg_action a_action = arg_action::STORE;
|
||||||
arg_nargs a_nargs;
|
arg_nargs a_nargs = 0;
|
||||||
std::optional<std::string> a_const;
|
std::optional<std::string> a_const{};
|
||||||
std::string a_default;
|
std::string a_default{};
|
||||||
std::string a_def;
|
std::string a_def{};
|
||||||
std::string a_help;
|
std::string a_help{};
|
||||||
std::string a_metavar;
|
std::string a_metavar{};
|
||||||
bool a_required = false;
|
bool a_required = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -166,7 +143,7 @@ namespace blt::parser {
|
||||||
public:
|
public:
|
||||||
arg_tokenizer() = default;
|
arg_tokenizer() = default;
|
||||||
|
|
||||||
arg_tokenizer(const char** argv, size_t argc);
|
arg_tokenizer(size_t argc, const char** argv);
|
||||||
|
|
||||||
inline void forward() {
|
inline void forward() {
|
||||||
nextIndex++;
|
nextIndex++;
|
||||||
|
@ -189,23 +166,28 @@ namespace blt::parser {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct arg_results {
|
|
||||||
private:
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class argparse {
|
class argparse {
|
||||||
private:
|
private:
|
||||||
arg_tokenizer tokenizer;
|
arg_tokenizer tokenizer;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
std::vector<arg_properties> argStorage;
|
||||||
|
HASHMAP<std::string, arg_properties*> flagAssociations;
|
||||||
|
HASHMAP<std::string, arg_properties*> nameAssociations;
|
||||||
|
} user_args;
|
||||||
|
|
||||||
|
struct arg_results {
|
||||||
|
std::string programName;
|
||||||
|
HASHMAP<std::string, std::string> positionalArgs;
|
||||||
|
|
||||||
|
} loaded_args;
|
||||||
|
|
||||||
static bool validateArgument(const arg_properties& args);
|
static bool validateArgument(const arg_properties& args);
|
||||||
public:
|
public:
|
||||||
argparse() = default;
|
argparse() = default;
|
||||||
|
|
||||||
void addArgument(const arg_properties& args);
|
void addArgument(const arg_properties& args);
|
||||||
|
const arg_results& parse_args(int argc, const char** argv);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
/*
|
|
||||||
* Created by Brett on 31/03/23.
|
|
||||||
* Licensed under GNU General Public License V3.0
|
|
||||||
* See LICENSE file for license detail
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef BLT_HASH_MAP_H
|
|
||||||
#define BLT_HASH_MAP_H
|
|
||||||
|
|
||||||
|
|
||||||
#endif //BLT_HASH_MAP_H
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
* Created by Brett on 31/03/23.
|
||||||
|
* Licensed under GNU General Public License V3.0
|
||||||
|
* See LICENSE file for license detail
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BLT_HASH_MAP_H
|
||||||
|
#define BLT_HASH_MAP_H
|
||||||
|
|
||||||
|
#ifndef HASHMAP
|
||||||
|
#if defined __has_include && __has_include(<parallel_hashmap/phmap.h>)
|
||||||
|
|
||||||
|
#include <parallel_hashmap/phmap.h>
|
||||||
|
#include <parallel_hashmap/phmap_fwd_decl.h>
|
||||||
|
|
||||||
|
template<class K, class V,
|
||||||
|
class Hash = phmap::priv::hash_default_hash<K>,
|
||||||
|
class Eq = phmap::priv::hash_default_eq<K>,
|
||||||
|
class Alloc = phmap::priv::Allocator<phmap::priv::Pair<const K, V>>>
|
||||||
|
using HASHMAP = phmap::flat_hash_map<K, V, Hash, Eq, Alloc>;
|
||||||
|
template<class T,
|
||||||
|
class Hash = phmap::priv::hash_default_hash<T>,
|
||||||
|
class Eq = phmap::priv::hash_default_eq<T>,
|
||||||
|
class Alloc = phmap::priv::Allocator<T>>
|
||||||
|
using HASHSET = phmap::flat_hash_set<T, Hash, Eq, Alloc>;
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
|
template<typename K, typename V,
|
||||||
|
typename Hash = std::hash<K>,
|
||||||
|
typename Eq = std::equal_to<K>,
|
||||||
|
typename Alloc = std::allocator<std::pair<const K, V>>>
|
||||||
|
using HASHMAP = std::unordered_map<K, V, Hash, Eq, Alloc>;
|
||||||
|
|
||||||
|
template<typename K,
|
||||||
|
typename Hash = std::hash<K>,
|
||||||
|
typename Eq = std::equal_to<K>,
|
||||||
|
typename Alloc = std::allocator<K>>
|
||||||
|
using HASHSET = std::unordered_set<K, Hash, Eq, Alloc>;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif //BLT_HASH_MAP_H
|
|
@ -1 +1 @@
|
||||||
Subproject commit 77cab8192a879e5d27188f97e8f2080dd7e36ca8
|
Subproject commit 93201da2ba5a6aba0a6e57ada64973555629b3e3
|
|
@ -96,7 +96,7 @@ namespace blt::parser {
|
||||||
flags |= ALL;
|
flags |= ALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
arg_tokenizer::arg_tokenizer(const char** argv, size_t argc) {
|
arg_tokenizer::arg_tokenizer(size_t argc, const char** argv) {
|
||||||
for (size_t i = 0; i < argc; i++)
|
for (size_t i = 0; i < argc; i++)
|
||||||
args.emplace_back(argv[i]);
|
args.emplace_back(argv[i]);
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,27 @@ namespace blt::parser {
|
||||||
BLT_WARN("(Discarding argument)");
|
BLT_WARN("(Discarding argument)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// store one copy of the properties (arg properties could in theory be very large!)
|
||||||
|
auto pos = user_args.argStorage.size();
|
||||||
|
user_args.argStorage.push_back(args);
|
||||||
|
auto& arg = user_args.argStorage[pos];
|
||||||
|
// associate the arg properties per name and flag to allow for quick access when parsing
|
||||||
|
auto& names = args.a_flags.getNames();
|
||||||
|
for (const auto& name : names)
|
||||||
|
user_args.nameAssociations[name] = &arg;
|
||||||
|
|
||||||
|
auto& flags = args.a_flags.getFlags();
|
||||||
|
for (const auto& flag : flags)
|
||||||
|
user_args.flagAssociations[flag] = &arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
const argparse::arg_results& argparse::parse_args(int argc, const char** argv) {
|
||||||
|
loaded_args = {};
|
||||||
|
arg_tokenizer asToken(argc, argv);
|
||||||
|
loaded_args.programName = asToken.next();
|
||||||
|
BLT_TRACE("Loading args for %s", loaded_args.programName.c_str());
|
||||||
|
|
||||||
|
return loaded_args;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#ifndef BLT_TESTS_HASHMAP_TEXTS_H
|
#ifndef BLT_TESTS_HASHMAP_TEXTS_H
|
||||||
#define BLT_TESTS_HASHMAP_TEXTS_H
|
#define BLT_TESTS_HASHMAP_TEXTS_H
|
||||||
|
|
||||||
#include <blt/std/hash_map.h>
|
#include <blt/std/hashmap.h>
|
||||||
|
|
||||||
inline static int test_hashmaps(){
|
inline static int test_hashmaps(){
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "binary_trees.h"
|
//#include "binary_trees.h"
|
||||||
#include "logging.h"
|
//#include "logging.h"
|
||||||
#include "profiling_tests.h"
|
#include "profiling_tests.h"
|
||||||
#include "nbt_tests.h"
|
#include "nbt_tests.h"
|
||||||
#include "queue_tests.h"
|
#include "blt/parse/argparse.h"
|
||||||
#include "blt/math/vectors.h"
|
//#include "queue_tests.h"
|
||||||
#include "blt/math/matrix.h"
|
//#include "blt/math/vectors.h"
|
||||||
#include <bitset>
|
//#include "blt/math/matrix.h"
|
||||||
#include "hashmap_tests.h"
|
//#include <bitset>
|
||||||
#include <functional>
|
//#include "hashmap_tests.h"
|
||||||
|
//#include <functional>
|
||||||
|
|
||||||
std::function<int(int i)> test{
|
std::function<int(int i)> test{
|
||||||
[](int i) -> int {
|
[](int i) -> int {
|
||||||
|
@ -66,7 +67,10 @@ int (*func_func)(int) = [](int i) -> int {
|
||||||
|
|
||||||
int (*func_func_in)(int) = &test_as_func;
|
int (*func_func_in)(int) = &test_as_func;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, const char** argv) {
|
||||||
|
blt::parser::argparse parser;
|
||||||
|
parser.addArgument({{"--foo", "-f"}});
|
||||||
|
auto args = parser.parse_args(argc, argv);
|
||||||
//
|
//
|
||||||
// if (argc > 1 && std::string(argv[1]) == "--no_color") {
|
// if (argc > 1 && std::string(argv[1]) == "--no_color") {
|
||||||
// for (int i = (int)blt::logging::log_level::NONE; i < (int)blt::logging::log_level::FATAL; i++) {
|
// for (int i = (int)blt::logging::log_level::NONE; i < (int)blt::logging::log_level::FATAL; i++) {
|
||||||
|
|
Loading…
Reference in New Issue