diff options
117 files changed, 3927 insertions, 2135 deletions
@@ -1,2 +1,3 @@ /.vscode -/build
\ No newline at end of file +/build +vgcore.*
\ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d9d99ba..794bb0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,13 @@ cmake_minimum_required( 3.20 ) project( - u8c + dux VERSION - 27 + 29 DESCRIPTION - "Unicode manipulation library." + "General purpose library." HOMEPAGE_URL - "https://mandelbrot.dk/delta/u8c" + "https://mandelbrot.dk/delta/dux" LANGUAGES CXX ) @@ -17,16 +17,23 @@ set( CMAKE_CXX_STANDARD 23 ) -set( - CMAKE_CXX_EXTENSIONS - OFF -) # Options: option( - U8C_TEST - "Build test program." - OFF + DUX_ENABLE_DEMO + "Build the demo program." +) +option( + DUX_ENABLE_SYS + "Enable the system extensions." +) +option( + DUX_GFXPROTO + "Set the graphics protocol: \"windx\" (WinAPI/DirectX), \"wlgl\" (Wayland/OpenGL), \"wlvk\" (Wayland/Vulkan), \"xgl\" (X/OpenGL), \"xvk\" (X/Vulkan)" +) +option( + DUX_SFXPROTO + "Set the sound protocol: \"dx\" (DirectX), \"pa\" (PulseAudio), \"pw\" (PipeWire)" ) # Disable in-souce builds: @@ -76,13 +83,24 @@ if( ) else() add_compile_options( + "-pedantic-errors" "-Wfatal-errors" "-Wall" + "-Wconversion" "-Werror" "-Wextra" - "-Wno-attributes" - "-pedantic-errors" + "-Wunreachable-code" + "-Wunused" ) + if( + "${CMAKE_CXX_COMPILER_ID}" + STREQUAL + "Clang" + ) + add_compile_options( + "-Wnewline-eof" + ) + endif() endif() if( CMAKE_BUILD_TYPE @@ -105,34 +123,177 @@ if( ) endif() endif() + +# Include directories: include_directories( - "${PROJECT_SOURCE_DIR}/u8c/include" + "${PROJECT_SOURCE_DIR}/include" ) -# u8c settings: +# dux settings: add_library( - u8c + dux SHARED - "u8c/src/operator.cc" - "u8c/src/u8c/fmt.cc" - "u8c/src/u8c/print.cc" - "u8c/src/u8c/println.cc" + "src/dux/_setsiginthandl.cc" + "src/dux/_siginthandl.cc" + "src/dux/_sigtocsig.cc" + "src/dux/abrt.cc" + "src/dux/endgfx.cc" + "src/dux/exit.cc" + "src/dux/getenv.cc" + "src/dux/goatmaster.cc" + "src/dux/initgfx.cc" + "src/dux/qexit.cc" + "src/dux/raise.cc" + "src/dux/sighandl.cc" + "src/dux/sleep.cc" + "src/dux/trap.cc" + "src/dux/unreach.cc" + "src/dux/win.cc" +) +if( + UNIX +) + set_property( + TARGET + dux + APPEND + PROPERTY + SOURCES + "src/dux/_freepthrdhandl.cc" + "src/dux/_getpthrdhandl.cc" + "src/dux/_pthrdcrt.cc" + "src/dux/_pthrdjoin.cc" + ) +endif() +target_compile_definitions( + dux + PRIVATE + _XOPEN_SOURCE=700 +) +if( + DUX_GFXPROTO + STREQUAL + "wlgl" +) + message( + STATUS + "Using Wayland/OpenGL for graphics." + ) + target_compile_definitions( + dux + PRIVATE + dux_gfxproto_wlgl + ) +elseif( + DUX_GFXPROTO + STREQUAL + "wlvk" +) + message( + STATUS + "Using Wayland/Vulkan for graphics." + ) + target_compile_definitions( + dux + PRIVATE + dux_gfxproto_wlvk + ) +elseif( + DUX_GFXPROTO + STREQUAL + "xgl" ) + message( + STATUS + "Using X/OpenGL for graphics." + ) + target_compile_definitions( + dux + PRIVATE + dux_gfxproto_xgl + ) +elseif( + DUX_GFXPROTO + STREQUAL + "xvk" +) + message( + STATUS + "Using X/Vulkan for graphics." + ) + target_compile_definitions( + dux + PRIVATE + dux_gfxproto_xvk + ) +else() + message( + FATAL_ERROR + "Graphics system undefined (or invalid)! Set option \"DUX_GFXPROTO\" to: \"wlgl\" (Wayland/OpenGL), \"wlvk\" (Wayland/Vulkan), \"xgl\" (X/OpenGL), or \"xvk\" (X/Vulkan)!" + ) +endif() +if( + DUX_GFXPROTO + STREQUAL + "wlgl" + OR + DUX_GFXPROTO + STREQUAL + "wlvk" +) + target_link_libraries( + dux + wayland-client + ) +elseif( + DUX_GFXPROTO + STREQUAL + "xgl" + OR + DUX_GFXPROTO + STREQUAL + "xvk" +) + target_link_libraries( + dux + xcb + ) + if( + DUX_GFXPROTO + STREQUAL + "xgl" + ) + target_link_libraries( + dux + X11-xcb + ) + endif() +endif() +if( + NOT + WIN32 +) + target_link_libraries( + dux + dl + pthread + ) +endif() -# Test settings: +# Demo settings: if( - U8C_TEST + DUX_ENABLE_DEMO ) add_executable( - test - "u8c-check/src/test.cc" + demo + "dux-demo/main.cc" ) add_dependencies( - test - u8c + demo + dux ) target_link_libraries( - test - u8c + demo + dux ) endif() @@ -1,21 +1,46 @@ -# u8c +# dux -[*u8c*](https://mandelbrot.dk/delta/u8c) is a free, open-source and portable general-purpose library. It is written in the C++ *(C++2b)* programming language. A wrapper for C may arrive in the future. +[*dux*](https://mandelbrot.dk/delta/dux) is a free, open-source and portable general-purpose library for the C++ programming language. + +It is intended as a modular, morden and stable replacement for the C++ standard library and other major libraries *(such as Boost)*. In the *features* section a list of fascilities included in this library is available. + +## Genesis + +*note: This section is outdated.* + +dux started out in 2019 as a small, useless library under the name *duckGFX*. This library was capable of two things: opening windows, followed by closing them, both achieved using an Xlib back-end. + +Progress stagnated following. The project was renamed to *duckFX*, and later to *dfx*, but during this time almost no development occured. + +In March of 2020, dfx saw a significant rework. The library was renamed yet again, this time to *duX*. XLib was dropped in favour of XCB *(where possible)*, and Wayland support was planned, but didn't become of much. + +In early April of 2020, duX was no longer a single-header header-only library. As a result of this, a build-system was logical, and so CMake was chosen. At the same time, support for Wayland was completely dropped. + +In late April and early May of 2020, Wayland support slowly crawled back. macOS support was considered, but also very quickly dropped, as I had no way to debug it. + +Later the same year, in an attempt of rebranding, the project was renamed to *duxXYZ*. It was actually planned to become a 3D-graphics engine, but development halted quickly. The project remained silent for almost a year from here, before any serious progress was made at least. + +When the [*luma*](https://mandelbrot.dk/delta/luma) programming-language was started in the early 2021, duxXYZ was decided to become a part of the standard-library. Some development was made, but the adoption was ultimately repealed. + +In the end of May of 2021, following the creation of the [*dux*](https://mandelbrot.dk/delta/dux) library, development returned again. All code from *duxXYZ* was rewritten from C++ to C, as the latter was my programming language of choice. The project as a whole was for the last time renamed, this time to *dux*. Contrary to what I once slated, Cocoa (replacing Quartz) and WinAPI was formally planned, however without a static date. An extension to this was the disposition that dux would also provide an interface for graphics rendering, with DirectX, Metal, OpenGL, and Vulkan back-ends all being planned, still without a static date. Wayland was also a top-priority. + +In the beginning of this same month of May, *u8c* – a library for encoding and decoding UTF-8 messages in the C programming language – was started. This project evolved a lot, later offering replacemnts for the character classifications fascilities in the C standard library with support for Unicode characters. + +After a few months, u8c was rewritten in C++. This new edition also offered compile-time *(constexpr)* replacements for some of the members of the C standard library, including the maths library and the string manipulation library. + +As a reaction to the massive bloat of some C++ standard library implementations, u8c also had replacements for a lot of the C++ standard template library. + +In October of 2021, progress on dux resumed. This was partly thanks to the maturity of u8c, as it [u8c] could now be used in other projects. Support for multithreading also started at this time. + +In the same month, dux and u8c underwent a merge. This was planned for some time, but was not executed, as u8c was supposed to be as portable as possible. dux was not as portable. To combat this, the new merged library was made modular. End-users could specify what modules to be build, allowing for the same level of portability. ## Features -u8c has the following features: +TBA -* Array container with support for compile-time, dynamic, and static arrays. -* Compile-time-compatible alternatives to the C maths library *(incomplete)*. -* Compile-time-compatible alternatives to the C string manipulation facilities *(incomplete)*. -* Facilities for determining the target platform using immediate functions *(Supports major platforms, including AIX, FreeBSD, Linux, macOS, OpenBSD, Windows NT)*. -* Optional platform-specific behaviour, including vendor-specific attributes, pointer-restriction. -* Quota type for fractional mathematics *(incomplete)*. -* String container with built-in UTF-conversions -* Unicode *(UTF-8, UTF-16 and UTF-32)* conversions and manipulations facilities *(UTF-16 lacking full support)*. +## Examples -With more to come in the future. +TBA ## Installing @@ -23,39 +48,40 @@ TBA ## Compiling -u8c has been tested to work with Clang 14. +dux has been tested to work with Clang 14. A compiler conforming to the C++2b standard is required. + +You may also directly install the header files (in `/include`) in case your system is not supported or you do not need the extra facilities. -1. Checkout u8c using `git`: +1. Checkout dux using `git`: - * Clone the repository: `git clone https://mandelbrot.dk/delta/u8c.git - * Or do a shallow cone: `git clone --depth 1 https://mandelbrot.dk/delta/u8c.git` + * Clone the repository: `git clone https://mandelbrot.dk/delta/dux.git` + * Or do a shallow cone: `git clone --depth 1 https://mandelbrot.dk/delta/dux.git` -2. Configure the compilation of u8c: +2. Configure the compilation of dux: - * `cd u8c` + * `cd dux` * `cmake -B build` You can append the following options to the command: * `-DCMAKE_BUILD_TYPE` — Set the build type. Can be either `Debug`or `Release`. - * `-DU8C_TEST` — Enables compilation of the test program if set to `ON`. -3. Build u8c build +3. Build dux build * `cmake --build build` ## Contributing -u8c does currently not accept **any** merge requests. +dux does currently not accept **any** merge requests. ## Copyright & License Copyright 2021 Gabriel Jensen -This file is part of u8c. +This file is part of dux. -u8c is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. +dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -u8c is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. +dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. -You should have received a copy of the GNU Affero General Public License along with u8c. If not, see <https://www.gnu.org/licenses/>.
\ No newline at end of file +You should have received a copy of the GNU Affero General Public License along with dux. If not, see <https://www.gnu.org/licenses/>.
\ No newline at end of file diff --git a/changelog.md b/changelog.md index 71f7f64..4f2de28 100644 --- a/changelog.md +++ b/changelog.md @@ -1,3 +1,16 @@ +# 25 + +* Merge with dux. +* Make new logo (based on dux_boxes). +* Merge maths facilities and sequence facilities. +* Implement alternatives for stdlib. +* Use new header structure +* Make thread API cleaner. +* Make windowing API cleaner. +* ... + +**TO-DO: Expand and improve the changelog for this version.** + # 24 * Remove constructor taking a single value for `u8c::arr`. @@ -6,6 +19,7 @@ * Remove `u8c::trunc`. * Initialise memory allocated by `u8c::arr`. * Add overload taking value used for memory-initialisation for `u8c::arr::alloc`. +* Update code formatting. # 23 diff --git a/dux-demo/main.cc b/dux-demo/main.cc new file mode 100644 index 0000000..fea721e --- /dev/null +++ b/dux-demo/main.cc @@ -0,0 +1,40 @@ +#include <dux/io> +#include <dux/media> +#include <dux/thrd> + +auto thrdfn0(int const _x,int const _y,int const _z,int const _w) -> int { + return _x * _y * _z * _w; +}; +auto thrdfn1(int const _x) -> int { + return _x * _x * _x; +}; + +auto main() -> int { + _Pragma("GCC diagnostic ignored \"-Wunreachable-code\""); + ::dux::dobj dobj; + dobj.link("libdux.so"); + dobj.call<void>("goatmaster",0xC); + ::dux::thrd thrd; + auto val{thrd(thrdfn0,0xC,0xC,0xC,0xC)}; + thrd.join(&val); + ::dux::print(U"Returned value: $\n",val); + val = thrd(thrdfn1,0x4); + thrd.join(&val); + ::dux::print(U"Returned value: $\n",val); + ::dux::initgfx(); + auto win = ::dux::win::crt("dux demo",::dux::uint32v(0x400),::dux::uint32v(0x300)); + for (auto run{true};run;) { + while (auto const evt = win.pollevt()) { + switch (evt->typ) { + default: + goto skipevt; + case ::dux::evttyp::quit: + run = false; + break; + } + } + skipevt:; + } + win.destr(); + ::dux::endgfx(); +} @@ -0,0 +1,41 @@ +<svg height="768" width="768" xmlns="http://www.w3.org/2000/svg"> + <clipPath id="clipPath22"> + <rect height="768" width="384" /> + </clipPath> + <clipPath id="clipPath29"> + <rect height="384" width="768" /> + </clipPath> + <clipPath id="clipPath40"> + <rect height="768" width="384" x="384" /> + </clipPath> + <clipPath id="clipPath49"> + <rect height="384" width="768" y="384" /> + </clipPath> + <clipPath id="clipPath62"> + <rect height="768" width="768" /> + <!--<rect height="768" rx="192" width="768" />--> <!-- Comment above line and uncomment this one (before this comment) for a background with rounded corners. --> + </clipPath> + <clipPath id="clipPath253"> + <rect height="768" width="384" x="384" /> + </clipPath> + <!-- Background --> + <rect clip-path="url(#clipPath62)" fill="#444747" height="768" width="768" /> + <!--<circle fill="#00000000" cx="384" cy="384" r="336" stroke="#444747" stroke-width="96" />--> <!-- Comment above line and uncomment this one (before this comment) for a transparent background. --> + <!-- White Middle Circle --> + <circle fill="#F8F8F1" cx="384" cy="384" r="288"/> + <!-- Spiral Border --> + <circle clip-path="url(#clipPath40)" cx="384" cy="216" fill="#00000000" r="168" stroke="#444747" stroke-width="96" /> + <circle clip-path="url(#clipPath29)" cx="216" cy="384" fill="#00000000" r="168" stroke="#444747" stroke-width="96" /> + <circle clip-path="url(#clipPath49)" cx="552" cy="384" fill="#00000000" r="168" stroke="#444747" stroke-width="96" /> + <circle clip-path="url(#clipPath22)" cx="384" cy="552" fill="#00000000" r="168" stroke="#444747" stroke-width="96" /> + <!-- Spiral Lower --> + <circle clip-path="url(#clipPath40)" cx="384" cy="216" fill="#00000000" r="168" stroke="#3DE1A9" stroke-width="32" /> + <circle clip-path="url(#clipPath22)" cx="384" cy="552" fill="#00000000" r="168" stroke="#3DE1A9" stroke-width="32" /> + <!-- Spiral Upper --> + <circle clip-path="url(#clipPath49)" cx="552" cy="384" fill="#00000000" r="168" stroke="#444747" stroke-width="64" /> + <circle clip-path="url(#clipPath29)" cx="216" cy="384" fill="#00000000" r="168" stroke="#444747" stroke-width="64" /> + <circle clip-path="url(#clipPath29)" cx="216" cy="384" fill="#00000000" r="168" stroke="#3DE1A9" stroke-width="32" /> + <circle clip-path="url(#clipPath49)" cx="552" cy="384" fill="#00000000" r="168" stroke="#3DE1A9" stroke-width="32" /> + <!-- Greater Ring --> + <circle fill="#00000000" cx="384" cy="384" r="336" stroke="#3DE1A9" stroke-width="32" /> +</svg> diff --git a/dux_boxes.svg b/dux_boxes.svg new file mode 100644 index 0000000..a55d0d2 --- /dev/null +++ b/dux_boxes.svg @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg height="96" version="1.1" width="256" xmlns="http://www.w3.org/2000/svg"> + <clipPath id="clipPath99"> + <polygon points="189.656854249,24 226.343145751,24 232,29.656854249 232,66.343145751 226.343145751,72 189.656854249,72 184,66.343145751 184,29.656854249" /> + </clipPath> + <clipPath id="clipPath236"> + <rect height="48" width="24" x="44" y="24" /> + </clipPath> + <!-- Box #0 --> + <rect fill="#444747" height="64" rx="8" ry="8" width="64" x="24" y="24" /> + <rect fill="#E1A93D" height="64" rx="8" ry="8" width="64" x="16" y="16" /> + <rect fill="#F8F8F1" height="48" width="16" x="28" y="24" /> + <rect fill="#E1A93D" height="32" width="8" x="36" y="32" /> + <circle clip-path="url(#clipPath236)" cx="44" cy="48" fill="#F8F8F1" r="24" /> + <circle clip-path="url(#clipPath236)" cx="44" cy="48" fill="#E1A93D" r="16" /> + <!-- Box #1 --> + <rect fill="#444747" height="64" rx="8" ry="8" width="64" x="104" y="24" /> + <rect fill="#3DE1A9" height="64" rx="8" ry="8" width="64" x="96" y="16" /> + <rect fill="#F8F8F1" height="32" width="32" x="112" y="24" /> + <circle cx="128" cy="56" fill="#F8F8F1" r="16"/> + <rect fill="#3DE1A9" height="36" width="16" x="120" y="20" /> + <circle fill="#3DE1A9" cx="128" cy="56" r="8"/> + <!-- Box #2 --> + <rect fill="#444747" height="64" rx="8" ry="8" width="64" x="184" y="24" /> + <rect fill="#A93DE1" height="64" rx="8" ry="8" width="64" x="176" y="16" /> + <polyline clip-path="url(#clipPath99)" stroke="#F8F8F1" points="240,16 176,80" stroke-width="8" /> + <polyline clip-path="url(#clipPath99)" stroke="#F8F8F1" points="176,16 240,80" stroke-width="8" /> +</svg> diff --git a/u8c/src/u8c/print.cc b/include/dux/algo index bb08cb4..4358784 100644 --- a/u8c/src/u8c/print.cc +++ b/include/dux/algo @@ -1,25 +1,26 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#include <ostream> /* std::ostream */ +#if !defined(dux_hdr_algo) +#define dux_hdr_algo + +#include <dux/base> +#include <dux/algo.hh> -#if 0x0 -auto u8c::print([[maybe_unused]] std::ostream & _strm,[[maybe_unused]] u8c::str _msg) -> void { -} #endif diff --git a/u8c/include/u8c/math.d/abs b/include/dux/algo.d/abs.hh index 53eaba3..b713c90 100644 --- a/u8c/include/u8c/math.d/abs +++ b/include/dux/algo.d/abs.hh @@ -1,29 +1,24 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_DHlzI0Min44ZJ3qF) -#define u8c_key_DHlzI0Min44ZJ3qF - -#include <type_traits> /* std::is_unsigned_v */ - -template<u8c::arith T> constexpr auto u8c::abs(T const _val) noexcept -> T { - if constexpr (std::is_unsigned_v<T>) { +template<::dux::arith T> constexpr auto ::dux::abs(T const _val) noexcept -> T { + if constexpr (::dux::isuint<T>) { return _val; } else { @@ -33,5 +28,3 @@ template<u8c::arith T> constexpr auto u8c::abs(T const _val) noexcept -> T { return _val; } } - -#endif diff --git a/include/dux/algo.d/cpy.hh b/include/dux/algo.d/cpy.hh new file mode 100644 index 0000000..5e287c9 --- /dev/null +++ b/include/dux/algo.d/cpy.hh @@ -0,0 +1,22 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::cpy(T const * const _begin,T const * const _end,T * const _out) noexcept -> void { + ::dux::cpyn(_begin,static_cast<::dux::usz>(_end - _begin),_out); +} diff --git a/include/dux/algo.d/cpyn.hh b/include/dux/algo.d/cpyn.hh new file mode 100644 index 0000000..6049fab --- /dev/null +++ b/include/dux/algo.d/cpyn.hh @@ -0,0 +1,27 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::cpyn(T const * const dux_restr _in,::dux::usz const _num,T * const _out) noexcept -> void { + if (!_num) [[unlikely]] { + return; + } + for (auto pos = 0x0uz;pos < _num;pos += 0x1uz) { + _out[pos] = _in[pos]; + } +} diff --git a/include/dux/algo.d/fill.hh b/include/dux/algo.d/fill.hh new file mode 100644 index 0000000..d0a76b9 --- /dev/null +++ b/include/dux/algo.d/fill.hh @@ -0,0 +1,22 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T,typename T0> constexpr auto ::dux::fill(T * const _begin,T * const _end,T0 const _val) noexcept -> void { + ::dux::filln(_begin,static_cast<::dux::usz>(_end - _begin),_val); +} diff --git a/include/dux/algo.d/filln.hh b/include/dux/algo.d/filln.hh new file mode 100644 index 0000000..f2d6988 --- /dev/null +++ b/include/dux/algo.d/filln.hh @@ -0,0 +1,28 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T,typename T0> constexpr auto ::dux::filln(T * const dux_restr _in,::dux::usz const _num,T0 const _val) noexcept -> void { + if (!_num) [[unlikely]] { + return; + } + auto const val = static_cast<T>(_val); + for (auto pos = 0x0uz;pos < _num;pos += 0x1uz) { + _in[pos] = val; + } +} diff --git a/u8c/include/u8c/math.d/fma b/include/dux/algo.d/fma.hh index e2b756d..87a59e7 100644 --- a/u8c/include/u8c/math.d/fma +++ b/include/dux/algo.d/fma.hh @@ -1,27 +1,22 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_3Xt4uPu34bdh53dB) -#define u8c_key_3Xt4uPu34bdh53dB - -template<u8c::arith T> constexpr auto u8c::fma(T const _x,T const _y,T const _z) noexcept -> T { +template<::dux::arith T> constexpr auto ::dux::fma(T const _x,T const _y,T const _z) noexcept -> T { return _x * _y + _z; } - -#endif diff --git a/include/dux/algo.d/ins.hh b/include/dux/algo.d/ins.hh new file mode 100644 index 0000000..6224951 --- /dev/null +++ b/include/dux/algo.d/ins.hh @@ -0,0 +1,22 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::ins(T const * const _begin,T const * const _end,T * const _out) noexcept -> void { + ::dux::insn(_begin,static_cast<::dux::usz>(_end - _begin),_out); +} diff --git a/include/dux/algo.d/insn.hh b/include/dux/algo.d/insn.hh new file mode 100644 index 0000000..59392d1 --- /dev/null +++ b/include/dux/algo.d/insn.hh @@ -0,0 +1,23 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::insn(T const * const _in,::dux::usz const _num,T * const _out) noexcept -> void { + ::dux::cpy(_out,_out + _num,_out + _num); + ::dux::cpy(_in,_in + _num,_out); +} diff --git a/include/dux/algo.d/isinf.hh b/include/dux/algo.d/isinf.hh new file mode 100644 index 0000000..e921cc8 --- /dev/null +++ b/include/dux/algo.d/isinf.hh @@ -0,0 +1,27 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <limits> /* ::std::numeric_limits */ + +template<::dux::arith T> constexpr auto ::dux::isinf(T const _val) noexcept -> bool { + if (::std::numeric_limits<T>::has_infinity) { + return _val == ::std::numeric_limits<T>::infinity(); + } + return false; +} diff --git a/include/dux/algo.d/isnan.hh b/include/dux/algo.d/isnan.hh new file mode 100644 index 0000000..26825e6 --- /dev/null +++ b/include/dux/algo.d/isnan.hh @@ -0,0 +1,22 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<::dux::arith T> constexpr auto ::dux::isnan(T const _val) noexcept -> bool { + return _val != _val; +} diff --git a/u8c/include/u8c/math.d/isprime b/include/dux/algo.d/isprime.hh index 5074d4b..a397f58 100644 --- a/u8c/include/u8c/math.d/isprime +++ b/include/dux/algo.d/isprime.hh @@ -1,26 +1,23 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_rrAoPS9LdRWHCbsB) -#define u8c_key_rrAoPS9LdRWHCbsB - -template<u8c::arith T> constexpr auto u8c::isprime(T const _val) noexcept -> bool { +template<::dux::arith T> constexpr auto ::dux::isprime(T const _val) noexcept -> bool { if (_val <= T{0x1}) [[unlikely]] { return false; } @@ -31,5 +28,3 @@ template<u8c::arith T> constexpr auto u8c::isprime(T const _val) noexcept -> boo } return true; } - -#endif diff --git a/include/dux/algo.d/min.hh b/include/dux/algo.d/min.hh new file mode 100644 index 0000000..67fc52d --- /dev/null +++ b/include/dux/algo.d/min.hh @@ -0,0 +1,25 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::min(T const & _lval,T const & _rval) noexcept -> T const & { + if (_lval < _rval) { + return _lval; + } + return _rval; +} diff --git a/include/dux/algo.d/mv.hh b/include/dux/algo.d/mv.hh new file mode 100644 index 0000000..29fc766 --- /dev/null +++ b/include/dux/algo.d/mv.hh @@ -0,0 +1,22 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::mv(T * const _begin,T * const _end,T * const _out) noexcept -> void { + ::dux::mvn(_begin,static_cast<::dux::usz>(_end - _begin),_out); +} diff --git a/include/dux/algo.d/mvn.hh b/include/dux/algo.d/mvn.hh new file mode 100644 index 0000000..82a1753 --- /dev/null +++ b/include/dux/algo.d/mvn.hh @@ -0,0 +1,25 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::mvn(T * const _in,::dux::usz const _num,T * const _out) noexcept -> void { + for (auto pos = 0x0uz;pos < _num;pos += 0x1uz) { + _out[pos] = _in[pos]; + _in[pos] = T{}; + } +} diff --git a/u8c/include/u8c/math.d/pow b/include/dux/algo.d/pow.hh index 53410b8..58370b0 100644 --- a/u8c/include/u8c/math.d/pow +++ b/include/dux/algo.d/pow.hh @@ -1,32 +1,27 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_JD8l4B23bwAqQ2HP) -#define u8c_key_JD8l4B23bwAqQ2HP - -#include <type_traits> /* std::is_floating_point_v */ - -template<u8c::arith T> constexpr auto u8c::pow(T const _base,T const _exp) noexcept -> T { - //if constexpr (std::is_floating_point_v<T>) { +template<::dux::arith T> constexpr auto ::dux::pow(T const _base,T const _exp) noexcept -> T { + //if constexpr (::std::is_floating_point_v<T>) { //} //else { - if (u8c::abs(_base) <= T{0x1}) [[unlikely]] { + if (::dux::abs(_base) <= T{0x1}) [[unlikely]] { return _base; } T res = _base; @@ -36,5 +31,3 @@ template<u8c::arith T> constexpr auto u8c::pow(T const _base,T const _exp) noexc return res; //} } - -#endif diff --git a/include/dux/algo.d/renew.hh b/include/dux/algo.d/renew.hh new file mode 100644 index 0000000..681a337 --- /dev/null +++ b/include/dux/algo.d/renew.hh @@ -0,0 +1,25 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::renew(T * const dux_restr _ptr,::dux::usz const _sz,::dux::usz const _newsz) -> T * { + T * const dux_restr ptr = ::new T[_newsz](); + ::dux::cpyn(_ptr,::dux::min(_sz,_newsz),ptr); + ::delete[] _ptr; + return ptr; +} diff --git a/u8c/include/u8c/math.d/sqrt b/include/dux/algo.d/sqrt.hh index d1eb5e1..418d2c6 100644 --- a/u8c/include/u8c/math.d/sqrt +++ b/include/dux/algo.d/sqrt.hh @@ -1,42 +1,36 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_GPVreQYtljZ3JsPu) -#define u8c_key_GPVreQYtljZ3JsPu +#include <limits> /* ::std::numeric_limits */ -#include <limits> /* std::numeric_limits */ -#include <type_traits> /* std::is_integral_v */ - -template<u8c::arith T> constexpr auto u8c::sqrt(T const _val) noexcept -> T { +template<::dux::arith T> constexpr auto ::dux::sqrt(T const _val) noexcept -> T { if (_val < T{0x0}) [[unlikely]] { - return std::numeric_limits<T>::quiet_NaN(); + return ::std::numeric_limits<T>::quiet_NaN(); } if (_val == T{0x0}) [[unlikely]] { return _val; } /*constexpr auto err = []() { - if constexpr(std::is_integral_v<T>) { + if constexpr(::std::is_integral_v<T>) { return T{0x1}; } - return std::numeric_limits<T>::epsilon(); + return ::std::numeric_limits<T>::epsilon(); }();*/ return _val; } - -#endif diff --git a/include/dux/algo.hh b/include/dux/algo.hh new file mode 100644 index 0000000..b11f9a4 --- /dev/null +++ b/include/dux/algo.hh @@ -0,0 +1,68 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace dux { + template<::dux::arith T> [[dux_attr_const, nodiscard]] constexpr auto abs( T val) noexcept -> T; + template<typename T> [[dux_attr_hot]] constexpr auto cpy( T const * begin,T const * end, T * out) noexcept -> void; + template<typename T> [[dux_attr_hot]] constexpr auto cpyn( T const * in, ::dux::usz num, T * out) noexcept -> void; + template<typename T,typename T0> [[dux_attr_hot]] constexpr auto fill( T * begin,T * end, T0 val) noexcept -> void; + template<typename T,typename T0> [[dux_attr_hot]] constexpr auto filln( T * in, ::dux::usz num, T0 val) noexcept -> void; + template<::dux::arith T> [[dux_attr_const, nodiscard]] constexpr auto fma( T x, T y, T z) noexcept -> T; + template<typename T> [[dux_attr_hot]] constexpr auto ins( T const * begin,T const * end, T * out) noexcept -> void; + template<typename T> [[dux_attr_hot]] constexpr auto insn( T const * om, ::dux::usz num, T * out) noexcept -> void; + //template<::dux::arith T> [[dux_attr_const]] constexpr auto isinf( T val) noexcept -> bool; + template<::dux::arith T> [[dux_attr_const]] constexpr auto isnan( T val) noexcept -> bool; + template<::dux::arith T> [[dux_attr_const]] constexpr auto isprime(T val) noexcept -> bool; + template<typename T> [[dux_attr_const, nodiscard]] constexpr auto max( T const & lval, T const & rval) noexcept -> T const &; + template<typename T> [[dux_attr_const, nodiscard]] constexpr auto min( T const & lval, T const & rval) noexcept -> T const &; + template<typename T> [[dux_attr_hot]] constexpr auto mv( T * begin,T * end, T * out) noexcept -> void; + template<typename T> [[dux_attr_hot]] constexpr auto mvn( T * in, ::dux::usz num, T * out) noexcept -> void; + template<::dux::arith T> [[dux_attr_const]] constexpr auto pow( T base, T exp) noexcept -> T; + template<typename T> [[dux_attr_allocsz(0x3),dux_attr_hot,dux_attr_malloc,dux_attr_nonnull(0x1),nodiscard]] constexpr auto renew( T * ptr, ::dux::usz sz, ::dux::usz newsz) -> T *; + template<::dux::arith T> [[dux_attr_const]] constexpr auto sqrt( T val) noexcept -> T; + + /* Consteval alternatives for mathematical functions: */ + template<::dux::arith T> [[nodiscard]] consteval auto cabs( T _val) noexcept -> T {return ::dux::abs(_val);} + template<::dux::arith T> [[nodiscard]] consteval auto cfma( T _x, T _y, T _z) noexcept -> T {return ::dux::fma(_x,_y,_z);} + //template<::dux::arith T> consteval auto cisinf( T _val) noexcept -> bool {return ::dux::isinf(_val);} + template<::dux::arith T> consteval auto cisnan( T _val) noexcept -> bool {return ::dux::isnan(_val);} + template<::dux::arith T> consteval auto cisprime(T _val) noexcept -> bool {return ::dux::isprime(_val);} + template<typename T> [[nodiscard]] consteval auto cmax( T const & _lval, T const & _rval) noexcept -> T const & {return ::dux::max(_lval,_rval);} + template<typename T> [[nodiscard]] consteval auto cmin( T const & _lval, T const & _rval) noexcept -> T const & {return ::dux::min(_lval,_rval);} + template<::dux::arith T> [[nodiscard]] consteval auto cpow( T _base, T _exp) noexcept -> T {return ::dux::pow(_base,_exp);} + template<::dux::arith T> [[nodiscard]] consteval auto csqrt( T _val) noexcept -> T {return ::dux::sqrt(_val);} +} + +#include <dux/algo.d/abs.hh> +#include <dux/algo.d/cpy.hh> +#include <dux/algo.d/cpyn.hh> +#include <dux/algo.d/fill.hh> +#include <dux/algo.d/filln.hh> +#include <dux/algo.d/fma.hh> +#include <dux/algo.d/ins.hh> +#include <dux/algo.d/insn.hh> +//#include <dux/algo.d/isinf.hh> +#include <dux/algo.d/isnan.hh> +#include <dux/algo.d/isprime.hh> +#include <dux/algo.d/min.hh> +#include <dux/algo.d/mv.hh> +#include <dux/algo.d/mvn.hh> +#include <dux/algo.d/pow.hh> +#include <dux/algo.d/renew.hh> +#include <dux/algo.d/sqrt.hh> diff --git a/include/dux/arr b/include/dux/arr new file mode 100644 index 0000000..ce83ad7 --- /dev/null +++ b/include/dux/arr @@ -0,0 +1,26 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#if !defined(dux_hdr_arr) +#define dux_hdr_arr + +#include <dux/algo> +#include <dux/arr.hh> + +#endif diff --git a/include/dux/arr.d/arr.hh b/include/dux/arr.d/arr.hh new file mode 100644 index 0000000..4af5df3 --- /dev/null +++ b/include/dux/arr.d/arr.hh @@ -0,0 +1,217 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::arr<T>::alloc(::dux::usz const _num) -> void { + if (this->isstatic()) [[unlikely]] { + this->_isstatic = false; + } + else { + ::delete[] this->_ptr; + } + if (_num > 0x0uz) [[likely]] { + this->_ptr = ::new T[_num](); + } + this->_sz = _num; +} +template<typename T> template<::dux::cnvto<T> T0> constexpr auto ::dux::arr<T>::alloc(::dux::usz const _num,T0 const _val) -> void { + this->alloc(_num); + this->fill(this->begin(),this->end(),_val); +} +template<typename T> constexpr auto ::dux::arr<T>::app(::dux::arr<T> const & _oth) -> ::dux::arr<T> const & { + this->realloc(this->sz() + _oth.sz()); + ::dux::cpy(_oth.begin(),_oth.end(),this->begin() + this->sz() - _oth.sz()); + return *this; +} +template<typename T> template<::dux::cnvto<T> T0> constexpr auto ::dux::arr<T>::app(T0 const _val) -> ::dux::arr<T> const & { + this->realloc(this->sz() + 0x1uz); + (*this)[this->sz() - 0x1uz] = static_cast<T>(_val); + return *this; +} +template<typename T> constexpr ::dux::arr<T>::arr(T const * const _begin,T const * const _end) { + if constexpr (::dux::dbg) { + if (_begin == nullptr || _end == nullptr) [[unlikely]] { + throw ::dux::invalarg("Provided parameter has value of nullptr."); + } + } + this->alloc(static_cast<::dux::usz>(_end - _begin) + 0x1uz); + ::dux::cpy(_begin,_end,this->begin()); +} +template<typename T> constexpr ::dux::arr<T>::arr(::dux::usz const _num) { + this->alloc(_num); +} +template<typename T> constexpr ::dux::arr<T>::arr(::dux::arr<T> const & _oth) { + if (_oth.isstatic()) [[unlikely]] { + this->_isstatic = true; + this->_ptr = _oth.begin(); + this->_sz = _oth.sz(); + return; + } + this->alloc(_oth.sz()); + this->ins(_oth.begin(),_oth.end(),0x0uz); +} +template<typename T> constexpr ::dux::arr<T>::arr(::dux::arr<T> && _oth) { + this->_isstatic = _oth.isstatic(); + this->_ptr = _oth.begin(); + this->_sz = _oth.sz(); + _oth._ptr = nullptr; + _oth._sz = 0x0uz; +} +template<typename T> template<::dux::usz N> constexpr ::dux::arr<T>::arr(T const (&_arr)[N]) noexcept { + this->_isstatic = true; + this->_ptr = _arr; + this->_sz = N; +} +template<typename T> template<::dux::cnvto<T> T0> constexpr ::dux::arr<T>::arr(::dux::usz const _num,T0 const _val) { + this->alloc(_num,_val); +} +template<typename T> constexpr auto ::dux::arr<T>::begin() noexcept -> T * { + return this->_ptr; +} +template<typename T> constexpr auto ::dux::arr<T>::begin() const noexcept -> T const * { + return this->_ptr; +} +template<typename T> constexpr auto ::dux::arr<T>::cbegin() const noexcept -> T const * { + return this->begin(); +} +template<typename T> constexpr auto ::dux::arr<T>::cend() const noexcept -> T const * { + return this->begin() + this->sz; +} +template<typename T> constexpr auto ::dux::arr<T>::del(::dux::usz const _pos) -> void { + if constexpr (::dux::dbg) { + if (_pos >= this->sz()) [[unlikely]] { + throw ::dux::outofdomain("Position out of bounds!"); + } + } + if (this->sz() <= 0x1uz) [[unlikely]] { + if (this->sz() == 0x0uz) { + this->alloc(0x0uz); + return; + } + return; + } + ::dux::cpy(this->begin() + _pos + 0x1uz,this->end(),this->begin() + _pos); + this->realloc(this->sz() - 0x1uz); +} +template<typename T> constexpr auto ::dux::arr<T>::end() noexcept -> T * { + return this->begin() + this->sz(); +} +template<typename T> constexpr auto ::dux::arr<T>::end() const noexcept -> T const * { + return this->begin() + this->sz(); +} +template<typename T> template<::dux::cnvto<T> T0> constexpr auto ::dux::arr<T>::fill(T0 const _val) -> void { + this->fill(this->begin(),this->end(),_val); +} +template<typename T> template<::dux::cnvto<T> T0> constexpr auto ::dux::arr<T>::fill(T * const dux_restr _begin,T * const dux_restr _end,T0 const _val) -> void { + if (this->sz() == 0x0uz) [[unlikely]] { + return; /* slime incident */ + } + if constexpr (::dux::dbg) { + if (_begin < this->begin() || _end > this->end()) [[unlikely]] { + throw ::dux::outofdomain("Beginning or end are out of this array's range."); + } + } + if (this->isstatic()) [[unlikely]] { + this->alloc(static_cast<::dux::usz>(_end - _begin) + 0x1uz); + } + ::dux::fill(this->begin(),this->end(),_val); +} +template<typename T> constexpr auto ::dux::arr<T>::ins(T const * const _begin,T const * const _end,::dux::usz const _pos) -> ::dux::arr<T> const & { + this->realloc(this->sz() + static_cast<::dux::usz>(_end - _begin) + 0x1uz); + ::dux::ins(_begin,_end,this->begin() + _pos); + return *this; +} +template<typename T> constexpr auto ::dux::arr<T>::ins(::dux::arr<T> const & _oth,::dux::usz const _pos) -> ::dux::arr<T> const & { + return this->ins(_oth.begin(),_oth.end(),_pos); +} +template<typename T> constexpr auto ::dux::arr<T>::isstatic() const noexcept -> bool { + return this->_isstatic; +} +template<typename T> constexpr auto ::dux::arr<T>::operator = (::dux::arr<T> const & _oth) -> ::dux::arr<T> const & { + this->~arr(); + if (_oth.isstatic()) [[unlikely]] { + this->_isstatic = true; + this->_ptr = const_cast<T *>(_oth.begin()); + this->_sz = _oth.sz(); + } + else { + this->alloc(_oth.sz()); + this->ins(_oth.begin(),_oth.end(),0x0uz); + } + return *this; +} +template<typename T> constexpr auto ::dux::arr<T>::operator [] (::dux::usz const _pos) -> T & { + if constexpr (::dux::dbg) { + if (_pos >= this->sz()) [[unlikely]] { + throw ::dux::invalarg("Input parameter is out of range."); + } + } + return this->begin()[_pos]; +} +template<typename T> constexpr auto ::dux::arr<T>::operator [] (::dux::usz const _pos) const -> T const & { + if constexpr (::dux::dbg) { + if (_pos >= this->sz()) [[unlikely]] { + throw ::dux::invalarg("Input parameter is out of range."); + } + } + return this->begin()[_pos]; +} +template<typename T> constexpr auto ::dux::arr<T>::realloc(::dux::usz const _num) -> void { + if (this->sz() == 0x0uz) [[unlikely]] { + return this->alloc(_num); + } + if (this->isstatic()) [[unlikely]] { + this->_isstatic = false; + } + this->_ptr = ::dux::renew(this->begin(),this->sz(),_num); + this->_sz = _num; +} +template<typename T> constexpr auto ::dux::arr<T>::setraw(T const * const dux_restr _ptr,::dux::usz const _sz) noexcept -> void { + if (!this->isstatic()) [[unlikely]] { + ::delete[] this->_ptr; + } + this->_ptr = const_cast<T *>(_ptr); + this->_sz = _sz; +} +template<typename T> constexpr auto ::dux::arr<T>::sub(::dux::usz const _pos,::dux::usz const _sz) const -> ::dux::arr<T> { + auto const sz = [&]() { + if (_sz == 0x0uz) { + return this->sz() - _sz; + } + return _sz; + }(); + ::dux::arr<T> arr; + if (this->isstatic()) [[unlikely]] { + arr._sz = sz; + arr._ptr = const_cast<T *>(this->begin()) + _pos; + } + else { + arr.alloc(sz); + ::dux::cpyn(this->begin(),sz,arr.begin()); + } + return arr; +} +template<typename T> constexpr auto ::dux::arr<T>::sz() const noexcept -> ::dux::usz { + return this->_sz; +} +template<typename T> constexpr ::dux::arr<T>::~arr<T>() noexcept { + if (this->isstatic()) { + return; + } + ::delete[] this->_ptr; +} diff --git a/include/dux/arr.hh b/include/dux/arr.hh new file mode 100644 index 0000000..10822c2 --- /dev/null +++ b/include/dux/arr.hh @@ -0,0 +1,61 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace dux { + template<typename T> class arr { + public: + constexpr auto alloc( ::dux::usz num) -> void; + template<::dux::cnvto<T> T0> constexpr auto alloc( ::dux::usz num, T0 val) -> void; + constexpr auto app( ::dux::arr<T> const & oth) -> ::dux::arr<T> const &; + template<::dux::cnvto<T> T0> constexpr auto app( T0 val) -> ::dux::arr<T> const &; + [[nodiscard]] constexpr arr() noexcept = default; + [[nodiscard]] constexpr arr( T const * begin, T const * end); + [[nodiscard]] constexpr arr( ::dux::usz num); + [[nodiscard]] constexpr arr( ::dux::arr<T> const & oth); + [[nodiscard]] constexpr arr( ::dux::arr<T> && oth); + template<::dux::usz N> [[nodiscard]] constexpr arr( T const (& arr)[N]) noexcept; + template<::dux::cnvto<T> T0> [[nodiscard]] constexpr arr( ::dux::usz num, T0 val); + [[nodiscard]] constexpr auto begin() noexcept -> T *; + [[nodiscard]] constexpr auto begin() const noexcept -> T const *; + [[nodiscard]] constexpr auto cbegin() const noexcept -> T const *; + [[nodiscard]] constexpr auto cend() const noexcept -> T const *; + constexpr auto del( ::dux::usz pos) -> void; + [[nodiscard]] constexpr auto end() noexcept -> T *; + [[nodiscard]] constexpr auto end() const noexcept -> T const *; + template<::dux::cnvto<T> T0> constexpr auto fill( T0 val) -> void; + template<::dux::cnvto<T> T0> constexpr auto fill( T * begin, T * end,T0 val) -> void; + constexpr auto ins( ::dux::arr<T> const & oth, ::dux::usz pos) -> ::dux::arr<T> const &; + constexpr auto ins( T const * begin, T const * end,::dux::usz pos) -> ::dux::arr<T> const &; + [[nodiscard]] constexpr auto isstatic() const noexcept -> bool; + constexpr auto operator = ( ::dux::arr<T> const & oth) -> ::dux::arr<T> const &; + [[nodiscard]] constexpr auto operator [] (::dux::usz pos) -> T &; + [[nodiscard]] constexpr auto operator [] (::dux::usz pos) const -> T const &; + constexpr auto realloc( ::dux::usz num) -> void; + constexpr auto setraw( T const * ptr, ::dux::usz sz) noexcept -> void; + [[nodiscard]] constexpr auto sub( ::dux::usz pos, ::dux::usz sz) const -> ::dux::arr<T>; + [[nodiscard]] constexpr auto sz() const noexcept -> ::dux::usz; + constexpr ~arr() noexcept; + private: + bool _isstatic{false}; + T * _ptr {nullptr}; + ::dux::usz _sz {0x0uz}; + }; +} + +#include <dux/arr.d/arr.hh> diff --git a/include/dux/base b/include/dux/base new file mode 100644 index 0000000..bec2c6e --- /dev/null +++ b/include/dux/base @@ -0,0 +1,25 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#if !defined(dux_hdr_base) +#define dux_hdr_base + +#include <dux/base.hh> + +#endif diff --git a/include/dux/base.d/opt.hh b/include/dux/base.d/opt.hh new file mode 100644 index 0000000..e779233 --- /dev/null +++ b/include/dux/base.d/opt.hh @@ -0,0 +1,55 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename T> constexpr auto ::dux::opt<T>::operator * () const -> T const & { + if (!*this) [[unlikely]] { + throw ::dux::badoptacs(); + } + return this->_val; +} +template<typename T> constexpr auto ::dux::opt<T>::operator -> () const -> T const * { + if (!*this) [[unlikely]] { + throw ::dux::badoptacs(); + } + return &**this; +} +template<typename T> constexpr auto ::dux::opt<T>::operator = (::dux::opt<T> const & _oth) -> ::dux::opt<T> const & { + if (!_oth) { + this->reset(); + return *this; + } + this->_has = true; + this->_val = *_oth; + return *this; +} +template<typename T> constexpr ::dux::opt<T>::opt(T const & _val) noexcept { + this->_has = true; + this->_val = _val; +} +template<typename T> constexpr ::dux::opt<T>::opt(::dux::opt<T> const & _oth) noexcept { + this->operator = (_oth); +} +template<typename T> constexpr auto ::dux::opt<T>::set(T const & _val) noexcept { + this->_val = _val; + this->_has = true; +} +template<typename T> constexpr auto ::dux::opt<T>::reset() noexcept -> void { + this->_has = false; + ::new (&this->_val) T; /* Placement new: used for "uninitialising" a variable (I think). */ +} diff --git a/include/dux/base.d/tup.hh b/include/dux/base.d/tup.hh new file mode 100644 index 0000000..432ff9c --- /dev/null +++ b/include/dux/base.d/tup.hh @@ -0,0 +1,43 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace dux { + template<typename Fn,typename... Ts,::dux::usz... N> [[nodiscard]] constexpr auto _tupapply(Fn && fn,::dux::tup<Ts...> const & tup,::dux::intseq<::dux::usz,N...>) -> decltype(auto); +} + +template<typename Fn,typename... Ts,::dux::usz... N> [[nodiscard]] constexpr auto ::dux::_tupapply(Fn && _fn,::dux::tup<Ts...> const & _tup,::dux::intseq<::dux::usz,N...>) -> decltype(auto) { + return _fn(_tup.template get<N>()...); +} +template<typename T,typename... Ts> template<typename Fn> constexpr auto ::dux::tup<T,Ts...>::apply(Fn const & _fn) const -> decltype(auto) { + return ::dux::_tupapply(_fn,*this,dux::mkintseq<::dux::usz,0x1uz + sizeof...(Ts)>{}); +} +template<typename T,typename... Ts> template<::dux::usz N> constexpr auto ::dux::tup<T,Ts...>::get() const noexcept -> auto { + return static_cast<::dux::_tupbase<N,typename ::dux::_tupgettyp<N,T,Ts...>::typ> const *>(this)->get(); +} +template<typename T,typename... Ts> template<typename T0,typename... Ts0> constexpr auto ::dux::tup<T,Ts...>::operator == (::dux::tup<T0,Ts0...> const & _oth) noexcept -> bool { + if constexpr (!::dux::issame<decltype(*this),decltype(_oth)>) { + return false; + } + else { + constexpr auto num{sizeof...(Ts)}; + if constexpr (num == 0x0uz) { + return true; + } + } +} diff --git a/include/dux/base.hh b/include/dux/base.hh new file mode 100644 index 0000000..32e4060 --- /dev/null +++ b/include/dux/base.hh @@ -0,0 +1,466 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +/* + base > algo ─>┬> arr ─>┬> str > sys >┬> io + └> cstr >┘ ├> media + └> thrd +*/ + +#if defined(__clang__) +#define dux_cmp_clang +#endif +#if defined(__INTEL_COMPILER) +#define dux_cmp_icc +#endif +#if defined(_MSC_VER) +#define dux_cmp_msvc +#endif +#if defined(__GNUG__) && (!defined(dux_cmp_clang) || !defined(dux_cmp_icc)) +#define dux_cmp_gcc +#endif + +#if defined(__TOS_AIX__) || defined(_AIX) +#define dux_os_aix +#endif +#if defined(__amigaos__) +#define dux_os_amigaos +#endif +#if defined(__ANDROID__) +#define dux_os_android +#endif +#if defined(__THW_BLUEGENE__) || defined(__TOS_BGQ__) || defined(__bg__) || defined(__bgq__) +#define dux_os_bluegene +#endif +#if defined(__DragonFly__) +#define dux_os_dragonflybsd +#endif +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#define dux_os_freebsd +#endif +#if defined(__BEOS__) +#define dux_os_haiku +#endif +#if defined(__hpux) || defined(_hpux) +#define dux_os_hpux +#endif +#if defined(__GNU__) || defined(__gnu_hurd__) +#define dux_os_hurd +#endif +#if defined(__OS400__) || defined(__OS400_TGTVRM__) +#define dux_os_ibmi +#endif +#if defined(__INTEGRITY) +#define dux_os_integrity +#endif +#if defined(__APPLE__) || defined(__MACH__) +#define dux_os_mac +#endif +#if defined(__minix) +#define dux_os_minix +#endif +#if defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) +#define dux_os_msdos +#endif +#if defined(__NetBSD__) +#define dux_os_netbsd +#endif +#if defined(__OpenBSD__) +#define dux_os_openbsd +#endif +#if defined(__OS2__) || defined(__TOS_OS2__) || defined(_OS2) +#define dux_os_os2 +#endif +#if defined(__sun) +#define dux_os_solaris +#endif +#if defined(__TOS_WIN__) || defined(__WIN32__) || defined(__WINDOWS__) || defined(_WIN16) || defined(_WIN32) || defined(_WIN32_CE) || defined(_WIN64) +#define dux_os_win +#endif +#if defined(__HOS_MVS__) || defined(__MVS__) || defined(__TOS_MVS__) +#define dux_os_zos +#endif +#if defined(_SYSTYPE_BSD) || defined(dux_os_dragonflybsd) || defined(dux_os_freebsd) || defined(dux_os_netbsd) || defined(dux_os_openbsd) +#define dux_os_bsd +#elif __has_include(<sys/param.h>) +#include <sys/param.h> +#if defined(BSD) +#define dux_os_bsd +#endif +#endif +#if defined(__linux__) || defined(dux_os_android) +#define dux_os_linux +#endif +#if defined(__unix) || defined(__unix__) || defined(dux_os_aix) || defined(dux_os_android)|| defined(dux_os_bsd) || defined(dux_os_hpux) || defined(dux_os_hurd) || defined(dux_os_linux) || defined(dux_os_mac) || defined(dux_os_minix) || defined(dux_os_solaris) +#define dux_os_posix +#elif __has_include(<unistd.h>) +#include <unistd.h> +#if defined(_POSIX_VERSION) +#define dux_os_posix +#endif +#endif + +#include <exception> /* This is the one STDLIB dependency which we cannot get rid of. By making our exception class ((::dux::except)) inherit from (::std::exception), we can get the exception message to be displayed on terminate. Luckily, this header is (in theory) small. */ + +#if defined(__has_builtin) +#define dux_hasbuiltin(builtin) __has_builtin(builtin) +#else +#define dux_hasbuiltin(builtin) false +#endif + +#if defined(dux_os_posix) /* POSIX requires the size of bytes (in bits) to be exactly 8. We can use this knowledge to decrease our STDLIB dependencies. */ +#define dux_bytesz 0x8u +#elif defined(dux_cmp_clang) || defined(dux_cmp_gcc) /* Nice! Clang and GCC define the (__CHAR_BIT) macro. */ +#define dux_bytesz __CHAR_BIT +#else /* :( */ +#include <climits> /* CHAR_BIT */ +#define dux_bytesz CHAR_BIT +#endif + +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) +#define dux_intmax __INT_MAX__ +#define dux_llongmax __LONG_LONG_MAX__ +#define dux_longmax __LONG_MAX__ +#define dux_shrtmax __SHRT_MAX__ +#else +#include <climits> +#define dux_intmax INT_MAX +#define dux_llongmax LLONG_MAX +#define dux_longmax LONG_MAX +#define dux_shrtmax SHRT_MAX +#endif + +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) || defined(dux_cmp_icc) +#define dux_attr_abitag( ...) gnu::abi_tag(__VA_ARGS__) +#define dux_attr_allocsz( ...) gnu::alloc_size(__VA_ARGS__) +#define dux_attr_artif gnu::artificial +#define dux_attr_cold gnu::cold +#define dux_attr_const gnu::const +#define dux_attr_fmt gnu::format +#define dux_attr_malloc gnu::malloc +#define dux_attr_nonnull( ...) gnu::nonnull(__VA_ARGS__) +#define dux_attr_hot gnu::hot +#define dux_attr_inline gnu::always_inline +#define dux_attr_pure gnu::pure +#define dux_attr_retnonnull gnu::returns_nonnull +#define dux_attr_sect( ...) gnu::section(__VA_ARGS__) +#else +#define dux_attr_abitag( ...) +#define dux_attr_allocsz( ...) +#define dux_attr_artif +#define dux_attr_cold +#define dux_attr_const +#define dux_attr_fmt +#define dux_attr_hot +#define dux_attr_inline +#define dux_attr_malloc +#define dux_attr_nonnull( ...) +#define dux_attr_pure +#define dux_attr_retnonnull +#define dux_attr_sect( ...) +#endif +#if defined(dux_cmp_clang) +#define dux_attr_noderef clang::noderef +#define dux_attr_noesc( ...) clang::noescape(__VA_ARGS__) +#else +#define dux_attr_noderef +#define dux_attr_noesc( ...) +#endif + +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) || defined(dux_cmp_icc) +#define dux_fnnm __PRETTY_FUNCTION__ +#elif defined(dux_cmp_msvc) +#define dux_fnnm __FUNCSIG__ +#else +#define dux_fnnm __func__ +#endif + + +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) +#define dux_restr __restrict__ +#elif defined(dux_cmp_icc) || defined(dux_cmp_msvc) +#define dux_restr __restrict +#else +#define dux_restr +#endif + +namespace dux { + using ubyte = unsigned char; + using sbyte = signed char; + template<typename T> consteval auto ubytev(T const & _val) noexcept {return static_cast<::dux::ubyte>(_val);} + template<typename T> consteval auto sbytev(T const & _val) noexcept {return static_cast<::dux::sbyte>(static_cast<::dux::ubyte>(_val));} /* We cast to the unsigned equivalent type first to avoid undefined behavoir, which will stop compilation, as we are in an immediate function. */ + + constexpr auto bytesz{static_cast<::dux::ubyte>(dux_bytesz)}; + + template<typename T,typename T0> struct _issame {constexpr static auto issame{false};}; + template<typename T> struct _issame<T,T> {constexpr static auto issame{true};}; + template<typename T,typename T0> constexpr auto issame{::dux::_issame<T,T0>::issame}; + + template<typename T> struct _remconst {using t = T;}; + template<typename T> struct _remconst<T const> {using t = T;}; + template<typename T> using remconst = typename ::dux::_remconst<T>::t; + + template<typename T> struct _remrestr {using t = T;}; + template<typename T> struct _remrestr<T * dux_restr> {using t = T *;}; + template<typename T> using remrestr = typename ::dux::_remrestr<T>::t; + + template<typename T> struct _remvolat {using t = T;}; + template<typename T> struct _remvolat<T volatile> {using t = T;}; + template<typename T> using remvolat = typename ::dux::_remvolat<T>::t; + + template<typename T> using remcr = typename ::dux::remrestr<::dux::remconst<T>>; + template<typename T> using remcrv = typename ::dux::remrestr<::dux::remvolat<::dux::remconst<T>>>; + template<typename T> using remcv = typename ::dux::remvolat<::dux::remconst<T>>; + template<typename T> using remvr = typename ::dux::remrestr<::dux::remvolat<T>>; + + using _flt128 = +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) + __float128; +#else + long double; +#endif + using _uint128 = +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) + unsigned __int128; +#else + unsigned long long; +#endif + using _sint128 = +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) + __int128; +#else + long long; +#endif + + template<typename T,typename T0> constexpr auto iscnvto = requires {static_cast<T>(T0{});}; + template<typename T,typename T0> concept cnvto = ::dux::iscnvto<T,T0>; + template<typename T> constexpr auto issint = ::dux::issame<T,::dux::_sint128> || ::dux::issame<T,int> || ::dux::issame<T,long> || ::dux::issame<T,long long> || ::dux::issame<T,short> || ::dux::issame<T,signed char>; + template<typename T> concept sint = ::dux::issint<T>; + template<typename T> constexpr auto isuint = ::dux::issame<T,::dux::_uint128> || ::dux::issame<T,unsigned> || ::dux::issame<T,unsigned char> || ::dux::issame<T,unsigned long> || ::dux::issame<T,unsigned long long> || ::dux::issame<T,unsigned short>; + template<typename T> concept uint = ::dux::isuint<T>; + template<typename T> constexpr auto ischr = ::dux::issame<T,char> || ::dux::issame<T,char16_t> || ::dux::issame<T,char32_t> || ::dux::issame<T,char8_t> || ::dux::issame<T,wchar_t>; + template<typename T> concept chr = ::dux::ischr<T>; + template<typename T> constexpr auto isflt = ::dux::issame<T,::dux::_flt128> || ::dux::issame<T,double> || ::dux::issame<T,float> || ::dux::issame<T,long double>; + template<typename T> concept flt = ::dux::isflt<T>; + template<typename T> constexpr auto isnullptrtyp = ::dux::issame<T,decltype(nullptr)>; + template<typename T> constexpr auto isutf = ::dux::issame<T,char16_t> || ::dux::issame<T,char32_t> || ::dux::issame<T,char8_t>; + template<typename T> concept utf = ::dux::isutf<T>; + template<typename T> constexpr auto isvoid = ::dux::issame<T,void>; + template<typename T> concept void_ = ::dux::isvoid<T>; + + template<typename T> struct _isptr {constexpr static auto isptr{false};}; + template<typename T> struct _isptr<T *> {constexpr static auto isptr{true};}; + template<typename T> constexpr auto isptr = ::dux::_isptr<T>::isptr; + + template<typename T> constexpr auto isint = ::dux::issame<T,char> || ::dux::issint<T> || ::dux::isuint<T>; + template<typename T> concept int_ = ::dux::isint<T>; + + template<typename T> constexpr auto isarith = ::dux::isflt<T> || ::dux::isint<T>; + template<typename T> concept arith = ::dux::isarith<T>; + + template<typename T> struct _sign {using t = T;}; + template<> struct _sign<char> {using t = signed char;}; + template<> struct _sign<unsigned> {using t = int;}; + template<> struct _sign<unsigned char> {using t = signed char;}; + template<> struct _sign<unsigned long> {using t = long;}; + template<> struct _sign<unsigned long long> {using t = long long;}; +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) + template<> struct _sign<unsigned __int128> {using t = __int128;}; +#endif + template<::dux::int_ T> using sign = typename ::dux::_sign<T>::t; + + template<typename T> struct _unsign {using t = T;}; + template<> struct _unsign<char> {using t = unsigned char;}; + template<> struct _unsign<int> {using t = unsigned;}; + template<> struct _unsign<long> {using t = unsigned long;}; + template<> struct _unsign<long long> {using t = unsigned long long;}; + template<> struct _unsign<signed char> {using t = unsigned char;}; +#if defined(dux_cmp_clang) || defined(dux_cmp_gcc) + template<> struct _unsign<__int128> {using t = unsigned __int128;}; +#endif + template<::dux::int_ T> using unsign = typename ::dux::_unsign<T>::t; + + using uint16 = +#if dux_bytesz >= 0x10u + unsigned char; +#else + unsigned short; +#endif + using uint32 = +#if dux_bytesz >= 0x20u + unsigned char; +#elif dux_shrtmax >= 0x7FFFFFFFu + unsigned short; +#elif dux_intmax >= 0x7FFFFFFFu + unsigned int; +#else + unsigned long; +#endif + using uint64 = +#if dux_bytesz >= 0x40u + unsigned char; +#elif dux_shrtmax >= 0x7FFFFFFFFFFFFFFFu + unsigned short; +#elif dux_intmax >= 0x7FFFFFFFFFFFFFFFu + unsigned int; +#elif dux_longmax >= 0x7FFFFFFFFFFFFFFFu + unsigned long; +#else + unsigned long long; +#endif + using sint16 = ::dux::sign<::dux::uint16>; + using sint32 = ::dux::sign<::dux::uint32>; + using sint64 = ::dux::sign<::dux::uint64>; + template<typename T> consteval auto uint16v(T const & _val) noexcept {return static_cast<::dux::uint16>(_val);} + template<typename T> consteval auto sint16v(T const & _val) noexcept {return static_cast<::dux::sint16>(static_cast<::dux::uint16>(_val));} + template<typename T> consteval auto uint32v(T const & _val) noexcept {return static_cast<::dux::uint32>(_val);} + template<typename T> consteval auto sint32v(T const & _val) noexcept {return static_cast<::dux::sint32>(static_cast<::dux::uint32>(_val));} + template<typename T> consteval auto uint64v(T const & _val) noexcept {return static_cast<::dux::uint64>(_val);} + template<typename T> consteval auto sint64v(T const & _val) noexcept {return static_cast<::dux::sint64>(static_cast<::dux::uint64>(_val));} + + using usz = decltype(0x0uz); + using ssz = decltype(0x0z); + + using nullptrtyp = decltype(nullptr); + + enum class endi : bool { + big = true, + little = false, + }; + + enum class stat : ::dux::ubyte { + err = ::dux::ubytev(0x1), + ok = ::dux::ubytev(0x0), + }; + + class except : public ::std::exception { + public: + [[nodiscard]] except() noexcept : _what("") {} + [[nodiscard]] except(char const * _what) noexcept : _what(_what) {} + virtual auto what() const noexcept -> char const * {return this->_what;} + private: + char const * const dux_restr _what; + }; + class badalloc : public ::dux::except { + public: + using ::dux::except::except; + }; + class badio : public ::dux::except { + public: + using ::dux::except::except; + }; + class badoptacs : public ::dux::except { + public: + using ::dux::except::except; + }; + class invalarg : public ::dux::except { + public: + using ::dux::except::except; + }; + class invalutf : public ::dux::except { + public: + using ::dux::except::except; + }; + class outofdomain : public ::dux::except { + public: + using ::dux::except::except; + }; + class runerr : public ::dux::except { + public: + using ::dux::except::except; + }; + + template<::dux::int_ T,T... Ints> class intseq { + public: + constexpr static auto sz{0x1uz + sizeof...(Ints)}; + }; + template<::dux::int_ T,T N> using mkintseq = +#if dux_hasbuiltin(__make_integer_seq) /* Clang has this builtin for this exact purpose. */ + __make_integer_seq<::dux::intseq,T,N>; +#elif dux_hasbuiltin(__integer_pack) + ::dux::intseq<__integer_pack(N)...>; +#else + ::dux::intseq<T,N>; +_Pragma("message \"Cannot implement (::dux::mkintseq)!\""); +#endif + + template<typename T> class opt { + public: + [[nodiscard]] constexpr auto operator * () const -> T const &; + [[nodiscard]] constexpr auto operator -> () const -> T const *; + constexpr auto operator = ( ::dux::opt<T> const & oth) -> ::dux::opt<T> const &; + [[nodiscard]] constexpr explicit operator bool () const noexcept {return this->_has;} + [[nodiscard]] constexpr opt() noexcept = default; + [[nodiscard]] constexpr opt( T const & val) noexcept; + [[nodiscard]] constexpr opt( ::dux::opt<T> const & oth) noexcept; + constexpr auto set( T const & val) noexcept; + constexpr auto reset() noexcept -> void; + private: + bool _has{false}; + T _val; + }; + + template<::dux::usz N,typename T> class _tupbase { + public: + [[nodiscard]] constexpr _tupbase() noexcept = default; + [[nodiscard]] constexpr _tupbase(T const & _val) noexcept {this->_val = _val;} + [[nodiscard]] constexpr auto get() const noexcept -> T const & {return this->_val;} + private: + T _val; + }; + template<::dux::usz N, typename... Ts> class _tuprecurbase {}; + template<::dux::usz N, typename T, typename... Ts> class _tuprecurbase<N,T,Ts...> : public ::dux::_tupbase<N,T>,public ::dux::_tuprecurbase<N + 0x1uz,Ts...> { + public: + [[nodiscard]] constexpr _tuprecurbase() noexcept = default; + template<typename T0,typename... Ts0> [[nodiscard]] constexpr _tuprecurbase(T0 const & _val,Ts0 const &... _vals) noexcept : ::dux::_tupbase<N,T0>(_val), ::dux::_tuprecurbase<N + 0x1uz,Ts...>(_vals...) {}; + }; + template<::dux::usz N,typename T,typename... Ts> class _tupgettyp { + public: + using typ = typename ::dux::_tupgettyp<N - 0x1uz,Ts...>::typ; + }; + template<typename T,typename... Ts> class _tupgettyp<0x0uz,T,Ts...> { + public: + using typ = T; + }; + template<typename T, typename... Ts> class tup : public ::dux::_tuprecurbase<0x0uz,T,Ts...> { + public: + template<typename Fn> [[nodiscard]] constexpr auto apply( Fn const & fn) const -> decltype(auto); + template<::dux::usz N> [[nodiscard]] constexpr auto get() const noexcept -> auto; + template<typename T0, typename... Ts0> [[nodiscard]] constexpr auto operator == (::dux::tup<T0,Ts0...> const & oth) noexcept -> bool; + [[nodiscard]] constexpr tup() noexcept = default; + [[nodiscard]] constexpr tup( T const & _val,Ts const &... _vals) noexcept : ::dux::_tuprecurbase<0x0uz,T,Ts...>(_val,_vals...) {} + + constexpr static auto sz{0x1uz + sizeof...(Ts)}; + }; + + constexpr auto dbg{[]() { +#if defined(NDEBUG) + return false; +#else + return true; +#endif + }()}; + constexpr auto lorem {U"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."}; + constexpr auto npos {-0x1uz}; + constexpr auto unimax{U'\U00010FFF'}; + constexpr auto ver {::dux::uint64v(0x1D)}; +} + +#include <dux/base.d/opt.hh> +#include <dux/base.d/tup.hh> diff --git a/include/dux/cstr b/include/dux/cstr new file mode 100644 index 0000000..2089c7c --- /dev/null +++ b/include/dux/cstr @@ -0,0 +1,26 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#if !defined(dux_hdr_cstr) +#define dux_hdr_cstr + +#include <dux/algo> +#include <dux/cstr.hh> + +#endif diff --git a/u8c/include/u8c/cstr.d/cstrcmp b/include/dux/cstr.d/cstrcmp.hh index 9615ad2..ad262dc 100644 --- a/u8c/include/u8c/cstr.d/cstrcmp +++ b/include/dux/cstr.d/cstrcmp.hh @@ -1,43 +1,35 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_hQ3g8CRKOedpjvM7) -#define u8c_key_hQ3g8CRKOedpjvM7 - - -#include <algorithm> /* std::min */ - -constexpr auto u8c::cstrcmp(char const * const u8c_restr _lstr,char const * const u8c_restr _rstr) noexcept -> u8c::byte { - auto const maxn = std::min(u8c::cstrlen(_lstr),u8c::cstrlen(_rstr)); +constexpr auto ::dux::cstrcmp(char const * const dux_restr _lstr,char const * const dux_restr _rstr) noexcept -> ::dux::sbyte { + auto const maxn = ::dux::min(::dux::cstrlen(_lstr),::dux::cstrlen(_rstr)); for (auto n = 0x0uz;n <= maxn;n += 0x1uz) { auto const lchr = _lstr[n]; auto const rchr = _rstr[n]; if (lchr != rchr) [[unlikely]] { if (lchr > rchr) { - return u8c_bytec(-0x1); + return ::dux::sbytev(-0x1); } if (lchr < rchr) { - return u8c_bytec(0x1); + return ::dux::sbytev(0x1); } } } - return u8c_bytec(0x0); + return ::dux::sbytev(0x0); } - -#endif diff --git a/u8c/include/u8c/cstr.d/cstrcpy b/include/dux/cstr.d/cstrcpy.hh index 37cad96..a8e5f65 100644 --- a/u8c/include/u8c/cstr.d/cstrcpy +++ b/include/dux/cstr.d/cstrcpy.hh @@ -1,34 +1,27 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_MvAfxuZelp52mHk5) -#define u8c_key_MvAfxuZelp52mHk5 - -#include <algorithm> /* std::copy */ - -constexpr auto u8c::cstrcpy(char * const u8c_restr _dest,char const * const u8c_restr _src) noexcept -> char * { - auto const sz = u8c::cstrlen(_src); +constexpr auto ::dux::cstrcpy(char * const dux_restr _dest,char const * const dux_restr _src) noexcept -> char * { + auto const sz = ::dux::cstrlen(_src); if (sz == 0x0uz) [[unlikely]] { return _dest; } - std::copy(_src,_src + sz - 0x1uz,_dest); + ::dux::cpy(_src,_src + sz - 0x1uz,_dest); return _dest; } - -#endif diff --git a/include/dux/cstr.d/cstrdup.hh b/include/dux/cstr.d/cstrdup.hh new file mode 100644 index 0000000..43ecc18 --- /dev/null +++ b/include/dux/cstr.d/cstrdup.hh @@ -0,0 +1,24 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +constexpr auto ::dux::cstrdup(char const * const dux_restr _str1) -> char * { + auto const sz = ::dux::cstrlen(_str1); + auto * const dux_restr str = ::new char[sz]; + return ::dux::cstrcpy(str,_str1); +} diff --git a/u8c/include/u8c/cstr.d/cstrlen b/include/dux/cstr.d/cstrlen.hh index 2f7cb5a..b8c8e58 100644 --- a/u8c/include/u8c/cstr.d/cstrlen +++ b/include/dux/cstr.d/cstrlen.hh @@ -1,28 +1,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_2yXSG12yvwzu2XCt) -#define u8c_key_2yXSG12yvwzu2XCt - -constexpr auto u8c::cstrlen(char const * const u8c_restr _str) noexcept -> u8c::size { +constexpr auto ::dux::cstrlen(char const * const dux_restr _str) noexcept -> ::dux::usz { auto sz = 0x0uz; - for (u8c::size n = 0x0uz;;n += 0x1uz) { + for (::dux::usz n = 0x0uz;;n += 0x1uz) { if (_str[n] == '\u0000') [[unlikely]] { break; } @@ -30,5 +27,3 @@ constexpr auto u8c::cstrlen(char const * const u8c_restr _str) noexcept -> u8c:: } return sz; } - -#endif diff --git a/include/dux/cstr.hh b/include/dux/cstr.hh new file mode 100644 index 0000000..7361f90 --- /dev/null +++ b/include/dux/cstr.hh @@ -0,0 +1,30 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace dux { + [[nodiscard]] constexpr auto cstrcmp(char const * lstr,char const * rstr) noexcept -> ::dux::sbyte; + [[nodiscard]] constexpr auto cstrcpy(char * dest,char const * src) noexcept -> char *; + [[nodiscard]] constexpr auto cstrdup(char const * str) -> char *; + [[nodiscard]] constexpr auto cstrlen(char const * str) noexcept -> ::dux::usz; +} + +#include <dux/cstr.d/cstrcmp.hh> +#include <dux/cstr.d/cstrcpy.hh> +#include <dux/cstr.d/cstrdup.hh> +#include <dux/cstr.d/cstrlen.hh> diff --git a/include/dux/io b/include/dux/io new file mode 100644 index 0000000..3c4413e --- /dev/null +++ b/include/dux/io @@ -0,0 +1,26 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#if !defined(dux_hdr_io) +#define dux_hdr_io + +#include <dux/sys> +#include <dux/io.hh> + +#endif diff --git a/include/dux/io.d/dbgprint.hh b/include/dux/io.d/dbgprint.hh new file mode 100644 index 0000000..3e9d0cd --- /dev/null +++ b/include/dux/io.d/dbgprint.hh @@ -0,0 +1,24 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<typename... Ts> constexpr auto ::dux::dbgprint(::dux::str const & _str,Ts... _args) -> void { + if constexpr (::dux::dbg) { + ::dux::print(_str,_args...); + } +} diff --git a/include/dux/io.d/fmt.hh b/include/dux/io.d/fmt.hh new file mode 100644 index 0000000..bf907f7 --- /dev/null +++ b/include/dux/io.d/fmt.hh @@ -0,0 +1,45 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +constexpr auto ::dux::fmt(::dux::str const & _str) -> ::dux::str { + if (auto const pos = _str.fnd(::dux::fmtchr);pos != ::dux::npos) { + throw ::dux::fmterr("Format-specifier '$' was found, but no object to be formatted was provided."); + } + return _str; +} +template<typename T> constexpr auto ::dux::fmt(::dux::str const & _str,T const _fmt) -> ::dux::str { + auto const pos = _str.fnd(::dux::fmtchr); + if (pos == ::dux::npos) { + throw ::dux::fmterr("Object to be formatted provided, but an equivalent format-specifier '$' was not found!"); + } + auto str = _str; + str.del(pos); + str.ins(pos,::dux::fmter(_fmt)); + return str; +} +template<typename T,typename... Ts> constexpr auto ::dux::fmt(::dux::str const & _str,T const _fmt,Ts... args) -> ::dux::str { + auto const pos = _str.fnd(::dux::fmtchr); + if (pos == ::dux::npos) { + throw ::dux::fmterr("Object to be formatted provided, but an equivalent format-specifier '$' was not found!"); + } + auto str = _str; + str.del(pos); + str.ins(pos,::dux::fmter(_fmt)); + return str + ::dux::fmt(_str.sub(pos + 0x1uz,0x0uz),args...); +} diff --git a/include/dux/io.d/fmter.hh b/include/dux/io.d/fmter.hh new file mode 100644 index 0000000..ef56ed1 --- /dev/null +++ b/include/dux/io.d/fmter.hh @@ -0,0 +1,98 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace dux::priv { + template<typename T> constexpr auto intfmter(T const _fmt) -> ::dux::str { + auto const fmt = [&]() { + if constexpr(::dux::isptr<T>) { + return (::dux::uint64)_fmt; + } + else { + return _fmt; + } + }(); + using T0 = decltype(fmt); + if constexpr (::dux::issint<T>) { + if (fmt < T0{0x0}) { + return ::dux::str(U'−') + ::dux::fmter(::dux::abs(fmt)); + } + } + if (fmt < ::dux::base) { + auto const nums = []() { + if (::dux::base == ::dux::ubytev(0xC)) { + return U"0123456789↊↋"; + } + return U"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + }(); + return nums[fmt]; + } + return ::dux::fmter(fmt / T0{::dux::base}) + ::dux::fmter(fmt % T0{::dux::base}); + } +} +template<> constexpr auto ::dux::fmter(bool const _fmt) -> ::dux::str { + if (_fmt) { + return U"true"; + } + return U"false"; +} +/*template<> constexpr auto ::dux::fmter(char16_t const * const dux_restr _fmt) -> ::dux::str { + return ::dux::str{_fmt}; +}*/ +template<> constexpr auto ::dux::fmter(char32_t const * const dux_restr _fmt) -> ::dux::str { + return ::dux::str{_fmt}; +} +template<> constexpr auto ::dux::fmter(char8_t const * const dux_restr _fmt) -> ::dux::str { + return ::dux::str{_fmt}; +} +template<> constexpr auto ::dux::fmter(int const _fmt) -> ::dux::str { + return ::dux::priv::intfmter(_fmt); +} +template<> constexpr auto ::dux::fmter(long const _fmt) -> ::dux::str { + return ::dux::priv::intfmter(_fmt); +} +template<> constexpr auto ::dux::fmter(long long const _fmt) -> ::dux::str { + return ::dux::priv::intfmter(_fmt); +} +template<> constexpr auto ::dux::fmter(short const _fmt) -> ::dux::str { + return ::dux::priv::intfmter(_fmt); +} +template<> constexpr auto ::dux::fmter(::dux::nullptrtyp) -> ::dux::str { + return U"nullptr"; +} +template<> constexpr auto ::dux::fmter(::dux::str const _fmt) -> ::dux::str { + return _fmt; +} +template<> constexpr auto ::dux::fmter(unsigned const _fmt) -> ::dux::str { + return ::dux::priv::intfmter(_fmt); +} +template<> constexpr auto ::dux::fmter(unsigned long const _fmt) -> ::dux::str { + return ::dux::priv::intfmter(_fmt); +} +template<> constexpr auto ::dux::fmter(unsigned long long const _fmt) -> ::dux::str { + return ::dux::priv::intfmter(_fmt); +} +template<> constexpr auto ::dux::fmter(unsigned short const _fmt) -> ::dux::str { + return ::dux::priv::intfmter(_fmt); +} +template<> constexpr auto ::dux::fmter(void const * const dux_restr _fmt) -> ::dux::str { + if (_fmt == nullptr) { + return ::dux::fmter(nullptr); + } + return ::dux::priv::intfmter(_fmt); +} diff --git a/include/dux/io.d/print.hh b/include/dux/io.d/print.hh new file mode 100644 index 0000000..3833583 --- /dev/null +++ b/include/dux/io.d/print.hh @@ -0,0 +1,30 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <cstdio> + +template<typename... Ts> constexpr auto ::dux::print(::dux::str const & _str,Ts... _args) -> void { + auto const str = ::dux::fmt(_str,_args...); + if (str.len() == 0x0uz) [[unlikely]] { + throw ::dux::invalarg("Too many format options!"); + } + if (::std::fwrite(str.u8().begin(),0x1uz,str.len(),stdout) < str.len()) { + throw ::dux::runerr("Unable to write to stout!"); + } +} diff --git a/include/dux/io.hh b/include/dux/io.hh new file mode 100644 index 0000000..b431cc6 --- /dev/null +++ b/include/dux/io.hh @@ -0,0 +1,44 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +/* + to-do: + Implement a prettier (and larger) API for I/O operations! +*/ + +namespace dux { + class fmterr : public ::dux::except { + public: + using ::dux::except::except; + }; + + template<typename... Ts> constexpr auto dbgprint(::dux::str const & str,Ts... args) -> void; + constexpr auto fmt( ::dux::str const & str) -> ::dux::str; + template<typename T> constexpr auto fmt( ::dux::str const & str,T fmt) -> ::dux::str; + template<typename T,typename... Ts> constexpr auto fmt( ::dux::str const & str,T fmt, Ts... args) -> ::dux::str; + template<typename T> constexpr auto fmter( T fmt) -> ::dux::str; + template<typename... Ts> constexpr auto print( ::dux::str const & str,Ts... args) -> void; + inline auto base {::dux::ubytev(0xC)}; + constexpr auto fmtchr{U'\u0024'}; +} + +#include <dux/io.d/dbgprint.hh> +#include <dux/io.d/fmt.hh> +#include <dux/io.d/fmter.hh> +#include <dux/io.d/print.hh> diff --git a/u8c/include/u8c/str.d/dbgprint b/include/dux/media index 4ecb6b9..bd00493 100644 --- a/u8c/include/u8c/str.d/dbgprint +++ b/include/dux/media @@ -1,32 +1,27 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_WQGQeKhIxLI16CtT) -#define u8c_key_WQGQeKhIxLI16CtT -#if 0x0 +#if !defined(dux_hdr_media) +#define dux_hdr_media -auto u8c::dbgprint(u8c::str const _msg) -> void { - if constexpr (u8c::dbg) { - return u8c::println(stderr,_msg); - } -} +#include <dux/sys> -#endif +#include <dux/media.hh> #endif diff --git a/include/dux/media.hh b/include/dux/media.hh new file mode 100644 index 0000000..70c748e --- /dev/null +++ b/include/dux/media.hh @@ -0,0 +1,54 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace dux { + enum class evttyp : ::dux::ubyte { + kbd, + mus, + quit, + resz, + unknwn, + }; + + class evt { + public: + ::dux::evttyp typ{::dux::evttyp::unknwn}; + }; + + class win { + public: + auto close() -> void; + auto mv( ::dux::uint16 x, ::dux::uint16 y) -> void; + [[nodiscard]] static auto crt( char const * nm,::dux::uint16 w,::dux::uint16 h) -> ::dux::win; + auto destr() noexcept -> void; + auto open() -> void; + auto renm( char const * nm) -> void; + auto resz( ::dux::uint16 w, ::dux::uint16 h) -> void; + auto pollevt() noexcept -> ::dux::opt<::dux::evt>; + [[nodiscard]] win(); + [[nodiscard]] win( ::dux::win const & oth); + ~win() noexcept; + private: + void * const dux_restr _dat; + bool _isopen{false}; + }; + + auto endgfx() -> void; + auto initgfx() -> void; +} diff --git a/include/dux/str b/include/dux/str new file mode 100644 index 0000000..57856e7 --- /dev/null +++ b/include/dux/str @@ -0,0 +1,28 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#if !defined(dux_hdr_str) +#define dux_hdr_str + +#include <dux/arr> +#include <dux/cstr> + +#include <dux/str.hh> + +#endif diff --git a/include/dux/str.d/cnv.hh b/include/dux/str.d/cnv.hh new file mode 100644 index 0000000..13c9d1a --- /dev/null +++ b/include/dux/str.d/cnv.hh @@ -0,0 +1,105 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +template<::dux::utf T,::dux::utf T0> constexpr auto ::dux::cnv(T0 const * const dux_restr _begin,T0 const * const dux_restr _end) -> ::dux::arr<T> { + if (_begin == nullptr || _end == nullptr) [[unlikely]] { + throw ::dux::invalarg("Null pointer provided as parameter."); + } + ::dux::arr<T0> in(_begin,_end); + ::dux::arr<T> out; + if constexpr (::dux::issame<T0,T>) { + out.alloc(static_cast<::dux::usz>(_end - _begin)); + ::dux::cpy(_begin,_end,out.begin()); + return out; + } + else { + if constexpr (::dux::issame<T0,char16_t>) { + } + else if constexpr (::dux::issame<T0,char32_t>) { + for (auto const tmp : in) { + if constexpr (::dux::issame<T,char16_t>) { + if (tmp >= ::dux::uint32v(0x10000)) { /* Two hextets. */ + char16_t const tmp0 = tmp - ::dux::uint16v(0x10000); + out.app((tmp0 / ::dux::uint16v(0x400) + ::dux::uint16v(0xD800))); + out.app((tmp0 % ::dux::uint16v(0x400) + ::dux::uint16v(0xDC00))); + } + else [[likely]] { + /* One hextet. */ + out.app((static_cast<char16_t>(tmp))); + } + } + else { + if (tmp >= ::dux::uint32v(0x10000)) { /* Four octets. */ + out.app((::dux::ubytev(0b11110000) + static_cast<char8_t>(tmp >> ::dux::uint32v(0x12) & ::dux::uint32v(0b00000111)))); + out.app((::dux::ubytev(0b10000000) + static_cast<char8_t>(tmp >> ::dux::uint32v(0xC) & ::dux::uint32v(0b00111111)))); + out.app((::dux::ubytev(0b10000000) + static_cast<char8_t>(tmp >> ::dux::uint32v(0x6) & ::dux::uint32v(0b00111111)))); + out.app((::dux::ubytev(0b10000000) + static_cast<char8_t>(tmp & ::dux::uint32v(0b00111111)))); + } + else if (tmp >= U'\u0800') { /* Three octets. */ + out.app((::dux::ubytev(0xE0) + static_cast<char8_t>(tmp >> ::dux::uint32v(0xC) & ::dux::uint32v(0b00001111)))); + out.app((::dux::ubytev(0x80) + static_cast<char8_t>(tmp >> ::dux::uint32v(0x6) & ::dux::uint32v(0b00111111)))); + out.app((::dux::ubytev(0x80) + static_cast<char8_t>(tmp & ::dux::uint32v(0b00111111)))); + } + else if (tmp >= U'\u0080') { /* Two octets. */ + out.app((::dux::ubytev(0xC0) + static_cast<char8_t>(tmp >> ::dux::uint32v(0x6) & ::dux::uint32v(0b00111111)))); + out.app((::dux::ubytev(0x80) + static_cast<char8_t>(tmp & ::dux::uint32v(0b00111111)))); + } + else [[likely]] { + /* One octet. */ + out.app(static_cast<char8_t>(tmp)); + } + } + } + } + else { + if constexpr (::dux::issame<T,char16_t>) { + } + else { + for (::dux::usz n = 0x0uz;n < in.sz();n += 0x1uz) { + auto const tmp = in[n]; + auto chr = U'\u0000'; + if (tmp >= ::dux::ubytev(0b11110000)) { /* Four octets. */ + chr = (tmp ^ ::dux::uint32v(0b11110000)) << ::dux::uint32v(0x12); + chr += (in[n + 0x1uz] ^ ::dux::uint32v(0b10000000)) << ::dux::uint32v(0xC); + chr += (in[n + 0x2uz] ^ ::dux::uint32v(0b10000000)) << ::dux::uint32v(0x6); + chr += in[n + 0x3uz] ^ ::dux::uint32v(0b10000000); + n += 0x3uz; + } + else if (tmp >= ::dux::ubytev(0b11100000)) { /* Three octets. */ + chr = (tmp ^ ::dux::uint32v(0b11100000)) << ::dux::uint32v(0xC); + chr += (in[n + 0x1uz] ^ ::dux::uint32v(0b10000000)) << ::dux::uint32v(0x6); + chr += in[n + 0x2uz] ^ ::dux::uint32v(0b10000000); + n += 0x2uz; + } + else if (tmp >= ::dux::ubytev(0b11000000)) { /* Two octets. */ + chr = (tmp ^ ::dux::uint32v(0b11000000)) << ::dux::uint32v(0x6); + chr += in[n + 0x1uz] ^ ::dux::uint32v(0b10000000); + n += 0x1uz; + } + else [[likely]] { + /* One octet. */ + chr = tmp; + } + out.app(chr); + } + } + } + } + return out; +} diff --git a/u8c/include/u8c/utf.d/isalnum b/include/dux/str.d/isalnum.hh index 0960e57..e7cc7aa 100644 --- a/u8c/include/u8c/utf.d/isalnum +++ b/include/dux/str.d/isalnum.hh @@ -1,32 +1,27 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_C8fUI0HFQi6fZDUx) -#define u8c_key_C8fUI0HFQi6fZDUx - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::isalpha(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::isalpha(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } - if(u8c::islower(_chr) || u8c::isupper(_chr)) [[unlikely]] { + if(::dux::islower(_chr) || ::dux::isupper(_chr)) [[unlikely]] { return true; } switch(_chr) { @@ -186,5 +181,3 @@ constexpr auto u8c::isalpha(char32_t const _chr) -> bool { return true; } } - -#endif
\ No newline at end of file diff --git a/include/dux/str.d/isalpha.hh b/include/dux/str.d/isalpha.hh new file mode 100644 index 0000000..49b5de6 --- /dev/null +++ b/include/dux/str.d/isalpha.hh @@ -0,0 +1,22 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +constexpr auto ::dux::isalnum(char32_t const _chr) -> bool { + return ::dux::isalpha(_chr) || ::dux::isdigit(_chr); +} diff --git a/u8c/include/u8c/utf.d/iscntrl b/include/dux/str.d/iscntrl.hh index 083bf52..f3e9cfb 100644 --- a/u8c/include/u8c/utf.d/iscntrl +++ b/include/dux/str.d/iscntrl.hh @@ -2,30 +2,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_KkxufRi4dPQDAbxV) -#define u8c_key_KkxufRi4dPQDAbxV - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::iscntrl(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::iscntrl(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } switch(_chr) { [[likely]] default: @@ -176,5 +171,3 @@ constexpr auto u8c::iscntrl(char32_t const _chr) -> bool { return true; } } - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/utf.d/isdigit b/include/dux/str.d/isdigit.hh index 84179e6..52f5bd4 100644 --- a/u8c/include/u8c/utf.d/isdigit +++ b/include/dux/str.d/isdigit.hh @@ -1,30 +1,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_8r8RPCDLujofbg3k) -#define u8c_key_8r8RPCDLujofbg3k - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::isdigit(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::isdigit(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } switch(_chr) { [[likely]] default: @@ -55,5 +50,3 @@ constexpr auto u8c::isdigit(char32_t const _chr) -> bool { return true; } } - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/utf.d/islower b/include/dux/str.d/islower.hh index 9fd40e6..0800573 100644 --- a/u8c/include/u8c/utf.d/islower +++ b/include/dux/str.d/islower.hh @@ -1,30 +1,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_AtxlGqMDj7uXYyKb) -#define u8c_key_AtxlGqMDj7uXYyKb - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::islower(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::islower(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } switch(_chr) { [[likely]] default: @@ -341,5 +336,3 @@ constexpr auto u8c::islower(char32_t const _chr) -> bool { return true; } } - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/utf.d/ispunct b/include/dux/str.d/ispunct.hh index f82f11e..bfa0ceb 100644 --- a/u8c/include/u8c/utf.d/ispunct +++ b/include/dux/str.d/ispunct.hh @@ -1,30 +1,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_tmcwLOAAPKkIUthE) -#define u8c_key_tmcwLOAAPKkIUthE - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::ispunct(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::ispunct(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } switch(_chr) { [[likely]] default: @@ -325,5 +320,3 @@ constexpr auto u8c::ispunct(char32_t const _chr) -> bool { return true; } } - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/utf.d/isspace b/include/dux/str.d/isspace.hh index ccf191a..79f3487 100644 --- a/u8c/include/u8c/utf.d/isspace +++ b/include/dux/str.d/isspace.hh @@ -1,30 +1,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_fRbwVyyBwfrm0Slq) -#define u8c_key_fRbwVyyBwfrm0Slq - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::isspace(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::isspace(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } switch(_chr) { [[likely]] default: @@ -43,5 +38,3 @@ constexpr auto u8c::isspace(char32_t const _chr) -> bool { return true; } } - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/utf.d/issurro b/include/dux/str.d/issurro.hh index 119c2e5..115bc0f 100644 --- a/u8c/include/u8c/utf.d/issurro +++ b/include/dux/str.d/issurro.hh @@ -1,35 +1,28 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_f4d3TezxF0FFmbn4) -#define u8c_key_f4d3TezxF0FFmbn4 - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::issurro(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::issurro(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } if(_chr >= U'\xD800' && _chr <= U'\xDFFF') [[unlikely]] { return true; } return false; } - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/utf.d/isupper b/include/dux/str.d/isupper.hh index 4a18fd5..7e96224 100644 --- a/u8c/include/u8c/utf.d/isupper +++ b/include/dux/str.d/isupper.hh @@ -1,30 +1,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_CNx6iimb2pI6RXGS) -#define u8c_key_CNx6iimb2pI6RXGS - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::isupper(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::isupper(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } switch(_chr) { [[likely]] default: @@ -261,5 +256,3 @@ constexpr auto u8c::isupper(char32_t const _chr) -> bool { return true; } } - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/utf.d/isxdigit b/include/dux/str.d/isxdigit.hh index cc73526..980ed5c 100644 --- a/u8c/include/u8c/utf.d/isxdigit +++ b/include/dux/str.d/isxdigit.hh @@ -1,30 +1,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_NdERYC9ToUZX0vHE) -#define u8c_key_NdERYC9ToUZX0vHE - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::isxdigit(char32_t const _chr) -> bool { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::isxdigit(char32_t const _chr) -> bool { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::outofdomain("Unicode codepoint too big!"); } switch(_chr) { [[likely]] default: @@ -64,5 +59,3 @@ constexpr auto u8c::isxdigit(char32_t const _chr) -> bool { return true; } } - -#endif
\ No newline at end of file diff --git a/include/dux/str.d/str.hh b/include/dux/str.d/str.hh new file mode 100644 index 0000000..d5bdf20 --- /dev/null +++ b/include/dux/str.d/str.hh @@ -0,0 +1,118 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +constexpr auto ::dux::str::begin() noexcept -> char32_t * { + return this->_arr.begin(); +} +constexpr auto ::dux::str::begin() const noexcept -> char32_t const * { + return this->_arr.begin(); +} +constexpr auto ::dux::str::cbegin() const noexcept -> char32_t const * { + return this->_arr.cbegin(); +} +constexpr auto ::dux::str::cend() const noexcept -> char32_t const * { + return this->_arr.cbegin(); +} +constexpr auto ::dux::str::del(::dux::usz const _pos) -> void { + this->_arr.del(_pos); +} +constexpr auto ::dux::str::end() noexcept -> char32_t * { + return this->_arr.end(); +} +constexpr auto ::dux::str::end() const noexcept -> char32_t const * { + return this->_arr.end(); +} +constexpr auto ::dux::str::fnd(char32_t const _chr) const noexcept -> ::dux::usz { + for (auto pos = 0x0uz;pos < this->len();pos += 0x1uz) { + if (this->operator [] (pos) == _chr) [[unlikely]] { + return pos; + } + } + return ::dux::npos; +} +constexpr auto ::dux::str::ins(::dux::usz const _pos,::dux::str const & _oth) -> ::dux::str const & { + this->_arr.ins(_oth._arr,_pos); + return *this; +} +constexpr auto ::dux::str::len() const noexcept -> ::dux::usz { + return this->_arr.sz(); +} +constexpr auto ::dux::str::operator + (::dux::str const & _oth) const -> ::dux::str { + auto str = *this; + str._arr.app(_oth._arr); + return str; +} +constexpr auto ::dux::str::operator = (::dux::str const & _oth) -> ::dux::str const & { + this->_arr = _oth._arr; + return *this; +} +constexpr auto ::dux::str::operator == (::dux::str const & _oth) const noexcept -> bool { + if (this->len() != _oth.len()) { + return false; + } + for (auto n = 0x0uz;n < this->len() && n < _oth.len();n += 0x1uz) { + if ((*this)[n] != _oth[n]) { + return false; + } + } + return true; +} +constexpr auto ::dux::str::operator [] (::dux::usz const _pos) noexcept -> char32_t & { + return this->_arr[_pos]; +} +constexpr auto ::dux::str::operator [] (::dux::usz const _pos) const noexcept -> char32_t const & { + return this->_arr[_pos]; +} +constexpr ::dux::str::str(char32_t const _chr) { + this->_arr.app(_chr); +} +constexpr ::dux::str::str(::dux::str const & _oth) { + *this = _oth; +} +constexpr ::dux::str::str(::dux::str && _oth) { + this->_arr.setraw(_oth._arr.begin(),_oth._arr.sz()); + _oth._arr.setraw(nullptr,0x0uz); +} +template<::dux::usz N> constexpr ::dux::str::str(char32_t const (& _strlit)[N]) noexcept { + this->_arr = _strlit; +} +template<::dux::utf T> constexpr ::dux::str::str(T const _chr) { + if constexpr (::dux::issame<T,char32_t>) { + this->_arr.alloc(0x1uz); + this->_arr[0x0uz] = _chr; + } +} +template<::dux::utf T> constexpr ::dux::str::str(T const * const dux_restr _utf) { + auto const sz = [&]() { + for (auto n = 0x0uz;;n += 0x1uz) { + if (_utf[n] == T{0x0}) { + return n; + } + } + }(); + this->_arr = ::dux::cnv<char32_t>(_utf,_utf + sz); +} +constexpr auto ::dux::str::sub(::dux::usz const _pos,::dux::usz const _len) const -> ::dux::str { + ::dux::str str; + str._arr = this->_arr.sub(_pos,_len); + return str; +} +constexpr auto ::dux::str::u8() const -> ::dux::arr<char8_t> { + return ::dux::cnv<char8_t>(this->begin(),this->end()); +} diff --git a/u8c/include/u8c/u8c.d/uniblk b/include/dux/str.d/uniblk.hh index e216833..4a5d1be 100644 --- a/u8c/include/u8c/u8c.d/uniblk +++ b/include/dux/str.d/uniblk.hh @@ -1,30 +1,25 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_Z0dBX6z5KYfITIHo) -#define u8c_key_Z0dBX6z5KYfITIHo - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::uniblk(char32_t const _chr) -> u8c::str { - if(_chr > u8c::unimax) [[unlikely]] { - throw std::domain_error("Unicode codepoint too big!"); +constexpr auto ::dux::uniblk(char32_t const _chr) -> ::dux::str { + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::invalutf("Unicode codepoint too big!"); } if(_chr <= U'\u007F') { return U"BASIC LATIN"; @@ -493,5 +488,3 @@ constexpr auto u8c::uniblk(char32_t const _chr) -> u8c::str { } return U"UNDEFINED IN UNICODE"; } - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/u8c.d/uninm b/include/dux/str.d/uninm.hh index 3fc67f3..7c40d2c 100644 --- a/u8c/include/u8c/u8c.d/uninm +++ b/include/dux/str.d/uninm.hh @@ -1,32 +1,27 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#if !defined(u8c_key_EW3CUEOMiNBCpImA) -#define u8c_key_EW3CUEOMiNBCpImA - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::uninm(char32_t const _chr) -> u8c::str{ +constexpr auto ::dux::uninm(char32_t const _chr) -> ::dux::str{ switch(_chr) { [[unlikely]] default: - if(_chr > u8c::unimax) [[unlikely]] { - throw std::out_of_range("Character out of range."); + if(_chr > ::dux::unimax) [[unlikely]] { + throw ::dux::invalutf("Character out of range."); } return U"UNDEFINED IN UNICODE"; /* BASIC LATIN: */ @@ -674,6 +669,36 @@ constexpr auto u8c::uninm(char32_t const _chr) -> u8c::str{ return U"LATIN CAPITAL LETTER L WITH MDDLE DOT"; case U'\u0140': return U"LATIN SMALL LETTER L WITH MIDDLE DOT"; + case U'\u0141': + return U"LATIN CAPITAL LETTER L WITH STROKE"; + case U'\u0142': + return U"LATIN SMALL LETTER L WITH STROKE"; + case U'\u0143': + return U"LATIN CAPITAL LETTER N WITH ACUTE"; + case U'\u0144': + return U"LATIN SMALL LETTER N WITH ACUTE"; + case U'\u0145': + return U"LATIN CAPITAL LETTER N WITH CEDILLA"; + case U'\u0146': + return U"LATIN SMALL LETTER N WITH CEDILLA"; + case U'\u0147': + return U"LATIN CAPITAL LETTER N WITH CARON"; + case U'\u0148': + return U"LATIN SMALL LETTER N WITH CARON"; + case U'\u0149': + return U"LATIN SMALL LETTER N PRECEDED BY APOSTROPHE"; + case U'\u014A': + return U"LATIN CAPITAL LETTER ENG"; + case U'\u014B': + return U"LATIN SMALL LETTER ENG"; + case U'\u014C': + return U"LATIN CAPITAL LETTER O WITH MACRON"; + case U'\u014D': + return U"LATIN SMALL LETTER O WITH MACRON"; + case U'\u014E': + return U"LATIN CAPITAL LETTER O WITH BREVE"; + case U'\u014F': + return U"LATIN SMALL LETTER O WITH BREVE"; case U'\u0150': return U"LATIN CAPITAL LETTER O WITH DOUBLE ACUTE"; case U'\u0160': @@ -2693,5 +2718,3 @@ constexpr auto u8c::uninm(char32_t const _chr) -> u8c::str{ return U"CANCEL TAG"; } } - -#endif
\ No newline at end of file diff --git a/include/dux/str.hh b/include/dux/str.hh new file mode 100644 index 0000000..6ecf0ca --- /dev/null +++ b/include/dux/str.hh @@ -0,0 +1,81 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace dux { + class str { + public: + constexpr auto app( ::dux::str const & oth) -> ::dux::str const &; + [[nodiscard]] constexpr auto begin() noexcept -> char32_t *; + [[nodiscard]] constexpr auto begin() const noexcept -> char32_t const *; + [[nodiscard]] constexpr auto cbegin() const noexcept -> char32_t const *; + [[nodiscard]] constexpr auto cend() const noexcept -> char32_t const *; + constexpr auto del( ::dux::usz pos) -> void; + [[nodiscard]] constexpr auto end() noexcept -> char32_t *; + [[nodiscard]] constexpr auto end() const noexcept -> char32_t const *; + [[nodiscard]] constexpr auto fnd( char32_t chr) const noexcept -> ::dux::usz; + constexpr auto ins( ::dux::usz pos, ::dux::str const & oth) -> ::dux::str const &; + constexpr auto len() const noexcept -> ::dux::usz; + constexpr auto operator + ( ::dux::str const & oth) const -> ::dux::str; + constexpr auto operator = ( ::dux::str const & oth) -> ::dux::str const &; + constexpr auto operator == (::dux::str const & oth) const noexcept -> bool; + constexpr auto operator [] (::dux::usz pos) noexcept -> char32_t &; + constexpr auto operator [] (::dux::usz pos) const noexcept -> char32_t const &; + [[nodiscard]] constexpr str() noexcept = default; + [[nodiscard]] constexpr str( char32_t chr); + [[nodiscard]] constexpr str( ::dux::str const & oth); + [[nodiscard]] constexpr str( ::dux::str && oth); + template<::dux::usz N> [[nodiscard]] constexpr str( char const (& strlit)[N]) noexcept = delete; + template<::dux::usz N> [[nodiscard]] constexpr str( char32_t const (& strlit)[N]) noexcept; + template<::dux::utf T> [[nodiscard]] constexpr str( T chr); + template<::dux::utf T> [[nodiscard]] constexpr str( T const * utf); + [[nodiscard]] constexpr auto sub( ::dux::usz pos, ::dux::usz len) const -> ::dux::str; + [[nodiscard]] constexpr auto u8() const -> ::dux::arr<char8_t>; + private: + ::dux::arr<char32_t> _arr; + }; + + template<::dux::utf T,::dux::utf T0> [[nodiscard]] constexpr auto cnv( T0 const * begin,T0 const * end) -> ::dux::arr<T>; + [[nodiscard,dux_attr_const]] constexpr auto isalnum( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto isalpha( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto iscntrl( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto isdigit( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto islower( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto ispunct( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto isspace( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto issurro( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto isupper( char32_t chr) -> bool; + [[nodiscard,dux_attr_const]] constexpr auto isxdigit(char32_t chr) -> bool; + [[nodiscard]] constexpr auto uniblk( char32_t chr) -> ::dux::str; + [[nodiscard]] constexpr auto uninm( char32_t chr) -> ::dux::str; +} + +#include <dux/str.d/cnv.hh> +#include <dux/str.d/isalnum.hh> +#include <dux/str.d/isalpha.hh> +#include <dux/str.d/iscntrl.hh> +#include <dux/str.d/isdigit.hh> +#include <dux/str.d/islower.hh> +#include <dux/str.d/ispunct.hh> +#include <dux/str.d/isspace.hh> +#include <dux/str.d/issurro.hh> +#include <dux/str.d/isupper.hh> +#include <dux/str.d/isxdigit.hh> +#include <dux/str.d/str.hh> +#include <dux/str.d/uniblk.hh> +#include <dux/str.d/uninm.hh> diff --git a/include/dux/sys b/include/dux/sys new file mode 100644 index 0000000..33dc533 --- /dev/null +++ b/include/dux/sys @@ -0,0 +1,27 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#if !defined(dux_hdr_sys) +#define dux_hdr_sys + +#include <dux/str> + +#include <dux/sys.hh> + +#endif diff --git a/include/dux/sys.d/_ass.hh b/include/dux/sys.d/_ass.hh new file mode 100644 index 0000000..ecb9548 --- /dev/null +++ b/include/dux/sys.d/_ass.hh @@ -0,0 +1,40 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <iostream> + +constexpr auto ::dux::_ass(char const * const dux_restr _fl,unsigned long const _ln,char const * const dux_restr _fn,bool const _expr,char const * const dux_restr _exprstr,char const * const dux_restr _msg) noexcept -> bool { + if (!_expr) [[unlikely]] { + ::std::cerr << "\n"; + ::std::cerr << "Assertion \u001B[38;2;225;61;61mfailed\u001B[0m"; + if (!::dux::cstrcmp(_msg,"")) { + ::std::cerr << "!"; + } + else { + ::std::cerr << ": \u001B[3m" << _msg << "\u001B[0m"; + } + ::std::cerr << "\n"; + ::std::cerr << "... at \u001B[38;2;225;169;61m\"" << _fl << "\"\u001B[0m:\u001B[38;2;255;169;61m" << _ln << "\u001B[0m\n"; + ::std::cerr << "... in \u001B[38;2;169;225;61m" << _fn << "\u001B[0m\n"; + ::std::cerr << " Expression (\u001B[38;2;61;169;225m" << _exprstr << "\u001B[0m) does not evaluate to true!\n"; + ::std::cerr << "\n"; + ::dux::abrt(); + } + return _expr; +} diff --git a/include/dux/sys.d/dobj.hh b/include/dux/sys.d/dobj.hh new file mode 100644 index 0000000..5f60b4c --- /dev/null +++ b/include/dux/sys.d/dobj.hh @@ -0,0 +1,65 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#if defined(dux_os_posix) +#include <dlfcn.h> +#endif + +namespace dux { + class _dobjdat { + public: +#if defined(dux_os_posix) + void * dlhandl{nullptr}; +#endif + }; +} + +template<typename T,typename... Ts> auto ::dux::dobj::call(char const * const dux_restr _fn,Ts const &... _args) -> T { + [[maybe_unused]] auto const dat = static_cast<::dux::_dobjdat *>(this->_dat); + dux_ass(_fn != nullptr,"Input C-string points to null!"); +#if defined(dux_os_posix) + dux_ass(dat->dlhandl != nullptr,"Dynamic object has not been linked!"); + auto const sym = reinterpret_cast<T (*)(Ts...)>(::dlsym(dat->dlhandl,_fn)); + if (sym == nullptr) [[unlikely]] { + throw ::dux::runerr("Unable to load function!"); + } + return sym(_args...); +#endif +} +::dux::dobj::dobj() : _dat(::new ::dux::_dobjdat) { +} +auto ::dux::dobj::link(char const * const dux_restr _lib) -> void { + [[maybe_unused]] auto const dat = static_cast<::dux::_dobjdat *>(this->_dat); + dux_ass(_lib != nullptr,"Input C-string points to null!"); +#if defined(dux_os_posix) + dat->dlhandl = ::dlopen(_lib,RTLD_LOCAL | RTLD_NOW); + if (dat->dlhandl == nullptr) [[unlikely]] { + throw ::dux::runerr("Unable to open library!"); + } +#endif +} +auto ::dux::dobj::unlink() noexcept -> void { + [[maybe_unused]] auto const dat = static_cast<::dux::_dobjdat *>(this->_dat); +#if defined(dux_os_posix) + if (dat->dlhandl != nullptr) { + ::dlclose(dat->dlhandl); + dat->dlhandl = nullptr; + } +#endif +} +::dux::dobj::~dobj() noexcept { + ::delete static_cast<::dux::_dobjdat *>(this->_dat); +} diff --git a/include/dux/sys.hh b/include/dux/sys.hh new file mode 100644 index 0000000..9f34f20 --- /dev/null +++ b/include/dux/sys.hh @@ -0,0 +1,98 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#define dux_ass(expr,msg) \ + ([&]() { \ + if constexpr (::dux::dbg) { \ + ::dux::_ass(__FILE__,static_cast<unsigned long>(__LINE__),dux_fnnm,expr,#expr,msg); \ + } \ + }()) + +namespace dux { + enum class sig : ::dux::ubyte { + abrt, + fpe, + ill, + int_, + kill, + segv, + term, + trap, +#if defined(dux_os_posix) + alrm, + bus, + cont, + hup, + iot, + pipe, + poll, + prof, + quit, + rtmax, + rtmin, + stop, + sys, + tstp, + ttin, + ttou, + urg, + usr1, + usr2, + vtalrm, + winch, + xcpu, + xfsz, +#endif + }; + constexpr auto numsig{static_cast<::dux::ubyte>([]() { +#if defined(dux_os_posix) + return ::dux::sig::xfsz; +#else + return ::dux::sig::trap; +#endif + }()) + ::dux::ubytev(0x1)}; + + class dobj { + public: + template<typename T,typename... Ts> [[nodiscard]] inline auto call( char const * fn, Ts const &... args) -> T; + [[nodiscard]] inline dobj(); + inline auto link( char const * lib) -> void; + inline auto unlink() noexcept -> void; + inline ~dobj() noexcept; + private: + void * const dux_restr _dat; + }; + + constexpr auto _ass( char const * fl, unsigned long ln, char const * fn, bool expr,char const * exprstr,char const * msg) noexcept -> bool; + [[noreturn]] auto abrt() noexcept -> void; + [[noreturn]] auto abrt( ::dux::str const & msg) noexcept -> void; + [[noreturn]] auto exit( ::dux::stat stat = ::dux::stat::ok) noexcept -> void; + [[nodiscard]] auto getenv( char const * var) -> char const *; + [[noreturn]] auto qexit( ::dux::stat stat = ::dux::stat::err) noexcept -> void; + auto raise( ::dux::sig sig) noexcept -> void; + auto sighandl(::dux::sig sig, auto (* handl)(::dux::sig) -> void) -> auto (&)(::dux::sig) -> void; + auto sleep( ::dux::uint64 sec, ::dux::uint64 nsecx = ::dux::uint64v(0x0),::dux::uint64 nsecy = ::dux::uint64v(0x1)) noexcept -> void; + [[noreturn]] auto trap() noexcept -> void; + [[noreturn]] auto unreach() noexcept -> void; + + constexpr auto (* dflsighandl)(::dux::sig) -> void {nullptr}; +} + +#include <dux/sys.d/_ass.hh> +#include <dux/sys.d/dobj.hh> diff --git a/include/dux/thrd b/include/dux/thrd new file mode 100644 index 0000000..cc443d7 --- /dev/null +++ b/include/dux/thrd @@ -0,0 +1,26 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#if !defined(dux_hdr_thrd) +#define dux_hdr_thrd + +#include <dux/sys> +#include <dux/thrd.hh> + +#endif diff --git a/include/dux/thrd.d/thrd.hh b/include/dux/thrd.d/thrd.hh new file mode 100644 index 0000000..5f8aa29 --- /dev/null +++ b/include/dux/thrd.d/thrd.hh @@ -0,0 +1,87 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +/* + thrd implementation: + (To-do) On Linux, we will use our own wrappers for the Linux system calls (syscalls) that enable multithreading; + On POSIX, we will use our own wrappers for the POSIX Threads API, as to not polute the global scope; +*/ + + +namespace dux { +#if defined(dux_os_posix) + template<typename Fn,typename... Ts> class _thrdwrapdat { + public: + ::dux::tup<Ts...> args; + Fn * fn {nullptr}; + }; +#endif +} +template<typename T> auto ::dux::thrd::join(T * const dux_restr _ret) -> void { + if (this->_isjoin) [[unlikely]] { /* We do not need to do anything if the thread has joined. */ + return; + } +#if defined(dux_os_posix) + auto const ret{static_cast<T *>(::dux::_pthrdjoin(this->_pthrdhandl))}; /* POSIX Threads return the pointer passed to (::pthread_exit) on joining of thread. */ + if constexpr (!::dux::isvoid<T>) { /* (void) is an incomplete type, and we do not need to operate on it. */ + if (_ret) { /* Safe: "A prvalue of integral, floating-point, unscoped enumeration, __pointer__, and pointer-to-member types can be converted to a prvalue of type bool.", cppreference, 2021-11-17T15:40:00+0100 */ + *_ret = *ret; + } + } + ::delete ret; /* Free the allocated memory we got from the wrapper lambda in (::dux::thrd::operator ()). */ +#else + _Pragma("GCC message Unable to implement (::dux::thrd::join)!"); +#endif + this->_isjoin = true; +} +template<typename Fn,typename... Ts> auto ::dux::thrd::operator () (Fn const & _fn, Ts const &... _args) -> auto { + using T = decltype(_fn(Ts{}...)); +#if defined(dux_os_posix) + auto thrdwrap{[](void * const dux_restr _dat) -> void * { /* POSIX Threads use functions of type (void * (void *)). We will create a wrapper lambda, which calls the provided function (_fn). */ + auto const dat {static_cast<::dux::_thrdwrapdat<Fn,Ts...> *>(_dat)}; + auto const fn {dat->fn}; + auto const args{dat->args}; + ::delete dat; + auto const ret{::new T}; + *ret = args.apply(fn); + return ret; + }}; + auto const thrdwrapdat{::new ::dux::_thrdwrapdat<Fn,Ts...>}; + thrdwrapdat->fn = _fn; + thrdwrapdat->args = ::dux::tup{_args...}; + ::dux::_pthrdcrt(this->_pthrdhandl,thrdwrap,thrdwrapdat); +#else + _Pragma("GCC message Unable to implement (::dux::thrd::operator ())!"); +#endif + this->_isjoin = false; + return T{}; +} +template<typename Fn,typename... Ts> auto ::dux::thrd::run(Fn const & _fn, Ts const &... _args) -> decltype(auto) { /* This is a wrapper for (::dux::thrd::operator ()) to be used in cases of the thread being accessed using a handle ((thrd->run(...)) is prettier than (thrc->operator () (...))). */ + return this->operator () (_fn,_args...); +} +#if defined(dux_os_posix) +::dux::thrd::thrd() : _pthrdhandl(::dux::_getpthrdhandl()) {} +#else +::dux::thrd::thrd() {} +#endif +::dux::thrd::~thrd() noexcept { + if (!this->_isjoin) [[unlikely]] { /* The programmer did not join the thread before it got out of scope. We want safe programming, so we will __not__ recover from this. */ + ::dux::abrt(U"dux :: Active thread got out of scope!"); + } +#if defined(dux_os_posix) + ::dux::_freepthrdhandl(this->_pthrdhandl); +#endif +} diff --git a/include/dux/thrd.hh b/include/dux/thrd.hh new file mode 100644 index 0000000..558b737 --- /dev/null +++ b/include/dux/thrd.hh @@ -0,0 +1,47 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +namespace dux { + class thrderr : public ::dux::except { + public: + using ::dux::except::except; + }; + + class thrd { + public: + template<typename T = ::dux::ubyte> auto join( T * ret = nullptr) -> void; + template<typename T> auto join( ::dux::nullptrtyp) = delete; + template<typename Fn, typename... Ts> auto operator () (Fn const & fn, Ts const &... args) -> auto; + template<typename Fn, typename... Ts> auto run( Fn const & fn, Ts const &... args) -> decltype(auto); + [[nodiscard]] inline thrd(); + inline ~thrd() noexcept; + private: + bool _isjoin{true}; + void * const dux_restr _pthrdhandl; + }; + +#if defined(dux_os_posix) + auto _freepthrdhandl(void * handl) noexcept -> void; + auto _getpthrdhandl() -> void *; + auto _pthrdcrt( void * handl,auto (* fn)( void *) -> void *,void const * arg) -> void; + auto _pthrdjoin( void * handl) -> void *; +#endif +} + +#include <dux/thrd.d/thrd.hh> diff --git a/src/dux/_freepthrdhandl.cc b/src/dux/_freepthrdhandl.cc new file mode 100644 index 0000000..9f499b5 --- /dev/null +++ b/src/dux/_freepthrdhandl.cc @@ -0,0 +1,26 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/thrd> + +#include "priv.hh" + +auto ::dux::_freepthrdhandl(void * const dux_restr _pthrdhandl) noexcept -> void { + ::delete static_cast<::dux::_pthrddat *>(_pthrdhandl); +} diff --git a/u8c/src/u8c/println.cc b/src/dux/_getpthrdhandl.cc index f607ad7..4968d44 100644 --- a/u8c/src/u8c/println.cc +++ b/src/dux/_getpthrdhandl.cc @@ -1,25 +1,26 @@ /* Copyright 2021 Gabriel Jensen - This file is part of u8c. + This file is part of dux. - u8c is free software: you can redistribute it and/or modify it under the + dux is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - u8c is distributed in the hope that it will be useful, but WITHOUT ANY + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. + along with dux. If not, see <https://www.gnu.org/licenses/>. */ -#include <ostream> /* std::ostream */ +#include <dux/thrd> -#if 0x0 -auto u8c::println([[maybe_unused]] std::ostream & _strm,[[maybe_unused]] u8c::str _msg) -> void { +#include "priv.hh" + +auto ::dux::_getpthrdhandl() -> void * { + return ::new ::dux::_pthrddat; } -#endif
\ No newline at end of file diff --git a/src/dux/_pthrdcrt.cc b/src/dux/_pthrdcrt.cc new file mode 100644 index 0000000..cb9a652 --- /dev/null +++ b/src/dux/_pthrdcrt.cc @@ -0,0 +1,30 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/thrd> +#include <pthread.h> + +#include "priv.hh" + +auto ::dux::_pthrdcrt(void * const dux_restr _pthrdhandl,auto (* _fn)(void *) -> void *,void const * const dux_restr _arg) -> void { + [[maybe_unused]] auto const thrddat = static_cast<::dux::_pthrddat *>(_pthrdhandl); + if (::pthread_create(&thrddat->pthrd,nullptr,_fn,const_cast<void *>(_arg)) != 0x0) [[unlikely]] { + throw ::dux::thrderr("Unable to initiate thread!"); + } +} diff --git a/src/dux/_pthrdjoin.cc b/src/dux/_pthrdjoin.cc new file mode 100644 index 0000000..33266ee --- /dev/null +++ b/src/dux/_pthrdjoin.cc @@ -0,0 +1,32 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/thrd> +#include <pthread.h> + +#include "priv.hh" + +auto ::dux::_pthrdjoin(void * const dux_restr _pthrdhandl) -> void * { + [[maybe_unused]] auto const thrddat = static_cast<::dux::_pthrddat *>(_pthrdhandl); + void * ret{nullptr}; + if (::pthread_join(thrddat->pthrd,&ret) != 0x0) [[unlikely]] { + throw ::dux::thrderr("Unable to join thread!"); + } + return ret; +} diff --git a/src/dux/_setsiginthandl.cc b/src/dux/_setsiginthandl.cc new file mode 100644 index 0000000..ba6c9a4 --- /dev/null +++ b/src/dux/_setsiginthandl.cc @@ -0,0 +1,29 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/io> + +#include "priv.hh" + +auto ::dux::_setsiginthandl() -> void { + ::dux::dbgprint(U"dux :: Setting the SIGINT signal handler!\n"); + if (!::dux::_inst.siginthandlset) { + ::dux::_inst.prevsiginthandl = ::dux::sighandl(::dux::sig::int_,::dux::_siginthandl); + ::dux::_inst.siginthandlset = true; + return; + } + ::dux::dbgprint(U"dux :: The SIGINT signal handler is already set!\n"); +}; diff --git a/src/dux/_siginthandl.cc b/src/dux/_siginthandl.cc new file mode 100644 index 0000000..5a9bb13 --- /dev/null +++ b/src/dux/_siginthandl.cc @@ -0,0 +1,23 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/sys> + +#include "priv.hh" + +auto ::dux::_siginthandl(::dux::sig) noexcept -> void { + ::dux::_inst.hassigint = true; /* We have detected the SIGINT signal. The ::dux::win::pollevt function will check this value. */ +}; diff --git a/src/dux/_sigtocsig.cc b/src/dux/_sigtocsig.cc new file mode 100644 index 0000000..3e2ca71 --- /dev/null +++ b/src/dux/_sigtocsig.cc @@ -0,0 +1,92 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/io> +#include <signal.h> + +#include "priv.hh" + +auto ::dux::_sigtocsig(::dux::sig const _sig) noexcept -> int { + switch (_sig) { + default: + ::dux::print(U"dux :: _::dux::_sigtocsig recieved unknown signal!\n"); + ::dux::abrt(); + case ::dux::sig::abrt: + return SIGABRT; + case ::dux::sig::fpe: + return SIGFPE; + case ::dux::sig::ill: + return SIGILL; + case ::dux::sig::int_: + return SIGINT; + case ::dux::sig::segv: + return SIGSEGV; + case ::dux::sig::term: + return SIGTERM; +#if defined(dux_os_posix) + case ::dux::sig::alrm: + return SIGALRM; + case ::dux::sig::bus: + return SIGBUS; + case ::dux::sig::cont: + return SIGCONT; + case ::dux::sig::hup: + return SIGHUP; + case ::dux::sig::iot: + return SIGIOT; + case ::dux::sig::kill: + return SIGKILL; + case ::dux::sig::pipe: + return SIGPIPE; + case ::dux::sig::poll: + return SIGPOLL; + case ::dux::sig::prof: + return SIGPROF; + case ::dux::sig::quit: + return SIGQUIT; + case ::dux::sig::rtmax: + return SIGRTMAX; + case ::dux::sig::rtmin: + return SIGRTMIN; + case ::dux::sig::stop: + return SIGSTOP; + case ::dux::sig::sys: + return SIGSYS; + case ::dux::sig::trap: + return SIGTRAP; + case ::dux::sig::tstp: + return SIGTSTP; + case ::dux::sig::ttin: + return SIGTTIN; + case ::dux::sig::ttou: + return SIGTTOU; + case ::dux::sig::urg: + return SIGURG; + case ::dux::sig::usr1: + return SIGUSR1; + case ::dux::sig::usr2: + return SIGUSR2; + case ::dux::sig::vtalrm: + return SIGVTALRM; + case ::dux::sig::winch: + return SIGWINCH; + case ::dux::sig::xcpu: + return SIGXCPU; + case ::dux::sig::xfsz: + return SIGXFSZ; +#endif + } +}; diff --git a/src/dux/abrt.cc b/src/dux/abrt.cc new file mode 100644 index 0000000..391089f --- /dev/null +++ b/src/dux/abrt.cc @@ -0,0 +1,46 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/io> +#if defined(dux_os_posix) +#include <pthread.h> +#endif + +namespace dux::_static { +#if defined(dux_os_posix) + static ::pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +#endif +} + +auto ::dux::abrt() noexcept -> void { + ::pthread_mutex_lock(&::dux::_static::lock); /* Lock this so we will not abort from multiple threads. */ + ::dux::dbgprint(U"dux :: Aborting!\n"); + ::dux::dbgprint(U"dux :: Raising SIGABRT!\n"); + ::dux::raise(::dux::sig::abrt); /* We will now raise SIGABRT in an attempt to quit. */ + ::dux::dbgprint(U"dux :: Signal handler returned! Reset it!\n"); + ::dux::sighandl(::dux::sig::abrt,::dux::dflsighandl); /* The signal handler has returned, and so we will attempt to set the default handler. */ + ::dux::dbgprint(U"dux :: Raising SIGABRT!\n"); + ::dux::raise(::dux::sig::abrt); /* Raise SIGABRT again to call the default signal handler. */ + ::dux::dbgprint(U"dux :: Default signal handler returned! Trapping!\n"); + ::dux::trap(); /* The default signal handler returned, so we will trap or never return. */ +} +auto ::dux::abrt(::dux::str const & _msg) noexcept -> void { + ::dux::print(U"dux :: Aborting due to \"$\"!\n",_msg); + ::dux::abrt(); +} diff --git a/src/dux/endgfx.cc b/src/dux/endgfx.cc new file mode 100644 index 0000000..90962ce --- /dev/null +++ b/src/dux/endgfx.cc @@ -0,0 +1,47 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/io> +#include <dux/media> +#if defined(dux_gfxproto_gl) +#include <GL/gl.h> +#endif +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) +#include <wayland-client.h> +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) +#include <xcb/xcb.h> +#if defined(dux_gfxproto_gl) +#include <GL/glx.h> +#include <X11/Xlib-xcb.h> +#endif +#endif + +#include "priv.hh" + +auto ::dux::endgfx() -> void { + ::dux::dbgprint(U"dux :: Ending the graphics module...\n"); + dux_ass(!::dux::_inst.numwin,"Ammount of windows is non-zero!"); + if (!::dux::_inst.gfxinit) [[unlikely]] { + goto isend; + } +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + ::dux::print(U"dux :: Disconnecting from the X server!\n"); + ::xcb_disconnect(::dux::_inst.xconn); +#endif +isend:; + ::dux::dbgprint(U"dux :: Ending successful!\n"); +} diff --git a/src/dux/exit.cc b/src/dux/exit.cc new file mode 100644 index 0000000..3d0b15a --- /dev/null +++ b/src/dux/exit.cc @@ -0,0 +1,29 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/sys> + +#include <cstdlib> + +auto ::dux::exit(::dux::stat const _stat) noexcept -> void { + if (_stat == ::dux::stat::err) { + ::std::exit(EXIT_FAILURE); + } + ::std::exit(EXIT_SUCCESS); +} diff --git a/src/dux/getenv.cc b/src/dux/getenv.cc new file mode 100644 index 0000000..fce63e2 --- /dev/null +++ b/src/dux/getenv.cc @@ -0,0 +1,30 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <cstdlib> +#include <dux/sys> + +auto ::dux::getenv(char const * const dux_restr _env) -> char const * { + if (auto const envval = ::std::getenv(_env);envval == nullptr) [[unlikely]] { + throw ::dux::runerr("Environment variable does not exist!"); + } + else { + return envval; + } +} diff --git a/src/dux/goatmaster.cc b/src/dux/goatmaster.cc new file mode 100644 index 0000000..8eb350b --- /dev/null +++ b/src/dux/goatmaster.cc @@ -0,0 +1,24 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/io> + +[[dux_attr_cold]] extern "C" void goatmaster(int const _x) { /* Test function for dynamic linking. */ + ::dux::print(U"The Goat Master has been summoned with the number $!\n",_x); +} diff --git a/src/dux/initgfx.cc b/src/dux/initgfx.cc new file mode 100644 index 0000000..3ab4141 --- /dev/null +++ b/src/dux/initgfx.cc @@ -0,0 +1,64 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/io> +#include <dux/media> +#if defined(dux_gfxproto_gl) +#include <GL/gl.h> +#endif +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) +#include <wayland-client.h> +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) +#include <xcb/xcb.h> +#if defined(dux_gfxproto_gl) +#include <GL/glx.h> +#include <X11/Xlib-xcb.h> +#endif +#endif + +#include "priv.hh" + +auto ::dux::initgfx() -> void { + ::dux::dbgprint(U"dux :: Initialising the graphics module...\n"); + if (::dux::_inst.gfxinit) [[unlikely]] { + goto isinit; + } +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) + try { + auto const * const dux_restr envval = ::dux::getenv("XDG_SESSION_TYPE"); + if (!!::dux::cstrcmp(envval,"wayland")) [[unlikely]] { + ::dux::print(U"dux :: Environment variable \"XDG_SESSION_TYPE\" is not set to \"wayland\", but dux is targeting Wayland!\n"); + } + } + catch (::dux::except const & e) { + } + ::dux::dbgprint(U"dux :: Wayland support is experimental!\n"); + ::dux::_inst.wldisp = ::wl_display_connect(nullptr); + if (::dux::_inst.wldisp == nullptr) [[unlikely]] { + throw ::dux::runerr("Unable to open Wayland display!"); + } +#else + if (::dux::_inst.xconn = ::xcb_connect(nullptr,nullptr);::dux::_inst.xconn == nullptr) [[unlikely]] { + throw ::dux::runerr("Unable to open connection to X server."); + } + ::dux::dbgprint(U"dux :: Made a connection to an X server!\n"); + ::dux::_inst.xscrn = ::xcb_setup_roots_iterator(xcb_get_setup(::dux::_inst.xconn)).data; + ::dux::dbgprint(U"dux :: Set up roots iterator!\n"); +#endif + ::dux::_inst.gfxinit = true; +isinit:; + ::dux::dbgprint(U"dux :: Initialisation successful!\n"); +} diff --git a/src/dux/priv.hh b/src/dux/priv.hh new file mode 100644 index 0000000..1c497d5 --- /dev/null +++ b/src/dux/priv.hh @@ -0,0 +1,58 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#if !defined(dux_hdr_priv) +#define dux_hdr_priv + +#include <dux/sys> +#if defined(dux_os_posix) +#include <pthread.h> +#endif +#if defined(dux_winsproto_wl) +#include <wayland-client.h> +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) +#include <xcb/xcb.h> +#endif + +namespace dux { + class _insttyp { + public: + bool gfxinit {false}; + bool hassigint {false}; + ::dux::uint16 numwin {::dux::uint16v(0x0)}; + void (* prevsiginthandl)(::dux::sig){::dux::dflsighandl}; /* Used for setting the previous signal handler in case there aren't any open windows to handle the signal. */ + bool siginthandlset {false}; +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) + ::wl_display * wldisp{nullptr}; +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + ::xcb_connection_t * xconn{nullptr}; + ::xcb_screen_t * xscrn{nullptr}; +#endif + } inline _inst; + +#if defined(dux_os_posix) + class _pthrddat { + public: + pthread_t pthrd; + }; +#endif + + auto _setsiginthandl() -> void; + auto _siginthandl( ::dux::sig) noexcept -> void; + auto _sigtocsig( ::dux::sig sig) noexcept -> int; +} + +#endif diff --git a/src/dux/qexit.cc b/src/dux/qexit.cc new file mode 100644 index 0000000..8cebfb8 --- /dev/null +++ b/src/dux/qexit.cc @@ -0,0 +1,46 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/sys> + +#if defined(dux_os_linux) +#include <sys/syscall.h> +#include <unistd.h> +#elif defined(dux_os_posix) +#include <stdlib.h> +#else +#include <cstdlib> +#endif + +auto ::dux::qexit(::dux::stat const _stat) noexcept -> void { +#if defined(dux_os_linux) + auto const stat = _stat == ::dux::stat::ok ? 0x0 : 0x1; + ::syscall(__NR_exit_group,stat); + ::syscall(__NR_exit,stat); + ::dux::trap(); +#else + auto const stat = _stat == ::dux::stat::ok ? EXIT_SUCCESS : EXIT_FAILURE; +#if defined(dux_os_posix) + ::_exit(stat); + ::dux::trap(); +#else + ::std::_Exit(stat); +#endif +#endif +} diff --git a/src/dux/raise.cc b/src/dux/raise.cc new file mode 100644 index 0000000..3c0d020 --- /dev/null +++ b/src/dux/raise.cc @@ -0,0 +1,53 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/io> + +#include <signal.h> +#if defined(dux_os_linux) +#include <sys/syscall.h> +#include <unistd.h> +#else +#include <pthread.h> +#endif + +#include "priv.hh" + +auto ::dux::raise(::dux::sig const _sig) noexcept -> void { + ::dux::dbgprint(U"dux :: Raising signal #$!\n",static_cast<int>(_sig)); +#if !defined(dux_os_posix) + if (_sig == ::dux::sig::kill) { + ::dux::abrt(); + } + if (_sig == ::dux::sig::trap) { + ::dux::trap(); + } +#endif + auto const sig = ::dux::_sigtocsig(_sig); +#if defined(dux_os_linux) + ::dux::dbgprint(U"dux :: Killing process via syscall!\n"); + ::syscall(__NR_kill,::syscall(__NR_getpid),sig); +#elif defined(dux_os_posix) +::dux::dbgprint(U"dux :: Killing thread!\n"); + ::pthread_kill(::pthread_self(),sig); +#else + ::dux::dbgprint(U"dux :: Raising signal!\n"); + ::raise(sig); +#endif +} diff --git a/src/dux/sighandl.cc b/src/dux/sighandl.cc new file mode 100644 index 0000000..8e21505 --- /dev/null +++ b/src/dux/sighandl.cc @@ -0,0 +1,94 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/io> + +#include <cerrno> +#include <signal.h> +#if defined(dux_os_linux) +#include <sys/syscall.h> +#include <unistd.h> +#endif + +#include "priv.hh" + +namespace dux::_static { + static auto (* _sighandls[::dux::numsig])(::dux::sig) -> void; + + static auto _sigwrap(int sig) -> void; +} + +static auto ::dux::_static::_sigwrap(int const _sig) -> void { +#if !defined(dux_os_posix) + ::signal(_sig,::dux::_static::sigwrap); +#endif + auto const sig = [&]() { + switch(_sig) { + default: + ::dux::abrt(); + case SIGABRT: + return ::dux::sig::abrt; + case SIGFPE: + return ::dux::sig::fpe; + case SIGILL: + return ::dux::sig::ill; + case SIGINT: + return ::dux::sig::int_; + case SIGSEGV: + return ::dux::sig::segv; + case SIGTERM: + return ::dux::sig::term; + } + }(); + ::dux::_static::_sighandls[static_cast<::dux::usz>(sig)](sig); +} + +auto ::dux::sighandl(::dux::sig const _sig,auto (* const _handl)(::dux::sig) -> void) -> auto (&)(::dux::sig) -> void { + ::dux::print(U"dux :: Setting signal handler!\n"); + auto & handl = ::dux::_static::_sighandls[static_cast<::dux::usz>(_sig)]; + auto const oldhandl = handl; + handl = _handl; + auto const sig = ::dux::_sigtocsig(_sig); + if (_handl == ::dux::dflsighandl) { + ::signal(sig,SIG_DFL); + goto ret; + } + { +#if defined(dux_os_posix) + struct ::sigaction sigact{}; + sigact.sa_handler = ::dux::_static::_sigwrap; + ::sigemptyset(&sigact.sa_mask); + sigact.sa_flags = SA_RESTART; +#endif + if ([&]() { +//#if defined(dux_os_linux) +// return ::syscall(__NR_rt_sigaction,sig,&sigact,nullptr,sizeof(::sigset_t)) == -0x1l; /* This syscall returns EINVAL and I could not get it to work. */ +//#elif defined(dux_os_posix) +#if defined(dux_os_posix) + return ::sigaction(sig,&sigact,nullptr) == -0x1; +#else + return ::std::signal(sig,::dux::_static::_sigwrap) == SIG_ERR; +#endif + }()) [[unlikely]] { + throw ::dux::runerr("Unable to set signal handler!"); + } + } +ret:; + return *oldhandl; +} diff --git a/src/dux/sleep.cc b/src/dux/sleep.cc new file mode 100644 index 0000000..84a74da --- /dev/null +++ b/src/dux/sleep.cc @@ -0,0 +1,49 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/sys> +#if defined(dux_os_posix) +#include <unistd.h> +#if defined(dux_os_linux) +#include <sys/syscall.h> +#else +#include <time.h> +#endif +#endif + +auto ::dux::sleep(::dux::uint64 const _sec,::dux::uint64 const _nsecx,::dux::uint64 const _nsecy) noexcept -> void { +#if defined(dux_os_posix) +#if defined(dux_os_linux) + class { + public: + ::dux::uint64 tv_sec; + long tv_nsec; + } timespec; +#else + ::timespec timespec; +#endif + timespec.tv_sec = _sec; + timespec.tv_nsec = static_cast<long>(static_cast<float>(_nsecx) / static_cast<float>(_nsecy) * 0x3B9ACA00p0); +#if defined(dux_os_linux) + ::syscall(__NR_nanosleep,×pec,×pec); +#else + ::nanosleep(×pec,×pec); +#endif +#endif +} diff --git a/src/dux/trap.cc b/src/dux/trap.cc new file mode 100644 index 0000000..a689451 --- /dev/null +++ b/src/dux/trap.cc @@ -0,0 +1,31 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/sys> + +auto ::dux::trap() noexcept -> void { + for (;;) { +#if defined(dux_os_unix) + ::dux::raise(::dux::sig::trap); +#elif dux_hasbuiltin(__builtin_trap) + ::__builtin_trap(); +#elif dux_hasbuiltin(__debugbreak) + ::__debugbreak(); +#else + ::dux::qexit(::dux::stat::err); +#endif + } +}; diff --git a/src/dux/unreach.cc b/src/dux/unreach.cc new file mode 100644 index 0000000..f03de41 --- /dev/null +++ b/src/dux/unreach.cc @@ -0,0 +1,30 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <dux/sys> + +auto ::dux::unreach() noexcept -> void { +#if dux_hasbuiltin(__assume) + ::__assume(false); +#elif dux_hasbuiltin(__builtin_unreachable) + ::__builtin_unreachable(); +#else + ::dux::trap(); +#endif +} diff --git a/src/dux/win.cc b/src/dux/win.cc new file mode 100644 index 0000000..2957892 --- /dev/null +++ b/src/dux/win.cc @@ -0,0 +1,144 @@ +/* + Copyright 2021 Gabriel Jensen + + This file is part of dux. + + dux is free software: + you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License along with dux. + If not, see <https://www.gnu.org/licenses/>. +*/ + +#include <cstdlib> +#include <dux/io> +#include <dux/media> +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) +#include <wayland-client.h> +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) +#include <xcb/xcb.h> +#include <xcb/xcb_atom.h> +#endif + +#include "priv.hh" + +namespace dux { + class windat { + public: + bool open{false}; +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) + ::wl_shell_surface * wlsurf{nullptr}; +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + ::xcb_window_t xwin{}; +#endif + }; +} +auto ::dux::win::close() -> void { + [[maybe_unused]] auto * const dux_restr dat = static_cast<::dux::windat *>(this->_dat); + ::dux::dbgprint(U"dux :: Closing window!\n"); +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + ::xcb_unmap_window(::dux::_inst.xconn,dat->xwin); + ::xcb_flush(::dux::_inst.xconn); +# endif + this->_isopen = false; + ::dux::_inst.numwin -= ::dux::uint16v(0x1); + ::dux::dbgprint(U"dux :: Current number of windows: $\n",::dux::_inst.numwin); + ::dux::dbgprint(U"dux :: Unsetting the SIGINT signal handler!\n"); + if (!::dux::_inst.numwin) { + ::dux::sighandl(::dux::sig::int_,*::dux::_inst.prevsiginthandl); + ::dux::_inst.siginthandlset = false; + return; + } + ::dux::dbgprint(U"dux :: An open window exists!\n"); +} +auto ::dux::win::crt(char const * const dux_restr _nm,::dux::uint16 const _w,::dux::uint16 const _h) -> ::dux::win { + ::dux::win win; + [[maybe_unused]] auto * const dux_restr dat = static_cast<::dux::windat *>(win._dat); +#if defined(dux_gfxproto_wlgl) +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + dat->xwin = ::xcb_generate_id(::dux::_inst.xconn); + ::dux::uint32 valmask[] = { + XCB_EVENT_MASK_EXPOSURE, + }; + ::xcb_create_window(::dux::_inst.xconn,XCB_COPY_FROM_PARENT,dat->xwin,::dux::_inst.xscrn->root,::dux::uint16v(0x0),::dux::uint16v(0x0),_w,_h,::dux::uint16v(0x0),XCB_WINDOW_CLASS_INPUT_OUTPUT,::dux::_inst.xscrn->root_visual,::dux::uint32v(0x0),valmask); + ::xcb_map_window(::dux::_inst.xconn,dat->xwin); + ::xcb_flush(::dux::_inst.xconn); + win.renm(_nm); +#endif + ::dux::_inst.numwin += ::dux::uint16v(0x1); + ::dux::dbgprint(U"dux :: Current number of windows: $\n",::dux::_inst.numwin); + ::dux::_setsiginthandl(); + win._isopen = true; + return win; +} +auto ::dux::win::destr() noexcept -> void { + ::dux::dbgprint(U"dux :: Destroying window!\n"); + this->close(); + ::delete static_cast<::dux::windat *>(this->_dat); +} +auto ::dux::win::open() -> void { + [[maybe_unused]] auto * const dux_restr dat = static_cast<::dux::windat *>(this->_dat); + ::dux::dbgprint(U"dux :: Opening window!\n"); +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + ::xcb_map_window(::dux::_inst.xconn,dat->xwin); + ::xcb_flush(::dux::_inst.xconn); +# endif + ::dux::_inst.numwin += ::dux::uint16v(0x1); + ::dux::dbgprint(U"dux :: Current number of windows: $\n",::dux::_inst.numwin); + ::dux::_setsiginthandl(); + this->_isopen = true; +} +auto ::dux::win::pollevt() noexcept -> ::dux::opt<::dux::evt> { + ::dux::evt evt; + if (::dux::_inst.hassigint) [[unlikely]] { + evt.typ = ::dux::evttyp::quit; + ::dux::_inst.hassigint = false; + return evt; + } +#if defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + while (auto const xevt = ::xcb_poll_for_event(::dux::_inst.xconn)) { + switch (xevt->response_type & ~0x80) { + case XCB_CLIENT_MESSAGE: + evt.typ = ::dux::evttyp::quit; + break; + } + ::std::free(xevt); + return evt; + } +#endif + return evt; +} +auto ::dux::win::renm(char const * const dux_restr _nm) -> void { + [[maybe_unused]] auto * const dux_restr dat = static_cast<::dux::windat *>(this->_dat); +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + ::xcb_change_property(::dux::_inst.xconn,XCB_PROP_MODE_REPLACE,dat->xwin,XCB_ATOM_WM_NAME,XCB_ATOM_STRING,::dux::ubytev(0x8),static_cast<::dux::uint32>(::dux::cstrlen(_nm)),_nm); + ::xcb_flush(::dux::_inst.xconn); +# endif +} +auto ::dux::win::resz(::dux::uint16 const _w,::dux::uint16 const _h) -> void { + [[maybe_unused]] auto * const dux_restr dat = static_cast<::dux::windat *>(this->_dat); +#if defined(dux_gfxproto_wlgl) || defined(dux_gfxproto_wlvk) +#elif defined(dux_gfxproto_xgl) || defined(dux_gfxproto_xvk) + ::dux::uint32 const vals[] = { + _w, + _h, + }; + ::xcb_configure_window(::dux::_inst.xconn,dat->xwin,XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_WIDTH,vals); + ::xcb_flush(::dux::_inst.xconn); +#endif +} +::dux::win::win() : _dat(::new ::dux::windat) { +} +::dux::win::~win() noexcept { + if (this->_isopen) [[unlikely]] { + ::dux::dbgprint(U"dux :: Window was not closed!\n"); + ::dux::abrt(); + } +} diff --git a/u8c-check/src/test.cc b/u8c-check/src/test.cc deleted file mode 100644 index 1b600aa..0000000 --- a/u8c-check/src/test.cc +++ /dev/null @@ -1,116 +0,0 @@ -#if defined(NDEBUG) -#undef NDEBUG -#endif - -#include <chrono> /* std::chrono::duration, std::chrono::high_resolution_clock */ -#include <cstdlib> /* EXIT_FAILURE, EXIT_SUCCESS, std::exit */ -#include <cstring> /* std::strcmp */ -#include <iostream> /* std::cerr, std::cout, std::endl */ -#include <limits> /* std::numeric_limits */ -#include <u8c/u8c> - -# include "test0.inl" -# include "test1.inl" - -static_assert(u8c::abs(-0x1) == 0x1); -static_assert(u8c::abs(-0x1p0) == 0x1p0); -static_assert(u8c::abs(-0x100p0) == 0x100p0); - -static_assert(u8c::fma(0x10,0x10,0x100) == 0x200); - -static_assert(!u8c::isinf(0x0)); -static_assert(u8c::isinf(std::numeric_limits<float>::infinity())); - -static_assert(!u8c::isnan(0x0)); -static_assert(u8c::isnan(std::numeric_limits<float>::quiet_NaN())); - -static_assert(u8c::isprime(0x2u)); -static_assert(u8c::isprime(0x3u)); -static_assert(!u8c::isprime(0x4u)); -static_assert(u8c::isprime(0x5u)); -static_assert(!u8c::isprime(0x6u)); -static_assert(u8c::isprime(0x7u)); -static_assert(!u8c::isprime(0x8u)); -static_assert(!u8c::isprime(0x9u)); -static_assert(!u8c::isprime(0xAu)); -static_assert(u8c::isprime(0xBu)); -static_assert(!u8c::isprime(0xCu)); -static_assert(u8c::isprime(0xDu)); -static_assert(!u8c::isprime(0xEu)); -static_assert(!u8c::isprime(0xFu)); - -static_assert(u8c::pow(0x1,0x10000) == 0x1); -static_assert(u8c::pow(0x2,0x2) == 0x4); -static_assert(u8c::pow(0x2,0x4) == 0x10); -static_assert(u8c::pow(0x2,0x10) == 0x10000); -static_assert(u8c::pow(0x3,0x3) == 0x1B); - -static_assert(u8c::quota(0x1,0x3) < u8c::quota<>::inf()); -static_assert(u8c::quota(0x1,0x3) == u8c::quota(0x2,0x6)); -static_assert(u8c::quota<>::inf() == u8c::quota<>::inf()); -static_assert(u8c::quota<>::nan() != u8c::quota<>::nan()); - -static_assert(u8c::cstrlen("This is a string!") == 0x11uz); -static_assert(u8c::cstrlen("Das war ein Befehl!") == 0x13uz); - -static_assert(u8c::cstrcmp("Clang","Clang") == u8c_bytec(0x0)); -static_assert(u8c::cstrcmp("Clang","GCC") == u8c_bytec(0x1)); -static_assert(u8c::cstrcmp("GCC","Clang") == u8c_bytec(-0x1)); -static_assert(u8c::cstrcmp("GCC","GCC") == u8c_bytec(0x0)); - -auto main(int const argc,char const * const * const argv) -> int { - int constexpr maxtestn = 0x1; - auto gettestnm = [](int const _n) { - switch (_n) { - [[unlikely]] default: - return "N/A"; - case 0x0: - return "Array Stress-testing"; - case 0x1: - return "Strings"; - } - }; - auto helpscrn = [&](char const * const _prognm) { - std::cout << "u8c-test: Test u8c" << std::endl; - std::cout << "Usage: " << _prognm << " [test number]" << std::endl; - std::cout << std::endl; - std::cout << "Test numbers:" << std::endl; - for (int n = 0x0;n <= maxtestn;n += 0x1) { - std::cout << "\t " << n << " - \"" << gettestnm(n) << "\"" << std::endl; - } - std::cout << std::endl; - std::cout << "u8c version: " << u8c::ver << std::endl; - }; - auto test = [&](int const _n) { - auto const testnm = gettestnm(_n); - std::cout << ":: \u001B[95mTesting\u001B[0m test #" << _n << " \u001B[3m\"" << testnm << "\"\u001B[0m..." << std::endl << std::endl; - auto begin = std::chrono::high_resolution_clock::now(); - switch (_n) { - [[unlikely]] default: - std::exit(EXIT_FAILURE); - case 0x0: - ::test0(); - break; - case 0x1: - ::test1(); - break; - } - auto const end = std::chrono::high_resolution_clock::now(); - std::chrono::duration<double> const tmdiff = end - begin; - std::cout << std::endl << ":: \u001B[96mDone\u001B[0m testing test #" << _n << " \u001B[3m\"" << testnm << "\"\u001B[0m (took " << tmdiff.count() << " seconds)." << std::endl; - }; - if (argc > 0x1) { - if (!std::strcmp(argv[0x1uz],"--help")) { - helpscrn(argv[0x0uz]); - std::exit(EXIT_SUCCESS); - } - else { - std::cerr << "Invalid argument \"\u001B[3m" << argv[0x1uz] << "\"\u001B[0m." << std::endl; - std::exit(EXIT_FAILURE); - } - } - for (int n = 0x0;n <= maxtestn;n += 0x1) { - test(n); - } - std::exit(EXIT_SUCCESS); -} diff --git a/u8c-check/src/test0.inl b/u8c-check/src/test0.inl deleted file mode 100644 index 5b4db6c..0000000 --- a/u8c-check/src/test0.inl +++ /dev/null @@ -1,49 +0,0 @@ -#include <iostream> /* std::cerr, std::endl */ -#include <limits> /* std::numeric_limits */ -#include <random> /* std::random_device, std::uniform_int_distribution */ -#include <u8c/arr> - -auto test0() -> void { - std::cerr << "Constructing array of 256 elements, each with a value of 15..."; - u8c::arr<int> arr(0x100uz,0xF); - u8c_assert(arr.sz() == 0x100uz); - u8c_assert(static_cast<u8c::size>(arr.end() - arr.begin()) == arr.sz()); - for (auto const elm : arr) { - u8c_assert(elm == 0xF); - } - std::cerr << " okay." << std::endl; - std::random_device rd; - { - std::uniform_int_distribution<int> distr(0x0,std::numeric_limits<int>::max()); - for (u8c::byte n = u8c_bytec(0x0);n <= u8c_bytec(0x10);n += u8c_ubytec(0x1)) { - auto const val = distr(rd); - std::cerr << "Filling array with the value of " << val << "..."; - arr.fill(val); - for (auto const elm : arr) { - u8c_assert(elm == val); - } - std::cerr << " okay." << std::endl; - } - } - { - std::uniform_int_distribution<u8c::size> distr(0x1,0xFFF); - for (u8c::byte n = u8c_bytec(0x0);n <= u8c_bytec(0x4);n += u8c_ubytec(0x1)) { - auto const sz = distr(rd); - std::cerr << "Allocating the array to the size of " << sz << "..."; - arr.alloc(sz); - u8c_assert(arr.sz() == sz); - std::cerr << " okay." << std::endl; - } - } - std::cerr << "Doing some additionel tests..."; - arr.alloc(0x2uz); - u8c_assert(arr.sz() == 0x2uz); - arr.fill(0xF); - u8c_assert(arr[0x0uz] == 0xF); - u8c_assert(arr[0x1uz] == 0xF); - arr.realloc(0x4uz); - u8c_assert(arr.sz() == 0x4uz); - u8c_assert(arr[0x0uz] == 0xF); - u8c_assert(arr[0x1uz] == 0xF); - std::cerr << " okay." << std::endl; -} diff --git a/u8c-check/src/test1.inl b/u8c-check/src/test1.inl deleted file mode 100644 index 4e2a18e..0000000 --- a/u8c-check/src/test1.inl +++ /dev/null @@ -1,24 +0,0 @@ -#include <cstdint> /* u8c_uint32c, u8c_ubytec, std::int_fast8_t, u8c::uint32 */ -#include <iomanip> /* std::hex */ -#include <iostream> /* std::cout, std::endl */ -#include <random> /* std::random_device */ - -auto test1() -> void { - std::random_device rd; - std::uniform_int_distribution<char32_t> distr(u8c_uint32c(0x0),u8c_uint32c(0x100)); - for(std::int_fast8_t n = u8c_bytec(0x0);n <= u8c_bytec(0x4);n += u8c_ubytec(0x1)) { - auto const chr = distr(rd); - std::cout << "U+" << std::hex << static_cast<u8c::uint32>(chr) << " (\"" << u8c::uninm(chr) << "\" @ \"" << u8c::uniblk(chr) << "\")" << std::endl; - std::cout << "Is alphanumeric: " << u8c::isalnum(chr) << std::endl; - std::cout << "Is alphabetic: " << u8c::isalpha(chr) << std::endl; - std::cout << "Is control character: " << u8c::iscntrl(chr) << std::endl; - std::cout << "Is digit: " << u8c::isdigit(chr) << std::endl; - std::cout << "Is lowercase: " << u8c::islower(chr) << std::endl; - std::cout << "Is punctuation mark: " << u8c::ispunct(chr) << std::endl; - std::cout << "Is whitespace: " << u8c::isspace(chr) << std::endl; - std::cout << "Is surrogate point: " << u8c::issurro(chr) << std::endl; - std::cout << "Is uppercase: " << u8c::isupper(chr) << std::endl; - std::cout << "Is hexadecimal digit: " << u8c::isxdigit(chr) << std::endl; - std::cout << std::endl; - } -} @@ -1,5 +1,4 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg height="768" version="1.1" width="768" xmlns="http://www.w3.org/2000/svg"> +<svg height="768" width="768" xmlns="http://www.w3.org/2000/svg"> <clipPath id="clipPath61"> <rect height="768" width="381" x="387" /> </clipPath> diff --git a/u8c/include/u8c/arr b/u8c/include/u8c/arr deleted file mode 100644 index 5d8fc4d..0000000 --- a/u8c/include/u8c/arr +++ /dev/null @@ -1,65 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_RMLtbYyYWBICBIbq) -#define u8c_key_RMLtbYyYWBICBIbq - -#include <u8c/misc> - -namespace u8c { - template<typename T> class arr { - public: - constexpr auto alloc( u8c::size num) -> void; - template<std::convertible_to<T> T0> constexpr auto alloc( u8c::size num, T0 val) -> void; - constexpr auto app( u8c::arr<T> const & oth) -> u8c::arr<T> const &; - template<std::convertible_to<T> T0> constexpr auto app( T0 val) -> u8c::arr<T> const &; - [[nodiscard]] constexpr arr() noexcept = default; - [[nodiscard]] constexpr arr( T const * begin, T const * end); - [[nodiscard]] constexpr arr( u8c::size num); - [[nodiscard]] constexpr arr( u8c::arr<T> const & oth); - template<u8c::size N> [[nodiscard]] constexpr arr( T const (& arr)[N]) noexcept; - template<std::convertible_to<T> T0> [[nodiscard]] constexpr arr( u8c::size num, T0 val); - [[nodiscard]] constexpr auto begin() const noexcept -> T *; - [[nodiscard]] constexpr auto end() const noexcept -> T *; - template<std::convertible_to<T> T0> constexpr auto fill( T0 val) -> void; - template<std::convertible_to<T> T0> constexpr auto fill( T * begin, T * end,T0 val) -> void; - [[nodiscard]] constexpr auto isstatic() const noexcept -> bool; - constexpr auto log( bool val) noexcept -> void; - constexpr auto operator = ( u8c::arr<T> const & oth) -> u8c::arr<T> const &; - [[nodiscard]] constexpr auto operator [] (u8c::size pos) const noexcept -> T &; - constexpr auto realloc( u8c::size num) -> void; - constexpr auto set( T const * begin, T const * end) -> void; - constexpr auto set( u8c::arr<T> const & oth) -> void; - template<u8c::size N> constexpr auto set( T const (& arr)[N]) noexcept -> void; - template<std::convertible_to<T> T0> constexpr auto set( T0 val) -> void; - [[nodiscard]] constexpr auto sub( T const * begin, T const * end) const -> u8c::arr<T>; - [[nodiscard]] constexpr auto sz() const noexcept -> u8c::size; - constexpr ~arr() noexcept; - constexpr static auto npos = -0x1uz; - private: - bool _isstatic = false; - bool mutable _log = false; - T * _ptr = nullptr; - u8c::size _sz = 0x0uz; - }; -} - -#include <u8c/arr.d/arr> - -#endif diff --git a/u8c/include/u8c/arr.d/arr b/u8c/include/u8c/arr.d/arr deleted file mode 100644 index 63f35ad..0000000 --- a/u8c/include/u8c/arr.d/arr +++ /dev/null @@ -1,183 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_zQ92KNf0pxkz48g2) -#define u8c_key_zQ92KNf0pxkz48g2 - -#include <algorithm> /* std::copy, std::fill */ -#include <cstdlib> /* std::abort */ -#include <iostream> /* std::cerr, std::endl */ -#include <stdexcept> /* std::invalid_argument, std::out_of_range */ -#include <type_traits> /* std::is_constant_evaluated */ - -template<typename T> constexpr auto u8c::arr<T>::alloc(u8c::size const _num) -> void { - if (this->isstatic()) [[unlikely]] { - this->_isstatic = false; - } - else { - ::delete[] this->_ptr; - } - this->_ptr = ::new T[_num](); - this->_sz = _num; -} -template<typename T> template<std::convertible_to<T> T0> constexpr auto u8c::arr<T>::alloc(u8c::size const _num,T0 const _val) -> void { - this->alloc(_num); - this->fill(this->begin(),this->end(),_val); -} -template<typename T> constexpr auto u8c::arr<T>::app(u8c::arr<T> const & _oth) -> u8c::arr<T> const & { - this->realloc(this->sz() + _oth.sz()); - std::copy(_oth.begin(),_oth.end(),this->begin() + this->sz() - _oth.sz()); - return *this; -} -template<typename T> template<std::convertible_to<T> T0> constexpr auto u8c::arr<T>::app(T0 const _val) -> u8c::arr<T> const & { - this->realloc(this->sz() + 0x1uz); - (*this)[this->sz() - 0x1uz] = static_cast<T>(_val); - return *this; -} -template<typename T> constexpr u8c::arr<T>::arr(T const * const _begin,T const * const _end) { - this->set(_begin,_end); -} -template<typename T> constexpr u8c::arr<T>::arr(u8c::size const _num) { - this->alloc(_num); -} -template<typename T> constexpr u8c::arr<T>::arr(u8c::arr<T> const & _oth) { - this->set(_oth); -} -template<typename T> template<u8c::size N> constexpr u8c::arr<T>::arr(T const (&_arr)[N]) noexcept { - this->set(_arr); -} -template<typename T> template<std::convertible_to<T> T0> constexpr u8c::arr<T>::arr(u8c::size const _num,T0 const _val) { - this->alloc(_num,_val); -} -template<typename T> constexpr auto u8c::arr<T>::begin() const noexcept -> T * { - return this->_ptr; -} -template<typename T> constexpr auto u8c::arr<T>::end() const noexcept -> T * { - return this->begin() + this->_sz; -} -template<typename T> template<std::convertible_to<T> T0> constexpr auto u8c::arr<T>::fill(T0 const _val) -> void { - this->fill(this->begin(),this->end(),_val); -} -template<typename T> template<std::convertible_to<T> T0> constexpr auto u8c::arr<T>::fill(T * const u8c_restr _begin,T * const u8c_restr _end,T0 const _val) -> void { - if (this->sz() == 0x0uz) [[unlikely]] { - return; /* slime incident */ - } - if constexpr (u8c::dbg) { - if (_begin < this->begin() || _end > this->end()) [[unlikely]] { - throw std::out_of_range("Beginning or end are out of this array's range."); - } - } - if (this->isstatic()) [[unlikely]] { - this->alloc(static_cast<u8c::size>(_end - _begin)); - } - std::fill(this->begin(),this->end(),static_cast<T>(_val)); -} -template<typename T> constexpr auto u8c::arr<T>::isstatic() const noexcept -> bool { - return this->_isstatic; -} -template<typename T> constexpr auto u8c::arr<T>::log(bool const _val) noexcept -> void { - this->_log = _val; -} -template<typename T> constexpr auto u8c::arr<T>::operator = (u8c::arr<T> const & _oth) -> u8c::arr<T> const & { - this->set(_oth); - return *this; -} -template<typename T> constexpr auto u8c::arr<T>::operator [] (u8c::size const _pos) const noexcept -> T & { - if constexpr (u8c::dbg) { - if (_pos >= this->sz()) [[unlikely]] { - std::cerr << "u8c :: " << __func__ << " :: Input parameter is out of range." << std::endl; - std::abort(); - } - } - return this->begin()[_pos]; -} -template<typename T> constexpr auto u8c::arr<T>::realloc(u8c::size const _num) -> void { - if (this->sz() == 0x0uz) [[unlikely]] { - return this->alloc(_num); - } - if (this->isstatic()) [[unlikely]] { - this->_isstatic = false; - } - this->_ptr = u8c::renew(this->begin(),this->sz(),_num); - this->_sz = _num; -} -template<typename T> constexpr auto u8c::arr<T>::set(T const * const u8c_restr _begin,T const * const u8c_restr _end) -> void { - if constexpr (u8c::dbg) { - if (_begin == nullptr || _end == nullptr) [[unlikely]] { - throw std::invalid_argument("Provided parameter has value of nullptr."); - } - } - this->alloc(static_cast<u8c::size>(_end - _begin + 0x1uz)); - std::copy(_begin,_end,this->begin()); -} -template<typename T> constexpr auto u8c::arr<T>::set(u8c::arr<T> const & _oth) -> void { - this->set(_oth.begin(),_oth.end()); -} -template<typename T> template<u8c::size N> constexpr auto u8c::arr<T>::set(T const (&_arr)[N]) noexcept -> void { - this->~arr(); - this->_isstatic = true; - this->_ptr = _arr; - this->_sz = N; -} -template<typename T> template<std::convertible_to<T> T0> constexpr auto u8c::arr<T>::set(T0 const _val) -> void { - this->alloc(0x1uz); - *this->begin() = _val; -} -template<typename T> constexpr auto u8c::arr<T>::sub(T const * const u8c_restr _begin,T const * const u8c_restr _end) const -> u8c::arr<T> { - if (this->_log) [[unlikely]] { - std::cerr << "u8c :: Generating subarray" << std::endl; - } - if constexpr (u8c::dbg) { - if (_begin < this->begin() || _end > this->end()) [[unlikely]] { - if (this->_log) [[unlikely]] { - std::cerr << "u8c :: Input out of range" << std::endl; - } - throw std::out_of_range("Beginning or end are out of this array's range."); - } - } - u8c::size const sz = static_cast<u8c::size>(_end - _begin) + 0x1uz; - u8c::arr<T> arr; - if (this->isstatic()) [[unlikely]] { - arr._sz = sz; - arr._ptr = _begin; - } - else { - arr.alloc(sz); - std::copy(_begin,_end,arr.begin()); - } - return arr; -} -template<typename T> constexpr auto u8c::arr<T>::sz() const noexcept -> u8c::size { - return this->_sz; -} -template<typename T> constexpr u8c::arr<T>::~arr<T>() noexcept { - if (this->isstatic()) { - if (this->_log) [[unlikely]] { - std::cerr << "u8c :: Destroying static array" << std::endl; - } - return; - } - if (this->_log) [[unlikely]] { - std::cerr << "u8c :: Destroying dynamic array" << std::endl; - std::cerr << "u8c :: Deallocating" << std::endl; - } - ::delete[] this->_ptr; -} - -#endif diff --git a/u8c/include/u8c/cstr b/u8c/include/u8c/cstr deleted file mode 100644 index f8f5184..0000000 --- a/u8c/include/u8c/cstr +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_gM1GPEGwZN8BgcwU) -#define u8c_key_gM1GPEGwZN8BgcwU - -#include <u8c/misc> - -namespace u8c { - constexpr auto cstrcmp(char const * lstr,char const * rstr) noexcept -> u8c::byte; - constexpr auto cstrcpy(char * dest,char const * src) noexcept -> char *; - constexpr auto cstrdup(char const * str) -> char *; - constexpr auto cstrlen(char const * str) noexcept -> u8c::size; -} - -#include <u8c/cstr.d/cstrcmp> -#include <u8c/cstr.d/cstrcpy> -#include <u8c/cstr.d/cstrdup> -#include <u8c/cstr.d/cstrlen> - -#endif diff --git a/u8c/include/u8c/cstr.d/cstrdup b/u8c/include/u8c/cstr.d/cstrdup deleted file mode 100644 index d37f03b..0000000 --- a/u8c/include/u8c/cstr.d/cstrdup +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_vf9vDNmIndanmgPg) -#define u8c_key_vf9vDNmIndanmgPg - -constexpr auto u8c::cstrdup(char const * const u8c_restr _str1) -> char * { - auto const sz = u8c::cstrlen(_str1); - auto * const u8c_restr str = ::new char[sz]; - return u8c::cstrcpy(str,_str1);; -} - -#endif diff --git a/u8c/include/u8c/impl b/u8c/include/u8c/impl deleted file mode 100644 index af6a2c4..0000000 --- a/u8c/include/u8c/impl +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_9y1ZpGLV5Chmuy9U) -#define u8c_key_9y1ZpGLV5Chmuy9U - -#include <u8c/cstr> - -namespace u8c { - [[nodiscard]] consteval auto isarch(char const * arch) noexcept -> bool; - [[nodiscard]] consteval auto isos( char const * os) noexcept -> bool; -} - -#include <u8c/impl.d/isarch> -#include <u8c/impl.d/isos> - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/impl.d/isarch b/u8c/include/u8c/impl.d/isarch deleted file mode 100644 index 33b0faa..0000000 --- a/u8c/include/u8c/impl.d/isarch +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_HeaDXGqHoIcCdWWR) -#define u8c_key_HeaDXGqHoIcCdWWR - -consteval auto u8c::isarch([[maybe_unused]] char const * const u8c_restr _arch) noexcept -> bool { - if (!u8c::cstrcmp(_arch,"alpha")) { -#if defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_arch,"arm")) { -#if defined(__TARGET_ARCH_ARM) || defined(__TARGET_ARCH_THUMB) || defined(__arm) || defined(__arm__) || defined(__thumb__) || defined(_M_ARM) || defined(_M_ARMT) - return true; -#else - return false; - } -#endif - if (!u8c::cstrcmp(_arch,"itanium")) { -#if defined(__IA64__) || defined(__ia64__) || defined(__itanium__) || defined(_IA64) || defined(_M_IA64) - return true; -#else - return false; - } -#endif - if (!u8c::cstrcmp(_arch,"m68k")) { -#if defined(__MC68K__) || defined(__m68k__) || defined(M68000) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_arch,"mips")) { -#if defined(__MIPS__) || defined(__mips) || defined(__mips__) || defined(mips) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_arch,"pa-risc")) { -#if defined(__HPPA__) || defined(__hppa) || defined(__hppa__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_arch,"ppc")) { -#if defined(__POWERPC__) || defined(__ppc) || defined(__PPC__) || defined(__powerpc) || defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(_M_PPC) || defined(_XENON) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_arch,"sparc")) { -#if defined(__sparc) || defined(__sparc__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_arch,"x86")) { -#if defined(__386) || defined(__I86__) || defined(__IA32__) || defined(__INTEL__) || defined(__THW_INTEL__) || defined(__X86__) || defined(__i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_I86) || defined(_M_IX86) || defined(_X86_) ||defined(i386) - return true; -#else - return false; -#endif - } - return false; -} - -#endif diff --git a/u8c/include/u8c/impl.d/isos b/u8c/include/u8c/impl.d/isos deleted file mode 100644 index 06a6934..0000000 --- a/u8c/include/u8c/impl.d/isos +++ /dev/null @@ -1,258 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_ACd4FIGZ23h2QNrU) -#define u8c_key_ACd4FIGZ23h2QNrU - -#if __has_include(<sys/param.h>) -#include <sys/param.h> /* BSD */ -#endif -#if __has_include(<unistd.h>) -#include <unistd.h> /* _POSIX_VERSION */ -#endif - -consteval auto u8c::isos(char const * const u8c_restr _os) noexcept -> bool { - if (!u8c::cstrcmp(_os,"aix")) { -#if defined(__TOS_AIX__) || defined(_AIX) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"amigaos")) { -#if defined(__amigaos__) || defined(AMIGA) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"android")) { -#if defined(__ANDROID__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"beos")) { -#if defined(__BEOS__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"bluegene")) { -#if defined(__THW_BLUEGENE__) || defined(__TOS_BGQ__) || defined(__bg__) || defined(__bgq__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"bsd")) { -#if defined(_SYSTYPE_BSD) || defined(BSD) - return true; -#else - return u8c::isos("bsdos") || u8c::isos("dragonflybsd") || u8c::isos("freebsd") || u8c::isos("netbsd") || u8c::isos("openbsd"); -#endif - } - if (!u8c::cstrcmp(_os,"bsdos")) { -#if defined(__bsdi__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"dragonflybsd")) { -#if defined(__DragonFly__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"freebsd")) { -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"hpux")) { -#if defined(__hpux) || defined(_hpux) || defined(hpux) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"hurd")) { -#if defined(__GNU__) || defined(__gnu_hurd__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"ibmi")) { -#if defined(__OS400__) || defined(__OS400_TGTVRM__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"integrity")) { -#if defined(__INTEGRITY) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"interix")) { -#if defined(__INTERIX) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"irix")) { -#if defined(__sgi) || defined(sgi) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"linux")) { -#if defined(__linux) || defined(__linux__) || defined(linux) || defined(u8c_os_android) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"mac")) { -#if (defined(__APPLE__) && defined(__MACH__)) || defined(Macintosh) || defined(macintosh) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"minix")) { -#if defined(__minix) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"msdos")) { -#if defined(__DOS__) || defined(__MSDOS__) || defined(_MSDOS) || defined(MSDOS) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"netbsd")) { -#if defined(__NetBSD__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"nonstop")) { -#if defined(__TANDEM) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"openbsd")) { -#if defined(__OpenBSD__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"os2")) { -#if defined(__OS2__) || defined(__TOS_OS2__) || defined(_OS2) || defined(OS2) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"palmos")) { -#if defined(__palmos__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"qnx")) { -#if defined(__QNX__) || defined(__QNXNTO__) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"solaris")) { -#if (defined(__SVR4) || defined(__svr4__) || defined(__sysv__) || defined(_SYSTYPE_SVR4)) && (defined(__sun) || defined(sun)) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"sun")) { -#if defined(__sun) || defined(sun) - return !u8c::isos("solaris"); -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"unicos")) { -#if defined(_UNICOS) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"unix")) { -#if defined(__unix) || defined(__unix__) || defined(_POSIX_VERSION) || defined(u8c_os_aix) || defined(u8c_os_android)|| defined(u8c_os_bsd) || defined(u8c_os_hpux) || defined(u8c_os_hurd) || defined(u8c_os_linux) || defined(u8c_os_mac) || defined(u8c_os_minix) || defined(u8c_os_solaris) || defined(u8c_os_sun) || defined(u8c_os_unicos) || defined(u8c_os_unixware) || defined(unix) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"unixware")) { -#if defined(sco) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"win")) { -#if defined(__TOS_WIN__) || defined(__WIN32__) || defined(__WINDOWS__) || defined(_WIN16) || defined(_WIN32) || defined(_WIN32_CE) || defined(_WIN64) - return true; -#else - return false; -#endif - } - if (!u8c::cstrcmp(_os,"zos")) { -#if defined(__HOS_MVS__) || defined(__MVS__) || defined(__TOS_MVS__) - return true; -#else - return false; -#endif - } - return false; -} - -#endif diff --git a/u8c/include/u8c/math b/u8c/include/u8c/math deleted file mode 100644 index d02a827..0000000 --- a/u8c/include/u8c/math +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_vm8mXaTP2bcUVL49) -#define u8c_key_vm8mXaTP2bcUVL49 - -#include <compare> /* std::partial_ordering */ -#include <concepts> /* std::convertible_to, std::floating_point, std::integral, std::signed_integral */ -#include <type_traits> /* std::is_arithmetic_v, std::is_same_v */ -#include <u8c/impl> - -namespace u8c { - template<std::signed_integral T = int> class quota { - public: - [[nodiscard]] constexpr static auto inf() noexcept -> u8c::quota<T>; - [[nodiscard]] constexpr auto isinf() const noexcept -> bool; - [[nodiscard]] constexpr auto isnan() const noexcept -> bool; - [[nodiscard]] constexpr auto lower() const noexcept -> T; - [[nodiscard]] constexpr static auto nan() noexcept -> u8c::quota<T>; - [[nodiscard]] constexpr auto upper() const noexcept -> T; - template<std::convertible_to<T> T0> [[nodiscard]] constexpr auto operator + (u8c::quota<T0> const & oth) const noexcept -> u8c::quota<T>; - template<std::convertible_to<T> T0> [[nodiscard]] constexpr auto operator - (u8c::quota<T0> const & oth) const noexcept -> u8c::quota<T>; - template<std::convertible_to<T> T0> [[nodiscard]] constexpr auto operator <=> (u8c::quota<T0> const & oth) const noexcept -> std::partial_ordering; - template<std::convertible_to<T> T0> [[nodiscard]] constexpr auto operator = ( u8c::quota<T0> const & oth) const noexcept -> bool; - template<std::convertible_to<T> T0> [[nodiscard]] constexpr auto operator == ( u8c::quota<T0> const & oth) const noexcept -> bool; - template<std::integral T0> [[nodiscard]] constexpr operator T0 () const noexcept; - [[nodiscard]] constexpr quota() noexcept = default; - template<std::convertible_to<T> T0> [[nodiscard]] constexpr quota( T0 val) noexcept; - template<std::convertible_to<T> T0> [[nodiscard]] constexpr quota( u8c::quota<T0> const & oth) noexcept; - template<std::signed_integral T0> [[nodiscard]] constexpr quota( T0 upper,T0 lower) noexcept; - constexpr ~quota() noexcept = default; - private: - u8c::ubyte _flags = false; - T _lower = T{0x0}; - T _upper = T{0x0}; - - }; - template<typename T,typename T0 = void> concept arith = std::is_arithmetic_v<T> || std::is_same_v<T,u8c::quota<T0>>; - template<typename T> [[u8c_attr_const]] constexpr auto abs( u8c::quota<T> val) noexcept -> u8c::quota<T>; - template<u8c::arith T> [[u8c_attr_const]] constexpr auto abs( T val) noexcept -> T; - template<typename T> [[u8c_attr_const]] constexpr auto fma( u8c::quota<T> x, u8c::quota<T> y, u8c::quota<T> z) noexcept -> u8c::quota<T>; - template<u8c::arith T> [[u8c_attr_const]] constexpr auto fma( T x, T y, T z) noexcept -> T; - template<u8c::arith T> [[u8c_attr_const]] constexpr auto isinf( T val) noexcept -> bool; - template<u8c::arith T> [[u8c_attr_const]] constexpr auto isnan( T val) noexcept -> bool; - template<typename T> [[u8c_attr_const]] constexpr auto isprime(u8c::quota<T> val) noexcept -> bool; - template<u8c::arith T> [[u8c_attr_const]] constexpr auto isprime(T val) noexcept -> bool; - template<typename T> [[u8c_attr_const]] constexpr auto pow( u8c::quota<T> base,u8c::quota<T> exp) noexcept -> u8c::quota<T>; - template<u8c::arith T> [[u8c_attr_const]] constexpr auto pow( T base,T exp) noexcept -> T; - template<typename T> [[u8c_attr_const]] constexpr auto sqrt( u8c::quota<T> val) noexcept -> u8c::quota<T>; - template<u8c::arith T> [[u8c_attr_const]] constexpr auto sqrt( T val) noexcept -> T; -} - -#include <u8c/math.d/abs> -#include <u8c/math.d/fma> -#include <u8c/math.d/isinf> -#include <u8c/math.d/isnan> -#include <u8c/math.d/isprime> -#include <u8c/math.d/pow> -#include <u8c/math.d/quota> -#include <u8c/math.d/sqrt> - -#endif diff --git a/u8c/include/u8c/math.d/isinf b/u8c/include/u8c/math.d/isinf deleted file mode 100644 index e77793a..0000000 --- a/u8c/include/u8c/math.d/isinf +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_aSzgnLkMAeJF6xFF) -#define u8c_key_aSzgnLkMAeJF6xFF - -#include <limits> /* std::numeric_limits */ - -template<u8c::arith T> constexpr auto u8c::isinf(T const _val) noexcept -> bool { - if (std::numeric_limits<T>::has_infinity) { - return _val == std::numeric_limits<T>::infinity(); - } - return false; -} - -#endif diff --git a/u8c/include/u8c/math.d/isnan b/u8c/include/u8c/math.d/isnan deleted file mode 100644 index 9e90d12..0000000 --- a/u8c/include/u8c/math.d/isnan +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_0RXxS4xdwMkbkEi6) -#define u8c_key_0RXxS4xdwMkbkEi6 - -#include <limits> /* std::numeric_limits */ - -template<u8c::arith T> constexpr auto u8c::isnan(T const _val) noexcept -> bool { - if constexpr (std::numeric_limits<T>::has_quiet_NaN) { - if constexpr (std::numeric_limits<T>::is_iec559) { - return _val != _val; - } - else { -#if defined(__cpp_if_consteval) - if consteval { - return _val != _val; - } - else { - u8c::ubyte * const u8c_restr nanval = nullptr; - u8c::ubyte * const u8c_restr valval = nullptr; - { - auto const tmp = std::numeric_limits<T>::quiet_NaN(); - nanval = reinterpret_cast<unsigned char *>(&tmp); - } - { - auto const tmp = _val; - valval = reinterpret_cast<unsigned char *>(&tmp); - } - for (std::size_t n = 0x0uz;n < sizeof(T);n += 0x1uz) { - if (valval[n] != nanval[n]) { - return false; - } - } - } -#else - return _val != _val; -#endif - } - } - else { - return false; - } -} - -#endif diff --git a/u8c/include/u8c/math.d/quota b/u8c/include/u8c/math.d/quota deleted file mode 100644 index 4e3ecf8..0000000 --- a/u8c/include/u8c/math.d/quota +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_k92caE4RpzrErnKD) -#define u8c_key_k92caE4RpzrErnKD - -#include <compare> /* std::partial_ordering */ -#include <concepts> /* std:convertible_to, std::integral, std::signed_integral */ - -template<std::signed_integral T> constexpr auto u8c::quota<T>::inf() noexcept -> u8c::quota<T> { - auto tmp = u8c::quota<T>(); - tmp._flags = u8c_ubytec(0b10); - return tmp; -} -template<std::signed_integral T> constexpr auto u8c::quota<T>::isinf() const noexcept -> bool { - return (this->_flags & u8c_ubytec(0b10)) == u8c_ubytec(0b10); -} -template<std::signed_integral T> constexpr auto u8c::quota<T>::isnan() const noexcept -> bool { - return (this->_flags & u8c_ubytec(0b1)) == u8c_ubytec(0b1); -} -template<std::signed_integral T> constexpr auto u8c::quota<T>::lower() const noexcept -> T { - return this->_lower; -} -template<std::signed_integral T> constexpr auto u8c::quota<T>::nan() noexcept -> u8c::quota<T> { - auto tmp = u8c::quota<T>(); - tmp._flags = u8c_ubytec(0b1); - return tmp; -} -template<std::signed_integral T> constexpr auto u8c::quota<T>::upper() const noexcept -> T { - return this->_upper; -} -template<std::signed_integral T> template<std::convertible_to<T> T0> constexpr auto u8c::quota<T>::operator <=> (u8c::quota<T0> const & _oth) const noexcept -> std::partial_ordering { - if (this->isinf()) { - return std::partial_ordering::greater; - } - if (_oth.isinf()) { - return std::partial_ordering::less; - } - if (this->isnan() || _oth.isnan()) [[unlikely]] { - return std::partial_ordering::unordered; - } - auto const tmp0 = this->upper() * _oth.lower(); - auto const tmp1 = _oth.upper() * this->lower(); - return tmp0 <=> tmp1; -} -template<std::signed_integral T> template<std::convertible_to<T> T0> constexpr auto u8c::quota<T>::operator == (u8c::quota<T0> const & _oth) const noexcept -> bool { - if (this->isinf() && _oth.isinf()) [[unlikely]] { - return true; - } - if (this->isnan() || _oth.isnan()) [[unlikely]] { - return false; - } - if (this->_flags != _oth._flags) [[unlikely]] { - return false; - } - return this->upper() * _oth.lower() == _oth.upper() * this->lower(); -} -template<std::signed_integral T> template<std::integral T0> constexpr u8c::quota<T>::operator T0 () const noexcept { - return static_cast<T0>(this->_upper / this->_lower); -} -template<std::signed_integral T> template<std::convertible_to<T> T0> constexpr u8c::quota<T>::quota(T0 const _val) noexcept { - if (u8c::isnan(_val)) [[unlikely]] { - this->_flags |= u8c_ubytec(0b1); - } - else if (u8c::isinf(_val)) [[unlikely]] { - this->_flags |= u8c_ubytec(0b10); - } - else { - this->_upper = T{_val}; - this->_lower = T{0x1}; - } -} -template<std::signed_integral T> template<std::signed_integral T0> constexpr u8c::quota<T>::quota(T0 const _upper,T0 const _lower) noexcept { - this->_upper = _upper; - this->_lower = _lower; -} - -#endif
\ No newline at end of file diff --git a/u8c/include/u8c/misc b/u8c/include/u8c/misc deleted file mode 100644 index f7deca1..0000000 --- a/u8c/include/u8c/misc +++ /dev/null @@ -1,132 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_4grZQR1RdsRJL14e) -#define u8c_key_4grZQR1RdsRJL14e - -#include <climits> /* CHAR_BIT */ -#include <cstdint> /* std::int_least16_t, std::int_least32_t, std::int_least64_t, std::int_least8_t, std::intmax_t, std::uint_least16_t, std::uint_least32_t, std::uint_least64_t, std::uint_least8_t, std::uintmax_t */ -#include <cstdlib> /* std::abort */ -#include <iostream> /* std::cerr, std::endl */ - -#define u8c_assert(expr) \ - if constexpr (!u8c::dbg) { \ - /*if consteval { \ - static_assert(expr); \ - } \ - else*/ if (!(expr)) [[unlikely]] { \ - std::cerr << "u8c :: \"" << __FILE__ "\" @ " << __LINE__ << ": Assertion failed: expression \"" << #expr << "\" evaluates to false." << std::endl; \ - std::abort(); \ - } \ - } \ - -#if defined(__GNUC__) || defined(__clang__) -#define u8c_attr_abitag(...) gnu::abi_tag(__VA_ARGS__) -#define u8c_attr_allocsz(...) gnu::alloc_size(__VA_ARGS__) -#define u8c_attr_artif gnu::artificial -#define u8c_attr_cold gnu::cold -#define u8c_attr_const gnu::const -#define u8c_attr_fmt gnu::format -#define u8c_attr_malloc gnu::malloc -#define u8c_attr_nonnull(...) gnu::nonnull(__VA_ARGS__) -#define u8c_attr_hot gnu::hot -#define u8c_attr_inline gnu::always_inline -#define u8c_attr_pure gnu::pure -#define u8c_attr_retnonnull gnu::returns_nonnull -#define u8c_attr_sect gnu::section -#define u8c_attr_used gnu::used -#else -#define u8c_attr_abitag(...) -#define u8c_attr_allocsz(...) -#define u8c_attr_artif -#define u8c_attr_cold -#define u8c_attr_const -#define u8c_attr_fmt -#define u8c_attr_hot -#define u8c_attr_inline -#define u8c_attr_malloc -#define u8c_attr_nonnull(...) -#define u8c_attr_pure -#define u8c_attr_retnonnull -#define u8c_attr_sect -#define u8c_attr_used -#endif -#if defined(__clang__) -#define u8c_attr_noderef clang::noderef -#define u8c_attr_nodup clang::noduplicate -#define u8c_attr_noesc(...) clang::noescape(__VA_ARGS__) -#else -#define u8c_attr_noderef -#define u8c_attr_nodup -#define u8c_attr_noesc(...) -#endif - -#define u8c_bytec(expr) (static_cast<u8c::byte>(INT8_C(expr))) -#define u8c_int16c(expr) (static_cast<u8c::int16>(INT16_C(expr))) -#define u8c_int32c(expr) (static_cast<u8c::int32>(INT32_C(expr))) -#define u8c_int64c(expr) (static_cast<u8c::int64>(INT64_C(expr))) -#define u8c_intmaxc(expr) (static_cast<u8c::intmax>(INTMAX_C(expr))) -#define u8c_ubytec(expr) (static_cast<u8c::ubyte>(UINT8_C(expr))) -#define u8c_uint16c(expr) (static_cast<u8c::uint16>(UINT16_C(expr))) -#define u8c_uint32c(expr) (static_cast<u8c::uint32>(UINT32_C(expr))) -#define u8c_uint64c(expr) (static_cast<u8c::uint64>(UINT64_C(expr))) -#define u8c_uintmaxc(expr) (static_cast<u8c::uintmax>(UINTMAX_C(expr))) - -#if defined(__GNUC__) || defined(__clang__) -#define u8c_restr __restrict__ -#elif defined(__INTEL_COMPILER) || defined(_MSC_VER) -#define u8c_restr __restrict -#else -#define u8c_restr -#endif - -namespace u8c { - using byte = signed char; - using int16 = std::int_least16_t; - using int32 = std::int_least32_t; - using int64 = std::int_least64_t; - using intmax = std::intmax_t; - using size = decltype(0x0uz); - using ssize = decltype(0x0z); - using ubyte = unsigned char; - using uint16 = std::uint_least16_t; - using uint32 = std::uint_least32_t; - using uint64 = std::uint_least64_t; - using uintmax = std::uintmax_t; - template<typename T> concept utf = std::is_same_v<T,char16_t> || std::is_same_v<T,char32_t> || std::is_same_v<T,char8_t>; - enum class endi : bool { - big = true, - little = false, - }; - template<typename T> [[nodiscard,u8c_attr_allocsz(0x3),u8c_attr_malloc,u8c_attr_nonnull(0x1)]] constexpr auto renew(T * ptr,u8c::size sz,u8c::size newsz) -> T *; - template<typename T> constexpr auto renew(std::nullptr_t, u8c::size sz,u8c::size newsz) -> T * = delete; - constexpr auto bytesz = static_cast<u8c::ubyte>(CHAR_BIT); - constexpr auto dbg = -#if defined(NDEBUG) || !defined(_DEBUG) - false; -#else - true; -#endif - constexpr auto unimax = U'\U00010FFF'; - constexpr auto ver = u8c_uint64c(0x1B); -} - -#include <u8c/misc.d/renew> - -#endif diff --git a/u8c/include/u8c/misc.d/renew b/u8c/include/u8c/misc.d/renew deleted file mode 100644 index 8d67b78..0000000 --- a/u8c/include/u8c/misc.d/renew +++ /dev/null @@ -1,32 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_PDOxHgtcAGQDjPjZ) -#define u8c_key_PDOxHgtcAGQDjPjZ - -#include <algorithm> /* std::copy_n, std::min */ - -template<typename T> auto constexpr u8c::renew(T * const u8c_restr _ptr,u8c::size const _sz,u8c::size const _newsz) -> T * { - T * const u8c_restr ptr = ::new T[_newsz]; - std::copy_n(_ptr,std::min(_sz,_newsz),ptr); - ::delete[] _ptr; - return ptr; -} - -#endif diff --git a/u8c/include/u8c/str b/u8c/include/u8c/str deleted file mode 100644 index d8f5753..0000000 --- a/u8c/include/u8c/str +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_ywSpAOVLrorTYrkK) -#define u8c_key_ywSpAOVLrorTYrkK - -#include <u8c/arr> -#include <u8c/utf> - -namespace u8c { - class str { - public: - constexpr auto app( u8c::str const & oth) -> u8c::str const &; - constexpr auto begin() const noexcept -> char32_t *; - constexpr auto end() const noexcept -> char32_t *; - constexpr auto operator = ( u8c::str const & oth) -> u8c::str const &; - constexpr auto operator [] (u8c::str const & oth) const noexcept -> u8c::str const &; - [[nodiscard]] constexpr str() noexcept; - [[nodiscard]] constexpr str( u8c::str const & oth); - template<u8c::utf T> [[nodiscard]] constexpr str( T chr); - template<u8c::utf T,u8c::size N> [[nodiscard]] constexpr str( T const (& strlit)[N]) noexcept; - [[nodiscard]] constexpr auto u8() const -> u8c::arr<char8_t>; - private: - u8c::arr<char32_t> _arr; - }; - template<typename T> [[nodiscard,u8c_attr_hot]] constexpr auto fmt( T fmt) -> u8c::str; - auto operator << (std::ostream & strm, u8c::str const & str) -> std::ostream &; - /*class { - public: - bool ascii = false; - u8c::ubyte base = u8c_ubytec(0xB); - u8c::endi endi = u8c::endi::little; - } inline fmtsets;*/ -} - -#include <u8c/str.d/dbgprint> -#include <u8c/str.d/str> - -#endif diff --git a/u8c/include/u8c/str.d/fmt b/u8c/include/u8c/str.d/fmt deleted file mode 100644 index 3c602f0..0000000 --- a/u8c/include/u8c/str.d/fmt +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_6cyujV0FoSmPeQWl) -#define u8c_key_6cyujV0FoSmPeQWl - -#if 0x0 -auto u8c::dbgprint(u8c::str const _msg) -> void { -#if defined(NDEBUG) - constexpr auto dbg = true; -#else - constexpr auto dbg = false; -#endif - if constexpr(dbg) { - return u8c::println(stderr,_msg); - } -} -auto u8c::fmt(u8c::str const _str) -> u8c::str { - return u8c::str(_str); -} -template<typename T> auto u8c::fmt(u8c::str const _str,T const _fmt) -> u8c::str { - u8c::str str; - for(auto chr : _str) { - if(chr == U'\uFFFC') [[unlikely]] { - return str + u8c::fmter::fmt(_fmt); - } - str += chr; - } - return str; -} -template<typename T,typename... TArgs> auto u8c::fmt(u8c::str const _str,T const _fmt,TArgs... _args) -> u8c::str { - u8c::str str; - for(auto chr : _str) { - if(chr == U'\uFFFC') [[unlikely]] { - return str + u8c::fmt(str,_fmt,_args...); - } - str += chr; - } - return str; -} -#endif - -#endif diff --git a/u8c/include/u8c/str.d/str b/u8c/include/u8c/str.d/str deleted file mode 100644 index f708f8a..0000000 --- a/u8c/include/u8c/str.d/str +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_3zvMYqWFDYnlTEyW) -#define u8c_key_3zvMYqWFDYnlTEyW - -#include <type_traits> /* std::is_same_v */ - -constexpr auto u8c::str::begin() const noexcept -> char32_t * { - return this->_arr.begin(); -} -constexpr auto u8c::str::end() const noexcept -> char32_t * { - return this->_arr.end(); -} -constexpr auto u8c::str::operator = (u8c::str const & _oth) -> u8c::str const & { - this->_arr = _oth._arr; - return *this; -} -constexpr u8c::str::str(u8c::str const & _oth) { - *this = _oth; -} -template<u8c::utf T> constexpr u8c::str::str(T const _chr) { - if constexpr (std::is_same_v<T,char32_t>) { - this->_arr.set(_chr); - } -} -template<u8c::utf T,u8c::size N> constexpr u8c::str::str(T const (& _strlit)[N]) noexcept { - this->_arr.set(_strlit,_strlit + N); -} -constexpr auto u8c::str::u8() const -> u8c::arr<char8_t> { - return u8c::cnv<char8_t>(this->begin(),this->end()); -} - -#endif diff --git a/u8c/include/u8c/u8c b/u8c/include/u8c/u8c deleted file mode 100644 index f9591c5..0000000 --- a/u8c/include/u8c/u8c +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -/* - Greater Header Dependencies: - - misc →┬─────────────────────────→┬→ u8c - ├→ arr ─→┬────────────────→┤ - │ └→ utf ─→┬───────→┤ - │ └→ str ─→┤ - └→ cstr →┬────────────────→┤ - └→ impl →┬───────→┤ - └→ math →┘ -*/ - -#if !defined(u8c_key_piDyeERQmK9By1n3) -#define u8c_key_piDyeERQmK9By1n3 - -#include <concepts> /* std::convertible_to */ -#include <ostream> /* std::ostream */ -#include <type_traits> /* std::is_same_v */ - -#include <u8c/math> -#include <u8c/str> - -namespace u8c { - [[nodiscard]] constexpr auto uniblk(char32_t chr) -> u8c::str; - [[nodiscard]] constexpr auto uninm( char32_t chr) -> u8c::str; -} - -#include <u8c/u8c.d/uniblk> -#include <u8c/u8c.d/uninm> - -#endif diff --git a/u8c/include/u8c/utf b/u8c/include/u8c/utf deleted file mode 100644 index 15bdc44..0000000 --- a/u8c/include/u8c/utf +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_xtmbVPu5vGoJz4tw) -#define u8c_key_xtmbVPu5vGoJz4tw - -#include <u8c/arr> - -namespace u8c { - template<u8c::utf T,u8c::utf T0> [[nodiscard]] constexpr auto cnv( T0 const * begin,T0 const * end) -> u8c::arr<T>; - [[nodiscard,u8c_attr_const]] constexpr auto isalnum( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto isalpha( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto iscntrl( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto isdigit( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto islower( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto ispunct( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto isspace( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto issurro( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto isupper( char32_t chr) -> bool; - [[nodiscard,u8c_attr_const]] constexpr auto isxdigit(char32_t chr) -> bool; -} - -#include <u8c/utf.d/cnv> -#include <u8c/utf.d/isalnum> -#include <u8c/utf.d/isalpha> -#include <u8c/utf.d/iscntrl> -#include <u8c/utf.d/isdigit> -#include <u8c/utf.d/islower> -#include <u8c/utf.d/ispunct> -#include <u8c/utf.d/isspace> -#include <u8c/utf.d/issurro> -#include <u8c/utf.d/isupper> -#include <u8c/utf.d/isxdigit> - -#endif diff --git a/u8c/include/u8c/utf.d/cnv b/u8c/include/u8c/utf.d/cnv deleted file mode 100644 index 95b66e9..0000000 --- a/u8c/include/u8c/utf.d/cnv +++ /dev/null @@ -1,116 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_nVkgRbXZfcq3BG8J) -#define u8c_key_nVkgRbXZfcq3BG8J - -#include <algorithm> /* std::copy */ -#include <cstddef> /* u8c::size */ -#include <stdexcept> /* std::invalid_argument, std::out_of_range */ -#include <type_traits> /* std::is_same_v */ -#include <vector> /* std::vector */ - -template<u8c::utf T,u8c::utf T0> constexpr auto u8c::cnv(T0 const * const u8c_restr _begin,T0 const * const u8c_restr _end) -> u8c::arr<T> { - if (_begin == nullptr || _end == nullptr) [[unlikely]] { - throw std::invalid_argument("Null pointer provided as parameter."); - } - u8c::arr<T0> in(_begin,_end); - u8c::arr<T> out; - if constexpr (std::is_same_v<T0,T>) { - out.alloc(static_cast<u8c::size>(_end - _begin)); - std::copy(_begin,_end,out.begin()); - return out; - } - else { - if constexpr (std::is_same_v<T0,char16_t>) { - } - else if constexpr (std::is_same_v<T0,char32_t>) { - for (auto const tmp : in) { - if constexpr (std::is_same_v<T,char16_t>) { - if (tmp >= u8c_uint32c(0x10000)) { /* Two hextets. */ - char16_t const tmp0 = tmp - u8c_uint16c(0x10000); - out.app((tmp0 / u8c_uint16c(0x400) + u8c_uint16c(0xD800))); - out.app((tmp0 % u8c_uint16c(0x400) + u8c_uint16c(0xDC00))); - } - else { - /* One hextet. */ - out.app((static_cast<char16_t>(tmp))); - } - } - else { - if (tmp >= u8c_uint32c(0x10000)) { /* Four octets. */ - out.app((u8c_ubytec(0b11110000) + static_cast<char8_t>(tmp >> u8c_uint32c(0x12) & u8c_uint32c(0b00000111)))); - out.app((u8c_ubytec(0b10000000) + static_cast<char8_t>(tmp >> u8c_uint32c(0xC) & u8c_uint32c(0b00111111)))); - out.app((u8c_ubytec(0b10000000) + static_cast<char8_t>(tmp >> u8c_uint32c(0x6) & u8c_uint32c(0b00111111)))); - out.app((u8c_ubytec(0b10000000) + static_cast<char8_t>(tmp & u8c_uint32c(0b00111111)))); - } - else if (tmp >= U'\u0800') { /* Three octets. */ - out.app((u8c_ubytec(0xE0) + static_cast<char8_t>(tmp >> u8c_uint32c(0xC) & u8c_uint32c(0b00001111)))); - out.app((u8c_ubytec(0x80) + static_cast<char8_t>(tmp >> u8c_uint32c(0x6) & u8c_uint32c(0b00111111)))); - out.app((u8c_ubytec(0x80) + static_cast<char8_t>(tmp & u8c_uint32c(0b00111111)))); - } - else if (tmp >= U'\u0080') { /* Two octets. */ - out.app((u8c_ubytec(0xC0) + static_cast<char8_t>(tmp >> u8c_uint32c(0x6) & u8c_uint32c(0b00111111)))); - out.app((u8c_ubytec(0x80) + static_cast<char8_t>(tmp & u8c_uint32c(0b00111111)))); - } - else { - /* One octet. */ - out.app(static_cast<char8_t>(tmp)); - } - } - } - return out; - } - else { - if constexpr (std::is_same_v<T,char16_t>) { - } - else { - for (u8c::size n = 0x0uz;n < in.sz();n += 0x1uz) { - auto const tmp = in[n]; - auto chr = U'\u0000'; - if (tmp >= u8c_ubytec(0b11110000)) { /* Four octets. */ - chr = (tmp ^ u8c_uint32c(0b11110000)) << u8c_uint32c(0x12); - chr += (in[n + 0x1uz] ^ u8c_uint32c(0b10000000)) << u8c_uint32c(0xC); - chr += (in[n + 0x2uz] ^ u8c_uint32c(0b10000000)) << u8c_uint32c(0x6); - chr += in[n + 0x3uz] ^ u8c_uint32c(0b10000000); - n += 0x3uz; - } - else if (tmp >= u8c_ubytec(0b11100000)) { /* Three octets. */ - chr = (tmp ^ u8c_uint32c(0b11100000)) << u8c_uint32c(0xC); - chr += (in[n + 0x1uz] ^ u8c_uint32c(0b10000000)) << u8c_uint32c(0x6); - chr += in[n + 0x2uz] ^ u8c_uint32c(0b10000000); - n += 0x2uz; - } - else if (tmp >= u8c_ubytec(0b11000000)) { /* Two octets. */ - chr = (tmp ^ u8c_uint32c(0b11000000)) << u8c_uint32c(0x6); - chr += in[n + 0x1uz] ^ u8c_uint32c(0b10000000); - n += 0x1uz; - } - else { - /* One octet. */ - chr = tmp; - } - out.app(chr); - } - } - } - } -} - -#endif diff --git a/u8c/include/u8c/utf.d/isalpha b/u8c/include/u8c/utf.d/isalpha deleted file mode 100644 index 3a0bb9d..0000000 --- a/u8c/include/u8c/utf.d/isalpha +++ /dev/null @@ -1,29 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#if !defined(u8c_key_YnTiCcefC1wLH21w) -#define u8c_key_YnTiCcefC1wLH21w - -#include <stdexcept> /* std::domain_error */ - -constexpr auto u8c::isalnum(char32_t const _chr) -> bool { - return u8c::isalpha(_chr) || u8c::isdigit(_chr); -} - -#endif
\ No newline at end of file diff --git a/u8c/src/operator.cc b/u8c/src/operator.cc deleted file mode 100644 index 3ea8eae..0000000 --- a/u8c/src/operator.cc +++ /dev/null @@ -1,28 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#include <algorithm> /* std::copy */ -#include <cstdint> /* u8c_ubytec */ -#include <ostream> /* std::ostream */ -#include <u8c/str> - -auto u8c::operator << (std::ostream & _strm,u8c::str const & _str) -> std::ostream & { - auto const u8 = _str.u8().app(u8'\u0000'); - return _strm << reinterpret_cast<unsigned char *>(u8.begin()); -} diff --git a/u8c/src/u8c/fmt.cc b/u8c/src/u8c/fmt.cc deleted file mode 100644 index 654fb98..0000000 --- a/u8c/src/u8c/fmt.cc +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright 2021 Gabriel Jensen - - This file is part of u8c. - - u8c is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your - option) any later version. - - u8c is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - License for more details. - - You should have received a copy of the GNU Affero General Public License - along with u8c. If not, see <https://www.gnu.org/licenses/>. -*/ - -#include <cstddef> /* std::nullptr_t */ -#include <string> /* std::u32string, std::u8string */ -#include <u8c/u8c> -#include <u8c/str> - -template<> auto u8c::fmt(char32_t const _chr) -> u8c::str { - return _chr; -} -template<> auto u8c::fmt(std::nullptr_t) -> u8c::str { - return U"nullptr"; -} -template<> auto u8c::fmt(u8c::str const _str) -> u8c::str { - return _str; -} -template<> auto u8c::fmt(void * _ptr) -> u8c::str { - if(_ptr == nullptr) [[unlikely]] { - return U"nullptr"; - } - return U"PTR"; -} |