├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── include └── neolib │ ├── app │ ├── application.hpp │ ├── application_info.hpp │ ├── i_application.hpp │ ├── i_application_info.hpp │ ├── i_logger.hpp │ ├── i_object.hpp │ ├── i_power.hpp │ ├── i_setting.hpp │ ├── i_setting_constraints.hpp │ ├── i_setting_value.hpp │ ├── i_settings.hpp │ ├── i_shared_thread_local.hpp │ ├── i_version.hpp │ ├── logger.hpp │ ├── module.hpp │ ├── object.hpp │ ├── os_version.hpp │ ├── ostream_logger.hpp │ ├── power.hpp │ ├── services.hpp │ ├── setting.hpp │ ├── setting_constraints.hpp │ ├── setting_value.hpp │ ├── settings.hpp │ ├── shared_thread_local.hpp │ └── version.hpp │ ├── core │ ├── 3rdparty │ │ └── plf_hive.h │ ├── allocator.hpp │ ├── any.hpp │ ├── any_iterator.hpp │ ├── any_predicate.hpp │ ├── any_ref.hpp │ ├── array_tree.hpp │ ├── bresenham_counter.hpp │ ├── container_iterator.hpp │ ├── crc.hpp │ ├── custom_type.hpp │ ├── deque.hpp │ ├── enum.hpp │ ├── fast_hash.hpp │ ├── fast_vector.hpp │ ├── fwd_abstract.hpp │ ├── gap_vector.hpp │ ├── generic_iterator.hpp │ ├── hive.hpp │ ├── i_any.hpp │ ├── i_container.hpp │ ├── i_contiguous_random_access_container.hpp │ ├── i_custom_type.hpp │ ├── i_custom_type_factory.hpp │ ├── i_deque.hpp │ ├── i_discoverable.hpp │ ├── i_enum.hpp │ ├── i_iterator.hpp │ ├── i_jar.hpp │ ├── i_lifetime.hpp │ ├── i_list.hpp │ ├── i_map.hpp │ ├── i_mutex.hpp │ ├── i_optional.hpp │ ├── i_pair.hpp │ ├── i_random_access_container.hpp │ ├── i_reference_counted.hpp │ ├── i_sequence_container.hpp │ ├── i_set.hpp │ ├── i_simple_variant.hpp │ ├── i_string.hpp │ ├── i_string_view.hpp │ ├── i_unordered_map.hpp │ ├── i_variant.hpp │ ├── i_vector.hpp │ ├── index_array_tree.hpp │ ├── indexitor.hpp │ ├── intrusive_sort.hpp │ ├── jar.hpp │ ├── lifetime.hpp │ ├── list.hpp │ ├── map.hpp │ ├── memory.hpp │ ├── mutable_set.hpp │ ├── mutex.hpp │ ├── noncopyable.hpp │ ├── numerical.hpp │ ├── optional.hpp │ ├── pair.hpp │ ├── polymorphic_vecarray.hpp │ ├── queue.hpp │ ├── quick_string.hpp │ ├── random.hpp │ ├── recursion.hpp │ ├── red_black_tree.hpp │ ├── reference_counted.hpp │ ├── scoped.hpp │ ├── segmented_array.hpp │ ├── segmented_tree.hpp │ ├── set.hpp │ ├── simd.hpp │ ├── singleton.hpp │ ├── small_buffer_allocator.hpp │ ├── small_vector.hpp │ ├── static_vector.hpp │ ├── stdint.hpp │ ├── string.hpp │ ├── string_ci.hpp │ ├── string_numeric.hpp │ ├── string_utf.hpp │ ├── string_utils.hpp │ ├── string_view.hpp │ ├── swizzle.hpp │ ├── tag_array.hpp │ ├── thread_local.hpp │ ├── tree.hpp │ ├── type_traits.hpp │ ├── unordered_map.hpp │ ├── utility.hpp │ ├── uuid.hpp │ ├── variadic.hpp │ ├── variant.hpp │ ├── vecarray.hpp │ ├── vector.hpp │ ├── visitor.hpp │ ├── win32 │ │ └── win32.hpp │ └── zip_iterator.hpp │ ├── ecs │ ├── 3rdparty │ │ └── facebook │ │ │ └── flicks.h │ ├── chrono.hpp │ ├── clock.hpp │ ├── component.hpp │ ├── ecs.hpp │ ├── ecs_ids.hpp │ ├── entity.hpp │ ├── entity_archetype.hpp │ ├── entity_info.hpp │ ├── entity_life_span.hpp │ ├── i_component.hpp │ ├── i_component_data.hpp │ ├── i_ecs.hpp │ ├── i_entity_archetype.hpp │ ├── i_system.hpp │ ├── system.hpp │ └── time.hpp │ ├── file │ ├── file.hpp │ ├── gunzip.hpp │ ├── hexdump.hpp │ ├── json.hpp │ ├── json.inl │ ├── parser.hpp │ ├── xml.hpp │ ├── xml.inl │ └── zip.hpp │ ├── io │ ├── binary_data_packet.hpp │ ├── binary_packet.hpp │ ├── data_packet.hpp │ ├── http.hpp │ ├── i_packet.hpp │ ├── oauth.hpp │ ├── openssl.hpp │ ├── packet_connection.hpp │ ├── packet_stream.hpp │ ├── resolver.hpp │ ├── string_packet.hpp │ ├── tcp_packet_stream_server.hpp │ ├── tld_packet.hpp │ └── uri.hpp │ ├── neolib.hpp │ ├── plugin │ ├── i_plugin.hpp │ ├── i_plugin_manager.hpp │ ├── i_plugin_variant.hpp │ ├── plugin.hpp │ ├── plugin_manager.hpp │ ├── plugin_variant.hpp │ └── simple_variant.hpp │ └── task │ ├── async_task.hpp │ ├── async_thread.hpp │ ├── event.hpp │ ├── i_async_task.hpp │ ├── i_event.hpp │ ├── i_message_queue.hpp │ ├── i_task.hpp │ ├── i_thread.hpp │ ├── i_timer_object.hpp │ ├── task.hpp │ ├── thread.hpp │ ├── thread_pool.hpp │ ├── timer.hpp │ ├── timer_object.hpp │ ├── waitable.hpp │ └── waitable_event.hpp ├── neolibConfig.cmake.in ├── src ├── app │ ├── application_info.cpp │ ├── module.cpp │ ├── os_version.cpp │ ├── power.cpp │ ├── services.cpp │ ├── settings.cpp │ └── shared_thread_local.cpp ├── core │ ├── crc.cpp │ ├── lifetime.cpp │ ├── string_utils.cpp │ └── uuid.cpp ├── ecs │ ├── ecs.cpp │ ├── entity.cpp │ ├── entity_archetype.cpp │ ├── system.cpp │ └── time.cpp ├── file │ ├── file.cpp │ ├── gunzip.cpp │ └── zip.cpp ├── io │ ├── http.cpp │ ├── oauth.cpp │ ├── openssl.cpp │ └── uri.cpp ├── plugin │ └── plugin_manager.cpp ├── posix │ └── app │ │ ├── posix_module.cpp │ │ └── posix_module.hpp ├── task │ ├── async_task.cpp │ ├── async_thread.cpp │ ├── event.cpp │ ├── thread.cpp │ ├── thread_pool.cpp │ ├── timer.cpp │ ├── timer_object.cpp │ └── waitable_event.cpp └── win32 │ ├── app │ ├── win32_module.cpp │ └── win32_module.hpp │ ├── core │ └── win32.cpp │ └── task │ ├── win32_message_queue.cpp │ └── win32_message_queue.hpp └── unit_tests ├── App └── src │ └── App.cpp ├── Containers ├── Containers.cpp └── Tree.cpp ├── Event └── src │ └── Event.cpp ├── File └── File.cpp ├── Logger └── Logger.cpp ├── NoFussJSON └── src │ └── NoFussJSONTest.cpp ├── StringUtils └── src │ └── StringUtils.cpp ├── Task └── Task.cpp └── threadpool.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | /lib/neolib.lib 2 | /lib/neolibd.lib 3 | /build/win32/vs2019/x64 4 | /build/win32/vs2019/neolib.vcxproj.user 5 | /build/win32/vs2019/Debug 6 | /build/win32/vs2019/Release 7 | /build/win32/vs2019/x64/Release 8 | /unit_tests/NoFussJSON/build/win32/vs2019/NoFussJSONTest/.vs 9 | /unit_tests/NoFussJSON/build/win32/vs2019/NoFussJSONTest/Debug 10 | /unit_tests/NoFussJSON/build/win32/vs2019/NoFussJSONTest/Release 11 | /unit_tests/NoFussJSON/build/win32/vs2019/NoFussJSONTest/x64 12 | /unit_tests/NoFussJSON/build/win32/vs2019/NoFussJSONTest/My Amplifier Results - NoFussJSONTest/My Amplifier Results - NoFussJSONTest.amplxeproj 13 | /unit_tests/NoFussJSON/build/win32/vs2019/NoFussJSONTest/NoFussJSONTest.vcxproj.user 14 | /unit_tests/Containers/.vs 15 | /unit_tests/Containers/x64 16 | /unit_tests/Containers/Containers.vcxproj.user 17 | /unit_tests/Event/build/win32/vs2019/Event/x64 18 | /unit_tests/Event/build/win32/vs2019/Event/Debug 19 | /unit_tests/Event/build/win32/vs2019/Event/Event.vcxproj.user 20 | /build/win32/vs2019/.vs 21 | /stage 22 | /build/win32/vs2017/Debug 23 | /build/win32/vs2017/Release 24 | /build/win32/vs2017/x64/Debug 25 | /build/win32/vs2017/x64/Release 26 | /unit_tests/NoFussJSON/build/win32/vs2017/NoFussJSONTest/Debug 27 | /unit_tests/NoFussJSON/build/win32/vs2017/NoFussJSONTest/*.user 28 | /build/win32/vs2017/.vs/neolib/v15 29 | /build/win32/vs2017/*.user 30 | /unit_tests/NoFussJSON/build/win32/vs2017/NoFussJSONTest/.vs/NoFussJSONTest/v15 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007-present, Leigh Johnston. 2 | 3 | All Rights Reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in the 14 | documentation and/or other materials provided with the distribution. 15 | 16 | * Neither the name of Leigh Johnston nor the names of any 17 | other contributors to this software may be used to endorse or 18 | promote products derived from this software without specific prior 19 | written permission. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 22 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 23 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 27 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 28 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | "neolib" is a cross-platform C++ utility library. 3 | 4 | # Dependencies 5 | * Boost 6 | * OpenSSL 7 | * zlib 8 | 9 | # Features 10 | * segmented_array container, see [http://i42.co.uk/stuff/segmented_array.htm](http://i42.co.uk/stuff/segmented_array.htm). 11 | * gap_vector container, a gap buffer. 12 | * neosigslot, see [http://i42.co.uk/stuff/neosigslot.htm](http://i42.co.uk/stuff/neosigslot.htm). 13 | * NoFussXML, see [http://i42.co.uk/stuff/NoFussXML.htm](http://i42.co.uk/stuff/NoFussXML.htm). 14 | * NoFussJSON, a fast JSON and Relaxed JSON parser/generator. 15 | * packet stream network library (based on Boost.Asio). 16 | * plugin framework; uses interfaces (vtables) similar to Microsoft's COM with support for containers/iterators and polymorphic variants and enums. 17 | * ECS (Entity-Component-System) including power management (green/turbo modes) and a time system. 18 | * vector/matrix math library with SIMD support 19 | -------------------------------------------------------------------------------- /include/neolib/app/application.hpp: -------------------------------------------------------------------------------- 1 | // application.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace neolib 46 | { 47 | template 48 | class application : public reference_counted 49 | { 50 | public: 51 | application(const i_application_info& aApplicationInfo, i_service_provider& aServiceProvider = allocate_service_provider()) : 52 | iServiceProvider{ aServiceProvider }, 53 | iApplicationInfo{ get_application_info(aApplicationInfo) }, 54 | iPluginManager{ *this } 55 | { 56 | } 57 | public: 58 | // from i_discoverable 59 | bool discover(const uuid& aId, void*& aObject) override 60 | { 61 | return iPluginManager.discover(aId, aObject); 62 | } 63 | // from i_application 64 | public: 65 | i_service_provider& service_provider() const override 66 | { 67 | return iServiceProvider; 68 | } 69 | public: 70 | const i_application_info& info() const override 71 | { 72 | return iApplicationInfo; 73 | } 74 | i_plugin_manager& plugin_manager() override 75 | { 76 | return iPluginManager; 77 | } 78 | private: 79 | i_service_provider& iServiceProvider; 80 | application_info iApplicationInfo; 81 | neolib::plugin_manager iPluginManager; 82 | }; 83 | } 84 | -------------------------------------------------------------------------------- /include/neolib/app/i_application.hpp: -------------------------------------------------------------------------------- 1 | // i_application.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace neolib 46 | { 47 | class i_application : public i_discoverable 48 | { 49 | public: 50 | virtual i_service_provider& service_provider() const = 0; 51 | public: 52 | virtual const i_application_info& info() const = 0; 53 | virtual i_plugin_manager& plugin_manager() = 0; 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /include/neolib/app/i_application_info.hpp: -------------------------------------------------------------------------------- 1 | // i_application_info.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace neolib 44 | { 45 | struct unknown_application_name : std::logic_error { unknown_application_name() : std::logic_error{ "neolib::unknown_application_name " } {} }; 46 | 47 | class i_program_arguments 48 | { 49 | public: 50 | typedef i_program_arguments abstract_type; 51 | public: 52 | virtual ~i_program_arguments() = default; 53 | public: 54 | virtual int argc() const = 0; 55 | virtual char** argv() const = 0; 56 | virtual const i_vector& as_vector() const = 0; 57 | }; 58 | 59 | class i_application_info 60 | { 61 | public: 62 | virtual ~i_application_info() = default; 63 | public: 64 | virtual const i_program_arguments& arguments() const = 0; 65 | virtual const i_string& name() const = 0; 66 | virtual const i_string& company() const = 0; 67 | virtual const i_version& version() const = 0; 68 | virtual const i_string& copyright() const = 0; 69 | virtual const i_string& application_folder(bool aUseDefault = true) const = 0; 70 | virtual const i_string& settings_folder(bool aUseDefault = true) const = 0; 71 | virtual const i_string& data_folder(bool aUseDefault = true) const = 0; 72 | virtual const i_string& plugin_extension() const = 0; 73 | virtual bool removable() const = 0; 74 | }; 75 | } 76 | -------------------------------------------------------------------------------- /include/neolib/app/i_object.hpp: -------------------------------------------------------------------------------- 1 | // i_object.hpp 2 | /* 3 | * Copyright (c) 2019, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace neolib 44 | { 45 | class i_object : public i_lifetime 46 | { 47 | public: 48 | declare_event(destroying); 49 | declare_event(destroyed); 50 | public: 51 | virtual ~i_object() = default; 52 | }; 53 | 54 | template 55 | inline bool is_alive(Object& aObject) 56 | { 57 | if constexpr (std::is_base_of_v) 58 | return static_cast(aObject).is_alive(); 59 | else 60 | return dynamic_cast(aObject).is_alive(); 61 | } 62 | 63 | template 64 | inline auto destroying(Object& aObject, const Handler aHandler) 65 | { 66 | if constexpr (std::is_base_of_v) 67 | return static_cast(aObject).destroying(aHandler); 68 | else 69 | return dynamic_cast(aObject).destroying(aHandler); 70 | } 71 | 72 | template 73 | inline auto destroyed(Object& aObject, const Handler aHandler) 74 | { 75 | if constexpr (std::is_base_of_v) 76 | return static_cast(aObject).destroyed(aHandler); 77 | else 78 | return dynamic_cast(aObject).destroyed(aHandler); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /include/neolib/app/i_setting_constraints.hpp: -------------------------------------------------------------------------------- 1 | // i_setting_constraints.hpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace neolib 44 | { 45 | class i_setting_constraints 46 | { 47 | public: 48 | virtual ~i_setting_constraints() = default; 49 | public: 50 | virtual bool optional() const = 0; 51 | virtual bool initially_disabled() const = 0; 52 | virtual bool has_minimum_value() const = 0; 53 | virtual bool has_maximum_value() const = 0; 54 | virtual bool has_step_value() const = 0; 55 | virtual bool has_allowable_values() const = 0; 56 | virtual i_setting_value const& minimum_value() const = 0; 57 | virtual i_setting_value const& maximum_value() const = 0; 58 | virtual i_setting_value const& step_value() const = 0; 59 | virtual i_vector const& allowable_values() const = 0; 60 | public: 61 | template 62 | abstract_return_t minimum_value() const 63 | { 64 | return minimum_value().get(); 65 | } 66 | template 67 | abstract_return_t maximum_value() const 68 | { 69 | return maximum_value().get(); 70 | } 71 | template 72 | abstract_return_t step_value() const 73 | { 74 | return step_value().get(); 75 | } 76 | }; 77 | } 78 | -------------------------------------------------------------------------------- /include/neolib/app/i_version.hpp: -------------------------------------------------------------------------------- 1 | // i_version.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | namespace neolib 45 | { 46 | class i_version 47 | { 48 | public: 49 | virtual uint32_t version_major() const = 0; 50 | virtual uint32_t version_minor() const = 0; 51 | virtual uint32_t version_maintenance() const = 0; 52 | virtual uint32_t version_build() const = 0; 53 | virtual const i_string& version_name() const = 0; 54 | }; 55 | 56 | inline std::ostream& operator<<(std::ostream& aStream, const i_version& aVersion) 57 | { 58 | aStream << aVersion.version_major() << "." << aVersion.version_minor() << "." << aVersion.version_maintenance(); 59 | if (aVersion.version_build() != 0) 60 | aStream << "." << aVersion.version_build(); 61 | if (!aVersion.version_name().empty()) 62 | aStream << " " << aVersion.version_name(); 63 | return aStream; 64 | } 65 | 66 | inline std::string to_string(const i_version& aVersion) 67 | { 68 | std::stringstream oss; 69 | oss << aVersion; 70 | return oss.str(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /include/neolib/app/module.hpp: -------------------------------------------------------------------------------- 1 | // module.hpp v1.0.1 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib 43 | { 44 | class os_module; 45 | 46 | class NEOLIB_EXPORT module 47 | { 48 | // types 49 | private: 50 | typedef std::unique_ptr os_module_ptr; 51 | // construction 52 | public: 53 | module(); 54 | module(const module& aOther); 55 | module(module&& aOther); 56 | module(const std::string& aPath); 57 | ~module(); 58 | // assignment 59 | public: 60 | module& operator=(const module& aOther); 61 | module& operator=(module&& aOther); 62 | // operations 63 | public: 64 | const std::string& path() const { return iPath; } 65 | bool load(); 66 | void unload(); 67 | bool loaded() const; 68 | void* procedure_address(const std::string& aProcedureName); 69 | template 70 | FunctionType procedure(const std::string& aProcedureName) 71 | { 72 | return reinterpret_cast(procedure_address(aProcedureName)); 73 | } 74 | // attributes 75 | private: 76 | std::string iPath; 77 | os_module_ptr iOsModule; 78 | }; 79 | } 80 | -------------------------------------------------------------------------------- /include/neolib/app/object.hpp: -------------------------------------------------------------------------------- 1 | // object.hpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | namespace neolib 45 | { 46 | template 47 | class object : public lifetime 48 | { 49 | typedef lifetime base_type; 50 | public: 51 | define_declared_event(Destroying, destroying); 52 | define_declared_event(Destroyed, destroyed); 53 | public: 54 | object(lifetime_state aState = lifetime_state::Creating) : 55 | base_type{ aState } 56 | { 57 | } 58 | ~object() 59 | { 60 | set_destroyed(); 61 | } 62 | // i_lifetime 63 | public: 64 | using base_type::is_alive; 65 | using base_type::is_destroyed; 66 | void set_destroying() override 67 | { 68 | if (is_alive()) 69 | { 70 | Destroying.trigger(); 71 | base_type::set_destroying(); 72 | } 73 | } 74 | void set_destroyed() override 75 | { 76 | if (!is_destroyed()) 77 | { 78 | Destroyed.trigger(); 79 | base_type::set_destroyed(); 80 | } 81 | } 82 | }; 83 | } 84 | -------------------------------------------------------------------------------- /include/neolib/app/os_version.hpp: -------------------------------------------------------------------------------- 1 | // os_version.hpp 2 | /* 3 | * Parts Copyright (c) 2007 Leigh Johnston. 4 | * The author makes no representations about the 5 | * suitability of this software for any purpose. It is provided 6 | * "as is" without express or implied warranty. 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace neolib 15 | { 16 | NEOLIB_EXPORT std::string os_name(); 17 | NEOLIB_EXPORT application_info get_application_info(i_application_info const& aAppInfo); 18 | } -------------------------------------------------------------------------------- /include/neolib/app/ostream_logger.hpp: -------------------------------------------------------------------------------- 1 | // ostream_logger.hpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib 43 | { 44 | namespace logger 45 | { 46 | template > 47 | class basic_ostream_logger : public logger 48 | { 49 | typedef logger base_type; 50 | protected: 51 | using typename base_type::buffer_t; 52 | public: 53 | basic_ostream_logger(std::basic_ostream& aStream) : 54 | iStream{ aStream } 55 | { 56 | } 57 | ~basic_ostream_logger() 58 | { 59 | finalize(); 60 | } 61 | public: 62 | using base_type::finalize; 63 | protected: 64 | void commit(buffer_t const& aBuffer) override 65 | { 66 | iStream << aBuffer << std::flush; 67 | } 68 | protected: 69 | using base_type::set_destroying; 70 | private: 71 | std::basic_ostream& iStream; 72 | }; 73 | 74 | template 75 | using ostream_logger = basic_ostream_logger; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /include/neolib/app/power.hpp: -------------------------------------------------------------------------------- 1 | // power.hpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | namespace neolib 45 | { 46 | class NEOLIB_EXPORT power : public i_power 47 | { 48 | public: 49 | define_declared_event(ActivityRegistered, activity_registered) 50 | define_declared_event(GreenModeEnabled, green_mode_enabled) 51 | define_declared_event(GreenModeDisabled, green_mode_disabled) 52 | define_declared_event(GreenModeEntered, green_mode_entered) 53 | define_declared_event(GreenModeLeft, green_mode_left) 54 | define_declared_event(TurboModeEnabled, turbo_mode_enabled) 55 | define_declared_event(TurboModeDisabled, turbo_mode_disabled) 56 | define_declared_event(TurboModeEntered, turbo_mode_entered) 57 | define_declared_event(TurboModeLeft, turbo_mode_left) 58 | public: 59 | power(); 60 | public: 61 | power_mode active_mode() const override; 62 | public: 63 | void register_activity() override; 64 | std::chrono::seconds activity_timeout() const override; 65 | void set_activity_timeout(std::chrono::seconds aTimeout) override; 66 | public: 67 | bool is_green_mode_enabled() const override; 68 | void enable_green_mode() override; 69 | void disable_green_mode() override; 70 | private: 71 | void set_active_mode(power_mode aMode); 72 | private: 73 | neolib::callback_timer iUpdater; 74 | power_mode iActiveMode; 75 | bool iGreenModeEnabled; 76 | std::chrono::seconds iActivityTimeout; 77 | std::chrono::steady_clock::time_point iLastActivityTime; 78 | }; 79 | } -------------------------------------------------------------------------------- /include/neolib/app/shared_thread_local.hpp: -------------------------------------------------------------------------------- 1 | // shared_thread_local.hpp 2 | /* 3 | * Copyright (c) 2023 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | class shared_thread_local : public i_shared_thread_local 44 | { 45 | public: 46 | result_type allocate_or_get(char const* aFullyQualifiedVariableName, std::size_t aVariableSize, void(*aDeleter)(void*)) final; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /include/neolib/core/crc.hpp: -------------------------------------------------------------------------------- 1 | // crc.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | NEOLIB_EXPORT uint32_t crc32(const uint8_t *aData, uint32_t aDataLength); 43 | } 44 | -------------------------------------------------------------------------------- /include/neolib/core/fast_hash.hpp: -------------------------------------------------------------------------------- 1 | // fast_hash.hpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | namespace detail 43 | { 44 | template 45 | inline T fast_hash(const void* aInput, std::size_t aLength); 46 | 47 | // https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function 48 | 49 | template <> 50 | inline uint32_t fast_hash(const void* aInput, std::size_t aLength) 51 | { 52 | uint32_t hash = 2166136261u; 53 | const uint8_t* octet = static_cast(aInput); 54 | auto endOctet = octet + aLength; 55 | while (octet != endOctet) 56 | { 57 | hash = hash ^ *octet++; 58 | hash = hash * 16777619u; 59 | } 60 | return hash; 61 | } 62 | 63 | template <> 64 | inline uint64_t fast_hash(const void* aInput, std::size_t aLength) 65 | { 66 | uint64_t hash = 14695981039346656037ull; 67 | const uint8_t* octet = static_cast(aInput); 68 | auto endOctet = octet + aLength; 69 | while (octet != endOctet) 70 | { 71 | hash = hash ^ *octet++; 72 | hash = hash * 1099511628211ull; 73 | } 74 | return hash; 75 | } 76 | } 77 | 78 | template 79 | inline T fast_hash(const void* aInput, std::size_t aLength) 80 | { 81 | return detail::fast_hash(aInput, aLength); 82 | } 83 | 84 | inline uint32_t fast_hash(const void* aInput, std::size_t aLength) 85 | { 86 | return fast_hash(aInput, aLength); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /include/neolib/core/fast_vector.hpp: -------------------------------------------------------------------------------- 1 | // fast_vector.hpp 2 | /* 3 | * Copyright (c) 2024 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | template 44 | using fast_vector = boost::container::small_vector; 45 | } 46 | -------------------------------------------------------------------------------- /include/neolib/core/fwd_abstract.hpp: -------------------------------------------------------------------------------- 1 | // fwd_abstract.hpp 2 | /* 3 | * Copyright (c) 2019 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | class i_string; 43 | class string; 44 | 45 | template 46 | struct abstract_interface { typedef ConcreteType type; }; 47 | 48 | template <> 49 | struct abstract_interface { typedef i_string type; }; 50 | 51 | template 52 | using abstract_interface_t = typename abstract_interface::type; 53 | } 54 | -------------------------------------------------------------------------------- /include/neolib/core/hive.hpp: -------------------------------------------------------------------------------- 1 | // hive.hpp 2 | /* 3 | * Copyright (c) 2023 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | using namespace plf; 44 | } -------------------------------------------------------------------------------- /include/neolib/core/i_custom_type_factory.hpp: -------------------------------------------------------------------------------- 1 | // i_custom_type_factory.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | namespace neolib 45 | { 46 | class i_custom_type_factory : public i_reference_counted 47 | { 48 | public: 49 | struct unsupported_custom_type : std::runtime_error { unsupported_custom_type(const std::string& aType) : std::runtime_error{ "neolib::i_custom_type_factory::unsupported_custom_type: " + aType } {} }; 50 | public: 51 | typedef i_custom_type_factory abstract_type; 52 | public: 53 | virtual void create(const i_string& aType, const i_string& aValue, i_ref_ptr& aObject) const = 0; 54 | public: 55 | ref_ptr create(const i_string& aType, const i_string& aValue) const 56 | { 57 | ref_ptr object; 58 | create(aType, aValue, object); 59 | return object; 60 | } 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /include/neolib/core/i_deque.hpp: -------------------------------------------------------------------------------- 1 | // i_deque.hpp 2 | /* 3 | * Copyright (c) 2021 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | template 44 | class i_deque : public i_random_access_container 45 | { 46 | typedef i_deque self_type; 47 | typedef i_random_access_container base_type; 48 | public: 49 | typedef self_type abstract_type; 50 | using typename base_type::const_iterator; 51 | using typename base_type::iterator; 52 | using typename base_type::const_reverse_iterator; 53 | using typename base_type::reverse_iterator; 54 | public: 55 | virtual void push_front(const T& aValue) = 0; 56 | virtual void pop_front() = 0; 57 | virtual const T& front() const = 0; 58 | virtual T& front() = 0; 59 | }; 60 | } 61 | -------------------------------------------------------------------------------- /include/neolib/core/i_discoverable.hpp: -------------------------------------------------------------------------------- 1 | // i_discoverable.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib 43 | { 44 | class i_discoverable : public i_reference_counted 45 | { 46 | public: 47 | template 48 | bool discover(i_ref_ptr& aObject) 49 | { 50 | void* result = nullptr; 51 | if (discover(Interface::iid(), result)) 52 | aObject.reset(static_cast(result)); 53 | return result != nullptr; 54 | } 55 | virtual bool discover(const uuid& aId, void*& aObject) = 0; 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /include/neolib/core/i_lifetime.hpp: -------------------------------------------------------------------------------- 1 | // i_lifetime.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace neolib 44 | { 45 | class i_lifetime_flag 46 | { 47 | public: 48 | virtual ~i_lifetime_flag() = default; 49 | public: 50 | virtual bool is_creating() const = 0; 51 | virtual bool is_alive() const = 0; 52 | virtual bool is_destroying() const = 0; 53 | virtual bool is_destroyed() const = 0; 54 | virtual operator bool() const = 0; 55 | public: 56 | virtual bool debug() const = 0; 57 | virtual void set_debug(bool aDebug = true) = 0; 58 | }; 59 | 60 | enum class lifetime_state 61 | { 62 | Creating, 63 | Alive, 64 | Destroying, 65 | Destroyed 66 | }; 67 | 68 | class i_lifetime 69 | { 70 | public: 71 | struct not_creating : std::logic_error { not_creating() : std::logic_error("i_lifetime::not_creating") {} }; 72 | struct already_destroyed : std::logic_error { already_destroyed() : std::logic_error("i_lifetime::already_destroyed") {} }; 73 | public: 74 | virtual ~i_lifetime() = default; 75 | public: 76 | virtual lifetime_state object_state() const = 0; 77 | virtual std::shared_ptr> object_state_ptr() const = 0; // todo: not polymorphic; use ref_ptr? 78 | virtual bool is_creating() const = 0; 79 | virtual bool is_alive() const = 0; 80 | virtual bool is_destroying() const = 0; 81 | virtual bool is_destroyed() const = 0; 82 | virtual void set_alive() = 0; 83 | virtual void set_destroying() = 0; 84 | virtual void set_destroyed() = 0; 85 | }; 86 | } 87 | -------------------------------------------------------------------------------- /include/neolib/core/i_list.hpp: -------------------------------------------------------------------------------- 1 | // i_list.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | template 44 | class i_list : public i_sequence_container, i_iterator > 45 | { 46 | typedef i_list self_type; 47 | typedef i_sequence_container, i_iterator > base_type; 48 | public: 49 | typedef self_type abstract_type; 50 | typedef typename base_type::size_type size_type; 51 | public: 52 | virtual void push_front(const T& aValue) = 0; 53 | virtual void pop_front() = 0; 54 | virtual const T& front() const = 0; 55 | virtual T& front() = 0; 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /include/neolib/core/i_mutex.hpp: -------------------------------------------------------------------------------- 1 | // i_mutex.hpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | struct i_lockable 43 | { 44 | virtual void lock() noexcept = 0; 45 | virtual void unlock() noexcept = 0; 46 | virtual bool try_lock() noexcept = 0; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /include/neolib/core/i_pair.hpp: -------------------------------------------------------------------------------- 1 | // i_pair.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | template 43 | class i_pair 44 | { 45 | typedef i_pair self_type; 46 | public: 47 | typedef self_type abstract_type; 48 | typedef T1 first_type; 49 | typedef T2 second_type; 50 | public: 51 | virtual self_type& operator=(const self_type& aRhs) = 0; 52 | public: 53 | virtual const first_type& first() const = 0; 54 | virtual first_type& first() = 0; 55 | virtual const second_type& second() const = 0; 56 | virtual second_type& second() = 0; 57 | public: 58 | friend void swap(self_type& a, self_type& b) 59 | { 60 | using std::swap; 61 | swap(a.first(), b.first()); 62 | swap(a.second(), b.second()); 63 | } 64 | public: 65 | constexpr bool operator==(const self_type& that) const noexcept 66 | { 67 | return first() == that.first() && second() == that.second(); 68 | } 69 | constexpr std::partial_ordering operator<=>(const self_type& that) const noexcept 70 | { 71 | if (*this == that) 72 | return std::partial_ordering::equivalent; 73 | else if (std::forward_as_tuple(first(), second()) < std::forward_as_tuple(that.first(), that.second())) 74 | return std::partial_ordering::less; 75 | else 76 | return std::partial_ordering::greater; 77 | } 78 | }; 79 | } 80 | -------------------------------------------------------------------------------- /include/neolib/core/i_random_access_container.hpp: -------------------------------------------------------------------------------- 1 | // i_random_access_container.hpp 2 | /* 3 | * Copyright (c) 2019, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | template 44 | class i_random_access_container : public i_sequence_container, i_random_access_iterator> 45 | { 46 | typedef i_random_access_container self_type; 47 | typedef i_sequence_container, i_random_access_iterator> base_type; 48 | public: 49 | typedef self_type abstract_type; 50 | public: 51 | using typename base_type::value_type; 52 | using typename base_type::size_type; 53 | public: 54 | using base_type::size; 55 | public: 56 | virtual const value_type& at(size_type aIndex) const = 0; 57 | virtual value_type& at(size_type aIndex) = 0; 58 | virtual const value_type& operator[](size_type aIndex) const = 0; 59 | virtual value_type& operator[](size_type aIndex) = 0; 60 | }; 61 | } 62 | -------------------------------------------------------------------------------- /include/neolib/core/i_variant.hpp: -------------------------------------------------------------------------------- 1 | // i_variant.hpp 2 | /* 3 | * Copyright (c) 2021 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace neolib 46 | { 47 | template 48 | class i_variant : public i_reference_counted 49 | { 50 | typedef i_variant self_type; 51 | public: 52 | typedef self_type abstract_type; 53 | public: 54 | virtual ~i_variant() = default; 55 | public: 56 | virtual std::size_t index() const = 0; 57 | private: 58 | virtual void const* ptr() const = 0; 59 | virtual void* ptr() = 0; 60 | public: 61 | template 62 | bool holds_alternative() const 63 | { 64 | return index() == variadic::index_v + 1; 65 | } 66 | template 67 | T const* get_if() const 68 | { 69 | if (holds_alternative()) 70 | return static_cast(ptr()); 71 | return nullptr; 72 | } 73 | template 74 | T* get_if() 75 | { 76 | if (holds_alternative()) 77 | return static_cast(ptr()); 78 | return nullptr; 79 | } 80 | template 81 | T const& get() const 82 | { 83 | if (holds_alternative()) 84 | return *get_if(); 85 | throw std::bad_variant_access(); 86 | } 87 | template 88 | T& get() 89 | { 90 | if (holds_alternative()) 91 | return *get_if(); 92 | throw std::bad_variant_access(); 93 | } 94 | }; 95 | } 96 | -------------------------------------------------------------------------------- /include/neolib/core/i_vector.hpp: -------------------------------------------------------------------------------- 1 | // i_vector.hpp 2 | /* 3 | * Copyright (c) 2019, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | template 44 | class i_vector : public i_contiguous_random_access_container 45 | { 46 | typedef i_vector self_type; 47 | typedef i_contiguous_random_access_container base_type; 48 | public: 49 | typedef self_type abstract_type; 50 | public: 51 | using typename base_type::value_type; 52 | using typename base_type::const_iterator; 53 | using typename base_type::iterator; 54 | using typename base_type::const_reverse_iterator; 55 | using typename base_type::reverse_iterator; 56 | public: 57 | // todo abstract push_back et al 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /include/neolib/core/memory.hpp: -------------------------------------------------------------------------------- 1 | // memory.hpp v2.4.1 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | /* WARNING: The classes present here are not a substitute for any equivalent std:: 37 | * classes available on your platform which you should be using instead. They exist here 38 | * either for technical reasons or for when there is no standard library available. 39 | */ 40 | 41 | #pragma once 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | namespace neolib 49 | { 50 | namespace detail 51 | { 52 | template inline 53 | void construct(void* mem, const T& object) 54 | { 55 | new (mem) T(object); 56 | } 57 | 58 | template inline 59 | OutIter uninitialized_copy_dispatch(InIter first, InIter last, OutIter result, std::false_type) 60 | { 61 | while (first != last) 62 | detail::construct(static_cast(&*result++), *first++); 63 | return result; 64 | } 65 | 66 | template inline 67 | T* uninitialized_copy_dispatch(const T* first, const T* last, T* result, std::true_type) 68 | { 69 | memcpy(result, first, (last - first) * sizeof(T)); 70 | result += (last - first); 71 | return result; 72 | } 73 | 74 | template inline 75 | OutIter uninitialized_copy(InIter first, InIter last, OutIter result, const T&) 76 | { 77 | return uninitialized_copy_dispatch(first, last, result, std::is_scalar::type()); 78 | } 79 | } 80 | 81 | template inline 82 | OutIter uninitialized_copy(InIter first, InIter last, OutIter result) 83 | { 84 | return detail::uninitialized_copy(first, last, result, *result); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /include/neolib/core/noncopyable.hpp: -------------------------------------------------------------------------------- 1 | // noncopyable.hpp v1.0 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | namespace neolib 39 | { 40 | class noncopyable 41 | { 42 | protected: 43 | constexpr noncopyable() = default; 44 | ~noncopyable() = default; 45 | noncopyable(const noncopyable&) = delete; 46 | noncopyable& operator=(const noncopyable&) = delete; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /include/neolib/core/recursion.hpp: -------------------------------------------------------------------------------- 1 | // recursion.hpp 2 | /* 3 | * Copyright (c) 2019, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | template 43 | class recursion_limiter 44 | { 45 | public: 46 | struct too_deep : std::runtime_error { too_deep() : std::runtime_error(std::string{ "Maximum recursion depth for '" } + typeid(Tag).name() + "' exceeded") {} }; 47 | public: 48 | recursion_limiter() : 49 | iMaxDepth{ Tag::RecursionLimit } 50 | { 51 | if (++depth() > max_depth()) 52 | throw too_deep(); 53 | } 54 | recursion_limiter(std::size_t aMaxDepth) : 55 | iMaxDepth{ aMaxDepth } 56 | { 57 | if (++depth() > max_depth()) 58 | throw too_deep(); 59 | } 60 | ~recursion_limiter() 61 | { 62 | --depth(); 63 | } 64 | public: 65 | std::size_t max_depth() const 66 | { 67 | return iMaxDepth; 68 | } 69 | static std::size_t& depth() 70 | { 71 | thread_local std::size_t tDepth; 72 | return tDepth; 73 | } 74 | private: 75 | const std::size_t iMaxDepth; 76 | }; 77 | } 78 | 79 | #define _limit_recursion_(a) neolib::recursion_limiter _##a##_recursion_limiter_ 80 | #define _limit_recursion_to_(a, b) neolib::recursion_limiter _##a##_recursion_limiter_{##b##} 81 | -------------------------------------------------------------------------------- /include/neolib/core/singleton.hpp: -------------------------------------------------------------------------------- 1 | // singleton.hpp v1.3 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | template 43 | class singleton 44 | { 45 | public: 46 | static T& instance() 47 | { 48 | static T sInstance; 49 | return sInstance; 50 | } 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /include/neolib/core/small_vector.hpp: -------------------------------------------------------------------------------- 1 | // small_vector.hpp 2 | /* 3 | * Copyright (c) 2024 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | template> 44 | using small_vector = growable_static_vector; 45 | } 46 | -------------------------------------------------------------------------------- /include/neolib/core/stdint.hpp: -------------------------------------------------------------------------------- 1 | // stdint.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | namespace stdint_suffix 44 | { 45 | constexpr std::int8_t operator "" _i8(unsigned long long v) 46 | { 47 | return static_cast(v); 48 | } 49 | 50 | constexpr std::uint8_t operator "" _u8(unsigned long long v) 51 | { 52 | return static_cast(v); 53 | } 54 | 55 | constexpr std::int16_t operator "" _i16(unsigned long long v) 56 | { 57 | return static_cast(v); 58 | } 59 | 60 | constexpr std::uint16_t operator "" _u16(unsigned long long v) 61 | { 62 | return static_cast(v); 63 | } 64 | 65 | constexpr std::int32_t operator "" _i32(unsigned long long v) 66 | { 67 | return static_cast(v); 68 | } 69 | 70 | constexpr std::uint32_t operator "" _u32(unsigned long long v) 71 | { 72 | return static_cast(v); 73 | } 74 | 75 | constexpr std::int64_t operator "" _i64(unsigned long long v) 76 | { 77 | return static_cast(v); 78 | } 79 | 80 | constexpr std::uint64_t operator "" _u64(unsigned long long v) 81 | { 82 | return static_cast(v); 83 | } 84 | 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /include/neolib/core/thread_local.hpp: -------------------------------------------------------------------------------- 1 | // thread_local.hpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib 43 | { 44 | template 45 | struct variable_stack 46 | { 47 | typedef T value_type; 48 | typedef std::unique_ptr pointer_type; 49 | typedef std::vector stack_type; 50 | 51 | std::size_t stackPointer = 0; 52 | stack_type stack; 53 | 54 | value_type& current() 55 | { 56 | auto& ptr = stack[stackPointer - 1]; 57 | if (ptr == nullptr) 58 | ptr = std::make_unique(); 59 | return *ptr; 60 | } 61 | 62 | void push() 63 | { 64 | ++stackPointer; 65 | if (stack.size() < stackPointer) 66 | stack.resize(stackPointer); 67 | } 68 | 69 | void pop() 70 | { 71 | --stackPointer; 72 | } 73 | }; 74 | 75 | template 76 | class variable_stack_context 77 | { 78 | public: 79 | variable_stack_context(variable_stack& aStack) : 80 | iStack{ aStack } 81 | { 82 | iStack.push(); 83 | } 84 | ~variable_stack_context() 85 | { 86 | iStack.pop(); 87 | } 88 | private: 89 | variable_stack& iStack; 90 | }; 91 | } 92 | -------------------------------------------------------------------------------- /include/neolib/core/tree.hpp: -------------------------------------------------------------------------------- 1 | // tree.h 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | template > 44 | using tree = segmented_tree; 45 | } 46 | -------------------------------------------------------------------------------- /include/neolib/core/utility.hpp: -------------------------------------------------------------------------------- 1 | // utility.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | /* WARNING: The classes present here are not a substitute for any equivalent std:: 37 | * classes available on your platform which you should be using instead. They exist here 38 | * either for technical reasons or for when there is no standard library available. 39 | */ 40 | 41 | #pragma once 42 | 43 | #include 44 | #include 45 | #include 46 | 47 | namespace neolib 48 | { 49 | template 50 | struct minmax : pair 51 | { 52 | typedef pair base_type; 53 | minmax() {} 54 | minmax(const T1& x, const T2& y) : pair(x, y) {} 55 | template minmax(const minmax& m) : pair(m.first(), m.second()) {} 56 | template minmax& operator=(const minmax& m) { base_type::first() = m.first(); base_type::second() = m.second(); return *this; } 57 | minmax operator-() const { minmax ret(-base_type::second(), -base_type::first()); return ret; } 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /include/neolib/core/variadic.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * variadic.hpp 3 | * 4 | * PUBLIC DOMAIN 5 | * 6 | * THIS SOURCE FILE IS PROVIDED BY THE CONTRIBUTORS "AS 7 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 8 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 9 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 10 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 11 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 12 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 13 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 14 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 15 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 16 | * SOURCE FILE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 | */ 18 | 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | namespace neolib 25 | { 26 | namespace variadic 27 | { 28 | template 29 | struct index; 30 | 31 | // found it 32 | template 33 | struct index : std::integral_constant {}; 34 | 35 | // still looking 36 | template 37 | struct index : std::integral_constant::value> {}; 38 | 39 | template 40 | constexpr size_t index_v = index::value; 41 | 42 | template 43 | constexpr size_t no_reference_index_v = index, R...>::value; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /include/neolib/core/vecarray.hpp: -------------------------------------------------------------------------------- 1 | // vecarray.hpp [deprecated] 2 | /* 3 | * Copyright (c) 2007,2023,2024 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | namespace detail 44 | { 45 | // deprecated 46 | template 47 | struct vecarray 48 | { 49 | using type = growable_static_vector; 50 | }; 51 | 52 | // deprecated 53 | template 54 | struct vecarray> 55 | { 56 | using type = static_vector; 57 | }; 58 | 59 | // deprecated 60 | template 61 | struct vecarray 62 | { 63 | using type = static_vector; 64 | }; 65 | } 66 | 67 | // deprecated 68 | template> 69 | using vecarray = typename detail::vecarray::type; 70 | } 71 | -------------------------------------------------------------------------------- /include/neolib/core/win32/win32.hpp: -------------------------------------------------------------------------------- 1 | // win32.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #pragma once 7 | 8 | #include 9 | 10 | #pragma warning (disable: 4355 ) // 'this' : used in base member initializer list 11 | #pragma warning (disable: 4258 ) // definition from the for loop is ignored; the definition from the enclosing scope is used 12 | #pragma warning (disable: 4503 ) // decorated name length exceeded, name was truncated 13 | #pragma warning (disable: 4351 ) // new behavior: elements of array 'xxx' will be default initialized 14 | #pragma warning (disable: 4512 ) // assignment operator could not be generated 15 | #pragma warning (disable: 4521 ) // multiple copy constructors specified 16 | #pragma warning (disable: 4996 ) // 'function': was declared deprecated 17 | #pragma warning (disable: 4345 ) // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized 18 | #pragma warning (disable: 4250 ) // class1' : inherits 'class2::member' via dominance 19 | #pragma warning (disable: 4834 ) // discarding return value of function with 'nodiscard' attribute 20 | #pragma warning (disable: 4459 ) // declaration of 'attr' hides global declaration 21 | #pragma warning (disable: 4100 ) // unreferenced formal parameter 22 | #pragma warning (disable: 4324 ) // structure was padded due to alignment specifier 23 | #pragma warning (disable: 4201 ) // nonstandard extension used : nameless struct / union 24 | 25 | #define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS 26 | 27 | #if _MSC_VER < 1900 28 | #pragma execution_character_set("utf-8") 29 | #define u8 30 | #endif 31 | 32 | #ifdef NDEBUG 33 | 34 | #ifndef _SCL_SECURE_NO_WARNINGS 35 | #define _SCL_SECURE_NO_WARNINGS 36 | #endif 37 | 38 | #ifndef _CRT_SECURE_NO_WARNINGS 39 | #define _CRT_SECURE_NO_WARNINGS 40 | #endif 41 | 42 | #ifdef _SECURE_SCL 43 | #undef _SECURE_SCL 44 | #endif 45 | #define _SECURE_SCL 0 46 | #ifdef _HAS_ITERATOR_DEBUGGING 47 | #undef _HAS_ITERATOR_DEBUGGING 48 | #endif 49 | #define _HAS_ITERATOR_DEBUGGING 0 50 | 51 | #endif 52 | 53 | #define _WIN32_WINNT _WIN32_WINNT_WINBLUE 54 | 55 | #define WIN32_LEAN_AND_MEAN 56 | #define NOMINMAX 57 | 58 | #ifdef USING_BOOST 59 | #define BOOST_USE_WINDOWS_H 60 | #endif 61 | 62 | namespace neolib 63 | { 64 | std::string win32_get_last_error_as_string(); 65 | } -------------------------------------------------------------------------------- /include/neolib/ecs/chrono.hpp: -------------------------------------------------------------------------------- 1 | // chrono.hpp 2 | /* 3 | * Copyright (c) 2015, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace neolib::ecs 44 | { 45 | namespace chrono 46 | { 47 | using namespace facebook::util; 48 | 49 | inline constexpr double to_milliseconds(const flicks ns) 50 | { 51 | return static_cast(std::chrono::duration_cast(std::chrono::duration(ns)).count()); 52 | } 53 | } 54 | 55 | using time_interval = primitives::scalar; 56 | using optional_time_interval = std::optional; 57 | using step_time_interval = std::int64_t; 58 | using optional_step_time_interval = std::optional; 59 | using step_time = step_time_interval; 60 | using optional_step_time = std::optional; 61 | 62 | inline step_time_interval to_step_time(time_interval aTime, step_time_interval aStepInterval) 63 | { 64 | auto fs = chrono::to_flicks(aTime).count(); 65 | return fs - (fs % aStepInterval); 66 | } 67 | 68 | inline step_time_interval to_step_time(optional_time_interval& aTime, step_time_interval aStepInterval) 69 | { 70 | if (aTime) 71 | return to_step_time(*aTime, aStepInterval); 72 | else 73 | return 0; 74 | } 75 | 76 | inline time_interval from_step_time(step_time_interval aStepTime) 77 | { 78 | return chrono::to_seconds(chrono::flicks{ aStepTime }); 79 | } 80 | } -------------------------------------------------------------------------------- /include/neolib/ecs/ecs_ids.hpp: -------------------------------------------------------------------------------- 1 | // ecs_ids.hpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib::ecs 43 | { 44 | using entity_archetype_id = neolib::uuid; 45 | using component_id = neolib::uuid; 46 | using system_id = neolib::uuid; 47 | 48 | using handle_t = void*; 49 | 50 | using id_t = neolib::cookie; 51 | constexpr id_t null_id = 0; 52 | using handle_id = id_t; 53 | using entity_id = id_t; 54 | constexpr entity_id null_entity = 0; 55 | } 56 | -------------------------------------------------------------------------------- /include/neolib/ecs/entity.hpp: -------------------------------------------------------------------------------- 1 | // entity.hpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib::ecs 43 | { 44 | class NEOLIB_EXPORT entity 45 | { 46 | public: 47 | entity(i_ecs& aEcs, entity_id aId); 48 | entity(i_ecs& aEcs, const entity_archetype_id& aArchetypeId); 49 | template 50 | entity(i_ecs& aEcs, const entity_archetype_id& aArchetypeId, ComponentData&&... aComponentData) : 51 | entity{ aEcs, aEcs.create_entity(aArchetypeId, aComponentData...) } {} 52 | ~entity(); 53 | public: 54 | entity(const entity& aOther) = delete; 55 | entity& operator=(const entity& aOther) = delete; 56 | public: 57 | i_ecs& ecs() const; 58 | entity_id id() const; 59 | bool detached_or_destroyed() const; 60 | entity_id detach(); 61 | private: 62 | i_ecs& iEcs; 63 | entity_id iId; 64 | sink iSink; 65 | }; 66 | } -------------------------------------------------------------------------------- /include/neolib/ecs/entity_archetype.hpp: -------------------------------------------------------------------------------- 1 | // entity_archetype.hpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | namespace neolib::ecs 47 | { 48 | class NEOLIB_EXPORT entity_archetype : public i_entity_archetype 49 | { 50 | private: 51 | typedef neolib::set, neolib::fast_pool_allocator> component_list; 52 | public: 53 | entity_archetype(const entity_archetype_id& aId, const std::string& aName, std::initializer_list aComponents); 54 | entity_archetype(const std::string& aName, std::initializer_list aComponents); 55 | entity_archetype(const entity_archetype& aOther); 56 | entity_archetype(entity_archetype&& aOther); 57 | public: 58 | const entity_archetype_id& id() const override; 59 | const i_string& name() const override; 60 | const i_set& components() const override; 61 | i_set& components() override; 62 | void populate_default_components(i_ecs& aEcs, entity_id aEntity) override; 63 | private: 64 | entity_archetype_id iId; 65 | string iName; 66 | component_list iComponents; 67 | }; 68 | } -------------------------------------------------------------------------------- /include/neolib/ecs/entity_life_span.hpp: -------------------------------------------------------------------------------- 1 | // entity_life_span.hpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace neolib::ecs 46 | { 47 | struct entity_life_span 48 | { 49 | i64 lifeSpan; 50 | 51 | struct meta : i_component_data::meta 52 | { 53 | static const neolib::uuid& id() 54 | { 55 | static const neolib::uuid sId = { 0x66736530, 0x521c, 0x4c2b, 0x9c60, { 0x2d, 0xe7, 0x8b, 0xd6, 0x58, 0xed } }; 56 | return sId; 57 | } 58 | static const neolib::i_string& name() 59 | { 60 | static const neolib::string sName = "Entity Life Span"; 61 | return sName; 62 | } 63 | static uint32_t field_count() 64 | { 65 | return 1; 66 | } 67 | static component_data_field_type field_type(uint32_t aFieldIndex) 68 | { 69 | switch (aFieldIndex) 70 | { 71 | case 0: 72 | return component_data_field_type::Int64; 73 | default: 74 | throw invalid_field_index(); 75 | } 76 | } 77 | static const neolib::i_string& field_name(uint32_t aFieldIndex) 78 | { 79 | static const neolib::string sFieldNames[] = 80 | { 81 | "Life Span" 82 | }; 83 | return sFieldNames[aFieldIndex]; 84 | } 85 | }; 86 | }; 87 | } -------------------------------------------------------------------------------- /include/neolib/ecs/i_entity_archetype.hpp: -------------------------------------------------------------------------------- 1 | // i_entity_archetype.hpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace neolib::ecs 46 | { 47 | class i_ecs; 48 | 49 | class i_entity_archetype 50 | { 51 | public: 52 | virtual const entity_archetype_id& id() const = 0; 53 | virtual const neolib::i_string& name() const = 0; 54 | virtual const neolib::i_set& components() const = 0; 55 | virtual neolib::i_set& components() = 0; 56 | virtual void populate_default_components(i_ecs& aEcs, entity_id aEntity) = 0; 57 | }; 58 | } -------------------------------------------------------------------------------- /include/neolib/ecs/time.hpp: -------------------------------------------------------------------------------- 1 | // time.hpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace neolib::ecs 44 | { 45 | class NEOLIB_EXPORT time : public system 46 | { 47 | private: 48 | class thread; 49 | public: 50 | time(i_ecs& aEcs); 51 | public: 52 | const system_id& id() const override; 53 | const neolib::i_string& name() const override; 54 | public: 55 | bool apply() override; 56 | public: 57 | step_time system_time() const; 58 | step_time world_time() const; 59 | public: 60 | struct meta 61 | { 62 | static const neolib::uuid& id() 63 | { 64 | static const neolib::uuid sId = { 0x714a0e4a, 0xd0be, 0x4737, 0xbd25, { 0xe8, 0x3e, 0x2a, 0x5c, 0xd7, 0x65 } }; 65 | return sId; 66 | } 67 | static const neolib::i_string& name() 68 | { 69 | static const neolib::string sName = "Time"; 70 | return sName; 71 | } 72 | }; 73 | private: 74 | mutable optional_step_time iSystemTimeOffset; 75 | }; 76 | } -------------------------------------------------------------------------------- /include/neolib/file/gunzip.hpp: -------------------------------------------------------------------------------- 1 | // gunzip.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | class NEOLIB_EXPORT gunzip 44 | { 45 | // types 46 | public: 47 | typedef std::vector compressed_data_t; 48 | typedef std::vector uncompressed_data_t; 49 | 50 | // construction 51 | public: 52 | gunzip(const compressed_data_t& aGzipData); 53 | 54 | // operations 55 | public: 56 | bool ok() const { return iOk; } 57 | const uncompressed_data_t& uncompressed_data() const { return iUncompressedData; } 58 | 59 | // attributes 60 | private: 61 | bool iOk; 62 | uncompressed_data_t iUncompressedData; 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /include/neolib/file/hexdump.hpp: -------------------------------------------------------------------------------- 1 | // hex_dump.hpp v1.0 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib 43 | { 44 | template 45 | inline void hex_dump(const void* aData, std::size_t aLength, std::basic_ostream& aStream, std::size_t aWidth = 16) 46 | { 47 | const char* const start = static_cast(aData); 48 | const char* const end = start + aLength; 49 | const char* line = start; 50 | while (line != end) 51 | { 52 | aStream.width(4); 53 | aStream.fill('0'); 54 | aStream << std::hex << line - start << " : "; 55 | std::size_t lineLength = std::min(aWidth, static_cast(end - line)); 56 | for (std::size_t pass = 1; pass <= 2; ++pass) 57 | { 58 | for (const char* next = line; next != end && next != line + aWidth; ++next) 59 | { 60 | char ch = *next; 61 | switch(pass) 62 | { 63 | case 1: 64 | aStream << (ch < 32 ? '.' : ch); 65 | break; 66 | case 2: 67 | if (next != line) 68 | aStream << " "; 69 | aStream.width(2); 70 | aStream.fill('0'); 71 | aStream << std::hex << std::uppercase << static_cast(static_cast(ch)); 72 | break; 73 | } 74 | } 75 | if (pass == 1 && lineLength != aWidth) 76 | aStream << std::string(aWidth - lineLength, ' '); 77 | aStream << " "; 78 | } 79 | aStream << std::endl; 80 | line = line + lineLength; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /include/neolib/file/zip.hpp: -------------------------------------------------------------------------------- 1 | // zip.h 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib 43 | { 44 | class zip 45 | { 46 | public: 47 | typedef std::vector buffer_type; 48 | public: 49 | struct zip_file_too_big : std::runtime_error { zip_file_too_big() : std::runtime_error("neolib::zip::zip_file_too_big") {} }; 50 | struct file_not_found : std::runtime_error { file_not_found() : std::runtime_error("neolib::zip::file_not_found") {} }; 51 | public: 52 | zip(const std::string& aZipFilePath); 53 | zip(const buffer_type& aZipFile); 54 | zip(buffer_type&& aZipFile); 55 | zip(const void* aZipFileData, std::size_t aZipFileDataLength); 56 | public: 57 | size_t file_count() const { return iFiles.size(); } 58 | std::size_t index_of(const std::string& aFile) const; 59 | bool extract(size_t aIndex, const std::string& aTargetDirectory); 60 | bool extract_to(size_t aIndex, buffer_type& aBuffer); 61 | std::string extract_to_string(size_t aIndex); 62 | const std::string& file_path(size_t aIndex) const; 63 | bool ok() const { return !iError; } 64 | private: 65 | bool parse(); 66 | const uint8_t* data_front(); 67 | const uint8_t* data_back(); 68 | private: 69 | buffer_type iZipFile; 70 | const uint8_t* iZipFileData; 71 | std::size_t iZipFileDataLength; 72 | bool iError; 73 | struct dir_header; 74 | struct dir_file_header; 75 | struct local_header; 76 | typedef unsigned long dword; 77 | typedef unsigned short word; 78 | typedef unsigned char byte; 79 | std::vector iDirEntries; 80 | std::vector iFiles; 81 | }; 82 | } 83 | -------------------------------------------------------------------------------- /include/neolib/io/i_packet.hpp: -------------------------------------------------------------------------------- 1 | // i_packet.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib 43 | { 44 | template 45 | class i_basic_packet 46 | { 47 | // types 48 | public: 49 | typedef CharType character_type; 50 | typedef const character_type* const_pointer; 51 | typedef character_type* pointer; 52 | typedef std::size_t size_type; 53 | typedef const_pointer const_iterator; 54 | typedef pointer iterator; 55 | typedef std::unique_ptr clone_pointer; 56 | // exceptions 57 | public: 58 | struct packet_empty : std::logic_error { packet_empty() : std::logic_error("i_basic_packet::packet_empty") {} }; 59 | struct packet_too_big : std::runtime_error { packet_too_big() : std::runtime_error("i_basic_packet::packet_too_big") {} }; 60 | // construction 61 | public: 62 | virtual ~i_basic_packet() = default; 63 | // interface 64 | public: 65 | virtual const_pointer data() const = 0; 66 | virtual pointer data() = 0; 67 | virtual size_type length() const = 0; 68 | virtual bool has_max_length() const = 0; 69 | virtual size_type max_length() const = 0; 70 | bool empty() const { return length() == 0; } 71 | virtual void clear() = 0; 72 | const_iterator begin() const { return !empty() ? data() : 0; } 73 | const_iterator end() const { return !empty() ? data() + length(): 0; } 74 | iterator begin() { return !empty() ? data() : 0; } 75 | iterator end() { return !empty() ? data() + length(): 0; } 76 | virtual bool take_some(const_pointer& aFirst, const_pointer aLast) = 0; 77 | virtual clone_pointer clone() const = 0; 78 | virtual void copy_from(const i_basic_packet& aSource) = 0; 79 | }; 80 | 81 | typedef i_basic_packet i_packet; 82 | } 83 | -------------------------------------------------------------------------------- /include/neolib/io/oauth.hpp: -------------------------------------------------------------------------------- 1 | // oauth.h 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | 48 | namespace neolib 49 | { 50 | class NEOLIB_EXPORT oauth 51 | { 52 | // events 53 | public: 54 | event<> started; 55 | event<> completed; 56 | event<> failure; 57 | 58 | // types 59 | public: 60 | typedef std::pair operation; 61 | 62 | // construction 63 | public: 64 | oauth(async_task& IoTask, const std::string& aConsumerKey, const std::string& aConsumerSecret, const operation& aRequestTokenOp, const operation& aUserAuthorizationOp, const operation& aAccessTokenOp); 65 | virtual ~oauth(); 66 | 67 | // operations 68 | public: 69 | void request(); 70 | 71 | // implementation 72 | private: 73 | 74 | // attributes 75 | private: 76 | http iHttpRequester; 77 | std::string iConsumerKey; 78 | std::string iConsumerSecret; 79 | operation iRequestTokenOp; 80 | operation iUserAuthorizationOp; 81 | operation iAccessTokenOp; 82 | }; 83 | } 84 | -------------------------------------------------------------------------------- /include/neolib/io/openssl.hpp: -------------------------------------------------------------------------------- 1 | // openssl.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | class NEOLIB_EXPORT openssl 44 | { 45 | private: 46 | static const std::size_t SEED_BUFFER_SIZE = 8; 47 | public: 48 | openssl(); 49 | ~openssl(); 50 | static openssl& instance(); 51 | public: 52 | bool generate_key(uint8_t* aKeyBuffer, std::size_t aKeySize); 53 | private: 54 | bool need_entropy() const; 55 | void generate_entropy(); 56 | }; 57 | } 58 | -------------------------------------------------------------------------------- /include/neolib/plugin/i_plugin.hpp: -------------------------------------------------------------------------------- 1 | // i_plugin.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | namespace neolib 45 | { 46 | class i_plugin : public i_discoverable 47 | { 48 | public: 49 | using abstract_type = i_plugin; 50 | public: 51 | virtual const uuid& id() const = 0; 52 | virtual const i_string& name() const = 0; 53 | virtual const i_string& description() const = 0; 54 | virtual const i_version& version() const = 0; 55 | virtual const i_string& copyright() const = 0; 56 | virtual bool loaded() const = 0; 57 | virtual bool initialized() const = 0; 58 | virtual bool enabled() const = 0; 59 | virtual bool load() = 0; 60 | virtual bool initialize() = 0; 61 | virtual void enable(bool aEnable) = 0; 62 | virtual bool unload() = 0; 63 | virtual bool open_uri(const i_string& aUri) = 0; 64 | }; 65 | } 66 | -------------------------------------------------------------------------------- /include/neolib/plugin/simple_variant.hpp: -------------------------------------------------------------------------------- 1 | // simple_variant.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | namespace neolib 50 | { 51 | typedef plugin_variant, ref_ptr> simple_variant; 52 | 53 | inline simple_variant from_string(std::string const& aString, simple_variant_type aType) 54 | { 55 | switch (aType) 56 | { 57 | case simple_variant_type::Boolean: 58 | if (aString == "true" || aString == "1") 59 | return true; 60 | else 61 | return false; 62 | case simple_variant_type::Integer: 63 | return string_to_int64(aString); 64 | case simple_variant_type::Real: 65 | return string_to_double(aString); 66 | case simple_variant_type::String: 67 | return aString; 68 | default: 69 | throw std::logic_error("neolib: cannot convert string to simple variant"); 70 | } 71 | } 72 | 73 | inline std::string to_string(simple_variant const& aVariant) 74 | { 75 | return to_string(static_cast(aVariant)); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /include/neolib/task/async_thread.hpp: -------------------------------------------------------------------------------- 1 | // async_thread.hpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | namespace neolib 44 | { 45 | class NEOLIB_EXPORT async_thread : public thread 46 | { 47 | // types 48 | private: 49 | struct queue_ref 50 | { 51 | async_event_queue& queue; 52 | destroyed_flag queueDestroyed; 53 | 54 | queue_ref(async_event_queue& queue) : 55 | queue{ queue }, 56 | queueDestroyed{ queue } 57 | {} 58 | }; 59 | // construction 60 | public: 61 | async_thread(async_task& aTask, const std::string& aName = "", bool aAttachToCurrentThread = false); 62 | ~async_thread(); 63 | // implemenation 64 | protected: 65 | void exec_preamble() override; 66 | void exec(yield_type aYieldType = yield_type::NoYield) override; 67 | private: 68 | async_task& iTask; 69 | std::optional iEventQueue; 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /include/neolib/task/i_message_queue.hpp: -------------------------------------------------------------------------------- 1 | // i_message_queue.hpp 2 | /* 3 | * Copyright (c) 2007,2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | class i_message_queue 43 | { 44 | public: 45 | virtual ~i_message_queue() = default; 46 | public: 47 | virtual bool have_message() const = 0; 48 | virtual int get_message() const = 0; 49 | virtual void bump() = 0; 50 | virtual bool in_idle() const = 0; 51 | virtual void idle() = 0; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /include/neolib/task/i_task.hpp: -------------------------------------------------------------------------------- 1 | // i_task.hpp 2 | /* 3 | * Copyright (c) 2007, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | 42 | namespace neolib 43 | { 44 | class i_task 45 | { 46 | // construction 47 | public: 48 | virtual ~i_task() = default; 49 | // operations 50 | public: 51 | virtual const std::string& name() const = 0; 52 | // implementation 53 | public: 54 | virtual void run(yield_type aYieldType = yield_type::NoYield) = 0; 55 | virtual bool do_work(yield_type aYieldType = yield_type::NoYield) = 0; 56 | virtual void cancel() = 0; 57 | virtual bool cancelled() const = 0; 58 | }; 59 | } 60 | -------------------------------------------------------------------------------- /include/neolib/task/i_thread.hpp: -------------------------------------------------------------------------------- 1 | // i_thread.hpp v1.0 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | enum class yield_type 43 | { 44 | NoYield, 45 | Yield, 46 | Sleep 47 | }; 48 | 49 | enum class thread_state 50 | { 51 | ReadyToStart, 52 | Starting, 53 | Started, 54 | Finished, 55 | Aborted, 56 | Cancelled, 57 | Error 58 | }; 59 | 60 | class i_thread 61 | { 62 | // exceptions 63 | public: 64 | struct nothing_to_do : std::logic_error { nothing_to_do() : std::logic_error{ "i_thread::nothing_to_do" } {} }; 65 | // construction 66 | public: 67 | virtual ~i_thread() = default; 68 | // operations 69 | public: 70 | virtual const std::string& name() const noexcept = 0; 71 | virtual thread_state state() const noexcept = 0; 72 | virtual bool finished() const noexcept = 0; 73 | virtual void abort(bool aWait = true) = 0; 74 | // implementation 75 | protected: 76 | virtual void exec_preamble() = 0; 77 | virtual void exec(yield_type aYieldType = yield_type::NoYield) = 0; 78 | }; 79 | } 80 | -------------------------------------------------------------------------------- /include/neolib/task/timer_object.hpp: -------------------------------------------------------------------------------- 1 | // timer_object.hpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace neolib 46 | { 47 | class NEOLIB_EXPORT timer_object : public lifetime> 48 | { 49 | public: 50 | timer_object(i_timer_service& aService); 51 | ~timer_object(); 52 | public: 53 | void expires_at(const std::chrono::steady_clock::time_point& aDeadline) override; 54 | void async_wait(i_timer_subscriber& aSubscriber) override; 55 | void unsubscribe(i_timer_subscriber& aSubscriber) override; 56 | void cancel() override; 57 | public: 58 | bool poll() override; 59 | public: 60 | bool debug() const override; 61 | void set_debug(bool aDebug) override; 62 | private: 63 | i_timer_service& iService; 64 | std::optional iExpiryTime; 65 | mutable std::recursive_mutex iSubscribersMutex; 66 | std::set> iSubscribers; 67 | #if !defined(NDEBUG) || defined(DEBUG_TIMER_OBJECTS) 68 | bool iDebug = false; 69 | #endif 70 | }; 71 | } 72 | -------------------------------------------------------------------------------- /include/neolib/task/waitable.hpp: -------------------------------------------------------------------------------- 1 | // waitable.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | 40 | namespace neolib 41 | { 42 | class waitable 43 | { 44 | public: 45 | virtual bool waitable_ready() const = 0; 46 | }; 47 | } 48 | -------------------------------------------------------------------------------- /neolibConfig.cmake.in: -------------------------------------------------------------------------------- 1 | set(NEOLIB_VERSION @PROJECT_VERSION@) 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/neolibTargets.cmake") 4 | 5 | find_package(Boost COMPONENTS chrono filesystem system REQUIRED) 6 | if(NOT @BUILD_SHARED_LIBS@) 7 | find_package(OpenSSL REQUIRED COMPONENTS SSL) 8 | find_package(ZLIB REQUIRED) 9 | endif() 10 | 11 | @PACKAGE_INIT@ 12 | -------------------------------------------------------------------------------- /src/core/crc.cpp: -------------------------------------------------------------------------------- 1 | // crc.cpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | namespace neolib 42 | { 43 | uint32_t crc32(const uint8_t *aData, uint32_t aDataLength) 44 | { 45 | return ::crc32(::crc32(0, NULL, 0), aData, aDataLength); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/core/uuid.cpp: -------------------------------------------------------------------------------- 1 | // uuid.cpp - v1.1 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace neolib 41 | { 42 | uuid generate_uuid() 43 | { 44 | uint8_t key[16]; 45 | if (!openssl::instance().generate_key(key, sizeof(key))) 46 | throw unable_to_generate_uuid(); 47 | uuid result{ 48 | *reinterpret_cast(&key[0]), 49 | *reinterpret_cast(&key[sizeof(uint32_t)]), 50 | *reinterpret_cast(&key[sizeof(uint32_t) + sizeof(uint16_t)]), 51 | *reinterpret_cast(&key[sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t)]), 52 | { 53 | key[sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) + 0], 54 | key[sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) + 1], 55 | key[sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) + 2], 56 | key[sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) + 3], 57 | key[sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) + 4], 58 | key[sizeof(uint32_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) + 5] 59 | } 60 | }; 61 | result.part3 = static_cast((result.part3 & (0x0FFF)) | (0x4 << 12)); 62 | result.part4 = static_cast((result.part4 & (0b0011111111111111)) | (0b10 << 14)); 63 | return result; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/ecs/entity.cpp: -------------------------------------------------------------------------------- 1 | // entity.cpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | namespace neolib::ecs 42 | { 43 | entity::entity(i_ecs& aEcs, entity_id aId) : 44 | iEcs{ aEcs }, iId{ aId } 45 | { 46 | iSink += ecs().entity_destroyed([this](entity_id aId) 47 | { 48 | if (aId == iId) 49 | iId = null_entity; 50 | }); 51 | } 52 | 53 | entity::entity(i_ecs& aEcs, const entity_archetype_id& aArchetypeId) : 54 | entity{ aEcs, aEcs.create_entity(aArchetypeId) } 55 | { 56 | } 57 | 58 | entity::~entity() 59 | { 60 | if (!detached_or_destroyed()) 61 | ecs().destroy_entity(iId); 62 | } 63 | 64 | i_ecs& entity::ecs() const 65 | { 66 | return iEcs; 67 | } 68 | 69 | entity_id entity::id() const 70 | { 71 | return iId; 72 | } 73 | 74 | bool entity::detached_or_destroyed() const 75 | { 76 | return iId == null_entity; 77 | } 78 | 79 | entity_id entity::detach() 80 | { 81 | ecs().archetype(ecs().component().entity_record(id()).archetypeId).populate_default_components(ecs(), id()); 82 | auto id = iId; 83 | iId = null_entity; 84 | return id; 85 | } 86 | } -------------------------------------------------------------------------------- /src/ecs/entity_archetype.cpp: -------------------------------------------------------------------------------- 1 | // entity_archetype.cpp 2 | /* 3 | * Copyright (c) 2018, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace neolib::ecs 41 | { 42 | entity_archetype::entity_archetype(const entity_archetype_id& aId, const std::string& aName, std::initializer_list aComponents) : 43 | iId{ aId }, iName{ aName }, iComponents{ aComponents } 44 | { 45 | } 46 | 47 | entity_archetype::entity_archetype(const std::string& aName, std::initializer_list aComponents) : 48 | iId{ neolib::generate_uuid() }, iName{ aName }, iComponents{ aComponents } 49 | { 50 | } 51 | 52 | entity_archetype::entity_archetype(const entity_archetype& aOther) : 53 | iId{ aOther.iId }, iName{ aOther.iName }, iComponents{ aOther.iComponents } 54 | { 55 | } 56 | 57 | entity_archetype::entity_archetype(entity_archetype&& aOther) : 58 | iId{ aOther.iId }, iName{ std::move(aOther.iName) }, iComponents{ std::move(aOther.iComponents) } 59 | { 60 | } 61 | 62 | const entity_archetype_id& entity_archetype::id() const 63 | { 64 | return iId; 65 | } 66 | 67 | const i_string& entity_archetype::name() const 68 | { 69 | return iName; 70 | } 71 | 72 | const i_set& entity_archetype::components() const 73 | { 74 | return iComponents; 75 | } 76 | 77 | i_set& entity_archetype::components() 78 | { 79 | return iComponents; 80 | } 81 | 82 | void entity_archetype::populate_default_components(i_ecs&, entity_id) 83 | { 84 | // nothing to do. 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/ecs/system.cpp: -------------------------------------------------------------------------------- 1 | // system.cpp 2 | /* 3 | * Copyright (c) 2024 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | namespace neolib::ecs 40 | { 41 | thread::thread(i_system& aOwner) : 42 | async_task{ "neolib::ecs::thread" }, async_thread{ *this, "neolib::ecs::thread" }, iOwner{ aOwner } 43 | { 44 | start(); 45 | } 46 | 47 | thread::~thread() 48 | { 49 | set_destroying(); 50 | if (iOwner.waiting()) 51 | iOwner.signal(); 52 | } 53 | 54 | bool thread::do_work(neolib::yield_type aYieldType) 55 | { 56 | bool didWork = async_task::do_work(aYieldType); 57 | if (iOwner.can_apply()) 58 | didWork = iOwner.apply() || didWork; 59 | if (iOwner.paused() && !iOwner.waiting()) 60 | iOwner.wait(); 61 | return didWork; 62 | } 63 | } -------------------------------------------------------------------------------- /src/io/oauth.cpp: -------------------------------------------------------------------------------- 1 | // oauth.cpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | namespace neolib 40 | { 41 | oauth::oauth(async_task& IoTask, const std::string& aConsumerKey, const std::string& aConsumerSecret, 42 | const operation& aRequestTokenOp, const operation& aUserAuthorizationOp, const operation& aAccessTokenOp) : 43 | iHttpRequester(IoTask), iConsumerKey(aConsumerKey), iConsumerSecret(aConsumerSecret), 44 | iRequestTokenOp(aRequestTokenOp), iUserAuthorizationOp(aUserAuthorizationOp), iAccessTokenOp(aAccessTokenOp) 45 | { 46 | // todo 47 | iHttpRequester.Started([](){}); 48 | iHttpRequester.Completed([](){}); 49 | iHttpRequester.Failure([](){}); 50 | } 51 | 52 | oauth::~oauth() 53 | { 54 | } 55 | 56 | void oauth::request() 57 | { 58 | // todo 59 | } 60 | } -------------------------------------------------------------------------------- /src/io/openssl.cpp: -------------------------------------------------------------------------------- 1 | // openssl.cpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #if OPENSSL_VERSION_NUMBER < 0x10100000 42 | static_assert(false, "OpenSSL version too old"); 43 | #endif 44 | 45 | namespace neolib 46 | { 47 | openssl::openssl() 48 | { 49 | } 50 | 51 | openssl::~openssl() 52 | { 53 | } 54 | 55 | openssl& openssl::instance() 56 | { 57 | static openssl sInstance; 58 | return sInstance; 59 | } 60 | 61 | bool openssl::generate_key(uint8_t* aKeyBuffer, std::size_t aKeySize) 62 | { 63 | while (need_entropy()) 64 | generate_entropy(); 65 | return RAND_bytes(aKeyBuffer, static_cast(aKeySize)) == 1; 66 | } 67 | 68 | bool openssl::need_entropy() const 69 | { 70 | return RAND_status() == 0; 71 | } 72 | 73 | void openssl::generate_entropy() 74 | { 75 | thread_local std::random_device tRandomDevice; 76 | thread_local std::random_device::result_type tSeedBuffer[SEED_BUFFER_SIZE]; 77 | for (std::size_t n = 0; n < SEED_BUFFER_SIZE; ++n) 78 | tSeedBuffer[n] = tRandomDevice(); 79 | RAND_seed(tSeedBuffer, sizeof(tSeedBuffer)); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/posix/app/posix_module.hpp: -------------------------------------------------------------------------------- 1 | // posix_module.cpp 2 | /* 3 | * Copyright (c) 2019, 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | 38 | namespace neolib 39 | { 40 | class os_module 41 | { 42 | // construction 43 | public: 44 | os_module(const std::string& aPath); 45 | os_module(const os_module& aOther); 46 | os_module(os_module&& aOther); 47 | ~os_module(); 48 | // assignment 49 | public: 50 | os_module& operator=(const os_module& aOther); 51 | os_module& operator=(os_module&& aOther); 52 | // operations 53 | public: 54 | bool load(const std::string& aPath); 55 | void unload(); 56 | bool loaded() const; 57 | void* procedure_address(const std::string& aProcedureName); 58 | // attributes 59 | private: 60 | void* iHandle; 61 | }; 62 | } -------------------------------------------------------------------------------- /src/task/async_thread.cpp: -------------------------------------------------------------------------------- 1 | // async_thread.cpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | 39 | namespace neolib 40 | { 41 | async_thread::async_thread(async_task& aTask, const std::string& aName, bool aAttachToCurrentThread) : 42 | neolib::thread{ aName, aAttachToCurrentThread }, iTask{ aTask } 43 | { 44 | iTask.join(*this); 45 | if (using_existing_thread()) 46 | { 47 | async_event_queue::instance().register_with_task(iTask); 48 | iEventQueue.emplace(async_event_queue::instance()); 49 | } 50 | } 51 | 52 | async_thread::~async_thread() 53 | { 54 | iTask.cancel(); 55 | iTask.set_destroying(); 56 | iTask.wait(); 57 | iTask.detach(); 58 | cancel(); 59 | } 60 | 61 | void async_thread::exec_preamble() 62 | { 63 | async_event_queue::instance().register_with_task(iTask); 64 | iEventQueue.emplace(async_event_queue::instance()); 65 | } 66 | 67 | void async_thread::exec(yield_type aYieldType) 68 | { 69 | iTask.run(aYieldType); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/win32/app/win32_module.hpp: -------------------------------------------------------------------------------- 1 | // win32_module.cpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | 38 | namespace neolib 39 | { 40 | class os_module 41 | { 42 | // construction 43 | public: 44 | os_module(const std::string& aPath); 45 | os_module(const os_module& aOther); 46 | os_module(os_module&& aOther); 47 | ~os_module(); 48 | // assignment 49 | public: 50 | os_module& operator=(const os_module& aOther); 51 | os_module& operator=(os_module&& aOther); 52 | // operations 53 | public: 54 | bool load(const std::string& aPath); 55 | void unload(); 56 | bool loaded() const; 57 | void* procedure_address(const std::string& aProcedureName); 58 | // attributes 59 | private: 60 | HMODULE iHandle; 61 | }; 62 | } -------------------------------------------------------------------------------- /src/win32/core/win32.cpp: -------------------------------------------------------------------------------- 1 | // win32.cpp 2 | /* 3 | * Copyright (c) 2020 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | namespace neolib 41 | { 42 | std::string win32_get_last_error_as_string() 43 | { 44 | DWORD errorMessageID = ::GetLastError(); 45 | if (errorMessageID == 0) 46 | return std::string(); 47 | 48 | LPSTR messageBuffer = nullptr; 49 | size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 50 | NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); 51 | 52 | std::string message(messageBuffer, size); 53 | 54 | LocalFree(messageBuffer); 55 | 56 | return message; 57 | } 58 | } -------------------------------------------------------------------------------- /src/win32/task/win32_message_queue.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "win32_message_queue.hpp" 4 | 5 | namespace neolib 6 | { 7 | std::map win32_message_queue::sTimerMap; 8 | 9 | win32_message_queue::win32_message_queue(async_task& aIoTask, std::function aIdleFunction, bool aCreateTimer) : 10 | iIoTask{ aIoTask }, 11 | iIdleFunction{ aIdleFunction }, 12 | iInIdle{ false } 13 | { 14 | if (aCreateTimer) 15 | { 16 | iTimer = ::SetTimer(NULL, 0, 10, &win32_message_queue::timer_proc); 17 | sTimerMap[iTimer] = this; 18 | } 19 | } 20 | 21 | win32_message_queue::~win32_message_queue() 22 | { 23 | for (auto& t : sTimerMap) 24 | ::KillTimer(NULL, t.first); 25 | } 26 | 27 | bool win32_message_queue::have_message() const 28 | { 29 | MSG msg; 30 | return ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) != 0; 31 | } 32 | 33 | int win32_message_queue::get_message() const 34 | { 35 | MSG msg; 36 | int result = ::GetMessage(&msg, NULL, 0, 0); 37 | if (result) 38 | { 39 | if (result != -1) 40 | { 41 | ::TranslateMessage(&msg); 42 | ::DispatchMessage(&msg); 43 | } 44 | } 45 | return result; 46 | } 47 | 48 | void win32_message_queue::bump() 49 | { 50 | ::PostMessage(NULL, WM_NULL, 0, 0); 51 | } 52 | 53 | bool win32_message_queue::in_idle() const 54 | { 55 | return iInIdle; 56 | } 57 | 58 | void win32_message_queue::idle() 59 | { 60 | if (!in_idle() && iIdleFunction) 61 | { 62 | scoped_flag sf{ iInIdle }; 63 | iIdleFunction(); 64 | } 65 | } 66 | 67 | void CALLBACK win32_message_queue::timer_proc(HWND, UINT, UINT_PTR aId, DWORD) 68 | { 69 | win32_message_queue& instance = *sTimerMap[aId]; 70 | instance.idle(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/win32/task/win32_message_queue.hpp: -------------------------------------------------------------------------------- 1 | // win32_message_queue.hpp 2 | /* 3 | * Copyright (c) 2007 Leigh Johnston. 4 | * 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are 9 | * met: 10 | * 11 | * * Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 14 | * * Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * * Neither the name of Leigh Johnston nor the names of any 19 | * other contributors to this software may be used to endorse or 20 | * promote products derived from this software without specific prior 21 | * written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | */ 35 | 36 | #pragma once 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | namespace neolib 46 | { 47 | class win32_message_queue : public i_message_queue 48 | { 49 | public: 50 | win32_message_queue(async_task& aIoTask, std::function aIdleFunction, bool aCreateTimer = true); 51 | ~win32_message_queue(); 52 | public: 53 | bool have_message() const override; 54 | int get_message() const override; 55 | void bump() override; 56 | bool in_idle() const override; 57 | void idle() override; 58 | private: 59 | static void CALLBACK timer_proc(HWND, UINT, UINT_PTR, DWORD); 60 | private: 61 | async_task& iIoTask; 62 | std::function iIdleFunction; 63 | static std::map sTimerMap; 64 | UINT_PTR iTimer; 65 | bool iInIdle; 66 | }; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /unit_tests/App/src/App.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int next_sequence() 7 | { 8 | static std::atomic sequence = 0; 9 | return ++sequence; 10 | } 11 | 12 | struct wibble 13 | { 14 | wibble() { std::cout << "wibble::wibble(), thread id: " << std::this_thread::get_id() << std::endl; } 15 | ~wibble() { std::cout << "wibble::~wibble(), thread id: " << std::this_thread::get_id() << std::endl; } 16 | }; 17 | 18 | template 19 | struct wobble 20 | { 21 | wobble() { f(); } 22 | int& f() { shared_thread_local_class(int, *this, f, n, next_sequence()); return n; } 23 | static int& sf() { shared_thread_local_class(int, wobble, sf, n, next_sequence()); return n; } 24 | }; 25 | 26 | namespace foo 27 | { 28 | int f() 29 | { 30 | shared_thread_local(int, foo::f, n, next_sequence()); 31 | shared_thread_local(wibble, foo::f, o); 32 | shared_thread_local(std::vector, foo::f, v, {}); 33 | v.push_back(42); 34 | return n; 35 | } 36 | } 37 | 38 | namespace bar 39 | { 40 | int f() 41 | { 42 | shared_thread_local(int, bar::f, n, next_sequence()); 43 | shared_thread_local(wibble, bar::f, o); 44 | shared_thread_local(std::vector, bar::f, v, {}); 45 | v.push_back(42); 46 | return n; 47 | } 48 | } 49 | 50 | namespace 51 | { 52 | void test_assert(bool assertion) 53 | { 54 | if (!assertion) 55 | throw std::logic_error("Test failed"); 56 | } 57 | } 58 | 59 | int main() 60 | { 61 | neolib::allocate_service_provider(); 62 | 63 | auto test = []() 64 | { 65 | test_assert(foo::f() == foo::f()); 66 | test_assert(bar::f() == bar::f()); 67 | test_assert(foo::f() != bar::f()); 68 | 69 | std::cout << foo::f() << " " << bar::f() << std::endl; 70 | 71 | wobble o1; 72 | wobble o2; 73 | 74 | test_assert(&o1.f() == &o1.f()); 75 | test_assert(&o2.f() == &o2.f()); 76 | test_assert(&o1.f() != &o2.f()); 77 | test_assert(&o1.sf() == &o1.sf()); 78 | test_assert(&o2.sf() == &o2.sf()); 79 | test_assert(&o1.sf() != &o2.sf()); 80 | 81 | test_assert(o1.f() == o1.f()); 82 | test_assert(o2.f() == o2.f()); 83 | test_assert(o1.f() != o2.f()); 84 | test_assert(o1.sf() == o1.sf()); 85 | test_assert(o2.sf() == o2.sf()); 86 | test_assert(o1.sf() != o2.sf()); 87 | }; 88 | 89 | test(); 90 | std::thread t1{ test }; 91 | std::thread t2{ test }; 92 | std::thread t3{ test }; 93 | std::thread t4{ test }; 94 | t1.join(); 95 | t2.join(); 96 | t3.join(); 97 | t4.join(); 98 | } -------------------------------------------------------------------------------- /unit_tests/Event/src/Event.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template class neolib::event; 5 | 6 | class greetings 7 | { 8 | public: 9 | neolib::event hello_and_goodbye; 10 | public: 11 | greetings() 12 | { 13 | iSink += hello_and_goodbye([this](const std::string& greeting) { handle_hello_and_goodbye(greeting); }); 14 | } 15 | ~greetings() 16 | { 17 | std::cout << "Destroying greetings object..." << std::endl; 18 | } 19 | public: 20 | void handle_hello_and_goodbye(const std::string& greeting) 21 | { 22 | static int phase; 23 | std::cout << "In handler, phase = " << phase << ", argument = '" << greeting << "'" << std::endl; 24 | switch (phase) 25 | { 26 | case 0: 27 | ++phase; 28 | hello_and_goodbye.trigger(", world!"); 29 | break; 30 | case 1: 31 | delete this; 32 | break; 33 | } 34 | } 35 | private: 36 | neolib::sink iSink; // performs the traditional role of slot handler de-registration 37 | }; 38 | 39 | class counter 40 | { 41 | public: 42 | neolib::event new_integer; 43 | neolib::event new_integer_ref; 44 | std::vector> refs; 45 | public: 46 | void count(int n) 47 | { 48 | for (int i = 1; i <= n; ++i) 49 | new_integer.trigger(i); 50 | for (int i = 1; i <= n; ++i) 51 | new_integer_ref.trigger(i); 52 | for (int i = 1; i <= n; ++i) 53 | new_integer.async_trigger(i); 54 | for (int i = 1; i <= n; ++i) 55 | { 56 | refs.push_back(std::make_shared(i)); 57 | int& ref = *refs.back(); 58 | new_integer_ref.async_trigger(ref); 59 | } 60 | } 61 | }; 62 | 63 | template<> neolib::i_async_task& neolib::services::start_service() 64 | { 65 | static neolib::async_task mainTask; 66 | static neolib::async_thread mainThread{ mainTask, "neolib::event unit test(s)", true }; 67 | return mainTask; 68 | } 69 | 70 | int main() 71 | { 72 | neolib::allocate_service_provider(); 73 | 74 | { 75 | // we shall use 'new' instead of smart pointer maker as greetings object will delete itself in event handler... 76 | auto object = new greetings{}; 77 | object->hello_and_goodbye.trigger("Hello"); 78 | } 79 | 80 | { 81 | counter c; 82 | { 83 | neolib::sink localSink; 84 | localSink += c.new_integer([](int n) 85 | { 86 | std::cout << "in sink: " << n << std::endl; 87 | }); 88 | localSink += ~~~~c.new_integer([](int n) 89 | { 90 | std::cout << "in sink: " << n << std::endl; 91 | }); 92 | localSink += c.new_integer_ref([](int& n) 93 | { 94 | std::cout << "in sink: " << n << std::endl; 95 | }); 96 | localSink += ~~~~c.new_integer_ref([](int& n) 97 | { 98 | std::cout << "in sink: " << n << std::endl; 99 | }); 100 | c.new_integer([](int n) 101 | { 102 | std::cout << "not in sink: " << n << std::endl; 103 | }); 104 | c.count(10); 105 | } 106 | c.count(10); // should only print "not in sink" 107 | neolib::async_event_queue::instance().pump_events(); 108 | } 109 | } -------------------------------------------------------------------------------- /unit_tests/Task/Task.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace test 7 | { 8 | struct thread : neolib::async_task, neolib::async_thread 9 | { 10 | thread() : async_task{ "test::task" }, async_thread{ *this, "test::thread" } 11 | { 12 | start(); 13 | } 14 | void exec_preamble() override 15 | { 16 | neolib::async_thread::exec_preamble(); 17 | timer.emplace(*this, [&](neolib::callback_timer&) 18 | { 19 | end = std::chrono::steady_clock::now(); 20 | }, std::chrono::milliseconds{ 100 }); 21 | } 22 | std::atomic> end; 23 | std::optional timer; 24 | }; 25 | } 26 | 27 | template<> neolib::i_async_task& neolib::services::start_service() 28 | { 29 | static neolib::async_task mainTask; 30 | static neolib::async_thread mainThread{ mainTask, "neolib::task unit test(s)", true }; 31 | return mainTask; 32 | } 33 | 34 | int main() 35 | { 36 | neolib::allocate_service_provider(); 37 | 38 | std::optional> stats; 39 | for (int32_t i = 1; i <= 200; ++i) 40 | { 41 | std::optional thread; 42 | thread.emplace(); 43 | while (thread->state() != neolib::thread_state::Started) 44 | std::this_thread::yield(); 45 | std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); 46 | while (thread->end.load() == std::nullopt) 47 | std::this_thread::yield(); 48 | auto time = std::chrono::duration(*thread->end.load() - start).count(); 49 | thread = std::nullopt; 50 | if (stats == std::nullopt) 51 | stats.emplace(time, time); 52 | else 53 | { 54 | stats->first = std::min(stats->first, time); 55 | stats->second = std::max(stats->second, time); 56 | } 57 | if (i % 20 == 0) 58 | std::cout << "Iteration #" << i << " time: " << time << " s" << ", min: " << stats->first << " s, max: " << stats->second << " s" << std::endl; 59 | if (time > 0.11) 60 | { 61 | std::cout << "Iteration #" << i << " FAILED, time: " << time << " s" << std::endl; 62 | throw std::logic_error("failed"); 63 | } 64 | } 65 | 66 | std::cout << std::endl; 67 | 68 | neolib::event e1; 69 | int total1 = 0; 70 | e1([&](int) 71 | { 72 | ++total1; 73 | }); 74 | auto start1 = std::chrono::high_resolution_clock::now(); 75 | for (int i = 0; i < 10000000; ++i) 76 | e1(42); 77 | auto end1 = std::chrono::high_resolution_clock::now(); 78 | std::cout << "neolib event emit rate: " << std::fixed << 79 | total1 / std::chrono::duration(end1 - start1).count() << "/sec" << std::endl; 80 | 81 | boost::signals2::signal e2; 82 | int total2 = 0; 83 | e2.connect([&](int) 84 | { 85 | ++total2; 86 | }); 87 | auto start2 = std::chrono::high_resolution_clock::now(); 88 | for (int i = 0; i < 10000000; ++i) 89 | e2(42); 90 | auto end2 = std::chrono::high_resolution_clock::now(); 91 | std::cout << "Boost.Signals2 emit rate: " << std::fixed << 92 | total2 / std::chrono::duration(end2 - start2).count() << "/sec" << std::endl; 93 | } -------------------------------------------------------------------------------- /unit_tests/threadpool.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | void benchmark_thread_pool() 8 | { 9 | neolib::thread_pool threadPool; 10 | 11 | std::vector v; 12 | const int ITERATIONS = 100000; 13 | v.resize(ITERATIONS); 14 | 15 | std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now(); 16 | 17 | for (int i = 0; i < ITERATIONS; ++i) 18 | threadPool.run([i, &v]() 19 | { 20 | v[i] = i; 21 | }); 22 | threadPool.wait(); 23 | 24 | std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now(); 25 | 26 | std::set s; 27 | for (auto n : v) 28 | s.insert(n); 29 | std::cout << "\ncheck: " << s.size() << "\ntime: " << std::chrono::duration_cast(end - begin).count() << "ms" << std::endl; 30 | } 31 | 32 | --------------------------------------------------------------------------------