├── .github └── workflows │ └── cmake.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── AUTHORS ├── CMakeLists.txt ├── CodingStyle.md ├── Doxyfile ├── LICENSE ├── README.md ├── appveyor.yml ├── btree_tests ├── Makefile ├── bwtree_test.cpp ├── compile_flags.txt ├── cxxopts.hpp ├── run-cache-misses.sh ├── run-ycsb.sh ├── run_copies.sh ├── test-leafds.cpp ├── test-plain.cpp ├── timers.hpp ├── tmp.sh └── ycsb.cpp ├── misc ├── cmake │ ├── tlx-config.cmake.in │ ├── tlx-version.cmake.in │ └── tlx.pc ├── format │ ├── analyze-source.pl │ └── uncrustify.cfg └── mk-doxygen-travis.sh ├── tlx-leafds ├── CMakeLists.txt ├── algorithm.hpp ├── algorithm │ ├── exclusive_scan.hpp │ ├── is_sorted_cmp.hpp │ ├── merge_advance.hpp │ ├── merge_combine.hpp │ ├── multisequence_partition.hpp │ ├── multisequence_selection.hpp │ ├── multiway_merge.hpp │ ├── multiway_merge_splitting.hpp │ ├── parallel_multiway_merge.cpp │ ├── parallel_multiway_merge.hpp │ └── random_bipartition_shuffle.hpp ├── allocator_base.hpp ├── backtrace.cpp ├── backtrace.hpp ├── cmdline_parser.cpp ├── cmdline_parser.hpp ├── container.hpp ├── container │ ├── btree.hpp │ ├── btree_map.hpp │ ├── btree_multimap.hpp │ ├── btree_multiset.hpp │ ├── btree_set.hpp │ ├── d_ary_addressable_int_heap.hpp │ ├── d_ary_heap.hpp │ ├── loser_tree.hpp │ ├── lru_cache.hpp │ ├── radix_heap.hpp │ ├── ring_buffer.hpp │ ├── simple_vector.hpp │ ├── splay_tree.hpp │ └── string_view.hpp ├── counting_ptr.hpp ├── define.hpp ├── define │ ├── attribute_always_inline.hpp │ ├── attribute_fallthrough.hpp │ ├── attribute_format_printf.hpp │ ├── attribute_packed.hpp │ ├── attribute_warn_unused_result.hpp │ ├── constexpr.hpp │ ├── deprecated.hpp │ ├── endian.hpp │ ├── likely.hpp │ └── visibility_hidden.hpp ├── delegate.hpp ├── die.hpp ├── die │ ├── core.cpp │ └── core.hpp ├── digest.hpp ├── digest │ ├── md5.cpp │ ├── md5.hpp │ ├── sha1.cpp │ ├── sha1.hpp │ ├── sha256.cpp │ ├── sha256.hpp │ ├── sha512.cpp │ └── sha512.hpp ├── logger.hpp ├── logger │ ├── all.hpp │ ├── array.hpp │ ├── core.cpp │ ├── core.hpp │ ├── deque.hpp │ ├── map.hpp │ ├── set.hpp │ ├── tuple.hpp │ ├── unordered_map.hpp │ ├── unordered_set.hpp │ └── wrap_unprintable.hpp ├── main.dox ├── math.hpp ├── math │ ├── abs_diff.hpp │ ├── aggregate.hpp │ ├── aggregate_min_max.hpp │ ├── bswap.hpp │ ├── bswap_be.hpp │ ├── bswap_le.hpp │ ├── clz.hpp │ ├── ctz.hpp │ ├── div_ceil.hpp │ ├── ffs.hpp │ ├── integer_log2.hpp │ ├── is_power_of_two.hpp │ ├── polynomial_regression.hpp │ ├── popcount.hpp │ ├── power_to_the.hpp │ ├── rol.hpp │ ├── ror.hpp │ ├── round_to_power_of_two.hpp │ ├── round_up.hpp │ └── sgn.hpp ├── meta.hpp ├── meta │ ├── apply_tuple.hpp │ ├── call_for_range.hpp │ ├── call_foreach.hpp │ ├── call_foreach_tuple.hpp │ ├── call_foreach_tuple_with_index.hpp │ ├── call_foreach_with_index.hpp │ ├── enable_if.hpp │ ├── fold_left.hpp │ ├── fold_left_tuple.hpp │ ├── fold_right.hpp │ ├── fold_right_tuple.hpp │ ├── function_chain.hpp │ ├── function_stack.hpp │ ├── has_member.hpp │ ├── has_method.hpp │ ├── index_sequence.hpp │ ├── is_std_array.hpp │ ├── is_std_pair.hpp │ ├── is_std_tuple.hpp │ ├── is_std_vector.hpp │ ├── log2.hpp │ ├── no_operation.hpp │ ├── static_index.hpp │ ├── vexpand.hpp │ ├── vmap_for_range.hpp │ ├── vmap_foreach.hpp │ ├── vmap_foreach_tuple.hpp │ ├── vmap_foreach_tuple_with_index.hpp │ └── vmap_foreach_with_index.hpp ├── multi_timer.cpp ├── multi_timer.hpp ├── port.hpp ├── port │ ├── setenv.cpp │ └── setenv.hpp ├── semaphore.hpp ├── simple_vector.hpp ├── siphash.hpp ├── sort.hpp ├── sort │ ├── networks │ │ ├── best.hpp │ │ ├── bose_nelson.hpp │ │ ├── bose_nelson_parameter.hpp │ │ └── cswap.hpp │ ├── parallel_mergesort.hpp │ ├── strings.hpp │ ├── strings │ │ ├── insertion_sort.hpp │ │ ├── multikey_quicksort.hpp │ │ ├── parallel_sample_sort.hpp │ │ ├── radix_sort.hpp │ │ ├── sample_sort_tools.hpp │ │ ├── string_ptr.hpp │ │ └── string_set.hpp │ └── strings_parallel.hpp ├── stack_allocator.hpp ├── string.hpp ├── string │ ├── appendline.cpp │ ├── appendline.hpp │ ├── base64.cpp │ ├── base64.hpp │ ├── bitdump.cpp │ ├── bitdump.hpp │ ├── compare_icase.cpp │ ├── compare_icase.hpp │ ├── contains.cpp │ ├── contains.hpp │ ├── contains_word.cpp │ ├── contains_word.hpp │ ├── ends_with.cpp │ ├── ends_with.hpp │ ├── equal_icase.cpp │ ├── equal_icase.hpp │ ├── erase_all.cpp │ ├── erase_all.hpp │ ├── escape_html.cpp │ ├── escape_html.hpp │ ├── escape_uri.cpp │ ├── escape_uri.hpp │ ├── expand_environment_variables.cpp │ ├── expand_environment_variables.hpp │ ├── extract_between.cpp │ ├── extract_between.hpp │ ├── format_iec_units.hpp │ ├── format_si_iec_units.cpp │ ├── format_si_iec_units.hpp │ ├── format_si_units.hpp │ ├── hash_djb2.hpp │ ├── hash_sdbm.hpp │ ├── hexdump.cpp │ ├── hexdump.hpp │ ├── index_of.cpp │ ├── index_of.hpp │ ├── join.cpp │ ├── join.hpp │ ├── join_generic.hpp │ ├── join_quoted.cpp │ ├── join_quoted.hpp │ ├── less_icase.cpp │ ├── less_icase.hpp │ ├── levenshtein.hpp │ ├── pad.cpp │ ├── pad.hpp │ ├── parse_si_iec_units.cpp │ ├── parse_si_iec_units.hpp │ ├── parse_uri.hpp │ ├── parse_uri_form_data.hpp │ ├── replace.cpp │ ├── replace.hpp │ ├── split.cpp │ ├── split.hpp │ ├── split_quoted.cpp │ ├── split_quoted.hpp │ ├── split_view.hpp │ ├── split_words.cpp │ ├── split_words.hpp │ ├── ssprintf.cpp │ ├── ssprintf.hpp │ ├── ssprintf_generic.hpp │ ├── starts_with.cpp │ ├── starts_with.hpp │ ├── to_lower.cpp │ ├── to_lower.hpp │ ├── to_upper.cpp │ ├── to_upper.hpp │ ├── trim.cpp │ ├── trim.hpp │ ├── union_words.cpp │ ├── union_words.hpp │ ├── word_wrap.cpp │ └── word_wrap.hpp ├── thread_barrier_mutex.hpp ├── thread_barrier_spin.hpp ├── thread_pool.cpp ├── thread_pool.hpp ├── timestamp.cpp ├── timestamp.hpp ├── unused.hpp ├── vector_free.hpp └── version.hpp ├── tlx-plain ├── CMakeLists.txt ├── algorithm.hpp ├── algorithm │ ├── exclusive_scan.hpp │ ├── is_sorted_cmp.hpp │ ├── merge_advance.hpp │ ├── merge_combine.hpp │ ├── multisequence_partition.hpp │ ├── multisequence_selection.hpp │ ├── multiway_merge.hpp │ ├── multiway_merge_splitting.hpp │ ├── parallel_multiway_merge.cpp │ ├── parallel_multiway_merge.hpp │ └── random_bipartition_shuffle.hpp ├── allocator_base.hpp ├── backtrace.cpp ├── backtrace.hpp ├── cmdline_parser.cpp ├── cmdline_parser.hpp ├── container.hpp ├── container │ ├── btree.hpp │ ├── btree_map.hpp │ ├── btree_multimap.hpp │ ├── btree_multiset.hpp │ ├── btree_set.hpp │ ├── d_ary_addressable_int_heap.hpp │ ├── d_ary_heap.hpp │ ├── loser_tree.hpp │ ├── lru_cache.hpp │ ├── radix_heap.hpp │ ├── ring_buffer.hpp │ ├── simple_vector.hpp │ ├── splay_tree.hpp │ └── string_view.hpp ├── counting_ptr.hpp ├── define.hpp ├── define │ ├── attribute_always_inline.hpp │ ├── attribute_fallthrough.hpp │ ├── attribute_format_printf.hpp │ ├── attribute_packed.hpp │ ├── attribute_warn_unused_result.hpp │ ├── constexpr.hpp │ ├── deprecated.hpp │ ├── endian.hpp │ ├── likely.hpp │ └── visibility_hidden.hpp ├── delegate.hpp ├── die.hpp ├── die │ ├── core.cpp │ └── core.hpp ├── digest.hpp ├── digest │ ├── md5.cpp │ ├── md5.hpp │ ├── sha1.cpp │ ├── sha1.hpp │ ├── sha256.cpp │ ├── sha256.hpp │ ├── sha512.cpp │ └── sha512.hpp ├── logger.hpp ├── logger │ ├── all.hpp │ ├── array.hpp │ ├── core.cpp │ ├── core.hpp │ ├── deque.hpp │ ├── map.hpp │ ├── set.hpp │ ├── tuple.hpp │ ├── unordered_map.hpp │ ├── unordered_set.hpp │ └── wrap_unprintable.hpp ├── main.dox ├── math.hpp ├── math │ ├── abs_diff.hpp │ ├── aggregate.hpp │ ├── aggregate_min_max.hpp │ ├── bswap.hpp │ ├── bswap_be.hpp │ ├── bswap_le.hpp │ ├── clz.hpp │ ├── ctz.hpp │ ├── div_ceil.hpp │ ├── ffs.hpp │ ├── integer_log2.hpp │ ├── is_power_of_two.hpp │ ├── polynomial_regression.hpp │ ├── popcount.hpp │ ├── power_to_the.hpp │ ├── rol.hpp │ ├── ror.hpp │ ├── round_to_power_of_two.hpp │ ├── round_up.hpp │ └── sgn.hpp ├── meta.hpp ├── meta │ ├── apply_tuple.hpp │ ├── call_for_range.hpp │ ├── call_foreach.hpp │ ├── call_foreach_tuple.hpp │ ├── call_foreach_tuple_with_index.hpp │ ├── call_foreach_with_index.hpp │ ├── enable_if.hpp │ ├── fold_left.hpp │ ├── fold_left_tuple.hpp │ ├── fold_right.hpp │ ├── fold_right_tuple.hpp │ ├── function_chain.hpp │ ├── function_stack.hpp │ ├── has_member.hpp │ ├── has_method.hpp │ ├── index_sequence.hpp │ ├── is_std_array.hpp │ ├── is_std_pair.hpp │ ├── is_std_tuple.hpp │ ├── is_std_vector.hpp │ ├── log2.hpp │ ├── no_operation.hpp │ ├── static_index.hpp │ ├── vexpand.hpp │ ├── vmap_for_range.hpp │ ├── vmap_foreach.hpp │ ├── vmap_foreach_tuple.hpp │ ├── vmap_foreach_tuple_with_index.hpp │ └── vmap_foreach_with_index.hpp ├── multi_timer.cpp ├── multi_timer.hpp ├── port.hpp ├── port │ ├── setenv.cpp │ └── setenv.hpp ├── semaphore.hpp ├── simple_vector.hpp ├── siphash.hpp ├── sort.hpp ├── sort │ ├── networks │ │ ├── best.hpp │ │ ├── bose_nelson.hpp │ │ ├── bose_nelson_parameter.hpp │ │ └── cswap.hpp │ ├── parallel_mergesort.hpp │ ├── strings.hpp │ ├── strings │ │ ├── insertion_sort.hpp │ │ ├── multikey_quicksort.hpp │ │ ├── parallel_sample_sort.hpp │ │ ├── radix_sort.hpp │ │ ├── sample_sort_tools.hpp │ │ ├── string_ptr.hpp │ │ └── string_set.hpp │ └── strings_parallel.hpp ├── stack_allocator.hpp ├── string.hpp ├── string │ ├── appendline.cpp │ ├── appendline.hpp │ ├── base64.cpp │ ├── base64.hpp │ ├── bitdump.cpp │ ├── bitdump.hpp │ ├── compare_icase.cpp │ ├── compare_icase.hpp │ ├── contains.cpp │ ├── contains.hpp │ ├── contains_word.cpp │ ├── contains_word.hpp │ ├── ends_with.cpp │ ├── ends_with.hpp │ ├── equal_icase.cpp │ ├── equal_icase.hpp │ ├── erase_all.cpp │ ├── erase_all.hpp │ ├── escape_html.cpp │ ├── escape_html.hpp │ ├── escape_uri.cpp │ ├── escape_uri.hpp │ ├── expand_environment_variables.cpp │ ├── expand_environment_variables.hpp │ ├── extract_between.cpp │ ├── extract_between.hpp │ ├── format_iec_units.hpp │ ├── format_si_iec_units.cpp │ ├── format_si_iec_units.hpp │ ├── format_si_units.hpp │ ├── hash_djb2.hpp │ ├── hash_sdbm.hpp │ ├── hexdump.cpp │ ├── hexdump.hpp │ ├── index_of.cpp │ ├── index_of.hpp │ ├── join.cpp │ ├── join.hpp │ ├── join_generic.hpp │ ├── join_quoted.cpp │ ├── join_quoted.hpp │ ├── less_icase.cpp │ ├── less_icase.hpp │ ├── levenshtein.hpp │ ├── pad.cpp │ ├── pad.hpp │ ├── parse_si_iec_units.cpp │ ├── parse_si_iec_units.hpp │ ├── parse_uri.hpp │ ├── parse_uri_form_data.hpp │ ├── replace.cpp │ ├── replace.hpp │ ├── split.cpp │ ├── split.hpp │ ├── split_quoted.cpp │ ├── split_quoted.hpp │ ├── split_view.hpp │ ├── split_words.cpp │ ├── split_words.hpp │ ├── ssprintf.cpp │ ├── ssprintf.hpp │ ├── ssprintf_generic.hpp │ ├── starts_with.cpp │ ├── starts_with.hpp │ ├── to_lower.cpp │ ├── to_lower.hpp │ ├── to_upper.cpp │ ├── to_upper.hpp │ ├── trim.cpp │ ├── trim.hpp │ ├── union_words.cpp │ ├── union_words.hpp │ ├── word_wrap.cpp │ └── word_wrap.hpp ├── thread_barrier_mutex.hpp ├── thread_barrier_spin.hpp ├── thread_pool.cpp ├── thread_pool.hpp ├── timestamp.cpp ├── timestamp.hpp ├── unused.hpp ├── vector_free.hpp └── version.hpp └── ycsb_inputs └── get-ycsb-inputs.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.csv 2 | out* 3 | basic 4 | ycsb 5 | CMakeFiles 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "btree_tests/ParallelTools"] 2 | path = btree_tests/ParallelTools 3 | url = git@github.com:wheatman/ParallelTools.git 4 | [submodule "tlx-leafds/leafDS"] 5 | path = tlx-leafds/container/leafDS 6 | url = git@github.com:itshelenxu/leafDS.git 7 | [submodule "btree_tests/BwTree"] 8 | path = btree_tests/BwTree 9 | url = git@github.com:itshelenxu/BwTree.git 10 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Andreas Beckmann 2 | Andreas Eberle 3 | Eugenio Angriman 4 | Hung Tran 5 | Huyen Chau Nguyen 6 | Jasper Marianczuk 7 | Johannes Singler 8 | Lorenz Hübschle-Schneider 9 | Manuel Penschuck 10 | Michael Axtmann 11 | Roman Dementiev 12 | Sebastian Lamm 13 | Thomas Keh 14 | Timo Bingmann 15 | -------------------------------------------------------------------------------- /CodingStyle.md: -------------------------------------------------------------------------------- 1 | # Coding Style in tlx 2 | 3 | This file should document some of the C++ coding style used in tlx. 4 | 5 | ## 80 Columns Rule 6 | 7 | All source must **strictly** adhere to the 80 column limit. 8 | 9 | This may seem overly short considered today's wide high-resolution screens, but there are some good reasons. 10 | 11 | - Sporadic long lines require more eye movement than a denser code packed for top-down reading. 12 | 13 | - A shorter limit allow to arrange more than one column of code, e.g. for reading side-by-side or diffs. 14 | 15 | For a fun read on the history of "Why 80 columns?", see 16 | 17 | 18 | ## Naming of Types, Methods, Functions, Variables. 19 | 20 | - Styles: `ThisIsWrittenInCamelCase` or `this_is_written_in_snake_case`. 21 | 22 | - All types, e.g. classes or typedef/usings are CamelCase, with the following exceptions: 23 | 24 | - All STL-style types which end with `_type`, `_traits`, or `iterator` are snake_case. 25 | 26 | - STL-style container or functor classes are granted an exception or may define an alias, e.g. `simple_vector`. 27 | 28 | - All variables are written in snake_case. Attributes of classes have a tailing underscore_. 29 | 30 | - Some exceptions are granted, e.g. the `debug` variable cannot have a tailing underscore. 31 | 32 | - Constant variables may alternatively be written as `kCamelCase` without underscore. 33 | 34 | - Structs used mainly to store fields may optionally omit the tailing underscore on all members. 35 | 36 | - Functions and class methods are written as snake_case. 37 | 38 | - currently no exceptions 39 | 40 | ## Formatting 41 | 42 | - Ignore formatting while writing code. Uncrustify will be run and fix nearly all formatting. 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 0.1.{build} 2 | pull_requests: 3 | do_not_increment_build_number: true 4 | image: 5 | - Visual Studio 2017 6 | configuration: 7 | - Debug 8 | - Release 9 | platform: 10 | - x64 11 | clone_folder: c:\dev\tlx 12 | 13 | init: 14 | - set arch= 15 | - if "%PLATFORM%"=="x64" (set arch= Win64) 16 | - echo %APPVEYOR_BUILD_WORKER_IMAGE% 17 | - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" (set generator="Visual Studio 15 2017%arch%") 18 | - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" (set generator="Visual Studio 14 2015%arch%") 19 | - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2013" (set generator="Visual Studio 12 2013%arch%") 20 | - echo %generator% 21 | - set more_tests=OFF 22 | - if "%CONFIGURATION%"=="Release" (set more_tests=ON) 23 | 24 | before_build: 25 | - cmd: |- 26 | echo Running cmake for %generator%... 27 | echo %CONFIGURATION% 28 | cd c:\dev\tlx 29 | md build 30 | cd build 31 | cmake -G %generator% -DTLX_BUILD_TESTS=ON -DTLX_TRY_COMPILE_HEADERS=ON -DTLX_MORE_TESTS=%more_tests% .. 32 | 33 | build: 34 | project: c:\dev\tlx\build\tlx.sln 35 | parallel: true 36 | verbosity: minimal 37 | 38 | test_script: 39 | - cmd: ctest -V --build-config %CONFIGURATION% 40 | -------------------------------------------------------------------------------- /btree_tests/compile_flags.txt: -------------------------------------------------------------------------------- 1 | -std=c++20 2 | -Wall 3 | -Wno-address-of-packed-member 4 | -Wextra 5 | -O3 6 | -g 7 | -std=c++20 8 | -march=native 9 | -IParallelTools/ 10 | -I../ 11 | -DCILK=0 -------------------------------------------------------------------------------- /btree_tests/run-cache-misses.sh: -------------------------------------------------------------------------------- 1 | numactl -N 1 perf stat -a -e cache-misses,LLC-loads,LLC-load-misses,LLC-stores,LLC-store-misses,LLC-prefetch-misses,dTLB-load-misses,dTLB-prefetches,iTLB-load-misses ./basic --cache_misses 2 | 3 | notes: look at the file 4 | first do the inserts 5 | 6 | 7 | then rebuild with commenting back in the sorted range 8 | run with --query_size {100, 1000, 10000, 100000} 9 | 10 | then unsorted range 11 | run with --query_size {100, 1000, 10000, 100000} 12 | 13 | -------------------------------------------------------------------------------- /btree_tests/run-ycsb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # 1st arg is distribution, second arg is num threads 4 | 5 | ./ycsb btree a randint $1 $2 6 | ./ycsb btree b randint $1 $2 7 | ./ycsb btree c randint $1 $2 8 | ./ycsb btree e randint $1 $2 9 | ./ycsb btree x randint $1 $2 10 | ./ycsb btree y randint $1 $2 11 | -------------------------------------------------------------------------------- /btree_tests/run_copies.sh: -------------------------------------------------------------------------------- 1 | : <<'END' 2 | for i in {0..23} 3 | do 4 | taskset -c $i ./basic --microbenchmark_baseline --num_inserts=100000000 --num_queries=0 --trials=5 & 5 | done 6 | for i in {48..71} 7 | do 8 | taskset -c $i ./basic --microbenchmark_baseline --num_inserts=100000000 --num_queries=0 --trials=5 & 9 | done 10 | wait 11 | END 12 | 13 | taskset -c 0-23 ./basic --microbenchmark_baseline --num_inserts=100000000 --num_queries=0 --trials=5 & 14 | taskset -c 48-71 ./basic --microbenchmark_baseline --num_inserts=100000000 --num_queries=0 --trials=5 & 15 | wait 16 | -------------------------------------------------------------------------------- /btree_tests/tmp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | numactl -N 1 -m 1 ./ycsb btree y randint uniform 48 3 | numactl -N 1 -m 1 ./ycsb btree y randint zipfian 48 4 | -------------------------------------------------------------------------------- /misc/cmake/tlx-config.cmake.in: -------------------------------------------------------------------------------- 1 | # CMake config file for TLX 2 | # 3 | # It defines the following variables 4 | # TLX_VERSION - library version 5 | # TLX_CXX_FLAGS - C++ flags for TLX 6 | # TLX_INCLUDE_DIRS - include directories for TLX 7 | # TLX_LIBRARIES - libraries to link against 8 | 9 | @PACKAGE_INIT@ 10 | 11 | set(TLX_VERSION "@TLX_VERSION@") 12 | 13 | # compute paths from current cmake file path 14 | get_filename_component(TLX_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 15 | 16 | # additional compiler flags 17 | set(TLX_CXX_FLAGS "@TLX_CXX_FLAGS@") 18 | 19 | # additional include directories for tlx dependencies 20 | set(TLX_INCLUDE_DIRS "@PACKAGE_TLX_INSTALL_INCLUDE_DIR@") 21 | 22 | # load our library dependencies (contains definitions for IMPORTED targets) 23 | include("${TLX_CMAKE_DIR}/tlx-targets.cmake") 24 | 25 | # these are IMPORTED targets created by tlx-targets.cmake, link these with 26 | # your program. 27 | set(TLX_LIBRARIES "@TLX_LIBRARIES@") 28 | -------------------------------------------------------------------------------- /misc/cmake/tlx-version.cmake.in: -------------------------------------------------------------------------------- 1 | set(PACKAGE_VERSION "@TLX_VERSION@") 2 | 3 | # Check whether the requested PACKAGE_FIND_VERSION is compatible 4 | if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}") 5 | set(PACKAGE_VERSION_COMPATIBLE FALSE) 6 | else() 7 | set(PACKAGE_VERSION_COMPATIBLE TRUE) 8 | if ("${PACKAGE_VERSION}" VERSION_EQUAL "${PACKAGE_FIND_VERSION}") 9 | set(PACKAGE_VERSION_EXACT TRUE) 10 | endif() 11 | endif() 12 | -------------------------------------------------------------------------------- /misc/cmake/tlx.pc: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | includedir=${prefix}/@TLX_INSTALL_INCLUDE_DIR@ 4 | libdir=${exec_prefix}/@TLX_INSTALL_LIB_DIR@ 5 | 6 | Name: tlx 7 | Description: tlx 8 | URL: http://panthema.net/tlx 9 | Version: @TLX_VERSION@ 10 | Cflags: -I${includedir} @TLX_CXX_FLAGS@ 11 | Libs: -L${libdir} -l@TLX_LIBNAME@ @TLX_EXTRA_LIBRARIES@ 12 | -------------------------------------------------------------------------------- /tlx-leafds/algorithm.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/algorithm.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_ALGORITHM_HEADER 12 | #define TLX_ALGORITHM_HEADER 13 | 14 | //! \defgroup tlx_algorithm Algorithms 15 | //! Algorithms for iterators and ranges 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/algorithm/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | // [[[end]]] 31 | 32 | #endif // !TLX_ALGORITHM_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/algorithm/is_sorted_cmp.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/algorithm/is_sorted_cmp.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_ALGORITHM_IS_SORTED_CMP_HEADER 12 | #define TLX_ALGORITHM_IS_SORTED_CMP_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_algorithm 19 | //! \{ 20 | 21 | /*! 22 | * Checks if a range is sorted using a three-way Comparator (with memcmp() 23 | * semantics). Returns an iterator to the first items not in order. 24 | */ 25 | template 26 | ForwardIterator is_sorted_until_cmp(ForwardIterator first, ForwardIterator last, 27 | Comparator cmp) { 28 | if (first != last) { 29 | ForwardIterator next = first; 30 | while (++next != last) { 31 | if (cmp(*first, *next) > 0) 32 | return next; 33 | first = next; 34 | } 35 | } 36 | return last; 37 | } 38 | 39 | /*! 40 | * Checks if a range is sorted using a three-way Comparator (with memcmp() 41 | * semantics). 42 | */ 43 | template 44 | bool is_sorted_cmp(ForwardIterator first, ForwardIterator last, 45 | Comparator cmp) { 46 | return is_sorted_until_cmp(first, last, cmp) == last; 47 | } 48 | 49 | //! \} 50 | 51 | } // namespace tlx 52 | 53 | #endif // !TLX_ALGORITHM_IS_SORTED_CMP_HEADER 54 | 55 | /******************************************************************************/ 56 | -------------------------------------------------------------------------------- /tlx-leafds/algorithm/parallel_multiway_merge.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/algorithm/parallel_multiway_merge.cpp 3 | * 4 | * Parallel multiway merge settings 5 | * 6 | * Copied and modified from STXXL, see http://stxxl.org, which itself extracted 7 | * it from MCSTL http://algo2.iti.uni-karlsruhe.de/singler/mcstl/. Both are 8 | * distributed under the Boost Software License, Version 1.0. 9 | * 10 | * Part of tlx - http://panthema.net/tlx 11 | * 12 | * Copyright (C) 2007 Johannes Singler 13 | * Copyright (C) 2014-2018 Timo Bingmann 14 | * 15 | * All rights reserved. Published under the Boost Software License, Version 1.0 16 | ******************************************************************************/ 17 | 18 | #include 19 | 20 | namespace tlx { 21 | 22 | //! \addtogroup tlx_algorithm 23 | //! \{ 24 | 25 | // parallel multiway merge settings 26 | 27 | bool parallel_multiway_merge_force_sequential = false; 28 | 29 | bool parallel_multiway_merge_force_parallel = false; 30 | 31 | size_t parallel_multiway_merge_minimal_k = 2; 32 | 33 | size_t parallel_multiway_merge_minimal_n = 1000; 34 | 35 | size_t parallel_multiway_merge_oversampling = 10; 36 | 37 | //! \} 38 | 39 | } // namespace tlx 40 | 41 | /******************************************************************************/ 42 | -------------------------------------------------------------------------------- /tlx-leafds/backtrace.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/backtrace.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2008-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_BACKTRACE_HEADER 12 | #define TLX_BACKTRACE_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | //! \name Stack Backtrace Printing 21 | //! \{ 22 | 23 | /*! 24 | * Print a plain hex stack backtrace of the called function to FILE* out. 25 | */ 26 | void print_raw_backtrace(FILE* out = stderr, unsigned int max_frames = 63); 27 | 28 | /*! 29 | * Print a plain hex stack backtrace of the called function to FILE* out, 30 | * prefixed with the given printf formatted output. 31 | */ 32 | void print_raw_backtrace(FILE* out, unsigned int max_frames, 33 | const char* fmt, ...) 34 | TLX_ATTRIBUTE_FORMAT_PRINTF(3, 4); 35 | 36 | /*! 37 | * Print a demangled stack backtrace of the caller function to FILE* out. 38 | * 39 | * \warning The binary has to be compiled with -rdynamic for meaningful 40 | * output. 41 | */ 42 | void print_cxx_backtrace(FILE* out = stderr, unsigned int max_frames = 63); 43 | 44 | /*! 45 | * Install SIGSEGV signal handler and output backtrace on segmentation fault. 46 | * Compile with `-rdynamic` for more useful output. 47 | */ 48 | void enable_segv_backtrace(); 49 | 50 | //! \} 51 | 52 | } // namespace tlx 53 | 54 | #endif // !TLX_BACKTRACE_HEADER 55 | 56 | /******************************************************************************/ 57 | -------------------------------------------------------------------------------- /tlx-leafds/container.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/container.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_CONTAINER_HEADER 12 | #define TLX_CONTAINER_HEADER 13 | 14 | //! \defgroup tlx_container Containers and Data Structures 15 | //! Containers and Data Structures 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/container/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | // [[[end]]] 35 | 36 | #endif // !TLX_CONTAINER_HEADER 37 | 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /tlx-leafds/define.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_HEADER 12 | #define TLX_DEFINE_HEADER 13 | 14 | //! \defgroup tlx_define Defines and Macros 15 | //! Attribute macros and other defines 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/define/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | // [[[end]]] 31 | 32 | #endif // !TLX_DEFINE_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/define/attribute_always_inline.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_always_inline.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_ALWAYS_INLINE_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_ALWAYS_INLINE_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((always_inline)) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) 24 | #else 25 | #define TLX_ATTRIBUTE_ALWAYS_INLINE 26 | #endif 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_DEFINE_ATTRIBUTE_ALWAYS_INLINE_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/define/attribute_fallthrough.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_fallthrough.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_FALLTHROUGH_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_FALLTHROUGH_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((fallthrough)) 21 | 22 | #if defined(__GNUC__) && __GNUC__ >= 7 23 | #define TLX_ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough)) 24 | #elif defined(__clang__) 25 | #define TLX_ATTRIBUTE_FALLTHROUGH [[clang::fallthrough]] 26 | #else 27 | #define TLX_ATTRIBUTE_FALLTHROUGH 28 | #endif 29 | 30 | //! \} 31 | 32 | } // namespace tlx 33 | 34 | #endif // !TLX_DEFINE_ATTRIBUTE_FALLTHROUGH_HEADER 35 | 36 | /******************************************************************************/ 37 | -------------------------------------------------------------------------------- /tlx-leafds/define/attribute_format_printf.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_format_printf.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_FORMAT_PRINTF_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_FORMAT_PRINTF_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((format(printf, #, #)) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_ATTRIBUTE_FORMAT_PRINTF(X, Y) \ 24 | __attribute__ ((format(printf, X, Y))) // NOLINT 25 | #else 26 | #define TLX_ATTRIBUTE_FORMAT_PRINTF(X, Y) 27 | #endif 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_DEFINE_ATTRIBUTE_FORMAT_PRINTF_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-leafds/define/attribute_packed.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_packed.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_PACKED_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_PACKED_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((packed)) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_ATTRIBUTE_PACKED __attribute__ ((packed)) 24 | #else 25 | #define TLX_ATTRIBUTE_PACKED 26 | #endif 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_DEFINE_ATTRIBUTE_PACKED_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/define/attribute_warn_unused_result.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_warn_unused_result.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_WARN_UNUSED_RESULT_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_WARN_UNUSED_RESULT_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((warn_unused_result)) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) 24 | #else 25 | #define TLX_ATTRIBUTE_WARN_UNUSED_RESULT 26 | #endif 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_DEFINE_ATTRIBUTE_WARN_UNUSED_RESULT_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/define/constexpr.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/constexpr.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2021 Lorenz Hübschle-Schneider 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_CONSTEXPR_HEADER 12 | #define TLX_DEFINE_CONSTEXPR_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | #if __cplusplus >= 201402L 20 | #define TLX_ADVANCED_CONSTEXPR constexpr 21 | #else 22 | #define TLX_ADVANCED_CONSTEXPR inline 23 | #endif 24 | 25 | //! \} 26 | 27 | } // namespace tlx 28 | 29 | #endif // !TLX_DEFINE_CONSTEXPR_HEADER 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-leafds/define/deprecated.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/deprecated.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2008-2009 Andreas Beckmann 7 | * Copyright (C) 2013 Timo Bingmann 8 | * Copyright (C) 2018 Manuel Penschuck 9 | * 10 | * All rights reserved. Published under the Boost Software License, Version 1.0 11 | ******************************************************************************/ 12 | 13 | #ifndef TLX_DEFINE_DEPRECATED_HEADER 14 | #define TLX_DEFINE_DEPRECATED_HEADER 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_define 19 | //! \{ 20 | 21 | #if TLX_NO_DEPRECATED 22 | #define TLX_DEPRECATED(x) x 23 | #elif defined(_MSC_VER) 24 | #define TLX_DEPRECATED(x) __declspec(deprecated)x 25 | #elif defined(__clang__) || defined(__GNUG__) 26 | #define TLX_DEPRECATED(x) x __attribute__ ((deprecated)) 27 | #endif 28 | 29 | #define TLX_DEPRECATED_FUNC_DEF(x) TLX_DEPRECATED(x); x 30 | 31 | //! \} 32 | 33 | } // namespace tlx 34 | 35 | #endif // !TLX_DEFINE_DEPRECATED_HEADER 36 | 37 | /******************************************************************************/ 38 | -------------------------------------------------------------------------------- /tlx-leafds/define/likely.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/likely.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_LIKELY_HEADER 12 | #define TLX_DEFINE_LIKELY_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | #if defined(__GNUC__) || defined(__clang__) 20 | #define TLX_LIKELY(c) __builtin_expect((c), 1) 21 | #define TLX_UNLIKELY(c) __builtin_expect((c), 0) 22 | #else 23 | #define TLX_LIKELY(c) c 24 | #define TLX_UNLIKELY(c) c 25 | #endif 26 | 27 | //! \} 28 | 29 | } // namespace tlx 30 | 31 | #endif // !TLX_DEFINE_LIKELY_HEADER 32 | 33 | /******************************************************************************/ 34 | -------------------------------------------------------------------------------- /tlx-leafds/define/visibility_hidden.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/visibility_hidden.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_VISIBILITY_HIDDEN_HEADER 12 | #define TLX_DEFINE_VISIBILITY_HIDDEN_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((visibility ("hidden"))) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_VISIBILITY_HIDDEN __attribute__ ((visibility("hidden"))) 24 | #else 25 | #define TLX_VISIBILITY_HIDDEN 26 | #endif 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_DEFINE_VISIBILITY_HIDDEN_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/digest.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/digest.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DIGEST_HEADER 12 | #define TLX_DIGEST_HEADER 13 | 14 | //! \defgroup tlx_digest Message Digests 15 | //! Message Digests: MD-5, SHA-256, and SHA-512. 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/digest/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | // [[[end]]] 25 | 26 | #endif // !TLX_DIGEST_HEADER 27 | 28 | /******************************************************************************/ 29 | -------------------------------------------------------------------------------- /tlx-leafds/logger.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger.hpp 3 | * 4 | * Simple logging methods using ostream output. 5 | * 6 | * Part of tlx - http://panthema.net/tlx 7 | * 8 | * Copyright (C) 2018 Timo Bingmann 9 | * 10 | * All rights reserved. Published under the Boost Software License, Version 1.0 11 | ******************************************************************************/ 12 | 13 | #ifndef TLX_LOGGER_HEADER 14 | #define TLX_LOGGER_HEADER 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | //! Explicitly specify the condition for logging 21 | #define LOGC(cond) TLX_LOGC(cond) 22 | 23 | //! Default logging method: output if the local debug variable is true. 24 | #define LOG LOGC(debug) 25 | 26 | //! Override default output: never or always output log. 27 | #define LOG0 LOGC(false) 28 | #define LOG1 LOGC(true) 29 | 30 | //! Explicitly specify the condition for logging 31 | #define sLOGC(cond) TLX_sLOGC(cond) 32 | 33 | //! Default logging method: output if the local debug variable is true. 34 | #define sLOG sLOGC(debug) 35 | 36 | //! Override default output: never or always output log. 37 | #define sLOG0 sLOGC(false) 38 | #define sLOG1 sLOGC(true) 39 | 40 | } // namespace tlx 41 | 42 | #endif // !TLX_LOGGER_HEADER 43 | 44 | /******************************************************************************/ 45 | -------------------------------------------------------------------------------- /tlx-leafds/logger/all.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/all.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_ALL_HEADER 12 | #define TLX_LOGGER_ALL_HEADER 13 | 14 | /*[[[perl 15 | foreach (sort glob("tlx/logger/"."*.hpp")) { 16 | next if $_ eq "tlx/logger/all.hpp"; 17 | print "#include <$_>\n"; 18 | } 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | // [[[end]]] 30 | 31 | #endif // !TLX_LOGGER_ALL_HEADER 32 | 33 | /******************************************************************************/ 34 | -------------------------------------------------------------------------------- /tlx-leafds/logger/array.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/array.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_ARRAY_HEADER 12 | #define TLX_LOGGER_ARRAY_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | template 21 | class LoggerFormatter > 22 | { 23 | public: 24 | static void print(std::ostream& os, const std::array& data) { 25 | os << '['; 26 | for (typename std::array::const_iterator it = data.begin(); 27 | it != data.end(); ++it) 28 | { 29 | if (it != data.begin()) os << ','; 30 | LoggerFormatter::print(os, *it); 31 | } 32 | os << ']'; 33 | } 34 | }; 35 | 36 | } // namespace tlx 37 | 38 | #endif // !TLX_LOGGER_ARRAY_HEADER 39 | 40 | /******************************************************************************/ 41 | -------------------------------------------------------------------------------- /tlx-leafds/logger/deque.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/deque.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_DEQUE_HEADER 12 | #define TLX_LOGGER_DEQUE_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | template 21 | class LoggerFormatter > 22 | { 23 | public: 24 | static void print(std::ostream& os, const std::deque& data) { 25 | os << '['; 26 | for (typename std::deque::const_iterator it = data.begin(); 27 | it != data.end(); ++it) 28 | { 29 | if (it != data.begin()) os << ','; 30 | LoggerFormatter::print(os, *it); 31 | } 32 | os << ']'; 33 | } 34 | }; 35 | 36 | } // namespace tlx 37 | 38 | #endif // !TLX_LOGGER_DEQUE_HEADER 39 | 40 | /******************************************************************************/ 41 | -------------------------------------------------------------------------------- /tlx-leafds/logger/set.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/set.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_SET_HEADER 12 | #define TLX_LOGGER_SET_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | template 21 | class LoggerFormatter > 22 | { 23 | public: 24 | static void print(std::ostream& os, const std::set& data) { 25 | os << '{'; 26 | for (typename std::set::const_iterator it = data.begin(); 27 | it != data.end(); ++it) 28 | { 29 | if (it != data.begin()) os << ','; 30 | LoggerFormatter::print(os, *it); 31 | } 32 | os << '}'; 33 | } 34 | }; 35 | 36 | template 37 | class LoggerFormatter > 38 | { 39 | public: 40 | static void print(std::ostream& os, const std::multiset& data) { 41 | os << '{'; 42 | for (typename std::multiset::const_iterator it = data.begin(); 43 | it != data.end(); ++it) 44 | { 45 | if (it != data.begin()) os << ','; 46 | LoggerFormatter::print(os, *it); 47 | } 48 | os << '}'; 49 | } 50 | }; 51 | 52 | } // namespace tlx 53 | 54 | #endif // !TLX_LOGGER_SET_HEADER 55 | 56 | /******************************************************************************/ 57 | -------------------------------------------------------------------------------- /tlx-leafds/logger/tuple.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/tuple.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_TUPLE_HEADER 12 | #define TLX_LOGGER_TUPLE_HEADER 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | namespace tlx { 20 | 21 | class LoggerTupleFormatter 22 | { 23 | public: 24 | explicit LoggerTupleFormatter(std::ostream& os) : os_(os) { } 25 | template 26 | void operator () (const Index&, const Arg& a) const { 27 | if (Index::index != 0) os_ << ','; 28 | LoggerFormatter::type>::print(os_, a); 29 | } 30 | std::ostream& os_; 31 | }; 32 | 33 | template 34 | class LoggerFormatter > 35 | { 36 | public: 37 | static void print(std::ostream& os, const std::tuple& t) { 38 | os << '('; 39 | call_foreach_tuple_with_index(LoggerTupleFormatter(os), t); 40 | os << ')'; 41 | } 42 | }; 43 | 44 | template <> 45 | class LoggerFormatter > 46 | { 47 | public: 48 | static void print(std::ostream& os, const std::tuple<>&) { 49 | os << '(' << ')'; 50 | } 51 | }; 52 | 53 | } // namespace tlx 54 | 55 | #endif // !TLX_LOGGER_TUPLE_HEADER 56 | 57 | /******************************************************************************/ 58 | -------------------------------------------------------------------------------- /tlx-leafds/math.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_MATH_HEADER 12 | #define TLX_MATH_HEADER 13 | 14 | //! \defgroup tlx_math Math Functions 15 | //! Simple math functions 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/math/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | // [[[end]]] 41 | 42 | #endif // !TLX_MATH_HEADER 43 | 44 | /******************************************************************************/ 45 | -------------------------------------------------------------------------------- /tlx-leafds/math/abs_diff.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/abs_diff.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_MATH_ABS_DIFF_HEADER 12 | #define TLX_MATH_ABS_DIFF_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_math 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // abs_diff() - calculate absolute difference 21 | 22 | //! absolute difference, which also works for unsigned types 23 | template 24 | T abs_diff(const T& a, const T& b) { 25 | return a > b ? a - b : b - a; 26 | } 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_MATH_ABS_DIFF_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/math/div_ceil.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/div_ceil.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_MATH_DIV_CEIL_HEADER 12 | #define TLX_MATH_DIV_CEIL_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_math 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // div_ceil() - calculate n div k with rounding up 21 | 22 | //! calculate n div k with rounding up, for n and k positive! 23 | template 24 | static inline constexpr 25 | auto div_ceil(const IntegralN& n, const IntegralK& k)->decltype(n + k) { 26 | return (n + k - 1) / k; 27 | } 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_MATH_DIV_CEIL_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-leafds/math/power_to_the.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/power_to_the.hpp 3 | * 4 | * power_to_the(x) raises x to the D-th power using log(D) unrolled 5 | * multiplications. 6 | * 7 | * Part of tlx - http://panthema.net/tlx 8 | * 9 | * Copyright (C) 2019 Manuel Penschuck 10 | * 11 | * All rights reserved. Published under the Boost Software License, Version 1.0 12 | ******************************************************************************/ 13 | 14 | #ifndef TLX_MATH_POWER_TO_THE_HEADER 15 | #define TLX_MATH_POWER_TO_THE_HEADER 16 | 17 | #include 18 | 19 | namespace tlx { 20 | 21 | //! \addtogroup tlx_math 22 | //! \{ 23 | 24 | /******************************************************************************/ 25 | //! power_to_the(x) 26 | 27 | //! returns x raised to the power of D using log(D) explicit multiplications. 28 | template 29 | static inline constexpr 30 | T power_to_the(T x) { 31 | // Compiler optimize two calls to the same recursion into one 32 | // Tested with GCC 4+, Clang 3+, MSVC 15+ 33 | return D < 1 ? 1 34 | : D == 1 ? x 35 | : power_to_the(x) * power_to_the(x); 36 | } 37 | 38 | //! \} 39 | 40 | } // namespace tlx 41 | 42 | #endif // !TLX_MATH_POWER_TO_THE_HEADER 43 | 44 | /******************************************************************************/ 45 | -------------------------------------------------------------------------------- /tlx-leafds/math/round_up.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/round_up.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_MATH_ROUND_UP_HEADER 12 | #define TLX_MATH_ROUND_UP_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_math 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // round_up() - round n up to the next multiple of k 21 | 22 | //! round n up to the next multiple of k, for n and k positive! 23 | template 24 | static inline constexpr 25 | auto round_up(const IntegralN& n, const IntegralK& k)->decltype(n + k) { 26 | return ((n + k - 1) / k) * k; 27 | } 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_MATH_ROUND_UP_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-leafds/math/sgn.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/sgn.hpp 3 | * 4 | * sgn() return the signum (-1, 0, +1) of a value. 5 | * 6 | * Part of tlx - http://panthema.net/tlx 7 | * 8 | * Copyright (C) 2018 Timo Bingmann 9 | * 10 | * All rights reserved. Published under the Boost Software License, Version 1.0 11 | ******************************************************************************/ 12 | 13 | #ifndef TLX_MATH_SGN_HEADER 14 | #define TLX_MATH_SGN_HEADER 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_math 19 | //! \{ 20 | 21 | /******************************************************************************/ 22 | //! sgn() - signum 23 | 24 | //! return the signum (-1, 0, +1) of a value. 25 | template 26 | int sgn(const T& val) { 27 | // from https://stackoverflow.com/questions/1903954 28 | return (T(0) < val) - (val < T(0)); 29 | } 30 | 31 | //! \} 32 | 33 | } // namespace tlx 34 | 35 | #endif // !TLX_MATH_SGN_HEADER 36 | 37 | /******************************************************************************/ 38 | -------------------------------------------------------------------------------- /tlx-leafds/meta/enable_if.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/enable_if.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_ENABLE_IF_HEADER 12 | #define TLX_META_ENABLE_IF_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_meta 17 | //! \{ 18 | 19 | //! SFINAE enable_if -- copy of std::enable_if<> with less extra cruft. 20 | template 21 | struct enable_if 22 | { }; 23 | 24 | template 25 | struct enable_if { 26 | typedef T type; 27 | }; 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_META_ENABLE_IF_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-leafds/meta/index_sequence.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/index_sequence.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_INDEX_SEQUENCE_HEADER 12 | #define TLX_META_INDEX_SEQUENCE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | // Compile-time integer sequences, an implementation of std::index_sequence and 22 | // std::make_index_sequence, as these are not available in many current 23 | // libraries (MS Visual C++). 24 | template 25 | struct index_sequence { 26 | static size_t size() { return sizeof ... (Indexes); } 27 | }; 28 | 29 | namespace meta_detail { 30 | 31 | template 32 | struct make_index_sequence_helper; 33 | 34 | template 35 | struct make_index_sequence_helper<0, Indexes...> { 36 | using type = index_sequence; 37 | }; 38 | 39 | template 40 | struct make_index_sequence_helper { 41 | using type = typename make_index_sequence_helper< 42 | CurrentIndex - 1, CurrentIndex - 1, Indexes...>::type; 43 | }; 44 | 45 | } // namespace meta_detail 46 | 47 | template 48 | struct make_index_sequence 49 | : public meta_detail::make_index_sequence_helper::type { }; 50 | 51 | //! \} 52 | 53 | } // namespace tlx 54 | 55 | #endif // !TLX_META_INDEX_SEQUENCE_HEADER 56 | 57 | /******************************************************************************/ 58 | -------------------------------------------------------------------------------- /tlx-leafds/meta/is_std_array.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/is_std_array.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_IS_STD_ARRAY_HEADER 12 | #define TLX_META_IS_STD_ARRAY_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_meta 20 | //! \{ 21 | 22 | //! test if is std::array 23 | template 24 | struct is_std_array : public std::false_type { }; 25 | 26 | template 27 | struct is_std_array >: public std::true_type { }; 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_META_IS_STD_ARRAY_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-leafds/meta/is_std_pair.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/is_std_pair.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_IS_STD_PAIR_HEADER 12 | #define TLX_META_IS_STD_PAIR_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | //! test if is a std::pair<...> 22 | template 23 | struct is_std_pair : public std::false_type { }; 24 | 25 | template 26 | struct is_std_pair >: public std::true_type { }; 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_META_IS_STD_PAIR_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/meta/is_std_tuple.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/is_std_tuple.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_IS_STD_TUPLE_HEADER 12 | #define TLX_META_IS_STD_TUPLE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | //! test if is a std::tuple<...> 22 | template 23 | struct is_std_tuple : public std::false_type { }; 24 | 25 | template 26 | struct is_std_tuple >: public std::true_type { }; 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_META_IS_STD_TUPLE_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/meta/is_std_vector.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/is_std_vector.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_IS_STD_VECTOR_HEADER 12 | #define TLX_META_IS_STD_VECTOR_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | //! test if is std::vector 22 | template 23 | struct is_std_vector : public std::false_type { }; 24 | 25 | template 26 | struct is_std_vector >: public std::true_type { }; 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_META_IS_STD_VECTOR_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/meta/no_operation.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/no_operation.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_NO_OPERATION_HEADER 12 | #define TLX_META_NO_OPERATION_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_meta 17 | //! \{ 18 | 19 | //! The noop functor, which takes any arguments and does nothing. This is a good 20 | //! default argument for lambda function parameters. 21 | template 22 | class NoOperation 23 | { 24 | public: 25 | explicit NoOperation(ReturnType return_value = ReturnType()) 26 | : return_value_(return_value) { } 27 | 28 | ReturnType operator () (...) const noexcept { 29 | return return_value_; 30 | } 31 | 32 | protected: 33 | ReturnType return_value_; 34 | }; 35 | 36 | //! Specialized noop functor which returns a void. 37 | template <> 38 | class NoOperation 39 | { 40 | public: 41 | void operator () (...) const noexcept { } 42 | }; 43 | 44 | //! \} 45 | 46 | } // namespace tlx 47 | 48 | #endif // !TLX_META_NO_OPERATION_HEADER 49 | 50 | /******************************************************************************/ 51 | -------------------------------------------------------------------------------- /tlx-leafds/meta/static_index.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/static_index.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_STATIC_INDEX_HEADER 12 | #define TLX_META_STATIC_INDEX_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | //! Helper for call_foreach_with_index() to save the index as a compile-time 22 | //! index 23 | template 24 | struct StaticIndex { 25 | //! compile-time index 26 | static constexpr size_t index = Index; 27 | 28 | //! implicit conversion to a run-time index. 29 | operator size_t () const { return index; } 30 | }; 31 | 32 | //! \} 33 | 34 | } // namespace tlx 35 | 36 | #endif // !TLX_META_STATIC_INDEX_HEADER 37 | 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /tlx-leafds/meta/vexpand.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/vexpand.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_VEXPAND_HEADER 12 | #define TLX_META_VEXPAND_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_meta 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // vexpand(variables...) -- macro to gobble up expanded parameter packes. This 21 | // is obviously identical to tlx::unused() but used in a different context. 22 | 23 | template 24 | void vexpand(Types&& ...) { } 25 | 26 | //! \} 27 | 28 | } // namespace tlx 29 | 30 | #endif // !TLX_META_VEXPAND_HEADER 31 | 32 | /******************************************************************************/ 33 | -------------------------------------------------------------------------------- /tlx-leafds/port.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/port.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_PORT_HEADER 12 | #define TLX_PORT_HEADER 13 | 14 | //! \defgroup tlx_port Helpers for Portable Code 15 | //! Tools to enable easier writing of portable code. 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/port/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | // [[[end]]] 22 | 23 | #endif // !TLX_PORT_HEADER 24 | 25 | /******************************************************************************/ 26 | -------------------------------------------------------------------------------- /tlx-leafds/port/setenv.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/port/setenv.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2020 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | // Windows porting madness because setenv() is apparently dangerous. 18 | #if defined(_MSC_VER) 19 | 20 | int setenv(const char* name, const char* value, int overwrite) { 21 | if (!overwrite) { 22 | size_t envsize = 0; 23 | int errcode = getenv_s(&envsize, nullptr, 0, name); 24 | if (errcode || envsize) return errcode; 25 | } 26 | return _putenv_s(name, value); 27 | } 28 | 29 | // More porting weirdness for MinGW (32 and 64) 30 | #elif defined(__MINGW32__) 31 | 32 | int setenv(const char* name, const char* value, int overwrite) { 33 | if (!overwrite) { 34 | const char* current = getenv(name); 35 | if (current) return 0; 36 | } 37 | return _putenv_s(name, value); 38 | } 39 | 40 | #else 41 | 42 | int setenv(const char* name, const char* value, int overwrite) { 43 | return ::setenv(name, value, overwrite); 44 | } 45 | 46 | #endif 47 | 48 | } // namespace tlx 49 | 50 | /******************************************************************************/ 51 | -------------------------------------------------------------------------------- /tlx-leafds/port/setenv.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/port/setenv.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_PORT_SETENV_HEADER 12 | #define TLX_PORT_SETENV_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_port 17 | //! \{ 18 | 19 | /*! 20 | * setenv - change or add an environment variable. 21 | * Windows porting madness because setenv() is apparently dangerous. 22 | */ 23 | int setenv(const char* name, const char* value, int overwrite); 24 | 25 | //! \} 26 | 27 | } // namespace tlx 28 | 29 | #endif // !TLX_PORT_SETENV_HEADER 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-leafds/simple_vector.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/simple_vector.hpp 3 | * 4 | * Alias for 5 | * 6 | * Part of tlx - http://panthema.net/tlx 7 | * 8 | * Copyright (C) 2018 Timo Bingmann 9 | * 10 | * All rights reserved. Published under the Boost Software License, Version 1.0 11 | ******************************************************************************/ 12 | 13 | #ifndef TLX_SIMPLE_VECTOR_HEADER 14 | #define TLX_SIMPLE_VECTOR_HEADER 15 | 16 | #include 17 | 18 | #endif // !TLX_SIMPLE_VECTOR_HEADER 19 | 20 | /******************************************************************************/ 21 | -------------------------------------------------------------------------------- /tlx-leafds/sort.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/sort.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_SORT_HEADER 12 | #define TLX_SORT_HEADER 13 | 14 | //! \defgroup tlx_sort Sorting Algorithms 15 | //! Specialized Sorting Algorithms 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort grep(!/_impl/, glob("tlx/sort/"."*.hpp")); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | // [[[end]]] 24 | 25 | #endif // !TLX_SORT_HEADER 26 | 27 | /******************************************************************************/ 28 | -------------------------------------------------------------------------------- /tlx-leafds/sort/networks/cswap.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/sort/networks/cswap.hpp 3 | * 4 | * Conditional swap implementation used for sorting networks. 5 | * 6 | * Part of tlx - http://panthema.net/tlx 7 | * 8 | * Copyright (C) 2018-2020 Jasper Marianczuk 9 | * Copyright (C) 2020 Timo Bingmann 10 | * 11 | * All rights reserved. Published under the Boost Software License, Version 1.0 12 | ******************************************************************************/ 13 | 14 | #ifndef TLX_SORT_NETWORKS_CSWAP_HEADER 15 | #define TLX_SORT_NETWORKS_CSWAP_HEADER 16 | 17 | #include 18 | 19 | namespace tlx { 20 | 21 | //! \addtogroup tlx_sort 22 | //! \{ 23 | //! \name Implementations of Sorting Networks 24 | //! \{ 25 | 26 | //! Implementations of sorting networks for up to sixteen elements. 27 | namespace sort_networks { 28 | 29 | //! Conditional swap implementation used for sorting networks: trivial portable 30 | //! C++ implementation with custom comparison method and std::swap(). 31 | template 32 | class CS_IfSwap 33 | { 34 | public: 35 | CS_IfSwap(Comparator cmp) : cmp_(cmp) { } 36 | 37 | template 38 | inline void operator () (Type& left, Type& right) { 39 | if (cmp_(right, left)) { std::swap(left, right); } 40 | } 41 | 42 | protected: 43 | Comparator cmp_; 44 | }; 45 | 46 | /******************************************************************************/ 47 | 48 | //! \} 49 | //! \} 50 | 51 | } // namespace sort_networks 52 | } // namespace tlx 53 | 54 | #endif // !TLX_SORT_NETWORKS_CSWAP_HEADER 55 | 56 | /******************************************************************************/ 57 | -------------------------------------------------------------------------------- /tlx-leafds/string/appendline.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/appendline.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_APPENDLINE_HEADER 12 | #define TLX_STRING_APPENDLINE_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | 22 | /******************************************************************************/ 23 | // appendline() 24 | 25 | //! like std::getline(istream, string, delim) except that it appends to the 26 | //! string, possibly reusing buffer capacity. 27 | std::istream& appendline(std::istream& is, std::string& str, char delim = '\n'); 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_STRING_APPENDLINE_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-leafds/string/compare_icase.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/compare_icase.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_COMPARE_ICASE_HEADER 12 | #define TLX_STRING_COMPARE_ICASE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /******************************************************************************/ 22 | // compare_icase() 23 | 24 | //! returns +1/0/-1 like strcmp(a, b) but without regard for letter case 25 | int compare_icase(const char* a, const char* b); 26 | 27 | //! returns +1/0/-1 like strcmp(a, b) but without regard for letter case 28 | int compare_icase(const char* a, const std::string& b); 29 | 30 | //! returns +1/0/-1 like strcmp(a, b) but without regard for letter case 31 | int compare_icase(const std::string& a, const char* b); 32 | 33 | //! returns +1/0/-1 like strcmp(a, b) but without regard for letter case 34 | int compare_icase(const std::string& a, const std::string& b); 35 | 36 | //! \} 37 | 38 | } // namespace tlx 39 | 40 | #endif // !TLX_STRING_COMPARE_ICASE_HEADER 41 | 42 | /******************************************************************************/ 43 | -------------------------------------------------------------------------------- /tlx-leafds/string/contains.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/contains.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | namespace tlx { 14 | 15 | bool contains(const std::string& str, const std::string& pattern) { 16 | return str.find(pattern) != std::string::npos; 17 | } 18 | 19 | bool contains(const std::string& str, const char* pattern) { 20 | return str.find(pattern) != std::string::npos; 21 | } 22 | 23 | bool contains(const std::string& str, const char ch) { 24 | return str.find(ch) != std::string::npos; 25 | } 26 | 27 | } // namespace tlx 28 | 29 | /******************************************************************************/ 30 | -------------------------------------------------------------------------------- /tlx-leafds/string/contains.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/contains.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_CONTAINS_HEADER 12 | #define TLX_STRING_CONTAINS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /******************************************************************************/ 22 | // contains() 23 | 24 | //! Tests of string contains pattern 25 | bool contains(const std::string& str, const std::string& pattern); 26 | 27 | //! Tests of string contains pattern 28 | bool contains(const std::string& str, const char* pattern); 29 | 30 | //! Tests of string contains character 31 | bool contains(const std::string& str, const char ch); 32 | 33 | //! \} 34 | 35 | } // namespace tlx 36 | 37 | #endif // !TLX_STRING_CONTAINS_HEADER 38 | 39 | /******************************************************************************/ 40 | -------------------------------------------------------------------------------- /tlx-leafds/string/equal_icase.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/equal_icase.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | bool equal_icase(const char* a, const char* b) { 19 | 20 | while (*a != 0 && *b != 0 && to_lower(*a) == to_lower(*b)) 21 | ++a, ++b; 22 | 23 | return *a == 0 && *b == 0; 24 | } 25 | 26 | bool equal_icase(const char* a, const std::string& b) { 27 | std::string::const_iterator bi = b.begin(); 28 | 29 | while (*a != 0 && bi != b.end() && to_lower(*a) == to_lower(*bi)) 30 | ++a, ++bi; 31 | 32 | return *a == 0 && bi == b.end(); 33 | } 34 | 35 | bool equal_icase(const std::string& a, const char* b) { 36 | std::string::const_iterator ai = a.begin(); 37 | 38 | while (ai != a.end() && *b != 0 && to_lower(*ai) == to_lower(*b)) 39 | ++ai, ++b; 40 | 41 | return ai == a.end() && *b != 0; 42 | } 43 | 44 | bool equal_icase(const std::string& a, const std::string& b) { 45 | if (a.size() != b.size()) return false; 46 | 47 | return std::equal( 48 | a.begin(), a.end(), b.begin(), 49 | [](char c1, char c2) { return to_lower(c1) == to_lower(c2); }); 50 | } 51 | 52 | } // namespace tlx 53 | 54 | /******************************************************************************/ 55 | -------------------------------------------------------------------------------- /tlx-leafds/string/equal_icase.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/equal_icase.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_EQUAL_ICASE_HEADER 12 | #define TLX_STRING_EQUAL_ICASE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /******************************************************************************/ 22 | // equal_icase() 23 | 24 | //! returns true if a == b without regard for letter case 25 | bool equal_icase(const char* a, const char* b); 26 | 27 | //! returns true if a == b without regard for letter case 28 | bool equal_icase(const char* a, const std::string& b); 29 | 30 | //! returns true if a == b without regard for letter case 31 | bool equal_icase(const std::string& a, const char* b); 32 | 33 | //! returns true if a == b without regard for letter case 34 | bool equal_icase(const std::string& a, const std::string& b); 35 | 36 | //! \} 37 | 38 | } // namespace tlx 39 | 40 | #endif // !TLX_STRING_EQUAL_ICASE_HEADER 41 | 42 | /******************************************************************************/ 43 | -------------------------------------------------------------------------------- /tlx-leafds/string/escape_html.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/escape_html.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | std::string escape_html(const std::string& str) { 18 | std::string os; 19 | os.reserve(str.size() + str.size() / 16); 20 | 21 | for (std::string::const_iterator si = str.begin(); si != str.end(); ++si) 22 | { 23 | if (*si == '&') os += "&"; 24 | else if (*si == '<') os += "<"; 25 | else if (*si == '>') os += ">"; 26 | else if (*si == '"') os += """; 27 | else os += *si; 28 | } 29 | 30 | return os; 31 | } 32 | 33 | std::string escape_html(const char* str) { 34 | size_t slen = strlen(str); 35 | std::string os; 36 | os.reserve(slen + slen / 16); 37 | 38 | for (const char* si = str; *si != 0; ++si) 39 | { 40 | if (*si == '&') os += "&"; 41 | else if (*si == '<') os += "<"; 42 | else if (*si == '>') os += ">"; 43 | else if (*si == '"') os += """; 44 | else os += *si; 45 | } 46 | 47 | return os; 48 | } 49 | 50 | } // namespace tlx 51 | 52 | /******************************************************************************/ 53 | -------------------------------------------------------------------------------- /tlx-leafds/string/escape_html.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/escape_html.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_ESCAPE_HTML_HEADER 12 | #define TLX_STRING_ESCAPE_HTML_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Escape characters for inclusion in HTML documents: replaces the characters <, 23 | * >, & and " with HTML entities. 24 | */ 25 | std::string escape_html(const std::string& str); 26 | 27 | /*! 28 | * Escape characters for inclusion in HTML documents: replaces the characters <, 29 | * >, & and " with HTML entities. 30 | */ 31 | std::string escape_html(const char* str); 32 | 33 | //! \} 34 | 35 | } // namespace tlx 36 | 37 | #endif // !TLX_STRING_ESCAPE_HTML_HEADER 38 | 39 | /******************************************************************************/ 40 | -------------------------------------------------------------------------------- /tlx-leafds/string/escape_uri.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/escape_uri.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_ESCAPE_URI_HEADER 12 | #define TLX_STRING_ESCAPE_URI_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Escape a string into a URI-encoding. This maps all non A-Z0-9 characters to 23 | * %HH hex representation. 24 | */ 25 | std::string escape_uri(const std::string& str); 26 | 27 | /*! 28 | * Escape a string into a URI-encoding. This maps all non A-Z0-9 characters to 29 | * %HH hex representation. 30 | */ 31 | std::string escape_uri(const char* str); 32 | 33 | //! \} 34 | 35 | } // namespace tlx 36 | 37 | #endif // !TLX_STRING_ESCAPE_URI_HEADER 38 | 39 | /******************************************************************************/ 40 | -------------------------------------------------------------------------------- /tlx-leafds/string/expand_environment_variables.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/expand_environment_variables.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_EXPAND_ENVIRONMENT_VARIABLES_HEADER 12 | #define TLX_STRING_EXPAND_ENVIRONMENT_VARIABLES_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Expand substrings $ABC_123 and ${ABC_123} into the corresponding environment 23 | * variables. Matches all substrings "$[a-zA-Z_][a-zA-Z0-9_]*" and 24 | * "${[^}]*}". Replaces all substrings in-place. 25 | */ 26 | std::string& expand_environment_variables(std::string* s); 27 | 28 | /*! 29 | * Expand substrings $ABC_123 and ${ABC_123} into the corresponding environment 30 | * variables. Matches all substrings "$[a-zA-Z_][a-zA-Z0-9_]*" and 31 | * "${[^}]*}". Returns a copy of the string with all substrings replaced. 32 | */ 33 | std::string expand_environment_variables(const std::string& s); 34 | 35 | /*! 36 | * Expand substrings $ABC_123 and ${ABC_123} into the corresponding environment 37 | * variables. Matches all substrings "$[a-zA-Z_][a-zA-Z0-9_]*" and 38 | * "${[^}]*}". Returns a copy of the string with all substrings replaced. 39 | */ 40 | std::string expand_environment_variables(const char* s); 41 | 42 | //! \} 43 | 44 | } // namespace tlx 45 | 46 | #endif // !TLX_STRING_EXPAND_ENVIRONMENT_VARIABLES_HEADER 47 | 48 | /******************************************************************************/ 49 | -------------------------------------------------------------------------------- /tlx-leafds/string/format_iec_units.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/format_iec_units.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_FORMAT_IEC_UNITS_HEADER 12 | #define TLX_STRING_FORMAT_IEC_UNITS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | //! Format a byte size using IEC (Ki, Mi, Gi, Ti) suffixes (powers of 22 | //! two). Returns "123 Ki" or similar. 23 | std::string format_iec_units(uint64_t number, int precision = 3); 24 | 25 | //! \} 26 | 27 | } // namespace tlx 28 | 29 | #endif // !TLX_STRING_FORMAT_IEC_UNITS_HEADER 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-leafds/string/format_si_iec_units.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/format_si_iec_units.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_FORMAT_SI_IEC_UNITS_HEADER 12 | #define TLX_STRING_FORMAT_SI_IEC_UNITS_HEADER 13 | 14 | #include 15 | #include 16 | 17 | #endif // !TLX_STRING_FORMAT_SI_IEC_UNITS_HEADER 18 | 19 | /******************************************************************************/ 20 | -------------------------------------------------------------------------------- /tlx-leafds/string/format_si_units.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/format_si_units.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_FORMAT_SI_UNITS_HEADER 12 | #define TLX_STRING_FORMAT_SI_UNITS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | //! Format a byte size using SI (K, M, G, T) suffixes (powers of ten). Returns 22 | //! "123 M" or similar. 23 | std::string format_si_units(uint64_t number, int precision = 3); 24 | 25 | //! \} 26 | 27 | } // namespace tlx 28 | 29 | #endif // !TLX_STRING_FORMAT_SI_UNITS_HEADER 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-leafds/string/index_of.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/index_of.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_INDEX_OF_HEADER 12 | #define TLX_STRING_INDEX_OF_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | 22 | /*! 23 | * Attempts to find str in the list and return the index. Throws a 24 | * std::runtime_error if it is not found. 25 | */ 26 | size_t index_of(const std::vector& list, const char* str); 27 | 28 | /*! 29 | * Attempts to find str in the list and return the index. Throws a 30 | * std::runtime_error if it is not found. 31 | */ 32 | size_t index_of(const std::vector& list, const std::string& str); 33 | 34 | /*! 35 | * Attempts to find str in the list and return the index using case-insensitive 36 | * comparisons. Throws a std::runtime_error if it is not found. 37 | */ 38 | size_t index_of_icase(const std::vector& list, const char* str); 39 | 40 | /*! 41 | * Attempts to find str in the list and return the index using case-insensitive 42 | * comparisons. Throws a std::runtime_error if it is not found. 43 | */ 44 | size_t 45 | index_of_icase(const std::vector& list, const std::string& str); 46 | 47 | //! \} 48 | 49 | } // namespace tlx 50 | 51 | #endif // !TLX_STRING_INDEX_OF_HEADER 52 | 53 | /******************************************************************************/ 54 | -------------------------------------------------------------------------------- /tlx-leafds/string/join.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/join.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | #include 13 | 14 | namespace tlx { 15 | 16 | std::string join(char glue, const std::vector& parts) { 17 | return join(glue, parts.begin(), parts.end()); 18 | } 19 | 20 | std::string join(const char* glue, const std::vector& parts) { 21 | return join(glue, parts.begin(), parts.end()); 22 | } 23 | 24 | std::string join( 25 | const std::string& glue, const std::vector& parts) { 26 | return join(glue, parts.begin(), parts.end()); 27 | } 28 | 29 | } // namespace tlx 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-leafds/string/join_quoted.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/join_quoted.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_JOIN_QUOTED_HEADER 12 | #define TLX_STRING_JOIN_QUOTED_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | //! \name Split and Join 22 | //! \{ 23 | 24 | /*! 25 | * Join a vector of strings using a separator character. If any string contains 26 | * the separator, quote the field. In the quoted string, escape all quotes, 27 | * escapes, \\n, \\r, \\t sequences. This is the opposite of split_quoted(). 28 | */ 29 | std::string join_quoted( 30 | const std::vector& str, char sep, char quote, char escape); 31 | 32 | /*! 33 | * Join a vector of strings using spaces as separator character. If any string 34 | * contains a space, quote the field. In the quoted string, escape all quotes, 35 | * escapes, \\n, \\r, \\t sequences. This is the opposite of split_quoted(). 36 | */ 37 | std::string join_quoted(const std::vector& str); 38 | 39 | //! \} 40 | //! \} 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_STRING_JOIN_QUOTED_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-leafds/string/pad.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/pad.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | namespace tlx { 14 | 15 | std::string pad(const std::string& s, size_t len, char pad_char) { 16 | std::string str = s; 17 | str.resize(len, pad_char); 18 | return str; 19 | } 20 | 21 | } // namespace tlx 22 | 23 | /******************************************************************************/ 24 | -------------------------------------------------------------------------------- /tlx-leafds/string/pad.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/pad.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_PAD_HEADER 12 | #define TLX_STRING_PAD_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Truncate or pad string to exactly len characters. 23 | */ 24 | std::string pad(const std::string& s, size_t len, char pad_char = ' '); 25 | 26 | //! \} 27 | 28 | } // namespace tlx 29 | 30 | #endif // !TLX_STRING_PAD_HEADER 31 | 32 | /******************************************************************************/ 33 | -------------------------------------------------------------------------------- /tlx-leafds/string/parse_si_iec_units.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/parse_si_iec_units.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_PARSE_SI_IEC_UNITS_HEADER 12 | #define TLX_STRING_PARSE_SI_IEC_UNITS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Parse a string like "343KB" or "44 GiB" into the corresponding size in 23 | * bytes. Returns the number of bytes and sets ok = true if the string could be 24 | * parsed correctly. If no units indicator is given, use def_unit in k/m/g/t/p 25 | * (powers of ten) or in K/M/G/T/P (power of two). 26 | */ 27 | bool parse_si_iec_units( 28 | const char* str, uint64_t* out_size, char default_unit = 0); 29 | 30 | /*! 31 | * Parse a string like "343KB" or "44 GiB" into the corresponding size in 32 | * bytes. Returns the number of bytes and sets ok = true if the string could be 33 | * parsed correctly. If no units indicator is given, use def_unit in k/m/g/t/p 34 | * (powers of ten) or in K/M/G/T/P (power of two). 35 | */ 36 | bool parse_si_iec_units( 37 | const std::string& str, uint64_t* out_size, char default_unit = 0); 38 | 39 | //! \} 40 | 41 | } // namespace tlx 42 | 43 | #endif // !TLX_STRING_PARSE_SI_IEC_UNITS_HEADER 44 | 45 | /******************************************************************************/ 46 | -------------------------------------------------------------------------------- /tlx-leafds/string/split_quoted.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/split_quoted.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_SPLIT_QUOTED_HEADER 12 | #define TLX_STRING_SPLIT_QUOTED_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | //! \name Split and Join 22 | //! \{ 23 | 24 | /*! 25 | * Split the given string at each separator character into distinct 26 | * substrings. Multiple separators are joined and will not result in empty split 27 | * substrings. Quoted fields extend to the next quote. Quoted fields may 28 | * containg escaped quote, and \\n \\r \\t \\\\ sequences. 29 | */ 30 | std::vector split_quoted( 31 | const std::string& str, char sep, char quote, char escape); 32 | 33 | /*! 34 | * Split the given string at each space into distinct substrings. Multiple 35 | * spaces are joined and will not result in empty split substrings. Quoted 36 | * fields extend to the next quote. Quoted fields may containg escaped quote, 37 | * and \\n \\r \\t \\\\ sequences. 38 | */ 39 | std::vector split_quoted(const std::string& str); 40 | 41 | //! \} 42 | //! \} 43 | 44 | } // namespace tlx 45 | 46 | #endif // !TLX_STRING_SPLIT_QUOTED_HEADER 47 | 48 | /******************************************************************************/ 49 | -------------------------------------------------------------------------------- /tlx-leafds/string/split_words.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/split_words.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | namespace tlx { 14 | 15 | std::vector split_words( 16 | const std::string& str, std::string::size_type limit) { 17 | std::vector out; 18 | if (limit == 0) return out; 19 | 20 | std::string::const_iterator it = str.begin(), last = it; 21 | 22 | for ( ; it != str.end(); ++it) 23 | { 24 | if (*it == ' ' || *it == '\n' || *it == '\t' || *it == '\r') 25 | { 26 | if (it == last) { // skip over empty split substrings 27 | last = it + 1; 28 | continue; 29 | } 30 | 31 | if (out.size() + 1 >= limit) 32 | { 33 | out.emplace_back(last, str.end()); 34 | return out; 35 | } 36 | 37 | out.emplace_back(last, it); 38 | last = it + 1; 39 | } 40 | } 41 | 42 | if (last != it) 43 | out.emplace_back(last, it); 44 | 45 | return out; 46 | } 47 | 48 | } // namespace tlx 49 | 50 | /******************************************************************************/ 51 | -------------------------------------------------------------------------------- /tlx-leafds/string/split_words.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/split_words.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_SPLIT_WORDS_HEADER 12 | #define TLX_STRING_SPLIT_WORDS_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | 22 | /*! 23 | * Split the given string by whitespaces into distinct words. Multiple 24 | * consecutive whitespaces are considered as one split point. Whitespaces are 25 | * space, tab, newline and carriage-return. 26 | * 27 | * \param str string to split 28 | * \param limit maximum number of parts returned 29 | * \return vector containing each split substring 30 | */ 31 | std::vector split_words( 32 | const std::string& str, std::string::size_type limit = std::string::npos); 33 | 34 | //! \} 35 | 36 | } // namespace tlx 37 | 38 | #endif // !TLX_STRING_SPLIT_WORDS_HEADER 39 | 40 | /******************************************************************************/ 41 | -------------------------------------------------------------------------------- /tlx-leafds/string/ssprintf.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/ssprintf.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace tlx { 17 | 18 | std::string ssprintf(const char* fmt, ...) { 19 | std::string out; 20 | out.resize(128); 21 | 22 | va_list args; 23 | va_start(args, fmt); 24 | 25 | int size = std::vsnprintf( 26 | const_cast(out.data()), out.size() + 1, fmt, args); 27 | 28 | if (size >= static_cast(out.size())) { 29 | // error, grow buffer and try again. 30 | out.resize(size); 31 | size = std::vsnprintf( 32 | const_cast(out.data()), out.size() + 1, fmt, args); 33 | } 34 | 35 | out.resize(size); 36 | 37 | va_end(args); 38 | 39 | return out; 40 | } 41 | 42 | std::string ssnprintf(size_t max_size, const char* fmt, ...) { 43 | std::string out; 44 | out.resize(max_size); 45 | 46 | va_list args; 47 | va_start(args, fmt); 48 | 49 | int size = std::vsnprintf( 50 | const_cast(out.data()), out.size() + 1, fmt, args); 51 | 52 | if (static_cast(size) < max_size) 53 | out.resize(static_cast(size)); 54 | 55 | va_end(args); 56 | 57 | return out; 58 | } 59 | 60 | } // namespace tlx 61 | 62 | /******************************************************************************/ 63 | -------------------------------------------------------------------------------- /tlx-leafds/string/ssprintf.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/ssprintf.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_SSPRINTF_HEADER 12 | #define TLX_STRING_SSPRINTF_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | //! \addtogroup tlx_string 21 | //! \{ 22 | 23 | /*! 24 | * Helper for return the result of a sprintf() call inside a std::string. 25 | * 26 | * \param fmt printf format and additional parameters 27 | */ 28 | std::string ssprintf(const char* fmt, ...) 29 | TLX_ATTRIBUTE_FORMAT_PRINTF(1, 2); 30 | 31 | /*! 32 | * Helper for return the result of a snprintf() call inside a std::string. 33 | * 34 | * \param max_size maximum length of output string, longer ones are truncated. 35 | * \param fmt printf format and additional parameters 36 | */ 37 | std::string ssnprintf(size_t max_size, const char* fmt, ...) 38 | TLX_ATTRIBUTE_FORMAT_PRINTF(2, 3); 39 | 40 | //! \} 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_STRING_SSPRINTF_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-leafds/string/to_lower.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/to_lower.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | char to_lower(char ch) { 18 | if (static_cast(ch - 'A') < 26u) 19 | ch = static_cast(ch - 'A' + 'a'); 20 | return ch; 21 | } 22 | 23 | std::string& to_lower(std::string* str) { 24 | std::transform(str->begin(), str->end(), str->begin(), 25 | [](char c) { return to_lower(c); }); 26 | return *str; 27 | } 28 | 29 | std::string to_lower(const std::string& str) { 30 | std::string str_copy(str.size(), 0); 31 | std::transform(str.begin(), str.end(), str_copy.begin(), 32 | [](char c) { return to_lower(c); }); 33 | return str_copy; 34 | } 35 | 36 | } // namespace tlx 37 | 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /tlx-leafds/string/to_lower.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/to_lower.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_TO_LOWER_HEADER 12 | #define TLX_STRING_TO_LOWER_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | //! Transform the given character to lower case without any localization. 22 | char to_lower(char ch); 23 | 24 | /*! 25 | * Transforms the given string to lowercase and returns a reference to it. 26 | * 27 | * \param str string to process 28 | * \return reference to the modified string 29 | */ 30 | std::string& to_lower(std::string* str); 31 | 32 | /*! 33 | * Returns a copy of the given string converted to lowercase. 34 | * 35 | * \param str string to process 36 | * \return new string lowercased 37 | */ 38 | std::string to_lower(const std::string& str); 39 | 40 | //! \} 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_STRING_TO_LOWER_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-leafds/string/to_upper.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/to_upper.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | char to_upper(char ch) { 18 | if (static_cast(ch - 'a') < 26u) 19 | ch = static_cast(ch - 'a' + 'A'); 20 | return ch; 21 | } 22 | 23 | std::string& to_upper(std::string* str) { 24 | std::transform(str->begin(), str->end(), str->begin(), 25 | [](char c) { return to_upper(c); }); 26 | return *str; 27 | } 28 | 29 | std::string to_upper(const std::string& str) { 30 | std::string str_copy(str.size(), 0); 31 | std::transform(str.begin(), str.end(), str_copy.begin(), 32 | [](char c) { return to_upper(c); }); 33 | return str_copy; 34 | } 35 | 36 | } // namespace tlx 37 | 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /tlx-leafds/string/to_upper.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/to_upper.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_TO_UPPER_HEADER 12 | #define TLX_STRING_TO_UPPER_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | //! Transform the given character to upper case without any localization. 22 | char to_upper(char ch); 23 | 24 | /*! 25 | * Transforms the given string to uppercase and returns a reference to it. 26 | * 27 | * \param str string to process 28 | * \return reference to the modified string 29 | */ 30 | std::string& to_upper(std::string* str); 31 | 32 | /*! 33 | * Returns a copy of the given string converted to uppercase. 34 | * 35 | * \param str string to process 36 | * \return new string uppercased 37 | */ 38 | std::string to_upper(const std::string& str); 39 | 40 | //! \} 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_STRING_TO_UPPER_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-leafds/string/union_words.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/union_words.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | #include 13 | 14 | namespace tlx { 15 | 16 | std::string union_words(const std::string& wordsA, const std::string& wordsB) { 17 | std::string words = wordsA; 18 | 19 | std::string::const_iterator it = wordsB.begin(); 20 | 21 | while (it != wordsB.end()) 22 | { 23 | // skip over whitespace 24 | while (*it == ' ' || *it == '\n' || *it == '\t' || *it == '\r') { 25 | if (++it == wordsB.end()) break; 26 | } 27 | 28 | std::string::const_iterator i1 = it; 29 | 30 | // find first non-whitespace 31 | while (it != wordsB.end() && 32 | *it != ' ' && *it != '\n' && *it != '\t' && *it != '\r') 33 | ++it; 34 | 35 | std::string w(i1, it); 36 | 37 | if (!contains_word(words, w)) { 38 | if (!words.empty()) 39 | words += ' '; 40 | words += w; 41 | } 42 | } 43 | 44 | return words; 45 | } 46 | 47 | } // namespace tlx 48 | 49 | /******************************************************************************/ 50 | -------------------------------------------------------------------------------- /tlx-leafds/string/union_words.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/union_words.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_UNION_WORDS_HEADER 12 | #define TLX_STRING_UNION_WORDS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Return union of two keyword sets. 23 | */ 24 | std::string union_words(const std::string& wordsA, const std::string& wordsB); 25 | 26 | //! \} 27 | 28 | } // namespace tlx 29 | 30 | #endif // !TLX_STRING_UNION_WORDS_HEADER 31 | 32 | /******************************************************************************/ 33 | -------------------------------------------------------------------------------- /tlx-leafds/string/word_wrap.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/word_wrap.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_WORD_WRAP_HEADER 12 | #define TLX_STRING_WORD_WRAP_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Try to wrap a string to 80 columns without split words. All newlines are 23 | * kept, new newline characters are inserted only at spaces, hence, words are 24 | * never split. If words longer than 80 columns occur they are NOT broken. 25 | */ 26 | std::string word_wrap(const std::string& str, unsigned int wrap = 80); 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_STRING_WORD_WRAP_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-leafds/timestamp.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/timestamp.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | double timestamp() { 18 | return static_cast( 19 | std::chrono::duration_cast( 20 | std::chrono::steady_clock::now().time_since_epoch()).count()) / 1e6; 21 | } 22 | 23 | } // namespace tlx 24 | 25 | /******************************************************************************/ 26 | -------------------------------------------------------------------------------- /tlx-leafds/timestamp.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/timestamp.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_TIMESTAMP_HEADER 12 | #define TLX_TIMESTAMP_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! Returns number of seconds since the epoch, currently microsecond resolution. 17 | double timestamp(); 18 | 19 | } // namespace tlx 20 | 21 | #endif // !TLX_TIMESTAMP_HEADER 22 | 23 | /******************************************************************************/ 24 | -------------------------------------------------------------------------------- /tlx-leafds/unused.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/unused.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_UNUSED_HEADER 12 | #define TLX_UNUSED_HEADER 13 | 14 | namespace tlx { 15 | 16 | /******************************************************************************/ 17 | // UNUSED(variables...) 18 | 19 | template 20 | void unused(Types&& ...) { } 21 | 22 | } // namespace tlx 23 | 24 | #endif // !TLX_UNUSED_HEADER 25 | 26 | /******************************************************************************/ 27 | -------------------------------------------------------------------------------- /tlx-leafds/vector_free.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/vector_free.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_VECTOR_FREE_HEADER 12 | #define TLX_VECTOR_FREE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! Simple method to free the underlying memory in a vector, because .clear() 19 | //! need not do it. 20 | template 21 | void vector_free(std::vector& v) { 22 | std::vector().swap(v); 23 | } 24 | 25 | } // namespace tlx 26 | 27 | #endif // !TLX_VECTOR_FREE_HEADER 28 | 29 | /******************************************************************************/ 30 | -------------------------------------------------------------------------------- /tlx-leafds/version.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/version.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_VERSION_HEADER 12 | #define TLX_VERSION_HEADER 13 | 14 | namespace tlx { 15 | 16 | // versions: synchronize with CMakeLists.txt 17 | 18 | //! TLX_MAJOR_VERSION is the library interface major version number: currently 19 | //! zero. 20 | #define TLX_MAJOR_VERSION 0 21 | 22 | //! TLX_MINOR_VERSION is the minor version number: currently zero. 23 | #define TLX_MINOR_VERSION 5 24 | 25 | /*[[[perl 26 | return "keep" if $ENV{USER} ne "tb"; 27 | use POSIX qw(strftime); 28 | my $date = strftime("%Y%m%d", localtime); 29 | print "//! TLX_PATCH_VERSION is the date of the last commit.\n"; 30 | print "#define TLX_PATCH_VERSION $date\n"; 31 | ]]]*/ 32 | //! TLX_PATCH_VERSION is the date of the last commit. 33 | #define TLX_PATCH_VERSION 20210401 34 | // [[[end]]] 35 | 36 | //! TLX_VERSION is a combination of TLX_MAJOR_VERSION, TLX_MINOR_VERSION, and 37 | //! TLX_PATCH_VERSION 38 | #define TLX_VERSION \ 39 | ((TLX_MAJOR_VERSION * 100lu + TLX_MINOR_VERSION) * 100000000lu \ 40 | + TLX_PATCH_VERSION) 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_VERSION_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-plain/algorithm.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/algorithm.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_ALGORITHM_HEADER 12 | #define TLX_ALGORITHM_HEADER 13 | 14 | //! \defgroup tlx_algorithm Algorithms 15 | //! Algorithms for iterators and ranges 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/algorithm/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | // [[[end]]] 31 | 32 | #endif // !TLX_ALGORITHM_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/algorithm/is_sorted_cmp.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/algorithm/is_sorted_cmp.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_ALGORITHM_IS_SORTED_CMP_HEADER 12 | #define TLX_ALGORITHM_IS_SORTED_CMP_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_algorithm 19 | //! \{ 20 | 21 | /*! 22 | * Checks if a range is sorted using a three-way Comparator (with memcmp() 23 | * semantics). Returns an iterator to the first items not in order. 24 | */ 25 | template 26 | ForwardIterator is_sorted_until_cmp(ForwardIterator first, ForwardIterator last, 27 | Comparator cmp) { 28 | if (first != last) { 29 | ForwardIterator next = first; 30 | while (++next != last) { 31 | if (cmp(*first, *next) > 0) 32 | return next; 33 | first = next; 34 | } 35 | } 36 | return last; 37 | } 38 | 39 | /*! 40 | * Checks if a range is sorted using a three-way Comparator (with memcmp() 41 | * semantics). 42 | */ 43 | template 44 | bool is_sorted_cmp(ForwardIterator first, ForwardIterator last, 45 | Comparator cmp) { 46 | return is_sorted_until_cmp(first, last, cmp) == last; 47 | } 48 | 49 | //! \} 50 | 51 | } // namespace tlx 52 | 53 | #endif // !TLX_ALGORITHM_IS_SORTED_CMP_HEADER 54 | 55 | /******************************************************************************/ 56 | -------------------------------------------------------------------------------- /tlx-plain/algorithm/parallel_multiway_merge.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/algorithm/parallel_multiway_merge.cpp 3 | * 4 | * Parallel multiway merge settings 5 | * 6 | * Copied and modified from STXXL, see http://stxxl.org, which itself extracted 7 | * it from MCSTL http://algo2.iti.uni-karlsruhe.de/singler/mcstl/. Both are 8 | * distributed under the Boost Software License, Version 1.0. 9 | * 10 | * Part of tlx - http://panthema.net/tlx 11 | * 12 | * Copyright (C) 2007 Johannes Singler 13 | * Copyright (C) 2014-2018 Timo Bingmann 14 | * 15 | * All rights reserved. Published under the Boost Software License, Version 1.0 16 | ******************************************************************************/ 17 | 18 | #include 19 | 20 | namespace tlx { 21 | 22 | //! \addtogroup tlx_algorithm 23 | //! \{ 24 | 25 | // parallel multiway merge settings 26 | 27 | bool parallel_multiway_merge_force_sequential = false; 28 | 29 | bool parallel_multiway_merge_force_parallel = false; 30 | 31 | size_t parallel_multiway_merge_minimal_k = 2; 32 | 33 | size_t parallel_multiway_merge_minimal_n = 1000; 34 | 35 | size_t parallel_multiway_merge_oversampling = 10; 36 | 37 | //! \} 38 | 39 | } // namespace tlx 40 | 41 | /******************************************************************************/ 42 | -------------------------------------------------------------------------------- /tlx-plain/backtrace.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/backtrace.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2008-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_BACKTRACE_HEADER 12 | #define TLX_BACKTRACE_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | //! \name Stack Backtrace Printing 21 | //! \{ 22 | 23 | /*! 24 | * Print a plain hex stack backtrace of the called function to FILE* out. 25 | */ 26 | void print_raw_backtrace(FILE* out = stderr, unsigned int max_frames = 63); 27 | 28 | /*! 29 | * Print a plain hex stack backtrace of the called function to FILE* out, 30 | * prefixed with the given printf formatted output. 31 | */ 32 | void print_raw_backtrace(FILE* out, unsigned int max_frames, 33 | const char* fmt, ...) 34 | TLX_ATTRIBUTE_FORMAT_PRINTF(3, 4); 35 | 36 | /*! 37 | * Print a demangled stack backtrace of the caller function to FILE* out. 38 | * 39 | * \warning The binary has to be compiled with -rdynamic for meaningful 40 | * output. 41 | */ 42 | void print_cxx_backtrace(FILE* out = stderr, unsigned int max_frames = 63); 43 | 44 | /*! 45 | * Install SIGSEGV signal handler and output backtrace on segmentation fault. 46 | * Compile with `-rdynamic` for more useful output. 47 | */ 48 | void enable_segv_backtrace(); 49 | 50 | //! \} 51 | 52 | } // namespace tlx 53 | 54 | #endif // !TLX_BACKTRACE_HEADER 55 | 56 | /******************************************************************************/ 57 | -------------------------------------------------------------------------------- /tlx-plain/container.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/container.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_CONTAINER_HEADER 12 | #define TLX_CONTAINER_HEADER 13 | 14 | //! \defgroup tlx_container Containers and Data Structures 15 | //! Containers and Data Structures 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/container/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | // [[[end]]] 35 | 36 | #endif // !TLX_CONTAINER_HEADER 37 | 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /tlx-plain/define.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_HEADER 12 | #define TLX_DEFINE_HEADER 13 | 14 | //! \defgroup tlx_define Defines and Macros 15 | //! Attribute macros and other defines 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/define/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | // [[[end]]] 31 | 32 | #endif // !TLX_DEFINE_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/define/attribute_always_inline.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_always_inline.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_ALWAYS_INLINE_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_ALWAYS_INLINE_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((always_inline)) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline)) 24 | #else 25 | #define TLX_ATTRIBUTE_ALWAYS_INLINE 26 | #endif 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_DEFINE_ATTRIBUTE_ALWAYS_INLINE_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/define/attribute_fallthrough.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_fallthrough.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_FALLTHROUGH_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_FALLTHROUGH_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((fallthrough)) 21 | 22 | #if defined(__GNUC__) && __GNUC__ >= 7 23 | #define TLX_ATTRIBUTE_FALLTHROUGH __attribute__ ((fallthrough)) 24 | #elif defined(__clang__) 25 | #define TLX_ATTRIBUTE_FALLTHROUGH [[clang::fallthrough]] 26 | #else 27 | #define TLX_ATTRIBUTE_FALLTHROUGH 28 | #endif 29 | 30 | //! \} 31 | 32 | } // namespace tlx 33 | 34 | #endif // !TLX_DEFINE_ATTRIBUTE_FALLTHROUGH_HEADER 35 | 36 | /******************************************************************************/ 37 | -------------------------------------------------------------------------------- /tlx-plain/define/attribute_format_printf.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_format_printf.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_FORMAT_PRINTF_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_FORMAT_PRINTF_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((format(printf, #, #)) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_ATTRIBUTE_FORMAT_PRINTF(X, Y) \ 24 | __attribute__ ((format(printf, X, Y))) // NOLINT 25 | #else 26 | #define TLX_ATTRIBUTE_FORMAT_PRINTF(X, Y) 27 | #endif 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_DEFINE_ATTRIBUTE_FORMAT_PRINTF_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-plain/define/attribute_packed.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_packed.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_PACKED_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_PACKED_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((packed)) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_ATTRIBUTE_PACKED __attribute__ ((packed)) 24 | #else 25 | #define TLX_ATTRIBUTE_PACKED 26 | #endif 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_DEFINE_ATTRIBUTE_PACKED_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/define/attribute_warn_unused_result.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/attribute_warn_unused_result.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_ATTRIBUTE_WARN_UNUSED_RESULT_HEADER 12 | #define TLX_DEFINE_ATTRIBUTE_WARN_UNUSED_RESULT_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((warn_unused_result)) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result)) 24 | #else 25 | #define TLX_ATTRIBUTE_WARN_UNUSED_RESULT 26 | #endif 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_DEFINE_ATTRIBUTE_WARN_UNUSED_RESULT_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/define/constexpr.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/constexpr.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2021 Lorenz Hübschle-Schneider 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_CONSTEXPR_HEADER 12 | #define TLX_DEFINE_CONSTEXPR_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | #if __cplusplus >= 201402L 20 | #define TLX_ADVANCED_CONSTEXPR constexpr 21 | #else 22 | #define TLX_ADVANCED_CONSTEXPR inline 23 | #endif 24 | 25 | //! \} 26 | 27 | } // namespace tlx 28 | 29 | #endif // !TLX_DEFINE_CONSTEXPR_HEADER 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-plain/define/deprecated.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/deprecated.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2008-2009 Andreas Beckmann 7 | * Copyright (C) 2013 Timo Bingmann 8 | * Copyright (C) 2018 Manuel Penschuck 9 | * 10 | * All rights reserved. Published under the Boost Software License, Version 1.0 11 | ******************************************************************************/ 12 | 13 | #ifndef TLX_DEFINE_DEPRECATED_HEADER 14 | #define TLX_DEFINE_DEPRECATED_HEADER 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_define 19 | //! \{ 20 | 21 | #if TLX_NO_DEPRECATED 22 | #define TLX_DEPRECATED(x) x 23 | #elif defined(_MSC_VER) 24 | #define TLX_DEPRECATED(x) __declspec(deprecated)x 25 | #elif defined(__clang__) || defined(__GNUG__) 26 | #define TLX_DEPRECATED(x) x __attribute__ ((deprecated)) 27 | #endif 28 | 29 | #define TLX_DEPRECATED_FUNC_DEF(x) TLX_DEPRECATED(x); x 30 | 31 | //! \} 32 | 33 | } // namespace tlx 34 | 35 | #endif // !TLX_DEFINE_DEPRECATED_HEADER 36 | 37 | /******************************************************************************/ 38 | -------------------------------------------------------------------------------- /tlx-plain/define/likely.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/likely.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_LIKELY_HEADER 12 | #define TLX_DEFINE_LIKELY_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | #if defined(__GNUC__) || defined(__clang__) 20 | #define TLX_LIKELY(c) __builtin_expect((c), 1) 21 | #define TLX_UNLIKELY(c) __builtin_expect((c), 0) 22 | #else 23 | #define TLX_LIKELY(c) c 24 | #define TLX_UNLIKELY(c) c 25 | #endif 26 | 27 | //! \} 28 | 29 | } // namespace tlx 30 | 31 | #endif // !TLX_DEFINE_LIKELY_HEADER 32 | 33 | /******************************************************************************/ 34 | -------------------------------------------------------------------------------- /tlx-plain/define/visibility_hidden.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/define/visibility_hidden.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DEFINE_VISIBILITY_HIDDEN_HEADER 12 | #define TLX_DEFINE_VISIBILITY_HIDDEN_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_define 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // __attribute__ ((visibility ("hidden"))) 21 | 22 | #if defined(__GNUC__) || defined(__clang__) 23 | #define TLX_VISIBILITY_HIDDEN __attribute__ ((visibility("hidden"))) 24 | #else 25 | #define TLX_VISIBILITY_HIDDEN 26 | #endif 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_DEFINE_VISIBILITY_HIDDEN_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/digest.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/digest.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_DIGEST_HEADER 12 | #define TLX_DIGEST_HEADER 13 | 14 | //! \defgroup tlx_digest Message Digests 15 | //! Message Digests: MD-5, SHA-256, and SHA-512. 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/digest/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | // [[[end]]] 25 | 26 | #endif // !TLX_DIGEST_HEADER 27 | 28 | /******************************************************************************/ 29 | -------------------------------------------------------------------------------- /tlx-plain/logger.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger.hpp 3 | * 4 | * Simple logging methods using ostream output. 5 | * 6 | * Part of tlx - http://panthema.net/tlx 7 | * 8 | * Copyright (C) 2018 Timo Bingmann 9 | * 10 | * All rights reserved. Published under the Boost Software License, Version 1.0 11 | ******************************************************************************/ 12 | 13 | #ifndef TLX_LOGGER_HEADER 14 | #define TLX_LOGGER_HEADER 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | //! Explicitly specify the condition for logging 21 | #define LOGC(cond) TLX_LOGC(cond) 22 | 23 | //! Default logging method: output if the local debug variable is true. 24 | #define LOG LOGC(debug) 25 | 26 | //! Override default output: never or always output log. 27 | #define LOG0 LOGC(false) 28 | #define LOG1 LOGC(true) 29 | 30 | //! Explicitly specify the condition for logging 31 | #define sLOGC(cond) TLX_sLOGC(cond) 32 | 33 | //! Default logging method: output if the local debug variable is true. 34 | #define sLOG sLOGC(debug) 35 | 36 | //! Override default output: never or always output log. 37 | #define sLOG0 sLOGC(false) 38 | #define sLOG1 sLOGC(true) 39 | 40 | } // namespace tlx 41 | 42 | #endif // !TLX_LOGGER_HEADER 43 | 44 | /******************************************************************************/ 45 | -------------------------------------------------------------------------------- /tlx-plain/logger/all.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/all.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_ALL_HEADER 12 | #define TLX_LOGGER_ALL_HEADER 13 | 14 | /*[[[perl 15 | foreach (sort glob("tlx/logger/"."*.hpp")) { 16 | next if $_ eq "tlx/logger/all.hpp"; 17 | print "#include <$_>\n"; 18 | } 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | // [[[end]]] 30 | 31 | #endif // !TLX_LOGGER_ALL_HEADER 32 | 33 | /******************************************************************************/ 34 | -------------------------------------------------------------------------------- /tlx-plain/logger/array.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/array.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_ARRAY_HEADER 12 | #define TLX_LOGGER_ARRAY_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | template 21 | class LoggerFormatter > 22 | { 23 | public: 24 | static void print(std::ostream& os, const std::array& data) { 25 | os << '['; 26 | for (typename std::array::const_iterator it = data.begin(); 27 | it != data.end(); ++it) 28 | { 29 | if (it != data.begin()) os << ','; 30 | LoggerFormatter::print(os, *it); 31 | } 32 | os << ']'; 33 | } 34 | }; 35 | 36 | } // namespace tlx 37 | 38 | #endif // !TLX_LOGGER_ARRAY_HEADER 39 | 40 | /******************************************************************************/ 41 | -------------------------------------------------------------------------------- /tlx-plain/logger/deque.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/deque.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_DEQUE_HEADER 12 | #define TLX_LOGGER_DEQUE_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | template 21 | class LoggerFormatter > 22 | { 23 | public: 24 | static void print(std::ostream& os, const std::deque& data) { 25 | os << '['; 26 | for (typename std::deque::const_iterator it = data.begin(); 27 | it != data.end(); ++it) 28 | { 29 | if (it != data.begin()) os << ','; 30 | LoggerFormatter::print(os, *it); 31 | } 32 | os << ']'; 33 | } 34 | }; 35 | 36 | } // namespace tlx 37 | 38 | #endif // !TLX_LOGGER_DEQUE_HEADER 39 | 40 | /******************************************************************************/ 41 | -------------------------------------------------------------------------------- /tlx-plain/logger/set.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/set.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_SET_HEADER 12 | #define TLX_LOGGER_SET_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | template 21 | class LoggerFormatter > 22 | { 23 | public: 24 | static void print(std::ostream& os, const std::set& data) { 25 | os << '{'; 26 | for (typename std::set::const_iterator it = data.begin(); 27 | it != data.end(); ++it) 28 | { 29 | if (it != data.begin()) os << ','; 30 | LoggerFormatter::print(os, *it); 31 | } 32 | os << '}'; 33 | } 34 | }; 35 | 36 | template 37 | class LoggerFormatter > 38 | { 39 | public: 40 | static void print(std::ostream& os, const std::multiset& data) { 41 | os << '{'; 42 | for (typename std::multiset::const_iterator it = data.begin(); 43 | it != data.end(); ++it) 44 | { 45 | if (it != data.begin()) os << ','; 46 | LoggerFormatter::print(os, *it); 47 | } 48 | os << '}'; 49 | } 50 | }; 51 | 52 | } // namespace tlx 53 | 54 | #endif // !TLX_LOGGER_SET_HEADER 55 | 56 | /******************************************************************************/ 57 | -------------------------------------------------------------------------------- /tlx-plain/logger/tuple.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/logger/tuple.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_LOGGER_TUPLE_HEADER 12 | #define TLX_LOGGER_TUPLE_HEADER 13 | 14 | #include 15 | #include 16 | 17 | #include 18 | 19 | namespace tlx { 20 | 21 | class LoggerTupleFormatter 22 | { 23 | public: 24 | explicit LoggerTupleFormatter(std::ostream& os) : os_(os) { } 25 | template 26 | void operator () (const Index&, const Arg& a) const { 27 | if (Index::index != 0) os_ << ','; 28 | LoggerFormatter::type>::print(os_, a); 29 | } 30 | std::ostream& os_; 31 | }; 32 | 33 | template 34 | class LoggerFormatter > 35 | { 36 | public: 37 | static void print(std::ostream& os, const std::tuple& t) { 38 | os << '('; 39 | call_foreach_tuple_with_index(LoggerTupleFormatter(os), t); 40 | os << ')'; 41 | } 42 | }; 43 | 44 | template <> 45 | class LoggerFormatter > 46 | { 47 | public: 48 | static void print(std::ostream& os, const std::tuple<>&) { 49 | os << '(' << ')'; 50 | } 51 | }; 52 | 53 | } // namespace tlx 54 | 55 | #endif // !TLX_LOGGER_TUPLE_HEADER 56 | 57 | /******************************************************************************/ 58 | -------------------------------------------------------------------------------- /tlx-plain/math.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_MATH_HEADER 12 | #define TLX_MATH_HEADER 13 | 14 | //! \defgroup tlx_math Math Functions 15 | //! Simple math functions 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/math/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | // [[[end]]] 41 | 42 | #endif // !TLX_MATH_HEADER 43 | 44 | /******************************************************************************/ 45 | -------------------------------------------------------------------------------- /tlx-plain/math/abs_diff.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/abs_diff.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_MATH_ABS_DIFF_HEADER 12 | #define TLX_MATH_ABS_DIFF_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_math 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // abs_diff() - calculate absolute difference 21 | 22 | //! absolute difference, which also works for unsigned types 23 | template 24 | T abs_diff(const T& a, const T& b) { 25 | return a > b ? a - b : b - a; 26 | } 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_MATH_ABS_DIFF_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/math/div_ceil.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/div_ceil.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_MATH_DIV_CEIL_HEADER 12 | #define TLX_MATH_DIV_CEIL_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_math 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // div_ceil() - calculate n div k with rounding up 21 | 22 | //! calculate n div k with rounding up, for n and k positive! 23 | template 24 | static inline constexpr 25 | auto div_ceil(const IntegralN& n, const IntegralK& k)->decltype(n + k) { 26 | return (n + k - 1) / k; 27 | } 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_MATH_DIV_CEIL_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-plain/math/power_to_the.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/power_to_the.hpp 3 | * 4 | * power_to_the(x) raises x to the D-th power using log(D) unrolled 5 | * multiplications. 6 | * 7 | * Part of tlx - http://panthema.net/tlx 8 | * 9 | * Copyright (C) 2019 Manuel Penschuck 10 | * 11 | * All rights reserved. Published under the Boost Software License, Version 1.0 12 | ******************************************************************************/ 13 | 14 | #ifndef TLX_MATH_POWER_TO_THE_HEADER 15 | #define TLX_MATH_POWER_TO_THE_HEADER 16 | 17 | #include 18 | 19 | namespace tlx { 20 | 21 | //! \addtogroup tlx_math 22 | //! \{ 23 | 24 | /******************************************************************************/ 25 | //! power_to_the(x) 26 | 27 | //! returns x raised to the power of D using log(D) explicit multiplications. 28 | template 29 | static inline constexpr 30 | T power_to_the(T x) { 31 | // Compiler optimize two calls to the same recursion into one 32 | // Tested with GCC 4+, Clang 3+, MSVC 15+ 33 | return D < 1 ? 1 34 | : D == 1 ? x 35 | : power_to_the(x) * power_to_the(x); 36 | } 37 | 38 | //! \} 39 | 40 | } // namespace tlx 41 | 42 | #endif // !TLX_MATH_POWER_TO_THE_HEADER 43 | 44 | /******************************************************************************/ 45 | -------------------------------------------------------------------------------- /tlx-plain/math/round_up.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/round_up.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_MATH_ROUND_UP_HEADER 12 | #define TLX_MATH_ROUND_UP_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_math 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // round_up() - round n up to the next multiple of k 21 | 22 | //! round n up to the next multiple of k, for n and k positive! 23 | template 24 | static inline constexpr 25 | auto round_up(const IntegralN& n, const IntegralK& k)->decltype(n + k) { 26 | return ((n + k - 1) / k) * k; 27 | } 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_MATH_ROUND_UP_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-plain/math/sgn.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/math/sgn.hpp 3 | * 4 | * sgn() return the signum (-1, 0, +1) of a value. 5 | * 6 | * Part of tlx - http://panthema.net/tlx 7 | * 8 | * Copyright (C) 2018 Timo Bingmann 9 | * 10 | * All rights reserved. Published under the Boost Software License, Version 1.0 11 | ******************************************************************************/ 12 | 13 | #ifndef TLX_MATH_SGN_HEADER 14 | #define TLX_MATH_SGN_HEADER 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_math 19 | //! \{ 20 | 21 | /******************************************************************************/ 22 | //! sgn() - signum 23 | 24 | //! return the signum (-1, 0, +1) of a value. 25 | template 26 | int sgn(const T& val) { 27 | // from https://stackoverflow.com/questions/1903954 28 | return (T(0) < val) - (val < T(0)); 29 | } 30 | 31 | //! \} 32 | 33 | } // namespace tlx 34 | 35 | #endif // !TLX_MATH_SGN_HEADER 36 | 37 | /******************************************************************************/ 38 | -------------------------------------------------------------------------------- /tlx-plain/meta/enable_if.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/enable_if.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_ENABLE_IF_HEADER 12 | #define TLX_META_ENABLE_IF_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_meta 17 | //! \{ 18 | 19 | //! SFINAE enable_if -- copy of std::enable_if<> with less extra cruft. 20 | template 21 | struct enable_if 22 | { }; 23 | 24 | template 25 | struct enable_if { 26 | typedef T type; 27 | }; 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_META_ENABLE_IF_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-plain/meta/index_sequence.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/index_sequence.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_INDEX_SEQUENCE_HEADER 12 | #define TLX_META_INDEX_SEQUENCE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | // Compile-time integer sequences, an implementation of std::index_sequence and 22 | // std::make_index_sequence, as these are not available in many current 23 | // libraries (MS Visual C++). 24 | template 25 | struct index_sequence { 26 | static size_t size() { return sizeof ... (Indexes); } 27 | }; 28 | 29 | namespace meta_detail { 30 | 31 | template 32 | struct make_index_sequence_helper; 33 | 34 | template 35 | struct make_index_sequence_helper<0, Indexes...> { 36 | using type = index_sequence; 37 | }; 38 | 39 | template 40 | struct make_index_sequence_helper { 41 | using type = typename make_index_sequence_helper< 42 | CurrentIndex - 1, CurrentIndex - 1, Indexes...>::type; 43 | }; 44 | 45 | } // namespace meta_detail 46 | 47 | template 48 | struct make_index_sequence 49 | : public meta_detail::make_index_sequence_helper::type { }; 50 | 51 | //! \} 52 | 53 | } // namespace tlx 54 | 55 | #endif // !TLX_META_INDEX_SEQUENCE_HEADER 56 | 57 | /******************************************************************************/ 58 | -------------------------------------------------------------------------------- /tlx-plain/meta/is_std_array.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/is_std_array.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_IS_STD_ARRAY_HEADER 12 | #define TLX_META_IS_STD_ARRAY_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_meta 20 | //! \{ 21 | 22 | //! test if is std::array 23 | template 24 | struct is_std_array : public std::false_type { }; 25 | 26 | template 27 | struct is_std_array >: public std::true_type { }; 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_META_IS_STD_ARRAY_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-plain/meta/is_std_pair.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/is_std_pair.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_IS_STD_PAIR_HEADER 12 | #define TLX_META_IS_STD_PAIR_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | //! test if is a std::pair<...> 22 | template 23 | struct is_std_pair : public std::false_type { }; 24 | 25 | template 26 | struct is_std_pair >: public std::true_type { }; 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_META_IS_STD_PAIR_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/meta/is_std_tuple.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/is_std_tuple.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_IS_STD_TUPLE_HEADER 12 | #define TLX_META_IS_STD_TUPLE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | //! test if is a std::tuple<...> 22 | template 23 | struct is_std_tuple : public std::false_type { }; 24 | 25 | template 26 | struct is_std_tuple >: public std::true_type { }; 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_META_IS_STD_TUPLE_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/meta/is_std_vector.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/is_std_vector.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_IS_STD_VECTOR_HEADER 12 | #define TLX_META_IS_STD_VECTOR_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | //! test if is std::vector 22 | template 23 | struct is_std_vector : public std::false_type { }; 24 | 25 | template 26 | struct is_std_vector >: public std::true_type { }; 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_META_IS_STD_VECTOR_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/meta/no_operation.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/no_operation.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_NO_OPERATION_HEADER 12 | #define TLX_META_NO_OPERATION_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_meta 17 | //! \{ 18 | 19 | //! The noop functor, which takes any arguments and does nothing. This is a good 20 | //! default argument for lambda function parameters. 21 | template 22 | class NoOperation 23 | { 24 | public: 25 | explicit NoOperation(ReturnType return_value = ReturnType()) 26 | : return_value_(return_value) { } 27 | 28 | ReturnType operator () (...) const noexcept { 29 | return return_value_; 30 | } 31 | 32 | protected: 33 | ReturnType return_value_; 34 | }; 35 | 36 | //! Specialized noop functor which returns a void. 37 | template <> 38 | class NoOperation 39 | { 40 | public: 41 | void operator () (...) const noexcept { } 42 | }; 43 | 44 | //! \} 45 | 46 | } // namespace tlx 47 | 48 | #endif // !TLX_META_NO_OPERATION_HEADER 49 | 50 | /******************************************************************************/ 51 | -------------------------------------------------------------------------------- /tlx-plain/meta/static_index.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/static_index.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_STATIC_INDEX_HEADER 12 | #define TLX_META_STATIC_INDEX_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_meta 19 | //! \{ 20 | 21 | //! Helper for call_foreach_with_index() to save the index as a compile-time 22 | //! index 23 | template 24 | struct StaticIndex { 25 | //! compile-time index 26 | static constexpr size_t index = Index; 27 | 28 | //! implicit conversion to a run-time index. 29 | operator size_t () const { return index; } 30 | }; 31 | 32 | //! \} 33 | 34 | } // namespace tlx 35 | 36 | #endif // !TLX_META_STATIC_INDEX_HEADER 37 | 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /tlx-plain/meta/vexpand.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/meta/vexpand.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_META_VEXPAND_HEADER 12 | #define TLX_META_VEXPAND_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_meta 17 | //! \{ 18 | 19 | /******************************************************************************/ 20 | // vexpand(variables...) -- macro to gobble up expanded parameter packes. This 21 | // is obviously identical to tlx::unused() but used in a different context. 22 | 23 | template 24 | void vexpand(Types&& ...) { } 25 | 26 | //! \} 27 | 28 | } // namespace tlx 29 | 30 | #endif // !TLX_META_VEXPAND_HEADER 31 | 32 | /******************************************************************************/ 33 | -------------------------------------------------------------------------------- /tlx-plain/port.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/port.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_PORT_HEADER 12 | #define TLX_PORT_HEADER 13 | 14 | //! \defgroup tlx_port Helpers for Portable Code 15 | //! Tools to enable easier writing of portable code. 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort glob("tlx/port/"."*.hpp"); 19 | ]]]*/ 20 | #include 21 | // [[[end]]] 22 | 23 | #endif // !TLX_PORT_HEADER 24 | 25 | /******************************************************************************/ 26 | -------------------------------------------------------------------------------- /tlx-plain/port/setenv.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/port/setenv.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2020 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | // Windows porting madness because setenv() is apparently dangerous. 18 | #if defined(_MSC_VER) 19 | 20 | int setenv(const char* name, const char* value, int overwrite) { 21 | if (!overwrite) { 22 | size_t envsize = 0; 23 | int errcode = getenv_s(&envsize, nullptr, 0, name); 24 | if (errcode || envsize) return errcode; 25 | } 26 | return _putenv_s(name, value); 27 | } 28 | 29 | // More porting weirdness for MinGW (32 and 64) 30 | #elif defined(__MINGW32__) 31 | 32 | int setenv(const char* name, const char* value, int overwrite) { 33 | if (!overwrite) { 34 | const char* current = getenv(name); 35 | if (current) return 0; 36 | } 37 | return _putenv_s(name, value); 38 | } 39 | 40 | #else 41 | 42 | int setenv(const char* name, const char* value, int overwrite) { 43 | return ::setenv(name, value, overwrite); 44 | } 45 | 46 | #endif 47 | 48 | } // namespace tlx 49 | 50 | /******************************************************************************/ 51 | -------------------------------------------------------------------------------- /tlx-plain/port/setenv.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/port/setenv.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_PORT_SETENV_HEADER 12 | #define TLX_PORT_SETENV_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! \addtogroup tlx_port 17 | //! \{ 18 | 19 | /*! 20 | * setenv - change or add an environment variable. 21 | * Windows porting madness because setenv() is apparently dangerous. 22 | */ 23 | int setenv(const char* name, const char* value, int overwrite); 24 | 25 | //! \} 26 | 27 | } // namespace tlx 28 | 29 | #endif // !TLX_PORT_SETENV_HEADER 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-plain/simple_vector.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/simple_vector.hpp 3 | * 4 | * Alias for 5 | * 6 | * Part of tlx - http://panthema.net/tlx 7 | * 8 | * Copyright (C) 2018 Timo Bingmann 9 | * 10 | * All rights reserved. Published under the Boost Software License, Version 1.0 11 | ******************************************************************************/ 12 | 13 | #ifndef TLX_SIMPLE_VECTOR_HEADER 14 | #define TLX_SIMPLE_VECTOR_HEADER 15 | 16 | #include 17 | 18 | #endif // !TLX_SIMPLE_VECTOR_HEADER 19 | 20 | /******************************************************************************/ 21 | -------------------------------------------------------------------------------- /tlx-plain/sort.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/sort.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_SORT_HEADER 12 | #define TLX_SORT_HEADER 13 | 14 | //! \defgroup tlx_sort Sorting Algorithms 15 | //! Specialized Sorting Algorithms 16 | 17 | /*[[[perl 18 | print "#include <$_>\n" foreach sort grep(!/_impl/, glob("tlx/sort/"."*.hpp")); 19 | ]]]*/ 20 | #include 21 | #include 22 | #include 23 | // [[[end]]] 24 | 25 | #endif // !TLX_SORT_HEADER 26 | 27 | /******************************************************************************/ 28 | -------------------------------------------------------------------------------- /tlx-plain/sort/networks/cswap.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/sort/networks/cswap.hpp 3 | * 4 | * Conditional swap implementation used for sorting networks. 5 | * 6 | * Part of tlx - http://panthema.net/tlx 7 | * 8 | * Copyright (C) 2018-2020 Jasper Marianczuk 9 | * Copyright (C) 2020 Timo Bingmann 10 | * 11 | * All rights reserved. Published under the Boost Software License, Version 1.0 12 | ******************************************************************************/ 13 | 14 | #ifndef TLX_SORT_NETWORKS_CSWAP_HEADER 15 | #define TLX_SORT_NETWORKS_CSWAP_HEADER 16 | 17 | #include 18 | 19 | namespace tlx { 20 | 21 | //! \addtogroup tlx_sort 22 | //! \{ 23 | //! \name Implementations of Sorting Networks 24 | //! \{ 25 | 26 | //! Implementations of sorting networks for up to sixteen elements. 27 | namespace sort_networks { 28 | 29 | //! Conditional swap implementation used for sorting networks: trivial portable 30 | //! C++ implementation with custom comparison method and std::swap(). 31 | template 32 | class CS_IfSwap 33 | { 34 | public: 35 | CS_IfSwap(Comparator cmp) : cmp_(cmp) { } 36 | 37 | template 38 | inline void operator () (Type& left, Type& right) { 39 | if (cmp_(right, left)) { std::swap(left, right); } 40 | } 41 | 42 | protected: 43 | Comparator cmp_; 44 | }; 45 | 46 | /******************************************************************************/ 47 | 48 | //! \} 49 | //! \} 50 | 51 | } // namespace sort_networks 52 | } // namespace tlx 53 | 54 | #endif // !TLX_SORT_NETWORKS_CSWAP_HEADER 55 | 56 | /******************************************************************************/ 57 | -------------------------------------------------------------------------------- /tlx-plain/string/appendline.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/appendline.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_APPENDLINE_HEADER 12 | #define TLX_STRING_APPENDLINE_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | 22 | /******************************************************************************/ 23 | // appendline() 24 | 25 | //! like std::getline(istream, string, delim) except that it appends to the 26 | //! string, possibly reusing buffer capacity. 27 | std::istream& appendline(std::istream& is, std::string& str, char delim = '\n'); 28 | 29 | //! \} 30 | 31 | } // namespace tlx 32 | 33 | #endif // !TLX_STRING_APPENDLINE_HEADER 34 | 35 | /******************************************************************************/ 36 | -------------------------------------------------------------------------------- /tlx-plain/string/compare_icase.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/compare_icase.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_COMPARE_ICASE_HEADER 12 | #define TLX_STRING_COMPARE_ICASE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /******************************************************************************/ 22 | // compare_icase() 23 | 24 | //! returns +1/0/-1 like strcmp(a, b) but without regard for letter case 25 | int compare_icase(const char* a, const char* b); 26 | 27 | //! returns +1/0/-1 like strcmp(a, b) but without regard for letter case 28 | int compare_icase(const char* a, const std::string& b); 29 | 30 | //! returns +1/0/-1 like strcmp(a, b) but without regard for letter case 31 | int compare_icase(const std::string& a, const char* b); 32 | 33 | //! returns +1/0/-1 like strcmp(a, b) but without regard for letter case 34 | int compare_icase(const std::string& a, const std::string& b); 35 | 36 | //! \} 37 | 38 | } // namespace tlx 39 | 40 | #endif // !TLX_STRING_COMPARE_ICASE_HEADER 41 | 42 | /******************************************************************************/ 43 | -------------------------------------------------------------------------------- /tlx-plain/string/contains.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/contains.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | namespace tlx { 14 | 15 | bool contains(const std::string& str, const std::string& pattern) { 16 | return str.find(pattern) != std::string::npos; 17 | } 18 | 19 | bool contains(const std::string& str, const char* pattern) { 20 | return str.find(pattern) != std::string::npos; 21 | } 22 | 23 | bool contains(const std::string& str, const char ch) { 24 | return str.find(ch) != std::string::npos; 25 | } 26 | 27 | } // namespace tlx 28 | 29 | /******************************************************************************/ 30 | -------------------------------------------------------------------------------- /tlx-plain/string/contains.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/contains.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_CONTAINS_HEADER 12 | #define TLX_STRING_CONTAINS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /******************************************************************************/ 22 | // contains() 23 | 24 | //! Tests of string contains pattern 25 | bool contains(const std::string& str, const std::string& pattern); 26 | 27 | //! Tests of string contains pattern 28 | bool contains(const std::string& str, const char* pattern); 29 | 30 | //! Tests of string contains character 31 | bool contains(const std::string& str, const char ch); 32 | 33 | //! \} 34 | 35 | } // namespace tlx 36 | 37 | #endif // !TLX_STRING_CONTAINS_HEADER 38 | 39 | /******************************************************************************/ 40 | -------------------------------------------------------------------------------- /tlx-plain/string/equal_icase.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/equal_icase.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | bool equal_icase(const char* a, const char* b) { 19 | 20 | while (*a != 0 && *b != 0 && to_lower(*a) == to_lower(*b)) 21 | ++a, ++b; 22 | 23 | return *a == 0 && *b == 0; 24 | } 25 | 26 | bool equal_icase(const char* a, const std::string& b) { 27 | std::string::const_iterator bi = b.begin(); 28 | 29 | while (*a != 0 && bi != b.end() && to_lower(*a) == to_lower(*bi)) 30 | ++a, ++bi; 31 | 32 | return *a == 0 && bi == b.end(); 33 | } 34 | 35 | bool equal_icase(const std::string& a, const char* b) { 36 | std::string::const_iterator ai = a.begin(); 37 | 38 | while (ai != a.end() && *b != 0 && to_lower(*ai) == to_lower(*b)) 39 | ++ai, ++b; 40 | 41 | return ai == a.end() && *b != 0; 42 | } 43 | 44 | bool equal_icase(const std::string& a, const std::string& b) { 45 | if (a.size() != b.size()) return false; 46 | 47 | return std::equal( 48 | a.begin(), a.end(), b.begin(), 49 | [](char c1, char c2) { return to_lower(c1) == to_lower(c2); }); 50 | } 51 | 52 | } // namespace tlx 53 | 54 | /******************************************************************************/ 55 | -------------------------------------------------------------------------------- /tlx-plain/string/equal_icase.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/equal_icase.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_EQUAL_ICASE_HEADER 12 | #define TLX_STRING_EQUAL_ICASE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /******************************************************************************/ 22 | // equal_icase() 23 | 24 | //! returns true if a == b without regard for letter case 25 | bool equal_icase(const char* a, const char* b); 26 | 27 | //! returns true if a == b without regard for letter case 28 | bool equal_icase(const char* a, const std::string& b); 29 | 30 | //! returns true if a == b without regard for letter case 31 | bool equal_icase(const std::string& a, const char* b); 32 | 33 | //! returns true if a == b without regard for letter case 34 | bool equal_icase(const std::string& a, const std::string& b); 35 | 36 | //! \} 37 | 38 | } // namespace tlx 39 | 40 | #endif // !TLX_STRING_EQUAL_ICASE_HEADER 41 | 42 | /******************************************************************************/ 43 | -------------------------------------------------------------------------------- /tlx-plain/string/escape_html.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/escape_html.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | std::string escape_html(const std::string& str) { 18 | std::string os; 19 | os.reserve(str.size() + str.size() / 16); 20 | 21 | for (std::string::const_iterator si = str.begin(); si != str.end(); ++si) 22 | { 23 | if (*si == '&') os += "&"; 24 | else if (*si == '<') os += "<"; 25 | else if (*si == '>') os += ">"; 26 | else if (*si == '"') os += """; 27 | else os += *si; 28 | } 29 | 30 | return os; 31 | } 32 | 33 | std::string escape_html(const char* str) { 34 | size_t slen = strlen(str); 35 | std::string os; 36 | os.reserve(slen + slen / 16); 37 | 38 | for (const char* si = str; *si != 0; ++si) 39 | { 40 | if (*si == '&') os += "&"; 41 | else if (*si == '<') os += "<"; 42 | else if (*si == '>') os += ">"; 43 | else if (*si == '"') os += """; 44 | else os += *si; 45 | } 46 | 47 | return os; 48 | } 49 | 50 | } // namespace tlx 51 | 52 | /******************************************************************************/ 53 | -------------------------------------------------------------------------------- /tlx-plain/string/escape_html.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/escape_html.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_ESCAPE_HTML_HEADER 12 | #define TLX_STRING_ESCAPE_HTML_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Escape characters for inclusion in HTML documents: replaces the characters <, 23 | * >, & and " with HTML entities. 24 | */ 25 | std::string escape_html(const std::string& str); 26 | 27 | /*! 28 | * Escape characters for inclusion in HTML documents: replaces the characters <, 29 | * >, & and " with HTML entities. 30 | */ 31 | std::string escape_html(const char* str); 32 | 33 | //! \} 34 | 35 | } // namespace tlx 36 | 37 | #endif // !TLX_STRING_ESCAPE_HTML_HEADER 38 | 39 | /******************************************************************************/ 40 | -------------------------------------------------------------------------------- /tlx-plain/string/escape_uri.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/escape_uri.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_ESCAPE_URI_HEADER 12 | #define TLX_STRING_ESCAPE_URI_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Escape a string into a URI-encoding. This maps all non A-Z0-9 characters to 23 | * %HH hex representation. 24 | */ 25 | std::string escape_uri(const std::string& str); 26 | 27 | /*! 28 | * Escape a string into a URI-encoding. This maps all non A-Z0-9 characters to 29 | * %HH hex representation. 30 | */ 31 | std::string escape_uri(const char* str); 32 | 33 | //! \} 34 | 35 | } // namespace tlx 36 | 37 | #endif // !TLX_STRING_ESCAPE_URI_HEADER 38 | 39 | /******************************************************************************/ 40 | -------------------------------------------------------------------------------- /tlx-plain/string/expand_environment_variables.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/expand_environment_variables.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_EXPAND_ENVIRONMENT_VARIABLES_HEADER 12 | #define TLX_STRING_EXPAND_ENVIRONMENT_VARIABLES_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Expand substrings $ABC_123 and ${ABC_123} into the corresponding environment 23 | * variables. Matches all substrings "$[a-zA-Z_][a-zA-Z0-9_]*" and 24 | * "${[^}]*}". Replaces all substrings in-place. 25 | */ 26 | std::string& expand_environment_variables(std::string* s); 27 | 28 | /*! 29 | * Expand substrings $ABC_123 and ${ABC_123} into the corresponding environment 30 | * variables. Matches all substrings "$[a-zA-Z_][a-zA-Z0-9_]*" and 31 | * "${[^}]*}". Returns a copy of the string with all substrings replaced. 32 | */ 33 | std::string expand_environment_variables(const std::string& s); 34 | 35 | /*! 36 | * Expand substrings $ABC_123 and ${ABC_123} into the corresponding environment 37 | * variables. Matches all substrings "$[a-zA-Z_][a-zA-Z0-9_]*" and 38 | * "${[^}]*}". Returns a copy of the string with all substrings replaced. 39 | */ 40 | std::string expand_environment_variables(const char* s); 41 | 42 | //! \} 43 | 44 | } // namespace tlx 45 | 46 | #endif // !TLX_STRING_EXPAND_ENVIRONMENT_VARIABLES_HEADER 47 | 48 | /******************************************************************************/ 49 | -------------------------------------------------------------------------------- /tlx-plain/string/format_iec_units.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/format_iec_units.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_FORMAT_IEC_UNITS_HEADER 12 | #define TLX_STRING_FORMAT_IEC_UNITS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | //! Format a byte size using IEC (Ki, Mi, Gi, Ti) suffixes (powers of 22 | //! two). Returns "123 Ki" or similar. 23 | std::string format_iec_units(uint64_t number, int precision = 3); 24 | 25 | //! \} 26 | 27 | } // namespace tlx 28 | 29 | #endif // !TLX_STRING_FORMAT_IEC_UNITS_HEADER 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-plain/string/format_si_iec_units.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/format_si_iec_units.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_FORMAT_SI_IEC_UNITS_HEADER 12 | #define TLX_STRING_FORMAT_SI_IEC_UNITS_HEADER 13 | 14 | #include 15 | #include 16 | 17 | #endif // !TLX_STRING_FORMAT_SI_IEC_UNITS_HEADER 18 | 19 | /******************************************************************************/ 20 | -------------------------------------------------------------------------------- /tlx-plain/string/format_si_units.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/format_si_units.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_FORMAT_SI_UNITS_HEADER 12 | #define TLX_STRING_FORMAT_SI_UNITS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | //! Format a byte size using SI (K, M, G, T) suffixes (powers of ten). Returns 22 | //! "123 M" or similar. 23 | std::string format_si_units(uint64_t number, int precision = 3); 24 | 25 | //! \} 26 | 27 | } // namespace tlx 28 | 29 | #endif // !TLX_STRING_FORMAT_SI_UNITS_HEADER 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-plain/string/index_of.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/index_of.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_INDEX_OF_HEADER 12 | #define TLX_STRING_INDEX_OF_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | 22 | /*! 23 | * Attempts to find str in the list and return the index. Throws a 24 | * std::runtime_error if it is not found. 25 | */ 26 | size_t index_of(const std::vector& list, const char* str); 27 | 28 | /*! 29 | * Attempts to find str in the list and return the index. Throws a 30 | * std::runtime_error if it is not found. 31 | */ 32 | size_t index_of(const std::vector& list, const std::string& str); 33 | 34 | /*! 35 | * Attempts to find str in the list and return the index using case-insensitive 36 | * comparisons. Throws a std::runtime_error if it is not found. 37 | */ 38 | size_t index_of_icase(const std::vector& list, const char* str); 39 | 40 | /*! 41 | * Attempts to find str in the list and return the index using case-insensitive 42 | * comparisons. Throws a std::runtime_error if it is not found. 43 | */ 44 | size_t 45 | index_of_icase(const std::vector& list, const std::string& str); 46 | 47 | //! \} 48 | 49 | } // namespace tlx 50 | 51 | #endif // !TLX_STRING_INDEX_OF_HEADER 52 | 53 | /******************************************************************************/ 54 | -------------------------------------------------------------------------------- /tlx-plain/string/join.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/join.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | #include 13 | 14 | namespace tlx { 15 | 16 | std::string join(char glue, const std::vector& parts) { 17 | return join(glue, parts.begin(), parts.end()); 18 | } 19 | 20 | std::string join(const char* glue, const std::vector& parts) { 21 | return join(glue, parts.begin(), parts.end()); 22 | } 23 | 24 | std::string join( 25 | const std::string& glue, const std::vector& parts) { 26 | return join(glue, parts.begin(), parts.end()); 27 | } 28 | 29 | } // namespace tlx 30 | 31 | /******************************************************************************/ 32 | -------------------------------------------------------------------------------- /tlx-plain/string/join_quoted.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/join_quoted.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_JOIN_QUOTED_HEADER 12 | #define TLX_STRING_JOIN_QUOTED_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | //! \name Split and Join 22 | //! \{ 23 | 24 | /*! 25 | * Join a vector of strings using a separator character. If any string contains 26 | * the separator, quote the field. In the quoted string, escape all quotes, 27 | * escapes, \\n, \\r, \\t sequences. This is the opposite of split_quoted(). 28 | */ 29 | std::string join_quoted( 30 | const std::vector& str, char sep, char quote, char escape); 31 | 32 | /*! 33 | * Join a vector of strings using spaces as separator character. If any string 34 | * contains a space, quote the field. In the quoted string, escape all quotes, 35 | * escapes, \\n, \\r, \\t sequences. This is the opposite of split_quoted(). 36 | */ 37 | std::string join_quoted(const std::vector& str); 38 | 39 | //! \} 40 | //! \} 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_STRING_JOIN_QUOTED_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-plain/string/pad.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/pad.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | namespace tlx { 14 | 15 | std::string pad(const std::string& s, size_t len, char pad_char) { 16 | std::string str = s; 17 | str.resize(len, pad_char); 18 | return str; 19 | } 20 | 21 | } // namespace tlx 22 | 23 | /******************************************************************************/ 24 | -------------------------------------------------------------------------------- /tlx-plain/string/pad.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/pad.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_PAD_HEADER 12 | #define TLX_STRING_PAD_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Truncate or pad string to exactly len characters. 23 | */ 24 | std::string pad(const std::string& s, size_t len, char pad_char = ' '); 25 | 26 | //! \} 27 | 28 | } // namespace tlx 29 | 30 | #endif // !TLX_STRING_PAD_HEADER 31 | 32 | /******************************************************************************/ 33 | -------------------------------------------------------------------------------- /tlx-plain/string/parse_si_iec_units.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/parse_si_iec_units.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_PARSE_SI_IEC_UNITS_HEADER 12 | #define TLX_STRING_PARSE_SI_IEC_UNITS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Parse a string like "343KB" or "44 GiB" into the corresponding size in 23 | * bytes. Returns the number of bytes and sets ok = true if the string could be 24 | * parsed correctly. If no units indicator is given, use def_unit in k/m/g/t/p 25 | * (powers of ten) or in K/M/G/T/P (power of two). 26 | */ 27 | bool parse_si_iec_units( 28 | const char* str, uint64_t* out_size, char default_unit = 0); 29 | 30 | /*! 31 | * Parse a string like "343KB" or "44 GiB" into the corresponding size in 32 | * bytes. Returns the number of bytes and sets ok = true if the string could be 33 | * parsed correctly. If no units indicator is given, use def_unit in k/m/g/t/p 34 | * (powers of ten) or in K/M/G/T/P (power of two). 35 | */ 36 | bool parse_si_iec_units( 37 | const std::string& str, uint64_t* out_size, char default_unit = 0); 38 | 39 | //! \} 40 | 41 | } // namespace tlx 42 | 43 | #endif // !TLX_STRING_PARSE_SI_IEC_UNITS_HEADER 44 | 45 | /******************************************************************************/ 46 | -------------------------------------------------------------------------------- /tlx-plain/string/split_quoted.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/split_quoted.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_SPLIT_QUOTED_HEADER 12 | #define TLX_STRING_SPLIT_QUOTED_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | //! \name Split and Join 22 | //! \{ 23 | 24 | /*! 25 | * Split the given string at each separator character into distinct 26 | * substrings. Multiple separators are joined and will not result in empty split 27 | * substrings. Quoted fields extend to the next quote. Quoted fields may 28 | * containg escaped quote, and \\n \\r \\t \\\\ sequences. 29 | */ 30 | std::vector split_quoted( 31 | const std::string& str, char sep, char quote, char escape); 32 | 33 | /*! 34 | * Split the given string at each space into distinct substrings. Multiple 35 | * spaces are joined and will not result in empty split substrings. Quoted 36 | * fields extend to the next quote. Quoted fields may containg escaped quote, 37 | * and \\n \\r \\t \\\\ sequences. 38 | */ 39 | std::vector split_quoted(const std::string& str); 40 | 41 | //! \} 42 | //! \} 43 | 44 | } // namespace tlx 45 | 46 | #endif // !TLX_STRING_SPLIT_QUOTED_HEADER 47 | 48 | /******************************************************************************/ 49 | -------------------------------------------------------------------------------- /tlx-plain/string/split_words.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/split_words.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | namespace tlx { 14 | 15 | std::vector split_words( 16 | const std::string& str, std::string::size_type limit) { 17 | std::vector out; 18 | if (limit == 0) return out; 19 | 20 | std::string::const_iterator it = str.begin(), last = it; 21 | 22 | for ( ; it != str.end(); ++it) 23 | { 24 | if (*it == ' ' || *it == '\n' || *it == '\t' || *it == '\r') 25 | { 26 | if (it == last) { // skip over empty split substrings 27 | last = it + 1; 28 | continue; 29 | } 30 | 31 | if (out.size() + 1 >= limit) 32 | { 33 | out.emplace_back(last, str.end()); 34 | return out; 35 | } 36 | 37 | out.emplace_back(last, it); 38 | last = it + 1; 39 | } 40 | } 41 | 42 | if (last != it) 43 | out.emplace_back(last, it); 44 | 45 | return out; 46 | } 47 | 48 | } // namespace tlx 49 | 50 | /******************************************************************************/ 51 | -------------------------------------------------------------------------------- /tlx-plain/string/split_words.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/split_words.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_SPLIT_WORDS_HEADER 12 | #define TLX_STRING_SPLIT_WORDS_HEADER 13 | 14 | #include 15 | #include 16 | 17 | namespace tlx { 18 | 19 | //! \addtogroup tlx_string 20 | //! \{ 21 | 22 | /*! 23 | * Split the given string by whitespaces into distinct words. Multiple 24 | * consecutive whitespaces are considered as one split point. Whitespaces are 25 | * space, tab, newline and carriage-return. 26 | * 27 | * \param str string to split 28 | * \param limit maximum number of parts returned 29 | * \return vector containing each split substring 30 | */ 31 | std::vector split_words( 32 | const std::string& str, std::string::size_type limit = std::string::npos); 33 | 34 | //! \} 35 | 36 | } // namespace tlx 37 | 38 | #endif // !TLX_STRING_SPLIT_WORDS_HEADER 39 | 40 | /******************************************************************************/ 41 | -------------------------------------------------------------------------------- /tlx-plain/string/ssprintf.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/ssprintf.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | namespace tlx { 17 | 18 | std::string ssprintf(const char* fmt, ...) { 19 | std::string out; 20 | out.resize(128); 21 | 22 | va_list args; 23 | va_start(args, fmt); 24 | 25 | int size = std::vsnprintf( 26 | const_cast(out.data()), out.size() + 1, fmt, args); 27 | 28 | if (size >= static_cast(out.size())) { 29 | // error, grow buffer and try again. 30 | out.resize(size); 31 | size = std::vsnprintf( 32 | const_cast(out.data()), out.size() + 1, fmt, args); 33 | } 34 | 35 | out.resize(size); 36 | 37 | va_end(args); 38 | 39 | return out; 40 | } 41 | 42 | std::string ssnprintf(size_t max_size, const char* fmt, ...) { 43 | std::string out; 44 | out.resize(max_size); 45 | 46 | va_list args; 47 | va_start(args, fmt); 48 | 49 | int size = std::vsnprintf( 50 | const_cast(out.data()), out.size() + 1, fmt, args); 51 | 52 | if (static_cast(size) < max_size) 53 | out.resize(static_cast(size)); 54 | 55 | va_end(args); 56 | 57 | return out; 58 | } 59 | 60 | } // namespace tlx 61 | 62 | /******************************************************************************/ 63 | -------------------------------------------------------------------------------- /tlx-plain/string/ssprintf.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/ssprintf.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_SSPRINTF_HEADER 12 | #define TLX_STRING_SSPRINTF_HEADER 13 | 14 | #include 15 | 16 | #include 17 | 18 | namespace tlx { 19 | 20 | //! \addtogroup tlx_string 21 | //! \{ 22 | 23 | /*! 24 | * Helper for return the result of a sprintf() call inside a std::string. 25 | * 26 | * \param fmt printf format and additional parameters 27 | */ 28 | std::string ssprintf(const char* fmt, ...) 29 | TLX_ATTRIBUTE_FORMAT_PRINTF(1, 2); 30 | 31 | /*! 32 | * Helper for return the result of a snprintf() call inside a std::string. 33 | * 34 | * \param max_size maximum length of output string, longer ones are truncated. 35 | * \param fmt printf format and additional parameters 36 | */ 37 | std::string ssnprintf(size_t max_size, const char* fmt, ...) 38 | TLX_ATTRIBUTE_FORMAT_PRINTF(2, 3); 39 | 40 | //! \} 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_STRING_SSPRINTF_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-plain/string/to_lower.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/to_lower.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | char to_lower(char ch) { 18 | if (static_cast(ch - 'A') < 26u) 19 | ch = static_cast(ch - 'A' + 'a'); 20 | return ch; 21 | } 22 | 23 | std::string& to_lower(std::string* str) { 24 | std::transform(str->begin(), str->end(), str->begin(), 25 | [](char c) { return to_lower(c); }); 26 | return *str; 27 | } 28 | 29 | std::string to_lower(const std::string& str) { 30 | std::string str_copy(str.size(), 0); 31 | std::transform(str.begin(), str.end(), str_copy.begin(), 32 | [](char c) { return to_lower(c); }); 33 | return str_copy; 34 | } 35 | 36 | } // namespace tlx 37 | 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /tlx-plain/string/to_lower.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/to_lower.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_TO_LOWER_HEADER 12 | #define TLX_STRING_TO_LOWER_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | //! Transform the given character to lower case without any localization. 22 | char to_lower(char ch); 23 | 24 | /*! 25 | * Transforms the given string to lowercase and returns a reference to it. 26 | * 27 | * \param str string to process 28 | * \return reference to the modified string 29 | */ 30 | std::string& to_lower(std::string* str); 31 | 32 | /*! 33 | * Returns a copy of the given string converted to lowercase. 34 | * 35 | * \param str string to process 36 | * \return new string lowercased 37 | */ 38 | std::string to_lower(const std::string& str); 39 | 40 | //! \} 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_STRING_TO_LOWER_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-plain/string/to_upper.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/to_upper.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | char to_upper(char ch) { 18 | if (static_cast(ch - 'a') < 26u) 19 | ch = static_cast(ch - 'a' + 'A'); 20 | return ch; 21 | } 22 | 23 | std::string& to_upper(std::string* str) { 24 | std::transform(str->begin(), str->end(), str->begin(), 25 | [](char c) { return to_upper(c); }); 26 | return *str; 27 | } 28 | 29 | std::string to_upper(const std::string& str) { 30 | std::string str_copy(str.size(), 0); 31 | std::transform(str.begin(), str.end(), str_copy.begin(), 32 | [](char c) { return to_upper(c); }); 33 | return str_copy; 34 | } 35 | 36 | } // namespace tlx 37 | 38 | /******************************************************************************/ 39 | -------------------------------------------------------------------------------- /tlx-plain/string/to_upper.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/to_upper.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2007-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_TO_UPPER_HEADER 12 | #define TLX_STRING_TO_UPPER_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | //! Transform the given character to upper case without any localization. 22 | char to_upper(char ch); 23 | 24 | /*! 25 | * Transforms the given string to uppercase and returns a reference to it. 26 | * 27 | * \param str string to process 28 | * \return reference to the modified string 29 | */ 30 | std::string& to_upper(std::string* str); 31 | 32 | /*! 33 | * Returns a copy of the given string converted to uppercase. 34 | * 35 | * \param str string to process 36 | * \return new string uppercased 37 | */ 38 | std::string to_upper(const std::string& str); 39 | 40 | //! \} 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_STRING_TO_UPPER_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /tlx-plain/string/union_words.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/union_words.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | #include 13 | 14 | namespace tlx { 15 | 16 | std::string union_words(const std::string& wordsA, const std::string& wordsB) { 17 | std::string words = wordsA; 18 | 19 | std::string::const_iterator it = wordsB.begin(); 20 | 21 | while (it != wordsB.end()) 22 | { 23 | // skip over whitespace 24 | while (*it == ' ' || *it == '\n' || *it == '\t' || *it == '\r') { 25 | if (++it == wordsB.end()) break; 26 | } 27 | 28 | std::string::const_iterator i1 = it; 29 | 30 | // find first non-whitespace 31 | while (it != wordsB.end() && 32 | *it != ' ' && *it != '\n' && *it != '\t' && *it != '\r') 33 | ++it; 34 | 35 | std::string w(i1, it); 36 | 37 | if (!contains_word(words, w)) { 38 | if (!words.empty()) 39 | words += ' '; 40 | words += w; 41 | } 42 | } 43 | 44 | return words; 45 | } 46 | 47 | } // namespace tlx 48 | 49 | /******************************************************************************/ 50 | -------------------------------------------------------------------------------- /tlx-plain/string/union_words.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/union_words.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_UNION_WORDS_HEADER 12 | #define TLX_STRING_UNION_WORDS_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Return union of two keyword sets. 23 | */ 24 | std::string union_words(const std::string& wordsA, const std::string& wordsB); 25 | 26 | //! \} 27 | 28 | } // namespace tlx 29 | 30 | #endif // !TLX_STRING_UNION_WORDS_HEADER 31 | 32 | /******************************************************************************/ 33 | -------------------------------------------------------------------------------- /tlx-plain/string/word_wrap.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/string/word_wrap.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2016-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_STRING_WORD_WRAP_HEADER 12 | #define TLX_STRING_WORD_WRAP_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! \addtogroup tlx_string 19 | //! \{ 20 | 21 | /*! 22 | * Try to wrap a string to 80 columns without split words. All newlines are 23 | * kept, new newline characters are inserted only at spaces, hence, words are 24 | * never split. If words longer than 80 columns occur they are NOT broken. 25 | */ 26 | std::string word_wrap(const std::string& str, unsigned int wrap = 80); 27 | 28 | //! \} 29 | 30 | } // namespace tlx 31 | 32 | #endif // !TLX_STRING_WORD_WRAP_HEADER 33 | 34 | /******************************************************************************/ 35 | -------------------------------------------------------------------------------- /tlx-plain/timestamp.cpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/timestamp.cpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #include 12 | 13 | #include 14 | 15 | namespace tlx { 16 | 17 | double timestamp() { 18 | return static_cast( 19 | std::chrono::duration_cast( 20 | std::chrono::steady_clock::now().time_since_epoch()).count()) / 1e6; 21 | } 22 | 23 | } // namespace tlx 24 | 25 | /******************************************************************************/ 26 | -------------------------------------------------------------------------------- /tlx-plain/timestamp.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/timestamp.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_TIMESTAMP_HEADER 12 | #define TLX_TIMESTAMP_HEADER 13 | 14 | namespace tlx { 15 | 16 | //! Returns number of seconds since the epoch, currently microsecond resolution. 17 | double timestamp(); 18 | 19 | } // namespace tlx 20 | 21 | #endif // !TLX_TIMESTAMP_HEADER 22 | 23 | /******************************************************************************/ 24 | -------------------------------------------------------------------------------- /tlx-plain/unused.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/unused.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2015-2017 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_UNUSED_HEADER 12 | #define TLX_UNUSED_HEADER 13 | 14 | namespace tlx { 15 | 16 | /******************************************************************************/ 17 | // UNUSED(variables...) 18 | 19 | template 20 | void unused(Types&& ...) { } 21 | 22 | } // namespace tlx 23 | 24 | #endif // !TLX_UNUSED_HEADER 25 | 26 | /******************************************************************************/ 27 | -------------------------------------------------------------------------------- /tlx-plain/vector_free.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/vector_free.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2019 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_VECTOR_FREE_HEADER 12 | #define TLX_VECTOR_FREE_HEADER 13 | 14 | #include 15 | 16 | namespace tlx { 17 | 18 | //! Simple method to free the underlying memory in a vector, because .clear() 19 | //! need not do it. 20 | template 21 | void vector_free(std::vector& v) { 22 | std::vector().swap(v); 23 | } 24 | 25 | } // namespace tlx 26 | 27 | #endif // !TLX_VECTOR_FREE_HEADER 28 | 29 | /******************************************************************************/ 30 | -------------------------------------------------------------------------------- /tlx-plain/version.hpp: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * tlx/version.hpp 3 | * 4 | * Part of tlx - http://panthema.net/tlx 5 | * 6 | * Copyright (C) 2018 Timo Bingmann 7 | * 8 | * All rights reserved. Published under the Boost Software License, Version 1.0 9 | ******************************************************************************/ 10 | 11 | #ifndef TLX_VERSION_HEADER 12 | #define TLX_VERSION_HEADER 13 | 14 | namespace tlx { 15 | 16 | // versions: synchronize with CMakeLists.txt 17 | 18 | //! TLX_MAJOR_VERSION is the library interface major version number: currently 19 | //! zero. 20 | #define TLX_MAJOR_VERSION 0 21 | 22 | //! TLX_MINOR_VERSION is the minor version number: currently zero. 23 | #define TLX_MINOR_VERSION 5 24 | 25 | /*[[[perl 26 | return "keep" if $ENV{USER} ne "tb"; 27 | use POSIX qw(strftime); 28 | my $date = strftime("%Y%m%d", localtime); 29 | print "//! TLX_PATCH_VERSION is the date of the last commit.\n"; 30 | print "#define TLX_PATCH_VERSION $date\n"; 31 | ]]]*/ 32 | //! TLX_PATCH_VERSION is the date of the last commit. 33 | #define TLX_PATCH_VERSION 20210401 34 | // [[[end]]] 35 | 36 | //! TLX_VERSION is a combination of TLX_MAJOR_VERSION, TLX_MINOR_VERSION, and 37 | //! TLX_PATCH_VERSION 38 | #define TLX_VERSION \ 39 | ((TLX_MAJOR_VERSION * 100lu + TLX_MINOR_VERSION) * 100000000lu \ 40 | + TLX_PATCH_VERSION) 41 | 42 | } // namespace tlx 43 | 44 | #endif // !TLX_VERSION_HEADER 45 | 46 | /******************************************************************************/ 47 | -------------------------------------------------------------------------------- /ycsb_inputs/get-ycsb-inputs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | wget https://www.dropbox.com/scl/fi/zmdtssbe60w9frta0hqjr/unif_ycsb.tar.gz?rlkey=ayrj9ss3j7oyxvgnob18mwdxv&dl=0 4 | 5 | wget https://www.dropbox.com/scl/fi/rq3bcra7l4rdp2clibte9/zipf_ycsb.tar.gz?rlkey=cxbgoeqb12fnkzbxc47bh94zl&dl=0 6 | --------------------------------------------------------------------------------