├── .clang-format ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── cmake └── Findvrm_core.cmake ├── for_temp.hpp ├── include └── vrm │ ├── core.hpp │ └── core │ ├── args_utils.hpp │ ├── args_utils │ ├── args_slice.hpp │ ├── args_slice │ │ ├── args_slice.hpp │ │ └── args_slice.inl │ ├── args_slice_aliases.hpp │ ├── args_slice_aliases │ │ ├── args_slice_aliases.hpp │ │ └── args_slice_aliases.inl │ ├── call_utils.hpp │ ├── impl │ │ └── wrappers.hpp │ └── nth_arg.hpp │ ├── assert.hpp │ ├── assert │ ├── assert.hpp │ ├── assert_macros.hpp │ ├── assert_macros_interface.hpp │ └── impl │ │ ├── assert.cpp │ │ ├── assert.hpp │ │ ├── assert.inl │ │ ├── assert_macros_disabled.hpp │ │ └── assert_macros_enabled.hpp │ ├── casts.hpp │ ├── casts │ ├── arithmetic.hpp │ ├── enum.hpp │ ├── impl │ │ ├── arithmetic.hpp │ │ ├── arithmetic_conversions.hpp │ │ └── overflow_check.hpp │ ├── polymorphic.hpp │ ├── self.hpp │ ├── storage.hpp │ ├── string_to_num.hpp │ └── void_ptr.hpp │ ├── config.hpp │ ├── config │ ├── api.hpp │ ├── api │ │ └── api.hpp │ ├── attributes.hpp │ ├── attributes │ │ └── attributes.hpp │ ├── detection.hpp │ └── detection │ │ ├── arch.hpp │ │ ├── arch │ │ ├── arch.hpp │ │ └── impl │ │ │ ├── arch.hpp │ │ │ ├── arch.inl │ │ │ └── arch_macros.hpp │ │ ├── compiler.hpp │ │ ├── compiler │ │ ├── compiler.hpp │ │ └── impl │ │ │ ├── compiler.hpp │ │ │ ├── compiler.inl │ │ │ └── compiler_macros.hpp │ │ ├── debug.hpp │ │ ├── debug │ │ ├── debug.hpp │ │ └── impl │ │ │ ├── debug.hpp │ │ │ ├── debug.inl │ │ │ └── debug_macros.hpp │ │ ├── os.hpp │ │ ├── os │ │ ├── impl │ │ │ ├── os.hpp │ │ │ ├── os.inl │ │ │ └── os_macros.hpp │ │ └── os.hpp │ │ ├── rtti.hpp │ │ ├── rtti │ │ ├── impl │ │ │ ├── rtti.hpp │ │ │ ├── rtti.inl │ │ │ └── rtti_macros.hpp │ │ └── rtti.hpp │ │ ├── stdlib.hpp │ │ └── stdlib │ │ ├── impl │ │ ├── stdlib.hpp │ │ ├── stdlib.inl │ │ └── stdlib_macros.hpp │ │ └── stdlib.hpp │ ├── experimental.hpp │ ├── experimental │ ├── console.hpp │ ├── console │ │ ├── format_state.hpp │ │ ├── format_types.hpp │ │ └── unix │ │ │ └── codes.hpp │ ├── delegate.hpp │ ├── delegate │ │ ├── base_delegate.hpp │ │ ├── delegate.hpp │ │ ├── dynamic_delegate.hpp │ │ ├── impl │ │ │ ├── base_delegate.hpp │ │ │ ├── base_delegate.inl │ │ │ ├── delegate.hpp │ │ │ ├── delegate.inl │ │ │ ├── dynamic_delegate.hpp │ │ │ └── dynamic_delegate.inl │ │ └── signature_helper.hpp │ ├── handle.hpp │ ├── handle │ │ ├── impl │ │ │ ├── aliases.hpp │ │ │ ├── settings.hpp │ │ │ ├── storage.hpp │ │ │ └── storage │ │ │ │ ├── array.hpp │ │ │ │ ├── array │ │ │ │ ├── array.hpp │ │ │ │ └── array.inl │ │ │ │ ├── vector.hpp │ │ │ │ └── vector │ │ │ │ ├── vector.hpp │ │ │ │ └── vector.inl │ │ ├── manager.hpp │ │ ├── manager │ │ │ ├── manager.hpp │ │ │ └── manager.inl │ │ ├── strategy.hpp │ │ ├── strategy │ │ │ ├── custom.hpp │ │ │ └── storage.hpp │ │ └── types.hpp │ ├── handle2.hpp │ ├── handle2 │ │ ├── container.hpp │ │ ├── container │ │ │ ├── owning_packed_array.hpp │ │ │ ├── owning_packed_array │ │ │ │ ├── owning_packed_array.hpp │ │ │ │ └── owning_packed_array.inl │ │ │ └── vector.hpp │ │ ├── context.hpp │ │ ├── manager.hpp │ │ ├── manager │ │ │ ├── packed_array.hpp │ │ │ └── packed_array │ │ │ │ ├── packed_array.hpp │ │ │ │ └── packed_array.inl │ │ ├── settings.hpp │ │ └── settings │ │ │ ├── aliases.hpp │ │ │ └── settings.hpp │ ├── multi_vector.hpp │ ├── multi_vector │ │ └── multi_vector.hpp │ ├── resizable_buffer.hpp │ ├── resizable_buffer │ │ ├── impl │ │ │ ├── resizable_buffer.hpp │ │ │ └── resizable_buffer.inl │ │ ├── multi_resizable_buffer.hpp │ │ └── resizable_buffer.hpp │ ├── resource.hpp │ ├── resource │ │ ├── access.hpp │ │ ├── base.hpp │ │ ├── base │ │ │ ├── base.hpp │ │ │ └── base.inl │ │ ├── behavior.hpp │ │ ├── behavior │ │ │ └── behavior_traits.hpp │ │ ├── fwd.hpp │ │ ├── fwd │ │ │ └── fwd.hpp │ │ ├── interface.hpp │ │ ├── shared.hpp │ │ ├── shared │ │ │ ├── metadata.hpp │ │ │ ├── metadata │ │ │ │ ├── metadata.hpp │ │ │ │ └── metadata.inl │ │ │ ├── policies.hpp │ │ │ ├── ref_counter.hpp │ │ │ ├── ref_counter │ │ │ │ ├── ref_counter.hpp │ │ │ │ └── ref_counter.inl │ │ │ ├── shared.hpp │ │ │ └── shared.inl │ │ ├── unique.hpp │ │ ├── unique │ │ │ ├── unique.hpp │ │ │ └── unique.inl │ │ ├── utils.hpp │ │ ├── utils │ │ │ └── make_resource.hpp │ │ ├── weak.hpp │ │ └── weak │ │ │ ├── weak.hpp │ │ │ └── weak.inl │ ├── sparse_set.hpp │ └── sparse_set │ │ ├── base_sparse_set.hpp │ │ ├── impl │ │ ├── base_sparse_set.hpp │ │ ├── base_sparse_set.inl │ │ ├── settings.hpp │ │ ├── storage.hpp │ │ └── storage │ │ │ ├── dynamic_vector.hpp │ │ │ ├── fixed_array.hpp │ │ │ ├── fixed_vector.hpp │ │ │ └── shared.hpp │ │ └── sparse_set.hpp │ ├── for_args.hpp │ ├── for_args │ ├── for_args.hpp │ ├── for_args_complete.hpp │ └── for_args_data.hpp │ ├── fwd_capture.hpp │ ├── fwd_capture │ ├── apply.hpp │ ├── pack.hpp │ └── single.hpp │ ├── is_valid.hpp │ ├── is_valid │ └── is_valid.hpp │ ├── literals.hpp │ ├── literals │ └── llong_constant.hpp │ ├── ostream_utils.hpp │ ├── ostream_utils │ ├── ignore_manipulator.hpp │ └── impl │ │ ├── ignore_manipulator.hpp │ │ └── ignore_manipulator.inl │ ├── overload.hpp │ ├── overload │ └── overload_set.hpp │ ├── perfect_wrapper.hpp │ ├── perfect_wrapper │ └── perfect_wrapper.hpp │ ├── strong_typedef.hpp │ ├── strong_typedef │ ├── is_strong_typedef.hpp │ ├── strong_typedef.hpp │ └── underlying.hpp │ ├── tuple_utils.hpp │ ├── tuple_utils │ ├── apply.hpp │ ├── for.hpp │ ├── impl │ │ └── tuple_transposer.hpp │ ├── index_of.hpp │ ├── ref_tuple.hpp │ ├── repeated_tuple.hpp │ └── transpose.hpp │ ├── type_aliases.hpp │ ├── type_aliases │ ├── integral_constant.hpp │ └── numerical.hpp │ ├── type_traits.hpp │ ├── type_traits │ ├── common.hpp │ ├── copy_if_rvalue.hpp │ ├── detection.hpp │ ├── forward_like.hpp │ ├── is_specialization_of.hpp │ ├── nonesuch.hpp │ ├── qualifiers.hpp │ ├── referenceness.hpp │ ├── remove_rvalue_reference.hpp │ ├── streamable.hpp │ └── tuple.hpp │ ├── utility_macros.hpp │ ├── utility_macros │ ├── fwd.hpp │ ├── likely_unlikely.hpp │ ├── returns.hpp │ └── unreachable.hpp │ ├── value_wrapper.hpp │ ├── value_wrapper │ └── value_wrapper.hpp │ ├── variadic_min_max.hpp │ ├── variadic_min_max │ ├── variadic_max.hpp │ └── variadic_min.hpp │ ├── y_combinator.hpp │ └── y_combinator │ └── y_combinator.hpp ├── init-repository.sh └── test ├── CMakeLists.txt ├── basic └── should_pass.cpp ├── core ├── args_utils │ ├── args_slice_aliases.cpp │ ├── args_utils.cpp │ └── call_utils.cpp ├── assert │ ├── assert_disabled.cpp │ ├── assert_enabled.cpp │ └── constexpr_assert.cpp ├── casts │ ├── arithmetic.cpp │ ├── enum.cpp │ ├── polymorphic.cpp │ ├── self.cpp │ ├── storage.cpp │ └── string_to_num.cpp ├── config │ └── detection │ │ ├── arch.cpp │ │ ├── compiler.cpp │ │ ├── debug.cpp │ │ ├── os.cpp │ │ ├── rtti.cpp │ │ └── stdlib.cpp ├── experimental │ ├── delegate │ │ ├── delegate.cpp │ │ └── dynamic_delegate.cpp │ ├── handle │ │ └── handle.cpp │ ├── handle2 │ │ ├── container_array.cpp │ │ ├── context.cpp │ │ └── settings.cpp │ ├── multi_vector │ │ └── multi_vector.cpp │ ├── resizable_buffer │ │ ├── multi_resizable_buffer.cpp │ │ └── resizable_buffer.cpp │ ├── resource │ │ ├── shared.cpp │ │ ├── unique.cpp │ │ └── weak.cpp │ └── sparse_set │ │ ├── dynamic_vector.cpp │ │ ├── fixed_array.cpp │ │ └── fixed_vector.cpp ├── for_args │ ├── for_args.cpp │ ├── for_args_data.cpp │ └── static_for_args.cpp ├── is_valid │ └── is_valid.cpp ├── ostream_utils │ └── ignore_manipulator.cpp ├── overload │ └── overload.cpp ├── perfect_wrapper │ └── perfect_wrapper.cpp ├── strong_typedef │ └── strong_typedef.cpp ├── tuple_utils │ ├── apply_interleaved.cpp │ ├── for.cpp │ ├── index_of.cpp │ ├── ref_tuple.cpp │ ├── repeated_tuple.cpp │ └── transpose.cpp ├── type_traits │ ├── copy_if_rvalue.cpp │ ├── forward_like.cpp │ ├── is_specialization_of.cpp │ ├── qualifiers.cpp │ ├── referenceness.cpp │ ├── remove_rvalue_reference.cpp │ ├── streamable.cpp │ └── udl.cpp ├── utility_macros │ ├── fwd.cpp │ ├── likely_unlikely.cpp │ └── unreachable.cpp └── value_wrapper │ └── value_wrapper.cpp └── utils ├── check_operations.cpp ├── test_res_utils.hpp ├── test_utils.hpp └── tracked_object.hpp /.clang-format: -------------------------------------------------------------------------------- 1 | AccessModifierOffset: -4 2 | AlignAfterOpenBracket: false 3 | AlignEscapedNewlinesLeft: true 4 | AlignOperands: true 5 | AlignTrailingComments: true 6 | AllowAllParametersOfDeclarationOnNextLine: true 7 | AllowShortCaseLabelsOnASingleLine: true 8 | AllowShortFunctionsOnASingleLine: false 9 | AllowShortIfStatementsOnASingleLine: true 10 | AllowShortLoopsOnASingleLine: true 11 | AlwaysBreakBeforeMultilineStrings: true 12 | AlwaysBreakTemplateDeclarations: true 13 | BasedOnStyle: LLVM 14 | BreakBeforeBraces: Allman 15 | ColumnLimit: 80 16 | ConstructorInitializerIndentWidth: 4 17 | ContinuationIndentWidth: 4 18 | Cpp11BracedListStyle: true 19 | IndentCaseLabels: true 20 | IndentWidth: 4 21 | IndentWrappedFunctionNames: false 22 | MaxEmptyLinesToKeep: 3 23 | NamespaceIndentation: All 24 | PenaltyBreakBeforeFirstCallParameter: 1000000000 25 | PointerAlignment: "Left" 26 | PointerBindsToType: true 27 | SpaceAfterCStyleCast: false 28 | SpaceBeforeAssignmentOperators: true 29 | SpaceBeforeParens: "Never" 30 | SpaceInEmptyParentheses: false 31 | SpacesInAngles: false 32 | SpacesInParentheses: false 33 | SpacesInSquareBrackets: false 34 | Standard: "Cpp11" 35 | TabWidth: 4 36 | UseTab: "Never" 37 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "extlibs/vrm_pp"] 2 | path = extlibs/vrm_pp 3 | url = https://github.com/SuperV1234/vrm_pp.git 4 | [submodule "extlibs/vrm_cmake"] 5 | path = extlibs/vrm_cmake 6 | url = https://github.com/SuperV1234/vrm_cmake.git 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | dist: xenial 4 | os: linux 5 | sudo: false 6 | 7 | matrix: 8 | fast_finish: true 9 | include: 10 | - env: MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && GENERATOR='Unix Makefiles' && CONFIG=Debug" 11 | addons: { apt: { packages: ["g++-7"], sources: ["ubuntu-toolchain-r-test"] } } 12 | 13 | - env: MATRIX_EVAL="CC=gcc-8 && CXX=g++-8 && GENERATOR='Unix Makefiles' && CONFIG=Debug" 14 | addons: { apt: { packages: ["g++-8"], sources: ["ubuntu-toolchain-r-test"] } } 15 | 16 | - env: MATRIX_EVAL="CC=clang-7 && CXX=clang++-7 && GENERATOR='Unix Makefiles' && CONFIG=Debug" 17 | addons: { apt: { packages: ["clang-7", "libc++-7-dev", "libc++abi-7-dev"], sources: ["llvm-toolchain-xenial-7"] } } 18 | 19 | - env: MATRIX_EVAL="CC=clang-8 && CXX=clang++-8 && GENERATOR='Unix Makefiles' && CONFIG=Debug" 20 | addons: { apt: { packages: ["clang-8", "libc++-8-dev", "libc++abi-8-dev"], sources: ["llvm-toolchain-xenial-8"] } } 21 | 22 | - env: MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && GENERATOR='Unix Makefiles' && CONFIG=Release" 23 | addons: { apt: { packages: ["g++-7"], sources: ["ubuntu-toolchain-r-test"] } } 24 | 25 | - env: MATRIX_EVAL="CC=gcc-8 && CXX=g++-8 && GENERATOR='Unix Makefiles' && CONFIG=Release" 26 | addons: { apt: { packages: ["g++-8"], sources: ["ubuntu-toolchain-r-test"] } } 27 | 28 | - env: MATRIX_EVAL="CC=clang-7 && CXX=clang++-7 && GENERATOR='Unix Makefiles' && CONFIG=Release" 29 | addons: { apt: { packages: ["clang-7", "libc++-7-dev", "libc++abi-7-dev"], sources: ["llvm-toolchain-xenial-7"] } } 30 | 31 | - env: MATRIX_EVAL="CC=clang-8 && CXX=clang++-8 && GENERATOR='Unix Makefiles' && CONFIG=Release" 32 | addons: { apt: { packages: ["clang-8", "libc++-8-dev", "libc++abi-8-dev"], sources: ["llvm-toolchain-xenial-8"] } } 33 | 34 | install: 35 | - eval "${MATRIX_EVAL}" 36 | - $CC --version 37 | - $CXX --version 38 | - cmake --version 39 | 40 | before_script: 41 | - eval "${MATRIX_EVAL}" 42 | - mkdir build 43 | - cd build 44 | - export VERBOSE=1 45 | - cmake -G"${GENERATOR}" -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_C_COMPILER=${CC} -DCMAKE_BUILD_TYPE=${CONFIG} .. 46 | 47 | script: 48 | - export VERBOSE=1 49 | - cmake --build . 50 | - cmake --build . --config ${CONFIG} --target check 51 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | # Include `vrm_cmake`. 4 | list(APPEND CMAKE_MODULE_PATH 5 | "${CMAKE_SOURCE_DIR}/../vrm_cmake/cmake/" 6 | "${CMAKE_SOURCE_DIR}/extlibs/vrm_cmake/cmake/") 7 | 8 | include(vrm_cmake) 9 | 10 | # Basic project setup. 11 | vrm_cmake_init_project(vrm_core) 12 | vrm_cmake_set_cxxstd(17) 13 | vrm_cmake_find_extlib(vrm_pp) 14 | 15 | # Alias the include directory. 16 | set(VRM_CORE_INC_DIR "${VRM_CORE_SOURCE_DIR}/include/") 17 | include_directories("${VRM_CORE_INC_DIR}") 18 | 19 | # Other compiler flags. 20 | vrm_cmake_add_common_compiler_flags() 21 | 22 | # The `check` target runs all tests and examples. 23 | vrm_check_target() 24 | 25 | # Setup subdirectories. 26 | add_subdirectory(test) 27 | 28 | # Create header-only install target (automatically glob) 29 | vrm_cmake_header_only_install_glob("${VRM_CORE_INC_DIR}" "include") 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vrm_core 2 | 3 | > **General-purpose C++17 utility library.** 4 | 5 | [![build][badge.build]][build] 6 | [![stability][badge.stability]][stability] 7 | [![license][badge.license]][license] 8 | [![gratipay][badge.gratipay]][gratipay] 9 | ![badge.cpp](https://img.shields.io/badge/c++-14-ff69b4.svg?style=flat-square) 10 | [![on-wandbox][badge.on-wandbox]][on-wandbox] 11 | [![on-godbolt][badge.on-godbolt]][on-godbolt] 12 | 13 | [badge.build]: https://img.shields.io/travis/SuperV1234/vrm_core.svg?style=flat-square 14 | [badge.stability]: https://img.shields.io/badge/stability-unstable-yellow.svg?style=flat-square 15 | [badge.license]: http://img.shields.io/badge/license-afl%203.0-blue.svg?style=flat-square 16 | [badge.gratipay]: https://img.shields.io/gratipay/user/SuperV1234.svg?style=flat-square 17 | [badge.on-wandbox]: https://img.shields.io/badge/on-wandbox-376666.svg?style=flat-square 18 | [badge.on-godbolt]: https://img.shields.io/badge/on-godbolt-376666.svg?style=flat-square 19 | 20 | [build]: https://travis-ci.org/SuperV1234/vrm_core 21 | [stability]: http://github.com/badges/stability-badges 22 | [license]: https://github.com/SuperV1234/vrm_core/blob/master/LICENSE 23 | [gratipay]: https://gratipay.com/~SuperV1234/ 24 | [on-wandbox]: https://wandbox.org/permlink/DfXLlf7bHm2rDfFj 25 | [on-godbolt]: https://godbolt.org/g/9t8gN5 26 | 27 | 28 | 29 | ## Intended usage (quick start) 30 | 31 | 1. Add this repository, [SuperV1234/vrm_cmake](https://github.com/SuperV1234/vrm_cmake) and [SuperV1234/vrm_pp](https://github.com/SuperV1234/vrm_pp) as submodules of your project, as subfolders in `your_project/extlibs/`: 32 | 33 | ```bash 34 | git submodule add https://github.com/SuperV1234/vrm_cmake.git your_project/extlibs/vrm_cmake 35 | git submodule add https://github.com/SuperV1234/vrm_pp.git your_project/extlibs/vrm_pp 36 | git submodule add https://github.com/SuperV1234/vrm_core.git your_project/extlibs/vrm_core 37 | ``` 38 | 39 | 2. Include `vrm_cmake` in your project's `CMakeLists.txt` and look for the `vrm_pp` and `vrm_core` extlibs: 40 | 41 | ```cmake 42 | # Include `vrm_cmake`: 43 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/extlibs/vrm_cmake/cmake/") 44 | include(vrm_cmake) 45 | 46 | # Find `vrm_pp` and `vrm_core`: 47 | vrm_cmake_find_extlib(vrm_pp) 48 | vrm_cmake_find_extlib(vrm_core) 49 | ``` 50 | 51 | *(Altenatively, only add `vrm_core` and `vrm_cmake` as submodules, and recursively pull submodules to let `vrm_core` find `vrm_pp`.)* 52 | -------------------------------------------------------------------------------- /cmake/Findvrm_core.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015-2016 Vittorio Romeo 2 | # License: Academic Free License ("AFL") v. 3.0 3 | # AFL License page: http://opensource.org/licenses/AFL-3.0 4 | # http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | # Adapted from Louise Dionne's FindHana.cmake file 7 | 8 | # Copyright Louis Dionne 2015 9 | # Distributed under the Boost Software License, Version 1.0. 10 | # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 11 | 12 | find_path( 13 | VRM_CORE_INCLUDE_DIR 14 | 15 | NAMES vrm/core.hpp 16 | DOC "Include directory for the vrm_core library" 17 | 18 | PATH_SUFFIXES include/ 19 | 20 | PATHS 21 | "${PROJECT_SOURCE_DIR}/../vrm_core/" 22 | ${VRM_CORE_ROOT} 23 | $ENV{VRM_CORE_ROOT} 24 | /usr/local/ 25 | /usr/ 26 | /sw/ 27 | /opt/local/ 28 | /opt/csw/ 29 | /opt/ 30 | "${PROJECT_SOURCE_DIR}/extlibs/vrm_core/" 31 | "${CMAKE_CURRENT_LIST_DIR}/../../" 32 | "${CMAKE_CURRENT_LIST_DIR}/../" 33 | 34 | NO_DEFAULT_PATH 35 | ) 36 | 37 | if (NOT EXISTS "${VRM_CORE_INCLUDE_DIR}" AND DEFINED VRM_CORE_CLONE_DIR) 38 | set(_build_dir "${CMAKE_CURRENT_BINARY_DIR}/vrm_core") 39 | 40 | if (DEFINED VRM_CORE_ENABLE_TESTS) 41 | set(_test_cmd ${CMAKE_COMMAND} --build ${_build_dir} --target check) 42 | else() 43 | set(_test_cmd "") 44 | endif() 45 | 46 | include(ExternalProject) 47 | ExternalProject_Add(vrm_core 48 | PREFIX ${_build_dir} 49 | STAMP_DIR ${_build_dir}/_stamps 50 | TMP_DIR ${_build_dir}/_tmp 51 | 52 | # Since we don't have any files to download, we set the DOWNLOAD_DIR 53 | # to TMP_DIR to avoid creating a useless empty directory. 54 | DOWNLOAD_DIR ${_build_dir}/_tmp 55 | 56 | # Download step 57 | GIT_REPOSITORY https://github.com/SuperV1234/vrm_core 58 | GIT_TAG master 59 | TIMEOUT 20 60 | 61 | # Configure step 62 | SOURCE_DIR "${VRM_CORE_CLONE_DIR}" 63 | CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} 64 | 65 | BINARY_DIR "${_build_dir}" 66 | BUILD_COMMAND "" 67 | 68 | # Install step (nothing to be done) 69 | INSTALL_COMMAND "" 70 | 71 | # Test step 72 | TEST_COMMAND ${_test_cmd} 73 | ) 74 | 75 | set(VRM_CORE_INCLUDE_DIR "${VRM_CORE_CLONE_DIR}/include") 76 | endif() 77 | 78 | include(FindPackageHandleStandardArgs) 79 | find_package_handle_standard_args(VRM_CORE DEFAULT_MSG VRM_CORE_INCLUDE_DIR) 80 | -------------------------------------------------------------------------------- /include/vrm/core.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | // API configuration and name-related macros. 9 | // Compiler/OS/target detection macros/utilities. 10 | #include 11 | 12 | // Macros that do not strongly depend on other vrm_core modules. 13 | #include 14 | 15 | // Pretty assertions. 16 | #include 17 | 18 | // Type-traits. 19 | #include 20 | 21 | // Safer and stricter casts. 22 | #include 23 | 24 | // ForArgs snippet. 25 | #include 26 | 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 | -------------------------------------------------------------------------------- /include/vrm/core/args_utils.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /include/vrm/core/args_utils/args_slice.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/args_utils/args_slice/args_slice.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace vrm::core 13 | { 14 | namespace impl 15 | { 16 | /// @brief Returns a `ref_tuple` from a variadic pack. 17 | /// @details Given an index sequence, a starting index and a variadic 18 | /// amount of arguments, returns a `ref_tuple` of the arguments with 19 | /// matching indices. The `ref_tuple` avoids copies: lvalues are taken 20 | /// as reference, rvalues are moved in the resulting tuple. 21 | template 22 | constexpr auto build_args_slice( 23 | std::index_sequence, Ts&&... xs) noexcept; 24 | } // namespace impl 25 | 26 | /// @brief Returns a `[TIBegin, TIEnd)` slice of the variadic arguments. 27 | /// @details A `ref_tuple` is used to store the arguments. 28 | template 29 | constexpr auto args_slice(Ts&&... xs) noexcept; 30 | } // namespace vrm::core 31 | -------------------------------------------------------------------------------- /include/vrm/core/args_utils/args_slice/args_slice.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace vrm::core 15 | { 16 | namespace impl 17 | { 18 | template 19 | VRM_CORE_ALWAYS_INLINE constexpr auto build_args_slice( 20 | std::index_sequence, Ts&&... xs) noexcept 21 | { 22 | return make_ref_tuple(nth_arg(FWD(xs)...)...); 23 | } 24 | } // namespace impl 25 | 26 | template 27 | VRM_CORE_ALWAYS_INLINE constexpr auto args_slice(Ts&&... xs) noexcept 28 | { 29 | // Assert range validity. 30 | static_assert(TIEnd >= TIBegin); 31 | static_assert(sizeof...(xs) >= TIEnd - TIBegin); 32 | 33 | return impl::build_args_slice( 34 | std::make_index_sequence(), FWD(xs)...); 35 | } 36 | } // namespace vrm::core 37 | -------------------------------------------------------------------------------- /include/vrm/core/args_utils/args_slice_aliases.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/args_utils/args_slice_aliases/args_slice_aliases.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace vrm::core 12 | { 13 | /// @brief Returns the slice `[..., TN)`. 14 | template 15 | constexpr auto first_n_args(Ts&&... xs) noexcept; 16 | 17 | /// @brief Returns the slice `(TN, ...]`. 18 | template 19 | constexpr auto last_n_args(Ts&&... xs) noexcept; 20 | 21 | /// @brief Returns the slice `[TN, ...]`. 22 | /// /// @details Includes `TN`. 23 | template 24 | constexpr auto all_args_from(Ts&&... xs) noexcept; 25 | 26 | /// @brief Returns the slice `(TN, ...]`. 27 | /// @details Excludes `TN`. 28 | template 29 | constexpr auto all_args_after(Ts&&... xs) noexcept; 30 | 31 | /// @brief Returns the slice `[..., TN]`. 32 | /// @details Includes `TN`. 33 | template 34 | constexpr auto all_args_until(Ts&&... xs) noexcept; 35 | 36 | /// @brief Returns the slice `[..., TN)`. 37 | /// @details Excludes `TN`. 38 | template 39 | constexpr auto all_args_before(Ts&&... xs) noexcept; 40 | 41 | /// @brief Returns the first argument of a variadic pack. 42 | template 43 | constexpr decltype(auto) first_arg(Ts&&... xs) noexcept; 44 | 45 | /// @brief Returns the last argument of a variadic pack. 46 | template 47 | constexpr decltype(auto) last_arg(Ts&&... xs) noexcept; 48 | } // namespace vrm::core 49 | -------------------------------------------------------------------------------- /include/vrm/core/args_utils/args_slice_aliases/args_slice_aliases.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace vrm::core 16 | { 17 | template 18 | VRM_CORE_ALWAYS_INLINE constexpr auto first_n_args(Ts&&... xs) noexcept 19 | { 20 | return args_slice<0, TN>(FWD(xs)...); 21 | } 22 | 23 | template 24 | VRM_CORE_ALWAYS_INLINE constexpr auto last_n_args(Ts&&... xs) noexcept 25 | { 26 | constexpr auto begin_idx(sizeof...(xs) - TN); 27 | return args_slice(FWD(xs)...); 28 | } 29 | 30 | template 31 | VRM_CORE_ALWAYS_INLINE constexpr auto all_args_from(Ts&&... xs) noexcept 32 | { 33 | return args_slice(FWD(xs)...); 34 | } 35 | 36 | template 37 | VRM_CORE_ALWAYS_INLINE constexpr auto all_args_after(Ts&&... xs) noexcept 38 | { 39 | return all_args_from(FWD(xs)...); 40 | } 41 | 42 | template 43 | VRM_CORE_ALWAYS_INLINE constexpr auto all_args_until(Ts&&... xs) noexcept 44 | { 45 | return first_n_args(FWD(xs)...); 46 | } 47 | 48 | template 49 | VRM_CORE_ALWAYS_INLINE constexpr auto all_args_before(Ts&&... xs) noexcept 50 | { 51 | return first_n_args(FWD(xs)...); 52 | } 53 | 54 | template 55 | VRM_CORE_ALWAYS_INLINE constexpr decltype(auto) first_arg( 56 | Ts&&... xs) noexcept 57 | { 58 | return copy_if_rvalue(std::get<0>(first_n_args<1>(FWD(xs)...))); 59 | } 60 | 61 | template 62 | VRM_CORE_ALWAYS_INLINE constexpr decltype(auto) last_arg( 63 | Ts&&... xs) noexcept 64 | { 65 | return copy_if_rvalue(std::get<0>(last_n_args<1>(FWD(xs)...))); 66 | } 67 | } // namespace vrm::core 68 | -------------------------------------------------------------------------------- /include/vrm/core/args_utils/nth_arg.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace vrm::core 16 | { 17 | /// @brief Returns the `TN`-th argument of a variadic argument pack, casting 18 | /// it to the type it would have when wrapped into a `ref_tuple`. 19 | /// @details The casted type is a reference if the argument is an lvalue, a 20 | /// value (moved) if the argument is an rvalue. 21 | template 22 | VRM_CORE_ALWAYS_INLINE constexpr decltype(auto) nth_arg(Ts&&... xs) // . 23 | noexcept(noexcept(std::get(make_ref_tuple(FWD(xs)...)))) 24 | { 25 | // Assert index validity. 26 | static_assert(sizeof...(xs) > TN); 27 | 28 | // Return the `TN`-th element of, copying it if it's an rvalue. 29 | return copy_if_rvalue(std::get(make_ref_tuple(FWD(xs)...))); 30 | } 31 | } // namespace vrm::core 32 | -------------------------------------------------------------------------------- /include/vrm/core/assert.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /include/vrm/core/assert/assert.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #if !VRM_CORE_IMPL_ASSERT_DISABLED 13 | 14 | #include 15 | #include 16 | 17 | #if defined(VRM_CORE_INLINE_LIBRARY) 18 | #include 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /include/vrm/core/assert/assert_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | // `VRM_CORE_ASSERT_FORCE_OFF` and `VRM_CORE_ASSERT_FORCE_ON` macros force 12 | // enabling/disabling of assertions. 13 | // `VRM_CORE_ASSERT_FORCE_ON` has priority over `VRM_CORE_ASSERT_FORCE_OFF`. 14 | 15 | #if(defined(VRM_CORE_ASSERT_FORCE_OFF) || !defined(VRM_CORE_DEBUG)) && \ 16 | !defined(VRM_CORE_ASSERT_FORCE_ON) 17 | #define VRM_CORE_IMPL_ASSERT_DISABLED 1 18 | #else 19 | #define VRM_CORE_IMPL_ASSERT_DISABLED 0 20 | #endif 21 | 22 | #if VRM_CORE_IMPL_ASSERT_DISABLED 23 | #include 24 | #else 25 | #include 26 | #endif 27 | -------------------------------------------------------------------------------- /include/vrm/core/assert/assert_macros_interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #define VRM_CORE_ASSERT_OP_MSG(lhs, op, rhs, msg) \ 11 | VRM_CORE_IMPL_ASSERT(lhs, op, rhs, msg) 12 | 13 | #define VRM_CORE_ASSERT_OP(lhs, op, rhs) \ 14 | VRM_CORE_ASSERT_OP_MSG(lhs, op, rhs, "") 15 | 16 | #define VRM_CORE_ASSERT_MSG(expr, msg) \ 17 | VRM_CORE_ASSERT_OP_MSG((expr), ==, true, msg) 18 | 19 | #define VRM_CORE_ASSERT(expr) VRM_CORE_ASSERT_MSG(expr, "") 20 | 21 | 22 | 23 | // `constexpr`-friendly assertions. 24 | #define VRM_CORE_CONSTEXPR_ASSERT_OP_MSG(lhs, op, rhs, msg) \ 25 | VRM_CORE_IMPL_CONSTEXPR_ASSERT(lhs, op, rhs, msg) 26 | 27 | #define VRM_CORE_CONSTEXPR_ASSERT_OP(lhs, op, rhs) \ 28 | VRM_CORE_CONSTEXPR_ASSERT_OP_MSG(lhs, op, rhs, "") 29 | 30 | #define VRM_CORE_CONSTEXPR_ASSERT_MSG(expr, msg) \ 31 | VRM_CORE_CONSTEXPR_ASSERT_OP_MSG((expr), ==, true, msg) 32 | 33 | #define VRM_CORE_CONSTEXPR_ASSERT(expr) VRM_CORE_CONSTEXPR_ASSERT_MSG(expr, "") 34 | -------------------------------------------------------------------------------- /include/vrm/core/assert/impl/assert.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #include 7 | #include 8 | 9 | #if !VRM_CORE_IMPL_ASSERT_DISABLED 10 | 11 | #include 12 | 13 | namespace vrm::core::impl::assert 14 | { 15 | [[nodiscard]] VRM_CORE_FN_API state& get_state() noexcept 16 | { 17 | thread_local state result; 18 | return result; 19 | } 20 | } // namespace vrm::core::impl::assert 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/vrm/core/assert/impl/assert.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #if !VRM_CORE_IMPL_ASSERT_DISABLED 13 | 14 | namespace vrm::core::impl::assert 15 | { 16 | /// @brief Assertion management state. 17 | /// @details Controls whether or not future assertion will be 18 | /// skipped. 19 | struct state final 20 | { 21 | bool _skip{false}; 22 | }; 23 | 24 | /// @brief Returns a reference to the thread-local assertion state. 25 | [[nodiscard]] state& get_state() noexcept; 26 | 27 | /// @brief Fires an assertion failure. 28 | template 29 | void fire(const char* code, const char* line, const char* file, 30 | const char* lhs, const char* op, const char* rhs, const char* msg, 31 | const TLhs& lhs_res, const TRhs& rhs_res); 32 | } // namespace vrm::core::impl::assert 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/vrm/core/assert/impl/assert.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #include 7 | 8 | #if !VRM_CORE_IMPL_ASSERT_DISABLED 9 | 10 | // TODO: optimize includes by using `` 11 | #include 12 | #include 13 | #include 14 | 15 | namespace vrm::core::impl::assert 16 | { 17 | template 18 | void fire(const char* code, const char* line, const char* file, 19 | const char* lhs, const char* op, const char* rhs, const char* msg, 20 | const TLhs& lhs_res, const TRhs& rhs_res) 21 | { 22 | const auto c_str_empty = [](auto c_str) { return c_str && !c_str[0]; }; 23 | 24 | std::cout << "ASSERTION FAILED\n"; 25 | 26 | if(!c_str_empty(msg)) 27 | { 28 | std::cout << "Message: " << msg << '\n'; 29 | } 30 | 31 | std::cout << '\n'; 32 | 33 | std::cout << "[file: " << file << "]\n" 34 | << "[line: " << line << "]\n\n" 35 | << code << "\n\n"; 36 | 37 | std::cout << lhs << " = " << lhs_res << '\n' 38 | << rhs << " = " << rhs_res << "\n\n" 39 | << "(" << lhs_res << " " << op << " " << rhs_res 40 | << ") == false\n\n"; 41 | 42 | if(get_state()._skip) 43 | { 44 | std::cout << "Skipping assertion..." << std::endl; 45 | return; 46 | } 47 | 48 | std::cout << "0) Skip this assertion.\n" 49 | << "1) Skip all assertions.\n" 50 | << "_) Terminate the program." << std::endl; 51 | 52 | std::string input; 53 | std::cin >> input; 54 | 55 | if(input == "0") 56 | { 57 | return; 58 | } 59 | 60 | if(input == "1") 61 | { 62 | get_state()._skip = true; 63 | return; 64 | } 65 | 66 | std::terminate(); 67 | } 68 | } // namespace vrm::core::impl::assert 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /include/vrm/core/assert/impl/assert_macros_disabled.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | /// @macro Assertion in release mode: this macro does nothing. 9 | #define VRM_CORE_IMPL_ASSERT(...) (void)0 10 | 11 | /// @macro Assertion in release mode: this macro does nothing. 12 | #define VRM_CORE_IMPL_CONSTEXPR_ASSERT(...) (void)0 13 | -------------------------------------------------------------------------------- /include/vrm/core/casts.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | -------------------------------------------------------------------------------- /include/vrm/core/casts/arithmetic.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /include/vrm/core/casts/enum.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace vrm::core 16 | { 17 | /// @brief Converts an enum to a type convertible to its underlying type. 18 | template 19 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr TOut from_enum( 20 | const TIn& x) noexcept 21 | { 22 | static_assert(std::is_enum_v); 23 | static_assert(underlying_convertible_to{}); 24 | 25 | return to_num(static_cast>(x)); 26 | } 27 | 28 | /// @brief Converts an enum to its underlying type. 29 | template 30 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr auto from_enum( 31 | const TIn& x) noexcept 32 | { 33 | return from_enum, TIn>(x); 34 | } 35 | 36 | /// @brief Converts a number to an enum. 37 | template 38 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr auto to_enum( 39 | const TIn& x) noexcept 40 | ->std::enable_if_t{}, TOut> 41 | { 42 | return static_cast(to_num>(x)); 43 | } 44 | 45 | /// @brief Converts an enum to another enum. 46 | /// @details The underlying types must be convertible between each other. 47 | template 48 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr auto to_enum( 49 | const TIn& x) noexcept 50 | ->std::enable_if_t{}, TOut> 51 | { 52 | static_assert(are_underlying_types_convertible{}); 53 | 54 | return to_enum(from_enum(x)); 55 | } 56 | } // namespace vrm::core 57 | -------------------------------------------------------------------------------- /include/vrm/core/casts/impl/arithmetic.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | namespace vrm::core 16 | { 17 | template 18 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr TOut to_num( 19 | const TIn& x) noexcept 20 | { 21 | static_assert( // . 22 | std::is_arithmetic_v>, 23 | "`TOut` output type must be an arithmetic type."); 24 | 25 | static_assert( // . 26 | std::is_arithmetic_v>, 27 | "`TIn` input type must be an arithmetic type."); 28 | 29 | VRM_CORE_CONSTEXPR_ASSERT((!impl::will_overflow(x))); 30 | 31 | return static_cast(x); 32 | } 33 | } // namespace vrm::core 34 | -------------------------------------------------------------------------------- /include/vrm/core/casts/self.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | namespace vrm::core 15 | { 16 | template 17 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr TOut self_cast( 18 | TIn&& x) noexcept 19 | { 20 | using out_decay = std::decay_t; 21 | using in_decay = std::decay_t; 22 | 23 | static_assert(std::is_same_v); 24 | 25 | return static_cast(FWD(x)); 26 | } 27 | } // namespace vrm::core 28 | -------------------------------------------------------------------------------- /include/vrm/core/casts/storage.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | namespace vrm::core 17 | { 18 | /// @brief Wrapper around `reinterpret_cast`, intended for use with aligned 19 | /// storages. Returns a pointer. 20 | template 21 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr auto storage_cast( 22 | TStorage* storage) noexcept 23 | { 24 | static_assert( // . 25 | sizeof(typename TStorage::type) >= sizeof(T), // . 26 | "`TStorage` is not big enough for `T`."); 27 | 28 | static_assert( // . 29 | alignof(typename TStorage::type) >= alignof(T), // . 30 | "`TStorage` is not properly aligned for `T`."); 31 | 32 | VRM_CORE_ASSERT_OP(storage, !=, nullptr); 33 | 34 | using return_type = copy_cv_qualifiers; 35 | return reinterpret_cast(storage); 36 | } 37 | 38 | /// @brief Wrapper around `reinterpret_cast`, intended for use with 39 | /// aligned storages. Returns a reference. 40 | template 41 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr decltype(auto) storage_cast( 42 | TStorage&& storage) noexcept 43 | { 44 | return forward_like(*storage_cast(&storage)); 45 | } 46 | } // namespace vrm::core 47 | -------------------------------------------------------------------------------- /include/vrm/core/casts/string_to_num.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace vrm::core 15 | { 16 | /// @brief Converts a string to `int`. 17 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE auto str_to_int(const char* x) 18 | { 19 | char* end; 20 | return to_int(std::strtol(x, &end, 10)); 21 | } 22 | 23 | /// @brief Converts a string to `float`. 24 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE auto str_to_float(const char* x) 25 | { 26 | char* end; 27 | return to_float(std::strtof(x, &end)); 28 | } 29 | 30 | /// @brief Converts a string to `double`. 31 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE auto str_to_double(const char* x) 32 | { 33 | char* end; 34 | return to_double(std::strtod(x, &end)); 35 | } 36 | 37 | /// @brief Converts a string to `sz_t`. 38 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE auto str_to_size_t(const char* x) 39 | { 40 | char* end; 41 | return to_sz_t(std::strtoll(x, &end, 10)); 42 | } 43 | 44 | /// @brief Converts a string to `int`. 45 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE auto str_to_int(const std::string& x) 46 | { 47 | return str_to_int(x.c_str()); 48 | } 49 | 50 | /// @brief Converts a string to `float`. 51 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE auto str_to_float(const std::string& x) 52 | { 53 | return str_to_float(x.c_str()); 54 | } 55 | 56 | /// @brief Converts a string to `double`. 57 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE auto str_to_double( 58 | const std::string& x) 59 | { 60 | return str_to_double(x.c_str()); 61 | } 62 | 63 | /// @brief Converts a string to `sz_t`. 64 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE auto str_to_size_t( 65 | const std::string& x) 66 | { 67 | return str_to_size_t(x.c_str()); 68 | } 69 | } // namespace vrm::core 70 | -------------------------------------------------------------------------------- /include/vrm/core/casts/void_ptr.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace vrm::core 14 | { 15 | template 16 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr auto to_void_ptr( 17 | T* x) noexcept 18 | { 19 | return static_cast*>(x); 20 | } 21 | 22 | template 23 | [[nodiscard]] VRM_CORE_ALWAYS_INLINE constexpr auto num_to_void_ptr( 24 | T&& x) noexcept 25 | -> std::enable_if_t{}, copy_cv_qualifiers*> 26 | { 27 | static_assert(std::is_arithmetic_v>); 28 | return reinterpret_cast*>(x); 29 | } 30 | } // namespace vrm::core 31 | -------------------------------------------------------------------------------- /include/vrm/core/config.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /include/vrm/core/config/api.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/config/api/api.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | // TODO: (temporary) 9 | #define VRM_CORE_INLINE_LIBRARY 1 10 | 11 | 12 | 13 | #if defined(VRM_CORE_INLINE_LIBRARY) 14 | 15 | /// @macro Use as an header-only library. 16 | #define VRM_CORE_FN_API inline 17 | #define VRM_CORE_CLASS_API 18 | 19 | /// @macro Use as a statically-linked library. 20 | #elif defined(VRM_CORE_STATIC_LIBRARY) 21 | 22 | #define VRM_CORE_FN_API 23 | #define VRM_CORE_CLASS_API 24 | 25 | /// @macro Use as an exported DLL. 26 | #elif defined(VRM_CORE_EXPORT_LIBRARY) 27 | 28 | #define VRM_CORE_FN_API __declspec(dllexport) 29 | #define VRM_CORE_CLASS_API __declspec(dllexport) 30 | 31 | #elif defined(VRM_CORE_IMPORT_LIBRARY) 32 | 33 | /// @macro Use as an imported DLL. 34 | #define VRM_CORE_FN_API __declspec(dllimport) 35 | #define VRM_CORE_CLASS_API __declspec(dllimport) 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/vrm/core/config/attributes.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2019 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/arch.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/arch/arch.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/arch/impl/arch.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | namespace vrm::core::detection 9 | { 10 | enum class architecture 11 | { 12 | x86, 13 | x64, 14 | unknown 15 | }; 16 | 17 | [[nodiscard]] constexpr architecture current_architecture() noexcept; 18 | } // namespace vrm::core::detection 19 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/arch/impl/arch.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace vrm::core::detection 12 | { 13 | [[nodiscard]] inline constexpr architecture current_architecture() noexcept 14 | { 15 | #if defined(VRM_CORE_ARCH_32) 16 | return architecture::x86; 17 | #elif defined(VRM_CORE_ARCH_64) 18 | return architecture::x64; 19 | #else 20 | return architecture::unknown; 21 | #endif 22 | } 23 | } // namespace vrm::core::detection 24 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/arch/impl/arch_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #if(defined(WIN_32) || defined(__i386__) || defined(i386) || defined(__x86__)) 9 | /// @macro This macro is defined if the current architecture is 32 bit. 10 | #define VRM_CORE_ARCH_32 1 11 | #elif(defined(__amd64) || defined(__amd64__) || defined(__x86_64) || \ 12 | defined(__x86_64__) || defined(_M_X64) || defined(__ia64__) || \ 13 | defined(_M_IA64)) 14 | /// @macro This macro is defined if the current architecture is 64 bit. 15 | #define VRM_CORE_ARCH_64 1 16 | #else 17 | /// @macro This macro is defined if the current architecture is unknown. 18 | #define VRM_CORE_ARCH_UNKNOWN 1 19 | #endif 20 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/compiler.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/compiler/compiler.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/compiler/impl/compiler.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | namespace vrm::core::detection 9 | { 10 | enum class compiler 11 | { 12 | clang, 13 | gcc, 14 | msvc, 15 | unknown 16 | }; 17 | 18 | [[nodiscard]] constexpr compiler current_compiler() noexcept; 19 | } // namespace vrm::core::detection 20 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/compiler/impl/compiler.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace vrm::core::detection 12 | { 13 | [[nodiscard]] inline constexpr compiler current_compiler() noexcept 14 | { 15 | #if defined(VRM_CORE_COMPILER_CLANG) 16 | return compiler::clang; 17 | #elif defined(VRM_CORE_COMPILER_GCC) 18 | return compiler::gcc; 19 | #elif defined(VRM_CORE_COMPILER_MSVC) 20 | return compiler::msvc; 21 | #else 22 | return compiler::unknown; 23 | #endif 24 | } 25 | } // namespace vrm::core::detection 26 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/compiler/impl/compiler_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #if defined(__clang__) 9 | /// @macro This macro is defined if the current compiler is clang. 10 | #define VRM_CORE_COMPILER_CLANG 1 11 | #elif defined(__GNUC__) 12 | /// @macro This macro is defined if the current compiler is gcc. 13 | #define VRM_CORE_COMPILER_GCC 1 14 | #elif defined(_MSC_VER) 15 | /// @macro This macro is defined if the current compiler is MSVC. 16 | #define VRM_CORE_COMPILER_MSVC 1 17 | #else 18 | /// @macro This macro is defined if the current compiler is unknown. 19 | #define VRM_CORE_COMPILER_UNKNOWN 1 20 | #endif 21 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/debug.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/debug/debug.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2019 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/debug/impl/debug.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2019 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | namespace vrm::core::detection 9 | { 10 | constexpr bool debug() noexcept; 11 | } // namespace vrm::core::detection 12 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/debug/impl/debug.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2019 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace vrm::core::detection 12 | { 13 | [[nodiscard]] inline constexpr bool debug() noexcept 14 | { 15 | #if defined(VRM_CORE_DEBUG) 16 | return true; 17 | #else 18 | return false; 19 | #endif 20 | } 21 | } // namespace vrm::core::detection 22 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/debug/impl/debug_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2019 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #if !defined(NDEBUG) 9 | #define VRM_CORE_DEBUG 1 10 | #endif 11 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/os.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/os/impl/os.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | namespace vrm::core::detection 9 | { 10 | enum class operating_system 11 | { 12 | os_linux, 13 | os_windows, 14 | os_mac, 15 | os_android, 16 | os_freebsd, 17 | os_unknown 18 | }; 19 | 20 | [[nodiscard]] constexpr operating_system 21 | current_operating_system() noexcept; 22 | 23 | [[nodiscard]] constexpr bool on_unix() noexcept; 24 | [[nodiscard]] constexpr bool on_windows() noexcept; 25 | [[nodiscard]] constexpr bool on_mac() noexcept; 26 | } // namespace vrm::core::detection 27 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/os/impl/os.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace vrm::core::detection 12 | { 13 | [[nodiscard]] inline constexpr operating_system 14 | current_operating_system() noexcept 15 | { 16 | #if defined(VRM_CORE_OS_LINUX) 17 | return operating_system::os_linux; 18 | #elif defined(VRM_CORE_OS_ANDROID) 19 | return operating_system::os_android; 20 | #elif defined(VRM_CORE_OS_FREEBSD) 21 | return operating_system::os_freebsd; 22 | #elif defined(VRM_CORE_OS_WINDOWS) 23 | return operating_system::os_windows; 24 | #elif defined(VRM_CORE_OS_MAC) 25 | return operating_system::os_mac; 26 | #else 27 | return operating_system::os_unknown; 28 | #endif 29 | } 30 | 31 | [[nodiscard]] inline constexpr bool on_unix() noexcept 32 | { 33 | return current_operating_system() == operating_system::os_linux || 34 | current_operating_system() == operating_system::os_android || 35 | current_operating_system() == operating_system::os_freebsd; 36 | } 37 | 38 | [[nodiscard]] inline constexpr bool on_windows() noexcept 39 | { 40 | return current_operating_system() == operating_system::os_windows; 41 | } 42 | 43 | [[nodiscard]] inline constexpr bool on_mac() noexcept 44 | { 45 | return current_operating_system() == operating_system::os_mac; 46 | } 47 | } // namespace vrm::core::detection 48 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/os/impl/os_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #if defined(__unix__) || defined(__unix) 9 | 10 | // --- 11 | #if defined(__ANDROID__) 12 | /// @macro This macro is defined if the current OS is Android. 13 | #define VRM_CORE_OS_ANDROID 1 14 | #elif defined(__linux__) 15 | /// @macro This macro is defined if the current OS is Linux. 16 | #define VRM_CORE_OS_LINUX 1 17 | #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) 18 | /// @macro This macro is defined if the current OS is FreeBSD. 19 | #define VRM_CORE_OS_FREEBSD 1 20 | #endif 21 | // --- 22 | 23 | #elif defined(_WIN64) || defined(_WIN32) || defined(__CYGWIN32__) || \ 24 | defined(__MINGW32__) 25 | 26 | /// @macro This macro is defined if the current OS is Windows. 27 | #define VRM_CORE_OS_WINDOWS 1 28 | 29 | #elif defined(MACOSX) || defined(__DARWIN__) || defined(__APPLE__) 30 | 31 | /// @macro This macro is defined if the current OS is Mac. 32 | #define VRM_CORE_OS_MAC 1 33 | 34 | #else 35 | 36 | /// @macro This macro is defined if the current OS is unknown. 37 | #define VRM_CORE_OS_UNKNOWN 1 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/os/os.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/rtti.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/rtti/impl/rtti.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | namespace vrm::core::detection 9 | { 10 | [[nodiscard]] constexpr bool rtti() noexcept; 11 | } // namespace vrm::core::detection 12 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/rtti/impl/rtti.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace vrm::core::detection 12 | { 13 | [[nodiscard]] inline constexpr bool rtti() noexcept 14 | { 15 | #if defined(VRM_CORE_RTTI_ENABLED) 16 | return true; 17 | #else 18 | return false; 19 | #endif 20 | } 21 | } // namespace vrm::core::detection 22 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/rtti/impl/rtti_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #if defined(__cpp_rtti) || defined(__GXX_RTTI) || defined(_CPPRTTI) 9 | /// @macro This macro is defined if RTTI is enabled. 10 | #define VRM_CORE_RTTI_ENABLED 1 11 | #else 12 | /// @macro This macro is defined if RTTI is disabled. 13 | #define VRM_CORE_RTTI_DISABLED 1 14 | #endif 15 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/rtti/rtti.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/stdlib.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/stdlib/impl/stdlib.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | namespace vrm::core::detection 9 | { 10 | enum class stdlib 11 | { 12 | libcxx, 13 | libstdcxx, 14 | unknown 15 | }; 16 | 17 | [[nodiscard]] constexpr stdlib current_stdlib() noexcept; 18 | } // namespace vrm::core::detection 19 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/stdlib/impl/stdlib.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace vrm::core::detection 12 | { 13 | [[nodiscard]] inline constexpr stdlib current_stdlib() noexcept 14 | { 15 | #if defined(VRM_CORE_STDLIB_LIBCXX) 16 | return stdlib::libcxx; 17 | #elif defined(VRM_CORE_STDLIB_LIBSTDCXX) 18 | return stdlib::libstdcxx; 19 | #else 20 | return stdlib::unknown; 21 | #endif 22 | } 23 | } // namespace vrm::core::detection 24 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/stdlib/impl/stdlib_macros.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #if defined(_LIBCPP_VERSION) 9 | #define VRM_CORE_STDLIB_LIBCXX 1 10 | #elif defined(__GLIBCXX__) 11 | #define VRM_CORE_STDLIB_LIBSTDCXX 1 12 | #else 13 | #define VRM_CORE_STDLIB_UNKNOWN 1 14 | #endif 15 | -------------------------------------------------------------------------------- /include/vrm/core/config/detection/stdlib/stdlib.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/console.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | // TODO: 9 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/console/format_state.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace vrm::core 13 | { 14 | namespace console 15 | { 16 | namespace impl 17 | { 18 | struct format_state 19 | { 20 | style _style{style::none}; 21 | color _fg_color{color::none}; 22 | color _bg_color{color::none}; 23 | }; 24 | } // namespace impl 25 | } // namespace console 26 | } // namespace vrm::core 27 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/console/format_types.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace vrm::core 13 | { 14 | namespace console 15 | { 16 | namespace impl 17 | { 18 | using style_type = i8; 19 | using color_type = i8; 20 | 21 | /// @brief Number of styles. 22 | constexpr sz_t style_count{13}; 23 | 24 | /// @brief Number of colors. 25 | constexpr sz_t color_count{16}; 26 | } // namespace impl 27 | 28 | /// @brief Enum class representing all the possible styles. 29 | enum class style : impl::style_type 30 | { 31 | none = 0, 32 | bold = 1, 33 | dim = 2, 34 | underline = 3, 35 | blink = 4, 36 | reverse_fg_bg = 5, 37 | hidden = 6 38 | }; 39 | 40 | /// @brief Enum class representing all the possible colors. 41 | enum class color : impl::color_type 42 | { 43 | none = 0, 44 | black = 1, 45 | red = 2, 46 | green = 3, 47 | yellow = 4, 48 | blue = 5, 49 | magenta = 6, 50 | cyan = 7, 51 | light_gray = 8, 52 | dark_gray = 9, 53 | light_red = 10, 54 | light_green = 11, 55 | light_yellow = 12, 56 | light_blue = 13, 57 | light_magenta = 14, 58 | light_cyan = 15, 59 | light_white = 16 60 | }; 61 | } // namespace console 62 | } // namespace vrm::core 63 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/delegate.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/delegate/base_delegate.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/delegate/delegate.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/delegate/dynamic_delegate.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/delegate/impl/delegate.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | // TODO: WIP 13 | // * templatize fn_type 14 | // * templatize container 15 | // ** fixed_delegate<10> 16 | // ** fixed_unsubscribable_delegate<10> 17 | // ** delegate 18 | // ** unsubscribable_delegate 19 | 20 | namespace vrm::core 21 | { 22 | namespace impl 23 | { 24 | template 25 | class VRM_CORE_CLASS_API delegate 26 | : public impl::base_delegate 27 | { 28 | private: 29 | using base_type = impl::base_delegate; 30 | using fn_signature = typename base_type::fn_signature; 31 | 32 | public: 33 | using fn_type = typename base_type::fn_type; 34 | 35 | delegate() = default; 36 | 37 | delegate(const delegate&) = default; 38 | delegate& operator=(const delegate&) = default; 39 | 40 | delegate(delegate&&) = default; 41 | delegate& operator=(delegate&&) = default; 42 | 43 | template 44 | void operator+=(TF&& f); 45 | }; 46 | } // namespace impl 47 | 48 | template > 51 | using delegate = impl::delegate< 52 | impl::delegate_settings>; 53 | } // namespace vrm::core 54 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/delegate/impl/delegate.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace vrm::core 14 | { 15 | namespace impl 16 | { 17 | template 18 | template 19 | void delegate::operator+=(TF&& f) 20 | { 21 | this->emplace_function(FWD(f)); 22 | } 23 | } // namespace impl 24 | } // namespace vrm::core 25 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/delegate/impl/dynamic_delegate.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace vrm::core 14 | { 15 | namespace impl 16 | { 17 | template 18 | auto VRM_CORE_PURE_FN dynamic_delegate::next_fn_idx() const 19 | noexcept 20 | { 21 | return this->_functions.size() - 1; 22 | } 23 | 24 | template 25 | template 26 | auto dynamic_delegate::operator+=(TF&& f) 27 | { 28 | // Emplace function at the end of functions vector. 29 | this->emplace_function(FWD(f)); 30 | 31 | // Return an handle to it. 32 | return _hm.create(next_fn_idx()); 33 | } 34 | 35 | template 36 | void dynamic_delegate::operator-=(const handle_type& h) 37 | { 38 | _hm.destroy(h, [this](auto i) { 39 | // Swap dead function with last function in the vector. 40 | using std::swap; 41 | swap(this->_functions[i], this->_functions.back()); 42 | 43 | // Pop back the dead function. 44 | this->_functions.pop_back(); 45 | }); 46 | } 47 | } // namespace impl 48 | } // namespace vrm::core 49 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/delegate/signature_helper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | 9 | namespace vrm::core 10 | { 11 | namespace impl 12 | { 13 | template 14 | struct signature_helper; 15 | 16 | template 17 | struct signature_helper 18 | { 19 | using return_type = TReturn; 20 | }; 21 | 22 | template 23 | using signature_return_type = 24 | typename signature_helper::return_type; 25 | } // namespace impl 26 | } // namespace vrm::core 27 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle/impl/aliases.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | 9 | namespace vrm::core 10 | { 11 | namespace handle 12 | { 13 | namespace impl 14 | { 15 | template 16 | using target_type = typename T::target_type; 17 | 18 | template 19 | using counter_type = typename T::counter_type; 20 | 21 | template 22 | using metadata_type = typename T::metadata_type; 23 | 24 | template 25 | using metadata_ref_type = typename T::metadata_ref_type; 26 | 27 | template 28 | using handle_type = typename T::template handle_type; 29 | } // namespace impl 30 | } // namespace handle 31 | } // namespace vrm::core 32 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle/impl/settings.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace vrm::core 11 | { 12 | namespace handle 13 | { 14 | /// @brief Compile-time settings for handle manager. 15 | template 16 | class settings 17 | { 18 | private: 19 | using target_underlying_type = 20 | underlying_if_strong_typedef_type; 21 | 22 | using counter_underlying_type = 23 | underlying_if_strong_typedef_type; 24 | 25 | static_assert(std::is_arithmetic{} && 26 | std::is_unsigned{}); 27 | 28 | static_assert( // . 29 | std::is_arithmetic{}); 30 | 31 | public: 32 | /// @brief Points from metadata to target user-specified object. 33 | using target_type = TTarget; 34 | 35 | /// @brief Counter type (checks handle validity). 36 | using counter_type = TCounter; 37 | 38 | /// @brief Lightweight handle that points to strategy-defined 39 | /// metadata and stores a counter. 40 | template 41 | struct handle_type 42 | { 43 | TMetadataRef _metadata_ref; 44 | counter_type _counter{0}; 45 | }; 46 | }; 47 | } // namespace handle 48 | } // namespace vrm::core 49 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle/impl/storage.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle/impl/storage/array.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle/impl/storage/array/array.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace vrm::core 15 | { 16 | namespace handle 17 | { 18 | namespace storage 19 | { 20 | /// @brief Fixed storage class. 21 | /// @details Uses pointers to point to metadata instances. 22 | /// Moving/copying the storage can invalidate existing pointers. 23 | template 24 | class hs_array 25 | { 26 | public: 27 | using settings_type = TSettings; 28 | using target_type = impl::target_type; 29 | using counter_type = impl::counter_type; 30 | 31 | using metadata_type = 32 | strategy::storage_metadata_type; 33 | 34 | using metadata_ref_type = metadata_type*; 35 | 36 | using handle_type = 37 | impl::handle_type; 38 | 39 | static constexpr sz_t count{TCount}; 40 | 41 | private: 42 | std::array _metadata; 43 | metadata_ref_type _next_ref{_metadata.data()}; 44 | 45 | public: 46 | auto& metadata_from_handle(const handle_type& h) noexcept; 47 | const auto& metadata_from_handle(const handle_type& h) const 48 | noexcept; 49 | 50 | auto create(const target_type& target) noexcept; 51 | void invalidate(const handle_type& h) noexcept; 52 | 53 | template 54 | void destroy(const handle_type& h, TF&& f); 55 | 56 | void clear() noexcept; 57 | void reserve(sz_t n) noexcept; 58 | }; 59 | } // namespace storage 60 | } // namespace handle 61 | } // namespace vrm::core 62 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle/impl/storage/vector.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle/manager.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle/strategy.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/container.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/container/owning_packed_array.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/container/owning_packed_array/owning_packed_array.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace vrm::core 15 | { 16 | namespace handle2 17 | { 18 | namespace container 19 | { 20 | template 21 | template 22 | auto owning_packed_array::create( 23 | TTargetFwd&& t) noexcept 24 | { 25 | // Create new valid handle. 26 | auto h(this->create_handle()); 27 | 28 | // Get handle data. 29 | auto m_ref(h._data); 30 | 31 | // Assign the target to the location pointed by the free 32 | // metadata. 33 | this->target(m_ref) = FWD(t); 34 | 35 | // Return the handle. 36 | return h; 37 | } 38 | 39 | template 40 | void owning_packed_array::destroy( 41 | const handle_type& h) 42 | { 43 | // Invalidate metadata for handle `h`. 44 | // Swap the last valid target with the destroyed one to maintain 45 | // array packedness. 46 | this->destroy_handle( 47 | h, [this](auto invalid_index, auto valid_index) { 48 | using std::swap; 49 | swap(_targets[invalid_index], _targets[valid_index]); 50 | }); 51 | } 52 | 53 | template 54 | void owning_packed_array::clear() noexcept 55 | { 56 | this->clear_metadata(); 57 | } 58 | } // namespace container 59 | } // namespace handle2 60 | } // namespace vrm::core 61 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/container/vector.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vittorioromeo/vrm_core/ee1b290f673e9776a9070f7e8d9a07a84a002178/include/vrm/core/experimental/handle2/container/vector.hpp -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/manager.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/manager/packed_array.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/settings.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/settings/aliases.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace vrm::core 11 | { 12 | namespace handle2 13 | { 14 | namespace aliases 15 | { 16 | template 17 | using handle_data_type = typename TSettings::handle_data_type; 18 | 19 | template 20 | using target_type = typename TSettings::target_type; 21 | 22 | template 23 | using counter_type = typename TSettings::counter_type; 24 | 25 | template 26 | using handle_type = typename TSettings::handle_type; 27 | } // namespace aliases 28 | } // namespace handle2 29 | } // namespace vrm::core 30 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/handle2/settings/settings.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | 9 | namespace vrm::core 10 | { 11 | namespace handle2 12 | { 13 | /// @brief Settings for an handle context. 14 | /// @tparam THandleData Type of data stored inside the handles. Usually 15 | /// an index that points to the desired real data. 16 | /// @tparam TTarget Type of data retrieved by accessing the handles. 17 | /// @tparam TCounter Type of validity counter. 18 | template < // . 19 | typename THandleData, // . 20 | typename TTarget, // . 21 | typename TCounter // . 22 | > 23 | class settings 24 | { 25 | public: 26 | using handle_data_type = THandleData; 27 | using target_type = TTarget; 28 | using counter_type = TCounter; 29 | 30 | struct handle_type 31 | { 32 | handle_data_type _data; 33 | counter_type _counter{0}; 34 | }; 35 | }; 36 | } // namespace handle2 37 | } // namespace vrm::core 38 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/multi_vector.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resizable_buffer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resizable_buffer/resizable_buffer.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | // TODO: 16 | #include 17 | #include 18 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/access.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | // TODO: analyze 9 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/base/base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace vrm::core 13 | { 14 | namespace resource 15 | { 16 | namespace impl 17 | { 18 | /// @brief Base resource class containing shared logic and state 19 | /// between 20 | /// multiple resource types. 21 | /// @details Provides `behavior_type` and `handle_type` type 22 | /// aliases. 23 | /// Provides a static `null_handle` shortcut method. 24 | /// Contains a single `handle_type _handle` instance. 25 | /// Defines a default constructor and an `explicit` constructor that 26 | /// taken an handle. 27 | /// Provides shortcut methods to `deinit`, `nullify`, and `release`. 28 | /// Provides a `get` method and `bool` conversions. 29 | template 30 | class base 31 | { 32 | template 33 | friend class weak; 34 | 35 | public: 36 | using behavior_type = TBehavior; 37 | using handle_type = typename behavior_type::handle_type; 38 | 39 | private: 40 | static auto null_handle() noexcept; 41 | 42 | protected: 43 | handle_type _handle; 44 | 45 | base() noexcept; 46 | explicit base(const handle_type& handle) noexcept; 47 | 48 | [[nodiscard]] auto is_null_handle() const noexcept; 49 | 50 | void deinit() noexcept(is_nothrow_deinit_t{}); 51 | void nullify() noexcept; 52 | auto release_and_nullify() noexcept; 53 | 54 | void swap(base& rhs) noexcept; 55 | 56 | public: 57 | [[nodiscard]] auto get() const noexcept; 58 | explicit operator bool() const noexcept; 59 | }; 60 | } // namespace impl 61 | } // namespace resource 62 | } // namespace vrm::core 63 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/behavior.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/behavior/behavior_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace vrm::core::resource 13 | { 14 | template 15 | using is_nothrow_init_t = bool_; 16 | 17 | template 18 | using is_nothrow_deinit_t = bool_()))>; 20 | 21 | template 22 | using is_zero_sized = std::integral_constant; 23 | 24 | template 25 | struct has_init : std::false_type 26 | { 27 | }; 28 | 29 | template 30 | struct has_init> : std::true_type 31 | { 32 | }; 33 | 34 | template 35 | using is_valid_behavior = std::integral_constant{} && has_init{} // . 37 | >; 38 | } // namespace vrm::core::resource 39 | 40 | // TODO: use is_valid ? 41 | // TODO: check other methods 42 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/fwd/fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace vrm::core 11 | { 12 | namespace resource 13 | { 14 | namespace impl 15 | { 16 | // Forward declarations. 17 | template 18 | class weak; 19 | 20 | template 21 | class shared; 22 | } // namespace impl 23 | } // namespace resource 24 | } // namespace vrm::core 25 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/interface.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | // TODO: analyze 9 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/shared.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include "./shared/metadata.hpp" 9 | #include "./shared/policies.hpp" 10 | #include "./shared/ref_counter.hpp" 11 | #include "./shared/shared.hpp" 12 | #include "./shared/shared.inl" 13 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/shared/metadata.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/shared/metadata/metadata.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | 11 | namespace vrm::core::resource::impl 12 | { 13 | // TODO: templatize with policy, use atomics for lock-policy 14 | 15 | /// @brief Type used to count references. 16 | using shared_counter_type = unsigned int; 17 | 18 | /// @brief Metadata necessary to keep track of owning shared 19 | /// references and weak references. 20 | /// @details This instance gets allocated once per resource, and 21 | /// deallocated when the resource is deinitialized. 22 | class shared_metadata 23 | { 24 | private: 25 | shared_counter_type _owner_count; 26 | shared_counter_type _weak_count; 27 | 28 | public: 29 | shared_metadata(shared_counter_type owner_count, 30 | shared_counter_type weak_count) noexcept; 31 | 32 | // Prevent copies. 33 | shared_metadata(const shared_metadata &) = delete; 34 | shared_metadata &operator=(const shared_metadata &) = delete; 35 | 36 | // Prevent moves. 37 | shared_metadata(shared_metadata &&) = delete; 38 | shared_metadata &operator=(shared_metadata &&) = delete; 39 | 40 | void increment_owner() noexcept; 41 | void decrement_owner() noexcept; 42 | 43 | void increment_weak() noexcept; 44 | void decrement_weak() noexcept; 45 | 46 | [[nodiscard]] auto owner_count() const noexcept; 47 | [[nodiscard]] auto weak_count() const noexcept; 48 | [[nodiscard]] auto total_count() const noexcept; 49 | 50 | [[nodiscard]] auto has_any_ref() const noexcept; 51 | }; 52 | } // namespace vrm::core::resource::impl 53 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/shared/metadata/metadata.inl: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace vrm::core 13 | { 14 | namespace resource 15 | { 16 | namespace impl 17 | { 18 | VRM_CORE_ALWAYS_INLINE shared_metadata::shared_metadata( 19 | shared_counter_type owner_count, 20 | shared_counter_type weak_count) noexcept 21 | : _owner_count{owner_count}, _weak_count{weak_count} 22 | { 23 | } 24 | 25 | VRM_CORE_ALWAYS_INLINE void 26 | shared_metadata::increment_owner() noexcept 27 | { 28 | ++_owner_count; 29 | } 30 | 31 | VRM_CORE_ALWAYS_INLINE void 32 | shared_metadata::decrement_owner() noexcept 33 | { 34 | VRM_CORE_ASSERT_OP(_owner_count, >, 0); 35 | --_owner_count; 36 | } 37 | 38 | VRM_CORE_ALWAYS_INLINE void 39 | shared_metadata::increment_weak() noexcept 40 | { 41 | ++_weak_count; 42 | } 43 | 44 | VRM_CORE_ALWAYS_INLINE void 45 | shared_metadata::decrement_weak() noexcept 46 | { 47 | VRM_CORE_ASSERT_OP(_weak_count, >, 0); 48 | --_weak_count; 49 | } 50 | 51 | VRM_CORE_ALWAYS_INLINE auto // . 52 | shared_metadata::owner_count() const noexcept 53 | { 54 | return _owner_count; 55 | } 56 | 57 | VRM_CORE_ALWAYS_INLINE auto // . 58 | shared_metadata::weak_count() const noexcept 59 | { 60 | return _weak_count; 61 | } 62 | 63 | VRM_CORE_ALWAYS_INLINE auto // . 64 | shared_metadata::total_count() const noexcept 65 | { 66 | return owner_count() + weak_count(); 67 | } 68 | 69 | VRM_CORE_ALWAYS_INLINE auto // . 70 | shared_metadata::has_any_ref() const noexcept 71 | { 72 | return total_count() > 0; 73 | } 74 | } // namespace impl 75 | } // namespace resource 76 | } // namespace vrm::core 77 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/shared/policies.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace vrm::core::resource::impl 11 | { 12 | // Thread-safety policies. 13 | namespace shared_lock_policy 14 | { 15 | /// @brief Non-thread-safe policy. No additional performance 16 | /// overhead. 17 | struct none 18 | { 19 | }; 20 | 21 | // TODO: other policies! 22 | } // namespace shared_lock_policy 23 | } // namespace vrm::core::resource::impl 24 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/shared/ref_counter.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include "./ref_counter/ref_counter.hpp" 9 | #include "./ref_counter/ref_counter.inl" 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/shared/ref_counter/ref_counter.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace vrm::core::resource::impl 14 | { 15 | // TODO: test polymorphism with custom shared_ptr 16 | class shared_ref_counter 17 | { 18 | private: 19 | shared_metadata* _metadata{nullptr}; 20 | 21 | auto &access_metadata() noexcept; 22 | [[nodiscard]] const auto &access_metadata() const noexcept; 23 | 24 | [[nodiscard]] auto weak_count() const noexcept; 25 | [[nodiscard]] auto total_count() const noexcept; 26 | 27 | [[nodiscard]] auto has_any_ref() const noexcept; 28 | 29 | void increment_owner() noexcept; 30 | void decrement_owner() noexcept; 31 | 32 | void deallocate() noexcept; 33 | 34 | template 35 | void deallocate_if_required(TF &&deleter) noexcept; 36 | 37 | void decrement_weak() noexcept; 38 | 39 | public: 40 | shared_ref_counter() noexcept = default; 41 | 42 | shared_ref_counter(const shared_ref_counter &) = default; 43 | shared_ref_counter &operator=(const shared_ref_counter &) = default; 44 | 45 | shared_ref_counter(shared_ref_counter &&rhs) noexcept; 46 | auto &operator=(shared_ref_counter &&rhs) noexcept; 47 | 48 | [[nodiscard]] bool is_null() const noexcept; 49 | 50 | [[nodiscard]] auto owner_count() const noexcept; 51 | [[nodiscard]] auto use_count() const noexcept; 52 | 53 | void acquire_from_null(); 54 | void acquire_existing() noexcept; 55 | 56 | void increment_weak() noexcept; 57 | 58 | template 59 | void lose_ownership(TF &&deleter) noexcept; 60 | 61 | template 62 | void lose_weak(TF &&deleter); 63 | }; 64 | } // namespace vrm::core::resource::impl 65 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/unique.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include "./unique/unique.hpp" 9 | #include "./unique/unique.inl" 10 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/utils.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | -------------------------------------------------------------------------------- /include/vrm/core/experimental/resource/utils/make_resource.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015-2020 Vittorio Romeo 2 | // License: Academic Free License ("AFL") v. 3.0 3 | // AFL License page: http://opensource.org/licenses/AFL-3.0 4 | // http://vittorioromeo.info | vittorio.romeo@outlook.com 5 | 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace vrm::core::resource 14 | { 15 | namespace impl 16 | { 17 | template