diff --git a/.gitignore b/.gitignore index 4735be3..93e3b49 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ CMakeCache.txt docs/* !docs/CMake* !docs/Doxyfile.in -!.clangd \ No newline at end of file +!.clangd +.glsld \ No newline at end of file diff --git a/engine/NBCore/CMakeLists.txt b/engine/NBCore/CMakeLists.txt index 8940f90..c73ff1e 100644 --- a/engine/NBCore/CMakeLists.txt +++ b/engine/NBCore/CMakeLists.txt @@ -13,10 +13,10 @@ toAbsolutePath(NB_CORE_SOURCE ./src/Logger.cpp ./src/Processes.cpp ./src/StringUtils.cpp + ./src/TypeTraits.cpp ./src/Utils.cpp ) toAbsolutePath(NB_CORE_INCLUDE - ./include/NBCore/ANSITerm.hpp ./include/NBCore/DataSink.hpp ./include/NBCore/Errors.hpp ./include/NBCore/ErrorsImpl.hpp diff --git a/engine/NBCore/include/NBCore/ANSITerm.hpp b/engine/NBCore/include/NBCore/ANSITerm.hpp deleted file mode 100644 index b729bac..0000000 --- a/engine/NBCore/include/NBCore/ANSITerm.hpp +++ /dev/null @@ -1,214 +0,0 @@ -#pragma once -#ifndef _NB_ANSI_TERM -#define _NB_ANSI_TERM - -#include -#include -#include - -/* ------------ TECH DEBT ------------ -Idk wtf to do here. This was originally to allow me to print -to terminal easily, but it's becoming too much of an investment. -For the time being, drop it. - -*/ - -namespace nb { - -template -struct SmartText { - using Type = ST; - using ValType = U; - static constexpr bool HasChild = Type::HasChild; - - SmartText() = default; -}; - -template -struct StyleFormatter : SmartText, U> { - using Base = SmartText, U>; - using typename Base::ValType; - static constexpr bool HasChild = true; - - StyleFormatter(const std::string& _fmt, const ValType& _val, const std::string& _closing) : - fmt{_fmt}, val{_val}, closing{_closing} {} - - std::string fmt; - ValType val; - std::string closing; -}; - -template -struct StyleFormatter : SmartText, void>{ - using Base = SmartText, void>; - using Base::ValType; - static constexpr bool HasChild = false; - - StyleFormatter(const std::string& _fmt) : fmt{_fmt} {} - - std::string fmt; -}; - -template -struct ANSITextColor; - -template -struct ANSITextColor : StyleFormatter, U> { - using Base = StyleFormatter; - using typename Base::ValType; - using Base::HasChild; - - template ::type> - ANSITextColor(const U& _val) : Base{"\x1b[39m", _val, "\x1b[39m"} {} - template > - ANSITextColor() : Base{"\x1b[92m"} {} -}; - -template <> -struct ANSITextColor : StyleFormatter, std::string> { - using Base = StyleFormatter, std::string>; - static constexpr bool HasChild = Base::HasChild; - - template - ANSITextColor(char const(&_val) [N]) : Base{"\x1b[92m", _val, "\x1b[39m"} {} - ANSITextColor(const char* _val) : Base{"\x1b[92m", _val, "\x1b[39m"} {} - ANSITextColor(const std::string& _val) : Base{"\x1b[92m", _val, "\x1b[39m"} {} -}; - -} // namespace nb - -template -std::ostream& operator<<(std::ostream& stream, const nb::StyleFormatter& msg) { - if (&stream == &std::cout) { - stream << msg.fmt; - if (msg.HasChild) { - stream << msg.val << msg.closing; - } - } else { - if (msg.HasChild) { stream << msg.val; } - } - stream << std::flush; - return stream; -} - -/* struct CellBase { - uint8_t width; - uint8_t height; -}; - -template -struct Cell : SmartText, T> { - using Base = SmartText, T>; - using typename Base::ValType; - using Base::HasChild; - - Cell(const ValType& _val, const uint8_t& w, const uint8_t& h=1) - : val(_val), width(w), height(h) {} - - ValType val; - uint8_t width; - - uint8_t height; -}; - -template <> -struct Cell : SmartText, std::string> { - using Base = SmartText, std::string>; - using typename Base::ValType; - using Base::HasChild; - - template - Cell( const(&_val) [N], const uint8_t& w, const uint8_t& h=0) : Cell(std::string(_val), w, h) {} - Cell(char* _val, const uint8_t& w, const uint8_t& h=0) : Cell(std::string(_val), w, h) {} - Cell(const ValType& _val, const uint8_t& w, const uint8_t& h=0) - : val(_val), width(w) { - unsigned int strsize = _val.size(); - height = strsize / width; - height += (strsize % width) ? 1 : 0; - } - - ValType val; - uint8_t width; - - uint8_t height; -}; - -template -std::ostream& operator<<(std::ostream& stream, const Cell& cll) { - if (&stream == &std::cout) { - stream << "\x1b[s" << cll.val << "\x1b[u\x1b[" << 1+cll.width << "C\x1b[" << 1+cll.height; - } - return stream; -} - -template -void ChangeCellHeight(int i, Cell& cll, const unsigned int& h) { - if (h < cll.height) { cll.height=h; } -} - -template -void GetTallestCell(int i, Cell& cll, unsigned int& h) { - if (cll.height > h) { h = cll.height; } -} - -template -struct TableRow { - using RowCells = std::tuple...>; - using CellWidths = std::array; - using DelimiterArray = std::array; - - TableRow(CellWidths&& widths_, DelimiterArray&& delims_, const Pack&... vals_) - : widths(widths_), delimiters(delims_), topBorder("") { - nb::ForEach(_cells, GetTallestCell, _height); - } - - static constexpr int num_columns = sizeof...(Pack); - - int height() const { return height; } - inline int height(const unsigned int newh) { - nb::ForEach(_cells, ChangeCellHeight, newh); - return (_height=newh); - } - - const CellWidths widths; - const DelimiterArray delimiters; - const std::string topBorder; - const std::string bottomBorder; - -protected: - RowCells _cells; - int _height; - -}; - -template -std::ostream& operator<<(std::ostream& stream, const TableRow& row) { - -} - -template -class Table { -public: - Table(const Pack&... _vals) : row(std::array(10), - std::array(""), _vals...) {} -private: - TableRow row; -}; - -} // namespace nb - -#ifdef _NB_TARGET_WINDOWS -template -std::ostream& operator<<(std::ostream& stream, const nb::TableRow& row) { - using PosType = decltype(stream.tellp()); - constexpr int num_cells = sizeof...(Types); - - int col_num = 0; - int col_start = 0; - - return stream; -} -#endif // _NB_TARGET_WINDOWS */ - -#endif // _NB_ANSI_TERM \ No newline at end of file diff --git a/engine/NBCore/include/NBCore/TypeTraits.hpp b/engine/NBCore/include/NBCore/TypeTraits.hpp index 17fae25..5542cf2 100644 --- a/engine/NBCore/include/NBCore/TypeTraits.hpp +++ b/engine/NBCore/include/NBCore/TypeTraits.hpp @@ -2,9 +2,7 @@ #ifndef _NB_TYPE_TRAITS #define _NB_TYPE_TRAITS -#include #include -#include namespace nb { @@ -31,6 +29,14 @@ namespace detail { }; } // namespace detail +enum TypeCodes { + UINT8, UINT16, UINT32, UINT64, INT8, INT16, INT32, INT64, + FLOAT16, FLOAT32, DOUBLE64, BOOL, NONE +}; + +template +static constexpr TypeCodes GetTypeEnum = NONE; + struct NoneType{}; template @@ -90,37 +96,6 @@ struct RunAndOutput { } }; -template -using SubtractType = decltype(std::declval() - std::declval()); - -template -using MultiplyType = decltype(std::declval() * std::declval()); - -template -using AdditionType = decltype(std::declval() + std::declval()); - -template -inline typename std::enable_if::type -ForEach(std::tuple&, Func) {} - -template -inline typename std::enable_if::type -ForEach(std::tuple& tup, Func f) { - f(N, std::get(tup)); - ForEach(tup, f); -} - -template -inline typename std::enable_if::type -ForEach(std::tuple&, Func, const Args&) {} - -template -inline typename std::enable_if::type -ForEach(std::tuple& tup, Func f, const Args& arg) { - f(N, std::get(tup), arg); - ForEach(tup, f, arg); -} - template struct Find; @@ -156,48 +131,6 @@ struct Find { >::value; }; -template -struct RefPackToPtrVec { - RefPackToPtrVec(std::vector _vec, Pack1& p1, Pack&... packs) - : vec(_vec) { - static_assert(std::is_base_of::value); - vec.push_back(&p1); - vec = RefPackToPtrVec(vec, packs...).vec; - } - - RefPackToPtrVec(Pack1& p1, Pack&... packs) - : RefPackToPtrVec({}, p1, packs...) {} - - std::vector vec; -}; - -template -struct RefPackToPtrVec { - RefPackToPtrVec(std::vector _vec, Pack& p1) - : vec(_vec) { - static_assert(std::is_base_of::value); - vec.push_back(&p1); - } - - RefPackToPtrVec(Pack& p1) - : RefPackToPtrVec({}, p1) {} - - std::vector vec; -}; - -template -struct PackIsSameType; - -template -struct PackIsSameType { - const bool value = std::is_base_of::value; -}; - -template -struct PackIsSameType { - const bool value = std::is_base_of::value && PackIsSameType::value; -}; - } // namespace nb #endif // _NB_TYPE_TRAITS \ No newline at end of file diff --git a/engine/NBCore/include/NBCore/Utils.hpp b/engine/NBCore/include/NBCore/Utils.hpp index d4e0ab5..19e046a 100644 --- a/engine/NBCore/include/NBCore/Utils.hpp +++ b/engine/NBCore/include/NBCore/Utils.hpp @@ -2,7 +2,6 @@ #ifndef _NB_CORE_TYPES #define _NB_CORE_TYPES -#include #include #include #include diff --git a/engine/NBCore/src/TypeTraits.cpp b/engine/NBCore/src/TypeTraits.cpp new file mode 100644 index 0000000..9689d0c --- /dev/null +++ b/engine/NBCore/src/TypeTraits.cpp @@ -0,0 +1,17 @@ +#include + +namespace nb { + +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::UINT8; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::UINT16; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::UINT32; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::UINT64; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::INT8; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::INT16; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::INT32; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::INT64; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::FLOAT32; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::DOUBLE64; +template<> constexpr TypeCodes GetTypeEnum = TypeCodes::BOOL; + +} // namespace nb \ No newline at end of file