From b0ff23aafa143ca054a62789d5391f0a0a9cda33 Mon Sep 17 00:00:00 2001 From: Babayaga Date: Tue, 3 Feb 2026 18:25:25 +0100 Subject: [PATCH] parameters --- .gitignore | 4 +- .npmignore | 4 - Blueprints.json | 25 + BlueprintsGraph.json | 4 + Blueprints_window.json | 10 + CMakeLists.txt | 33 + Doxyfile | 2 +- {examples => applications}/CMakeLists.txt | 152 +- .../base}/CMakeLists.txt | 45 +- applications/base/include/app-types.h | 33 + .../base/include/base.h | 26 +- .../base/source/base.cpp | 79 +- applications/base/source/config.h | 4 + .../base}/source/config.h.in | 0 .../base}/source/entry_point.cpp | 15 +- .../base}/source/imgui_extra_keys.h | 0 .../base}/source/imgui_impl_dx11.cpp | 0 .../base}/source/imgui_impl_dx11.h | 0 .../base}/source/imgui_impl_glfw.cpp | 0 .../base}/source/imgui_impl_glfw.h | 0 .../base}/source/imgui_impl_opengl3.cpp | 0 .../base}/source/imgui_impl_opengl3.h | 0 .../base}/source/imgui_impl_opengl3_loader.h | 0 .../base}/source/imgui_impl_win32.cpp | 0 .../base}/source/imgui_impl_win32.h | 0 .../base}/source/platform.h | 0 .../base}/source/platform_glfw.cpp | 0 .../base}/source/platform_win32.cpp | 2 +- .../base}/source/renderer.h | 0 .../base}/source/renderer_dx11.cpp | 0 .../base}/source/renderer_ogl3.cpp | 0 .../base}/source/setup.h | 0 .../base}/support/Icon.icns | Bin .../base}/support/Icon.ico | Bin .../base}/support/Icon.png | Bin .../base}/support/Info.plist.in | 0 .../base}/support/Resource.rc.in | 0 .../data/BlueprintBackground.png | Bin .../data/Cuprum-Bold.ttf | Bin .../data/Cuprum-OFL.txt | 0 .../data/Oswald-OFL.txt | 0 .../data/Oswald-Regular.ttf | Bin {examples => applications}/data/Play-OFL.txt | 0 .../data/Play-Regular.ttf | Bin .../data/ic_restore_white_24dp.png | Bin .../data/ic_save_white_24dp.png | Bin applications/nodehub/CMakeLists.txt | 112 + .../nodehub}/Logging.cpp | 0 .../nodehub}/Logging.h | 0 applications/nodehub/all.h | 14 + .../nodehub}/app-logic.cpp | 13 - .../nodehub}/app-render.cpp | Bin 310300 -> 309682 bytes .../nodehub}/app-runtime.cpp | 1 + .../nodehub}/app-screenshot.cpp | 38 +- .../nodehub}/app.cpp | 640 +-- .../nodehub}/app.h | 17 +- .../nodehub}/blocks/NodeEx.cpp | 0 .../nodehub/blocks/NodeEx.h | 0 .../nodehub}/blocks/block.cpp | 51 +- .../nodehub}/blocks/block.h | 89 +- .../nodehub}/blocks/block_edit_dialog.cpp | 16 +- .../nodehub}/blocks/block_edit_dialog.h | 2 +- .../nodehub}/blocks/constants.h | 0 .../nodehub}/blocks/group_block.cpp | 14 +- .../nodehub}/blocks/group_block.h | 8 +- .../nodehub}/blocks/log_block.cpp | 5 +- .../nodehub}/blocks/log_block.h | 10 +- .../nodehub}/blocks/logic_blocks.cpp | 24 +- .../nodehub}/blocks/logic_blocks.h | 2 +- .../nodehub}/blocks/math_blocks.cpp | 0 .../nodehub}/blocks/math_blocks.h | 12 +- .../nodehub}/blocks/parameter_edit_dialog.cpp | 0 .../nodehub}/blocks/parameter_edit_dialog.h | 0 .../nodehub}/blocks/parameter_node.cpp | 23 +- .../nodehub}/blocks/parameter_node.h | 19 +- .../nodehub}/blocks/parameter_operation.cpp | 4 +- .../nodehub}/blocks/parameter_operation.h | 6 +- .../nodehub}/blocks/start_block.cpp | 0 .../nodehub}/blocks/start_block.h | 4 +- applications/nodehub/commons.h | 36 + applications/nodehub/config.h | 8 + .../nodehub}/containers/container.cpp | 8 +- .../nodehub}/containers/container.h | 0 .../nodehub}/containers/root_container.cpp | 3 - .../nodehub}/containers/root_container.h | 2 +- applications/nodehub/core/BaseManager.cpp | 1 + applications/nodehub/core/BaseManager.h | 33 + applications/nodehub/core/Context.cpp | 38 + applications/nodehub/core/Context.h | 41 + applications/nodehub/core/Object.cpp | 1 + applications/nodehub/core/Object.h | 111 + applications/nodehub/core/Parameter.cpp | 68 + applications/nodehub/core/Parameter.h | 59 + applications/nodehub/core/ParameterIn.cpp | 81 + applications/nodehub/core/ParameterIn.h | 45 + .../nodehub/core/ParameterManager.cpp | 64 + applications/nodehub/core/ParameterManager.h | 26 + applications/nodehub/core/ParameterOut.cpp | 39 + applications/nodehub/core/ParameterOut.h | 79 + applications/nodehub/core/XClassArray.h | 574 +++ applications/nodehub/core/XPriorityQueue.h | 177 + applications/nodehub/core/XSArray.h | 490 ++ applications/nodehub/core/XSHashTable.h | 787 +++ applications/nodehub/core/XSmartPtr.h | 181 + .../nodehub}/core/graph_state.cpp | 0 .../nodehub}/core/graph_state.h | 0 applications/nodehub/core/utils.h | 183 + .../nodehub/data/BlueprintBackground.png | Bin 0 -> 5513 bytes applications/nodehub/data/Cuprum-Bold.ttf | Bin 0 -> 96364 bytes applications/nodehub/data/Cuprum-OFL.txt | 93 + applications/nodehub/data/Oswald-OFL.txt | 93 + applications/nodehub/data/Oswald-Regular.ttf | Bin 0 -> 91400 bytes applications/nodehub/data/Play-OFL.txt | 93 + applications/nodehub/data/Play-Regular.ttf | Bin 0 -> 183852 bytes .../nodehub/data/ic_restore_white_24dp.png | Bin 0 -> 332 bytes .../nodehub/data/ic_save_white_24dp.png | Bin 0 -> 168 bytes applications/nodehub/enums.h | 272 + applications/nodehub/enums_gui.h | 6 + .../nodehub/main.cpp | 112 +- applications/nodehub/stats.cpp | 62 + applications/nodehub/stats.h | 26 + applications/nodehub/types.h | 304 ++ .../nodehub}/utilities/edge_editing.cpp | 0 .../nodehub}/utilities/edge_editing.h | 0 .../nodehub}/utilities/node_renderer_base.cpp | 0 .../nodehub}/utilities/node_renderer_base.h | 0 .../nodehub}/utilities/pathfinding.cpp | 0 .../nodehub}/utilities/pathfinding.h | 2 +- .../nodehub}/utilities/pin_renderer.cpp | 2 +- .../nodehub}/utilities/pin_renderer.h | 0 .../nodehub}/utilities/style_manager.cpp | 2 +- .../nodehub}/utilities/style_manager.h | 0 .../nodehub}/utilities/uuid_generator.cpp | 0 .../nodehub}/utilities/uuid_generator.h | 4 +- .../nodehub}/utilities/uuid_id_manager.cpp | 0 .../nodehub}/utilities/uuid_id_manager.h | 0 applications/protos/CMakeLists.txt | 23 + applications/protos/parameter.proto | 12 + applications/tests/CMakeLists.txt | 106 + applications/tests/block_test.cpp | 42 + applications/tests/commons-test.cpp | 16 + applications/tests/commons-test.h | 19 + applications/tests/main-test.cpp | 10 + applications/tests/parameter_test.cpp | 140 + applications/tests/protobuf_test.cpp | 100 + applications/tests/protos/parameter.pb.cc | 494 ++ applications/tests/protos/parameter.pb.h | 547 ++ .../tests/protos/test_primitives.pb.cc | 1235 +++++ .../tests/protos/test_primitives.pb.h | 1041 ++++ applications/tests/test_primitives.proto | 20 + blueprints.log | 5 + docs-classes.md | 354 -- docs/COMPLETE_SOLUTION_SUMMARY.md | 327 -- docs/CONSOLE_VARIANT_SETUP.md | 203 - docs/IMPLEMENTATION_SUMMARY.md | 217 - docs/WINDOW_STATE_TEST_REPORT.md | 241 - docs/ZOOM_TO_CONTENT_FIX.md | 226 - docs/cli-implementation-example.md | 395 -- docs/cmake-protobuf.md | 69 + docs/groups-new.md | 237 - docs/llm/blocks.md | 93 + docs/llm/cli.md | 46 + docs/llm/create-blocks.md | 75 + docs/llm/testing.md | 54 + docs/shortcuts.md | 216 - docs/taking-screenshots-mcp.md | 75 - examples/blueprints-example/CMakeLists.txt | 75 - .../blueprints-example/LOGGING_INTEGRATION.md | 220 - .../blueprints-example/blueprints_cli.cpp | 317 -- examples/blueprints-example/blueprints_cli.h | 55 - .../blueprints-example/blueprints_engine.cpp | 337 -- .../blueprints-example/blueprints_engine.h | 176 - examples/blueprints-example/commons.h | 26 - examples/blueprints-example/enums.h | 112 - examples/blueprints-example/external/async.h | 99 - .../external/async_logger-inl.h | 84 - .../external/async_logger.h | 74 - .../blueprints-example/external/cfg/argv.h | 40 - .../blueprints-example/external/cfg/env.h | 36 - .../external/cfg/helpers-inl.h | 106 - .../blueprints-example/external/cfg/helpers.h | 29 - .../blueprints-example/external/common-inl.h | 68 - examples/blueprints-example/external/common.h | 406 -- .../external/details/backtracer-inl.h | 63 - .../external/details/backtracer.h | 45 - .../external/details/circular_q.h | 115 - .../external/details/console_globals.h | 28 - .../external/details/file_helper-inl.h | 151 - .../external/details/file_helper.h | 61 - .../external/details/fmt_helper.h | 141 - .../external/details/log_msg-inl.h | 44 - .../external/details/log_msg.h | 40 - .../external/details/log_msg_buffer-inl.h | 54 - .../external/details/log_msg_buffer.h | 32 - .../external/details/mpmc_blocking_q.h | 177 - .../external/details/null_mutex.h | 35 - .../external/details/os-inl.h | 605 --- .../blueprints-example/external/details/os.h | 127 - .../external/details/periodic_worker-inl.h | 26 - .../external/details/periodic_worker.h | 58 - .../external/details/registry-inl.h | 270 - .../external/details/registry.h | 131 - .../external/details/synchronous_factory.h | 22 - .../external/details/tcp_client-windows.h | 217 - .../external/details/tcp_client.h | 202 - .../external/details/thread_pool-inl.h | 125 - .../external/details/thread_pool.h | 117 - .../external/details/udp_client-windows.h | 98 - .../external/details/udp_client.h | 81 - .../external/details/windows_include.h | 11 - .../blueprints-example/external/example.cpp | 401 -- .../external/fmt/bin_to_hex.h | 224 - .../external/fmt/bundled/args.h | 220 - .../external/fmt/bundled/base.h | 2994 ----------- .../external/fmt/bundled/chrono.h | 2241 --------- .../external/fmt/bundled/color.h | 637 --- .../external/fmt/bundled/compile.h | 585 --- .../external/fmt/bundled/core.h | 5 - .../external/fmt/bundled/fmt.license.rst | 27 - .../external/fmt/bundled/format-inl.h | 1953 -------- .../external/fmt/bundled/format.h | 4383 ----------------- .../external/fmt/bundled/os.h | 428 -- .../external/fmt/bundled/ostream.h | 167 - .../external/fmt/bundled/printf.h | 624 --- .../external/fmt/bundled/ranges.h | 852 ---- .../external/fmt/bundled/std.h | 707 --- .../external/fmt/bundled/xchar.h | 356 -- .../blueprints-example/external/fmt/chrono.h | 23 - .../blueprints-example/external/fmt/compile.h | 23 - .../blueprints-example/external/fmt/fmt.h | 26 - .../blueprints-example/external/fmt/ostr.h | 23 - .../blueprints-example/external/fmt/ranges.h | 23 - .../blueprints-example/external/fmt/std.h | 24 - .../blueprints-example/external/fmt/xchar.h | 23 - .../blueprints-example/external/formatter.h | 17 - examples/blueprints-example/external/fwd.h | 18 - .../blueprints-example/external/logger-inl.h | 198 - examples/blueprints-example/external/logger.h | 379 -- examples/blueprints-example/external/mdc.h | 52 - .../external/pattern_formatter-inl.h | 1340 ----- .../external/pattern_formatter.h | 118 - .../external/sinks/android_sink.h | 137 - .../external/sinks/ansicolor_sink-inl.h | 142 - .../external/sinks/ansicolor_sink.h | 116 - .../external/sinks/base_sink-inl.h | 59 - .../external/sinks/base_sink.h | 51 - .../external/sinks/basic_file_sink-inl.h | 48 - .../external/sinks/basic_file_sink.h | 66 - .../external/sinks/callback_sink.h | 56 - .../external/sinks/daily_file_sink.h | 254 - .../external/sinks/dist_sink.h | 81 - .../external/sinks/dup_filter_sink.h | 91 - .../external/sinks/hourly_file_sink.h | 193 - .../external/sinks/kafka_sink.h | 119 - .../external/sinks/mongo_sink.h | 108 - .../external/sinks/msvc_sink.h | 68 - .../external/sinks/null_sink.h | 41 - .../external/sinks/ostream_sink.h | 43 - .../external/sinks/qt_sinks.h | 304 -- .../external/sinks/ringbuffer_sink.h | 71 - .../external/sinks/rotating_file_sink-inl.h | 179 - .../external/sinks/rotating_file_sink.h | 93 - .../external/sinks/sink-inl.h | 22 - .../blueprints-example/external/sinks/sink.h | 34 - .../external/sinks/stdout_color_sinks-inl.h | 38 - .../external/sinks/stdout_color_sinks.h | 49 - .../external/sinks/stdout_sinks-inl.h | 127 - .../external/sinks/stdout_sinks.h | 84 - .../external/sinks/syslog_sink.h | 104 - .../external/sinks/systemd_sink.h | 121 - .../external/sinks/tcp_sink.h | 89 - .../external/sinks/udp_sink.h | 69 - .../external/sinks/win_eventlog_sink.h | 260 - .../external/sinks/wincolor_sink-inl.h | 172 - .../external/sinks/wincolor_sink.h | 82 - .../blueprints-example/external/spdlog-inl.h | 96 - examples/blueprints-example/external/spdlog.h | 357 -- .../external/spdlog/async.h | 99 - .../external/spdlog/async_logger-inl.h | 84 - .../external/spdlog/async_logger.h | 74 - .../external/spdlog/cfg/argv.h | 40 - .../external/spdlog/cfg/env.h | 36 - .../external/spdlog/cfg/helpers-inl.h | 106 - .../external/spdlog/cfg/helpers.h | 29 - .../external/spdlog/common-inl.h | 68 - .../external/spdlog/common.h | 406 -- .../external/spdlog/details/backtracer-inl.h | 63 - .../external/spdlog/details/backtracer.h | 45 - .../external/spdlog/details/circular_q.h | 115 - .../external/spdlog/details/console_globals.h | 28 - .../external/spdlog/details/file_helper-inl.h | 151 - .../external/spdlog/details/file_helper.h | 61 - .../external/spdlog/details/fmt_helper.h | 141 - .../external/spdlog/details/log_msg-inl.h | 44 - .../external/spdlog/details/log_msg.h | 40 - .../spdlog/details/log_msg_buffer-inl.h | 54 - .../external/spdlog/details/log_msg_buffer.h | 32 - .../external/spdlog/details/mpmc_blocking_q.h | 177 - .../external/spdlog/details/null_mutex.h | 35 - .../external/spdlog/details/os-inl.h | 605 --- .../external/spdlog/details/os.h | 127 - .../spdlog/details/periodic_worker-inl.h | 26 - .../external/spdlog/details/periodic_worker.h | 58 - .../external/spdlog/details/registry-inl.h | 270 - .../external/spdlog/details/registry.h | 131 - .../spdlog/details/synchronous_factory.h | 22 - .../spdlog/details/tcp_client-windows.h | 217 - .../external/spdlog/details/tcp_client.h | 202 - .../external/spdlog/details/thread_pool-inl.h | 125 - .../external/spdlog/details/thread_pool.h | 117 - .../spdlog/details/udp_client-windows.h | 98 - .../external/spdlog/details/udp_client.h | 81 - .../external/spdlog/details/windows_include.h | 11 - .../external/spdlog/example.cpp | 401 -- .../external/spdlog/fmt/bin_to_hex.h | 224 - .../external/spdlog/fmt/bundled/args.h | 220 - .../external/spdlog/fmt/bundled/base.h | 2994 ----------- .../external/spdlog/fmt/bundled/chrono.h | 2241 --------- .../external/spdlog/fmt/bundled/color.h | 637 --- .../external/spdlog/fmt/bundled/compile.h | 585 --- .../external/spdlog/fmt/bundled/core.h | 5 - .../spdlog/fmt/bundled/fmt.license.rst | 27 - .../external/spdlog/fmt/bundled/format-inl.h | 1953 -------- .../external/spdlog/fmt/bundled/format.h | 4383 ----------------- .../external/spdlog/fmt/bundled/os.h | 428 -- .../external/spdlog/fmt/bundled/ostream.h | 167 - .../external/spdlog/fmt/bundled/printf.h | 624 --- .../external/spdlog/fmt/bundled/ranges.h | 852 ---- .../external/spdlog/fmt/bundled/std.h | 707 --- .../external/spdlog/fmt/bundled/xchar.h | 356 -- .../external/spdlog/fmt/chrono.h | 23 - .../external/spdlog/fmt/compile.h | 23 - .../external/spdlog/fmt/fmt.h | 26 - .../external/spdlog/fmt/ostr.h | 23 - .../external/spdlog/fmt/ranges.h | 23 - .../external/spdlog/fmt/std.h | 24 - .../external/spdlog/fmt/xchar.h | 23 - .../external/spdlog/formatter.h | 17 - .../blueprints-example/external/spdlog/fwd.h | 18 - .../external/spdlog/logger-inl.h | 198 - .../external/spdlog/logger.h | 379 -- .../blueprints-example/external/spdlog/mdc.h | 52 - .../external/spdlog/pattern_formatter-inl.h | 1340 ----- .../external/spdlog/pattern_formatter.h | 118 - .../external/spdlog/sinks/android_sink.h | 137 - .../spdlog/sinks/ansicolor_sink-inl.h | 142 - .../external/spdlog/sinks/ansicolor_sink.h | 116 - .../external/spdlog/sinks/base_sink-inl.h | 59 - .../external/spdlog/sinks/base_sink.h | 51 - .../spdlog/sinks/basic_file_sink-inl.h | 48 - .../external/spdlog/sinks/basic_file_sink.h | 66 - .../external/spdlog/sinks/callback_sink.h | 56 - .../external/spdlog/sinks/daily_file_sink.h | 254 - .../external/spdlog/sinks/dist_sink.h | 81 - .../external/spdlog/sinks/dup_filter_sink.h | 91 - .../external/spdlog/sinks/hourly_file_sink.h | 193 - .../external/spdlog/sinks/kafka_sink.h | 119 - .../external/spdlog/sinks/mongo_sink.h | 108 - .../external/spdlog/sinks/msvc_sink.h | 68 - .../external/spdlog/sinks/null_sink.h | 41 - .../external/spdlog/sinks/ostream_sink.h | 43 - .../external/spdlog/sinks/qt_sinks.h | 304 -- .../external/spdlog/sinks/ringbuffer_sink.h | 71 - .../spdlog/sinks/rotating_file_sink-inl.h | 179 - .../spdlog/sinks/rotating_file_sink.h | 93 - .../external/spdlog/sinks/sink-inl.h | 22 - .../external/spdlog/sinks/sink.h | 34 - .../spdlog/sinks/stdout_color_sinks-inl.h | 38 - .../spdlog/sinks/stdout_color_sinks.h | 49 - .../external/spdlog/sinks/stdout_sinks-inl.h | 127 - .../external/spdlog/sinks/stdout_sinks.h | 84 - .../external/spdlog/sinks/syslog_sink.h | 104 - .../external/spdlog/sinks/systemd_sink.h | 121 - .../external/spdlog/sinks/tcp_sink.h | 89 - .../external/spdlog/sinks/udp_sink.h | 69 - .../external/spdlog/sinks/win_eventlog_sink.h | 260 - .../external/spdlog/sinks/wincolor_sink-inl.h | 172 - .../external/spdlog/sinks/wincolor_sink.h | 82 - .../external/spdlog/spdlog-inl.h | 96 - .../external/spdlog/spdlog.h | 357 -- .../external/spdlog/stopwatch.h | 66 - .../external/spdlog/tweakme.h | 148 - .../external/spdlog/version.h | 11 - .../blueprints-example/external/stopwatch.h | 66 - .../blueprints-example/external/tweakme.h | 148 - .../blueprints-example/external/version.h | 11 - examples/blueprints-example/nodes.cpp | 132 - examples/blueprints-example/nodes.h | 25 - examples/blueprints-example/types.h | 191 - .../utilities/LINK_FITTING.md | 172 - .../utilities/STANDARD_UUID_CONVERSION.md | 302 -- .../utilities/UUID64_USAGE.md | 324 -- .../utilities/UUID_COLLISION_ANALYSIS.md | 252 - .../utilities/UUID_DUAL_ID_SYSTEM.md | 386 -- .../utilities/UUID_USAGE.md | 151 - .../utilities/WAYPOINT_REFINEMENT.md | 261 - crude_json.cpp => external/crude_json.cpp | 0 crude_json.h => external/crude_json.h | 0 external/imgui/CMakeLists.txt | 12 +- external/imgui/imgui_draw.cpp | 1 + .../imgui_node/EditorContext.cpp | 0 .../imgui_node/EditorContext.h | 0 NodeEx.cpp => external/imgui_node/NodeEx.cpp | 0 .../blocks => external/imgui_node}/NodeEx.h | 0 .../imgui_node/imgui_bezier_math.h | 0 .../imgui_node/imgui_bezier_math.inl | 0 .../imgui_node/imgui_canvas.cpp | 0 .../imgui_node/imgui_canvas.h | 0 .../imgui_node/imgui_extra_math.h | 0 .../imgui_node/imgui_extra_math.inl | 0 .../imgui_node/imgui_node_editor.cpp | 29 +- .../imgui_node/imgui_node_editor.h | 16 - .../imgui_node_editor_animation.cpp | 0 .../imgui_node/imgui_node_editor_api.cpp | 12 - .../imgui_node/imgui_node_editor_internal.h | 6 +- .../imgui_node/imgui_node_editor_internal.inl | 0 .../imgui_node/imgui_node_editor_store.cpp | 0 .../imgui_node/links-guided.cpp | 0 .../imgui_node/links-guided.h | 0 imgui_node_editor_edit.cpp | 45 - imgui_node_editor_links.cpp | 23 - imgui_node_editor_render.cpp | 23 - imgui_node_editor_runtime.cpp | 15 - imgui_node_editor_selection.cpp | 23 - imgui_node_editor_tools.cpp | 186 - .../cmake-modules/Findimgui_node_editor.cmake | 70 +- package-lock.json | 1346 +++++ package.json | 60 +- ref/basic-interaction-example.cpp | 2 +- ref/cpp/main.c | 130 + ref/cpp/main.cpp | 217 + ref/virtools/Includes/CKObject.h | 106 +- ref/vt-ex/include/AutoLock.h | 572 +++ ref/vt-ex/include/BaseMacros.h | 101 + ref/vt-ex/include/ConStream.h | 55 + ref/vt-ex/include/DllTools.h | 83 + ref/vt-ex/include/bCCOError.h | 183 + ref/vt-ex/include/base.h | 288 ++ ref/vt-ex/include/base_macros.h | 21 + ref/vt-ex/include/pch.h | 94 + ref/vt-ex/include/sharedStructs.h | 30 + ref/vt-ex/include/uxString.h | 569 +++ ref/vt-ex/include/virtools/vtAll.h | 48 + ref/vt-ex/include/virtools/vtBBHelper.h | 461 ++ ref/vt-ex/include/virtools/vtBBMacros.h | 143 + ref/vt-ex/include/virtools/vtBase.h | 24 + ref/vt-ex/include/virtools/vtBaseMacros.h | 20 + ref/vt-ex/include/virtools/vtCXGlobal.h | 116 + ref/vt-ex/include/virtools/vtCXPlatform32.h | 22 + ref/vt-ex/include/virtools/vtCXPrecomp.h | 11 + ref/vt-ex/include/virtools/vtGUID.h | 91 + ref/vt-ex/include/virtools/vtStructHelper.h | 133 + ref/vt-ex/include/virtools/vtTools.h | 836 ++++ ref/vt-ex/include/vtxall.h | 49 + ref/vt-ex/include/xAssertCustomization.h | 61 + ref/vt-ex/include/xAssertion.h | 366 ++ ref/vt-ex/include/xBitSet.h | 102 + ref/vt-ex/include/xDebugTools.h | 328 ++ ref/vt-ex/include/xLogger.h | 227 + ref/vt-ex/include/xPlatform.h | 220 + ref/vt-ex/src/3D/DXDiagNVUtil.cpp | 770 +++ ref/vt-ex/src/3D/GetGPUAndSystemInfo.cpp | 287 ++ ref/vt-ex/src/3D/NV_StringFuncs.cpp | 386 ++ ref/vt-ex/src/3D/nvfile.cpp | 297 ++ ref/vt-ex/src/profile/GDirectory.cpp | 296 ++ ref/vt-ex/src/profile/GException.cpp | 689 +++ ref/vt-ex/src/profile/GList.cpp | 353 ++ ref/vt-ex/src/profile/GProfile.cpp | 523 ++ ref/vt-ex/src/profile/GString.cpp | 2621 ++++++++++ ref/vt-ex/src/profile/GStringList.cpp | 221 + .../Behaviors/generic/BGInstancer.cpp | 926 ++++ .../virtools/Behaviors/generic/BGInstancer.h | 52 + .../Behaviors/generic/GBLAsyncBlock.cpp | 321 ++ .../Behaviors/generic/GBLAsyncBlock.h | 22 + .../virtools/Behaviors/generic/GetSubBBId.cpp | 79 + .../Behaviors/joystick/JSetXYForce.cpp | 572 +++ .../Behaviors/joystick/PlayEffect.cpp | 471 ++ .../virtools/Behaviors/joystick/hasFFe.cpp | 169 + .../src/virtools/Behaviors/joystick/jTest.cmo | Bin 0 -> 3189 bytes .../virtools/Behaviors/joystick/readffe.cpp | 405 ++ ref/vt-ex/src/virtools/vtTools.cpp | 844 ++++ run-console.sh | 2 +- run-with-console.bat | 24 - run.sh | 2 +- scripts/build.bat | 43 - scripts/build.ps1 | 40 - scripts/build.sh | 6 +- scripts/generate_protos.sh | 25 + src/.gitignore | 0 sslast.png | 0 tests/commons.ts | 44 + tests/e2e.test.ts | 16 + tests/fixtures/graph-log.json | 108 + 493 files changed, 26772 insertions(+), 62054 deletions(-) delete mode 100644 .npmignore create mode 100644 Blueprints.json create mode 100644 BlueprintsGraph.json create mode 100644 Blueprints_window.json create mode 100644 CMakeLists.txt rename {examples => applications}/CMakeLists.txt (53%) rename {examples/application => applications/base}/CMakeLists.txt (68%) create mode 100644 applications/base/include/app-types.h rename examples/application/include/application.h => applications/base/include/base.h (70%) rename examples/application/source/application.cpp => applications/base/source/base.cpp (82%) create mode 100644 applications/base/source/config.h rename {examples/application => applications/base}/source/config.h.in (100%) rename {examples/application => applications/base}/source/entry_point.cpp (95%) rename {examples/application => applications/base}/source/imgui_extra_keys.h (100%) rename {examples/application => applications/base}/source/imgui_impl_dx11.cpp (100%) rename {examples/application => applications/base}/source/imgui_impl_dx11.h (100%) rename {examples/application => applications/base}/source/imgui_impl_glfw.cpp (100%) rename {examples/application => applications/base}/source/imgui_impl_glfw.h (100%) rename {examples/application => applications/base}/source/imgui_impl_opengl3.cpp (100%) rename {examples/application => applications/base}/source/imgui_impl_opengl3.h (100%) rename {examples/application => applications/base}/source/imgui_impl_opengl3_loader.h (100%) rename {examples/application => applications/base}/source/imgui_impl_win32.cpp (100%) rename {examples/application => applications/base}/source/imgui_impl_win32.h (100%) rename {examples/application => applications/base}/source/platform.h (100%) rename {examples/application => applications/base}/source/platform_glfw.cpp (100%) rename {examples/application => applications/base}/source/platform_win32.cpp (99%) rename {examples/application => applications/base}/source/renderer.h (100%) rename {examples/application => applications/base}/source/renderer_dx11.cpp (100%) rename {examples/application => applications/base}/source/renderer_ogl3.cpp (100%) rename {examples/application => applications/base}/source/setup.h (100%) rename {examples/application => applications/base}/support/Icon.icns (100%) rename {examples/application => applications/base}/support/Icon.ico (100%) rename {examples/application => applications/base}/support/Icon.png (100%) rename {examples/application => applications/base}/support/Info.plist.in (100%) rename {examples/application => applications/base}/support/Resource.rc.in (100%) rename {examples/blueprints-example => applications}/data/BlueprintBackground.png (100%) rename {examples => applications}/data/Cuprum-Bold.ttf (100%) rename {examples => applications}/data/Cuprum-OFL.txt (100%) rename {examples => applications}/data/Oswald-OFL.txt (100%) rename {examples => applications}/data/Oswald-Regular.ttf (100%) rename {examples => applications}/data/Play-OFL.txt (100%) rename {examples => applications}/data/Play-Regular.ttf (100%) rename {examples/blueprints-example => applications}/data/ic_restore_white_24dp.png (100%) rename {examples/blueprints-example => applications}/data/ic_save_white_24dp.png (100%) create mode 100644 applications/nodehub/CMakeLists.txt rename {examples/blueprints-example => applications/nodehub}/Logging.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/Logging.h (100%) create mode 100644 applications/nodehub/all.h rename {examples/blueprints-example => applications/nodehub}/app-logic.cpp (98%) rename {examples/blueprints-example => applications/nodehub}/app-render.cpp (99%) rename {examples/blueprints-example => applications/nodehub}/app-runtime.cpp (99%) rename {examples/blueprints-example => applications/nodehub}/app-screenshot.cpp (71%) rename {examples/blueprints-example => applications/nodehub}/app.cpp (92%) rename {examples/blueprints-example => applications/nodehub}/app.h (97%) rename {examples/blueprints-example => applications/nodehub}/blocks/NodeEx.cpp (100%) rename NodeEx.h => applications/nodehub/blocks/NodeEx.h (100%) rename {examples/blueprints-example => applications/nodehub}/blocks/block.cpp (95%) rename {examples/blueprints-example => applications/nodehub}/blocks/block.h (67%) rename {examples/blueprints-example => applications/nodehub}/blocks/block_edit_dialog.cpp (98%) rename {examples/blueprints-example => applications/nodehub}/blocks/block_edit_dialog.h (87%) rename {examples/blueprints-example => applications/nodehub}/blocks/constants.h (100%) rename {examples/blueprints-example => applications/nodehub}/blocks/group_block.cpp (98%) rename {examples/blueprints-example => applications/nodehub}/blocks/group_block.h (94%) rename {examples/blueprints-example => applications/nodehub}/blocks/log_block.cpp (96%) rename {examples/blueprints-example => applications/nodehub}/blocks/log_block.h (86%) rename {examples/blueprints-example => applications/nodehub}/blocks/logic_blocks.cpp (91%) rename {examples/blueprints-example => applications/nodehub}/blocks/logic_blocks.h (91%) rename {examples/blueprints-example => applications/nodehub}/blocks/math_blocks.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/blocks/math_blocks.h (73%) rename {examples/blueprints-example => applications/nodehub}/blocks/parameter_edit_dialog.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/blocks/parameter_edit_dialog.h (100%) rename {examples/blueprints-example => applications/nodehub}/blocks/parameter_node.cpp (95%) rename {examples/blueprints-example => applications/nodehub}/blocks/parameter_node.h (90%) rename {examples/blueprints-example => applications/nodehub}/blocks/parameter_operation.cpp (96%) rename {examples/blueprints-example => applications/nodehub}/blocks/parameter_operation.h (92%) rename {examples/blueprints-example => applications/nodehub}/blocks/start_block.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/blocks/start_block.h (80%) create mode 100644 applications/nodehub/commons.h create mode 100644 applications/nodehub/config.h rename {examples/blueprints-example => applications/nodehub}/containers/container.cpp (95%) rename {examples/blueprints-example => applications/nodehub}/containers/container.h (100%) rename {examples/blueprints-example => applications/nodehub}/containers/root_container.cpp (94%) rename {examples/blueprints-example => applications/nodehub}/containers/root_container.h (96%) create mode 100644 applications/nodehub/core/BaseManager.cpp create mode 100644 applications/nodehub/core/BaseManager.h create mode 100644 applications/nodehub/core/Context.cpp create mode 100644 applications/nodehub/core/Context.h create mode 100644 applications/nodehub/core/Object.cpp create mode 100644 applications/nodehub/core/Object.h create mode 100644 applications/nodehub/core/Parameter.cpp create mode 100644 applications/nodehub/core/Parameter.h create mode 100644 applications/nodehub/core/ParameterIn.cpp create mode 100644 applications/nodehub/core/ParameterIn.h create mode 100644 applications/nodehub/core/ParameterManager.cpp create mode 100644 applications/nodehub/core/ParameterManager.h create mode 100644 applications/nodehub/core/ParameterOut.cpp create mode 100644 applications/nodehub/core/ParameterOut.h create mode 100644 applications/nodehub/core/XClassArray.h create mode 100644 applications/nodehub/core/XPriorityQueue.h create mode 100644 applications/nodehub/core/XSArray.h create mode 100644 applications/nodehub/core/XSHashTable.h create mode 100644 applications/nodehub/core/XSmartPtr.h rename {examples/blueprints-example => applications/nodehub}/core/graph_state.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/core/graph_state.h (100%) create mode 100644 applications/nodehub/core/utils.h create mode 100644 applications/nodehub/data/BlueprintBackground.png create mode 100644 applications/nodehub/data/Cuprum-Bold.ttf create mode 100644 applications/nodehub/data/Cuprum-OFL.txt create mode 100644 applications/nodehub/data/Oswald-OFL.txt create mode 100644 applications/nodehub/data/Oswald-Regular.ttf create mode 100644 applications/nodehub/data/Play-OFL.txt create mode 100644 applications/nodehub/data/Play-Regular.ttf create mode 100644 applications/nodehub/data/ic_restore_white_24dp.png create mode 100644 applications/nodehub/data/ic_save_white_24dp.png create mode 100644 applications/nodehub/enums.h create mode 100644 applications/nodehub/enums_gui.h rename examples/blueprints-example/blueprints-example.cpp => applications/nodehub/main.cpp (75%) create mode 100644 applications/nodehub/stats.cpp create mode 100644 applications/nodehub/stats.h create mode 100644 applications/nodehub/types.h rename {examples/blueprints-example => applications/nodehub}/utilities/edge_editing.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/edge_editing.h (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/node_renderer_base.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/node_renderer_base.h (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/pathfinding.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/pathfinding.h (96%) rename {examples/blueprints-example => applications/nodehub}/utilities/pin_renderer.cpp (96%) rename {examples/blueprints-example => applications/nodehub}/utilities/pin_renderer.h (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/style_manager.cpp (97%) rename {examples/blueprints-example => applications/nodehub}/utilities/style_manager.h (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/uuid_generator.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/uuid_generator.h (94%) rename {examples/blueprints-example => applications/nodehub}/utilities/uuid_id_manager.cpp (100%) rename {examples/blueprints-example => applications/nodehub}/utilities/uuid_id_manager.h (100%) create mode 100644 applications/protos/CMakeLists.txt create mode 100644 applications/protos/parameter.proto create mode 100644 applications/tests/CMakeLists.txt create mode 100644 applications/tests/block_test.cpp create mode 100644 applications/tests/commons-test.cpp create mode 100644 applications/tests/commons-test.h create mode 100644 applications/tests/main-test.cpp create mode 100644 applications/tests/parameter_test.cpp create mode 100644 applications/tests/protobuf_test.cpp create mode 100644 applications/tests/protos/parameter.pb.cc create mode 100644 applications/tests/protos/parameter.pb.h create mode 100644 applications/tests/protos/test_primitives.pb.cc create mode 100644 applications/tests/protos/test_primitives.pb.h create mode 100644 applications/tests/test_primitives.proto create mode 100644 blueprints.log delete mode 100644 docs-classes.md delete mode 100644 docs/COMPLETE_SOLUTION_SUMMARY.md delete mode 100644 docs/CONSOLE_VARIANT_SETUP.md delete mode 100644 docs/IMPLEMENTATION_SUMMARY.md delete mode 100644 docs/WINDOW_STATE_TEST_REPORT.md delete mode 100644 docs/ZOOM_TO_CONTENT_FIX.md delete mode 100644 docs/cli-implementation-example.md create mode 100644 docs/cmake-protobuf.md delete mode 100644 docs/groups-new.md create mode 100644 docs/llm/blocks.md create mode 100644 docs/llm/cli.md create mode 100644 docs/llm/create-blocks.md create mode 100644 docs/llm/testing.md delete mode 100644 docs/shortcuts.md delete mode 100644 docs/taking-screenshots-mcp.md delete mode 100644 examples/blueprints-example/CMakeLists.txt delete mode 100644 examples/blueprints-example/LOGGING_INTEGRATION.md delete mode 100644 examples/blueprints-example/blueprints_cli.cpp delete mode 100644 examples/blueprints-example/blueprints_cli.h delete mode 100644 examples/blueprints-example/blueprints_engine.cpp delete mode 100644 examples/blueprints-example/blueprints_engine.h delete mode 100644 examples/blueprints-example/commons.h delete mode 100644 examples/blueprints-example/enums.h delete mode 100644 examples/blueprints-example/external/async.h delete mode 100644 examples/blueprints-example/external/async_logger-inl.h delete mode 100644 examples/blueprints-example/external/async_logger.h delete mode 100644 examples/blueprints-example/external/cfg/argv.h delete mode 100644 examples/blueprints-example/external/cfg/env.h delete mode 100644 examples/blueprints-example/external/cfg/helpers-inl.h delete mode 100644 examples/blueprints-example/external/cfg/helpers.h delete mode 100644 examples/blueprints-example/external/common-inl.h delete mode 100644 examples/blueprints-example/external/common.h delete mode 100644 examples/blueprints-example/external/details/backtracer-inl.h delete mode 100644 examples/blueprints-example/external/details/backtracer.h delete mode 100644 examples/blueprints-example/external/details/circular_q.h delete mode 100644 examples/blueprints-example/external/details/console_globals.h delete mode 100644 examples/blueprints-example/external/details/file_helper-inl.h delete mode 100644 examples/blueprints-example/external/details/file_helper.h delete mode 100644 examples/blueprints-example/external/details/fmt_helper.h delete mode 100644 examples/blueprints-example/external/details/log_msg-inl.h delete mode 100644 examples/blueprints-example/external/details/log_msg.h delete mode 100644 examples/blueprints-example/external/details/log_msg_buffer-inl.h delete mode 100644 examples/blueprints-example/external/details/log_msg_buffer.h delete mode 100644 examples/blueprints-example/external/details/mpmc_blocking_q.h delete mode 100644 examples/blueprints-example/external/details/null_mutex.h delete mode 100644 examples/blueprints-example/external/details/os-inl.h delete mode 100644 examples/blueprints-example/external/details/os.h delete mode 100644 examples/blueprints-example/external/details/periodic_worker-inl.h delete mode 100644 examples/blueprints-example/external/details/periodic_worker.h delete mode 100644 examples/blueprints-example/external/details/registry-inl.h delete mode 100644 examples/blueprints-example/external/details/registry.h delete mode 100644 examples/blueprints-example/external/details/synchronous_factory.h delete mode 100644 examples/blueprints-example/external/details/tcp_client-windows.h delete mode 100644 examples/blueprints-example/external/details/tcp_client.h delete mode 100644 examples/blueprints-example/external/details/thread_pool-inl.h delete mode 100644 examples/blueprints-example/external/details/thread_pool.h delete mode 100644 examples/blueprints-example/external/details/udp_client-windows.h delete mode 100644 examples/blueprints-example/external/details/udp_client.h delete mode 100644 examples/blueprints-example/external/details/windows_include.h delete mode 100644 examples/blueprints-example/external/example.cpp delete mode 100644 examples/blueprints-example/external/fmt/bin_to_hex.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/args.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/base.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/chrono.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/color.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/compile.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/core.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/fmt.license.rst delete mode 100644 examples/blueprints-example/external/fmt/bundled/format-inl.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/format.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/os.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/ostream.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/printf.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/ranges.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/std.h delete mode 100644 examples/blueprints-example/external/fmt/bundled/xchar.h delete mode 100644 examples/blueprints-example/external/fmt/chrono.h delete mode 100644 examples/blueprints-example/external/fmt/compile.h delete mode 100644 examples/blueprints-example/external/fmt/fmt.h delete mode 100644 examples/blueprints-example/external/fmt/ostr.h delete mode 100644 examples/blueprints-example/external/fmt/ranges.h delete mode 100644 examples/blueprints-example/external/fmt/std.h delete mode 100644 examples/blueprints-example/external/fmt/xchar.h delete mode 100644 examples/blueprints-example/external/formatter.h delete mode 100644 examples/blueprints-example/external/fwd.h delete mode 100644 examples/blueprints-example/external/logger-inl.h delete mode 100644 examples/blueprints-example/external/logger.h delete mode 100644 examples/blueprints-example/external/mdc.h delete mode 100644 examples/blueprints-example/external/pattern_formatter-inl.h delete mode 100644 examples/blueprints-example/external/pattern_formatter.h delete mode 100644 examples/blueprints-example/external/sinks/android_sink.h delete mode 100644 examples/blueprints-example/external/sinks/ansicolor_sink-inl.h delete mode 100644 examples/blueprints-example/external/sinks/ansicolor_sink.h delete mode 100644 examples/blueprints-example/external/sinks/base_sink-inl.h delete mode 100644 examples/blueprints-example/external/sinks/base_sink.h delete mode 100644 examples/blueprints-example/external/sinks/basic_file_sink-inl.h delete mode 100644 examples/blueprints-example/external/sinks/basic_file_sink.h delete mode 100644 examples/blueprints-example/external/sinks/callback_sink.h delete mode 100644 examples/blueprints-example/external/sinks/daily_file_sink.h delete mode 100644 examples/blueprints-example/external/sinks/dist_sink.h delete mode 100644 examples/blueprints-example/external/sinks/dup_filter_sink.h delete mode 100644 examples/blueprints-example/external/sinks/hourly_file_sink.h delete mode 100644 examples/blueprints-example/external/sinks/kafka_sink.h delete mode 100644 examples/blueprints-example/external/sinks/mongo_sink.h delete mode 100644 examples/blueprints-example/external/sinks/msvc_sink.h delete mode 100644 examples/blueprints-example/external/sinks/null_sink.h delete mode 100644 examples/blueprints-example/external/sinks/ostream_sink.h delete mode 100644 examples/blueprints-example/external/sinks/qt_sinks.h delete mode 100644 examples/blueprints-example/external/sinks/ringbuffer_sink.h delete mode 100644 examples/blueprints-example/external/sinks/rotating_file_sink-inl.h delete mode 100644 examples/blueprints-example/external/sinks/rotating_file_sink.h delete mode 100644 examples/blueprints-example/external/sinks/sink-inl.h delete mode 100644 examples/blueprints-example/external/sinks/sink.h delete mode 100644 examples/blueprints-example/external/sinks/stdout_color_sinks-inl.h delete mode 100644 examples/blueprints-example/external/sinks/stdout_color_sinks.h delete mode 100644 examples/blueprints-example/external/sinks/stdout_sinks-inl.h delete mode 100644 examples/blueprints-example/external/sinks/stdout_sinks.h delete mode 100644 examples/blueprints-example/external/sinks/syslog_sink.h delete mode 100644 examples/blueprints-example/external/sinks/systemd_sink.h delete mode 100644 examples/blueprints-example/external/sinks/tcp_sink.h delete mode 100644 examples/blueprints-example/external/sinks/udp_sink.h delete mode 100644 examples/blueprints-example/external/sinks/win_eventlog_sink.h delete mode 100644 examples/blueprints-example/external/sinks/wincolor_sink-inl.h delete mode 100644 examples/blueprints-example/external/sinks/wincolor_sink.h delete mode 100644 examples/blueprints-example/external/spdlog-inl.h delete mode 100644 examples/blueprints-example/external/spdlog.h delete mode 100644 examples/blueprints-example/external/spdlog/async.h delete mode 100644 examples/blueprints-example/external/spdlog/async_logger-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/async_logger.h delete mode 100644 examples/blueprints-example/external/spdlog/cfg/argv.h delete mode 100644 examples/blueprints-example/external/spdlog/cfg/env.h delete mode 100644 examples/blueprints-example/external/spdlog/cfg/helpers-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/cfg/helpers.h delete mode 100644 examples/blueprints-example/external/spdlog/common-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/common.h delete mode 100644 examples/blueprints-example/external/spdlog/details/backtracer-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/details/backtracer.h delete mode 100644 examples/blueprints-example/external/spdlog/details/circular_q.h delete mode 100644 examples/blueprints-example/external/spdlog/details/console_globals.h delete mode 100644 examples/blueprints-example/external/spdlog/details/file_helper-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/details/file_helper.h delete mode 100644 examples/blueprints-example/external/spdlog/details/fmt_helper.h delete mode 100644 examples/blueprints-example/external/spdlog/details/log_msg-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/details/log_msg.h delete mode 100644 examples/blueprints-example/external/spdlog/details/log_msg_buffer-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/details/log_msg_buffer.h delete mode 100644 examples/blueprints-example/external/spdlog/details/mpmc_blocking_q.h delete mode 100644 examples/blueprints-example/external/spdlog/details/null_mutex.h delete mode 100644 examples/blueprints-example/external/spdlog/details/os-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/details/os.h delete mode 100644 examples/blueprints-example/external/spdlog/details/periodic_worker-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/details/periodic_worker.h delete mode 100644 examples/blueprints-example/external/spdlog/details/registry-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/details/registry.h delete mode 100644 examples/blueprints-example/external/spdlog/details/synchronous_factory.h delete mode 100644 examples/blueprints-example/external/spdlog/details/tcp_client-windows.h delete mode 100644 examples/blueprints-example/external/spdlog/details/tcp_client.h delete mode 100644 examples/blueprints-example/external/spdlog/details/thread_pool-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/details/thread_pool.h delete mode 100644 examples/blueprints-example/external/spdlog/details/udp_client-windows.h delete mode 100644 examples/blueprints-example/external/spdlog/details/udp_client.h delete mode 100644 examples/blueprints-example/external/spdlog/details/windows_include.h delete mode 100644 examples/blueprints-example/external/spdlog/example.cpp delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bin_to_hex.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/args.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/base.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/chrono.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/color.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/compile.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/core.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/fmt.license.rst delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/format-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/format.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/os.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/ostream.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/printf.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/ranges.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/std.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/bundled/xchar.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/chrono.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/compile.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/fmt.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/ostr.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/ranges.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/std.h delete mode 100644 examples/blueprints-example/external/spdlog/fmt/xchar.h delete mode 100644 examples/blueprints-example/external/spdlog/formatter.h delete mode 100644 examples/blueprints-example/external/spdlog/fwd.h delete mode 100644 examples/blueprints-example/external/spdlog/logger-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/logger.h delete mode 100644 examples/blueprints-example/external/spdlog/mdc.h delete mode 100644 examples/blueprints-example/external/spdlog/pattern_formatter-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/pattern_formatter.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/android_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/ansicolor_sink-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/ansicolor_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/base_sink-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/base_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/basic_file_sink-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/basic_file_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/callback_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/daily_file_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/dist_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/dup_filter_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/hourly_file_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/kafka_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/mongo_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/msvc_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/null_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/ostream_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/qt_sinks.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/ringbuffer_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/rotating_file_sink-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/rotating_file_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/sink-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/stdout_color_sinks-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/stdout_color_sinks.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/stdout_sinks-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/stdout_sinks.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/syslog_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/systemd_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/tcp_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/udp_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/win_eventlog_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/wincolor_sink-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/sinks/wincolor_sink.h delete mode 100644 examples/blueprints-example/external/spdlog/spdlog-inl.h delete mode 100644 examples/blueprints-example/external/spdlog/spdlog.h delete mode 100644 examples/blueprints-example/external/spdlog/stopwatch.h delete mode 100644 examples/blueprints-example/external/spdlog/tweakme.h delete mode 100644 examples/blueprints-example/external/spdlog/version.h delete mode 100644 examples/blueprints-example/external/stopwatch.h delete mode 100644 examples/blueprints-example/external/tweakme.h delete mode 100644 examples/blueprints-example/external/version.h delete mode 100644 examples/blueprints-example/nodes.cpp delete mode 100644 examples/blueprints-example/nodes.h delete mode 100644 examples/blueprints-example/types.h delete mode 100644 examples/blueprints-example/utilities/LINK_FITTING.md delete mode 100644 examples/blueprints-example/utilities/STANDARD_UUID_CONVERSION.md delete mode 100644 examples/blueprints-example/utilities/UUID64_USAGE.md delete mode 100644 examples/blueprints-example/utilities/UUID_COLLISION_ANALYSIS.md delete mode 100644 examples/blueprints-example/utilities/UUID_DUAL_ID_SYSTEM.md delete mode 100644 examples/blueprints-example/utilities/UUID_USAGE.md delete mode 100644 examples/blueprints-example/utilities/WAYPOINT_REFINEMENT.md rename crude_json.cpp => external/crude_json.cpp (100%) rename crude_json.h => external/crude_json.h (100%) rename EditorContext.cpp => external/imgui_node/EditorContext.cpp (100%) rename EditorContext.h => external/imgui_node/EditorContext.h (100%) rename NodeEx.cpp => external/imgui_node/NodeEx.cpp (100%) rename {examples/blueprints-example/blocks => external/imgui_node}/NodeEx.h (100%) rename imgui_bezier_math.h => external/imgui_node/imgui_bezier_math.h (100%) rename imgui_bezier_math.inl => external/imgui_node/imgui_bezier_math.inl (100%) rename imgui_canvas.cpp => external/imgui_node/imgui_canvas.cpp (100%) rename imgui_canvas.h => external/imgui_node/imgui_canvas.h (100%) rename imgui_extra_math.h => external/imgui_node/imgui_extra_math.h (100%) rename imgui_extra_math.inl => external/imgui_node/imgui_extra_math.inl (100%) rename imgui_node_editor.cpp => external/imgui_node/imgui_node_editor.cpp (99%) rename imgui_node_editor.h => external/imgui_node/imgui_node_editor.h (98%) rename imgui_node_editor_animation.cpp => external/imgui_node/imgui_node_editor_animation.cpp (100%) rename imgui_node_editor_api.cpp => external/imgui_node/imgui_node_editor_api.cpp (99%) rename imgui_node_editor_internal.h => external/imgui_node/imgui_node_editor_internal.h (99%) rename imgui_node_editor_internal.inl => external/imgui_node/imgui_node_editor_internal.inl (100%) rename imgui_node_editor_store.cpp => external/imgui_node/imgui_node_editor_store.cpp (100%) rename links-guided.cpp => external/imgui_node/links-guided.cpp (100%) rename links-guided.h => external/imgui_node/links-guided.h (100%) delete mode 100644 imgui_node_editor_edit.cpp delete mode 100644 imgui_node_editor_links.cpp delete mode 100644 imgui_node_editor_render.cpp delete mode 100644 imgui_node_editor_runtime.cpp delete mode 100644 imgui_node_editor_selection.cpp delete mode 100644 imgui_node_editor_tools.cpp create mode 100644 package-lock.json create mode 100644 ref/cpp/main.c create mode 100644 ref/cpp/main.cpp create mode 100644 ref/vt-ex/include/AutoLock.h create mode 100644 ref/vt-ex/include/BaseMacros.h create mode 100644 ref/vt-ex/include/ConStream.h create mode 100644 ref/vt-ex/include/DllTools.h create mode 100644 ref/vt-ex/include/bCCOError.h create mode 100644 ref/vt-ex/include/base.h create mode 100644 ref/vt-ex/include/base_macros.h create mode 100644 ref/vt-ex/include/pch.h create mode 100644 ref/vt-ex/include/sharedStructs.h create mode 100644 ref/vt-ex/include/uxString.h create mode 100644 ref/vt-ex/include/virtools/vtAll.h create mode 100644 ref/vt-ex/include/virtools/vtBBHelper.h create mode 100644 ref/vt-ex/include/virtools/vtBBMacros.h create mode 100644 ref/vt-ex/include/virtools/vtBase.h create mode 100644 ref/vt-ex/include/virtools/vtBaseMacros.h create mode 100644 ref/vt-ex/include/virtools/vtCXGlobal.h create mode 100644 ref/vt-ex/include/virtools/vtCXPlatform32.h create mode 100644 ref/vt-ex/include/virtools/vtCXPrecomp.h create mode 100644 ref/vt-ex/include/virtools/vtGUID.h create mode 100644 ref/vt-ex/include/virtools/vtStructHelper.h create mode 100644 ref/vt-ex/include/virtools/vtTools.h create mode 100644 ref/vt-ex/include/vtxall.h create mode 100644 ref/vt-ex/include/xAssertCustomization.h create mode 100644 ref/vt-ex/include/xAssertion.h create mode 100644 ref/vt-ex/include/xBitSet.h create mode 100644 ref/vt-ex/include/xDebugTools.h create mode 100644 ref/vt-ex/include/xLogger.h create mode 100644 ref/vt-ex/include/xPlatform.h create mode 100644 ref/vt-ex/src/3D/DXDiagNVUtil.cpp create mode 100644 ref/vt-ex/src/3D/GetGPUAndSystemInfo.cpp create mode 100644 ref/vt-ex/src/3D/NV_StringFuncs.cpp create mode 100644 ref/vt-ex/src/3D/nvfile.cpp create mode 100644 ref/vt-ex/src/profile/GDirectory.cpp create mode 100644 ref/vt-ex/src/profile/GException.cpp create mode 100644 ref/vt-ex/src/profile/GList.cpp create mode 100644 ref/vt-ex/src/profile/GProfile.cpp create mode 100644 ref/vt-ex/src/profile/GString.cpp create mode 100644 ref/vt-ex/src/profile/GStringList.cpp create mode 100644 ref/vt-ex/src/virtools/Behaviors/generic/BGInstancer.cpp create mode 100644 ref/vt-ex/src/virtools/Behaviors/generic/BGInstancer.h create mode 100644 ref/vt-ex/src/virtools/Behaviors/generic/GBLAsyncBlock.cpp create mode 100644 ref/vt-ex/src/virtools/Behaviors/generic/GBLAsyncBlock.h create mode 100644 ref/vt-ex/src/virtools/Behaviors/generic/GetSubBBId.cpp create mode 100644 ref/vt-ex/src/virtools/Behaviors/joystick/JSetXYForce.cpp create mode 100644 ref/vt-ex/src/virtools/Behaviors/joystick/PlayEffect.cpp create mode 100644 ref/vt-ex/src/virtools/Behaviors/joystick/hasFFe.cpp create mode 100644 ref/vt-ex/src/virtools/Behaviors/joystick/jTest.cmo create mode 100644 ref/vt-ex/src/virtools/Behaviors/joystick/readffe.cpp create mode 100644 ref/vt-ex/src/virtools/vtTools.cpp delete mode 100644 run-with-console.bat delete mode 100644 scripts/build.bat delete mode 100644 scripts/build.ps1 create mode 100644 scripts/generate_protos.sh delete mode 100644 src/.gitignore delete mode 100644 sslast.png create mode 100644 tests/commons.ts create mode 100644 tests/e2e.test.ts create mode 100644 tests/fixtures/graph-log.json diff --git a/.gitignore b/.gitignore index 12d83a1..634306d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ bin *.VC.opendb *.user *.ini -*.json docs/html docs/docbook -build +node_modules +last-run.log \ No newline at end of file diff --git a/.npmignore b/.npmignore deleted file mode 100644 index 4c9adda..0000000 --- a/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -./docs -./scripts -./tests -./incoming \ No newline at end of file diff --git a/Blueprints.json b/Blueprints.json new file mode 100644 index 0000000..69082ea --- /dev/null +++ b/Blueprints.json @@ -0,0 +1,25 @@ +{ + "selection": null, + "view": + { + "scroll": + { + "x": 0, + "y": 0 + }, + "visible_rect": + { + "max": + { + "x": 1000, + "y": 562 + }, + "min": + { + "x": 0, + "y": 0 + } + }, + "zoom": 1 + } +} \ No newline at end of file diff --git a/BlueprintsGraph.json b/BlueprintsGraph.json new file mode 100644 index 0000000..5303ee4 --- /dev/null +++ b/BlueprintsGraph.json @@ -0,0 +1,4 @@ +{ + "app_links": null, + "app_nodes": null +} \ No newline at end of file diff --git a/Blueprints_window.json b/Blueprints_window.json new file mode 100644 index 0000000..8a8310a --- /dev/null +++ b/Blueprints_window.json @@ -0,0 +1,10 @@ +{ + "window": { + "x": -1, + "y": -1, + "width": 1440, + "height": 800, + "monitor": 0, + "maximized": false + } +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f354bc8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 3.5) +project(NodeHub) + +# ============================================================================== +# Dependencies +# ============================================================================== +include(FetchContent) + +# Google Test (for C++ unit tests) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) +FetchContent_MakeAvailable(googletest) + +# Protocol Buffers +FetchContent_Declare( + protobuf + GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git + GIT_TAG v21.9 +) +FetchContent_MakeAvailable(protobuf) + +# ============================================================================== +# Add subdirectories +# ============================================================================== +add_subdirectory(applications/base) +add_subdirectory(applications/nodehub) +add_subdirectory(applications/protos) +if (BUILD_TESTING) + add_subdirectory(applications/tests) +endif() diff --git a/Doxyfile b/Doxyfile index 851157b..5819ab6 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1057,7 +1057,7 @@ EXCLUDE = ./build \ ./external/stb_image_latest \ ./misc \ ./NodeEditor/External \ - ./examples/application + ./applications/ # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/examples/CMakeLists.txt b/applications/CMakeLists.txt similarity index 53% rename from examples/CMakeLists.txt rename to applications/CMakeLists.txt index 4c6d198..8db5318 100644 --- a/examples/CMakeLists.txt +++ b/applications/CMakeLists.txt @@ -1,31 +1,117 @@ -cmake_minimum_required(VERSION 3.12) +# Set up vcpkg toolchain +if(DEFINED CMAKE_TOOLCHAIN_FILE AND EXISTS "${CMAKE_TOOLCHAIN_FILE}") + include(${CMAKE_TOOLCHAIN_FILE}) +endif() +#------------------------------------------------------------------------------ +# ImGui Node Editor examples build configuration. +# - `get_filename_component(... ABSOLUTE CACHE)` resolves the project root to +# an absolute path and stores it in CMake's cache so re-configures reuse it. +# - `USE_FOLDERS` enables logical IDE folders for generated projects. +# - `BUILD_CONSOLE_VARIANTS` toggles additional Win32 console builds. +# - `USE_CONSOLE_AS_STARTUP` selects which target Visual Studio launches. +# - `EXAMPLES_NO_WARNING_FLAGS` holds warning overrides (set to `/W0` on MSVC). +#------------------------------------------------------------------------------ +cmake_minimum_required(VERSION 3.5) + +# Root project that pulls in the node editor and builds the sample apps. project(imgui-node-editor) +# Enable testing capabilities with CTest +enable_testing() + +# Fetch Google Test framework +include(FetchContent) +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) + +# Enforce the same compiler settings for gtest as for our project +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +FetchContent_MakeAvailable(googletest) + +# Option to enable/disable protobuf support (default: ON) +option(ENABLE_PROTOBUF "Enable Protocol Buffers support" ON) + +# Protocol Buffers support (optional, via vcpkg) +if (ENABLE_PROTOBUF) + # Try CONFIG mode first (modern protobuf CMake, works with vcpkg) + find_package(protobuf CONFIG QUIET) + if (protobuf_FOUND) + message(STATUS "Protocol Buffers: ENABLED (found via CONFIG mode)") + # Create an interface library to propagate protobuf settings + add_library(protobuf_interface INTERFACE) + target_link_libraries(protobuf_interface INTERFACE + protobuf::libprotobuf + protobuf::libprotoc + ) + target_compile_definitions(protobuf_interface INTERFACE ENABLE_PROTOBUF=1) + else() + # Fallback to MODULE mode (legacy FindProtobuf) + find_package(Protobuf QUIET) + if (Protobuf_FOUND) + message(STATUS "Protocol Buffers: ENABLED (found via MODULE mode)") + # Create an interface library to propagate protobuf settings + add_library(protobuf_interface INTERFACE) + target_link_libraries(protobuf_interface INTERFACE ${Protobuf_LIBRARIES}) + target_include_directories(protobuf_interface INTERFACE ${Protobuf_INCLUDE_DIRS}) + target_compile_definitions(protobuf_interface INTERFACE ENABLE_PROTOBUF=1) + else() + message(WARNING "Protocol Buffers: ENABLED but not found. Install via 'vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows' or set ENABLE_PROTOBUF=OFF") + message(WARNING " To use vcpkg, configure CMake with: -DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake") + endif() + endif() +else() + message(STATUS "Protocol Buffers: DISABLED") +endif() + # Define IMGUI_NODE_EDITOR_ROOT_DIR pointing to project root directory get_filename_component(IMGUI_NODE_EDITOR_ROOT_DIR ${CMAKE_SOURCE_DIR}/.. ABSOLUTE CACHE) +# Define IMGUI_NODE_EDITOR_ROOT_DIR pointing to project root directory +get_filename_component(ROOT_DIR ${CMAKE_SOURCE_DIR}/.. ABSOLUTE CACHE) + +# Ensure IDE generators expose logical folder groupings instead of a flat list. # Enable solution folders in Visual Studio and Folders in Xcode set_property(GLOBAL PROPERTY USE_FOLDERS ON) +# Extend the module search path so `find_package(imgui_node_editor)` locates the +# custom `Findimgui_node_editor.cmake` bundled with this repository. # Point CMake where to look for module files. list(APPEND CMAKE_MODULE_PATH ${IMGUI_NODE_EDITOR_ROOT_DIR}/misc/cmake-modules) +# Central place to tweak warning configuration for all example targets. +if (MSVC) + set(EXAMPLES_NO_WARNING_FLAGS "/W0" CACHE STRING "Compiler warning overrides applied to all example targets" FORCE) +elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") + set(EXAMPLES_NO_WARNING_FLAGS "-w" CACHE STRING "Compiler warning overrides applied to all example targets" FORCE) +else() + set(EXAMPLES_NO_WARNING_FLAGS "" CACHE STRING "Compiler warning overrides applied to all example targets" FORCE) +endif() + +# Examples use C++17 features (structured bindings, custom unordered_map hash). # Node editor use C++17 (required for structured bindings and unordered_map with custom hash) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED YES) +# Make it easy to toggle console builds without editing the file. # Option to also build console variants on Windows -option(BUILD_CONSOLE_VARIANTS "Also build console variants of applications on Windows" ON) +# option(BUILD_CONSOLE_VARIANTS "Also build console variants of applications on Windows" ON) +# Let developers choose which target Visual Studio launches by default. # Option to set console variant as default VS startup project -option(USE_CONSOLE_AS_STARTUP "Set console variant as Visual Studio startup project" ON) +# option(USE_CONSOLE_AS_STARTUP "Set console variant as Visual Studio startup project" ON) # Macro that will configure an example application macro(add_example_executable name) + # Start a nested project for each example so properties such as versioning + # remain isolated. project(${name}) + # Collect all sources provided by the caller. set(_Example_Sources ${ARGN} ) @@ -37,24 +123,26 @@ macro(add_example_executable name) # Group example sources under their tree source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${ARGN}) # Group entry_point.cpp separately since it's from application directory - source_group("application" FILES ${APPLICATION_ENTRY_POINT_SOURCE}) + source_group("base" FILES ${APPLICATION_ENTRY_POINT_SOURCE}) - file(GLOB _Example_CommonResources CONFIGURE_DEPENDS "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/data/*") + file(GLOB _Nodehub_CommonResources CONFIGURE_DEPENDS "${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/nodehub/data/*") + file(GLOB _Example_CommonResources CONFIGURE_DEPENDS "${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/base/data/*") file(GLOB _Example_Resources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/data/*") #message(FATAL_ERROR "_Example_Resources = ${_Example_Resources}") + # Choose bundle/executable type depending on platform. set(_Example_Type) if (WIN32) set(_Example_Type WIN32) - set(ApplicationIcon ${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/Application/Support/Icon.ico) + set(ApplicationIcon ${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/base/support/Icon.ico) file(TO_NATIVE_PATH "${ApplicationIcon}" ApplicationIcon) string(REPLACE "\\" "\\\\" ApplicationIcon "${ApplicationIcon}") configure_file( - ${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/Application/Support/Resource.rc.in + ${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/base/support/Resource.rc.in ${CMAKE_CURRENT_BINARY_DIR}/Resource.rc ) - source_group(TREE "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples" FILES ${_Example_CommonResources}) + source_group(TREE "${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/base" FILES ${_Example_CommonResources}) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${_Example_Resources}) list(APPEND _Example_Resources ${CMAKE_CURRENT_BINARY_DIR}/Resource.rc @@ -67,7 +155,7 @@ macro(add_example_executable name) set_source_files_properties(${_Example_Resources} ${_Example_CommonResources} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/data" ) - set(_Example_Icon "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/application/support/Icon.icns") + set(_Example_Icon "${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/base/support/Icon.icns") list(APPEND _Example_Resources ${_Example_Icon}) set_source_files_properties(${_Example_Icon} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" @@ -76,6 +164,10 @@ macro(add_example_executable name) add_executable(${name} ${_Example_Type} ${_Example_Sources} ${_Example_Resources} ${_Example_CommonResources}) + if (EXAMPLES_NO_WARNING_FLAGS) + target_compile_options(${name} PRIVATE ${EXAMPLES_NO_WARNING_FLAGS}) + endif() + # Add /FS flag for MSVC to prevent PDB locking issues during parallel builds if (WIN32 AND MSVC) target_compile_options(${name} PRIVATE /FS) @@ -83,12 +175,17 @@ macro(add_example_executable name) find_package(imgui REQUIRED) find_package(imgui_node_editor REQUIRED) - target_link_libraries(${name} PRIVATE imgui imgui_node_editor application) + target_link_libraries(${name} PRIVATE imgui imgui_node_editor base) + + # Link protobuf if available + if (ENABLE_PROTOBUF AND TARGET protobuf_interface) + target_link_libraries(${name} PRIVATE protobuf_interface) + endif() set(_ExampleBinDir ${CMAKE_BINARY_DIR}/bin) set_target_properties(${name} PROPERTIES - FOLDER "examples" + FOLDER "applications" RUNTIME_OUTPUT_DIRECTORY "${_ExampleBinDir}" RUNTIME_OUTPUT_DIRECTORY_DEBUG "${_ExampleBinDir}" RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${_ExampleBinDir}" @@ -98,7 +195,7 @@ macro(add_example_executable name) RELWITHDEBINGO_POSTFIX _rd MINSIZEREL_POSTFIX _r VS_DEBUGGER_WORKING_DIRECTORY ${_ExampleBinDir} - MACOSX_BUNDLE_INFO_PLIST "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/application/support/Info.plist.in" + MACOSX_BUNDLE_INFO_PLIST "${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/base/support/Info.plist.in" MACOSX_BUNDLE_BUNDLE_NAME "${PACKAGE_NAME}" MACOSX_BUNDLE_GUI_IDENTIFIER "com.sandbox.collisions" MACOSX_BUNDLE_LONG_VERSION_STRING "${PACKAGE_VERSION}" @@ -106,6 +203,7 @@ macro(add_example_executable name) MACOSX_BUNDLE_ICON_FILE Icon.icns ) + # Ensure the runtime data directory exists before copying anything in. add_custom_command( TARGET ${name} PRE_BUILD @@ -113,7 +211,9 @@ macro(add_example_executable name) ) set(_ResourceRoot ${CMAKE_CURRENT_SOURCE_DIR}) - foreach(_Resource ROOT "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/data" ${_Example_CommonResources} ROOT "${CMAKE_CURRENT_SOURCE_DIR}/data" ${_Example_Resources}) + # Copy both shared and example-specific data into the runtime folder while + # preserving relative paths. + foreach(_Resource ROOT "${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/base/data" ${_Example_CommonResources} ROOT "${CMAKE_CURRENT_SOURCE_DIR}/data" ${_Example_Resources}) if (_Resource STREQUAL ROOT) set(_ResourceRoot FALSE) continue() @@ -144,6 +244,10 @@ macro(add_example_executable name) # Create console executable (without WIN32 flag) add_executable(${_ConsoleTargetName} ${_Example_Sources} ${_Example_Resources} ${_Example_CommonResources}) + if (EXAMPLES_NO_WARNING_FLAGS) + target_compile_options(${_ConsoleTargetName} PRIVATE ${EXAMPLES_NO_WARNING_FLAGS}) + endif() + # Define _CONSOLE to use main() instead of WinMain() target_compile_definitions(${_ConsoleTargetName} PRIVATE _CONSOLE) @@ -157,6 +261,11 @@ macro(add_example_executable name) find_package(imgui_node_editor REQUIRED) target_link_libraries(${_ConsoleTargetName} PRIVATE imgui imgui_node_editor application) + # Link protobuf if available + if (ENABLE_PROTOBUF AND TARGET protobuf_interface) + target_link_libraries(${_ConsoleTargetName} PRIVATE protobuf_interface) + endif() + # Set the same properties as the GUI version set_target_properties(${_ConsoleTargetName} PROPERTIES FOLDER "examples" @@ -178,7 +287,7 @@ macro(add_example_executable name) COMMAND ${CMAKE_COMMAND} -E make_directory ARGS ${_ExampleBinDir}/data ) - foreach(_Resource ROOT "${IMGUI_NODE_EDITOR_ROOT_DIR}/examples/data" ${_Example_CommonResources} ROOT "${CMAKE_CURRENT_SOURCE_DIR}/data" ${_Example_Resources}) + foreach(_Resource ROOT "${IMGUI_NODE_EDITOR_ROOT_DIR}/applications/base/data" ${_Example_CommonResources} ROOT "${CMAKE_CURRENT_SOURCE_DIR}/data" ${_Example_Resources}) if (_Resource STREQUAL ROOT) set(_ResourceRoot FALSE) continue() @@ -193,6 +302,7 @@ macro(add_example_executable name) file(RELATIVE_PATH _RelResource ${_ResourceRoot} ${_Resource}) + # Reuse the resource copying logic for the console binary. add_custom_command( TARGET ${_ConsoleTargetName} PRE_BUILD @@ -203,14 +313,16 @@ macro(add_example_executable name) endmacro() -add_subdirectory(application) -add_subdirectory(blueprints-example) +# Build the shared application support code and individual examples. +add_subdirectory(base) +add_subdirectory(nodehub) +add_subdirectory(tests) # Set the default Visual Studio startup project if (WIN32 AND BUILD_CONSOLE_VARIANTS AND USE_CONSOLE_AS_STARTUP) - set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT blueprints-example-console) - message(STATUS "Visual Studio startup project: blueprints-example-console") + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT nodehub-console) + message(STATUS "Visual Studio startup project: nodehub-console") else() - set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT blueprints-example) - message(STATUS "Visual Studio startup project: blueprints-example") + set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT nodehub) + message(STATUS "Visual Studio startup project: nodehub") endif() diff --git a/examples/application/CMakeLists.txt b/applications/base/CMakeLists.txt similarity index 68% rename from examples/application/CMakeLists.txt rename to applications/base/CMakeLists.txt index bbfd4b4..5ced4bd 100644 --- a/examples/application/CMakeLists.txt +++ b/applications/base/CMakeLists.txt @@ -1,8 +1,9 @@ -project(application) +cmake_minimum_required(VERSION 3.5) +project(base) -set(_Application_Sources - include/application.h - source/application.cpp +set(_base_Sources + include/base.h + source/base.cpp source/entry_point.cpp source/imgui_extra_keys.h source/config.h.in @@ -18,23 +19,23 @@ set(_Application_Sources # entry_point.cpp is not included in the library because it has # conditional compilation for WinMain() vs main() based on _CONSOLE define. # It will be added directly to each executable target instead. -set(APPLICATION_ENTRY_POINT_SOURCE +set(base_ENTRY_POINT_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/source/entry_point.cpp CACHE INTERNAL "" ) -add_library(application STATIC) +add_library(base STATIC) -target_include_directories(application PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) +target_include_directories(base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) find_package(imgui REQUIRED) find_package(stb_image REQUIRED) find_package(ScopeGuard REQUIRED) -target_link_libraries(application PUBLIC imgui) -target_link_libraries(application PRIVATE stb_image ScopeGuard) +target_link_libraries(base PUBLIC imgui) +target_link_libraries(base PRIVATE stb_image ScopeGuard) if (WIN32) - list(APPEND _Application_Sources + list(APPEND _base_Sources source/imgui_impl_dx11.cpp source/imgui_impl_dx11.h source/imgui_impl_win32.cpp @@ -59,13 +60,13 @@ if (WIN32) INTERFACE_LINK_LIBRARIES "$<$:dxerr>" ) - target_link_libraries(application PRIVATE d3d11.lib d3dcompiler.lib d3dx11) + target_link_libraries(base PRIVATE d3d11.lib d3dcompiler.lib d3dx11) else() find_package(OpenGL REQUIRED) find_package(glfw3 3 REQUIRED) if (APPLE) - target_link_libraries(application PRIVATE + target_link_libraries(base PRIVATE "-framework CoreFoundation" "-framework Cocoa" "-framework IOKit" @@ -77,9 +78,9 @@ endif() if (OpenGL_FOUND) set(HAVE_OPENGL YES) - target_include_directories(application PRIVATE ${OPENGL_INCLUDE_DIR}) - target_link_libraries(application PRIVATE ${OPENGL_gl_LIBRARY}) - list(APPEND _Application_Sources + target_include_directories(base PRIVATE ${OPENGL_INCLUDE_DIR}) + target_link_libraries(base PRIVATE ${OPENGL_gl_LIBRARY}) + list(APPEND _base_Sources source/imgui_impl_opengl3.cpp source/imgui_impl_opengl3.h source/imgui_impl_opengl3_loader.h @@ -89,11 +90,11 @@ endif() if (glfw3_FOUND) set(HAVE_GLFW3 YES) - list(APPEND _Application_Sources + list(APPEND _base_Sources source/imgui_impl_glfw.cpp source/imgui_impl_glfw.h ) - target_link_libraries(application PRIVATE + target_link_libraries(base PRIVATE glfw ) endif() @@ -103,16 +104,16 @@ configure_file( ${CMAKE_CURRENT_BINARY_DIR}/source/config.h ) -target_compile_definitions(application PRIVATE +target_compile_definitions(base PRIVATE #BACKEND_CONFIG=IMGUI_GLFW #RENDERER_CONFIG=IMGUI_OGL3 ) # Make config.h include directory PUBLIC since entry_point.cpp (which needs it) is now compiled in executables -target_include_directories(application PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/source) +target_include_directories(base PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/source) -source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${_Application_Sources}) +source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${_base_Sources}) -target_sources(application PRIVATE ${_Application_Sources}) +target_sources(base PRIVATE ${_base_Sources}) -set_property(TARGET application PROPERTY FOLDER "examples") \ No newline at end of file +set_property(TARGET base PROPERTY FOLDER "applications") \ No newline at end of file diff --git a/applications/base/include/app-types.h b/applications/base/include/app-types.h new file mode 100644 index 0000000..1223af9 --- /dev/null +++ b/applications/base/include/app-types.h @@ -0,0 +1,33 @@ +#ifndef APP_TYPES_H +#define APP_TYPES_H + +# include +# include +# include +# include +#include + +struct ArgValue +{ + enum class Type { Empty, Bool, Int, Double, String }; + + Type Type = Type::Empty; + + bool Bool = false; + long long Int = 0; + double Double = 0.0; + std::string String; + + ArgValue() = default; + ArgValue(bool value) : Type(Type::Bool), Bool(value) {} + ArgValue(int value) : Type(Type::Int), Int(value) {} + ArgValue(long long value) : Type(Type::Int), Int(value) {} + ArgValue(float value) : Type(Type::Double), Double(value) {} + ArgValue(double value) : Type(Type::Double), Double(value) {} + ArgValue(const char* value) : Type(Type::String), String(value) {} + ArgValue(std::string value) : Type(Type::String), String(std::move(value)) {} +}; + +using ArgsMap = std::map; + +#endif \ No newline at end of file diff --git a/examples/application/include/application.h b/applications/base/include/base.h similarity index 70% rename from examples/application/include/application.h rename to applications/base/include/base.h index f9ad2d1..4cdc1fc 100644 --- a/examples/application/include/application.h +++ b/applications/base/include/base.h @@ -5,6 +5,9 @@ # include # include +# include "app-types.h" + + struct WindowState { int x = -1; @@ -15,29 +18,6 @@ struct WindowState bool maximized = false; }; -struct ArgValue -{ - enum class Type { Empty, Bool, Int, Double, String }; - - Type Type = Type::Empty; - - bool Bool = false; - long long Int = 0; - double Double = 0.0; - std::string String; - - ArgValue() = default; - ArgValue(bool value) : Type(Type::Bool), Bool(value) {} - ArgValue(int value) : Type(Type::Int), Int(value) {} - ArgValue(long long value) : Type(Type::Int), Int(value) {} - ArgValue(float value) : Type(Type::Double), Double(value) {} - ArgValue(double value) : Type(Type::Double), Double(value) {} - ArgValue(const char* value) : Type(Type::String), String(value) {} - ArgValue(std::string value) : Type(Type::String), String(std::move(value)) {} -}; - -using ArgsMap = std::map; - struct Platform; struct Renderer; diff --git a/examples/application/source/application.cpp b/applications/base/source/base.cpp similarity index 82% rename from examples/application/source/application.cpp rename to applications/base/source/base.cpp index 7f78406..54ce464 100644 --- a/examples/application/source/application.cpp +++ b/applications/base/source/base.cpp @@ -1,4 +1,4 @@ -# include "application.h" +# include "base.h" # include "setup.h" # include "platform.h" # include "renderer.h" @@ -14,6 +14,71 @@ # include #endif +namespace { + +#ifdef _WIN32 +static inline std::string WideToUtf8(const wchar_t* wstr) { + if (!wstr) return {}; + // Ask for required size (includes NUL) + const int n = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, nullptr, 0, nullptr, nullptr); + if (n <= 0) return {}; + std::string out; + out.resize(n - 1); // we store without the trailing NUL + +#if __cplusplus >= 201703L + // C++17: string::data() is char* + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, out.data(), n, nullptr, nullptr); +#else + // C++11/14: use &out[0] to get char* + WideCharToMultiByte(CP_UTF8, 0, wstr, -1, &out[0], n, nullptr, nullptr); +#endif + + // The call above wrote a NUL at the end because we passed length n. + // Keep size at n-1 (already set via resize). + return out; +} + +static std::string GetExecutableDir() +{ + wchar_t exe_path_buffer[MAX_PATH] = { 0 }; + if (GetModuleFileNameW(NULL, exe_path_buffer, MAX_PATH) == 0) + return ""; + + std::wstring exe_path(exe_path_buffer); + size_t last_slash = exe_path.find_last_of(L"\\/"); + if (last_slash == std::wstring::npos) + return ""; + + return WideToUtf8(exe_path.substr(0, last_slash).c_str()); +} +#else +static std::string GetExecutableDir() +{ + // Implementation for other platforms (e.g., Linux, macOS) would go here. + return ""; +} +#endif + +static std::string ResolveResourcePath(const std::string& relativePath) +{ + static const std::string exeDir = GetExecutableDir(); + if (!exeDir.empty()) + { + std::string exePath = exeDir + "/" + relativePath; + std::ifstream f(exePath); + if (f.good()) + { + return exePath; + } + } + + // Fallback to CWD + return relativePath; +} + +} // namespace + + extern "C" { #define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_STATIC @@ -22,11 +87,7 @@ extern "C" { Application::Application(const char* name) - : Application(name, {}) -{ - int d = 2; - d++; -} + : Application(name, {}){} Application::Application(const char* name, const ArgsMap& args) : m_Name(name) @@ -170,8 +231,8 @@ void Application::RecreateFontAtlas() config.OversampleV = 4; config.PixelSnapH = false; - m_DefaultFont = io.Fonts->AddFontFromFileTTF("data/Play-Regular.ttf", 18.0f, &config); - m_HeaderFont = io.Fonts->AddFontFromFileTTF("data/Cuprum-Bold.ttf", 20.0f, &config); + m_DefaultFont = io.Fonts->AddFontFromFileTTF(ResolveResourcePath("data/Play-Regular.ttf").c_str(), 18.0f, &config); + m_HeaderFont = io.Fonts->AddFontFromFileTTF(ResolveResourcePath("data/Cuprum-Bold.ttf").c_str(), 20.0f, &config); io.Fonts->Build(); } @@ -273,7 +334,7 @@ ImFont* Application::HeaderFont() const ImTextureID Application::LoadTexture(const char* path) { int width = 0, height = 0, component = 0; - if (auto data = stbi_load(path, &width, &height, &component, 4)) + if (auto data = stbi_load(ResolveResourcePath(path).c_str(), &width, &height, &component, 4)) { auto texture = CreateTexture(data, width, height); stbi_image_free(data); diff --git a/applications/base/source/config.h b/applications/base/source/config.h new file mode 100644 index 0000000..2131cc7 --- /dev/null +++ b/applications/base/source/config.h @@ -0,0 +1,4 @@ +# pragma once + +# define HAVE_GLFW3 0 +# define HAVE_OPENGL 0 diff --git a/examples/application/source/config.h.in b/applications/base/source/config.h.in similarity index 100% rename from examples/application/source/config.h.in rename to applications/base/source/config.h.in diff --git a/examples/application/source/entry_point.cpp b/applications/base/source/entry_point.cpp similarity index 95% rename from examples/application/source/entry_point.cpp rename to applications/base/source/entry_point.cpp index 1b915c0..b4ce262 100644 --- a/examples/application/source/entry_point.cpp +++ b/applications/base/source/entry_point.cpp @@ -1,6 +1,6 @@ #define _CRT_SECURE_NO_WARNINGS -# include "application.h" +# include "base.h" # include "platform.h" # include # include @@ -44,7 +44,7 @@ public: // Runtime execution options app.add_flag("--run", "Execute the graph runtime (used with --headless and --graph)"); - app.add_option("--log", "Logging options (all, blocks, links, none)")->capture_default_str(); + app.add_option("--log", "Path to log file (absolute or relative)")->capture_default_str(); app.add_option("--log-level", "Minimum logging level (trace, debug, info, warn, error, critical, off)")->capture_default_str(); // Manual pre-check for help flag because allow_extras() interferes with normal help handling @@ -68,9 +68,16 @@ public: for (const CLI::Option* option : app.get_options()) { - if(option->count() > 0 && !option->get_lnames().empty() && !option->results().empty()) + if(option->count() > 0 && !option->get_lnames().empty()) { - (*args_map)[option->get_lnames()[0]] = ParseValue(option->results()[0]); + if (!option->results().empty()) + { + (*args_map)[option->get_lnames()[0]] = ParseValue(option->results()[0]); + } + else + { + (*args_map)[option->get_lnames()[0]] = ArgValue(true); + } } } diff --git a/examples/application/source/imgui_extra_keys.h b/applications/base/source/imgui_extra_keys.h similarity index 100% rename from examples/application/source/imgui_extra_keys.h rename to applications/base/source/imgui_extra_keys.h diff --git a/examples/application/source/imgui_impl_dx11.cpp b/applications/base/source/imgui_impl_dx11.cpp similarity index 100% rename from examples/application/source/imgui_impl_dx11.cpp rename to applications/base/source/imgui_impl_dx11.cpp diff --git a/examples/application/source/imgui_impl_dx11.h b/applications/base/source/imgui_impl_dx11.h similarity index 100% rename from examples/application/source/imgui_impl_dx11.h rename to applications/base/source/imgui_impl_dx11.h diff --git a/examples/application/source/imgui_impl_glfw.cpp b/applications/base/source/imgui_impl_glfw.cpp similarity index 100% rename from examples/application/source/imgui_impl_glfw.cpp rename to applications/base/source/imgui_impl_glfw.cpp diff --git a/examples/application/source/imgui_impl_glfw.h b/applications/base/source/imgui_impl_glfw.h similarity index 100% rename from examples/application/source/imgui_impl_glfw.h rename to applications/base/source/imgui_impl_glfw.h diff --git a/examples/application/source/imgui_impl_opengl3.cpp b/applications/base/source/imgui_impl_opengl3.cpp similarity index 100% rename from examples/application/source/imgui_impl_opengl3.cpp rename to applications/base/source/imgui_impl_opengl3.cpp diff --git a/examples/application/source/imgui_impl_opengl3.h b/applications/base/source/imgui_impl_opengl3.h similarity index 100% rename from examples/application/source/imgui_impl_opengl3.h rename to applications/base/source/imgui_impl_opengl3.h diff --git a/examples/application/source/imgui_impl_opengl3_loader.h b/applications/base/source/imgui_impl_opengl3_loader.h similarity index 100% rename from examples/application/source/imgui_impl_opengl3_loader.h rename to applications/base/source/imgui_impl_opengl3_loader.h diff --git a/examples/application/source/imgui_impl_win32.cpp b/applications/base/source/imgui_impl_win32.cpp similarity index 100% rename from examples/application/source/imgui_impl_win32.cpp rename to applications/base/source/imgui_impl_win32.cpp diff --git a/examples/application/source/imgui_impl_win32.h b/applications/base/source/imgui_impl_win32.h similarity index 100% rename from examples/application/source/imgui_impl_win32.h rename to applications/base/source/imgui_impl_win32.h diff --git a/examples/application/source/platform.h b/applications/base/source/platform.h similarity index 100% rename from examples/application/source/platform.h rename to applications/base/source/platform.h diff --git a/examples/application/source/platform_glfw.cpp b/applications/base/source/platform_glfw.cpp similarity index 100% rename from examples/application/source/platform_glfw.cpp rename to applications/base/source/platform_glfw.cpp diff --git a/examples/application/source/platform_win32.cpp b/applications/base/source/platform_win32.cpp similarity index 99% rename from examples/application/source/platform_win32.cpp rename to applications/base/source/platform_win32.cpp index 05be5a2..615b7c6 100644 --- a/examples/application/source/platform_win32.cpp +++ b/applications/base/source/platform_win32.cpp @@ -3,7 +3,7 @@ # if BACKEND(IMGUI_WIN32) -# include "application.h" +# include "base.h" # include "renderer.h" # define NOMINMAX diff --git a/examples/application/source/renderer.h b/applications/base/source/renderer.h similarity index 100% rename from examples/application/source/renderer.h rename to applications/base/source/renderer.h diff --git a/examples/application/source/renderer_dx11.cpp b/applications/base/source/renderer_dx11.cpp similarity index 100% rename from examples/application/source/renderer_dx11.cpp rename to applications/base/source/renderer_dx11.cpp diff --git a/examples/application/source/renderer_ogl3.cpp b/applications/base/source/renderer_ogl3.cpp similarity index 100% rename from examples/application/source/renderer_ogl3.cpp rename to applications/base/source/renderer_ogl3.cpp diff --git a/examples/application/source/setup.h b/applications/base/source/setup.h similarity index 100% rename from examples/application/source/setup.h rename to applications/base/source/setup.h diff --git a/examples/application/support/Icon.icns b/applications/base/support/Icon.icns similarity index 100% rename from examples/application/support/Icon.icns rename to applications/base/support/Icon.icns diff --git a/examples/application/support/Icon.ico b/applications/base/support/Icon.ico similarity index 100% rename from examples/application/support/Icon.ico rename to applications/base/support/Icon.ico diff --git a/examples/application/support/Icon.png b/applications/base/support/Icon.png similarity index 100% rename from examples/application/support/Icon.png rename to applications/base/support/Icon.png diff --git a/examples/application/support/Info.plist.in b/applications/base/support/Info.plist.in similarity index 100% rename from examples/application/support/Info.plist.in rename to applications/base/support/Info.plist.in diff --git a/examples/application/support/Resource.rc.in b/applications/base/support/Resource.rc.in similarity index 100% rename from examples/application/support/Resource.rc.in rename to applications/base/support/Resource.rc.in diff --git a/examples/blueprints-example/data/BlueprintBackground.png b/applications/data/BlueprintBackground.png similarity index 100% rename from examples/blueprints-example/data/BlueprintBackground.png rename to applications/data/BlueprintBackground.png diff --git a/examples/data/Cuprum-Bold.ttf b/applications/data/Cuprum-Bold.ttf similarity index 100% rename from examples/data/Cuprum-Bold.ttf rename to applications/data/Cuprum-Bold.ttf diff --git a/examples/data/Cuprum-OFL.txt b/applications/data/Cuprum-OFL.txt similarity index 100% rename from examples/data/Cuprum-OFL.txt rename to applications/data/Cuprum-OFL.txt diff --git a/examples/data/Oswald-OFL.txt b/applications/data/Oswald-OFL.txt similarity index 100% rename from examples/data/Oswald-OFL.txt rename to applications/data/Oswald-OFL.txt diff --git a/examples/data/Oswald-Regular.ttf b/applications/data/Oswald-Regular.ttf similarity index 100% rename from examples/data/Oswald-Regular.ttf rename to applications/data/Oswald-Regular.ttf diff --git a/examples/data/Play-OFL.txt b/applications/data/Play-OFL.txt similarity index 100% rename from examples/data/Play-OFL.txt rename to applications/data/Play-OFL.txt diff --git a/examples/data/Play-Regular.ttf b/applications/data/Play-Regular.ttf similarity index 100% rename from examples/data/Play-Regular.ttf rename to applications/data/Play-Regular.ttf diff --git a/examples/blueprints-example/data/ic_restore_white_24dp.png b/applications/data/ic_restore_white_24dp.png similarity index 100% rename from examples/blueprints-example/data/ic_restore_white_24dp.png rename to applications/data/ic_restore_white_24dp.png diff --git a/examples/blueprints-example/data/ic_save_white_24dp.png b/applications/data/ic_save_white_24dp.png similarity index 100% rename from examples/blueprints-example/data/ic_save_white_24dp.png rename to applications/data/ic_save_white_24dp.png diff --git a/applications/nodehub/CMakeLists.txt b/applications/nodehub/CMakeLists.txt new file mode 100644 index 0000000..b51f32d --- /dev/null +++ b/applications/nodehub/CMakeLists.txt @@ -0,0 +1,112 @@ +cmake_minimum_required(VERSION 3.5) + +add_example_executable(nodehub + main.cpp + types.h + app.h + app.cpp + app-logic.cpp + app-render.cpp + app-screenshot.cpp + app-runtime.cpp + containers/container.h + containers/container.cpp + containers/root_container.h + containers/root_container.cpp + core/graph_state.h + core/graph_state.cpp + core/Object.h + core/Object.cpp + core/Parameter.h + core/Parameter.cpp + core/ParameterIn.h + core/ParameterIn.cpp + core/ParameterOut.h + core/ParameterOut.cpp + core/ParameterManager.h + core/ParameterManager.cpp + core/BaseManager.h + core/BaseManager.cpp + core/Context.h + core/Context.cpp + blocks/NodeEx.h + blocks/NodeEx.cpp + blocks/block.h + blocks/block.cpp + blocks/math_blocks.h + blocks/math_blocks.cpp + blocks/logic_blocks.h + blocks/logic_blocks.cpp + blocks/start_block.h + blocks/start_block.cpp + blocks/log_block.h + blocks/log_block.cpp + blocks/parameter_operation.h + blocks/parameter_operation.cpp + blocks/group_block.h + blocks/group_block.cpp + blocks/parameter_node.h + blocks/parameter_node.cpp + blocks/block_edit_dialog.h + blocks/block_edit_dialog.cpp + blocks/parameter_edit_dialog.h + blocks/parameter_edit_dialog.cpp + utilities/node_renderer_base.h + utilities/pathfinding.h + utilities/edge_editing.h + utilities/pin_renderer.h + utilities/style_manager.h + utilities/uuid_generator.h + utilities/uuid_id_manager.h + utilities/node_renderer_base.cpp + utilities/pathfinding.cpp + utilities/edge_editing.cpp + utilities/pin_renderer.cpp + utilities/style_manager.cpp + utilities/uuid_generator.cpp + utilities/uuid_id_manager.cpp + Logging.h + Logging.cpp + stats.cpp +) + +target_include_directories(nodehub PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../application/include") +target_include_directories(nodehub PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../nodehub/core") +target_include_directories(nodehub PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../nodehub/blocks") + +# Add local spdlog include directory (we copied it into our project) +target_include_directories(nodehub PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/external") +target_compile_definitions(nodehub PRIVATE FMT_HEADER_ONLY=1) + +# Add /utf-8 compiler flag for spdlog on MSVC +if (MSVC) + target_compile_options(nodehub PRIVATE /utf-8) +endif() + +# Link protobuf if available +if (PROTOBUF_AVAILABLE AND TARGET protobuf_interface) + target_link_libraries(nodehub PRIVATE protobuf_interface) +endif() + +# Also add to console variant if it exists +if (WIN32 AND BUILD_CONSOLE_VARIANTS) + target_include_directories(nodehub-console PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../application/include") + target_include_directories(nodehub-console PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/external") + target_compile_definitions(nodehub-console PRIVATE FMT_HEADER_ONLY=1) + if (MSVC) + target_compile_options(nodehub-console PRIVATE /utf-8) + endif() + # Link protobuf to console variant if available + if (PROTOBUF_AVAILABLE AND TARGET protobuf_interface) + target_link_libraries(nodehub-console PRIVATE protobuf_interface) + endif() +endif() + +file(GLOB NodeHubResources CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/data/*") +add_custom_command( + TARGET nodehub + PRE_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_directory + "${CMAKE_CURRENT_SOURCE_DIR}/data" + "$/data" +) diff --git a/examples/blueprints-example/Logging.cpp b/applications/nodehub/Logging.cpp similarity index 100% rename from examples/blueprints-example/Logging.cpp rename to applications/nodehub/Logging.cpp diff --git a/examples/blueprints-example/Logging.h b/applications/nodehub/Logging.h similarity index 100% rename from examples/blueprints-example/Logging.h rename to applications/nodehub/Logging.h diff --git a/applications/nodehub/all.h b/applications/nodehub/all.h new file mode 100644 index 0000000..c3db9e7 --- /dev/null +++ b/applications/nodehub/all.h @@ -0,0 +1,14 @@ +#pragma once + +// v2 +#include "commons.h" +#include "core/Object.h" +#include "core/Parameter.h" + +#include "utilities/uuid_generator.h" + + +//legacy blocks - v1 +#include "blocks/block.h" +#include "blocks/parameter_node.h" +#include "blocks/parameter_operation.h" diff --git a/examples/blueprints-example/app-logic.cpp b/applications/nodehub/app-logic.cpp similarity index 98% rename from examples/blueprints-example/app-logic.cpp rename to applications/nodehub/app-logic.cpp index 522cc00..cc69eed 100644 --- a/examples/blueprints-example/app-logic.cpp +++ b/applications/nodehub/app-logic.cpp @@ -482,19 +482,6 @@ void App::SaveGraph(const std::string& filename, RootContainer* container) continue; } - // Validate node pointer is not corrupted - uintptr_t nodePtrValue = reinterpret_cast(nodePtr); - if (nodePtrValue < 0x1000 || - nodePtrValue == 0xFFFFFFFFFFFFFFFFULL || - nodePtrValue == 0xDDDDDDDDDDDDDDDDULL || - nodePtrValue == 0xCDCDCDCDCDCDCDCDULL) - { - LOG_WARN("[SAVE] SaveGraph: Skipping corrupted node pointer: 0x{:016X}", - static_cast(nodePtrValue)); - orphanedNodes.push_back(const_cast(nodePtr)); - continue; - } - // Safe access to node type NodeType nodeType; try { diff --git a/examples/blueprints-example/app-render.cpp b/applications/nodehub/app-render.cpp similarity index 99% rename from examples/blueprints-example/app-render.cpp rename to applications/nodehub/app-render.cpp index 2419621084dab6cc14be669b56c7a645323d165e..4bf385057df14e1d1d4d0d9f9a70da559a7ad9c1 100644 GIT binary patch delta 337 zcmbR9Luk`yp$QEWe~E0|)%9p{Nw3882aYUkn`NE^iHnCY)Do!S@?H{>{9*0@ delta 534 zcma)%&nv@m7{{N_=ksl5^J8XfM%JP+MJO&dY-|fn`EgOEj4ed7MwHW}oE+3wdk*Bs z9nF+)DJLfv{0G)txQUBa z?`LFJw;Ek_Ooj0jSGBK#73LrUO%Q}Al@%7qF+&xG7~Q7m%)R7vOZh$w(|F`#<+$@K ztj!)$1?jh+816j5|IKgzLF-g&vLfEoxu1cU2*oLCaJ__zTzyF!mIH^P9E#Zrkf>*KL&d@U3fY#bCN z*fK8~QTN0uaQlPz;HN=U;#NTNUuebc8b-BDjm~4CV^O)uY{FzvNN7=!I%kos4{A)d oF-aNQ6!*6Os*%)}a=KQdtegn{=^tTqn2vF0!YC>f%2GG+1(6Mvx&QzG diff --git a/examples/blueprints-example/app-runtime.cpp b/applications/nodehub/app-runtime.cpp similarity index 99% rename from examples/blueprints-example/app-runtime.cpp rename to applications/nodehub/app-runtime.cpp index 95335cc..5bcd721 100644 --- a/examples/blueprints-example/app-runtime.cpp +++ b/applications/nodehub/app-runtime.cpp @@ -447,4 +447,5 @@ bool App::ExecuteRuntimeStep() return didAnyWork; } + return false; } diff --git a/examples/blueprints-example/app-screenshot.cpp b/applications/nodehub/app-screenshot.cpp similarity index 71% rename from examples/blueprints-example/app-screenshot.cpp rename to applications/nodehub/app-screenshot.cpp index ce59caa..cdaf684 100644 --- a/examples/blueprints-example/app-screenshot.cpp +++ b/applications/nodehub/app-screenshot.cpp @@ -4,38 +4,6 @@ #include #include -// Helper function to log to blueprints-log.md -static void LogToFile(const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - - // Always log to stdout/console - vprintf(fmt, args); - printf("\n"); - fflush(stdout); - - // Log to blueprints-log.md (in the same directory as the executable) - // The app runs from build/bin/, so just use relative path - static FILE* logFile = nullptr; - if (!logFile) - { - logFile = fopen("blueprints-log.md", "a"); - if (logFile) - { - fprintf(logFile, "\n"); - } - } - - if (logFile) - { - vfprintf(logFile, fmt, args); - fprintf(logFile, "\n"); - fflush(logFile); - } - - va_end(args); -} void App::TakeScreenshot(const char* filename) { @@ -58,8 +26,6 @@ void App::TakeScreenshot(const char* filename) printf("App::TakeScreenshot - Using provided filename: %s\n", fname.c_str()); } - LogToFile("Screenshot: Starting screenshot capture..."); - LogToFile("Screenshot: Using filename: %s", fname.c_str()); // Delegate to Application base class which calls the renderer bool success = Application::TakeScreenshot(fname.c_str()); @@ -71,13 +37,13 @@ void App::TakeScreenshot(const char* filename) { m_ScreenshotMessage = "Screenshot saved: " + fname; m_ScreenshotMessageTime = 5.0f; - LogToFile("Screenshot: SUCCESS - Screenshot saved to: %s", fname.c_str()); + } else { m_ScreenshotMessage = "Failed to save screenshot: " + fname; m_ScreenshotMessageTime = 5.0f; - LogToFile("Screenshot: FAILED - Could not save screenshot"); + } } diff --git a/examples/blueprints-example/app.cpp b/applications/nodehub/app.cpp similarity index 92% rename from examples/blueprints-example/app.cpp rename to applications/nodehub/app.cpp index dccd86e..ee9a0b4 100644 --- a/examples/blueprints-example/app.cpp +++ b/applications/nodehub/app.cpp @@ -1,306 +1,334 @@ -#define IMGUI_DEFINE_MATH_OPERATORS -#include "app.h" -#include "nodes.h" -#include "containers/root_container.h" -#include "Logging.h" -#include -#include - -namespace ed = ax::NodeEditor; - -ed::EditorContext* m_Editor = nullptr; - -void App::OnStart() -{ - // Determine desired log level from CLI args - std::string logLevelArg = "debug"; - auto logLevelIt = m_Args.find("log-level"); - if (logLevelIt != m_Args.end() && logLevelIt->second.Type == ArgValue::Type::String && !logLevelIt->second.String.empty()) - { - logLevelArg = logLevelIt->second.String; - } - - bool logLevelValid = true; - auto parsedLogLevel = ParseLogLevel(logLevelArg, &logLevelValid); - - // Initialize spdlog logger system - InitLogger("blueprints", true, true, "blueprints.log"); - SetLoggerLevel(parsedLogLevel); - - if (parsedLogLevel != spdlog::level::off) - { - spdlog::log(parsedLogLevel, "Logger level set to {}", spdlog::level::to_string_view(parsedLogLevel)); - } - if (!logLevelValid) - { - LOG_WARN("Unknown log level '{}', defaulting to 'debug'", logLevelArg); - } - - LOG_TRACE("[CHECKPOINT] OnStart: Beginning"); - - // Get graph filename from CLI args (--graph), default to BlueprintsGraph.json - // Supports both relative and absolute paths - auto it = m_Args.find("graph"); - if (it != m_Args.end() && it->second.Type == ArgValue::Type::String) - { - m_GraphFilename = it->second.String; - LOG_INFO("Using graph file: {}", m_GraphFilename); - } - else - { - LOG_INFO("Using default graph file: {}", m_GraphFilename); - } - - LOG_TRACE("[CHECKPOINT] OnStart: About to create root container"); - - // Create default root container from graph filename - AddRootContainer(m_GraphFilename); - - LOG_TRACE("[CHECKPOINT] OnStart: Root container created, active={:p}", - static_cast(GetActiveRootContainer())); - - ed::Config config; - - // Use custom settings callbacks instead of SettingsFile - // Graph data (nodes, links, positions, control points) → specified file or BlueprintsGraph.json (handled in SaveGraph/LoadGraph) - // View state only (scroll, zoom, selection) → Blueprints.json (handled via callbacks) - config.SettingsFile = "Blueprints.json"; - config.UserPointer = this; - - config.LoadSettings = [](char* data, void* userPointer) -> size_t - { - auto self = static_cast(userPointer); - return self->LoadViewSettings(data); - }; - - config.SaveSettings = [](const char* data, size_t size, ed::SaveReasonFlags reason, void* userPointer) -> bool - { - auto self = static_cast(userPointer); - return self->SaveViewSettings(data, size); - }; - - // Disable per-node settings - we handle everything in BlueprintsGraph.json - config.SaveNodeSettings = nullptr; - config.LoadNodeSettings = nullptr; - - // Provide callbacks to access container nodes/links for BuildControl - config.GetContainerNodeIds = [](void* userPointer, ed::NodeId* nodeIdsOut, int maxNodes) -> int - { - auto self = static_cast(userPointer); - auto* container = self->GetActiveRootContainer(); - if (!container) - return 0; - - // Get all container nodes - auto nodes = container->GetNodes(self); - - if (nodeIdsOut == nullptr) - return static_cast(nodes.size()); // Return count only - - // Fill node IDs array - int count = 0; - for (auto* node : nodes) - { - if (node && count < maxNodes) - { - nodeIdsOut[count] = node->ID; - count++; - } - } - return count; - }; - - config.GetContainerLinkIds = [](void* userPointer, ed::LinkId* linkIdsOut, int maxLinks) -> int - { - auto self = static_cast(userPointer); - auto* container = self->GetActiveRootContainer(); - if (!container) - return 0; - - // Get all container links - auto links = container->GetLinks(self); - - if (linkIdsOut == nullptr) - return static_cast(links.size()); // Return count only - - // Fill link IDs array - int count = 0; - for (auto* link : links) - { - if (link && count < maxLinks) - { - linkIdsOut[count] = link->ID; - count++; - } - } - return count; - }; - - // Provide callback to mark links as user-manipulated when user edits waypoints - config.MarkLinkUserManipulated = [](ed::LinkId linkId, void* userPointer) -> void - { - auto self = static_cast(userPointer); - self->MarkLinkUserManipulated(linkId); - }; - - // Provide callback when block display mode changes (triggers link auto-adjustment) - config.OnBlockDisplayModeChanged = [](ed::NodeId nodeId, void* userPointer) -> void - { - auto self = static_cast(userPointer); - // When display mode changes, the node size changes immediately - // Call AutoAdjustLinkWaypoints immediately - it will detect the size change - // by comparing current size with m_LastNodeSizes (which has the old size from last frame) - self->AutoAdjustLinkWaypoints(); - // Update the last known size for this node after adjustment - self->UpdateLastNodeSize(nodeId); - LOG_TRACE("[CHECKPOINT] OnBlockDisplayModeChanged: AutoAdjustLinkWaypoints called"); - }; - - LOG_TRACE("[CHECKPOINT] OnStart: About to create editor"); - - m_Editor = ed::CreateEditor(&config); - ed::SetCurrentEditor(m_Editor); - // Load custom node styles from JSON - if (m_StyleManager.LoadFromFile("styles.json")) - { - LOG_TRACE("[CHECKPOINT] OnStart: Custom styles loaded from styles.json"); - } - else - { - - } - m_StyleManager.ApplyToEditorStyle(m_Editor); - - // Register runtime callback for block execution - ed::Detail::EditorContext::RegisterRuntimeCallback(this, [](void* app) { - static_cast(app)->ExecuteRuntimeStep(); - }); - - LOG_TRACE("[CHECKPOINT] OnStart: Runtime callback registered"); - - // Set global style - no arrows on any pins - auto& style = ed::GetStyle(); - style.PinArrowSize = 0.0f; - style.PinArrowWidth = 0.0f; - - LOG_TRACE("[CHECKPOINT] OnStart: About to load graph"); - - // Load saved graph (nodes and links from BlueprintsGraph.json) - auto* activeContainer = GetActiveRootContainer(); - if (activeContainer) - { - LoadGraph(m_GraphFilename, activeContainer); - } - - LOG_TRACE("[CHECKPOINT] OnStart: Graph loaded, about to build nodes"); - - BuildNodes(); - - LOG_TRACE("[CHECKPOINT] OnStart: Nodes built, about to load textures"); - - m_HeaderBackground = LoadTexture("data/BlueprintBackground.png"); - m_SaveIcon = LoadTexture("data/ic_save_white_24dp.png"); - m_RestoreIcon = LoadTexture("data/ic_restore_white_24dp.png"); - - LOG_TRACE("[CHECKPOINT] OnStart: Textures loaded, about to navigate to content"); - - // Only navigate to content if we don't have saved view settings - // (m_NeedsInitialZoom is set to false in LoadViewSettings if Blueprints.json exists) - if (m_NeedsInitialZoom) - { - LOG_TRACE("[CHECKPOINT] OnStart: No saved view state, navigating to content"); - ed::NavigateToContent(0.0f); - } - else - { - LOG_TRACE("[CHECKPOINT] OnStart: Saved view state will be restored, skipping initial zoom"); - } - - LOG_TRACE("[CHECKPOINT] OnStart: Complete"); -} - -void App::OnStop() -{ - // Save graph before shutdown - auto* activeContainer = GetActiveRootContainer(); - if (activeContainer) - { - SaveGraph(m_GraphFilename, activeContainer); - } - - auto releaseTexture = [this](ImTextureID& id) - { - if (id) - { - DestroyTexture(id); - id = nullptr; - } - }; - - releaseTexture(m_RestoreIcon); - releaseTexture(m_SaveIcon); - releaseTexture(m_HeaderBackground); - - if (m_Editor) - { - ed::DestroyEditor(m_Editor); - m_Editor = nullptr; - } - - // Shutdown spdlog logger - ShutdownLogger(); -} - -// UUID Generation Methods (32-bit) -uint32_t App::GenerateRandomUuid() -{ - return m_UuidGenerator.GenerateRandom(); -} - -uint32_t App::GenerateSequentialUuid() -{ - return m_UuidGenerator.GenerateSequential(); -} - -std::string App::UuidToHexString(uint32_t uuid) -{ - return UuidGenerator::ToHexString(uuid); -} - -uint32_t App::HexStringToUuid(const std::string& hexString) -{ - return UuidGenerator::FromHexString(hexString); -} - -// UUID Generation Methods (64-bit using dual 32-bit words) -Uuid64 App::GenerateRandomUuid64() -{ - return m_UuidGenerator.GenerateRandom64(); -} - -Uuid64 App::GenerateSequentialUuid64() -{ - return m_UuidGenerator.GenerateSequential64(); -} - -std::string App::UuidToHexString64(const Uuid64& uuid) -{ - return UuidGenerator::ToHexString64(uuid); -} - -Uuid64 App::HexStringToUuid64(const std::string& hexString) -{ - return UuidGenerator::FromHexString64(hexString); -} - -// Standard UUID Format Conversion Methods -std::string App::UuidToStandardString(const Uuid64& uuid) -{ - return uuid.ToStandardUuidString(); -} - -Uuid64 App::StandardStringToUuid(const std::string& uuidStr, bool takeLast64) -{ - return Uuid64::FromStandardUuidString(uuidStr, takeLast64); -} - +#define IMGUI_DEFINE_MATH_OPERATORS +#include "app.h" +#include "containers/root_container.h" +#include "Logging.h" +#include +#include + +#include + +namespace ed = ax::NodeEditor; + +ed::EditorContext* m_Editor = nullptr; + +App::App(const char* name) : Application(name){ + m_Context = new NH_Context(); + initLogger(); + // m_Context->SetParameterManager(new NH_ParameterManager(m_Context)); + +} + +App::App(const char* name, const ArgsMap& args) : Application(name, args){ + m_Context = new NH_Context(); + initLogger(); +} + +App::App() : Application("Blueprints"){ + m_Context = new NH_Context(); + initLogger(); +} + +NH_Context* App::GetContext() +{ + return m_Context; +} + +void App::initLogger() +{ + // Determine desired log level from CLI args + std::string logLevelArg = "debug"; + auto logLevelIt = m_Args.find("log-level"); + if (logLevelIt != m_Args.end() && logLevelIt->second.Type == ArgValue::Type::String && !logLevelIt->second.String.empty()) + { + logLevelArg = logLevelIt->second.String; + } + + bool logLevelValid = true; + auto parsedLogLevel = ParseLogLevel(logLevelArg, &logLevelValid); + + // Initialize spdlog logger system + InitLogger("blueprints", true, true, "blueprints.log"); + SetLoggerLevel(parsedLogLevel); + + if (parsedLogLevel != spdlog::level::off) + { + spdlog::log(parsedLogLevel, "Logger level set to {}", spdlog::level::to_string_view(parsedLogLevel)); + } + if (!logLevelValid) + { + LOG_WARN("Unknown log level '{}', defaulting to 'debug'", logLevelArg); + } + } + +void App::OnStart() +{ + // Get graph filename from CLI args (--graph), default to BlueprintsGraph.json + // Supports both relative and absolute paths + auto it = m_Args.find("graph"); + if (it != m_Args.end() && it->second.Type == ArgValue::Type::String) + { + m_GraphFilename = it->second.String; + LOG_INFO("Using graph file: {}", m_GraphFilename); + } + else + { + LOG_INFO("Using default graph file: {}", m_GraphFilename); + } + + + + // Create default root container from graph filename + AddRootContainer(m_GraphFilename); + + LOG_TRACE("[CHECKPOINT] OnStart: Root container created, active={:p}", + static_cast(GetActiveRootContainer())); + + ed::Config config; + + // Use custom settings callbacks instead of SettingsFile + // Graph data (nodes, links, positions, control points) → specified file or BlueprintsGraph.json (handled in SaveGraph/LoadGraph) + // View state only (scroll, zoom, selection) → Blueprints.json (handled via callbacks) + config.SettingsFile = "Blueprints.json"; + config.UserPointer = this; + + config.LoadSettings = [](char* data, void* userPointer) -> size_t + { + auto self = static_cast(userPointer); + return self->LoadViewSettings(data); + }; + + config.SaveSettings = [](const char* data, size_t size, ed::SaveReasonFlags reason, void* userPointer) -> bool + { + auto self = static_cast(userPointer); + return self->SaveViewSettings(data, size); + }; + + // Disable per-node settings - we handle everything in BlueprintsGraph.json + config.SaveNodeSettings = nullptr; + config.LoadNodeSettings = nullptr; + + // Provide callbacks to access container nodes/links for BuildControl + config.GetContainerNodeIds = [](void* userPointer, ed::NodeId* nodeIdsOut, int maxNodes) -> int + { + auto self = static_cast(userPointer); + auto* container = self->GetActiveRootContainer(); + if (!container) + return 0; + + // Get all container nodes + auto nodes = container->GetNodes(self); + + if (nodeIdsOut == nullptr) + return static_cast(nodes.size()); // Return count only + + // Fill node IDs array + int count = 0; + for (auto* node : nodes) + { + if (node && count < maxNodes) + { + nodeIdsOut[count] = node->ID; + count++; + } + } + return count; + }; + + config.GetContainerLinkIds = [](void* userPointer, ed::LinkId* linkIdsOut, int maxLinks) -> int + { + auto self = static_cast(userPointer); + auto* container = self->GetActiveRootContainer(); + if (!container) + return 0; + + // Get all container links + auto links = container->GetLinks(self); + + if (linkIdsOut == nullptr) + return static_cast(links.size()); // Return count only + + // Fill link IDs array + int count = 0; + for (auto* link : links) + { + if (link && count < maxLinks) + { + linkIdsOut[count] = link->ID; + count++; + } + } + return count; + }; + + // Provide callback to mark links as user-manipulated when user edits waypoints + config.MarkLinkUserManipulated = [](ed::LinkId linkId, void* userPointer) -> void + { + auto self = static_cast(userPointer); + self->MarkLinkUserManipulated(linkId); + }; + + // Provide callback when block display mode changes (triggers link auto-adjustment) + config.OnBlockDisplayModeChanged = [](ed::NodeId nodeId, void* userPointer) -> void + { + auto self = static_cast(userPointer); + // When display mode changes, the node size changes immediately + // Call AutoAdjustLinkWaypoints immediately - it will detect the size change + // by comparing current size with m_LastNodeSizes (which has the old size from last frame) + self->AutoAdjustLinkWaypoints(); + // Update the last known size for this node after adjustment + self->UpdateLastNodeSize(nodeId); + LOG_TRACE("[CHECKPOINT] OnBlockDisplayModeChanged: AutoAdjustLinkWaypoints called"); + }; + + LOG_TRACE("[CHECKPOINT] OnStart: About to create editor"); + + m_Editor = ed::CreateEditor(&config); + ed::SetCurrentEditor(m_Editor); + // Load custom node styles from JSON + if (m_StyleManager.LoadFromFile("styles.json")) + { + LOG_TRACE("[CHECKPOINT] OnStart: Custom styles loaded from styles.json"); + } + else + { + + } + m_StyleManager.ApplyToEditorStyle(m_Editor); + + // Register runtime callback for block execution + ed::Detail::EditorContext::RegisterRuntimeCallback(this, [](void* app) { + static_cast(app)->ExecuteRuntimeStep(); + }); + + LOG_TRACE("[CHECKPOINT] OnStart: Runtime callback registered"); + + // Set global style - no arrows on any pins + auto& style = ed::GetStyle(); + style.PinArrowSize = 0.0f; + style.PinArrowWidth = 0.0f; + + LOG_TRACE("[CHECKPOINT] OnStart: About to load graph"); + + // Load saved graph (nodes and links from BlueprintsGraph.json) + auto* activeContainer = GetActiveRootContainer(); + if (activeContainer) + { + LoadGraph(m_GraphFilename, activeContainer); + } + + LOG_TRACE("[CHECKPOINT] OnStart: Graph loaded, about to build nodes"); + + BuildNodes(); + + LOG_TRACE("[CHECKPOINT] OnStart: Nodes built, about to initialize context"); + + m_Context->init(this); + + LOG_TRACE("[CHECKPOINT] OnStart: Context initialized, about to load textures"); + + m_HeaderBackground = LoadTexture("data/BlueprintBackground.png"); + m_SaveIcon = LoadTexture("data/ic_save_white_24dp.png"); + m_RestoreIcon = LoadTexture("data/ic_restore_white_24dp.png"); + + LOG_TRACE("[CHECKPOINT] OnStart: Textures loaded, about to navigate to content"); + + // Only navigate to content if we don't have saved view settings + // (m_NeedsInitialZoom is set to false in LoadViewSettings if Blueprints.json exists) + if (m_NeedsInitialZoom) + { + LOG_TRACE("[CHECKPOINT] OnStart: No saved view state, navigating to content"); + ed::NavigateToContent(0.0f); + } + else + { + LOG_TRACE("[CHECKPOINT] OnStart: Saved view state will be restored, skipping initial zoom"); + } + + LOG_TRACE("[CHECKPOINT] OnStart: Complete"); +} + +void App::OnStop() +{ + // Save graph before shutdown + auto* activeContainer = GetActiveRootContainer(); + if (activeContainer) + { + SaveGraph(m_GraphFilename, activeContainer); + } + + auto releaseTexture = [this](ImTextureID& id) + { + if (id) + { + DestroyTexture(id); + id = nullptr; + } + }; + + releaseTexture(m_RestoreIcon); + releaseTexture(m_SaveIcon); + releaseTexture(m_HeaderBackground); + + if (m_Editor) + { + ed::DestroyEditor(m_Editor); + m_Editor = nullptr; + } + + // Shutdown spdlog logger + ShutdownLogger(); +} + +// UUID Generation Methods (32-bit) +uint32_t App::GenerateRandomUuid() +{ + return m_UuidGenerator.GenerateRandom(); +} + +uint32_t App::GenerateSequentialUuid() +{ + return m_UuidGenerator.GenerateSequential(); +} + +std::string App::UuidToHexString(uint32_t uuid) +{ + return UuidGenerator::ToHexString(uuid); +} + +uint32_t App::HexStringToUuid(const std::string& hexString) +{ + return UuidGenerator::FromHexString(hexString); +} + +// UUID Generation Methods (64-bit using dual 32-bit words) +Uuid64 App::GenerateRandomUuid64() +{ + return m_UuidGenerator.GenerateRandom64(); +} + +Uuid64 App::GenerateSequentialUuid64() +{ + return m_UuidGenerator.GenerateSequential64(); +} + +std::string App::UuidToHexString64(const Uuid64& uuid) +{ + return UuidGenerator::ToHexString64(uuid); +} + +Uuid64 App::HexStringToUuid64(const std::string& hexString) +{ + return UuidGenerator::FromHexString64(hexString); +} + +// Standard UUID Format Conversion Methods +std::string App::UuidToStandardString(const Uuid64& uuid) +{ + return uuid.ToStandardUuidString(); +} + +Uuid64 App::StandardStringToUuid(const std::string& uuidStr, bool takeLast64) +{ + return Uuid64::FromStandardUuidString(uuidStr, takeLast64); +} + diff --git a/examples/blueprints-example/app.h b/applications/nodehub/app.h similarity index 97% rename from examples/blueprints-example/app.h rename to applications/nodehub/app.h index b05d4ec..f73f842 100644 --- a/examples/blueprints-example/app.h +++ b/applications/nodehub/app.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include "types.h" #include "blocks/parameter_node.h" #include "utilities/edge_editing.h" @@ -11,11 +11,20 @@ #include "core/graph_state.h" #include +#include "app-types.h" + +#include "core/Context.h" + namespace ed = ax::NodeEditor; class App: public Application { public: + + App(); + App(const char* name); + App(const char* name, const ArgsMap& args); + using Application::Application; // Application lifecycle @@ -159,7 +168,10 @@ public: // Made public so blocks can access it for visualization std::map m_RunningNodes; // Node ID -> expiration time + NH_Context* GetContext(); + private: + void initLogger(); // Container management delegated to GraphState - see m_GraphState // Link highlighting for Run() visualization std::map m_HighlightedLinks; // Link ID -> expiration time @@ -184,5 +196,8 @@ private: Pin* m_NewLinkPin = nullptr; float m_LeftPaneWidth = 400.0f; float m_RightPaneWidth = 800.0f; + + NH_Context *m_Context; + }; diff --git a/examples/blueprints-example/blocks/NodeEx.cpp b/applications/nodehub/blocks/NodeEx.cpp similarity index 100% rename from examples/blueprints-example/blocks/NodeEx.cpp rename to applications/nodehub/blocks/NodeEx.cpp diff --git a/NodeEx.h b/applications/nodehub/blocks/NodeEx.h similarity index 100% rename from NodeEx.h rename to applications/nodehub/blocks/NodeEx.h diff --git a/examples/blueprints-example/blocks/block.cpp b/applications/nodehub/blocks/block.cpp similarity index 95% rename from examples/blueprints-example/blocks/block.cpp rename to applications/nodehub/blocks/block.cpp index 8a3d9dd..5a82785 100644 --- a/examples/blueprints-example/blocks/block.cpp +++ b/applications/nodehub/blocks/block.cpp @@ -1,14 +1,16 @@ #define IMGUI_DEFINE_MATH_OPERATORS +#include + #include "block.h" #include "../app.h" #include "../utilities/node_renderer_base.h" #include "../containers/container.h" -#include "../../crude_json.h" #include "NodeEx.h" #include "constants.h" #include #include #include +#include "../Logging.h" namespace ed = ax::NodeEditor; using namespace ax::NodeRendering; @@ -41,7 +43,7 @@ static void RenderFlowPin(ImDrawList* drawList, const ImVec2& center, const ImVe void ParameterizedBlock::Render(Node& node, App* app, Pin* newLinkPin) { // Check if node is currently running (for red border visualization) - float currentTime = ImGui::GetTime(); + double currentTime = (double)ImGui::GetTime(); bool isRunning = false; auto runningIt = app->m_RunningNodes.find(node.ID); if (runningIt != app->m_RunningNodes.end()) @@ -234,7 +236,7 @@ void ParameterizedBlock::Render(Node& node, App* app, Pin* newLinkPin) // NodeStyleScope destructor handles cleanup automatically } -void ParameterizedBlock::AddInputParameter(App* app, Node& node, const char* name, PinType type) +void ParameterizedBlock::AddInputParameter(App* app, Node& node, NH_CSTRING name, PinType type) { int pinId = app->GetNextId(); m_InputParams.push_back(pinId); @@ -242,7 +244,7 @@ void ParameterizedBlock::AddInputParameter(App* app, Node& node, const char* nam node.Inputs.emplace_back(pinId, name, type); } -void ParameterizedBlock::AddOutputParameter(App* app, Node& node, const char* name, PinType type) +void ParameterizedBlock::AddOutputParameter(App* app, Node& node, NH_CSTRING name, PinType type) { int pinId = app->GetNextId(); m_OutputParams.push_back(pinId); @@ -250,19 +252,19 @@ void ParameterizedBlock::AddOutputParameter(App* app, Node& node, const char* na node.Outputs.emplace_back(pinId, name, type); } -void ParameterizedBlock::AddInput(App* app, Node& node, const char* name) +void ParameterizedBlock::AddInput(App* app, Node& node, NH_CSTRING name) { int pinId = app->GetNextId(); m_Inputs.push_back(pinId); - const char* displayName = (name && *name) ? name : ""; + NH_CSTRING displayName = (name && *name) ? name : ""; node.Inputs.emplace_back(pinId, displayName, PinType::Flow); } -void ParameterizedBlock::AddOutput(App* app, Node& node, const char* name) +void ParameterizedBlock::AddOutput(App* app, Node& node, NH_CSTRING name) { int pinId = app->GetNextId(); m_Outputs.push_back(pinId); - const char* displayName = (name && *name) ? name : ""; + NH_CSTRING displayName = (name && *name) ? name : ""; node.Outputs.emplace_back(pinId, displayName, PinType::Flow); } @@ -321,10 +323,7 @@ void ParameterizedBlock::OnMenu(Node& node, App* app) if (ImGui::MenuItem("Run (R)")) { int result = Run(node, app); - printf("Block '%s' (ID: %d) Run() returned: %d\n", - node.Name.c_str(), node.ID.Get(), result); - ax::NodeEditor::AddInAppLog("Block '%s' (ID: %d) Run() returned: %d\n", - node.Name.c_str(), node.ID.Get(), result); + // LOG_INFO("Block '{}' (ID: {}) Run() returned: {}", node.Name.c_str(), node.ID.Get(), result); } } @@ -347,7 +346,7 @@ int ParameterizedBlock::GetInputParamValueInt(const Pin& pin, Node& node, App* a else if (sourcePin->Node->IsBlockBased()) { // Source is a block output - read from UnconnectedParamValues - int sourcePinId = sourcePin->ID.Get(); + const int sourcePinId = ToRuntimeId(sourcePin->ID); auto& sourceParamValues = sourcePin->Node->UnconnectedParamValues; if (sourceParamValues.find(sourcePinId) != sourceParamValues.end()) { @@ -362,7 +361,7 @@ int ParameterizedBlock::GetInputParamValueInt(const Pin& pin, Node& node, App* a } // Not connected, use default value from UnconnectedParamValues - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); auto& paramValues = node.UnconnectedParamValues; if (paramValues.find(pinId) != paramValues.end()) { @@ -394,7 +393,7 @@ float ParameterizedBlock::GetInputParamValueFloat(const Pin& pin, Node& node, Ap else if (sourcePin->Node->IsBlockBased()) { // Source is a block output - read from UnconnectedParamValues - int sourcePinId = sourcePin->ID.Get(); + const int sourcePinId = ToRuntimeId(sourcePin->ID); auto& sourceParamValues = sourcePin->Node->UnconnectedParamValues; if (sourceParamValues.find(sourcePinId) != sourceParamValues.end()) { @@ -409,7 +408,7 @@ float ParameterizedBlock::GetInputParamValueFloat(const Pin& pin, Node& node, Ap } // Not connected, use default value from UnconnectedParamValues - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); auto& paramValues = node.UnconnectedParamValues; if (paramValues.find(pinId) != paramValues.end()) { @@ -441,7 +440,7 @@ bool ParameterizedBlock::GetInputParamValueBool(const Pin& pin, Node& node, App* else if (sourcePin->Node->IsBlockBased()) { // Source is a block output - read from UnconnectedParamValues - int sourcePinId = sourcePin->ID.Get(); + const int sourcePinId = ToRuntimeId(sourcePin->ID); auto& sourceParamValues = sourcePin->Node->UnconnectedParamValues; if (sourceParamValues.find(sourcePinId) != sourceParamValues.end()) { @@ -456,7 +455,7 @@ bool ParameterizedBlock::GetInputParamValueBool(const Pin& pin, Node& node, App* } // Not connected, use default value from UnconnectedParamValues - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); auto& paramValues = node.UnconnectedParamValues; if (paramValues.find(pinId) != paramValues.end()) { @@ -488,7 +487,7 @@ std::string ParameterizedBlock::GetInputParamValueString(const Pin& pin, Node& n else if (sourcePin->Node->IsBlockBased()) { // Source is a block output - read from UnconnectedParamValues - int sourcePinId = sourcePin->ID.Get(); + const int sourcePinId = ToRuntimeId(sourcePin->ID); auto& sourceParamValues = sourcePin->Node->UnconnectedParamValues; auto it = sourceParamValues.find(sourcePinId); if (it != sourceParamValues.end()) @@ -500,7 +499,7 @@ std::string ParameterizedBlock::GetInputParamValueString(const Pin& pin, Node& n } // Not connected, use default value from UnconnectedParamValues - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); auto& paramValues = node.UnconnectedParamValues; auto it = paramValues.find(pinId); if (it != paramValues.end()) @@ -514,7 +513,7 @@ std::string ParameterizedBlock::GetInputParamValueString(const Pin& pin, Node& n void ParameterizedBlock::SetOutputParamValueInt(const Pin& pin, Node& node, App* app, int value) { // Store output value in node's UnconnectedParamValues (output pins can be read by connected nodes) - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); node.UnconnectedParamValues[pinId] = std::to_string(value); // Propagate to ALL connected parameter nodes (iterate through all links from active container) @@ -542,7 +541,7 @@ void ParameterizedBlock::SetOutputParamValueInt(const Pin& pin, Node& node, App* void ParameterizedBlock::SetOutputParamValueFloat(const Pin& pin, Node& node, App* app, float value) { // Store output value in node's UnconnectedParamValues - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); char buf[32]; snprintf(buf, sizeof(buf), "%.6g", value); node.UnconnectedParamValues[pinId] = buf; @@ -571,7 +570,7 @@ void ParameterizedBlock::SetOutputParamValueFloat(const Pin& pin, Node& node, Ap void ParameterizedBlock::SetOutputParamValueBool(const Pin& pin, Node& node, App* app, bool value) { // Store output value in node's UnconnectedParamValues - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); node.UnconnectedParamValues[pinId] = value ? "true" : "false"; // Propagate to ALL connected parameter nodes (iterate through all links from active container) @@ -599,7 +598,7 @@ void ParameterizedBlock::SetOutputParamValueBool(const Pin& pin, Node& node, App void ParameterizedBlock::SetOutputParamValueString(const Pin& pin, Node& node, App* app, const std::string& value) { // Store output value in node's UnconnectedParamValues - int pinId = pin.ID.Get(); + int pinId = ToRuntimeId(pin.ID); node.UnconnectedParamValues[pinId] = value; // Propagate to ALL connected parameter nodes (iterate through all links from active container) @@ -638,7 +637,7 @@ void ParameterizedBlock::SaveState(Node& node, crude_json::value& nodeData, cons if (pin.Type == PinType::Flow) continue; - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); auto& paramValues = node.UnconnectedParamValues; auto it = paramValues.find(pinId); @@ -672,7 +671,7 @@ void ParameterizedBlock::SaveState(Node& node, crude_json::value& nodeData, cons if (pin.Type == PinType::Flow) continue; - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); auto& paramValues = node.UnconnectedParamValues; auto it = paramValues.find(pinId); diff --git a/examples/blueprints-example/blocks/block.h b/applications/nodehub/blocks/block.h similarity index 67% rename from examples/blueprints-example/blocks/block.h rename to applications/nodehub/blocks/block.h index 08b9709..272ea6d 100644 --- a/examples/blueprints-example/blocks/block.h +++ b/applications/nodehub/blocks/block.h @@ -1,7 +1,7 @@ #pragma once #include "../commons.h" - +#include "../core/Object.h" #include "../utilities/node_renderer_base.h" #include #include @@ -9,75 +9,32 @@ #include #include -// Pin icon offset constants -namespace BlockPinOffsets { - // Y offset for input parameter pins (moves pins higher on top edge) - static constexpr float INPUT_PARAM_Y = -8.0f; - // Y offset for output parameter pins (moves pins lower on bottom edge) - static constexpr float OUTPUT_PARAM_Y = 8; // Negated (12.0f) - - // Parameter node specific output offset (can be different from general blocks) - static constexpr float PARAM_NODE_OUTPUT_Y = 0.0f; - - // Combined ImVec2 offsets for convenience - static const ImVec2 INPUT_PARAM(0.0f, -15); - static const ImVec2 OUTPUT_PARAM(0.0f, OUTPUT_PARAM_Y); - static const ImVec2 PARAM_NODE_OUTPUT(0.0f, PARAM_NODE_OUTPUT_Y); - - static const ImVec2 GROUP_INPUT_PARAM(0.0f, -15.0f); -} - -// Block style constants -namespace BlockStyle { - // Node appearance constants - static constexpr float ROUNDING = 1.0f; - static constexpr float BORDER_WIDTH = 1.0f; - static constexpr float PADDING = 0.0f; - - // Group block specific (more rounded, slightly thicker border) - static constexpr float GROUP_ROUNDING = 1.0f; - static constexpr float GROUP_BORDER_WIDTH = 1.0f; - - // Parameter node constants (standardized across all display modes) - static constexpr float PARAM_ROUNDING = 0.0f; - static constexpr float PARAM_BORDER_WIDTH = 1.0f; - static constexpr float PARAM_BORDER_WIDTH_SOURCE = 2.0f; // Thicker for source nodes - static constexpr float PARAM_BORDER_WIDTH_NAME_AND_VALUE = 1.5f; // Slightly thicker for name+value mode - static constexpr float PARAM_BORDER_WIDTH_SOURCE_NAME_AND_VALUE = 2.5f; // Source in name+value mode - - // Parameter node padding (ImVec4 for per-edge control) - static const ImVec4 PARAM_PADDING_NAME_ONLY(4.0f, 2.0f, 4.0f, 2.0f); - static const ImVec4 PARAM_PADDING_NAME_AND_VALUE(8.0f, 4.0f, 8.0f, 4.0f); - static const ImVec4 PARAM_PADDING_SMALL_BOX(2.0f, 2.0f, 2.0f, 2.0f); - static const ImVec4 PARAM_PADDING_MINIMAL(4.0f, 4.0f, 4.0f, 4.0f); -} - - // Forward declarations class App; class Container; namespace crude_json { struct value; } -class Block +class Block : public NH_Object { public: - Block(int id, const char* name) - : m_ID(id) - , m_Name(name) + Block(int id, NH_CSTRING name) + : NH_Object(id, name) , m_Type(NodeType::Blueprint) - , m_Color(ImColor(255, 255, 255)) - , m_bFlags(NHBEHAVIOR_NONE) - { + , m_Color(ImColor(255, 255, 255)) + { } virtual ~Block() = default; // Core identification - int GetID() const { return m_ID; } - const char* GetName() const { return m_Name.c_str(); } - const char* GetTypeName() const { return m_TypeName.c_str(); } - NH_BEHAVIOR_FLAGS GetFlags() const { return m_bFlags; } + int GetID() const { return NH_Object::GetID(); } + NH_CSTRING GetName() const { return NH_Object::GetName(); } + NH_CSTRING GetTypeName() const { return NH_Object::GetTypeName(); } + NH_BEHAVIOR_FLAGS GetFlags() const { return GetBehaviorFlags(); } + void SetFlags(NH_BEHAVIOR_FLAGS flags) { SetBehaviorFlags(flags); } + void AddFlags(NH_BEHAVIOR_FLAGS flags) { AddBehaviorFlags(flags); } + void RemoveFlags(NH_BEHAVIOR_FLAGS flags) { RemoveBehaviorFlags(flags); } // Node building (like NHBehavior's CreateInput/CreateOutput) virtual void Build(Node& node, App* app) = 0; @@ -86,7 +43,7 @@ public: virtual void Render(Node& node, App* app, Pin* newLinkPin) = 0; // Serialization support - virtual const char* GetBlockType() const = 0; // Unique type identifier + virtual NH_CSTRING GetBlockType() const = 0; // Unique type identifier // State save/load callbacks (optional - subclasses can override to save/load custom state) // These are called from App::SaveGraph() / App::LoadGraph() @@ -122,19 +79,15 @@ protected: // Activation state (stored per-block instance) std::vector m_OutputActive; // Output activation states std::vector m_InputActive; // Input activation states - int m_ID; - std::string m_Name; - std::string m_TypeName; NodeType m_Type; ImColor m_Color; - NH_BEHAVIOR_FLAGS m_bFlags; // Behavior flags }; // Extended block with parameters - like NHBehavior with params class ParameterizedBlock : public Block, public ax::NodeRendering::NodeRendererBase { public: - ParameterizedBlock(int id, const char* name) + ParameterizedBlock(int id, NH_CSTRING name) : Block(id, name) { } @@ -142,12 +95,12 @@ public: virtual ~ParameterizedBlock() = default; // Parameter creation helpers (like NHBehavior::CreateInputParameter) - void AddInputParameter(App* app, Node& node, const char* name, PinType type); - void AddOutputParameter(App* app, Node& node, const char* name, PinType type); + void AddInputParameter(App* app, Node& node, NH_CSTRING name, PinType type); + void AddOutputParameter(App* app, Node& node, NH_CSTRING name, PinType type); // I/O creation (flow control) - void AddInput(App* app, Node& node, const char* name); - void AddOutput(App* app, Node& node, const char* name); + void AddInput(App* app, Node& node, NH_CSTRING name); + void AddOutput(App* app, Node& node, NH_CSTRING name); int GetInputParameterCount() const override { return (int)m_InputParams.size(); } int GetOutputParameterCount() const override { return (int)m_OutputParams.size(); } @@ -197,12 +150,12 @@ public: return instance; } - void RegisterBlock(const char* typeName, BlockFactory factory) + void RegisterBlock(NH_CSTRING typeName, BlockFactory factory) { m_Factories[typeName] = factory; } - Block* CreateBlock(const char* typeName, int id) + Block* CreateBlock(NH_CSTRING typeName, int id) { auto it = m_Factories.find(typeName); if (it != m_Factories.end()) diff --git a/examples/blueprints-example/blocks/block_edit_dialog.cpp b/applications/nodehub/blocks/block_edit_dialog.cpp similarity index 98% rename from examples/blueprints-example/blocks/block_edit_dialog.cpp rename to applications/nodehub/blocks/block_edit_dialog.cpp index e5b8a64..6236985 100644 --- a/examples/blueprints-example/blocks/block_edit_dialog.cpp +++ b/applications/nodehub/blocks/block_edit_dialog.cpp @@ -106,7 +106,7 @@ void RenderBlockEditDialog() ImGui::SameLine(); ImGui::PushItemWidth(200.0f); static std::map nodeNameBuffers; // Per-node name buffers - int nodeId = s_EditingNode->ID.Get(); + int nodeId = ToRuntimeId(s_EditingNode->ID); if (nodeNameBuffers.find(nodeId) == nodeNameBuffers.end()) { nodeNameBuffers[nodeId] = s_EditingNode->Name; @@ -159,7 +159,7 @@ void RenderBlockEditDialog() // Editable flow input name ImGui::PushItemWidth(150.0f); static std::map flowInputNameBuffers; - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); if (flowInputNameBuffers.find(pinId) == flowInputNameBuffers.end()) { flowInputNameBuffers[pinId] = pin.Name; @@ -250,7 +250,7 @@ void RenderBlockEditDialog() // Editable parameter name ImGui::PushItemWidth(150.0f); static std::map nameBuffers; // Per-pin name buffers - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); if (nameBuffers.find(pinId) == nameBuffers.end()) { nameBuffers[pinId] = pin.Name; @@ -411,7 +411,7 @@ void RenderBlockEditDialog() case PinType::String: { static std::map stringBuffers; // Per-pin buffers - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); if (stringBuffers.find(pinId) == stringBuffers.end()) { stringBuffers[pinId] = paramNode->StringValue; @@ -455,7 +455,7 @@ void RenderBlockEditDialog() ImGui::PushItemWidth(150.0f); // Get or create default value - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); auto& paramValues = s_EditingNode->UnconnectedParamValues; if (paramValues.find(pinId) == paramValues.end()) { @@ -586,7 +586,7 @@ void RenderBlockEditDialog() // Editable flow output name ImGui::PushItemWidth(150.0f); static std::map flowOutputNameBuffers; - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); if (flowOutputNameBuffers.find(pinId) == flowOutputNameBuffers.end()) { flowOutputNameBuffers[pinId] = pin.Name; @@ -677,7 +677,7 @@ void RenderBlockEditDialog() // Editable parameter name ImGui::PushItemWidth(150.0f); static std::map outputNameBuffers; // Per-pin name buffers for outputs - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); if (outputNameBuffers.find(pinId) == outputNameBuffers.end()) { outputNameBuffers[pinId] = pin.Name; @@ -708,7 +708,7 @@ void RenderBlockEditDialog() // Editable parameter type (combo) for outputs ImGui::PushItemWidth(100.0f); static std::map outputTypeIndices; // Per-pin type index buffers for outputs - int outputPinId = pin.ID.Get(); + const int outputPinId = ToRuntimeId(pin.ID); const char* outputTypeItems[] = { "Bool", "Int", "Float", "String", "Object", "Function", "Delegate" }; PinType outputTypeValues[] = { PinType::Bool, PinType::Int, PinType::Float, PinType::String, PinType::Object, PinType::Function, PinType::Delegate }; diff --git a/examples/blueprints-example/blocks/block_edit_dialog.h b/applications/nodehub/blocks/block_edit_dialog.h similarity index 87% rename from examples/blueprints-example/blocks/block_edit_dialog.h rename to applications/nodehub/blocks/block_edit_dialog.h index 295488d..9e0e07e 100644 --- a/examples/blueprints-example/blocks/block_edit_dialog.h +++ b/applications/nodehub/blocks/block_edit_dialog.h @@ -1,7 +1,7 @@ #pragma once // Forward declarations -class Node; +struct Node; class App; void OpenBlockEditDialog(Node* node, App* app); diff --git a/examples/blueprints-example/blocks/constants.h b/applications/nodehub/blocks/constants.h similarity index 100% rename from examples/blueprints-example/blocks/constants.h rename to applications/nodehub/blocks/constants.h diff --git a/examples/blueprints-example/blocks/group_block.cpp b/applications/nodehub/blocks/group_block.cpp similarity index 98% rename from examples/blueprints-example/blocks/group_block.cpp rename to applications/nodehub/blocks/group_block.cpp index dc9d3e7..e89c958 100644 --- a/examples/blueprints-example/blocks/group_block.cpp +++ b/applications/nodehub/blocks/group_block.cpp @@ -1,9 +1,9 @@ #define IMGUI_DEFINE_MATH_OPERATORS +#include #include "group_block.h" #include "../app.h" #include "block.h" #include "../utilities/node_renderer_base.h" -#include "../../crude_json.h" #include "NodeEx.h" #include "constants.h" #include "../Logging.h" @@ -317,7 +317,7 @@ void GroupBlock::RenderExpanded(Node& node, App* app, Pin* newLinkPin) static std::map resizeStartSize; static std::map resizeStartMouseCanvas; - int nodeId = node.ID.Get(); + const int nodeId = ToRuntimeId(node.ID); if (ImGui::IsItemActive()) { @@ -377,12 +377,12 @@ void GroupBlock::RebuildPins(Node& node, App* app) for (const auto& input : node.Inputs) { if (input.UUID.IsValid()) - oldPinUuids[input.ID.Get()] = input.UUID; + oldPinUuids[ToRuntimeId(input.ID)] = input.UUID; } for (const auto& output : node.Outputs) { if (output.UUID.IsValid()) - oldPinUuids[output.ID.Get()] = output.UUID; + oldPinUuids[ToRuntimeId(output.ID)] = output.UUID; } LOG_DEBUG("[GroupBlock::RebuildPins] Preserved {} pin UUIDs before rebuild", oldPinUuids.size()); @@ -399,7 +399,7 @@ void GroupBlock::RebuildPins(Node& node, App* app) // Restore or generate UUIDs for pins for (auto& input : node.Inputs) { - int pinId = input.ID.Get(); + const int pinId = ToRuntimeId(input.ID); // Try to restore old UUID if this pin ID existed before auto it = oldPinUuids.find(pinId); @@ -425,7 +425,7 @@ void GroupBlock::RebuildPins(Node& node, App* app) for (auto& output : node.Outputs) { - int pinId = output.ID.Get(); + const int pinId = ToRuntimeId(output.ID); // Try to restore old UUID if this pin ID existed before auto it = oldPinUuids.find(pinId); @@ -863,7 +863,7 @@ void GroupBlock::LoadState(Node& node, const crude_json::value& nodeData, Contai RebuildPins(node, app); LOG_DEBUG("[GroupBlock::LoadState] Rebuilt node {} with {} inputs, {} outputs", - node.ID.Get(), node.Inputs.size(), node.Outputs.size()); + ToRuntimeId(node.ID), node.Inputs.size(), node.Outputs.size()); // Call base class to load parameter values (after rebuilding structure) ParameterizedBlock::LoadState(node, nodeData, container, app); diff --git a/examples/blueprints-example/blocks/group_block.h b/applications/nodehub/blocks/group_block.h similarity index 94% rename from examples/blueprints-example/blocks/group_block.h rename to applications/nodehub/blocks/group_block.h index 1a87c70..a1af9c5 100644 --- a/examples/blueprints-example/blocks/group_block.h +++ b/applications/nodehub/blocks/group_block.h @@ -29,19 +29,19 @@ class GroupBlock : public ParameterizedBlock public: GroupBlock(int id) : ParameterizedBlock(id, "Group") { - m_TypeName = "Group"; + SetTypeName("Group"); m_Type = NodeType::Group; m_Color = ImColor(200, 150, 200); // Purple-ish color for groups - m_bFlags = static_cast( + SetFlags(static_cast( NHBEHAVIOR_SCRIPT | NHBEHAVIOR_VARIABLEINPUTS | NHBEHAVIOR_VARIABLEOUTPUTS | - NHBEHAVIOR_VARIABLEPARAMETERINPUTS | NHBEHAVIOR_VARIABLEPARAMETEROUTPUTS); + NHBEHAVIOR_VARIABLEPARAMETERINPUTS | NHBEHAVIOR_VARIABLEPARAMETEROUTPUTS)); m_DisplayMode = GroupDisplayMode::Expanded; // Default to expanded m_CollapsedSize = ImVec2(150.0f, 80.0f); // Default collapsed size } void Build(Node& node, App* app) override; int Run(Node& node, App* app) override; - const char* GetBlockType() const override { return "Group"; } + NH_CSTRING GetBlockType() const override { return "Group"; } // Rendering (uses base class rendering like any other block) void Render(Node& node, App* app, Pin* newLinkPin) override; diff --git a/examples/blueprints-example/blocks/log_block.cpp b/applications/nodehub/blocks/log_block.cpp similarity index 96% rename from examples/blueprints-example/blocks/log_block.cpp rename to applications/nodehub/blocks/log_block.cpp index 0f868a8..2ae3d58 100644 --- a/examples/blueprints-example/blocks/log_block.cpp +++ b/applications/nodehub/blocks/log_block.cpp @@ -1,11 +1,10 @@ +#include + #include "log_block.h" #include "../app.h" -#include "../../crude_json.h" #include "../Logging.h" #include #include -#include -#include #ifdef _WIN32 #include diff --git a/examples/blueprints-example/blocks/log_block.h b/applications/nodehub/blocks/log_block.h similarity index 86% rename from examples/blueprints-example/blocks/log_block.h rename to applications/nodehub/blocks/log_block.h index ffa7160..3186c5b 100644 --- a/examples/blueprints-example/blocks/log_block.h +++ b/applications/nodehub/blocks/log_block.h @@ -14,17 +14,17 @@ class LogBlock : public ParameterizedBlock public: LogBlock(int id) : ParameterizedBlock(id, "Log") { - m_TypeName = "Log"; + SetTypeName("Log"); m_Type = NodeType::Blueprint; m_Color = ImColor(255, 200, 100); - m_bFlags = static_cast( + SetFlags(static_cast( NHBEHAVIOR_SCRIPT | - NHBEHAVIOR_VARIABLEINPUTS); + NHBEHAVIOR_VARIABLEINPUTS)); } void Build(Node& node, App* app) override; int Run(Node& node, App* app) override; - const char* GetBlockType() const override { return "Log"; } + NH_CSTRING GetBlockType() const override { return "Log"; } // State save/load to persist variable parameters void SaveState(Node& node, crude_json::value& nodeData, const Container* container, App* app) override; @@ -56,7 +56,7 @@ private: // Log settings template - void LogWithConfiguredLevel(const char* fmt, Args&&... args) const + void LogWithConfiguredLevel(NH_CSTRING fmt, Args&&... args) const { if (m_LogLevel == spdlog::level::off || !g_logger) return; diff --git a/examples/blueprints-example/blocks/logic_blocks.cpp b/applications/nodehub/blocks/logic_blocks.cpp similarity index 91% rename from examples/blueprints-example/blocks/logic_blocks.cpp rename to applications/nodehub/blocks/logic_blocks.cpp index 6f52f96..7c897db 100644 --- a/examples/blueprints-example/blocks/logic_blocks.cpp +++ b/applications/nodehub/blocks/logic_blocks.cpp @@ -2,7 +2,7 @@ #include "../app.h" #include "../Logging.h" -#include "../../crude_json.h" +#include #include #include #include @@ -32,7 +32,7 @@ LogicTestBlock::LogicTestBlock(int id) , m_FlowOutputIds({-1, -1}) , m_ValueParamIds({-1, -1}) { - m_TypeName = "Logic.Test"; + SetTypeName("Logic.Test"); m_Type = NodeType::Blueprint; m_Color = ImColor(230, 180, 95); } @@ -130,7 +130,7 @@ int LogicTestBlock::Run(Node& node, App* app) if (!valuePins[0] || !valuePins[1]) { - LOG_WARN("[Logic.Test] Missing parameter inputs on node {}", node.ID.Get()); + LOG_WARN("[Logic.Test] Missing parameter inputs on node {}", ToRuntimeId(node.ID)); ActivateOutput(0, false); ActivateOutput(1, false); return E_OK; @@ -171,7 +171,7 @@ int LogicTestBlock::Run(Node& node, App* app) } default: { - LOG_WARN("[Logic.Test] Unsupported parameter type on node {}", node.ID.Get()); + LOG_WARN("[Logic.Test] Unsupported parameter type on node {}", ToRuntimeId(node.ID)); comparisonResult = false; break; } @@ -180,7 +180,7 @@ int LogicTestBlock::Run(Node& node, App* app) ActivateOutput(0, comparisonResult); ActivateOutput(1, !comparisonResult); - LOG_DEBUG("[Logic.Test] Node {} result={} (operator={})", node.ID.Get(), comparisonResult ? "true" : "false", ToString(m_Operator)); + LOG_DEBUG("[Logic.Test] Node {} result={} (operator={})", ToRuntimeId(node.ID), comparisonResult ? "true" : "false", ToString(m_Operator)); return E_OK; } @@ -230,7 +230,7 @@ void LogicTestBlock::RebuildPins(Node& node, App* app) std::map oldPinUuids; for (const auto& input : node.Inputs) { - int pinId = input.ID.Get(); + const int pinId = ToRuntimeId(input.ID); if (input.UUID.IsValid()) { oldPinUuids[pinId] = input.UUID; @@ -240,7 +240,7 @@ void LogicTestBlock::RebuildPins(Node& node, App* app) { if (output.UUID.IsValid()) { - oldPinUuids[output.ID.Get()] = output.UUID; + oldPinUuids[ToRuntimeId(output.ID)] = output.UUID; } } @@ -255,7 +255,7 @@ void LogicTestBlock::RebuildPins(Node& node, App* app) for (auto& input : node.Inputs) { - int pinId = input.ID.Get(); + const int pinId = ToRuntimeId(input.ID); auto it = oldPinUuids.find(pinId); if (it != oldPinUuids.end()) { @@ -273,7 +273,7 @@ void LogicTestBlock::RebuildPins(Node& node, App* app) for (auto& output : node.Outputs) { - int pinId = output.ID.Get(); + const int pinId = ToRuntimeId(output.ID); auto it = oldPinUuids.find(pinId); if (it != oldPinUuids.end()) { @@ -328,7 +328,7 @@ void LogicTestBlock::LoadState(Node& node, const crude_json::value& nodeData, Co // If IDs were not saved (backward compatibility), capture current IDs from node if (m_FlowInputId < 0 && !node.Inputs.empty()) - m_FlowInputId = node.Inputs.front().ID.Get(); + m_FlowInputId = ToRuntimeId(node.Inputs.front().ID); int paramCounter = 0; for (const auto& pin : node.Inputs) @@ -338,7 +338,7 @@ void LogicTestBlock::LoadState(Node& node, const crude_json::value& nodeData, Co int valueIndex = paramCounter; if (valueIndex < 2 && m_ValueParamIds[valueIndex] < 0) - m_ValueParamIds[valueIndex] = pin.ID.Get(); + m_ValueParamIds[valueIndex] = ToRuntimeId(pin.ID); ++paramCounter; } @@ -350,7 +350,7 @@ void LogicTestBlock::LoadState(Node& node, const crude_json::value& nodeData, Co continue; if (flowOutCounter < 2 && m_FlowOutputIds[flowOutCounter] < 0) { - m_FlowOutputIds[flowOutCounter] = pin.ID.Get(); + m_FlowOutputIds[flowOutCounter] = ToRuntimeId(pin.ID); } ++flowOutCounter; } diff --git a/examples/blueprints-example/blocks/logic_blocks.h b/applications/nodehub/blocks/logic_blocks.h similarity index 91% rename from examples/blueprints-example/blocks/logic_blocks.h rename to applications/nodehub/blocks/logic_blocks.h index 5451167..14ce758 100644 --- a/examples/blueprints-example/blocks/logic_blocks.h +++ b/applications/nodehub/blocks/logic_blocks.h @@ -24,7 +24,7 @@ public: void Build(Node& node, App* app) override; int Run(Node& node, App* app) override; - const char* GetBlockType() const override { return "Logic.Test"; } + NH_CSTRING GetBlockType() const override { return "Logic.Test"; } void SaveState(Node& node, crude_json::value& nodeData, const Container* container, App* app) override; void LoadState(Node& node, const crude_json::value& nodeData, Container* container, App* app) override; void OnMenu(Node& node, App* app) override; diff --git a/examples/blueprints-example/blocks/math_blocks.cpp b/applications/nodehub/blocks/math_blocks.cpp similarity index 100% rename from examples/blueprints-example/blocks/math_blocks.cpp rename to applications/nodehub/blocks/math_blocks.cpp diff --git a/examples/blueprints-example/blocks/math_blocks.h b/applications/nodehub/blocks/math_blocks.h similarity index 73% rename from examples/blueprints-example/blocks/math_blocks.h rename to applications/nodehub/blocks/math_blocks.h index 732ab31..b29b536 100644 --- a/examples/blueprints-example/blocks/math_blocks.h +++ b/applications/nodehub/blocks/math_blocks.h @@ -9,14 +9,14 @@ class AddBlock : public ParameterizedBlock public: AddBlock(int id) : ParameterizedBlock(id, "Add") { - m_TypeName = "Math.Add"; + SetTypeName("Math.Add"); m_Type = NodeType::Blueprint; m_Color = ImColor(128, 195, 248); } void Build(Node& node, App* app) override; int Run(Node& node, App* app) override; - const char* GetBlockType() const override { return "Math.Add"; } + NH_CSTRING GetBlockType() const override { return "Math.Add"; } }; class MultiplyBlock : public ParameterizedBlock @@ -24,14 +24,14 @@ class MultiplyBlock : public ParameterizedBlock public: MultiplyBlock(int id) : ParameterizedBlock(id, "Multiply") { - m_TypeName = "Math.Multiply"; + SetTypeName("Math.Multiply"); m_Type = NodeType::Blueprint; m_Color = ImColor(128, 195, 248); } void Build(Node& node, App* app) override; int Run(Node& node, App* app) override; - const char* GetBlockType() const override { return "Math.Multiply"; } + NH_CSTRING GetBlockType() const override { return "Math.Multiply"; } }; class CompareBlock : public ParameterizedBlock @@ -39,13 +39,13 @@ class CompareBlock : public ParameterizedBlock public: CompareBlock(int id) : ParameterizedBlock(id, "Compare") { - m_TypeName = "Math.Compare"; + SetTypeName("Math.Compare"); m_Type = NodeType::Blueprint; m_Color = ImColor(128, 195, 248); } void Build(Node& node, App* app) override; int Run(Node& node, App* app) override; - const char* GetBlockType() const override { return "Math.Compare"; } + NH_CSTRING GetBlockType() const override { return "Math.Compare"; } }; diff --git a/examples/blueprints-example/blocks/parameter_edit_dialog.cpp b/applications/nodehub/blocks/parameter_edit_dialog.cpp similarity index 100% rename from examples/blueprints-example/blocks/parameter_edit_dialog.cpp rename to applications/nodehub/blocks/parameter_edit_dialog.cpp diff --git a/examples/blueprints-example/blocks/parameter_edit_dialog.h b/applications/nodehub/blocks/parameter_edit_dialog.h similarity index 100% rename from examples/blueprints-example/blocks/parameter_edit_dialog.h rename to applications/nodehub/blocks/parameter_edit_dialog.h diff --git a/examples/blueprints-example/blocks/parameter_node.cpp b/applications/nodehub/blocks/parameter_node.cpp similarity index 95% rename from examples/blueprints-example/blocks/parameter_node.cpp rename to applications/nodehub/blocks/parameter_node.cpp index 5a197e2..718969a 100644 --- a/examples/blueprints-example/blocks/parameter_node.cpp +++ b/applications/nodehub/blocks/parameter_node.cpp @@ -1,10 +1,13 @@ #define IMGUI_DEFINE_MATH_OPERATORS +#include + +#include "../all.h" + #include "parameter_node.h" #include "../app.h" -#include "block.h" // For BlockStyle constants (legacy) +#include "block.h" #include "../utilities/node_renderer_base.h" #include "../containers/container.h" -#include "../../crude_json.h" #include "NodeEx.h" #include "constants.h" #include @@ -251,7 +254,7 @@ int ParameterNode::RunInternal(Node& node, App* app, int depth) { // Source doesn't exist - orphaned shortcut, clear reference printf("[RUN] Parameter node %d: Source node %d not found, clearing shortcut reference\n", - node.ID.Get(), m_SourceID); + ToRuntimeId(node.ID), m_SourceID); m_SourceID = 0; m_IsSource = false; } @@ -333,7 +336,7 @@ int ParameterNode::RunInternal(Node& node, App* app, int depth) { // Source is a block output - read value from block's output parameter // Block outputs store their values in UnconnectedParamValues - int sourcePinId = sourcePin->ID.Get(); + const int sourcePinId = ToRuntimeId(sourcePin->ID); auto& paramValues = sourceNode->UnconnectedParamValues; if (paramValues.find(sourcePinId) != paramValues.end()) @@ -998,10 +1001,6 @@ void ParameterNode::OnMenu(Node& node, App* app) if (ImGui::MenuItem("Run (R)")) { int result = Run(node, app); - printf("Parameter '%s' (ID: %d) Run() returned: %d\n", - node.Name.c_str(), node.ID.Get(), result); - ax::NodeEditor::AddInAppLog("Parameter '%s' (ID: %d) Run() returned: %d\n", - node.Name.c_str(), node.ID.Get(), result); } // Source/Shortcut management @@ -1125,8 +1124,6 @@ void ParameterNode::LoadState(Node& node, const crude_json::value& nodeData, Con else { // Source doesn't exist - orphaned shortcut, clear reference - printf("[LOAD] Parameter node %d: Source node %d not found, clearing shortcut reference\n", - node.ID.Get(), sourceId); m_SourceID = 0; m_IsSource = false; } @@ -1198,14 +1195,14 @@ Node* ParameterNode::CreateShortcut(Node& sourceNode, App* app) ed::SetNodePosition(shortcutNode->ID, shortcutPos); printf("[SHORTCUT] Created shortcut node %d for source %d at (%.1f, %.1f)\n", - shortcutNode->ID.Get(), m_ID, shortcutPos.x, shortcutPos.y); + ToRuntimeId(shortcutNode->ID), m_ID, shortcutPos.x, shortcutPos.y); return shortcutNode; } -ParameterNode* ParameterRegistry::CreateParameter(PinType type, int id, const char* name) +ParameterNode* ParameterRegistry::CreateParameter(PinType type, int id, NH_CSTRING name) { - const char* defaultName = nullptr; + NH_CSTRING defaultName = nullptr; switch (type) { case PinType::Bool: defaultName = "Bool"; break; diff --git a/examples/blueprints-example/blocks/parameter_node.h b/applications/nodehub/blocks/parameter_node.h similarity index 90% rename from examples/blueprints-example/blocks/parameter_node.h rename to applications/nodehub/blocks/parameter_node.h index 916b23e..fc480ca 100644 --- a/examples/blueprints-example/blocks/parameter_node.h +++ b/applications/nodehub/blocks/parameter_node.h @@ -1,6 +1,8 @@ #pragma once +#include "../commons.h" #include "../types.h" #include "../utilities/node_renderer_base.h" +#include "../core/Object.h" #include #include @@ -20,12 +22,11 @@ enum class ParameterDisplayMode }; // Base parameter node class -class ParameterNode : public ax::NodeRendering::NodeRendererBase +class ParameterNode : public NH_Object, public ax::NodeRendering::NodeRendererBase { public: - ParameterNode(int id, const char* name, PinType type) - : m_ID(id) - , m_Name(name) + ParameterNode(int id, NH_CSTRING name, PinType type) + : NH_Object(id, name) , m_Type(type) , m_DisplayMode(ParameterDisplayMode::NameAndValue) , m_IsSource(false) @@ -37,9 +38,9 @@ public: virtual ~ParameterNode() = default; // Core properties - int GetID() const { return m_ID; } - const char* GetName() const { return m_Name.c_str(); } - void SetName(const char* name) { m_Name = name; } + int GetID() const { return NH_Object::GetID(); } + NH_CSTRING GetName() const { return NH_Object::GetName(); } + void SetName(NH_CSTRING name) { NH_Object::SetName(name); } PinType GetType() const { return m_Type; } void SetType(PinType type) { m_Type = type; InitializeDefaultValue(); } @@ -113,8 +114,6 @@ protected: void RenderMinimal(Node& node, App* app, Pin* newLinkPin); void RenderMinimalLinks(Node& node, App* app, Pin* newLinkPin); - int m_ID; - std::string m_Name; PinType m_Type; ParameterDisplayMode m_DisplayMode; @@ -141,7 +140,7 @@ public: return instance; } - ParameterNode* CreateParameter(PinType type, int id, const char* name = nullptr); + ParameterNode* CreateParameter(PinType type, int id, NH_CSTRING name = nullptr); private: ParameterRegistry() = default; diff --git a/examples/blueprints-example/blocks/parameter_operation.cpp b/applications/nodehub/blocks/parameter_operation.cpp similarity index 96% rename from examples/blueprints-example/blocks/parameter_operation.cpp rename to applications/nodehub/blocks/parameter_operation.cpp index 4ddc36a..f0d823c 100644 --- a/examples/blueprints-example/blocks/parameter_operation.cpp +++ b/applications/nodehub/blocks/parameter_operation.cpp @@ -3,7 +3,7 @@ #include "../app.h" #include "../utilities/node_renderer_base.h" #include "NodeEx.h" -#include "../../crude_json.h" +#include #include #include @@ -227,7 +227,7 @@ int ParameterOperationBlock::Run(Node& node, App* app) void ParameterOperationBlock::Render(Node& node, App* app, Pin* newLinkPin) { // Check if node is currently running (for red border visualization) - float currentTime = ImGui::GetTime(); + double currentTime = (double)ImGui::GetTime(); bool isRunning = false; auto runningIt = app->m_RunningNodes.find(node.ID); if (runningIt != app->m_RunningNodes.end()) diff --git a/examples/blueprints-example/blocks/parameter_operation.h b/applications/nodehub/blocks/parameter_operation.h similarity index 92% rename from examples/blueprints-example/blocks/parameter_operation.h rename to applications/nodehub/blocks/parameter_operation.h index 77e05f7..dc9f3f9 100644 --- a/examples/blueprints-example/blocks/parameter_operation.h +++ b/applications/nodehub/blocks/parameter_operation.h @@ -47,10 +47,10 @@ class ParameterOperationBlock : public ParameterizedBlock public: ParameterOperationBlock(int id) : ParameterizedBlock(id, "ParamOp") { - m_TypeName = "ParamOp"; + SetTypeName("ParamOp"); m_Type = NodeType::Blueprint; m_Color = ImColor(180, 200, 180); // Light green - m_bFlags = static_cast(NHBEHAVIOR_SCRIPT); + SetFlags(static_cast(NHBEHAVIOR_SCRIPT)); // Default types m_InputAType = PinType::Int; @@ -62,7 +62,7 @@ public: void Build(Node& node, App* app) override; int Run(Node& node, App* app) override; void Render(Node& node, App* app, Pin* newLinkPin) override; - const char* GetBlockType() const override { return "ParamOp"; } + NH_CSTRING GetBlockType() const override { return "ParamOp"; } void OnMenu(Node& node, App* app) override; diff --git a/examples/blueprints-example/blocks/start_block.cpp b/applications/nodehub/blocks/start_block.cpp similarity index 100% rename from examples/blueprints-example/blocks/start_block.cpp rename to applications/nodehub/blocks/start_block.cpp diff --git a/examples/blueprints-example/blocks/start_block.h b/applications/nodehub/blocks/start_block.h similarity index 80% rename from examples/blueprints-example/blocks/start_block.h rename to applications/nodehub/blocks/start_block.h index b8acb8b..df82199 100644 --- a/examples/blueprints-example/blocks/start_block.h +++ b/applications/nodehub/blocks/start_block.h @@ -9,13 +9,13 @@ class StartBlock : public ParameterizedBlock public: StartBlock(int id) : ParameterizedBlock(id, "Start") { - m_TypeName = "Start"; + SetTypeName("Start"); m_Type = NodeType::Blueprint; m_Color = ImColor(100, 255, 100); } void Build(Node& node, App* app) override; int Run(Node& node, App* app) override; - const char* GetBlockType() const override { return "Start"; } + NH_CSTRING GetBlockType() const override { return "Start"; } }; diff --git a/applications/nodehub/commons.h b/applications/nodehub/commons.h new file mode 100644 index 0000000..e368e0f --- /dev/null +++ b/applications/nodehub/commons.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include "./enums.h" +#include "./utilities/uuid_generator.h" + + +#ifndef NH_CSTRING +#define NH_CSTRING const char* +#endif + +typedef char* NH_STRING; +typedef char NH_CHAR; +typedef unsigned short* NH_USTRING; +typedef unsigned short NH_UCHAR; + +typedef int NH_BOOL; +typedef unsigned char NH_BYTE; +typedef unsigned int NH_DWORD; +typedef unsigned short NH_WORD; + +typedef int NH_ERROR; +typedef int NH_PARAMETER_TYPE; +typedef int NH_OPERATION_TYPE; +typedef int NH_MESSAGE_TYPE; +typedef int NH_ATTRIBUTE_TYPE; +typedef int NH_ATTRIBUTE_CATEGORY; + +typedef Uuid64 NH_GUID; +typedef unsigned int NH_ID; +typedef unsigned int NH_CLASS_ID; diff --git a/applications/nodehub/config.h b/applications/nodehub/config.h new file mode 100644 index 0000000..fbdc756 --- /dev/null +++ b/applications/nodehub/config.h @@ -0,0 +1,8 @@ +#ifndef CONFIG_H +#define CONFIG_H + +#ifndef NH_GUI +#define NH_GUI +#endif + +#endif \ No newline at end of file diff --git a/examples/blueprints-example/containers/container.cpp b/applications/nodehub/containers/container.cpp similarity index 95% rename from examples/blueprints-example/containers/container.cpp rename to applications/nodehub/containers/container.cpp index 11943c4..cff61f2 100644 --- a/examples/blueprints-example/containers/container.cpp +++ b/applications/nodehub/containers/container.cpp @@ -181,7 +181,7 @@ void Container::RemoveNode(Node* node) int nodeId = -1; try { - nodeId = node->ID.Get(); + nodeId = ToRuntimeId(node->ID); } catch (...) { printf("[DELETE] Container::RemoveNode: Cannot access node ID (corrupted pointer %p)\n", (void*)node); fflush(stdout); @@ -216,10 +216,12 @@ void Container::AddLink(Link* link) return; } + const int linkId = ToRuntimeId(link->ID); + if (ContainsLink(link->ID)) { printf("[LINK_DRAG] Container::AddLink: Link ID %lld already exists in container, REJECTING!\n", - (long long)link->ID.Get()); + static_cast(linkId)); printf("[LINK_DRAG] Container::AddLink: Current link IDs in container: "); for (auto id : m_LinkIds) printf("%lld ", (long long)id.Get()); @@ -228,7 +230,7 @@ void Container::AddLink(Link* link) return; } - printf("[LINK_DRAG] Container::AddLink: Adding link ID=%lld to container\n", (long long)link->ID.Get()); + printf("[LINK_DRAG] Container::AddLink: Adding link ID=%lld to container\n", static_cast(linkId)); fflush(stdout); // Store ID - actual link is stored in RootContainer::m_Links diff --git a/examples/blueprints-example/containers/container.h b/applications/nodehub/containers/container.h similarity index 100% rename from examples/blueprints-example/containers/container.h rename to applications/nodehub/containers/container.h diff --git a/examples/blueprints-example/containers/root_container.cpp b/applications/nodehub/containers/root_container.cpp similarity index 94% rename from examples/blueprints-example/containers/root_container.cpp rename to applications/nodehub/containers/root_container.cpp index 570103c..9392b85 100644 --- a/examples/blueprints-example/containers/root_container.cpp +++ b/applications/nodehub/containers/root_container.cpp @@ -112,9 +112,6 @@ Pin* RootContainer::FindPin(ed::PinId id, App* app) // Ensure pin's Node pointer is correct (should be set by BuildNode after AddNode) if (pin.Node != &node) { - printf("[FindPin] FIXING pin %d - Node pointer incorrect (was %p, setting to %p)\n", - id.Get(), (void*)pin.Node, (void*)&node); - fflush(stdout); pin.Node = &node; // Fix to point to actual node in container } return &pin; diff --git a/examples/blueprints-example/containers/root_container.h b/applications/nodehub/containers/root_container.h similarity index 96% rename from examples/blueprints-example/containers/root_container.h rename to applications/nodehub/containers/root_container.h index a230d11..df108a4 100644 --- a/examples/blueprints-example/containers/root_container.h +++ b/applications/nodehub/containers/root_container.h @@ -7,7 +7,7 @@ namespace ed = ax::NodeEditor; class App; -class Pin; +struct Pin; /** * RootContainer - Owns actual Node and Link objects for its graph diff --git a/applications/nodehub/core/BaseManager.cpp b/applications/nodehub/core/BaseManager.cpp new file mode 100644 index 0000000..419b960 --- /dev/null +++ b/applications/nodehub/core/BaseManager.cpp @@ -0,0 +1 @@ +#include "BaseManager.h" \ No newline at end of file diff --git a/applications/nodehub/core/BaseManager.h b/applications/nodehub/core/BaseManager.h new file mode 100644 index 0000000..6e4f91e --- /dev/null +++ b/applications/nodehub/core/BaseManager.h @@ -0,0 +1,33 @@ +#ifndef NH_BASE_MANAGER_H +#define NH_BASE_MANAGER_H + +#include "../commons.h" +#include "../types.h" + +class NH_Context; + +class NH_BaseManager { +public: + NH_BaseManager() {} + virtual ~NH_BaseManager() = default; + + virtual NH_ERROR OnInit() { return E_OK; } + + NH_Context* GetContext() { return m_Context; } + void SetContext(NH_Context* context) { m_Context = context; } + + Uuid64 GetGuid() { return m_Guid; } + std::string GetName() { return m_Name; } + + void SetName(std::string name) { m_Name = name; } + void SetGuid(Uuid64 guid) { m_Guid = guid; } + + protected: + NH_Context* m_Context; + Uuid64 m_Guid; + std::string m_Name; + +}; + + +#endif \ No newline at end of file diff --git a/applications/nodehub/core/Context.cpp b/applications/nodehub/core/Context.cpp new file mode 100644 index 0000000..7fdb192 --- /dev/null +++ b/applications/nodehub/core/Context.cpp @@ -0,0 +1,38 @@ +#include "Context.h" +#include "../logging.h" +#include "ParameterManager.h" +#include "ParameterIn.h" +#include "ParameterOut.h" +#include "../utilities/uuid_generator.h" + +NH_Context::NH_Context() : m_ParameterManager(nullptr), m_App(nullptr) {} + +NH_Context::~NH_Context() +{ + delete m_ParameterManager; +} + +NH_ERROR NH_Context::init(App *app) +{ + m_App = app; + m_ParameterManager = new NH_ParameterManager(this); + m_ParameterManager->OnInit(); + LOG_INFO("Context initialized"); + return E_OK; +} + +NH_ParameterIn* NH_Context::CreateParameterIn(NH_CSTRING name, const Uuid64& guid) +{ + // A proper implementation would use an object manager to handle IDs and memory. + auto* param = new NH_ParameterIn(0, name); + // TODO: Set the parameter type based on the GUID by looking it up in the ParameterManager. + return param; +} + +NH_ParameterOut* NH_Context::CreateParameterOut(NH_CSTRING name, const Uuid64& guid) +{ + // A proper implementation would use an object manager. + auto* param = new NH_ParameterOut(0, name); + // TODO: Set the parameter type based on the GUID. + return param; +} \ No newline at end of file diff --git a/applications/nodehub/core/Context.h b/applications/nodehub/core/Context.h new file mode 100644 index 0000000..fb57313 --- /dev/null +++ b/applications/nodehub/core/Context.h @@ -0,0 +1,41 @@ +#ifndef NH_CONTEXT_H +#define NH_CONTEXT_H + +#include "../commons.h" +#include "../types.h" + +class App; +class NH_ParameterManager; +class NH_ParameterIn; +class NH_ParameterOut; +struct Uuid64; + +class NH_Context { +public: + NH_Context(); + virtual ~NH_Context(); + + NH_ParameterManager* GetParameterManager() { return m_ParameterManager; } + void SetParameterManager(NH_ParameterManager* parameterManager) { m_ParameterManager = parameterManager; } + + App* GetApp() { return m_App; } + void SetApp(App* app) { m_App = app; } + + //----------------------------------------- + // Lifecycle + //----------------------------------------- + NH_ERROR init(App *app); + + // Object Management + NH_ParameterIn* CreateParameterIn(NH_CSTRING name, const Uuid64& guid); + NH_ParameterOut* CreateParameterOut(NH_CSTRING name, const Uuid64& guid); + +protected: + NH_ParameterManager* m_ParameterManager; + + // legacy support + App* m_App; + +}; + +#endif diff --git a/applications/nodehub/core/Object.cpp b/applications/nodehub/core/Object.cpp new file mode 100644 index 0000000..30b4abe --- /dev/null +++ b/applications/nodehub/core/Object.cpp @@ -0,0 +1 @@ +#include "Object.h" diff --git a/applications/nodehub/core/Object.h b/applications/nodehub/core/Object.h new file mode 100644 index 0000000..678720a --- /dev/null +++ b/applications/nodehub/core/Object.h @@ -0,0 +1,111 @@ +#pragma once + +#include "../commons.h" +#include "../utilities/uuid_generator.h" +#include + +class App; +class Container; +namespace crude_json { struct value; } + +class NH_Object +{ +public: + NH_Object() + : m_ID(0) + , m_Name("") + , m_TypeName("") + , m_Parent(nullptr) + , m_BehaviorFlags(NHBEHAVIOR_NONE) + , m_ObjectFlags(NH_OBJECT_DYNAMIC) + {} + + NH_Object(int id, NH_CSTRING name, NH_CSTRING typeName = nullptr) + : NH_Object() + { + m_ID = id; + if (name) + m_Name = name; + if (typeName) + m_TypeName = typeName; + } + virtual ~NH_Object() = default; + + // Core identification + int GetID() const { return m_ID; } + void SetID(int id) { m_ID = id; } + + NH_CSTRING GetName() const { return m_Name.c_str(); } + const std::string& GetNameString() const { return m_Name; } + void SetName(NH_CSTRING name) + { + m_Name = name ? name : ""; + } + + NH_CSTRING GetTypeName() const { return m_TypeName.c_str(); } + void SetTypeName(NH_CSTRING typeName) + { + m_TypeName = typeName ? typeName : ""; + } + + NH_Object* GetParent() const { return m_Parent; } + void SetParent(NH_Object* parent) { m_Parent = parent; } + + // Behavior flags (Virtools-style) + NH_BEHAVIOR_FLAGS GetBehaviorFlags() const { return m_BehaviorFlags; } + void SetBehaviorFlags(NH_BEHAVIOR_FLAGS flags) { m_BehaviorFlags = flags; } + void AddBehaviorFlags(NH_BEHAVIOR_FLAGS flags) + { + m_BehaviorFlags = static_cast( + static_cast(m_BehaviorFlags) | static_cast(flags)); + } + + void RemoveBehaviorFlags(NH_BEHAVIOR_FLAGS flags) + { + m_BehaviorFlags = static_cast( + static_cast(m_BehaviorFlags) & ~static_cast(flags)); + } + + // Object flags (base Virtools object flags) + NH_OBJECT_FLAGS GetObjectFlags() const + { + return static_cast(m_ObjectFlags); + } + void SetObjectFlags(NH_OBJECT_FLAGS flags) + { + m_ObjectFlags = static_cast(flags); + } + void AddObjectFlags(NH_OBJECT_FLAGS flags) + { + m_ObjectFlags |= static_cast(flags); + } + void ClearObjectFlags(NH_OBJECT_FLAGS flags) + { + m_ObjectFlags &= ~static_cast(flags); + } + + // Serialization hooks (mirror block/parameter APIs) + virtual void SaveState(crude_json::value& data, const Container* container, App* app) {} + virtual void LoadState(const crude_json::value& data, Container* container, App* app) {} + + Uuid64 m_UUID; + void SetUUID(Uuid64 uuid) { m_UUID = uuid; } + Uuid64 GetUUID() const { return m_UUID; } + + + NH_STRING GetClassName(); + // Class Registering + static NH_STRING m_ClassName; + + virtual NH_CLASS_ID GetClassID() { return NHCID_PARAMETER; } + +protected: + int m_ID; + std::string m_Name; + std::string m_TypeName; + NH_Object* m_Parent; + NH_BEHAVIOR_FLAGS m_BehaviorFlags; + NH_DWORD m_ObjectFlags; + NH_CLASS_ID m_ClassID; + +}; diff --git a/applications/nodehub/core/Parameter.cpp b/applications/nodehub/core/Parameter.cpp new file mode 100644 index 0000000..d936a0d --- /dev/null +++ b/applications/nodehub/core/Parameter.cpp @@ -0,0 +1,68 @@ +#include "Parameter.h" +#include "Context.h" +#include "ParameterManager.h" +#include + +NH_Parameter::NH_Parameter(int id, NH_CSTRING name) : NH_Object(id, name) { + m_Owner = nullptr; + m_AllocatedSize = 0; + m_Buffer = nullptr; + m_ParamType = nullptr; +} + +NH_Parameter::~NH_Parameter() { + if (m_Buffer) { + delete[] m_Buffer; + m_Buffer = nullptr; + } +} + +NH_ERROR NH_Parameter::GetValue(void *buf, NH_BOOL update) { + if (!buf || !m_Buffer) return E_FAIL; + memcpy(buf, m_Buffer, m_DataSize); + return E_OK; +} + +NH_ERROR NH_Parameter::SetValue(const void *buf, int size) { + if (!buf) return E_FAIL; + + int dataSize = size; + if (dataSize == 0 && m_ParamType) { + dataSize = m_ParamType->DefaultSize; + } + + if (dataSize == 0) return E_FAIL; + + if (m_AllocatedSize < dataSize) { + if (m_Buffer) { + delete[] m_Buffer; + } + m_Buffer = new NH_BYTE[dataSize]; + m_AllocatedSize = dataSize; + } + + memcpy(m_Buffer, buf, dataSize); + m_DataSize = dataSize; + + return E_OK; +} + +NH_ERROR NH_Parameter::CopyValue(NH_Parameter *param, NH_BOOL UpdateParam) { + return E_NOTIMPL; +} + +void *NH_Parameter::GetReadDataPtr(NH_BOOL update) { + return m_Buffer; +} + +void *NH_Parameter::GetWriteDataPtr() { + return nullptr; +} + +NH_ERROR NH_Parameter::SetStringValue(NH_STRING Value) { + return E_NOTIMPL; +} + +int NH_Parameter::GetStringValue(NH_STRING Value, NH_BOOL update) { + return E_NOTIMPL; +} diff --git a/applications/nodehub/core/Parameter.h b/applications/nodehub/core/Parameter.h new file mode 100644 index 0000000..2e757c6 --- /dev/null +++ b/applications/nodehub/core/Parameter.h @@ -0,0 +1,59 @@ +#ifndef NH_PARAMETER_H +#define NH_PARAMETER_H + +#include "../commons.h" +#include "../types.h" +#include "./Object.h" + +class NH_Parameter : public NH_Object { +public: + NH_Parameter(int id, NH_CSTRING name); + virtual ~NH_Parameter(); + + NH_PARAMETER_TYPE GetType(); + void SetType(NH_PARAMETER_TYPE type); + + NH_CLASS_ID GetParameterClassID(); + virtual NH_CLASS_ID GetClassID() { return NHCID_PARAMETER; } + + void SetOwner(NH_Object *owner) { m_Owner = owner; } + NH_Object *GetOwner() { return m_Owner; } + + NH_ParameterTypeDesc *GetParameterType() { return m_ParamType; } + + // Convertion from / to string + virtual NH_ERROR SetStringValue(NH_STRING Value); + virtual int GetStringValue(NH_STRING Value, NH_BOOL update = true); + + //-------------------------------------------- + // Value + + NH_Object *GetValueObject(NH_BOOL update = true); + + virtual NH_ERROR GetValue(void *buf, NH_BOOL update = true); + virtual NH_ERROR SetValue(const void *buf, int size = 0); + virtual NH_ERROR CopyValue(NH_Parameter *param, NH_BOOL UpdateParam = true); + + NH_BOOL IsCompatibleWith(NH_Parameter *param); + //-------------------------------------------- + // Data pointer + int GetDataSize(); + virtual void *GetReadDataPtr(NH_BOOL update = true); + virtual void *GetWriteDataPtr(); + +protected: + NH_Object *m_Owner; + + union { + int m_DataSize; + int m_AllocatedSize; + }; + union { + NH_BYTE *m_Buffer; + NH_DWORD m_Value; + }; + + NH_ParameterTypeDesc *m_ParamType; +}; + +#endif \ No newline at end of file diff --git a/applications/nodehub/core/ParameterIn.cpp b/applications/nodehub/core/ParameterIn.cpp new file mode 100644 index 0000000..20cbd1c --- /dev/null +++ b/applications/nodehub/core/ParameterIn.cpp @@ -0,0 +1,81 @@ +#include "./ParameterIn.h" +#include "./Context.h" +#include "ParameterManager.h" + +NH_ParameterIn::NH_ParameterIn(int id, NH_CSTRING name) : NH_Parameter(id, name) { + m_ObjectFlags &= ~NH_PARAMETERIN_SHARED; + m_DirectSource = nullptr; +} + +NH_Parameter* NH_ParameterIn::GetRealSource() { + if (m_ObjectFlags & NH_PARAMETERIN_SHARED) { + if (m_SharedSource) return m_SharedSource->GetRealSource(); + } else { + return m_DirectSource; + } + return nullptr; +} + +NH_Parameter* NH_ParameterIn::GetDirectSource() { + if (m_ObjectFlags & NH_PARAMETERIN_SHARED) return nullptr; + return m_DirectSource; +} + +NH_ERROR NH_ParameterIn::SetDirectSource(NH_Parameter* param) { + m_ObjectFlags &= ~NH_PARAMETERIN_SHARED; + m_DirectSource = param; + return E_OK; +} + +NH_ParameterIn* NH_ParameterIn::GetSharedSource() { + if (!(m_ObjectFlags & NH_PARAMETERIN_SHARED)) return nullptr; + return m_SharedSource; +} + +NH_ERROR NH_ParameterIn::ShareSourceWith(NH_ParameterIn* param) { + m_ObjectFlags |= NH_PARAMETERIN_SHARED; + m_SharedSource = param; + return E_OK; +} + +NH_ERROR NH_ParameterIn::GetValue(void* buf, NH_BOOL update) { + // Stub implementation + NH_Parameter* src = GetRealSource(); + if (!src) return E_FAIL; + return src->GetValue(buf, update); +} + +void* NH_ParameterIn::GetReadDataPtr(NH_BOOL update) { + // Stub implementation + NH_Parameter* src = GetRealSource(); + if (!src) return nullptr; + return src->GetReadDataPtr(update); +} + +NH_ERROR NH_ParameterIn::SetValue(const void* buf, int size) { + // Input parameters are read-only + return E_ACCESSDENIED; +} + +void* NH_ParameterIn::GetWriteDataPtr() { + // Input parameters are read-only + return nullptr; +} + +NH_ERROR NH_ParameterIn::CopyValue(NH_Parameter* param, NH_BOOL UpdateParam) { + NH_Parameter* src = GetRealSource(); + if (!src || !param) return E_FAIL; + return src->CopyValue(param, UpdateParam); +} + +NH_ERROR NH_ParameterIn::SetStringValue(NH_STRING Value) { + NH_Parameter* src = GetRealSource(); + if (!src) return E_FAIL; + return src->SetStringValue(Value); +} + +int NH_ParameterIn::GetStringValue(NH_STRING Value, NH_BOOL update) { + NH_Parameter* src = GetRealSource(); + if (!src) return E_FAIL; + return src->GetStringValue(Value, update); +} diff --git a/applications/nodehub/core/ParameterIn.h b/applications/nodehub/core/ParameterIn.h new file mode 100644 index 0000000..ff7ddc4 --- /dev/null +++ b/applications/nodehub/core/ParameterIn.h @@ -0,0 +1,45 @@ +#ifndef NH_PARAMETER_IN_H +#define NH_PARAMETER_IN_H + +#include "./Parameter.h" + +// Forward declaration +class NH_ParameterIn; + +class NH_ParameterIn : public NH_Parameter { +public: + NH_ParameterIn(int id, NH_CSTRING name); + virtual ~NH_ParameterIn() = default; + + // Source management + NH_Parameter *GetRealSource(); + + NH_Parameter *GetDirectSource(); + NH_ERROR SetDirectSource(NH_Parameter *param); + + NH_ParameterIn *GetSharedSource(); + NH_ERROR ShareSourceWith(NH_ParameterIn *param); + + // Overridden value accessors + virtual NH_ERROR GetValue(void *buf, NH_BOOL update = true) override; + virtual void *GetReadDataPtr(NH_BOOL update = true) override; + + // Disable writing + virtual NH_ERROR SetValue(const void *buf, int size = 0) override; + virtual NH_ERROR CopyValue(NH_Parameter *param, NH_BOOL UpdateParam = true) override; + virtual void *GetWriteDataPtr() override; + + // String conversion + virtual NH_ERROR SetStringValue(NH_STRING Value) override; + virtual int GetStringValue(NH_STRING Value, NH_BOOL update = true) override; + + virtual NH_CLASS_ID GetClassID() override { return NHCID_PARAMETERIN; } + +protected: + union { + NH_Parameter *m_DirectSource; + NH_ParameterIn *m_SharedSource; + }; +}; + +#endif // NH_PARAMETER_IN_H \ No newline at end of file diff --git a/applications/nodehub/core/ParameterManager.cpp b/applications/nodehub/core/ParameterManager.cpp new file mode 100644 index 0000000..3b249a9 --- /dev/null +++ b/applications/nodehub/core/ParameterManager.cpp @@ -0,0 +1,64 @@ +#include "ParameterManager.h" +#include + +NH_ParameterManager::NH_ParameterManager(NH_Context *context) : NH_BaseManager() { + SetContext(context); +} + +NH_ERROR NH_ParameterManager::OnInit() { + NH_ParameterTypeDesc pdesc; + + // Float + pdesc.Guid = NHP_GUID_FLOAT; + pdesc.TypeName = "Float"; + pdesc.DefaultSize = sizeof(float); + RegisterParameterType(&pdesc); + + // Int + pdesc.Guid = NHP_GUID_INT; + pdesc.TypeName = "Int"; + pdesc.DefaultSize = sizeof(int); + RegisterParameterType(&pdesc); + + // Bool + pdesc.Guid = NHP_GUID_BOOL; + pdesc.TypeName = "Bool"; + pdesc.DefaultSize = sizeof(bool); + RegisterParameterType(&pdesc); + + // String + pdesc.Guid = NHP_GUID_STRING; + pdesc.TypeName = "String"; + pdesc.DefaultSize = sizeof(char*); + RegisterParameterType(&pdesc); + + // Vector + pdesc.Guid = NHP_GUID_VECTOR; + pdesc.TypeName = "Vector"; + pdesc.DefaultSize = sizeof(float) * 3; + RegisterParameterType(&pdesc); + + return E_OK; +} + +NH_ERROR +NH_ParameterManager::RegisterParameterType(NH_ParameterTypeDesc *parameterType) { + if (!parameterType) + return E_FAIL; + + // Check if GUID is valid + if (!parameterType->Guid.IsValid()) + return E_FAIL; + + // Check if GUID already exists + if (m_ParameterGuids.find(parameterType->Guid) != m_ParameterGuids.end()) { + return E_OK; // Or an error for duplicate + } + + m_ParameterTypes.push_back(*parameterType); + int newIndex = m_ParameterTypes.size() - 1; + m_ParameterTypes.back().Index = newIndex; + m_ParameterGuids[parameterType->Guid] = newIndex; + + return E_OK; +} \ No newline at end of file diff --git a/applications/nodehub/core/ParameterManager.h b/applications/nodehub/core/ParameterManager.h new file mode 100644 index 0000000..5b351ce --- /dev/null +++ b/applications/nodehub/core/ParameterManager.h @@ -0,0 +1,26 @@ +#ifndef NH_PARAMETER_MANAGER_H +#define NH_PARAMETER_MANAGER_H + +#include "../commons.h" +#include "../enums.h" +#include "../types.h" +#include "./BaseManager.h" +#include "./Parameter.h" +#include +#include + +class NH_ParameterManager : public NH_BaseManager { +public: + NH_ParameterManager(NH_Context *context); + virtual ~NH_ParameterManager() = default; + + virtual NH_ERROR OnInit() override; + + NH_ERROR RegisterParameterType(NH_ParameterTypeDesc *parameterType); + +protected: + std::vector m_ParameterTypes; + std::map m_ParameterGuids; +}; + +#endif \ No newline at end of file diff --git a/applications/nodehub/core/ParameterOut.cpp b/applications/nodehub/core/ParameterOut.cpp new file mode 100644 index 0000000..bd0f1ad --- /dev/null +++ b/applications/nodehub/core/ParameterOut.cpp @@ -0,0 +1,39 @@ +#include "ParameterOut.h" + +NH_ERROR NH_ParameterOut::GetValue(void* buf, NH_BOOL update) { + return NH_Parameter::GetValue(buf, update); +} + +NH_ERROR NH_ParameterOut::SetValue(const void* buf, int size) { + return NH_Parameter::SetValue(buf, size); +} + +NH_ERROR NH_ParameterOut::CopyValue(NH_Parameter* param, NH_BOOL UpdateParam) { + return NH_Parameter::CopyValue(param, UpdateParam); +} + +void* NH_ParameterOut::GetReadDataPtr(NH_BOOL update) { + return NH_Parameter::GetReadDataPtr(update); +} + +int NH_ParameterOut::GetStringValue(NH_STRING Value, NH_BOOL update) { + return NH_Parameter::GetStringValue(Value, update); +} + +void NH_ParameterOut::DataChanged() {} + +NH_ERROR NH_ParameterOut::AddDestination(NH_Parameter* param, NH_BOOL CheckType) { + return E_NOTIMPL; +} + +void NH_ParameterOut::RemoveDestination(NH_Parameter* param) {} + +int NH_ParameterOut::GetDestinationCount() { + return 0; +} + +NH_Parameter* NH_ParameterOut::GetDestination(int pos) { + return nullptr; +} + +void NH_ParameterOut::RemoveAllDestinations() {} diff --git a/applications/nodehub/core/ParameterOut.h b/applications/nodehub/core/ParameterOut.h new file mode 100644 index 0000000..07e19e7 --- /dev/null +++ b/applications/nodehub/core/ParameterOut.h @@ -0,0 +1,79 @@ +#ifndef NH_PARAMETER_OUT_H +#define NH_PARAMETER_OUT_H + +#include "../commons.h" +#include "./Parameter.h" + +/************************************************************************** +Name: CKParameterOut + +Summary: Output parameter providing a value + +Remarks: + {Image:ParameterOut} + + + The type of the parameter defines the type of the data provided. These +types are maintained by the parameter manager. It defines the size of the buffer +to use, and also decides what can be plugged onto the output parameter. To have +the list and definition of predefined parameter types see CKParameterManager. + + + An output parameter may have destinations to which it pushes the data +each time it is changed. These destinations are other output parameters, which +for example provide their value out of the enclosing behavior, or local +parameters which provide values to other parts of the graph of sub-behaviors. +These destinations are managed using the AddDestination and related methods. +When the data of the output parameter changes, it pushes the new value down to +its destinations. + + + An output parameter will probably also be plugged into input +parameters. These input parameters will pull the value from the output parameter +when needed. + + + An output parameter usually knows how to write its data from and to a +string. This is useful for display and debugging purposes. When you define a new +type of parameter, you can specify the function that converts to and from +strings. + + + An output parameter can also have an edition window. When you define a +new type of parameter, you can specify the function that will create the edition +window when needed by the interface. + + + A NH_ParameterOut is created with CKBehavior::CreateOutputParameter or +CKContext::CreateCKParameterOut. + + + The class id of NH_ParameterOut is NHCID_PARAMETEROUT. + + +See also: NH_ParameterIn, NH_ParameterOperation +**********************************************************************************/ + +class NH_ParameterOut : public NH_Parameter { +public: + NH_ParameterOut(int id, NH_CSTRING name) : NH_Parameter(id, name) {} + virtual ~NH_ParameterOut() = default; + + virtual NH_CLASS_ID GetClassID() override { return NHCID_PARAMETEROUT; } + + //-------------------------------------------- + // Value + + virtual NH_ERROR GetValue(void *buf, NH_BOOL update = true); + virtual NH_ERROR SetValue(const void *buf, int size = 0); + virtual NH_ERROR CopyValue(NH_Parameter *param, NH_BOOL UpdateParam = true); + virtual void *GetReadDataPtr(NH_BOOL update = true); + virtual int GetStringValue(NH_STRING Value, NH_BOOL update = true); + + // void CheckClass(CKParameterTypeDesc* iType); + + //-------------------------------------------- + // Destinations + + void DataChanged(); + NH_ERROR AddDestination(NH_Parameter *param, NH_BOOL CheckType = true); + void RemoveDestination(NH_Parameter *param); + int GetDestinationCount(); + NH_Parameter *GetDestination(int pos); + void RemoveAllDestinations(); +}; + +#endif \ No newline at end of file diff --git a/applications/nodehub/core/XClassArray.h b/applications/nodehub/core/XClassArray.h new file mode 100644 index 0000000..267db9b --- /dev/null +++ b/applications/nodehub/core/XClassArray.h @@ -0,0 +1,574 @@ +/*************************************************************************/ +/* File : XClassArray.h */ +/* Author : Aymeric Bard */ +/* */ +/* Virtools SDK */ +/* Copyright (c) Virtools 2000, All Rights Reserved. */ +/*************************************************************************/ +#ifndef _XCLASSARRAY_H_ +#define _XCLASSARRAY_H_ "$Id:$" + +#include "XUtil.h" + +#ifdef _WIN32 +#pragma warning(disable : 4786) +#endif + +/************************************************ +{filename:XClassArray} +Name: XClassArray + +Summary: Class representation of an array. + +Remarks: + This array is designed to hold structure or class +which have something specific to do on the construction, +deletion or recopy, like allocating/destroying pointers. + + + +See Also : XArray, XSArray +************************************************/ +template +class XClassArray +{ +public: + typedef T* Iterator; + + /************************************************ + Summary: Constructors. + + Input Arguments: + ss: Default number of reserved elements. + a: An array to copy from. + + ************************************************/ + XClassArray(int ss=0) + { + // Allocated + if(ss>0) { + m_Begin = Allocate(ss); + m_End = m_Begin; + m_AllocatedEnd = m_Begin+ss; + } else { + m_AllocatedEnd = 0; + m_Begin = m_End = 0; + } + } + + XClassArray(const XClassArray& a) + { + // the resize + int size = a.Size(); + m_Begin = Allocate(size); + m_End = m_Begin+size; + m_AllocatedEnd = m_End; + // The copy + XCopy(m_Begin,a.m_Begin,a.m_End); + } + + /************************************************ + Summary: Destructor. + + Remarks: + Release the elements contained in the array. If + you were storing pointers, you need first to iterate + on the array and call delete on each pointer. + ************************************************/ + ~XClassArray() + { + Clear(); + } + + /************************************************ + Summary: Affectation operator. + + Remarks: + The content of the array is enterely overwritten + by the given array. + ************************************************/ + XClassArray& operator = (const XClassArray& a) + { + if(this != &a) { + if (Allocated() >= a.Size()) { // No need to allocate + // The copy + XCopy(m_Begin,a.m_Begin,a.m_End); + m_End = m_Begin + a.Size(); + } else { + Free(); + // the resize + int size = a.Size(); + m_Begin = Allocate(size); + m_End = m_Begin+size; + m_AllocatedEnd = m_End; + // The copy + XCopy(m_Begin,a.m_Begin,a.m_End); + } + } + + return *this; + } + + /************************************************ + Summary: Removes all the elements from an array. + + Remarks: + There is no more space reserved after this call. + ************************************************/ + void Clear() + { + Free(); + m_Begin = 0; + m_End = 0; + m_AllocatedEnd = 0; + } + + /************************************************ + Summary: Reserves n elements for an array. + + Remarks: + The elements beyond the reserved limit are + discarded. + ************************************************/ + void Reserve(int size) + { + // allocation of new size + T* newdata = Allocate(size); + + // Recopy of old elements + T* last = XMin(m_Begin+size,m_End); + XCopy(newdata,m_Begin,last); + + // new Pointers + Free(); + m_End = newdata+(last-m_Begin); + m_Begin = newdata; + m_AllocatedEnd = newdata+size; + } + + /************************************************ + Summary: Resizes th elements numbers of an array. + + Remarks: + If the size is greater than the reserved size, + the array is reallocated at the exact needed size. + If not, there is no reallocation at all. Resize(0) + is faster than Clear() if you know you will probably + push some more elements after. + ************************************************/ + void Resize(int size) + { + // we check if the array has enough capacity + int oldsize = (m_AllocatedEnd-m_Begin); + // If not, we allocate extra data + if(size > oldsize) Reserve(size); + // We set the end cursor + m_End = m_Begin+size; + } + + /************************************************ + Summary: Inserts an element at the end of an array. + + Input Arguments: + o: object to insert. + ************************************************/ + void PushBack(const T& o) + { + XInsert(m_End,o); + } + + /************************************************ + Summary: Expands an array of e elements. + + Input Arguments: + e: size to expand. + ************************************************/ + void Expand(int e = 1) + { + // we check if the array has enough capacity + + // If not, we allocate extra data + while (Size()+e > Allocated()) { + Reserve(Allocated()?Allocated()*2:2); + } + // We set the end cursor + m_End += e; + } + + /************************************************ + Summary: Inserts an element at the start of an array. + + Input Arguments: + o: object to insert. + ************************************************/ + void PushFront(const T& o) + { + XInsert(m_Begin,o); + } + + /************************************************ + Summary: Inserts an element before another one. + + Input Arguments: + i: iterator on the element to insert before. + pos: position to insert the object + o: object to insert. + + Remarks: + The element to insert before is given as + an iterator on it, i.e. a pointer on it in + this case. + ************************************************/ + void Insert(T* i, const T& o) + { + // TODO : s'assurer que i est dans les limites... + if(im_End) return; + + // The Call + XInsert(i,o); + } + void Insert(int pos, const T& o) + { + Insert(m_Begin+pos,o); + } + + /************************************************ + Summary: Removes the last element of an array. + ************************************************/ + void PopBack() + { + // we remove the last element only if it exists + if(m_End > m_Begin) XRemove(m_End-1); + } + + /************************************************ + Summary: Removes the first element of an array. + ************************************************/ + void PopFront() + { + // we remove the first element only if it exists + if(m_Begin != m_End) XRemove(m_Begin); + } + + /************************************************ + Summary: Removes an element. + + Input Arguments: + i: iterator on the element to remove. + pos: position of the object to remove. + + Return Value: an iterator on the next + element after the element removed (to go on with + an iteration). + + Remarks: + The elements are given by iterators on them, + i.e. pointer on them in this case. + ************************************************/ + T* Remove(T* i) + { + // we ensure i is in boundary... + if(i=m_End) return 0; + + // the Call + return XRemove(i); + } + + + T* RemoveAt(int pos) + { + // we ensure i is in boundary... + if (pos >= Size()) return NULL; + + // the Call + return XRemove(m_Begin+pos); + } + + void FastRemove(const T& o) + { + FastRemove(Find(o)); + } + + void FastRemove(const Iterator& iT) + { + // we ensure i is in boundary... + if(iT=m_End) + return; + + m_End--; + if (iT < m_End) + *iT = *m_End; + } + + /************************************************ + Summary: Access to an array element. + + Input Arguments: + i: index of the element to access. + + Return Value: a reference on the object accessed. + + Remarks: + No test are provided on i. + ************************************************/ + T& operator [](int i) const + { + XASSERT(i>=0 && i= (unsigned int)Size()) return m_End; + return m_Begin+i; + } + + /************************************************ + Summary: Swaps two items in array. + + Input Arguments: + pos1: position of first item to swap + pos2: position of second item to swap. + ************************************************/ + void Swap(int pos1,int pos2) + { + char buffer[sizeof(T)]; + memcpy(buffer,m_Begin+pos1,sizeof(T)); + memcpy(m_Begin+pos1,m_Begin+pos2,sizeof(T)); + memcpy(m_Begin+pos2,buffer,sizeof(T)); + } + + /************************************************ + Summary: Swaps two arrays. + + Input Arguments: + o: second array to swap. + ************************************************/ + void Swap(XClassArray& a) + { + XSwap(m_Begin,a.m_Begin); + XSwap(m_End,a.m_End); + XSwap(m_AllocatedEnd,a.m_AllocatedEnd); + } + + /************************************************ + Summary: Returns the last element of an array. + + Remarks: + No test are provided to see if there is an + element. + ************************************************/ + T& Back() {return *(End()-1);} + + const T& Back() const {return *(End()-1);} + + /************************************************ + Summary: Returns an iterator on the first element. + + Example: + Typically, an algorithm iterating on an array + looks like: + + for(T* t = a.Begin(); t != a.End(); ++t) { + // do something with *t + } + + ************************************************/ + T* Begin() const {return m_Begin;} + + /************************************************ + Summary: Returns an iterator after the last element. + ************************************************/ + T* End() const {return m_End;} + + /************************************************ + Summary: Returns the elements number. + ************************************************/ + int Size() const {return m_End-m_Begin;} + + /************************************************ + Summary: Returns the elements allocated. + ************************************************/ + int Allocated() const {return m_AllocatedEnd-m_Begin;} + + /************************************************ + Summary: Returns the occupied size in memory in bytes + + Parameters: + addstatic: TRUE if you want to add the size occupied + by the class itself. + ************************************************/ + int GetMemoryOccupation(XBOOL addstatic=FALSE) const { + return Allocated()*sizeof(T)+(addstatic?sizeof(*this):0); + } + + /************************************************ + Summary: Finds an element. + + Input Arguments: + o: element to find. + + Return Value: a pointer on the first object found + or End() if the object is not found. + ************************************************/ + T* Find(const T& o) const + { + // If the array is empty + if(!(m_End - m_Begin)) return m_End; + T* t = m_Begin; + while(t < m_End && *t != o) + ++t; + + return t; + } + + /************************************************ + Summary: Returns the position of an element. + + Input Arguments: + o: element to find. + + Return Value: position or -1 if not found. + ************************************************/ + int GetPosition(const T& o) const + { + T* t = Find(o); + // If the element is not found + if(t == m_End) return -1; + // else return the position + return t-m_Begin; + } + + + static + int XCompare(const void *elem1, const void *elem2 ) + { + return *(T*)elem1 - *(T*)elem2; + } + + /************************************************ + Summary: Sorts an array with a quick sort. + + Input Arguments: + compare: The function comparing two elements. + + Remarks: + Two sorts algorithm are available : BubbleSort + and (quick)Sort. + ************************************************/ + void Sort( VxSortFunc Fct = XCompare) + { + qsort(m_Begin,Size(),sizeof(T),Fct); + } + +protected: + /// + // Methods + + + void XCopy(T* dest, T* start, T* end) + { + while(start != end) { + *dest = *start; + start++; + dest++; + } + } + + + void XMove(T* dest, T* start, T* end) + { + if (dest>start) + { + dest += end-start; + while(start != end) { + --dest; + --end; + *dest = *end; + } + } else XCopy(dest,start,end); + } + + void XInsert(T* i, const T& o) + { + // Test For Reallocation + if(m_End+1 > m_AllocatedEnd) { + int newsize = (m_AllocatedEnd-m_Begin)*2;//+m_AllocationSize; + if(!newsize) newsize = 1; + T* newdata = Allocate(newsize); + + // copy before insertion point + XCopy(newdata,m_Begin,i); + + // copy the new element + T* insertionpoint = newdata+(i-m_Begin); + *(insertionpoint) = o; + + // copy after insertion point + XCopy(insertionpoint+1,i,m_End); + + // New Pointers + m_End = newdata+(m_End-m_Begin); + Free(); + m_Begin = newdata; + m_AllocatedEnd = newdata+newsize; + } else { + // copy after insertion point + XMove(i+1,i,m_End); + // copy the new element + *i = o; + } + m_End++; + } + + + T* XRemove(T* i) + { + // copy after insertion point + XMove(i,i+1,m_End); + m_End--; + return i; + } + + /// + // Allocation and deallocation methods : to be override for alignement purposes + + + T* Allocate(int size) + { + if(size) return new T[size]; + else return 0; + } + + + void Free() + { + delete [] m_Begin; + } + + /// + // Members + + + T* m_Begin; + + T* m_End; + + T* m_AllocatedEnd; + +}; + + +#endif diff --git a/applications/nodehub/core/XPriorityQueue.h b/applications/nodehub/core/XPriorityQueue.h new file mode 100644 index 0000000..d891325 --- /dev/null +++ b/applications/nodehub/core/XPriorityQueue.h @@ -0,0 +1,177 @@ + +#ifndef XPRIORITYQUEUE_H +#define XPRIORITYQUEUE_H + +template + +struct XPriority +{ + int operator()(const T& iT) const { + return iT; + } +}; + +/************************************************ +Name: XPriorityQueue + +Summary: Class representation of a priority queue. + +Template Parameters: + T : type of object to store into the queue + PF : priority function, which is use to tell the priority (an int) + of a T object. + +Remarks: + This container is used to fastly pop an object, sorted by a criterion, called here the + priority of the object. Insertion and Pop are in O(log(n)) and the objects are stored + flat, in an array, avoiding many small allocations. + You can not store objects with ctor and dtor in it because they won't be called. + + + +See Also : XArray, XList +************************************************/ +template > +class XPriorityQueue +{ +public: + /************************************************ + Summary: Constructors. + + Input Arguments: + iBaseNumber: Default number of reserved elements. + ************************************************/ + XPriorityQueue(int iBaseNumber = 0):m_Cells(iBaseNumber) {} + + /************************************************ + Summary: Removes all the elements from the queue. + + Remarks: + The memory allocated is not freed by this call. + ************************************************/ + void Clear() + { + if (m_Cells.Size()) { // already allocated : sets to the beginning + m_Cells.Resize(1); + } + + } + + void Insert(const T& iT) + { + if (!m_Cells.Size()) { // first insertion : init + m_Cells.Reserve(2); + m_Cells.Resize(1); // the first node is the root + } + + int i = m_Cells.Size(); + m_Cells.PushBack(iT); + + T* cells = m_Cells.Begin(); + + PF prio; + int insertPrio = prio(iT); + while (i > 1 && prio(cells[i / 2]) < insertPrio) { + cells[i] = cells[i / 2]; + i /= 2; + } + cells[i] = iT; + } + + /************************************************ + Summary: Removes the higher priority element of + the queue. + + Input Arguments: + oT: pointer to the T object that will be filled + with the higher priority element. + The pointer need to be valid. + + Return Value: TRUE if an object is popped. + ************************************************/ + XBOOL + Pop(T* oT) + { + if (m_Cells.Size() <= 1) + return 0; + + { + T* cells = m_Cells.Begin(); + + *oT = cells[1]; + } + + T tmp = m_Cells.PopBack(); + int size = m_Cells.Size(); + if (size == 1) // was the last one + return 1; + + int i = 1; + int j; + + + PF prio; + int lastPriority = prio(tmp); + + T* cells = m_Cells.Begin(); + + while (i <= size / 2) { + j = 2 * i; + if (j < size && + prio(cells[j]) < prio(cells[j + 1])) { + j++; + } + if (prio(cells[j]) <= lastPriority) { + break; + } + cells[i] = cells[j]; + i = j; + } + + cells[i] = tmp; + return 1; + } + + /************************************************ + Summary: Peeks the higher priority element of + the queue. + + Input Arguments: + oT: pointer to the T object that will be filled + with the higher priority element. + The pointer need to be valid. + + Return Value: TRUE if an object is popped. + ************************************************/ + XBOOL + Peek(T* oT) const + { + if (m_Cells.Size() <= 1) + return 0; + + T* cells = m_Cells.Begin(); + + *oT = cells[1]; + return 1; + } + + + /************************************************ + Summary: Returns the occupied size in memory in bytes + + Parameters: + addstatic: TRUE if you want to add the size occupied + by the class itself. + ************************************************/ + int GetMemoryOccupation(XBOOL iAddStatic = FALSE) const + { + return m_Cells.GetMemoryOccupation(iAddStatic); + } + + +protected: + // array of queue cells + XArray m_Cells; +}; + +#endif \ No newline at end of file diff --git a/applications/nodehub/core/XSArray.h b/applications/nodehub/core/XSArray.h new file mode 100644 index 0000000..43a0240 --- /dev/null +++ b/applications/nodehub/core/XSArray.h @@ -0,0 +1,490 @@ +/*************************************************************************/ +/* File : XSArray.h */ +/* Author : Aymeric Bard */ +/* */ +/* Virtools SDK */ +/* Copyright (c) Virtools 2000, All Rights Reserved. */ +/*************************************************************************/ + +#ifndef _XSARRAY_H_ +#define _XSARRAY_H_ + +#include "XUtil.h" + +#ifdef DOCJET_DUMMY +#else + +#ifdef PSP + #define USE_OPT_ARRAY 0 +#else + #define USE_OPT_ARRAY 0 +#endif + +#endif + + +#if USE_OPT_ARRAY + #include "XSArrayOpt.h" +#else + +/************************************************ +Name: XSArray + +Summary: Class representation of an array. + +Remarks: + This array behaves exactly like the XArray, +exept that its size is exactly the number it contains, +so it is more slow for adding and removing elements, +but it occupies less memory. + + + +See Also : XClassArray, XArray +************************************************/ +template +class XSArray +{ +public: + + XSArray() + { + // Init + m_Begin = m_End = 0; + } + + + XSArray(const XSArray& a) + { + // the resize + int size = a.Size(); + m_Begin = Allocate(size); + m_End = m_Begin+size; + // The copy + XCopy(m_Begin,a.m_Begin,a.m_End); + } + + + ~XSArray() + { + Clear(); + } + + + XSArray& operator = (const XSArray& a) + { + if(this != &a) { + Free(); + // the resize + int size = a.Size(); + m_Begin = Allocate(size); + m_End = m_Begin+size; + // The copy + XCopy(m_Begin,a.m_Begin,a.m_End); + } + + return *this; + } + + + XSArray& operator += (const XSArray& a) + { + int size = a.Size(); + if (size) { + int oldsize = Size(); + T* temp = Allocate(oldsize+size); + + // we recopy the old array + XCopy(temp,m_Begin,m_End); + m_End = temp+oldsize; + + // we copy the given array + XCopy(m_End,a.m_Begin,a.m_End); + m_End += size; + + // we free the old memory + Free(); + + // we set the new pointer + m_Begin = temp; + } + + return *this; + } + + + XSArray& operator -= (const XSArray& a) + { + int size = a.Size(); + if (size) { + int oldsize = Size(); + if (oldsize) { + T* newarray = Allocate(oldsize); + T* temp = newarray; + + for(T* t = m_Begin; t != m_End; ++t) { + // we search for the element in the other array + if(a.Find(*t) == a.m_End) { + // the element is not in the other array, we copy it to the newone + *temp = *t; + ++temp; + } + } + + // we free the memory + Free(); + // the resize + int size = temp - newarray; + m_Begin = Allocate(size); + m_End = m_Begin+size; + // The copy + XCopy(m_Begin,newarray,temp); + } + } + + return *this; + } + + + void Clear() + { + Free(); + m_Begin = 0; + m_End = 0; + } + + + void Fill(const T& o) + { + for(T* t = m_Begin; t != m_End; ++t) + *t=o; + } + + + void Resize(int size) + { + // No change ? + if (size == Size()) return; + + // allocation of new size + T* newdata = Allocate(size); + + // Recopy of old elements + T* last = XMin(m_Begin+size,m_End); + XCopy(newdata,m_Begin,last); + + // new Pointers + Free(); + m_Begin = newdata; + m_End = newdata+size; + } + + + void PushBack(const T& o) + { + XInsert(m_End,o); + } + + + void PushFront(const T& o) + { + XInsert(m_Begin,o); + } + + + void Insert(T* i, const T& o) + { + // TODO : s'assurer que i est dans les limites... + if(im_End) return; + + // The Call + XInsert(i,o); + } + + + void Insert(int pos, const T& o) + { + Insert(m_Begin+pos,o); + } + + + void Move(T* i, T* n) + { + // TODO : s'assurer que i est dans les limites... + if(im_End) return; + if(nm_End) return; + + // The Call + int insertpos = i - m_Begin; + if (n < i) --insertpos; + + T tn = *n; + XRemove(n); + Insert(insertpos,tn); + } + + + void PopBack() + { + // we remove the last element only if it exists + if(m_End > m_Begin) XRemove(m_End-1); + } + + + void PopFront() + { + // we remove the first element only if it exists + if(m_Begin != m_End) XRemove(m_Begin); + } + + + T* Remove(T* i) + { + // we ensure i is in boundary... + if(i=m_End) return 0; + + // the Call + return XRemove(i); + } + + + XBOOL RemoveAt(unsigned int pos,T& old) + { + T* t = m_Begin+pos; + // we ensure i is in boundary... + if(t >= m_End) return 0; + old = *t; // we keep the old value + // the removal + XRemove(t); + return TRUE; // really removed + } + + + T* RemoveAt(int pos) + { + // we ensure i is in boundary... + if((pos < 0) || (m_Begin+pos >= m_End)) return 0; + + // the Call + return XRemove(m_Begin+pos); + } + + + int Remove(const T& o) + { + for(T* t = m_Begin; t != m_End; ++t) { + if(*t == o) { + XRemove(t); + return 1; + } + } + return 0; + } + + + T& operator [](unsigned int i) const + { + return *(m_Begin+i); + } + + + T* At(unsigned int i) const + { + if (i >= (unsigned int) Size()) return m_End; + return m_Begin+i; + } + + + T* Find(const T& o) const + { + for(T* t = m_Begin; t != m_End; ++t) { + if(*t == o) return t; + } + return m_End; + } + + + XBOOL IsHere(const T& o) const + { + T* t = m_Begin; + while(t < m_End && *t != o) ++t; + + return (t != m_End); + } + + + int GetPosition(const T& o) const + { + for(T* t = m_Begin; t != m_End; ++t) { + if(*t == o) return (t-m_Begin); + } + return -1; + } + + /************************************************ + Summary: Swaps two items in array. + + Input Arguments: + pos1: position of first item to swap + pos2: position of second item to swap. + ************************************************/ + void Swap(int pos1,int pos2) + { + char buffer[sizeof(T)]; + memcpy(buffer,m_Begin+pos1,sizeof(T)); + memcpy(m_Begin+pos1,m_Begin+pos2,sizeof(T)); + memcpy(m_Begin+pos2,buffer,sizeof(T)); + } + + + void Swap(XSArray& a) + { + XSwap(m_Begin,a.m_Begin); + XSwap(m_End,a.m_End); + } + + + static + int XCompare(const void *elem1, const void *elem2 ) + { + return *(T*)elem1 < *(T*)elem2; + } + + + // compare func should return : + // < 0 elem1 less than elem2 + // 0 elem1 equivalent to elem2 + // > 0 elem1 greater than elem2 + // elem1 & elem2 T* + void Sort( VxSortFunc compare = XCompare ) + { + if (Size() > 1) qsort(m_Begin,Size(),sizeof(T),compare); + } + + + void BubbleSort( VxSortFunc compare = XCompare) + { + if (!compare) return; + if ((m_End-m_Begin)<=1) return; + + + BOOL Noswap=TRUE; + for (T* it1=m_Begin+1;it1=it1;it2--) { + T* t2= it2-1; + if (compare(it2,t2) < 0) { + XSwap(*it2,*t2); + Noswap=FALSE; + } + } + if (Noswap) break; + Noswap=TRUE; + } + } + + + T* Begin() const {return m_Begin;} + + + T* End() const {return m_End;} + + + int Size() const {return m_End-m_Begin;} + + + int GetMemoryOccupation(XBOOL addstatic=FALSE) const {return Size()*sizeof(T)+addstatic?sizeof(*this):0;} + +protected: + /// + // Methods + + + void XCopy(T* dest, T* start, T* end) + { + int size = ((XBYTE*)end - (XBYTE*)start); + if(size) + memcpy(dest,start,size); + } + + + void XMove(T* dest, T* start, T* end) + { + int size = ((XBYTE*)end - (XBYTE*)start); + if(size) + memmove(dest,start,size); + } + + + void XInsert(T* i, const T& o) + { + // Reallocation + int newsize = (m_End-m_Begin)+1; + T* newdata = Allocate(newsize); + + // copy before insertion point + XCopy(newdata,m_Begin,i); + + // copy the new element + T* insertionpoint = newdata+(i-m_Begin); + *(insertionpoint) = o; + + // copy after insertion point + XCopy(insertionpoint+1,i,m_End); + + // New Pointers + m_End = newdata+newsize; + Free(); + m_Begin = newdata; + } + + + T* XRemove(T* i) + { + // Reallocation + int newsize = (m_End-m_Begin)-1; + T* newdata = Allocate(newsize); + + // copy before insertion point + XCopy(newdata,m_Begin,i); + + // copy after insertion point + T* deletionpoint = newdata+(i-m_Begin); + XCopy(deletionpoint,i+1,m_End); + i = deletionpoint; + + // New Pointers + m_End = newdata+newsize; + Free(); + m_Begin = newdata; + + return i; + } + + /// + // Allocation and deallocation methods : to be override for alignement purposes + + + T* Allocate(int size) + { + if(size) return (T*)VxNew(sizeof(T) * size); + else return 0; + } + + + void Free() + { + VxDelete(m_Begin); + } + + + + /// + // Members + + + T* m_Begin; + + T* m_End; +}; +#endif // USE_OPT_ARRAY +#endif diff --git a/applications/nodehub/core/XSHashTable.h b/applications/nodehub/core/XSHashTable.h new file mode 100644 index 0000000..374a394 --- /dev/null +++ b/applications/nodehub/core/XSHashTable.h @@ -0,0 +1,787 @@ +/*************************************************************************/ +/* File : XSHashTable.h */ +/* Author : Aymeric Bard */ +/* */ +/* Virtools SDK */ +/* Copyright (c) Virtools 2000, All Rights Reserved. */ +/*************************************************************************/ + + +#ifndef _XSHashTable_H_ +#define _XSHashTable_H_ + +#include "XArray.h" +#include "XHashFun.h" + + +template +class XSHashTable; + + +#define STATUS_FREE 0 + +#define STATUS_OCCUPIED 1 + +#define STATUS_DELETED 2 + + +template +class XSHashTableEntry +{ + typedef XSHashTableEntry* pEntry; +public: + + XSHashTableEntry():m_Status(STATUS_FREE) {} + XSHashTableEntry(const XSHashTableEntry& e) : m_Key(e.m_Key),m_Data(e.m_Data),m_Status(STATUS_OCCUPIED) {} + ~XSHashTableEntry() {} + + void Set(const K& key, const T& data) + { + m_Key = key; + m_Data = data; + m_Status = STATUS_OCCUPIED; + } + + K m_Key; + T m_Data; + int m_Status; +}; + +/************************************************ +Summary: Iterator on a hash table. + +Remarks: This iterator is the only way to iterate on +elements in a hash table. The iteration will be in no +specific order, not in the insertion order. Here is an example +of how to use it: + +Example: + + XSHashTableIt it = hashtable.Begin(); + while (it != hashtable.End()) { + // access to the key + it.GetKey(); + + // access to the element + *it; + + // next element + ++it; + } + + +************************************************/ +template , class Eq = XEqual > +class XSHashTableIt +{ + typedef XSHashTableEntry* pEntry; + typedef XSHashTableIt tIterator; + typedef XSHashTable* tTable; + friend class XSHashTable; +public: + /************************************************ + Summary: Default constructor of the iterator. + ************************************************/ + XSHashTableIt():m_Node(0),m_Table(0){} + /************************************************ + Summary: Copy constructor of the iterator. + ************************************************/ + XSHashTableIt(const tIterator& n):m_Node(n.m_Node),m_Table(n.m_Table){} + + /************************************************ + Summary: Operator Equal of the iterator. + ************************************************/ + int operator==(const tIterator& it) const { return m_Node == it.m_Node; } + + /************************************************ + Summary: Operator Equal of the iterator. + ************************************************/ + int operator!=(const tIterator& it) const { return m_Node != it.m_Node; } + + /************************************************ + Summary: Returns a constant reference on the data + pointed by the iterator. + + Remarks: + The returned reference is constant, so you can't + modify its value. Use the other * operator for this + purpose. + ************************************************/ + const T& operator*() const { return (*m_Node).m_Data; } + + /************************************************ + Summary: Returns a reference on the data pointed + by the iterator. + + Remarks: + The returned reference is not constant, so you + can modify its value. + ************************************************/ + T& operator*() { return (*m_Node).m_Data; } + + /************************************************ + Summary: Returns a pointer on a T object. + ************************************************/ + operator const T*() const { return &(m_Node->m_Data); } + + /************************************************ + Summary: Returns a const reference on the key of + the pointed entry. + ************************************************/ + const K& GetKey() const {return m_Node->m_Key;} + + /************************************************ + Summary: Jumps to next entry in the hashtable. + ************************************************/ + tIterator& operator++() { // Prefixe + ++m_Node; + pEntry end = m_Table->m_Table.End(); + while (m_Node != end) { // we're not at the end of the list yet + if (m_Node->m_Status == STATUS_OCCUPIED) break; + ++m_Node; + } + return *this; + } + + /************************************************ + Summary: Jumps to next entry in the hashtable. + ************************************************/ + tIterator operator++(int) { + tIterator tmp = *this; + ++*this; + return tmp; + } + +protected: + + XSHashTableIt(pEntry n,tTable t):m_Node(n),m_Table(t){} + // The Current Node {secret} + pEntry m_Node; + // The Current Table {secret} + tTable m_Table; +}; + +/************************************************ +Summary: Constant iterator on a hash table. + +Remarks: This iterator is the only way to iterate on +elements in a constant hash table. The iteration will be in no +specific order, not in the insertion order. Here is an example +of how to use it: + +Example: + + void MyClass::MyMethod() const + { + XSHashTableConstIt it = m_Hashtable.Begin(); + while (it != m_Hashtable.End()) { + // access to the key + it.GetKey(); + + // access to the element + *it; + + // next element + ++it; + } + } + + +************************************************/ +template , class Eq = XEqual > +class XSHashTableConstIt +{ + typedef XSHashTableEntry* pEntry; + typedef XSHashTableConstIt tConstIterator; + typedef XSHashTableconst* tConstTable; + friend class XSHashTable; +public: + /************************************************ + Summary: Default constructor of the iterator. + ************************************************/ + XSHashTableConstIt():m_Node(0),m_Table(0){} + /************************************************ + Summary: Copy constructor of the iterator. + ************************************************/ + XSHashTableConstIt(const tConstIterator& n):m_Node(n.m_Node),m_Table(n.m_Table){} + + /************************************************ + Summary: Operator Equal of the iterator. + ************************************************/ + int operator==(const tConstIterator& it) const { return m_Node == it.m_Node; } + + /************************************************ + Summary: Operator Equal of the iterator. + ************************************************/ + int operator!=(const tConstIterator& it) const { return m_Node != it.m_Node; } + + /************************************************ + Summary: Returns a constant reference on the data + pointed by the iterator. + + Remarks: + The returned reference is constant, so you can't + modify its value. Use the other * operator for this + purpose. + ************************************************/ + const T& operator*() const { return (*m_Node).m_Data; } + + /************************************************ + Summary: Returns a pointer on a T object. + ************************************************/ + operator const T*() const { return &(m_Node->m_Data); } + + /************************************************ + Summary: Returns a const reference on the key of + the pointed entry. + ************************************************/ + const K& GetKey() const {return m_Node->m_Key;} + + /************************************************ + Summary: Jumps to next entry in the hashtable. + ************************************************/ + tConstIterator& operator++() { // Prefixe + ++m_Node; + pEntry end = m_Table->m_Table.End(); + while (m_Node != end) { // we're not at the end of the list yet + if (m_Node->m_Status == STATUS_OCCUPIED) break; + ++m_Node; + } + return *this; + } + + /************************************************ + Summary: Jumps to next entry in the hashtable. + ************************************************/ + tConstIterator operator++(int) { + tConstIterator tmp = *this; + ++*this; + return tmp; + } + +protected: + + XSHashTableConstIt(pEntry n,tConstTable t):m_Node(n),m_Table(t){} + // The Current Node {secret} + pEntry m_Node; + // The Current Table {secret} + tConstTable m_Table; +}; + +/************************************************ +Summary: Struct containing an iterator on an object +inserted and a BOOL determining if it were really +inserted (TRUE) or already there (FALSE). + + +************************************************/ +template , class Eq = XEqual > +class XSHashTablePair +{ + public: + XSHashTablePair(XSHashTableIt it,int n) : m_Iterator(it),m_New(n) {}; + + XSHashTableIt m_Iterator; + BOOL m_New; +}; + +/************************************************ +Summary: Class representation of an Hash Table +container. + +Remarks: + T is the type of element to insert + K is the type of the key + H is the hash function to hash the key + + Several hash functions for basic types are +already defined in XHashFun.h + + This implementation of the hash table uses +Linked List in each bucket for element hashed to +the same index, so there are memory allocation +for each insertion. For a static implementation +without dynamic allocation, look at XSHashTable. + + There is a m_LoadFactor member which allow the +user to decide at which occupation the hash table +must be extended and rehashed. + + +************************************************/ +template , class Eq = XEqual > +class XSHashTable +{ + // Types + typedef XSHashTable tTable; + typedef XSHashTableEntry tEntry; + typedef tEntry* pEntry; + typedef XSHashTableIt tIterator; + typedef XSHashTableConstIt tConstIterator; + typedef XSHashTablePair tPair; + // Friendship + friend class XSHashTableIt; + friend class XSHashTableConstIt; +public: + typedef XSHashTableIt Iterator; + typedef XSHashTableConstIt ConstIterator; + + /************************************************ + Summary: Constructors. + + Input Arguments: + initialsize: The default number of buckets + (should be a power of 2, otherwise will be + converted.) + l: Load Factor (see Class Description). + a: hash table to copy. + + ************************************************/ + XSHashTable(int initialsize = 8,float l = 0.75f) + { + int dec = -1; + while (initialsize) { initialsize>>=1; dec++; } + if (dec > -1) initialsize = 1<= m_Threshold) { // Yes + Rehash(m_Table.Size()*2); + return InsertUnique(key,o); + } else { // No + m_Table[index].Set(key,o); + return tIterator(&m_Table[index],this); + } + } + + /************************************************ + Summary: Removes an element. + + Input Arguments: + key: key of the element to remove. + it: iterator on the object to remove. + + Return Value: iterator on the lement next to + the one just removed. + + ************************************************/ + void Remove(const K& key) + { + int index = XFindPos( key ); + if (m_Table[index].m_Status == STATUS_OCCUPIED) { + m_Table[index].m_Status = STATUS_DELETED; + --m_Count; + } + } + + tIterator Remove(const tIterator& it) + { + // may be not necessary + pEntry e = it.m_Node; + if (e == m_Table.End()) return it; + + if (e->m_Status == STATUS_OCCUPIED) { + e->m_Status = STATUS_DELETED; + --m_Count; + } + + ++e; + while (e != m_Table.End()) { // we're not at the end of the list yet + if (e->m_Status == STATUS_OCCUPIED) break; + ++e; + } + + return tIterator(e,this); + } + + /************************************************ + Summary: Access to an hash table element. + + Input Arguments: + key: key of the element to access. + + Return Value: a reference of the element found. + + Remarks: + If no element correspond to the key, an exception. + ************************************************/ + T& operator [] (const K& key) + { + // Insert x as active + int index = XFindPos( key ); + + if (m_Table[index].m_Status != STATUS_OCCUPIED) { + + // If the element was deleted, we remove an element + if ((m_Table[index].m_Status != STATUS_DELETED)) { + ++m_Occupation; + ++m_Count; + } else { + ++m_Count; + } + m_Table[index].m_Status = STATUS_OCCUPIED; + m_Table[index].m_Key = key; + } + + // Test the rehash need + if( m_Occupation < m_Threshold ) return m_Table[index].m_Data; + + Rehash(m_Table.Size()*2); + return m_Table[XFindPos( key )].m_Data; + } + + /************************************************ + Summary: Access to an hash table element. + + Input Arguments: + key: key of the element to access. + + Return Value: an iterator of the element found. End() + if not found. + + ************************************************/ + tIterator Find(const K& key) const + { + return tIterator(XFindIndex(key),this); + } + + /************************************************ + Summary: Access to an hash table element. + + Input Arguments: + key: key of the element to access. + + Return Value: a pointer on the element found. NULL + if not found. + + ************************************************/ + T *FindPtr(const K& key) const + { + pEntry e = XFindIndex(key); + if (e) return &e->m_Data; + else return 0; + } + + /************************************************ + Summary: search for an hash table element. + + Input Arguments: + key: key of the element to access. + value: value to receive the element found value. + + Return Value: TRUE if the key was found, FALSE + otherwise.. + + ************************************************/ + BOOL LookUp(const K& key,T& value) const + { + pEntry e = XFindIndex(key); + if (e) { + value = e->m_Data; + return TRUE; + } else + return FALSE; + } + + /************************************************ + Summary: test for the presence of a key. + + Input Arguments: + key: key of the element to access. + + Return Value: TRUE if the key was found, FALSE + otherwise.. + + ************************************************/ + int IsHere(const K& key) const + { + return (int)XFindIndex(key); + } + + /************************************************ + Summary: Returns an iterator on the first element. + + Example: + Typically, an algorithm iterating on an hash table + looks like: + + XSHashTableIt it = h.Begin(); + XSHashTableIt itend = h.End(); + + for(; it != itend; ++it) { + // do something with *t + } + + ************************************************/ + tIterator Begin() + { + for(pEntry it = m_Table.Begin();it != m_Table.End();it++) { + if (it->m_Status == STATUS_OCCUPIED) return tIterator(it,this); + } + return End(); + + } + + tConstIterator Begin() const + { + for(pEntry it = m_Table.Begin();it != m_Table.End();it++) { + if (it->m_Status == STATUS_OCCUPIED) return tConstIterator(it,this); + } + return End(); + + } + + /************************************************ + Summary: Returns an iterator out of the hash table. + ************************************************/ + tIterator End() + { + return tIterator(m_Table.End(),this); + } + + /************************************************ + Summary: Returns an iterator out of the hash table. + ************************************************/ + tConstIterator End() const + { + return tConstIterator(m_Table.End(),this); + } + + /************************************************ + Summary: Returns the index of the given key. + + Input Arguments: + key: key of the element to find the index. + ************************************************/ + int Index(const K& key) const + { + H hashfun; + return XIndex(hashfun(key),m_Table.Size()); + } + + /************************************************ + Summary: Returns the elements number. + ************************************************/ + int Size() const + { + return m_Count; + } + +private: + /// + // Methods + pEntry* GetFirstBucket() const {return m_Table.ConstBegin();} + + void + Rehash(int size) { + int oldsize = m_Table.Size(); + m_Threshold = (int)(size * m_LoadFactor); + + // Temporary table + XClassArray tmp; + tmp.Resize(size); + + m_Table.Swap(tmp); + m_Count = 0; + m_Occupation = 0; + + for (int index = 0; index < oldsize; ++index) { + pEntry first = &tmp[index]; + + if (first->m_Status == STATUS_OCCUPIED) { + Insert(first->m_Key,first->m_Data,TRUE); + } + } + } + + int XIndex(int key,int size) const + { + return key&(size-1); + } + + + void XCopy(const XSHashTable& a) + { + m_Table = a.m_Table; + m_Occupation = a.m_Occupation; + m_LoadFactor = a.m_LoadFactor; + m_Count = a.m_Count; + m_Threshold = a.m_Threshold; + } + + + pEntry XFindIndex(const K& key) const + { + int index = XFindPos( key ); + if (index < 0) return NULL; + pEntry e = &m_Table[index]; + if (e->m_Status == STATUS_OCCUPIED) return e; + else return NULL; + } + + + int XFindPos(const K& key) const + { + int index = Index(key); + int oldindex = index; + + Eq eqaulFunc; + + while (m_Table[index].m_Status == STATUS_OCCUPIED) { + if (eqaulFunc(m_Table[index].m_Key,key)) + return index; + ++index; // Compute ith probe + if (index == m_Table.Size()) index=0; + if (index == oldindex) return -1; + } + return index; + } + + /// + // Members + + // the hash table data + XClassArray m_Table; + // The entry count + int m_Count; + // The entry count + int m_Occupation; + // Rehashes the table when count exceeds this threshold. + int m_Threshold; + // The load factor for the hashtable. + float m_LoadFactor; + + +}; + +#endif diff --git a/applications/nodehub/core/XSmartPtr.h b/applications/nodehub/core/XSmartPtr.h new file mode 100644 index 0000000..7e886fb --- /dev/null +++ b/applications/nodehub/core/XSmartPtr.h @@ -0,0 +1,181 @@ +/*************************************************************************/ +/* File : XP.h */ +/* Author : Aymeric Bard */ +/* */ +/* Virtools SDK */ +/* Copyright (c) Virtools 2000, All Rights Reserved. */ +/*************************************************************************/ + +#ifndef _XSMARTPTR_H_ +#define _XSMARTPTR_H_ + +#include "XUtil.h" + +#ifdef _MSC_VER + #pragma warning (disable:4284) +#endif + +/************************************************ +Summary: a reference counting class. You must derive from this +class to use smart pointers. + +Remarks: + + + +See Also : XP,XSmartPtr +************************************************/ +class XRefCount +{ +public: + // Reference counter + mutable unsigned int m_RefCount; + + /// Destructor which release pinfo if necessary. + ~XRefCount() {} + /// Default constructor init XRefs to 0. + XRefCount():m_RefCount(0) {} + /// operator= must NOT copy XRefs/pinfo!! + XRefCount &operator=(const XRefCount &) { + return *this; + } + /// copy cons must NOT copy XRefs/pinfo!! + XRefCount(const XRefCount &) {m_RefCount = 0;} +}; + +/************************************************ +Summary: Smart pointer class. + +Remarks: +See Also : XP,XRefCount +************************************************/ +template +class XSmartPtr +{ +public: + /************************************************ + Summary: + ************************************************/ + XSmartPtr() : m_Pointee(NULL) {} + + /************************************************ + Summary: + ************************************************/ + explicit XSmartPtr(T* p) : m_Pointee(p) {AddRef();} + + /************************************************ + Summary: Releases the pointed object. + ************************************************/ + ~XSmartPtr() {Release();} + + /************************************************ + Summary: Copy the pointer and release it the burden + from the source XP. + ************************************************/ + XSmartPtr(const XSmartPtr& a) : m_Pointee(a.m_Pointee) {AddRef();} + + /************************************************ + Summary: Copy the pointer and release it the burden + from the source XP. + ************************************************/ + XSmartPtr& operator = (const XSmartPtr& a) {return operator=(a.m_Pointee);} + + XSmartPtr& operator = (T* p) { + if (p) ++p->m_RefCount; + Release(); + m_Pointee = p; + + return *this; + } + + /************************************************ + Summary: Direct access to the pointer. + ************************************************/ + T* operator-> () const {return m_Pointee;} + + /************************************************ + Summary: Direct access to the pointer. + ************************************************/ + T& operator* () const {return *m_Pointee;} + + /************************************************ + Summary: Original pointer cast. + ************************************************/ + operator T* () const {return m_Pointee;} + +protected: + + + void AddRef() {if (m_Pointee) ++m_Pointee->m_RefCount;} + + void Release() {if (m_Pointee && (--(m_Pointee->m_RefCount) == 0)) delete m_Pointee;} + + /// + // Members + + // The pointee object + T* m_Pointee; +}; + +/************************************************ +Summary: Strided pointers iterator class. + +Remarks: +See Also : XP +************************************************/ +template +class XPtrStrided : public VxStridedData { +public: + XPtrStrided() {} + + XPtrStrided(void* Ptr, unsigned int Stride):VxStridedData(Ptr,Stride) {} + + template + XPtrStrided(const XPtrStrided& copy) { + Ptr = copy.Ptr; + Stride = copy.Stride; + } + + void Set(void* iPtr, unsigned int iStride) { Ptr = iPtr; Stride = iStride; } + + template + XPtrStrided& operator = (const XPtrStrided& copy) { + Ptr = copy.Ptr; + Stride = copy.Stride; + } + + /************************************************ + Summary: Cast to the relevant type of pointer. + ************************************************/ + operator T* () {return (T*)Ptr;} + + /************************************************ + Summary: Dereferencing operators. + ************************************************/ + T& operator * () {return *(T*)Ptr;} + const T& operator * () const {return *(T*)Ptr;} + T* operator -> () {return (T*)Ptr;} + + const T& operator [] (unsigned short iCount) const {return *(T*)(CPtr+iCount*Stride);} + T& operator [] (unsigned short iCount) {return *(T*)(CPtr+iCount*Stride);} + + const T& operator [] (int iCount) const {return *(T*)(CPtr+iCount*Stride);} + T& operator [] (int iCount) {return *(T*)(CPtr+iCount*Stride);} + + const T& operator [] (unsigned int iCount) const {return *(T*)(CPtr+iCount*Stride);} + T& operator [] (unsigned int iCount) {return *(T*)(CPtr+iCount*Stride);} + + /************************************************ + Summary: Go to the next element. + ************************************************/ + XPtrStrided& operator ++() {CPtr += Stride;return *this;} + XPtrStrided operator ++(int) {XPtrStrided tmp = *this; CPtr += Stride;return tmp;} + + /************************************************ + Summary: Go to the n next element. + ************************************************/ + XPtrStrided operator +(int n) {return XPtrStrided( CPtr+n*Stride,Stride);} + XPtrStrided& operator +=(int n) { CPtr += n*Stride;return *this;} +}; + +#endif diff --git a/examples/blueprints-example/core/graph_state.cpp b/applications/nodehub/core/graph_state.cpp similarity index 100% rename from examples/blueprints-example/core/graph_state.cpp rename to applications/nodehub/core/graph_state.cpp diff --git a/examples/blueprints-example/core/graph_state.h b/applications/nodehub/core/graph_state.h similarity index 100% rename from examples/blueprints-example/core/graph_state.h rename to applications/nodehub/core/graph_state.h diff --git a/applications/nodehub/core/utils.h b/applications/nodehub/core/utils.h new file mode 100644 index 0000000..63307d3 --- /dev/null +++ b/applications/nodehub/core/utils.h @@ -0,0 +1,183 @@ +#ifndef NODEHUB_CORE_UTILS_H +#define NODEHUB_CORE_UTILS_H + +#include +#include +#include +#include // For mutex helpers +#include // For thread helpers (C11) + +// From https://hwisnu.bearblog.dev/giving-c-a-superpower-custom-header-file-safe_ch/ + +//============================================================================== +// ATTRIBUTES & BUILTINS +//============================================================================== + +// The magic behind CLEANUP: zero overhead, maximum safety +// NOTE: [[cleanup]] is a C23 feature. __attribute__((cleanup)) is a GCC/Clang extension. +// This will work in C++ with GCC/Clang but is not standard C++. +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L +#define CLEANUP(func) [[cleanup(func)]] +#else +#define CLEANUP(func) __attribute__((cleanup(func))) +#endif + +// Branch prediction that actually matters in hot paths +#ifdef __GNUC__ +#define LIKELY(x) __builtin_expect(!!(x), 1) +#define UNLIKELY(x) __builtin_expect(!!(x), 0) +#else +#define LIKELY(x) (x) +#define UNLIKELY(x) (x) +#endif + +//============================================================================== +// SMART POINTERS +//============================================================================== + +// --- UniquePtr --- +// NOTE: The blog post did not define UNIQUE_PTR_INIT or unique_ptr_delete. +// A reasonable implementation is provided below. + +typedef struct { + void* ptr; + void (*deleter)(void*); +} UniquePtr; + +#define UNIQUE_PTR_INIT(p, d) {.ptr = p, .deleter = d} + +static inline void unique_ptr_cleanup(UniquePtr* uptr) { + if (uptr && uptr->ptr && uptr->deleter) { + uptr->deleter(uptr->ptr); + uptr->ptr = NULL; + } +} + +#define AUTO_UNIQUE_PTR(name, ptr, deleter) \ + UniquePtr name CLEANUP(unique_ptr_cleanup) = UNIQUE_PTR_INIT(ptr, deleter) + +// Manually release the resource, for reassignment. +static inline void unique_ptr_delete(UniquePtr* uptr) { + unique_ptr_cleanup(uptr); +} + + +// --- SharedPtr --- +// NOTE: The blog post mentioned shared_ptr_init, shared_ptr_copy, and shared_ptr_delete +// but did not provide their implementations. A reasonable implementation is provided below. + +typedef struct { + void* ptr; + void (*deleter)(void*); + size_t* ref_count; +} SharedPtr; + +static inline void shared_ptr_delete(SharedPtr* sptr); // Forward declare + +static inline void shared_ptr_cleanup(SharedPtr* sptr) { + shared_ptr_delete(sptr); // Decrement and free if last reference +} + +#define AUTO_SHARED_PTR(name) \ + SharedPtr name CLEANUP(shared_ptr_cleanup) = {.ptr = NULL, .deleter = NULL, .ref_count = NULL} + + +static inline void shared_ptr_init(SharedPtr* sptr, void* ptr, void (*deleter)(void*)) { + if (!sptr) return; + sptr->ptr = ptr; + sptr->deleter = deleter; + if (ptr) { + sptr->ref_count = (size_t*)malloc(sizeof(size_t)); + if (sptr->ref_count) { + *(sptr->ref_count) = 1; + } + } else { + sptr->ref_count = NULL; + } +} + +static inline SharedPtr shared_ptr_copy(SharedPtr* sptr) { + SharedPtr new_sptr = { .ptr = NULL, .deleter = NULL, .ref_count = NULL }; + if (sptr && sptr->ptr && sptr->ref_count) { + new_sptr.ptr = sptr->ptr; + new_sptr.deleter = sptr->deleter; + new_sptr.ref_count = sptr->ref_count; + (*(new_sptr.ref_count))++; + } + return new_sptr; +} + +static inline void shared_ptr_delete(SharedPtr* sptr) { + if (sptr && sptr->ptr && sptr->ref_count) { + (*(sptr->ref_count))--; + if (*(sptr->ref_count) == 0) { + if (sptr->deleter) { + sptr->deleter(sptr->ptr); + } + free(sptr->ref_count); + } + sptr->ptr = NULL; + sptr->deleter = NULL; + sptr->ref_count = NULL; + } +} + +//============================================================================== +// DYNAMIC ARRAYS (VECTORS) +//============================================================================== + +// NOTE: The DEFINE_VECTOR_TYPE macro in the blog post was truncated ("... (6495 chars omitted)..."). +// It cannot be fully reproduced from the article. + + +//============================================================================== +// SAFE STRING OPERATIONS +//============================================================================== + +static inline bool safe_strcpy(char* dest, size_t dest_size, const char* src) { + if (!dest || dest_size == 0 || !src) return false; + size_t src_len = strlen(src); + if (src_len >= dest_size) return false; + memcpy(dest, src, src_len + 1); + return true; +} + + +//============================================================================== +// CONCURRENCY HELPERS +//============================================================================== + +// --- RAII Mutexes --- + +// RAII-style mutex locking using the CLEANUP attribute. +// The mutex is automatically unlocked when the pointer goes out of scope. +static inline void mutex_unlock_cleanup(pthread_mutex_t** lock) { + if (lock && *lock) { + pthread_mutex_unlock(*lock); + } +} + +/* Example Usage: + pthread_mutex_t my_lock; + pthread_mutex_init(&my_lock, NULL); + ... + { + pthread_mutex_t* lock_ptr CLEANUP(mutex_unlock_cleanup) = &my_lock; + pthread_mutex_lock(lock_ptr); + // ... critical section ... + if (some_error) return; // Mutex is automatically unlocked + } +*/ + +// --- Threading Macros --- +// NOTE: These use C11 threads (). Ensure your compiler supports it. + +#define SPAWN_THREAD(name, func, arg) \ + thrd_t name; \ + if (thrd_create(&name, (thrd_start_t)(func), (arg)) != thrd_success) { /* handle error */ } + +#define JOIN_THREAD(name) \ + thrd_join(name, NULL) + + +#endif // NODEHUB_CORE_UTILS_H diff --git a/applications/nodehub/data/BlueprintBackground.png b/applications/nodehub/data/BlueprintBackground.png new file mode 100644 index 0000000000000000000000000000000000000000..ce7edce3ad7f46987a20a0a814dd1a55b11202e8 GIT binary patch literal 5513 zcmV;46?W>0P)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0uoBa_M6WNWeqIg~6QE69c9o#eyhGvpiOA@W-aonk<7r1(?fC{oI5N*U!4 zfg=2N-7=cNnjjOr{yriy6mMFgG#l znCF=fnQv8CDz++o6_Lscl}eQ+l^ZHARH>?_s@|##Rr6KLRFA1%Q+=*RRWnoLsR`7U zt5vFIcfW3@?wFpwUVxrVZ>QdQz32KIeJ}k~{cZZE^+ya? z2D1z#2HOnI7(B%_ac?{wFUQ;QQA1tBKtrWrm0_3Rgps+?Jfqb{jYbcQX~taRB;#$y zZN{S}1|}gUOHJxc?wV3fxuz+mJ4`!F$IZ;mqRrNsHJd##*D~ju=bP7?-?v~|cv>vB zsJ6IeNwVZxrdjT`yl#bBIa#GxRa#xMMy;K#CDyyGyQdMSxlWT#tDe?p!?5wT$+oGt z8L;Kp2HUQ-ZMJ=3XJQv;x5ci*?vuTfeY$;({XGW_huIFR9a(?@3)XSs8O^N5RyOM=TTmp(3=8^+zpz2r)C z^>JO{deZfso3oq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ikq;e z@@1^4dB7!n4k} zT8(QbeltUU9U<4Ekn7A)xZ${aLSKjdwwxr~rJ-=cF>VR@4ZF?Qpv&`wxTM~~ z{GJYdeJz95CE__5sPRF@3cs}Qnlk;&dF744bx?bV=AFd33 zk_`^YSan3B%-}HDgikhDC7X2qWXAqvgIlt}?QaIRWC_VhEtwx2HP2@yq&jNyJ!;a) zaGinA&&+ecbuR9=U1*)@d#$&`&3z0qmZOoVuW{v>uQTN-xvRI$2>rJ8y0}fg-;#WZ zC8PBRX5{_AjO$Y@(XxBhxc8fs51W+NnUpUxDIa!8%7;zLhfT_dP0EZw#Ko$td^IWW zHeYv}kh@Ko-6k(APZMUhgwY2~E=Nr++f6Rlnp}=bE_$R%=cq~Hs7dWvhe}eGqbA3I zN$sc|(#$6=H~1GCpHEEOPfW-kN=VM#F@v$(w!ca97beY51VhW7hkRn<5{cWfDV5QF zi(zJ>nVU@DDH?#yR*TWylU9}jjAWd>jkg~9ig~W($<3wAQ&QxM`_c z&#mUU(>&XFMx#xUjlS79PODD9Mqo3iJ?Ao8B2A&e(8E$Q+|fka9QwNPS!AB;jQ=|0 r_L}Eb^V}(OyrDK|=|! literal 0 HcmV?d00001 diff --git a/applications/nodehub/data/Cuprum-OFL.txt b/applications/nodehub/data/Cuprum-OFL.txt new file mode 100644 index 0000000..6acddd0 --- /dev/null +++ b/applications/nodehub/data/Cuprum-OFL.txt @@ -0,0 +1,93 @@ +Copyright 2010 The Cuprum Project Authors (lemonad@jovanny.ru), with Reserved Font Name "Cuprum". + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/applications/nodehub/data/Oswald-OFL.txt b/applications/nodehub/data/Oswald-OFL.txt new file mode 100644 index 0000000..7e2c152 --- /dev/null +++ b/applications/nodehub/data/Oswald-OFL.txt @@ -0,0 +1,93 @@ +Copyright 2016 The Oswald Project Authors (https://github.com/googlefonts/OswaldFont) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/applications/nodehub/data/Oswald-Regular.ttf b/applications/nodehub/data/Oswald-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..2492c44a2de20b40ee64b10d8da1f8129227c78f GIT binary patch literal 91400 zcmc$H33yybm2TC&y-RAT)tg$qsnwg*+IMSjNtR^Uk}Y|a?08W&FR~rm*%LxcNJ7{l zo?#fsKp2<@2}>M?44J%4h!e1##UYS|fdK*`5Flh>O$MUY`%l&FtJap}eeb>RInh>q zZq=z%r%s(Z+hv?FR*Y{3RyMqPaOlvV54AI1`!UA&4a4IbHhuDj+s`px?_#X>(cw*7 z`ror|rjYSnKV!`J*A1KM8t=-#@*|A>?N8`s&!)|No3Fn0K#=hZe~iCV7aW>Ca+~#a zeD>yM#w<5naK&Y11@X{7GVZ(|pWkrtk-djL)9QMXal?NyW_RzMzVry%i!lBz_-WaD z@al_M&lkTBT&fxS_1E@YG<{()H-D0`S6{&At^3em`I_;cG5(YIJGSr8WmoYR_dLMZ zYXQdczJBnM3#J3Bp8qvtzj+h*{_4>5RYwf{g`N1D@GCn!edwYKzWL!<#$9Q~)Xb4f zF1_qiYnu{`m*8*D(2-*o9VzNMc!u%f*8u+*Q`mOKlyNo1RAy$WbP}zq!qmM?;au6q z6ov0L;5WX3F|)~N0GR49n!Ht)IwFpE#1Yxf|B^Y%D>DD7rrvyZyK)73bYgZtM2}`> zW7X+O8#gdMiq%lKLD`4?YsQQ!davc{8M9gdW_CCnCabUNQfHGhnv9yAO{()NhrT)! z|CeOz`&LuOk3Y_X{LtK-?AuUg!i+GAS$UZKh5edY?pFB8U!QEL%0j5W*CEcb*O!AZ z+@wSNCJUkHeawwx23j91seBKk&}iAd)PUX$6Q+=n%il&S@SW z(MPckaV86~2#Z857EW{5Dx9bqEtpG7Ur*m%$@!(PjF{hL^Cv7fSF3I7ehq6yDqG&?L@9`BN=J9)C z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#Cu^2;m&g<=l9X_#^BE%TelN| zm1%Hf2+)#BG0#y`dmkxJI8jWG(>|nCTV@XVE*xtPS8=w^M7ucjNazv!3M;EC`A_A) ztn*U_Cfnt=NT(wnW5Z84tI(`uIq&Kq)^dFfAzlmAWm$vrJ?(iV%H0M zN08ahnQk6usr&(RCo{hur>JyEysr|6RpJAcXjKW(zQdDs@_w57Y6{qaqrJ6IDGj;b z4DR%~7`N{u{~~D9NX_+*dO+^&p>? zmLu!tx^mxNb6g>=GL8Eh?*?^yW)5pPgS2UmQ5tg?ti$KU_$V2p!xCB#&CtEhjkI(y|;RnBuz_0L_${X=;r?bu_)W$ literal 0 HcmV?d00001 diff --git a/applications/nodehub/data/Play-OFL.txt b/applications/nodehub/data/Play-OFL.txt new file mode 100644 index 0000000..cb9baa9 --- /dev/null +++ b/applications/nodehub/data/Play-OFL.txt @@ -0,0 +1,93 @@ +Copyright (c) 2011, Jonas Hecksher, Playtypes, e-types AS (lasse@e-types.com), with Reserved Font Name 'Play', 'Playtype', 'Playtype Sans'. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/applications/nodehub/data/Play-Regular.ttf b/applications/nodehub/data/Play-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..25a72a746cf4061c7a19b22aa9d0039e4a801ac7 GIT binary patch literal 183852 zcmeFad3;<~eK&m0y)$!X(`Z(Wq#2E7=8iPl_rBG;i{xKxtl@LJKW4fkGQ-oV0;L;Yny|frbL@QzvZ-O(}Z_@Bj_b`1$_Mx%bYU zO;XbL{k;9-C1mlPyPWge_ro}2EP{WySa|osu1o)B;*0;ADepVNm~w9S-YfV0>gPW2 z4W|6wQ;fC$Z1=tc^O4jqew!(eevPr%p)2(8D(b5-{}zrvIgf5uqTnbRj;c^1!w@xA@{xA*id zue<)LU;I+Xy=kUQZoA>siR%KN{Lv6oc7GJVPu+kEp1ZWq?NHo^^jTgzrrq!u{D>PntOeTo`FKn(<}{tFy2>MGUpTc``tF|N{Qg^g zw<>q8z2@=9xtDj9p1gQbenDMid0>Ds)zzWwWX!(4$G)CbviRL)-v1a=0k>9`W(SOy zxwyhruBhj516LS7#nd2odsO%7CLUm3E#N)H{C>|W^LP#{`M9QCtu42;xm<1Owsfk! zHQADg$D$Ee*wq}##UkO5Sih!wx{Kp2<73m~9?hd`&J8V|Sz3(jRHi)Jwt1#_Haj_4 zu|xH-~O*LPL!_2P}n8&zvhx+}>a7kjSU+vomY-dk)u*?4c?I@7tBTxV;a zJO1waTO&eo1x$1mT~VOxLtJwulqsHLk&i3Hf#IT8?Q^`As;xz!ApG8><+iP6z<)Dg1kT3_uo^ydf++1}F5>Y`S0q$p-$FH4Y zKA(G)x!nhryxilt+Or&s#adz@36OF`&~q@*0eaT-BH&ik^rVv#{sENmzMJQ_&Fyqy~u*V_S_Wg)_j?1>F0&k9pia&nf2hx>g~|4lHTh?Y`Q*91e$L zVaNjczityBaeE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OCZLheLRxWWFtz7udCsrlW%c9xt{yUP25lRazDA5`^mRs{RH#-NLl~6_njW-e(lGa zMk|}-l`V-^wq#z}Aj!qE6wP&y;-UMLahQc?U`C&VTaHDz5VmC`~0y6Md_1B-ZvR_}1xq&gF(sb% z(HfD&tBiwvl;V{bhY1TQQO)IWshI+u<)j4_&rmufK{u^kXJTKThIKHk8wTo={6Bxm BicUGN2b1hWCd=dd4yp1_}#p=-xr8W$(4 z@phdVq^0L1_n*S5o)beq9s6JP=Y>n0TGLS~EqLua`krT!j!X2+q`?Eb z=xgUTg#+{y8Kba^&$-PiPR(QlRYuG@!^<@3VJ$UOsdx*2YN%546h~m~d);&>bS=4oo3rm?!+ZW^Z&F3yw>^L?w eaA@0d?z>-rMJX$#4*z=q0000U8 literal 0 HcmV?d00001 diff --git a/applications/nodehub/data/ic_save_white_24dp.png b/applications/nodehub/data/ic_save_white_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..015062ed3b316909362e3bfe43579715a4f2c14e GIT binary patch literal 168 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM0wlfaz7_+id`}n05R2ZcmmRqp6hvGD%@cNQ zTrf?MD{tY`DCrY!+h+!7)MX@<|M>91UCT6U&6_Q^vKIW^bNn|gNPwG~q2dAY{6@(2Ul)|NDzIgd>D5-Nv3R_&pT)_9!>hC0v RLqMw;JYD@<);T3K0RZw0JMaJi literal 0 HcmV?d00001 diff --git a/applications/nodehub/enums.h b/applications/nodehub/enums.h new file mode 100644 index 0000000..fc1a386 --- /dev/null +++ b/applications/nodehub/enums.h @@ -0,0 +1,272 @@ +#pragma once +#include "config.h" +#include "utilities/uuid_generator.h" + + +//------------------------------------------------------------------------------ +// +// Objects +// +//------------------------------------------------------------------------------ + +/*************************************************** +{filename:CK_OBJECT_FLAGS} +Summary: CKObject Flags + +Remarks: ++ Flags specifying special settings for basic objects. ++ Some of this flags are shared with sub-classes such as CKParameterIn,CKParameterOut and CKBehaviorIO. ++ You rarely need to modify directly this flags through CKObject::SetFlags or CKObject::ModifyObjectFlags instead +you should always use the specific acces function (given between ()) which may need to perform additionnal operations. +See also: CKObject,CKObject::GetObjectFlags,CKObject::ModifyObjectFlags +*************************************************/ +typedef enum NH_OBJECT_FLAGS { + NH_OBJECT_INTERFACEOBJ = 0x00000001, // Reserved for Inteface Use + NH_OBJECT_PRIVATE = 0x00000002, // The object must not be displayed in interface (Lists,Level view,etc...),nor should it be saved. (CKObject::IsPrivate() + NH_OBJECT_INTERFACEMARK = 0x00000004, + NH_OBJECT_FREEID = 0x00000008, // ID of this object can be released safely and is free to be reused by future CKobjects. + NH_OBJECT_TOBEDELETED = 0x00000010, // This object is being deleted + NH_OBJECT_NOTTOBESAVED = 0x00000020, // This object must not be saved + NH_OBJECT_VISIBLE = 0x00000040, // This object is visible (CKObject::Show) + NH_OBJECT_NAMESHARED = 0x00000080, // This object has its name from another entity + NH_OBJECT_DYNAMIC = 0x00000108, // This object may be created or deleted at run-time, it also contails CK_OBJECT_FREEID. (CKObject::IsDynamic,CKContext::CreateObject) + NH_OBJECT_HIERACHICALHIDE = 0x00000200, // This object hides all its hierarchy (CKObject::Show) + NH_OBJECT_UPTODATE = 0x00000400, // (Camera,etc..) + NH_OBJECT_TEMPMARKER = 0x00000800, + NH_OBJECT_ONLYFORFILEREFERENCE = 0x00001000, + NH_OBJECT_NOTTOBEDELETED = 0x00002000, // This object must not be deleted in a clear all + NH_OBJECT_APPDATA = 0x00004000, // This object has app data + NH_OBJECT_SINGLEACTIVITY = 0x00008000, // this object has an information of single activity (active at scene start,etc..) + NH_OBJECT_LOADSKIPBEOBJECT = 0x00010000, // When loading this object the CKBeObject part should be skipped + NH_OBJECT_KEEPSINGLEACTIVITY = 0x00020000, // this object must keep its information of single activity (active at scene start,etc..) + NH_OBJECT_LOADREPLACINGOBJECT = 0x00040000, // Indicates the object being loaded is being replaced + + NH_OBJECT_NOTTOBELISTEDANDSAVED = 0x00000023, // Combination of Private and Not To Be Saved + NH_OBJECT_SELECTIONSET = 0x00080000, // if group, then it is a selection set, otherwise, temporary flag used for objects belonging to a selection set. Used by Virtools's Interface + NH_OBJECT_VR_DISTRIBUTED = 0x00100000, // distributed object for VR (ie mainly used for distributed parameters for VR) + + +// The following flags are specific to parameters (they are stored here for object's size purposes ) + NH_PARAMETEROUT_SETTINGS = 0x00400000, + NH_PARAMETEROUT_PARAMOP = 0x00800000, // This parameter is the output of a CKParameterOperation (Automatically set by Engine) + NH_PARAMETERIN_DISABLED = 0x01000000, // Parameter In or Out is disabled (CKBehavior::EnableInputParameter,CKBehavior::DisableInputParameter) + NH_PARAMETERIN_THIS = 0x02000000, // Special parameter type : its value and type are always equal to its owner (CKParameter::SetAsMyselfParameter) + NH_PARAMETERIN_SHARED = 0x04000000, + NH_PARAMETEROUT_DELETEAFTERUSE = 0x08000000, // When adding parameters to CKMessage, they can be automatically deleted when message is released (CKMessage::AddParameter) + NH_OBJECT_PARAMMASK = 0x0FC00000, // Mask for options specific to parameters + +// The Following flags are specific for Behavior ios (CKBehaviorIO) + NH_BEHAVIORIO_IN = 0x10000000, // This BehaviorIO is a behavior input (CKBehaviorIO::SetType} + NH_BEHAVIORIO_OUT = 0x20000000, // This BehaviorIO is a behavior output (CKBehaviorIO::SetType) + NH_BEHAVIORIO_ACTIVE = 0x40000000, // This BehaviorIO is a currently active (CKBehaviorIO::Activate} + NH_OBJECT_IOTYPEMASK = 0x30000000, + NH_OBJECT_IOMASK = 0xF0000000, + + // The Following flags are specific for Behavior ios (CKBehaviorIO) + NH_BEHAVIORLINK_RESERVED = 0x10000000, // This BehaviorIO is a behavior input (CKBehaviorIO::SetType} + NH_BEHAVIORLINK_ACTIVATEDLASTFRAME = 0x20000000, // This link had been activated last frame + NH_OBJECT_BEHAVIORLINKMASK = 0x30000000, +} NH_OBJECT_FLAGS; + + +//------------------------------------------------------------------------------ +// +// Building Blocks +// +//------------------------------------------------------------------------------ + +/************************************************************ +{filename:NH_BEHAVIOR_FLAGS} +Summary: Flags settings for behaviors. +Remarks: + + When creating a prototype, you can precise various flags + about how your behavior will act: whether it will send or receive message, + does the user may add inputs,outputs or parameters, is it active, etc. + +See also: NHBehaviorPrototype::SetBehaviorFlags,Behavior Prototype Creation +**********************************************************/ +typedef enum NH_BEHAVIOR_FLAGS { + NHBEHAVIOR_NONE =0x00000000, // Reserved for future use + NHBEHAVIOR_ACTIVE =0x00000001, // This behavior is active + NHBEHAVIOR_SCRIPT =0x00000002, // This behavior is a script + NHBEHAVIOR_RESERVED1 =0x00000004, // Reserved for internal use. + NHBEHAVIOR_USEFUNCTION =0x00000008, // Behavior uses a function and not a graph + NHBEHAVIOR_RESERVED2 =0x00000010, // Reserved for internal use. + NHBEHAVIOR_CUSTOMSETTINGSEDITDIALOG =0x00000020, // Behavior has a custom Dialog Box for settings edition . + NHBEHAVIOR_WAITSFORMESSAGE =0x00000040, // Behavior is waiting for a message to activate one of its outputs + NHBEHAVIOR_VARIABLEINPUTS =0x00000080, // Behavior may have its inputs changed by editing them + NHBEHAVIOR_VARIABLEOUTPUTS =0x00000100, // Behavior may have its outputs changed by editing them + NHBEHAVIOR_VARIABLEPARAMETERINPUTS =0x00000200, // Behavior may have its number of input parameters changed by editing them + NHBEHAVIOR_VARIABLEPARAMETEROUTPUTS =0x00000400, // Behavior may have its number of output parameters changed by editing them + NHBEHAVIOR_TOPMOST =0x00004000, // No other Behavior includes this one + NHBEHAVIOR_BUILDINGBLOCK =0x00008000, // This Behavior is a building block. Automatically set by the engine when coming from a DLL. + NHBEHAVIOR_MESSAGESENDER =0x00010000, // Behavior may send messages during its execution. + NHBEHAVIOR_MESSAGERECEIVER =0x00020000, // Behavior may check messages during its execution. + NHBEHAVIOR_TARGETABLE =0x00040000, // Behavior may be owned by a different object that the one to which its execution will apply. + NHBEHAVIOR_CUSTOMEDITDIALOG =0x00080000, // This Behavior have a custom Dialog Box for parameters edition . + NHBEHAVIOR_RESERVED0 =0x00100000, // Reserved for internal use. + NHBEHAVIOR_EXECUTEDLASTFRAME =0x00200000, // This behavior has been executed during last process. (Available only in profile mode ) + NHBEHAVIOR_DEACTIVATENEXTFRAME =0x00400000, // Behavior will be deactivated next frame + NHBEHAVIOR_RESETNEXTFRAME =0x00800000, // Behavior will be reseted next frame + NHBEHAVIOR_INTERNALLYCREATEDINPUTS =0x01000000, // Behavior execution may create/delete inputs + NHBEHAVIOR_INTERNALLYCREATEDOUTPUTS =0x02000000, // Behavior execution may create/delete outputs + NHBEHAVIOR_INTERNALLYCREATEDINPUTPARAMS =0x04000000, // Behavior execution may create/delete input parameters or change their type + NHBEHAVIOR_INTERNALLYCREATEDOUTPUTPARAMS=0x08000000, // Behavior execution may create/delete output parameters or change their type + NHBEHAVIOR_INTERNALLYCREATEDLOCALPARAMS =0x40000000, // Behavior execution may create/delete local parameters or change their type + NHBEHAVIOR_ACTIVATENEXTFRAME =0x10000000, // Behavior will be activated next frame + NHBEHAVIOR_LOCKED =0x20000000, // Behavior is locked for utilisation in Virtools + NHBEHAVIOR_LAUNCHEDONCE =0x80000000, // Behavior has not yet been launched... +} NH_BEHAVIOR_FLAGS; + +//------------------------------------------------------------------------------ +// +// Parameters +// +//------------------------------------------------------------------------------ + +/************************************************* +{filename:NH_PARAMETERTYPE_FLAGS} +Summary: Flags settings for new parameter types + +Remarks: ++These flags specify special settings for a parameter type. ++Parameter may have a fixed or variable buffer size, some may be hidden +so that they are not displayed in the interface. +See also: NHParameterTypeDesc +*************************************************/ +typedef enum NH_PARAMETERTYPE_FLAGS { + NHPARAMETERTYPE_VARIABLESIZE = 0x00000001, // Size of the buffer stored by the parameter may change + NHPARAMETERTYPE_RESERVED = 0x00000002, // Reserved + NHPARAMETERTYPE_HIDDEN = 0x00000004, // This parameter type should not be shown in the interface + NHPARAMETERTYPE_FLAGS = 0x00000008, // This parameter type is a flag (See NHParameterManager::RegisterNewFlags) + NHPARAMETERTYPE_STRUCT = 0x00000010, // This parameter type is a structure of parameters (See NHParameterManager::RegisterNewStructure) + NHPARAMETERTYPE_ENUMS = 0x00000020, // This parameter type is an enumeration (See NHParameterManager::RegisterNewEnum) + NHPARAMETERTYPE_USER = 0x00000040, // This parameter type is a user-defined one created in the interface + NHPARAMETERTYPE_NOENDIANCONV = 0x00000080, // Do not try to convert this parameter buffer On Big-Endian processors (strings, void buffer have this flags) + NHPARAMETERTYPE_TOSAVE = 0x00000100, // Temporary flag set in CKFile::EndSave(). This parameter type is to be saved in the SaveData callback of managers. Used in Parameter Manager (used user's flags & enums) +} NH_PARAMETERTYPE_FLAGS; + +//----------------------------------------------------------// +// Standard Parameter GUIDs // +//----------------------------------------------------------// + +constexpr Uuid64 NHP_GUID_NONE(0x1cb10760, 0x419f50c5); +constexpr Uuid64 NHP_GUID_VOIDBUF(0x4d082c90, 0x0c8339a2); +constexpr Uuid64 NHP_GUID_FLOAT(0x47884c3f, 0x432c2c20); +constexpr Uuid64 NHP_GUID_ANGLE(0x11262cf5, 0x30b0233a); +constexpr Uuid64 NHP_GUID_PERCENTAGE(0xf3c84b4e, 0x0ffacc34); +constexpr Uuid64 NHP_GUID_FLOATSLIDER(0x429d42cf, 0x211c0cc2); +constexpr Uuid64 NHP_GUID_INT(0x5a5716fd, 0x44e276d7); +constexpr Uuid64 NHP_GUID_KEY(0xfa6e1bdd, 0x62d2abd7); +constexpr Uuid64 NHP_GUID_BOOL(0x1ad52a8e, 0x5e741920); +constexpr Uuid64 NHP_GUID_STRING(0x6bd010e2, 0x115617ea); +constexpr Uuid64 NHP_GUID_RECT(0x7ab20d20, 0x693044a9); +constexpr Uuid64 NHP_GUID_VECTOR(0x48824eae, 0x2fe47960); +constexpr Uuid64 NHP_GUID_VECTOR4(0x6c439ee0, 0x2fe47960); +constexpr Uuid64 NHP_GUID_2DVECTOR(0x4efcb34a, 0x6079e42f); +constexpr Uuid64 NHP_GUID_QUATERNION(0x06c439ee, 0x45b50fc2); +constexpr Uuid64 NHP_GUID_EULERANGLES(0x13b01b3c, 0x1942583e); +constexpr Uuid64 NHP_GUID_MATRIX(0x643f046e, 0x65211b71); +constexpr Uuid64 NHP_GUID_COLOR(0x57d42fee, 0x7cbb3b91); +constexpr Uuid64 NHP_GUID_BOX(0x668649c8, 0x283e2ee1); +constexpr Uuid64 NHP_GUID_OBJECTARRAY(0x71df7142, 0xc437133a); +constexpr Uuid64 NHP_GUID_OBJECT(0x30ec20ab, 0x6df6517d); +constexpr Uuid64 NHP_GUID_BEOBJECT(0x71d80779, 0x402f42f3); + +constexpr Uuid64 NHP_GUID_ENUMS(0x4dd37f6b, 0x240f5fa2); +constexpr Uuid64 NHP_GUID_STRUCTS(0x38df566a, 0x30f77b9e); +constexpr Uuid64 NHP_GUID_FLAGS(0x2b49245d, 0x582d60d6); + +//----------------------------------------------------------//// +// Data Array Flags and Enums //// +//----------------------------------------------------------//// + +/************************************************ +{filename:NH_BINARYOPERATOR} +Summary: Available operations between colums of a DataArray + +See Also: CKDataArray::ColumnTransform, CKDataArray::ColumnsOperate +************************************************/ +typedef enum NH_BINARYOPERATOR{ + NHADD = 1, // Addition + NHSUB = 2, // Substraction + NHMUL = 3, // Multiplication + NHDIV = 4 // Division +} NH_BINARYOPERATOR; + +/************************************************ +{filename:NH_COMPOPERATOR} +Summary: Available comparisons between colums of a DataArray +Remarks: + +See Also: CKDataArray::CreateGroup, CKDataArray::FindLine +************************************************/ +typedef enum NH_COMPOPERATOR{ + NHEQUAL = 1, + NHNOTEQUAL = 2, + NHLESSER = 3, + NHLESSEREQUAL = 4, + NHGREATER = 5, + NHGREATEREQUAL = 6 +} NH_COMPOPERATOR; + + +//----------------------------------------------------------// +// Class Identifier List // +//----------------------------------------------------------// + +#define NHCID_OBJECT 1 + #define NHCID_PARAMETERIN 2 + #define NHCID_PARAMETEROPERATION 4 + #define NHCID_STATE 5 + #define NHCID_BEHAVIORLINK 6 + #define NHCID_BEHAVIOR 8 + #define NHCID_BEHAVIORIO 9 + #define NHCID_RENDERCONTEXT 12 + #define NHCID_KINEMATICCHAIN 13 + #define NHCID_SCENEOBJECT 11 + #define NHCID_OBJECTANIMATION 15 + #define NHCID_ANIMATION 16 + #define NHCID_KEYEDANIMATION 18 + #define NHCID_BEOBJECT 19 + #define NHCID_DATAARRAY 52 + #define NHCID_SCENE 10 + #define NHCID_LEVEL 21 + #define NHCID_PLACE 22 + #define NHCID_GROUP 23 + #define NHCID_SOUND 24 + #define NHCID_WAVESOUND 25 + #define NHCID_MIDISOUND 26 + #define NHCID_MATERIAL 30 + #define NHCID_TEXTURE 31 + #define NHCID_MESH 32 + #define NHCID_PATCHMESH 53 + #define NHCID_RENDEROBJECT 47 + #define NHCID_2DENTITY 27 + #define NHCID_SPRITE 28 + #define NHCID_SPRITETEXT 29 + #define NHCID_3DENTITY 33 + #define NHCID_GRID 50 + #define NHCID_CURVEPOINT 36 + #define NHCID_SPRITE3D 37 + #define NHCID_CURVE 43 + #define NHCID_CAMERA 34 + #define NHCID_TARGETCAMERA 35 + #define NHCID_LIGHT 38 + #define NHCID_TARGETLIGHT 39 + #define NHCID_CHARACTER 40 + #define NHCID_3DOBJECT 41 + #define NHCID_BODYPART 42 + #define NHCID_PARAMETER 46 + #define NHCID_PARAMETERLOCAL 45 + #define NHCID_PARAMETERVARIABLE 55 + #define NHCID_PARAMETEROUT 3 + #define NHCID_INTERFACEOBJECTMANAGER 48 + #define NHCID_CRITICALSECTION 49 + #define NHCID_LAYER 51 + #define NHCID_PROGRESSIVEMESH 54 + #define NHCID_SYNCHRO 20 + +#ifdef NH_GUI + #include "enums_gui.h" +#endif \ No newline at end of file diff --git a/applications/nodehub/enums_gui.h b/applications/nodehub/enums_gui.h new file mode 100644 index 0000000..b26efea --- /dev/null +++ b/applications/nodehub/enums_gui.h @@ -0,0 +1,6 @@ +#ifndef ENUMS_GUI_H +#define ENUMS_GUI_H + + + +#endif diff --git a/examples/blueprints-example/blueprints-example.cpp b/applications/nodehub/main.cpp similarity index 75% rename from examples/blueprints-example/blueprints-example.cpp rename to applications/nodehub/main.cpp index e1165ab..daa0053 100644 --- a/examples/blueprints-example/blueprints-example.cpp +++ b/applications/nodehub/main.cpp @@ -1,86 +1,19 @@ +#include +#include #include "app.h" #include "core/graph_state.h" #include "blocks/block.h" -#include "blocks/start_block.h" + #include "containers/root_container.h" #include "crude_json.h" #include -#include -#include -#include #include -#include -#include #include "Logging.h" +#include "stats.h" + #if defined(_WIN32) -#include -#include -#pragma comment(lib, "Psapi.lib") - -#define PRINT_STATS 0 - -struct MemoryUsageWin32 -{ - SIZE_T workingSet = 0; - SIZE_T privateBytes = 0; -}; -struct CpuTimesWin32 -{ - ULONGLONG kernel = 0; - ULONGLONG user = 0; -}; -static MemoryUsageWin32 CaptureMemoryUsageWin32() -{ - MemoryUsageWin32 usage; - PROCESS_MEMORY_COUNTERS_EX pmc; - if (GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast(&pmc), sizeof(pmc))) - { - usage.workingSet = pmc.WorkingSetSize; - usage.privateBytes = pmc.PrivateUsage; - } - return usage; -} -static void LogMemoryUsageWin32(const char *label, const MemoryUsageWin32 &usage) -{ - double workingSetMb = static_cast(usage.workingSet) / (1024.0 * 1024.0); - double privateMb = static_cast(usage.privateBytes) / (1024.0 * 1024.0); - LOG_INFO("[Memory] {} - Working Set: {:.2f} MB, Private Bytes: {:.2f} MB", label, workingSetMb, privateMb); -} -static CpuTimesWin32 CaptureCpuTimesWin32() -{ - CpuTimesWin32 result; - FILETIME creation{}, exit{}, kernel{}, user{}; - if (GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user)) - { - ULARGE_INTEGER k{}; - k.LowPart = kernel.dwLowDateTime; - k.HighPart = kernel.dwHighDateTime; - ULARGE_INTEGER u{}; - u.LowPart = user.dwLowDateTime; - u.HighPart = user.dwHighDateTime; - result.kernel = k.QuadPart; - result.user = u.QuadPart; - } - return result; -} -static double ComputeCpuUsagePercentWin32(const CpuTimesWin32 &begin, - const CpuTimesWin32 &end, - double elapsedSeconds) -{ - if (elapsedSeconds <= 0.0) - return 0.0; - ULONGLONG deltaKernel = end.kernel - begin.kernel; - ULONGLONG deltaUser = end.user - begin.user; - double cpuSeconds = static_cast(deltaKernel + deltaUser) / 10'000'000.0; - SYSTEM_INFO info; - GetSystemInfo(&info); - double cores = static_cast(info.dwNumberOfProcessors > 0 ? info.dwNumberOfProcessors : 1); - double usage = (cpuSeconds / (elapsedSeconds * cores)) * 100.0; - if (usage < 0.0) - usage = 0.0; - return usage; -} #endif +#define PRINT_STATS 1 // Helper to get string argument with default std::string GetStringArg(const ArgsMap &args, const std::string &key, const std::string &defaultValue = "") @@ -130,7 +63,8 @@ int RunHeadless(const ArgsMap &args) bool logLevelValid = true; auto parsedLogLevel = ParseLogLevel(logLevelOption, &logLevelValid); - InitLogger("blueprints-headless", true, true, "blueprints.log"); + std::string logFile = GetStringArg(args, "log", "blueprints.log"); + InitLogger("blueprints-headless", true, true, logFile.c_str()); SetLoggerLevel(parsedLogLevel); if (!logLevelValid) { @@ -214,7 +148,6 @@ int RunHeadless(const ArgsMap &args) } LOG_INFO("Graph file: {}", graphFile); - std::string logOption = GetStringArg(args, "log", "all"); // Check if we should execute (--run flag) bool shouldRun = GetBoolArg(args, "run", false); if (!shouldRun) @@ -271,9 +204,11 @@ int RunHeadless(const ArgsMap &args) ImGuiContext *context = ImGui::CreateContext(); ImGui::SetCurrentContext(context); App *app = new App("Blueprints_Headless", args); + // Initialize the app's graph state without creating window // OnStart() will load the graph from the file specified in args app->OnStart(); + RootContainer *rootContainer = app->GetActiveRootContainer(); if (!rootContainer) { @@ -360,34 +295,27 @@ int RunHeadless(const ArgsMap &args) int Main(const ArgsMap &args) { + // Check for headless mode first to ensure logger is initialized correctly for the mode + bool headless = GetBoolArg(args, "headless", false); + if (headless) + { + return RunHeadless(args); + } + + // --- GUI Mode --- if (!g_logger) { - InitLogger("blueprints", true, true, "blueprints.log"); + std::string logFile = GetStringArg(args, "log", "blueprints.log"); + InitLogger("blueprints", true, true, logFile.c_str()); } LOG_TRACE("[CHECKPOINT] Main: Beginning"); - // Check for headless mode - bool headless = GetBoolArg(args, "headless", false); - - if (headless) - { - LOG_TRACE("[CHECKPOINT] Main: Headless mode detected"); - return RunHeadless(args); - } - // GUI mode (existing code) App example("Blueprints", args); - - LOG_TRACE("[CHECKPOINT] Main: App created, about to call Create()"); - if (example.Create()) { - LOG_TRACE("[CHECKPOINT] Main: App created successfully, about to Run()"); return example.Run(); } - - LOG_TRACE("[CHECKPOINT] Main: App.Create() returned false"); - return 0; } diff --git a/applications/nodehub/stats.cpp b/applications/nodehub/stats.cpp new file mode 100644 index 0000000..aa07bdc --- /dev/null +++ b/applications/nodehub/stats.cpp @@ -0,0 +1,62 @@ +#include "stats.h" +#include "Logging.h" // For LOG_INFO + +#if defined(_WIN32) +#include +#include +#pragma comment(lib, "Psapi.lib") + +MemoryUsageWin32 CaptureMemoryUsageWin32() +{ + MemoryUsageWin32 usage; + PROCESS_MEMORY_COUNTERS_EX pmc; + if (GetProcessMemoryInfo(GetCurrentProcess(), reinterpret_cast(&pmc), sizeof(pmc))) + { + usage.workingSet = pmc.WorkingSetSize; + usage.privateBytes = pmc.PrivateUsage; + } + return usage; +} + +void LogMemoryUsageWin32(const char *label, const MemoryUsageWin32 &usage) +{ + double workingSetMb = static_cast(usage.workingSet) / (1024.0 * 1024.0); + double privateMb = static_cast(usage.privateBytes) / (1024.0 * 1024.0); + LOG_INFO("[Memory] {} - Working Set: {:.2f} MB, Private Bytes: {:.2f} MB", label, workingSetMb, privateMb); +} + +CpuTimesWin32 CaptureCpuTimesWin32() +{ + CpuTimesWin32 result; + FILETIME creation{}, exit{}, kernel{}, user{}; + if (GetProcessTimes(GetCurrentProcess(), &creation, &exit, &kernel, &user)) + { + ULARGE_INTEGER k{}; + k.LowPart = kernel.dwLowDateTime; + k.HighPart = kernel.dwHighDateTime; + ULARGE_INTEGER u{}; + u.LowPart = user.dwLowDateTime; + u.HighPart = user.dwHighDateTime; + result.kernel = k.QuadPart; + result.user = u.QuadPart; + } + return result; +} +double ComputeCpuUsagePercentWin32(const CpuTimesWin32 &begin, + const CpuTimesWin32 &end, + double elapsedSeconds) +{ + if (elapsedSeconds <= 0.0) + return 0.0; + ULONGLONG deltaKernel = end.kernel - begin.kernel; + ULONGLONG deltaUser = end.user - begin.user; + double cpuSeconds = static_cast(deltaKernel + deltaUser) / 10'000'000.0; + SYSTEM_INFO info; + GetSystemInfo(&info); + double cores = static_cast(info.dwNumberOfProcessors > 0 ? info.dwNumberOfProcessors : 1); + double usage = (cpuSeconds / (elapsedSeconds * cores)) * 100.0; + if (usage < 0.0) + usage = 0.0; + return usage; +} +#endif diff --git a/applications/nodehub/stats.h b/applications/nodehub/stats.h new file mode 100644 index 0000000..62519fb --- /dev/null +++ b/applications/nodehub/stats.h @@ -0,0 +1,26 @@ +#pragma once + +#if defined(_WIN32) + +#include // For ULONGLONG, SIZE_T etc. + +struct MemoryUsageWin32 +{ + SIZE_T workingSet = 0; + SIZE_T privateBytes = 0; +}; + +struct CpuTimesWin32 +{ + ULONGLONG kernel = 0; + ULONGLONG user = 0; +}; + +MemoryUsageWin32 CaptureMemoryUsageWin32(); +void LogMemoryUsageWin32(const char *label, const MemoryUsageWin32 &usage); +CpuTimesWin32 CaptureCpuTimesWin32(); +double ComputeCpuUsagePercentWin32(const CpuTimesWin32 &begin, + const CpuTimesWin32 &end, + double elapsedSeconds); + +#endif diff --git a/applications/nodehub/types.h b/applications/nodehub/types.h new file mode 100644 index 0000000..183dec9 --- /dev/null +++ b/applications/nodehub/types.h @@ -0,0 +1,304 @@ +#pragma once +#include "commons.h" +#define IMGUI_DEFINE_MATH_OPERATORS +#include "utilities/uuid_generator.h" +#include +#include +#include + +#include // For ImRect +#include +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// +// v2 +//------------------------------------------------------------------------------ + +class NH_Parameter; +class NH_DependenciesContext { +public: + NH_DependenciesContext() {} + ~NH_DependenciesContext() {} +}; +//----------------------------------------------------------// +// Parameter type functions +//// +//----------------------------------------------------------// + +struct NH_PluginEntry; + +typedef NH_ERROR (*NH_PARAMETERCREATEDEFAULTFUNCTION)(NH_Parameter *); +typedef void (*NH_PARAMETERDELETEFUNCTION)(NH_Parameter *); +typedef void (*NH_PARAMETERCHECKFUNCTION)(NH_Parameter *); +typedef void (*NH_PARAMETERCOPYFUNCTION)(NH_Parameter *, NH_Parameter *); +typedef int (*NH_PARAMETERSTRINGFUNCTION)(NH_Parameter *param, + NH_STRING ValueString, + NH_BOOL ReadFromString); +typedef void (*NH_PARAMETERREMAPFUNCTION)(NH_Parameter *, + NH_DependenciesContext &); +/// typedef void (*NH_PARAMETERSAVELOADFUNCTION)(NH_Parameter* +/// param,NH_StateChunk **chunk,NH_BOOL load); +// typedef WIN_HANDLE (*NH_PARAMETERUICREATORFUNCTION)(NH_Parameter* +// param,WIN_HANDLE ParentWindow,CKRECT *rect); + +// for custom parameters, in use with CustomObjectParameterDialog +struct NH_CustomParameter { + int id; + const char *name; +}; +// if iIndex<0 || oObjec==0, the function shall return object count +// otherwise, shall return 0 if failed, 1 otherwise, +// adress of an existing instance of CKCustomParameter should be given +/// typedef int (*NH_PARAMETERGETCUSTOMOBJECTFUNCTION)(NH_Parameter* iParam,int +/// iIndex,NH_CustomParameter* ioObject); + +typedef struct NH_ParameterTypeDesc { + // Index in the parameter array (used internally) + NH_PARAMETER_TYPE Index; + // Glocal Unique identifier to identify this type + Uuid64 Guid; + // GUID of the parameter type from which this type is derivated + Uuid64 DerivedFrom; + // Name of this type + std::string TypeName; + // (used internally) + int Valid; + // Default size (in bytes) of parameters ofthis type + int DefaultSize; + // Creation function called each time a parameter of this type is created. + NH_PARAMETERCREATEDEFAULTFUNCTION CreateDefaultFunction; + // Deletion function called each time a parameter of this type is deleted. + NH_PARAMETERDELETEFUNCTION DeleteFunction; + // Function use to save or load parameters of this type. Only needed if + // special processing should be done during load and save operations. + /// NH_PARAMETERSAVELOADFUNCTION SaveLoadFunction; + // Function use to check parameters for object utilisation + NH_PARAMETERCHECKFUNCTION CheckFunction; + // Function use to copy the value from a parameter to another (Optionnal). + NH_PARAMETERCOPYFUNCTION CopyFunction; + // Function to convert a parameter to or from a string. + NH_PARAMETERSTRINGFUNCTION StringFunction; + // Function called to create the dialog box when editing this type of + // parameter. + /// NH_PARAMETERUICREATORFUNCTION UICreatorFunction; + + // An index to the registred Dlls from which this type was declared (used + // internally) + // NH_PluginEntry *CreatorDll; + // An application reserved DWORD for placing parameter type specific data. + NH_DWORD dwParam; + // Flags specifying special settings for this parameter type + // (CK_PARAMETERTYPE_FLAGS) + NH_DWORD dwFlags; + // Special case for parameter types that refer to CKObjects => corresponding + // class ID of the object + NH_DWORD Cid; + // Updated by parameter manager...: Bitmask for all class this type can be + // derived from directly or indirectly (used internally) + // XBitArray DerivationMask; + // Int Manager GUID + // Uuid64 Saver_Manager; + + // for custom parameters, in use with CustomObjectParameterDialog + // if iIndex<0 || oObjec==0, the function shall return object count + // otherwise, shall return 0 if failed, 1 otherwise, + // adress of an existing instance of CKCustomParameter should be given + /// NH_PARAMETERGETCUSTOMOBJECTFUNCTION GetCustomObjectFunction; + + NH_ParameterTypeDesc() : Cid(0), DefaultSize(0), Valid(0), dwParam(0), dwFlags(0) { + StringFunction = nullptr; + CreateDefaultFunction = nullptr; + DeleteFunction = nullptr; + CopyFunction = nullptr; + CheckFunction = nullptr; + } +} NH_ParameterTypeDesc; + +//------------------------------------------------------------------------------ +// +// Legacy code from imgui-node-editor +//------------------------------------------------------------------------------ + +namespace ed = ax::NodeEditor; + +template inline int ToRuntimeId(IdT id) { + const auto value = id.Get(); + return static_cast(value); +} + +// Return code constants +enum { + E_OK = 0, // Success return code + E_NOTIMPL, + E_ACCESSDENIED, + E_FAIL +}; + +// Forward declarations +class ParameterNode; +enum class ParameterDisplayMode; + +// Block display modes +enum class BlockDisplayMode { + NameOnly, // Just block name (compact) + NameAndParameters // Block name + parameter labels (default) +}; + +enum class PinType { + Flow, + Bool, + Int, + Float, + String, + Object, + Function, + Delegate, +}; + +enum class PinKind { Output, Input }; + +enum class NodeType { + Blueprint, + Simple, + Tree, + Comment, + Houdini, + Parameter, // Standalone parameter value node + Group // Group block node +}; + +struct Node; + +struct Pin { + ed::PinId ID; // Runtime ID (dynamic, for imgui-node-editor) + Uuid64 UUID; // Persistent ID (stable across sessions) + ::Node *Node; + std::string Name; + PinType Type; + PinKind Kind; + + // Position tracking (updated during rendering) + ImVec2 LastPivotPosition; // Where links connect (screen space) + ImRect LastRenderBounds; // Full pin area for hit testing + bool HasPositionData; // True after first render + + Pin(int id, const char *name, PinType type) + : ID(id), UUID(0, 0), Node(nullptr), Name(name), Type(type), + Kind(PinKind::Input), LastPivotPosition(0, 0), + LastRenderBounds(ImVec2(0, 0), ImVec2(0, 0)), HasPositionData(false) {} + + // Get pin position relative to its node (implementation after Node is + // defined) + ImVec2 GetRelativePivotPosition() const; +}; + +struct Node { + ed::NodeId ID; // Runtime ID (dynamic, for imgui-node-editor) + Uuid64 UUID; // Persistent ID (stable across sessions) + std::string Name; + std::vector Inputs; + std::vector Outputs; + ImColor Color; + NodeType Type; + ImVec2 Size; + + std::string State; + std::string SavedState; + + // Block metadata (only used when (Type == NodeType::Blueprint || Type == + // NodeType::Group) && IsBlockBased()) + std::string + BlockType; // e.g. "Math.Add" or "Group" - empty for hardcoded nodes + bool IsBlockBased() const { return !BlockType.empty(); } + ::BlockDisplayMode BlockDisplay; // Display mode for blocks + class Block *BlockInstance; // Block class instance (owns rendering logic) - + // ONLY set for block-based nodes + + // Safe getter for BlockInstance - returns nullptr for non-block nodes + // Full validation (ID match, node type) should be done at call site after + // including block.h + class Block *GetBlockInstance() const { + // Only return BlockInstance for actual block-based nodes + if (Type == NodeType::Parameter || !IsBlockBased()) + return nullptr; + return BlockInstance; + } + + // Parameter node metadata (only used when Type == NodeType::Parameter) + PinType ParameterType; + union { + bool BoolValue; + int IntValue; + float FloatValue; + }; + std::string StringValue; // For string parameters + ParameterNode *ParameterInstance; // Parameter class instance (owned by node) + // - ONLY set for parameter nodes + + // Safe getter for ParameterInstance - returns nullptr for non-parameter nodes + ParameterNode *GetParameterInstance() const { + // Only return ParameterInstance for actual parameter nodes + if (Type != NodeType::Parameter) + return nullptr; + return ParameterInstance; + } + + // Unconnected parameter values (for block input parameters) + // Maps pin ID -> value (stored as string, parsed based on pin type) + std::map UnconnectedParamValues; + + Node(int id, const char *name, ImColor color = ImColor(255, 255, 255)) + : ID(id), UUID(0, 0), Name(name), Color(color), Type(NodeType::Blueprint), + Size(0, 0), BlockType(""), + BlockDisplay(::BlockDisplayMode::NameAndParameters), + BlockInstance(nullptr), ParameterType(PinType::Float), FloatValue(0.0f), + StringValue(""), ParameterInstance(nullptr) {} +}; + +struct Link { + ed::LinkId ID; // Runtime ID (dynamic, for imgui-node-editor) + Uuid64 UUID; // Persistent ID (stable across sessions) + + ed::PinId StartPinID; + ed::PinId EndPinID; + + ImColor Color; + bool IsParameterLink; // True if parameter → block input (for styling) + bool UserManipulatedWaypoints; // True if user manually edited waypoints + // (preserve path, disable auto-adjust) + float Delay; // Custom delay unit (displayed on hover, editable via + // double-click) + + Link(ed::LinkId id, ed::PinId startPinId, ed::PinId endPinId) + : ID(id), UUID(0, 0), StartPinID(startPinId), EndPinID(endPinId), + Color(255, 255, 255), IsParameterLink(false), + UserManipulatedWaypoints(false), Delay(0.0f) {} +}; + +struct NodeIdLess { + bool operator()(const ed::NodeId &lhs, const ed::NodeId &rhs) const { + return lhs.AsPointer() < rhs.AsPointer(); + } +}; + +struct LinkIdLess { + bool operator()(const ed::LinkId &lhs, const ed::LinkId &rhs) const { + return lhs.AsPointer() < rhs.AsPointer(); + } +}; + +//------------------------------------------------------------------------------ +// Pin method implementations (after Node is fully defined) +//------------------------------------------------------------------------------ + +inline ImVec2 Pin::GetRelativePivotPosition() const { + if (Node && HasPositionData) { + ImVec2 nodePos = ed::GetNodePosition(Node->ID); + return LastPivotPosition - nodePos; + } + return ImVec2(0, 0); +} diff --git a/examples/blueprints-example/utilities/edge_editing.cpp b/applications/nodehub/utilities/edge_editing.cpp similarity index 100% rename from examples/blueprints-example/utilities/edge_editing.cpp rename to applications/nodehub/utilities/edge_editing.cpp diff --git a/examples/blueprints-example/utilities/edge_editing.h b/applications/nodehub/utilities/edge_editing.h similarity index 100% rename from examples/blueprints-example/utilities/edge_editing.h rename to applications/nodehub/utilities/edge_editing.h diff --git a/examples/blueprints-example/utilities/node_renderer_base.cpp b/applications/nodehub/utilities/node_renderer_base.cpp similarity index 100% rename from examples/blueprints-example/utilities/node_renderer_base.cpp rename to applications/nodehub/utilities/node_renderer_base.cpp diff --git a/examples/blueprints-example/utilities/node_renderer_base.h b/applications/nodehub/utilities/node_renderer_base.h similarity index 100% rename from examples/blueprints-example/utilities/node_renderer_base.h rename to applications/nodehub/utilities/node_renderer_base.h diff --git a/examples/blueprints-example/utilities/pathfinding.cpp b/applications/nodehub/utilities/pathfinding.cpp similarity index 100% rename from examples/blueprints-example/utilities/pathfinding.cpp rename to applications/nodehub/utilities/pathfinding.cpp diff --git a/examples/blueprints-example/utilities/pathfinding.h b/applications/nodehub/utilities/pathfinding.h similarity index 96% rename from examples/blueprints-example/utilities/pathfinding.h rename to applications/nodehub/utilities/pathfinding.h index a31da4e..2d884fd 100644 --- a/examples/blueprints-example/utilities/pathfinding.h +++ b/applications/nodehub/utilities/pathfinding.h @@ -4,7 +4,7 @@ #include // Forward declarations to avoid circular includes -namespace ax::NodeEditor { namespace Detail { class EditorContext; } } +namespace ax::NodeEditor { namespace Detail { struct EditorContext; } } class Container; // Forward declare enums (actual definitions in types.h) diff --git a/examples/blueprints-example/utilities/pin_renderer.cpp b/applications/nodehub/utilities/pin_renderer.cpp similarity index 96% rename from examples/blueprints-example/utilities/pin_renderer.cpp rename to applications/nodehub/utilities/pin_renderer.cpp index 8d43196..a4ffd61 100644 --- a/examples/blueprints-example/utilities/pin_renderer.cpp +++ b/applications/nodehub/utilities/pin_renderer.cpp @@ -138,7 +138,7 @@ void ParameterPinRenderer::Render( // Unconnected: get default value from node if (pin.Node) { - int pinId = pin.ID.Get(); + const int pinId = ToRuntimeId(pin.ID); auto& paramValues = pin.Node->UnconnectedParamValues; if (paramValues.find(pinId) != paramValues.end()) { diff --git a/examples/blueprints-example/utilities/pin_renderer.h b/applications/nodehub/utilities/pin_renderer.h similarity index 100% rename from examples/blueprints-example/utilities/pin_renderer.h rename to applications/nodehub/utilities/pin_renderer.h diff --git a/examples/blueprints-example/utilities/style_manager.cpp b/applications/nodehub/utilities/style_manager.cpp similarity index 97% rename from examples/blueprints-example/utilities/style_manager.cpp rename to applications/nodehub/utilities/style_manager.cpp index 71a989c..d8b79d9 100644 --- a/examples/blueprints-example/utilities/style_manager.cpp +++ b/applications/nodehub/utilities/style_manager.cpp @@ -1,5 +1,5 @@ #include "style_manager.h" -#include "../../crude_json.h" +#include #include #include #include diff --git a/examples/blueprints-example/utilities/style_manager.h b/applications/nodehub/utilities/style_manager.h similarity index 100% rename from examples/blueprints-example/utilities/style_manager.h rename to applications/nodehub/utilities/style_manager.h diff --git a/examples/blueprints-example/utilities/uuid_generator.cpp b/applications/nodehub/utilities/uuid_generator.cpp similarity index 100% rename from examples/blueprints-example/utilities/uuid_generator.cpp rename to applications/nodehub/utilities/uuid_generator.cpp diff --git a/examples/blueprints-example/utilities/uuid_generator.h b/applications/nodehub/utilities/uuid_generator.h similarity index 94% rename from examples/blueprints-example/utilities/uuid_generator.h rename to applications/nodehub/utilities/uuid_generator.h index 213fa9c..681b56f 100644 --- a/examples/blueprints-example/utilities/uuid_generator.h +++ b/applications/nodehub/utilities/uuid_generator.h @@ -16,8 +16,8 @@ struct Uuid64 uint32_t high; // Upper 32 bits uint32_t low; // Lower 32 bits - Uuid64() : high(0), low(0) {} - Uuid64(uint32_t h, uint32_t l) : high(h), low(l) {} + constexpr Uuid64() : high(0), low(0) {} + constexpr Uuid64(uint32_t h, uint32_t l) : high(h), low(l) {} // Comparison operators for use in maps/sets (highly optimized) bool operator==(const Uuid64& other) const { return high == other.high && low == other.low; } diff --git a/examples/blueprints-example/utilities/uuid_id_manager.cpp b/applications/nodehub/utilities/uuid_id_manager.cpp similarity index 100% rename from examples/blueprints-example/utilities/uuid_id_manager.cpp rename to applications/nodehub/utilities/uuid_id_manager.cpp diff --git a/examples/blueprints-example/utilities/uuid_id_manager.h b/applications/nodehub/utilities/uuid_id_manager.h similarity index 100% rename from examples/blueprints-example/utilities/uuid_id_manager.h rename to applications/nodehub/utilities/uuid_id_manager.h diff --git a/applications/protos/CMakeLists.txt b/applications/protos/CMakeLists.txt new file mode 100644 index 0000000..fe16aa6 --- /dev/null +++ b/applications/protos/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required(VERSION 3.5) + +project(nodehub_protos) + +set(CMAKE_CXX_STANDARD 17) + +find_package(Protobuf REQUIRED) + +# Define proto files and output directory +set(PROTO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/parameter.proto") +set(PROTO_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated") +file(MAKE_DIRECTORY ${PROTO_GEN_DIR}) + +# Generate C++ sources +protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES}) + +# Create a library from the generated sources +add_library(protos ${PROTO_SRCS}) +target_include_directories(protos PUBLIC ${PROTO_GEN_DIR} ${Protobuf_INCLUDE_DIRS}) +target_link_libraries(protos PUBLIC protobuf::libprotobuf) + +# Make generated headers available to other targets +target_include_directories(protos INTERFACE $) diff --git a/applications/protos/parameter.proto b/applications/protos/parameter.proto new file mode 100644 index 0000000..2f6f64d --- /dev/null +++ b/applications/protos/parameter.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package nodehub; + +message ParameterValue { + oneof value { + int32 int_val = 1; + float float_val = 2; + bool bool_val = 3; + string string_val = 4; + } +} diff --git a/applications/tests/CMakeLists.txt b/applications/tests/CMakeLists.txt new file mode 100644 index 0000000..4e0b6e2 --- /dev/null +++ b/applications/tests/CMakeLists.txt @@ -0,0 +1,106 @@ +# Define the test project +project(NodeEditorTests) + +# Custom target to generate protobuf files +add_custom_target(generate_protos + COMMAND sh ${IMGUI_NODE_EDITOR_ROOT_DIR}/scripts/generate_protos.sh + WORKING_DIRECTORY ${IMGUI_NODE_EDITOR_ROOT_DIR} + COMMENT "Generating protobuf files" +) + +# Create the executable for the tests + +set(CORE_TESTS_SOURCES + "../nodehub/app.cpp" + "../nodehub/app-logic.cpp" + "../nodehub/app-render.cpp" + "../nodehub/app-screenshot.cpp" + "../nodehub/app-runtime.cpp" + "../nodehub/containers/container.cpp" + "../nodehub/containers/root_container.cpp" + "../nodehub/core/graph_state.cpp" + "../nodehub/core/Object.cpp" + "../nodehub/core/Parameter.cpp" + "../nodehub/core/ParameterIn.cpp" + "../nodehub/core/ParameterOut.cpp" + "../nodehub/core/ParameterManager.cpp" + "../nodehub/core/BaseManager.cpp" + "../nodehub/core/Context.cpp" + "../nodehub/blocks/NodeEx.cpp" + "../nodehub/blocks/block.cpp" + "../nodehub/blocks/math_blocks.cpp" + "../nodehub/blocks/logic_blocks.cpp" + "../nodehub/blocks/start_block.cpp" + "../nodehub/blocks/log_block.cpp" + "../nodehub/blocks/parameter_operation.cpp" + "../nodehub/blocks/group_block.cpp" + "../nodehub/blocks/parameter_node.cpp" + "../nodehub/blocks/block_edit_dialog.cpp" + "../nodehub/blocks/parameter_edit_dialog.cpp" + "../nodehub/utilities/node_renderer_base.cpp" + "../nodehub/utilities/pathfinding.cpp" + "../nodehub/utilities/edge_editing.cpp" + "../nodehub/utilities/pin_renderer.cpp" + "../nodehub/utilities/style_manager.cpp" + "../nodehub/utilities/uuid_generator.cpp" + "../nodehub/utilities/uuid_id_manager.cpp" + "../nodehub/Logging.cpp" + "../nodehub/stats.cpp" + "main-test.cpp" + "commons-test.cpp" + "block_test.cpp" + "parameter_test.cpp" +) + +if (PROTOBUF_AVAILABLE) + # list(APPEND CORE_TESTS_SOURCES "protobuf_test.cpp") +endif() + +add_executable(core_tests ${CORE_TESTS_SOURCES}) + +# Add dependency to ensure protos are generated before building the tests +add_dependencies(core_tests generate_protos) + +# Add /utf-8 compiler flag for spdlog on MSVC +if (MSVC) + target_compile_options(core_tests PRIVATE /utf-8) +endif() + +# Add definitions to match the main application +target_compile_definitions(core_tests PRIVATE FMT_HEADER_ONLY=1) + +# Add include directories to find project headers +target_include_directories(core_tests PRIVATE + "${CMAKE_SOURCE_DIR}" + "${CMAKE_SOURCE_DIR}/base/include" + "${CMAKE_SOURCE_DIR}/nodehub" + "${CMAKE_CURRENT_SOURCE_DIR}/protos" +) + +# Link libraries +target_link_libraries(core_tests + PRIVATE + gtest_main + imgui_node_editor + base + imgui +) + +# Link protobuf if available +if (PROTOBUF_AVAILABLE AND TARGET protobuf_interface) + target_link_libraries(core_tests PRIVATE protobuf_interface) + + # Generate protobuf sources for testing + set(TEST_PROTO_FILES "${CMAKE_CURRENT_SOURCE_DIR}/test_primitives.proto") + protobuf_generate_cpp(TEST_PROTO_SRCS TEST_PROTO_HDRS ${TEST_PROTO_FILES}) + + # Add generated files to executable + target_sources(core_tests PRIVATE ${TEST_PROTO_SRCS}) + + # Include generated directory + target_include_directories(core_tests PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") +endif() + +# Enable test discovery for CTest +include(GoogleTest) +gtest_discover_tests(core_tests) diff --git a/applications/tests/block_test.cpp b/applications/tests/block_test.cpp new file mode 100644 index 0000000..090dec8 --- /dev/null +++ b/applications/tests/block_test.cpp @@ -0,0 +1,42 @@ +#include "commons-test.h" +#include "blocks/block.h" +#include "types.h" // Include for the application's Node struct + +/// A mock block class that inherits from ParameterizedBlock, just like real blocks. +class MockBlock : public ParameterizedBlock +{ +public: + MockBlock(int id) : ParameterizedBlock(id, "MockBlock") {} + + // Implement the remaining pure virtual functions. + // 'Render' is already implemented by ParameterizedBlock. + void Build(Node& node, App* app) override {} + NH_CSTRING GetBlockType() const override { return "MockBlockType"; } +}; + +// Test fixture for BlockRegistry tests. +// Inherits from AppTest to get a valid App instance, though this specific test doesn't use it. +class BlockRegistryTest : public AppTest +{}; + +TEST_F(BlockRegistryTest, RegistrationAndCreation) +{ + auto& registry = BlockRegistry::Instance(); + const char* mockBlockTypeName = "MyMockBlock"; + + // Register our mock block + registry.RegisterBlock(mockBlockTypeName, [](int id) -> Block* { + return new MockBlock(id); + }); + + // Attempt to create the registered block + Block* createdBlock = registry.CreateBlock(mockBlockTypeName, 42); + ASSERT_NE(createdBlock, nullptr) << "Block creation failed for a registered type."; + EXPECT_EQ(createdBlock->GetID(), 42); + EXPECT_STREQ(createdBlock->GetBlockType(), "MockBlockType"); + delete createdBlock; + + // Attempt to create a non-existent block + Block* nonExistentBlock = registry.CreateBlock("NonExistentBlock", 100); + EXPECT_EQ(nonExistentBlock, nullptr) << "Block creation should fail for an unregistered type."; +} diff --git a/applications/tests/commons-test.cpp b/applications/tests/commons-test.cpp new file mode 100644 index 0000000..b58c3aa --- /dev/null +++ b/applications/tests/commons-test.cpp @@ -0,0 +1,16 @@ +#include "commons-test.h" +#include "base.h" // For g_Application + +void AppTest::SetUp() +{ + // Create an App instance with an empty argument map. + // The Application constructor will set g_Application = this. + // This mimics the setup in entry_point.cpp without creating a window. + m_App = std::make_unique("TestApp", ArgsMap{}); +} + +void AppTest::TearDown() +{ + m_App.reset(); + g_Application = nullptr; +} diff --git a/applications/tests/commons-test.h b/applications/tests/commons-test.h new file mode 100644 index 0000000..0230d18 --- /dev/null +++ b/applications/tests/commons-test.h @@ -0,0 +1,19 @@ +#pragma once +#include "gtest/gtest.h" +#include "app.h" +#include "core/Context.h" + +#include + +// A base test fixture that provides a valid `App` instance for testing. +// This avoids creating windows or a renderer, making it suitable for unit/functional tests. +class AppTest : public ::testing::Test +{ +protected: + void SetUp() override; + void TearDown() override; + + // Use a unique_ptr to manage the lifetime of the app instance. + // It's a pointer to App, not Application, to allow access to NodeHub-specific functionality. + std::unique_ptr m_App; +}; diff --git a/applications/tests/main-test.cpp b/applications/tests/main-test.cpp new file mode 100644 index 0000000..49f9967 --- /dev/null +++ b/applications/tests/main-test.cpp @@ -0,0 +1,10 @@ +#include "base.h" + +// This is a stub implementation of the application's Main() function. +// It is required to resolve linker errors when building the test suite, +// as the test scaffolding pulls in the entire application framework which +// expects this function to exist. It will not be called during test execution. +int Main(const ArgsMap& args) +{ + return 0; +} diff --git a/applications/tests/parameter_test.cpp b/applications/tests/parameter_test.cpp new file mode 100644 index 0000000..71f05bb --- /dev/null +++ b/applications/tests/parameter_test.cpp @@ -0,0 +1,140 @@ +#include "commons-test.h" +#include "core/ParameterIn.h" +#include "core/ParameterOut.h" +#include "core/Context.h" +#include "enums.h" + +// Test fixture for Parameter tests +class ParameterTest : public AppTest {}; + +TEST_F(ParameterTest, CreateParameters) { + ASSERT_NE(m_App, nullptr); + auto* context = m_App->GetContext(); + ASSERT_NE(context, nullptr); + + // Create an output parameter + auto* p_out = context->CreateParameterOut("MyFloatOut", NHP_GUID_FLOAT); + ASSERT_NE(p_out, nullptr); + EXPECT_STREQ(p_out->GetName(), "MyFloatOut"); + EXPECT_EQ(p_out->GetClassID(), NHCID_PARAMETEROUT); + + // Create an input parameter + auto* p_in = context->CreateParameterIn("MyFloatIn", NHP_GUID_FLOAT); + ASSERT_NE(p_in, nullptr); + EXPECT_STREQ(p_in->GetName(), "MyFloatIn"); + EXPECT_EQ(p_in->GetClassID(), NHCID_PARAMETERIN); + + delete p_out; + delete p_in; +} + +TEST_F(ParameterTest, LinkParametersAndGetValue) { + ASSERT_NE(m_App, nullptr); + auto* context = m_App->GetContext(); + ASSERT_NE(context, nullptr); + + // 1. Create parameters + auto* p_out = context->CreateParameterOut("SourceFloat", NHP_GUID_FLOAT); + auto* p_in = context->CreateParameterIn("DestFloat", NHP_GUID_FLOAT); + + // 2. Set a value on the output parameter + float out_value = 3.14f; + p_out->SetValue(&out_value, sizeof(float)); + + // 3. Link the input parameter to the output parameter + p_in->SetDirectSource(p_out); + + // 4. Get the value from the input parameter + float in_value = 0.0f; + p_in->GetValue(&in_value); + + // 5. Verify the value is correct + EXPECT_FLOAT_EQ(in_value, out_value); + + // 6. Test GetReadDataPtr + void* data_ptr = p_in->GetReadDataPtr(); + ASSERT_NE(data_ptr, nullptr); + EXPECT_FLOAT_EQ(*(static_cast(data_ptr)), out_value); + + delete p_out; + delete p_in; +} + +TEST_F(ParameterTest, OutputToMultipleInputs) { + ASSERT_NE(m_App, nullptr); + auto* context = m_App->GetContext(); + ASSERT_NE(context, nullptr); + + // 1. Create one output and multiple input parameters + auto* p_out = context->CreateParameterOut("SourceFloat", NHP_GUID_FLOAT); + auto* p_in1 = context->CreateParameterIn("DestFloat1", NHP_GUID_FLOAT); + auto* p_in2 = context->CreateParameterIn("DestFloat2", NHP_GUID_FLOAT); + auto* p_in3 = context->CreateParameterIn("DestFloat3", NHP_GUID_FLOAT); + + // 2. Set a value on the output parameter + float out_value = 42.0f; + p_out->SetValue(&out_value, sizeof(float)); + + // 3. Link all input parameters to the single output parameter + p_in1->SetDirectSource(p_out); + p_in2->SetDirectSource(p_out); + p_in3->SetDirectSource(p_out); + + // 4. Verify the value for all inputs + float in_value1 = 0.0f, in_value2 = 0.0f, in_value3 = 0.0f; + p_in1->GetValue(&in_value1); + p_in2->GetValue(&in_value2); + p_in3->GetValue(&in_value3); + + EXPECT_FLOAT_EQ(in_value1, out_value); + EXPECT_FLOAT_EQ(in_value2, out_value); + EXPECT_FLOAT_EQ(in_value3, out_value); + + delete p_out; + delete p_in1; + delete p_in2; + delete p_in3; +} + +TEST_F(ParameterTest, SingleSourceForInput) { + ASSERT_NE(m_App, nullptr); + auto* context = m_App->GetContext(); + ASSERT_NE(context, nullptr); + + // 1. Create multiple source parameters and inputs + auto* p_out1 = context->CreateParameterOut("Source1", NHP_GUID_INT); + auto* p_out2 = context->CreateParameterOut("Source2", NHP_GUID_INT); + auto* p_in1 = context->CreateParameterIn("Input1", NHP_GUID_INT); + auto* p_in2 = context->CreateParameterIn("Input2", NHP_GUID_INT); + + int val1 = 111, val2 = 222; + p_out1->SetValue(&val1, sizeof(int)); + p_out2->SetValue(&val2, sizeof(int)); + + // 2. Link p_in2 to p_out2 + p_in2->SetDirectSource(p_out2); + EXPECT_EQ(p_in2->GetRealSource(), p_out2); + + // 3. Link p_in1 to p_out1 initially + p_in1->SetDirectSource(p_out1); + EXPECT_EQ(p_in1->GetRealSource(), p_out1); + EXPECT_EQ(p_in1->GetSharedSource(), nullptr); + + // 4. Now, share p_in1 with p_in2. This should override the direct source. + p_in1->ShareSourceWith(p_in2); + EXPECT_EQ(p_in1->GetDirectSource(), nullptr); + EXPECT_EQ(p_in1->GetSharedSource(), p_in2); + + // 5. The real source of p_in1 should now be p_out2 (through p_in2) + EXPECT_EQ(p_in1->GetRealSource(), p_out2); + + // 6. Verify the value comes from the new real source + int in_value = 0; + p_in1->GetValue(&in_value); + EXPECT_EQ(in_value, val2); + + delete p_out1; + delete p_out2; + delete p_in1; + delete p_in2; +} diff --git a/applications/tests/protobuf_test.cpp b/applications/tests/protobuf_test.cpp new file mode 100644 index 0000000..627771f --- /dev/null +++ b/applications/tests/protobuf_test.cpp @@ -0,0 +1,100 @@ +#include "commons-test.h" +#include "core/ParameterOut.h" +#include "enums.h" +#include "protos/test_primitives.pb.h" // Generated protobuf header + +// Test fixture for Protobuf tests +class ProtobufTest : public AppTest {}; + +TEST_F(ProtobufTest, IntSerialization) { + auto* context = m_App->GetContext(); + auto* p_out = context->CreateParameterOut("MyInt", NHP_GUID_INT); + + int out_value = 12345; + p_out->SetValue(&out_value); + + // Serialize + nodehub::primitives::IntValue proto_msg; + proto_msg.set_value(*(int*)p_out->GetReadDataPtr()); + std::string serialized_data; + ASSERT_TRUE(proto_msg.SerializeToString(&serialized_data)); + + // Deserialize + nodehub::primitives::IntValue new_proto_msg; + ASSERT_TRUE(new_proto_msg.ParseFromString(serialized_data)); + + // Verify + EXPECT_EQ(new_proto_msg.value(), out_value); + + delete p_out; +} + +TEST_F(ProtobufTest, FloatSerialization) { + auto* context = m_App->GetContext(); + auto* p_out = context->CreateParameterOut("MyFloat", NHP_GUID_FLOAT); + + float out_value = 3.14f; + p_out->SetValue(&out_value); + + // Serialize + nodehub::primitives::FloatValue proto_msg; + proto_msg.set_value(*(float*)p_out->GetReadDataPtr()); + std::string serialized_data; + ASSERT_TRUE(proto_msg.SerializeToString(&serialized_data)); + + // Deserialize + nodehub::primitives::FloatValue new_proto_msg; + ASSERT_TRUE(new_proto_msg.ParseFromString(serialized_data)); + + // Verify + EXPECT_FLOAT_EQ(new_proto_msg.value(), out_value); + + delete p_out; +} + +TEST_F(ProtobufTest, BoolSerialization) { + auto* context = m_App->GetContext(); + auto* p_out = context->CreateParameterOut("MyBool", NHP_GUID_BOOL); + + bool out_value = true; + p_out->SetValue(&out_value); + + // Serialize + nodehub::primitives::BoolValue proto_msg; + proto_msg.set_value(*(bool*)p_out->GetReadDataPtr()); + std::string serialized_data; + ASSERT_TRUE(proto_msg.SerializeToString(&serialized_data)); + + // Deserialize + nodehub::primitives::BoolValue new_proto_msg; + ASSERT_TRUE(new_proto_msg.ParseFromString(serialized_data)); + + // Verify + EXPECT_EQ(new_proto_msg.value(), out_value); + + delete p_out; +} + +TEST_F(ProtobufTest, StringSerialization) { + auto* context = m_App->GetContext(); + auto* p_out = context->CreateParameterOut("MyString", NHP_GUID_STRING); + + const char* out_value = "Hello, Protobuf!"; + p_out->SetValue(out_value, strlen(out_value) + 1); + + // Serialize + nodehub::primitives::StringValue proto_msg; + proto_msg.set_value((char*)p_out->GetReadDataPtr()); + std::string serialized_data; + ASSERT_TRUE(proto_msg.SerializeToString(&serialized_data)); + + // Deserialize + nodehub::primitives::StringValue new_proto_msg; + ASSERT_TRUE(new_proto_msg.ParseFromString(serialized_data)); + + // Verify + EXPECT_STREQ(new_proto_msg.value().c_str(), out_value); + + delete p_out; +} + diff --git a/applications/tests/protos/parameter.pb.cc b/applications/tests/protos/parameter.pb.cc new file mode 100644 index 0000000..533338f --- /dev/null +++ b/applications/tests/protos/parameter.pb.cc @@ -0,0 +1,494 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: parameter.proto +// Protobuf C++ Version: 6.34.0-dev + +#include "parameter.pb.h" + +#include +#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/internal_visibility.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" +// @@protoc_insertion_point(includes) + +// Must be included last. +#include "google/protobuf/port_def.inc" +PROTOBUF_PRAGMA_INIT_SEG +namespace _pb = ::google::protobuf; +namespace _pbi = ::google::protobuf::internal; +namespace _fl = ::google::protobuf::internal::field_layout; +namespace nodehub { + +inline constexpr ParameterValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + ::_pbi::ConstantInitialized) noexcept + : value_{}, + _cached_size_{0}, + _oneof_case_{} {} + +template +PROTOBUF_CONSTEXPR ParameterValue::ParameterValue(::_pbi::ConstantInitialized) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(ParameterValue_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(internal_visibility(), ::_pbi::ConstantInitialized()) { +} +struct ParameterValueDefaultTypeInternal { + PROTOBUF_CONSTEXPR ParameterValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~ParameterValueDefaultTypeInternal() {} + union { + ParameterValue _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ParameterValueDefaultTypeInternal _ParameterValue_default_instance_; +} // namespace nodehub +static constexpr const ::_pb::EnumDescriptor* PROTOBUF_NONNULL* PROTOBUF_NULLABLE + file_level_enum_descriptors_parameter_2eproto = nullptr; +static constexpr const ::_pb::ServiceDescriptor* PROTOBUF_NONNULL* PROTOBUF_NULLABLE + file_level_service_descriptors_parameter_2eproto = nullptr; +const ::uint32_t + TableStruct_parameter_2eproto::offsets[] ABSL_ATTRIBUTE_SECTION_VARIABLE( + protodesc_cold) = { + 0x004, // bitmap + PROTOBUF_FIELD_OFFSET(::nodehub::ParameterValue, _impl_._oneof_case_[0]), + PROTOBUF_FIELD_OFFSET(::nodehub::ParameterValue, _impl_.value_), + PROTOBUF_FIELD_OFFSET(::nodehub::ParameterValue, _impl_.value_), + PROTOBUF_FIELD_OFFSET(::nodehub::ParameterValue, _impl_.value_), + PROTOBUF_FIELD_OFFSET(::nodehub::ParameterValue, _impl_.value_), + PROTOBUF_FIELD_OFFSET(::nodehub::ParameterValue, _impl_.value_), +}; + +static const ::_pbi::MigrationSchema + schemas[] ABSL_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + {0, sizeof(::nodehub::ParameterValue)}, +}; +static const ::_pb::Message* PROTOBUF_NONNULL const file_default_instances[] = { + &::nodehub::_ParameterValue_default_instance_._instance, +}; +const char descriptor_table_protodef_parameter_2eproto[] ABSL_ATTRIBUTE_SECTION_VARIABLE( + protodesc_cold) = { + "\n\017parameter.proto\022\007nodehub\"k\n\016ParameterV" + "alue\022\021\n\007int_val\030\001 \001(\005H\000\022\023\n\tfloat_val\030\002 \001" + "(\002H\000\022\022\n\010bool_val\030\003 \001(\010H\000\022\024\n\nstring_val\030\004" + " \001(\tH\000B\007\n\005valueb\006proto3" +}; +static ::absl::once_flag descriptor_table_parameter_2eproto_once; +PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_parameter_2eproto = { + false, + false, + 143, + descriptor_table_protodef_parameter_2eproto, + "parameter.proto", + &descriptor_table_parameter_2eproto_once, + nullptr, + 0, + 1, + schemas, + file_default_instances, + TableStruct_parameter_2eproto::offsets, + file_level_enum_descriptors_parameter_2eproto, + file_level_service_descriptors_parameter_2eproto, +}; +namespace nodehub { +// =================================================================== + +class ParameterValue::_Internal { + public: + static constexpr ::int32_t kOneofCaseOffset = + PROTOBUF_FIELD_OFFSET(::nodehub::ParameterValue, _impl_._oneof_case_); +}; + +ParameterValue::ParameterValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, ParameterValue_class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:nodehub.ParameterValue) +} +PROTOBUF_NDEBUG_INLINE ParameterValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + [[maybe_unused]] ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const Impl_& from, + [[maybe_unused]] const ::nodehub::ParameterValue& from_msg) + : value_{}, + _cached_size_{0}, + _oneof_case_{from._oneof_case_[0]} {} + +ParameterValue::ParameterValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, + const ParameterValue& from) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, ParameterValue_class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + ParameterValue* const _this = this; + (void)_this; + _internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); + new (&_impl_) Impl_(internal_visibility(), arena, from._impl_, from); + switch (value_case()) { + case VALUE_NOT_SET: + break; + case kIntVal: + _impl_.value_.int_val_ = from._impl_.value_.int_val_; + break; + case kFloatVal: + _impl_.value_.float_val_ = from._impl_.value_.float_val_; + break; + case kBoolVal: + _impl_.value_.bool_val_ = from._impl_.value_.bool_val_; + break; + case kStringVal: + new (&_impl_.value_.string_val_) decltype(_impl_.value_.string_val_){arena, from._impl_.value_.string_val_}; + break; + } + + // @@protoc_insertion_point(copy_constructor:nodehub.ParameterValue) +} +PROTOBUF_NDEBUG_INLINE ParameterValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + [[maybe_unused]] ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) + : value_{}, + _cached_size_{0}, + _oneof_case_{} {} + +inline void ParameterValue::SharedCtor(::_pb::Arena* PROTOBUF_NULLABLE arena) { + new (&_impl_) Impl_(internal_visibility(), arena); +} +ParameterValue::~ParameterValue() { + // @@protoc_insertion_point(destructor:nodehub.ParameterValue) + SharedDtor(*this); +} +inline void ParameterValue::SharedDtor(MessageLite& self) { + ParameterValue& this_ = static_cast(self); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + this_._internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>(); + ABSL_DCHECK(this_.GetArena() == nullptr); + if (this_.has_value()) { + this_.clear_value(); + } + this_._impl_.~Impl_(); +} + +void ParameterValue::clear_value() { +// @@protoc_insertion_point(one_of_clear_start:nodehub.ParameterValue) + ::google::protobuf::internal::TSanWrite(&_impl_); + switch (value_case()) { + case kIntVal: { + // No need to clear + break; + } + case kFloatVal: { + // No need to clear + break; + } + case kBoolVal: { + // No need to clear + break; + } + case kStringVal: { + _impl_.value_.string_val_.Destroy(); + break; + } + case VALUE_NOT_SET: { + break; + } + } + _impl_._oneof_case_[0] = VALUE_NOT_SET; +} + + +inline void* PROTOBUF_NONNULL ParameterValue::PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) { + return ::new (mem) ParameterValue(arena); +} +constexpr auto ParameterValue::InternalNewImpl_() { + return ::google::protobuf::internal::MessageCreator::ZeroInit(sizeof(ParameterValue), + alignof(ParameterValue)); +} +constexpr auto ParameterValue::InternalGenerateClassData_() { + return ::google::protobuf::internal::ClassDataFull{ + ::google::protobuf::internal::ClassData{ + &_ParameterValue_default_instance_._instance, + &_table_.header, + nullptr, // OnDemandRegisterArenaDtor + nullptr, // IsInitialized + &ParameterValue::MergeImpl, + ::google::protobuf::Message::GetNewImpl(), +#if defined(PROTOBUF_CUSTOM_VTABLE) + &ParameterValue::SharedDtor, + ::google::protobuf::Message::GetClearImpl(), &ParameterValue::ByteSizeLong, + &ParameterValue::_InternalSerialize, +#endif // PROTOBUF_CUSTOM_VTABLE + PROTOBUF_FIELD_OFFSET(ParameterValue, _impl_._cached_size_), + false, + }, + &ParameterValue::kDescriptorMethods, + &descriptor_table_parameter_2eproto, + nullptr, // tracker + }; +} + +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 const + ::google::protobuf::internal::ClassDataFull ParameterValue_class_data_ = + ParameterValue::InternalGenerateClassData_(); + +PROTOBUF_ATTRIBUTE_WEAK const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL +ParameterValue::GetClassData() const { + ::google::protobuf::internal::PrefetchToLocalCache(&ParameterValue_class_data_); + ::google::protobuf::internal::PrefetchToLocalCache(ParameterValue_class_data_.tc_table); + return ParameterValue_class_data_.base(); +} +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::_pbi::TcParseTable<0, 4, 0, 41, 2> +ParameterValue::_table_ = { + { + PROTOBUF_FIELD_OFFSET(ParameterValue, + _impl_._cached_size_), // no hasbits + 0, // no _extensions_ + 4, 0, // max_field_number, fast_idx_mask + offsetof(decltype(_table_), field_lookup_table), + 4294967280, // skipmap + offsetof(decltype(_table_), field_entries), + 4, // num_field_entries + 0, // num_aux_entries + offsetof(decltype(_table_), field_names), // no aux_entries + ParameterValue_class_data_.base(), + nullptr, // post_loop_handler + ::_pbi::TcParser::GenericFallback, // fallback + #ifdef PROTOBUF_PREFETCH_PARSE_TABLE + ::_pbi::TcParser::GetTable<::nodehub::ParameterValue>(), // to_prefetch + #endif // PROTOBUF_PREFETCH_PARSE_TABLE + }, {{ + {::_pbi::TcParser::MiniParse, {}}, + }}, {{ + 65535, 65535 + }}, {{ + // int32 int_val = 1; + {PROTOBUF_FIELD_OFFSET(ParameterValue, _impl_.value_.int_val_), _Internal::kOneofCaseOffset + 0, 0, (0 | ::_fl::kFcOneof | ::_fl::kInt32)}, + // float float_val = 2; + {PROTOBUF_FIELD_OFFSET(ParameterValue, _impl_.value_.float_val_), _Internal::kOneofCaseOffset + 0, 0, (0 | ::_fl::kFcOneof | ::_fl::kFloat)}, + // bool bool_val = 3; + {PROTOBUF_FIELD_OFFSET(ParameterValue, _impl_.value_.bool_val_), _Internal::kOneofCaseOffset + 0, 0, (0 | ::_fl::kFcOneof | ::_fl::kBool)}, + // string string_val = 4; + {PROTOBUF_FIELD_OFFSET(ParameterValue, _impl_.value_.string_val_), _Internal::kOneofCaseOffset + 0, 0, (0 | ::_fl::kFcOneof | ::_fl::kUtf8String | ::_fl::kRepAString)}, + }}, + // no aux_entries + {{ + "\26\0\0\0\12\0\0\0" + "nodehub.ParameterValue" + "string_val" + }}, +}; +PROTOBUF_NOINLINE void ParameterValue::Clear() { +// @@protoc_insertion_point(message_clear_start:nodehub.ParameterValue) + ::google::protobuf::internal::TSanWrite(&_impl_); + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + clear_value(); + _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::uint8_t* PROTOBUF_NONNULL ParameterValue::_InternalSerialize( + const ::google::protobuf::MessageLite& base, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) { + const ParameterValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::uint8_t* PROTOBUF_NONNULL ParameterValue::_InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + const ParameterValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(serialize_to_array_start:nodehub.ParameterValue) + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + switch (this_.value_case()) { + case kIntVal: { + target = + ::google::protobuf::internal::WireFormatLite::WriteInt32ToArrayWithField<1>( + stream, this_._internal_int_val(), target); + break; + } + case kFloatVal: { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteFloatToArray( + 2, this_._internal_float_val(), target); + break; + } + case kBoolVal: { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray( + 3, this_._internal_bool_val(), target); + break; + } + case kStringVal: { + const ::std::string& _s = this_._internal_string_val(); + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + _s.data(), static_cast(_s.length()), ::google::protobuf::internal::WireFormatLite::SERIALIZE, "nodehub.ParameterValue.string_val"); + target = stream->WriteStringMaybeAliased(4, _s, target); + break; + } + default: + break; + } + if (ABSL_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { + target = + ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + this_._internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:nodehub.ParameterValue) + return target; +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::size_t ParameterValue::ByteSizeLong(const MessageLite& base) { + const ParameterValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::size_t ParameterValue::ByteSizeLong() const { + const ParameterValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(message_byte_size_start:nodehub.ParameterValue) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + switch (this_.value_case()) { + // int32 int_val = 1; + case kIntVal: { + total_size += ::_pbi::WireFormatLite::Int32SizePlusOne( + this_._internal_int_val()); + break; + } + // float float_val = 2; + case kFloatVal: { + total_size += 5; + break; + } + // bool bool_val = 3; + case kBoolVal: { + total_size += 2; + break; + } + // string string_val = 4; + case kStringVal: { + total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( + this_._internal_string_val()); + break; + } + case VALUE_NOT_SET: { + break; + } + } + return this_.MaybeComputeUnknownFieldsSize(total_size, + &this_._impl_._cached_size_); +} + +void ParameterValue::MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg) { + auto* const _this = + static_cast(&to_msg); + auto& from = static_cast(from_msg); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + from.CheckHasBitConsistency(); + } + ::google::protobuf::Arena* arena = _this->GetArena(); + // @@protoc_insertion_point(class_specific_merge_from_start:nodehub.ParameterValue) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + if (const uint32_t oneof_from_case = + from._impl_._oneof_case_[0]) { + const uint32_t oneof_to_case = _this->_impl_._oneof_case_[0]; + const bool oneof_needs_init = oneof_to_case != oneof_from_case; + if (oneof_needs_init) { + if (oneof_to_case != 0) { + _this->clear_value(); + } + _this->_impl_._oneof_case_[0] = oneof_from_case; + } + + switch (oneof_from_case) { + case kIntVal: { + _this->_impl_.value_.int_val_ = from._impl_.value_.int_val_; + break; + } + case kFloatVal: { + _this->_impl_.value_.float_val_ = from._impl_.value_.float_val_; + break; + } + case kBoolVal: { + _this->_impl_.value_.bool_val_ = from._impl_.value_.bool_val_; + break; + } + case kStringVal: { + if (oneof_needs_init) { + _this->_impl_.value_.string_val_.InitDefault(); + } + _this->_impl_.value_.string_val_.Set(from._internal_string_val(), arena); + break; + } + case VALUE_NOT_SET: + break; + } + } + _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); +} + +void ParameterValue::CopyFrom(const ParameterValue& from) { + // @@protoc_insertion_point(class_specific_copy_from_start:nodehub.ParameterValue) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + + +void ParameterValue::InternalSwap(ParameterValue* PROTOBUF_RESTRICT PROTOBUF_NONNULL other) { + using ::std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_.value_, other->_impl_.value_); + swap(_impl_._oneof_case_[0], other->_impl_._oneof_case_[0]); +} + +::google::protobuf::Metadata ParameterValue::GetMetadata() const { + return ::google::protobuf::Message::GetMetadataImpl(GetClassData()->full()); +} +// @@protoc_insertion_point(namespace_scope) +} // namespace nodehub +namespace google { +namespace protobuf { +} // namespace protobuf +} // namespace google +// @@protoc_insertion_point(global_scope) +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::std::false_type + _static_init2_ [[maybe_unused]] = + (::_pbi::AddDescriptors(&descriptor_table_parameter_2eproto), + ::std::false_type{}); +#include "google/protobuf/port_undef.inc" diff --git a/applications/tests/protos/parameter.pb.h b/applications/tests/protos/parameter.pb.h new file mode 100644 index 0000000..8974928 --- /dev/null +++ b/applications/tests/protos/parameter.pb.h @@ -0,0 +1,547 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: parameter.proto +// Protobuf C++ Version: 6.34.0-dev + +#ifndef parameter_2eproto_2epb_2eh +#define parameter_2eproto_2epb_2eh + +#include +#include +#include +#include + +#include "google/protobuf/runtime_version.h" +#if PROTOBUF_VERSION != 6034000 +#error "Protobuf C++ gencode is built with an incompatible version of" +#error "Protobuf C++ headers/runtime. See" +#error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp" +#endif +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_tctable_decl.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" +// @@protoc_insertion_point(includes) + +// Must be included last. +#include "google/protobuf/port_def.inc" + +#define PROTOBUF_INTERNAL_EXPORT_parameter_2eproto + +namespace google { +namespace protobuf { +namespace internal { +template +::absl::string_view GetAnyMessageName(); +} // namespace internal +} // namespace protobuf +} // namespace google + +// Internal implementation detail -- do not use these members. +struct TableStruct_parameter_2eproto { + static const ::uint32_t offsets[]; +}; +extern "C" { +extern const ::google::protobuf::internal::DescriptorTable descriptor_table_parameter_2eproto; +} // extern "C" +namespace nodehub { +class ParameterValue; +struct ParameterValueDefaultTypeInternal; +extern ParameterValueDefaultTypeInternal _ParameterValue_default_instance_; +extern const ::google::protobuf::internal::ClassDataFull ParameterValue_class_data_; +} // namespace nodehub +namespace google { +namespace protobuf { +} // namespace protobuf +} // namespace google + +namespace nodehub { + +// =================================================================== + + +// ------------------------------------------------------------------- + +class ParameterValue final : public ::google::protobuf::Message +/* @@protoc_insertion_point(class_definition:nodehub.ParameterValue) */ { + public: + inline ParameterValue() : ParameterValue(nullptr) {} + ~ParameterValue() PROTOBUF_FINAL; + +#if defined(PROTOBUF_CUSTOM_VTABLE) + void operator delete(ParameterValue* PROTOBUF_NONNULL msg, ::std::destroying_delete_t) { + SharedDtor(*msg); + ::google::protobuf::internal::SizedDelete(msg, sizeof(ParameterValue)); + } +#endif + + template + explicit PROTOBUF_CONSTEXPR ParameterValue(::google::protobuf::internal::ConstantInitialized); + + inline ParameterValue(const ParameterValue& from) : ParameterValue(nullptr, from) {} + inline ParameterValue(ParameterValue&& from) noexcept + : ParameterValue(nullptr, ::std::move(from)) {} + inline ParameterValue& operator=(const ParameterValue& from) { + CopyFrom(from); + return *this; + } + inline ParameterValue& operator=(ParameterValue&& from) noexcept { + if (this == &from) return *this; + if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance); + } + inline ::google::protobuf::UnknownFieldSet* PROTOBUF_NONNULL mutable_unknown_fields() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>(); + } + + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL descriptor() { + return GetDescriptor(); + } + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::google::protobuf::Reflection* PROTOBUF_NONNULL GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const ParameterValue& default_instance() { + return *reinterpret_cast( + &_ParameterValue_default_instance_); + } + enum ValueCase { + kIntVal = 1, + kFloatVal = 2, + kBoolVal = 3, + kStringVal = 4, + VALUE_NOT_SET = 0, + }; + static constexpr int kIndexInFileMessages = 0; + friend void swap(ParameterValue& a, ParameterValue& b) { a.Swap(&b); } + inline void Swap(ParameterValue* PROTOBUF_NONNULL other) { + if (other == this) return; + if (::google::protobuf::internal::CanUseInternalSwap(GetArena(), other->GetArena())) { + InternalSwap(other); + } else { + ::google::protobuf::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(ParameterValue* PROTOBUF_NONNULL other) { + if (other == this) return; + ABSL_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + ParameterValue* PROTOBUF_NONNULL New(::google::protobuf::Arena* PROTOBUF_NULLABLE arena = nullptr) const { + return ::google::protobuf::Message::DefaultConstruct(arena); + } + using ::google::protobuf::Message::CopyFrom; + void CopyFrom(const ParameterValue& from); + using ::google::protobuf::Message::MergeFrom; + void MergeFrom(const ParameterValue& from) { ParameterValue::MergeImpl(*this, from); } + + private: + static void MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg); + + public: + bool IsInitialized() const { + return true; + } + ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL; + #if defined(PROTOBUF_CUSTOM_VTABLE) + private: + static ::size_t ByteSizeLong(const ::google::protobuf::MessageLite& msg); + static ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + const ::google::protobuf::MessageLite& msg, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream); + + public: + ::size_t ByteSizeLong() const { return ByteSizeLong(*this); } + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + return _InternalSerialize(*this, target, stream); + } + #else // PROTOBUF_CUSTOM_VTABLE + ::size_t ByteSizeLong() const final; + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const final; + #endif // PROTOBUF_CUSTOM_VTABLE + int GetCachedSize() const { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static void SharedDtor(MessageLite& self); + void InternalSwap(ParameterValue* PROTOBUF_NONNULL other); + private: + template + friend ::absl::string_view(::google::protobuf::internal::GetAnyMessageName)(); + static ::absl::string_view FullMessageName() { return "nodehub.ParameterValue"; } + + explicit ParameterValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + ParameterValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const ParameterValue& from); + ParameterValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, ParameterValue&& from) noexcept + : ParameterValue(arena) { + *this = ::std::move(from); + } + const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL GetClassData() const PROTOBUF_FINAL; + static void* PROTOBUF_NONNULL PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static constexpr auto InternalNewImpl_(); + + public: + static constexpr auto InternalGenerateClassData_(); + + ::google::protobuf::Metadata GetMetadata() const; + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + enum : int { + kIntValFieldNumber = 1, + kFloatValFieldNumber = 2, + kBoolValFieldNumber = 3, + kStringValFieldNumber = 4, + }; + // int32 int_val = 1; + [[nodiscard]] bool has_int_val() + const; + void clear_int_val() ; + ::int32_t int_val() const; + void set_int_val(::int32_t value); + + private: + ::int32_t _internal_int_val() const; + void _internal_set_int_val(::int32_t value); + + public: + // float float_val = 2; + [[nodiscard]] bool has_float_val() + const; + void clear_float_val() ; + float float_val() const; + void set_float_val(float value); + + private: + float _internal_float_val() const; + void _internal_set_float_val(float value); + + public: + // bool bool_val = 3; + [[nodiscard]] bool has_bool_val() + const; + void clear_bool_val() ; + bool bool_val() const; + void set_bool_val(bool value); + + private: + bool _internal_bool_val() const; + void _internal_set_bool_val(bool value); + + public: + // string string_val = 4; + [[nodiscard]] bool has_string_val() + const; + void clear_string_val() ; + const ::std::string& string_val() const; + template + void set_string_val(Arg_&& arg, Args_... args); + ::std::string* PROTOBUF_NONNULL mutable_string_val(); + [[nodiscard]] ::std::string* PROTOBUF_NULLABLE release_string_val(); + void set_allocated_string_val(::std::string* PROTOBUF_NULLABLE value); + + private: + const ::std::string& _internal_string_val() const; + PROTOBUF_ALWAYS_INLINE void _internal_set_string_val(const ::std::string& value); + ::std::string* PROTOBUF_NONNULL _internal_mutable_string_val(); + + public: + void clear_value(); + ValueCase value_case() const; + // @@protoc_insertion_point(class_scope:nodehub.ParameterValue) + private: + class _Internal; + void set_has_int_val(); + void set_has_float_val(); + void set_has_bool_val(); + void set_has_string_val(); + [[nodiscard]] inline bool has_value() const; + inline void clear_has_value(); + friend class ::google::protobuf::internal::TcParser; + static const ::google::protobuf::internal::TcParseTable<0, 4, + 0, 41, + 2> + _table_; + + friend class ::google::protobuf::MessageLite; + friend class ::google::protobuf::Arena; + friend ::google::protobuf::internal::PrivateAccess; + template + friend class ::google::protobuf::Arena::InternalHelper; + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + struct Impl_ { + inline explicit constexpr Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::internal::ConstantInitialized) noexcept; + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const Impl_& from, + const ParameterValue& from_msg); + union ValueUnion { + constexpr ValueUnion() : _constinit_{} {} + ::google::protobuf::internal::ConstantInitialized _constinit_; + ::int32_t int_val_; + float float_val_; + bool bool_val_; + ::google::protobuf::internal::ArenaStringPtr string_val_; + } value_; + ::google::protobuf::internal::CachedSize _cached_size_; + ::uint32_t _oneof_case_[1]; + PROTOBUF_TSAN_DECLARE_MEMBER + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_parameter_2eproto; +}; + +extern const ::google::protobuf::internal::ClassDataFull ParameterValue_class_data_; + +// =================================================================== + + + + +// =================================================================== + + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// ParameterValue + +// int32 int_val = 1; +inline bool ParameterValue::has_int_val() const { + return value_case() == kIntVal; +} +inline void ParameterValue::set_has_int_val() { + _impl_._oneof_case_[0] = kIntVal; +} +inline void ParameterValue::clear_int_val() { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value_case() == kIntVal) { + _impl_.value_.int_val_ = 0; + clear_has_value(); + } +} +inline ::int32_t ParameterValue::int_val() const { + // @@protoc_insertion_point(field_get:nodehub.ParameterValue.int_val) + return _internal_int_val(); +} +inline void ParameterValue::set_int_val(::int32_t value) { + if (value_case() != kIntVal) { + clear_value(); + set_has_int_val(); + } + _impl_.value_.int_val_ = value; + // @@protoc_insertion_point(field_set:nodehub.ParameterValue.int_val) +} +inline ::int32_t ParameterValue::_internal_int_val() const { + if (value_case() == kIntVal) { + return _impl_.value_.int_val_; + } + return 0; +} + +// float float_val = 2; +inline bool ParameterValue::has_float_val() const { + return value_case() == kFloatVal; +} +inline void ParameterValue::set_has_float_val() { + _impl_._oneof_case_[0] = kFloatVal; +} +inline void ParameterValue::clear_float_val() { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value_case() == kFloatVal) { + _impl_.value_.float_val_ = 0; + clear_has_value(); + } +} +inline float ParameterValue::float_val() const { + // @@protoc_insertion_point(field_get:nodehub.ParameterValue.float_val) + return _internal_float_val(); +} +inline void ParameterValue::set_float_val(float value) { + if (value_case() != kFloatVal) { + clear_value(); + set_has_float_val(); + } + _impl_.value_.float_val_ = value; + // @@protoc_insertion_point(field_set:nodehub.ParameterValue.float_val) +} +inline float ParameterValue::_internal_float_val() const { + if (value_case() == kFloatVal) { + return _impl_.value_.float_val_; + } + return 0; +} + +// bool bool_val = 3; +inline bool ParameterValue::has_bool_val() const { + return value_case() == kBoolVal; +} +inline void ParameterValue::set_has_bool_val() { + _impl_._oneof_case_[0] = kBoolVal; +} +inline void ParameterValue::clear_bool_val() { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value_case() == kBoolVal) { + _impl_.value_.bool_val_ = false; + clear_has_value(); + } +} +inline bool ParameterValue::bool_val() const { + // @@protoc_insertion_point(field_get:nodehub.ParameterValue.bool_val) + return _internal_bool_val(); +} +inline void ParameterValue::set_bool_val(bool value) { + if (value_case() != kBoolVal) { + clear_value(); + set_has_bool_val(); + } + _impl_.value_.bool_val_ = value; + // @@protoc_insertion_point(field_set:nodehub.ParameterValue.bool_val) +} +inline bool ParameterValue::_internal_bool_val() const { + if (value_case() == kBoolVal) { + return _impl_.value_.bool_val_; + } + return false; +} + +// string string_val = 4; +inline bool ParameterValue::has_string_val() const { + return value_case() == kStringVal; +} +inline void ParameterValue::set_has_string_val() { + _impl_._oneof_case_[0] = kStringVal; +} +inline void ParameterValue::clear_string_val() { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value_case() == kStringVal) { + _impl_.value_.string_val_.Destroy(); + clear_has_value(); + } +} +inline const ::std::string& ParameterValue::string_val() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_get:nodehub.ParameterValue.string_val) + return _internal_string_val(); +} +template +PROTOBUF_ALWAYS_INLINE void ParameterValue::set_string_val(Arg_&& arg, Args_... args) { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value_case() != kStringVal) { + clear_value(); + + set_has_string_val(); + _impl_.value_.string_val_.InitDefault(); + } + _impl_.value_.string_val_.Set(static_cast(arg), args..., GetArena()); + // @@protoc_insertion_point(field_set:nodehub.ParameterValue.string_val) +} +inline ::std::string* PROTOBUF_NONNULL ParameterValue::mutable_string_val() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + if (value_case() != kStringVal) { + clear_value(); + + set_has_string_val(); + _impl_.value_.string_val_.InitDefault(); + } + ::std::string* _s = _internal_mutable_string_val(); + // @@protoc_insertion_point(field_mutable:nodehub.ParameterValue.string_val) + return _s; +} +inline const ::std::string& ParameterValue::_internal_string_val() const { + ::google::protobuf::internal::TSanRead(&_impl_); + if (value_case() != kStringVal) { + return ::google::protobuf::internal::GetEmptyStringAlreadyInited(); + } + return _impl_.value_.string_val_.Get(); +} +inline void ParameterValue::_internal_set_string_val(const ::std::string& value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_.string_val_.Set(value, GetArena()); +} +inline ::std::string* PROTOBUF_NONNULL ParameterValue::_internal_mutable_string_val() { + ::google::protobuf::internal::TSanWrite(&_impl_); + return _impl_.value_.string_val_.Mutable( GetArena()); +} +inline ::std::string* PROTOBUF_NULLABLE ParameterValue::release_string_val() { + ::google::protobuf::internal::TSanWrite(&_impl_); + // @@protoc_insertion_point(field_release:nodehub.ParameterValue.string_val) + if (value_case() != kStringVal) { + return nullptr; + } + clear_has_value(); + return _impl_.value_.string_val_.Release(); +} +inline void ParameterValue::set_allocated_string_val(::std::string* PROTOBUF_NULLABLE value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (has_value()) { + clear_value(); + } + if (value != nullptr) { + set_has_string_val(); + _impl_.value_.string_val_.InitAllocated(value, GetArena()); + } + // @@protoc_insertion_point(field_set_allocated:nodehub.ParameterValue.string_val) +} + +inline bool ParameterValue::has_value() const { + return value_case() != VALUE_NOT_SET; +} +inline void ParameterValue::clear_has_value() { + _impl_._oneof_case_[0] = VALUE_NOT_SET; +} +inline ParameterValue::ValueCase ParameterValue::value_case() const { + return ParameterValue::ValueCase(_impl_._oneof_case_[0]); +} +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // __GNUC__ + +// @@protoc_insertion_point(namespace_scope) +} // namespace nodehub + + +// @@protoc_insertion_point(global_scope) + +#include "google/protobuf/port_undef.inc" + +#endif // parameter_2eproto_2epb_2eh diff --git a/applications/tests/protos/test_primitives.pb.cc b/applications/tests/protos/test_primitives.pb.cc new file mode 100644 index 0000000..3017fc8 --- /dev/null +++ b/applications/tests/protos/test_primitives.pb.cc @@ -0,0 +1,1235 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: test_primitives.proto +// Protobuf C++ Version: 6.34.0-dev + +#include "test_primitives.pb.h" + +#include +#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/generated_message_tctable_impl.h" +#include "google/protobuf/internal_visibility.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" +// @@protoc_insertion_point(includes) + +// Must be included last. +#include "google/protobuf/port_def.inc" +PROTOBUF_PRAGMA_INIT_SEG +namespace _pb = ::google::protobuf; +namespace _pbi = ::google::protobuf::internal; +namespace _fl = ::google::protobuf::internal::field_layout; +namespace nodehub { +namespace tests { + +inline constexpr StringValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + ::_pbi::ConstantInitialized) noexcept + : _cached_size_{0}, + value_( + &::google::protobuf::internal::fixed_address_empty_string, + ::_pbi::ConstantInitialized()) {} + +template +PROTOBUF_CONSTEXPR StringValue::StringValue(::_pbi::ConstantInitialized) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(StringValue_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(internal_visibility(), ::_pbi::ConstantInitialized()) { +} +struct StringValueDefaultTypeInternal { + PROTOBUF_CONSTEXPR StringValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~StringValueDefaultTypeInternal() {} + union { + StringValue _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 StringValueDefaultTypeInternal _StringValue_default_instance_; + +inline constexpr IntValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + ::_pbi::ConstantInitialized) noexcept + : _cached_size_{0}, + value_{0} {} + +template +PROTOBUF_CONSTEXPR IntValue::IntValue(::_pbi::ConstantInitialized) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(IntValue_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(internal_visibility(), ::_pbi::ConstantInitialized()) { +} +struct IntValueDefaultTypeInternal { + PROTOBUF_CONSTEXPR IntValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~IntValueDefaultTypeInternal() {} + union { + IntValue _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 IntValueDefaultTypeInternal _IntValue_default_instance_; + +inline constexpr FloatValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + ::_pbi::ConstantInitialized) noexcept + : _cached_size_{0}, + value_{0} {} + +template +PROTOBUF_CONSTEXPR FloatValue::FloatValue(::_pbi::ConstantInitialized) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(FloatValue_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(internal_visibility(), ::_pbi::ConstantInitialized()) { +} +struct FloatValueDefaultTypeInternal { + PROTOBUF_CONSTEXPR FloatValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~FloatValueDefaultTypeInternal() {} + union { + FloatValue _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 FloatValueDefaultTypeInternal _FloatValue_default_instance_; + +inline constexpr BoolValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + ::_pbi::ConstantInitialized) noexcept + : _cached_size_{0}, + value_{false} {} + +template +PROTOBUF_CONSTEXPR BoolValue::BoolValue(::_pbi::ConstantInitialized) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(BoolValue_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(internal_visibility(), ::_pbi::ConstantInitialized()) { +} +struct BoolValueDefaultTypeInternal { + PROTOBUF_CONSTEXPR BoolValueDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~BoolValueDefaultTypeInternal() {} + union { + BoolValue _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 BoolValueDefaultTypeInternal _BoolValue_default_instance_; +} // namespace tests +} // namespace nodehub +static constexpr const ::_pb::EnumDescriptor* PROTOBUF_NONNULL* PROTOBUF_NULLABLE + file_level_enum_descriptors_test_5fprimitives_2eproto = nullptr; +static constexpr const ::_pb::ServiceDescriptor* PROTOBUF_NONNULL* PROTOBUF_NULLABLE + file_level_service_descriptors_test_5fprimitives_2eproto = nullptr; +const ::uint32_t + TableStruct_test_5fprimitives_2eproto::offsets[] ABSL_ATTRIBUTE_SECTION_VARIABLE( + protodesc_cold) = { + 0x081, // bitmap + PROTOBUF_FIELD_OFFSET(::nodehub::tests::IntValue, _impl_._has_bits_), + 4, // hasbit index offset + PROTOBUF_FIELD_OFFSET(::nodehub::tests::IntValue, _impl_.value_), + 0, + 0x081, // bitmap + PROTOBUF_FIELD_OFFSET(::nodehub::tests::FloatValue, _impl_._has_bits_), + 4, // hasbit index offset + PROTOBUF_FIELD_OFFSET(::nodehub::tests::FloatValue, _impl_.value_), + 0, + 0x081, // bitmap + PROTOBUF_FIELD_OFFSET(::nodehub::tests::BoolValue, _impl_._has_bits_), + 4, // hasbit index offset + PROTOBUF_FIELD_OFFSET(::nodehub::tests::BoolValue, _impl_.value_), + 0, + 0x081, // bitmap + PROTOBUF_FIELD_OFFSET(::nodehub::tests::StringValue, _impl_._has_bits_), + 4, // hasbit index offset + PROTOBUF_FIELD_OFFSET(::nodehub::tests::StringValue, _impl_.value_), + 0, +}; + +static const ::_pbi::MigrationSchema + schemas[] ABSL_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + {0, sizeof(::nodehub::tests::IntValue)}, + {5, sizeof(::nodehub::tests::FloatValue)}, + {10, sizeof(::nodehub::tests::BoolValue)}, + {15, sizeof(::nodehub::tests::StringValue)}, +}; +static const ::_pb::Message* PROTOBUF_NONNULL const file_default_instances[] = { + &::nodehub::tests::_IntValue_default_instance_._instance, + &::nodehub::tests::_FloatValue_default_instance_._instance, + &::nodehub::tests::_BoolValue_default_instance_._instance, + &::nodehub::tests::_StringValue_default_instance_._instance, +}; +const char descriptor_table_protodef_test_5fprimitives_2eproto[] ABSL_ATTRIBUTE_SECTION_VARIABLE( + protodesc_cold) = { + "\n\025test_primitives.proto\022\rnodehub.tests\"\031" + "\n\010IntValue\022\r\n\005value\030\001 \001(\005\"\033\n\nFloatValue\022" + "\r\n\005value\030\001 \001(\002\"\032\n\tBoolValue\022\r\n\005value\030\001 \001" + "(\010\"\034\n\013StringValue\022\r\n\005value\030\001 \001(\tb\006proto3" +}; +static ::absl::once_flag descriptor_table_test_5fprimitives_2eproto_once; +PROTOBUF_CONSTINIT const ::_pbi::DescriptorTable descriptor_table_test_5fprimitives_2eproto = { + false, + false, + 160, + descriptor_table_protodef_test_5fprimitives_2eproto, + "test_primitives.proto", + &descriptor_table_test_5fprimitives_2eproto_once, + nullptr, + 0, + 4, + schemas, + file_default_instances, + TableStruct_test_5fprimitives_2eproto::offsets, + file_level_enum_descriptors_test_5fprimitives_2eproto, + file_level_service_descriptors_test_5fprimitives_2eproto, +}; +namespace nodehub { +namespace tests { +// =================================================================== + +class IntValue::_Internal { + public: + using HasBits = + decltype(::std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(IntValue, _impl_._has_bits_); +}; + +IntValue::IntValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, IntValue_class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:nodehub.tests.IntValue) +} +IntValue::IntValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const IntValue& from) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, IntValue_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(from._impl_) { + _internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); +} +PROTOBUF_NDEBUG_INLINE IntValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + [[maybe_unused]] ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) + : _cached_size_{0} {} + +inline void IntValue::SharedCtor(::_pb::Arena* PROTOBUF_NULLABLE arena) { + new (&_impl_) Impl_(internal_visibility(), arena); + _impl_.value_ = {}; +} +IntValue::~IntValue() { + // @@protoc_insertion_point(destructor:nodehub.tests.IntValue) + SharedDtor(*this); +} +inline void IntValue::SharedDtor(MessageLite& self) { + IntValue& this_ = static_cast(self); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + this_._internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>(); + ABSL_DCHECK(this_.GetArena() == nullptr); + this_._impl_.~Impl_(); +} + +inline void* PROTOBUF_NONNULL IntValue::PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) { + return ::new (mem) IntValue(arena); +} +constexpr auto IntValue::InternalNewImpl_() { + return ::google::protobuf::internal::MessageCreator::ZeroInit(sizeof(IntValue), + alignof(IntValue)); +} +constexpr auto IntValue::InternalGenerateClassData_() { + return ::google::protobuf::internal::ClassDataFull{ + ::google::protobuf::internal::ClassData{ + &_IntValue_default_instance_._instance, + &_table_.header, + nullptr, // OnDemandRegisterArenaDtor + nullptr, // IsInitialized + &IntValue::MergeImpl, + ::google::protobuf::Message::GetNewImpl(), +#if defined(PROTOBUF_CUSTOM_VTABLE) + &IntValue::SharedDtor, + ::google::protobuf::Message::GetClearImpl(), &IntValue::ByteSizeLong, + &IntValue::_InternalSerialize, +#endif // PROTOBUF_CUSTOM_VTABLE + PROTOBUF_FIELD_OFFSET(IntValue, _impl_._cached_size_), + false, + }, + &IntValue::kDescriptorMethods, + &descriptor_table_test_5fprimitives_2eproto, + nullptr, // tracker + }; +} + +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 const + ::google::protobuf::internal::ClassDataFull IntValue_class_data_ = + IntValue::InternalGenerateClassData_(); + +PROTOBUF_ATTRIBUTE_WEAK const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL +IntValue::GetClassData() const { + ::google::protobuf::internal::PrefetchToLocalCache(&IntValue_class_data_); + ::google::protobuf::internal::PrefetchToLocalCache(IntValue_class_data_.tc_table); + return IntValue_class_data_.base(); +} +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::_pbi::TcParseTable<0, 1, 0, 0, 2> +IntValue::_table_ = { + { + PROTOBUF_FIELD_OFFSET(IntValue, _impl_._has_bits_), + 0, // no _extensions_ + 1, 0, // max_field_number, fast_idx_mask + offsetof(decltype(_table_), field_lookup_table), + 4294967294, // skipmap + offsetof(decltype(_table_), field_entries), + 1, // num_field_entries + 0, // num_aux_entries + offsetof(decltype(_table_), field_names), // no aux_entries + IntValue_class_data_.base(), + nullptr, // post_loop_handler + ::_pbi::TcParser::GenericFallback, // fallback + #ifdef PROTOBUF_PREFETCH_PARSE_TABLE + ::_pbi::TcParser::GetTable<::nodehub::tests::IntValue>(), // to_prefetch + #endif // PROTOBUF_PREFETCH_PARSE_TABLE + }, {{ + // int32 value = 1; + {::_pbi::TcParser::SingularVarintNoZag1<::uint32_t, offsetof(IntValue, _impl_.value_), 0>(), + {8, 0, 0, + PROTOBUF_FIELD_OFFSET(IntValue, _impl_.value_)}}, + }}, {{ + 65535, 65535 + }}, {{ + // int32 value = 1; + {PROTOBUF_FIELD_OFFSET(IntValue, _impl_.value_), _Internal::kHasBitsOffset + 0, 0, (0 | ::_fl::kFcOptional | ::_fl::kInt32)}, + }}, + // no aux_entries + {{ + }}, +}; +PROTOBUF_NOINLINE void IntValue::Clear() { +// @@protoc_insertion_point(message_clear_start:nodehub.tests.IntValue) + ::google::protobuf::internal::TSanWrite(&_impl_); + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.value_ = 0; + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::uint8_t* PROTOBUF_NONNULL IntValue::_InternalSerialize( + const ::google::protobuf::MessageLite& base, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) { + const IntValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::uint8_t* PROTOBUF_NONNULL IntValue::_InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + const IntValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(serialize_to_array_start:nodehub.tests.IntValue) + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = this_._impl_._has_bits_[0]; + // int32 value = 1; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (this_._internal_value() != 0) { + target = + ::google::protobuf::internal::WireFormatLite::WriteInt32ToArrayWithField<1>( + stream, this_._internal_value(), target); + } + } + + if (ABSL_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { + target = + ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + this_._internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:nodehub.tests.IntValue) + return target; +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::size_t IntValue::ByteSizeLong(const MessageLite& base) { + const IntValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::size_t IntValue::ByteSizeLong() const { + const IntValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(message_byte_size_start:nodehub.tests.IntValue) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + { + // int32 value = 1; + cached_has_bits = this_._impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (this_._internal_value() != 0) { + total_size += ::_pbi::WireFormatLite::Int32SizePlusOne( + this_._internal_value()); + } + } + } + return this_.MaybeComputeUnknownFieldsSize(total_size, + &this_._impl_._cached_size_); +} + +void IntValue::MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg) { + auto* const _this = + static_cast(&to_msg); + auto& from = static_cast(from_msg); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + from.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(class_specific_merge_from_start:nodehub.tests.IntValue) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = from._impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (from._internal_value() != 0) { + _this->_impl_.value_ = from._impl_.value_; + } + } + _this->_impl_._has_bits_[0] |= cached_has_bits; + _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); +} + +void IntValue::CopyFrom(const IntValue& from) { + // @@protoc_insertion_point(class_specific_copy_from_start:nodehub.tests.IntValue) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + + +void IntValue::InternalSwap(IntValue* PROTOBUF_RESTRICT PROTOBUF_NONNULL other) { + using ::std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + swap(_impl_.value_, other->_impl_.value_); +} + +::google::protobuf::Metadata IntValue::GetMetadata() const { + return ::google::protobuf::Message::GetMetadataImpl(GetClassData()->full()); +} +// =================================================================== + +class FloatValue::_Internal { + public: + using HasBits = + decltype(::std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(FloatValue, _impl_._has_bits_); +}; + +FloatValue::FloatValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, FloatValue_class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:nodehub.tests.FloatValue) +} +FloatValue::FloatValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const FloatValue& from) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, FloatValue_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(from._impl_) { + _internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); +} +PROTOBUF_NDEBUG_INLINE FloatValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + [[maybe_unused]] ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) + : _cached_size_{0} {} + +inline void FloatValue::SharedCtor(::_pb::Arena* PROTOBUF_NULLABLE arena) { + new (&_impl_) Impl_(internal_visibility(), arena); + _impl_.value_ = {}; +} +FloatValue::~FloatValue() { + // @@protoc_insertion_point(destructor:nodehub.tests.FloatValue) + SharedDtor(*this); +} +inline void FloatValue::SharedDtor(MessageLite& self) { + FloatValue& this_ = static_cast(self); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + this_._internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>(); + ABSL_DCHECK(this_.GetArena() == nullptr); + this_._impl_.~Impl_(); +} + +inline void* PROTOBUF_NONNULL FloatValue::PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) { + return ::new (mem) FloatValue(arena); +} +constexpr auto FloatValue::InternalNewImpl_() { + return ::google::protobuf::internal::MessageCreator::ZeroInit(sizeof(FloatValue), + alignof(FloatValue)); +} +constexpr auto FloatValue::InternalGenerateClassData_() { + return ::google::protobuf::internal::ClassDataFull{ + ::google::protobuf::internal::ClassData{ + &_FloatValue_default_instance_._instance, + &_table_.header, + nullptr, // OnDemandRegisterArenaDtor + nullptr, // IsInitialized + &FloatValue::MergeImpl, + ::google::protobuf::Message::GetNewImpl(), +#if defined(PROTOBUF_CUSTOM_VTABLE) + &FloatValue::SharedDtor, + ::google::protobuf::Message::GetClearImpl(), &FloatValue::ByteSizeLong, + &FloatValue::_InternalSerialize, +#endif // PROTOBUF_CUSTOM_VTABLE + PROTOBUF_FIELD_OFFSET(FloatValue, _impl_._cached_size_), + false, + }, + &FloatValue::kDescriptorMethods, + &descriptor_table_test_5fprimitives_2eproto, + nullptr, // tracker + }; +} + +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 const + ::google::protobuf::internal::ClassDataFull FloatValue_class_data_ = + FloatValue::InternalGenerateClassData_(); + +PROTOBUF_ATTRIBUTE_WEAK const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL +FloatValue::GetClassData() const { + ::google::protobuf::internal::PrefetchToLocalCache(&FloatValue_class_data_); + ::google::protobuf::internal::PrefetchToLocalCache(FloatValue_class_data_.tc_table); + return FloatValue_class_data_.base(); +} +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::_pbi::TcParseTable<0, 1, 0, 0, 2> +FloatValue::_table_ = { + { + PROTOBUF_FIELD_OFFSET(FloatValue, _impl_._has_bits_), + 0, // no _extensions_ + 1, 0, // max_field_number, fast_idx_mask + offsetof(decltype(_table_), field_lookup_table), + 4294967294, // skipmap + offsetof(decltype(_table_), field_entries), + 1, // num_field_entries + 0, // num_aux_entries + offsetof(decltype(_table_), field_names), // no aux_entries + FloatValue_class_data_.base(), + nullptr, // post_loop_handler + ::_pbi::TcParser::GenericFallback, // fallback + #ifdef PROTOBUF_PREFETCH_PARSE_TABLE + ::_pbi::TcParser::GetTable<::nodehub::tests::FloatValue>(), // to_prefetch + #endif // PROTOBUF_PREFETCH_PARSE_TABLE + }, {{ + // float value = 1; + {::_pbi::TcParser::FastF32S1, + {13, 0, 0, + PROTOBUF_FIELD_OFFSET(FloatValue, _impl_.value_)}}, + }}, {{ + 65535, 65535 + }}, {{ + // float value = 1; + {PROTOBUF_FIELD_OFFSET(FloatValue, _impl_.value_), _Internal::kHasBitsOffset + 0, 0, (0 | ::_fl::kFcOptional | ::_fl::kFloat)}, + }}, + // no aux_entries + {{ + }}, +}; +PROTOBUF_NOINLINE void FloatValue::Clear() { +// @@protoc_insertion_point(message_clear_start:nodehub.tests.FloatValue) + ::google::protobuf::internal::TSanWrite(&_impl_); + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.value_ = 0; + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::uint8_t* PROTOBUF_NONNULL FloatValue::_InternalSerialize( + const ::google::protobuf::MessageLite& base, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) { + const FloatValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::uint8_t* PROTOBUF_NONNULL FloatValue::_InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + const FloatValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(serialize_to_array_start:nodehub.tests.FloatValue) + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = this_._impl_._has_bits_[0]; + // float value = 1; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (::absl::bit_cast<::uint32_t>(this_._internal_value()) != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteFloatToArray( + 1, this_._internal_value(), target); + } + } + + if (ABSL_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { + target = + ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + this_._internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:nodehub.tests.FloatValue) + return target; +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::size_t FloatValue::ByteSizeLong(const MessageLite& base) { + const FloatValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::size_t FloatValue::ByteSizeLong() const { + const FloatValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(message_byte_size_start:nodehub.tests.FloatValue) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + { + // float value = 1; + cached_has_bits = this_._impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (::absl::bit_cast<::uint32_t>(this_._internal_value()) != 0) { + total_size += 5; + } + } + } + return this_.MaybeComputeUnknownFieldsSize(total_size, + &this_._impl_._cached_size_); +} + +void FloatValue::MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg) { + auto* const _this = + static_cast(&to_msg); + auto& from = static_cast(from_msg); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + from.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(class_specific_merge_from_start:nodehub.tests.FloatValue) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = from._impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (::absl::bit_cast<::uint32_t>(from._internal_value()) != 0) { + _this->_impl_.value_ = from._impl_.value_; + } + } + _this->_impl_._has_bits_[0] |= cached_has_bits; + _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); +} + +void FloatValue::CopyFrom(const FloatValue& from) { + // @@protoc_insertion_point(class_specific_copy_from_start:nodehub.tests.FloatValue) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + + +void FloatValue::InternalSwap(FloatValue* PROTOBUF_RESTRICT PROTOBUF_NONNULL other) { + using ::std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + swap(_impl_.value_, other->_impl_.value_); +} + +::google::protobuf::Metadata FloatValue::GetMetadata() const { + return ::google::protobuf::Message::GetMetadataImpl(GetClassData()->full()); +} +// =================================================================== + +class BoolValue::_Internal { + public: + using HasBits = + decltype(::std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(BoolValue, _impl_._has_bits_); +}; + +BoolValue::BoolValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, BoolValue_class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:nodehub.tests.BoolValue) +} +BoolValue::BoolValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const BoolValue& from) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, BoolValue_class_data_.base()), +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena), +#endif // PROTOBUF_CUSTOM_VTABLE + _impl_(from._impl_) { + _internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); +} +PROTOBUF_NDEBUG_INLINE BoolValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + [[maybe_unused]] ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) + : _cached_size_{0} {} + +inline void BoolValue::SharedCtor(::_pb::Arena* PROTOBUF_NULLABLE arena) { + new (&_impl_) Impl_(internal_visibility(), arena); + _impl_.value_ = {}; +} +BoolValue::~BoolValue() { + // @@protoc_insertion_point(destructor:nodehub.tests.BoolValue) + SharedDtor(*this); +} +inline void BoolValue::SharedDtor(MessageLite& self) { + BoolValue& this_ = static_cast(self); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + this_._internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>(); + ABSL_DCHECK(this_.GetArena() == nullptr); + this_._impl_.~Impl_(); +} + +inline void* PROTOBUF_NONNULL BoolValue::PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) { + return ::new (mem) BoolValue(arena); +} +constexpr auto BoolValue::InternalNewImpl_() { + return ::google::protobuf::internal::MessageCreator::ZeroInit(sizeof(BoolValue), + alignof(BoolValue)); +} +constexpr auto BoolValue::InternalGenerateClassData_() { + return ::google::protobuf::internal::ClassDataFull{ + ::google::protobuf::internal::ClassData{ + &_BoolValue_default_instance_._instance, + &_table_.header, + nullptr, // OnDemandRegisterArenaDtor + nullptr, // IsInitialized + &BoolValue::MergeImpl, + ::google::protobuf::Message::GetNewImpl(), +#if defined(PROTOBUF_CUSTOM_VTABLE) + &BoolValue::SharedDtor, + ::google::protobuf::Message::GetClearImpl(), &BoolValue::ByteSizeLong, + &BoolValue::_InternalSerialize, +#endif // PROTOBUF_CUSTOM_VTABLE + PROTOBUF_FIELD_OFFSET(BoolValue, _impl_._cached_size_), + false, + }, + &BoolValue::kDescriptorMethods, + &descriptor_table_test_5fprimitives_2eproto, + nullptr, // tracker + }; +} + +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 const + ::google::protobuf::internal::ClassDataFull BoolValue_class_data_ = + BoolValue::InternalGenerateClassData_(); + +PROTOBUF_ATTRIBUTE_WEAK const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL +BoolValue::GetClassData() const { + ::google::protobuf::internal::PrefetchToLocalCache(&BoolValue_class_data_); + ::google::protobuf::internal::PrefetchToLocalCache(BoolValue_class_data_.tc_table); + return BoolValue_class_data_.base(); +} +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::_pbi::TcParseTable<0, 1, 0, 0, 2> +BoolValue::_table_ = { + { + PROTOBUF_FIELD_OFFSET(BoolValue, _impl_._has_bits_), + 0, // no _extensions_ + 1, 0, // max_field_number, fast_idx_mask + offsetof(decltype(_table_), field_lookup_table), + 4294967294, // skipmap + offsetof(decltype(_table_), field_entries), + 1, // num_field_entries + 0, // num_aux_entries + offsetof(decltype(_table_), field_names), // no aux_entries + BoolValue_class_data_.base(), + nullptr, // post_loop_handler + ::_pbi::TcParser::GenericFallback, // fallback + #ifdef PROTOBUF_PREFETCH_PARSE_TABLE + ::_pbi::TcParser::GetTable<::nodehub::tests::BoolValue>(), // to_prefetch + #endif // PROTOBUF_PREFETCH_PARSE_TABLE + }, {{ + // bool value = 1; + {::_pbi::TcParser::SingularVarintNoZag1(), + {8, 0, 0, + PROTOBUF_FIELD_OFFSET(BoolValue, _impl_.value_)}}, + }}, {{ + 65535, 65535 + }}, {{ + // bool value = 1; + {PROTOBUF_FIELD_OFFSET(BoolValue, _impl_.value_), _Internal::kHasBitsOffset + 0, 0, (0 | ::_fl::kFcOptional | ::_fl::kBool)}, + }}, + // no aux_entries + {{ + }}, +}; +PROTOBUF_NOINLINE void BoolValue::Clear() { +// @@protoc_insertion_point(message_clear_start:nodehub.tests.BoolValue) + ::google::protobuf::internal::TSanWrite(&_impl_); + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.value_ = false; + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::uint8_t* PROTOBUF_NONNULL BoolValue::_InternalSerialize( + const ::google::protobuf::MessageLite& base, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) { + const BoolValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::uint8_t* PROTOBUF_NONNULL BoolValue::_InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + const BoolValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(serialize_to_array_start:nodehub.tests.BoolValue) + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = this_._impl_._has_bits_[0]; + // bool value = 1; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (this_._internal_value() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteBoolToArray( + 1, this_._internal_value(), target); + } + } + + if (ABSL_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { + target = + ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + this_._internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:nodehub.tests.BoolValue) + return target; +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::size_t BoolValue::ByteSizeLong(const MessageLite& base) { + const BoolValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::size_t BoolValue::ByteSizeLong() const { + const BoolValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(message_byte_size_start:nodehub.tests.BoolValue) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + { + // bool value = 1; + cached_has_bits = this_._impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (this_._internal_value() != 0) { + total_size += 2; + } + } + } + return this_.MaybeComputeUnknownFieldsSize(total_size, + &this_._impl_._cached_size_); +} + +void BoolValue::MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg) { + auto* const _this = + static_cast(&to_msg); + auto& from = static_cast(from_msg); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + from.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(class_specific_merge_from_start:nodehub.tests.BoolValue) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = from._impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (from._internal_value() != 0) { + _this->_impl_.value_ = from._impl_.value_; + } + } + _this->_impl_._has_bits_[0] |= cached_has_bits; + _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); +} + +void BoolValue::CopyFrom(const BoolValue& from) { + // @@protoc_insertion_point(class_specific_copy_from_start:nodehub.tests.BoolValue) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + + +void BoolValue::InternalSwap(BoolValue* PROTOBUF_RESTRICT PROTOBUF_NONNULL other) { + using ::std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + swap(_impl_.value_, other->_impl_.value_); +} + +::google::protobuf::Metadata BoolValue::GetMetadata() const { + return ::google::protobuf::Message::GetMetadataImpl(GetClassData()->full()); +} +// =================================================================== + +class StringValue::_Internal { + public: + using HasBits = + decltype(::std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(StringValue, _impl_._has_bits_); +}; + +StringValue::StringValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, StringValue_class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + SharedCtor(arena); + // @@protoc_insertion_point(arena_constructor:nodehub.tests.StringValue) +} +PROTOBUF_NDEBUG_INLINE StringValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + [[maybe_unused]] ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const Impl_& from, + [[maybe_unused]] const ::nodehub::tests::StringValue& from_msg) + : _has_bits_{from._has_bits_}, + _cached_size_{0}, + value_(arena, from.value_) {} + +StringValue::StringValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, + const StringValue& from) +#if defined(PROTOBUF_CUSTOM_VTABLE) + : ::google::protobuf::Message(arena, StringValue_class_data_.base()) { +#else // PROTOBUF_CUSTOM_VTABLE + : ::google::protobuf::Message(arena) { +#endif // PROTOBUF_CUSTOM_VTABLE + StringValue* const _this = this; + (void)_this; + _internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); + new (&_impl_) Impl_(internal_visibility(), arena, from._impl_, from); + + // @@protoc_insertion_point(copy_constructor:nodehub.tests.StringValue) +} +PROTOBUF_NDEBUG_INLINE StringValue::Impl_::Impl_( + [[maybe_unused]] ::google::protobuf::internal::InternalVisibility visibility, + [[maybe_unused]] ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) + : _cached_size_{0}, + value_(arena) {} + +inline void StringValue::SharedCtor(::_pb::Arena* PROTOBUF_NULLABLE arena) { + new (&_impl_) Impl_(internal_visibility(), arena); +} +StringValue::~StringValue() { + // @@protoc_insertion_point(destructor:nodehub.tests.StringValue) + SharedDtor(*this); +} +inline void StringValue::SharedDtor(MessageLite& self) { + StringValue& this_ = static_cast(self); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + this_._internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>(); + ABSL_DCHECK(this_.GetArena() == nullptr); + this_._impl_.value_.Destroy(); + this_._impl_.~Impl_(); +} + +inline void* PROTOBUF_NONNULL StringValue::PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena) { + return ::new (mem) StringValue(arena); +} +constexpr auto StringValue::InternalNewImpl_() { + return ::google::protobuf::internal::MessageCreator::CopyInit(sizeof(StringValue), + alignof(StringValue)); +} +constexpr auto StringValue::InternalGenerateClassData_() { + return ::google::protobuf::internal::ClassDataFull{ + ::google::protobuf::internal::ClassData{ + &_StringValue_default_instance_._instance, + &_table_.header, + nullptr, // OnDemandRegisterArenaDtor + nullptr, // IsInitialized + &StringValue::MergeImpl, + ::google::protobuf::Message::GetNewImpl(), +#if defined(PROTOBUF_CUSTOM_VTABLE) + &StringValue::SharedDtor, + ::google::protobuf::Message::GetClearImpl(), &StringValue::ByteSizeLong, + &StringValue::_InternalSerialize, +#endif // PROTOBUF_CUSTOM_VTABLE + PROTOBUF_FIELD_OFFSET(StringValue, _impl_._cached_size_), + false, + }, + &StringValue::kDescriptorMethods, + &descriptor_table_test_5fprimitives_2eproto, + nullptr, // tracker + }; +} + +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 const + ::google::protobuf::internal::ClassDataFull StringValue_class_data_ = + StringValue::InternalGenerateClassData_(); + +PROTOBUF_ATTRIBUTE_WEAK const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL +StringValue::GetClassData() const { + ::google::protobuf::internal::PrefetchToLocalCache(&StringValue_class_data_); + ::google::protobuf::internal::PrefetchToLocalCache(StringValue_class_data_.tc_table); + return StringValue_class_data_.base(); +} +PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 +const ::_pbi::TcParseTable<0, 1, 0, 39, 2> +StringValue::_table_ = { + { + PROTOBUF_FIELD_OFFSET(StringValue, _impl_._has_bits_), + 0, // no _extensions_ + 1, 0, // max_field_number, fast_idx_mask + offsetof(decltype(_table_), field_lookup_table), + 4294967294, // skipmap + offsetof(decltype(_table_), field_entries), + 1, // num_field_entries + 0, // num_aux_entries + offsetof(decltype(_table_), field_names), // no aux_entries + StringValue_class_data_.base(), + nullptr, // post_loop_handler + ::_pbi::TcParser::GenericFallback, // fallback + #ifdef PROTOBUF_PREFETCH_PARSE_TABLE + ::_pbi::TcParser::GetTable<::nodehub::tests::StringValue>(), // to_prefetch + #endif // PROTOBUF_PREFETCH_PARSE_TABLE + }, {{ + // string value = 1; + {::_pbi::TcParser::FastUS1, + {10, 0, 0, + PROTOBUF_FIELD_OFFSET(StringValue, _impl_.value_)}}, + }}, {{ + 65535, 65535 + }}, {{ + // string value = 1; + {PROTOBUF_FIELD_OFFSET(StringValue, _impl_.value_), _Internal::kHasBitsOffset + 0, 0, (0 | ::_fl::kFcOptional | ::_fl::kUtf8String | ::_fl::kRepAString)}, + }}, + // no aux_entries + {{ + "\31\5\0\0\0\0\0\0" + "nodehub.tests.StringValue" + "value" + }}, +}; +PROTOBUF_NOINLINE void StringValue::Clear() { +// @@protoc_insertion_point(message_clear_start:nodehub.tests.StringValue) + ::google::protobuf::internal::TSanWrite(&_impl_); + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + cached_has_bits = _impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + _impl_.value_.ClearNonDefaultToEmpty(); + } + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>(); +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::uint8_t* PROTOBUF_NONNULL StringValue::_InternalSerialize( + const ::google::protobuf::MessageLite& base, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) { + const StringValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::uint8_t* PROTOBUF_NONNULL StringValue::_InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + const StringValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + this_.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(serialize_to_array_start:nodehub.tests.StringValue) + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = this_._impl_._has_bits_[0]; + // string value = 1; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (!this_._internal_value().empty()) { + const ::std::string& _s = this_._internal_value(); + ::google::protobuf::internal::WireFormatLite::VerifyUtf8String( + _s.data(), static_cast(_s.length()), ::google::protobuf::internal::WireFormatLite::SERIALIZE, "nodehub.tests.StringValue.value"); + target = stream->WriteStringMaybeAliased(1, _s, target); + } + } + + if (ABSL_PREDICT_FALSE(this_._internal_metadata_.have_unknown_fields())) { + target = + ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + this_._internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:nodehub.tests.StringValue) + return target; +} + +#if defined(PROTOBUF_CUSTOM_VTABLE) +::size_t StringValue::ByteSizeLong(const MessageLite& base) { + const StringValue& this_ = static_cast(base); +#else // PROTOBUF_CUSTOM_VTABLE +::size_t StringValue::ByteSizeLong() const { + const StringValue& this_ = *this; +#endif // PROTOBUF_CUSTOM_VTABLE + // @@protoc_insertion_point(message_byte_size_start:nodehub.tests.StringValue) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + { + // string value = 1; + cached_has_bits = this_._impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (!this_._internal_value().empty()) { + total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( + this_._internal_value()); + } + } + } + return this_.MaybeComputeUnknownFieldsSize(total_size, + &this_._impl_._cached_size_); +} + +void StringValue::MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg) { + auto* const _this = + static_cast(&to_msg); + auto& from = static_cast(from_msg); + if constexpr (::_pbi::DebugHardenCheckHasBitConsistency()) { + from.CheckHasBitConsistency(); + } + // @@protoc_insertion_point(class_specific_merge_from_start:nodehub.tests.StringValue) + ABSL_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void)cached_has_bits; + + cached_has_bits = from._impl_._has_bits_[0]; + if (CheckHasBit(cached_has_bits, 0x00000001U)) { + if (!from._internal_value().empty()) { + _this->_internal_set_value(from._internal_value()); + } else { + if (_this->_impl_.value_.IsDefault()) { + _this->_internal_set_value(""); + } + } + } + _this->_impl_._has_bits_[0] |= cached_has_bits; + _this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>( + from._internal_metadata_); +} + +void StringValue::CopyFrom(const StringValue& from) { + // @@protoc_insertion_point(class_specific_copy_from_start:nodehub.tests.StringValue) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + + +void StringValue::InternalSwap(StringValue* PROTOBUF_RESTRICT PROTOBUF_NONNULL other) { + using ::std::swap; + auto* arena = GetArena(); + ABSL_DCHECK_EQ(arena, other->GetArena()); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + ::_pbi::ArenaStringPtr::InternalSwap(&_impl_.value_, &other->_impl_.value_, arena); +} + +::google::protobuf::Metadata StringValue::GetMetadata() const { + return ::google::protobuf::Message::GetMetadataImpl(GetClassData()->full()); +} +// @@protoc_insertion_point(namespace_scope) +} // namespace tests +} // namespace nodehub +namespace google { +namespace protobuf { +} // namespace protobuf +} // namespace google +// @@protoc_insertion_point(global_scope) +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 static ::std::false_type + _static_init2_ [[maybe_unused]] = + (::_pbi::AddDescriptors(&descriptor_table_test_5fprimitives_2eproto), + ::std::false_type{}); +#include "google/protobuf/port_undef.inc" diff --git a/applications/tests/protos/test_primitives.pb.h b/applications/tests/protos/test_primitives.pb.h new file mode 100644 index 0000000..dee90d3 --- /dev/null +++ b/applications/tests/protos/test_primitives.pb.h @@ -0,0 +1,1041 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// NO CHECKED-IN PROTOBUF GENCODE +// source: test_primitives.proto +// Protobuf C++ Version: 6.34.0-dev + +#ifndef test_5fprimitives_2eproto_2epb_2eh +#define test_5fprimitives_2eproto_2epb_2eh + +#include +#include +#include +#include + +#include "google/protobuf/runtime_version.h" +#if PROTOBUF_VERSION != 6034000 +#error "Protobuf C++ gencode is built with an incompatible version of" +#error "Protobuf C++ headers/runtime. See" +#error "https://protobuf.dev/support/cross-version-runtime-guarantee/#cpp" +#endif +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_tctable_decl.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/message_lite.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" +// @@protoc_insertion_point(includes) + +// Must be included last. +#include "google/protobuf/port_def.inc" + +#define PROTOBUF_INTERNAL_EXPORT_test_5fprimitives_2eproto + +namespace google { +namespace protobuf { +namespace internal { +template +::absl::string_view GetAnyMessageName(); +} // namespace internal +} // namespace protobuf +} // namespace google + +// Internal implementation detail -- do not use these members. +struct TableStruct_test_5fprimitives_2eproto { + static const ::uint32_t offsets[]; +}; +extern "C" { +extern const ::google::protobuf::internal::DescriptorTable descriptor_table_test_5fprimitives_2eproto; +} // extern "C" +namespace nodehub { +namespace tests { +class BoolValue; +struct BoolValueDefaultTypeInternal; +extern BoolValueDefaultTypeInternal _BoolValue_default_instance_; +extern const ::google::protobuf::internal::ClassDataFull BoolValue_class_data_; +class FloatValue; +struct FloatValueDefaultTypeInternal; +extern FloatValueDefaultTypeInternal _FloatValue_default_instance_; +extern const ::google::protobuf::internal::ClassDataFull FloatValue_class_data_; +class IntValue; +struct IntValueDefaultTypeInternal; +extern IntValueDefaultTypeInternal _IntValue_default_instance_; +extern const ::google::protobuf::internal::ClassDataFull IntValue_class_data_; +class StringValue; +struct StringValueDefaultTypeInternal; +extern StringValueDefaultTypeInternal _StringValue_default_instance_; +extern const ::google::protobuf::internal::ClassDataFull StringValue_class_data_; +} // namespace tests +} // namespace nodehub +namespace google { +namespace protobuf { +} // namespace protobuf +} // namespace google + +namespace nodehub { +namespace tests { + +// =================================================================== + + +// ------------------------------------------------------------------- + +class StringValue final : public ::google::protobuf::Message +/* @@protoc_insertion_point(class_definition:nodehub.tests.StringValue) */ { + public: + inline StringValue() : StringValue(nullptr) {} + ~StringValue() PROTOBUF_FINAL; + +#if defined(PROTOBUF_CUSTOM_VTABLE) + void operator delete(StringValue* PROTOBUF_NONNULL msg, ::std::destroying_delete_t) { + SharedDtor(*msg); + ::google::protobuf::internal::SizedDelete(msg, sizeof(StringValue)); + } +#endif + + template + explicit PROTOBUF_CONSTEXPR StringValue(::google::protobuf::internal::ConstantInitialized); + + inline StringValue(const StringValue& from) : StringValue(nullptr, from) {} + inline StringValue(StringValue&& from) noexcept + : StringValue(nullptr, ::std::move(from)) {} + inline StringValue& operator=(const StringValue& from) { + CopyFrom(from); + return *this; + } + inline StringValue& operator=(StringValue&& from) noexcept { + if (this == &from) return *this; + if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance); + } + inline ::google::protobuf::UnknownFieldSet* PROTOBUF_NONNULL mutable_unknown_fields() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>(); + } + + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL descriptor() { + return GetDescriptor(); + } + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::google::protobuf::Reflection* PROTOBUF_NONNULL GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const StringValue& default_instance() { + return *reinterpret_cast( + &_StringValue_default_instance_); + } + static constexpr int kIndexInFileMessages = 3; + friend void swap(StringValue& a, StringValue& b) { a.Swap(&b); } + inline void Swap(StringValue* PROTOBUF_NONNULL other) { + if (other == this) return; + if (::google::protobuf::internal::CanUseInternalSwap(GetArena(), other->GetArena())) { + InternalSwap(other); + } else { + ::google::protobuf::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(StringValue* PROTOBUF_NONNULL other) { + if (other == this) return; + ABSL_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + StringValue* PROTOBUF_NONNULL New(::google::protobuf::Arena* PROTOBUF_NULLABLE arena = nullptr) const { + return ::google::protobuf::Message::DefaultConstruct(arena); + } + using ::google::protobuf::Message::CopyFrom; + void CopyFrom(const StringValue& from); + using ::google::protobuf::Message::MergeFrom; + void MergeFrom(const StringValue& from) { StringValue::MergeImpl(*this, from); } + + private: + static void MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg); + + public: + bool IsInitialized() const { + return true; + } + ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL; + #if defined(PROTOBUF_CUSTOM_VTABLE) + private: + static ::size_t ByteSizeLong(const ::google::protobuf::MessageLite& msg); + static ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + const ::google::protobuf::MessageLite& msg, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream); + + public: + ::size_t ByteSizeLong() const { return ByteSizeLong(*this); } + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + return _InternalSerialize(*this, target, stream); + } + #else // PROTOBUF_CUSTOM_VTABLE + ::size_t ByteSizeLong() const final; + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const final; + #endif // PROTOBUF_CUSTOM_VTABLE + int GetCachedSize() const { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static void SharedDtor(MessageLite& self); + void InternalSwap(StringValue* PROTOBUF_NONNULL other); + private: + template + friend ::absl::string_view(::google::protobuf::internal::GetAnyMessageName)(); + static ::absl::string_view FullMessageName() { return "nodehub.tests.StringValue"; } + + explicit StringValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + StringValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const StringValue& from); + StringValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, StringValue&& from) noexcept + : StringValue(arena) { + *this = ::std::move(from); + } + const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL GetClassData() const PROTOBUF_FINAL; + static void* PROTOBUF_NONNULL PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static constexpr auto InternalNewImpl_(); + + public: + static constexpr auto InternalGenerateClassData_(); + + ::google::protobuf::Metadata GetMetadata() const; + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; + // string value = 1; + void clear_value() ; + const ::std::string& value() const; + template + void set_value(Arg_&& arg, Args_... args); + ::std::string* PROTOBUF_NONNULL mutable_value(); + [[nodiscard]] ::std::string* PROTOBUF_NULLABLE release_value(); + void set_allocated_value(::std::string* PROTOBUF_NULLABLE value); + + private: + const ::std::string& _internal_value() const; + PROTOBUF_ALWAYS_INLINE void _internal_set_value(const ::std::string& value); + ::std::string* PROTOBUF_NONNULL _internal_mutable_value(); + + public: + // @@protoc_insertion_point(class_scope:nodehub.tests.StringValue) + private: + class _Internal; + friend class ::google::protobuf::internal::TcParser; + static const ::google::protobuf::internal::TcParseTable<0, 1, + 0, 39, + 2> + _table_; + + friend class ::google::protobuf::MessageLite; + friend class ::google::protobuf::Arena; + friend ::google::protobuf::internal::PrivateAccess; + template + friend class ::google::protobuf::Arena::InternalHelper; + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + struct Impl_ { + inline explicit constexpr Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::internal::ConstantInitialized) noexcept; + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const Impl_& from, + const StringValue& from_msg); + ::google::protobuf::internal::HasBits<1> _has_bits_; + ::google::protobuf::internal::CachedSize _cached_size_; + ::google::protobuf::internal::ArenaStringPtr value_; + PROTOBUF_TSAN_DECLARE_MEMBER + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_test_5fprimitives_2eproto; +}; + +extern const ::google::protobuf::internal::ClassDataFull StringValue_class_data_; +// ------------------------------------------------------------------- + +class IntValue final : public ::google::protobuf::Message +/* @@protoc_insertion_point(class_definition:nodehub.tests.IntValue) */ { + public: + inline IntValue() : IntValue(nullptr) {} + ~IntValue() PROTOBUF_FINAL; + +#if defined(PROTOBUF_CUSTOM_VTABLE) + void operator delete(IntValue* PROTOBUF_NONNULL msg, ::std::destroying_delete_t) { + SharedDtor(*msg); + ::google::protobuf::internal::SizedDelete(msg, sizeof(IntValue)); + } +#endif + + template + explicit PROTOBUF_CONSTEXPR IntValue(::google::protobuf::internal::ConstantInitialized); + + inline IntValue(const IntValue& from) : IntValue(nullptr, from) {} + inline IntValue(IntValue&& from) noexcept + : IntValue(nullptr, ::std::move(from)) {} + inline IntValue& operator=(const IntValue& from) { + CopyFrom(from); + return *this; + } + inline IntValue& operator=(IntValue&& from) noexcept { + if (this == &from) return *this; + if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance); + } + inline ::google::protobuf::UnknownFieldSet* PROTOBUF_NONNULL mutable_unknown_fields() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>(); + } + + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL descriptor() { + return GetDescriptor(); + } + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::google::protobuf::Reflection* PROTOBUF_NONNULL GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const IntValue& default_instance() { + return *reinterpret_cast( + &_IntValue_default_instance_); + } + static constexpr int kIndexInFileMessages = 0; + friend void swap(IntValue& a, IntValue& b) { a.Swap(&b); } + inline void Swap(IntValue* PROTOBUF_NONNULL other) { + if (other == this) return; + if (::google::protobuf::internal::CanUseInternalSwap(GetArena(), other->GetArena())) { + InternalSwap(other); + } else { + ::google::protobuf::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(IntValue* PROTOBUF_NONNULL other) { + if (other == this) return; + ABSL_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + IntValue* PROTOBUF_NONNULL New(::google::protobuf::Arena* PROTOBUF_NULLABLE arena = nullptr) const { + return ::google::protobuf::Message::DefaultConstruct(arena); + } + using ::google::protobuf::Message::CopyFrom; + void CopyFrom(const IntValue& from); + using ::google::protobuf::Message::MergeFrom; + void MergeFrom(const IntValue& from) { IntValue::MergeImpl(*this, from); } + + private: + static void MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg); + + public: + bool IsInitialized() const { + return true; + } + ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL; + #if defined(PROTOBUF_CUSTOM_VTABLE) + private: + static ::size_t ByteSizeLong(const ::google::protobuf::MessageLite& msg); + static ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + const ::google::protobuf::MessageLite& msg, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream); + + public: + ::size_t ByteSizeLong() const { return ByteSizeLong(*this); } + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + return _InternalSerialize(*this, target, stream); + } + #else // PROTOBUF_CUSTOM_VTABLE + ::size_t ByteSizeLong() const final; + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const final; + #endif // PROTOBUF_CUSTOM_VTABLE + int GetCachedSize() const { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static void SharedDtor(MessageLite& self); + void InternalSwap(IntValue* PROTOBUF_NONNULL other); + private: + template + friend ::absl::string_view(::google::protobuf::internal::GetAnyMessageName)(); + static ::absl::string_view FullMessageName() { return "nodehub.tests.IntValue"; } + + explicit IntValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + IntValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const IntValue& from); + IntValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, IntValue&& from) noexcept + : IntValue(arena) { + *this = ::std::move(from); + } + const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL GetClassData() const PROTOBUF_FINAL; + static void* PROTOBUF_NONNULL PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static constexpr auto InternalNewImpl_(); + + public: + static constexpr auto InternalGenerateClassData_(); + + ::google::protobuf::Metadata GetMetadata() const; + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; + // int32 value = 1; + void clear_value() ; + ::int32_t value() const; + void set_value(::int32_t value); + + private: + ::int32_t _internal_value() const; + void _internal_set_value(::int32_t value); + + public: + // @@protoc_insertion_point(class_scope:nodehub.tests.IntValue) + private: + class _Internal; + friend class ::google::protobuf::internal::TcParser; + static const ::google::protobuf::internal::TcParseTable<0, 1, + 0, 0, + 2> + _table_; + + friend class ::google::protobuf::MessageLite; + friend class ::google::protobuf::Arena; + friend ::google::protobuf::internal::PrivateAccess; + template + friend class ::google::protobuf::Arena::InternalHelper; + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + struct Impl_ { + inline explicit constexpr Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::internal::ConstantInitialized) noexcept; + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const Impl_& from, + const IntValue& from_msg); + ::google::protobuf::internal::HasBits<1> _has_bits_; + ::google::protobuf::internal::CachedSize _cached_size_; + ::int32_t value_; + PROTOBUF_TSAN_DECLARE_MEMBER + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_test_5fprimitives_2eproto; +}; + +extern const ::google::protobuf::internal::ClassDataFull IntValue_class_data_; +// ------------------------------------------------------------------- + +class FloatValue final : public ::google::protobuf::Message +/* @@protoc_insertion_point(class_definition:nodehub.tests.FloatValue) */ { + public: + inline FloatValue() : FloatValue(nullptr) {} + ~FloatValue() PROTOBUF_FINAL; + +#if defined(PROTOBUF_CUSTOM_VTABLE) + void operator delete(FloatValue* PROTOBUF_NONNULL msg, ::std::destroying_delete_t) { + SharedDtor(*msg); + ::google::protobuf::internal::SizedDelete(msg, sizeof(FloatValue)); + } +#endif + + template + explicit PROTOBUF_CONSTEXPR FloatValue(::google::protobuf::internal::ConstantInitialized); + + inline FloatValue(const FloatValue& from) : FloatValue(nullptr, from) {} + inline FloatValue(FloatValue&& from) noexcept + : FloatValue(nullptr, ::std::move(from)) {} + inline FloatValue& operator=(const FloatValue& from) { + CopyFrom(from); + return *this; + } + inline FloatValue& operator=(FloatValue&& from) noexcept { + if (this == &from) return *this; + if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance); + } + inline ::google::protobuf::UnknownFieldSet* PROTOBUF_NONNULL mutable_unknown_fields() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>(); + } + + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL descriptor() { + return GetDescriptor(); + } + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::google::protobuf::Reflection* PROTOBUF_NONNULL GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const FloatValue& default_instance() { + return *reinterpret_cast( + &_FloatValue_default_instance_); + } + static constexpr int kIndexInFileMessages = 1; + friend void swap(FloatValue& a, FloatValue& b) { a.Swap(&b); } + inline void Swap(FloatValue* PROTOBUF_NONNULL other) { + if (other == this) return; + if (::google::protobuf::internal::CanUseInternalSwap(GetArena(), other->GetArena())) { + InternalSwap(other); + } else { + ::google::protobuf::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FloatValue* PROTOBUF_NONNULL other) { + if (other == this) return; + ABSL_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + FloatValue* PROTOBUF_NONNULL New(::google::protobuf::Arena* PROTOBUF_NULLABLE arena = nullptr) const { + return ::google::protobuf::Message::DefaultConstruct(arena); + } + using ::google::protobuf::Message::CopyFrom; + void CopyFrom(const FloatValue& from); + using ::google::protobuf::Message::MergeFrom; + void MergeFrom(const FloatValue& from) { FloatValue::MergeImpl(*this, from); } + + private: + static void MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg); + + public: + bool IsInitialized() const { + return true; + } + ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL; + #if defined(PROTOBUF_CUSTOM_VTABLE) + private: + static ::size_t ByteSizeLong(const ::google::protobuf::MessageLite& msg); + static ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + const ::google::protobuf::MessageLite& msg, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream); + + public: + ::size_t ByteSizeLong() const { return ByteSizeLong(*this); } + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + return _InternalSerialize(*this, target, stream); + } + #else // PROTOBUF_CUSTOM_VTABLE + ::size_t ByteSizeLong() const final; + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const final; + #endif // PROTOBUF_CUSTOM_VTABLE + int GetCachedSize() const { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static void SharedDtor(MessageLite& self); + void InternalSwap(FloatValue* PROTOBUF_NONNULL other); + private: + template + friend ::absl::string_view(::google::protobuf::internal::GetAnyMessageName)(); + static ::absl::string_view FullMessageName() { return "nodehub.tests.FloatValue"; } + + explicit FloatValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + FloatValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const FloatValue& from); + FloatValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, FloatValue&& from) noexcept + : FloatValue(arena) { + *this = ::std::move(from); + } + const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL GetClassData() const PROTOBUF_FINAL; + static void* PROTOBUF_NONNULL PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static constexpr auto InternalNewImpl_(); + + public: + static constexpr auto InternalGenerateClassData_(); + + ::google::protobuf::Metadata GetMetadata() const; + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; + // float value = 1; + void clear_value() ; + float value() const; + void set_value(float value); + + private: + float _internal_value() const; + void _internal_set_value(float value); + + public: + // @@protoc_insertion_point(class_scope:nodehub.tests.FloatValue) + private: + class _Internal; + friend class ::google::protobuf::internal::TcParser; + static const ::google::protobuf::internal::TcParseTable<0, 1, + 0, 0, + 2> + _table_; + + friend class ::google::protobuf::MessageLite; + friend class ::google::protobuf::Arena; + friend ::google::protobuf::internal::PrivateAccess; + template + friend class ::google::protobuf::Arena::InternalHelper; + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + struct Impl_ { + inline explicit constexpr Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::internal::ConstantInitialized) noexcept; + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const Impl_& from, + const FloatValue& from_msg); + ::google::protobuf::internal::HasBits<1> _has_bits_; + ::google::protobuf::internal::CachedSize _cached_size_; + float value_; + PROTOBUF_TSAN_DECLARE_MEMBER + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_test_5fprimitives_2eproto; +}; + +extern const ::google::protobuf::internal::ClassDataFull FloatValue_class_data_; +// ------------------------------------------------------------------- + +class BoolValue final : public ::google::protobuf::Message +/* @@protoc_insertion_point(class_definition:nodehub.tests.BoolValue) */ { + public: + inline BoolValue() : BoolValue(nullptr) {} + ~BoolValue() PROTOBUF_FINAL; + +#if defined(PROTOBUF_CUSTOM_VTABLE) + void operator delete(BoolValue* PROTOBUF_NONNULL msg, ::std::destroying_delete_t) { + SharedDtor(*msg); + ::google::protobuf::internal::SizedDelete(msg, sizeof(BoolValue)); + } +#endif + + template + explicit PROTOBUF_CONSTEXPR BoolValue(::google::protobuf::internal::ConstantInitialized); + + inline BoolValue(const BoolValue& from) : BoolValue(nullptr, from) {} + inline BoolValue(BoolValue&& from) noexcept + : BoolValue(nullptr, ::std::move(from)) {} + inline BoolValue& operator=(const BoolValue& from) { + CopyFrom(from); + return *this; + } + inline BoolValue& operator=(BoolValue&& from) noexcept { + if (this == &from) return *this; + if (::google::protobuf::internal::CanMoveWithInternalSwap(GetArena(), from.GetArena())) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance); + } + inline ::google::protobuf::UnknownFieldSet* PROTOBUF_NONNULL mutable_unknown_fields() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>(); + } + + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL descriptor() { + return GetDescriptor(); + } + static const ::google::protobuf::Descriptor* PROTOBUF_NONNULL GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::google::protobuf::Reflection* PROTOBUF_NONNULL GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const BoolValue& default_instance() { + return *reinterpret_cast( + &_BoolValue_default_instance_); + } + static constexpr int kIndexInFileMessages = 2; + friend void swap(BoolValue& a, BoolValue& b) { a.Swap(&b); } + inline void Swap(BoolValue* PROTOBUF_NONNULL other) { + if (other == this) return; + if (::google::protobuf::internal::CanUseInternalSwap(GetArena(), other->GetArena())) { + InternalSwap(other); + } else { + ::google::protobuf::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(BoolValue* PROTOBUF_NONNULL other) { + if (other == this) return; + ABSL_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + BoolValue* PROTOBUF_NONNULL New(::google::protobuf::Arena* PROTOBUF_NULLABLE arena = nullptr) const { + return ::google::protobuf::Message::DefaultConstruct(arena); + } + using ::google::protobuf::Message::CopyFrom; + void CopyFrom(const BoolValue& from); + using ::google::protobuf::Message::MergeFrom; + void MergeFrom(const BoolValue& from) { BoolValue::MergeImpl(*this, from); } + + private: + static void MergeImpl(::google::protobuf::MessageLite& to_msg, + const ::google::protobuf::MessageLite& from_msg); + + public: + bool IsInitialized() const { + return true; + } + ABSL_ATTRIBUTE_REINITIALIZES void Clear() PROTOBUF_FINAL; + #if defined(PROTOBUF_CUSTOM_VTABLE) + private: + static ::size_t ByteSizeLong(const ::google::protobuf::MessageLite& msg); + static ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + const ::google::protobuf::MessageLite& msg, ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream); + + public: + ::size_t ByteSizeLong() const { return ByteSizeLong(*this); } + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const { + return _InternalSerialize(*this, target, stream); + } + #else // PROTOBUF_CUSTOM_VTABLE + ::size_t ByteSizeLong() const final; + ::uint8_t* PROTOBUF_NONNULL _InternalSerialize( + ::uint8_t* PROTOBUF_NONNULL target, + ::google::protobuf::io::EpsCopyOutputStream* PROTOBUF_NONNULL stream) const final; + #endif // PROTOBUF_CUSTOM_VTABLE + int GetCachedSize() const { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static void SharedDtor(MessageLite& self); + void InternalSwap(BoolValue* PROTOBUF_NONNULL other); + private: + template + friend ::absl::string_view(::google::protobuf::internal::GetAnyMessageName)(); + static ::absl::string_view FullMessageName() { return "nodehub.tests.BoolValue"; } + + explicit BoolValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + BoolValue(::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const BoolValue& from); + BoolValue( + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, BoolValue&& from) noexcept + : BoolValue(arena) { + *this = ::std::move(from); + } + const ::google::protobuf::internal::ClassData* PROTOBUF_NONNULL GetClassData() const PROTOBUF_FINAL; + static void* PROTOBUF_NONNULL PlacementNew_( + const void* PROTOBUF_NONNULL, void* PROTOBUF_NONNULL mem, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + static constexpr auto InternalNewImpl_(); + + public: + static constexpr auto InternalGenerateClassData_(); + + ::google::protobuf::Metadata GetMetadata() const; + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + enum : int { + kValueFieldNumber = 1, + }; + // bool value = 1; + void clear_value() ; + bool value() const; + void set_value(bool value); + + private: + bool _internal_value() const; + void _internal_set_value(bool value); + + public: + // @@protoc_insertion_point(class_scope:nodehub.tests.BoolValue) + private: + class _Internal; + friend class ::google::protobuf::internal::TcParser; + static const ::google::protobuf::internal::TcParseTable<0, 1, + 0, 0, + 2> + _table_; + + friend class ::google::protobuf::MessageLite; + friend class ::google::protobuf::Arena; + friend ::google::protobuf::internal::PrivateAccess; + template + friend class ::google::protobuf::Arena::InternalHelper; + using InternalArenaConstructable_ = void; + using DestructorSkippable_ = void; + struct Impl_ { + inline explicit constexpr Impl_(::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::internal::ConstantInitialized) noexcept; + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena); + inline explicit Impl_( + ::google::protobuf::internal::InternalVisibility visibility, + ::google::protobuf::Arena* PROTOBUF_NULLABLE arena, const Impl_& from, + const BoolValue& from_msg); + ::google::protobuf::internal::HasBits<1> _has_bits_; + ::google::protobuf::internal::CachedSize _cached_size_; + bool value_; + PROTOBUF_TSAN_DECLARE_MEMBER + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_test_5fprimitives_2eproto; +}; + +extern const ::google::protobuf::internal::ClassDataFull BoolValue_class_data_; + +// =================================================================== + + + + +// =================================================================== + + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// IntValue + +// int32 value = 1; +inline void IntValue::clear_value() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_ = 0; + ClearHasBit(_impl_._has_bits_[0], + 0x00000001U); +} +inline ::int32_t IntValue::value() const { + // @@protoc_insertion_point(field_get:nodehub.tests.IntValue.value) + return _internal_value(); +} +inline void IntValue::set_value(::int32_t value) { + _internal_set_value(value); + SetHasBit(_impl_._has_bits_[0], 0x00000001U); + // @@protoc_insertion_point(field_set:nodehub.tests.IntValue.value) +} +inline ::int32_t IntValue::_internal_value() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.value_; +} +inline void IntValue::_internal_set_value(::int32_t value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_ = value; +} + +// ------------------------------------------------------------------- + +// FloatValue + +// float value = 1; +inline void FloatValue::clear_value() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_ = 0; + ClearHasBit(_impl_._has_bits_[0], + 0x00000001U); +} +inline float FloatValue::value() const { + // @@protoc_insertion_point(field_get:nodehub.tests.FloatValue.value) + return _internal_value(); +} +inline void FloatValue::set_value(float value) { + _internal_set_value(value); + SetHasBit(_impl_._has_bits_[0], 0x00000001U); + // @@protoc_insertion_point(field_set:nodehub.tests.FloatValue.value) +} +inline float FloatValue::_internal_value() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.value_; +} +inline void FloatValue::_internal_set_value(float value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_ = value; +} + +// ------------------------------------------------------------------- + +// BoolValue + +// bool value = 1; +inline void BoolValue::clear_value() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_ = false; + ClearHasBit(_impl_._has_bits_[0], + 0x00000001U); +} +inline bool BoolValue::value() const { + // @@protoc_insertion_point(field_get:nodehub.tests.BoolValue.value) + return _internal_value(); +} +inline void BoolValue::set_value(bool value) { + _internal_set_value(value); + SetHasBit(_impl_._has_bits_[0], 0x00000001U); + // @@protoc_insertion_point(field_set:nodehub.tests.BoolValue.value) +} +inline bool BoolValue::_internal_value() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.value_; +} +inline void BoolValue::_internal_set_value(bool value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_ = value; +} + +// ------------------------------------------------------------------- + +// StringValue + +// string value = 1; +inline void StringValue::clear_value() { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_.ClearToEmpty(); + ClearHasBit(_impl_._has_bits_[0], + 0x00000001U); +} +inline const ::std::string& StringValue::value() const + ABSL_ATTRIBUTE_LIFETIME_BOUND { + // @@protoc_insertion_point(field_get:nodehub.tests.StringValue.value) + return _internal_value(); +} +template +PROTOBUF_ALWAYS_INLINE void StringValue::set_value(Arg_&& arg, Args_... args) { + ::google::protobuf::internal::TSanWrite(&_impl_); + SetHasBit(_impl_._has_bits_[0], 0x00000001U); + _impl_.value_.Set(static_cast(arg), args..., GetArena()); + // @@protoc_insertion_point(field_set:nodehub.tests.StringValue.value) +} +inline ::std::string* PROTOBUF_NONNULL StringValue::mutable_value() + ABSL_ATTRIBUTE_LIFETIME_BOUND { + SetHasBit(_impl_._has_bits_[0], 0x00000001U); + ::std::string* _s = _internal_mutable_value(); + // @@protoc_insertion_point(field_mutable:nodehub.tests.StringValue.value) + return _s; +} +inline const ::std::string& StringValue::_internal_value() const { + ::google::protobuf::internal::TSanRead(&_impl_); + return _impl_.value_.Get(); +} +inline void StringValue::_internal_set_value(const ::std::string& value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + _impl_.value_.Set(value, GetArena()); +} +inline ::std::string* PROTOBUF_NONNULL StringValue::_internal_mutable_value() { + ::google::protobuf::internal::TSanWrite(&_impl_); + return _impl_.value_.Mutable( GetArena()); +} +inline ::std::string* PROTOBUF_NULLABLE StringValue::release_value() { + ::google::protobuf::internal::TSanWrite(&_impl_); + // @@protoc_insertion_point(field_release:nodehub.tests.StringValue.value) + if (!CheckHasBit(_impl_._has_bits_[0], 0x00000001U)) { + return nullptr; + } + ClearHasBit(_impl_._has_bits_[0], 0x00000001U); + auto* released = _impl_.value_.Release(); + if (::google::protobuf::internal::DebugHardenForceCopyDefaultString()) { + _impl_.value_.Set("", GetArena()); + } + return released; +} +inline void StringValue::set_allocated_value(::std::string* PROTOBUF_NULLABLE value) { + ::google::protobuf::internal::TSanWrite(&_impl_); + if (value != nullptr) { + SetHasBit(_impl_._has_bits_[0], 0x00000001U); + } else { + ClearHasBit(_impl_._has_bits_[0], 0x00000001U); + } + _impl_.value_.SetAllocated(value, GetArena()); + if (::google::protobuf::internal::DebugHardenForceCopyDefaultString() && _impl_.value_.IsDefault()) { + _impl_.value_.Set("", GetArena()); + } + // @@protoc_insertion_point(field_set_allocated:nodehub.tests.StringValue.value) +} + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // __GNUC__ + +// @@protoc_insertion_point(namespace_scope) +} // namespace tests +} // namespace nodehub + + +// @@protoc_insertion_point(global_scope) + +#include "google/protobuf/port_undef.inc" + +#endif // test_5fprimitives_2eproto_2epb_2eh diff --git a/applications/tests/test_primitives.proto b/applications/tests/test_primitives.proto new file mode 100644 index 0000000..67ff854 --- /dev/null +++ b/applications/tests/test_primitives.proto @@ -0,0 +1,20 @@ +syntax = "proto3"; + +package nodehub.tests; + +message IntValue { + int32 value = 1; +} + +message FloatValue { + float value = 1; +} + +message BoolValue { + bool value = 1; +} + +message StringValue { + string value = 1; +} + diff --git a/blueprints.log b/blueprints.log new file mode 100644 index 0000000..a8f2c90 --- /dev/null +++ b/blueprints.log @@ -0,0 +1,5 @@ +[2025-11-19 22:47:18:143] [debug] [blueprints] Logger level set to debug +[2025-11-19 22:47:18:144] [info] [blueprints] Using graph file: ./BlueprintsGraph.json +[2025-11-19 22:47:18:144] [info] [blueprints] Loading graph from: ./BlueprintsGraph.json +[2025-11-19 22:47:18:145] [info] [blueprints] Context initialized +[2025-11-19 22:47:18:155] [warning] [blueprints] WARNING: No Start blocks found in graph diff --git a/docs-classes.md b/docs-classes.md deleted file mode 100644 index 50e6af6..0000000 --- a/docs-classes.md +++ /dev/null @@ -1,354 +0,0 @@ -# Class Diagram Overview - -Compact class diagram showing key classes and their relationships. - -``` -┌─────────────────────────────────────┠-│ Application │ -│ (Base application lifecycle) │ -├─────────────────────────────────────┤ -│ +OnStart() │ -│ +OnStop() │ -│ +OnFrame(deltaTime) │ -│ +TakeScreenshot() │ -└──────────────┬──────────────────────┘ - │ extends - â–¼ -┌─────────────────────────────────────┠-│ App │ -│ (Main application class) │ -├─────────────────────────────────────┤ -│ -m_Nodes: vector │ -│ -m_Links: vector │ -│ -m_RootContainers: vector<...> │ -│ -m_ActiveRootContainer: RootContainer│ -│ +GetNextId(): int │ -│ +FindNode(id): Node* │ -│ +FindLink(id): Link* │ -│ +FindPin(id): Pin* │ -│ +SpawnBlockNode(type): Node* │ -│ +SpawnParameterNode(type): Node* │ -│ +SaveGraph() │ -│ +LoadGraph() │ -│ +ExecuteRuntimeStep() │ -│ +RenderNodes() │ -│ +RenderLinks() │ -└─┬────────────┬───────────────┬──────┘ - │ │ │ - │ manages │ owns │ uses - │ │ │ - â–¼ â–¼ â–¼ -┌──────────────────────┠┌─────────┠┌──────────────┠-│ RootContainer │ │ Node │ │ BlockRegistry│ -│ (File-based graph) │ │ │ │ (Factory) │ -├──────────────────────┤ └────┬────┘ ├──────────────┤ -│ -m_Filename: string │ │ │ +CreateBlock()│ -│ -m_IsDirty: bool │ │ has │ +Register() │ -│ +GetFilename() │ â–¼ └──────────────┘ -│ +SetDirty() │ ┌─────────┠-└──────────┬───────────┘ │ Block │◄───┠- │ extends │ │ │ - â–¼ ├─────────┤ │ -┌──────────────────────┠│ +Build() │ │ extends -│ Container │ │ +Render()│ │ -│ (Hierarchical group) │ │ +Run() │ │ -├──────────────────────┤ │ +Activate│ │ -│ -m_NodeIds: vector │ │ Output()│ │ -│ -m_LinkIds: vector │ │ +Activate│ │ -│ -m_Children: vector │ │ Input() │ │ -│ +GetNextId(): int │ └────┬────┘ │ -│ +AddNode() │ │ │ -│ +RemoveNode() │ │ │ -│ +GetNodes(): vector │ │ │ -│ +GetLinks(): vector │ │ │ -│ +Run() │ │ │ -│ +Render() │ │ │ -└──────────────────────┘ │ │ - │ │ - │ │ - ┌────────────┴──┠│ - │ │ │ - â–¼ â–¼ │ - ┌──────────────────┠┌──────────────────┠- │ ParameterizedBlock│ │ ParameterNode │ - │ (Block + params) │ │ (Value nodes) │ - ├──────────────────┤ ├──────────────────┤ - │ -m_InputParams │ │ -m_ID: int │ - │ -m_OutputParams │ │ -m_Name: string │ - │ -m_Inputs │ │ -m_Type: PinType │ - │ -m_Outputs │ │ -m_BoolValue │ - │ +AddInputParam() │ │ -m_IntValue │ - │ +AddOutputParam() │ │ -m_FloatValue │ - │ +AddInput() │ │ +GetBool() │ - │ +AddOutput() │ │ +SetBool() │ - └──────────────────┘ │ +Run() │ - │ +Render() │ - │ +Build() │ - └──────────────────┘ - â–² - │ creates - │ - ┌──────────────────┠- │ParameterRegistry │ - │ (Factory) │ - ├──────────────────┤ - │ +CreateParameter()│ - └──────────────────┘ - - -┌──────────────────────────────────────┠-│ EditorContext │ -│ (Core editor & rendering) │ -├──────────────────────────────────────┤ -│ -m_Links: vector │ -│ -m_Nodes: vector │ -│ -m_GuidedLinks: map │ -│ +CreateLink(id): Link* │ -│ +DrawNodes() │ -│ +DrawLinks() │ -│ +HandleControlPointDragging() │ -│ +HandleGuidedLinkInteractions() │ -│ +ExecuteRuntime() │ -└───────┬────────────┬──────────────────┘ - │ manages │ manages - │ │ - â–¼ â–¼ - ┌─────────┠┌──────────────────┠- │ Link │ │ GuidedLink │ - │ │ │ (Waypoint routing)│ - └─────────┘ ├──────────────────┤ - │ +ID: LinkId │ - │ +Mode: LinkMode │ - │ +ControlPoints │ - │ +AddControlPoint() │ - │ +RemoveControlP()│ - │ +GetCurveSegm() │ - └────┬─────────────┘ - │ contains - â–¼ - ┌──────────────────┠- │ ControlPoint │ - │ (Waypoint) │ - ├──────────────────┤ - │ +Position: ImVec2│ - │ +IsManual: bool │ - └──────────────────┘ - â–² - │ persists - │ - ┌──────────────────┠- │ LinkSettings │ - │ (Persistence) │ - ├──────────────────┤ - │ +m_ID: LinkId │ - │ +m_Mode: LinkMode│ - │ +m_ControlPoints │ - │ +Serialize(): json│ - └──────────────────┘ - - -Relationship Legend: - ───► = manages/owns (composition) - ──..â–º = uses/creates (dependency) - ──┬── = extends (inheritance) - ──o── = has (aggregation) -``` - -## Key Components - -### Application Layer -- **[App](examples/blueprints-example/app.h)**: Main application class managing nodes, links, containers, and runtime execution -- Extends **[Application](examples/application/include/application.h)** base class for windowing and rendering - -### Block System -- **[Block](examples/blueprints-example/blocks/block.h)**: Abstract base class for executable nodes -- **[ParameterizedBlock](examples/blueprints-example/blocks/block.h)**: Block with input/output parameters and flow control -- **[BlockRegistry](examples/blueprints-example/blocks/block.h)**: Factory pattern for creating block instances - -### Parameter System -- **[ParameterNode](examples/blueprints-example/blocks/parameter_node.h)**: Standalone value nodes (Bool/Int/Float/String) -- **[ParameterRegistry](examples/blueprints-example/blocks/parameter_node.h)**: Factory for creating parameter nodes - -### Container System -- **[Container](examples/blueprints-example/containers/container.h)**: Hierarchical node/link grouping with ID management -- **[RootContainer](examples/blueprints-example/containers/root_container.h)**: Top-level container tied to a graph file - -### Editor System -- **[EditorContext](imgui_node_editor_internal.h)**: Core editor managing rendering and interactions -- **[GuidedLink](links-guided.h)**: User-controllable waypoints for link routing -- **[ControlPoint](links-guided.h)**: Individual waypoint on a guided link -- **[LinkSettings](links-guided.h)**: Persistence for guided link configuration - -## Source Files Reference - -| Class | Description | Header File | Implementation Files | -|-------|-------------|-------------|---------------------| -| [Application](examples/application/include/application.h) | Base application class for windowing, rendering, and lifecycle management | `examples/application/include/application.h` | - | -| [App](examples/blueprints-example/app.h) | Main application class managing nodes, links, containers, graph persistence, and runtime execution | `examples/blueprints-example/app.h` | `app-logic.cpp`, `app-render.cpp`, `app-runtime.cpp` | -| [Block](examples/blueprints-example/blocks/block.h) | Abstract base class for executable nodes with Build/Render/Run interface and activation API | `examples/blueprints-example/blocks/block.h` | `blocks/*.cpp` | -| [ParameterizedBlock](examples/blueprints-example/blocks/block.h) | Block with input/output parameters and flow control pins | `examples/blueprints-example/blocks/block.h` | `blocks/*.cpp` | -| [BlockRegistry](examples/blueprints-example/blocks/block.h) | Factory pattern registry for creating block instances by type name | `examples/blueprints-example/blocks/block.h` | - | -| [ParameterNode](examples/blueprints-example/blocks/parameter_node.h) | Standalone value nodes (Bool/Int/Float/String) with editable display modes | `examples/blueprints-example/blocks/parameter_node.h` | `blocks/parameter_node.cpp` | -| [ParameterRegistry](examples/blueprints-example/blocks/parameter_node.h) | Factory for creating parameter nodes by type | `examples/blueprints-example/blocks/parameter_node.h` | - | -| [Container](examples/blueprints-example/containers/container.h) | Hierarchical container for grouping nodes/links with ID management and safe pointer resolution | `examples/blueprints-example/containers/container.h` | `containers/container.cpp` | -| [RootContainer](examples/blueprints-example/containers/root_container.h) | Top-level container tied to a graph file, manages root-level nodes and links | `examples/blueprints-example/containers/root_container.h` | `containers/root_container.cpp` | -| [EditorContext](imgui_node_editor_internal.h) | Core editor managing rendering, interactions, link management, and guided link editing | `imgui_node_editor_internal.h` | `imgui_node_editor_render.cpp`, `imgui_node_editor_links.cpp` | -| [GuidedLink](links-guided.h) | User-controllable waypoints for custom link routing with control point management | `links-guided.h` | `imgui_node_editor_links.cpp` | -| [ControlPoint](links-guided.h) | Individual waypoint on a guided link with manual/auto placement flags | `links-guided.h` | - | -| [LinkSettings](links-guided.h) | Persistence structure for guided link configuration (mode, control points, snap settings) | `links-guided.h` | - | - -## Key Methods - -### App Core Operations -- `SaveGraph()` / `LoadGraph()`: Graph persistence -- `ExecuteRuntimeStep()`: Process activated blocks -- `RenderNodes()` / `RenderLinks()`: Visual rendering -- `FindNode()` / `FindLink()` / `FindPin()`: ID-based lookups - -### Block Execution -- `Block::Run()`: Execute block logic -- `Block::ActivateOutput()` / `ActivateInput()`: Flow control -- `Block::Build()`: Create node structure with pins -- `Block::Render()`: Custom rendering per block - -### Container Management -- `Container::GetNodes()` / `GetLinks()`: Safe ID-to-pointer resolution -- `Container::GetNextId()`: Unique ID generation -- `Container::Run()`: Execute container contents - -### Editor Rendering -- `EditorContext::DrawNodes()` / `DrawLinks()`: Core rendering -- `EditorContext::HandleGuidedLinkInteractions()`: Waypoint editing -- `EditorContext::ExecuteRuntime()`: Runtime integration point - -## Simplification Suggestions - -### Core API Requirements -The `imgui_node_editor.h` API only requires: -- **NodeId, LinkId, PinId**: Type-safe IDs (already used correctly) -- **BeginNode()/EndNode()**: Node creation blocks -- **BeginPin()/EndPin()**: Pin creation blocks -- **Link()**: Create link between two PinIds -- **QueryNewLink/QueryNewNode**: Creation callbacks -- **QueryDeletedNode/QueryDeletedLink**: Deletion callbacks -- **GetNodePosition/SetNodePosition**: Position management - -The editor **does NOT require**: -- ⌠Container/grouping hierarchy -- ⌠Complex inheritance chains -- ⌠Registry/factory patterns -- ⌠Duplicate storage systems - -### ðŸ—‘ï¸ Candidates for Removal/Simplification - -#### 1. **Container System Redundancy** âš ï¸ HIGH IMPACT -**Problem**: `App` stores nodes/links in both `m_Nodes`/`m_Links` AND `RootContainer::m_NodeIds`/`m_LinkIds` -- Core API works with IDs directly - doesn't need containers -- Double storage = sync complexity + pointer invalidation risks -- `GetNodes()/GetLinks()` converts IDs→pointers unnecessarily - -**Suggestion**: -- **Remove `Container`/`RootContainer` entirely** OR -- **Make Container just a grouping/visual feature** (nodes still in App's flat list) -- Use `std::map` for O(1) lookups instead of ID vectors - -**Files affected**: `containers/container.h`, `containers/root_container.h`, `app-logic.cpp` (GetNodes/GetLinks calls) - ---- - -#### 2. **Registry Pattern Overhead** âš ï¸ MEDIUM IMPACT -**Problem**: `BlockRegistry` and `ParameterRegistry` are singleton factories that just map strings to constructors -- Adds indirection for simple "create by type name" operations -- Could be simple function tables or even switch statements - -**Suggestion**: -- Replace with `std::function` map directly in `App` -- OR use simple `switch(typeName)` if block types are finite -- Keep factories only if you need dynamic plugin loading - -**Files affected**: `blocks/block.h` (registry), `app-logic.cpp` (CreateBlock calls) - ---- - -#### 3. **Block vs ParameterizedBlock Inheritance** âš ï¸ MEDIUM IMPACT -**Problem**: Two-level inheritance when most/all blocks need parameters anyway -- Base `Block` is abstract but has minimal functionality -- `ParameterizedBlock` adds params, but could just be the base class - -**Suggestion**: -- Merge `Block` and `ParameterizedBlock` into single `Block` class -- OR make `ParameterizedBlock` the base, drop abstract `Block` if unused -- Check if any blocks actually use base `Block` without parameters - -**Files affected**: `blocks/block.h`, all block implementations - ---- - -#### 4. **LinkSettings vs GuidedLink Duplication** âš ï¸ LOW IMPACT -**Problem**: `LinkSettings` (for persistence) and `GuidedLink` (for runtime) store same data -- Two structures for same concept = sync complexity - -**Suggestion**: -- Merge into single structure with `Serialize()` method -- OR make `GuidedLink` contain `LinkSettings` directly -- Eliminates conversion between formats - -**Files affected**: `links-guided.h`, save/load code - ---- - -#### 5. **Node Instance Union Pattern** âš ï¸ LOW IMPACT -**Problem**: `Node` stores either `BlockInstance*` OR `ParameterInstance*` (mutually exclusive) -- Requires runtime type checking (`IsBlockBased()`, `GetBlockInstance()`, etc.) -- Could use `std::variant` or simpler approach - -**Suggestion**: -- Use `std::variant` for type safety OR -- Separate `BlockNode` and `ParameterNode` completely (no shared base) -- Current pattern works but adds complexity - -**Files affected**: `types.h` (Node struct), rendering/runtime code - ---- - -#### 6. **GetNodes()/GetLinks() ID→Pointer Conversion** âš ï¸ MEDIUM IMPACT -**Problem**: Container stores IDs in vectors, then converts to pointers via `App::FindNode()` -- Adds indirection layer, performance overhead (though minimal) -- Pointer invalidation risks when vectors resize - -**Suggestion**: -- Store pointers directly if Container system is kept -- OR use `std::unordered_map` for O(1) lookup -- Current ID-based storage is safer but adds complexity - -**Files affected**: `containers/container.cpp` (GetNodes/GetLinks implementations) - ---- - -### ✅ What to Keep - -- **Block abstraction**: Good separation of concerns (Build/Render/Run) -- **Activation API**: Useful for flow control in runtime -- **Guided Links**: Core feature, keep but simplify persistence -- **ID-based lookups**: Type safety is valuable, but consider maps vs vectors - -### 📊 Impact Summary - -| Simplification | Impact | Effort | Priority | -|---------------|--------|--------|----------| -| Remove Container system | HIGH | HIGH | â­â­â­ | -| Simplify Registry | MEDIUM | LOW | â­â­ | -| Merge Block inheritance | MEDIUM | MEDIUM | â­â­ | -| Merge LinkSettings | LOW | LOW | â­ | -| Simplify Node instances | LOW | MEDIUM | â­ | - -### 🔠Recommended Investigation - -Before removing anything, verify: -1. Are containers used for anything beyond tracking node/link ownership? (groups? nesting?) -2. Do any blocks actually inherit from `Block` directly without parameters? -3. Can we prove Container system adds value beyond App's flat storage? -4. What percentage of code deals with Container vs direct Node/Link access? - -**Core Insight**: The editor API works with IDs. Your abstractions should minimize conversion between IDs ↔ pointers ↔ containers. - diff --git a/docs/COMPLETE_SOLUTION_SUMMARY.md b/docs/COMPLETE_SOLUTION_SUMMARY.md deleted file mode 100644 index 7323b95..0000000 --- a/docs/COMPLETE_SOLUTION_SUMMARY.md +++ /dev/null @@ -1,327 +0,0 @@ -# Complete Session Persistence Solution - -**Date:** November 5, 2025 -**Status:** ✅ FULLY IMPLEMENTED AND TESTED -**Platform:** Win32 + DirectX 11 - ---- - -## Problem Statement - -The NodeHub application was not restoring window position, size, or monitor selection between sessions. Additionally, the "zoom-to-content" feature was overriding saved canvas view states. - -## Solution Delivered - -### ✅ Complete Persistence Across All Layers - -``` -┌─────────────────────────────────────────────────────┠-│ Layer 1: OS Window (Win32) │ -│ ✅ NOW PERSISTED via Blueprints_window.json │ -│ - Window position (x, y) │ -│ - Window size (width, height) │ -│ - Monitor selection │ -│ - Maximized state │ -└─────────────────────────────────────────────────────┘ - ↓ -┌─────────────────────────────────────────────────────┠-│ Layer 2: ImGui UI (Internal Panels) │ -│ ✅ PERSISTED via Blueprints.ini │ -│ - Internal window positions │ -│ - Internal window sizes │ -│ - Collapsed states │ -└─────────────────────────────────────────────────────┘ - ↓ -┌─────────────────────────────────────────────────────┠-│ Layer 3: Node Editor Canvas │ -│ ✅ PERSISTED via Blueprints.json │ -│ - Canvas zoom level │ -│ - Canvas pan/scroll position │ -│ - Visible rectangle │ -│ - Selection state │ -│ + FIXED: Zoom-to-content no longer overrides │ -└─────────────────────────────────────────────────────┘ -``` - ---- - -## Implementation Details - -### Part 1: Window State Persistence (~268 lines) - -**What:** Save/restore OS window position, size, and monitor - -**Files Modified:** -- `examples/application/include/application.h` -- `examples/application/source/application.cpp` -- `examples/application/source/platform.h` -- `examples/application/source/platform_win32.cpp` -- `examples/application/source/platform_glfw.cpp` - -**Key APIs Used:** -- `GetWindowPlacement()` / `SetWindowPlacement()` -- `MonitorFromWindow()` - Multi-monitor support -- `EnumDisplayMonitors()` - Monitor enumeration -- JSON file I/O - Simple custom parser - -**Storage:** `Blueprints_window.json` - -### Part 2: Zoom-to-Content Fix (~32 lines) - -**What:** Prevent zoom-to-content from overriding saved canvas view - -**Files Modified:** -- `examples/blueprints-example/app-logic.cpp` -- `examples/blueprints-example/app.cpp` -- `examples/blueprints-example/app-render.cpp` - -**Key Mechanism:** -- Set `m_NeedsInitialZoom = false` when saved view exists -- Skip `NavigateToContent()` in `OnStart()` when view exists -- Skip zoom-to-content in first frame when view exists - -**Result:** Saved zoom/pan restored correctly! - ---- - -## User Experience - -### Before Implementation - -**Launch App:** -1. Window appears at OS default position ⌠-2. Window uses default size ⌠-3. Canvas zooms to content (ignoring saved zoom/pan) ⌠-4. User must reposition everything 😞 - -### After Implementation - -**Launch App:** -1. Window appears exactly where you left it ✅ -2. Window opens at your preferred size ✅ -3. Canvas restores your custom zoom and pan ✅ -4. Everything is exactly as you left it! 😊 - ---- - -## Technical Achievements - -### Window State Features ✅ -- [x] Position restoration (screen coordinates) -- [x] Size restoration -- [x] Multi-monitor support with index-based tracking -- [x] Maximized state support (code complete) -- [x] Off-screen validation (50px minimum visible) -- [x] Monitor disconnect handling (fallback to primary) -- [x] JSON parse error handling -- [x] First-launch handling - -### Canvas View Features ✅ -- [x] Zoom level restoration -- [x] Pan position restoration -- [x] Zoom-to-content skipped when view exists -- [x] Conditional navigation logic -- [x] Clear console logging - -### Code Quality ✅ -- [x] Clean platform abstraction -- [x] No external dependencies -- [x] Comprehensive error handling -- [x] Extensive logging for debugging -- [x] Edge case validation -- [x] Zero compilation errors -- [x] No regressions - ---- - -## File Structure - -``` -build/bin/ -├── Blueprints_window.json ↠NEW: OS window state -├── Blueprints.json ↠Canvas view state (zoom, pan) -└── Blueprints.ini ↠ImGui internal windows - -docs/ -├── screen.md ↠Updated: Implementation complete -├── IMPLEMENTATION_SUMMARY.md ↠This file -├── WINDOW_STATE_TEST_REPORT.md ↠Detailed test results -└── ZOOM_TO_CONTENT_FIX.md ↠Zoom-to-content fix explanation -``` - ---- - -## Console Output Example - -### Complete Launch Sequence -``` -============================================== -APPLICATION STARTED: Blueprints -Logging is enabled - output visible in terminal -============================================== -Loaded window state: pos=(2630,252) size=855x382 monitor=1 maximized=0 -Restored window state successfully - -[LoadViewSettings] Found saved view state, skipping initial zoom to content -[OnStart] Saved view state will be restored, skipping initial zoom -[OnFrame] Skipping initial zoom - restoring saved canvas view state - -Window state saved successfully -``` - -Clear, informative logging at every step! 📠- ---- - -## Test Evidence - -### Window Position Test -- **Saved:** x=2630, y=252 (right monitor, upper area) -- **Restored:** ✅ Window appeared at exactly (2630, 252) -- **Monitor:** ✅ Window appeared on monitor 1 - -### Window Size Test -- **Saved:** 855x382 (custom compact size) -- **Restored:** ✅ Window opened at exactly 855x382 - -### Canvas View Test -- **Saved:** zoom=0.44x, custom pan position -- **Restored:** ✅ Canvas showed zoom=0.44x (visible in screenshot) -- **Zoom-to-content:** ✅ Correctly skipped (didn't override) - ---- - -## Code Statistics - -### Lines of Code -- Window persistence core: 268 lines -- Zoom-to-content fix: 32 lines -- **Total new code: 300 lines** - -### Distribution -- Platform layer: 155 lines (52%) -- Application layer: 110 lines (37%) -- Blueprints app: 32 lines (11%) - -### Complexity -- Simple functions, clear logic -- No complex algorithms -- Straightforward Win32 API usage -- Custom JSON parser (80 lines, simple) - ---- - -## Future Enhancements - -### Recommended -- [ ] Complete GLFW monitor/maximized implementation -- [ ] Test maximized state restoration -- [ ] Add command-line `--reset-window-state` flag - -### Nice to Have -- [ ] DPI-aware coordinate scaling -- [ ] Per-graph window positions -- [ ] Remember window state per monitor configuration - -### Not Needed -- ✅ Current implementation is production-ready -- ✅ Handles all common use cases -- ✅ Edge cases properly validated - ---- - -## Success Criteria - All Met ✅ - -| Requirement | Status | Evidence | -|-------------|--------|----------| -| Window position restored | ✅ PASS | Screenshot shows correct position | -| Window size restored | ✅ PASS | Dimensions match saved values | -| Monitor selection works | ✅ PASS | Window on monitor 1 as saved | -| Canvas zoom restored | ✅ PASS | Screenshot shows 0.44x zoom | -| Canvas pan restored | ✅ PASS | Canvas coordinates preserved | -| No build errors | ✅ PASS | Clean compilation | -| No regressions | ✅ PASS | All existing features work | -| Edge cases handled | ✅ PASS | Off-screen, missing monitor, etc. | - ---- - -## Verification Commands - -### Quick Test Cycle -```bash -# 1. Build -sh scripts/build.sh - -# 2. Run -./build/bin/blueprints-example_d.exe - -# 3. Move window, zoom canvas, then close (ESC) - -# 4. Check saved state -cat build/bin/Blueprints_window.json -cat build/bin/Blueprints.json - -# 5. Relaunch - verify everything restored! -./build/bin/blueprints-example_d.exe -``` - -### Expected Result -- Window opens at saved position ✅ -- Window has saved size ✅ -- Canvas shows saved zoom level ✅ -- Canvas shows saved pan position ✅ - ---- - -## Key Technical Insights - -### 1. OS Window vs ImGui Window -- OS window managed by Win32/GLFW (outside ImGui) -- ImGui windows managed internally (can save to .ini) -- **Solution:** Platform-specific code at OS level - -### 2. Timing Coordination -- Zoom-to-content happens after nodes loaded -- View state restoration happens during editor creation -- **Solution:** Conditional zoom based on saved state existence - -### 3. Multi-Monitor Complexity -- Monitors can be added/removed between sessions -- Monitor indices can change -- **Solution:** Validate and fallback to primary monitor - -### 4. Edge Case Philosophy -- Better to show window slightly wrong than completely off-screen -- 50-pixel minimum visibility ensures recoverability -- Graceful degradation when hardware changes - ---- - -## Conclusion - -**Mission Accomplished! 🎉** - -The NodeHub application now provides **complete session persistence**: -- ✅ OS window state (position, size, monitor) -- ✅ Canvas view state (zoom, pan, selection) -- ✅ ImGui UI state (panel positions) - -All three layers work together seamlessly. Users can close the app mid-work and return to find everything **exactly as they left it**. - -**Total Implementation:** -- 300 lines of production code -- 8 files modified -- 0 compilation errors -- All tests passing -- Full documentation provided - ---- - -**Implementation by:** AI Assistant -**Date:** November 5, 2025 -**Quality:** Production Ready ✅ - - - - - diff --git a/docs/CONSOLE_VARIANT_SETUP.md b/docs/CONSOLE_VARIANT_SETUP.md deleted file mode 100644 index 4c9083a..0000000 --- a/docs/CONSOLE_VARIANT_SETUP.md +++ /dev/null @@ -1,203 +0,0 @@ -# Console Variant Setup Summary - -## What Was Changed - -This document summarizes the changes made to support building both GUI and console variants of Windows applications. - -## Files Modified - -### 1. `examples/CMakeLists.txt` - -**Added:** -- CMake option `BUILD_CONSOLE_VARIANTS` (default: `ON`) -- Logic in `add_example_executable` macro to create console variants on Windows -- Console variants get `-console` suffix (e.g., `blueprints-example-console`) - -**Key Changes:** -```cmake -# New option at the top -option(BUILD_CONSOLE_VARIANTS "Also build console variants of applications on Windows" ON) - -# New code at end of add_example_executable macro -if (WIN32 AND BUILD_CONSOLE_VARIANTS) - set(_ConsoleTargetName ${name}-console) - add_executable(${_ConsoleTargetName} ...) - target_compile_definitions(${_ConsoleTargetName} PRIVATE _CONSOLE) - # ... same properties and resource copying as GUI variant -endif() -``` - -### 2. `scripts/build.sh` - -**Updated:** -- Added support for optional `console` argument -- Usage: `./scripts/build.sh [Debug|Release] [console]` - -**Examples:** -```bash -# Build GUI variant (default) -./scripts/build.sh Debug - -# Build console variant -./scripts/build.sh Debug console - -# Build Release console variant -./scripts/build.sh Release console -``` - -### 3. New Files - -**`docs/console-variants.md`** -- Complete documentation on console variants -- Usage examples -- Comparison table -- When to use which variant - -**`run-console.sh`** -- Quick script to build and run console variant -- Equivalent to `run.sh` but for console variant - -## How It Works - -### CMake Configuration - -1. When `BUILD_CONSOLE_VARIANTS=ON` (default) on Windows: - - For each example, TWO executables are created - - GUI variant: Uses `WIN32` flag, calls `WinMain()` - - Console variant: No `WIN32` flag, defines `_CONSOLE`, calls `main()` - -2. Both variants: - - Share the same source files - - Link to the same libraries - - Output to the same directory (`build/bin`) - - Have the same debug postfix (`_d`) - -### Entry Point Selection - -In `examples/application/source/entry_point.cpp`: - -```cpp -#if defined(_WIN32) && !defined(_CONSOLE) -// GUI variant: uses WinMain() -int WINAPI WinMain(...) -{ - // Handles console attachment/allocation - // Uses WindowsCommandLineParser with MessageBox on error -} -#else -// Console variant: uses main() -int main(int argc, char** argv) -{ - // Standard console entry point - // Uses CommandLineParser -} -#endif -``` - -## Quick Start - -### Build Both Variants - -```bash -# Configure (creates both GUI and console targets) -cmake -S examples -B build -G "Visual Studio 16 2019" -A x64 - -# Build GUI variant -cmake --build build --config Debug --target blueprints-example - -# Build console variant -cmake --build build --config Debug --target blueprints-example-console - -# Or use the build script -./scripts/build.sh Debug # GUI variant -./scripts/build.sh Debug console # Console variant -``` - -### Visual Studio Startup Project - -By default, **the console variant is set as the startup project** in Visual Studio. This means when you open `build\imgui-node-editor.sln` and press F5, it will debug the console variant. - -To change this behavior: - -```bash -# Use GUI variant as default startup project -cmake -S examples -B build -DUSE_CONSOLE_AS_STARTUP=OFF - -# Use console variant as default startup project (default) -cmake -S examples -B build -DUSE_CONSOLE_AS_STARTUP=ON -``` - -You can also manually change the startup project in Visual Studio: Right-click the project → "Set as StartUp Project". - -### Run - -```bash -# GUI variant (existing workflow) -./run.sh -# or -./build/bin/blueprints-example_d.exe - -# Console variant (new) -./run-console.sh -# or -./build/bin/blueprints-example-console_d.exe -``` - -### Visual Studio - -After running CMake, the Visual Studio solution will contain both projects: -- `blueprints-example` (GUI) -- `blueprints-example-console` (Console) - -Set either as the startup project and press F5 to debug. - -## Disable Console Variants - -If you don't want to build console variants: - -```bash -cmake -S examples -B build -G "Visual Studio 16 2019" -A x64 -DBUILD_CONSOLE_VARIANTS=OFF -``` - -This will only create the GUI variants (original behavior). - -## Benefits - -### For Development -- **Immediate console output**: See logs without attaching debugger or checking files -- **Easier debugging**: Standard console I/O redirection works -- **Script integration**: Better for automation and testing - -### For Production -- **GUI variant unchanged**: End users get clean GUI experience -- **No breaking changes**: Existing build scripts work as before -- **Optional**: Can be disabled with CMake flag - -## Implementation Notes - -1. **No code changes required**: The existing `entry_point.cpp` already has both `main()` and `WinMain()` implementations -2. **Preprocessor-based**: Selection between entry points is done via `_CONSOLE` define -3. **Minimal overhead**: Console variants use simpler entry point without WinMain complexity -4. **Automatic**: All examples get console variants automatically when macro is used - -## Testing - -To verify the console variant works: - -```bash -# Build and run console variant -./scripts/build.sh Debug console -./build/bin/blueprints-example-console_d.exe --help - -# You should see help text immediately in the console -# Compare with GUI variant which may open a message box or create new console -``` - -## Future Enhancements - -Possible improvements: -1. Add CMake target to build both variants at once -2. Create combined `run.sh` that detects which variant to use -3. Add CI/CD integration examples -4. Per-target control of console variant generation - diff --git a/docs/IMPLEMENTATION_SUMMARY.md b/docs/IMPLEMENTATION_SUMMARY.md deleted file mode 100644 index 889b686..0000000 --- a/docs/IMPLEMENTATION_SUMMARY.md +++ /dev/null @@ -1,217 +0,0 @@ -# Window State Persistence - Implementation Summary - -## 🎉 Feature Complete! - -**Date:** November 5, 2025 -**Platform:** Win32 + DirectX 11 -**Status:** Production Ready -**Bonus Fix:** Zoom-to-content no longer overrides saved canvas view - ---- - -## What Was Built - -### The Problem -The application did not remember its window position, size, or monitor between sessions. Users had to reposition the window every time they launched the app. - -### The Solution -Implemented full OS window state persistence using: -- Win32 API (`GetWindowPlacement`, `SetWindowPlacement`) -- Monitor enumeration and validation -- JSON file storage (`Blueprints_window.json`) -- Edge case handling (off-screen, missing monitors) - ---- - -## Implementation Statistics - -| Metric | Value | -|--------|-------| -| **Total Lines Added** | 300 (+32 for zoom fix) | -| **Files Modified** | 8 (+3 for zoom fix) | -| **Build Time** | < 30 seconds | -| **Compilation Errors** | 0 | -| **Test Cases Passed** | 5/5 | -| **Implementation Time** | ~60 minutes | - ---- - -## Files Changed - -``` -examples/application/include/application.h (+17 lines) -examples/application/source/application.cpp (+93 lines) -examples/application/source/platform.h (+3 lines) -examples/application/source/platform_win32.cpp (+127 lines) -examples/application/source/platform_glfw.cpp (+28 lines, stubs) -examples/blueprints-example/app-logic.cpp (+7 lines, zoom fix) -examples/blueprints-example/app.cpp (+11 lines, zoom fix) -examples/blueprints-example/app-render.cpp (+14 lines, zoom fix) -``` - ---- - -## New Features - -### User-Facing -1. **Window Position Persistence** - Window reopens where you left it -2. **Window Size Persistence** - Window size is remembered -3. **Multi-Monitor Support** - Window returns to correct monitor -4. **Canvas View Persistence** - Canvas zoom and pan are preserved (zoom-to-content fix) -5. **Graceful Fallback** - Handles disconnected monitors gracefully - -### Developer-Facing -1. **Clean API** - `SaveWindowState()` / `LoadWindowState()` -2. **Platform Abstraction** - Virtual `GetWindowState()` / `SetWindowState()` -3. **JSON Format** - Human-readable, easy to debug -4. **Console Logging** - Clear feedback for debugging - ---- - -## How It Works - -### On Startup -``` -1. Application::Create() called -2. LoadWindowState() reads Blueprints_window.json -3. Opens window with saved width/height -4. Calls SetWindowState() to restore position/monitor -5. Validates position is on-screen -``` - -### On Shutdown -``` -1. User closes window (ESC or close button) -2. Application::~Application() destructor called -3. GetWindowState() queries current window state from OS -4. SaveWindowState() writes to Blueprints_window.json -5. Platform cleanup proceeds normally -``` - ---- - -## JSON Format - -```json -{ - "window": { - "x": 800, - "y": 50, - "width": 1000, - "height": 900, - "monitor": 0, - "maximized": false - } -} -``` - -**Fields:** -- `x, y` - Window position in screen coordinates -- `width, height` - Window dimensions in pixels -- `monitor` - Zero-based monitor index -- `maximized` - Whether window was maximized - ---- - -## Test Results - -| Test | Status | Notes | -|------|--------|-------| -| First launch (no JSON) | ✅ PASS | Uses defaults correctly | -| Save on close | ✅ PASS | JSON created with correct values | -| Restore position | ✅ PASS | Window opens at saved position | -| Restore size | ✅ PASS | Window opens at saved size | -| Off-screen validation | ✅ CODE COMPLETE | 50px minimum visible enforced | -| Monitor validation | ✅ CODE COMPLETE | Falls back to primary if missing | -| JSON parse error | ✅ CODE COMPLETE | Try/catch with fallback | - ---- - -## Example Console Output - -### First Launch -``` -No saved window state found, using defaults -APPLICATION STARTED: Blueprints -``` - -### Subsequent Launches -``` -Loaded window state: pos=(800,50) size=1000x900 monitor=0 maximized=0 -Restored window state successfully -APPLICATION STARTED: Blueprints -``` - -### On Close -``` -Window state saved successfully -``` - ---- - -## Code Quality - -### Strengths -✅ Clean separation of concerns (Platform abstraction) -✅ No external dependencies (simple JSON parser) -✅ Comprehensive error handling -✅ Console logging for debugging -✅ Edge case validation -✅ Cross-platform API design (ready for GLFW) - -### Technical Decisions -- **Separate JSON file** instead of extending Blueprints.json -- **Simple custom JSON parser** instead of adding library dependency -- **Monitor index** instead of monitor name (more reliable) -- **50-pixel visibility requirement** to prevent off-screen windows -- **Console printf** for debugging (consistent with existing code style) - ---- - -## Future Enhancements - -### High Priority -- [ ] Complete GLFW implementation for cross-platform support -- [ ] Test maximized state restoration - -### Medium Priority -- [ ] DPI-aware coordinate scaling -- [ ] Command-line flag to reset window state -- [ ] User preference to disable persistence - -### Low Priority -- [ ] Remember window state per-graph file -- [ ] Support for multi-window applications - ---- - -## Verification Commands - -### Build -```bash -sh scripts/build.sh -``` - -### Run -```bash -./build/bin/blueprints-example_d.exe -``` - -### Check Window State -```powershell -Get-Content build/bin/Blueprints_window.json -``` - ---- - -## Documentation - -- `docs/screen.md` - Investigation and implementation details (updated with completion status) -- `docs/WINDOW_STATE_TEST_REPORT.md` - Comprehensive test report -- `docs/ZOOM_TO_CONTENT_FIX.md` - Fix for zoom-to-content overriding saved view -- `docs/IMPLEMENTATION_SUMMARY.md` - This file - ---- - -**Status: COMPLETE AND VERIFIED ✅** - diff --git a/docs/WINDOW_STATE_TEST_REPORT.md b/docs/WINDOW_STATE_TEST_REPORT.md deleted file mode 100644 index 73d548d..0000000 --- a/docs/WINDOW_STATE_TEST_REPORT.md +++ /dev/null @@ -1,241 +0,0 @@ -# Window State Persistence - Test Report - -**Date:** November 5, 2025 -**Status:** ✅ IMPLEMENTATION SUCCESSFUL -**Platform:** Win32 + DirectX 11 -**Build:** Debug - ---- - -## Implementation Summary - -Successfully implemented OS window state persistence for the NodeHub application. The feature saves and restores: - -- ✅ Window Position (x, y screen coordinates) -- ✅ Window Size (width, height) -- ✅ Monitor Selection (multi-monitor support) -- ✅ Maximized State -- ✅ Edge Case Validation (off-screen detection, monitor validation) - ---- - -## Build Results - -### All Phases Completed - -✅ **Phase 1:** WindowState struct and Platform interface methods -✅ **Phase 2:** Window state storage in Application class -✅ **Phase 3:** Lifecycle hooks (load on startup, save on shutdown) -✅ **Phase 4:** Win32-specific Get/SetWindowState implementation -✅ **Phase 5:** JSON persistence (`Blueprints_window.json`) -✅ **Phase 6:** Edge case validation (monitor bounds checking) -✅ **Phase 7:** Build and testing - -### Build Output -``` -✓ Build successful! -Executable location: build/bin/blueprints-example_d.exe -``` - -No compilation errors. Only pre-existing warnings in other files. - ---- - -## Test Results - -### Test 1: First Launch (No Saved State) ✅ - -**Action:** Launch application without existing `Blueprints_window.json` - -**Expected:** Application uses default size (1440x800) at OS default position - -**Result:** ✅ PASS -- Console output: "No saved window state found, using defaults" -- Window opened with default dimensions - -### Test 2: Save Window State ✅ - -**Action:** Close application with ESC key - -**Expected:** `Blueprints_window.json` created with current window state - -**Result:** ✅ PASS - -**File Created:** -```json -{ - "window": { - "x": 78, - "y": 78, - "width": 1440, - "height": 753, - "monitor": 0, - "maximized": false - } -} -``` - -### Test 3: Restore Saved Position ✅ - -**Action:** -1. Modify JSON to set position (800, 50) and size (1000, 900) -2. Relaunch application - -**Expected:** Window opens at position (800, 50) with size 1000x900 - -**Result:** ✅ PASS -- Console output: "Loaded window state: pos=(800,50) size=1000x900 monitor=0 maximized=0" -- Console output: "Restored window state successfully" -- Window visually appeared at correct position (right side of screen) - -**Screenshot Evidence:** Window positioned at x≈800 (right side of screen) - -### Test 4: Save Modified Position ✅ - -**Action:** Close application after it restored to (800, 50) - -**Expected:** JSON file updates with current window position - -**Result:** ✅ PASS - -**Final JSON Content:** -```json -{ - "window": { - "x": 800, - "y": 50, - "width": 1000, - "height": 900, - "monitor": 0, - "maximized": false - } -} -``` - -Position and size correctly saved! - ---- - -## Files Modified - -| File | Lines Added | Description | -|------|------------|-------------| -| `examples/application/include/application.h` | +17 | WindowState struct, Save/Load methods | -| `examples/application/source/application.cpp` | +93 | JSON persistence, lifecycle hooks | -| `examples/application/source/platform.h` | +3 | Virtual methods for Get/SetWindowState | -| `examples/application/source/platform_win32.cpp` | +127 | Win32 GetWindowPlacement/SetWindowPlacement | -| `examples/application/source/platform_glfw.cpp` | +28 | GLFW stubs (partial implementation) | - -**Total:** ~268 lines of new code (close to estimated 200) - ---- - -## Features Implemented - -### Core Functionality -- [x] Save window position to JSON on shutdown -- [x] Load window position from JSON on startup -- [x] Save window size -- [x] Restore window size -- [x] Monitor index persistence -- [x] Maximized state support (code ready, not tested) - -### Edge Case Handling -- [x] Invalid position detection (off-screen) -- [x] Monitor validation (falls back to primary if monitor doesn't exist) -- [x] Minimum visible area enforcement (50 pixels must be visible) -- [x] JSON parse error handling (graceful fallback to defaults) -- [x] Missing file handling (first launch) - -### Implementation Details -- [x] Uses Win32 `GetWindowPlacement()` / `SetWindowPlacement()` -- [x] Enumerates monitors with `EnumDisplayMonitors()` -- [x] Validates monitor with `MonitorFromWindow()` -- [x] Bounds checking with `MONITORINFO` work area -- [x] Simple JSON parser (no external dependencies) -- [x] Filename: `Blueprints_window.json` (matches app name pattern) - ---- - -## Console Output Examples - -### First Launch (No Saved State) -``` -No saved window state found, using defaults -APPLICATION STARTED: Blueprints -``` - -### Launch with Saved State -``` -Loaded window state: pos=(800,50) size=1000x900 monitor=0 maximized=0 -Restored window state successfully -APPLICATION STARTED: Blueprints -``` - -### On Shutdown -``` -Window state saved successfully -``` - ---- - -## Known Limitations - -1. **GLFW Backend:** Only partial stub implementation (basic position/size, no monitor/maximized) -2. **DPI Scaling:** Not yet implemented (would save DPI-independent coordinates) -3. **Maximized State:** Implementation complete but not tested in this session - ---- - -## Platform-Specific Notes - -### Win32 Implementation -- Uses `WINDOWPLACEMENT` structure for full state -- Stores **normal position** (even when maximized) -- Validates against monitor work area (excludes taskbar) -- Supports multi-monitor setups via monitor enumeration - -### GLFW Implementation -- Basic stubs only (position and size) -- TODO: Monitor detection via `glfwGetWindowMonitor()` -- TODO: Maximized state detection - ---- - -## Recommendations - -### Immediate -- ✅ Feature is production-ready for Win32+DirectX builds -- ✅ Window state persistence working as designed -- ✅ Edge cases handled appropriately - -### Future Enhancements -- [ ] Complete GLFW implementation for cross-platform support -- [ ] Add DPI-aware coordinate saving/restoration -- [ ] Test maximized state restoration -- [ ] Add user preference to disable window state persistence -- [ ] Consider adding window state reset command-line flag - ---- - -## Conclusion - -**Implementation Status:** ✅ COMPLETE AND VERIFIED - -The window state persistence feature is **fully functional** on Win32+DirectX 11. All test cases passed successfully: - -- Window position saves correctly on shutdown -- Window position restores correctly on startup -- Window size is preserved -- Monitor selection preserved (tested with monitor 0) -- Edge cases handled (off-screen validation, missing files, parse errors) -- No regressions in existing functionality - -The feature adds approximately 268 lines of clean, well-documented code with proper error handling and validation. - ---- - -**Test Conducted By:** AI Implementation -**Test Date:** November 5, 2025 -**Result:** PASS ✅ - diff --git a/docs/ZOOM_TO_CONTENT_FIX.md b/docs/ZOOM_TO_CONTENT_FIX.md deleted file mode 100644 index 77ea7f2..0000000 --- a/docs/ZOOM_TO_CONTENT_FIX.md +++ /dev/null @@ -1,226 +0,0 @@ -# Zoom-to-Content vs Saved View State - Fix Documentation - -**Date:** November 5, 2025 -**Issue:** Zoom-to-content was overriding saved canvas view state -**Status:** ✅ FIXED - ---- - -## The Problem - -The application has an "initial zoom to content" feature that automatically navigates to show all nodes on first launch. However, this was **overriding the saved canvas view state** (zoom and pan position) when users relaunched the application. - -### Symptoms -- Window position/size restored correctly ✅ -- Canvas zoom/pan **NOT** restored (reverted to zoom-to-content) ⌠-- Users lost their carefully positioned canvas view on every relaunch - ---- - -## Root Cause - -### Zoom-to-Content Calls - -**Location 1:** `app.cpp:195` - Called in `OnStart()` -```cpp -void App::OnStart() -{ - // ...load graph, build nodes... - ed::NavigateToContent(0.0f); // ↠Called EVERY time -} -``` - -**Location 2:** `app-render.cpp:3447-3479` - Called on first frame -```cpp -if (m_NeedsInitialZoom && hasNodes) -{ - ed::NavigateToContent(0.0f); // ↠Called on first frame after load - m_NeedsInitialZoom = false; -} -``` - -### The Conflict - -``` -Timeline: -1. App starts -2. Editor created with config.SettingsFile = "Blueprints.json" -3. LoadViewSettings() loads saved zoom/pan from Blueprints.json -4. Editor internally restores saved view state -5. OnStart() calls NavigateToContent() ↠OVERRIDES saved state! -6. OR first frame calls NavigateToContent() ↠OVERRIDES saved state! -``` - ---- - -## The Solution - -### Conditional Zoom-to-Content - -Only perform zoom-to-content **if no saved view state exists**. - -### Implementation - -**File:** `app-logic.cpp:877-909` - Detect saved view state -```cpp -size_t App::LoadViewSettings(char* data) -{ - if (!data) - { - std::ifstream file("Blueprints.json"); - if (!file) - return 0; - - file.seekg(0, std::ios::end); - size_t size = static_cast(file.tellg()); - - // If we have saved view settings, skip initial zoom to content - if (size > 0) - { - m_NeedsInitialZoom = false; // ↠KEY FIX! - printf("[LoadViewSettings] Found saved view state, skipping initial zoom\n"); - } - - return size; - } - // ... -} -``` - -**File:** `app.cpp:195-207` - Conditional navigation in OnStart() -```cpp -void App::OnStart() -{ - // ... - - // Only navigate to content if we don't have saved view settings - if (m_NeedsInitialZoom) - { - printf("[OnStart] No saved view state, navigating to content\n"); - ed::NavigateToContent(0.0f); - } - else - { - printf("[OnStart] Saved view state will be restored, skipping initial zoom\n"); - } -} -``` - -**File:** `app-render.cpp:3447-3492` - Enhanced logging -```cpp -// Initial zoom to content (after first frame when nodes are rendered) -// Skip if we have saved view settings -if (m_NeedsInitialZoom && hasNodes) -{ - printf("[OnFrame] Performing initial zoom to content (no saved view state)\n"); - ed::NavigateToContent(0.0f); - // ... expand bounds logic ... - m_NeedsInitialZoom = false; -} -else if (!m_NeedsInitialZoom && hasNodes) -{ - printf("[OnFrame] Skipping initial zoom - restoring saved canvas view state\n"); -} -``` - ---- - -## How It Works Now - -### First Launch (No Blueprints.json) -``` -1. LoadViewSettings() called -2. Blueprints.json not found → returns 0 -3. m_NeedsInitialZoom remains true -4. OnStart() calls NavigateToContent() -5. First frame also zooms to content -6. Result: Canvas shows all nodes nicely ✅ -``` - -### Subsequent Launches (Blueprints.json exists) -``` -1. LoadViewSettings() called -2. Blueprints.json found → size > 0 -3. m_NeedsInitialZoom set to false ↠SKIP ZOOM! -4. Editor restores saved zoom/pan from JSON -5. OnStart() skips NavigateToContent() -6. First frame skips zoom-to-content -7. Result: Canvas shows EXACTLY where user left it ✅ -``` - ---- - -## Verification - -### Console Output - First Launch -``` -No saved window state found, using defaults -[OnStart] No saved view state, navigating to content -[OnFrame] Performing initial zoom to content (no saved view state) -``` - -### Console Output - Subsequent Launches -``` -Loaded window state: pos=(2630,252) size=855x382 monitor=1 maximized=0 -Restored window state successfully -[LoadViewSettings] Found saved view state, skipping initial zoom to content -[OnStart] Saved view state will be restored, skipping initial zoom -[OnFrame] Skipping initial zoom - restoring saved canvas view state -``` - -###Screenshot Evidence - -**Before Fix:** -- Window position: Restored ✅ -- Canvas zoom: Reset to zoom-to-content ⌠(always 1.00x) - -**After Fix:** -- Window position: Restored ✅ -- Canvas zoom: Restored ✅ (shows 0.44x in screenshot) -- Canvas pan: Restored ✅ (shows correct Canvas coordinates) - ---- - -## Files Modified - -| File | Changes | Purpose | -|------|---------|---------| -| `app-logic.cpp` | +7 lines | Detect saved view state, set m_NeedsInitialZoom = false | -| `app.cpp` | +11 lines | Conditional NavigateToContent() in OnStart() | -| `app-render.cpp` | +14 lines | Enhanced logging, skip message | - -**Total:** 32 additional lines - ---- - -## Key Insight - -The `m_NeedsInitialZoom` flag is the coordination mechanism between: -- **Saved view state** (managed by node editor via Blueprints.json) -- **Initial zoom behavior** (managed by app logic) - -By setting `m_NeedsInitialZoom = false` when we detect saved view state, we prevent the zoom-to-content from interfering with view restoration. - ---- - -## Testing Matrix - -| Scenario | Window State | Canvas View | Result | -|----------|--------------|-------------|--------| -| First launch (no JSON files) | Default | Zoom to content | ✅ PASS | -| Saved window + saved view | Restored position | Restored zoom/pan | ✅ PASS | -| Saved window only | Restored position | Zoom to content | ✅ PASS | -| No window state + saved view | Default position | Restored zoom/pan | ✅ PASS | - -All scenarios handled correctly! - ---- - -**Status: COMPLETE ✅** - -The fix ensures that saved canvas view state is **never overridden** by zoom-to-content when the user has an established view preference. - - - - - diff --git a/docs/cli-implementation-example.md b/docs/cli-implementation-example.md deleted file mode 100644 index 8ac04ab..0000000 --- a/docs/cli-implementation-example.md +++ /dev/null @@ -1,395 +0,0 @@ -# CLI Implementation Example (Headless Mode) - -This document shows a concrete implementation of **Option 1: Headless Flag** from [cli.md](cli.md). - -## Step 1: Update CLI Argument Parser - -Add headless mode and CLI command options to `entry_point.cpp`: - -```cpp -// entry_point.cpp - in CommandLineParser::Parse() -CLI::App app{"NodeHub"}; -app.allow_extras(); - -app.add_option("--file", "the source path")->capture_default_str(); - -// CLI mode options -app.add_flag("--headless", "Run without GUI (CLI mode)"); -app.add_option("--command", "Command to execute in headless mode (validate, export, execute)") - ->capture_default_str() - ->check(CLI::IsMember({"validate", "export", "execute", "info"})); -app.add_option("--output", "Output file path for export commands")->capture_default_str(); -app.add_option("--format", "Output format (json, xml, yaml)")->capture_default_str(); -``` - -## Step 2: Add CLI Helper Functions - -Create `blueprints-cli.h`: - -```cpp -// blueprints-cli.h -#pragma once -#include "application.h" -#include - -// Helper to extract string from ArgsMap -inline std::string GetStringArg(const ArgsMap& args, const std::string& key, const std::string& defaultValue = "") -{ - auto it = args.find(key); - if (it != args.end() && it->second.Type == ArgValue::Type::String) - return it->second.String; - return defaultValue; -} - -// Helper to extract bool from ArgsMap -inline bool GetBoolArg(const ArgsMap& args, const std::string& key, bool defaultValue = false) -{ - auto it = args.find(key); - if (it != args.end() && it->second.Type == ArgValue::Type::Bool) - return it->second.Bool; - return defaultValue; -} - -// CLI command execution -int RunCLI(const ArgsMap& args); -``` - -Create `blueprints-cli.cpp`: - -```cpp -// blueprints-cli.cpp -#include "blueprints-cli.h" -#include "core/graph_state.h" -#include - -static int CommandValidate(const std::string& filename) -{ - printf("Validating: %s\n", filename.c_str()); - - GraphState graph; - if (!graph.Load(filename)) { - fprintf(stderr, "Error: Failed to load graph from %s\n", filename.c_str()); - return 1; - } - - // TODO: Add actual validation logic - // For now, just check if it loaded - printf("✓ Graph loaded successfully\n"); - printf(" Nodes: %zu\n", graph.GetNodes().size()); - printf(" Links: %zu\n", graph.GetLinks().size()); - - // Basic validation - bool valid = true; - - // Check for disconnected pins - for (const auto& link : graph.GetLinks()) { - if (!graph.FindPin(link.StartPinID)) { - fprintf(stderr, "Error: Link references missing start pin\n"); - valid = false; - } - if (!graph.FindPin(link.EndPinID)) { - fprintf(stderr, "Error: Link references missing end pin\n"); - valid = false; - } - } - - if (valid) { - printf("✓ Validation passed\n"); - return 0; - } else { - fprintf(stderr, "✗ Validation failed\n"); - return 1; - } -} - -static int CommandExport(const std::string& filename, const std::string& output, const std::string& format) -{ - printf("Exporting: %s -> %s (%s)\n", filename.c_str(), output.c_str(), format.c_str()); - - GraphState graph; - if (!graph.Load(filename)) { - fprintf(stderr, "Error: Failed to load graph from %s\n", filename.c_str()); - return 1; - } - - // Export based on format - if (format == "json") { - if (graph.Save(output)) { - printf("✓ Exported to JSON: %s\n", output.c_str()); - return 0; - } else { - fprintf(stderr, "Error: Failed to export to %s\n", output.c_str()); - return 1; - } - } else if (format == "xml" || format == "yaml") { - fprintf(stderr, "Error: Format '%s' not yet implemented\n", format.c_str()); - return 1; - } else { - fprintf(stderr, "Error: Unknown format '%s'\n", format.c_str()); - return 1; - } -} - -static int CommandExecute(const std::string& filename) -{ - printf("Executing: %s\n", filename.c_str()); - - GraphState graph; - if (!graph.Load(filename)) { - fprintf(stderr, "Error: Failed to load graph from %s\n", filename.c_str()); - return 1; - } - - // TODO: Implement graph execution - fprintf(stderr, "Error: Graph execution not yet implemented\n"); - return 1; -} - -static int CommandInfo(const std::string& filename) -{ - printf("Graph info: %s\n", filename.c_str()); - - GraphState graph; - if (!graph.Load(filename)) { - fprintf(stderr, "Error: Failed to load graph from %s\n", filename.c_str()); - return 1; - } - - printf("Nodes: %zu\n", graph.GetNodes().size()); - printf("Links: %zu\n", graph.GetLinks().size()); - - // Node type breakdown - std::map nodeTypes; - for (const auto& node : graph.GetNodes()) { - nodeTypes[node.Type]++; - } - - printf("\nNode Types:\n"); - for (const auto& [type, count] : nodeTypes) { - printf(" %s: %d\n", type.c_str(), count); - } - - return 0; -} - -int RunCLI(const ArgsMap& args) -{ - std::string filename = GetStringArg(args, "file", ""); - if (filename.empty()) { - fprintf(stderr, "Error: --file required in headless mode\n"); - fprintf(stderr, "\nUsage:\n"); - fprintf(stderr, " --headless --file --command [options]\n"); - fprintf(stderr, "\nCommands:\n"); - fprintf(stderr, " validate Validate graph structure\n"); - fprintf(stderr, " export Export to different format\n"); - fprintf(stderr, " execute Execute graph (headless)\n"); - fprintf(stderr, " info Display graph information\n"); - return 1; - } - - std::string command = GetStringArg(args, "command", "validate"); - - if (command == "validate") { - return CommandValidate(filename); - } - else if (command == "export") { - std::string output = GetStringArg(args, "output", ""); - if (output.empty()) { - fprintf(stderr, "Error: --output required for export command\n"); - return 1; - } - std::string format = GetStringArg(args, "format", "json"); - return CommandExport(filename, output, format); - } - else if (command == "execute") { - return CommandExecute(filename); - } - else if (command == "info") { - return CommandInfo(filename); - } - else { - fprintf(stderr, "Error: Unknown command '%s'\n", command.c_str()); - return 1; - } -} -``` - -## Step 3: Update blueprints-example.cpp - -Modify the main entry point to support headless mode: - -```cpp -// blueprints-example.cpp -#include "app.h" -#include "blueprints-cli.h" -#include -#include - -int Main(const ArgsMap& args) -{ - // Check for headless mode - bool headless = GetBoolArg(args, "headless", false); - - if (headless) { - printf("[CLI MODE] Running in headless mode\n"); - return RunCLI(args); - } - - // GUI mode (existing code) - printf("[GUI MODE] Starting application\n"); - - App example("Blueprints", args); - - if (example.Create()) - return example.Run(); - - return 0; -} -``` - -## Step 4: Update CMakeLists.txt - -Add the new CLI files to the build: - -```cmake -# examples/blueprints-example/CMakeLists.txt -add_example_executable(blueprints-example - blueprints-example.cpp - blueprints-cli.h - blueprints-cli.cpp # Add this - types.h - nodes.h - nodes.cpp - # ... rest of files -) -``` - -## Usage Examples - -Once implemented, you can use it like this: - -### Validate a graph -```bash -./build/bin/blueprints-example-console_d.exe --headless --file graph.json --command validate -``` - -Output: -``` -[CLI MODE] Running in headless mode -Validating: graph.json -✓ Graph loaded successfully - Nodes: 15 - Links: 12 -✓ Validation passed -``` - -### Get graph info -```bash -./build/bin/blueprints-example-console_d.exe --headless --file graph.json --command info -``` - -Output: -``` -[CLI MODE] Running in headless mode -Graph info: graph.json -Nodes: 15 -Links: 12 - -Node Types: - Math: 5 - Input: 3 - Output: 2 - Group: 5 -``` - -### Export to different format -```bash -./build/bin/blueprints-example-console_d.exe --headless --file graph.json --command export --output converted.json --format json -``` - -### Batch validation -```bash -# PowerShell -Get-ChildItem *.json | ForEach-Object { - Write-Host "Processing $_" - ./build/bin/blueprints-example-console_d.exe --headless --file $_.Name --command validate -} - -# Bash -for file in *.json; do - echo "Processing $file" - ./build/bin/blueprints-example-console_d.exe --headless --file "$file" --command validate -done -``` - -## Testing - -### Test GUI mode still works -```bash -./build/bin/blueprints-example_d.exe --file graph.json -# Should open normally -``` - -### Test CLI mode -```bash -./build/bin/blueprints-example-console_d.exe --headless --file graph.json --command validate -# Should NOT create any windows -``` - -### Test without file argument -```bash -./build/bin/blueprints-example-console_d.exe --headless -# Should show error and usage -``` - -## Benefits - -✅ **No UI overhead** - Headless mode doesn't create any windows or ImGui context -✅ **Fast** - Perfect for CI/CD pipelines -✅ **Automatable** - Can be scripted and batched -✅ **Same binary** - No need to maintain separate executables initially -✅ **Reuses CLI parsing** - All argument handling already in place - -## Next Steps - -1. **Implement actual validation** - Add real graph validation logic -2. **Add more commands** - Convert, merge, diff, etc. -3. **Add tests** - Unit tests for CLI commands -4. **Consider refactoring** - If CLI usage grows, consider Option 3 or 4 from [cli.md](cli.md) - -## Integration with CI/CD - -Example GitHub Actions workflow: - -```yaml -# .github/workflows/validate-graphs.yml -name: Validate Graphs - -on: [push, pull_request] - -jobs: - validate: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - - name: Build - run: | - cmake -S examples -B build - cmake --build build --config Release --target blueprints-example-console - - - name: Validate all graphs - run: | - Get-ChildItem -Path test-graphs -Filter *.json | ForEach-Object { - Write-Host "Validating $_" - ./build/bin/blueprints-example-console.exe --headless --file $_.FullName --command validate - if ($LASTEXITCODE -ne 0) { exit 1 } - } -``` - -## See Also - -- [CLI Architecture Options](cli.md) - Full architectural discussion -- [Console Variants Guide](console-variants.md) - Console vs GUI variants -- [Debugging Guide](../DEBUGGING.md) - How to debug both modes - diff --git a/docs/cmake-protobuf.md b/docs/cmake-protobuf.md new file mode 100644 index 0000000..2a6e8a7 --- /dev/null +++ b/docs/cmake-protobuf.md @@ -0,0 +1,69 @@ +# Protocol Buffers (Protobuf) Integration + +This project supports optional Protocol Buffers integration via [vcpkg](https://vcpkg.io/). + +## Installation + +Install protobuf via vcpkg: + +```bash +vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows +``` + +## CMake Configuration + +### Option 1: Using vcpkg Toolchain (Recommended) + +When configuring CMake, specify the vcpkg toolchain file: + +```bash +cmake -S applications -B build --toolchain [path to vcpkg]/scripts/buildsystems/vcpkg.cmake +``` + +Or set it as an environment variable: + +```powershell +$env:CMAKE_TOOLCHAIN_FILE = "[path to vcpkg]/scripts/buildsystems/vcpkg.cmake" +cmake -S applications -B build +``` + +### Option 2: Disable Protobuf (if not needed) + +```bash +cmake -S applications -B build -DENABLE_PROTOBUF=OFF +``` + +## CMake Options + +- `ENABLE_PROTOBUF` (default: `ON`) - Enable or disable Protocol Buffers support + +## Usage in Code + +When protobuf is enabled, the `ENABLE_PROTOBUF` preprocessor macro is defined: + +```cpp +#ifdef ENABLE_PROTOBUF + #include + // Use protobuf APIs +#else + // Fallback code when protobuf is disabled +#endif +``` + +## Targets + +All executables automatically link to protobuf when available: +- `nodehub` +- `nodehub-console` +- `core_tests` + +Protobuf is linked via the `protobuf_interface` interface library, which provides: +- `protobuf::libprotobuf` - Main protobuf library +- `protobuf::libprotoc` - Protocol compiler library +- `ENABLE_PROTOBUF=1` compile definition + +## References + +- [Protobuf CMake README](https://github.com/protocolbuffers/protobuf/blob/main/cmake/README.md) +- [vcpkg Documentation](https://vcpkg.io/) + diff --git a/docs/groups-new.md b/docs/groups-new.md deleted file mode 100644 index 49aeca2..0000000 --- a/docs/groups-new.md +++ /dev/null @@ -1,237 +0,0 @@ -# Group Block Implementation Plan - Spatial Grouping - -## Overview - -This document outlines the implementation plan for adding **spatial grouping functionality** to Group blocks in Expanded mode. This allows Group blocks to act as containers that automatically adopt nodes when they are dragged into their bounds, similar to the "Test Comment" nodes in the old demo. - -**Core Principle:** Groups work through **spatial containment** - any node whose bounds fall within a group's `m_GroupBounds` becomes a child. The group can be dragged by its header to move all children together, and can be resized to adjust its containment area. - -## Reference Implementation - -Based on `ref/old_demo.cpp` and `ref/old_editor.cpp`, the old comment/group nodes worked as follows: - -1. **`ed::Group(size)`**: Called during `ed::BeginNode()` / `ed::EndNode()` to mark the node as a group and set its group bounds -2. **Spatial Containment**: Nodes within `m_GroupBounds` are automatically considered children -3. **`GetGroupedNodes()`**: Recursively finds all nodes within bounds using `FindNodesInRect()` -4. **Header Dragging**: Dragging the group header moves the group and all children -5. **Resizing**: Groups can be resized by dragging edges/corners, updating `m_GroupBounds` -6. **Group Hints**: `BeginGroupHint()` / `EndGroupHint()` allow rendering title bar outside bounds - -## Architecture Notes - -- The imgui_node_editor uses **internal `NodeType::Group`** in `ed::Node` (separate from our application `NodeType::Group`) -- Our Group blocks use **application-level `NodeType::Group`** but need to integrate with editor's group system -- The editor's group system is based on **spatial containment** - no explicit parent/child references -- Groups are sorted separately from regular nodes for rendering order - -## Implementation Tasks - -### Phase 1: Basic Group Infrastructure - -#### Task 1.1: Integrate Group Block with Editor's Group System -**Files:** `examples/blueprints-example/blocks/group_block.cpp` - -- [ ] Update `RenderExpanded()` to call `ed::Group(size)` during node rendering - - Call `ed::Group(groupSize)` within `ed::BeginNode()` / `ed::EndNode()` - - Store group size in GroupBlock (initial size from node bounds or default) - - This marks the node as a group in the editor's internal system -- [ ] Add group size tracking to GroupBlock - - Add `ImVec2 m_GroupSize` member variable - - Initialize with default size (e.g., 400x300) or based on node bounds - - Save/load group size in `SaveState()` / `LoadState()` -- [ ] Verify node is recognized as group by editor - - Editor should automatically recognize it via `ed::Group()` call - - Check that `IsGroup()` returns true for our nodes - -**Dependencies:** None - ---- - -#### Task 1.2: Implement Group Hints (Title Bar Rendering) -**Files:** `examples/blueprints-example/blocks/group_block.cpp` - -- [ ] Render group title bar using `ed::BeginGroupHint()` / `ed::EndGroupHint()` - - Display group name in the hint - - Position title bar at top of group bounds (using `ed::GetGroupMin()`) - - Style similar to old comment nodes (semi-transparent background) -- [ ] Make title bar draggable - - Editor automatically handles dragging when `GetRegion()` returns `NodeRegion::Header` - - Verify dragging group header moves the group - -**Dependencies:** Task 1.1 - ---- - -### Phase 2: Spatial Containment & Child Management - -#### Task 2.1: Automatic Child Detection -**Files:** `examples/blueprints-example/blocks/group_block.cpp`, `examples/blueprints-example/app-render.cpp` - -- [ ] Verify automatic child detection works - - Editor's `GetGroupedNodes()` automatically finds nodes within `m_GroupBounds` - - Uses `FindNodesInRect(m_GroupBounds)` internally - - Test: Drag a block into group bounds → should become child -- [ ] Optional: Store child node IDs for quick access - - Not strictly necessary (editor handles this via `GetGroupedNodes()`) - - Could cache for performance if needed later - -**Dependencies:** Task 1.1 - ---- - -#### Task 2.2: Dragging Group Header Moves Children -**Files:** `examples/blueprints-example/app-render.cpp` (if needed) - -- [ ] Verify editor automatically handles child movement - - Editor's `DragAction` calls `GetGroupedNodes()` when dragging group - - Children are included in drag operation automatically - - Test: Drag group header → all children should move -- [ ] Handle edge cases - - Prevent dragging children out of group when dragging group - - Or allow it (editor might handle automatically) - -**Dependencies:** Task 1.1, 2.1 - ---- - -### Phase 3: Group Resizing - -#### Task 3.1: Enable Group Resizing -**Files:** `examples/blueprints-example/blocks/group_block.cpp`, `examples/blueprints-example/app-render.cpp` - -- [ ] Verify editor handles resizing automatically - - Editor's `SizeAction` handles group resizing when `IsGroup()` is true - - User can drag edges/corners to resize - - Updates both `m_Bounds` and `m_GroupBounds` -- [ ] Update group size tracking - - When group is resized, update `m_GroupSize` in GroupBlock - - Save updated size in `SaveState()` -- [ ] Call `ed::SetGroupSize()` if needed for initial size - - May need to call this after creating group to set initial bounds - -**Dependencies:** Task 1.1 - ---- - -#### Task 3.2: Auto-Resize Based on Children -**Files:** `examples/blueprints-example/blocks/group_block.cpp` - -- [ ] Optional: Auto-expand group when nodes are added - - Calculate bounding box of all child nodes - - Expand `m_GroupBounds` to encompass all children (with padding) - - Update `m_GroupSize` accordingly -- [ ] Optional: Auto-shrink when nodes removed - - Recalculate bounds when child count decreases - - Shrink group to fit remaining children - -**Dependencies:** Task 3.1, 2.1 - ---- - -### Phase 4: Visual Polish - -#### Task 4.1: Group Visual Styling -**Files:** `examples/blueprints-example/blocks/group_block.cpp` - -- [ ] Style group background (in Expanded mode) - - Semi-transparent background (similar to old comment nodes) - - Border styling - - Visual distinction from regular blocks -- [ ] Style group title bar (hint) - - Background color - - Text styling - - Padding and spacing - -**Dependencies:** Task 1.1, 1.2 - ---- - -#### Task 4.2: Visual Feedback for Child Nodes -**Files:** `examples/blueprints-example/app-render.cpp` (if needed) - -- [ ] Optional: Visual indication of group membership - - Slight visual change for nodes inside groups - - Border color change or subtle background tint - - Or keep same (spatial containment is self-evident) - -**Dependencies:** Task 2.1 - ---- - -### Phase 5: Edge Cases & Validation - -#### Task 5.1: Prevent Group Nesting Issues -**Files:** `examples/blueprints-example/app-logic.cpp` - -- [ ] Validate group operations - - Prevent groups from being dragged into themselves (recursive nesting) - - Handle groups being moved into other groups (nested groups) - - Editor should handle this, but verify behavior -- [ ] Handle group deletion - - When group is deleted, children should become top-level nodes - - Or delete children too (decide on behavior) - -**Dependencies:** Task 2.1 - ---- - -#### Task 5.2: Save/Load Group Bounds -**Files:** `examples/blueprints-example/blocks/group_block.cpp` - -- [ ] Save group size to JSON - - Already added in Task 1.1, verify it works -- [ ] Load group size from JSON - - Restore size when loading saved graph - - Call `ed::SetGroupSize()` if needed after loading - -**Dependencies:** Task 1.1 - ---- - -### Phase 6: Collapsed Mode (Future) - -#### Task 6.1: Collapsed Mode Rendering -**Files:** `examples/blueprints-example/blocks/group_block.cpp` - -- [ ] Implement `RenderCollapsed()` - - Show compact representation (just title, maybe pin count) - - Hide all child nodes visually - - Children still exist but not rendered -- [ ] Toggle between modes - - User can switch via context menu - - State persists across save/load - -**Dependencies:** Task 1.1, 4.1 - ---- - -## Key API Functions - -From imgui_node_editor: - -- `ed::Group(ImVec2 size)` - Mark node as group and set group bounds -- `ed::SetGroupSize(NodeId, ImVec2)` - Set group size externally -- `ed::BeginGroupHint(NodeId)` / `ed::EndGroupHint()` - Render title bar -- `ed::GetGroupMin()` / `ed::GetGroupMax()` - Get group bounds (in hint context) -- `node->GetGroupedNodes(vector)` - Find all nodes within bounds -- Editor automatically handles dragging groups with children via `GetGroupedNodes()` - -## Testing Checklist - -- [ ] Create Group block → should show as group with title bar -- [ ] Drag block into group → should become child -- [ ] Drag group header → should move group and all children -- [ ] Resize group → should update bounds, children still contained -- [ ] Drag child out of group → should work -- [ ] Save/load → group size should persist -- [ ] Toggle display mode → should switch between expanded/collapsed - -## Notes - -- The editor's group system is **spatial-based**, not reference-based -- No explicit parent/child links needed - containment is automatic -- `ed::Group()` must be called during node rendering, not after -- Group bounds (`m_GroupBounds`) are separate from node bounds (`m_Bounds`) - - `m_Bounds` = the actual node rectangle (for header/title bar) - - `m_GroupBounds` = the area that contains child nodes (usually larger) - diff --git a/docs/llm/blocks.md b/docs/llm/blocks.md new file mode 100644 index 0000000..b1f30cf --- /dev/null +++ b/docs/llm/blocks.md @@ -0,0 +1,93 @@ +# Block Reference + +This document provides a brief overview of the available blocks, their purpose, and their parameters. For a guide on how to create and connect these blocks programmatically, see [Creating Blocks Programmatically](./create-blocks.md). + +## Logic Blocks + +### [`Logic.Test`](./applications/nodehub/blocks/logic_blocks.cpp) + +Compares two input values (`A` and `B`) based on a configurable operator and triggers a `True` or `False` flow output. + +- **Flow Inputs**: + - `Execute` +- **Parameter Inputs**: + - `A` (Bool, Int, Float, or String): The first value for comparison. + - `B` (Bool, Int, Float, or String): The second value for comparison. +- **Flow Outputs**: + - `True`: Executed if the comparison is true. + - `False`: Executed if the comparison is false. +- **Configurable**: + - **Parameter Type**: Can be set to Bool, Int, Float, or String. + - **Operator**: Can be set to Equal, Not Equal, Less, Less or Equal, Greater, or Greater or Equal. + +## Math Blocks + +### [`Math.Add`](./applications/nodehub/blocks/math_blocks.cpp) + +Adds two integer values (`A` and `B`) and outputs the sum. + +- **Flow Inputs**: + - `Execute` +- **Parameter Inputs**: + - `A` (Int): The first integer. + - `B` (Int): The second integer. +- **Flow Outputs**: + - `Done` +- **Parameter Outputs**: + - `Result` (Int): The sum of `A` and `B`. + +### [`Math.Multiply`](./applications/nodehub/blocks/math_blocks.cpp) + +Multiplies two integer values (`A` and `B`) and outputs the product. + +- **Flow Inputs**: + - `Execute` +- **Parameter Inputs**: + - `A` (Int): The first integer. + - `B` (Int): The second integer. +- **Flow Outputs**: + - `Done` +- **Parameter Outputs**: + - `Result` (Int): The product of `A` and `B`. + +### [`Math.Compare`](./applications/nodehub/blocks/math_blocks.cpp) + +Compares two integer values (`A` and `B`) and provides boolean outputs for equality, less than, and greater than. + +- **Flow Inputs**: + - `Execute` +- **Parameter Inputs**: + - `A` (Int): The first integer. + - `B` (Int): The second integer. +- **Flow Outputs**: + - `Done` +- **Parameter Outputs**: + - `==` (Bool): True if `A` is equal to `B`. + - `<` (Bool): True if `A` is less than `B`. + - `>` (Bool): True if `A` is greater than `B`. + +## Utility Blocks + +### [`Log`](./applications/nodehub/blocks/log_block.cpp) + +Writes a timestamped log entry to a JSON file. It has one fixed input for the file path and can be configured with additional variable parameters to be included in the log. + +- **Flow Inputs**: + - `Execute` +- **Parameter Inputs**: + - `FilePath` (String): The path to the output JSON file. + - *(Variable Parameters)*: Additional parameters of type Bool, Int, Float, or String can be added via the context menu. +- **Flow Outputs**: + - `Done` +- **Configurable**: + - Can add/remove variable input parameters. + - Settings for appending to the file vs. overwriting, and for logging to the console. + +### [`Start`](./applications/nodehub/blocks/start_block.cpp) + +Acts as an entry point for the graph execution. It has no inputs and a single flow output. + +- **Flow Inputs**: + - *(None)* +- **Flow Outputs**: + - `Start` diff --git a/docs/llm/cli.md b/docs/llm/cli.md new file mode 100644 index 0000000..2c78c16 --- /dev/null +++ b/docs/llm/cli.md @@ -0,0 +1,46 @@ +# Command-Line Interface (CLI) Guide + +This document provides a guide to using the application's command-line interface for headless execution. + +## Basic Usage + +The application can be run in a headless (no GUI) mode, which is ideal for scripting, testing, and server environments. The executable is located at `build/bin/nodehub_d.exe`. + +The general command structure is: + +```bash +./build/bin/nodehub_d.exe [ARGUMENTS] +``` + +## Key Arguments + +The following are some of the most common arguments used for headless execution: + +- `--headless` + - **Required** for CLI mode. This flag prevents the GUI from launching. + +- `--run` + - Instructs the application to execute the graph's runtime logic. + +- `--graph=` + - Specifies the path to the graph file to load and execute. The path should be relative to the executable's directory (`build/bin/`). + +- `--log-level=` + - Sets the verbosity of the console output. Common levels include `info`, `debug`, and `warn`. + +- `--max-steps=` + - Defines the maximum number of execution steps to run before the application terminates. This is a safeguard to prevent infinite loops in graphs. + +## Example + +The following command, taken from [`run-console.sh`](../../run-console.sh), demonstrates a typical headless execution: + +```bash +./build/bin/nodehub_d.exe --graph=./BlueprintsGraph.json --run --headless --log-level=info --max-steps=1000 +``` + +This command will: +1. Load the `BlueprintsGraph.json` file. +2. Run the graph in headless mode. +3. Output logs at the `info` level. +4. Stop after a maximum of 1000 execution steps. diff --git a/docs/llm/create-blocks.md b/docs/llm/create-blocks.md new file mode 100644 index 0000000..b647225 --- /dev/null +++ b/docs/llm/create-blocks.md @@ -0,0 +1,75 @@ +# Creating Blocks Programmatically + +This guide provides a concise overview of how to add and configure block nodes programmatically in a command-line or testing environment. This is essential for creating automated unit tests. We assume a working `App` instance is available, as set up in headless mode (see `main.cpp`). + +## Process Overview + +Creating and connecting a block involves several steps: + +1. **Get Active Container**: Obtain a pointer to the current `RootContainer` from the `App` instance. +2. **Spawn Nodes**: Create the necessary nodes. For example, to use a `Log` block, you need to spawn the `Log` block itself and also any parameter nodes that will provide its inputs (like the file path). +3. **Configure Parameter Nodes**: Set the values for the parameter nodes you've created. +4. **Connect Nodes**: Find the corresponding input and output pins on the nodes and create a `Link` to connect them. +5. **Set Positions (Optional)**: If you plan to save the graph for visual inspection, set the node positions using `ed::SetNodePosition()`. +6. **Save Graph**: Persist the changes by calling `App::SaveGraph()`, passing the container and a file path. + +## Example: Creating and Connecting a `Log` Block + +The following function demonstrates adding a "Log" block, providing its required "FilePath" input via a "String" parameter node, connecting them, and saving the graph. + +```cpp +#include "app.h" +#include "containers/root_container.h" +#include "blocks/parameter_node.h" // Required for ParameterInstance + +// Assumes 'app' is an initialized App instance +void AddAndConnectLogBlock(App& app, const std::string& logFilePath, const std::string& savePath) +{ + // 1. Get container + RootContainer* container = app.GetActiveRootContainer(); + if (!container) + return; + + // 2. Spawn the log block and a parameter node for the file path + Node* logNode = app.SpawnBlockNode("Log", -1); + Node* pathNode = app.SpawnParameterNode(PinType::String, -1); + if (!logNode || !pathNode) + return; + + // 3. Configure the parameter node's value + pathNode->StringValue = logFilePath; + if (pathNode->ParameterInstance) { + pathNode->ParameterInstance->SetString(logFilePath.c_str()); + } + + // 4. Connect the nodes + // The String parameter node has one output. + Pin* pathOutputPin = &pathNode->Outputs[0]; + + // The Log block's 'FilePath' is its first non-flow input pin. + // Input[0] is 'Execute' (flow), Input[1] is 'FilePath'. + Pin* logInputPin = nullptr; + if (logNode->Inputs.size() > 1) { + logInputPin = &logNode->Inputs[1]; + } + + if (pathOutputPin && logInputPin) + { + Link newLink(app.GetNextLinkId(), pathOutputPin->ID, logInputPin->ID); + container->AddLink(newLink); + } + + // 5. Set positions (optional, requires an editor context) + ed::SetNodePosition(logNode->ID, ImVec2(200.0f, 100.0f)); + ed::SetNodePosition(pathNode->ID, ImVec2(0.0f, 100.0f)); + + // 6. Save the updated graph + app.SaveGraph(savePath, container); +} +``` + +This more detailed example provides a solid foundation for scripting graph creation for unit tests, ensuring that blocks are not only created but also correctly configured and connected. + +## Block Reference + +For a complete list of available blocks and their parameters, see the [Block Reference](./blocks.md). diff --git a/docs/llm/testing.md b/docs/llm/testing.md new file mode 100644 index 0000000..dbe115e --- /dev/null +++ b/docs/llm/testing.md @@ -0,0 +1,54 @@ +# Testing Guide + +This project uses a combination of C++-based unit/functional tests and TypeScript-based end-to-end (E2E) tests to ensure code quality and correctness. + +## 1. Unit & Functional Tests (C++/Google Test) + +The C++ tests are built on the Google Test framework and are designed to test individual classes and functions in isolation. + +- **Location:** All C++ tests are located in the [`applications/tests/`](../../applications/tests/) directory. +- **Test Scaffolding:** A common test fixture is defined in [`applications/tests/commons-test.h`](../../applications/tests/commons-test.h) and [`applications/tests/commons-test.cpp`](../../applications/tests/commons-test.cpp). This scaffolding provides a headless `App` instance, which is useful for testing components that rely on the application context. +- **Example:** See [`applications/tests/block_test.cpp`](../../applications/tests/block_test.cpp) for an example of how to write a test and use the `AppTest` fixture. + +### How to Run + +To run the entire C++ test suite, use the corresponding `npm` script from the project root: + +```bash +npm run test:core +``` + +This command will: +1. Compile the test executable (`core_tests`). +2. Run the tests using CTest. + +### How to Add a New Test + +1. Create a new `_test.cpp` file inside the [`applications/tests/`](../../applications/tests/) directory. +2. Include `"commons-test.h"` and any other necessary headers. +3. Write your tests using the Google Test `TEST_F` macro, inheriting from the `AppTest` fixture if you need an application instance. +4. Add the name of your new file to the `add_executable` command in [`applications/tests/CMakeLists.txt`](../../applications/tests/CMakeLists.txt). + +## 2. End-to-End Tests (TypeScript/Vitest) + +The E2E tests are built with Vitest and are designed to test the compiled command-line application (`nodehub_d.exe`) as a whole. + +- **Location:** All E2E tests are located in the [`tests/`](../../tests/) directory at the project root. +- **Test Runner:** A helper function for executing the binary is located in [`tests/commons.ts`](../../tests/commons.ts). This helper manages the command-line arguments and process execution. +- **Example:** See [`tests/e2e.test.ts`](../../tests/e2e.test.ts) for an example of how to use the `runCli` helper to test the application's behavior. + +### How to Run + +To run the entire E2E test suite, use the corresponding `npm` script from the project root: + +```bash +npm run test:e2e:core +``` + +This command will invoke Vitest, which will discover and run all `*.test.ts` files inside the `tests/` directory. + +### How to Add a New Test + +1. Create a new `_test.ts` file inside the [`tests/`](../../tests/) directory. +2. Import `describe`, `it`, and `expect` from `"vitest"`, and the `runCli` helper from `"./commons"`. +3. Write your tests. Each test should call `runCli` with the desired command-line arguments and then use `expect` to assert the correctness of the `stdout`, `stderr`, or exit `code`. diff --git a/docs/shortcuts.md b/docs/shortcuts.md deleted file mode 100644 index 4544aa7..0000000 --- a/docs/shortcuts.md +++ /dev/null @@ -1,216 +0,0 @@ -# Parameter Node Shortcuts Feature Plan - -## Overview - -Parameter nodes can now act as "sources" and have "shortcut" clones that reference them. This allows creating multiple convenient access points to the same parameter value across the graph without physical links. - -## Core Concepts - -- **Source Node**: A parameter node marked as a source (`m_IsSource = true`) that acts as the master copy -- **Shortcut/Clone**: A parameter node that references a source node (`m_SourceID` set) and syncs its value from the source -- **Value Synchronization**: When a shortcut's value/name/type is edited, it updates the source, and all shortcuts automatically receive updates from the source - -## Feature Requirements - -### 1. Source Node Toggle -- Context menu option "As Source" toggles `m_IsSource` flag -- Only visible for parameter nodes -- When enabled, shows additional menu item "Create Shortcut" - -### 2. Create Shortcut -- Only visible when node is a source (`m_IsSource == true`) -- Creates a new parameter node (clone) with: - - Same type as source - - Same value as source (retrieved via `Run()`) - - Same name as source (with optional suffix for uniqueness) - - `m_SourceID` set to source node's ID - - Positioned next to source node (offset right by ~200px) - -### 3. Visual Differentiation -- Source nodes: Render with different border color/style (e.g., gold/bright border, or "★" indicator) -- Shortcut nodes: Render with different background color/style (e.g., slightly dimmed, or "📋" indicator) -- Visual cues should be subtle but clear - -### 4. Value Synchronization -- **Shortcut → Source**: When shortcut's value/name/type is edited, update source immediately -- **Source → Shortcuts**: When source's value/name/type is edited, all shortcuts sync (via `Run()` mechanism) -- Use existing `Run()` infrastructure for value propagation - -### 5. Source Deletion Handling -- When source node is deleted, shortcuts remain but become independent -- Set `m_SourceID = 0` on all affected shortcuts -- Clear `m_IsSource = false` if somehow a shortcut was marked as source - -### 6. Save/Load -- Save `m_IsSource` flag -- Save `m_SourceID` (0 if not a shortcut) -- On load, validate source still exists; if not, clear `m_SourceID` and `m_IsSource` - -## Affected Files & Classes - -### Core Parameter Node Files -1. **`examples/blueprints-example/blocks/parameter_node.h`** - - Add `m_IsSource` member (bool) - - Add `m_SourceID` member (int, 0 if not a shortcut) - - Add getter/setter methods for source management - - Add method to find source node via App* - - Add method to create shortcut from this node - -2. **`examples/blueprints-example/blocks/parameter_node.cpp`** - - Modify `OnMenu()` to add "As Source" toggle - - Modify `OnMenu()` to add "Create Shortcut" (conditional on `m_IsSource`) - - Modify `Render*()` methods to show visual differentiation - - Modify `SetBool/Int/Float/String()` to sync to source if this is a shortcut - - Modify `SetName()` to sync to source if this is a shortcut - - Modify `Run()` to check if source exists, sync from source if shortcut - - Modify `SaveState()` to save `m_IsSource` and `m_SourceID` - - Modify `LoadState()` to load `m_IsSource` and `m_SourceID`, validate source exists - - Add helper method `GetSourceNode()` to find source via App* - - Add helper method `SyncValueToSource()` for shortcut→source updates - - Add helper method `SyncValueFromSource()` for source→shortcut updates - - Add helper method `CreateShortcut()` to spawn clone at offset position - -### App Logic Files -3. **`examples/blueprints-example/app-logic.cpp`** - - Modify `LoadGraph()` to validate source nodes exist when loading shortcuts - - Add helper method `FindAllShortcutsForSource()` (optional, for cleanup) - - May need to handle source deletion in node removal code - -### App Render Files -4. **`examples/blueprints-example/app-render.cpp`** - - Context menu already calls `ParameterInstance->OnMenu()`, no changes needed - - Node deletion already handled, but may want to add cleanup hook - -### Node Types/Structure -5. **`examples/blueprints-example/types.h`** (if needed) - - May need to add source-related fields to Node struct (optional, prefer keeping in ParameterNode) - -### Save/Load JSON Format -6. **JSON Structure Addition:** - ```json - { - "node_type": "parameter", - "param_type": 2, - "is_source": true, // NEW - "source_id": 0, // NEW (0 = not a shortcut, >0 = source node ID) - "value": 42, - "display_mode": 1 - } - ``` - -## Implementation Tasks - -### Phase 1: Core Data Structures -- [ ] Add `m_IsSource` boolean member to `ParameterNode` class -- [ ] Add `m_SourceID` int member to `ParameterNode` class (default 0) -- [ ] Initialize both members in constructor -- [ ] Add getter/setter methods: `IsSource()`, `SetIsSource()`, `GetSourceID()`, `SetSourceID()` - -### Phase 2: Context Menu Integration -- [ ] Modify `ParameterNode::OnMenu()` to add "As Source" menu item (checkbox style) -- [ ] Toggle `m_IsSource` when menu item clicked -- [ ] Add conditional "Create Shortcut" menu item (only if `m_IsSource == true`) -- [ ] Implement shortcut creation logic when menu item clicked - -### Phase 3: Shortcut Creation -- [ ] Create `ParameterNode::CreateShortcut()` helper method -- [ ] Get source node's position using `ed::GetNodePosition()` -- [ ] Calculate offset position (source.x + 200, source.y) -- [ ] Call `App::SpawnParameterNode()` with source's type and calculated position -- [ ] Set new node's `m_SourceID` to source node's ID -- [ ] Copy source's value to new node via `Set*()` methods -- [ ] Set new node's name to source's name (or add suffix like "Copy") -- [ ] Set new node's position using `ed::SetNodePosition()` - -### Phase 4: Value Synchronization (Shortcut → Source) -- [ ] Modify `ParameterNode::SetBool()` to check if `m_SourceID > 0` -- [ ] If shortcut, find source node via `App::FindNode()` -- [ ] Update source's value and sync to source's `ParameterInstance` -- [ ] Similarly modify `SetInt()`, `SetFloat()`, `SetString()` -- [ ] Modify `SetName()` to sync to source if shortcut -- [ ] Note: Type changes should propagate too, but may require node recreation (advanced) - -### Phase 5: Value Synchronization (Source → Shortcuts) -- [ ] Add helper method `SyncAllShortcuts()` in `ParameterNode` (called from source) -- [ ] In source's `SetBool/Int/Float/String()`, if `m_IsSource == true`, find all shortcuts -- [ ] Iterate through all nodes in container, find ones with `m_SourceID == this->m_ID` -- [ ] Update each shortcut's value via `Set*()` methods (avoid recursion by checking source) -- [ ] Alternative: Use existing `Run()` mechanism - shortcuts call `Run()` which reads from source - -### Phase 6: Visual Differentiation -- [ ] Modify `RenderNameOnly()` to show indicator for source/shortcut -- [ ] Modify `RenderNameAndValue()` to show indicator and/or different border color -- [ ] Modify `RenderSmallBox()` to show indicator -- [ ] Source nodes: Gold/bright border or "★" icon -- [ ] Shortcut nodes: Dimmed background or "📋" icon or different border style - -### Phase 7: Save/Load -- [ ] Modify `ParameterNode::SaveState()` to save `m_IsSource` as boolean -- [ ] Modify `ParameterNode::SaveState()` to save `m_SourceID` (0 if not a shortcut) -- [ ] Modify `ParameterNode::LoadState()` to load `m_IsSource` -- [ ] Modify `ParameterNode::LoadState()` to load `m_SourceID` -- [ ] In `LoadState()`, validate source node exists: `app->FindNode(ed::NodeId(m_SourceID))` -- [ ] If source doesn't exist, clear `m_SourceID = 0` and `m_IsSource = false` (orphaned shortcut) - -### Phase 8: Source Deletion Handling -- [ ] When node is deleted, check if it's a source (`m_IsSource == true`) -- [ ] Find all shortcuts: iterate nodes, find ones with `m_SourceID == deleted_node_id` -- [ ] Clear `m_SourceID = 0` and `m_IsSource = false` on all found shortcuts -- [ ] Implementation: Hook into node deletion in `app-render.cpp` or `app-logic.cpp -- [ ] Alternative: Check in `ParameterNode::Run()` - if source not found, clear `m_SourceID` - -### Phase 9: Edge Cases & Polish -- [ ] Handle circular references (source→shortcut→source, prevent infinite loops) -- [ ] Handle source being a shortcut itself (prevent chains, keep flat) -- [ ] Update tooltips or help text to explain source/shortcut concept -- [ ] Test save/load with source nodes -- [ ] Test save/load with shortcuts -- [ ] Test source deletion with active shortcuts -- [ ] Test creating shortcuts from shortcuts (should reference original source) - -## Technical Notes - -### Source ID Management -- `m_SourceID = 0` means "not a shortcut" -- `m_SourceID > 0` means "shortcut, source node ID is m_SourceID" -- Source nodes have `m_IsSource = true` and `m_SourceID = 0` (they are not shortcuts of themselves) - -### Value Sync Direction -- **Shortcut edits → Source**: Direct update via `Set*()` methods -- **Source edits → Shortcuts**: Can use existing `Run()` mechanism or direct updates -- **Recommendation**: Use `Run()` for source→shortcut (already handles connected inputs), direct update for shortcut→source - -### Position Calculation -- Offset new shortcut to the right of source: `sourcePos.x + 200.0f, sourcePos.y` -- Use `ed::GetNodePosition()` and `ed::SetNodePosition()` for positioning -- Consider node size for better spacing - -### Finding Shortcuts -- When source updates, need to find all shortcuts -- Iterate through `container->GetNodes(app)` or `app->GetActiveRootContainer()->GetNodes(app)` -- Check each node: `node->Type == NodeType::Parameter && node->ParameterInstance && node->ParameterInstance->GetSourceID() == source_id` - -## Testing Checklist - -- [ ] Create parameter node, mark as source -- [ ] Create shortcut from source -- [ ] Edit source value, verify shortcut updates -- [ ] Edit shortcut value, verify source updates -- [ ] Create multiple shortcuts from same source -- [ ] Edit source name, verify shortcuts sync (if implemented) -- [ ] Delete source, verify shortcuts become independent -- [ ] Save graph with source and shortcuts -- [ ] Load graph with source and shortcuts -- [ ] Load graph where source no longer exists (orphaned shortcuts) -- [ ] Visual indicators show correctly for source/shortcut -- [ ] Context menu shows/hides correctly - -## Future Enhancements (Out of Scope) - -- Type change propagation (requires node recreation) -- Name sync from source to shortcuts -- Batch operations (create multiple shortcuts at once) -- Shortcut manager UI (list all shortcuts for a source) -- Shortcut-to-source navigation (jump to source) -- Breaking shortcut connection (make shortcut independent) - diff --git a/docs/taking-screenshots-mcp.md b/docs/taking-screenshots-mcp.md deleted file mode 100644 index a23a4bd..0000000 --- a/docs/taking-screenshots-mcp.md +++ /dev/null @@ -1,75 +0,0 @@ -# Taking Screenshots Using MCP Computer Control Tools - -This guide documents how to use MCP (Model Context Protocol) Computer Control tools to capture screenshots of the ImGui Node Editor application for testing and documentation purposes. - -## Overview - -The MCP Computer Control MCP server provides screenshot capabilities that allow you to capture specific windows or the entire screen. This is useful for: -- Testing the built-in screenshot functionality -- Documenting features and UI changes -- Debugging rendering issues -- Creating visual documentation - -## Prerequisites - -1. **MCP Server**: Ensure the `computer-control-mcp` server is running and configured -2. **Application**: Build and run the application - ```powershell - sh ./run.sh - ``` - -**Alternative:** Use the PowerShell command from project root: -```powershell -cd C:\Users\zx\Desktop\polymech\extern\imgui-node-editor; cd build\bin; Start-Process -FilePath ".\blueprints-example_d.exe" -PassThru | Out-Null; Start-Sleep -Seconds 3 -``` - -Wait 2-3 seconds for the application to fully initialize. - -### 2. List All Windows (Optional but Recommended) - -Use `mcp_computer-control-mcp_list_windows` to see all available windows and find your target: - - -### 3. Activate the Application Window - -Activate the "Application" window using regex matching: - -```python -mcp_computer-control-mcp_activate_window( - title_pattern="^NodeHub$", - use_regex=True, - threshold=10 -) -``` - -**Parameters:** -- `title_pattern="^NodeHub$"`: Exact match for window title "NodeHub" -- `use_regex=True`: Use regex for matching (allows `^$` anchors) -- `threshold=10`: Minimum fuzzy match score (lower = more strict) - -### 4. Wait for Window Activation - -Give the system time to bring the window to foreground: - -```python -mcp_computer-control-mcp_wait_milliseconds(milliseconds=500) -``` - -### 5. Take Screenshot - -**Option A: Window-specific Screenshot** -```python -mcp_computer-control-mcp_take_screenshot( - title_pattern="^NodeHub$", - use_regex=True, - threshold=10, - save_to_downloads=True # Optional: save to downloads folder -) -``` - -**Option B: Full Screen Screenshot** -```python -mcp_computer-control-mcp_take_screenshot( - save_to_downloads=True # Optional: save to downloads folder -) -``` diff --git a/examples/blueprints-example/CMakeLists.txt b/examples/blueprints-example/CMakeLists.txt deleted file mode 100644 index 2d9a590..0000000 --- a/examples/blueprints-example/CMakeLists.txt +++ /dev/null @@ -1,75 +0,0 @@ -add_example_executable(blueprints-example - blueprints-example.cpp - types.h - nodes.h - nodes.cpp - app.h - app.cpp - app-logic.cpp - app-render.cpp - app-screenshot.cpp - app-runtime.cpp - containers/container.h - containers/container.cpp - containers/root_container.h - containers/root_container.cpp - core/graph_state.h - core/graph_state.cpp - blocks/NodeEx.h - blocks/NodeEx.cpp - blocks/block.h - blocks/block.cpp - blocks/math_blocks.h - blocks/math_blocks.cpp - blocks/logic_blocks.h - blocks/logic_blocks.cpp - blocks/start_block.h - blocks/start_block.cpp - blocks/log_block.h - blocks/log_block.cpp - blocks/parameter_operation.h - blocks/parameter_operation.cpp - blocks/group_block.h - blocks/group_block.cpp - blocks/parameter_node.h - blocks/parameter_node.cpp - blocks/block_edit_dialog.h - blocks/block_edit_dialog.cpp - blocks/parameter_edit_dialog.h - blocks/parameter_edit_dialog.cpp - utilities/node_renderer_base.h - utilities/pathfinding.h - utilities/edge_editing.h - utilities/pin_renderer.h - utilities/style_manager.h - utilities/uuid_generator.h - utilities/uuid_id_manager.h - utilities/node_renderer_base.cpp - utilities/pathfinding.cpp - utilities/edge_editing.cpp - utilities/pin_renderer.cpp - utilities/style_manager.cpp - utilities/uuid_generator.cpp - utilities/uuid_id_manager.cpp - Logging.h - Logging.cpp - -) - -# Add local spdlog include directory (we copied it into our project) -target_include_directories(blueprints-example PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/external") -target_compile_definitions(blueprints-example PRIVATE FMT_HEADER_ONLY=1) - -# Add /utf-8 compiler flag for spdlog on MSVC -if (MSVC) - target_compile_options(blueprints-example PRIVATE /utf-8) -endif() - -# Also add to console variant if it exists -if (WIN32 AND BUILD_CONSOLE_VARIANTS) - target_include_directories(blueprints-example-console PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/external") - target_compile_definitions(blueprints-example-console PRIVATE FMT_HEADER_ONLY=1) - if (MSVC) - target_compile_options(blueprints-example-console PRIVATE /utf-8) - endif() -endif() diff --git a/examples/blueprints-example/LOGGING_INTEGRATION.md b/examples/blueprints-example/LOGGING_INTEGRATION.md deleted file mode 100644 index 70533c8..0000000 --- a/examples/blueprints-example/LOGGING_INTEGRATION.md +++ /dev/null @@ -1,220 +0,0 @@ -# Spdlog Logger Integration Summary - -## Overview -Integrated **spdlog** (high-performance C++ logging library) into the imgui-node-editor blueprints-example for Win32/ImGui. The system uses LOG_* macros that can be disabled via `DISABLE_LOGGING` compile flag. - -## Files Created/Modified - -### Core Logger Files -- **`Logging.h`** - Simple wrapper with LOG_* macros for spdlog -- **`Logging.cpp`** - Initialization/shutdown using spdlog -- **`external/spdlog/`** - Copied locally (header-only mode) - -### Modified Files -1. **`examples/CMakeLists.txt`** - Added spdlog INTERFACE library -2. **`examples/blueprints-example/CMakeLists.txt`** - Added include path and `/utf-8` compiler flag -3. **`app.cpp`** - Initialize/cleanup logger with `InitLogger()` and `ShutdownLogger()` -4. **`app-render.cpp`** - Replaced key printf() calls with LOG_* macros - -## Features - -### Log Levels (spdlog) -```cpp -LOG_TRACE(...) // Most verbose (detailed trace info) -LOG_DEBUG(...) // Debug information -LOG_INFO(...) // Informational messages -LOG_WARN(...) // Warnings -LOG_ERROR(...) // Errors -LOG_CRITICAL(...) // Critical errors (renamed from FATAL) - -// Legacy compatibility -LOG_FATAL(...) -> LOG_CRITICAL(...) -LOG_VERBOSE(...) -> LOG_TRACE(...) -``` - -### Sinks (Output Targets) -- **Console Sink** - Color-coded output to stdout (Windows console colors via spdlog) -- **File Sink** - Persistent logging to `blueprints.log` - -## Usage - -### Initialization (in app.cpp::OnStart) -```cpp -// Initialize spdlog logger system -InitLogger("blueprints", true, true, "blueprints.log"); -// ^app name ^console ^file ^filename -``` - -### Logging Examples -```cpp -// Info level -LOG_INFO("[DELETE] DeleteNodeAndInstances: Starting deletion of node {} (ptr={})", - nodeId, (void *)&node); - -// Error level -LOG_ERROR("[ERROR] RenderNodes: Node pointer corrupted: 0x{:x}", nodePtrValue); - -// Warning level -LOG_WARN("[WARNING] RenderNodes: null node pointer in container!"); -``` - -### Shutdown (in app.cpp::OnStop) -```cpp -// Shutdown spdlog logger -ShutdownLogger(); -``` - -## Architecture - -### Header-Only Mode -- Spdlog compiled in header-only mode (`SPDLOG_HEADER_ONLY`) -- No separate library linking required -- All template code included at compile time - -### Multi-Sink Support -- Console sink: `[HH:MM:SS] [LEVEL] message` -- File sink: `[YYYY-MM-DD HH:MM:SS.mmm] [LEVEL] message` - -### Thread Safety -- Spdlog provides thread-safe logging via `_mt` (multi-threaded) sinks -- `stdout_color_sink_mt` and `basic_file_sink_mt` are thread-safe - -## Log Format - -### Console Output -``` -[14:32:15] [info] === Logger System Initialized (spdlog) === -[14:32:16] [error] Node pointer itself is corrupted: 0xDDDDDDDDDDDDDDDD -[14:32:17] [warn] null node pointer in container! -``` - -### File Output (`blueprints.log`) -``` -[2025-11-07 14:32:15.123] [info] === Logger System Initialized (spdlog) === -[2025-11-07 14:32:16.456] [error] Node pointer itself is corrupted: 0xDDDDDDDDDDDDDDDD -[2025-11-07 14:32:17.789] [warn] null node pointer in container! -``` - -## Advantages Over Custom Logger - -### Why Spdlog? -✅ **Performance** - Extremely fast, async logging support -✅ **Feature-Rich** - Rotating files, daily files, custom sinks -✅ **Mature** - Battle-tested library used in production -✅ **Cross-Platform** - Works on Windows, Linux, macOS -✅ **Modern C++** - Uses C++11/14/17 features properly -✅ **No Dependencies** - Header-only mode, no external libs - -### Performance -- Zero-cost abstractions when logging is disabled -- Minimal overhead in release builds -- Optional async logging for high-throughput scenarios - -## Build Configuration - -### Required CMake Changes -1. **`examples/CMakeLists.txt`**: - - Added spdlog INTERFACE library - -2. **`examples/blueprints-example/CMakeLists.txt`**: - ```cmake - # Add local spdlog include directory - target_include_directories(blueprints-example PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/external") - - # Add /utf-8 compiler flag for spdlog on MSVC - if (MSVC) - target_compile_options(blueprints-example PRIVATE /utf-8) - endif() - ``` - -### Build Verification -✅ Build successful with `sh scripts/build.sh` -- Spdlog compiles cleanly in header-only mode -- `/utf-8` flag required for MSVC (Unicode support) -- All LOG_* macros expand correctly - -## Output Files - -### Console -- Color-coded log messages (via spdlog wincolor_sink) -- Real-time feedback during execution - -### `blueprints.log` -- Persistent log history with millisecond precision -- Appends to existing file (doesn't overwrite) -- Full timestamp format - -## Configuration - -### Disable Logging Completely -Define `DISABLE_LOGGING` before including `Logging.h`: -```cpp -#define DISABLE_LOGGING -#include "Logging.h" -``` - -All LOG_* macros become `(void)0` - zero runtime cost! - -### Change Log Level at Runtime -```cpp -// Set global level (only works if you access spdlog directly) -g_logger->set_level(spdlog::level::err); // Only errors and critical -``` - -### Add Custom Sinks -```cpp -// You can extend InitLogger() to add more sinks: -auto rotating_sink = std::make_shared( - "app.log", 1024*1024*5, 3); // 5MB, 3 files -g_logger->sinks().push_back(rotating_sink); -``` - -## Testing - -Run the application: -```bash -./build/bin/blueprints-example_d.exe -``` - -Check: -- **Console** - Colored log messages with timestamps -- **`build/bin/blueprints.log`** - Persistent log file - -## Future Enhancements - -Possible additions: -- **Async logging** - For high-throughput scenarios -- **Rotating files** - Size/time based rotation -- **Remote logging** - Network sinks (UDP/TCP) -- **Custom formatters** - Different log formats per sink -- **Log filtering** - By component/category -- **ImGui log viewer** - In-app log window - -## Example Advanced Usage - -### Multiple Loggers -```cpp -// Create separate loggers for different subsystems -auto render_logger = spdlog::stdout_color_mt("render"); -auto physics_logger = spdlog::basic_logger_mt("physics", "physics.log"); -``` - -### Structured Logging -```cpp -LOG_INFO("User {} performed action {}", username, action); -LOG_ERROR("Failed to load file: {} (error: {})", filename, err_code); -``` - -### Conditional Compilation -```cpp -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG - LOG_DEBUG("Expensive debug info: {}", compute_debug_info()); -#endif -``` - ---- - -**Integration Date:** November 7, 2025 -**Spdlog Version:** Header-only (bundled) -**Status:** ✅ Complete and verified -**Build:** ✅ Successful with `/utf-8` flag diff --git a/examples/blueprints-example/blueprints_cli.cpp b/examples/blueprints-example/blueprints_cli.cpp deleted file mode 100644 index d1d23b8..0000000 --- a/examples/blueprints-example/blueprints_cli.cpp +++ /dev/null @@ -1,317 +0,0 @@ -#include "blueprints_cli.h" -#include -#include - -// ============================================================================ -// Helper Functions (Global) -// ============================================================================ - -std::string GetStringArg(const ArgsMap& args, const std::string& key, const std::string& defaultValue) -{ - auto it = args.find(key); - if (it != args.end() && it->second.Type == ArgValue::Type::String) - return it->second.String; - return defaultValue; -} - -bool GetBoolArg(const ArgsMap& args, const std::string& key, bool defaultValue) -{ - auto it = args.find(key); - if (it != args.end() && it->second.Type == ArgValue::Type::Bool) - return it->second.Bool; - return defaultValue; -} - -int GetIntArg(const ArgsMap& args, const std::string& key, int defaultValue) -{ - auto it = args.find(key); - if (it != args.end() && it->second.Type == ArgValue::Type::Int) - return static_cast(it->second.Int); - return defaultValue; -} - -double GetDoubleArg(const ArgsMap& args, const std::string& key, double defaultValue) -{ - auto it = args.find(key); - if (it != args.end() && it->second.Type == ArgValue::Type::Double) - return it->second.Double; - return defaultValue; -} - -// ============================================================================ -// BlueprintsCLI Implementation -// ============================================================================ - -BlueprintsCLI::BlueprintsCLI(const ArgsMap& args) - : m_Args(args) -{ - // Set graph filename if provided - std::string filename = GetStringArg("file", ""); - if (!filename.empty()) { - SetGraphFilename(filename); - } -} - -int BlueprintsCLI::Execute() -{ - std::string command = GetStringArg("command", "help"); - - if (command == "validate") { - return CommandValidate(); - } - else if (command == "export") { - return CommandExport(); - } - else if (command == "execute") { - return CommandExecute(); - } - else if (command == "info") { - return CommandInfo(); - } - else if (command == "help") { - return CommandHelp(); - } - else { - PrintError("Unknown command: " + command); - CommandHelp(); - return 1; - } -} - -// ============================================================================ -// Command Implementations -// ============================================================================ - -int BlueprintsCLI::CommandValidate() -{ - std::string filename = GetGraphFilename(); - - if (filename.empty()) { - PrintError("No graph file specified. Use --file "); - return 1; - } - - PrintInfo("Validating: " + filename); - - // Create root container - auto* container = AddRootContainer(filename); - if (!container) { - PrintError("Failed to create container"); - return 1; - } - - // Load graph - if (!LoadGraph(filename)) { - PrintError("Failed to load graph: " + GetLastError()); - return 1; - } - - auto info = GetGraphInfo(); - PrintSuccess("Graph loaded successfully"); - printf(" Nodes: %s\n", info["nodes"].c_str()); - printf(" Links: %s\n", info["links"].c_str()); - - // Validate - if (!ValidateGraph()) { - PrintError("Validation failed: " + GetLastError()); - return 1; - } - - PrintSuccess("Validation passed"); - return 0; -} - -int BlueprintsCLI::CommandExport() -{ - std::string filename = GetGraphFilename(); - std::string output = GetStringArg("output", ""); - std::string format = GetStringArg("format", "json"); - - if (filename.empty()) { - PrintError("No graph file specified. Use --file "); - return 1; - } - - if (output.empty()) { - PrintError("No output file specified. Use --output "); - return 1; - } - - PrintInfo("Exporting: " + filename + " -> " + output + " (" + format + ")"); - - // Create root container and load - auto* container = AddRootContainer(filename); - if (!container) { - PrintError("Failed to create container"); - return 1; - } - - if (!LoadGraph(filename)) { - PrintError("Failed to load graph: " + GetLastError()); - return 1; - } - - // Export based on format - if (format == "json") { - // For JSON, just save to output file - if (SaveGraph(output)) { - PrintSuccess("Exported to JSON: " + output); - return 0; - } else { - PrintError("Failed to export: " + GetLastError()); - return 1; - } - } - else { - PrintError("Format '" + format + "' not yet implemented"); - printf(" Supported formats: json\n"); - printf(" Planned: xml, yaml, dot\n"); - return 1; - } -} - -int BlueprintsCLI::CommandExecute() -{ - std::string filename = GetGraphFilename(); - - if (filename.empty()) { - PrintError("No graph file specified. Use --file "); - return 1; - } - - PrintInfo("Executing: " + filename); - - // Create root container and load - auto* container = AddRootContainer(filename); - if (!container) { - PrintError("Failed to create container"); - return 1; - } - - if (!LoadGraph(filename)) { - PrintError("Failed to load graph: " + GetLastError()); - return 1; - } - - // Execute - if (!ExecuteGraph()) { - PrintError("Execution failed: " + GetLastError()); - return 1; - } - - PrintSuccess("Execution completed"); - return 0; -} - -int BlueprintsCLI::CommandInfo() -{ - std::string filename = GetGraphFilename(); - - if (filename.empty()) { - PrintError("No graph file specified. Use --file "); - return 1; - } - - PrintInfo("Graph info: " + filename); - - // Create root container and load - auto* container = AddRootContainer(filename); - if (!container) { - PrintError("Failed to create container"); - return 1; - } - - if (!LoadGraph(filename)) { - PrintError("Failed to load graph: " + GetLastError()); - return 1; - } - - auto info = GetGraphInfo(); - - printf("Nodes: %s\n", info["nodes"].c_str()); - printf("Links: %s\n", info["links"].c_str()); - - // Print node types - printf("\nNode Types:\n"); - for (const auto& [key, value] : info) { - if (key.find("type_") == 0) { - std::string type = key.substr(5); // Remove "type_" prefix - printf(" %s: %s\n", type.c_str(), value.c_str()); - } - } - - return 0; -} - -int BlueprintsCLI::CommandHelp() -{ - printf("Blueprints CLI - Node graph manipulation tool\n"); - printf("\n"); - printf("Usage:\n"); - printf(" blueprints-example-console --headless --file --command [options]\n"); - printf("\n"); - printf("Commands:\n"); - printf(" validate Validate graph structure\n"); - printf(" export Export to different format\n"); - printf(" execute Execute graph (headless)\n"); - printf(" info Display graph information\n"); - printf(" help Show this help message\n"); - printf("\n"); - printf("Options:\n"); - printf(" --file Path to graph JSON file (required)\n"); - printf(" --output Output file path (for export)\n"); - printf(" --format Output format (json, xml, yaml, dot)\n"); - printf("\n"); - printf("Examples:\n"); - printf(" # Validate a graph\n"); - printf(" blueprints-example-console --headless --file graph.json --command validate\n"); - printf("\n"); - printf(" # Get graph info\n"); - printf(" blueprints-example-console --headless --file graph.json --command info\n"); - printf("\n"); - printf(" # Export to JSON\n"); - printf(" blueprints-example-console --headless --file graph.json --command export --output out.json\n"); - printf("\n"); - printf(" # Execute graph\n"); - printf(" blueprints-example-console --headless --file graph.json --command execute\n"); - printf("\n"); - - return 0; -} - -// ============================================================================ -// Output Helpers -// ============================================================================ - -void BlueprintsCLI::PrintError(const std::string& message) -{ - fprintf(stderr, "ERROR: %s\n", message.c_str()); - fflush(stderr); -} - -void BlueprintsCLI::PrintSuccess(const std::string& message) -{ - printf("SUCCESS: %s\n", message.c_str()); - fflush(stdout); -} - -void BlueprintsCLI::PrintInfo(const std::string& message) -{ - printf("INFO: %s\n", message.c_str()); - fflush(stdout); -} - -// ============================================================================ -// Member Helper Functions -// ============================================================================ - -std::string BlueprintsCLI::GetStringArg(const std::string& key, const std::string& defaultValue) const -{ - return ::GetStringArg(m_Args, key, defaultValue); -} - -bool BlueprintsCLI::GetBoolArg(const std::string& key, bool defaultValue) const -{ - return ::GetBoolArg(m_Args, key, defaultValue); -} - diff --git a/examples/blueprints-example/blueprints_cli.h b/examples/blueprints-example/blueprints_cli.h deleted file mode 100644 index 970cfbb..0000000 --- a/examples/blueprints-example/blueprints_cli.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include "blueprints_engine.h" -#include "application.h" -#include - -/** - * BlueprintsCLI - Command-line interface for blueprints engine - * - * Provides headless operations on graphs without requiring GUI/rendering. - * Inherits from BlueprintsEngine to access core graph operations. - * - * Usage: - * BlueprintsCLI cli(args); - * return cli.Execute(); - */ -class BlueprintsCLI : public BlueprintsEngine -{ -public: - explicit BlueprintsCLI(const ArgsMap& args); - - /** - * Execute the CLI command - * @return Exit code (0 = success, non-zero = error) - */ - int Execute(); - -private: - ArgsMap m_Args; - - // Helper to extract string argument - std::string GetStringArg(const std::string& key, const std::string& defaultValue = "") const; - - // Helper to extract bool argument - bool GetBoolArg(const std::string& key, bool defaultValue = false) const; - - // Command implementations - int CommandValidate(); - int CommandExport(); - int CommandExecute(); - int CommandInfo(); - int CommandHelp(); - - // Output helpers - void PrintError(const std::string& message); - void PrintSuccess(const std::string& message); - void PrintInfo(const std::string& message); -}; - -// Helper functions (can be used outside CLI class) -std::string GetStringArg(const ArgsMap& args, const std::string& key, const std::string& defaultValue = ""); -bool GetBoolArg(const ArgsMap& args, const std::string& key, bool defaultValue = false); -int GetIntArg(const ArgsMap& args, const std::string& key, int defaultValue = 0); -double GetDoubleArg(const ArgsMap& args, const std::string& key, double defaultValue = 0.0); - diff --git a/examples/blueprints-example/blueprints_engine.cpp b/examples/blueprints-example/blueprints_engine.cpp deleted file mode 100644 index f59a170..0000000 --- a/examples/blueprints-example/blueprints_engine.cpp +++ /dev/null @@ -1,337 +0,0 @@ -#include "blueprints_engine.h" -#include "containers/root_container.h" -#include "nodes.h" -#include -#include -#include - -BlueprintsEngine::BlueprintsEngine() - : m_GraphFilename("BlueprintsGraph.json") -{ -} - -// ============================================================================ -// File I/O -// ============================================================================ - -bool BlueprintsEngine::LoadGraph(const std::string& filename) -{ - ClearError(); - - // Note: This is a virtual method that will be overridden by subclasses - // BlueprintsCLI will provide its own implementation - // App will use its existing SaveGraph/LoadGraph methods - - SetError("LoadGraph must be implemented by subclass"); - return false; -} - -bool BlueprintsEngine::SaveGraph(const std::string& filename) -{ - ClearError(); - - // Note: Virtual method - will be overridden by subclasses - SetError("SaveGraph must be implemented by subclass"); - return false; -} - -// ============================================================================ -// Validation -// ============================================================================ - -bool BlueprintsEngine::ValidateGraph() -{ - ClearError(); - - auto* container = GetActiveRootContainer(); - if (!container) { - SetError("No active container"); - return false; - } - - // Basic checks - if (!ValidateNodeConnections()) { - return false; - } - - if (!ValidatePinTypes()) { - return false; - } - - if (!ValidateNoCycles()) { - return false; - } - - return true; -} - -bool BlueprintsEngine::ValidateNodeConnections() -{ - // Virtual method - subclasses will implement - return true; -} - -bool BlueprintsEngine::ValidatePinTypes() -{ - // Virtual method - subclasses will implement - return true; -} - -bool BlueprintsEngine::ValidateNoCycles() -{ - auto* container = GetActiveRootContainer(); - if (!container) return false; - - // TODO: Implement cycle detection - // For now, just return true - return true; -} - -// ============================================================================ -// Execution -// ============================================================================ - -std::vector BlueprintsEngine::GetExecutionOrder() -{ - // Virtual method - subclasses will implement - return std::vector(); -} - -bool BlueprintsEngine::ExecuteNode(Node* node) -{ - if (!node) return false; - - // TODO: Implement actual node execution - // This would evaluate the node's operation based on input values - // and produce output values - - printf("Executing node: %s (ID: %d)\n", node->Name.c_str(), node->ID.Get()); - - return true; -} - -bool BlueprintsEngine::ExecuteGraph() -{ - ClearError(); - - if (!ValidateGraph()) { - return false; - } - - auto executionOrder = GetExecutionOrder(); - - printf("Executing %zu nodes...\n", executionOrder.size()); - - for (Node* node : executionOrder) { - if (!ExecuteNode(node)) { - SetError("Failed to execute node: " + node->Name); - return false; - } - } - - printf("Graph execution completed successfully\n"); - return true; -} - -// ============================================================================ -// Graph Info -// ============================================================================ - -std::map BlueprintsEngine::GetGraphInfo() const -{ - // Virtual method - subclasses will implement - std::map info; - info["error"] = "GetGraphInfo must be implemented by subclass"; - return info; -} - -// ============================================================================ -// Export -// ============================================================================ - -std::string BlueprintsEngine::ExportGraph(const std::string& format) const -{ - ClearError(); - - if (format == "json") { - // TODO: Implement JSON export (different from internal format) - return "{}"; - } - else if (format == "xml") { - // TODO: Implement XML export - return ""; - } - else if (format == "yaml") { - // TODO: Implement YAML export - return ""; - } - else if (format == "dot") { - // TODO: Implement Graphviz DOT export - return ""; - } - - return ""; -} - -// ============================================================================ -// ID Management (delegates to GraphState) -// ============================================================================ - -int BlueprintsEngine::GetNextId() -{ - return m_GraphState.GetNextId(); -} - -ed::LinkId BlueprintsEngine::GetNextLinkId() -{ - return m_GraphState.GetNextLinkId(); -} - -// ============================================================================ -// UUID Management (delegates to UuidGenerator) -// ============================================================================ - -uint32_t BlueprintsEngine::GenerateRandomUuid() -{ - return m_UuidGenerator.GenerateRandom(); -} - -uint32_t BlueprintsEngine::GenerateSequentialUuid() -{ - return m_UuidGenerator.GenerateSequential(); -} - -std::string BlueprintsEngine::UuidToHexString(uint32_t uuid) -{ - return m_UuidGenerator.ToHexString(uuid); -} - -uint32_t BlueprintsEngine::HexStringToUuid(const std::string& hexString) -{ - return m_UuidGenerator.FromHexString(hexString); -} - -Uuid64 BlueprintsEngine::GenerateRandomUuid64() -{ - return m_UuidGenerator.GenerateRandom64(); -} - -Uuid64 BlueprintsEngine::GenerateSequentialUuid64() -{ - return m_UuidGenerator.GenerateSequential64(); -} - -std::string BlueprintsEngine::UuidToHexString64(const Uuid64& uuid) -{ - return m_UuidGenerator.ToHexString64(uuid); -} - -Uuid64 BlueprintsEngine::HexStringToUuid64(const std::string& hexString) -{ - return m_UuidGenerator.FromHexString64(hexString); -} - -std::string BlueprintsEngine::UuidToStandardString(const Uuid64& uuid) -{ - // Format as standard UUID string - char buf[64]; - snprintf(buf, sizeof(buf), "%08x-%04x-%04x-%04x-%08x%04x", - 0, 0, 0, 0, uuid.high, uuid.low); - return std::string(buf); -} - -Uuid64 BlueprintsEngine::StandardStringToUuid(const std::string& uuidStr, bool takeLast64) -{ - // Parse standard UUID string - for now just return empty - Uuid64 result; - result.high = 0; - result.low = 0; - return result; -} - -// ============================================================================ -// Node/Link/Pin Lookups (delegates to GraphState) -// ============================================================================ - -Node* BlueprintsEngine::FindNode(ed::NodeId id) -{ - return m_GraphState.FindNode(id); -} - -Link* BlueprintsEngine::FindLink(ed::LinkId id) -{ - return m_GraphState.FindLink(id); -} - -Pin* BlueprintsEngine::FindPin(ed::PinId id) -{ - // FindPin requires iterating nodes which requires App* for container lookup - // Subclasses will implement this - return nullptr; -} - -// ============================================================================ -// Validation Helpers -// ============================================================================ - -bool BlueprintsEngine::IsPinLinked(ed::PinId id) -{ - // Virtual method - subclasses will implement - return false; -} - -bool BlueprintsEngine::CanCreateLink(Pin* a, Pin* b) -{ - if (!a || !b || a == b) - return false; - - // Can only connect Input to Output - if (a->Kind == b->Kind) - return false; - - // TODO: Add type compatibility checking - - return true; -} - -bool BlueprintsEngine::IsLinkDuplicate(ed::PinId startPinId, ed::PinId endPinId) -{ - // Virtual method - subclasses will implement - return false; -} - -Link* BlueprintsEngine::FindLinkConnectedToPin(ed::PinId pinId) -{ - // Virtual method - subclasses will implement - return nullptr; -} - -// ============================================================================ -// Container Management (delegates to GraphState) -// ============================================================================ - -RootContainer* BlueprintsEngine::GetActiveRootContainer() const -{ - return m_GraphState.GetActiveRootContainer(); -} - -RootContainer* BlueprintsEngine::AddRootContainer(const std::string& filename) -{ - return m_GraphState.AddRootContainer(filename); -} - -void BlueprintsEngine::RemoveRootContainer(RootContainer* container) -{ - m_GraphState.RemoveRootContainer(container); -} - -void BlueprintsEngine::SetActiveRootContainer(RootContainer* container) -{ - m_GraphState.SetActiveRootContainer(container); -} - -Container* BlueprintsEngine::FindContainerForNode(ed::NodeId nodeId) -{ - return m_GraphState.FindContainerForNode(nodeId); -} - diff --git a/examples/blueprints-example/blueprints_engine.h b/examples/blueprints-example/blueprints_engine.h deleted file mode 100644 index b3f3161..0000000 --- a/examples/blueprints-example/blueprints_engine.h +++ /dev/null @@ -1,176 +0,0 @@ -#pragma once - -#include "core/graph_state.h" -#include "utilities/uuid_generator.h" -#include "utilities/uuid_id_manager.h" -#include "types.h" -#include -#include - -namespace ed = ax::NodeEditor; - -/** - * BlueprintsEngine - Core graph engine without UI dependencies - * - * This class contains all the core graph manipulation, validation, - * and file I/O logic. It can be used in both GUI and CLI contexts. - * - * Responsibilities: - * - Graph state management (via GraphState) - * - File I/O (load/save graphs) - * - Graph validation - * - UUID generation and management - * - Node/Link/Pin lookups - * - Graph execution logic (headless) - * - * Does NOT contain: - * - ImGui/rendering code - * - Editor context - * - UI state - * - Visual styling - */ -class BlueprintsEngine -{ -public: - BlueprintsEngine(); - virtual ~BlueprintsEngine() = default; - - // ======================================================================== - // Core Graph Operations - // ======================================================================== - - /** - * Load graph from file - * @param filename Path to graph JSON file - * @return true if loaded successfully - */ - virtual bool LoadGraph(const std::string& filename); - - /** - * Save graph to file - * @param filename Path to save graph JSON file - * @return true if saved successfully - */ - virtual bool SaveGraph(const std::string& filename); - - /** - * Validate graph structure - * @return true if graph is valid (no broken links, no cycles, etc.) - */ - bool ValidateGraph(); - - /** - * Execute graph (headless mode) - * Processes all nodes in topological order - * @return true if execution completed without errors - */ - bool ExecuteGraph(); - - /** - * Get graph information - * @return Map of info: {"nodes": count, "links": count, "types": {...}} - */ - std::map GetGraphInfo() const; - - /** - * Export graph to different format - * @param format Export format ("json", "xml", "yaml", "dot") - * @return Exported string, or empty string on error - */ - std::string ExportGraph(const std::string& format) const; - - // ======================================================================== - // ID Management - // ======================================================================== - - int GetNextId(); - ed::LinkId GetNextLinkId(); - - // UUID generation (32-bit) - uint32_t GenerateRandomUuid(); - uint32_t GenerateSequentialUuid(); - std::string UuidToHexString(uint32_t uuid); - uint32_t HexStringToUuid(const std::string& hexString); - - // UUID generation (64-bit) - Uuid64 GenerateRandomUuid64(); - Uuid64 GenerateSequentialUuid64(); - std::string UuidToHexString64(const Uuid64& uuid); - Uuid64 HexStringToUuid64(const std::string& hexString); - - // Standard UUID format - std::string UuidToStandardString(const Uuid64& uuid); - Uuid64 StandardStringToUuid(const std::string& uuidStr, bool takeLast64 = true); - - UuidGenerator& GetUuidGenerator() { return m_UuidGenerator; } - UuidIdManager& GetUuidIdManager() { return m_UuidIdManager; } - - // ======================================================================== - // Node/Link/Pin Queries - // ======================================================================== - - Node* FindNode(ed::NodeId id); - Link* FindLink(ed::LinkId id); - Pin* FindPin(ed::PinId id); - - // ======================================================================== - // Validation Helpers - // ======================================================================== - - bool IsPinLinked(ed::PinId id); - bool CanCreateLink(Pin* a, Pin* b); - bool IsLinkDuplicate(ed::PinId startPinId, ed::PinId endPinId); - Link* FindLinkConnectedToPin(ed::PinId pinId); - - // ======================================================================== - // Container Management - // ======================================================================== - - RootContainer* GetActiveRootContainer() const; - RootContainer* AddRootContainer(const std::string& filename); - void RemoveRootContainer(RootContainer* container); - void SetActiveRootContainer(RootContainer* container); - Container* FindContainerForNode(ed::NodeId nodeId); - - // ======================================================================== - // Core State Access - // ======================================================================== - - GraphState& GetGraphState() { return m_GraphState; } - const GraphState& GetGraphState() const { return m_GraphState; } - - // ======================================================================== - // Configuration - // ======================================================================== - - void SetGraphFilename(const std::string& filename) { m_GraphFilename = filename; } - const std::string& GetGraphFilename() const { return m_GraphFilename; } - - // ======================================================================== - // Error Reporting (for CLI use) - // ======================================================================== - - const std::string& GetLastError() const { return m_LastError; } - -protected: - // Core state - GraphState m_GraphState; // Central graph data management - UuidGenerator m_UuidGenerator; // UUID generation - UuidIdManager m_UuidIdManager; // UUID <-> Runtime ID mapping - std::string m_GraphFilename; // Current graph file - std::string m_LastError; // Last error message (for CLI) - - // Helper methods for subclasses - void SetError(const std::string& error) { m_LastError = error; } - void ClearError() { m_LastError.clear(); } - - // Internal validation helpers - bool ValidateNodeConnections(); - bool ValidateNoCycles(); - bool ValidatePinTypes(); - - // Internal execution helpers - std::vector GetExecutionOrder(); - bool ExecuteNode(Node* node); -}; - diff --git a/examples/blueprints-example/commons.h b/examples/blueprints-example/commons.h deleted file mode 100644 index 607c5d3..0000000 --- a/examples/blueprints-example/commons.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -#include "./types.h" -#include "./enums.h" - - -typedef char* NHSTRING; -typedef char NHCHAR; -typedef unsigned short* NHUSTRING; -typedef unsigned short NHUCHAR; -typedef int NHBOOL; -typedef unsigned char NHBYTE; -typedef unsigned int NHDWORD; -typedef unsigned short NHWORD; -typedef int NHERROR; -typedef int NHParameterType; -typedef int NHOperationType; -typedef int NHMessageType; -typedef int NHAttributeType; -typedef int NHAttributeCategory; \ No newline at end of file diff --git a/examples/blueprints-example/enums.h b/examples/blueprints-example/enums.h deleted file mode 100644 index eea9d9b..0000000 --- a/examples/blueprints-example/enums.h +++ /dev/null @@ -1,112 +0,0 @@ -#pragma once - -//------------------------------------------------------------------------------ -// -// Building Blocks -// -//------------------------------------------------------------------------------ - -/************************************************************ -{filename:NH_BEHAVIOR_FLAGS} -Summary: Flags settings for behaviors. -Remarks: - + When creating a prototype, you can precise various flags - about how your behavior will act: whether it will send or receive message, - does the user may add inputs,outputs or parameters, is it active, etc. - -See also: NHBehaviorPrototype::SetBehaviorFlags,Behavior Prototype Creation -**********************************************************/ -typedef enum NH_BEHAVIOR_FLAGS { - NHBEHAVIOR_NONE =0x00000000, // Reserved for future use - NHBEHAVIOR_ACTIVE =0x00000001, // This behavior is active - NHBEHAVIOR_SCRIPT =0x00000002, // This behavior is a script - NHBEHAVIOR_RESERVED1 =0x00000004, // Reserved for internal use. - NHBEHAVIOR_USEFUNCTION =0x00000008, // Behavior uses a function and not a graph - NHBEHAVIOR_RESERVED2 =0x00000010, // Reserved for internal use. - NHBEHAVIOR_CUSTOMSETTINGSEDITDIALOG =0x00000020, // Behavior has a custom Dialog Box for settings edition . - NHBEHAVIOR_WAITSFORMESSAGE =0x00000040, // Behavior is waiting for a message to activate one of its outputs - NHBEHAVIOR_VARIABLEINPUTS =0x00000080, // Behavior may have its inputs changed by editing them - NHBEHAVIOR_VARIABLEOUTPUTS =0x00000100, // Behavior may have its outputs changed by editing them - NHBEHAVIOR_VARIABLEPARAMETERINPUTS =0x00000200, // Behavior may have its number of input parameters changed by editing them - NHBEHAVIOR_VARIABLEPARAMETEROUTPUTS =0x00000400, // Behavior may have its number of output parameters changed by editing them - NHBEHAVIOR_TOPMOST =0x00004000, // No other Behavior includes this one - NHBEHAVIOR_BUILDINGBLOCK =0x00008000, // This Behavior is a building block. Automatically set by the engine when coming from a DLL. - NHBEHAVIOR_MESSAGESENDER =0x00010000, // Behavior may send messages during its execution. - NHBEHAVIOR_MESSAGERECEIVER =0x00020000, // Behavior may check messages during its execution. - NHBEHAVIOR_TARGETABLE =0x00040000, // Behavior may be owned by a different object that the one to which its execution will apply. - NHBEHAVIOR_CUSTOMEDITDIALOG =0x00080000, // This Behavior have a custom Dialog Box for parameters edition . - NHBEHAVIOR_RESERVED0 =0x00100000, // Reserved for internal use. - NHBEHAVIOR_EXECUTEDLASTFRAME =0x00200000, // This behavior has been executed during last process. (Available only in profile mode ) - NHBEHAVIOR_DEACTIVATENEXTFRAME =0x00400000, // Behavior will be deactivated next frame - NHBEHAVIOR_RESETNEXTFRAME =0x00800000, // Behavior will be reseted next frame - NHBEHAVIOR_INTERNALLYCREATEDINPUTS =0x01000000, // Behavior execution may create/delete inputs - NHBEHAVIOR_INTERNALLYCREATEDOUTPUTS =0x02000000, // Behavior execution may create/delete outputs - NHBEHAVIOR_INTERNALLYCREATEDINPUTPARAMS =0x04000000, // Behavior execution may create/delete input parameters or change their type - NHBEHAVIOR_INTERNALLYCREATEDOUTPUTPARAMS=0x08000000, // Behavior execution may create/delete output parameters or change their type - NHBEHAVIOR_INTERNALLYCREATEDLOCALPARAMS =0x40000000, // Behavior execution may create/delete local parameters or change their type - NHBEHAVIOR_ACTIVATENEXTFRAME =0x10000000, // Behavior will be activated next frame - NHBEHAVIOR_LOCKED =0x20000000, // Behavior is locked for utilisation in Virtools - NHBEHAVIOR_LAUNCHEDONCE =0x80000000, // Behavior has not yet been launched... -} NH_BEHAVIOR_FLAGS; - -//------------------------------------------------------------------------------ -// -// Parameters -// -//------------------------------------------------------------------------------ - -/************************************************* -{filename:NH_PARAMETERTYPE_FLAGS} -Summary: Flags settings for new parameter types - -Remarks: -+These flags specify special settings for a parameter type. -+Parameter may have a fixed or variable buffer size, some may be hidden -so that they are not displayed in the interface. -See also: NHParameterTypeDesc -*************************************************/ -typedef enum NH_PARAMETERTYPE_FLAGS { - NHPARAMETERTYPE_VARIABLESIZE = 0x00000001, // Size of the buffer stored by the parameter may change - NHPARAMETERTYPE_RESERVED = 0x00000002, // Reserved - NHPARAMETERTYPE_HIDDEN = 0x00000004, // This parameter type should not be shown in the interface - NHPARAMETERTYPE_FLAGS = 0x00000008, // This parameter type is a flag (See NHParameterManager::RegisterNewFlags) - NHPARAMETERTYPE_STRUCT = 0x00000010, // This parameter type is a structure of parameters (See NHParameterManager::RegisterNewStructure) - NHPARAMETERTYPE_ENUMS = 0x00000020, // This parameter type is an enumeration (See NHParameterManager::RegisterNewEnum) - NHPARAMETERTYPE_USER = 0x00000040, // This parameter type is a user-defined one created in the interface - NHPARAMETERTYPE_NOENDIANCONV = 0x00000080, // Do not try to convert this parameter buffer On Big-Endian processors (strings, void buffer have this flags) - NHPARAMETERTYPE_TOSAVE = 0x00000100, // Temporary flag set in CKFile::EndSave(). This parameter type is to be saved in the SaveData callback of managers. Used in Parameter Manager (used user's flags & enums) -} NH_PARAMETERTYPE_FLAGS; - -//----------------------------------------------------------//// -// Data Array Flags and Enums //// -//----------------------------------------------------------//// - -/************************************************ -{filename:NH_BINARYOPERATOR} -Summary: Available operations between colums of a DataArray - -See Also: CKDataArray::ColumnTransform, CKDataArray::ColumnsOperate -************************************************/ -typedef enum NH_BINARYOPERATOR{ - NHADD = 1, // Addition - NHSUB = 2, // Substraction - NHMUL = 3, // Multiplication - NHDIV = 4 // Division -} NH_BINARYOPERATOR; - -/************************************************ -{filename:NH_COMPOPERATOR} -Summary: Available comparisons between colums of a DataArray -Remarks: - -See Also: CKDataArray::CreateGroup, CKDataArray::FindLine -************************************************/ -typedef enum NH_COMPOPERATOR{ - NHEQUAL = 1, - NHNOTEQUAL = 2, - NHLESSER = 3, - NHLESSEREQUAL = 4, - NHGREATER = 5, - NHGREATEREQUAL = 6 -} NH_COMPOPERATOR; - diff --git a/examples/blueprints-example/external/async.h b/examples/blueprints-example/external/async.h deleted file mode 100644 index 92fcd9a..0000000 --- a/examples/blueprints-example/external/async.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// -// Async logging using global thread pool -// All loggers created here share same global thread pool. -// Each log message is pushed to a queue along with a shared pointer to the -// logger. -// If a logger deleted while having pending messages in the queue, it's actual -// destruction will defer -// until all its messages are processed by the thread pool. -// This is because each message in the queue holds a shared_ptr to the -// originating logger. - -#include -#include -#include - -#include -#include -#include - -namespace spdlog { - -namespace details { -static const size_t default_async_q_size = 8192; -} - -// async logger factory - creates async loggers backed with thread pool. -// if a global thread pool doesn't already exist, create it with default queue -// size of 8192 items and single thread. -template -struct async_factory_impl { - template - static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) { - auto ®istry_inst = details::registry::instance(); - - // create global thread pool if not already exists.. - - auto &mutex = registry_inst.tp_mutex(); - std::lock_guard tp_lock(mutex); - auto tp = registry_inst.get_tp(); - if (tp == nullptr) { - tp = std::make_shared(details::default_async_q_size, 1U); - registry_inst.set_tp(tp); - } - - auto sink = std::make_shared(std::forward(args)...); - auto new_logger = std::make_shared(std::move(logger_name), std::move(sink), - std::move(tp), OverflowPolicy); - registry_inst.initialize_logger(new_logger); - return new_logger; - } -}; - -using async_factory = async_factory_impl; -using async_factory_nonblock = async_factory_impl; - -template -inline std::shared_ptr create_async(std::string logger_name, - SinkArgs &&...sink_args) { - return async_factory::create(std::move(logger_name), - std::forward(sink_args)...); -} - -template -inline std::shared_ptr create_async_nb(std::string logger_name, - SinkArgs &&...sink_args) { - return async_factory_nonblock::create(std::move(logger_name), - std::forward(sink_args)...); -} - -// set global thread pool. -inline void init_thread_pool(size_t q_size, - size_t thread_count, - std::function on_thread_start, - std::function on_thread_stop) { - auto tp = std::make_shared(q_size, thread_count, on_thread_start, - on_thread_stop); - details::registry::instance().set_tp(std::move(tp)); -} - -inline void init_thread_pool(size_t q_size, - size_t thread_count, - std::function on_thread_start) { - init_thread_pool(q_size, thread_count, on_thread_start, [] {}); -} - -inline void init_thread_pool(size_t q_size, size_t thread_count) { - init_thread_pool(q_size, thread_count, [] {}, [] {}); -} - -// get the global thread pool. -inline std::shared_ptr thread_pool() { - return details::registry::instance().get_tp(); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/async_logger-inl.h b/examples/blueprints-example/external/async_logger-inl.h deleted file mode 100644 index a681d97..0000000 --- a/examples/blueprints-example/external/async_logger-inl.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include - -SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name, - sinks_init_list sinks_list, - std::weak_ptr tp, - async_overflow_policy overflow_policy) - : async_logger(std::move(logger_name), - sinks_list.begin(), - sinks_list.end(), - std::move(tp), - overflow_policy) {} - -SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name, - sink_ptr single_sink, - std::weak_ptr tp, - async_overflow_policy overflow_policy) - : async_logger( - std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) {} - -// send the log message to the thread pool -SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg){ - SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){ - pool_ptr -> post_log(shared_from_this(), msg, overflow_policy_); -} -else { - throw_spdlog_ex("async log: thread pool doesn't exist anymore"); -} -} -SPDLOG_LOGGER_CATCH(msg.source) -} - -// send flush request to the thread pool -SPDLOG_INLINE void spdlog::async_logger::flush_(){ - SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){ - pool_ptr -> post_flush(shared_from_this(), overflow_policy_); -} -else { - throw_spdlog_ex("async flush: thread pool doesn't exist anymore"); -} -} -SPDLOG_LOGGER_CATCH(source_loc()) -} - -// -// backend functions - called from the thread pool to do the actual job -// -SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) { - for (auto &sink : sinks_) { - if (sink->should_log(msg.level)) { - SPDLOG_TRY { sink->log(msg); } - SPDLOG_LOGGER_CATCH(msg.source) - } - } - - if (should_flush_(msg)) { - backend_flush_(); - } -} - -SPDLOG_INLINE void spdlog::async_logger::backend_flush_() { - for (auto &sink : sinks_) { - SPDLOG_TRY { sink->flush(); } - SPDLOG_LOGGER_CATCH(source_loc()) - } -} - -SPDLOG_INLINE std::shared_ptr spdlog::async_logger::clone(std::string new_name) { - auto cloned = std::make_shared(*this); - cloned->name_ = std::move(new_name); - return cloned; -} diff --git a/examples/blueprints-example/external/async_logger.h b/examples/blueprints-example/external/async_logger.h deleted file mode 100644 index 846c4c6..0000000 --- a/examples/blueprints-example/external/async_logger.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Fast asynchronous logger. -// Uses pre allocated queue. -// Creates a single back thread to pop messages from the queue and log them. -// -// Upon each log write the logger: -// 1. Checks if its log level is enough to log the message -// 2. Push a new copy of the message to a queue (or block the caller until -// space is available in the queue) -// Upon destruction, logs all remaining messages in the queue before -// destructing.. - -#include - -namespace spdlog { - -// Async overflow policy - block by default. -enum class async_overflow_policy { - block, // Block until message can be enqueued - overrun_oldest, // Discard oldest message in the queue if full when trying to - // add new item. - discard_new // Discard new message if the queue is full when trying to add new item. -}; - -namespace details { -class thread_pool; -} - -class SPDLOG_API async_logger final : public std::enable_shared_from_this, - public logger { - friend class details::thread_pool; - -public: - template - async_logger(std::string logger_name, - It begin, - It end, - std::weak_ptr tp, - async_overflow_policy overflow_policy = async_overflow_policy::block) - : logger(std::move(logger_name), begin, end), - thread_pool_(std::move(tp)), - overflow_policy_(overflow_policy) {} - - async_logger(std::string logger_name, - sinks_init_list sinks_list, - std::weak_ptr tp, - async_overflow_policy overflow_policy = async_overflow_policy::block); - - async_logger(std::string logger_name, - sink_ptr single_sink, - std::weak_ptr tp, - async_overflow_policy overflow_policy = async_overflow_policy::block); - - std::shared_ptr clone(std::string new_name) override; - -protected: - void sink_it_(const details::log_msg &msg) override; - void flush_() override; - void backend_sink_it_(const details::log_msg &incoming_log_msg); - void backend_flush_(); - -private: - std::weak_ptr thread_pool_; - async_overflow_policy overflow_policy_; -}; -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "async_logger-inl.h" -#endif diff --git a/examples/blueprints-example/external/cfg/argv.h b/examples/blueprints-example/external/cfg/argv.h deleted file mode 100644 index 7de2f83..0000000 --- a/examples/blueprints-example/external/cfg/argv.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once -#include -#include - -// -// Init log levels using each argv entry that starts with "SPDLOG_LEVEL=" -// -// set all loggers to debug level: -// example.exe "SPDLOG_LEVEL=debug" - -// set logger1 to trace level -// example.exe "SPDLOG_LEVEL=logger1=trace" - -// turn off all logging except for logger1 and logger2: -// example.exe "SPDLOG_LEVEL=off,logger1=debug,logger2=info" - -namespace spdlog { -namespace cfg { - -// search for SPDLOG_LEVEL= in the args and use it to init the levels -inline void load_argv_levels(int argc, const char **argv) { - const std::string spdlog_level_prefix = "SPDLOG_LEVEL="; - for (int i = 1; i < argc; i++) { - std::string arg = argv[i]; - if (arg.find(spdlog_level_prefix) == 0) { - auto levels_string = arg.substr(spdlog_level_prefix.size()); - helpers::load_levels(levels_string); - } - } -} - -inline void load_argv_levels(int argc, char **argv) { - load_argv_levels(argc, const_cast(argv)); -} - -} // namespace cfg -} // namespace spdlog diff --git a/examples/blueprints-example/external/cfg/env.h b/examples/blueprints-example/external/cfg/env.h deleted file mode 100644 index 47bf61c..0000000 --- a/examples/blueprints-example/external/cfg/env.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once -#include -#include -#include - -// -// Init levels and patterns from env variables SPDLOG_LEVEL -// Inspired from Rust's "env_logger" crate (https://crates.io/crates/env_logger). -// Note - fallback to "info" level on unrecognized levels -// -// Examples: -// -// set global level to debug: -// export SPDLOG_LEVEL=debug -// -// turn off all logging except for logger1: -// export SPDLOG_LEVEL="*=off,logger1=debug" -// - -// turn off all logging except for logger1 and logger2: -// export SPDLOG_LEVEL="off,logger1=debug,logger2=info" - -namespace spdlog { -namespace cfg { -inline void load_env_levels(const char* var = "SPDLOG_LEVEL") { - auto env_val = details::os::getenv(var); - if (!env_val.empty()) { - helpers::load_levels(env_val); - } -} - -} // namespace cfg -} // namespace spdlog diff --git a/examples/blueprints-example/external/cfg/helpers-inl.h b/examples/blueprints-example/external/cfg/helpers-inl.h deleted file mode 100644 index 61b9b9f..0000000 --- a/examples/blueprints-example/external/cfg/helpers-inl.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include -#include -#include - -namespace spdlog { -namespace cfg { -namespace helpers { - -// inplace convert to lowercase -inline std::string &to_lower_(std::string &str) { - std::transform(str.begin(), str.end(), str.begin(), [](char ch) { - return static_cast((ch >= 'A' && ch <= 'Z') ? ch + ('a' - 'A') : ch); - }); - return str; -} - -// inplace trim spaces -inline std::string &trim_(std::string &str) { - const char *spaces = " \n\r\t"; - str.erase(str.find_last_not_of(spaces) + 1); - str.erase(0, str.find_first_not_of(spaces)); - return str; -} - -// return (name,value) trimmed pair from the given "name = value" string. -// return empty string on missing parts -// "key=val" => ("key", "val") -// " key = val " => ("key", "val") -// "key=" => ("key", "") -// "val" => ("", "val") - -inline std::pair extract_kv_(char sep, const std::string &str) { - auto n = str.find(sep); - std::string k, v; - if (n == std::string::npos) { - v = str; - } else { - k = str.substr(0, n); - v = str.substr(n + 1); - } - return std::make_pair(trim_(k), trim_(v)); -} - -// return vector of key/value pairs from a sequence of "K1=V1,K2=V2,.." -// "a=AAA,b=BBB,c=CCC,.." => {("a","AAA"),("b","BBB"),("c", "CCC"),...} -inline std::unordered_map extract_key_vals_(const std::string &str) { - std::string token; - std::istringstream token_stream(str); - std::unordered_map rv{}; - while (std::getline(token_stream, token, ',')) { - if (token.empty()) { - continue; - } - auto kv = extract_kv_('=', token); - rv[kv.first] = kv.second; - } - return rv; -} - -SPDLOG_INLINE void load_levels(const std::string &input) { - if (input.empty() || input.size() >= 32768) { - return; - } - - auto key_vals = extract_key_vals_(input); - std::unordered_map levels; - level::level_enum global_level = level::info; - bool global_level_found = false; - - for (auto &name_level : key_vals) { - const auto &logger_name = name_level.first; - const auto &level_name = to_lower_(name_level.second); - auto level = level::from_str(level_name); - // ignore unrecognized level names - if (level == level::off && level_name != "off") { - continue; - } - if (logger_name.empty()) // no logger name indicates global level - { - global_level_found = true; - global_level = level; - } else { - levels[logger_name] = level; - } - } - - details::registry::instance().set_levels(std::move(levels), - global_level_found ? &global_level : nullptr); -} - -} // namespace helpers -} // namespace cfg -} // namespace spdlog diff --git a/examples/blueprints-example/external/cfg/helpers.h b/examples/blueprints-example/external/cfg/helpers.h deleted file mode 100644 index c023818..0000000 --- a/examples/blueprints-example/external/cfg/helpers.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { -namespace cfg { -namespace helpers { -// -// Init levels from given string -// -// Examples: -// -// set global level to debug: "debug" -// turn off all logging except for logger1: "off,logger1=debug" -// turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info" -// -SPDLOG_API void load_levels(const std::string &txt); -} // namespace helpers - -} // namespace cfg -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "helpers-inl.h" -#endif // SPDLOG_HEADER_ONLY diff --git a/examples/blueprints-example/external/common-inl.h b/examples/blueprints-example/external/common-inl.h deleted file mode 100644 index a8a0453..0000000 --- a/examples/blueprints-example/external/common-inl.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { -namespace level { - -#if __cplusplus >= 201703L -constexpr -#endif - static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; - -static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; - -SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { - return level_string_views[l]; -} - -SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { - return short_level_names[l]; -} - -SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT { - auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); - if (it != std::end(level_string_views)) - return static_cast(std::distance(std::begin(level_string_views), it)); - - // check also for "warn" and "err" before giving up.. - if (name == "warn") { - return level::warn; - } - if (name == "err") { - return level::err; - } - return level::off; -} -} // namespace level - -SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) - : msg_(std::move(msg)) {} - -SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) { -#ifdef SPDLOG_USE_STD_FORMAT - msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what(); -#else - memory_buf_t outbuf; - fmt::format_system_error(outbuf, last_errno, msg.c_str()); - msg_ = fmt::to_string(outbuf); -#endif -} - -SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT { return msg_.c_str(); } - -SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno) { - SPDLOG_THROW(spdlog_ex(msg, last_errno)); -} - -SPDLOG_INLINE void throw_spdlog_ex(std::string msg) { SPDLOG_THROW(spdlog_ex(std::move(msg))); } - -} // namespace spdlog diff --git a/examples/blueprints-example/external/common.h b/examples/blueprints-example/external/common.h deleted file mode 100644 index ba9a2e7..0000000 --- a/examples/blueprints-example/external/common.h +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef SPDLOG_USE_STD_FORMAT - #include - #if __cpp_lib_format >= 202207L - #include - #else - #include - #endif -#endif - -#ifdef SPDLOG_COMPILED_LIB - #undef SPDLOG_HEADER_ONLY - #if defined(SPDLOG_SHARED_LIB) - #if defined(_WIN32) - #ifdef spdlog_EXPORTS - #define SPDLOG_API __declspec(dllexport) - #else // !spdlog_EXPORTS - #define SPDLOG_API __declspec(dllimport) - #endif - #else // !defined(_WIN32) - #define SPDLOG_API __attribute__((visibility("default"))) - #endif - #else // !defined(SPDLOG_SHARED_LIB) - #define SPDLOG_API - #endif - #define SPDLOG_INLINE -#else // !defined(SPDLOG_COMPILED_LIB) - #define SPDLOG_API - #define SPDLOG_HEADER_ONLY - #define SPDLOG_INLINE inline -#endif // #ifdef SPDLOG_COMPILED_LIB - -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) && \ - FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8 - #define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string) - #define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) - #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) - #include - #endif -#else - #define SPDLOG_FMT_RUNTIME(format_string) format_string - #define SPDLOG_FMT_STRING(format_string) format_string -#endif - -// visual studio up to 2013 does not support noexcept nor constexpr -#if defined(_MSC_VER) && (_MSC_VER < 1900) - #define SPDLOG_NOEXCEPT _NOEXCEPT - #define SPDLOG_CONSTEXPR -#else - #define SPDLOG_NOEXCEPT noexcept - #define SPDLOG_CONSTEXPR constexpr -#endif - -// If building with std::format, can just use constexpr, otherwise if building with fmt -// SPDLOG_CONSTEXPR_FUNC needs to be set the same as FMT_CONSTEXPR to avoid situations where -// a constexpr function in spdlog could end up calling a non-constexpr function in fmt -// depending on the compiler -// If fmt determines it can't use constexpr, we should inline the function instead -#ifdef SPDLOG_USE_STD_FORMAT - #define SPDLOG_CONSTEXPR_FUNC constexpr -#else // Being built with fmt - #if FMT_USE_CONSTEXPR - #define SPDLOG_CONSTEXPR_FUNC FMT_CONSTEXPR - #else - #define SPDLOG_CONSTEXPR_FUNC inline - #endif -#endif - -#if defined(__GNUC__) || defined(__clang__) - #define SPDLOG_DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) - #define SPDLOG_DEPRECATED __declspec(deprecated) -#else - #define SPDLOG_DEPRECATED -#endif - -// disable thread local on msvc 2013 -#ifndef SPDLOG_NO_TLS - #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt) - #define SPDLOG_NO_TLS 1 - #endif -#endif - -#ifndef SPDLOG_FUNCTION - #define SPDLOG_FUNCTION static_cast(__FUNCTION__) -#endif - -#ifdef SPDLOG_NO_EXCEPTIONS - #define SPDLOG_TRY - #define SPDLOG_THROW(ex) \ - do { \ - printf("spdlog fatal error: %s\n", ex.what()); \ - std::abort(); \ - } while (0) - #define SPDLOG_CATCH_STD -#else - #define SPDLOG_TRY try - #define SPDLOG_THROW(ex) throw(ex) - #define SPDLOG_CATCH_STD \ - catch (const std::exception &) { \ - } -#endif - -namespace spdlog { - -class formatter; - -namespace sinks { -class sink; -} - -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) -using filename_t = std::wstring; - // allow macro expansion to occur in SPDLOG_FILENAME_T - #define SPDLOG_FILENAME_T_INNER(s) L##s - #define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s) -#else -using filename_t = std::string; - #define SPDLOG_FILENAME_T(s) s -#endif - -using log_clock = std::chrono::system_clock; -using sink_ptr = std::shared_ptr; -using sinks_init_list = std::initializer_list; -using err_handler = std::function; -#ifdef SPDLOG_USE_STD_FORMAT -namespace fmt_lib = std; - -using string_view_t = std::string_view; -using memory_buf_t = std::string; - -template - #if __cpp_lib_format >= 202207L -using format_string_t = std::format_string; - #else -using format_string_t = std::string_view; - #endif - -template -struct is_convertible_to_basic_format_string - : std::integral_constant>::value> {}; - - #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -using wstring_view_t = std::wstring_view; -using wmemory_buf_t = std::wstring; - -template - #if __cpp_lib_format >= 202207L -using wformat_string_t = std::wformat_string; - #else -using wformat_string_t = std::wstring_view; - #endif - #endif - #define SPDLOG_BUF_TO_STRING(x) x -#else // use fmt lib instead of std::format -namespace fmt_lib = fmt; - -using string_view_t = fmt::basic_string_view; -using memory_buf_t = fmt::basic_memory_buffer; - -template -using format_string_t = fmt::format_string; - -template -using remove_cvref_t = typename std::remove_cv::type>::type; - -template - #if FMT_VERSION >= 90101 -using fmt_runtime_string = fmt::runtime_format_string; - #else -using fmt_runtime_string = fmt::basic_runtime; - #endif - -// clang doesn't like SFINAE disabled constructor in std::is_convertible<> so have to repeat the -// condition from basic_format_string here, in addition, fmt::basic_runtime is only -// convertible to basic_format_string but not basic_string_view -template -struct is_convertible_to_basic_format_string - : std::integral_constant>::value || - std::is_same, fmt_runtime_string>::value> { -}; - - #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -using wstring_view_t = fmt::basic_string_view; -using wmemory_buf_t = fmt::basic_memory_buffer; - -template -using wformat_string_t = fmt::wformat_string; - #endif - #define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) -#endif - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - #ifndef _WIN32 - #error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows - #endif // _WIN32 -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT - -template -struct is_convertible_to_any_format_string - : std::integral_constant::value || - is_convertible_to_basic_format_string::value> {}; - -#if defined(SPDLOG_NO_ATOMIC_LEVELS) -using level_t = details::null_atomic_int; -#else -using level_t = std::atomic; -#endif - -#define SPDLOG_LEVEL_TRACE 0 -#define SPDLOG_LEVEL_DEBUG 1 -#define SPDLOG_LEVEL_INFO 2 -#define SPDLOG_LEVEL_WARN 3 -#define SPDLOG_LEVEL_ERROR 4 -#define SPDLOG_LEVEL_CRITICAL 5 -#define SPDLOG_LEVEL_OFF 6 - -#if !defined(SPDLOG_ACTIVE_LEVEL) - #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO -#endif - -// Log level enum -namespace level { -enum level_enum : int { - trace = SPDLOG_LEVEL_TRACE, - debug = SPDLOG_LEVEL_DEBUG, - info = SPDLOG_LEVEL_INFO, - warn = SPDLOG_LEVEL_WARN, - err = SPDLOG_LEVEL_ERROR, - critical = SPDLOG_LEVEL_CRITICAL, - off = SPDLOG_LEVEL_OFF, - n_levels -}; - -#define SPDLOG_LEVEL_NAME_TRACE spdlog::string_view_t("trace", 5) -#define SPDLOG_LEVEL_NAME_DEBUG spdlog::string_view_t("debug", 5) -#define SPDLOG_LEVEL_NAME_INFO spdlog::string_view_t("info", 4) -#define SPDLOG_LEVEL_NAME_WARNING spdlog::string_view_t("warning", 7) -#define SPDLOG_LEVEL_NAME_ERROR spdlog::string_view_t("error", 5) -#define SPDLOG_LEVEL_NAME_CRITICAL spdlog::string_view_t("critical", 8) -#define SPDLOG_LEVEL_NAME_OFF spdlog::string_view_t("off", 3) - -#if !defined(SPDLOG_LEVEL_NAMES) - #define SPDLOG_LEVEL_NAMES \ - { \ - SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO, \ - SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, SPDLOG_LEVEL_NAME_CRITICAL, \ - SPDLOG_LEVEL_NAME_OFF \ - } -#endif - -#if !defined(SPDLOG_SHORT_LEVEL_NAMES) - - #define SPDLOG_SHORT_LEVEL_NAMES \ - { "T", "D", "I", "W", "E", "C", "O" } -#endif - -SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; -SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; -SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT; - -} // namespace level - -// -// Color mode used by sinks with color support. -// -enum class color_mode { always, automatic, never }; - -// -// Pattern time - specific time getting to use for pattern_formatter. -// local time by default -// -enum class pattern_time_type { - local, // log localtime - utc // log utc -}; - -// -// Log exception -// -class SPDLOG_API spdlog_ex : public std::exception { -public: - explicit spdlog_ex(std::string msg); - spdlog_ex(const std::string &msg, int last_errno); - const char *what() const SPDLOG_NOEXCEPT override; - -private: - std::string msg_; -}; - -[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno); -[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg); - -struct source_loc { - SPDLOG_CONSTEXPR source_loc() = default; - SPDLOG_CONSTEXPR source_loc(const char *filename_in, int line_in, const char *funcname_in) - : filename{filename_in}, - line{line_in}, - funcname{funcname_in} {} - - SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT { return line <= 0; } - const char *filename{nullptr}; - int line{0}; - const char *funcname{nullptr}; -}; - -struct file_event_handlers { - file_event_handlers() - : before_open(nullptr), - after_open(nullptr), - before_close(nullptr), - after_close(nullptr) {} - - std::function before_open; - std::function after_open; - std::function before_close; - std::function after_close; -}; - -namespace details { - -// to_string_view - -SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view(const memory_buf_t &buf) - SPDLOG_NOEXCEPT { - return spdlog::string_view_t{buf.data(), buf.size()}; -} - -SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view(spdlog::string_view_t str) - SPDLOG_NOEXCEPT { - return str; -} - -#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view(const wmemory_buf_t &buf) - SPDLOG_NOEXCEPT { - return spdlog::wstring_view_t{buf.data(), buf.size()}; -} - -SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) - SPDLOG_NOEXCEPT { - return str; -} -#endif - -#if defined(SPDLOG_USE_STD_FORMAT) && __cpp_lib_format >= 202207L -template -SPDLOG_CONSTEXPR_FUNC std::basic_string_view to_string_view( - std::basic_format_string fmt) SPDLOG_NOEXCEPT { - return fmt.get(); -} -#endif - -// make_unique support for pre c++14 -#if __cplusplus >= 201402L // C++14 and beyond -using std::enable_if_t; -using std::make_unique; -#else -template -using enable_if_t = typename std::enable_if::type; - -template -std::unique_ptr make_unique(Args &&...args) { - static_assert(!std::is_array::value, "arrays not supported"); - return std::unique_ptr(new T(std::forward(args)...)); -} -#endif - -// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) -template ::value, int> = 0> -constexpr T conditional_static_cast(U value) { - return static_cast(value); -} - -template ::value, int> = 0> -constexpr T conditional_static_cast(U value) { - return value; -} - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "common-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/backtracer-inl.h b/examples/blueprints-example/external/details/backtracer-inl.h deleted file mode 100644 index 43d1002..0000000 --- a/examples/blueprints-example/external/details/backtracer-inl.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif -namespace spdlog { -namespace details { -SPDLOG_INLINE backtracer::backtracer(const backtracer &other) { - std::lock_guard lock(other.mutex_); - enabled_ = other.enabled(); - messages_ = other.messages_; -} - -SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT { - std::lock_guard lock(other.mutex_); - enabled_ = other.enabled(); - messages_ = std::move(other.messages_); -} - -SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) { - std::lock_guard lock(mutex_); - enabled_ = other.enabled(); - messages_ = std::move(other.messages_); - return *this; -} - -SPDLOG_INLINE void backtracer::enable(size_t size) { - std::lock_guard lock{mutex_}; - enabled_.store(true, std::memory_order_relaxed); - messages_ = circular_q{size}; -} - -SPDLOG_INLINE void backtracer::disable() { - std::lock_guard lock{mutex_}; - enabled_.store(false, std::memory_order_relaxed); -} - -SPDLOG_INLINE bool backtracer::enabled() const { return enabled_.load(std::memory_order_relaxed); } - -SPDLOG_INLINE void backtracer::push_back(const log_msg &msg) { - std::lock_guard lock{mutex_}; - messages_.push_back(log_msg_buffer{msg}); -} - -SPDLOG_INLINE bool backtracer::empty() const { - std::lock_guard lock{mutex_}; - return messages_.empty(); -} - -// pop all items in the q and apply the given fun on each of them. -SPDLOG_INLINE void backtracer::foreach_pop(std::function fun) { - std::lock_guard lock{mutex_}; - while (!messages_.empty()) { - auto &front_msg = messages_.front(); - fun(front_msg); - messages_.pop_front(); - } -} -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/backtracer.h b/examples/blueprints-example/external/details/backtracer.h deleted file mode 100644 index 541339c..0000000 --- a/examples/blueprints-example/external/details/backtracer.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -#include -#include -#include - -// Store log messages in circular buffer. -// Useful for storing debug data in case of error/warning happens. - -namespace spdlog { -namespace details { -class SPDLOG_API backtracer { - mutable std::mutex mutex_; - std::atomic enabled_{false}; - circular_q messages_; - -public: - backtracer() = default; - backtracer(const backtracer &other); - - backtracer(backtracer &&other) SPDLOG_NOEXCEPT; - backtracer &operator=(backtracer other); - - void enable(size_t size); - void disable(); - bool enabled() const; - void push_back(const log_msg &msg); - bool empty() const; - - // pop all items in the q and apply the given fun on each of them. - void foreach_pop(std::function fun); -}; - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "backtracer-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/circular_q.h b/examples/blueprints-example/external/details/circular_q.h deleted file mode 100644 index 29e9d25..0000000 --- a/examples/blueprints-example/external/details/circular_q.h +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// circular q view of std::vector. -#pragma once - -#include -#include - -#include "spdlog/common.h" - -namespace spdlog { -namespace details { -template -class circular_q { - size_t max_items_ = 0; - typename std::vector::size_type head_ = 0; - typename std::vector::size_type tail_ = 0; - size_t overrun_counter_ = 0; - std::vector v_; - -public: - using value_type = T; - - // empty ctor - create a disabled queue with no elements allocated at all - circular_q() = default; - - explicit circular_q(size_t max_items) - : max_items_(max_items + 1) // one item is reserved as marker for full q - , - v_(max_items_) {} - - circular_q(const circular_q &) = default; - circular_q &operator=(const circular_q &) = default; - - // move cannot be default, - // since we need to reset head_, tail_, etc to zero in the moved object - circular_q(circular_q &&other) SPDLOG_NOEXCEPT { copy_moveable(std::move(other)); } - - circular_q &operator=(circular_q &&other) SPDLOG_NOEXCEPT { - copy_moveable(std::move(other)); - return *this; - } - - // push back, overrun (oldest) item if no room left - void push_back(T &&item) { - if (max_items_ > 0) { - v_[tail_] = std::move(item); - tail_ = (tail_ + 1) % max_items_; - - if (tail_ == head_) // overrun last item if full - { - head_ = (head_ + 1) % max_items_; - ++overrun_counter_; - } - } - } - - // Return reference to the front item. - // If there are no elements in the container, the behavior is undefined. - const T &front() const { return v_[head_]; } - - T &front() { return v_[head_]; } - - // Return number of elements actually stored - size_t size() const { - if (tail_ >= head_) { - return tail_ - head_; - } else { - return max_items_ - (head_ - tail_); - } - } - - // Return const reference to item by index. - // If index is out of range 0…size()-1, the behavior is undefined. - const T &at(size_t i) const { - assert(i < size()); - return v_[(head_ + i) % max_items_]; - } - - // Pop item from front. - // If there are no elements in the container, the behavior is undefined. - void pop_front() { head_ = (head_ + 1) % max_items_; } - - bool empty() const { return tail_ == head_; } - - bool full() const { - // head is ahead of the tail by 1 - if (max_items_ > 0) { - return ((tail_ + 1) % max_items_) == head_; - } - return false; - } - - size_t overrun_counter() const { return overrun_counter_; } - - void reset_overrun_counter() { overrun_counter_ = 0; } - -private: - // copy from other&& and reset it to disabled state - void copy_moveable(circular_q &&other) SPDLOG_NOEXCEPT { - max_items_ = other.max_items_; - head_ = other.head_; - tail_ = other.tail_; - overrun_counter_ = other.overrun_counter_; - v_ = std::move(other.v_); - - // put &&other in disabled, but valid state - other.max_items_ = 0; - other.head_ = other.tail_ = 0; - other.overrun_counter_ = 0; - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/console_globals.h b/examples/blueprints-example/external/details/console_globals.h deleted file mode 100644 index 9c55210..0000000 --- a/examples/blueprints-example/external/details/console_globals.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { -namespace details { - -struct console_mutex { - using mutex_t = std::mutex; - static mutex_t &mutex() { - static mutex_t s_mutex; - return s_mutex; - } -}; - -struct console_nullmutex { - using mutex_t = null_mutex; - static mutex_t &mutex() { - static mutex_t s_mutex; - return s_mutex; - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/file_helper-inl.h b/examples/blueprints-example/external/details/file_helper-inl.h deleted file mode 100644 index 0c514ef..0000000 --- a/examples/blueprints-example/external/details/file_helper-inl.h +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include -#include -#include - -namespace spdlog { -namespace details { - -SPDLOG_INLINE file_helper::file_helper(const file_event_handlers &event_handlers) - : event_handlers_(event_handlers) {} - -SPDLOG_INLINE file_helper::~file_helper() { close(); } - -SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate) { - close(); - filename_ = fname; - - auto *mode = SPDLOG_FILENAME_T("ab"); - auto *trunc_mode = SPDLOG_FILENAME_T("wb"); - - if (event_handlers_.before_open) { - event_handlers_.before_open(filename_); - } - for (int tries = 0; tries < open_tries_; ++tries) { - // create containing folder if not exists already. - os::create_dir(os::dir_name(fname)); - if (truncate) { - // Truncate by opening-and-closing a tmp file in "wb" mode, always - // opening the actual log-we-write-to in "ab" mode, since that - // interacts more politely with eternal processes that might - // rotate/truncate the file underneath us. - std::FILE *tmp; - if (os::fopen_s(&tmp, fname, trunc_mode)) { - continue; - } - std::fclose(tmp); - } - if (!os::fopen_s(&fd_, fname, mode)) { - if (event_handlers_.after_open) { - event_handlers_.after_open(filename_, fd_); - } - return; - } - - details::os::sleep_for_millis(open_interval_); - } - - throw_spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing", - errno); -} - -SPDLOG_INLINE void file_helper::reopen(bool truncate) { - if (filename_.empty()) { - throw_spdlog_ex("Failed re opening file - was not opened before"); - } - this->open(filename_, truncate); -} - -SPDLOG_INLINE void file_helper::flush() { - if (std::fflush(fd_) != 0) { - throw_spdlog_ex("Failed flush to file " + os::filename_to_str(filename_), errno); - } -} - -SPDLOG_INLINE void file_helper::sync() { - if (!os::fsync(fd_)) { - throw_spdlog_ex("Failed to fsync file " + os::filename_to_str(filename_), errno); - } -} - -SPDLOG_INLINE void file_helper::close() { - if (fd_ != nullptr) { - if (event_handlers_.before_close) { - event_handlers_.before_close(filename_, fd_); - } - - std::fclose(fd_); - fd_ = nullptr; - - if (event_handlers_.after_close) { - event_handlers_.after_close(filename_); - } - } -} - -SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf) { - if (fd_ == nullptr) return; - size_t msg_size = buf.size(); - auto data = buf.data(); - - if (!details::os::fwrite_bytes(data, msg_size, fd_)) { - throw_spdlog_ex("Failed writing to file " + os::filename_to_str(filename_), errno); - } -} - -SPDLOG_INLINE size_t file_helper::size() const { - if (fd_ == nullptr) { - throw_spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(filename_)); - } - return os::filesize(fd_); -} - -SPDLOG_INLINE const filename_t &file_helper::filename() const { return filename_; } - -// -// return file path and its extension: -// -// "mylog.txt" => ("mylog", ".txt") -// "mylog" => ("mylog", "") -// "mylog." => ("mylog.", "") -// "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") -// -// the starting dot in filenames is ignored (hidden files): -// -// ".mylog" => (".mylog". "") -// "my_folder/.mylog" => ("my_folder/.mylog", "") -// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") -SPDLOG_INLINE std::tuple file_helper::split_by_extension( - const filename_t &fname) { - auto ext_index = fname.rfind('.'); - - // no valid extension found - return whole path and empty string as - // extension - if (ext_index == filename_t::npos || ext_index == 0 || ext_index == fname.size() - 1) { - return std::make_tuple(fname, filename_t()); - } - - // treat cases like "/etc/rc.d/somelogfile or "/abc/.hiddenfile" - auto folder_index = fname.find_last_of(details::os::folder_seps_filename); - if (folder_index != filename_t::npos && folder_index >= ext_index - 1) { - return std::make_tuple(fname, filename_t()); - } - - // finally - return a valid base and extension tuple - return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index)); -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/file_helper.h b/examples/blueprints-example/external/details/file_helper.h deleted file mode 100644 index f0e5d18..0000000 --- a/examples/blueprints-example/external/details/file_helper.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { -namespace details { - -// Helper class for file sinks. -// When failing to open a file, retry several times(5) with a delay interval(10 ms). -// Throw spdlog_ex exception on errors. - -class SPDLOG_API file_helper { -public: - file_helper() = default; - explicit file_helper(const file_event_handlers &event_handlers); - - file_helper(const file_helper &) = delete; - file_helper &operator=(const file_helper &) = delete; - ~file_helper(); - - void open(const filename_t &fname, bool truncate = false); - void reopen(bool truncate); - void flush(); - void sync(); - void close(); - void write(const memory_buf_t &buf); - size_t size() const; - const filename_t &filename() const; - - // - // return file path and its extension: - // - // "mylog.txt" => ("mylog", ".txt") - // "mylog" => ("mylog", "") - // "mylog." => ("mylog.", "") - // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") - // - // the starting dot in filenames is ignored (hidden files): - // - // ".mylog" => (".mylog". "") - // "my_folder/.mylog" => ("my_folder/.mylog", "") - // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") - static std::tuple split_by_extension(const filename_t &fname); - -private: - const int open_tries_ = 5; - const unsigned int open_interval_ = 10; - std::FILE *fd_{nullptr}; - filename_t filename_; - file_event_handlers event_handlers_; -}; -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "file_helper-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/fmt_helper.h b/examples/blueprints-example/external/details/fmt_helper.h deleted file mode 100644 index 6130600..0000000 --- a/examples/blueprints-example/external/details/fmt_helper.h +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -#pragma once - -#include -#include -#include -#include -#include - -#ifdef SPDLOG_USE_STD_FORMAT - #include - #include -#endif - -// Some fmt helpers to efficiently format and pad ints and strings -namespace spdlog { -namespace details { -namespace fmt_helper { - -inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest) { - auto *buf_ptr = view.data(); - dest.append(buf_ptr, buf_ptr + view.size()); -} - -#ifdef SPDLOG_USE_STD_FORMAT -template -inline void append_int(T n, memory_buf_t &dest) { - // Buffer should be large enough to hold all digits (digits10 + 1) and a sign - SPDLOG_CONSTEXPR const auto BUF_SIZE = std::numeric_limits::digits10 + 2; - char buf[BUF_SIZE]; - - auto [ptr, ec] = std::to_chars(buf, buf + BUF_SIZE, n, 10); - if (ec == std::errc()) { - dest.append(buf, ptr); - } else { - throw_spdlog_ex("Failed to format int", static_cast(ec)); - } -} -#else -template -inline void append_int(T n, memory_buf_t &dest) { - fmt::format_int i(n); - dest.append(i.data(), i.data() + i.size()); -} -#endif - -template -SPDLOG_CONSTEXPR_FUNC unsigned int count_digits_fallback(T n) { - // taken from fmt: https://github.com/fmtlib/fmt/blob/8.0.1/include/fmt/format.h#L899-L912 - unsigned int count = 1; - for (;;) { - // Integer division is slow so do it for a group of four digits instead - // of for every digit. The idea comes from the talk by Alexandrescu - // "Three Optimization Tips for C++". See speed-test for a comparison. - if (n < 10) return count; - if (n < 100) return count + 1; - if (n < 1000) return count + 2; - if (n < 10000) return count + 3; - n /= 10000u; - count += 4; - } -} - -template -inline unsigned int count_digits(T n) { - using count_type = - typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type; -#ifdef SPDLOG_USE_STD_FORMAT - return count_digits_fallback(static_cast(n)); -#else - return static_cast(fmt:: - // fmt 7.0.0 renamed the internal namespace to detail. - // See: https://github.com/fmtlib/fmt/issues/1538 - #if FMT_VERSION < 70000 - internal - #else - detail - #endif - ::count_digits(static_cast(n))); -#endif -} - -inline void pad2(int n, memory_buf_t &dest) { - if (n >= 0 && n < 100) // 0-99 - { - dest.push_back(static_cast('0' + n / 10)); - dest.push_back(static_cast('0' + n % 10)); - } else // unlikely, but just in case, let fmt deal with it - { - fmt_lib::format_to(std::back_inserter(dest), SPDLOG_FMT_STRING("{:02}"), n); - } -} - -template -inline void pad_uint(T n, unsigned int width, memory_buf_t &dest) { - static_assert(std::is_unsigned::value, "pad_uint must get unsigned T"); - for (auto digits = count_digits(n); digits < width; digits++) { - dest.push_back('0'); - } - append_int(n, dest); -} - -template -inline void pad3(T n, memory_buf_t &dest) { - static_assert(std::is_unsigned::value, "pad3 must get unsigned T"); - if (n < 1000) { - dest.push_back(static_cast(n / 100 + '0')); - n = n % 100; - dest.push_back(static_cast((n / 10) + '0')); - dest.push_back(static_cast((n % 10) + '0')); - } else { - append_int(n, dest); - } -} - -template -inline void pad6(T n, memory_buf_t &dest) { - pad_uint(n, 6, dest); -} - -template -inline void pad9(T n, memory_buf_t &dest) { - pad_uint(n, 9, dest); -} - -// return fraction of a second of the given time_point. -// e.g. -// fraction(tp) -> will return the millis part of the second -template -inline ToDuration time_fraction(log_clock::time_point tp) { - using std::chrono::duration_cast; - using std::chrono::seconds; - auto duration = tp.time_since_epoch(); - auto secs = duration_cast(duration); - return duration_cast(duration) - duration_cast(secs); -} - -} // namespace fmt_helper -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/log_msg-inl.h b/examples/blueprints-example/external/details/log_msg-inl.h deleted file mode 100644 index aa3a957..0000000 --- a/examples/blueprints-example/external/details/log_msg-inl.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include - -namespace spdlog { -namespace details { - -SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, - spdlog::source_loc loc, - string_view_t a_logger_name, - spdlog::level::level_enum lvl, - spdlog::string_view_t msg) - : logger_name(a_logger_name), - level(lvl), - time(log_time) -#ifndef SPDLOG_NO_THREAD_ID - , - thread_id(os::thread_id()) -#endif - , - source(loc), - payload(msg) { -} - -SPDLOG_INLINE log_msg::log_msg(spdlog::source_loc loc, - string_view_t a_logger_name, - spdlog::level::level_enum lvl, - spdlog::string_view_t msg) - : log_msg(os::now(), loc, a_logger_name, lvl, msg) {} - -SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, - spdlog::level::level_enum lvl, - spdlog::string_view_t msg) - : log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg) {} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/log_msg.h b/examples/blueprints-example/external/details/log_msg.h deleted file mode 100644 index 87df1e8..0000000 --- a/examples/blueprints-example/external/details/log_msg.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { -namespace details { -struct SPDLOG_API log_msg { - log_msg() = default; - log_msg(log_clock::time_point log_time, - source_loc loc, - string_view_t logger_name, - level::level_enum lvl, - string_view_t msg); - log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); - log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); - log_msg(const log_msg &other) = default; - log_msg &operator=(const log_msg &other) = default; - - string_view_t logger_name; - level::level_enum level{level::off}; - log_clock::time_point time; - size_t thread_id{0}; - - // wrapping the formatted text with color (updated by pattern_formatter). - mutable size_t color_range_start{0}; - mutable size_t color_range_end{0}; - - source_loc source; - string_view_t payload; -}; -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "log_msg-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/log_msg_buffer-inl.h b/examples/blueprints-example/external/details/log_msg_buffer-inl.h deleted file mode 100644 index 2eb2428..0000000 --- a/examples/blueprints-example/external/details/log_msg_buffer-inl.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -namespace spdlog { -namespace details { - -SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg) - : log_msg{orig_msg} { - buffer.append(logger_name.begin(), logger_name.end()); - buffer.append(payload.begin(), payload.end()); - update_string_views(); -} - -SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other) - : log_msg{other} { - buffer.append(logger_name.begin(), logger_name.end()); - buffer.append(payload.begin(), payload.end()); - update_string_views(); -} - -SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT - : log_msg{other}, - buffer{std::move(other.buffer)} { - update_string_views(); -} - -SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other) { - log_msg::operator=(other); - buffer.clear(); - buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size()); - update_string_views(); - return *this; -} - -SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT { - log_msg::operator=(other); - buffer = std::move(other.buffer); - update_string_views(); - return *this; -} - -SPDLOG_INLINE void log_msg_buffer::update_string_views() { - logger_name = string_view_t{buffer.data(), logger_name.size()}; - payload = string_view_t{buffer.data() + logger_name.size(), payload.size()}; -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/log_msg_buffer.h b/examples/blueprints-example/external/details/log_msg_buffer.h deleted file mode 100644 index 1143b3b..0000000 --- a/examples/blueprints-example/external/details/log_msg_buffer.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include - -namespace spdlog { -namespace details { - -// Extend log_msg with internal buffer to store its payload. -// This is needed since log_msg holds string_views that points to stack data. - -class SPDLOG_API log_msg_buffer : public log_msg { - memory_buf_t buffer; - void update_string_views(); - -public: - log_msg_buffer() = default; - explicit log_msg_buffer(const log_msg &orig_msg); - log_msg_buffer(const log_msg_buffer &other); - log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT; - log_msg_buffer &operator=(const log_msg_buffer &other); - log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT; -}; - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "log_msg_buffer-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/mpmc_blocking_q.h b/examples/blueprints-example/external/details/mpmc_blocking_q.h deleted file mode 100644 index 5848cca..0000000 --- a/examples/blueprints-example/external/details/mpmc_blocking_q.h +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// multi producer-multi consumer blocking queue. -// enqueue(..) - will block until room found to put the new message. -// enqueue_nowait(..) - will return immediately with false if no room left in -// the queue. -// dequeue_for(..) - will block until the queue is not empty or timeout have -// passed. - -#include - -#include -#include -#include - -namespace spdlog { -namespace details { - -template -class mpmc_blocking_queue { -public: - using item_type = T; - explicit mpmc_blocking_queue(size_t max_items) - : q_(max_items) {} - -#ifndef __MINGW32__ - // try to enqueue and block if no room left - void enqueue(T &&item) { - { - std::unique_lock lock(queue_mutex_); - pop_cv_.wait(lock, [this] { return !this->q_.full(); }); - q_.push_back(std::move(item)); - } - push_cv_.notify_one(); - } - - // enqueue immediately. overrun oldest message in the queue if no room left. - void enqueue_nowait(T &&item) { - { - std::unique_lock lock(queue_mutex_); - q_.push_back(std::move(item)); - } - push_cv_.notify_one(); - } - - void enqueue_if_have_room(T &&item) { - bool pushed = false; - { - std::unique_lock lock(queue_mutex_); - if (!q_.full()) { - q_.push_back(std::move(item)); - pushed = true; - } - } - - if (pushed) { - push_cv_.notify_one(); - } else { - ++discard_counter_; - } - } - - // dequeue with a timeout. - // Return true, if succeeded dequeue item, false otherwise - bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration) { - { - std::unique_lock lock(queue_mutex_); - if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); })) { - return false; - } - popped_item = std::move(q_.front()); - q_.pop_front(); - } - pop_cv_.notify_one(); - return true; - } - - // blocking dequeue without a timeout. - void dequeue(T &popped_item) { - { - std::unique_lock lock(queue_mutex_); - push_cv_.wait(lock, [this] { return !this->q_.empty(); }); - popped_item = std::move(q_.front()); - q_.pop_front(); - } - pop_cv_.notify_one(); - } - -#else - // apparently mingw deadlocks if the mutex is released before cv.notify_one(), - // so release the mutex at the very end each function. - - // try to enqueue and block if no room left - void enqueue(T &&item) { - std::unique_lock lock(queue_mutex_); - pop_cv_.wait(lock, [this] { return !this->q_.full(); }); - q_.push_back(std::move(item)); - push_cv_.notify_one(); - } - - // enqueue immediately. overrun oldest message in the queue if no room left. - void enqueue_nowait(T &&item) { - std::unique_lock lock(queue_mutex_); - q_.push_back(std::move(item)); - push_cv_.notify_one(); - } - - void enqueue_if_have_room(T &&item) { - bool pushed = false; - std::unique_lock lock(queue_mutex_); - if (!q_.full()) { - q_.push_back(std::move(item)); - pushed = true; - } - - if (pushed) { - push_cv_.notify_one(); - } else { - ++discard_counter_; - } - } - - // dequeue with a timeout. - // Return true, if succeeded dequeue item, false otherwise - bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration) { - std::unique_lock lock(queue_mutex_); - if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); })) { - return false; - } - popped_item = std::move(q_.front()); - q_.pop_front(); - pop_cv_.notify_one(); - return true; - } - - // blocking dequeue without a timeout. - void dequeue(T &popped_item) { - std::unique_lock lock(queue_mutex_); - push_cv_.wait(lock, [this] { return !this->q_.empty(); }); - popped_item = std::move(q_.front()); - q_.pop_front(); - pop_cv_.notify_one(); - } - -#endif - - size_t overrun_counter() { - std::lock_guard lock(queue_mutex_); - return q_.overrun_counter(); - } - - size_t discard_counter() { return discard_counter_.load(std::memory_order_relaxed); } - - size_t size() { - std::lock_guard lock(queue_mutex_); - return q_.size(); - } - - void reset_overrun_counter() { - std::lock_guard lock(queue_mutex_); - q_.reset_overrun_counter(); - } - - void reset_discard_counter() { discard_counter_.store(0, std::memory_order_relaxed); } - -private: - std::mutex queue_mutex_; - std::condition_variable push_cv_; - std::condition_variable pop_cv_; - spdlog::details::circular_q q_; - std::atomic discard_counter_{0}; -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/null_mutex.h b/examples/blueprints-example/external/details/null_mutex.h deleted file mode 100644 index e3b3220..0000000 --- a/examples/blueprints-example/external/details/null_mutex.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -// null, no cost dummy "mutex" and dummy "atomic" int - -namespace spdlog { -namespace details { -struct null_mutex { - void lock() const {} - void unlock() const {} -}; - -struct null_atomic_int { - int value; - null_atomic_int() = default; - - explicit null_atomic_int(int new_value) - : value(new_value) {} - - int load(std::memory_order = std::memory_order_relaxed) const { return value; } - - void store(int new_value, std::memory_order = std::memory_order_relaxed) { value = new_value; } - - int exchange(int new_value, std::memory_order = std::memory_order_relaxed) { - std::swap(new_value, value); - return new_value; // return value before the call - } -}; - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/os-inl.h b/examples/blueprints-example/external/details/os-inl.h deleted file mode 100644 index 8a2e203..0000000 --- a/examples/blueprints-example/external/details/os-inl.h +++ /dev/null @@ -1,605 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 - #include - #include // for _get_osfhandle, _isatty, _fileno - #include // for _get_pid - - #ifdef __MINGW32__ - #include - #endif - - #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES) - #include - #include - #endif - - #include // for _mkdir/_wmkdir - -#else // unix - - #include - #include - - #ifdef __linux__ - #include //Use gettid() syscall under linux to get thread id - - #elif defined(_AIX) - #include // for pthread_getthrds_np - - #elif defined(__DragonFly__) || defined(__FreeBSD__) - #include // for pthread_getthreadid_np - - #elif defined(__NetBSD__) - #include // for _lwp_self - - #elif defined(__sun) - #include // for thr_self - #endif - -#endif // unix - -#if defined __APPLE__ - #include -#endif - -#ifndef __has_feature // Clang - feature checking macros. - #define __has_feature(x) 0 // Compatibility with non-clang compilers. -#endif - -namespace spdlog { -namespace details { -namespace os { - -SPDLOG_INLINE spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT { -#if defined __linux__ && defined SPDLOG_CLOCK_COARSE - timespec ts; - ::clock_gettime(CLOCK_REALTIME_COARSE, &ts); - return std::chrono::time_point( - std::chrono::duration_cast( - std::chrono::seconds(ts.tv_sec) + std::chrono::nanoseconds(ts.tv_nsec))); - -#else - return log_clock::now(); -#endif -} -SPDLOG_INLINE std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT { -#ifdef _WIN32 - std::tm tm; - ::localtime_s(&tm, &time_tt); -#else - std::tm tm; - ::localtime_r(&time_tt, &tm); -#endif - return tm; -} - -SPDLOG_INLINE std::tm localtime() SPDLOG_NOEXCEPT { - std::time_t now_t = ::time(nullptr); - return localtime(now_t); -} - -SPDLOG_INLINE std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT { -#ifdef _WIN32 - std::tm tm; - ::gmtime_s(&tm, &time_tt); -#else - std::tm tm; - ::gmtime_r(&time_tt, &tm); -#endif - return tm; -} - -SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT { - std::time_t now_t = ::time(nullptr); - return gmtime(now_t); -} - -// fopen_s on non windows for writing -SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) { -#ifdef _WIN32 - #ifdef SPDLOG_WCHAR_FILENAMES - *fp = ::_wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); - #else - *fp = ::_fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); - #endif - #if defined(SPDLOG_PREVENT_CHILD_FD) - if (*fp != nullptr) { - auto file_handle = reinterpret_cast(_get_osfhandle(::_fileno(*fp))); - if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0)) { - ::fclose(*fp); - *fp = nullptr; - } - } - #endif -#else // unix - #if defined(SPDLOG_PREVENT_CHILD_FD) - const int mode_flag = mode == SPDLOG_FILENAME_T("ab") ? O_APPEND : O_TRUNC; - const int fd = - ::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644)); - if (fd == -1) { - return true; - } - *fp = ::fdopen(fd, mode.c_str()); - if (*fp == nullptr) { - ::close(fd); - } - #else - *fp = ::fopen((filename.c_str()), mode.c_str()); - #endif -#endif - - return *fp == nullptr; -} - -SPDLOG_INLINE int remove(const filename_t &filename) SPDLOG_NOEXCEPT { -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) - return ::_wremove(filename.c_str()); -#else - return std::remove(filename.c_str()); -#endif -} - -SPDLOG_INLINE int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT { - return path_exists(filename) ? remove(filename) : 0; -} - -SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT { -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) - return ::_wrename(filename1.c_str(), filename2.c_str()); -#else - return std::rename(filename1.c_str(), filename2.c_str()); -#endif -} - -// Return true if path exists (file or directory) -SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT { -#ifdef _WIN32 - struct _stat buffer; - #ifdef SPDLOG_WCHAR_FILENAMES - return (::_wstat(filename.c_str(), &buffer) == 0); - #else - return (::_stat(filename.c_str(), &buffer) == 0); - #endif -#else // common linux/unix all have the stat system call - struct stat buffer; - return (::stat(filename.c_str(), &buffer) == 0); -#endif -} - -#ifdef _MSC_VER - // avoid warning about unreachable statement at the end of filesize() - #pragma warning(push) - #pragma warning(disable : 4702) -#endif - -// Return file size according to open FILE* object -SPDLOG_INLINE size_t filesize(FILE *f) { - if (f == nullptr) { - throw_spdlog_ex("Failed getting file size. fd is null"); - } -#if defined(_WIN32) && !defined(__CYGWIN__) - int fd = ::_fileno(f); - #if defined(_WIN64) // 64 bits - __int64 ret = ::_filelengthi64(fd); - if (ret >= 0) { - return static_cast(ret); - } - - #else // windows 32 bits - long ret = ::_filelength(fd); - if (ret >= 0) { - return static_cast(ret); - } - #endif - -#else // unix - // OpenBSD and AIX doesn't compile with :: before the fileno(..) - #if defined(__OpenBSD__) || defined(_AIX) - int fd = fileno(f); - #else - int fd = ::fileno(f); - #endif - // 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated) - #if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && \ - (defined(__LP64__) || defined(_LP64)) - struct stat64 st; - if (::fstat64(fd, &st) == 0) { - return static_cast(st.st_size); - } - #else // other unix or linux 32 bits or cygwin - struct stat st; - if (::fstat(fd, &st) == 0) { - return static_cast(st.st_size); - } - #endif -#endif - throw_spdlog_ex("Failed getting file size from fd", errno); - return 0; // will not be reached. -} - -#ifdef _MSC_VER - #pragma warning(pop) -#endif - -// Return utc offset in minutes or throw spdlog_ex on failure -SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) { -#ifdef _WIN32 - #if _WIN32_WINNT < _WIN32_WINNT_WS08 - TIME_ZONE_INFORMATION tzinfo; - auto rv = ::GetTimeZoneInformation(&tzinfo); - #else - DYNAMIC_TIME_ZONE_INFORMATION tzinfo; - auto rv = ::GetDynamicTimeZoneInformation(&tzinfo); - #endif - if (rv == TIME_ZONE_ID_INVALID) throw_spdlog_ex("Failed getting timezone info. ", errno); - - int offset = -tzinfo.Bias; - if (tm.tm_isdst) { - offset -= tzinfo.DaylightBias; - } else { - offset -= tzinfo.StandardBias; - } - return offset; -#else - - #if defined(sun) || defined(__sun) || defined(_AIX) || \ - (defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \ - (!defined(__APPLE__) && !defined(_BSD_SOURCE) && !defined(_GNU_SOURCE) && \ - (!defined(_POSIX_VERSION) || (_POSIX_VERSION < 202405L))) - // 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris - struct helper { - static long int calculate_gmt_offset(const std::tm &localtm = details::os::localtime(), - const std::tm &gmtm = details::os::gmtime()) { - int local_year = localtm.tm_year + (1900 - 1); - int gmt_year = gmtm.tm_year + (1900 - 1); - - long int days = ( - // difference in day of year - localtm.tm_yday - - gmtm.tm_yday - - // + intervening leap days - + ((local_year >> 2) - (gmt_year >> 2)) - (local_year / 100 - gmt_year / 100) + - ((local_year / 100 >> 2) - (gmt_year / 100 >> 2)) - - // + difference in years * 365 */ - + static_cast(local_year - gmt_year) * 365); - - long int hours = (24 * days) + (localtm.tm_hour - gmtm.tm_hour); - long int mins = (60 * hours) + (localtm.tm_min - gmtm.tm_min); - long int secs = (60 * mins) + (localtm.tm_sec - gmtm.tm_sec); - - return secs; - } - }; - - auto offset_seconds = helper::calculate_gmt_offset(tm); - #else - auto offset_seconds = tm.tm_gmtoff; - #endif - - return static_cast(offset_seconds / 60); -#endif -} - -// Return current thread id as size_t -// It exists because the std::this_thread::get_id() is much slower(especially -// under VS 2013) -SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT { -#ifdef _WIN32 - return static_cast(::GetCurrentThreadId()); -#elif defined(__linux__) - #if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21) - #define SYS_gettid __NR_gettid - #endif - return static_cast(::syscall(SYS_gettid)); -#elif defined(_AIX) - struct __pthrdsinfo buf; - int reg_size = 0; - pthread_t pt = pthread_self(); - int retval = pthread_getthrds_np(&pt, PTHRDSINFO_QUERY_TID, &buf, sizeof(buf), NULL, ®_size); - int tid = (!retval) ? buf.__pi_tid : 0; - return static_cast(tid); -#elif defined(__DragonFly__) || defined(__FreeBSD__) - return static_cast(::pthread_getthreadid_np()); -#elif defined(__NetBSD__) - return static_cast(::_lwp_self()); -#elif defined(__OpenBSD__) - return static_cast(::getthrid()); -#elif defined(__sun) - return static_cast(::thr_self()); -#elif __APPLE__ - uint64_t tid; - // There is no pthread_threadid_np prior to Mac OS X 10.6, and it is not supported on any PPC, - // including 10.6.8 Rosetta. __POWERPC__ is Apple-specific define encompassing ppc and ppc64. - #ifdef MAC_OS_X_VERSION_MAX_ALLOWED - { - #if (MAC_OS_X_VERSION_MAX_ALLOWED < 1060) || defined(__POWERPC__) - tid = pthread_mach_thread_np(pthread_self()); - #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (&pthread_threadid_np) { - pthread_threadid_np(nullptr, &tid); - } else { - tid = pthread_mach_thread_np(pthread_self()); - } - #else - pthread_threadid_np(nullptr, &tid); - #endif - } - #else - pthread_threadid_np(nullptr, &tid); - #endif - return static_cast(tid); -#else // Default to standard C++11 (other Unix) - return static_cast(std::hash()(std::this_thread::get_id())); -#endif -} - -// Return current thread id as size_t (from thread local storage) -SPDLOG_INLINE size_t thread_id() SPDLOG_NOEXCEPT { -#if defined(SPDLOG_NO_TLS) - return _thread_id(); -#else // cache thread id in tls - static thread_local const size_t tid = _thread_id(); - return tid; -#endif -} - -// This is avoid msvc issue in sleep_for that happens if the clock changes. -// See https://github.com/gabime/spdlog/issues/609 -SPDLOG_INLINE void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT { -#if defined(_WIN32) - ::Sleep(milliseconds); -#else - std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); -#endif -} - -// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined) -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) -SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) { - memory_buf_t buf; - wstr_to_utf8buf(filename, buf); - return SPDLOG_BUF_TO_STRING(buf); -} -#else -SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) { return filename; } -#endif - -SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT { -#ifdef _WIN32 - return conditional_static_cast(::GetCurrentProcessId()); -#else - return conditional_static_cast(::getpid()); -#endif -} - -// Determine if the terminal supports colors -// Based on: https://github.com/agauniyal/rang/ -SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT { -#ifdef _WIN32 - return true; -#else - - static const bool result = []() { - const char *env_colorterm_p = std::getenv("COLORTERM"); - if (env_colorterm_p != nullptr) { - return true; - } - - static constexpr std::array terms = { - {"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", - "putty", "rxvt", "screen", "vt100", "xterm", "alacritty", "vt102"}}; - - const char *env_term_p = std::getenv("TERM"); - if (env_term_p == nullptr) { - return false; - } - - return std::any_of(terms.begin(), terms.end(), [&](const char *term) { - return std::strstr(env_term_p, term) != nullptr; - }); - }(); - - return result; -#endif -} - -// Determine if the terminal attached -// Source: https://github.com/agauniyal/rang/ -SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT { -#ifdef _WIN32 - return ::_isatty(_fileno(file)) != 0; -#else - return ::isatty(fileno(file)) != 0; -#endif -} - -#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) -SPDLOG_INLINE void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) { - if (wstr.size() > static_cast((std::numeric_limits::max)()) / 4 - 1) { - throw_spdlog_ex("UTF-16 string is too big to be converted to UTF-8"); - } - - int wstr_size = static_cast(wstr.size()); - if (wstr_size == 0) { - target.resize(0); - return; - } - - int result_size = static_cast(target.capacity()); - if ((wstr_size + 1) * 4 > result_size) { - result_size = - ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, NULL, 0, NULL, NULL); - } - - if (result_size > 0) { - target.resize(result_size); - result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(), - result_size, NULL, NULL); - - if (result_size > 0) { - target.resize(result_size); - return; - } - } - - throw_spdlog_ex( - fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError())); -} - -SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) { - if (str.size() > static_cast((std::numeric_limits::max)()) - 1) { - throw_spdlog_ex("UTF-8 string is too big to be converted to UTF-16"); - } - - int str_size = static_cast(str.size()); - if (str_size == 0) { - target.resize(0); - return; - } - - // find the size to allocate for the result buffer - int result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, NULL, 0); - - if (result_size > 0) { - target.resize(result_size); - result_size = - ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, target.data(), result_size); - if (result_size > 0) { - assert(result_size == static_cast(target.size())); - return; - } - } - - throw_spdlog_ex( - fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError())); -} -#endif // (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && - // defined(_WIN32) - -// return true on success -static SPDLOG_INLINE bool mkdir_(const filename_t &path) { -#ifdef _WIN32 - #ifdef SPDLOG_WCHAR_FILENAMES - return ::_wmkdir(path.c_str()) == 0; - #else - return ::_mkdir(path.c_str()) == 0; - #endif -#else - return ::mkdir(path.c_str(), mode_t(0755)) == 0; -#endif -} - -// create the given directory - and all directories leading to it -// return true on success or if the directory already exists -SPDLOG_INLINE bool create_dir(const filename_t &path) { - if (path_exists(path)) { - return true; - } - - if (path.empty()) { - return false; - } - - size_t search_offset = 0; - do { - auto token_pos = path.find_first_of(folder_seps_filename, search_offset); - // treat the entire path as a folder if no folder separator not found - if (token_pos == filename_t::npos) { - token_pos = path.size(); - } - - auto subdir = path.substr(0, token_pos); -#ifdef _WIN32 - // if subdir is just a drive letter, add a slash e.g. "c:"=>"c:\", - // otherwise path_exists(subdir) returns false (issue #3079) - const bool is_drive = subdir.length() == 2 && subdir[1] == ':'; - if (is_drive) { - subdir += '\\'; - token_pos++; - } -#endif - - if (!subdir.empty() && !path_exists(subdir) && !mkdir_(subdir)) { - return false; // return error if failed creating dir - } - search_offset = token_pos + 1; - } while (search_offset < path.size()); - - return true; -} - -// Return directory name from given path or empty string -// "abc/file" => "abc" -// "abc/" => "abc" -// "abc" => "" -// "abc///" => "abc//" -SPDLOG_INLINE filename_t dir_name(const filename_t &path) { - auto pos = path.find_last_of(folder_seps_filename); - return pos != filename_t::npos ? path.substr(0, pos) : filename_t{}; -} - -#ifdef _MSC_VER - #pragma warning(push) - #pragma warning(disable : 4996) -#endif // _MSC_VER -std::string SPDLOG_INLINE getenv(const char *field) { -#if defined(_MSC_VER) && defined(__cplusplus_winrt) - return std::string{}; // not supported under uwp -#else - char *buf = std::getenv(field); - return buf ? buf : std::string{}; -#endif -} -#ifdef _MSC_VER - #pragma warning(pop) -#endif // _MSC_VER - -// Do fsync by FILE handlerpointer -// Return true on success -SPDLOG_INLINE bool fsync(FILE *fp) { -#ifdef _WIN32 - return FlushFileBuffers(reinterpret_cast(_get_osfhandle(_fileno(fp)))) != 0; -#else - return ::fsync(fileno(fp)) == 0; -#endif -} - -// Do non-locking fwrite if possible by the os or use the regular locking fwrite -// Return true on success. -SPDLOG_INLINE bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp) { -#if defined(_WIN32) && defined(SPDLOG_FWRITE_UNLOCKED) - return _fwrite_nolock(ptr, 1, n_bytes, fp) == n_bytes; -#elif defined(SPDLOG_FWRITE_UNLOCKED) - return ::fwrite_unlocked(ptr, 1, n_bytes, fp) == n_bytes; -#else - return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes; -#endif -} - -} // namespace os -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/os.h b/examples/blueprints-example/external/details/os.h deleted file mode 100644 index 5fd12ba..0000000 --- a/examples/blueprints-example/external/details/os.h +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include // std::time_t -#include - -namespace spdlog { -namespace details { -namespace os { - -SPDLOG_API spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT; - -SPDLOG_API std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; - -SPDLOG_API std::tm localtime() SPDLOG_NOEXCEPT; - -SPDLOG_API std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; - -SPDLOG_API std::tm gmtime() SPDLOG_NOEXCEPT; - -// eol definition -#if !defined(SPDLOG_EOL) - #ifdef _WIN32 - #define SPDLOG_EOL "\r\n" - #else - #define SPDLOG_EOL "\n" - #endif -#endif - -SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL; - -// folder separator -#if !defined(SPDLOG_FOLDER_SEPS) - #ifdef _WIN32 - #define SPDLOG_FOLDER_SEPS "\\/" - #else - #define SPDLOG_FOLDER_SEPS "/" - #endif -#endif - -SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS; -SPDLOG_CONSTEXPR static const filename_t::value_type folder_seps_filename[] = - SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS); - -// fopen_s on non windows for writing -SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); - -// Remove filename. return 0 on success -SPDLOG_API int remove(const filename_t &filename) SPDLOG_NOEXCEPT; - -// Remove file if exists. return 0 on success -// Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread) -SPDLOG_API int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT; - -SPDLOG_API int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT; - -// Return if file exists. -SPDLOG_API bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT; - -// Return file size according to open FILE* object -SPDLOG_API size_t filesize(FILE *f); - -// Return utc offset in minutes or throw spdlog_ex on failure -SPDLOG_API int utc_minutes_offset(const std::tm &tm = details::os::localtime()); - -// Return current thread id as size_t -// It exists because the std::this_thread::get_id() is much slower(especially -// under VS 2013) -SPDLOG_API size_t _thread_id() SPDLOG_NOEXCEPT; - -// Return current thread id as size_t (from thread local storage) -SPDLOG_API size_t thread_id() SPDLOG_NOEXCEPT; - -// This is avoid msvc issue in sleep_for that happens if the clock changes. -// See https://github.com/gabime/spdlog/issues/609 -SPDLOG_API void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT; - -SPDLOG_API std::string filename_to_str(const filename_t &filename); - -SPDLOG_API int pid() SPDLOG_NOEXCEPT; - -// Determine if the terminal supports colors -// Source: https://github.com/agauniyal/rang/ -SPDLOG_API bool is_color_terminal() SPDLOG_NOEXCEPT; - -// Determine if the terminal attached -// Source: https://github.com/agauniyal/rang/ -SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; - -#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) -SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target); - -SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target); -#endif - -// Return directory name from given path or empty string -// "abc/file" => "abc" -// "abc/" => "abc" -// "abc" => "" -// "abc///" => "abc//" -SPDLOG_API filename_t dir_name(const filename_t &path); - -// Create a dir from the given path. -// Return true if succeeded or if this dir already exists. -SPDLOG_API bool create_dir(const filename_t &path); - -// non thread safe, cross platform getenv/getenv_s -// return empty string if field not found -SPDLOG_API std::string getenv(const char *field); - -// Do fsync by FILE objectpointer. -// Return true on success. -SPDLOG_API bool fsync(FILE *fp); - -// Do non-locking fwrite if possible by the os or use the regular locking fwrite -// Return true on success. -SPDLOG_API bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp); - -} // namespace os -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "os-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/periodic_worker-inl.h b/examples/blueprints-example/external/details/periodic_worker-inl.h deleted file mode 100644 index 18f11fb..0000000 --- a/examples/blueprints-example/external/details/periodic_worker-inl.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -namespace spdlog { -namespace details { - -// stop the worker thread and join it -SPDLOG_INLINE periodic_worker::~periodic_worker() { - if (worker_thread_.joinable()) { - { - std::lock_guard lock(mutex_); - active_ = false; - } - cv_.notify_one(); - worker_thread_.join(); - } -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/periodic_worker.h b/examples/blueprints-example/external/details/periodic_worker.h deleted file mode 100644 index d647b66..0000000 --- a/examples/blueprints-example/external/details/periodic_worker.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// periodic worker thread - periodically executes the given callback function. -// -// RAII over the owned thread: -// creates the thread on construction. -// stops and joins the thread on destruction (if the thread is executing a callback, wait for it -// to finish first). - -#include -#include -#include -#include -#include -namespace spdlog { -namespace details { - -class SPDLOG_API periodic_worker { -public: - template - periodic_worker(const std::function &callback_fun, - std::chrono::duration interval) { - active_ = (interval > std::chrono::duration::zero()); - if (!active_) { - return; - } - - worker_thread_ = std::thread([this, callback_fun, interval]() { - for (;;) { - std::unique_lock lock(this->mutex_); - if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) { - return; // active_ == false, so exit this thread - } - callback_fun(); - } - }); - } - std::thread &get_thread() { return worker_thread_; } - periodic_worker(const periodic_worker &) = delete; - periodic_worker &operator=(const periodic_worker &) = delete; - // stop the worker thread and join it - ~periodic_worker(); - -private: - bool active_; - std::thread worker_thread_; - std::mutex mutex_; - std::condition_variable cv_; -}; -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "periodic_worker-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/registry-inl.h b/examples/blueprints-example/external/details/registry-inl.h deleted file mode 100644 index 272bebb..0000000 --- a/examples/blueprints-example/external/details/registry-inl.h +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include -#include -#include - -#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER - // support for the default stdout color logger - #ifdef _WIN32 - #include - #else - #include - #endif -#endif // SPDLOG_DISABLE_DEFAULT_LOGGER - -#include -#include -#include -#include -#include - -namespace spdlog { -namespace details { - -SPDLOG_INLINE registry::registry() - : formatter_(new pattern_formatter()) { -#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER - // create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows). - #ifdef _WIN32 - auto color_sink = std::make_shared(); - #else - auto color_sink = std::make_shared(); - #endif - - const char *default_logger_name = ""; - default_logger_ = std::make_shared(default_logger_name, std::move(color_sink)); - loggers_[default_logger_name] = default_logger_; - -#endif // SPDLOG_DISABLE_DEFAULT_LOGGER -} - -SPDLOG_INLINE registry::~registry() = default; - -SPDLOG_INLINE void registry::register_logger(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - register_logger_(std::move(new_logger)); -} - -SPDLOG_INLINE void registry::register_or_replace(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - register_or_replace_(std::move(new_logger)); -} - -SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - new_logger->set_formatter(formatter_->clone()); - - if (err_handler_) { - new_logger->set_error_handler(err_handler_); - } - - // set new level according to previously configured level or default level - auto it = log_levels_.find(new_logger->name()); - auto new_level = it != log_levels_.end() ? it->second : global_log_level_; - new_logger->set_level(new_level); - - new_logger->flush_on(flush_level_); - - if (backtrace_n_messages_ > 0) { - new_logger->enable_backtrace(backtrace_n_messages_); - } - - if (automatic_registration_) { - register_logger_(std::move(new_logger)); - } -} - -SPDLOG_INLINE std::shared_ptr registry::get(const std::string &logger_name) { - std::lock_guard lock(logger_map_mutex_); - auto found = loggers_.find(logger_name); - return found == loggers_.end() ? nullptr : found->second; -} - -SPDLOG_INLINE std::shared_ptr registry::default_logger() { - std::lock_guard lock(logger_map_mutex_); - return default_logger_; -} - -// Return raw ptr to the default logger. -// To be used directly by the spdlog default api (e.g. spdlog::info) -// This make the default API faster, but cannot be used concurrently with set_default_logger(). -// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another. -SPDLOG_INLINE logger *registry::get_default_raw() { return default_logger_.get(); } - -// set default logger. -// the default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. -SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr new_default_logger) { - std::lock_guard lock(logger_map_mutex_); - if (new_default_logger != nullptr) { - loggers_[new_default_logger->name()] = new_default_logger; - } - default_logger_ = std::move(new_default_logger); -} - -SPDLOG_INLINE void registry::set_tp(std::shared_ptr tp) { - std::lock_guard lock(tp_mutex_); - tp_ = std::move(tp); -} - -SPDLOG_INLINE std::shared_ptr registry::get_tp() { - std::lock_guard lock(tp_mutex_); - return tp_; -} - -// Set global formatter. Each sink in each logger will get a clone of this object -SPDLOG_INLINE void registry::set_formatter(std::unique_ptr formatter) { - std::lock_guard lock(logger_map_mutex_); - formatter_ = std::move(formatter); - for (auto &l : loggers_) { - l.second->set_formatter(formatter_->clone()); - } -} - -SPDLOG_INLINE void registry::enable_backtrace(size_t n_messages) { - std::lock_guard lock(logger_map_mutex_); - backtrace_n_messages_ = n_messages; - - for (auto &l : loggers_) { - l.second->enable_backtrace(n_messages); - } -} - -SPDLOG_INLINE void registry::disable_backtrace() { - std::lock_guard lock(logger_map_mutex_); - backtrace_n_messages_ = 0; - for (auto &l : loggers_) { - l.second->disable_backtrace(); - } -} - -SPDLOG_INLINE void registry::set_level(level::level_enum log_level) { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - l.second->set_level(log_level); - } - global_log_level_ = log_level; -} - -SPDLOG_INLINE void registry::flush_on(level::level_enum log_level) { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - l.second->flush_on(log_level); - } - flush_level_ = log_level; -} - -SPDLOG_INLINE void registry::set_error_handler(err_handler handler) { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - l.second->set_error_handler(handler); - } - err_handler_ = std::move(handler); -} - -SPDLOG_INLINE void registry::apply_all( - const std::function)> &fun) { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - fun(l.second); - } -} - -SPDLOG_INLINE void registry::flush_all() { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - l.second->flush(); - } -} - -SPDLOG_INLINE void registry::drop(const std::string &logger_name) { - std::lock_guard lock(logger_map_mutex_); - auto is_default_logger = default_logger_ && default_logger_->name() == logger_name; - loggers_.erase(logger_name); - if (is_default_logger) { - default_logger_.reset(); - } -} - -SPDLOG_INLINE void registry::drop_all() { - std::lock_guard lock(logger_map_mutex_); - loggers_.clear(); - default_logger_.reset(); -} - -// clean all resources and threads started by the registry -SPDLOG_INLINE void registry::shutdown() { - { - std::lock_guard lock(flusher_mutex_); - periodic_flusher_.reset(); - } - - drop_all(); - - { - std::lock_guard lock(tp_mutex_); - tp_.reset(); - } -} - -SPDLOG_INLINE std::recursive_mutex ®istry::tp_mutex() { return tp_mutex_; } - -SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registration) { - std::lock_guard lock(logger_map_mutex_); - automatic_registration_ = automatic_registration; -} - -SPDLOG_INLINE void registry::set_levels(log_levels levels, level::level_enum *global_level) { - std::lock_guard lock(logger_map_mutex_); - log_levels_ = std::move(levels); - auto global_level_requested = global_level != nullptr; - global_log_level_ = global_level_requested ? *global_level : global_log_level_; - - for (auto &logger : loggers_) { - auto logger_entry = log_levels_.find(logger.first); - if (logger_entry != log_levels_.end()) { - logger.second->set_level(logger_entry->second); - } else if (global_level_requested) { - logger.second->set_level(*global_level); - } - } -} - -SPDLOG_INLINE registry ®istry::instance() { - static registry s_instance; - return s_instance; -} - -SPDLOG_INLINE void registry::apply_logger_env_levels(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - auto it = log_levels_.find(new_logger->name()); - auto new_level = it != log_levels_.end() ? it->second : global_log_level_; - new_logger->set_level(new_level); -} - -SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name) { - if (loggers_.find(logger_name) != loggers_.end()) { - throw_spdlog_ex("logger with name '" + logger_name + "' already exists"); - } -} - -SPDLOG_INLINE void registry::register_logger_(std::shared_ptr new_logger) { - auto &logger_name = new_logger->name(); - throw_if_exists_(logger_name); - loggers_[logger_name] = std::move(new_logger); -} - -SPDLOG_INLINE void registry::register_or_replace_(std::shared_ptr new_logger) { - loggers_[new_logger->name()] = std::move(new_logger); -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/registry.h b/examples/blueprints-example/external/details/registry.h deleted file mode 100644 index 72c70b8..0000000 --- a/examples/blueprints-example/external/details/registry.h +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Loggers registry of unique name->logger pointer -// An attempt to create a logger with an already existing name will result with spdlog_ex exception. -// If user requests a non existing logger, nullptr will be returned -// This class is thread safe - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace spdlog { -class logger; - -namespace details { -class thread_pool; - -class SPDLOG_API registry { -public: - using log_levels = std::unordered_map; - registry(const registry &) = delete; - registry &operator=(const registry &) = delete; - - void register_logger(std::shared_ptr new_logger); - void register_or_replace(std::shared_ptr new_logger); - void initialize_logger(std::shared_ptr new_logger); - std::shared_ptr get(const std::string &logger_name); - std::shared_ptr default_logger(); - - // Return raw ptr to the default logger. - // To be used directly by the spdlog default api (e.g. spdlog::info) - // This make the default API faster, but cannot be used concurrently with set_default_logger(). - // e.g do not call set_default_logger() from one thread while calling spdlog::info() from - // another. - logger *get_default_raw(); - - // set default logger and add it to the registry if not registered already. - // default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. - // Note: Make sure to unregister it when no longer needed or before calling again with a new - // logger. - void set_default_logger(std::shared_ptr new_default_logger); - - void set_tp(std::shared_ptr tp); - - std::shared_ptr get_tp(); - - // Set global formatter. Each sink in each logger will get a clone of this object - void set_formatter(std::unique_ptr formatter); - - void enable_backtrace(size_t n_messages); - - void disable_backtrace(); - - void set_level(level::level_enum log_level); - - void flush_on(level::level_enum log_level); - - template - void flush_every(std::chrono::duration interval) { - std::lock_guard lock(flusher_mutex_); - auto clbk = [this]() { this->flush_all(); }; - periodic_flusher_ = details::make_unique(clbk, interval); - } - - std::unique_ptr &get_flusher() { - std::lock_guard lock(flusher_mutex_); - return periodic_flusher_; - } - - void set_error_handler(err_handler handler); - - void apply_all(const std::function)> &fun); - - void flush_all(); - - void drop(const std::string &logger_name); - - void drop_all(); - - // clean all resources and threads started by the registry - void shutdown(); - - std::recursive_mutex &tp_mutex(); - - void set_automatic_registration(bool automatic_registration); - - // set levels for all existing/future loggers. global_level can be null if should not set. - void set_levels(log_levels levels, level::level_enum *global_level); - - static registry &instance(); - - void apply_logger_env_levels(std::shared_ptr new_logger); - -private: - registry(); - ~registry(); - - void throw_if_exists_(const std::string &logger_name); - void register_logger_(std::shared_ptr new_logger); - void register_or_replace_(std::shared_ptr new_logger); - bool set_level_from_cfg_(logger *logger); - std::mutex logger_map_mutex_, flusher_mutex_; - std::recursive_mutex tp_mutex_; - std::unordered_map> loggers_; - log_levels log_levels_; - std::unique_ptr formatter_; - spdlog::level::level_enum global_log_level_ = level::info; - level::level_enum flush_level_ = level::off; - err_handler err_handler_; - std::shared_ptr tp_; - std::unique_ptr periodic_flusher_; - std::shared_ptr default_logger_; - bool automatic_registration_ = true; - size_t backtrace_n_messages_ = 0; -}; - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "registry-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/synchronous_factory.h b/examples/blueprints-example/external/details/synchronous_factory.h deleted file mode 100644 index 4bd5a51..0000000 --- a/examples/blueprints-example/external/details/synchronous_factory.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include "registry.h" - -namespace spdlog { - -// Default logger factory- creates synchronous loggers -class logger; - -struct synchronous_factory { - template - static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) { - auto sink = std::make_shared(std::forward(args)...); - auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); - details::registry::instance().initialize_logger(new_logger); - return new_logger; - } -}; -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/tcp_client-windows.h b/examples/blueprints-example/external/details/tcp_client-windows.h deleted file mode 100644 index 956f9f9..0000000 --- a/examples/blueprints-example/external/details/tcp_client-windows.h +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#define WIN32_LEAN_AND_MEAN -// tcp client helper -#include -#include - -#include -#include -#include -#include -#include -#include - -#pragma comment(lib, "Ws2_32.lib") -#pragma comment(lib, "Mswsock.lib") -#pragma comment(lib, "AdvApi32.lib") - -namespace spdlog { -namespace details { -class tcp_client { - SOCKET socket_ = INVALID_SOCKET; - - static void init_winsock_() { - WSADATA wsaData; - auto rv = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (rv != 0) { - throw_winsock_error_("WSAStartup failed", ::WSAGetLastError()); - } - } - - static void throw_winsock_error_(const std::string &msg, int last_error) { - char buf[512]; - ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, - (sizeof(buf) / sizeof(char)), NULL); - - throw_spdlog_ex(fmt_lib::format("tcp_sink - {}: {}", msg, buf)); - } - -public: - tcp_client() { init_winsock_(); } - - ~tcp_client() { - close(); - ::WSACleanup(); - } - - bool is_connected() const { return socket_ != INVALID_SOCKET; } - - void close() { - ::closesocket(socket_); - socket_ = INVALID_SOCKET; - } - - SOCKET fd() const { return socket_; } - - int connect_socket_with_timeout(SOCKET sockfd, - const struct sockaddr *addr, - int addrlen, - const timeval &tv) { - // If no timeout requested, do a normal blocking connect. - if (tv.tv_sec == 0 && tv.tv_usec == 0) { - int rv = ::connect(sockfd, addr, addrlen); - if (rv == SOCKET_ERROR && WSAGetLastError() == WSAEISCONN) { - return 0; - } - return rv; - } - - // Switch to nonâ€blocking mode - u_long mode = 1UL; - if (::ioctlsocket(sockfd, FIONBIO, &mode) == SOCKET_ERROR) { - return SOCKET_ERROR; - } - - int rv = ::connect(sockfd, addr, addrlen); - int last_error = WSAGetLastError(); - if (rv == 0 || last_error == WSAEISCONN) { - mode = 0UL; - if (::ioctlsocket(sockfd, FIONBIO, &mode) == SOCKET_ERROR) { - return SOCKET_ERROR; - } - return 0; - } - if (last_error != WSAEWOULDBLOCK) { - // Real error - mode = 0UL; - if (::ioctlsocket(sockfd, FIONBIO, &mode)) { - return SOCKET_ERROR; - } - return SOCKET_ERROR; - } - - // Wait until socket is writable or timeout expires - fd_set wfds; - FD_ZERO(&wfds); - FD_SET(sockfd, &wfds); - - rv = ::select(0, nullptr, &wfds, nullptr, const_cast(&tv)); - - // Restore blocking mode regardless of select result - mode = 0UL; - if (::ioctlsocket(sockfd, FIONBIO, &mode) == SOCKET_ERROR) { - return SOCKET_ERROR; - } - - if (rv == 0) { - WSASetLastError(WSAETIMEDOUT); - return SOCKET_ERROR; - } - if (rv == SOCKET_ERROR) { - return SOCKET_ERROR; - } - - int so_error = 0; - int len = sizeof(so_error); - if (::getsockopt(sockfd, SOL_SOCKET, SO_ERROR, reinterpret_cast(&so_error), &len) == - SOCKET_ERROR) { - return SOCKET_ERROR; - } - if (so_error != 0 && so_error != WSAEISCONN) { - // connection failed - WSASetLastError(so_error); - return SOCKET_ERROR; - } - - return 0; // success - } - - // try to connect or throw on failure - void connect(const std::string &host, int port, int timeout_ms = 0) { - if (is_connected()) { - close(); - } - struct addrinfo hints {}; - ZeroMemory(&hints, sizeof(hints)); - - hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on - hints.ai_socktype = SOCK_STREAM; // TCP - hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value - hints.ai_protocol = 0; - - timeval tv; - tv.tv_sec = timeout_ms / 1000; - tv.tv_usec = (timeout_ms % 1000) * 1000; - - auto port_str = std::to_string(port); - struct addrinfo *addrinfo_result; - auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result); - int last_error = 0; - if (rv != 0) { - last_error = ::WSAGetLastError(); - WSACleanup(); - throw_winsock_error_("getaddrinfo failed", last_error); - } - - // Try each address until we successfully connect(2). - for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) { - socket_ = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (socket_ == INVALID_SOCKET) { - last_error = ::WSAGetLastError(); - WSACleanup(); - continue; - } - if (connect_socket_with_timeout(socket_, rp->ai_addr, (int)rp->ai_addrlen, tv) == 0) { - last_error = 0; - break; - } - last_error = WSAGetLastError(); - ::closesocket(socket_); - socket_ = INVALID_SOCKET; - } - ::freeaddrinfo(addrinfo_result); - if (socket_ == INVALID_SOCKET) { - WSACleanup(); - throw_winsock_error_("connect failed", last_error); - } - if (timeout_ms > 0) { - DWORD tv = static_cast(timeout_ms); - ::setsockopt(socket_, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv)); - ::setsockopt(socket_, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tv, sizeof(tv)); - } - - // set TCP_NODELAY - int enable_flag = 1; - ::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&enable_flag), - sizeof(enable_flag)); - } - - // Send exactly n_bytes of the given data. - // On error close the connection and throw. - void send(const char *data, size_t n_bytes) { - size_t bytes_sent = 0; - while (bytes_sent < n_bytes) { - const int send_flags = 0; - auto write_result = - ::send(socket_, data + bytes_sent, (int)(n_bytes - bytes_sent), send_flags); - if (write_result == SOCKET_ERROR) { - int last_error = ::WSAGetLastError(); - close(); - throw_winsock_error_("send failed", last_error); - } - - if (write_result == 0) // (probably should not happen but in any case..) - { - break; - } - bytes_sent += static_cast(write_result); - } - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/tcp_client.h b/examples/blueprints-example/external/details/tcp_client.h deleted file mode 100644 index 1eaa3cb..0000000 --- a/examples/blueprints-example/external/details/tcp_client.h +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifdef _WIN32 - #error include tcp_client-windows.h instead -#endif - -// tcp client helper -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -namespace spdlog { -namespace details { -class tcp_client { - int socket_ = -1; - -public: - bool is_connected() const { return socket_ != -1; } - - void close() { - if (is_connected()) { - ::close(socket_); - socket_ = -1; - } - } - - int fd() const { return socket_; } - - ~tcp_client() { close(); } - - int connect_socket_with_timeout(int sockfd, - const struct sockaddr *addr, - socklen_t addrlen, - const timeval &tv) { - // Blocking connect if timeout is zero - if (tv.tv_sec == 0 && tv.tv_usec == 0) { - int rv = ::connect(sockfd, addr, addrlen); - if (rv < 0 && errno == EISCONN) { - // already connected, treat as success - return 0; - } - return rv; - } - - // Non-blocking path - int orig_flags = ::fcntl(sockfd, F_GETFL, 0); - if (orig_flags < 0) { - return -1; - } - if (::fcntl(sockfd, F_SETFL, orig_flags | O_NONBLOCK) < 0) { - return -1; - } - - int rv = ::connect(sockfd, addr, addrlen); - if (rv == 0 || (rv < 0 && errno == EISCONN)) { - // immediate connect or already connected - ::fcntl(sockfd, F_SETFL, orig_flags); - return 0; - } - if (errno != EINPROGRESS) { - ::fcntl(sockfd, F_SETFL, orig_flags); - return -1; - } - - // wait for writability - fd_set wfds; - FD_ZERO(&wfds); - FD_SET(sockfd, &wfds); - - struct timeval tv_copy = tv; - rv = ::select(sockfd + 1, nullptr, &wfds, nullptr, &tv_copy); - if (rv <= 0) { - // timeout or error - ::fcntl(sockfd, F_SETFL, orig_flags); - if (rv == 0) errno = ETIMEDOUT; - return -1; - } - - // check socket error - int so_error = 0; - socklen_t len = sizeof(so_error); - if (::getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &so_error, &len) < 0) { - ::fcntl(sockfd, F_SETFL, orig_flags); - return -1; - } - ::fcntl(sockfd, F_SETFL, orig_flags); - if (so_error != 0 && so_error != EISCONN) { - errno = so_error; - return -1; - } - - return 0; - } - - // try to connect or throw on failure - void connect(const std::string &host, int port, int timeout_ms = 0) { - close(); - struct addrinfo hints {}; - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on - hints.ai_socktype = SOCK_STREAM; // TCP - hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value - hints.ai_protocol = 0; - - struct timeval tv; - tv.tv_sec = timeout_ms / 1000; - tv.tv_usec = (timeout_ms % 1000) * 1000; - - auto port_str = std::to_string(port); - struct addrinfo *addrinfo_result; - auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result); - if (rv != 0) { - throw_spdlog_ex(fmt_lib::format("::getaddrinfo failed: {}", gai_strerror(rv))); - } - - // Try each address until we successfully connect(2). - int last_errno = 0; - for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) { -#if defined(SOCK_CLOEXEC) - const int flags = SOCK_CLOEXEC; -#else - const int flags = 0; -#endif - socket_ = ::socket(rp->ai_family, rp->ai_socktype | flags, rp->ai_protocol); - if (socket_ == -1) { - last_errno = errno; - continue; - } - ::fcntl(socket_, F_SETFD, FD_CLOEXEC); - if (connect_socket_with_timeout(socket_, rp->ai_addr, rp->ai_addrlen, tv) == 0) { - last_errno = 0; - break; - } - last_errno = errno; - ::close(socket_); - socket_ = -1; - } - ::freeaddrinfo(addrinfo_result); - if (socket_ == -1) { - throw_spdlog_ex("::connect failed", last_errno); - } - - if (timeout_ms > 0) { - // Set timeouts for send and recv - ::setsockopt(socket_, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv)); - ::setsockopt(socket_, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tv, sizeof(tv)); - } - - // set TCP_NODELAY - int enable_flag = 1; - ::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&enable_flag), - sizeof(enable_flag)); - - // prevent sigpipe on systems where MSG_NOSIGNAL is not available -#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) - ::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast(&enable_flag), - sizeof(enable_flag)); -#endif - -#if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) - #error "tcp_sink would raise SIGPIPE since neither SO_NOSIGPIPE nor MSG_NOSIGNAL are available" -#endif - } - - // Send exactly n_bytes of the given data. - // On error close the connection and throw. - void send(const char *data, size_t n_bytes) { - size_t bytes_sent = 0; - while (bytes_sent < n_bytes) { -#if defined(MSG_NOSIGNAL) - const int send_flags = MSG_NOSIGNAL; -#else - const int send_flags = 0; -#endif - auto write_result = - ::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags); - if (write_result < 0) { - close(); - throw_spdlog_ex("write(2) failed", errno); - } - - if (write_result == 0) // (probably should not happen but in any case..) - { - break; - } - bytes_sent += static_cast(write_result); - } - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/thread_pool-inl.h b/examples/blueprints-example/external/details/thread_pool-inl.h deleted file mode 100644 index b172b28..0000000 --- a/examples/blueprints-example/external/details/thread_pool-inl.h +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { -namespace details { - -SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, - size_t threads_n, - std::function on_thread_start, - std::function on_thread_stop) - : q_(q_max_items) { - if (threads_n == 0 || threads_n > 1000) { - throw_spdlog_ex( - "spdlog::thread_pool(): invalid threads_n param (valid " - "range is 1-1000)"); - } - for (size_t i = 0; i < threads_n; i++) { - threads_.emplace_back([this, on_thread_start, on_thread_stop] { - on_thread_start(); - this->thread_pool::worker_loop_(); - on_thread_stop(); - }); - } -} - -SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, - size_t threads_n, - std::function on_thread_start) - : thread_pool(q_max_items, threads_n, std::move(on_thread_start), [] {}) {} - -SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n) - : thread_pool(q_max_items, threads_n, [] {}, [] {}) {} - -// message all threads to terminate gracefully join them -SPDLOG_INLINE thread_pool::~thread_pool() { - SPDLOG_TRY { - for (size_t i = 0; i < threads_.size(); i++) { - post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block); - } - - for (auto &t : threads_) { - t.join(); - } - } - SPDLOG_CATCH_STD -} - -void SPDLOG_INLINE thread_pool::post_log(async_logger_ptr &&worker_ptr, - const details::log_msg &msg, - async_overflow_policy overflow_policy) { - async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg); - post_async_msg_(std::move(async_m), overflow_policy); -} - -void SPDLOG_INLINE thread_pool::post_flush(async_logger_ptr &&worker_ptr, - async_overflow_policy overflow_policy) { - post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy); -} - -size_t SPDLOG_INLINE thread_pool::overrun_counter() { return q_.overrun_counter(); } - -void SPDLOG_INLINE thread_pool::reset_overrun_counter() { q_.reset_overrun_counter(); } - -size_t SPDLOG_INLINE thread_pool::discard_counter() { return q_.discard_counter(); } - -void SPDLOG_INLINE thread_pool::reset_discard_counter() { q_.reset_discard_counter(); } - -size_t SPDLOG_INLINE thread_pool::queue_size() { return q_.size(); } - -void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, - async_overflow_policy overflow_policy) { - if (overflow_policy == async_overflow_policy::block) { - q_.enqueue(std::move(new_msg)); - } else if (overflow_policy == async_overflow_policy::overrun_oldest) { - q_.enqueue_nowait(std::move(new_msg)); - } else { - assert(overflow_policy == async_overflow_policy::discard_new); - q_.enqueue_if_have_room(std::move(new_msg)); - } -} - -void SPDLOG_INLINE thread_pool::worker_loop_() { - while (process_next_msg_()) { - } -} - -// process next message in the queue -// returns true if this thread should still be active (while no terminated msg was received) -bool SPDLOG_INLINE thread_pool::process_next_msg_() { - async_msg incoming_async_msg; - q_.dequeue(incoming_async_msg); - - switch (incoming_async_msg.msg_type) { - case async_msg_type::log: { - incoming_async_msg.worker_ptr->backend_sink_it_(incoming_async_msg); - return true; - } - case async_msg_type::flush: { - incoming_async_msg.worker_ptr->backend_flush_(); - return true; - } - - case async_msg_type::terminate: { - return false; - } - - default: { - assert(false); - } - } - - return true; -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/thread_pool.h b/examples/blueprints-example/external/details/thread_pool.h deleted file mode 100644 index f22b078..0000000 --- a/examples/blueprints-example/external/details/thread_pool.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace spdlog { -class async_logger; - -namespace details { - -using async_logger_ptr = std::shared_ptr; - -enum class async_msg_type { log, flush, terminate }; - -// Async msg to move to/from the queue -// Movable only. should never be copied -struct async_msg : log_msg_buffer { - async_msg_type msg_type{async_msg_type::log}; - async_logger_ptr worker_ptr; - - async_msg() = default; - ~async_msg() = default; - - // should only be moved in or out of the queue.. - async_msg(const async_msg &) = delete; - -// support for vs2013 move -#if defined(_MSC_VER) && _MSC_VER <= 1800 - async_msg(async_msg &&other) - : log_msg_buffer(std::move(other)), - msg_type(other.msg_type), - worker_ptr(std::move(other.worker_ptr)) {} - - async_msg &operator=(async_msg &&other) { - *static_cast(this) = std::move(other); - msg_type = other.msg_type; - worker_ptr = std::move(other.worker_ptr); - return *this; - } -#else // (_MSC_VER) && _MSC_VER <= 1800 - async_msg(async_msg &&) = default; - async_msg &operator=(async_msg &&) = default; -#endif - - // construct from log_msg with given type - async_msg(async_logger_ptr &&worker, async_msg_type the_type, const details::log_msg &m) - : log_msg_buffer{m}, - msg_type{the_type}, - worker_ptr{std::move(worker)} {} - - async_msg(async_logger_ptr &&worker, async_msg_type the_type) - : log_msg_buffer{}, - msg_type{the_type}, - worker_ptr{std::move(worker)} {} - - explicit async_msg(async_msg_type the_type) - : async_msg{nullptr, the_type} {} -}; - -class SPDLOG_API thread_pool { -public: - using item_type = async_msg; - using q_type = details::mpmc_blocking_queue; - - thread_pool(size_t q_max_items, - size_t threads_n, - std::function on_thread_start, - std::function on_thread_stop); - thread_pool(size_t q_max_items, size_t threads_n, std::function on_thread_start); - thread_pool(size_t q_max_items, size_t threads_n); - - // message all threads to terminate gracefully and join them - ~thread_pool(); - - thread_pool(const thread_pool &) = delete; - thread_pool &operator=(thread_pool &&) = delete; - - void post_log(async_logger_ptr &&worker_ptr, - const details::log_msg &msg, - async_overflow_policy overflow_policy); - void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy); - size_t overrun_counter(); - void reset_overrun_counter(); - size_t discard_counter(); - void reset_discard_counter(); - size_t queue_size(); - -private: - q_type q_; - - std::vector threads_; - - void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); - void worker_loop_(); - - // process next message in the queue - // return true if this thread should still be active (while no terminate msg - // was received) - bool process_next_msg_(); -}; - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "thread_pool-inl.h" -#endif diff --git a/examples/blueprints-example/external/details/udp_client-windows.h b/examples/blueprints-example/external/details/udp_client-windows.h deleted file mode 100644 index 8b7c223..0000000 --- a/examples/blueprints-example/external/details/udp_client-windows.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Helper RAII over winsock udp client socket. -// Will throw on construction if socket creation failed. - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(_MSC_VER) - #pragma comment(lib, "Ws2_32.lib") - #pragma comment(lib, "Mswsock.lib") - #pragma comment(lib, "AdvApi32.lib") -#endif - -namespace spdlog { -namespace details { -class udp_client { - static constexpr int TX_BUFFER_SIZE = 1024 * 10; - SOCKET socket_ = INVALID_SOCKET; - sockaddr_in addr_ = {}; - - static void init_winsock_() { - WSADATA wsaData; - auto rv = ::WSAStartup(MAKEWORD(2, 2), &wsaData); - if (rv != 0) { - throw_winsock_error_("WSAStartup failed", ::WSAGetLastError()); - } - } - - static void throw_winsock_error_(const std::string &msg, int last_error) { - char buf[512]; - ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, - (sizeof(buf) / sizeof(char)), NULL); - - throw_spdlog_ex(fmt_lib::format("udp_sink - {}: {}", msg, buf)); - } - - void cleanup_() { - if (socket_ != INVALID_SOCKET) { - ::closesocket(socket_); - } - socket_ = INVALID_SOCKET; - ::WSACleanup(); - } - -public: - udp_client(const std::string &host, uint16_t port) { - init_winsock_(); - - addr_.sin_family = PF_INET; - addr_.sin_port = htons(port); - addr_.sin_addr.s_addr = INADDR_ANY; - if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1) { - int last_error = ::WSAGetLastError(); - ::WSACleanup(); - throw_winsock_error_("error: Invalid address!", last_error); - } - - socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); - if (socket_ == INVALID_SOCKET) { - int last_error = ::WSAGetLastError(); - ::WSACleanup(); - throw_winsock_error_("error: Create Socket failed", last_error); - } - - int option_value = TX_BUFFER_SIZE; - if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, - reinterpret_cast(&option_value), sizeof(option_value)) < 0) { - int last_error = ::WSAGetLastError(); - cleanup_(); - throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error); - } - } - - ~udp_client() { cleanup_(); } - - SOCKET fd() const { return socket_; } - - void send(const char *data, size_t n_bytes) { - socklen_t tolen = sizeof(struct sockaddr); - if (::sendto(socket_, data, static_cast(n_bytes), 0, (struct sockaddr *)&addr_, - tolen) == -1) { - throw_spdlog_ex("sendto(2) failed", errno); - } - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/udp_client.h b/examples/blueprints-example/external/details/udp_client.h deleted file mode 100644 index 95826f5..0000000 --- a/examples/blueprints-example/external/details/udp_client.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Helper RAII over unix udp client socket. -// Will throw on construction if the socket creation failed. - -#ifdef _WIN32 - #error "include udp_client-windows.h instead" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace spdlog { -namespace details { - -class udp_client { - static constexpr int TX_BUFFER_SIZE = 1024 * 10; - int socket_ = -1; - struct sockaddr_in sockAddr_; - - void cleanup_() { - if (socket_ != -1) { - ::close(socket_); - socket_ = -1; - } - } - -public: - udp_client(const std::string &host, uint16_t port) { - socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); - if (socket_ < 0) { - throw_spdlog_ex("error: Create Socket Failed!"); - } - - int option_value = TX_BUFFER_SIZE; - if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, - reinterpret_cast(&option_value), sizeof(option_value)) < 0) { - cleanup_(); - throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!"); - } - - sockAddr_.sin_family = AF_INET; - sockAddr_.sin_port = htons(port); - - if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) { - cleanup_(); - throw_spdlog_ex("error: Invalid address!"); - } - - ::memset(sockAddr_.sin_zero, 0x00, sizeof(sockAddr_.sin_zero)); - } - - ~udp_client() { cleanup_(); } - - int fd() const { return socket_; } - - // Send exactly n_bytes of the given data. - // On error close the connection and throw. - void send(const char *data, size_t n_bytes) { - ssize_t toslen = 0; - socklen_t tolen = sizeof(struct sockaddr); - if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == - -1) { - throw_spdlog_ex("sendto(2) failed", errno); - } - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/details/windows_include.h b/examples/blueprints-example/external/details/windows_include.h deleted file mode 100644 index bbab59b..0000000 --- a/examples/blueprints-example/external/details/windows_include.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifndef NOMINMAX - #define NOMINMAX // prevent windows redefining min/max -#endif - -#ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN -#endif - -#include diff --git a/examples/blueprints-example/external/example.cpp b/examples/blueprints-example/external/example.cpp deleted file mode 100644 index 16575d1..0000000 --- a/examples/blueprints-example/external/example.cpp +++ /dev/null @@ -1,401 +0,0 @@ -// -// Copyright(c) 2015 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// spdlog usage example - -#include -#include - -void load_levels_example(); -void stdout_logger_example(); -void basic_example(); -void rotating_example(); -void daily_example(); -void callback_example(); -void async_example(); -void binary_example(); -void vector_example(); -void stopwatch_example(); -void trace_example(); -void multi_sink_example(); -void user_defined_example(); -void err_handler_example(); -void syslog_example(); -void udp_example(); -void custom_flags_example(); -void file_events_example(); -void replace_default_logger_example(); -void mdc_example(); - -#include "spdlog/spdlog.h" -#include "spdlog/cfg/env.h" // support for loading levels from the environment variable -#include "spdlog/fmt/ostr.h" // support for user defined types - -int main(int, char *[]) { - try { - // Log levels can be loaded from argv/env using "SPDLOG_LEVEL" - load_levels_example(); - - spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, - SPDLOG_VER_PATCH); - - spdlog::warn("Easy padding in numbers like {:08d}", 12); - spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); - spdlog::info("Support for floats {:03.2f}", 1.23456); - spdlog::info("Positional args are {1} {0}..", "too", "supported"); - spdlog::info("{:>8} aligned, {:<8} aligned", "right", "left"); - - // Runtime log levels - spdlog::set_level(spdlog::level::info); // Set global log level to info - spdlog::debug("This message should not be displayed!"); - spdlog::set_level(spdlog::level::trace); // Set specific logger's log level - spdlog::debug("This message should be displayed.."); - - // Customize msg format for all loggers - spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v"); - spdlog::info("This an info message with custom format"); - spdlog::set_pattern("%+"); // back to default format - spdlog::set_level(spdlog::level::info); - - // Backtrace support - // Loggers can store in a ring buffer all messages (including debug/trace) for later - // inspection. When needed, call dump_backtrace() to see what happened: - spdlog::enable_backtrace(10); // create ring buffer with capacity of 10 messages - for (int i = 0; i < 100; i++) { - spdlog::debug("Backtrace message {}", i); // not logged.. - } - // e.g. if some error happened: - spdlog::dump_backtrace(); // log them now! - - stdout_logger_example(); - basic_example(); - rotating_example(); - daily_example(); - callback_example(); - async_example(); - binary_example(); - vector_example(); - multi_sink_example(); - user_defined_example(); - err_handler_example(); - trace_example(); - stopwatch_example(); - udp_example(); - custom_flags_example(); - file_events_example(); - replace_default_logger_example(); - mdc_example(); - - // Flush all *registered* loggers using a worker thread every 3 seconds. - // note: registered loggers *must* be thread safe for this to work correctly! - spdlog::flush_every(std::chrono::seconds(3)); - - // Apply some function on all registered loggers - spdlog::apply_all([&](std::shared_ptr l) { l->info("End of example."); }); - - // Release all spdlog resources, and drop all loggers in the registry. - // This is optional (only mandatory if using windows + async log). - spdlog::shutdown(); - } - - // Exceptions will only be thrown upon failed logger or sink construction (not during logging). - catch (const spdlog::spdlog_ex &ex) { - std::printf("Log initialization failed: %s\n", ex.what()); - return 1; - } -} - -#include "spdlog/sinks/stdout_color_sinks.h" -// or #include "spdlog/sinks/stdout_sinks.h" if no colors needed. -void stdout_logger_example() { - // Create color multi threaded logger. - auto console = spdlog::stdout_color_mt("console"); - // or for stderr: - // auto console = spdlog::stderr_color_mt("error-logger"); -} - -#include "spdlog/sinks/basic_file_sink.h" -void basic_example() { - // Create basic file logger (not rotated). - auto my_logger = spdlog::basic_logger_mt("file_logger", "logs/basic-log.txt", true); -} - -#include "spdlog/sinks/rotating_file_sink.h" -void rotating_example() { - // Create a file rotating logger with 5mb size max and 3 rotated files. - auto rotating_logger = - spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3); -} - -#include "spdlog/sinks/daily_file_sink.h" -void daily_example() { - // Create a daily logger - a new file is created every day on 2:30am. - auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30); -} - -#include "spdlog/sinks/callback_sink.h" -void callback_example() { - // Create the logger - auto logger = spdlog::callback_logger_mt("custom_callback_logger", - [](const spdlog::details::log_msg & /*msg*/) { - // do what you need to do with msg - }); -} - -#include "spdlog/cfg/env.h" -void load_levels_example() { - // Set the log level to "info" and mylogger to "trace": - // SPDLOG_LEVEL=info,mylogger=trace && ./example - spdlog::cfg::load_env_levels(); - // or specify the env variable name: - // MYAPP_LEVEL=info,mylogger=trace && ./example - // spdlog::cfg::load_env_levels("MYAPP_LEVEL"); - // or from command line: - // ./example SPDLOG_LEVEL=info,mylogger=trace - // #include "spdlog/cfg/argv.h" // for loading levels from argv - // spdlog::cfg::load_argv_levels(args, argv); -} - -#include "spdlog/async.h" -void async_example() { - // Default thread pool settings can be modified *before* creating the async logger: - // spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread. - auto async_file = - spdlog::basic_logger_mt("async_file_logger", "logs/async_log.txt"); - // alternatively: - // auto async_file = - // spdlog::create_async("async_file_logger", - // "logs/async_log.txt"); - - for (int i = 1; i < 101; ++i) { - async_file->info("Async message #{}", i); - } -} - -// Log binary data as hex. -// Many types of std::container types can be used. -// Iterator ranges are supported too. -// Format flags: -// {:X} - print in uppercase. -// {:s} - don't separate each byte with space. -// {:p} - don't print the position on each line start. -// {:n} - don't split the output to lines. - -#if !defined SPDLOG_USE_STD_FORMAT || defined(_MSC_VER) - #include "spdlog/fmt/bin_to_hex.h" -void binary_example() { - std::vector buf; - for (int i = 0; i < 80; i++) { - buf.push_back(static_cast(i & 0xff)); - } - spdlog::info("Binary example: {}", spdlog::to_hex(buf)); - spdlog::info("Another binary example:{:n}", - spdlog::to_hex(std::begin(buf), std::begin(buf) + 10)); - // more examples: - // logger->info("uppercase: {:X}", spdlog::to_hex(buf)); - // logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf)); - // logger->info("uppercase, no delimiters, no position info: {:Xsp}", spdlog::to_hex(buf)); - // logger->info("hexdump style: {:a}", spdlog::to_hex(buf)); - // logger->info("hexdump style, 20 chars per line {:a}", spdlog::to_hex(buf, 20)); -} -#else -void binary_example() { - // not supported with std::format yet -} -#endif - -// Log a vector of numbers -#ifndef SPDLOG_USE_STD_FORMAT - #include "spdlog/fmt/ranges.h" -void vector_example() { - std::vector vec = {1, 2, 3}; - spdlog::info("Vector example: {}", vec); -} - -#else -void vector_example() {} -#endif - -// ! DSPDLOG_USE_STD_FORMAT - -// Compile time log levels. -// define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE) -void trace_example() { - // trace from default logger - SPDLOG_TRACE("Some trace message.. {} ,{}", 1, 3.23); - // debug from default logger - SPDLOG_DEBUG("Some debug message.. {} ,{}", 1, 3.23); - - // trace from logger object - auto logger = spdlog::get("file_logger"); - SPDLOG_LOGGER_TRACE(logger, "another trace message"); -} - -// stopwatch example -#include "spdlog/stopwatch.h" -#include -void stopwatch_example() { - spdlog::stopwatch sw; - std::this_thread::sleep_for(std::chrono::milliseconds(123)); - spdlog::info("Stopwatch: {} seconds", sw); -} - -#include "spdlog/sinks/udp_sink.h" -void udp_example() { - spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091); - auto my_logger = spdlog::udp_logger_mt("udplog", cfg); - my_logger->set_level(spdlog::level::debug); - my_logger->info("hello world"); -} - -// A logger with multiple sinks (stdout and file) - each with a different format and log level. -void multi_sink_example() { - auto console_sink = std::make_shared(); - console_sink->set_level(spdlog::level::warn); - console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v"); - - auto file_sink = - std::make_shared("logs/multisink.txt", true); - file_sink->set_level(spdlog::level::trace); - - spdlog::logger logger("multi_sink", {console_sink, file_sink}); - logger.set_level(spdlog::level::debug); - logger.warn("this should appear in both console and file"); - logger.info("this message should not appear in the console, only in the file"); -} - -// User defined types logging -struct my_type { - int i = 0; - explicit my_type(int i) - : i(i) {} -}; - -#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib -template <> -struct fmt::formatter : fmt::formatter { - auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) { - return fmt::format_to(ctx.out(), "[my_type i={}]", my.i); - } -}; - -#else // when using std::format -template <> -struct std::formatter : std::formatter { - auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) { - return std::format_to(ctx.out(), "[my_type i={}]", my.i); - } -}; -#endif - -void user_defined_example() { spdlog::info("user defined type: {}", my_type(14)); } - -// Custom error handler. Will be triggered on log failure. -void err_handler_example() { - // can be set globally or per logger(logger->set_error_handler(..)) - spdlog::set_error_handler([](const std::string &msg) { - printf("*** Custom log error handler: %s ***\n", msg.c_str()); - }); -} - -// syslog example (linux/osx/freebsd) -#ifndef _WIN32 - #include "spdlog/sinks/syslog_sink.h" -void syslog_example() { - std::string ident = "spdlog-example"; - auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID); - syslog_logger->warn("This is warning that will end up in syslog."); -} -#endif - -// Android example. -#if defined(__ANDROID__) - #include "spdlog/sinks/android_sink.h" -void android_example() { - std::string tag = "spdlog-android"; - auto android_logger = spdlog::android_logger_mt("android", tag); - android_logger->critical("Use \"adb shell logcat\" to view this message."); -} -#endif - -// Log patterns can contain custom flags. -// this will add custom flag '%*' which will be bound to a instance -#include "spdlog/pattern_formatter.h" -class my_formatter_flag : public spdlog::custom_flag_formatter { -public: - void format(const spdlog::details::log_msg &, - const std::tm &, - spdlog::memory_buf_t &dest) override { - std::string some_txt = "custom-flag"; - dest.append(some_txt.data(), some_txt.data() + some_txt.size()); - } - - std::unique_ptr clone() const override { - return spdlog::details::make_unique(); - } -}; - -void custom_flags_example() { - using spdlog::details::make_unique; // for pre c++14 - auto formatter = make_unique(); - formatter->add_flag('*').set_pattern("[%n] [%*] [%^%l%$] %v"); - // set the new formatter using spdlog::set_formatter(formatter) or - // logger->set_formatter(formatter) spdlog::set_formatter(std::move(formatter)); -} - -void file_events_example() { - // pass the spdlog::file_event_handlers to file sinks for open/close log file notifications - spdlog::file_event_handlers handlers; - handlers.before_open = [](spdlog::filename_t filename) { - spdlog::info("Before opening {}", filename); - }; - handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) { - spdlog::info("After opening {}", filename); - fputs("After opening\n", fstream); - }; - handlers.before_close = [](spdlog::filename_t filename, std::FILE *fstream) { - spdlog::info("Before closing {}", filename); - fputs("Before closing\n", fstream); - }; - handlers.after_close = [](spdlog::filename_t filename) { - spdlog::info("After closing {}", filename); - }; - auto file_sink = std::make_shared("logs/events-sample.txt", - true, handlers); - spdlog::logger my_logger("some_logger", file_sink); - my_logger.info("Some log line"); -} - -void replace_default_logger_example() { - // store the old logger so we don't break other examples. - auto old_logger = spdlog::default_logger(); - - auto new_logger = spdlog::basic_logger_mt("new_default_logger", "logs/somelog.txt", true); - spdlog::set_default_logger(std::move(new_logger)); - spdlog::set_level(spdlog::level::info); - spdlog::debug("This message should not be displayed!"); - spdlog::set_level(spdlog::level::trace); - spdlog::debug("This message should be displayed.."); - spdlog::set_default_logger(std::move(old_logger)); -} - -// Mapped Diagnostic Context (MDC) is a map that stores key-value pairs (string values) in thread -// local storage. Each thread maintains its own MDC, which loggers use to append diagnostic -// information to log outputs. Note: it is not supported in asynchronous mode due to its reliance on -// thread-local storage. - -#ifndef SPDLOG_NO_TLS - #include "spdlog/mdc.h" -void mdc_example() { - spdlog::mdc::put("key1", "value1"); - spdlog::mdc::put("key2", "value2"); - // if not using the default format, you can use the %& formatter to print mdc data as well - spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [%&] %v"); - spdlog::info("Some log message with context"); -} -#else -void mdc_example() { - // if TLS feature is disabled -} -#endif diff --git a/examples/blueprints-example/external/fmt/bin_to_hex.h b/examples/blueprints-example/external/fmt/bin_to_hex.h deleted file mode 100644 index 6ed68e4..0000000 --- a/examples/blueprints-example/external/fmt/bin_to_hex.h +++ /dev/null @@ -1,224 +0,0 @@ -// -// Copyright(c) 2015 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once - -#include -#include - -#if defined(__has_include) - #if __has_include() - #include - #endif -#endif - -#if __cpp_lib_span >= 202002L - #include -#endif - -// -// Support for logging binary data as hex -// format flags, any combination of the following: -// {:X} - print in uppercase. -// {:s} - don't separate each byte with space. -// {:p} - don't print the position on each line start. -// {:n} - don't split the output to lines. -// {:a} - show ASCII if :n is not set - -// -// Examples: -// -// std::vector v(200, 0x0b); -// logger->info("Some buffer {}", spdlog::to_hex(v)); -// char buf[128]; -// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf))); -// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf), 16)); - -namespace spdlog { -namespace details { - -template -class dump_info { -public: - dump_info(It range_begin, It range_end, size_t size_per_line) - : begin_(range_begin), - end_(range_end), - size_per_line_(size_per_line) {} - - // do not use begin() and end() to avoid collision with fmt/ranges - It get_begin() const { return begin_; } - It get_end() const { return end_; } - size_t size_per_line() const { return size_per_line_; } - -private: - It begin_, end_; - size_t size_per_line_; -}; -} // namespace details - -// create a dump_info that wraps the given container -template -inline details::dump_info to_hex(const Container &container, - size_t size_per_line = 32) { - static_assert(sizeof(typename Container::value_type) == 1, - "sizeof(Container::value_type) != 1"); - using Iter = typename Container::const_iterator; - return details::dump_info(std::begin(container), std::end(container), size_per_line); -} - -#if __cpp_lib_span >= 202002L - -template -inline details::dump_info::iterator> to_hex( - const std::span &container, size_t size_per_line = 32) { - using Container = std::span; - static_assert(sizeof(typename Container::value_type) == 1, - "sizeof(Container::value_type) != 1"); - using Iter = typename Container::iterator; - return details::dump_info(std::begin(container), std::end(container), size_per_line); -} - -#endif - -// create dump_info from ranges -template -inline details::dump_info to_hex(const It range_begin, - const It range_end, - size_t size_per_line = 32) { - return details::dump_info(range_begin, range_end, size_per_line); -} - -} // namespace spdlog - -namespace -#ifdef SPDLOG_USE_STD_FORMAT - std -#else - fmt -#endif -{ - -template -struct formatter, char> { - char delimiter = ' '; - bool put_newlines = true; - bool put_delimiters = true; - bool use_uppercase = false; - bool put_positions = true; // position on start of each line - bool show_ascii = false; - - // parse the format string flags - template - SPDLOG_CONSTEXPR_FUNC auto parse(ParseContext &ctx) -> decltype(ctx.begin()) { - auto it = ctx.begin(); - while (it != ctx.end() && *it != '}') { - switch (*it) { - case 'X': - use_uppercase = true; - break; - case 's': - put_delimiters = false; - break; - case 'p': - put_positions = false; - break; - case 'n': - put_newlines = false; - show_ascii = false; - break; - case 'a': - if (put_newlines) { - show_ascii = true; - } - break; - } - - ++it; - } - return it; - } - - // format the given bytes range as hex - template - auto format(const spdlog::details::dump_info &the_range, - FormatContext &ctx) const -> decltype(ctx.out()) { - SPDLOG_CONSTEXPR const char *hex_upper = "0123456789ABCDEF"; - SPDLOG_CONSTEXPR const char *hex_lower = "0123456789abcdef"; - const char *hex_chars = use_uppercase ? hex_upper : hex_lower; - -#if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION < 60000 - auto inserter = ctx.begin(); -#else - auto inserter = ctx.out(); -#endif - - int size_per_line = static_cast(the_range.size_per_line()); - auto start_of_line = the_range.get_begin(); - for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) { - auto ch = static_cast(*i); - - if (put_newlines && - (i == the_range.get_begin() || i - start_of_line >= size_per_line)) { - if (show_ascii && i != the_range.get_begin()) { - *inserter++ = delimiter; - *inserter++ = delimiter; - for (auto j = start_of_line; j < i; j++) { - auto pc = static_cast(*j); - *inserter++ = std::isprint(pc) ? static_cast(*j) : '.'; - } - } - - put_newline(inserter, static_cast(i - the_range.get_begin())); - - // put first byte without delimiter in front of it - *inserter++ = hex_chars[(ch >> 4) & 0x0f]; - *inserter++ = hex_chars[ch & 0x0f]; - start_of_line = i; - continue; - } - - if (put_delimiters && i != the_range.get_begin()) { - *inserter++ = delimiter; - } - - *inserter++ = hex_chars[(ch >> 4) & 0x0f]; - *inserter++ = hex_chars[ch & 0x0f]; - } - if (show_ascii) // add ascii to last line - { - if (the_range.get_end() - the_range.get_begin() > size_per_line) { - auto blank_num = size_per_line - (the_range.get_end() - start_of_line); - while (blank_num-- > 0) { - *inserter++ = delimiter; - *inserter++ = delimiter; - if (put_delimiters) { - *inserter++ = delimiter; - } - } - } - *inserter++ = delimiter; - *inserter++ = delimiter; - for (auto j = start_of_line; j != the_range.get_end(); j++) { - auto pc = static_cast(*j); - *inserter++ = std::isprint(pc) ? static_cast(*j) : '.'; - } - } - return inserter; - } - - // put newline(and position header) - template - void put_newline(It inserter, std::size_t pos) const { -#ifdef _WIN32 - *inserter++ = '\r'; -#endif - *inserter++ = '\n'; - - if (put_positions) { - spdlog::fmt_lib::format_to(inserter, SPDLOG_FMT_STRING("{:04X}: "), pos); - } - } -}; -} // namespace std diff --git a/examples/blueprints-example/external/fmt/bundled/args.h b/examples/blueprints-example/external/fmt/bundled/args.h deleted file mode 100644 index 5e5f40f..0000000 --- a/examples/blueprints-example/external/fmt/bundled/args.h +++ /dev/null @@ -1,220 +0,0 @@ -// Formatting library for C++ - dynamic argument lists -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_ARGS_H_ -#define FMT_ARGS_H_ - -#ifndef FMT_MODULE -# include // std::reference_wrapper -# include // std::unique_ptr -# include -#endif - -#include "format.h" // std_string_view - -FMT_BEGIN_NAMESPACE -namespace detail { - -template struct is_reference_wrapper : std::false_type {}; -template -struct is_reference_wrapper> : std::true_type {}; - -template auto unwrap(const T& v) -> const T& { return v; } -template -auto unwrap(const std::reference_wrapper& v) -> const T& { - return static_cast(v); -} - -// node is defined outside dynamic_arg_list to workaround a C2504 bug in MSVC -// 2022 (v17.10.0). -// -// Workaround for clang's -Wweak-vtables. Unlike for regular classes, for -// templates it doesn't complain about inability to deduce single translation -// unit for placing vtable. So node is made a fake template. -template struct node { - virtual ~node() = default; - std::unique_ptr> next; -}; - -class dynamic_arg_list { - template struct typed_node : node<> { - T value; - - template - FMT_CONSTEXPR typed_node(const Arg& arg) : value(arg) {} - - template - FMT_CONSTEXPR typed_node(const basic_string_view& arg) - : value(arg.data(), arg.size()) {} - }; - - std::unique_ptr> head_; - - public: - template auto push(const Arg& arg) -> const T& { - auto new_node = std::unique_ptr>(new typed_node(arg)); - auto& value = new_node->value; - new_node->next = std::move(head_); - head_ = std::move(new_node); - return value; - } -}; -} // namespace detail - -/** - * A dynamic list of formatting arguments with storage. - * - * It can be implicitly converted into `fmt::basic_format_args` for passing - * into type-erased formatting functions such as `fmt::vformat`. - */ -FMT_EXPORT template class dynamic_format_arg_store { - private: - using char_type = typename Context::char_type; - - template struct need_copy { - static constexpr detail::type mapped_type = - detail::mapped_type_constant::value; - - enum { - value = !(detail::is_reference_wrapper::value || - std::is_same>::value || - std::is_same>::value || - (mapped_type != detail::type::cstring_type && - mapped_type != detail::type::string_type && - mapped_type != detail::type::custom_type)) - }; - }; - - template - using stored_t = conditional_t< - std::is_convertible>::value && - !detail::is_reference_wrapper::value, - std::basic_string, T>; - - // Storage of basic_format_arg must be contiguous. - std::vector> data_; - std::vector> named_info_; - - // Storage of arguments not fitting into basic_format_arg must grow - // without relocation because items in data_ refer to it. - detail::dynamic_arg_list dynamic_args_; - - friend class basic_format_args; - - auto data() const -> const basic_format_arg* { - return named_info_.empty() ? data_.data() : data_.data() + 1; - } - - template void emplace_arg(const T& arg) { - data_.emplace_back(arg); - } - - template - void emplace_arg(const detail::named_arg& arg) { - if (named_info_.empty()) - data_.insert(data_.begin(), basic_format_arg(nullptr, 0)); - data_.emplace_back(detail::unwrap(arg.value)); - auto pop_one = [](std::vector>* data) { - data->pop_back(); - }; - std::unique_ptr>, decltype(pop_one)> - guard{&data_, pop_one}; - named_info_.push_back({arg.name, static_cast(data_.size() - 2u)}); - data_[0] = {named_info_.data(), named_info_.size()}; - guard.release(); - } - - public: - constexpr dynamic_format_arg_store() = default; - - operator basic_format_args() const { - return basic_format_args(data(), static_cast(data_.size()), - !named_info_.empty()); - } - - /** - * Adds an argument into the dynamic store for later passing to a formatting - * function. - * - * Note that custom types and string types (but not string views) are copied - * into the store dynamically allocating memory if necessary. - * - * **Example**: - * - * fmt::dynamic_format_arg_store store; - * store.push_back(42); - * store.push_back("abc"); - * store.push_back(1.5f); - * std::string result = fmt::vformat("{} and {} and {}", store); - */ - template void push_back(const T& arg) { - if (detail::const_check(need_copy::value)) - emplace_arg(dynamic_args_.push>(arg)); - else - emplace_arg(detail::unwrap(arg)); - } - - /** - * Adds a reference to the argument into the dynamic store for later passing - * to a formatting function. - * - * **Example**: - * - * fmt::dynamic_format_arg_store store; - * char band[] = "Rolling Stones"; - * store.push_back(std::cref(band)); - * band[9] = 'c'; // Changing str affects the output. - * std::string result = fmt::vformat("{}", store); - * // result == "Rolling Scones" - */ - template void push_back(std::reference_wrapper arg) { - static_assert( - need_copy::value, - "objects of built-in types and string views are always copied"); - emplace_arg(arg.get()); - } - - /** - * Adds named argument into the dynamic store for later passing to a - * formatting function. `std::reference_wrapper` is supported to avoid - * copying of the argument. The name is always copied into the store. - */ - template - void push_back(const detail::named_arg& arg) { - const char_type* arg_name = - dynamic_args_.push>(arg.name).c_str(); - if (detail::const_check(need_copy::value)) { - emplace_arg( - fmt::arg(arg_name, dynamic_args_.push>(arg.value))); - } else { - emplace_arg(fmt::arg(arg_name, arg.value)); - } - } - - /// Erase all elements from the store. - void clear() { - data_.clear(); - named_info_.clear(); - dynamic_args_ = {}; - } - - /// Reserves space to store at least `new_cap` arguments including - /// `new_cap_named` named arguments. - void reserve(size_t new_cap, size_t new_cap_named) { - FMT_ASSERT(new_cap >= new_cap_named, - "set of arguments includes set of named arguments"); - data_.reserve(new_cap); - named_info_.reserve(new_cap_named); - } - - /// Returns the number of elements in the store. - auto size() const noexcept -> size_t { return data_.size(); } -}; - -FMT_END_NAMESPACE - -#endif // FMT_ARGS_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/base.h b/examples/blueprints-example/external/fmt/bundled/base.h deleted file mode 100644 index 42e192a..0000000 --- a/examples/blueprints-example/external/fmt/bundled/base.h +++ /dev/null @@ -1,2994 +0,0 @@ -// Formatting library for C++ - the base API for char/UTF-8 -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_BASE_H_ -#define FMT_BASE_H_ - -#if defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) -# define FMT_MODULE -#endif - -#ifndef FMT_MODULE -# include // CHAR_BIT -# include // FILE -# include // memcmp - -# include // std::enable_if -#endif - -// The fmt library version in the form major * 10000 + minor * 100 + patch. -#define FMT_VERSION 120000 - -// Detect compiler versions. -#if defined(__clang__) && !defined(__ibmxl__) -# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) -#else -# define FMT_CLANG_VERSION 0 -#endif -#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) -# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) -#else -# define FMT_GCC_VERSION 0 -#endif -#if defined(__ICL) -# define FMT_ICC_VERSION __ICL -#elif defined(__INTEL_COMPILER) -# define FMT_ICC_VERSION __INTEL_COMPILER -#else -# define FMT_ICC_VERSION 0 -#endif -#if defined(_MSC_VER) -# define FMT_MSC_VERSION _MSC_VER -#else -# define FMT_MSC_VERSION 0 -#endif - -// Detect standard library versions. -#ifdef _GLIBCXX_RELEASE -# define FMT_GLIBCXX_RELEASE _GLIBCXX_RELEASE -#else -# define FMT_GLIBCXX_RELEASE 0 -#endif -#ifdef _LIBCPP_VERSION -# define FMT_LIBCPP_VERSION _LIBCPP_VERSION -#else -# define FMT_LIBCPP_VERSION 0 -#endif - -#ifdef _MSVC_LANG -# define FMT_CPLUSPLUS _MSVC_LANG -#else -# define FMT_CPLUSPLUS __cplusplus -#endif - -// Detect __has_*. -#ifdef __has_feature -# define FMT_HAS_FEATURE(x) __has_feature(x) -#else -# define FMT_HAS_FEATURE(x) 0 -#endif -#ifdef __has_include -# define FMT_HAS_INCLUDE(x) __has_include(x) -#else -# define FMT_HAS_INCLUDE(x) 0 -#endif -#ifdef __has_builtin -# define FMT_HAS_BUILTIN(x) __has_builtin(x) -#else -# define FMT_HAS_BUILTIN(x) 0 -#endif -#ifdef __has_cpp_attribute -# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#else -# define FMT_HAS_CPP_ATTRIBUTE(x) 0 -#endif - -#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \ - (FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute)) - -#define FMT_HAS_CPP17_ATTRIBUTE(attribute) \ - (FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute)) - -// Detect C++14 relaxed constexpr. -#ifdef FMT_USE_CONSTEXPR -// Use the provided definition. -#elif FMT_GCC_VERSION >= 702 && FMT_CPLUSPLUS >= 201402L -// GCC only allows constexpr member functions in non-literal types since 7.2: -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66297. -# define FMT_USE_CONSTEXPR 1 -#elif FMT_ICC_VERSION -# define FMT_USE_CONSTEXPR 0 // https://github.com/fmtlib/fmt/issues/1628 -#elif FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VERSION >= 1912 -# define FMT_USE_CONSTEXPR 1 -#else -# define FMT_USE_CONSTEXPR 0 -#endif -#if FMT_USE_CONSTEXPR -# define FMT_CONSTEXPR constexpr -#else -# define FMT_CONSTEXPR -#endif - -// Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated. -#if !defined(__cpp_lib_is_constant_evaluated) -# define FMT_USE_CONSTEVAL 0 -#elif FMT_CPLUSPLUS < 201709L -# define FMT_USE_CONSTEVAL 0 -#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10 -# define FMT_USE_CONSTEVAL 0 -#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000 -# define FMT_USE_CONSTEVAL 0 -#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L -# define FMT_USE_CONSTEVAL 0 // consteval is broken in Apple clang < 14. -#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929 -# define FMT_USE_CONSTEVAL 0 // consteval is broken in MSVC VS2019 < 16.10. -#elif defined(__cpp_consteval) -# define FMT_USE_CONSTEVAL 1 -#elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101 -# define FMT_USE_CONSTEVAL 1 -#else -# define FMT_USE_CONSTEVAL 0 -#endif -#if FMT_USE_CONSTEVAL -# define FMT_CONSTEVAL consteval -# define FMT_CONSTEXPR20 constexpr -#else -# define FMT_CONSTEVAL -# define FMT_CONSTEXPR20 -#endif - -// Check if exceptions are disabled. -#ifdef FMT_USE_EXCEPTIONS -// Use the provided definition. -#elif defined(__GNUC__) && !defined(__EXCEPTIONS) -# define FMT_USE_EXCEPTIONS 0 -#elif defined(__clang__) && !defined(__cpp_exceptions) -# define FMT_USE_EXCEPTIONS 0 -#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS -# define FMT_USE_EXCEPTIONS 0 -#else -# define FMT_USE_EXCEPTIONS 1 -#endif -#if FMT_USE_EXCEPTIONS -# define FMT_TRY try -# define FMT_CATCH(x) catch (x) -#else -# define FMT_TRY if (true) -# define FMT_CATCH(x) if (false) -#endif - -#ifdef FMT_NO_UNIQUE_ADDRESS -// Use the provided definition. -#elif FMT_CPLUSPLUS < 202002L -// Not supported. -#elif FMT_HAS_CPP_ATTRIBUTE(no_unique_address) -# define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]] -// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485). -#elif FMT_MSC_VERSION >= 1929 && !FMT_CLANG_VERSION -# define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -#endif -#ifndef FMT_NO_UNIQUE_ADDRESS -# define FMT_NO_UNIQUE_ADDRESS -#endif - -#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough) -# define FMT_FALLTHROUGH [[fallthrough]] -#elif defined(__clang__) -# define FMT_FALLTHROUGH [[clang::fallthrough]] -#elif FMT_GCC_VERSION >= 700 && \ - (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520) -# define FMT_FALLTHROUGH [[gnu::fallthrough]] -#else -# define FMT_FALLTHROUGH -#endif - -// Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings. -#if FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && !defined(__NVCC__) -# define FMT_NORETURN [[noreturn]] -#else -# define FMT_NORETURN -#endif - -#ifdef FMT_NODISCARD -// Use the provided definition. -#elif FMT_HAS_CPP17_ATTRIBUTE(nodiscard) -# define FMT_NODISCARD [[nodiscard]] -#else -# define FMT_NODISCARD -#endif - -#if FMT_GCC_VERSION || FMT_CLANG_VERSION -# define FMT_VISIBILITY(value) __attribute__((visibility(value))) -#else -# define FMT_VISIBILITY(value) -#endif - -// Detect pragmas. -#define FMT_PRAGMA_IMPL(x) _Pragma(#x) -#if FMT_GCC_VERSION >= 504 && !defined(__NVCOMPILER) -// Workaround a _Pragma bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59884 -// and an nvhpc warning: https://github.com/fmtlib/fmt/pull/2582. -# define FMT_PRAGMA_GCC(x) FMT_PRAGMA_IMPL(GCC x) -#else -# define FMT_PRAGMA_GCC(x) -#endif -#if FMT_CLANG_VERSION -# define FMT_PRAGMA_CLANG(x) FMT_PRAGMA_IMPL(clang x) -#else -# define FMT_PRAGMA_CLANG(x) -#endif -#if FMT_MSC_VERSION -# define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__)) -#else -# define FMT_MSC_WARNING(...) -#endif - -// Enable minimal optimizations for more compact code in debug mode. -FMT_PRAGMA_GCC(push_options) -#if !defined(__OPTIMIZE__) && !defined(__CUDACC__) && !defined(FMT_MODULE) -FMT_PRAGMA_GCC(optimize("Og")) -# define FMT_GCC_OPTIMIZED -#endif -FMT_PRAGMA_CLANG(diagnostic push) - -#ifdef FMT_ALWAYS_INLINE -// Use the provided definition. -#elif FMT_GCC_VERSION || FMT_CLANG_VERSION -# define FMT_ALWAYS_INLINE inline __attribute__((always_inline)) -#else -# define FMT_ALWAYS_INLINE inline -#endif -// A version of FMT_ALWAYS_INLINE to prevent code bloat in debug mode. -#if defined(NDEBUG) || defined(FMT_GCC_OPTIMIZED) -# define FMT_INLINE FMT_ALWAYS_INLINE -#else -# define FMT_INLINE inline -#endif - -#ifndef FMT_BEGIN_NAMESPACE -# define FMT_BEGIN_NAMESPACE \ - namespace fmt { \ - inline namespace v12 { -# define FMT_END_NAMESPACE \ - } \ - } -#endif - -#ifndef FMT_EXPORT -# define FMT_EXPORT -# define FMT_BEGIN_EXPORT -# define FMT_END_EXPORT -#endif - -#ifdef _WIN32 -# define FMT_WIN32 1 -#else -# define FMT_WIN32 0 -#endif - -#if !defined(FMT_HEADER_ONLY) && FMT_WIN32 -# if defined(FMT_LIB_EXPORT) -# define FMT_API __declspec(dllexport) -# elif defined(FMT_SHARED) -# define FMT_API __declspec(dllimport) -# endif -#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED) -# define FMT_API FMT_VISIBILITY("default") -#endif -#ifndef FMT_API -# define FMT_API -#endif - -#ifndef FMT_OPTIMIZE_SIZE -# define FMT_OPTIMIZE_SIZE 0 -#endif - -// FMT_BUILTIN_TYPE=0 may result in smaller library size at the cost of higher -// per-call binary size by passing built-in types through the extension API. -#ifndef FMT_BUILTIN_TYPES -# define FMT_BUILTIN_TYPES 1 -#endif - -#define FMT_APPLY_VARIADIC(expr) \ - using unused = int[]; \ - (void)unused { 0, (expr, 0)... } - -FMT_BEGIN_NAMESPACE - -// Implementations of enable_if_t and other metafunctions for older systems. -template -using enable_if_t = typename std::enable_if::type; -template -using conditional_t = typename std::conditional::type; -template using bool_constant = std::integral_constant; -template -using remove_reference_t = typename std::remove_reference::type; -template -using remove_const_t = typename std::remove_const::type; -template -using remove_cvref_t = typename std::remove_cv>::type; -template -using make_unsigned_t = typename std::make_unsigned::type; -template -using underlying_t = typename std::underlying_type::type; -template using decay_t = typename std::decay::type; -using nullptr_t = decltype(nullptr); - -#if (FMT_GCC_VERSION && FMT_GCC_VERSION < 500) || FMT_MSC_VERSION -// A workaround for gcc 4.9 & MSVC v141 to make void_t work in a SFINAE context. -template struct void_t_impl { - using type = void; -}; -template using void_t = typename void_t_impl::type; -#else -template using void_t = void; -#endif - -struct monostate { - constexpr monostate() {} -}; - -// An enable_if helper to be used in template parameters which results in much -// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed -// to workaround a bug in MSVC 2019 (see #1140 and #1186). -#ifdef FMT_DOC -# define FMT_ENABLE_IF(...) -#else -# define FMT_ENABLE_IF(...) fmt::enable_if_t<(__VA_ARGS__), int> = 0 -#endif - -template constexpr auto min_of(T a, T b) -> T { - return a < b ? a : b; -} -template constexpr auto max_of(T a, T b) -> T { - return a > b ? a : b; -} - -FMT_NORETURN FMT_API void assert_fail(const char* file, int line, - const char* message); - -namespace detail { -// Suppresses "unused variable" warnings with the method described in -// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/. -// (void)var does not work on many Intel compilers. -template FMT_CONSTEXPR void ignore_unused(const T&...) {} - -constexpr auto is_constant_evaluated(bool default_value = false) noexcept - -> bool { -// Workaround for incompatibility between clang 14 and libstdc++ consteval-based -// std::is_constant_evaluated: https://github.com/fmtlib/fmt/issues/3247. -#if FMT_CPLUSPLUS >= 202002L && FMT_GLIBCXX_RELEASE >= 12 && \ - (FMT_CLANG_VERSION >= 1400 && FMT_CLANG_VERSION < 1500) - ignore_unused(default_value); - return __builtin_is_constant_evaluated(); -#elif defined(__cpp_lib_is_constant_evaluated) - ignore_unused(default_value); - return std::is_constant_evaluated(); -#else - return default_value; -#endif -} - -// Suppresses "conditional expression is constant" warnings. -template FMT_ALWAYS_INLINE constexpr auto const_check(T val) -> T { - return val; -} - -FMT_NORETURN FMT_API void assert_fail(const char* file, int line, - const char* message); - -#if defined(FMT_ASSERT) -// Use the provided definition. -#elif defined(NDEBUG) -// FMT_ASSERT is not empty to avoid -Wempty-body. -# define FMT_ASSERT(condition, message) \ - fmt::detail::ignore_unused((condition), (message)) -#else -# define FMT_ASSERT(condition, message) \ - ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \ - ? (void)0 \ - : ::fmt::assert_fail(__FILE__, __LINE__, (message))) -#endif - -#ifdef FMT_USE_INT128 -// Use the provided definition. -#elif defined(__SIZEOF_INT128__) && !defined(__NVCC__) && \ - !(FMT_CLANG_VERSION && FMT_MSC_VERSION) -# define FMT_USE_INT128 1 -using int128_opt = __int128_t; // An optional native 128-bit integer. -using uint128_opt = __uint128_t; -inline auto map(int128_opt x) -> int128_opt { return x; } -inline auto map(uint128_opt x) -> uint128_opt { return x; } -#else -# define FMT_USE_INT128 0 -#endif -#if !FMT_USE_INT128 -enum class int128_opt {}; -enum class uint128_opt {}; -// Reduce template instantiations. -inline auto map(int128_opt) -> monostate { return {}; } -inline auto map(uint128_opt) -> monostate { return {}; } -#endif - -#ifndef FMT_USE_BITINT -# define FMT_USE_BITINT (FMT_CLANG_VERSION >= 1500) -#endif - -#if FMT_USE_BITINT -FMT_PRAGMA_CLANG(diagnostic ignored "-Wbit-int-extension") -template using bitint = _BitInt(N); -template using ubitint = unsigned _BitInt(N); -#else -template struct bitint {}; -template struct ubitint {}; -#endif // FMT_USE_BITINT - -// Casts a nonnegative integer to unsigned. -template -FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t { - FMT_ASSERT(std::is_unsigned::value || value >= 0, "negative value"); - return static_cast>(value); -} - -template -using unsigned_char = conditional_t; - -// A heuristic to detect std::string and std::[experimental::]string_view. -// It is mainly used to avoid dependency on <[experimental/]string_view>. -template -struct is_std_string_like : std::false_type {}; -template -struct is_std_string_like().find_first_of( - typename T::value_type(), 0))>> - : std::is_convertible().data()), - const typename T::value_type*> {}; - -// Check if the literal encoding is UTF-8. -enum { is_utf8_enabled = "\u00A7"[1] == '\xA7' }; -enum { use_utf8 = !FMT_WIN32 || is_utf8_enabled }; - -#ifndef FMT_UNICODE -# define FMT_UNICODE 1 -#endif - -static_assert(!FMT_UNICODE || use_utf8, - "Unicode support requires compiling with /utf-8"); - -template constexpr auto narrow(T*) -> char* { return nullptr; } -constexpr FMT_ALWAYS_INLINE auto narrow(const char* s) -> const char* { - return s; -} - -template -FMT_CONSTEXPR auto compare(const Char* s1, const Char* s2, size_t n) -> int { - if (!is_constant_evaluated() && sizeof(Char) == 1) return memcmp(s1, s2, n); - for (; n != 0; ++s1, ++s2, --n) { - if (*s1 < *s2) return -1; - if (*s1 > *s2) return 1; - } - return 0; -} - -namespace adl { -using namespace std; - -template -auto invoke_back_inserter() - -> decltype(back_inserter(std::declval())); -} // namespace adl - -template -struct is_back_insert_iterator : std::false_type {}; - -template -struct is_back_insert_iterator< - It, bool_constant()), - It>::value>> : std::true_type {}; - -// Extracts a reference to the container from *insert_iterator. -template -inline FMT_CONSTEXPR20 auto get_container(OutputIt it) -> - typename OutputIt::container_type& { - struct accessor : OutputIt { - FMT_CONSTEXPR20 accessor(OutputIt base) : OutputIt(base) {} - using OutputIt::container; - }; - return *accessor(it).container; -} -} // namespace detail - -// Parsing-related public API and forward declarations. -FMT_BEGIN_EXPORT - -/** - * An implementation of `std::basic_string_view` for pre-C++17. It provides a - * subset of the API. `fmt::basic_string_view` is used for format strings even - * if `std::basic_string_view` is available to prevent issues when a library is - * compiled with a different `-std` option than the client code (which is not - * recommended). - */ -template class basic_string_view { - private: - const Char* data_; - size_t size_; - - public: - using value_type = Char; - using iterator = const Char*; - - constexpr basic_string_view() noexcept : data_(nullptr), size_(0) {} - - /// Constructs a string view object from a C string and a size. - constexpr basic_string_view(const Char* s, size_t count) noexcept - : data_(s), size_(count) {} - - constexpr basic_string_view(nullptr_t) = delete; - - /// Constructs a string view object from a C string. -#if FMT_GCC_VERSION - FMT_ALWAYS_INLINE -#endif - FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) { -#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION - if (std::is_same::value && !detail::is_constant_evaluated()) { - size_ = __builtin_strlen(detail::narrow(s)); // strlen is not constexpr. - return; - } -#endif - size_t len = 0; - while (*s++) ++len; - size_ = len; - } - - /// Constructs a string view from a `std::basic_string` or a - /// `std::basic_string_view` object. - template ::value&& std::is_same< - typename S::value_type, Char>::value)> - FMT_CONSTEXPR basic_string_view(const S& s) noexcept - : data_(s.data()), size_(s.size()) {} - - /// Returns a pointer to the string data. - constexpr auto data() const noexcept -> const Char* { return data_; } - - /// Returns the string size. - constexpr auto size() const noexcept -> size_t { return size_; } - - constexpr auto begin() const noexcept -> iterator { return data_; } - constexpr auto end() const noexcept -> iterator { return data_ + size_; } - - constexpr auto operator[](size_t pos) const noexcept -> const Char& { - return data_[pos]; - } - - FMT_CONSTEXPR void remove_prefix(size_t n) noexcept { - data_ += n; - size_ -= n; - } - - FMT_CONSTEXPR auto starts_with(basic_string_view sv) const noexcept - -> bool { - return size_ >= sv.size_ && detail::compare(data_, sv.data_, sv.size_) == 0; - } - FMT_CONSTEXPR auto starts_with(Char c) const noexcept -> bool { - return size_ >= 1 && *data_ == c; - } - FMT_CONSTEXPR auto starts_with(const Char* s) const -> bool { - return starts_with(basic_string_view(s)); - } - - FMT_CONSTEXPR auto compare(basic_string_view other) const -> int { - int result = - detail::compare(data_, other.data_, min_of(size_, other.size_)); - if (result != 0) return result; - return size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1); - } - - FMT_CONSTEXPR friend auto operator==(basic_string_view lhs, - basic_string_view rhs) -> bool { - return lhs.compare(rhs) == 0; - } - friend auto operator!=(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) != 0; - } - friend auto operator<(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) < 0; - } - friend auto operator<=(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) <= 0; - } - friend auto operator>(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) > 0; - } - friend auto operator>=(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) >= 0; - } -}; - -using string_view = basic_string_view; - -template class basic_appender; -using appender = basic_appender; - -// Checks whether T is a container with contiguous storage. -template struct is_contiguous : std::false_type {}; - -class context; -template class generic_context; -template class parse_context; - -// Longer aliases for C++20 compatibility. -template using basic_format_parse_context = parse_context; -using format_parse_context = parse_context; -template -using basic_format_context = - conditional_t::value, context, - generic_context>; -using format_context = context; - -template -using buffered_context = - conditional_t::value, context, - generic_context, Char>>; - -template class basic_format_arg; -template class basic_format_args; - -// A separate type would result in shorter symbols but break ABI compatibility -// between clang and gcc on ARM (#1919). -using format_args = basic_format_args; - -// A formatter for objects of type T. -template -struct formatter { - // A deleted default constructor indicates a disabled formatter. - formatter() = delete; -}; - -/// Reports a format error at compile time or, via a `format_error` exception, -/// at runtime. -// This function is intentionally not constexpr to give a compile-time error. -FMT_NORETURN FMT_API void report_error(const char* message); - -enum class presentation_type : unsigned char { - // Common specifiers: - none = 0, - debug = 1, // '?' - string = 2, // 's' (string, bool) - - // Integral, bool and character specifiers: - dec = 3, // 'd' - hex, // 'x' or 'X' - oct, // 'o' - bin, // 'b' or 'B' - chr, // 'c' - - // String and pointer specifiers: - pointer = 3, // 'p' - - // Floating-point specifiers: - exp = 1, // 'e' or 'E' (1 since there is no FP debug presentation) - fixed, // 'f' or 'F' - general, // 'g' or 'G' - hexfloat // 'a' or 'A' -}; - -enum class align { none, left, right, center, numeric }; -enum class sign { none, minus, plus, space }; -enum class arg_id_kind { none, index, name }; - -// Basic format specifiers for built-in and string types. -class basic_specs { - private: - // Data is arranged as follows: - // - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // |type |align| w | p | s |u|#|L| f | unused | - // +-----+-----+---+---+---+-+-+-+-----+---------------------------+ - // - // w - dynamic width info - // p - dynamic precision info - // s - sign - // u - uppercase (e.g. 'X' for 'x') - // # - alternate form ('#') - // L - localized - // f - fill size - // - // Bitfields are not used because of compiler bugs such as gcc bug 61414. - enum : unsigned { - type_mask = 0x00007, - align_mask = 0x00038, - width_mask = 0x000C0, - precision_mask = 0x00300, - sign_mask = 0x00C00, - uppercase_mask = 0x01000, - alternate_mask = 0x02000, - localized_mask = 0x04000, - fill_size_mask = 0x38000, - - align_shift = 3, - width_shift = 6, - precision_shift = 8, - sign_shift = 10, - fill_size_shift = 15, - - max_fill_size = 4 - }; - - unsigned data_ = 1 << fill_size_shift; - static_assert(sizeof(basic_specs::data_) * CHAR_BIT >= 18, ""); - - // Character (code unit) type is erased to prevent template bloat. - char fill_data_[max_fill_size] = {' '}; - - FMT_CONSTEXPR void set_fill_size(size_t size) { - data_ = (data_ & ~fill_size_mask) | - (static_cast(size) << fill_size_shift); - } - - public: - constexpr auto type() const -> presentation_type { - return static_cast(data_ & type_mask); - } - FMT_CONSTEXPR void set_type(presentation_type t) { - data_ = (data_ & ~type_mask) | static_cast(t); - } - - constexpr auto align() const -> align { - return static_cast((data_ & align_mask) >> align_shift); - } - FMT_CONSTEXPR void set_align(fmt::align a) { - data_ = (data_ & ~align_mask) | (static_cast(a) << align_shift); - } - - constexpr auto dynamic_width() const -> arg_id_kind { - return static_cast((data_ & width_mask) >> width_shift); - } - FMT_CONSTEXPR void set_dynamic_width(arg_id_kind w) { - data_ = (data_ & ~width_mask) | (static_cast(w) << width_shift); - } - - FMT_CONSTEXPR auto dynamic_precision() const -> arg_id_kind { - return static_cast((data_ & precision_mask) >> - precision_shift); - } - FMT_CONSTEXPR void set_dynamic_precision(arg_id_kind p) { - data_ = (data_ & ~precision_mask) | - (static_cast(p) << precision_shift); - } - - constexpr auto dynamic() const -> bool { - return (data_ & (width_mask | precision_mask)) != 0; - } - - constexpr auto sign() const -> sign { - return static_cast((data_ & sign_mask) >> sign_shift); - } - FMT_CONSTEXPR void set_sign(fmt::sign s) { - data_ = (data_ & ~sign_mask) | (static_cast(s) << sign_shift); - } - - constexpr auto upper() const -> bool { return (data_ & uppercase_mask) != 0; } - FMT_CONSTEXPR void set_upper() { data_ |= uppercase_mask; } - - constexpr auto alt() const -> bool { return (data_ & alternate_mask) != 0; } - FMT_CONSTEXPR void set_alt() { data_ |= alternate_mask; } - FMT_CONSTEXPR void clear_alt() { data_ &= ~alternate_mask; } - - constexpr auto localized() const -> bool { - return (data_ & localized_mask) != 0; - } - FMT_CONSTEXPR void set_localized() { data_ |= localized_mask; } - - constexpr auto fill_size() const -> size_t { - return (data_ & fill_size_mask) >> fill_size_shift; - } - - template ::value)> - constexpr auto fill() const -> const Char* { - return fill_data_; - } - template ::value)> - constexpr auto fill() const -> const Char* { - return nullptr; - } - - template constexpr auto fill_unit() const -> Char { - using uchar = unsigned char; - return static_cast(static_cast(fill_data_[0]) | - (static_cast(fill_data_[1]) << 8) | - (static_cast(fill_data_[2]) << 16)); - } - - FMT_CONSTEXPR void set_fill(char c) { - fill_data_[0] = c; - set_fill_size(1); - } - - template - FMT_CONSTEXPR void set_fill(basic_string_view s) { - auto size = s.size(); - set_fill_size(size); - if (size == 1) { - unsigned uchar = static_cast>(s[0]); - fill_data_[0] = static_cast(uchar); - fill_data_[1] = static_cast(uchar >> 8); - fill_data_[2] = static_cast(uchar >> 16); - return; - } - FMT_ASSERT(size <= max_fill_size, "invalid fill"); - for (size_t i = 0; i < size; ++i) - fill_data_[i & 3] = static_cast(s[i]); - } - - FMT_CONSTEXPR void copy_fill_from(const basic_specs& specs) { - set_fill_size(specs.fill_size()); - for (size_t i = 0; i < max_fill_size; ++i) - fill_data_[i] = specs.fill_data_[i]; - } -}; - -// Format specifiers for built-in and string types. -struct format_specs : basic_specs { - int width; - int precision; - - constexpr format_specs() : width(0), precision(-1) {} -}; - -/** - * Parsing context consisting of a format string range being parsed and an - * argument counter for automatic indexing. - */ -template class parse_context { - private: - basic_string_view fmt_; - int next_arg_id_; - - enum { use_constexpr_cast = !FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200 }; - - FMT_CONSTEXPR void do_check_arg_id(int arg_id); - - public: - using char_type = Char; - using iterator = const Char*; - - constexpr explicit parse_context(basic_string_view fmt, - int next_arg_id = 0) - : fmt_(fmt), next_arg_id_(next_arg_id) {} - - /// Returns an iterator to the beginning of the format string range being - /// parsed. - constexpr auto begin() const noexcept -> iterator { return fmt_.begin(); } - - /// Returns an iterator past the end of the format string range being parsed. - constexpr auto end() const noexcept -> iterator { return fmt_.end(); } - - /// Advances the begin iterator to `it`. - FMT_CONSTEXPR void advance_to(iterator it) { - fmt_.remove_prefix(detail::to_unsigned(it - begin())); - } - - /// Reports an error if using the manual argument indexing; otherwise returns - /// the next argument index and switches to the automatic indexing. - FMT_CONSTEXPR auto next_arg_id() -> int { - if (next_arg_id_ < 0) { - report_error("cannot switch from manual to automatic argument indexing"); - return 0; - } - int id = next_arg_id_++; - do_check_arg_id(id); - return id; - } - - /// Reports an error if using the automatic argument indexing; otherwise - /// switches to the manual indexing. - FMT_CONSTEXPR void check_arg_id(int id) { - if (next_arg_id_ > 0) { - report_error("cannot switch from automatic to manual argument indexing"); - return; - } - next_arg_id_ = -1; - do_check_arg_id(id); - } - FMT_CONSTEXPR void check_arg_id(basic_string_view) { - next_arg_id_ = -1; - } - FMT_CONSTEXPR void check_dynamic_spec(int arg_id); -}; - -#ifndef FMT_USE_LOCALE -# define FMT_USE_LOCALE (FMT_OPTIMIZE_SIZE <= 1) -#endif - -// A type-erased reference to std::locale to avoid the heavy include. -class locale_ref { -#if FMT_USE_LOCALE - private: - const void* locale_; // A type-erased pointer to std::locale. - - public: - constexpr locale_ref() : locale_(nullptr) {} - - template - locale_ref(const Locale& loc); - - inline explicit operator bool() const noexcept { return locale_ != nullptr; } -#endif // FMT_USE_LOCALE - - public: - template auto get() const -> Locale; -}; - -FMT_END_EXPORT - -namespace detail { - -// Specifies if `T` is a code unit type. -template struct is_code_unit : std::false_type {}; -template <> struct is_code_unit : std::true_type {}; -template <> struct is_code_unit : std::true_type {}; -template <> struct is_code_unit : std::true_type {}; -template <> struct is_code_unit : std::true_type {}; -#ifdef __cpp_char8_t -template <> struct is_code_unit : bool_constant {}; -#endif - -// Constructs fmt::basic_string_view from types implicitly convertible -// to it, deducing Char. Explicitly convertible types such as the ones returned -// from FMT_STRING are intentionally excluded. -template ::value)> -constexpr auto to_string_view(const Char* s) -> basic_string_view { - return s; -} -template ::value)> -constexpr auto to_string_view(const T& s) - -> basic_string_view { - return s; -} -template -constexpr auto to_string_view(basic_string_view s) - -> basic_string_view { - return s; -} - -template -struct has_to_string_view : std::false_type {}; -// detail:: is intentional since to_string_view is not an extension point. -template -struct has_to_string_view< - T, void_t()))>> - : std::true_type {}; - -/// String's character (code unit) type. detail:: is intentional to prevent ADL. -template ()))> -using char_t = typename V::value_type; - -enum class type { - none_type, - // Integer types should go first, - int_type, - uint_type, - long_long_type, - ulong_long_type, - int128_type, - uint128_type, - bool_type, - char_type, - last_integer_type = char_type, - // followed by floating-point types. - float_type, - double_type, - long_double_type, - last_numeric_type = long_double_type, - cstring_type, - string_type, - pointer_type, - custom_type -}; - -// Maps core type T to the corresponding type enum constant. -template -struct type_constant : std::integral_constant {}; - -#define FMT_TYPE_CONSTANT(Type, constant) \ - template \ - struct type_constant \ - : std::integral_constant {} - -FMT_TYPE_CONSTANT(int, int_type); -FMT_TYPE_CONSTANT(unsigned, uint_type); -FMT_TYPE_CONSTANT(long long, long_long_type); -FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type); -FMT_TYPE_CONSTANT(int128_opt, int128_type); -FMT_TYPE_CONSTANT(uint128_opt, uint128_type); -FMT_TYPE_CONSTANT(bool, bool_type); -FMT_TYPE_CONSTANT(Char, char_type); -FMT_TYPE_CONSTANT(float, float_type); -FMT_TYPE_CONSTANT(double, double_type); -FMT_TYPE_CONSTANT(long double, long_double_type); -FMT_TYPE_CONSTANT(const Char*, cstring_type); -FMT_TYPE_CONSTANT(basic_string_view, string_type); -FMT_TYPE_CONSTANT(const void*, pointer_type); - -constexpr auto is_integral_type(type t) -> bool { - return t > type::none_type && t <= type::last_integer_type; -} -constexpr auto is_arithmetic_type(type t) -> bool { - return t > type::none_type && t <= type::last_numeric_type; -} - -constexpr auto set(type rhs) -> int { return 1 << static_cast(rhs); } -constexpr auto in(type t, int set) -> bool { - return ((set >> static_cast(t)) & 1) != 0; -} - -// Bitsets of types. -enum { - sint_set = - set(type::int_type) | set(type::long_long_type) | set(type::int128_type), - uint_set = set(type::uint_type) | set(type::ulong_long_type) | - set(type::uint128_type), - bool_set = set(type::bool_type), - char_set = set(type::char_type), - float_set = set(type::float_type) | set(type::double_type) | - set(type::long_double_type), - string_set = set(type::string_type), - cstring_set = set(type::cstring_type), - pointer_set = set(type::pointer_type) -}; - -struct view {}; - -template -struct is_view : std::false_type {}; -template -struct is_view> : std::is_base_of {}; - -template struct named_arg; -template struct is_named_arg : std::false_type {}; -template struct is_static_named_arg : std::false_type {}; - -template -struct is_named_arg> : std::true_type {}; - -template struct named_arg : view { - const Char* name; - const T& value; - - named_arg(const Char* n, const T& v) : name(n), value(v) {} - static_assert(!is_named_arg::value, "nested named arguments"); -}; - -template constexpr auto count() -> int { return B ? 1 : 0; } -template constexpr auto count() -> int { - return (B1 ? 1 : 0) + count(); -} - -template constexpr auto count_named_args() -> int { - return count::value...>(); -} -template constexpr auto count_static_named_args() -> int { - return count::value...>(); -} - -template struct named_arg_info { - const Char* name; - int id; -}; - -// named_args is non-const to suppress a bogus -Wmaybe-uninitialized in gcc 13. -template -FMT_CONSTEXPR void check_for_duplicate(named_arg_info* named_args, - int named_arg_index, - basic_string_view arg_name) { - for (int i = 0; i < named_arg_index; ++i) { - if (named_args[i].name == arg_name) report_error("duplicate named arg"); - } -} - -template ::value)> -void init_named_arg(named_arg_info*, int& arg_index, int&, const T&) { - ++arg_index; -} -template ::value)> -void init_named_arg(named_arg_info* named_args, int& arg_index, - int& named_arg_index, const T& arg) { - check_for_duplicate(named_args, named_arg_index, arg.name); - named_args[named_arg_index++] = {arg.name, arg_index++}; -} - -template ::value)> -FMT_CONSTEXPR void init_static_named_arg(named_arg_info*, int& arg_index, - int&) { - ++arg_index; -} -template ::value)> -FMT_CONSTEXPR void init_static_named_arg(named_arg_info* named_args, - int& arg_index, int& named_arg_index) { - check_for_duplicate(named_args, named_arg_index, T::name); - named_args[named_arg_index++] = {T::name, arg_index++}; -} - -// To minimize the number of types we need to deal with, long is translated -// either to int or to long long depending on its size. -enum { long_short = sizeof(long) == sizeof(int) && FMT_BUILTIN_TYPES }; -using long_type = conditional_t; -using ulong_type = conditional_t; - -template -using format_as_result = - remove_cvref_t()))>; -template -using format_as_member_result = - remove_cvref_t::format_as(std::declval()))>; - -template -struct use_format_as : std::false_type {}; -// format_as member is only used to avoid injection into the std namespace. -template -struct use_format_as_member : std::false_type {}; - -// Only map owning types because mapping views can be unsafe. -template -struct use_format_as< - T, bool_constant>::value>> - : std::true_type {}; -template -struct use_format_as_member< - T, bool_constant>::value>> - : std::true_type {}; - -template > -using use_formatter = - bool_constant<(std::is_class::value || std::is_enum::value || - std::is_union::value || std::is_array::value) && - !has_to_string_view::value && !is_named_arg::value && - !use_format_as::value && !use_format_as_member::value>; - -template > -auto has_formatter_impl(T* p, buffered_context* ctx = nullptr) - -> decltype(formatter().format(*p, *ctx), std::true_type()); -template auto has_formatter_impl(...) -> std::false_type; - -// T can be const-qualified to check if it is const-formattable. -template constexpr auto has_formatter() -> bool { - return decltype(has_formatter_impl(static_cast(nullptr)))::value; -} - -// Maps formatting argument types to natively supported types or user-defined -// types with formatters. Returns void on errors to be SFINAE-friendly. -template struct type_mapper { - static auto map(signed char) -> int; - static auto map(unsigned char) -> unsigned; - static auto map(short) -> int; - static auto map(unsigned short) -> unsigned; - static auto map(int) -> int; - static auto map(unsigned) -> unsigned; - static auto map(long) -> long_type; - static auto map(unsigned long) -> ulong_type; - static auto map(long long) -> long long; - static auto map(unsigned long long) -> unsigned long long; - static auto map(int128_opt) -> int128_opt; - static auto map(uint128_opt) -> uint128_opt; - static auto map(bool) -> bool; - - template - static auto map(bitint) -> conditional_t; - template - static auto map(ubitint) - -> conditional_t; - - template ::value)> - static auto map(T) -> conditional_t< - std::is_same::value || std::is_same::value, Char, void>; - - static auto map(float) -> float; - static auto map(double) -> double; - static auto map(long double) -> long double; - - static auto map(Char*) -> const Char*; - static auto map(const Char*) -> const Char*; - template , - FMT_ENABLE_IF(!std::is_pointer::value)> - static auto map(const T&) -> conditional_t::value, - basic_string_view, void>; - - static auto map(void*) -> const void*; - static auto map(const void*) -> const void*; - static auto map(volatile void*) -> const void*; - static auto map(const volatile void*) -> const void*; - static auto map(nullptr_t) -> const void*; - template ::value || - std::is_member_pointer::value)> - static auto map(const T&) -> void; - - template ::value)> - static auto map(const T& x) -> decltype(map(format_as(x))); - template ::value)> - static auto map(const T& x) -> decltype(map(formatter::format_as(x))); - - template ::value)> - static auto map(T&) -> conditional_t(), T&, void>; - - template ::value)> - static auto map(const T& named_arg) -> decltype(map(named_arg.value)); -}; - -// detail:: is used to workaround a bug in MSVC 2017. -template -using mapped_t = decltype(detail::type_mapper::map(std::declval())); - -// A type constant after applying type_mapper. -template -using mapped_type_constant = type_constant, Char>; - -template ::value> -using stored_type_constant = std::integral_constant< - type, Context::builtin_types || TYPE == type::int_type ? TYPE - : type::custom_type>; -// A parse context with extra data used only in compile-time checks. -template -class compile_parse_context : public parse_context { - private: - int num_args_; - const type* types_; - using base = parse_context; - - public: - FMT_CONSTEXPR explicit compile_parse_context(basic_string_view fmt, - int num_args, const type* types, - int next_arg_id = 0) - : base(fmt, next_arg_id), num_args_(num_args), types_(types) {} - - constexpr auto num_args() const -> int { return num_args_; } - constexpr auto arg_type(int id) const -> type { return types_[id]; } - - FMT_CONSTEXPR auto next_arg_id() -> int { - int id = base::next_arg_id(); - if (id >= num_args_) report_error("argument not found"); - return id; - } - - FMT_CONSTEXPR void check_arg_id(int id) { - base::check_arg_id(id); - if (id >= num_args_) report_error("argument not found"); - } - using base::check_arg_id; - - FMT_CONSTEXPR void check_dynamic_spec(int arg_id) { - ignore_unused(arg_id); - if (arg_id < num_args_ && types_ && !is_integral_type(types_[arg_id])) - report_error("width/precision is not integer"); - } -}; - -// An argument reference. -template union arg_ref { - FMT_CONSTEXPR arg_ref(int idx = 0) : index(idx) {} - FMT_CONSTEXPR arg_ref(basic_string_view n) : name(n) {} - - int index; - basic_string_view name; -}; - -// Format specifiers with width and precision resolved at formatting rather -// than parsing time to allow reusing the same parsed specifiers with -// different sets of arguments (precompilation of format strings). -template struct dynamic_format_specs : format_specs { - arg_ref width_ref; - arg_ref precision_ref; -}; - -// Converts a character to ASCII. Returns '\0' on conversion failure. -template ::value)> -constexpr auto to_ascii(Char c) -> char { - return c <= 0xff ? static_cast(c) : '\0'; -} - -// Returns the number of code units in a code point or 1 on error. -template -FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int { - if (const_check(sizeof(Char) != 1)) return 1; - auto c = static_cast(*begin); - return static_cast((0x3a55000000000000ull >> (2 * (c >> 3))) & 3) + 1; -} - -// Parses the range [begin, end) as an unsigned integer. This function assumes -// that the range is non-empty and the first character is a digit. -template -FMT_CONSTEXPR auto parse_nonnegative_int(const Char*& begin, const Char* end, - int error_value) noexcept -> int { - FMT_ASSERT(begin != end && '0' <= *begin && *begin <= '9', ""); - unsigned value = 0, prev = 0; - auto p = begin; - do { - prev = value; - value = value * 10 + unsigned(*p - '0'); - ++p; - } while (p != end && '0' <= *p && *p <= '9'); - auto num_digits = p - begin; - begin = p; - int digits10 = static_cast(sizeof(int) * CHAR_BIT * 3 / 10); - if (num_digits <= digits10) return static_cast(value); - // Check for overflow. - unsigned max = INT_MAX; - return num_digits == digits10 + 1 && - prev * 10ull + unsigned(p[-1] - '0') <= max - ? static_cast(value) - : error_value; -} - -FMT_CONSTEXPR inline auto parse_align(char c) -> align { - switch (c) { - case '<': return align::left; - case '>': return align::right; - case '^': return align::center; - } - return align::none; -} - -template constexpr auto is_name_start(Char c) -> bool { - return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_'; -} - -template -FMT_CONSTEXPR auto parse_arg_id(const Char* begin, const Char* end, - Handler&& handler) -> const Char* { - Char c = *begin; - if (c >= '0' && c <= '9') { - int index = 0; - if (c != '0') - index = parse_nonnegative_int(begin, end, INT_MAX); - else - ++begin; - if (begin == end || (*begin != '}' && *begin != ':')) - report_error("invalid format string"); - else - handler.on_index(index); - return begin; - } - if (FMT_OPTIMIZE_SIZE > 1 || !is_name_start(c)) { - report_error("invalid format string"); - return begin; - } - auto it = begin; - do { - ++it; - } while (it != end && (is_name_start(*it) || ('0' <= *it && *it <= '9'))); - handler.on_name({begin, to_unsigned(it - begin)}); - return it; -} - -template struct dynamic_spec_handler { - parse_context& ctx; - arg_ref& ref; - arg_id_kind& kind; - - FMT_CONSTEXPR void on_index(int id) { - ref = id; - kind = arg_id_kind::index; - ctx.check_arg_id(id); - ctx.check_dynamic_spec(id); - } - FMT_CONSTEXPR void on_name(basic_string_view id) { - ref = id; - kind = arg_id_kind::name; - ctx.check_arg_id(id); - } -}; - -template struct parse_dynamic_spec_result { - const Char* end; - arg_id_kind kind; -}; - -// Parses integer | "{" [arg_id] "}". -template -FMT_CONSTEXPR auto parse_dynamic_spec(const Char* begin, const Char* end, - int& value, arg_ref& ref, - parse_context& ctx) - -> parse_dynamic_spec_result { - FMT_ASSERT(begin != end, ""); - auto kind = arg_id_kind::none; - if ('0' <= *begin && *begin <= '9') { - int val = parse_nonnegative_int(begin, end, -1); - if (val == -1) report_error("number is too big"); - value = val; - } else { - if (*begin == '{') { - ++begin; - if (begin != end) { - Char c = *begin; - if (c == '}' || c == ':') { - int id = ctx.next_arg_id(); - ref = id; - kind = arg_id_kind::index; - ctx.check_dynamic_spec(id); - } else { - begin = parse_arg_id(begin, end, - dynamic_spec_handler{ctx, ref, kind}); - } - } - if (begin != end && *begin == '}') return {++begin, kind}; - } - report_error("invalid format string"); - } - return {begin, kind}; -} - -template -FMT_CONSTEXPR auto parse_width(const Char* begin, const Char* end, - format_specs& specs, arg_ref& width_ref, - parse_context& ctx) -> const Char* { - auto result = parse_dynamic_spec(begin, end, specs.width, width_ref, ctx); - specs.set_dynamic_width(result.kind); - return result.end; -} - -template -FMT_CONSTEXPR auto parse_precision(const Char* begin, const Char* end, - format_specs& specs, - arg_ref& precision_ref, - parse_context& ctx) -> const Char* { - ++begin; - if (begin == end) { - report_error("invalid precision"); - return begin; - } - auto result = - parse_dynamic_spec(begin, end, specs.precision, precision_ref, ctx); - specs.set_dynamic_precision(result.kind); - return result.end; -} - -enum class state { start, align, sign, hash, zero, width, precision, locale }; - -// Parses standard format specifiers. -template -FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end, - dynamic_format_specs& specs, - parse_context& ctx, type arg_type) - -> const Char* { - auto c = '\0'; - if (end - begin > 1) { - auto next = to_ascii(begin[1]); - c = parse_align(next) == align::none ? to_ascii(*begin) : '\0'; - } else { - if (begin == end) return begin; - c = to_ascii(*begin); - } - - struct { - state current_state = state::start; - FMT_CONSTEXPR void operator()(state s, bool valid = true) { - if (current_state >= s || !valid) - report_error("invalid format specifier"); - current_state = s; - } - } enter_state; - - using pres = presentation_type; - constexpr auto integral_set = sint_set | uint_set | bool_set | char_set; - struct { - const Char*& begin; - format_specs& specs; - type arg_type; - - FMT_CONSTEXPR auto operator()(pres pres_type, int set) -> const Char* { - if (!in(arg_type, set)) report_error("invalid format specifier"); - specs.set_type(pres_type); - return begin + 1; - } - } parse_presentation_type{begin, specs, arg_type}; - - for (;;) { - switch (c) { - case '<': - case '>': - case '^': - enter_state(state::align); - specs.set_align(parse_align(c)); - ++begin; - break; - case '+': - case ' ': - specs.set_sign(c == ' ' ? sign::space : sign::plus); - FMT_FALLTHROUGH; - case '-': - enter_state(state::sign, in(arg_type, sint_set | float_set)); - ++begin; - break; - case '#': - enter_state(state::hash, is_arithmetic_type(arg_type)); - specs.set_alt(); - ++begin; - break; - case '0': - enter_state(state::zero); - if (!is_arithmetic_type(arg_type)) - report_error("format specifier requires numeric argument"); - if (specs.align() == align::none) { - // Ignore 0 if align is specified for compatibility with std::format. - specs.set_align(align::numeric); - specs.set_fill('0'); - } - ++begin; - break; - // clang-format off - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': case '{': - // clang-format on - enter_state(state::width); - begin = parse_width(begin, end, specs, specs.width_ref, ctx); - break; - case '.': - enter_state(state::precision, - in(arg_type, float_set | string_set | cstring_set)); - begin = parse_precision(begin, end, specs, specs.precision_ref, ctx); - break; - case 'L': - enter_state(state::locale, is_arithmetic_type(arg_type)); - specs.set_localized(); - ++begin; - break; - case 'd': return parse_presentation_type(pres::dec, integral_set); - case 'X': specs.set_upper(); FMT_FALLTHROUGH; - case 'x': return parse_presentation_type(pres::hex, integral_set); - case 'o': return parse_presentation_type(pres::oct, integral_set); - case 'B': specs.set_upper(); FMT_FALLTHROUGH; - case 'b': return parse_presentation_type(pres::bin, integral_set); - case 'E': specs.set_upper(); FMT_FALLTHROUGH; - case 'e': return parse_presentation_type(pres::exp, float_set); - case 'F': specs.set_upper(); FMT_FALLTHROUGH; - case 'f': return parse_presentation_type(pres::fixed, float_set); - case 'G': specs.set_upper(); FMT_FALLTHROUGH; - case 'g': return parse_presentation_type(pres::general, float_set); - case 'A': specs.set_upper(); FMT_FALLTHROUGH; - case 'a': return parse_presentation_type(pres::hexfloat, float_set); - case 'c': - if (arg_type == type::bool_type) report_error("invalid format specifier"); - return parse_presentation_type(pres::chr, integral_set); - case 's': - return parse_presentation_type(pres::string, - bool_set | string_set | cstring_set); - case 'p': - return parse_presentation_type(pres::pointer, pointer_set | cstring_set); - case '?': - return parse_presentation_type(pres::debug, - char_set | string_set | cstring_set); - case '}': return begin; - default: { - if (*begin == '}') return begin; - // Parse fill and alignment. - auto fill_end = begin + code_point_length(begin); - if (end - fill_end <= 0) { - report_error("invalid format specifier"); - return begin; - } - if (*begin == '{') { - report_error("invalid fill character '{'"); - return begin; - } - auto alignment = parse_align(to_ascii(*fill_end)); - enter_state(state::align, alignment != align::none); - specs.set_fill( - basic_string_view(begin, to_unsigned(fill_end - begin))); - specs.set_align(alignment); - begin = fill_end + 1; - } - } - if (begin == end) return begin; - c = to_ascii(*begin); - } -} - -template -FMT_CONSTEXPR FMT_INLINE auto parse_replacement_field(const Char* begin, - const Char* end, - Handler&& handler) - -> const Char* { - ++begin; - if (begin == end) { - handler.on_error("invalid format string"); - return end; - } - int arg_id = 0; - switch (*begin) { - case '}': - handler.on_replacement_field(handler.on_arg_id(), begin); - return begin + 1; - case '{': handler.on_text(begin, begin + 1); return begin + 1; - case ':': arg_id = handler.on_arg_id(); break; - default: { - struct id_adapter { - Handler& handler; - int arg_id; - - FMT_CONSTEXPR void on_index(int id) { arg_id = handler.on_arg_id(id); } - FMT_CONSTEXPR void on_name(basic_string_view id) { - arg_id = handler.on_arg_id(id); - } - } adapter = {handler, 0}; - begin = parse_arg_id(begin, end, adapter); - arg_id = adapter.arg_id; - Char c = begin != end ? *begin : Char(); - if (c == '}') { - handler.on_replacement_field(arg_id, begin); - return begin + 1; - } - if (c != ':') { - handler.on_error("missing '}' in format string"); - return end; - } - break; - } - } - begin = handler.on_format_specs(arg_id, begin + 1, end); - if (begin == end || *begin != '}') - return handler.on_error("unknown format specifier"), end; - return begin + 1; -} - -template -FMT_CONSTEXPR void parse_format_string(basic_string_view fmt, - Handler&& handler) { - auto begin = fmt.data(), end = begin + fmt.size(); - auto p = begin; - while (p != end) { - auto c = *p++; - if (c == '{') { - handler.on_text(begin, p - 1); - begin = p = parse_replacement_field(p - 1, end, handler); - } else if (c == '}') { - if (p == end || *p != '}') - return handler.on_error("unmatched '}' in format string"); - handler.on_text(begin, p); - begin = ++p; - } - } - handler.on_text(begin, end); -} - -// Checks char specs and returns true iff the presentation type is char-like. -FMT_CONSTEXPR inline auto check_char_specs(const format_specs& specs) -> bool { - auto type = specs.type(); - if (type != presentation_type::none && type != presentation_type::chr && - type != presentation_type::debug) { - return false; - } - if (specs.align() == align::numeric || specs.sign() != sign::none || - specs.alt()) { - report_error("invalid format specifier for char"); - } - return true; -} - -// A base class for compile-time strings. -struct compile_string {}; - -template -FMT_VISIBILITY("hidden") // Suppress an ld warning on macOS (#3769). -FMT_CONSTEXPR auto invoke_parse(parse_context& ctx) -> const Char* { - using mapped_type = remove_cvref_t>; - constexpr bool formattable = - std::is_constructible>::value; - if (!formattable) return ctx.begin(); // Error is reported in the value ctor. - using formatted_type = conditional_t; - return formatter().parse(ctx); -} - -template struct arg_pack {}; - -template -class format_string_checker { - private: - type types_[max_of(1, NUM_ARGS)]; - named_arg_info named_args_[max_of(1, NUM_NAMED_ARGS)]; - compile_parse_context context_; - - using parse_func = auto (*)(parse_context&) -> const Char*; - parse_func parse_funcs_[max_of(1, NUM_ARGS)]; - - public: - template - FMT_CONSTEXPR explicit format_string_checker(basic_string_view fmt, - arg_pack) - : types_{mapped_type_constant::value...}, - named_args_{}, - context_(fmt, NUM_ARGS, types_), - parse_funcs_{&invoke_parse...} { - int arg_index = 0, named_arg_index = 0; - FMT_APPLY_VARIADIC( - init_static_named_arg(named_args_, arg_index, named_arg_index)); - ignore_unused(arg_index, named_arg_index); - } - - FMT_CONSTEXPR void on_text(const Char*, const Char*) {} - - FMT_CONSTEXPR auto on_arg_id() -> int { return context_.next_arg_id(); } - FMT_CONSTEXPR auto on_arg_id(int id) -> int { - context_.check_arg_id(id); - return id; - } - FMT_CONSTEXPR auto on_arg_id(basic_string_view id) -> int { - for (int i = 0; i < NUM_NAMED_ARGS; ++i) { - if (named_args_[i].name == id) return named_args_[i].id; - } - if (!DYNAMIC_NAMES) on_error("argument not found"); - return -1; - } - - FMT_CONSTEXPR void on_replacement_field(int id, const Char* begin) { - on_format_specs(id, begin, begin); // Call parse() on empty specs. - } - - FMT_CONSTEXPR auto on_format_specs(int id, const Char* begin, const Char* end) - -> const Char* { - context_.advance_to(begin); - if (id >= 0 && id < NUM_ARGS) return parse_funcs_[id](context_); - - // If id is out of range, it means we do not know the type and cannot parse - // the format at compile time. Instead, skip over content until we finish - // the format spec, accounting for any nested replacements. - for (int bracket_count = 0; - begin != end && (bracket_count > 0 || *begin != '}'); ++begin) { - if (*begin == '{') - ++bracket_count; - else if (*begin == '}') - --bracket_count; - } - return begin; - } - - FMT_NORETURN FMT_CONSTEXPR void on_error(const char* message) { - report_error(message); - } -}; - -/// A contiguous memory buffer with an optional growing ability. It is an -/// internal class and shouldn't be used directly, only via `memory_buffer`. -template class buffer { - private: - T* ptr_; - size_t size_; - size_t capacity_; - - using grow_fun = void (*)(buffer& buf, size_t capacity); - grow_fun grow_; - - protected: - // Don't initialize ptr_ since it is not accessed to save a few cycles. - FMT_MSC_WARNING(suppress : 26495) - FMT_CONSTEXPR buffer(grow_fun grow, size_t sz) noexcept - : size_(sz), capacity_(sz), grow_(grow) {} - - constexpr buffer(grow_fun grow, T* p = nullptr, size_t sz = 0, - size_t cap = 0) noexcept - : ptr_(p), size_(sz), capacity_(cap), grow_(grow) {} - - FMT_CONSTEXPR20 ~buffer() = default; - buffer(buffer&&) = default; - - /// Sets the buffer data and capacity. - FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept { - ptr_ = buf_data; - capacity_ = buf_capacity; - } - - public: - using value_type = T; - using const_reference = const T&; - - buffer(const buffer&) = delete; - void operator=(const buffer&) = delete; - - auto begin() noexcept -> T* { return ptr_; } - auto end() noexcept -> T* { return ptr_ + size_; } - - auto begin() const noexcept -> const T* { return ptr_; } - auto end() const noexcept -> const T* { return ptr_ + size_; } - - /// Returns the size of this buffer. - constexpr auto size() const noexcept -> size_t { return size_; } - - /// Returns the capacity of this buffer. - constexpr auto capacity() const noexcept -> size_t { return capacity_; } - - /// Returns a pointer to the buffer data (not null-terminated). - FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; } - FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; } - - /// Clears this buffer. - FMT_CONSTEXPR void clear() { size_ = 0; } - - // Tries resizing the buffer to contain `count` elements. If T is a POD type - // the new elements may not be initialized. - FMT_CONSTEXPR void try_resize(size_t count) { - try_reserve(count); - size_ = min_of(count, capacity_); - } - - // Tries increasing the buffer capacity to `new_capacity`. It can increase the - // capacity by a smaller amount than requested but guarantees there is space - // for at least one additional element either by increasing the capacity or by - // flushing the buffer if it is full. - FMT_CONSTEXPR void try_reserve(size_t new_capacity) { - if (new_capacity > capacity_) grow_(*this, new_capacity); - } - - FMT_CONSTEXPR void push_back(const T& value) { - try_reserve(size_ + 1); - ptr_[size_++] = value; - } - - /// Appends data to the end of the buffer. - template -// Workaround for MSVC2019 to fix error C2893: Failed to specialize function -// template 'void fmt::v11::detail::buffer::append(const U *,const U *)'. -#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1940 - FMT_CONSTEXPR20 -#endif - void - append(const U* begin, const U* end) { - while (begin != end) { - auto count = to_unsigned(end - begin); - try_reserve(size_ + count); - auto free_cap = capacity_ - size_; - if (free_cap < count) count = free_cap; - // A loop is faster than memcpy on small sizes. - T* out = ptr_ + size_; - for (size_t i = 0; i < count; ++i) out[i] = begin[i]; - size_ += count; - begin += count; - } - } - - template FMT_CONSTEXPR auto operator[](Idx index) -> T& { - return ptr_[index]; - } - template - FMT_CONSTEXPR auto operator[](Idx index) const -> const T& { - return ptr_[index]; - } -}; - -struct buffer_traits { - constexpr explicit buffer_traits(size_t) {} - constexpr auto count() const -> size_t { return 0; } - constexpr auto limit(size_t size) const -> size_t { return size; } -}; - -class fixed_buffer_traits { - private: - size_t count_ = 0; - size_t limit_; - - public: - constexpr explicit fixed_buffer_traits(size_t limit) : limit_(limit) {} - constexpr auto count() const -> size_t { return count_; } - FMT_CONSTEXPR auto limit(size_t size) -> size_t { - size_t n = limit_ > count_ ? limit_ - count_ : 0; - count_ += size; - return min_of(size, n); - } -}; - -// A buffer that writes to an output iterator when flushed. -template -class iterator_buffer : public Traits, public buffer { - private: - OutputIt out_; - enum { buffer_size = 256 }; - T data_[buffer_size]; - - static FMT_CONSTEXPR void grow(buffer& buf, size_t) { - if (buf.size() == buffer_size) static_cast(buf).flush(); - } - - void flush() { - auto size = this->size(); - this->clear(); - const T* begin = data_; - const T* end = begin + this->limit(size); - while (begin != end) *out_++ = *begin++; - } - - public: - explicit iterator_buffer(OutputIt out, size_t n = buffer_size) - : Traits(n), buffer(grow, data_, 0, buffer_size), out_(out) {} - iterator_buffer(iterator_buffer&& other) noexcept - : Traits(other), - buffer(grow, data_, 0, buffer_size), - out_(other.out_) {} - ~iterator_buffer() { - // Don't crash if flush fails during unwinding. - FMT_TRY { flush(); } - FMT_CATCH(...) {} - } - - auto out() -> OutputIt { - flush(); - return out_; - } - auto count() const -> size_t { return Traits::count() + this->size(); } -}; - -template -class iterator_buffer : public fixed_buffer_traits, - public buffer { - private: - T* out_; - enum { buffer_size = 256 }; - T data_[buffer_size]; - - static FMT_CONSTEXPR void grow(buffer& buf, size_t) { - if (buf.size() == buf.capacity()) - static_cast(buf).flush(); - } - - void flush() { - size_t n = this->limit(this->size()); - if (this->data() == out_) { - out_ += n; - this->set(data_, buffer_size); - } - this->clear(); - } - - public: - explicit iterator_buffer(T* out, size_t n = buffer_size) - : fixed_buffer_traits(n), buffer(grow, out, 0, n), out_(out) {} - iterator_buffer(iterator_buffer&& other) noexcept - : fixed_buffer_traits(other), - buffer(static_cast(other)), - out_(other.out_) { - if (this->data() != out_) { - this->set(data_, buffer_size); - this->clear(); - } - } - ~iterator_buffer() { flush(); } - - auto out() -> T* { - flush(); - return out_; - } - auto count() const -> size_t { - return fixed_buffer_traits::count() + this->size(); - } -}; - -template class iterator_buffer : public buffer { - public: - explicit iterator_buffer(T* out, size_t = 0) - : buffer([](buffer&, size_t) {}, out, 0, ~size_t()) {} - - auto out() -> T* { return &*this->end(); } -}; - -template -class container_buffer : public buffer { - private: - using value_type = typename Container::value_type; - - static FMT_CONSTEXPR void grow(buffer& buf, size_t capacity) { - auto& self = static_cast(buf); - self.container.resize(capacity); - self.set(&self.container[0], capacity); - } - - public: - Container& container; - - explicit container_buffer(Container& c) - : buffer(grow, c.size()), container(c) {} -}; - -// A buffer that writes to a container with the contiguous storage. -template -class iterator_buffer< - OutputIt, - enable_if_t::value && - is_contiguous::value, - typename OutputIt::container_type::value_type>> - : public container_buffer { - private: - using base = container_buffer; - - public: - explicit iterator_buffer(typename OutputIt::container_type& c) : base(c) {} - explicit iterator_buffer(OutputIt out, size_t = 0) - : base(get_container(out)) {} - - auto out() -> OutputIt { return OutputIt(this->container); } -}; - -// A buffer that counts the number of code units written discarding the output. -template class counting_buffer : public buffer { - private: - enum { buffer_size = 256 }; - T data_[buffer_size]; - size_t count_ = 0; - - static FMT_CONSTEXPR void grow(buffer& buf, size_t) { - if (buf.size() != buffer_size) return; - static_cast(buf).count_ += buf.size(); - buf.clear(); - } - - public: - FMT_CONSTEXPR counting_buffer() : buffer(grow, data_, 0, buffer_size) {} - - constexpr auto count() const noexcept -> size_t { - return count_ + this->size(); - } -}; - -template -struct is_back_insert_iterator> : std::true_type {}; - -template -struct has_back_insert_iterator_container_append : std::false_type {}; -template -struct has_back_insert_iterator_container_append< - OutputIt, InputIt, - void_t()) - .append(std::declval(), - std::declval()))>> : std::true_type {}; - -template -struct has_back_insert_iterator_container_insert_at_end : std::false_type {}; - -template -struct has_back_insert_iterator_container_insert_at_end< - OutputIt, InputIt, - void_t()) - .insert(get_container(std::declval()).end(), - std::declval(), - std::declval()))>> : std::true_type {}; - -// An optimized version of std::copy with the output value type (T). -template ::value&& - has_back_insert_iterator_container_append< - OutputIt, InputIt>::value)> -FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out) - -> OutputIt { - get_container(out).append(begin, end); - return out; -} - -template ::value && - !has_back_insert_iterator_container_append< - OutputIt, InputIt>::value && - has_back_insert_iterator_container_insert_at_end< - OutputIt, InputIt>::value)> -FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out) - -> OutputIt { - auto& c = get_container(out); - c.insert(c.end(), begin, end); - return out; -} - -template ::value && - (has_back_insert_iterator_container_append< - OutputIt, InputIt>::value || - has_back_insert_iterator_container_insert_at_end< - OutputIt, InputIt>::value)))> -FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt { - while (begin != end) *out++ = static_cast(*begin++); - return out; -} - -template -FMT_CONSTEXPR auto copy(basic_string_view s, OutputIt out) -> OutputIt { - return copy(s.begin(), s.end(), out); -} - -template -struct is_buffer_appender : std::false_type {}; -template -struct is_buffer_appender< - It, bool_constant< - is_back_insert_iterator::value && - std::is_base_of, - typename It::container_type>::value>> - : std::true_type {}; - -// Maps an output iterator to a buffer. -template ::value)> -auto get_buffer(OutputIt out) -> iterator_buffer { - return iterator_buffer(out); -} -template ::value)> -auto get_buffer(OutputIt out) -> buffer& { - return get_container(out); -} - -template -auto get_iterator(Buf& buf, OutputIt) -> decltype(buf.out()) { - return buf.out(); -} -template -auto get_iterator(buffer&, OutputIt out) -> OutputIt { - return out; -} - -// This type is intentionally undefined, only used for errors. -template struct type_is_unformattable_for; - -template struct string_value { - const Char* data; - size_t size; - auto str() const -> basic_string_view { return {data, size}; } -}; - -template struct custom_value { - using char_type = typename Context::char_type; - void* value; - void (*format)(void* arg, parse_context& parse_ctx, Context& ctx); -}; - -template struct named_arg_value { - const named_arg_info* data; - size_t size; -}; - -struct custom_tag {}; - -#if !FMT_BUILTIN_TYPES -# define FMT_BUILTIN , monostate -#else -# define FMT_BUILTIN -#endif - -// A formatting argument value. -template class value { - public: - using char_type = typename Context::char_type; - - union { - monostate no_value; - int int_value; - unsigned uint_value; - long long long_long_value; - unsigned long long ulong_long_value; - int128_opt int128_value; - uint128_opt uint128_value; - bool bool_value; - char_type char_value; - float float_value; - double double_value; - long double long_double_value; - const void* pointer; - string_value string; - custom_value custom; - named_arg_value named_args; - }; - - constexpr FMT_INLINE value() : no_value() {} - constexpr FMT_INLINE value(signed char x) : int_value(x) {} - constexpr FMT_INLINE value(unsigned char x FMT_BUILTIN) : uint_value(x) {} - constexpr FMT_INLINE value(signed short x) : int_value(x) {} - constexpr FMT_INLINE value(unsigned short x FMT_BUILTIN) : uint_value(x) {} - constexpr FMT_INLINE value(int x) : int_value(x) {} - constexpr FMT_INLINE value(unsigned x FMT_BUILTIN) : uint_value(x) {} - FMT_CONSTEXPR FMT_INLINE value(long x FMT_BUILTIN) : value(long_type(x)) {} - FMT_CONSTEXPR FMT_INLINE value(unsigned long x FMT_BUILTIN) - : value(ulong_type(x)) {} - constexpr FMT_INLINE value(long long x FMT_BUILTIN) : long_long_value(x) {} - constexpr FMT_INLINE value(unsigned long long x FMT_BUILTIN) - : ulong_long_value(x) {} - FMT_INLINE value(int128_opt x FMT_BUILTIN) : int128_value(x) {} - FMT_INLINE value(uint128_opt x FMT_BUILTIN) : uint128_value(x) {} - constexpr FMT_INLINE value(bool x FMT_BUILTIN) : bool_value(x) {} - - template - constexpr FMT_INLINE value(bitint x FMT_BUILTIN) : long_long_value(x) { - static_assert(N <= 64, "unsupported _BitInt"); - } - template - constexpr FMT_INLINE value(ubitint x FMT_BUILTIN) : ulong_long_value(x) { - static_assert(N <= 64, "unsupported _BitInt"); - } - - template ::value)> - constexpr FMT_INLINE value(T x FMT_BUILTIN) : char_value(x) { - static_assert( - std::is_same::value || std::is_same::value, - "mixing character types is disallowed"); - } - - constexpr FMT_INLINE value(float x FMT_BUILTIN) : float_value(x) {} - constexpr FMT_INLINE value(double x FMT_BUILTIN) : double_value(x) {} - FMT_INLINE value(long double x FMT_BUILTIN) : long_double_value(x) {} - - FMT_CONSTEXPR FMT_INLINE value(char_type* x FMT_BUILTIN) { - string.data = x; - if (is_constant_evaluated()) string.size = 0; - } - FMT_CONSTEXPR FMT_INLINE value(const char_type* x FMT_BUILTIN) { - string.data = x; - if (is_constant_evaluated()) string.size = 0; - } - template , - FMT_ENABLE_IF(!std::is_pointer::value)> - FMT_CONSTEXPR value(const T& x FMT_BUILTIN) { - static_assert(std::is_same::value, - "mixing character types is disallowed"); - auto sv = to_string_view(x); - string.data = sv.data(); - string.size = sv.size(); - } - FMT_INLINE value(void* x FMT_BUILTIN) : pointer(x) {} - FMT_INLINE value(const void* x FMT_BUILTIN) : pointer(x) {} - FMT_INLINE value(volatile void* x FMT_BUILTIN) - : pointer(const_cast(x)) {} - FMT_INLINE value(const volatile void* x FMT_BUILTIN) - : pointer(const_cast(x)) {} - FMT_INLINE value(nullptr_t) : pointer(nullptr) {} - - template ::value || - std::is_member_pointer::value)> - value(const T&) { - // Formatting of arbitrary pointers is disallowed. If you want to format a - // pointer cast it to `void*` or `const void*`. In particular, this forbids - // formatting of `[const] volatile char*` printed as bool by iostreams. - static_assert(sizeof(T) == 0, - "formatting of non-void pointers is disallowed"); - } - - template ::value)> - value(const T& x) : value(format_as(x)) {} - template ::value)> - value(const T& x) : value(formatter::format_as(x)) {} - - template ::value)> - value(const T& named_arg) : value(named_arg.value) {} - - template ::value || !FMT_BUILTIN_TYPES)> - FMT_CONSTEXPR20 FMT_INLINE value(T& x) : value(x, custom_tag()) {} - - FMT_ALWAYS_INLINE value(const named_arg_info* args, size_t size) - : named_args{args, size} {} - - private: - template ())> - FMT_CONSTEXPR value(T& x, custom_tag) { - using value_type = remove_const_t; - // T may overload operator& e.g. std::vector::reference in libc++. - if (!is_constant_evaluated()) { - custom.value = - const_cast(&reinterpret_cast(x)); - } else { - custom.value = nullptr; -#if defined(__cpp_if_constexpr) - if constexpr (std::is_same*>::value) - custom.value = const_cast(&x); -#endif - } - custom.format = format_custom; - } - - template ())> - FMT_CONSTEXPR value(const T&, custom_tag) { - // Cannot format an argument; to make type T formattable provide a - // formatter specialization: https://fmt.dev/latest/api.html#udt. - type_is_unformattable_for _; - } - - // Formats an argument of a custom type, such as a user-defined class. - template - static void format_custom(void* arg, parse_context& parse_ctx, - Context& ctx) { - auto f = formatter(); - parse_ctx.advance_to(f.parse(parse_ctx)); - using qualified_type = - conditional_t(), const T, T>; - // format must be const for compatibility with std::format and compilation. - const auto& cf = f; - ctx.advance_to(cf.format(*static_cast(arg), ctx)); - } -}; - -enum { packed_arg_bits = 4 }; -// Maximum number of arguments with packed types. -enum { max_packed_args = 62 / packed_arg_bits }; -enum : unsigned long long { is_unpacked_bit = 1ULL << 63 }; -enum : unsigned long long { has_named_args_bit = 1ULL << 62 }; - -template -struct is_output_iterator : std::false_type {}; - -template <> struct is_output_iterator : std::true_type {}; - -template -struct is_output_iterator< - It, T, - enable_if_t&>()++), - T>::value>> : std::true_type {}; - -template constexpr auto encode_types() -> unsigned long long { - return 0; -} - -template -constexpr auto encode_types() -> unsigned long long { - return static_cast(stored_type_constant::value) | - (encode_types() << packed_arg_bits); -} - -template -constexpr auto make_descriptor() -> unsigned long long { - return NUM_ARGS <= max_packed_args ? encode_types() - : is_unpacked_bit | NUM_ARGS; -} - -template -using arg_t = conditional_t, - basic_format_arg>; - -template -struct named_arg_store { - // args_[0].named_args points to named_args to avoid bloating format_args. - arg_t args[1u + NUM_ARGS]; - named_arg_info - named_args[static_cast(NUM_NAMED_ARGS)]; - - template - FMT_CONSTEXPR FMT_ALWAYS_INLINE named_arg_store(T&... values) - : args{{named_args, NUM_NAMED_ARGS}, values...} { - int arg_index = 0, named_arg_index = 0; - FMT_APPLY_VARIADIC( - init_named_arg(named_args, arg_index, named_arg_index, values)); - } - - named_arg_store(named_arg_store&& rhs) { - args[0] = {named_args, NUM_NAMED_ARGS}; - for (size_t i = 1; i < sizeof(args) / sizeof(*args); ++i) - args[i] = rhs.args[i]; - for (size_t i = 0; i < NUM_NAMED_ARGS; ++i) - named_args[i] = rhs.named_args[i]; - } - - named_arg_store(const named_arg_store& rhs) = delete; - auto operator=(const named_arg_store& rhs) -> named_arg_store& = delete; - auto operator=(named_arg_store&& rhs) -> named_arg_store& = delete; - operator const arg_t*() const { return args + 1; } -}; - -// An array of references to arguments. It can be implicitly converted to -// `basic_format_args` for passing into type-erased formatting functions -// such as `vformat`. It is a plain struct to reduce binary size in debug mode. -template -struct format_arg_store { - // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning. - using type = - conditional_t[max_of(1, NUM_ARGS)], - named_arg_store>; - type args; -}; - -// TYPE can be different from type_constant, e.g. for __float128. -template struct native_formatter { - private: - dynamic_format_specs specs_; - - public: - using nonlocking = void; - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); - auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE); - if (const_check(TYPE == type::char_type)) check_char_specs(specs_); - return end; - } - - template - FMT_CONSTEXPR void set_debug_format(bool set = true) { - specs_.set_type(set ? presentation_type::debug : presentation_type::none); - } - - FMT_PRAGMA_CLANG(diagnostic ignored "-Wundefined-inline") - template - FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const - -> decltype(ctx.out()); -}; - -template -struct locking - : bool_constant::value == type::custom_type> {}; -template -struct locking>::nonlocking>> - : std::false_type {}; - -template FMT_CONSTEXPR inline auto is_locking() -> bool { - return locking::value; -} -template -FMT_CONSTEXPR inline auto is_locking() -> bool { - return locking::value || is_locking(); -} - -FMT_API void vformat_to(buffer& buf, string_view fmt, format_args args, - locale_ref loc = {}); - -#if FMT_WIN32 -FMT_API void vprint_mojibake(FILE*, string_view, format_args, bool); -#else // format_args is passed by reference since it is defined later. -inline void vprint_mojibake(FILE*, string_view, const format_args&, bool) {} -#endif -} // namespace detail - -// The main public API. - -template -FMT_CONSTEXPR void parse_context::do_check_arg_id(int arg_id) { - // Argument id is only checked at compile time during parsing because - // formatting has its own validation. - if (detail::is_constant_evaluated() && use_constexpr_cast) { - auto ctx = static_cast*>(this); - if (arg_id >= ctx->num_args()) report_error("argument not found"); - } -} - -template -FMT_CONSTEXPR void parse_context::check_dynamic_spec(int arg_id) { - using detail::compile_parse_context; - if (detail::is_constant_evaluated() && use_constexpr_cast) - static_cast*>(this)->check_dynamic_spec(arg_id); -} - -FMT_BEGIN_EXPORT - -// An output iterator that appends to a buffer. It is used instead of -// back_insert_iterator to reduce symbol sizes and avoid dependency. -template class basic_appender { - protected: - detail::buffer* container; - - public: - using container_type = detail::buffer; - - FMT_CONSTEXPR basic_appender(detail::buffer& buf) : container(&buf) {} - - FMT_CONSTEXPR20 auto operator=(T c) -> basic_appender& { - container->push_back(c); - return *this; - } - FMT_CONSTEXPR20 auto operator*() -> basic_appender& { return *this; } - FMT_CONSTEXPR20 auto operator++() -> basic_appender& { return *this; } - FMT_CONSTEXPR20 auto operator++(int) -> basic_appender { return *this; } -}; - -// A formatting argument. Context is a template parameter for the compiled API -// where output can be unbuffered. -template class basic_format_arg { - private: - detail::value value_; - detail::type type_; - - friend class basic_format_args; - - using char_type = typename Context::char_type; - - public: - class handle { - private: - detail::custom_value custom_; - - public: - explicit handle(detail::custom_value custom) : custom_(custom) {} - - void format(parse_context& parse_ctx, Context& ctx) const { - custom_.format(custom_.value, parse_ctx, ctx); - } - }; - - constexpr basic_format_arg() : type_(detail::type::none_type) {} - basic_format_arg(const detail::named_arg_info* args, size_t size) - : value_(args, size) {} - template - basic_format_arg(T&& val) - : value_(val), type_(detail::stored_type_constant::value) {} - - constexpr explicit operator bool() const noexcept { - return type_ != detail::type::none_type; - } - auto type() const -> detail::type { return type_; } - - /** - * Visits an argument dispatching to the appropriate visit method based on - * the argument type. For example, if the argument type is `double` then - * `vis(value)` will be called with the value of type `double`. - */ - template - FMT_CONSTEXPR FMT_INLINE auto visit(Visitor&& vis) const -> decltype(vis(0)) { - using detail::map; - switch (type_) { - case detail::type::none_type: break; - case detail::type::int_type: return vis(value_.int_value); - case detail::type::uint_type: return vis(value_.uint_value); - case detail::type::long_long_type: return vis(value_.long_long_value); - case detail::type::ulong_long_type: return vis(value_.ulong_long_value); - case detail::type::int128_type: return vis(map(value_.int128_value)); - case detail::type::uint128_type: return vis(map(value_.uint128_value)); - case detail::type::bool_type: return vis(value_.bool_value); - case detail::type::char_type: return vis(value_.char_value); - case detail::type::float_type: return vis(value_.float_value); - case detail::type::double_type: return vis(value_.double_value); - case detail::type::long_double_type: return vis(value_.long_double_value); - case detail::type::cstring_type: return vis(value_.string.data); - case detail::type::string_type: return vis(value_.string.str()); - case detail::type::pointer_type: return vis(value_.pointer); - case detail::type::custom_type: return vis(handle(value_.custom)); - } - return vis(monostate()); - } - - auto format_custom(const char_type* parse_begin, - parse_context& parse_ctx, Context& ctx) - -> bool { - if (type_ != detail::type::custom_type) return false; - parse_ctx.advance_to(parse_begin); - value_.custom.format(value_.custom.value, parse_ctx, ctx); - return true; - } -}; - -/** - * A view of a collection of formatting arguments. To avoid lifetime issues it - * should only be used as a parameter type in type-erased functions such as - * `vformat`: - * - * void vlog(fmt::string_view fmt, fmt::format_args args); // OK - * fmt::format_args args = fmt::make_format_args(); // Dangling reference - */ -template class basic_format_args { - private: - // A descriptor that contains information about formatting arguments. - // If the number of arguments is less or equal to max_packed_args then - // argument types are passed in the descriptor. This reduces binary code size - // per formatting function call. - unsigned long long desc_; - union { - // If is_packed() returns true then argument values are stored in values_; - // otherwise they are stored in args_. This is done to improve cache - // locality and reduce compiled code size since storing larger objects - // may require more code (at least on x86-64) even if the same amount of - // data is actually copied to stack. It saves ~10% on the bloat test. - const detail::value* values_; - const basic_format_arg* args_; - }; - - constexpr auto is_packed() const -> bool { - return (desc_ & detail::is_unpacked_bit) == 0; - } - constexpr auto has_named_args() const -> bool { - return (desc_ & detail::has_named_args_bit) != 0; - } - - FMT_CONSTEXPR auto type(int index) const -> detail::type { - int shift = index * detail::packed_arg_bits; - unsigned mask = (1 << detail::packed_arg_bits) - 1; - return static_cast((desc_ >> shift) & mask); - } - - template - using store = - detail::format_arg_store; - - public: - using format_arg = basic_format_arg; - - constexpr basic_format_args() : desc_(0), args_(nullptr) {} - - /// Constructs a `basic_format_args` object from `format_arg_store`. - template - constexpr FMT_ALWAYS_INLINE basic_format_args( - const store& s) - : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)), - values_(s.args) {} - - template detail::max_packed_args)> - constexpr basic_format_args(const store& s) - : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)), - args_(s.args) {} - - /// Constructs a `basic_format_args` object from a dynamic list of arguments. - constexpr basic_format_args(const format_arg* args, int count, - bool has_named = false) - : desc_(detail::is_unpacked_bit | detail::to_unsigned(count) | - (has_named ? +detail::has_named_args_bit : 0)), - args_(args) {} - - /// Returns the argument with the specified id. - FMT_CONSTEXPR auto get(int id) const -> format_arg { - auto arg = format_arg(); - if (!is_packed()) { - if (id < max_size()) arg = args_[id]; - return arg; - } - if (static_cast(id) >= detail::max_packed_args) return arg; - arg.type_ = type(id); - if (arg.type_ != detail::type::none_type) arg.value_ = values_[id]; - return arg; - } - - template - auto get(basic_string_view name) const -> format_arg { - int id = get_id(name); - return id >= 0 ? get(id) : format_arg(); - } - - template - FMT_CONSTEXPR auto get_id(basic_string_view name) const -> int { - if (!has_named_args()) return -1; - const auto& named_args = - (is_packed() ? values_[-1] : args_[-1].value_).named_args; - for (size_t i = 0; i < named_args.size; ++i) { - if (named_args.data[i].name == name) return named_args.data[i].id; - } - return -1; - } - - auto max_size() const -> int { - unsigned long long max_packed = detail::max_packed_args; - return static_cast(is_packed() ? max_packed - : desc_ & ~detail::is_unpacked_bit); - } -}; - -// A formatting context. -class context { - private: - appender out_; - format_args args_; - FMT_NO_UNIQUE_ADDRESS locale_ref loc_; - - public: - using char_type = char; ///< The character type for the output. - using iterator = appender; - using format_arg = basic_format_arg; - enum { builtin_types = FMT_BUILTIN_TYPES }; - - /// Constructs a `context` object. References to the arguments are stored - /// in the object so make sure they have appropriate lifetimes. - FMT_CONSTEXPR context(iterator out, format_args args, locale_ref loc = {}) - : out_(out), args_(args), loc_(loc) {} - context(context&&) = default; - context(const context&) = delete; - void operator=(const context&) = delete; - - FMT_CONSTEXPR auto arg(int id) const -> format_arg { return args_.get(id); } - inline auto arg(string_view name) const -> format_arg { - return args_.get(name); - } - FMT_CONSTEXPR auto arg_id(string_view name) const -> int { - return args_.get_id(name); - } - auto args() const -> const format_args& { return args_; } - - // Returns an iterator to the beginning of the output range. - FMT_CONSTEXPR auto out() const -> iterator { return out_; } - - // Advances the begin iterator to `it`. - FMT_CONSTEXPR void advance_to(iterator) {} - - FMT_CONSTEXPR auto locale() const -> locale_ref { return loc_; } -}; - -template struct runtime_format_string { - basic_string_view str; -}; - -/** - * Creates a runtime format string. - * - * **Example**: - * - * // Check format string at runtime instead of compile-time. - * fmt::print(fmt::runtime("{:d}"), "I am not a number"); - */ -inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; } - -/// A compile-time format string. Use `format_string` in the public API to -/// prevent type deduction. -template struct fstring { - private: - static constexpr int num_static_named_args = - detail::count_static_named_args(); - - using checker = detail::format_string_checker< - char, static_cast(sizeof...(T)), num_static_named_args, - num_static_named_args != detail::count_named_args()>; - - using arg_pack = detail::arg_pack; - - public: - string_view str; - using t = fstring; - - // Reports a compile-time error if S is not a valid format string for T. - template - FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const char (&s)[N]) : str(s, N - 1) { - using namespace detail; - static_assert(count<(is_view>::value && - std::is_reference::value)...>() == 0, - "passing views as lvalues is disallowed"); - if (FMT_USE_CONSTEVAL) parse_format_string(s, checker(s, arg_pack())); -#ifdef FMT_ENFORCE_COMPILE_STRING - static_assert( - FMT_USE_CONSTEVAL && sizeof(s) != 0, - "FMT_ENFORCE_COMPILE_STRING requires format strings to use FMT_STRING"); -#endif - } - template ::value)> - FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const S& s) : str(s) { - auto sv = string_view(str); - if (FMT_USE_CONSTEVAL) - detail::parse_format_string(sv, checker(sv, arg_pack())); -#ifdef FMT_ENFORCE_COMPILE_STRING - static_assert( - FMT_USE_CONSTEVAL && sizeof(s) != 0, - "FMT_ENFORCE_COMPILE_STRING requires format strings to use FMT_STRING"); -#endif - } - template ::value&& - std::is_same::value)> - FMT_ALWAYS_INLINE fstring(const S&) : str(S()) { - FMT_CONSTEXPR auto sv = string_view(S()); - FMT_CONSTEXPR int unused = - (parse_format_string(sv, checker(sv, arg_pack())), 0); - detail::ignore_unused(unused); - } - fstring(runtime_format_string<> fmt) : str(fmt.str) {} - - // Returning by reference generates better code in debug mode. - FMT_ALWAYS_INLINE operator const string_view&() const { return str; } - auto get() const -> string_view { return str; } -}; - -template using format_string = typename fstring::t; - -template -using is_formattable = bool_constant::value, int*, T>, Char>, - void>::value>; -#ifdef __cpp_concepts -template -concept formattable = is_formattable, Char>::value; -#endif - -// A formatter specialization for natively supported types. -template -struct formatter::value != - detail::type::custom_type>> - : detail::native_formatter::value> { -}; - -/** - * Constructs an object that stores references to arguments and can be - * implicitly converted to `format_args`. `Context` can be omitted in which case - * it defaults to `context`. See `arg` for lifetime considerations. - */ -// Take arguments by lvalue references to avoid some lifetime issues, e.g. -// auto args = make_format_args(std::string()); -template (), - unsigned long long DESC = detail::make_descriptor()> -constexpr FMT_ALWAYS_INLINE auto make_format_args(T&... args) - -> detail::format_arg_store { - // Suppress warnings for pathological types convertible to detail::value. - FMT_PRAGMA_GCC(diagnostic ignored "-Wconversion") - return {{args...}}; -} - -template -using vargs = - detail::format_arg_store(), - detail::make_descriptor()>; - -/** - * Returns a named argument to be used in a formatting function. - * It should only be used in a call to a formatting function. - * - * **Example**: - * - * fmt::print("The answer is {answer}.", fmt::arg("answer", 42)); - */ -template -inline auto arg(const Char* name, const T& arg) -> detail::named_arg { - return {name, arg}; -} - -/// Formats a string and writes the output to `out`. -template , - char>::value)> -auto vformat_to(OutputIt&& out, string_view fmt, format_args args) - -> remove_cvref_t { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, fmt, args, {}); - return detail::get_iterator(buf, out); -} - -/** - * Formats `args` according to specifications in `fmt`, writes the result to - * the output iterator `out` and returns the iterator past the end of the output - * range. `format_to` does not append a terminating null character. - * - * **Example**: - * - * auto out = std::vector(); - * fmt::format_to(std::back_inserter(out), "{}", 42); - */ -template , - char>::value)> -FMT_INLINE auto format_to(OutputIt&& out, format_string fmt, T&&... args) - -> remove_cvref_t { - return vformat_to(out, fmt.str, vargs{{args...}}); -} - -template struct format_to_n_result { - /// Iterator past the end of the output range. - OutputIt out; - /// Total (not truncated) output size. - size_t size; -}; - -template ::value)> -auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args) - -> format_to_n_result { - using traits = detail::fixed_buffer_traits; - auto buf = detail::iterator_buffer(out, n); - detail::vformat_to(buf, fmt, args, {}); - return {buf.out(), buf.count()}; -} - -/** - * Formats `args` according to specifications in `fmt`, writes up to `n` - * characters of the result to the output iterator `out` and returns the total - * (not truncated) output size and the iterator past the end of the output - * range. `format_to_n` does not append a terminating null character. - */ -template ::value)> -FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string fmt, - T&&... args) -> format_to_n_result { - return vformat_to_n(out, n, fmt.str, vargs{{args...}}); -} - -struct format_to_result { - /// Pointer to just after the last successful write in the array. - char* out; - /// Specifies if the output was truncated. - bool truncated; - - FMT_CONSTEXPR operator char*() const { - // Report truncation to prevent silent data loss. - if (truncated) report_error("output is truncated"); - return out; - } -}; - -template -auto vformat_to(char (&out)[N], string_view fmt, format_args args) - -> format_to_result { - auto result = vformat_to_n(out, N, fmt, args); - return {result.out, result.size > N}; -} - -template -FMT_INLINE auto format_to(char (&out)[N], format_string fmt, T&&... args) - -> format_to_result { - auto result = vformat_to_n(out, N, fmt.str, vargs{{args...}}); - return {result.out, result.size > N}; -} - -/// Returns the number of chars in the output of `format(fmt, args...)`. -template -FMT_NODISCARD FMT_INLINE auto formatted_size(format_string fmt, - T&&... args) -> size_t { - auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, fmt.str, vargs{{args...}}, {}); - return buf.count(); -} - -FMT_API void vprint(string_view fmt, format_args args); -FMT_API void vprint(FILE* f, string_view fmt, format_args args); -FMT_API void vprintln(FILE* f, string_view fmt, format_args args); -FMT_API void vprint_buffered(FILE* f, string_view fmt, format_args args); - -/** - * Formats `args` according to specifications in `fmt` and writes the output - * to `stdout`. - * - * **Example**: - * - * fmt::print("The answer is {}.", 42); - */ -template -FMT_INLINE void print(format_string fmt, T&&... args) { - vargs va = {{args...}}; - if (detail::const_check(!detail::use_utf8)) - return detail::vprint_mojibake(stdout, fmt.str, va, false); - return detail::is_locking() ? vprint_buffered(stdout, fmt.str, va) - : vprint(fmt.str, va); -} - -/** - * Formats `args` according to specifications in `fmt` and writes the - * output to the file `f`. - * - * **Example**: - * - * fmt::print(stderr, "Don't {}!", "panic"); - */ -template -FMT_INLINE void print(FILE* f, format_string fmt, T&&... args) { - vargs va = {{args...}}; - if (detail::const_check(!detail::use_utf8)) - return detail::vprint_mojibake(f, fmt.str, va, false); - return detail::is_locking() ? vprint_buffered(f, fmt.str, va) - : vprint(f, fmt.str, va); -} - -/// Formats `args` according to specifications in `fmt` and writes the output -/// to the file `f` followed by a newline. -template -FMT_INLINE void println(FILE* f, format_string fmt, T&&... args) { - vargs va = {{args...}}; - return detail::const_check(detail::use_utf8) - ? vprintln(f, fmt.str, va) - : detail::vprint_mojibake(f, fmt.str, va, true); -} - -/// Formats `args` according to specifications in `fmt` and writes the output -/// to `stdout` followed by a newline. -template -FMT_INLINE void println(format_string fmt, T&&... args) { - return fmt::println(stdout, fmt, static_cast(args)...); -} - -FMT_PRAGMA_CLANG(diagnostic pop) -FMT_PRAGMA_GCC(pop_options) -FMT_END_EXPORT -FMT_END_NAMESPACE - -#ifdef FMT_HEADER_ONLY -# include "format.h" -#endif -#endif // FMT_BASE_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/chrono.h b/examples/blueprints-example/external/fmt/bundled/chrono.h deleted file mode 100644 index a788d3e..0000000 --- a/examples/blueprints-example/external/fmt/bundled/chrono.h +++ /dev/null @@ -1,2241 +0,0 @@ -// Formatting library for C++ - chrono support -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_CHRONO_H_ -#define FMT_CHRONO_H_ - -#ifndef FMT_MODULE -# include -# include -# include // std::isfinite -# include // std::memcpy -# include -# include -# include -# include -# include -#endif - -#include "format.h" - -FMT_BEGIN_NAMESPACE - -// Enable safe chrono durations, unless explicitly disabled. -#ifndef FMT_SAFE_DURATION_CAST -# define FMT_SAFE_DURATION_CAST 1 -#endif -#if FMT_SAFE_DURATION_CAST - -// For conversion between std::chrono::durations without undefined -// behaviour or erroneous results. -// This is a stripped down version of duration_cast, for inclusion in fmt. -// See https://github.com/pauldreik/safe_duration_cast -// -// Copyright Paul Dreik 2019 -namespace safe_duration_cast { - -// DEPRECATED! -template ::value && - std::numeric_limits::is_signed == - std::numeric_limits::is_signed)> -FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec) - -> To { - ec = 0; - using F = std::numeric_limits; - using T = std::numeric_limits; - static_assert(F::is_integer, "From must be integral"); - static_assert(T::is_integer, "To must be integral"); - - // A and B are both signed, or both unsigned. - if (detail::const_check(F::digits <= T::digits)) { - // From fits in To without any problem. - } else { - // From does not always fit in To, resort to a dynamic check. - if (from < (T::min)() || from > (T::max)()) { - // outside range. - ec = 1; - return {}; - } - } - return static_cast(from); -} - -/// Converts From to To, without loss. If the dynamic value of from -/// can't be converted to To without loss, ec is set. -template ::value && - std::numeric_limits::is_signed != - std::numeric_limits::is_signed)> -FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec) - -> To { - ec = 0; - using F = std::numeric_limits; - using T = std::numeric_limits; - static_assert(F::is_integer, "From must be integral"); - static_assert(T::is_integer, "To must be integral"); - - if (detail::const_check(F::is_signed && !T::is_signed)) { - // From may be negative, not allowed! - if (fmt::detail::is_negative(from)) { - ec = 1; - return {}; - } - // From is positive. Can it always fit in To? - if (detail::const_check(F::digits > T::digits) && - from > static_cast(detail::max_value())) { - ec = 1; - return {}; - } - } - - if (detail::const_check(!F::is_signed && T::is_signed && - F::digits >= T::digits) && - from > static_cast(detail::max_value())) { - ec = 1; - return {}; - } - return static_cast(from); // Lossless conversion. -} - -template ::value)> -FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec) - -> To { - ec = 0; - return from; -} // function - -// clang-format off -/** - * converts From to To if possible, otherwise ec is set. - * - * input | output - * ---------------------------------|--------------- - * NaN | NaN - * Inf | Inf - * normal, fits in output | converted (possibly lossy) - * normal, does not fit in output | ec is set - * subnormal | best effort - * -Inf | -Inf - */ -// clang-format on -template ::value)> -FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To { - ec = 0; - using T = std::numeric_limits; - static_assert(std::is_floating_point::value, "From must be floating"); - static_assert(std::is_floating_point::value, "To must be floating"); - - // catch the only happy case - if (std::isfinite(from)) { - if (from >= T::lowest() && from <= (T::max)()) { - return static_cast(from); - } - // not within range. - ec = 1; - return {}; - } - - // nan and inf will be preserved - return static_cast(from); -} // function - -template ::value)> -FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To { - ec = 0; - static_assert(std::is_floating_point::value, "From must be floating"); - return from; -} - -/// Safe duration_cast between floating point durations -template ::value), - FMT_ENABLE_IF(std::is_floating_point::value)> -auto safe_duration_cast(std::chrono::duration from, - int& ec) -> To { - using From = std::chrono::duration; - ec = 0; - - // the basic idea is that we need to convert from count() in the from type - // to count() in the To type, by multiplying it with this: - struct Factor - : std::ratio_divide {}; - - static_assert(Factor::num > 0, "num must be positive"); - static_assert(Factor::den > 0, "den must be positive"); - - // the conversion is like this: multiply from.count() with Factor::num - // /Factor::den and convert it to To::rep, all this without - // overflow/underflow. let's start by finding a suitable type that can hold - // both To, From and Factor::num - using IntermediateRep = - typename std::common_type::type; - - // force conversion of From::rep -> IntermediateRep to be safe, - // even if it will never happen be narrowing in this context. - IntermediateRep count = - safe_float_conversion(from.count(), ec); - if (ec) { - return {}; - } - - // multiply with Factor::num without overflow or underflow - if (detail::const_check(Factor::num != 1)) { - constexpr auto max1 = detail::max_value() / - static_cast(Factor::num); - if (count > max1) { - ec = 1; - return {}; - } - constexpr auto min1 = std::numeric_limits::lowest() / - static_cast(Factor::num); - if (count < min1) { - ec = 1; - return {}; - } - count *= static_cast(Factor::num); - } - - // this can't go wrong, right? den>0 is checked earlier. - if (detail::const_check(Factor::den != 1)) { - using common_t = typename std::common_type::type; - count /= static_cast(Factor::den); - } - - // convert to the to type, safely - using ToRep = typename To::rep; - - const ToRep tocount = safe_float_conversion(count, ec); - if (ec) { - return {}; - } - return To{tocount}; -} -} // namespace safe_duration_cast -#endif - -namespace detail { - -// Check if std::chrono::utc_time is available. -#ifdef FMT_USE_UTC_TIME -// Use the provided definition. -#elif defined(__cpp_lib_chrono) -# define FMT_USE_UTC_TIME (__cpp_lib_chrono >= 201907L) -#else -# define FMT_USE_UTC_TIME 0 -#endif -#if FMT_USE_UTC_TIME -using utc_clock = std::chrono::utc_clock; -#else -struct utc_clock { - template void to_sys(T); -}; -#endif - -// Check if std::chrono::local_time is available. -#ifdef FMT_USE_LOCAL_TIME -// Use the provided definition. -#elif defined(__cpp_lib_chrono) -# define FMT_USE_LOCAL_TIME (__cpp_lib_chrono >= 201907L) -#else -# define FMT_USE_LOCAL_TIME 0 -#endif -#if FMT_USE_LOCAL_TIME -using local_t = std::chrono::local_t; -#else -struct local_t {}; -#endif - -} // namespace detail - -template -using sys_time = std::chrono::time_point; - -template -using utc_time = std::chrono::time_point; - -template -using local_time = std::chrono::time_point; - -namespace detail { - -// Prevents expansion of a preceding token as a function-style macro. -// Usage: f FMT_NOMACRO() -#define FMT_NOMACRO - -template struct null {}; -inline auto gmtime_r(...) -> null<> { return null<>(); } -inline auto gmtime_s(...) -> null<> { return null<>(); } - -// It is defined here and not in ostream.h because the latter has expensive -// includes. -template class formatbuf : public StreamBuf { - private: - using char_type = typename StreamBuf::char_type; - using streamsize = decltype(std::declval().sputn(nullptr, 0)); - using int_type = typename StreamBuf::int_type; - using traits_type = typename StreamBuf::traits_type; - - buffer& buffer_; - - public: - explicit formatbuf(buffer& buf) : buffer_(buf) {} - - protected: - // The put area is always empty. This makes the implementation simpler and has - // the advantage that the streambuf and the buffer are always in sync and - // sputc never writes into uninitialized memory. A disadvantage is that each - // call to sputc always results in a (virtual) call to overflow. There is no - // disadvantage here for sputn since this always results in a call to xsputn. - - auto overflow(int_type ch) -> int_type override { - if (!traits_type::eq_int_type(ch, traits_type::eof())) - buffer_.push_back(static_cast(ch)); - return ch; - } - - auto xsputn(const char_type* s, streamsize count) -> streamsize override { - buffer_.append(s, s + count); - return count; - } -}; - -inline auto get_classic_locale() -> const std::locale& { - static const auto& locale = std::locale::classic(); - return locale; -} - -template struct codecvt_result { - static constexpr size_t max_size = 32; - CodeUnit buf[max_size]; - CodeUnit* end; -}; - -template -void write_codecvt(codecvt_result& out, string_view in, - const std::locale& loc) { - FMT_PRAGMA_CLANG(diagnostic push) - FMT_PRAGMA_CLANG(diagnostic ignored "-Wdeprecated") - auto& f = std::use_facet>(loc); - FMT_PRAGMA_CLANG(diagnostic pop) - auto mb = std::mbstate_t(); - const char* from_next = nullptr; - auto result = f.in(mb, in.begin(), in.end(), from_next, std::begin(out.buf), - std::end(out.buf), out.end); - if (result != std::codecvt_base::ok) - FMT_THROW(format_error("failed to format time")); -} - -template -auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale& loc) - -> OutputIt { - if (const_check(detail::use_utf8) && loc != get_classic_locale()) { - // char16_t and char32_t codecvts are broken in MSVC (linkage errors) and - // gcc-4. -#if FMT_MSC_VERSION != 0 || \ - (defined(__GLIBCXX__) && \ - (!defined(_GLIBCXX_USE_DUAL_ABI) || _GLIBCXX_USE_DUAL_ABI == 0)) - // The _GLIBCXX_USE_DUAL_ABI macro is always defined in libstdc++ from gcc-5 - // and newer. - using code_unit = wchar_t; -#else - using code_unit = char32_t; -#endif - - using unit_t = codecvt_result; - unit_t unit; - write_codecvt(unit, in, loc); - // In UTF-8 is used one to four one-byte code units. - auto u = - to_utf8>(); - if (!u.convert({unit.buf, to_unsigned(unit.end - unit.buf)})) - FMT_THROW(format_error("failed to format time")); - return copy(u.c_str(), u.c_str() + u.size(), out); - } - return copy(in.data(), in.data() + in.size(), out); -} - -template ::value)> -auto write_tm_str(OutputIt out, string_view sv, const std::locale& loc) - -> OutputIt { - codecvt_result unit; - write_codecvt(unit, sv, loc); - return copy(unit.buf, unit.end, out); -} - -template ::value)> -auto write_tm_str(OutputIt out, string_view sv, const std::locale& loc) - -> OutputIt { - return write_encoded_tm_str(out, sv, loc); -} - -template -inline void do_write(buffer& buf, const std::tm& time, - const std::locale& loc, char format, char modifier) { - auto&& format_buf = formatbuf>(buf); - auto&& os = std::basic_ostream(&format_buf); - os.imbue(loc); - const auto& facet = std::use_facet>(loc); - auto end = facet.put(os, os, Char(' '), &time, format, modifier); - if (end.failed()) FMT_THROW(format_error("failed to format time")); -} - -template ::value)> -auto write(OutputIt out, const std::tm& time, const std::locale& loc, - char format, char modifier = 0) -> OutputIt { - auto&& buf = get_buffer(out); - do_write(buf, time, loc, format, modifier); - return get_iterator(buf, out); -} - -template ::value)> -auto write(OutputIt out, const std::tm& time, const std::locale& loc, - char format, char modifier = 0) -> OutputIt { - auto&& buf = basic_memory_buffer(); - do_write(buf, time, loc, format, modifier); - return write_encoded_tm_str(out, string_view(buf.data(), buf.size()), loc); -} - -template -using is_similar_arithmetic_type = - bool_constant<(std::is_integral::value && std::is_integral::value) || - (std::is_floating_point::value && - std::is_floating_point::value)>; - -FMT_NORETURN inline void throw_duration_error() { - FMT_THROW(format_error("cannot format duration")); -} - -// Cast one integral duration to another with an overflow check. -template ::value&& - std::is_integral::value)> -auto duration_cast(std::chrono::duration from) -> To { -#if !FMT_SAFE_DURATION_CAST - return std::chrono::duration_cast(from); -#else - // The conversion factor: to.count() == factor * from.count(). - using factor = std::ratio_divide; - - using common_rep = typename std::common_type::type; - common_rep count = from.count(); // This conversion is lossless. - - // Multiply from.count() by factor and check for overflow. - if (const_check(factor::num != 1)) { - if (count > max_value() / factor::num) throw_duration_error(); - const auto min = (std::numeric_limits::min)() / factor::num; - if (const_check(!std::is_unsigned::value) && count < min) - throw_duration_error(); - count *= factor::num; - } - if (const_check(factor::den != 1)) count /= factor::den; - int ec = 0; - auto to = - To(safe_duration_cast::lossless_integral_conversion( - count, ec)); - if (ec) throw_duration_error(); - return to; -#endif -} - -template ::value&& - std::is_floating_point::value)> -auto duration_cast(std::chrono::duration from) -> To { -#if FMT_SAFE_DURATION_CAST - // Preserve infinity and NaN. - if (!isfinite(from.count())) return static_cast(from.count()); - // Throwing version of safe_duration_cast is only available for - // integer to integer or float to float casts. - int ec; - To to = safe_duration_cast::safe_duration_cast(from, ec); - if (ec) throw_duration_error(); - return to; -#else - // Standard duration cast, may overflow. - return std::chrono::duration_cast(from); -#endif -} - -template ::value)> -auto duration_cast(std::chrono::duration from) -> To { - // Mixed integer <-> float cast is not supported by safe duration_cast. - return std::chrono::duration_cast(from); -} - -template -auto to_time_t(sys_time time_point) -> std::time_t { - // Cannot use std::chrono::system_clock::to_time_t since this would first - // require a cast to std::chrono::system_clock::time_point, which could - // overflow. - return detail::duration_cast>( - time_point.time_since_epoch()) - .count(); -} - -} // namespace detail - -FMT_BEGIN_EXPORT - -/** - * Converts given time since epoch as `std::time_t` value into calendar time, - * expressed in Coordinated Universal Time (UTC). Unlike `std::gmtime`, this - * function is thread-safe on most platforms. - */ -inline auto gmtime(std::time_t time) -> std::tm { - struct dispatcher { - std::time_t time_; - std::tm tm_; - - inline dispatcher(std::time_t t) : time_(t) {} - - inline auto run() -> bool { - using namespace fmt::detail; - return handle(gmtime_r(&time_, &tm_)); - } - - inline auto handle(std::tm* tm) -> bool { return tm != nullptr; } - - inline auto handle(detail::null<>) -> bool { - using namespace fmt::detail; - return fallback(gmtime_s(&tm_, &time_)); - } - - inline auto fallback(int res) -> bool { return res == 0; } - -#if !FMT_MSC_VERSION - inline auto fallback(detail::null<>) -> bool { - std::tm* tm = std::gmtime(&time_); - if (tm) tm_ = *tm; - return tm != nullptr; - } -#endif - }; - auto gt = dispatcher(time); - // Too big time values may be unsupported. - if (!gt.run()) FMT_THROW(format_error("time_t value out of range")); - return gt.tm_; -} - -template -inline auto gmtime(sys_time time_point) -> std::tm { - return gmtime(detail::to_time_t(time_point)); -} - -namespace detail { - -// Writes two-digit numbers a, b and c separated by sep to buf. -// The method by Pavel Novikov based on -// https://johnnylee-sde.github.io/Fast-unsigned-integer-to-time-string/. -inline void write_digit2_separated(char* buf, unsigned a, unsigned b, - unsigned c, char sep) { - unsigned long long digits = - a | (b << 24) | (static_cast(c) << 48); - // Convert each value to BCD. - // We have x = a * 10 + b and we want to convert it to BCD y = a * 16 + b. - // The difference is - // y - x = a * 6 - // a can be found from x: - // a = floor(x / 10) - // then - // y = x + a * 6 = x + floor(x / 10) * 6 - // floor(x / 10) is (x * 205) >> 11 (needs 16 bits). - digits += (((digits * 205) >> 11) & 0x000f00000f00000f) * 6; - // Put low nibbles to high bytes and high nibbles to low bytes. - digits = ((digits & 0x00f00000f00000f0) >> 4) | - ((digits & 0x000f00000f00000f) << 8); - auto usep = static_cast(sep); - // Add ASCII '0' to each digit byte and insert separators. - digits |= 0x3030003030003030 | (usep << 16) | (usep << 40); - - constexpr size_t len = 8; - if (const_check(is_big_endian())) { - char tmp[len]; - std::memcpy(tmp, &digits, len); - std::reverse_copy(tmp, tmp + len, buf); - } else { - std::memcpy(buf, &digits, len); - } -} - -template -FMT_CONSTEXPR inline auto get_units() -> const char* { - if (std::is_same::value) return "as"; - if (std::is_same::value) return "fs"; - if (std::is_same::value) return "ps"; - if (std::is_same::value) return "ns"; - if (std::is_same::value) - return detail::use_utf8 ? "µs" : "us"; - if (std::is_same::value) return "ms"; - if (std::is_same::value) return "cs"; - if (std::is_same::value) return "ds"; - if (std::is_same>::value) return "s"; - if (std::is_same::value) return "das"; - if (std::is_same::value) return "hs"; - if (std::is_same::value) return "ks"; - if (std::is_same::value) return "Ms"; - if (std::is_same::value) return "Gs"; - if (std::is_same::value) return "Ts"; - if (std::is_same::value) return "Ps"; - if (std::is_same::value) return "Es"; - if (std::is_same>::value) return "min"; - if (std::is_same>::value) return "h"; - if (std::is_same>::value) return "d"; - return nullptr; -} - -enum class numeric_system { - standard, - // Alternative numeric system, e.g. å二 instead of 12 in ja_JP locale. - alternative -}; - -// Glibc extensions for formatting numeric values. -enum class pad_type { - // Pad a numeric result string with zeros (the default). - zero, - // Do not pad a numeric result string. - none, - // Pad a numeric result string with spaces. - space, -}; - -template -auto write_padding(OutputIt out, pad_type pad, int width) -> OutputIt { - if (pad == pad_type::none) return out; - return detail::fill_n(out, width, pad == pad_type::space ? ' ' : '0'); -} - -template -auto write_padding(OutputIt out, pad_type pad) -> OutputIt { - if (pad != pad_type::none) *out++ = pad == pad_type::space ? ' ' : '0'; - return out; -} - -// Parses a put_time-like format string and invokes handler actions. -template -FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end, - Handler&& handler) -> const Char* { - if (begin == end || *begin == '}') return begin; - if (*begin != '%') FMT_THROW(format_error("invalid format")); - auto ptr = begin; - while (ptr != end) { - pad_type pad = pad_type::zero; - auto c = *ptr; - if (c == '}') break; - if (c != '%') { - ++ptr; - continue; - } - if (begin != ptr) handler.on_text(begin, ptr); - ++ptr; // consume '%' - if (ptr == end) FMT_THROW(format_error("invalid format")); - c = *ptr; - switch (c) { - case '_': - pad = pad_type::space; - ++ptr; - break; - case '-': - pad = pad_type::none; - ++ptr; - break; - } - if (ptr == end) FMT_THROW(format_error("invalid format")); - c = *ptr++; - switch (c) { - case '%': handler.on_text(ptr - 1, ptr); break; - case 'n': { - const Char newline[] = {'\n'}; - handler.on_text(newline, newline + 1); - break; - } - case 't': { - const Char tab[] = {'\t'}; - handler.on_text(tab, tab + 1); - break; - } - // Year: - case 'Y': handler.on_year(numeric_system::standard, pad); break; - case 'y': handler.on_short_year(numeric_system::standard); break; - case 'C': handler.on_century(numeric_system::standard); break; - case 'G': handler.on_iso_week_based_year(); break; - case 'g': handler.on_iso_week_based_short_year(); break; - // Day of the week: - case 'a': handler.on_abbr_weekday(); break; - case 'A': handler.on_full_weekday(); break; - case 'w': handler.on_dec0_weekday(numeric_system::standard); break; - case 'u': handler.on_dec1_weekday(numeric_system::standard); break; - // Month: - case 'b': - case 'h': handler.on_abbr_month(); break; - case 'B': handler.on_full_month(); break; - case 'm': handler.on_dec_month(numeric_system::standard, pad); break; - // Day of the year/month: - case 'U': - handler.on_dec0_week_of_year(numeric_system::standard, pad); - break; - case 'W': - handler.on_dec1_week_of_year(numeric_system::standard, pad); - break; - case 'V': handler.on_iso_week_of_year(numeric_system::standard, pad); break; - case 'j': handler.on_day_of_year(pad); break; - case 'd': handler.on_day_of_month(numeric_system::standard, pad); break; - case 'e': - handler.on_day_of_month(numeric_system::standard, pad_type::space); - break; - // Hour, minute, second: - case 'H': handler.on_24_hour(numeric_system::standard, pad); break; - case 'I': handler.on_12_hour(numeric_system::standard, pad); break; - case 'M': handler.on_minute(numeric_system::standard, pad); break; - case 'S': handler.on_second(numeric_system::standard, pad); break; - // Other: - case 'c': handler.on_datetime(numeric_system::standard); break; - case 'x': handler.on_loc_date(numeric_system::standard); break; - case 'X': handler.on_loc_time(numeric_system::standard); break; - case 'D': handler.on_us_date(); break; - case 'F': handler.on_iso_date(); break; - case 'r': handler.on_12_hour_time(); break; - case 'R': handler.on_24_hour_time(); break; - case 'T': handler.on_iso_time(); break; - case 'p': handler.on_am_pm(); break; - case 'Q': handler.on_duration_value(); break; - case 'q': handler.on_duration_unit(); break; - case 'z': handler.on_utc_offset(numeric_system::standard); break; - case 'Z': handler.on_tz_name(); break; - // Alternative representation: - case 'E': { - if (ptr == end) FMT_THROW(format_error("invalid format")); - c = *ptr++; - switch (c) { - case 'Y': handler.on_year(numeric_system::alternative, pad); break; - case 'y': handler.on_offset_year(); break; - case 'C': handler.on_century(numeric_system::alternative); break; - case 'c': handler.on_datetime(numeric_system::alternative); break; - case 'x': handler.on_loc_date(numeric_system::alternative); break; - case 'X': handler.on_loc_time(numeric_system::alternative); break; - case 'z': handler.on_utc_offset(numeric_system::alternative); break; - default: FMT_THROW(format_error("invalid format")); - } - break; - } - case 'O': - if (ptr == end) FMT_THROW(format_error("invalid format")); - c = *ptr++; - switch (c) { - case 'y': handler.on_short_year(numeric_system::alternative); break; - case 'm': handler.on_dec_month(numeric_system::alternative, pad); break; - case 'U': - handler.on_dec0_week_of_year(numeric_system::alternative, pad); - break; - case 'W': - handler.on_dec1_week_of_year(numeric_system::alternative, pad); - break; - case 'V': - handler.on_iso_week_of_year(numeric_system::alternative, pad); - break; - case 'd': - handler.on_day_of_month(numeric_system::alternative, pad); - break; - case 'e': - handler.on_day_of_month(numeric_system::alternative, pad_type::space); - break; - case 'w': handler.on_dec0_weekday(numeric_system::alternative); break; - case 'u': handler.on_dec1_weekday(numeric_system::alternative); break; - case 'H': handler.on_24_hour(numeric_system::alternative, pad); break; - case 'I': handler.on_12_hour(numeric_system::alternative, pad); break; - case 'M': handler.on_minute(numeric_system::alternative, pad); break; - case 'S': handler.on_second(numeric_system::alternative, pad); break; - case 'z': handler.on_utc_offset(numeric_system::alternative); break; - default: FMT_THROW(format_error("invalid format")); - } - break; - default: FMT_THROW(format_error("invalid format")); - } - begin = ptr; - } - if (begin != ptr) handler.on_text(begin, ptr); - return ptr; -} - -template struct null_chrono_spec_handler { - FMT_CONSTEXPR void unsupported() { - static_cast(this)->unsupported(); - } - FMT_CONSTEXPR void on_year(numeric_system, pad_type) { unsupported(); } - FMT_CONSTEXPR void on_short_year(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_offset_year() { unsupported(); } - FMT_CONSTEXPR void on_century(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_iso_week_based_year() { unsupported(); } - FMT_CONSTEXPR void on_iso_week_based_short_year() { unsupported(); } - FMT_CONSTEXPR void on_abbr_weekday() { unsupported(); } - FMT_CONSTEXPR void on_full_weekday() { unsupported(); } - FMT_CONSTEXPR void on_dec0_weekday(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_dec1_weekday(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_abbr_month() { unsupported(); } - FMT_CONSTEXPR void on_full_month() { unsupported(); } - FMT_CONSTEXPR void on_dec_month(numeric_system, pad_type) { unsupported(); } - FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system, pad_type) { - unsupported(); - } - FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system, pad_type) { - unsupported(); - } - FMT_CONSTEXPR void on_iso_week_of_year(numeric_system, pad_type) { - unsupported(); - } - FMT_CONSTEXPR void on_day_of_year(pad_type) { unsupported(); } - FMT_CONSTEXPR void on_day_of_month(numeric_system, pad_type) { - unsupported(); - } - FMT_CONSTEXPR void on_24_hour(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_12_hour(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_minute(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_second(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_datetime(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_loc_date(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_loc_time(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_us_date() { unsupported(); } - FMT_CONSTEXPR void on_iso_date() { unsupported(); } - FMT_CONSTEXPR void on_12_hour_time() { unsupported(); } - FMT_CONSTEXPR void on_24_hour_time() { unsupported(); } - FMT_CONSTEXPR void on_iso_time() { unsupported(); } - FMT_CONSTEXPR void on_am_pm() { unsupported(); } - FMT_CONSTEXPR void on_duration_value() { unsupported(); } - FMT_CONSTEXPR void on_duration_unit() { unsupported(); } - FMT_CONSTEXPR void on_utc_offset(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_tz_name() { unsupported(); } -}; - -class tm_format_checker : public null_chrono_spec_handler { - private: - bool has_timezone_ = false; - - public: - constexpr explicit tm_format_checker(bool has_timezone) - : has_timezone_(has_timezone) {} - - FMT_NORETURN inline void unsupported() { - FMT_THROW(format_error("no format")); - } - - template - FMT_CONSTEXPR void on_text(const Char*, const Char*) {} - FMT_CONSTEXPR void on_year(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_short_year(numeric_system) {} - FMT_CONSTEXPR void on_offset_year() {} - FMT_CONSTEXPR void on_century(numeric_system) {} - FMT_CONSTEXPR void on_iso_week_based_year() {} - FMT_CONSTEXPR void on_iso_week_based_short_year() {} - FMT_CONSTEXPR void on_abbr_weekday() {} - FMT_CONSTEXPR void on_full_weekday() {} - FMT_CONSTEXPR void on_dec0_weekday(numeric_system) {} - FMT_CONSTEXPR void on_dec1_weekday(numeric_system) {} - FMT_CONSTEXPR void on_abbr_month() {} - FMT_CONSTEXPR void on_full_month() {} - FMT_CONSTEXPR void on_dec_month(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_iso_week_of_year(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_day_of_year(pad_type) {} - FMT_CONSTEXPR void on_day_of_month(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_24_hour(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_12_hour(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_minute(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_second(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_datetime(numeric_system) {} - FMT_CONSTEXPR void on_loc_date(numeric_system) {} - FMT_CONSTEXPR void on_loc_time(numeric_system) {} - FMT_CONSTEXPR void on_us_date() {} - FMT_CONSTEXPR void on_iso_date() {} - FMT_CONSTEXPR void on_12_hour_time() {} - FMT_CONSTEXPR void on_24_hour_time() {} - FMT_CONSTEXPR void on_iso_time() {} - FMT_CONSTEXPR void on_am_pm() {} - FMT_CONSTEXPR void on_utc_offset(numeric_system) { - if (!has_timezone_) FMT_THROW(format_error("no timezone")); - } - FMT_CONSTEXPR void on_tz_name() { - if (!has_timezone_) FMT_THROW(format_error("no timezone")); - } -}; - -inline auto tm_wday_full_name(int wday) -> const char* { - static constexpr const char* full_name_list[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday"}; - return wday >= 0 && wday <= 6 ? full_name_list[wday] : "?"; -} -inline auto tm_wday_short_name(int wday) -> const char* { - static constexpr const char* short_name_list[] = {"Sun", "Mon", "Tue", "Wed", - "Thu", "Fri", "Sat"}; - return wday >= 0 && wday <= 6 ? short_name_list[wday] : "???"; -} - -inline auto tm_mon_full_name(int mon) -> const char* { - static constexpr const char* full_name_list[] = { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December"}; - return mon >= 0 && mon <= 11 ? full_name_list[mon] : "?"; -} -inline auto tm_mon_short_name(int mon) -> const char* { - static constexpr const char* short_name_list[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", - }; - return mon >= 0 && mon <= 11 ? short_name_list[mon] : "???"; -} - -template -struct has_tm_gmtoff : std::false_type {}; -template -struct has_tm_gmtoff> : std::true_type {}; - -template struct has_tm_zone : std::false_type {}; -template -struct has_tm_zone> : std::true_type {}; - -template ::value)> -auto set_tm_zone(T& time, char* tz) -> bool { - time.tm_zone = tz; - return true; -} -template ::value)> -auto set_tm_zone(T&, char*) -> bool { - return false; -} - -inline auto utc() -> char* { - static char tz[] = "UTC"; - return tz; -} - -// Converts value to Int and checks that it's in the range [0, upper). -template ::value)> -inline auto to_nonnegative_int(T value, Int upper) -> Int { - if (!std::is_unsigned::value && - (value < 0 || to_unsigned(value) > to_unsigned(upper))) { - FMT_THROW(format_error("chrono value is out of range")); - } - return static_cast(value); -} -template ::value)> -inline auto to_nonnegative_int(T value, Int upper) -> Int { - auto int_value = static_cast(value); - if (int_value < 0 || value > static_cast(upper)) - FMT_THROW(format_error("invalid value")); - return int_value; -} - -constexpr auto pow10(std::uint32_t n) -> long long { - return n == 0 ? 1 : 10 * pow10(n - 1); -} - -// Counts the number of fractional digits in the range [0, 18] according to the -// C++20 spec. If more than 18 fractional digits are required then returns 6 for -// microseconds precision. -template () / 10)> -struct count_fractional_digits { - static constexpr int value = - Num % Den == 0 ? N : count_fractional_digits::value; -}; - -// Base case that doesn't instantiate any more templates -// in order to avoid overflow. -template -struct count_fractional_digits { - static constexpr int value = (Num % Den == 0) ? N : 6; -}; - -// Format subseconds which are given as an integer type with an appropriate -// number of digits. -template -void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) { - constexpr auto num_fractional_digits = - count_fractional_digits::value; - - using subsecond_precision = std::chrono::duration< - typename std::common_type::type, - std::ratio<1, pow10(num_fractional_digits)>>; - - const auto fractional = d - detail::duration_cast(d); - const auto subseconds = - std::chrono::treat_as_floating_point< - typename subsecond_precision::rep>::value - ? fractional.count() - : detail::duration_cast(fractional).count(); - auto n = static_cast>(subseconds); - const int num_digits = count_digits(n); - - int leading_zeroes = (std::max)(0, num_fractional_digits - num_digits); - if (precision < 0) { - FMT_ASSERT(!std::is_floating_point::value, ""); - if (std::ratio_less::value) { - *out++ = '.'; - out = detail::fill_n(out, leading_zeroes, '0'); - out = format_decimal(out, n, num_digits); - } - } else if (precision > 0) { - *out++ = '.'; - leading_zeroes = min_of(leading_zeroes, precision); - int remaining = precision - leading_zeroes; - out = detail::fill_n(out, leading_zeroes, '0'); - if (remaining < num_digits) { - int num_truncated_digits = num_digits - remaining; - n /= to_unsigned(pow10(to_unsigned(num_truncated_digits))); - if (n != 0) out = format_decimal(out, n, remaining); - return; - } - if (n != 0) { - out = format_decimal(out, n, num_digits); - remaining -= num_digits; - } - out = detail::fill_n(out, remaining, '0'); - } -} - -// Format subseconds which are given as a floating point type with an -// appropriate number of digits. We cannot pass the Duration here, as we -// explicitly need to pass the Rep value in the duration_formatter. -template -void write_floating_seconds(memory_buffer& buf, Duration duration, - int num_fractional_digits = -1) { - using rep = typename Duration::rep; - FMT_ASSERT(std::is_floating_point::value, ""); - - auto val = duration.count(); - - if (num_fractional_digits < 0) { - // For `std::round` with fallback to `round`: - // On some toolchains `std::round` is not available (e.g. GCC 6). - using namespace std; - num_fractional_digits = - count_fractional_digits::value; - if (num_fractional_digits < 6 && static_cast(round(val)) != val) - num_fractional_digits = 6; - } - - fmt::format_to(std::back_inserter(buf), FMT_STRING("{:.{}f}"), - std::fmod(val * static_cast(Duration::period::num) / - static_cast(Duration::period::den), - static_cast(60)), - num_fractional_digits); -} - -template -class tm_writer { - private: - static constexpr int days_per_week = 7; - - const std::locale& loc_; - bool is_classic_; - OutputIt out_; - const Duration* subsecs_; - const std::tm& tm_; - - auto tm_sec() const noexcept -> int { - FMT_ASSERT(tm_.tm_sec >= 0 && tm_.tm_sec <= 61, ""); - return tm_.tm_sec; - } - auto tm_min() const noexcept -> int { - FMT_ASSERT(tm_.tm_min >= 0 && tm_.tm_min <= 59, ""); - return tm_.tm_min; - } - auto tm_hour() const noexcept -> int { - FMT_ASSERT(tm_.tm_hour >= 0 && tm_.tm_hour <= 23, ""); - return tm_.tm_hour; - } - auto tm_mday() const noexcept -> int { - FMT_ASSERT(tm_.tm_mday >= 1 && tm_.tm_mday <= 31, ""); - return tm_.tm_mday; - } - auto tm_mon() const noexcept -> int { - FMT_ASSERT(tm_.tm_mon >= 0 && tm_.tm_mon <= 11, ""); - return tm_.tm_mon; - } - auto tm_year() const noexcept -> long long { return 1900ll + tm_.tm_year; } - auto tm_wday() const noexcept -> int { - FMT_ASSERT(tm_.tm_wday >= 0 && tm_.tm_wday <= 6, ""); - return tm_.tm_wday; - } - auto tm_yday() const noexcept -> int { - FMT_ASSERT(tm_.tm_yday >= 0 && tm_.tm_yday <= 365, ""); - return tm_.tm_yday; - } - - auto tm_hour12() const noexcept -> int { - auto h = tm_hour(); - auto z = h < 12 ? h : h - 12; - return z == 0 ? 12 : z; - } - - // POSIX and the C Standard are unclear or inconsistent about what %C and %y - // do if the year is negative or exceeds 9999. Use the convention that %C - // concatenated with %y yields the same output as %Y, and that %Y contains at - // least 4 characters, with more only if necessary. - auto split_year_lower(long long year) const noexcept -> int { - auto l = year % 100; - if (l < 0) l = -l; // l in [0, 99] - return static_cast(l); - } - - // Algorithm: https://en.wikipedia.org/wiki/ISO_week_date. - auto iso_year_weeks(long long curr_year) const noexcept -> int { - auto prev_year = curr_year - 1; - auto curr_p = - (curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) % - days_per_week; - auto prev_p = - (prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) % - days_per_week; - return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0); - } - auto iso_week_num(int tm_yday, int tm_wday) const noexcept -> int { - return (tm_yday + 11 - (tm_wday == 0 ? days_per_week : tm_wday)) / - days_per_week; - } - auto tm_iso_week_year() const noexcept -> long long { - auto year = tm_year(); - auto w = iso_week_num(tm_yday(), tm_wday()); - if (w < 1) return year - 1; - if (w > iso_year_weeks(year)) return year + 1; - return year; - } - auto tm_iso_week_of_year() const noexcept -> int { - auto year = tm_year(); - auto w = iso_week_num(tm_yday(), tm_wday()); - if (w < 1) return iso_year_weeks(year - 1); - if (w > iso_year_weeks(year)) return 1; - return w; - } - - void write1(int value) { - *out_++ = static_cast('0' + to_unsigned(value) % 10); - } - void write2(int value) { - const char* d = digits2(to_unsigned(value) % 100); - *out_++ = *d++; - *out_++ = *d; - } - void write2(int value, pad_type pad) { - unsigned int v = to_unsigned(value) % 100; - if (v >= 10) { - const char* d = digits2(v); - *out_++ = *d++; - *out_++ = *d; - } else { - out_ = detail::write_padding(out_, pad); - *out_++ = static_cast('0' + v); - } - } - - void write_year_extended(long long year, pad_type pad) { - // At least 4 characters. - int width = 4; - bool negative = year < 0; - if (negative) { - year = 0 - year; - --width; - } - uint32_or_64_or_128_t n = to_unsigned(year); - const int num_digits = count_digits(n); - if (negative && pad == pad_type::zero) *out_++ = '-'; - if (width > num_digits) - out_ = detail::write_padding(out_, pad, width - num_digits); - if (negative && pad != pad_type::zero) *out_++ = '-'; - out_ = format_decimal(out_, n, num_digits); - } - void write_year(long long year, pad_type pad) { - write_year_extended(year, pad); - } - - void write_utc_offset(long long offset, numeric_system ns) { - if (offset < 0) { - *out_++ = '-'; - offset = -offset; - } else { - *out_++ = '+'; - } - offset /= 60; - write2(static_cast(offset / 60)); - if (ns != numeric_system::standard) *out_++ = ':'; - write2(static_cast(offset % 60)); - } - - template ::value)> - void format_utc_offset(const T& tm, numeric_system ns) { - write_utc_offset(tm.tm_gmtoff, ns); - } - template ::value)> - void format_utc_offset(const T&, numeric_system ns) { - write_utc_offset(0, ns); - } - - template ::value)> - void format_tz_name(const T& tm) { - out_ = write_tm_str(out_, tm.tm_zone, loc_); - } - template ::value)> - void format_tz_name(const T&) { - out_ = std::copy_n(utc(), 3, out_); - } - - void format_localized(char format, char modifier = 0) { - out_ = write(out_, tm_, loc_, format, modifier); - } - - public: - tm_writer(const std::locale& loc, OutputIt out, const std::tm& tm, - const Duration* subsecs = nullptr) - : loc_(loc), - is_classic_(loc_ == get_classic_locale()), - out_(out), - subsecs_(subsecs), - tm_(tm) {} - - auto out() const -> OutputIt { return out_; } - - FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) { - out_ = copy(begin, end, out_); - } - - void on_abbr_weekday() { - if (is_classic_) - out_ = write(out_, tm_wday_short_name(tm_wday())); - else - format_localized('a'); - } - void on_full_weekday() { - if (is_classic_) - out_ = write(out_, tm_wday_full_name(tm_wday())); - else - format_localized('A'); - } - void on_dec0_weekday(numeric_system ns) { - if (is_classic_ || ns == numeric_system::standard) return write1(tm_wday()); - format_localized('w', 'O'); - } - void on_dec1_weekday(numeric_system ns) { - if (is_classic_ || ns == numeric_system::standard) { - auto wday = tm_wday(); - write1(wday == 0 ? days_per_week : wday); - } else { - format_localized('u', 'O'); - } - } - - void on_abbr_month() { - if (is_classic_) - out_ = write(out_, tm_mon_short_name(tm_mon())); - else - format_localized('b'); - } - void on_full_month() { - if (is_classic_) - out_ = write(out_, tm_mon_full_name(tm_mon())); - else - format_localized('B'); - } - - void on_datetime(numeric_system ns) { - if (is_classic_) { - on_abbr_weekday(); - *out_++ = ' '; - on_abbr_month(); - *out_++ = ' '; - on_day_of_month(numeric_system::standard, pad_type::space); - *out_++ = ' '; - on_iso_time(); - *out_++ = ' '; - on_year(numeric_system::standard, pad_type::space); - } else { - format_localized('c', ns == numeric_system::standard ? '\0' : 'E'); - } - } - void on_loc_date(numeric_system ns) { - if (is_classic_) - on_us_date(); - else - format_localized('x', ns == numeric_system::standard ? '\0' : 'E'); - } - void on_loc_time(numeric_system ns) { - if (is_classic_) - on_iso_time(); - else - format_localized('X', ns == numeric_system::standard ? '\0' : 'E'); - } - void on_us_date() { - char buf[8]; - write_digit2_separated(buf, to_unsigned(tm_mon() + 1), - to_unsigned(tm_mday()), - to_unsigned(split_year_lower(tm_year())), '/'); - out_ = copy(std::begin(buf), std::end(buf), out_); - } - void on_iso_date() { - auto year = tm_year(); - char buf[10]; - size_t offset = 0; - if (year >= 0 && year < 10000) { - write2digits(buf, static_cast(year / 100)); - } else { - offset = 4; - write_year_extended(year, pad_type::zero); - year = 0; - } - write_digit2_separated(buf + 2, static_cast(year % 100), - to_unsigned(tm_mon() + 1), to_unsigned(tm_mday()), - '-'); - out_ = copy(std::begin(buf) + offset, std::end(buf), out_); - } - - void on_utc_offset(numeric_system ns) { format_utc_offset(tm_, ns); } - void on_tz_name() { format_tz_name(tm_); } - - void on_year(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write_year(tm_year(), pad); - format_localized('Y', 'E'); - } - void on_short_year(numeric_system ns) { - if (is_classic_ || ns == numeric_system::standard) - return write2(split_year_lower(tm_year())); - format_localized('y', 'O'); - } - void on_offset_year() { - if (is_classic_) return write2(split_year_lower(tm_year())); - format_localized('y', 'E'); - } - - void on_century(numeric_system ns) { - if (is_classic_ || ns == numeric_system::standard) { - auto year = tm_year(); - auto upper = year / 100; - if (year >= -99 && year < 0) { - // Zero upper on negative year. - *out_++ = '-'; - *out_++ = '0'; - } else if (upper >= 0 && upper < 100) { - write2(static_cast(upper)); - } else { - out_ = write(out_, upper); - } - } else { - format_localized('C', 'E'); - } - } - - void on_dec_month(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_mon() + 1, pad); - format_localized('m', 'O'); - } - - void on_dec0_week_of_year(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2((tm_yday() + days_per_week - tm_wday()) / days_per_week, - pad); - format_localized('U', 'O'); - } - void on_dec1_week_of_year(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) { - auto wday = tm_wday(); - write2((tm_yday() + days_per_week - - (wday == 0 ? (days_per_week - 1) : (wday - 1))) / - days_per_week, - pad); - } else { - format_localized('W', 'O'); - } - } - void on_iso_week_of_year(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_iso_week_of_year(), pad); - format_localized('V', 'O'); - } - - void on_iso_week_based_year() { - write_year(tm_iso_week_year(), pad_type::zero); - } - void on_iso_week_based_short_year() { - write2(split_year_lower(tm_iso_week_year())); - } - - void on_day_of_year(pad_type pad) { - auto yday = tm_yday() + 1; - auto digit1 = yday / 100; - if (digit1 != 0) - write1(digit1); - else - out_ = detail::write_padding(out_, pad); - write2(yday % 100, pad); - } - - void on_day_of_month(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_mday(), pad); - format_localized('d', 'O'); - } - - void on_24_hour(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_hour(), pad); - format_localized('H', 'O'); - } - void on_12_hour(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_hour12(), pad); - format_localized('I', 'O'); - } - void on_minute(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_min(), pad); - format_localized('M', 'O'); - } - - void on_second(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) { - write2(tm_sec(), pad); - if (subsecs_) { - if (std::is_floating_point::value) { - auto buf = memory_buffer(); - write_floating_seconds(buf, *subsecs_); - if (buf.size() > 1) { - // Remove the leading "0", write something like ".123". - out_ = copy(buf.begin() + 1, buf.end(), out_); - } - } else { - write_fractional_seconds(out_, *subsecs_); - } - } - } else { - // Currently no formatting of subseconds when a locale is set. - format_localized('S', 'O'); - } - } - - void on_12_hour_time() { - if (is_classic_) { - char buf[8]; - write_digit2_separated(buf, to_unsigned(tm_hour12()), - to_unsigned(tm_min()), to_unsigned(tm_sec()), ':'); - out_ = copy(std::begin(buf), std::end(buf), out_); - *out_++ = ' '; - on_am_pm(); - } else { - format_localized('r'); - } - } - void on_24_hour_time() { - write2(tm_hour()); - *out_++ = ':'; - write2(tm_min()); - } - void on_iso_time() { - on_24_hour_time(); - *out_++ = ':'; - on_second(numeric_system::standard, pad_type::zero); - } - - void on_am_pm() { - if (is_classic_) { - *out_++ = tm_hour() < 12 ? 'A' : 'P'; - *out_++ = 'M'; - } else { - format_localized('p'); - } - } - - // These apply to chrono durations but not tm. - void on_duration_value() {} - void on_duration_unit() {} -}; - -struct chrono_format_checker : null_chrono_spec_handler { - bool has_precision_integral = false; - - FMT_NORETURN inline void unsupported() { FMT_THROW(format_error("no date")); } - - template - FMT_CONSTEXPR void on_text(const Char*, const Char*) {} - FMT_CONSTEXPR void on_day_of_year(pad_type) {} - FMT_CONSTEXPR void on_24_hour(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_12_hour(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_minute(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_second(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_12_hour_time() {} - FMT_CONSTEXPR void on_24_hour_time() {} - FMT_CONSTEXPR void on_iso_time() {} - FMT_CONSTEXPR void on_am_pm() {} - FMT_CONSTEXPR void on_duration_value() const { - if (has_precision_integral) - FMT_THROW(format_error("precision not allowed for this argument type")); - } - FMT_CONSTEXPR void on_duration_unit() {} -}; - -template ::value&& has_isfinite::value)> -inline auto isfinite(T) -> bool { - return true; -} - -template ::value)> -inline auto mod(T x, int y) -> T { - return x % static_cast(y); -} -template ::value)> -inline auto mod(T x, int y) -> T { - return std::fmod(x, static_cast(y)); -} - -// If T is an integral type, maps T to its unsigned counterpart, otherwise -// leaves it unchanged (unlike std::make_unsigned). -template ::value> -struct make_unsigned_or_unchanged { - using type = T; -}; - -template struct make_unsigned_or_unchanged { - using type = typename std::make_unsigned::type; -}; - -template ::value)> -inline auto get_milliseconds(std::chrono::duration d) - -> std::chrono::duration { - // This may overflow and/or the result may not fit in the target type. -#if FMT_SAFE_DURATION_CAST - using common_seconds_type = - typename std::common_type::type; - auto d_as_common = detail::duration_cast(d); - auto d_as_whole_seconds = - detail::duration_cast(d_as_common); - // This conversion should be nonproblematic. - auto diff = d_as_common - d_as_whole_seconds; - auto ms = detail::duration_cast>(diff); - return ms; -#else - auto s = detail::duration_cast(d); - return detail::duration_cast(d - s); -#endif -} - -template ::value)> -auto format_duration_value(OutputIt out, Rep val, int) -> OutputIt { - return write(out, val); -} - -template ::value)> -auto format_duration_value(OutputIt out, Rep val, int precision) -> OutputIt { - auto specs = format_specs(); - specs.precision = precision; - specs.set_type(precision >= 0 ? presentation_type::fixed - : presentation_type::general); - return write(out, val, specs); -} - -template -auto copy_unit(string_view unit, OutputIt out, Char) -> OutputIt { - return copy(unit.begin(), unit.end(), out); -} - -template -auto copy_unit(string_view unit, OutputIt out, wchar_t) -> OutputIt { - // This works when wchar_t is UTF-32 because units only contain characters - // that have the same representation in UTF-16 and UTF-32. - utf8_to_utf16 u(unit); - return copy(u.c_str(), u.c_str() + u.size(), out); -} - -template -auto format_duration_unit(OutputIt out) -> OutputIt { - if (const char* unit = get_units()) - return copy_unit(string_view(unit), out, Char()); - *out++ = '['; - out = write(out, Period::num); - if (const_check(Period::den != 1)) { - *out++ = '/'; - out = write(out, Period::den); - } - *out++ = ']'; - *out++ = 's'; - return out; -} - -class get_locale { - private: - union { - std::locale locale_; - }; - bool has_locale_ = false; - - public: - inline get_locale(bool localized, locale_ref loc) : has_locale_(localized) { - if (localized) - ::new (&locale_) std::locale(loc.template get()); - } - inline ~get_locale() { - if (has_locale_) locale_.~locale(); - } - inline operator const std::locale&() const { - return has_locale_ ? locale_ : get_classic_locale(); - } -}; - -template -struct duration_formatter { - using iterator = basic_appender; - iterator out; - // rep is unsigned to avoid overflow. - using rep = - conditional_t::value && sizeof(Rep) < sizeof(int), - unsigned, typename make_unsigned_or_unchanged::type>; - rep val; - int precision; - locale_ref locale; - bool localized = false; - using seconds = std::chrono::duration; - seconds s; - using milliseconds = std::chrono::duration; - bool negative; - - using tm_writer_type = tm_writer; - - duration_formatter(iterator o, std::chrono::duration d, - locale_ref loc) - : out(o), val(static_cast(d.count())), locale(loc), negative(false) { - if (d.count() < 0) { - val = 0 - val; - negative = true; - } - - // this may overflow and/or the result may not fit in the - // target type. - // might need checked conversion (rep!=Rep) - s = detail::duration_cast(std::chrono::duration(val)); - } - - // returns true if nan or inf, writes to out. - auto handle_nan_inf() -> bool { - if (isfinite(val)) return false; - if (isnan(val)) { - write_nan(); - return true; - } - // must be +-inf - if (val > 0) - std::copy_n("inf", 3, out); - else - std::copy_n("-inf", 4, out); - return true; - } - - auto days() const -> Rep { return static_cast(s.count() / 86400); } - auto hour() const -> Rep { - return static_cast(mod((s.count() / 3600), 24)); - } - - auto hour12() const -> Rep { - Rep hour = static_cast(mod((s.count() / 3600), 12)); - return hour <= 0 ? 12 : hour; - } - - auto minute() const -> Rep { - return static_cast(mod((s.count() / 60), 60)); - } - auto second() const -> Rep { return static_cast(mod(s.count(), 60)); } - - auto time() const -> std::tm { - auto time = std::tm(); - time.tm_hour = to_nonnegative_int(hour(), 24); - time.tm_min = to_nonnegative_int(minute(), 60); - time.tm_sec = to_nonnegative_int(second(), 60); - return time; - } - - void write_sign() { - if (!negative) return; - *out++ = '-'; - negative = false; - } - - void write(Rep value, int width, pad_type pad = pad_type::zero) { - write_sign(); - if (isnan(value)) return write_nan(); - uint32_or_64_or_128_t n = - to_unsigned(to_nonnegative_int(value, max_value())); - int num_digits = detail::count_digits(n); - if (width > num_digits) { - out = detail::write_padding(out, pad, width - num_digits); - } - out = format_decimal(out, n, num_digits); - } - - void write_nan() { std::copy_n("nan", 3, out); } - - template - void format_tm(const tm& time, Callback cb, Args... args) { - if (isnan(val)) return write_nan(); - get_locale loc(localized, locale); - auto w = tm_writer_type(loc, out, time); - (w.*cb)(args...); - out = w.out(); - } - - void on_text(const Char* begin, const Char* end) { - copy(begin, end, out); - } - - // These are not implemented because durations don't have date information. - void on_abbr_weekday() {} - void on_full_weekday() {} - void on_dec0_weekday(numeric_system) {} - void on_dec1_weekday(numeric_system) {} - void on_abbr_month() {} - void on_full_month() {} - void on_datetime(numeric_system) {} - void on_loc_date(numeric_system) {} - void on_loc_time(numeric_system) {} - void on_us_date() {} - void on_iso_date() {} - void on_utc_offset(numeric_system) {} - void on_tz_name() {} - void on_year(numeric_system, pad_type) {} - void on_short_year(numeric_system) {} - void on_offset_year() {} - void on_century(numeric_system) {} - void on_iso_week_based_year() {} - void on_iso_week_based_short_year() {} - void on_dec_month(numeric_system, pad_type) {} - void on_dec0_week_of_year(numeric_system, pad_type) {} - void on_dec1_week_of_year(numeric_system, pad_type) {} - void on_iso_week_of_year(numeric_system, pad_type) {} - void on_day_of_month(numeric_system, pad_type) {} - - void on_day_of_year(pad_type) { - if (handle_nan_inf()) return; - write(days(), 0); - } - - void on_24_hour(numeric_system ns, pad_type pad) { - if (handle_nan_inf()) return; - - if (ns == numeric_system::standard) return write(hour(), 2, pad); - auto time = tm(); - time.tm_hour = to_nonnegative_int(hour(), 24); - format_tm(time, &tm_writer_type::on_24_hour, ns, pad); - } - - void on_12_hour(numeric_system ns, pad_type pad) { - if (handle_nan_inf()) return; - - if (ns == numeric_system::standard) return write(hour12(), 2, pad); - auto time = tm(); - time.tm_hour = to_nonnegative_int(hour12(), 12); - format_tm(time, &tm_writer_type::on_12_hour, ns, pad); - } - - void on_minute(numeric_system ns, pad_type pad) { - if (handle_nan_inf()) return; - - if (ns == numeric_system::standard) return write(minute(), 2, pad); - auto time = tm(); - time.tm_min = to_nonnegative_int(minute(), 60); - format_tm(time, &tm_writer_type::on_minute, ns, pad); - } - - void on_second(numeric_system ns, pad_type pad) { - if (handle_nan_inf()) return; - - if (ns == numeric_system::standard) { - if (std::is_floating_point::value) { - auto buf = memory_buffer(); - write_floating_seconds(buf, std::chrono::duration(val), - precision); - if (negative) *out++ = '-'; - if (buf.size() < 2 || buf[1] == '.') - out = detail::write_padding(out, pad); - out = copy(buf.begin(), buf.end(), out); - } else { - write(second(), 2, pad); - write_fractional_seconds( - out, std::chrono::duration(val), precision); - } - return; - } - auto time = tm(); - time.tm_sec = to_nonnegative_int(second(), 60); - format_tm(time, &tm_writer_type::on_second, ns, pad); - } - - void on_12_hour_time() { - if (handle_nan_inf()) return; - format_tm(time(), &tm_writer_type::on_12_hour_time); - } - - void on_24_hour_time() { - if (handle_nan_inf()) { - *out++ = ':'; - handle_nan_inf(); - return; - } - - write(hour(), 2); - *out++ = ':'; - write(minute(), 2); - } - - void on_iso_time() { - on_24_hour_time(); - *out++ = ':'; - if (handle_nan_inf()) return; - on_second(numeric_system::standard, pad_type::zero); - } - - void on_am_pm() { - if (handle_nan_inf()) return; - format_tm(time(), &tm_writer_type::on_am_pm); - } - - void on_duration_value() { - if (handle_nan_inf()) return; - write_sign(); - out = format_duration_value(out, val, precision); - } - - void on_duration_unit() { out = format_duration_unit(out); } -}; - -} // namespace detail - -#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907 -using weekday = std::chrono::weekday; -using day = std::chrono::day; -using month = std::chrono::month; -using year = std::chrono::year; -using year_month_day = std::chrono::year_month_day; -#else -// A fallback version of weekday. -class weekday { - private: - unsigned char value_; - - public: - weekday() = default; - constexpr explicit weekday(unsigned wd) noexcept - : value_(static_cast(wd != 7 ? wd : 0)) {} - constexpr auto c_encoding() const noexcept -> unsigned { return value_; } -}; - -class day { - private: - unsigned char value_; - - public: - day() = default; - constexpr explicit day(unsigned d) noexcept - : value_(static_cast(d)) {} - constexpr explicit operator unsigned() const noexcept { return value_; } -}; - -class month { - private: - unsigned char value_; - - public: - month() = default; - constexpr explicit month(unsigned m) noexcept - : value_(static_cast(m)) {} - constexpr explicit operator unsigned() const noexcept { return value_; } -}; - -class year { - private: - int value_; - - public: - year() = default; - constexpr explicit year(int y) noexcept : value_(y) {} - constexpr explicit operator int() const noexcept { return value_; } -}; - -class year_month_day { - private: - fmt::year year_; - fmt::month month_; - fmt::day day_; - - public: - year_month_day() = default; - constexpr year_month_day(const year& y, const month& m, const day& d) noexcept - : year_(y), month_(m), day_(d) {} - constexpr auto year() const noexcept -> fmt::year { return year_; } - constexpr auto month() const noexcept -> fmt::month { return month_; } - constexpr auto day() const noexcept -> fmt::day { return day_; } -}; -#endif // __cpp_lib_chrono >= 201907 - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it != end && *it == 'L') { - ++it; - this->set_localized(); - } - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_wday = static_cast(wd.c_encoding()); - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(this->localized(), ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_abbr_weekday(); - return w.out(); - } -}; - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_mday = static_cast(static_cast(d)); - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(false, ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_day_of_month(detail::numeric_system::standard, detail::pad_type::zero); - return w.out(); - } -}; - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it != end && *it == 'L') { - ++it; - this->set_localized(); - } - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_mon = static_cast(static_cast(m)) - 1; - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(this->localized(), ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_abbr_month(); - return w.out(); - } -}; - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_year = static_cast(y) - 1900; - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(false, ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_year(detail::numeric_system::standard, detail::pad_type::zero); - return w.out(); - } -}; - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(year_month_day val, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_year = static_cast(val.year()) - 1900; - time.tm_mon = static_cast(static_cast(val.month())) - 1; - time.tm_mday = static_cast(static_cast(val.day())); - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(true, ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_iso_date(); - return w.out(); - } -}; - -template -struct formatter, Char> { - private: - format_specs specs_; - detail::arg_ref width_ref_; - detail::arg_ref precision_ref_; - basic_string_view fmt_; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it == end || *it == '}') return it; - - it = detail::parse_align(it, end, specs_); - if (it == end) return it; - - Char c = *it; - if ((c >= '0' && c <= '9') || c == '{') { - it = detail::parse_width(it, end, specs_, width_ref_, ctx); - if (it == end) return it; - } - - auto checker = detail::chrono_format_checker(); - if (*it == '.') { - checker.has_precision_integral = !std::is_floating_point::value; - it = detail::parse_precision(it, end, specs_, precision_ref_, ctx); - } - if (it != end && *it == 'L') { - specs_.set_localized(); - ++it; - } - end = detail::parse_chrono_format(it, end, checker); - fmt_ = {it, detail::to_unsigned(end - it)}; - return end; - } - - template - auto format(std::chrono::duration d, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto specs = specs_; - auto precision = specs.precision; - specs.precision = -1; - auto begin = fmt_.begin(), end = fmt_.end(); - // As a possible future optimization, we could avoid extra copying if width - // is not specified. - auto buf = basic_memory_buffer(); - auto out = basic_appender(buf); - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, - ctx); - detail::handle_dynamic_spec(specs.dynamic_precision(), precision, - precision_ref_, ctx); - if (begin == end || *begin == '}') { - out = detail::format_duration_value(out, d.count(), precision); - detail::format_duration_unit(out); - } else { - auto f = - detail::duration_formatter(out, d, ctx.locale()); - f.precision = precision; - f.localized = specs_.localized(); - detail::parse_chrono_format(begin, end, f); - } - return detail::write( - ctx.out(), basic_string_view(buf.data(), buf.size()), specs); - } -}; - -template struct formatter { - private: - format_specs specs_; - detail::arg_ref width_ref_; - basic_string_view fmt_ = - detail::string_literal(); - - protected: - auto localized() const -> bool { return specs_.localized(); } - FMT_CONSTEXPR void set_localized() { specs_.set_localized(); } - - FMT_CONSTEXPR auto do_parse(parse_context& ctx, bool has_timezone) - -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it == end || *it == '}') return it; - - it = detail::parse_align(it, end, specs_); - if (it == end) return it; - - Char c = *it; - if ((c >= '0' && c <= '9') || c == '{') { - it = detail::parse_width(it, end, specs_, width_ref_, ctx); - if (it == end) return it; - } - - if (*it == 'L') { - specs_.set_localized(); - ++it; - } - - end = detail::parse_chrono_format(it, end, - detail::tm_format_checker(has_timezone)); - // Replace the default format string only if the new spec is not empty. - if (end != it) fmt_ = {it, detail::to_unsigned(end - it)}; - return end; - } - - template - auto do_format(const std::tm& tm, FormatContext& ctx, - const Duration* subsecs) const -> decltype(ctx.out()) { - auto specs = specs_; - auto buf = basic_memory_buffer(); - auto out = basic_appender(buf); - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, - ctx); - - auto loc_ref = specs.localized() ? ctx.locale() : locale_ref(); - detail::get_locale loc(static_cast(loc_ref), loc_ref); - auto w = detail::tm_writer, Char, Duration>( - loc, out, tm, subsecs); - detail::parse_chrono_format(fmt_.begin(), fmt_.end(), w); - return detail::write( - ctx.out(), basic_string_view(buf.data(), buf.size()), specs); - } - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return do_parse(ctx, detail::has_tm_gmtoff::value); - } - - template - auto format(const std::tm& tm, FormatContext& ctx) const - -> decltype(ctx.out()) { - return do_format(tm, ctx, nullptr); - } -}; - -// DEPRECATED! Reversed order of template parameters. -template -struct formatter, Char> : private formatter { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return this->do_parse(ctx, true); - } - - template - auto format(sys_time val, FormatContext& ctx) const - -> decltype(ctx.out()) { - std::tm tm = gmtime(val); - using period = typename Duration::period; - if (detail::const_check( - period::num == 1 && period::den == 1 && - !std::is_floating_point::value)) { - detail::set_tm_zone(tm, detail::utc()); - return formatter::format(tm, ctx); - } - Duration epoch = val.time_since_epoch(); - Duration subsecs = detail::duration_cast( - epoch - detail::duration_cast(epoch)); - if (subsecs.count() < 0) { - auto second = detail::duration_cast(std::chrono::seconds(1)); - if (tm.tm_sec != 0) { - --tm.tm_sec; - } else { - tm = gmtime(val - second); - detail::set_tm_zone(tm, detail::utc()); - } - subsecs += second; - } - return formatter::do_format(tm, ctx, &subsecs); - } -}; - -template -struct formatter, Char> - : formatter, Char> { - template - auto format(utc_time val, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter, Char>::format( - detail::utc_clock::to_sys(val), ctx); - } -}; - -template -struct formatter, Char> - : private formatter { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return this->do_parse(ctx, false); - } - - template - auto format(local_time val, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto time_since_epoch = val.time_since_epoch(); - auto seconds_since_epoch = - detail::duration_cast(time_since_epoch); - // Use gmtime to prevent time zone conversion since local_time has an - // unspecified time zone. - std::tm t = gmtime(seconds_since_epoch.count()); - using period = typename Duration::period; - if (period::num == 1 && period::den == 1 && - !std::is_floating_point::value) { - return formatter::format(t, ctx); - } - auto subsecs = - detail::duration_cast(time_since_epoch - seconds_since_epoch); - return formatter::do_format(t, ctx, &subsecs); - } -}; - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_CHRONO_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/color.h b/examples/blueprints-example/external/fmt/bundled/color.h deleted file mode 100644 index b69c148..0000000 --- a/examples/blueprints-example/external/fmt/bundled/color.h +++ /dev/null @@ -1,637 +0,0 @@ -// Formatting library for C++ - color support -// -// Copyright (c) 2018 - present, Victor Zverovich and fmt contributors -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_COLOR_H_ -#define FMT_COLOR_H_ - -#include "format.h" - -FMT_BEGIN_NAMESPACE -FMT_BEGIN_EXPORT - -enum class color : uint32_t { - alice_blue = 0xF0F8FF, // rgb(240,248,255) - antique_white = 0xFAEBD7, // rgb(250,235,215) - aqua = 0x00FFFF, // rgb(0,255,255) - aquamarine = 0x7FFFD4, // rgb(127,255,212) - azure = 0xF0FFFF, // rgb(240,255,255) - beige = 0xF5F5DC, // rgb(245,245,220) - bisque = 0xFFE4C4, // rgb(255,228,196) - black = 0x000000, // rgb(0,0,0) - blanched_almond = 0xFFEBCD, // rgb(255,235,205) - blue = 0x0000FF, // rgb(0,0,255) - blue_violet = 0x8A2BE2, // rgb(138,43,226) - brown = 0xA52A2A, // rgb(165,42,42) - burly_wood = 0xDEB887, // rgb(222,184,135) - cadet_blue = 0x5F9EA0, // rgb(95,158,160) - chartreuse = 0x7FFF00, // rgb(127,255,0) - chocolate = 0xD2691E, // rgb(210,105,30) - coral = 0xFF7F50, // rgb(255,127,80) - cornflower_blue = 0x6495ED, // rgb(100,149,237) - cornsilk = 0xFFF8DC, // rgb(255,248,220) - crimson = 0xDC143C, // rgb(220,20,60) - cyan = 0x00FFFF, // rgb(0,255,255) - dark_blue = 0x00008B, // rgb(0,0,139) - dark_cyan = 0x008B8B, // rgb(0,139,139) - dark_golden_rod = 0xB8860B, // rgb(184,134,11) - dark_gray = 0xA9A9A9, // rgb(169,169,169) - dark_green = 0x006400, // rgb(0,100,0) - dark_khaki = 0xBDB76B, // rgb(189,183,107) - dark_magenta = 0x8B008B, // rgb(139,0,139) - dark_olive_green = 0x556B2F, // rgb(85,107,47) - dark_orange = 0xFF8C00, // rgb(255,140,0) - dark_orchid = 0x9932CC, // rgb(153,50,204) - dark_red = 0x8B0000, // rgb(139,0,0) - dark_salmon = 0xE9967A, // rgb(233,150,122) - dark_sea_green = 0x8FBC8F, // rgb(143,188,143) - dark_slate_blue = 0x483D8B, // rgb(72,61,139) - dark_slate_gray = 0x2F4F4F, // rgb(47,79,79) - dark_turquoise = 0x00CED1, // rgb(0,206,209) - dark_violet = 0x9400D3, // rgb(148,0,211) - deep_pink = 0xFF1493, // rgb(255,20,147) - deep_sky_blue = 0x00BFFF, // rgb(0,191,255) - dim_gray = 0x696969, // rgb(105,105,105) - dodger_blue = 0x1E90FF, // rgb(30,144,255) - fire_brick = 0xB22222, // rgb(178,34,34) - floral_white = 0xFFFAF0, // rgb(255,250,240) - forest_green = 0x228B22, // rgb(34,139,34) - fuchsia = 0xFF00FF, // rgb(255,0,255) - gainsboro = 0xDCDCDC, // rgb(220,220,220) - ghost_white = 0xF8F8FF, // rgb(248,248,255) - gold = 0xFFD700, // rgb(255,215,0) - golden_rod = 0xDAA520, // rgb(218,165,32) - gray = 0x808080, // rgb(128,128,128) - green = 0x008000, // rgb(0,128,0) - green_yellow = 0xADFF2F, // rgb(173,255,47) - honey_dew = 0xF0FFF0, // rgb(240,255,240) - hot_pink = 0xFF69B4, // rgb(255,105,180) - indian_red = 0xCD5C5C, // rgb(205,92,92) - indigo = 0x4B0082, // rgb(75,0,130) - ivory = 0xFFFFF0, // rgb(255,255,240) - khaki = 0xF0E68C, // rgb(240,230,140) - lavender = 0xE6E6FA, // rgb(230,230,250) - lavender_blush = 0xFFF0F5, // rgb(255,240,245) - lawn_green = 0x7CFC00, // rgb(124,252,0) - lemon_chiffon = 0xFFFACD, // rgb(255,250,205) - light_blue = 0xADD8E6, // rgb(173,216,230) - light_coral = 0xF08080, // rgb(240,128,128) - light_cyan = 0xE0FFFF, // rgb(224,255,255) - light_golden_rod_yellow = 0xFAFAD2, // rgb(250,250,210) - light_gray = 0xD3D3D3, // rgb(211,211,211) - light_green = 0x90EE90, // rgb(144,238,144) - light_pink = 0xFFB6C1, // rgb(255,182,193) - light_salmon = 0xFFA07A, // rgb(255,160,122) - light_sea_green = 0x20B2AA, // rgb(32,178,170) - light_sky_blue = 0x87CEFA, // rgb(135,206,250) - light_slate_gray = 0x778899, // rgb(119,136,153) - light_steel_blue = 0xB0C4DE, // rgb(176,196,222) - light_yellow = 0xFFFFE0, // rgb(255,255,224) - lime = 0x00FF00, // rgb(0,255,0) - lime_green = 0x32CD32, // rgb(50,205,50) - linen = 0xFAF0E6, // rgb(250,240,230) - magenta = 0xFF00FF, // rgb(255,0,255) - maroon = 0x800000, // rgb(128,0,0) - medium_aquamarine = 0x66CDAA, // rgb(102,205,170) - medium_blue = 0x0000CD, // rgb(0,0,205) - medium_orchid = 0xBA55D3, // rgb(186,85,211) - medium_purple = 0x9370DB, // rgb(147,112,219) - medium_sea_green = 0x3CB371, // rgb(60,179,113) - medium_slate_blue = 0x7B68EE, // rgb(123,104,238) - medium_spring_green = 0x00FA9A, // rgb(0,250,154) - medium_turquoise = 0x48D1CC, // rgb(72,209,204) - medium_violet_red = 0xC71585, // rgb(199,21,133) - midnight_blue = 0x191970, // rgb(25,25,112) - mint_cream = 0xF5FFFA, // rgb(245,255,250) - misty_rose = 0xFFE4E1, // rgb(255,228,225) - moccasin = 0xFFE4B5, // rgb(255,228,181) - navajo_white = 0xFFDEAD, // rgb(255,222,173) - navy = 0x000080, // rgb(0,0,128) - old_lace = 0xFDF5E6, // rgb(253,245,230) - olive = 0x808000, // rgb(128,128,0) - olive_drab = 0x6B8E23, // rgb(107,142,35) - orange = 0xFFA500, // rgb(255,165,0) - orange_red = 0xFF4500, // rgb(255,69,0) - orchid = 0xDA70D6, // rgb(218,112,214) - pale_golden_rod = 0xEEE8AA, // rgb(238,232,170) - pale_green = 0x98FB98, // rgb(152,251,152) - pale_turquoise = 0xAFEEEE, // rgb(175,238,238) - pale_violet_red = 0xDB7093, // rgb(219,112,147) - papaya_whip = 0xFFEFD5, // rgb(255,239,213) - peach_puff = 0xFFDAB9, // rgb(255,218,185) - peru = 0xCD853F, // rgb(205,133,63) - pink = 0xFFC0CB, // rgb(255,192,203) - plum = 0xDDA0DD, // rgb(221,160,221) - powder_blue = 0xB0E0E6, // rgb(176,224,230) - purple = 0x800080, // rgb(128,0,128) - rebecca_purple = 0x663399, // rgb(102,51,153) - red = 0xFF0000, // rgb(255,0,0) - rosy_brown = 0xBC8F8F, // rgb(188,143,143) - royal_blue = 0x4169E1, // rgb(65,105,225) - saddle_brown = 0x8B4513, // rgb(139,69,19) - salmon = 0xFA8072, // rgb(250,128,114) - sandy_brown = 0xF4A460, // rgb(244,164,96) - sea_green = 0x2E8B57, // rgb(46,139,87) - sea_shell = 0xFFF5EE, // rgb(255,245,238) - sienna = 0xA0522D, // rgb(160,82,45) - silver = 0xC0C0C0, // rgb(192,192,192) - sky_blue = 0x87CEEB, // rgb(135,206,235) - slate_blue = 0x6A5ACD, // rgb(106,90,205) - slate_gray = 0x708090, // rgb(112,128,144) - snow = 0xFFFAFA, // rgb(255,250,250) - spring_green = 0x00FF7F, // rgb(0,255,127) - steel_blue = 0x4682B4, // rgb(70,130,180) - tan = 0xD2B48C, // rgb(210,180,140) - teal = 0x008080, // rgb(0,128,128) - thistle = 0xD8BFD8, // rgb(216,191,216) - tomato = 0xFF6347, // rgb(255,99,71) - turquoise = 0x40E0D0, // rgb(64,224,208) - violet = 0xEE82EE, // rgb(238,130,238) - wheat = 0xF5DEB3, // rgb(245,222,179) - white = 0xFFFFFF, // rgb(255,255,255) - white_smoke = 0xF5F5F5, // rgb(245,245,245) - yellow = 0xFFFF00, // rgb(255,255,0) - yellow_green = 0x9ACD32 // rgb(154,205,50) -}; // enum class color - -enum class terminal_color : uint8_t { - black = 30, - red, - green, - yellow, - blue, - magenta, - cyan, - white, - bright_black = 90, - bright_red, - bright_green, - bright_yellow, - bright_blue, - bright_magenta, - bright_cyan, - bright_white -}; - -enum class emphasis : uint8_t { - bold = 1, - faint = 1 << 1, - italic = 1 << 2, - underline = 1 << 3, - blink = 1 << 4, - reverse = 1 << 5, - conceal = 1 << 6, - strikethrough = 1 << 7, -}; - -// rgb is a struct for red, green and blue colors. -// Using the name "rgb" makes some editors show the color in a tooltip. -struct rgb { - constexpr rgb() : r(0), g(0), b(0) {} - constexpr rgb(uint8_t r_, uint8_t g_, uint8_t b_) : r(r_), g(g_), b(b_) {} - constexpr rgb(uint32_t hex) - : r((hex >> 16) & 0xFF), g((hex >> 8) & 0xFF), b(hex & 0xFF) {} - constexpr rgb(color hex) - : r((uint32_t(hex) >> 16) & 0xFF), - g((uint32_t(hex) >> 8) & 0xFF), - b(uint32_t(hex) & 0xFF) {} - uint8_t r; - uint8_t g; - uint8_t b; -}; - -namespace detail { - -// A bit-packed variant of an RGB color, a terminal color, or unset color. -// see text_style for the bit-packing scheme. -struct color_type { - constexpr color_type() noexcept = default; - constexpr color_type(color rgb_color) noexcept - : value_(static_cast(rgb_color) | (1 << 24)) {} - constexpr color_type(rgb rgb_color) noexcept - : color_type(static_cast( - (static_cast(rgb_color.r) << 16) | - (static_cast(rgb_color.g) << 8) | rgb_color.b)) {} - constexpr color_type(terminal_color term_color) noexcept - : value_(static_cast(term_color) | (3 << 24)) {} - - constexpr auto is_terminal_color() const noexcept -> bool { - return (value_ & (1 << 25)) != 0; - } - - constexpr auto value() const noexcept -> uint32_t { - return value_ & 0xFFFFFF; - } - - constexpr color_type(uint32_t value) noexcept : value_(value) {} - - uint32_t value_ = 0; -}; -} // namespace detail - -/// A text style consisting of foreground and background colors and emphasis. -class text_style { - // The information is packed as follows: - // ┌──┠- // │ 0│─┠- // │..│ ├── foreground color value - // │23│─┘ - // ├──┤ - // │24│─┬── discriminator for the above value. 00 if unset, 01 if it's - // │25│─┘ an RGB color, or 11 if it's a terminal color (10 is unused) - // ├──┤ - // │26│──── overflow bit, always zero (see below) - // ├──┤ - // │27│─┠- // │..│ │ - // │50│ │ - // ├──┤ │ - // │51│ ├── background color (same format as the foreground color) - // │52│ │ - // ├──┤ │ - // │53│─┘ - // ├──┤ - // │54│─┠- // │..│ ├── emphases - // │61│─┘ - // ├──┤ - // │62│─┬── unused - // │63│─┘ - // └──┘ - // The overflow bits are there to make operator|= efficient. - // When ORing, we must throw if, for either the foreground or background, - // one style specifies a terminal color and the other specifies any color - // (terminal or RGB); in other words, if one discriminator is 11 and the - // other is 11 or 01. - // - // We do that check by adding the styles. Consider what adding does to each - // possible pair of discriminators: - // 00 + 00 = 000 - // 01 + 00 = 001 - // 11 + 00 = 011 - // 01 + 01 = 010 - // 11 + 01 = 100 (!!) - // 11 + 11 = 110 (!!) - // In the last two cases, the ones we want to catch, the third bit——the - // overflow bit——is set. Bingo. - // - // We must take into account the possible carry bit from the bits - // before the discriminator. The only potentially problematic case is - // 11 + 00 = 011 (a carry bit would make it 100, not good!), but a carry - // bit is impossible in that case, because 00 (unset color) means the - // 24 bits that precede the discriminator are all zero. - // - // This test can be applied to both colors simultaneously. - - public: - FMT_CONSTEXPR text_style(emphasis em = emphasis()) noexcept - : style_(static_cast(em) << 54) {} - - FMT_CONSTEXPR auto operator|=(text_style rhs) -> text_style& { - if (((style_ + rhs.style_) & ((1ULL << 26) | (1ULL << 53))) != 0) - report_error("can't OR a terminal color"); - style_ |= rhs.style_; - return *this; - } - - friend FMT_CONSTEXPR auto operator|(text_style lhs, text_style rhs) - -> text_style { - return lhs |= rhs; - } - - FMT_CONSTEXPR auto operator==(text_style rhs) const noexcept -> bool { - return style_ == rhs.style_; - } - - FMT_CONSTEXPR auto operator!=(text_style rhs) const noexcept -> bool { - return !(*this == rhs); - } - - FMT_CONSTEXPR auto has_foreground() const noexcept -> bool { - return (style_ & (1 << 24)) != 0; - } - FMT_CONSTEXPR auto has_background() const noexcept -> bool { - return (style_ & (1ULL << 51)) != 0; - } - FMT_CONSTEXPR auto has_emphasis() const noexcept -> bool { - return (style_ >> 54) != 0; - } - FMT_CONSTEXPR auto get_foreground() const noexcept -> detail::color_type { - FMT_ASSERT(has_foreground(), "no foreground specified for this style"); - return style_ & 0x3FFFFFF; - } - FMT_CONSTEXPR auto get_background() const noexcept -> detail::color_type { - FMT_ASSERT(has_background(), "no background specified for this style"); - return (style_ >> 27) & 0x3FFFFFF; - } - FMT_CONSTEXPR auto get_emphasis() const noexcept -> emphasis { - FMT_ASSERT(has_emphasis(), "no emphasis specified for this style"); - return static_cast(style_ >> 54); - } - - private: - FMT_CONSTEXPR text_style(uint64_t style) noexcept : style_(style) {} - - friend FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept - -> text_style; - - friend FMT_CONSTEXPR auto bg(detail::color_type background) noexcept - -> text_style; - - uint64_t style_ = 0; -}; - -/// Creates a text style from the foreground (text) color. -FMT_CONSTEXPR inline auto fg(detail::color_type foreground) noexcept - -> text_style { - return foreground.value_; -} - -/// Creates a text style from the background color. -FMT_CONSTEXPR inline auto bg(detail::color_type background) noexcept - -> text_style { - return static_cast(background.value_) << 27; -} - -FMT_CONSTEXPR inline auto operator|(emphasis lhs, emphasis rhs) noexcept - -> text_style { - return text_style(lhs) | rhs; -} - -namespace detail { - -template struct ansi_color_escape { - FMT_CONSTEXPR ansi_color_escape(color_type text_color, - const char* esc) noexcept { - // If we have a terminal color, we need to output another escape code - // sequence. - if (text_color.is_terminal_color()) { - bool is_background = esc == string_view("\x1b[48;2;"); - uint32_t value = text_color.value(); - // Background ASCII codes are the same as the foreground ones but with - // 10 more. - if (is_background) value += 10u; - - buffer[size++] = static_cast('\x1b'); - buffer[size++] = static_cast('['); - - if (value >= 100u) { - buffer[size++] = static_cast('1'); - value %= 100u; - } - buffer[size++] = static_cast('0' + value / 10u); - buffer[size++] = static_cast('0' + value % 10u); - - buffer[size++] = static_cast('m'); - return; - } - - for (int i = 0; i < 7; i++) { - buffer[i] = static_cast(esc[i]); - } - rgb color(text_color.value()); - to_esc(color.r, buffer + 7, ';'); - to_esc(color.g, buffer + 11, ';'); - to_esc(color.b, buffer + 15, 'm'); - size = 19; - } - FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept { - uint8_t em_codes[num_emphases] = {}; - if (has_emphasis(em, emphasis::bold)) em_codes[0] = 1; - if (has_emphasis(em, emphasis::faint)) em_codes[1] = 2; - if (has_emphasis(em, emphasis::italic)) em_codes[2] = 3; - if (has_emphasis(em, emphasis::underline)) em_codes[3] = 4; - if (has_emphasis(em, emphasis::blink)) em_codes[4] = 5; - if (has_emphasis(em, emphasis::reverse)) em_codes[5] = 7; - if (has_emphasis(em, emphasis::conceal)) em_codes[6] = 8; - if (has_emphasis(em, emphasis::strikethrough)) em_codes[7] = 9; - - buffer[size++] = static_cast('\x1b'); - buffer[size++] = static_cast('['); - - for (size_t i = 0; i < num_emphases; ++i) { - if (!em_codes[i]) continue; - buffer[size++] = static_cast('0' + em_codes[i]); - buffer[size++] = static_cast(';'); - } - - buffer[size - 1] = static_cast('m'); - } - FMT_CONSTEXPR operator const Char*() const noexcept { return buffer; } - - FMT_CONSTEXPR auto begin() const noexcept -> const Char* { return buffer; } - FMT_CONSTEXPR auto end() const noexcept -> const Char* { - return buffer + size; - } - - private: - static constexpr size_t num_emphases = 8; - Char buffer[7u + 4u * num_emphases]; - size_t size = 0; - - static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out, - char delimiter) noexcept { - out[0] = static_cast('0' + c / 100); - out[1] = static_cast('0' + c / 10 % 10); - out[2] = static_cast('0' + c % 10); - out[3] = static_cast(delimiter); - } - static FMT_CONSTEXPR auto has_emphasis(emphasis em, emphasis mask) noexcept - -> bool { - return static_cast(em) & static_cast(mask); - } -}; - -template -FMT_CONSTEXPR auto make_foreground_color(color_type foreground) noexcept - -> ansi_color_escape { - return ansi_color_escape(foreground, "\x1b[38;2;"); -} - -template -FMT_CONSTEXPR auto make_background_color(color_type background) noexcept - -> ansi_color_escape { - return ansi_color_escape(background, "\x1b[48;2;"); -} - -template -FMT_CONSTEXPR auto make_emphasis(emphasis em) noexcept - -> ansi_color_escape { - return ansi_color_escape(em); -} - -template inline void reset_color(buffer& buffer) { - auto reset_color = string_view("\x1b[0m"); - buffer.append(reset_color.begin(), reset_color.end()); -} - -template struct styled_arg : view { - const T& value; - text_style style; - styled_arg(const T& v, text_style s) : value(v), style(s) {} -}; - -template -void vformat_to(buffer& buf, text_style ts, basic_string_view fmt, - basic_format_args> args) { - if (ts.has_emphasis()) { - auto emphasis = make_emphasis(ts.get_emphasis()); - buf.append(emphasis.begin(), emphasis.end()); - } - if (ts.has_foreground()) { - auto foreground = make_foreground_color(ts.get_foreground()); - buf.append(foreground.begin(), foreground.end()); - } - if (ts.has_background()) { - auto background = make_background_color(ts.get_background()); - buf.append(background.begin(), background.end()); - } - vformat_to(buf, fmt, args); - if (ts != text_style()) reset_color(buf); -} -} // namespace detail - -inline void vprint(FILE* f, text_style ts, string_view fmt, format_args args) { - auto buf = memory_buffer(); - detail::vformat_to(buf, ts, fmt, args); - print(f, FMT_STRING("{}"), string_view(buf.begin(), buf.size())); -} - -/** - * Formats a string and prints it to the specified file stream using ANSI - * escape sequences to specify text formatting. - * - * **Example**: - * - * fmt::print(fmt::emphasis::bold | fg(fmt::color::red), - * "Elapsed time: {0:.2f} seconds", 1.23); - */ -template -void print(FILE* f, text_style ts, format_string fmt, T&&... args) { - vprint(f, ts, fmt.str, vargs{{args...}}); -} - -/** - * Formats a string and prints it to stdout using ANSI escape sequences to - * specify text formatting. - * - * **Example**: - * - * fmt::print(fmt::emphasis::bold | fg(fmt::color::red), - * "Elapsed time: {0:.2f} seconds", 1.23); - */ -template -void print(text_style ts, format_string fmt, T&&... args) { - return print(stdout, ts, fmt, std::forward(args)...); -} - -inline auto vformat(text_style ts, string_view fmt, format_args args) - -> std::string { - auto buf = memory_buffer(); - detail::vformat_to(buf, ts, fmt, args); - return fmt::to_string(buf); -} - -/** - * Formats arguments and returns the result as a string using ANSI escape - * sequences to specify text formatting. - * - * **Example**: - * - * ``` - * #include - * std::string message = fmt::format(fmt::emphasis::bold | fg(fmt::color::red), - * "The answer is {}", 42); - * ``` - */ -template -inline auto format(text_style ts, format_string fmt, T&&... args) - -> std::string { - return fmt::vformat(ts, fmt.str, vargs{{args...}}); -} - -/// Formats a string with the given text_style and writes the output to `out`. -template ::value)> -auto vformat_to(OutputIt out, text_style ts, string_view fmt, format_args args) - -> OutputIt { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, ts, fmt, args); - return detail::get_iterator(buf, out); -} - -/** - * Formats arguments with the given text style, writes the result to the output - * iterator `out` and returns the iterator past the end of the output range. - * - * **Example**: - * - * std::vector out; - * fmt::format_to(std::back_inserter(out), - * fmt::emphasis::bold | fg(fmt::color::red), "{}", 42); - */ -template ::value)> -inline auto format_to(OutputIt out, text_style ts, format_string fmt, - T&&... args) -> OutputIt { - return vformat_to(out, ts, fmt.str, vargs{{args...}}); -} - -template -struct formatter, Char> : formatter { - template - auto format(const detail::styled_arg& arg, FormatContext& ctx) const - -> decltype(ctx.out()) { - const auto& ts = arg.style; - auto out = ctx.out(); - - bool has_style = false; - if (ts.has_emphasis()) { - has_style = true; - auto emphasis = detail::make_emphasis(ts.get_emphasis()); - out = detail::copy(emphasis.begin(), emphasis.end(), out); - } - if (ts.has_foreground()) { - has_style = true; - auto foreground = - detail::make_foreground_color(ts.get_foreground()); - out = detail::copy(foreground.begin(), foreground.end(), out); - } - if (ts.has_background()) { - has_style = true; - auto background = - detail::make_background_color(ts.get_background()); - out = detail::copy(background.begin(), background.end(), out); - } - out = formatter::format(arg.value, ctx); - if (has_style) { - auto reset_color = string_view("\x1b[0m"); - out = detail::copy(reset_color.begin(), reset_color.end(), out); - } - return out; - } -}; - -/** - * Returns an argument that will be formatted using ANSI escape sequences, - * to be used in a formatting function. - * - * **Example**: - * - * fmt::print("Elapsed time: {0:.2f} seconds", - * fmt::styled(1.23, fmt::fg(fmt::color::green) | - * fmt::bg(fmt::color::blue))); - */ -template -FMT_CONSTEXPR auto styled(const T& value, text_style ts) - -> detail::styled_arg> { - return detail::styled_arg>{value, ts}; -} - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_COLOR_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/compile.h b/examples/blueprints-example/external/fmt/bundled/compile.h deleted file mode 100644 index f711ba4..0000000 --- a/examples/blueprints-example/external/fmt/bundled/compile.h +++ /dev/null @@ -1,585 +0,0 @@ -// Formatting library for C++ - experimental format string compilation -// -// Copyright (c) 2012 - present, Victor Zverovich and fmt contributors -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_COMPILE_H_ -#define FMT_COMPILE_H_ - -#ifndef FMT_MODULE -# include // std::back_inserter -#endif - -#include "format.h" - -FMT_BEGIN_NAMESPACE - -// A compile-time string which is compiled into fast formatting code. -FMT_EXPORT class compiled_string {}; - -template -struct is_compiled_string : std::is_base_of {}; - -/** - * Converts a string literal `s` into a format string that will be parsed at - * compile time and converted into efficient formatting code. Requires C++17 - * `constexpr if` compiler support. - * - * **Example**: - * - * // Converts 42 into std::string using the most efficient method and no - * // runtime format string processing. - * std::string s = fmt::format(FMT_COMPILE("{}"), 42); - */ -#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) -# define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::compiled_string) -#else -# define FMT_COMPILE(s) FMT_STRING(s) -#endif - -/** - * Converts a string literal into a format string that will be parsed at - * compile time and converted into efficient formatting code. Requires support - * for class types in constant template parameters (a C++20 feature). - * - * **Example**: - * - * // Converts 42 into std::string using the most efficient method and no - * // runtime format string processing. - * using namespace fmt::literals; - * std::string s = fmt::format("{}"_cf, 42); - */ -#if FMT_USE_NONTYPE_TEMPLATE_ARGS -inline namespace literals { -template constexpr auto operator""_cf() { - return FMT_COMPILE(Str.data); -} -} // namespace literals -#endif - -namespace detail { - -template -constexpr auto first(const T& value, const Tail&...) -> const T& { - return value; -} - -#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) -template struct type_list {}; - -// Returns a reference to the argument at index N from [first, rest...]. -template -constexpr auto get([[maybe_unused]] const T& first, - [[maybe_unused]] const Args&... rest) -> const auto& { - static_assert(N < 1 + sizeof...(Args), "index is out of bounds"); - if constexpr (N == 0) - return first; - else - return detail::get(rest...); -} - -# if FMT_USE_NONTYPE_TEMPLATE_ARGS -template -constexpr auto get_arg_index_by_name(basic_string_view name) -> int { - if constexpr (is_static_named_arg()) { - if (name == T::name) return N; - } - if constexpr (sizeof...(Args) > 0) - return get_arg_index_by_name(name); - (void)name; // Workaround an MSVC bug about "unused" parameter. - return -1; -} -# endif - -template -FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view name) -> int { -# if FMT_USE_NONTYPE_TEMPLATE_ARGS - if constexpr (sizeof...(Args) > 0) - return get_arg_index_by_name<0, Args...>(name); -# endif - (void)name; - return -1; -} - -template -constexpr auto get_arg_index_by_name(basic_string_view name, - type_list) -> int { - return get_arg_index_by_name(name); -} - -template struct get_type_impl; - -template struct get_type_impl> { - using type = - remove_cvref_t(std::declval()...))>; -}; - -template -using get_type = typename get_type_impl::type; - -template struct is_compiled_format : std::false_type {}; - -template struct text { - basic_string_view data; - using char_type = Char; - - template - constexpr auto format(OutputIt out, const T&...) const -> OutputIt { - return write(out, data); - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -template -constexpr auto make_text(basic_string_view s, size_t pos, size_t size) - -> text { - return {{&s[pos], size}}; -} - -template struct code_unit { - Char value; - using char_type = Char; - - template - constexpr auto format(OutputIt out, const T&...) const -> OutputIt { - *out++ = value; - return out; - } -}; - -// This ensures that the argument type is convertible to `const T&`. -template -constexpr auto get_arg_checked(const Args&... args) -> const T& { - const auto& arg = detail::get(args...); - if constexpr (detail::is_named_arg>()) { - return arg.value; - } else { - return arg; - } -} - -template -struct is_compiled_format> : std::true_type {}; - -// A replacement field that refers to argument N. -template struct field { - using char_type = Char; - - template - constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { - const V& arg = get_arg_checked(args...); - if constexpr (std::is_convertible>::value) { - auto s = basic_string_view(arg); - return copy(s.begin(), s.end(), out); - } else { - return write(out, arg); - } - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -// A replacement field that refers to argument with name. -template struct runtime_named_field { - using char_type = Char; - basic_string_view name; - - template - constexpr static auto try_format_argument( - OutputIt& out, - // [[maybe_unused]] due to unused-but-set-parameter warning in GCC 7,8,9 - [[maybe_unused]] basic_string_view arg_name, const T& arg) -> bool { - if constexpr (is_named_arg::type>::value) { - if (arg_name == arg.name) { - out = write(out, arg.value); - return true; - } - } - return false; - } - - template - constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { - bool found = (try_format_argument(out, name, args) || ...); - if (!found) { - FMT_THROW(format_error("argument with specified name is not found")); - } - return out; - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -// A replacement field that refers to argument N and has format specifiers. -template struct spec_field { - using char_type = Char; - formatter fmt; - - template - constexpr FMT_INLINE auto format(OutputIt out, const T&... args) const - -> OutputIt { - const auto& vargs = - fmt::make_format_args>(args...); - basic_format_context ctx(out, vargs); - return fmt.format(get_arg_checked(args...), ctx); - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -template struct concat { - L lhs; - R rhs; - using char_type = typename L::char_type; - - template - constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { - out = lhs.format(out, args...); - return rhs.format(out, args...); - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -template -constexpr auto make_concat(L lhs, R rhs) -> concat { - return {lhs, rhs}; -} - -struct unknown_format {}; - -template -constexpr auto parse_text(basic_string_view str, size_t pos) -> size_t { - for (size_t size = str.size(); pos != size; ++pos) { - if (str[pos] == '{' || str[pos] == '}') break; - } - return pos; -} - -template -constexpr auto compile_format_string(S fmt); - -template -constexpr auto parse_tail(T head, S fmt) { - if constexpr (POS != basic_string_view(fmt).size()) { - constexpr auto tail = compile_format_string(fmt); - if constexpr (std::is_same, - unknown_format>()) - return tail; - else - return make_concat(head, tail); - } else { - return head; - } -} - -template struct parse_specs_result { - formatter fmt; - size_t end; - int next_arg_id; -}; - -enum { manual_indexing_id = -1 }; - -template -constexpr auto parse_specs(basic_string_view str, size_t pos, - int next_arg_id) -> parse_specs_result { - str.remove_prefix(pos); - auto ctx = - compile_parse_context(str, max_value(), nullptr, next_arg_id); - auto f = formatter(); - auto end = f.parse(ctx); - return {f, pos + fmt::detail::to_unsigned(end - str.data()), - next_arg_id == 0 ? manual_indexing_id : ctx.next_arg_id()}; -} - -template struct arg_id_handler { - arg_id_kind kind; - arg_ref arg_id; - - constexpr auto on_auto() -> int { - FMT_ASSERT(false, "handler cannot be used with automatic indexing"); - return 0; - } - constexpr auto on_index(int id) -> int { - kind = arg_id_kind::index; - arg_id = arg_ref(id); - return 0; - } - constexpr auto on_name(basic_string_view id) -> int { - kind = arg_id_kind::name; - arg_id = arg_ref(id); - return 0; - } -}; - -template struct parse_arg_id_result { - arg_id_kind kind; - arg_ref arg_id; - const Char* arg_id_end; -}; - -template -constexpr auto parse_arg_id(const Char* begin, const Char* end) { - auto handler = arg_id_handler{arg_id_kind::none, arg_ref{}}; - auto arg_id_end = parse_arg_id(begin, end, handler); - return parse_arg_id_result{handler.kind, handler.arg_id, arg_id_end}; -} - -template struct field_type { - using type = remove_cvref_t; -}; - -template -struct field_type::value>> { - using type = remove_cvref_t; -}; - -template -constexpr auto parse_replacement_field_then_tail(S fmt) { - using char_type = typename S::char_type; - constexpr auto str = basic_string_view(fmt); - constexpr char_type c = END_POS != str.size() ? str[END_POS] : char_type(); - if constexpr (c == '}') { - return parse_tail( - field::type, ARG_INDEX>(), fmt); - } else if constexpr (c != ':') { - FMT_THROW(format_error("expected ':'")); - } else { - constexpr auto result = parse_specs::type>( - str, END_POS + 1, NEXT_ID == manual_indexing_id ? 0 : NEXT_ID); - if constexpr (result.end >= str.size() || str[result.end] != '}') { - FMT_THROW(format_error("expected '}'")); - return 0; - } else { - return parse_tail( - spec_field::type, ARG_INDEX>{ - result.fmt}, - fmt); - } - } -} - -// Compiles a non-empty format string and returns the compiled representation -// or unknown_format() on unrecognized input. -template -constexpr auto compile_format_string(S fmt) { - using char_type = typename S::char_type; - constexpr auto str = basic_string_view(fmt); - if constexpr (str[POS] == '{') { - if constexpr (POS + 1 == str.size()) - FMT_THROW(format_error("unmatched '{' in format string")); - if constexpr (str[POS + 1] == '{') { - return parse_tail(make_text(str, POS, 1), fmt); - } else if constexpr (str[POS + 1] == '}' || str[POS + 1] == ':') { - static_assert(ID != manual_indexing_id, - "cannot switch from manual to automatic argument indexing"); - constexpr auto next_id = - ID != manual_indexing_id ? ID + 1 : manual_indexing_id; - return parse_replacement_field_then_tail, Args, - POS + 1, ID, next_id>(fmt); - } else { - constexpr auto arg_id_result = - parse_arg_id(str.data() + POS + 1, str.data() + str.size()); - constexpr auto arg_id_end_pos = arg_id_result.arg_id_end - str.data(); - constexpr char_type c = - arg_id_end_pos != str.size() ? str[arg_id_end_pos] : char_type(); - static_assert(c == '}' || c == ':', "missing '}' in format string"); - if constexpr (arg_id_result.kind == arg_id_kind::index) { - static_assert( - ID == manual_indexing_id || ID == 0, - "cannot switch from automatic to manual argument indexing"); - constexpr auto arg_index = arg_id_result.arg_id.index; - return parse_replacement_field_then_tail, - Args, arg_id_end_pos, - arg_index, manual_indexing_id>( - fmt); - } else if constexpr (arg_id_result.kind == arg_id_kind::name) { - constexpr auto arg_index = - get_arg_index_by_name(arg_id_result.arg_id.name, Args{}); - if constexpr (arg_index >= 0) { - constexpr auto next_id = - ID != manual_indexing_id ? ID + 1 : manual_indexing_id; - return parse_replacement_field_then_tail< - decltype(get_type::value), Args, arg_id_end_pos, - arg_index, next_id>(fmt); - } else if constexpr (c == '}') { - return parse_tail( - runtime_named_field{arg_id_result.arg_id.name}, fmt); - } else if constexpr (c == ':') { - return unknown_format(); // no type info for specs parsing - } - } - } - } else if constexpr (str[POS] == '}') { - if constexpr (POS + 1 == str.size()) - FMT_THROW(format_error("unmatched '}' in format string")); - return parse_tail(make_text(str, POS, 1), fmt); - } else { - constexpr auto end = parse_text(str, POS + 1); - if constexpr (end - POS > 1) { - return parse_tail(make_text(str, POS, end - POS), fmt); - } else { - return parse_tail(code_unit{str[POS]}, fmt); - } - } -} - -template ::value)> -constexpr auto compile(S fmt) { - constexpr auto str = basic_string_view(fmt); - if constexpr (str.size() == 0) { - return detail::make_text(str, 0, 0); - } else { - constexpr auto result = - detail::compile_format_string, 0, 0>(fmt); - return result; - } -} -#endif // defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) -} // namespace detail - -FMT_BEGIN_EXPORT - -#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) - -template ::value)> -FMT_INLINE FMT_CONSTEXPR_STRING auto format(const CompiledFormat& cf, - const T&... args) - -> std::basic_string { - auto s = std::basic_string(); - cf.format(std::back_inserter(s), args...); - return s; -} - -template ::value)> -constexpr FMT_INLINE auto format_to(OutputIt out, const CompiledFormat& cf, - const T&... args) -> OutputIt { - return cf.format(out, args...); -} - -template ::value)> -FMT_INLINE FMT_CONSTEXPR_STRING auto format(const S&, T&&... args) - -> std::basic_string { - if constexpr (std::is_same::value) { - constexpr auto str = basic_string_view(S()); - if constexpr (str.size() == 2 && str[0] == '{' && str[1] == '}') { - const auto& first = detail::first(args...); - if constexpr (detail::is_named_arg< - remove_cvref_t>::value) { - return fmt::to_string(first.value); - } else { - return fmt::to_string(first); - } - } - } - constexpr auto compiled = detail::compile(S()); - if constexpr (std::is_same, - detail::unknown_format>()) { - return fmt::format( - static_cast>(S()), - std::forward(args)...); - } else { - return fmt::format(compiled, std::forward(args)...); - } -} - -template ::value)> -FMT_CONSTEXPR auto format_to(OutputIt out, const S&, T&&... args) -> OutputIt { - constexpr auto compiled = detail::compile(S()); - if constexpr (std::is_same, - detail::unknown_format>()) { - return fmt::format_to( - out, static_cast>(S()), - std::forward(args)...); - } else { - return fmt::format_to(out, compiled, std::forward(args)...); - } -} -#endif - -template ::value)> -auto format_to_n(OutputIt out, size_t n, const S& fmt, T&&... args) - -> format_to_n_result { - using traits = detail::fixed_buffer_traits; - auto buf = detail::iterator_buffer(out, n); - fmt::format_to(std::back_inserter(buf), fmt, std::forward(args)...); - return {buf.out(), buf.count()}; -} - -template ::value)> -FMT_CONSTEXPR20 auto formatted_size(const S& fmt, T&&... args) -> size_t { - auto buf = detail::counting_buffer<>(); - fmt::format_to(appender(buf), fmt, std::forward(args)...); - return buf.count(); -} - -template ::value)> -void print(std::FILE* f, const S& fmt, T&&... args) { - auto buf = memory_buffer(); - fmt::format_to(appender(buf), fmt, std::forward(args)...); - detail::print(f, {buf.data(), buf.size()}); -} - -template ::value)> -void print(const S& fmt, T&&... args) { - print(stdout, fmt, std::forward(args)...); -} - -template class static_format_result { - private: - char data[N]; - - public: - template ::value)> - explicit FMT_CONSTEXPR static_format_result(const S& fmt, T&&... args) { - *fmt::format_to(data, fmt, std::forward(args)...) = '\0'; - } - - auto str() const -> fmt::string_view { return {data, N - 1}; } - auto c_str() const -> const char* { return data; } -}; - -/** - * Formats arguments according to the format string `fmt_str` and produces - * a string of the exact required size at compile time. Both the format string - * and the arguments must be compile-time expressions. - * - * The resulting string can be accessed as a C string via `c_str()` or as - * a `fmt::string_view` via `str()`. - * - * **Example**: - * - * // Produces the static string "42" at compile time. - * static constexpr auto result = FMT_STATIC_FORMAT("{}", 42); - * const char* s = result.c_str(); - */ -#define FMT_STATIC_FORMAT(fmt_str, ...) \ - fmt::static_format_result< \ - fmt::formatted_size(FMT_COMPILE(fmt_str), __VA_ARGS__) + 1>( \ - FMT_COMPILE(fmt_str), __VA_ARGS__) - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_COMPILE_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/core.h b/examples/blueprints-example/external/fmt/bundled/core.h deleted file mode 100644 index 8ca735f..0000000 --- a/examples/blueprints-example/external/fmt/bundled/core.h +++ /dev/null @@ -1,5 +0,0 @@ -// This file is only provided for compatibility and may be removed in future -// versions. Use fmt/base.h if you don't need fmt::format and fmt/format.h -// otherwise. - -#include "format.h" diff --git a/examples/blueprints-example/external/fmt/bundled/fmt.license.rst b/examples/blueprints-example/external/fmt/bundled/fmt.license.rst deleted file mode 100644 index 1cd1ef9..0000000 --- a/examples/blueprints-example/external/fmt/bundled/fmt.license.rst +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ---- Optional exception to the license --- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into a machine-executable object form of such -source code, you may redistribute such embedded portions in such object form -without including the above copyright and permission notices. diff --git a/examples/blueprints-example/external/fmt/bundled/format-inl.h b/examples/blueprints-example/external/fmt/bundled/format-inl.h deleted file mode 100644 index 9d568dc..0000000 --- a/examples/blueprints-example/external/fmt/bundled/format-inl.h +++ /dev/null @@ -1,1953 +0,0 @@ -// Formatting library for C++ - implementation -// -// Copyright (c) 2012 - 2016, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_FORMAT_INL_H_ -#define FMT_FORMAT_INL_H_ - -#ifndef FMT_MODULE -# include -# include // errno -# include -# include -# include -#endif - -#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE) -# include // _isatty -#endif - -#include "format.h" - -#if FMT_USE_LOCALE && !defined(FMT_MODULE) -# include -#endif - -#ifndef FMT_FUNC -# define FMT_FUNC -#endif - -FMT_BEGIN_NAMESPACE - -#ifndef FMT_CUSTOM_ASSERT_FAIL -FMT_FUNC void assert_fail(const char* file, int line, const char* message) { - // Use unchecked std::fprintf to avoid triggering another assertion when - // writing to stderr fails. - fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message); - abort(); -} -#endif - -#if FMT_USE_LOCALE -namespace detail { -using std::locale; -using std::numpunct; -using std::use_facet; -} // namespace detail - -template > -locale_ref::locale_ref(const Locale& loc) : locale_(&loc) { - static_assert(std::is_same::value, ""); -} -#else -namespace detail { -struct locale {}; -template struct numpunct { - auto grouping() const -> std::string { return "\03"; } - auto thousands_sep() const -> Char { return ','; } - auto decimal_point() const -> Char { return '.'; } -}; -template Facet use_facet(locale) { return {}; } -} // namespace detail -#endif // FMT_USE_LOCALE - -template auto locale_ref::get() const -> Locale { - using namespace detail; - static_assert(std::is_same::value, ""); -#if FMT_USE_LOCALE - if (locale_) return *static_cast(locale_); -#endif - return locale(); -} - -namespace detail { - -FMT_FUNC void format_error_code(detail::buffer& out, int error_code, - string_view message) noexcept { - // Report error code making sure that the output fits into - // inline_buffer_size to avoid dynamic memory allocation and potential - // bad_alloc. - out.try_resize(0); - static const char SEP[] = ": "; - static const char ERROR_STR[] = "error "; - // Subtract 2 to account for terminating null characters in SEP and ERROR_STR. - size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; - auto abs_value = static_cast>(error_code); - if (detail::is_negative(error_code)) { - abs_value = 0 - abs_value; - ++error_code_size; - } - error_code_size += detail::to_unsigned(detail::count_digits(abs_value)); - auto it = appender(out); - if (message.size() <= inline_buffer_size - error_code_size) - fmt::format_to(it, FMT_STRING("{}{}"), message, SEP); - fmt::format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code); - FMT_ASSERT(out.size() <= inline_buffer_size, ""); -} - -FMT_FUNC void do_report_error(format_func func, int error_code, - const char* message) noexcept { - memory_buffer full_message; - func(full_message, error_code, message); - // Don't use fwrite_all because the latter may throw. - if (std::fwrite(full_message.data(), full_message.size(), 1, stderr) > 0) - std::fputc('\n', stderr); -} - -// A wrapper around fwrite that throws on error. -inline void fwrite_all(const void* ptr, size_t count, FILE* stream) { - size_t written = std::fwrite(ptr, 1, count, stream); - if (written < count) - FMT_THROW(system_error(errno, FMT_STRING("cannot write to file"))); -} - -template -FMT_FUNC auto thousands_sep_impl(locale_ref loc) -> thousands_sep_result { - auto&& facet = use_facet>(loc.get()); - auto grouping = facet.grouping(); - auto thousands_sep = grouping.empty() ? Char() : facet.thousands_sep(); - return {std::move(grouping), thousands_sep}; -} -template -FMT_FUNC auto decimal_point_impl(locale_ref loc) -> Char { - return use_facet>(loc.get()).decimal_point(); -} - -#if FMT_USE_LOCALE -FMT_FUNC auto write_loc(appender out, loc_value value, - const format_specs& specs, locale_ref loc) -> bool { - auto locale = loc.get(); - // We cannot use the num_put facet because it may produce output in - // a wrong encoding. - using facet = format_facet; - if (std::has_facet(locale)) - return use_facet(locale).put(out, value, specs); - return facet(locale).put(out, value, specs); -} -#endif -} // namespace detail - -FMT_FUNC void report_error(const char* message) { -#if FMT_MSC_VERSION || defined(__NVCC__) - // Silence unreachable code warnings in MSVC and NVCC because these - // are nearly impossible to fix in a generic code. - volatile bool b = true; - if (!b) return; -#endif - FMT_THROW(format_error(message)); -} - -template typename Locale::id format_facet::id; - -template format_facet::format_facet(Locale& loc) { - auto& np = detail::use_facet>(loc); - grouping_ = np.grouping(); - if (!grouping_.empty()) separator_ = std::string(1, np.thousands_sep()); -} - -#if FMT_USE_LOCALE -template <> -FMT_API FMT_FUNC auto format_facet::do_put( - appender out, loc_value val, const format_specs& specs) const -> bool { - return val.visit( - detail::loc_writer<>{out, specs, separator_, grouping_, decimal_point_}); -} -#endif - -FMT_FUNC auto vsystem_error(int error_code, string_view fmt, format_args args) - -> std::system_error { - auto ec = std::error_code(error_code, std::generic_category()); - return std::system_error(ec, vformat(fmt, args)); -} - -namespace detail { - -template -inline auto operator==(basic_fp x, basic_fp y) -> bool { - return x.f == y.f && x.e == y.e; -} - -// Compilers should be able to optimize this into the ror instruction. -FMT_INLINE auto rotr(uint32_t n, uint32_t r) noexcept -> uint32_t { - r &= 31; - return (n >> r) | (n << (32 - r)); -} -FMT_INLINE auto rotr(uint64_t n, uint32_t r) noexcept -> uint64_t { - r &= 63; - return (n >> r) | (n << (64 - r)); -} - -// Implementation of Dragonbox algorithm: https://github.com/jk-jeon/dragonbox. -namespace dragonbox { -// Computes upper 64 bits of multiplication of a 32-bit unsigned integer and a -// 64-bit unsigned integer. -inline auto umul96_upper64(uint32_t x, uint64_t y) noexcept -> uint64_t { - return umul128_upper64(static_cast(x) << 32, y); -} - -// Computes lower 128 bits of multiplication of a 64-bit unsigned integer and a -// 128-bit unsigned integer. -inline auto umul192_lower128(uint64_t x, uint128_fallback y) noexcept - -> uint128_fallback { - uint64_t high = x * y.high(); - uint128_fallback high_low = umul128(x, y.low()); - return {high + high_low.high(), high_low.low()}; -} - -// Computes lower 64 bits of multiplication of a 32-bit unsigned integer and a -// 64-bit unsigned integer. -inline auto umul96_lower64(uint32_t x, uint64_t y) noexcept -> uint64_t { - return x * y; -} - -// Various fast log computations. -inline auto floor_log10_pow2_minus_log10_4_over_3(int e) noexcept -> int { - FMT_ASSERT(e <= 2936 && e >= -2985, "too large exponent"); - return (e * 631305 - 261663) >> 21; -} - -FMT_INLINE_VARIABLE constexpr struct div_small_pow10_infos_struct { - uint32_t divisor; - int shift_amount; -} div_small_pow10_infos[] = {{10, 16}, {100, 16}}; - -// Replaces n by floor(n / pow(10, N)) returning true if and only if n is -// divisible by pow(10, N). -// Precondition: n <= pow(10, N + 1). -template -auto check_divisibility_and_divide_by_pow10(uint32_t& n) noexcept -> bool { - // The numbers below are chosen such that: - // 1. floor(n/d) = floor(nm / 2^k) where d=10 or d=100, - // 2. nm mod 2^k < m if and only if n is divisible by d, - // where m is magic_number, k is shift_amount - // and d is divisor. - // - // Item 1 is a common technique of replacing division by a constant with - // multiplication, see e.g. "Division by Invariant Integers Using - // Multiplication" by Granlund and Montgomery (1994). magic_number (m) is set - // to ceil(2^k/d) for large enough k. - // The idea for item 2 originates from Schubfach. - constexpr auto info = div_small_pow10_infos[N - 1]; - FMT_ASSERT(n <= info.divisor * 10, "n is too large"); - constexpr uint32_t magic_number = - (1u << info.shift_amount) / info.divisor + 1; - n *= magic_number; - const uint32_t comparison_mask = (1u << info.shift_amount) - 1; - bool result = (n & comparison_mask) < magic_number; - n >>= info.shift_amount; - return result; -} - -// Computes floor(n / pow(10, N)) for small n and N. -// Precondition: n <= pow(10, N + 1). -template auto small_division_by_pow10(uint32_t n) noexcept -> uint32_t { - constexpr auto info = div_small_pow10_infos[N - 1]; - FMT_ASSERT(n <= info.divisor * 10, "n is too large"); - constexpr uint32_t magic_number = - (1u << info.shift_amount) / info.divisor + 1; - return (n * magic_number) >> info.shift_amount; -} - -// Computes floor(n / 10^(kappa + 1)) (float) -inline auto divide_by_10_to_kappa_plus_1(uint32_t n) noexcept -> uint32_t { - // 1374389535 = ceil(2^37/100) - return static_cast((static_cast(n) * 1374389535) >> 37); -} -// Computes floor(n / 10^(kappa + 1)) (double) -inline auto divide_by_10_to_kappa_plus_1(uint64_t n) noexcept -> uint64_t { - // 2361183241434822607 = ceil(2^(64+7)/1000) - return umul128_upper64(n, 2361183241434822607ull) >> 7; -} - -// Various subroutines using pow10 cache -template struct cache_accessor; - -template <> struct cache_accessor { - using carrier_uint = float_info::carrier_uint; - using cache_entry_type = uint64_t; - - static auto get_cached_power(int k) noexcept -> uint64_t { - FMT_ASSERT(k >= float_info::min_k && k <= float_info::max_k, - "k is out of range"); - static constexpr uint64_t pow10_significands[] = { - 0x81ceb32c4b43fcf5, 0xa2425ff75e14fc32, 0xcad2f7f5359a3b3f, - 0xfd87b5f28300ca0e, 0x9e74d1b791e07e49, 0xc612062576589ddb, - 0xf79687aed3eec552, 0x9abe14cd44753b53, 0xc16d9a0095928a28, - 0xf1c90080baf72cb2, 0x971da05074da7bef, 0xbce5086492111aeb, - 0xec1e4a7db69561a6, 0x9392ee8e921d5d08, 0xb877aa3236a4b44a, - 0xe69594bec44de15c, 0x901d7cf73ab0acda, 0xb424dc35095cd810, - 0xe12e13424bb40e14, 0x8cbccc096f5088cc, 0xafebff0bcb24aaff, - 0xdbe6fecebdedd5bf, 0x89705f4136b4a598, 0xabcc77118461cefd, - 0xd6bf94d5e57a42bd, 0x8637bd05af6c69b6, 0xa7c5ac471b478424, - 0xd1b71758e219652c, 0x83126e978d4fdf3c, 0xa3d70a3d70a3d70b, - 0xcccccccccccccccd, 0x8000000000000000, 0xa000000000000000, - 0xc800000000000000, 0xfa00000000000000, 0x9c40000000000000, - 0xc350000000000000, 0xf424000000000000, 0x9896800000000000, - 0xbebc200000000000, 0xee6b280000000000, 0x9502f90000000000, - 0xba43b74000000000, 0xe8d4a51000000000, 0x9184e72a00000000, - 0xb5e620f480000000, 0xe35fa931a0000000, 0x8e1bc9bf04000000, - 0xb1a2bc2ec5000000, 0xde0b6b3a76400000, 0x8ac7230489e80000, - 0xad78ebc5ac620000, 0xd8d726b7177a8000, 0x878678326eac9000, - 0xa968163f0a57b400, 0xd3c21bcecceda100, 0x84595161401484a0, - 0xa56fa5b99019a5c8, 0xcecb8f27f4200f3a, 0x813f3978f8940985, - 0xa18f07d736b90be6, 0xc9f2c9cd04674edf, 0xfc6f7c4045812297, - 0x9dc5ada82b70b59e, 0xc5371912364ce306, 0xf684df56c3e01bc7, - 0x9a130b963a6c115d, 0xc097ce7bc90715b4, 0xf0bdc21abb48db21, - 0x96769950b50d88f5, 0xbc143fa4e250eb32, 0xeb194f8e1ae525fe, - 0x92efd1b8d0cf37bf, 0xb7abc627050305ae, 0xe596b7b0c643c71a, - 0x8f7e32ce7bea5c70, 0xb35dbf821ae4f38c, 0xe0352f62a19e306f}; - return pow10_significands[k - float_info::min_k]; - } - - struct compute_mul_result { - carrier_uint result; - bool is_integer; - }; - struct compute_mul_parity_result { - bool parity; - bool is_integer; - }; - - static auto compute_mul(carrier_uint u, - const cache_entry_type& cache) noexcept - -> compute_mul_result { - auto r = umul96_upper64(u, cache); - return {static_cast(r >> 32), - static_cast(r) == 0}; - } - - static auto compute_delta(const cache_entry_type& cache, int beta) noexcept - -> uint32_t { - return static_cast(cache >> (64 - 1 - beta)); - } - - static auto compute_mul_parity(carrier_uint two_f, - const cache_entry_type& cache, - int beta) noexcept - -> compute_mul_parity_result { - FMT_ASSERT(beta >= 1, ""); - FMT_ASSERT(beta < 64, ""); - - auto r = umul96_lower64(two_f, cache); - return {((r >> (64 - beta)) & 1) != 0, - static_cast(r >> (32 - beta)) == 0}; - } - - static auto compute_left_endpoint_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return static_cast( - (cache - (cache >> (num_significand_bits() + 2))) >> - (64 - num_significand_bits() - 1 - beta)); - } - - static auto compute_right_endpoint_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return static_cast( - (cache + (cache >> (num_significand_bits() + 1))) >> - (64 - num_significand_bits() - 1 - beta)); - } - - static auto compute_round_up_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return (static_cast( - cache >> (64 - num_significand_bits() - 2 - beta)) + - 1) / - 2; - } -}; - -template <> struct cache_accessor { - using carrier_uint = float_info::carrier_uint; - using cache_entry_type = uint128_fallback; - - static auto get_cached_power(int k) noexcept -> uint128_fallback { - FMT_ASSERT(k >= float_info::min_k && k <= float_info::max_k, - "k is out of range"); - - static constexpr uint128_fallback pow10_significands[] = { -#if FMT_USE_FULL_CACHE_DRAGONBOX - {0xff77b1fcbebcdc4f, 0x25e8e89c13bb0f7b}, - {0x9faacf3df73609b1, 0x77b191618c54e9ad}, - {0xc795830d75038c1d, 0xd59df5b9ef6a2418}, - {0xf97ae3d0d2446f25, 0x4b0573286b44ad1e}, - {0x9becce62836ac577, 0x4ee367f9430aec33}, - {0xc2e801fb244576d5, 0x229c41f793cda740}, - {0xf3a20279ed56d48a, 0x6b43527578c11110}, - {0x9845418c345644d6, 0x830a13896b78aaaa}, - {0xbe5691ef416bd60c, 0x23cc986bc656d554}, - {0xedec366b11c6cb8f, 0x2cbfbe86b7ec8aa9}, - {0x94b3a202eb1c3f39, 0x7bf7d71432f3d6aa}, - {0xb9e08a83a5e34f07, 0xdaf5ccd93fb0cc54}, - {0xe858ad248f5c22c9, 0xd1b3400f8f9cff69}, - {0x91376c36d99995be, 0x23100809b9c21fa2}, - {0xb58547448ffffb2d, 0xabd40a0c2832a78b}, - {0xe2e69915b3fff9f9, 0x16c90c8f323f516d}, - {0x8dd01fad907ffc3b, 0xae3da7d97f6792e4}, - {0xb1442798f49ffb4a, 0x99cd11cfdf41779d}, - {0xdd95317f31c7fa1d, 0x40405643d711d584}, - {0x8a7d3eef7f1cfc52, 0x482835ea666b2573}, - {0xad1c8eab5ee43b66, 0xda3243650005eed0}, - {0xd863b256369d4a40, 0x90bed43e40076a83}, - {0x873e4f75e2224e68, 0x5a7744a6e804a292}, - {0xa90de3535aaae202, 0x711515d0a205cb37}, - {0xd3515c2831559a83, 0x0d5a5b44ca873e04}, - {0x8412d9991ed58091, 0xe858790afe9486c3}, - {0xa5178fff668ae0b6, 0x626e974dbe39a873}, - {0xce5d73ff402d98e3, 0xfb0a3d212dc81290}, - {0x80fa687f881c7f8e, 0x7ce66634bc9d0b9a}, - {0xa139029f6a239f72, 0x1c1fffc1ebc44e81}, - {0xc987434744ac874e, 0xa327ffb266b56221}, - {0xfbe9141915d7a922, 0x4bf1ff9f0062baa9}, - {0x9d71ac8fada6c9b5, 0x6f773fc3603db4aa}, - {0xc4ce17b399107c22, 0xcb550fb4384d21d4}, - {0xf6019da07f549b2b, 0x7e2a53a146606a49}, - {0x99c102844f94e0fb, 0x2eda7444cbfc426e}, - {0xc0314325637a1939, 0xfa911155fefb5309}, - {0xf03d93eebc589f88, 0x793555ab7eba27cb}, - {0x96267c7535b763b5, 0x4bc1558b2f3458df}, - {0xbbb01b9283253ca2, 0x9eb1aaedfb016f17}, - {0xea9c227723ee8bcb, 0x465e15a979c1cadd}, - {0x92a1958a7675175f, 0x0bfacd89ec191eca}, - {0xb749faed14125d36, 0xcef980ec671f667c}, - {0xe51c79a85916f484, 0x82b7e12780e7401b}, - {0x8f31cc0937ae58d2, 0xd1b2ecb8b0908811}, - {0xb2fe3f0b8599ef07, 0x861fa7e6dcb4aa16}, - {0xdfbdcece67006ac9, 0x67a791e093e1d49b}, - {0x8bd6a141006042bd, 0xe0c8bb2c5c6d24e1}, - {0xaecc49914078536d, 0x58fae9f773886e19}, - {0xda7f5bf590966848, 0xaf39a475506a899f}, - {0x888f99797a5e012d, 0x6d8406c952429604}, - {0xaab37fd7d8f58178, 0xc8e5087ba6d33b84}, - {0xd5605fcdcf32e1d6, 0xfb1e4a9a90880a65}, - {0x855c3be0a17fcd26, 0x5cf2eea09a550680}, - {0xa6b34ad8c9dfc06f, 0xf42faa48c0ea481f}, - {0xd0601d8efc57b08b, 0xf13b94daf124da27}, - {0x823c12795db6ce57, 0x76c53d08d6b70859}, - {0xa2cb1717b52481ed, 0x54768c4b0c64ca6f}, - {0xcb7ddcdda26da268, 0xa9942f5dcf7dfd0a}, - {0xfe5d54150b090b02, 0xd3f93b35435d7c4d}, - {0x9efa548d26e5a6e1, 0xc47bc5014a1a6db0}, - {0xc6b8e9b0709f109a, 0x359ab6419ca1091c}, - {0xf867241c8cc6d4c0, 0xc30163d203c94b63}, - {0x9b407691d7fc44f8, 0x79e0de63425dcf1e}, - {0xc21094364dfb5636, 0x985915fc12f542e5}, - {0xf294b943e17a2bc4, 0x3e6f5b7b17b2939e}, - {0x979cf3ca6cec5b5a, 0xa705992ceecf9c43}, - {0xbd8430bd08277231, 0x50c6ff782a838354}, - {0xece53cec4a314ebd, 0xa4f8bf5635246429}, - {0x940f4613ae5ed136, 0x871b7795e136be9a}, - {0xb913179899f68584, 0x28e2557b59846e40}, - {0xe757dd7ec07426e5, 0x331aeada2fe589d0}, - {0x9096ea6f3848984f, 0x3ff0d2c85def7622}, - {0xb4bca50b065abe63, 0x0fed077a756b53aa}, - {0xe1ebce4dc7f16dfb, 0xd3e8495912c62895}, - {0x8d3360f09cf6e4bd, 0x64712dd7abbbd95d}, - {0xb080392cc4349dec, 0xbd8d794d96aacfb4}, - {0xdca04777f541c567, 0xecf0d7a0fc5583a1}, - {0x89e42caaf9491b60, 0xf41686c49db57245}, - {0xac5d37d5b79b6239, 0x311c2875c522ced6}, - {0xd77485cb25823ac7, 0x7d633293366b828c}, - {0x86a8d39ef77164bc, 0xae5dff9c02033198}, - {0xa8530886b54dbdeb, 0xd9f57f830283fdfd}, - {0xd267caa862a12d66, 0xd072df63c324fd7c}, - {0x8380dea93da4bc60, 0x4247cb9e59f71e6e}, - {0xa46116538d0deb78, 0x52d9be85f074e609}, - {0xcd795be870516656, 0x67902e276c921f8c}, - {0x806bd9714632dff6, 0x00ba1cd8a3db53b7}, - {0xa086cfcd97bf97f3, 0x80e8a40eccd228a5}, - {0xc8a883c0fdaf7df0, 0x6122cd128006b2ce}, - {0xfad2a4b13d1b5d6c, 0x796b805720085f82}, - {0x9cc3a6eec6311a63, 0xcbe3303674053bb1}, - {0xc3f490aa77bd60fc, 0xbedbfc4411068a9d}, - {0xf4f1b4d515acb93b, 0xee92fb5515482d45}, - {0x991711052d8bf3c5, 0x751bdd152d4d1c4b}, - {0xbf5cd54678eef0b6, 0xd262d45a78a0635e}, - {0xef340a98172aace4, 0x86fb897116c87c35}, - {0x9580869f0e7aac0e, 0xd45d35e6ae3d4da1}, - {0xbae0a846d2195712, 0x8974836059cca10a}, - {0xe998d258869facd7, 0x2bd1a438703fc94c}, - {0x91ff83775423cc06, 0x7b6306a34627ddd0}, - {0xb67f6455292cbf08, 0x1a3bc84c17b1d543}, - {0xe41f3d6a7377eeca, 0x20caba5f1d9e4a94}, - {0x8e938662882af53e, 0x547eb47b7282ee9d}, - {0xb23867fb2a35b28d, 0xe99e619a4f23aa44}, - {0xdec681f9f4c31f31, 0x6405fa00e2ec94d5}, - {0x8b3c113c38f9f37e, 0xde83bc408dd3dd05}, - {0xae0b158b4738705e, 0x9624ab50b148d446}, - {0xd98ddaee19068c76, 0x3badd624dd9b0958}, - {0x87f8a8d4cfa417c9, 0xe54ca5d70a80e5d7}, - {0xa9f6d30a038d1dbc, 0x5e9fcf4ccd211f4d}, - {0xd47487cc8470652b, 0x7647c32000696720}, - {0x84c8d4dfd2c63f3b, 0x29ecd9f40041e074}, - {0xa5fb0a17c777cf09, 0xf468107100525891}, - {0xcf79cc9db955c2cc, 0x7182148d4066eeb5}, - {0x81ac1fe293d599bf, 0xc6f14cd848405531}, - {0xa21727db38cb002f, 0xb8ada00e5a506a7d}, - {0xca9cf1d206fdc03b, 0xa6d90811f0e4851d}, - {0xfd442e4688bd304a, 0x908f4a166d1da664}, - {0x9e4a9cec15763e2e, 0x9a598e4e043287ff}, - {0xc5dd44271ad3cdba, 0x40eff1e1853f29fe}, - {0xf7549530e188c128, 0xd12bee59e68ef47d}, - {0x9a94dd3e8cf578b9, 0x82bb74f8301958cf}, - {0xc13a148e3032d6e7, 0xe36a52363c1faf02}, - {0xf18899b1bc3f8ca1, 0xdc44e6c3cb279ac2}, - {0x96f5600f15a7b7e5, 0x29ab103a5ef8c0ba}, - {0xbcb2b812db11a5de, 0x7415d448f6b6f0e8}, - {0xebdf661791d60f56, 0x111b495b3464ad22}, - {0x936b9fcebb25c995, 0xcab10dd900beec35}, - {0xb84687c269ef3bfb, 0x3d5d514f40eea743}, - {0xe65829b3046b0afa, 0x0cb4a5a3112a5113}, - {0x8ff71a0fe2c2e6dc, 0x47f0e785eaba72ac}, - {0xb3f4e093db73a093, 0x59ed216765690f57}, - {0xe0f218b8d25088b8, 0x306869c13ec3532d}, - {0x8c974f7383725573, 0x1e414218c73a13fc}, - {0xafbd2350644eeacf, 0xe5d1929ef90898fb}, - {0xdbac6c247d62a583, 0xdf45f746b74abf3a}, - {0x894bc396ce5da772, 0x6b8bba8c328eb784}, - {0xab9eb47c81f5114f, 0x066ea92f3f326565}, - {0xd686619ba27255a2, 0xc80a537b0efefebe}, - {0x8613fd0145877585, 0xbd06742ce95f5f37}, - {0xa798fc4196e952e7, 0x2c48113823b73705}, - {0xd17f3b51fca3a7a0, 0xf75a15862ca504c6}, - {0x82ef85133de648c4, 0x9a984d73dbe722fc}, - {0xa3ab66580d5fdaf5, 0xc13e60d0d2e0ebbb}, - {0xcc963fee10b7d1b3, 0x318df905079926a9}, - {0xffbbcfe994e5c61f, 0xfdf17746497f7053}, - {0x9fd561f1fd0f9bd3, 0xfeb6ea8bedefa634}, - {0xc7caba6e7c5382c8, 0xfe64a52ee96b8fc1}, - {0xf9bd690a1b68637b, 0x3dfdce7aa3c673b1}, - {0x9c1661a651213e2d, 0x06bea10ca65c084f}, - {0xc31bfa0fe5698db8, 0x486e494fcff30a63}, - {0xf3e2f893dec3f126, 0x5a89dba3c3efccfb}, - {0x986ddb5c6b3a76b7, 0xf89629465a75e01d}, - {0xbe89523386091465, 0xf6bbb397f1135824}, - {0xee2ba6c0678b597f, 0x746aa07ded582e2d}, - {0x94db483840b717ef, 0xa8c2a44eb4571cdd}, - {0xba121a4650e4ddeb, 0x92f34d62616ce414}, - {0xe896a0d7e51e1566, 0x77b020baf9c81d18}, - {0x915e2486ef32cd60, 0x0ace1474dc1d122f}, - {0xb5b5ada8aaff80b8, 0x0d819992132456bb}, - {0xe3231912d5bf60e6, 0x10e1fff697ed6c6a}, - {0x8df5efabc5979c8f, 0xca8d3ffa1ef463c2}, - {0xb1736b96b6fd83b3, 0xbd308ff8a6b17cb3}, - {0xddd0467c64bce4a0, 0xac7cb3f6d05ddbdf}, - {0x8aa22c0dbef60ee4, 0x6bcdf07a423aa96c}, - {0xad4ab7112eb3929d, 0x86c16c98d2c953c7}, - {0xd89d64d57a607744, 0xe871c7bf077ba8b8}, - {0x87625f056c7c4a8b, 0x11471cd764ad4973}, - {0xa93af6c6c79b5d2d, 0xd598e40d3dd89bd0}, - {0xd389b47879823479, 0x4aff1d108d4ec2c4}, - {0x843610cb4bf160cb, 0xcedf722a585139bb}, - {0xa54394fe1eedb8fe, 0xc2974eb4ee658829}, - {0xce947a3da6a9273e, 0x733d226229feea33}, - {0x811ccc668829b887, 0x0806357d5a3f5260}, - {0xa163ff802a3426a8, 0xca07c2dcb0cf26f8}, - {0xc9bcff6034c13052, 0xfc89b393dd02f0b6}, - {0xfc2c3f3841f17c67, 0xbbac2078d443ace3}, - {0x9d9ba7832936edc0, 0xd54b944b84aa4c0e}, - {0xc5029163f384a931, 0x0a9e795e65d4df12}, - {0xf64335bcf065d37d, 0x4d4617b5ff4a16d6}, - {0x99ea0196163fa42e, 0x504bced1bf8e4e46}, - {0xc06481fb9bcf8d39, 0xe45ec2862f71e1d7}, - {0xf07da27a82c37088, 0x5d767327bb4e5a4d}, - {0x964e858c91ba2655, 0x3a6a07f8d510f870}, - {0xbbe226efb628afea, 0x890489f70a55368c}, - {0xeadab0aba3b2dbe5, 0x2b45ac74ccea842f}, - {0x92c8ae6b464fc96f, 0x3b0b8bc90012929e}, - {0xb77ada0617e3bbcb, 0x09ce6ebb40173745}, - {0xe55990879ddcaabd, 0xcc420a6a101d0516}, - {0x8f57fa54c2a9eab6, 0x9fa946824a12232e}, - {0xb32df8e9f3546564, 0x47939822dc96abfa}, - {0xdff9772470297ebd, 0x59787e2b93bc56f8}, - {0x8bfbea76c619ef36, 0x57eb4edb3c55b65b}, - {0xaefae51477a06b03, 0xede622920b6b23f2}, - {0xdab99e59958885c4, 0xe95fab368e45ecee}, - {0x88b402f7fd75539b, 0x11dbcb0218ebb415}, - {0xaae103b5fcd2a881, 0xd652bdc29f26a11a}, - {0xd59944a37c0752a2, 0x4be76d3346f04960}, - {0x857fcae62d8493a5, 0x6f70a4400c562ddc}, - {0xa6dfbd9fb8e5b88e, 0xcb4ccd500f6bb953}, - {0xd097ad07a71f26b2, 0x7e2000a41346a7a8}, - {0x825ecc24c873782f, 0x8ed400668c0c28c9}, - {0xa2f67f2dfa90563b, 0x728900802f0f32fb}, - {0xcbb41ef979346bca, 0x4f2b40a03ad2ffba}, - {0xfea126b7d78186bc, 0xe2f610c84987bfa9}, - {0x9f24b832e6b0f436, 0x0dd9ca7d2df4d7ca}, - {0xc6ede63fa05d3143, 0x91503d1c79720dbc}, - {0xf8a95fcf88747d94, 0x75a44c6397ce912b}, - {0x9b69dbe1b548ce7c, 0xc986afbe3ee11abb}, - {0xc24452da229b021b, 0xfbe85badce996169}, - {0xf2d56790ab41c2a2, 0xfae27299423fb9c4}, - {0x97c560ba6b0919a5, 0xdccd879fc967d41b}, - {0xbdb6b8e905cb600f, 0x5400e987bbc1c921}, - {0xed246723473e3813, 0x290123e9aab23b69}, - {0x9436c0760c86e30b, 0xf9a0b6720aaf6522}, - {0xb94470938fa89bce, 0xf808e40e8d5b3e6a}, - {0xe7958cb87392c2c2, 0xb60b1d1230b20e05}, - {0x90bd77f3483bb9b9, 0xb1c6f22b5e6f48c3}, - {0xb4ecd5f01a4aa828, 0x1e38aeb6360b1af4}, - {0xe2280b6c20dd5232, 0x25c6da63c38de1b1}, - {0x8d590723948a535f, 0x579c487e5a38ad0f}, - {0xb0af48ec79ace837, 0x2d835a9df0c6d852}, - {0xdcdb1b2798182244, 0xf8e431456cf88e66}, - {0x8a08f0f8bf0f156b, 0x1b8e9ecb641b5900}, - {0xac8b2d36eed2dac5, 0xe272467e3d222f40}, - {0xd7adf884aa879177, 0x5b0ed81dcc6abb10}, - {0x86ccbb52ea94baea, 0x98e947129fc2b4ea}, - {0xa87fea27a539e9a5, 0x3f2398d747b36225}, - {0xd29fe4b18e88640e, 0x8eec7f0d19a03aae}, - {0x83a3eeeef9153e89, 0x1953cf68300424ad}, - {0xa48ceaaab75a8e2b, 0x5fa8c3423c052dd8}, - {0xcdb02555653131b6, 0x3792f412cb06794e}, - {0x808e17555f3ebf11, 0xe2bbd88bbee40bd1}, - {0xa0b19d2ab70e6ed6, 0x5b6aceaeae9d0ec5}, - {0xc8de047564d20a8b, 0xf245825a5a445276}, - {0xfb158592be068d2e, 0xeed6e2f0f0d56713}, - {0x9ced737bb6c4183d, 0x55464dd69685606c}, - {0xc428d05aa4751e4c, 0xaa97e14c3c26b887}, - {0xf53304714d9265df, 0xd53dd99f4b3066a9}, - {0x993fe2c6d07b7fab, 0xe546a8038efe402a}, - {0xbf8fdb78849a5f96, 0xde98520472bdd034}, - {0xef73d256a5c0f77c, 0x963e66858f6d4441}, - {0x95a8637627989aad, 0xdde7001379a44aa9}, - {0xbb127c53b17ec159, 0x5560c018580d5d53}, - {0xe9d71b689dde71af, 0xaab8f01e6e10b4a7}, - {0x9226712162ab070d, 0xcab3961304ca70e9}, - {0xb6b00d69bb55c8d1, 0x3d607b97c5fd0d23}, - {0xe45c10c42a2b3b05, 0x8cb89a7db77c506b}, - {0x8eb98a7a9a5b04e3, 0x77f3608e92adb243}, - {0xb267ed1940f1c61c, 0x55f038b237591ed4}, - {0xdf01e85f912e37a3, 0x6b6c46dec52f6689}, - {0x8b61313bbabce2c6, 0x2323ac4b3b3da016}, - {0xae397d8aa96c1b77, 0xabec975e0a0d081b}, - {0xd9c7dced53c72255, 0x96e7bd358c904a22}, - {0x881cea14545c7575, 0x7e50d64177da2e55}, - {0xaa242499697392d2, 0xdde50bd1d5d0b9ea}, - {0xd4ad2dbfc3d07787, 0x955e4ec64b44e865}, - {0x84ec3c97da624ab4, 0xbd5af13bef0b113f}, - {0xa6274bbdd0fadd61, 0xecb1ad8aeacdd58f}, - {0xcfb11ead453994ba, 0x67de18eda5814af3}, - {0x81ceb32c4b43fcf4, 0x80eacf948770ced8}, - {0xa2425ff75e14fc31, 0xa1258379a94d028e}, - {0xcad2f7f5359a3b3e, 0x096ee45813a04331}, - {0xfd87b5f28300ca0d, 0x8bca9d6e188853fd}, - {0x9e74d1b791e07e48, 0x775ea264cf55347e}, - {0xc612062576589dda, 0x95364afe032a819e}, - {0xf79687aed3eec551, 0x3a83ddbd83f52205}, - {0x9abe14cd44753b52, 0xc4926a9672793543}, - {0xc16d9a0095928a27, 0x75b7053c0f178294}, - {0xf1c90080baf72cb1, 0x5324c68b12dd6339}, - {0x971da05074da7bee, 0xd3f6fc16ebca5e04}, - {0xbce5086492111aea, 0x88f4bb1ca6bcf585}, - {0xec1e4a7db69561a5, 0x2b31e9e3d06c32e6}, - {0x9392ee8e921d5d07, 0x3aff322e62439fd0}, - {0xb877aa3236a4b449, 0x09befeb9fad487c3}, - {0xe69594bec44de15b, 0x4c2ebe687989a9b4}, - {0x901d7cf73ab0acd9, 0x0f9d37014bf60a11}, - {0xb424dc35095cd80f, 0x538484c19ef38c95}, - {0xe12e13424bb40e13, 0x2865a5f206b06fba}, - {0x8cbccc096f5088cb, 0xf93f87b7442e45d4}, - {0xafebff0bcb24aafe, 0xf78f69a51539d749}, - {0xdbe6fecebdedd5be, 0xb573440e5a884d1c}, - {0x89705f4136b4a597, 0x31680a88f8953031}, - {0xabcc77118461cefc, 0xfdc20d2b36ba7c3e}, - {0xd6bf94d5e57a42bc, 0x3d32907604691b4d}, - {0x8637bd05af6c69b5, 0xa63f9a49c2c1b110}, - {0xa7c5ac471b478423, 0x0fcf80dc33721d54}, - {0xd1b71758e219652b, 0xd3c36113404ea4a9}, - {0x83126e978d4fdf3b, 0x645a1cac083126ea}, - {0xa3d70a3d70a3d70a, 0x3d70a3d70a3d70a4}, - {0xcccccccccccccccc, 0xcccccccccccccccd}, - {0x8000000000000000, 0x0000000000000000}, - {0xa000000000000000, 0x0000000000000000}, - {0xc800000000000000, 0x0000000000000000}, - {0xfa00000000000000, 0x0000000000000000}, - {0x9c40000000000000, 0x0000000000000000}, - {0xc350000000000000, 0x0000000000000000}, - {0xf424000000000000, 0x0000000000000000}, - {0x9896800000000000, 0x0000000000000000}, - {0xbebc200000000000, 0x0000000000000000}, - {0xee6b280000000000, 0x0000000000000000}, - {0x9502f90000000000, 0x0000000000000000}, - {0xba43b74000000000, 0x0000000000000000}, - {0xe8d4a51000000000, 0x0000000000000000}, - {0x9184e72a00000000, 0x0000000000000000}, - {0xb5e620f480000000, 0x0000000000000000}, - {0xe35fa931a0000000, 0x0000000000000000}, - {0x8e1bc9bf04000000, 0x0000000000000000}, - {0xb1a2bc2ec5000000, 0x0000000000000000}, - {0xde0b6b3a76400000, 0x0000000000000000}, - {0x8ac7230489e80000, 0x0000000000000000}, - {0xad78ebc5ac620000, 0x0000000000000000}, - {0xd8d726b7177a8000, 0x0000000000000000}, - {0x878678326eac9000, 0x0000000000000000}, - {0xa968163f0a57b400, 0x0000000000000000}, - {0xd3c21bcecceda100, 0x0000000000000000}, - {0x84595161401484a0, 0x0000000000000000}, - {0xa56fa5b99019a5c8, 0x0000000000000000}, - {0xcecb8f27f4200f3a, 0x0000000000000000}, - {0x813f3978f8940984, 0x4000000000000000}, - {0xa18f07d736b90be5, 0x5000000000000000}, - {0xc9f2c9cd04674ede, 0xa400000000000000}, - {0xfc6f7c4045812296, 0x4d00000000000000}, - {0x9dc5ada82b70b59d, 0xf020000000000000}, - {0xc5371912364ce305, 0x6c28000000000000}, - {0xf684df56c3e01bc6, 0xc732000000000000}, - {0x9a130b963a6c115c, 0x3c7f400000000000}, - {0xc097ce7bc90715b3, 0x4b9f100000000000}, - {0xf0bdc21abb48db20, 0x1e86d40000000000}, - {0x96769950b50d88f4, 0x1314448000000000}, - {0xbc143fa4e250eb31, 0x17d955a000000000}, - {0xeb194f8e1ae525fd, 0x5dcfab0800000000}, - {0x92efd1b8d0cf37be, 0x5aa1cae500000000}, - {0xb7abc627050305ad, 0xf14a3d9e40000000}, - {0xe596b7b0c643c719, 0x6d9ccd05d0000000}, - {0x8f7e32ce7bea5c6f, 0xe4820023a2000000}, - {0xb35dbf821ae4f38b, 0xdda2802c8a800000}, - {0xe0352f62a19e306e, 0xd50b2037ad200000}, - {0x8c213d9da502de45, 0x4526f422cc340000}, - {0xaf298d050e4395d6, 0x9670b12b7f410000}, - {0xdaf3f04651d47b4c, 0x3c0cdd765f114000}, - {0x88d8762bf324cd0f, 0xa5880a69fb6ac800}, - {0xab0e93b6efee0053, 0x8eea0d047a457a00}, - {0xd5d238a4abe98068, 0x72a4904598d6d880}, - {0x85a36366eb71f041, 0x47a6da2b7f864750}, - {0xa70c3c40a64e6c51, 0x999090b65f67d924}, - {0xd0cf4b50cfe20765, 0xfff4b4e3f741cf6d}, - {0x82818f1281ed449f, 0xbff8f10e7a8921a5}, - {0xa321f2d7226895c7, 0xaff72d52192b6a0e}, - {0xcbea6f8ceb02bb39, 0x9bf4f8a69f764491}, - {0xfee50b7025c36a08, 0x02f236d04753d5b5}, - {0x9f4f2726179a2245, 0x01d762422c946591}, - {0xc722f0ef9d80aad6, 0x424d3ad2b7b97ef6}, - {0xf8ebad2b84e0d58b, 0xd2e0898765a7deb3}, - {0x9b934c3b330c8577, 0x63cc55f49f88eb30}, - {0xc2781f49ffcfa6d5, 0x3cbf6b71c76b25fc}, - {0xf316271c7fc3908a, 0x8bef464e3945ef7b}, - {0x97edd871cfda3a56, 0x97758bf0e3cbb5ad}, - {0xbde94e8e43d0c8ec, 0x3d52eeed1cbea318}, - {0xed63a231d4c4fb27, 0x4ca7aaa863ee4bde}, - {0x945e455f24fb1cf8, 0x8fe8caa93e74ef6b}, - {0xb975d6b6ee39e436, 0xb3e2fd538e122b45}, - {0xe7d34c64a9c85d44, 0x60dbbca87196b617}, - {0x90e40fbeea1d3a4a, 0xbc8955e946fe31ce}, - {0xb51d13aea4a488dd, 0x6babab6398bdbe42}, - {0xe264589a4dcdab14, 0xc696963c7eed2dd2}, - {0x8d7eb76070a08aec, 0xfc1e1de5cf543ca3}, - {0xb0de65388cc8ada8, 0x3b25a55f43294bcc}, - {0xdd15fe86affad912, 0x49ef0eb713f39ebf}, - {0x8a2dbf142dfcc7ab, 0x6e3569326c784338}, - {0xacb92ed9397bf996, 0x49c2c37f07965405}, - {0xd7e77a8f87daf7fb, 0xdc33745ec97be907}, - {0x86f0ac99b4e8dafd, 0x69a028bb3ded71a4}, - {0xa8acd7c0222311bc, 0xc40832ea0d68ce0d}, - {0xd2d80db02aabd62b, 0xf50a3fa490c30191}, - {0x83c7088e1aab65db, 0x792667c6da79e0fb}, - {0xa4b8cab1a1563f52, 0x577001b891185939}, - {0xcde6fd5e09abcf26, 0xed4c0226b55e6f87}, - {0x80b05e5ac60b6178, 0x544f8158315b05b5}, - {0xa0dc75f1778e39d6, 0x696361ae3db1c722}, - {0xc913936dd571c84c, 0x03bc3a19cd1e38ea}, - {0xfb5878494ace3a5f, 0x04ab48a04065c724}, - {0x9d174b2dcec0e47b, 0x62eb0d64283f9c77}, - {0xc45d1df942711d9a, 0x3ba5d0bd324f8395}, - {0xf5746577930d6500, 0xca8f44ec7ee3647a}, - {0x9968bf6abbe85f20, 0x7e998b13cf4e1ecc}, - {0xbfc2ef456ae276e8, 0x9e3fedd8c321a67f}, - {0xefb3ab16c59b14a2, 0xc5cfe94ef3ea101f}, - {0x95d04aee3b80ece5, 0xbba1f1d158724a13}, - {0xbb445da9ca61281f, 0x2a8a6e45ae8edc98}, - {0xea1575143cf97226, 0xf52d09d71a3293be}, - {0x924d692ca61be758, 0x593c2626705f9c57}, - {0xb6e0c377cfa2e12e, 0x6f8b2fb00c77836d}, - {0xe498f455c38b997a, 0x0b6dfb9c0f956448}, - {0x8edf98b59a373fec, 0x4724bd4189bd5ead}, - {0xb2977ee300c50fe7, 0x58edec91ec2cb658}, - {0xdf3d5e9bc0f653e1, 0x2f2967b66737e3ee}, - {0x8b865b215899f46c, 0xbd79e0d20082ee75}, - {0xae67f1e9aec07187, 0xecd8590680a3aa12}, - {0xda01ee641a708de9, 0xe80e6f4820cc9496}, - {0x884134fe908658b2, 0x3109058d147fdcde}, - {0xaa51823e34a7eede, 0xbd4b46f0599fd416}, - {0xd4e5e2cdc1d1ea96, 0x6c9e18ac7007c91b}, - {0x850fadc09923329e, 0x03e2cf6bc604ddb1}, - {0xa6539930bf6bff45, 0x84db8346b786151d}, - {0xcfe87f7cef46ff16, 0xe612641865679a64}, - {0x81f14fae158c5f6e, 0x4fcb7e8f3f60c07f}, - {0xa26da3999aef7749, 0xe3be5e330f38f09e}, - {0xcb090c8001ab551c, 0x5cadf5bfd3072cc6}, - {0xfdcb4fa002162a63, 0x73d9732fc7c8f7f7}, - {0x9e9f11c4014dda7e, 0x2867e7fddcdd9afb}, - {0xc646d63501a1511d, 0xb281e1fd541501b9}, - {0xf7d88bc24209a565, 0x1f225a7ca91a4227}, - {0x9ae757596946075f, 0x3375788de9b06959}, - {0xc1a12d2fc3978937, 0x0052d6b1641c83af}, - {0xf209787bb47d6b84, 0xc0678c5dbd23a49b}, - {0x9745eb4d50ce6332, 0xf840b7ba963646e1}, - {0xbd176620a501fbff, 0xb650e5a93bc3d899}, - {0xec5d3fa8ce427aff, 0xa3e51f138ab4cebf}, - {0x93ba47c980e98cdf, 0xc66f336c36b10138}, - {0xb8a8d9bbe123f017, 0xb80b0047445d4185}, - {0xe6d3102ad96cec1d, 0xa60dc059157491e6}, - {0x9043ea1ac7e41392, 0x87c89837ad68db30}, - {0xb454e4a179dd1877, 0x29babe4598c311fc}, - {0xe16a1dc9d8545e94, 0xf4296dd6fef3d67b}, - {0x8ce2529e2734bb1d, 0x1899e4a65f58660d}, - {0xb01ae745b101e9e4, 0x5ec05dcff72e7f90}, - {0xdc21a1171d42645d, 0x76707543f4fa1f74}, - {0x899504ae72497eba, 0x6a06494a791c53a9}, - {0xabfa45da0edbde69, 0x0487db9d17636893}, - {0xd6f8d7509292d603, 0x45a9d2845d3c42b7}, - {0x865b86925b9bc5c2, 0x0b8a2392ba45a9b3}, - {0xa7f26836f282b732, 0x8e6cac7768d7141f}, - {0xd1ef0244af2364ff, 0x3207d795430cd927}, - {0x8335616aed761f1f, 0x7f44e6bd49e807b9}, - {0xa402b9c5a8d3a6e7, 0x5f16206c9c6209a7}, - {0xcd036837130890a1, 0x36dba887c37a8c10}, - {0x802221226be55a64, 0xc2494954da2c978a}, - {0xa02aa96b06deb0fd, 0xf2db9baa10b7bd6d}, - {0xc83553c5c8965d3d, 0x6f92829494e5acc8}, - {0xfa42a8b73abbf48c, 0xcb772339ba1f17fa}, - {0x9c69a97284b578d7, 0xff2a760414536efc}, - {0xc38413cf25e2d70d, 0xfef5138519684abb}, - {0xf46518c2ef5b8cd1, 0x7eb258665fc25d6a}, - {0x98bf2f79d5993802, 0xef2f773ffbd97a62}, - {0xbeeefb584aff8603, 0xaafb550ffacfd8fb}, - {0xeeaaba2e5dbf6784, 0x95ba2a53f983cf39}, - {0x952ab45cfa97a0b2, 0xdd945a747bf26184}, - {0xba756174393d88df, 0x94f971119aeef9e5}, - {0xe912b9d1478ceb17, 0x7a37cd5601aab85e}, - {0x91abb422ccb812ee, 0xac62e055c10ab33b}, - {0xb616a12b7fe617aa, 0x577b986b314d600a}, - {0xe39c49765fdf9d94, 0xed5a7e85fda0b80c}, - {0x8e41ade9fbebc27d, 0x14588f13be847308}, - {0xb1d219647ae6b31c, 0x596eb2d8ae258fc9}, - {0xde469fbd99a05fe3, 0x6fca5f8ed9aef3bc}, - {0x8aec23d680043bee, 0x25de7bb9480d5855}, - {0xada72ccc20054ae9, 0xaf561aa79a10ae6b}, - {0xd910f7ff28069da4, 0x1b2ba1518094da05}, - {0x87aa9aff79042286, 0x90fb44d2f05d0843}, - {0xa99541bf57452b28, 0x353a1607ac744a54}, - {0xd3fa922f2d1675f2, 0x42889b8997915ce9}, - {0x847c9b5d7c2e09b7, 0x69956135febada12}, - {0xa59bc234db398c25, 0x43fab9837e699096}, - {0xcf02b2c21207ef2e, 0x94f967e45e03f4bc}, - {0x8161afb94b44f57d, 0x1d1be0eebac278f6}, - {0xa1ba1ba79e1632dc, 0x6462d92a69731733}, - {0xca28a291859bbf93, 0x7d7b8f7503cfdcff}, - {0xfcb2cb35e702af78, 0x5cda735244c3d43f}, - {0x9defbf01b061adab, 0x3a0888136afa64a8}, - {0xc56baec21c7a1916, 0x088aaa1845b8fdd1}, - {0xf6c69a72a3989f5b, 0x8aad549e57273d46}, - {0x9a3c2087a63f6399, 0x36ac54e2f678864c}, - {0xc0cb28a98fcf3c7f, 0x84576a1bb416a7de}, - {0xf0fdf2d3f3c30b9f, 0x656d44a2a11c51d6}, - {0x969eb7c47859e743, 0x9f644ae5a4b1b326}, - {0xbc4665b596706114, 0x873d5d9f0dde1fef}, - {0xeb57ff22fc0c7959, 0xa90cb506d155a7eb}, - {0x9316ff75dd87cbd8, 0x09a7f12442d588f3}, - {0xb7dcbf5354e9bece, 0x0c11ed6d538aeb30}, - {0xe5d3ef282a242e81, 0x8f1668c8a86da5fb}, - {0x8fa475791a569d10, 0xf96e017d694487bd}, - {0xb38d92d760ec4455, 0x37c981dcc395a9ad}, - {0xe070f78d3927556a, 0x85bbe253f47b1418}, - {0x8c469ab843b89562, 0x93956d7478ccec8f}, - {0xaf58416654a6babb, 0x387ac8d1970027b3}, - {0xdb2e51bfe9d0696a, 0x06997b05fcc0319f}, - {0x88fcf317f22241e2, 0x441fece3bdf81f04}, - {0xab3c2fddeeaad25a, 0xd527e81cad7626c4}, - {0xd60b3bd56a5586f1, 0x8a71e223d8d3b075}, - {0x85c7056562757456, 0xf6872d5667844e4a}, - {0xa738c6bebb12d16c, 0xb428f8ac016561dc}, - {0xd106f86e69d785c7, 0xe13336d701beba53}, - {0x82a45b450226b39c, 0xecc0024661173474}, - {0xa34d721642b06084, 0x27f002d7f95d0191}, - {0xcc20ce9bd35c78a5, 0x31ec038df7b441f5}, - {0xff290242c83396ce, 0x7e67047175a15272}, - {0x9f79a169bd203e41, 0x0f0062c6e984d387}, - {0xc75809c42c684dd1, 0x52c07b78a3e60869}, - {0xf92e0c3537826145, 0xa7709a56ccdf8a83}, - {0x9bbcc7a142b17ccb, 0x88a66076400bb692}, - {0xc2abf989935ddbfe, 0x6acff893d00ea436}, - {0xf356f7ebf83552fe, 0x0583f6b8c4124d44}, - {0x98165af37b2153de, 0xc3727a337a8b704b}, - {0xbe1bf1b059e9a8d6, 0x744f18c0592e4c5d}, - {0xeda2ee1c7064130c, 0x1162def06f79df74}, - {0x9485d4d1c63e8be7, 0x8addcb5645ac2ba9}, - {0xb9a74a0637ce2ee1, 0x6d953e2bd7173693}, - {0xe8111c87c5c1ba99, 0xc8fa8db6ccdd0438}, - {0x910ab1d4db9914a0, 0x1d9c9892400a22a3}, - {0xb54d5e4a127f59c8, 0x2503beb6d00cab4c}, - {0xe2a0b5dc971f303a, 0x2e44ae64840fd61e}, - {0x8da471a9de737e24, 0x5ceaecfed289e5d3}, - {0xb10d8e1456105dad, 0x7425a83e872c5f48}, - {0xdd50f1996b947518, 0xd12f124e28f7771a}, - {0x8a5296ffe33cc92f, 0x82bd6b70d99aaa70}, - {0xace73cbfdc0bfb7b, 0x636cc64d1001550c}, - {0xd8210befd30efa5a, 0x3c47f7e05401aa4f}, - {0x8714a775e3e95c78, 0x65acfaec34810a72}, - {0xa8d9d1535ce3b396, 0x7f1839a741a14d0e}, - {0xd31045a8341ca07c, 0x1ede48111209a051}, - {0x83ea2b892091e44d, 0x934aed0aab460433}, - {0xa4e4b66b68b65d60, 0xf81da84d56178540}, - {0xce1de40642e3f4b9, 0x36251260ab9d668f}, - {0x80d2ae83e9ce78f3, 0xc1d72b7c6b42601a}, - {0xa1075a24e4421730, 0xb24cf65b8612f820}, - {0xc94930ae1d529cfc, 0xdee033f26797b628}, - {0xfb9b7cd9a4a7443c, 0x169840ef017da3b2}, - {0x9d412e0806e88aa5, 0x8e1f289560ee864f}, - {0xc491798a08a2ad4e, 0xf1a6f2bab92a27e3}, - {0xf5b5d7ec8acb58a2, 0xae10af696774b1dc}, - {0x9991a6f3d6bf1765, 0xacca6da1e0a8ef2a}, - {0xbff610b0cc6edd3f, 0x17fd090a58d32af4}, - {0xeff394dcff8a948e, 0xddfc4b4cef07f5b1}, - {0x95f83d0a1fb69cd9, 0x4abdaf101564f98f}, - {0xbb764c4ca7a4440f, 0x9d6d1ad41abe37f2}, - {0xea53df5fd18d5513, 0x84c86189216dc5ee}, - {0x92746b9be2f8552c, 0x32fd3cf5b4e49bb5}, - {0xb7118682dbb66a77, 0x3fbc8c33221dc2a2}, - {0xe4d5e82392a40515, 0x0fabaf3feaa5334b}, - {0x8f05b1163ba6832d, 0x29cb4d87f2a7400f}, - {0xb2c71d5bca9023f8, 0x743e20e9ef511013}, - {0xdf78e4b2bd342cf6, 0x914da9246b255417}, - {0x8bab8eefb6409c1a, 0x1ad089b6c2f7548f}, - {0xae9672aba3d0c320, 0xa184ac2473b529b2}, - {0xda3c0f568cc4f3e8, 0xc9e5d72d90a2741f}, - {0x8865899617fb1871, 0x7e2fa67c7a658893}, - {0xaa7eebfb9df9de8d, 0xddbb901b98feeab8}, - {0xd51ea6fa85785631, 0x552a74227f3ea566}, - {0x8533285c936b35de, 0xd53a88958f872760}, - {0xa67ff273b8460356, 0x8a892abaf368f138}, - {0xd01fef10a657842c, 0x2d2b7569b0432d86}, - {0x8213f56a67f6b29b, 0x9c3b29620e29fc74}, - {0xa298f2c501f45f42, 0x8349f3ba91b47b90}, - {0xcb3f2f7642717713, 0x241c70a936219a74}, - {0xfe0efb53d30dd4d7, 0xed238cd383aa0111}, - {0x9ec95d1463e8a506, 0xf4363804324a40ab}, - {0xc67bb4597ce2ce48, 0xb143c6053edcd0d6}, - {0xf81aa16fdc1b81da, 0xdd94b7868e94050b}, - {0x9b10a4e5e9913128, 0xca7cf2b4191c8327}, - {0xc1d4ce1f63f57d72, 0xfd1c2f611f63a3f1}, - {0xf24a01a73cf2dccf, 0xbc633b39673c8ced}, - {0x976e41088617ca01, 0xd5be0503e085d814}, - {0xbd49d14aa79dbc82, 0x4b2d8644d8a74e19}, - {0xec9c459d51852ba2, 0xddf8e7d60ed1219f}, - {0x93e1ab8252f33b45, 0xcabb90e5c942b504}, - {0xb8da1662e7b00a17, 0x3d6a751f3b936244}, - {0xe7109bfba19c0c9d, 0x0cc512670a783ad5}, - {0x906a617d450187e2, 0x27fb2b80668b24c6}, - {0xb484f9dc9641e9da, 0xb1f9f660802dedf7}, - {0xe1a63853bbd26451, 0x5e7873f8a0396974}, - {0x8d07e33455637eb2, 0xdb0b487b6423e1e9}, - {0xb049dc016abc5e5f, 0x91ce1a9a3d2cda63}, - {0xdc5c5301c56b75f7, 0x7641a140cc7810fc}, - {0x89b9b3e11b6329ba, 0xa9e904c87fcb0a9e}, - {0xac2820d9623bf429, 0x546345fa9fbdcd45}, - {0xd732290fbacaf133, 0xa97c177947ad4096}, - {0x867f59a9d4bed6c0, 0x49ed8eabcccc485e}, - {0xa81f301449ee8c70, 0x5c68f256bfff5a75}, - {0xd226fc195c6a2f8c, 0x73832eec6fff3112}, - {0x83585d8fd9c25db7, 0xc831fd53c5ff7eac}, - {0xa42e74f3d032f525, 0xba3e7ca8b77f5e56}, - {0xcd3a1230c43fb26f, 0x28ce1bd2e55f35ec}, - {0x80444b5e7aa7cf85, 0x7980d163cf5b81b4}, - {0xa0555e361951c366, 0xd7e105bcc3326220}, - {0xc86ab5c39fa63440, 0x8dd9472bf3fefaa8}, - {0xfa856334878fc150, 0xb14f98f6f0feb952}, - {0x9c935e00d4b9d8d2, 0x6ed1bf9a569f33d4}, - {0xc3b8358109e84f07, 0x0a862f80ec4700c9}, - {0xf4a642e14c6262c8, 0xcd27bb612758c0fb}, - {0x98e7e9cccfbd7dbd, 0x8038d51cb897789d}, - {0xbf21e44003acdd2c, 0xe0470a63e6bd56c4}, - {0xeeea5d5004981478, 0x1858ccfce06cac75}, - {0x95527a5202df0ccb, 0x0f37801e0c43ebc9}, - {0xbaa718e68396cffd, 0xd30560258f54e6bb}, - {0xe950df20247c83fd, 0x47c6b82ef32a206a}, - {0x91d28b7416cdd27e, 0x4cdc331d57fa5442}, - {0xb6472e511c81471d, 0xe0133fe4adf8e953}, - {0xe3d8f9e563a198e5, 0x58180fddd97723a7}, - {0x8e679c2f5e44ff8f, 0x570f09eaa7ea7649}, - {0xb201833b35d63f73, 0x2cd2cc6551e513db}, - {0xde81e40a034bcf4f, 0xf8077f7ea65e58d2}, - {0x8b112e86420f6191, 0xfb04afaf27faf783}, - {0xadd57a27d29339f6, 0x79c5db9af1f9b564}, - {0xd94ad8b1c7380874, 0x18375281ae7822bd}, - {0x87cec76f1c830548, 0x8f2293910d0b15b6}, - {0xa9c2794ae3a3c69a, 0xb2eb3875504ddb23}, - {0xd433179d9c8cb841, 0x5fa60692a46151ec}, - {0x849feec281d7f328, 0xdbc7c41ba6bcd334}, - {0xa5c7ea73224deff3, 0x12b9b522906c0801}, - {0xcf39e50feae16bef, 0xd768226b34870a01}, - {0x81842f29f2cce375, 0xe6a1158300d46641}, - {0xa1e53af46f801c53, 0x60495ae3c1097fd1}, - {0xca5e89b18b602368, 0x385bb19cb14bdfc5}, - {0xfcf62c1dee382c42, 0x46729e03dd9ed7b6}, - {0x9e19db92b4e31ba9, 0x6c07a2c26a8346d2}, - {0xc5a05277621be293, 0xc7098b7305241886}, - {0xf70867153aa2db38, 0xb8cbee4fc66d1ea8}, - {0x9a65406d44a5c903, 0x737f74f1dc043329}, - {0xc0fe908895cf3b44, 0x505f522e53053ff3}, - {0xf13e34aabb430a15, 0x647726b9e7c68ff0}, - {0x96c6e0eab509e64d, 0x5eca783430dc19f6}, - {0xbc789925624c5fe0, 0xb67d16413d132073}, - {0xeb96bf6ebadf77d8, 0xe41c5bd18c57e890}, - {0x933e37a534cbaae7, 0x8e91b962f7b6f15a}, - {0xb80dc58e81fe95a1, 0x723627bbb5a4adb1}, - {0xe61136f2227e3b09, 0xcec3b1aaa30dd91d}, - {0x8fcac257558ee4e6, 0x213a4f0aa5e8a7b2}, - {0xb3bd72ed2af29e1f, 0xa988e2cd4f62d19e}, - {0xe0accfa875af45a7, 0x93eb1b80a33b8606}, - {0x8c6c01c9498d8b88, 0xbc72f130660533c4}, - {0xaf87023b9bf0ee6a, 0xeb8fad7c7f8680b5}, - {0xdb68c2ca82ed2a05, 0xa67398db9f6820e2}, -#else - {0xff77b1fcbebcdc4f, 0x25e8e89c13bb0f7b}, - {0xce5d73ff402d98e3, 0xfb0a3d212dc81290}, - {0xa6b34ad8c9dfc06f, 0xf42faa48c0ea481f}, - {0x86a8d39ef77164bc, 0xae5dff9c02033198}, - {0xd98ddaee19068c76, 0x3badd624dd9b0958}, - {0xafbd2350644eeacf, 0xe5d1929ef90898fb}, - {0x8df5efabc5979c8f, 0xca8d3ffa1ef463c2}, - {0xe55990879ddcaabd, 0xcc420a6a101d0516}, - {0xb94470938fa89bce, 0xf808e40e8d5b3e6a}, - {0x95a8637627989aad, 0xdde7001379a44aa9}, - {0xf1c90080baf72cb1, 0x5324c68b12dd6339}, - {0xc350000000000000, 0x0000000000000000}, - {0x9dc5ada82b70b59d, 0xf020000000000000}, - {0xfee50b7025c36a08, 0x02f236d04753d5b5}, - {0xcde6fd5e09abcf26, 0xed4c0226b55e6f87}, - {0xa6539930bf6bff45, 0x84db8346b786151d}, - {0x865b86925b9bc5c2, 0x0b8a2392ba45a9b3}, - {0xd910f7ff28069da4, 0x1b2ba1518094da05}, - {0xaf58416654a6babb, 0x387ac8d1970027b3}, - {0x8da471a9de737e24, 0x5ceaecfed289e5d3}, - {0xe4d5e82392a40515, 0x0fabaf3feaa5334b}, - {0xb8da1662e7b00a17, 0x3d6a751f3b936244}, - {0x95527a5202df0ccb, 0x0f37801e0c43ebc9}, - {0xf13e34aabb430a15, 0x647726b9e7c68ff0} -#endif - }; - -#if FMT_USE_FULL_CACHE_DRAGONBOX - return pow10_significands[k - float_info::min_k]; -#else - static constexpr uint64_t powers_of_5_64[] = { - 0x0000000000000001, 0x0000000000000005, 0x0000000000000019, - 0x000000000000007d, 0x0000000000000271, 0x0000000000000c35, - 0x0000000000003d09, 0x000000000001312d, 0x000000000005f5e1, - 0x00000000001dcd65, 0x00000000009502f9, 0x0000000002e90edd, - 0x000000000e8d4a51, 0x0000000048c27395, 0x000000016bcc41e9, - 0x000000071afd498d, 0x0000002386f26fc1, 0x000000b1a2bc2ec5, - 0x000003782dace9d9, 0x00001158e460913d, 0x000056bc75e2d631, - 0x0001b1ae4d6e2ef5, 0x000878678326eac9, 0x002a5a058fc295ed, - 0x00d3c21bcecceda1, 0x0422ca8b0a00a425, 0x14adf4b7320334b9}; - - static const int compression_ratio = 27; - - // Compute base index. - int cache_index = (k - float_info::min_k) / compression_ratio; - int kb = cache_index * compression_ratio + float_info::min_k; - int offset = k - kb; - - // Get base cache. - uint128_fallback base_cache = pow10_significands[cache_index]; - if (offset == 0) return base_cache; - - // Compute the required amount of bit-shift. - int alpha = floor_log2_pow10(kb + offset) - floor_log2_pow10(kb) - offset; - FMT_ASSERT(alpha > 0 && alpha < 64, "shifting error detected"); - - // Try to recover the real cache. - uint64_t pow5 = powers_of_5_64[offset]; - uint128_fallback recovered_cache = umul128(base_cache.high(), pow5); - uint128_fallback middle_low = umul128(base_cache.low(), pow5); - - recovered_cache += middle_low.high(); - - uint64_t high_to_middle = recovered_cache.high() << (64 - alpha); - uint64_t middle_to_low = recovered_cache.low() << (64 - alpha); - - recovered_cache = - uint128_fallback{(recovered_cache.low() >> alpha) | high_to_middle, - ((middle_low.low() >> alpha) | middle_to_low)}; - FMT_ASSERT(recovered_cache.low() + 1 != 0, ""); - return {recovered_cache.high(), recovered_cache.low() + 1}; -#endif - } - - struct compute_mul_result { - carrier_uint result; - bool is_integer; - }; - struct compute_mul_parity_result { - bool parity; - bool is_integer; - }; - - static auto compute_mul(carrier_uint u, - const cache_entry_type& cache) noexcept - -> compute_mul_result { - auto r = umul192_upper128(u, cache); - return {r.high(), r.low() == 0}; - } - - static auto compute_delta(const cache_entry_type& cache, int beta) noexcept - -> uint32_t { - return static_cast(cache.high() >> (64 - 1 - beta)); - } - - static auto compute_mul_parity(carrier_uint two_f, - const cache_entry_type& cache, - int beta) noexcept - -> compute_mul_parity_result { - FMT_ASSERT(beta >= 1, ""); - FMT_ASSERT(beta < 64, ""); - - auto r = umul192_lower128(two_f, cache); - return {((r.high() >> (64 - beta)) & 1) != 0, - ((r.high() << beta) | (r.low() >> (64 - beta))) == 0}; - } - - static auto compute_left_endpoint_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return (cache.high() - - (cache.high() >> (num_significand_bits() + 2))) >> - (64 - num_significand_bits() - 1 - beta); - } - - static auto compute_right_endpoint_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return (cache.high() + - (cache.high() >> (num_significand_bits() + 1))) >> - (64 - num_significand_bits() - 1 - beta); - } - - static auto compute_round_up_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return ((cache.high() >> (64 - num_significand_bits() - 2 - beta)) + - 1) / - 2; - } -}; - -FMT_FUNC auto get_cached_power(int k) noexcept -> uint128_fallback { - return cache_accessor::get_cached_power(k); -} - -// Various integer checks -template -auto is_left_endpoint_integer_shorter_interval(int exponent) noexcept -> bool { - const int case_shorter_interval_left_endpoint_lower_threshold = 2; - const int case_shorter_interval_left_endpoint_upper_threshold = 3; - return exponent >= case_shorter_interval_left_endpoint_lower_threshold && - exponent <= case_shorter_interval_left_endpoint_upper_threshold; -} - -// Remove trailing zeros from n and return the number of zeros removed (float). -FMT_INLINE auto remove_trailing_zeros(uint32_t& n, int s = 0) noexcept -> int { - FMT_ASSERT(n != 0, ""); - // Modular inverse of 5 (mod 2^32): (mod_inv_5 * 5) mod 2^32 = 1. - constexpr uint32_t mod_inv_5 = 0xcccccccd; - constexpr uint32_t mod_inv_25 = 0xc28f5c29; // = mod_inv_5 * mod_inv_5 - - while (true) { - auto q = rotr(n * mod_inv_25, 2); - if (q > max_value() / 100) break; - n = q; - s += 2; - } - auto q = rotr(n * mod_inv_5, 1); - if (q <= max_value() / 10) { - n = q; - s |= 1; - } - return s; -} - -// Removes trailing zeros and returns the number of zeros removed (double). -FMT_INLINE auto remove_trailing_zeros(uint64_t& n) noexcept -> int { - FMT_ASSERT(n != 0, ""); - - // Is n is divisible by 10^8? - constexpr uint32_t ten_pow_8 = 100000000u; - if ((n % ten_pow_8) == 0) { - // If yes, work with the quotient... - auto n32 = static_cast(n / ten_pow_8); - // ... and use the 32 bit variant of the function - int num_zeros = remove_trailing_zeros(n32, 8); - n = n32; - return num_zeros; - } - - // If n is not divisible by 10^8, work with n itself. - constexpr uint64_t mod_inv_5 = 0xcccccccccccccccd; - constexpr uint64_t mod_inv_25 = 0x8f5c28f5c28f5c29; // mod_inv_5 * mod_inv_5 - - int s = 0; - while (true) { - auto q = rotr(n * mod_inv_25, 2); - if (q > max_value() / 100) break; - n = q; - s += 2; - } - auto q = rotr(n * mod_inv_5, 1); - if (q <= max_value() / 10) { - n = q; - s |= 1; - } - - return s; -} - -// The main algorithm for shorter interval case -template -FMT_INLINE auto shorter_interval_case(int exponent) noexcept -> decimal_fp { - decimal_fp ret_value; - // Compute k and beta - const int minus_k = floor_log10_pow2_minus_log10_4_over_3(exponent); - const int beta = exponent + floor_log2_pow10(-minus_k); - - // Compute xi and zi - using cache_entry_type = typename cache_accessor::cache_entry_type; - const cache_entry_type cache = cache_accessor::get_cached_power(-minus_k); - - auto xi = cache_accessor::compute_left_endpoint_for_shorter_interval_case( - cache, beta); - auto zi = cache_accessor::compute_right_endpoint_for_shorter_interval_case( - cache, beta); - - // If the left endpoint is not an integer, increase it - if (!is_left_endpoint_integer_shorter_interval(exponent)) ++xi; - - // Try bigger divisor - ret_value.significand = zi / 10; - - // If succeed, remove trailing zeros if necessary and return - if (ret_value.significand * 10 >= xi) { - ret_value.exponent = minus_k + 1; - ret_value.exponent += remove_trailing_zeros(ret_value.significand); - return ret_value; - } - - // Otherwise, compute the round-up of y - ret_value.significand = - cache_accessor::compute_round_up_for_shorter_interval_case(cache, - beta); - ret_value.exponent = minus_k; - - // When tie occurs, choose one of them according to the rule - if (exponent >= float_info::shorter_interval_tie_lower_threshold && - exponent <= float_info::shorter_interval_tie_upper_threshold) { - ret_value.significand = ret_value.significand % 2 == 0 - ? ret_value.significand - : ret_value.significand - 1; - } else if (ret_value.significand < xi) { - ++ret_value.significand; - } - return ret_value; -} - -template auto to_decimal(T x) noexcept -> decimal_fp { - // Step 1: integer promotion & Schubfach multiplier calculation. - - using carrier_uint = typename float_info::carrier_uint; - using cache_entry_type = typename cache_accessor::cache_entry_type; - auto br = bit_cast(x); - - // Extract significand bits and exponent bits. - const carrier_uint significand_mask = - (static_cast(1) << num_significand_bits()) - 1; - carrier_uint significand = (br & significand_mask); - int exponent = - static_cast((br & exponent_mask()) >> num_significand_bits()); - - if (exponent != 0) { // Check if normal. - exponent -= exponent_bias() + num_significand_bits(); - - // Shorter interval case; proceed like Schubfach. - // In fact, when exponent == 1 and significand == 0, the interval is - // regular. However, it can be shown that the end-results are anyway same. - if (significand == 0) return shorter_interval_case(exponent); - - significand |= (static_cast(1) << num_significand_bits()); - } else { - // Subnormal case; the interval is always regular. - if (significand == 0) return {0, 0}; - exponent = - std::numeric_limits::min_exponent - num_significand_bits() - 1; - } - - const bool include_left_endpoint = (significand % 2 == 0); - const bool include_right_endpoint = include_left_endpoint; - - // Compute k and beta. - const int minus_k = floor_log10_pow2(exponent) - float_info::kappa; - const cache_entry_type cache = cache_accessor::get_cached_power(-minus_k); - const int beta = exponent + floor_log2_pow10(-minus_k); - - // Compute zi and deltai. - // 10^kappa <= deltai < 10^(kappa + 1) - const uint32_t deltai = cache_accessor::compute_delta(cache, beta); - const carrier_uint two_fc = significand << 1; - - // For the case of binary32, the result of integer check is not correct for - // 29711844 * 2^-82 - // = 6.1442653300000000008655037797566933477355632930994033813476... * 10^-18 - // and 29711844 * 2^-81 - // = 1.2288530660000000001731007559513386695471126586198806762695... * 10^-17, - // and they are the unique counterexamples. However, since 29711844 is even, - // this does not cause any problem for the endpoints calculations; it can only - // cause a problem when we need to perform integer check for the center. - // Fortunately, with these inputs, that branch is never executed, so we are - // fine. - const typename cache_accessor::compute_mul_result z_mul = - cache_accessor::compute_mul((two_fc | 1) << beta, cache); - - // Step 2: Try larger divisor; remove trailing zeros if necessary. - - // Using an upper bound on zi, we might be able to optimize the division - // better than the compiler; we are computing zi / big_divisor here. - decimal_fp ret_value; - ret_value.significand = divide_by_10_to_kappa_plus_1(z_mul.result); - uint32_t r = static_cast(z_mul.result - float_info::big_divisor * - ret_value.significand); - - if (r < deltai) { - // Exclude the right endpoint if necessary. - if (r == 0 && (z_mul.is_integer & !include_right_endpoint)) { - --ret_value.significand; - r = float_info::big_divisor; - goto small_divisor_case_label; - } - } else if (r > deltai) { - goto small_divisor_case_label; - } else { - // r == deltai; compare fractional parts. - const typename cache_accessor::compute_mul_parity_result x_mul = - cache_accessor::compute_mul_parity(two_fc - 1, cache, beta); - - if (!(x_mul.parity | (x_mul.is_integer & include_left_endpoint))) - goto small_divisor_case_label; - } - ret_value.exponent = minus_k + float_info::kappa + 1; - - // We may need to remove trailing zeros. - ret_value.exponent += remove_trailing_zeros(ret_value.significand); - return ret_value; - - // Step 3: Find the significand with the smaller divisor. - -small_divisor_case_label: - ret_value.significand *= 10; - ret_value.exponent = minus_k + float_info::kappa; - - uint32_t dist = r - (deltai / 2) + (float_info::small_divisor / 2); - const bool approx_y_parity = - ((dist ^ (float_info::small_divisor / 2)) & 1) != 0; - - // Is dist divisible by 10^kappa? - const bool divisible_by_small_divisor = - check_divisibility_and_divide_by_pow10::kappa>(dist); - - // Add dist / 10^kappa to the significand. - ret_value.significand += dist; - - if (!divisible_by_small_divisor) return ret_value; - - // Check z^(f) >= epsilon^(f). - // We have either yi == zi - epsiloni or yi == (zi - epsiloni) - 1, - // where yi == zi - epsiloni if and only if z^(f) >= epsilon^(f). - // Since there are only 2 possibilities, we only need to care about the - // parity. Also, zi and r should have the same parity since the divisor - // is an even number. - const auto y_mul = cache_accessor::compute_mul_parity(two_fc, cache, beta); - - // If z^(f) >= epsilon^(f), we might have a tie when z^(f) == epsilon^(f), - // or equivalently, when y is an integer. - if (y_mul.parity != approx_y_parity) - --ret_value.significand; - else if (y_mul.is_integer & (ret_value.significand % 2 != 0)) - --ret_value.significand; - return ret_value; -} -} // namespace dragonbox -} // namespace detail - -template <> struct formatter { - FMT_CONSTEXPR auto parse(format_parse_context& ctx) - -> format_parse_context::iterator { - return ctx.begin(); - } - - auto format(const detail::bigint& n, format_context& ctx) const - -> format_context::iterator { - auto out = ctx.out(); - bool first = true; - for (auto i = n.bigits_.size(); i > 0; --i) { - auto value = n.bigits_[i - 1u]; - if (first) { - out = fmt::format_to(out, FMT_STRING("{:x}"), value); - first = false; - continue; - } - out = fmt::format_to(out, FMT_STRING("{:08x}"), value); - } - if (n.exp_ > 0) - out = fmt::format_to(out, FMT_STRING("p{}"), - n.exp_ * detail::bigint::bigit_bits); - return out; - } -}; - -FMT_FUNC detail::utf8_to_utf16::utf8_to_utf16(string_view s) { - for_each_codepoint(s, [this](uint32_t cp, string_view) { - if (cp == invalid_code_point) FMT_THROW(std::runtime_error("invalid utf8")); - if (cp <= 0xFFFF) { - buffer_.push_back(static_cast(cp)); - } else { - cp -= 0x10000; - buffer_.push_back(static_cast(0xD800 + (cp >> 10))); - buffer_.push_back(static_cast(0xDC00 + (cp & 0x3FF))); - } - return true; - }); - buffer_.push_back(0); -} - -FMT_FUNC void format_system_error(detail::buffer& out, int error_code, - const char* message) noexcept { - FMT_TRY { - auto ec = std::error_code(error_code, std::generic_category()); - detail::write(appender(out), std::system_error(ec, message).what()); - return; - } - FMT_CATCH(...) {} - format_error_code(out, error_code, message); -} - -FMT_FUNC void report_system_error(int error_code, - const char* message) noexcept { - do_report_error(format_system_error, error_code, message); -} - -FMT_FUNC auto vformat(string_view fmt, format_args args) -> std::string { - // Don't optimize the "{}" case to keep the binary size small and because it - // can be better optimized in fmt::format anyway. - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - return to_string(buffer); -} - -namespace detail { - -FMT_FUNC void vformat_to(buffer& buf, string_view fmt, format_args args, - locale_ref loc) { - auto out = appender(buf); - if (fmt.size() == 2 && equal2(fmt.data(), "{}")) - return args.get(0).visit(default_arg_formatter{out}); - parse_format_string(fmt, - format_handler<>{parse_context<>(fmt), {out, args, loc}}); -} - -template struct span { - T* data; - size_t size; -}; - -template auto flockfile(F* f) -> decltype(_lock_file(f)) { - _lock_file(f); -} -template auto funlockfile(F* f) -> decltype(_unlock_file(f)) { - _unlock_file(f); -} - -#ifndef getc_unlocked -template auto getc_unlocked(F* f) -> decltype(_fgetc_nolock(f)) { - return _fgetc_nolock(f); -} -#endif - -template -struct has_flockfile : std::false_type {}; - -template -struct has_flockfile()))>> - : std::true_type {}; - -// A FILE wrapper. F is FILE defined as a template parameter to make system API -// detection work. -template class file_base { - public: - F* file_; - - public: - file_base(F* file) : file_(file) {} - operator F*() const { return file_; } - - // Reads a code unit from the stream. - auto get() -> int { - int result = getc_unlocked(file_); - if (result == EOF && ferror(file_) != 0) - FMT_THROW(system_error(errno, FMT_STRING("getc failed"))); - return result; - } - - // Puts the code unit back into the stream buffer. - void unget(char c) { - if (ungetc(c, file_) == EOF) - FMT_THROW(system_error(errno, FMT_STRING("ungetc failed"))); - } - - void flush() { fflush(this->file_); } -}; - -// A FILE wrapper for glibc. -template class glibc_file : public file_base { - private: - enum { - line_buffered = 0x200, // _IO_LINE_BUF - unbuffered = 2 // _IO_UNBUFFERED - }; - - public: - using file_base::file_base; - - auto is_buffered() const -> bool { - return (this->file_->_flags & unbuffered) == 0; - } - - void init_buffer() { - if (this->file_->_IO_write_ptr < this->file_->_IO_write_end) return; - // Force buffer initialization by placing and removing a char in a buffer. - putc_unlocked(0, this->file_); - --this->file_->_IO_write_ptr; - } - - // Returns the file's read buffer. - auto get_read_buffer() const -> span { - auto ptr = this->file_->_IO_read_ptr; - return {ptr, to_unsigned(this->file_->_IO_read_end - ptr)}; - } - - // Returns the file's write buffer. - auto get_write_buffer() const -> span { - auto ptr = this->file_->_IO_write_ptr; - return {ptr, to_unsigned(this->file_->_IO_buf_end - ptr)}; - } - - void advance_write_buffer(size_t size) { this->file_->_IO_write_ptr += size; } - - auto needs_flush() const -> bool { - if ((this->file_->_flags & line_buffered) == 0) return false; - char* end = this->file_->_IO_write_end; - auto size = max_of(this->file_->_IO_write_ptr - end, 0); - return memchr(end, '\n', static_cast(size)); - } - - void flush() { fflush_unlocked(this->file_); } -}; - -// A FILE wrapper for Apple's libc. -template class apple_file : public file_base { - private: - enum { - line_buffered = 1, // __SNBF - unbuffered = 2 // __SLBF - }; - - public: - using file_base::file_base; - - auto is_buffered() const -> bool { - return (this->file_->_flags & unbuffered) == 0; - } - - void init_buffer() { - if (this->file_->_p) return; - // Force buffer initialization by placing and removing a char in a buffer. - if (!FMT_CLANG_ANALYZER) putc_unlocked(0, this->file_); - --this->file_->_p; - ++this->file_->_w; - } - - auto get_read_buffer() const -> span { - return {reinterpret_cast(this->file_->_p), - to_unsigned(this->file_->_r)}; - } - - auto get_write_buffer() const -> span { - return {reinterpret_cast(this->file_->_p), - to_unsigned(this->file_->_bf._base + this->file_->_bf._size - - this->file_->_p)}; - } - - void advance_write_buffer(size_t size) { - this->file_->_p += size; - this->file_->_w -= size; - } - - auto needs_flush() const -> bool { - if ((this->file_->_flags & line_buffered) == 0) return false; - return memchr(this->file_->_p + this->file_->_w, '\n', - to_unsigned(-this->file_->_w)); - } -}; - -// A fallback FILE wrapper. -template class fallback_file : public file_base { - private: - char next_; // The next unconsumed character in the buffer. - bool has_next_ = false; - - public: - using file_base::file_base; - - auto is_buffered() const -> bool { return false; } - auto needs_flush() const -> bool { return false; } - void init_buffer() {} - - auto get_read_buffer() const -> span { - return {&next_, has_next_ ? 1u : 0u}; - } - - auto get_write_buffer() const -> span { return {nullptr, 0}; } - - void advance_write_buffer(size_t) {} - - auto get() -> int { - has_next_ = false; - return file_base::get(); - } - - void unget(char c) { - file_base::unget(c); - next_ = c; - has_next_ = true; - } -}; - -#ifndef FMT_USE_FALLBACK_FILE -# define FMT_USE_FALLBACK_FILE 0 -#endif - -template -auto get_file(F* f, int) -> apple_file { - return f; -} -template -inline auto get_file(F* f, int) -> glibc_file { - return f; -} - -inline auto get_file(FILE* f, ...) -> fallback_file { return f; } - -using file_ref = decltype(get_file(static_cast(nullptr), 0)); - -template -class file_print_buffer : public buffer { - public: - explicit file_print_buffer(F*) : buffer(nullptr, size_t()) {} -}; - -template -class file_print_buffer::value>> - : public buffer { - private: - file_ref file_; - - static void grow(buffer& base, size_t) { - auto& self = static_cast(base); - self.file_.advance_write_buffer(self.size()); - if (self.file_.get_write_buffer().size == 0) self.file_.flush(); - auto buf = self.file_.get_write_buffer(); - FMT_ASSERT(buf.size > 0, ""); - self.set(buf.data, buf.size); - self.clear(); - } - - public: - explicit file_print_buffer(F* f) : buffer(grow, size_t()), file_(f) { - flockfile(f); - file_.init_buffer(); - auto buf = file_.get_write_buffer(); - set(buf.data, buf.size); - } - ~file_print_buffer() { - file_.advance_write_buffer(size()); - bool flush = file_.needs_flush(); - F* f = file_; // Make funlockfile depend on the template parameter F - funlockfile(f); // for the system API detection to work. - if (flush) fflush(file_); - } -}; - -#if !defined(_WIN32) || defined(FMT_USE_WRITE_CONSOLE) -FMT_FUNC auto write_console(int, string_view) -> bool { return false; } -#else -using dword = conditional_t; -extern "C" __declspec(dllimport) int __stdcall WriteConsoleW( // - void*, const void*, dword, dword*, void*); - -FMT_FUNC bool write_console(int fd, string_view text) { - auto u16 = utf8_to_utf16(text); - return WriteConsoleW(reinterpret_cast(_get_osfhandle(fd)), u16.c_str(), - static_cast(u16.size()), nullptr, nullptr) != 0; -} -#endif - -#ifdef _WIN32 -// Print assuming legacy (non-Unicode) encoding. -FMT_FUNC void vprint_mojibake(std::FILE* f, string_view fmt, format_args args, - bool newline) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - if (newline) buffer.push_back('\n'); - fwrite_all(buffer.data(), buffer.size(), f); -} -#endif - -FMT_FUNC void print(std::FILE* f, string_view text) { -#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE) - int fd = _fileno(f); - if (_isatty(fd)) { - std::fflush(f); - if (write_console(fd, text)) return; - } -#endif - fwrite_all(text.data(), text.size(), f); -} -} // namespace detail - -FMT_FUNC void vprint_buffered(std::FILE* f, string_view fmt, format_args args) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - detail::print(f, {buffer.data(), buffer.size()}); -} - -FMT_FUNC void vprint(std::FILE* f, string_view fmt, format_args args) { - if (!detail::file_ref(f).is_buffered() || !detail::has_flockfile<>()) - return vprint_buffered(f, fmt, args); - auto&& buffer = detail::file_print_buffer<>(f); - return detail::vformat_to(buffer, fmt, args); -} - -FMT_FUNC void vprintln(std::FILE* f, string_view fmt, format_args args) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - buffer.push_back('\n'); - detail::print(f, {buffer.data(), buffer.size()}); -} - -FMT_FUNC void vprint(string_view fmt, format_args args) { - vprint(stdout, fmt, args); -} - -namespace detail { - -struct singleton { - unsigned char upper; - unsigned char lower_count; -}; - -inline auto is_printable(uint16_t x, const singleton* singletons, - size_t singletons_size, - const unsigned char* singleton_lowers, - const unsigned char* normal, size_t normal_size) - -> bool { - auto upper = x >> 8; - auto lower_start = 0; - for (size_t i = 0; i < singletons_size; ++i) { - auto s = singletons[i]; - auto lower_end = lower_start + s.lower_count; - if (upper < s.upper) break; - if (upper == s.upper) { - for (auto j = lower_start; j < lower_end; ++j) { - if (singleton_lowers[j] == (x & 0xff)) return false; - } - } - lower_start = lower_end; - } - - auto xsigned = static_cast(x); - auto current = true; - for (size_t i = 0; i < normal_size; ++i) { - auto v = static_cast(normal[i]); - auto len = (v & 0x80) != 0 ? (v & 0x7f) << 8 | normal[++i] : v; - xsigned -= len; - if (xsigned < 0) break; - current = !current; - } - return current; -} - -// This code is generated by support/printable.py. -FMT_FUNC auto is_printable(uint32_t cp) -> bool { - static constexpr singleton singletons0[] = { - {0x00, 1}, {0x03, 5}, {0x05, 6}, {0x06, 3}, {0x07, 6}, {0x08, 8}, - {0x09, 17}, {0x0a, 28}, {0x0b, 25}, {0x0c, 20}, {0x0d, 16}, {0x0e, 13}, - {0x0f, 4}, {0x10, 3}, {0x12, 18}, {0x13, 9}, {0x16, 1}, {0x17, 5}, - {0x18, 2}, {0x19, 3}, {0x1a, 7}, {0x1c, 2}, {0x1d, 1}, {0x1f, 22}, - {0x20, 3}, {0x2b, 3}, {0x2c, 2}, {0x2d, 11}, {0x2e, 1}, {0x30, 3}, - {0x31, 2}, {0x32, 1}, {0xa7, 2}, {0xa9, 2}, {0xaa, 4}, {0xab, 8}, - {0xfa, 2}, {0xfb, 5}, {0xfd, 4}, {0xfe, 3}, {0xff, 9}, - }; - static constexpr unsigned char singletons0_lower[] = { - 0xad, 0x78, 0x79, 0x8b, 0x8d, 0xa2, 0x30, 0x57, 0x58, 0x8b, 0x8c, 0x90, - 0x1c, 0x1d, 0xdd, 0x0e, 0x0f, 0x4b, 0x4c, 0xfb, 0xfc, 0x2e, 0x2f, 0x3f, - 0x5c, 0x5d, 0x5f, 0xb5, 0xe2, 0x84, 0x8d, 0x8e, 0x91, 0x92, 0xa9, 0xb1, - 0xba, 0xbb, 0xc5, 0xc6, 0xc9, 0xca, 0xde, 0xe4, 0xe5, 0xff, 0x00, 0x04, - 0x11, 0x12, 0x29, 0x31, 0x34, 0x37, 0x3a, 0x3b, 0x3d, 0x49, 0x4a, 0x5d, - 0x84, 0x8e, 0x92, 0xa9, 0xb1, 0xb4, 0xba, 0xbb, 0xc6, 0xca, 0xce, 0xcf, - 0xe4, 0xe5, 0x00, 0x04, 0x0d, 0x0e, 0x11, 0x12, 0x29, 0x31, 0x34, 0x3a, - 0x3b, 0x45, 0x46, 0x49, 0x4a, 0x5e, 0x64, 0x65, 0x84, 0x91, 0x9b, 0x9d, - 0xc9, 0xce, 0xcf, 0x0d, 0x11, 0x29, 0x45, 0x49, 0x57, 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0, 0xd1, 0xd8, 0xd9, 0xe7, - 0xfe, 0xff, - }; - static constexpr singleton singletons1[] = { - {0x00, 6}, {0x01, 1}, {0x03, 1}, {0x04, 2}, {0x08, 8}, {0x09, 2}, - {0x0a, 5}, {0x0b, 2}, {0x0e, 4}, {0x10, 1}, {0x11, 2}, {0x12, 5}, - {0x13, 17}, {0x14, 1}, {0x15, 2}, {0x17, 2}, {0x19, 13}, {0x1c, 5}, - {0x1d, 8}, {0x24, 1}, {0x6a, 3}, {0x6b, 2}, {0xbc, 2}, {0xd1, 2}, - {0xd4, 12}, {0xd5, 9}, {0xd6, 2}, {0xd7, 2}, {0xda, 1}, {0xe0, 5}, - {0xe1, 2}, {0xe8, 2}, {0xee, 32}, {0xf0, 4}, {0xf8, 2}, {0xf9, 2}, - {0xfa, 2}, {0xfb, 1}, - }; - static constexpr unsigned char singletons1_lower[] = { - 0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e, 0x9e, 0x9f, 0x06, 0x07, - 0x09, 0x36, 0x3d, 0x3e, 0x56, 0xf3, 0xd0, 0xd1, 0x04, 0x14, 0x18, 0x36, - 0x37, 0x56, 0x57, 0x7f, 0xaa, 0xae, 0xaf, 0xbd, 0x35, 0xe0, 0x12, 0x87, - 0x89, 0x8e, 0x9e, 0x04, 0x0d, 0x0e, 0x11, 0x12, 0x29, 0x31, 0x34, 0x3a, - 0x45, 0x46, 0x49, 0x4a, 0x4e, 0x4f, 0x64, 0x65, 0x5c, 0xb6, 0xb7, 0x1b, - 0x1c, 0x07, 0x08, 0x0a, 0x0b, 0x14, 0x17, 0x36, 0x39, 0x3a, 0xa8, 0xa9, - 0xd8, 0xd9, 0x09, 0x37, 0x90, 0x91, 0xa8, 0x07, 0x0a, 0x3b, 0x3e, 0x66, - 0x69, 0x8f, 0x92, 0x6f, 0x5f, 0xee, 0xef, 0x5a, 0x62, 0x9a, 0x9b, 0x27, - 0x28, 0x55, 0x9d, 0xa0, 0xa1, 0xa3, 0xa4, 0xa7, 0xa8, 0xad, 0xba, 0xbc, - 0xc4, 0x06, 0x0b, 0x0c, 0x15, 0x1d, 0x3a, 0x3f, 0x45, 0x51, 0xa6, 0xa7, - 0xcc, 0xcd, 0xa0, 0x07, 0x19, 0x1a, 0x22, 0x25, 0x3e, 0x3f, 0xc5, 0xc6, - 0x04, 0x20, 0x23, 0x25, 0x26, 0x28, 0x33, 0x38, 0x3a, 0x48, 0x4a, 0x4c, - 0x50, 0x53, 0x55, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x63, 0x65, 0x66, - 0x6b, 0x73, 0x78, 0x7d, 0x7f, 0x8a, 0xa4, 0xaa, 0xaf, 0xb0, 0xc0, 0xd0, - 0xae, 0xaf, 0x79, 0xcc, 0x6e, 0x6f, 0x93, - }; - static constexpr unsigned char normal0[] = { - 0x00, 0x20, 0x5f, 0x22, 0x82, 0xdf, 0x04, 0x82, 0x44, 0x08, 0x1b, 0x04, - 0x06, 0x11, 0x81, 0xac, 0x0e, 0x80, 0xab, 0x35, 0x28, 0x0b, 0x80, 0xe0, - 0x03, 0x19, 0x08, 0x01, 0x04, 0x2f, 0x04, 0x34, 0x04, 0x07, 0x03, 0x01, - 0x07, 0x06, 0x07, 0x11, 0x0a, 0x50, 0x0f, 0x12, 0x07, 0x55, 0x07, 0x03, - 0x04, 0x1c, 0x0a, 0x09, 0x03, 0x08, 0x03, 0x07, 0x03, 0x02, 0x03, 0x03, - 0x03, 0x0c, 0x04, 0x05, 0x03, 0x0b, 0x06, 0x01, 0x0e, 0x15, 0x05, 0x3a, - 0x03, 0x11, 0x07, 0x06, 0x05, 0x10, 0x07, 0x57, 0x07, 0x02, 0x07, 0x15, - 0x0d, 0x50, 0x04, 0x43, 0x03, 0x2d, 0x03, 0x01, 0x04, 0x11, 0x06, 0x0f, - 0x0c, 0x3a, 0x04, 0x1d, 0x25, 0x5f, 0x20, 0x6d, 0x04, 0x6a, 0x25, 0x80, - 0xc8, 0x05, 0x82, 0xb0, 0x03, 0x1a, 0x06, 0x82, 0xfd, 0x03, 0x59, 0x07, - 0x15, 0x0b, 0x17, 0x09, 0x14, 0x0c, 0x14, 0x0c, 0x6a, 0x06, 0x0a, 0x06, - 0x1a, 0x06, 0x59, 0x07, 0x2b, 0x05, 0x46, 0x0a, 0x2c, 0x04, 0x0c, 0x04, - 0x01, 0x03, 0x31, 0x0b, 0x2c, 0x04, 0x1a, 0x06, 0x0b, 0x03, 0x80, 0xac, - 0x06, 0x0a, 0x06, 0x21, 0x3f, 0x4c, 0x04, 0x2d, 0x03, 0x74, 0x08, 0x3c, - 0x03, 0x0f, 0x03, 0x3c, 0x07, 0x38, 0x08, 0x2b, 0x05, 0x82, 0xff, 0x11, - 0x18, 0x08, 0x2f, 0x11, 0x2d, 0x03, 0x20, 0x10, 0x21, 0x0f, 0x80, 0x8c, - 0x04, 0x82, 0x97, 0x19, 0x0b, 0x15, 0x88, 0x94, 0x05, 0x2f, 0x05, 0x3b, - 0x07, 0x02, 0x0e, 0x18, 0x09, 0x80, 0xb3, 0x2d, 0x74, 0x0c, 0x80, 0xd6, - 0x1a, 0x0c, 0x05, 0x80, 0xff, 0x05, 0x80, 0xdf, 0x0c, 0xee, 0x0d, 0x03, - 0x84, 0x8d, 0x03, 0x37, 0x09, 0x81, 0x5c, 0x14, 0x80, 0xb8, 0x08, 0x80, - 0xcb, 0x2a, 0x38, 0x03, 0x0a, 0x06, 0x38, 0x08, 0x46, 0x08, 0x0c, 0x06, - 0x74, 0x0b, 0x1e, 0x03, 0x5a, 0x04, 0x59, 0x09, 0x80, 0x83, 0x18, 0x1c, - 0x0a, 0x16, 0x09, 0x4c, 0x04, 0x80, 0x8a, 0x06, 0xab, 0xa4, 0x0c, 0x17, - 0x04, 0x31, 0xa1, 0x04, 0x81, 0xda, 0x26, 0x07, 0x0c, 0x05, 0x05, 0x80, - 0xa5, 0x11, 0x81, 0x6d, 0x10, 0x78, 0x28, 0x2a, 0x06, 0x4c, 0x04, 0x80, - 0x8d, 0x04, 0x80, 0xbe, 0x03, 0x1b, 0x03, 0x0f, 0x0d, - }; - static constexpr unsigned char normal1[] = { - 0x5e, 0x22, 0x7b, 0x05, 0x03, 0x04, 0x2d, 0x03, 0x66, 0x03, 0x01, 0x2f, - 0x2e, 0x80, 0x82, 0x1d, 0x03, 0x31, 0x0f, 0x1c, 0x04, 0x24, 0x09, 0x1e, - 0x05, 0x2b, 0x05, 0x44, 0x04, 0x0e, 0x2a, 0x80, 0xaa, 0x06, 0x24, 0x04, - 0x24, 0x04, 0x28, 0x08, 0x34, 0x0b, 0x01, 0x80, 0x90, 0x81, 0x37, 0x09, - 0x16, 0x0a, 0x08, 0x80, 0x98, 0x39, 0x03, 0x63, 0x08, 0x09, 0x30, 0x16, - 0x05, 0x21, 0x03, 0x1b, 0x05, 0x01, 0x40, 0x38, 0x04, 0x4b, 0x05, 0x2f, - 0x04, 0x0a, 0x07, 0x09, 0x07, 0x40, 0x20, 0x27, 0x04, 0x0c, 0x09, 0x36, - 0x03, 0x3a, 0x05, 0x1a, 0x07, 0x04, 0x0c, 0x07, 0x50, 0x49, 0x37, 0x33, - 0x0d, 0x33, 0x07, 0x2e, 0x08, 0x0a, 0x81, 0x26, 0x52, 0x4e, 0x28, 0x08, - 0x2a, 0x56, 0x1c, 0x14, 0x17, 0x09, 0x4e, 0x04, 0x1e, 0x0f, 0x43, 0x0e, - 0x19, 0x07, 0x0a, 0x06, 0x48, 0x08, 0x27, 0x09, 0x75, 0x0b, 0x3f, 0x41, - 0x2a, 0x06, 0x3b, 0x05, 0x0a, 0x06, 0x51, 0x06, 0x01, 0x05, 0x10, 0x03, - 0x05, 0x80, 0x8b, 0x62, 0x1e, 0x48, 0x08, 0x0a, 0x80, 0xa6, 0x5e, 0x22, - 0x45, 0x0b, 0x0a, 0x06, 0x0d, 0x13, 0x39, 0x07, 0x0a, 0x36, 0x2c, 0x04, - 0x10, 0x80, 0xc0, 0x3c, 0x64, 0x53, 0x0c, 0x48, 0x09, 0x0a, 0x46, 0x45, - 0x1b, 0x48, 0x08, 0x53, 0x1d, 0x39, 0x81, 0x07, 0x46, 0x0a, 0x1d, 0x03, - 0x47, 0x49, 0x37, 0x03, 0x0e, 0x08, 0x0a, 0x06, 0x39, 0x07, 0x0a, 0x81, - 0x36, 0x19, 0x80, 0xb7, 0x01, 0x0f, 0x32, 0x0d, 0x83, 0x9b, 0x66, 0x75, - 0x0b, 0x80, 0xc4, 0x8a, 0xbc, 0x84, 0x2f, 0x8f, 0xd1, 0x82, 0x47, 0xa1, - 0xb9, 0x82, 0x39, 0x07, 0x2a, 0x04, 0x02, 0x60, 0x26, 0x0a, 0x46, 0x0a, - 0x28, 0x05, 0x13, 0x82, 0xb0, 0x5b, 0x65, 0x4b, 0x04, 0x39, 0x07, 0x11, - 0x40, 0x05, 0x0b, 0x02, 0x0e, 0x97, 0xf8, 0x08, 0x84, 0xd6, 0x2a, 0x09, - 0xa2, 0xf7, 0x81, 0x1f, 0x31, 0x03, 0x11, 0x04, 0x08, 0x81, 0x8c, 0x89, - 0x04, 0x6b, 0x05, 0x0d, 0x03, 0x09, 0x07, 0x10, 0x93, 0x60, 0x80, 0xf6, - 0x0a, 0x73, 0x08, 0x6e, 0x17, 0x46, 0x80, 0x9a, 0x14, 0x0c, 0x57, 0x09, - 0x19, 0x80, 0x87, 0x81, 0x47, 0x03, 0x85, 0x42, 0x0f, 0x15, 0x85, 0x50, - 0x2b, 0x80, 0xd5, 0x2d, 0x03, 0x1a, 0x04, 0x02, 0x81, 0x70, 0x3a, 0x05, - 0x01, 0x85, 0x00, 0x80, 0xd7, 0x29, 0x4c, 0x04, 0x0a, 0x04, 0x02, 0x83, - 0x11, 0x44, 0x4c, 0x3d, 0x80, 0xc2, 0x3c, 0x06, 0x01, 0x04, 0x55, 0x05, - 0x1b, 0x34, 0x02, 0x81, 0x0e, 0x2c, 0x04, 0x64, 0x0c, 0x56, 0x0a, 0x80, - 0xae, 0x38, 0x1d, 0x0d, 0x2c, 0x04, 0x09, 0x07, 0x02, 0x0e, 0x06, 0x80, - 0x9a, 0x83, 0xd8, 0x08, 0x0d, 0x03, 0x0d, 0x03, 0x74, 0x0c, 0x59, 0x07, - 0x0c, 0x14, 0x0c, 0x04, 0x38, 0x08, 0x0a, 0x06, 0x28, 0x08, 0x22, 0x4e, - 0x81, 0x54, 0x0c, 0x15, 0x03, 0x03, 0x05, 0x07, 0x09, 0x19, 0x07, 0x07, - 0x09, 0x03, 0x0d, 0x07, 0x29, 0x80, 0xcb, 0x25, 0x0a, 0x84, 0x06, - }; - auto lower = static_cast(cp); - if (cp < 0x10000) { - return is_printable(lower, singletons0, - sizeof(singletons0) / sizeof(*singletons0), - singletons0_lower, normal0, sizeof(normal0)); - } - if (cp < 0x20000) { - return is_printable(lower, singletons1, - sizeof(singletons1) / sizeof(*singletons1), - singletons1_lower, normal1, sizeof(normal1)); - } - if (0x2a6de <= cp && cp < 0x2a700) return false; - if (0x2b735 <= cp && cp < 0x2b740) return false; - if (0x2b81e <= cp && cp < 0x2b820) return false; - if (0x2cea2 <= cp && cp < 0x2ceb0) return false; - if (0x2ebe1 <= cp && cp < 0x2f800) return false; - if (0x2fa1e <= cp && cp < 0x30000) return false; - if (0x3134b <= cp && cp < 0xe0100) return false; - if (0xe01f0 <= cp && cp < 0x110000) return false; - return cp < 0x110000; -} - -} // namespace detail - -FMT_END_NAMESPACE - -#endif // FMT_FORMAT_INL_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/format.h b/examples/blueprints-example/external/fmt/bundled/format.h deleted file mode 100644 index c3a1bda..0000000 --- a/examples/blueprints-example/external/fmt/bundled/format.h +++ /dev/null @@ -1,4383 +0,0 @@ -/* - Formatting library for C++ - - Copyright (c) 2012 - present, Victor Zverovich - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - --- Optional exception to the license --- - - As an exception, if, as a result of your compiling your source code, portions - of this Software are embedded into a machine-executable object form of such - source code, you may redistribute such embedded portions in such object form - without including the above copyright and permission notices. - */ - -#ifndef FMT_FORMAT_H_ -#define FMT_FORMAT_H_ - -#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES -# define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES -# define FMT_REMOVE_TRANSITIVE_INCLUDES -#endif - -#include "base.h" - -#ifndef FMT_MODULE -# include // std::signbit -# include // std::byte -# include // uint32_t -# include // std::malloc, std::free -# include // std::memcpy -# include // std::numeric_limits -# include // std::bad_alloc -# if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI) -// Workaround for pre gcc 5 libstdc++. -# include // std::allocator_traits -# endif -# include // std::runtime_error -# include // std::string -# include // std::system_error - -// Check FMT_CPLUSPLUS to avoid a warning in MSVC. -# if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L -# include // std::bit_cast -# endif - -// libc++ supports string_view in pre-c++17. -# if FMT_HAS_INCLUDE() && \ - (FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION)) -# include -# define FMT_USE_STRING_VIEW -# endif - -# if FMT_MSC_VERSION -# include // _BitScanReverse[64], _umul128 -# endif -#endif // FMT_MODULE - -#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS) -// Use the provided definition. -#elif defined(__NVCOMPILER) -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0 -#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 -#elif defined(__cpp_nontype_template_args) && \ - __cpp_nontype_template_args >= 201911L -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 -#elif FMT_CLANG_VERSION >= 1200 && FMT_CPLUSPLUS >= 202002L -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 -#else -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0 -#endif - -#if defined __cpp_inline_variables && __cpp_inline_variables >= 201606L -# define FMT_INLINE_VARIABLE inline -#else -# define FMT_INLINE_VARIABLE -#endif - -// Check if RTTI is disabled. -#ifdef FMT_USE_RTTI -// Use the provided definition. -#elif defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \ - defined(__INTEL_RTTI__) || defined(__RTTI) -// __RTTI is for EDG compilers. _CPPRTTI is for MSVC. -# define FMT_USE_RTTI 1 -#else -# define FMT_USE_RTTI 0 -#endif - -// Visibility when compiled as a shared library/object. -#if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED) -# define FMT_SO_VISIBILITY(value) FMT_VISIBILITY(value) -#else -# define FMT_SO_VISIBILITY(value) -#endif - -#if FMT_GCC_VERSION || FMT_CLANG_VERSION -# define FMT_NOINLINE __attribute__((noinline)) -#else -# define FMT_NOINLINE -#endif - -#ifdef FMT_DEPRECATED -// Use the provided definition. -#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated) -# define FMT_DEPRECATED [[deprecated]] -#else -# define FMT_DEPRECATED /* deprecated */ -#endif - -// Detect constexpr std::string. -#if !FMT_USE_CONSTEVAL -# define FMT_USE_CONSTEXPR_STRING 0 -#elif defined(__cpp_lib_constexpr_string) && \ - __cpp_lib_constexpr_string >= 201907L -# if FMT_CLANG_VERSION && FMT_GLIBCXX_RELEASE -// clang + libstdc++ are able to work only starting with gcc13.3 -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113294 -# if FMT_GLIBCXX_RELEASE < 13 -# define FMT_USE_CONSTEXPR_STRING 0 -# elif FMT_GLIBCXX_RELEASE == 13 && __GLIBCXX__ < 20240521 -# define FMT_USE_CONSTEXPR_STRING 0 -# else -# define FMT_USE_CONSTEXPR_STRING 1 -# endif -# else -# define FMT_USE_CONSTEXPR_STRING 1 -# endif -#else -# define FMT_USE_CONSTEXPR_STRING 0 -#endif -#if FMT_USE_CONSTEXPR_STRING -# define FMT_CONSTEXPR_STRING constexpr -#else -# define FMT_CONSTEXPR_STRING -#endif - -// GCC 4.9 doesn't support qualified names in specializations. -namespace std { -template struct iterator_traits> { - using iterator_category = output_iterator_tag; - using value_type = T; - using difference_type = - decltype(static_cast(nullptr) - static_cast(nullptr)); - using pointer = void; - using reference = void; -}; -} // namespace std - -#ifdef FMT_THROW -// Use the provided definition. -#elif FMT_USE_EXCEPTIONS -# define FMT_THROW(x) throw x -#else -# define FMT_THROW(x) ::fmt::assert_fail(__FILE__, __LINE__, (x).what()) -#endif - -#ifdef __clang_analyzer__ -# define FMT_CLANG_ANALYZER 1 -#else -# define FMT_CLANG_ANALYZER 0 -#endif - -// Defining FMT_REDUCE_INT_INSTANTIATIONS to 1, will reduce the number of -// integer formatter template instantiations to just one by only using the -// largest integer type. This results in a reduction in binary size but will -// cause a decrease in integer formatting performance. -#if !defined(FMT_REDUCE_INT_INSTANTIATIONS) -# define FMT_REDUCE_INT_INSTANTIATIONS 0 -#endif - -FMT_BEGIN_NAMESPACE - -template -struct is_contiguous> - : std::true_type {}; - -namespace detail { - -// __builtin_clz is broken in clang with Microsoft codegen: -// https://github.com/fmtlib/fmt/issues/519. -#if !FMT_MSC_VERSION -# if FMT_HAS_BUILTIN(__builtin_clz) || FMT_GCC_VERSION || FMT_ICC_VERSION -# define FMT_BUILTIN_CLZ(n) __builtin_clz(n) -# endif -# if FMT_HAS_BUILTIN(__builtin_clzll) || FMT_GCC_VERSION || FMT_ICC_VERSION -# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) -# endif -#endif - -// Some compilers masquerade as both MSVC and GCC but otherwise support -// __builtin_clz and __builtin_clzll, so only define FMT_BUILTIN_CLZ using the -// MSVC intrinsics if the clz and clzll builtins are not available. -#if FMT_MSC_VERSION && !defined(FMT_BUILTIN_CLZLL) -// Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning. -# ifndef __clang__ -# pragma intrinsic(_BitScanReverse) -# ifdef _WIN64 -# pragma intrinsic(_BitScanReverse64) -# endif -# endif - -inline auto clz(uint32_t x) -> int { - FMT_ASSERT(x != 0, ""); - FMT_MSC_WARNING(suppress : 6102) // Suppress a bogus static analysis warning. - unsigned long r = 0; - _BitScanReverse(&r, x); - return 31 ^ static_cast(r); -} -# define FMT_BUILTIN_CLZ(n) detail::clz(n) - -inline auto clzll(uint64_t x) -> int { - FMT_ASSERT(x != 0, ""); - FMT_MSC_WARNING(suppress : 6102) // Suppress a bogus static analysis warning. - unsigned long r = 0; -# ifdef _WIN64 - _BitScanReverse64(&r, x); -# else - // Scan the high 32 bits. - if (_BitScanReverse(&r, static_cast(x >> 32))) - return 63 ^ static_cast(r + 32); - // Scan the low 32 bits. - _BitScanReverse(&r, static_cast(x)); -# endif - return 63 ^ static_cast(r); -} -# define FMT_BUILTIN_CLZLL(n) detail::clzll(n) -#endif // FMT_MSC_VERSION && !defined(FMT_BUILTIN_CLZLL) - -FMT_CONSTEXPR inline void abort_fuzzing_if(bool condition) { - ignore_unused(condition); -#ifdef FMT_FUZZ - if (condition) throw std::runtime_error("fuzzing limit reached"); -#endif -} - -#if defined(FMT_USE_STRING_VIEW) -template using std_string_view = std::basic_string_view; -#else -template struct std_string_view { - operator basic_string_view() const; -}; -#endif - -template struct string_literal { - static constexpr Char value[sizeof...(C)] = {C...}; - constexpr operator basic_string_view() const { - return {value, sizeof...(C)}; - } -}; -#if FMT_CPLUSPLUS < 201703L -template -constexpr Char string_literal::value[sizeof...(C)]; -#endif - -// Implementation of std::bit_cast for pre-C++20. -template -FMT_CONSTEXPR20 auto bit_cast(const From& from) -> To { -#ifdef __cpp_lib_bit_cast - if (is_constant_evaluated()) return std::bit_cast(from); -#endif - auto to = To(); - // The cast suppresses a bogus -Wclass-memaccess on GCC. - std::memcpy(static_cast(&to), &from, sizeof(to)); - return to; -} - -inline auto is_big_endian() -> bool { -#ifdef _WIN32 - return false; -#elif defined(__BIG_ENDIAN__) - return true; -#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) - return __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__; -#else - struct bytes { - char data[sizeof(int)]; - }; - return bit_cast(1).data[0] == 0; -#endif -} - -class uint128_fallback { - private: - uint64_t lo_, hi_; - - public: - constexpr uint128_fallback(uint64_t hi, uint64_t lo) : lo_(lo), hi_(hi) {} - constexpr uint128_fallback(uint64_t value = 0) : lo_(value), hi_(0) {} - - constexpr auto high() const noexcept -> uint64_t { return hi_; } - constexpr auto low() const noexcept -> uint64_t { return lo_; } - - template ::value)> - constexpr explicit operator T() const { - return static_cast(lo_); - } - - friend constexpr auto operator==(const uint128_fallback& lhs, - const uint128_fallback& rhs) -> bool { - return lhs.hi_ == rhs.hi_ && lhs.lo_ == rhs.lo_; - } - friend constexpr auto operator!=(const uint128_fallback& lhs, - const uint128_fallback& rhs) -> bool { - return !(lhs == rhs); - } - friend constexpr auto operator>(const uint128_fallback& lhs, - const uint128_fallback& rhs) -> bool { - return lhs.hi_ != rhs.hi_ ? lhs.hi_ > rhs.hi_ : lhs.lo_ > rhs.lo_; - } - friend constexpr auto operator|(const uint128_fallback& lhs, - const uint128_fallback& rhs) - -> uint128_fallback { - return {lhs.hi_ | rhs.hi_, lhs.lo_ | rhs.lo_}; - } - friend constexpr auto operator&(const uint128_fallback& lhs, - const uint128_fallback& rhs) - -> uint128_fallback { - return {lhs.hi_ & rhs.hi_, lhs.lo_ & rhs.lo_}; - } - friend constexpr auto operator~(const uint128_fallback& n) - -> uint128_fallback { - return {~n.hi_, ~n.lo_}; - } - friend FMT_CONSTEXPR auto operator+(const uint128_fallback& lhs, - const uint128_fallback& rhs) - -> uint128_fallback { - auto result = uint128_fallback(lhs); - result += rhs; - return result; - } - friend FMT_CONSTEXPR auto operator*(const uint128_fallback& lhs, uint32_t rhs) - -> uint128_fallback { - FMT_ASSERT(lhs.hi_ == 0, ""); - uint64_t hi = (lhs.lo_ >> 32) * rhs; - uint64_t lo = (lhs.lo_ & ~uint32_t()) * rhs; - uint64_t new_lo = (hi << 32) + lo; - return {(hi >> 32) + (new_lo < lo ? 1 : 0), new_lo}; - } - friend constexpr auto operator-(const uint128_fallback& lhs, uint64_t rhs) - -> uint128_fallback { - return {lhs.hi_ - (lhs.lo_ < rhs ? 1 : 0), lhs.lo_ - rhs}; - } - FMT_CONSTEXPR auto operator>>(int shift) const -> uint128_fallback { - if (shift == 64) return {0, hi_}; - if (shift > 64) return uint128_fallback(0, hi_) >> (shift - 64); - return {hi_ >> shift, (hi_ << (64 - shift)) | (lo_ >> shift)}; - } - FMT_CONSTEXPR auto operator<<(int shift) const -> uint128_fallback { - if (shift == 64) return {lo_, 0}; - if (shift > 64) return uint128_fallback(lo_, 0) << (shift - 64); - return {hi_ << shift | (lo_ >> (64 - shift)), (lo_ << shift)}; - } - FMT_CONSTEXPR auto operator>>=(int shift) -> uint128_fallback& { - return *this = *this >> shift; - } - FMT_CONSTEXPR void operator+=(uint128_fallback n) { - uint64_t new_lo = lo_ + n.lo_; - uint64_t new_hi = hi_ + n.hi_ + (new_lo < lo_ ? 1 : 0); - FMT_ASSERT(new_hi >= hi_, ""); - lo_ = new_lo; - hi_ = new_hi; - } - FMT_CONSTEXPR void operator&=(uint128_fallback n) { - lo_ &= n.lo_; - hi_ &= n.hi_; - } - - FMT_CONSTEXPR20 auto operator+=(uint64_t n) noexcept -> uint128_fallback& { - if (is_constant_evaluated()) { - lo_ += n; - hi_ += (lo_ < n ? 1 : 0); - return *this; - } -#if FMT_HAS_BUILTIN(__builtin_addcll) && !defined(__ibmxl__) - unsigned long long carry; - lo_ = __builtin_addcll(lo_, n, 0, &carry); - hi_ += carry; -#elif FMT_HAS_BUILTIN(__builtin_ia32_addcarryx_u64) && !defined(__ibmxl__) - unsigned long long result; - auto carry = __builtin_ia32_addcarryx_u64(0, lo_, n, &result); - lo_ = result; - hi_ += carry; -#elif defined(_MSC_VER) && defined(_M_X64) - auto carry = _addcarry_u64(0, lo_, n, &lo_); - _addcarry_u64(carry, hi_, 0, &hi_); -#else - lo_ += n; - hi_ += (lo_ < n ? 1 : 0); -#endif - return *this; - } -}; - -using uint128_t = conditional_t; - -#ifdef UINTPTR_MAX -using uintptr_t = ::uintptr_t; -#else -using uintptr_t = uint128_t; -#endif - -// Returns the largest possible value for type T. Same as -// std::numeric_limits::max() but shorter and not affected by the max macro. -template constexpr auto max_value() -> T { - return (std::numeric_limits::max)(); -} -template constexpr auto num_bits() -> int { - return std::numeric_limits::digits; -} -// std::numeric_limits::digits may return 0 for 128-bit ints. -template <> constexpr auto num_bits() -> int { return 128; } -template <> constexpr auto num_bits() -> int { return 128; } -template <> constexpr auto num_bits() -> int { return 128; } - -// A heterogeneous bit_cast used for converting 96-bit long double to uint128_t -// and 128-bit pointers to uint128_fallback. -template sizeof(From))> -inline auto bit_cast(const From& from) -> To { - constexpr auto size = static_cast(sizeof(From) / sizeof(unsigned short)); - struct data_t { - unsigned short value[static_cast(size)]; - } data = bit_cast(from); - auto result = To(); - if (const_check(is_big_endian())) { - for (int i = 0; i < size; ++i) - result = (result << num_bits()) | data.value[i]; - } else { - for (int i = size - 1; i >= 0; --i) - result = (result << num_bits()) | data.value[i]; - } - return result; -} - -template -FMT_CONSTEXPR20 inline auto countl_zero_fallback(UInt n) -> int { - int lz = 0; - constexpr UInt msb_mask = static_cast(1) << (num_bits() - 1); - for (; (n & msb_mask) == 0; n <<= 1) lz++; - return lz; -} - -FMT_CONSTEXPR20 inline auto countl_zero(uint32_t n) -> int { -#ifdef FMT_BUILTIN_CLZ - if (!is_constant_evaluated()) return FMT_BUILTIN_CLZ(n); -#endif - return countl_zero_fallback(n); -} - -FMT_CONSTEXPR20 inline auto countl_zero(uint64_t n) -> int { -#ifdef FMT_BUILTIN_CLZLL - if (!is_constant_evaluated()) return FMT_BUILTIN_CLZLL(n); -#endif - return countl_zero_fallback(n); -} - -FMT_INLINE void assume(bool condition) { - (void)condition; -#if FMT_HAS_BUILTIN(__builtin_assume) && !FMT_ICC_VERSION - __builtin_assume(condition); -#elif FMT_GCC_VERSION - if (!condition) __builtin_unreachable(); -#endif -} - -// Attempts to reserve space for n extra characters in the output range. -// Returns a pointer to the reserved range or a reference to it. -template ::value&& - is_contiguous::value)> -#if FMT_CLANG_VERSION >= 307 && !FMT_ICC_VERSION -__attribute__((no_sanitize("undefined"))) -#endif -FMT_CONSTEXPR20 inline auto -reserve(OutputIt it, size_t n) -> typename OutputIt::value_type* { - auto& c = get_container(it); - size_t size = c.size(); - c.resize(size + n); - return &c[size]; -} - -template -FMT_CONSTEXPR20 inline auto reserve(basic_appender it, size_t n) - -> basic_appender { - buffer& buf = get_container(it); - buf.try_reserve(buf.size() + n); - return it; -} - -template -constexpr auto reserve(Iterator& it, size_t) -> Iterator& { - return it; -} - -template -using reserve_iterator = - remove_reference_t(), 0))>; - -template -constexpr auto to_pointer(OutputIt, size_t) -> T* { - return nullptr; -} -template FMT_CONSTEXPR auto to_pointer(T*& ptr, size_t n) -> T* { - T* begin = ptr; - ptr += n; - return begin; -} -template -FMT_CONSTEXPR20 auto to_pointer(basic_appender it, size_t n) -> T* { - buffer& buf = get_container(it); - buf.try_reserve(buf.size() + n); - auto size = buf.size(); - if (buf.capacity() < size + n) return nullptr; - buf.try_resize(size + n); - return buf.data() + size; -} - -template ::value&& - is_contiguous::value)> -inline auto base_iterator(OutputIt it, - typename OutputIt::container_type::value_type*) - -> OutputIt { - return it; -} - -template -constexpr auto base_iterator(Iterator, Iterator it) -> Iterator { - return it; -} - -// is spectacularly slow to compile in C++20 so use a simple fill_n -// instead (#1998). -template -FMT_CONSTEXPR auto fill_n(OutputIt out, Size count, const T& value) - -> OutputIt { - for (Size i = 0; i < count; ++i) *out++ = value; - return out; -} -template -FMT_CONSTEXPR20 auto fill_n(T* out, Size count, char value) -> T* { - if (is_constant_evaluated()) return fill_n(out, count, value); - static_assert(sizeof(T) == 1, - "sizeof(T) must be 1 to use char for initialization"); - std::memset(out, value, to_unsigned(count)); - return out + count; -} - -template -FMT_CONSTEXPR FMT_NOINLINE auto copy_noinline(InputIt begin, InputIt end, - OutputIt out) -> OutputIt { - return copy(begin, end, out); -} - -// A public domain branchless UTF-8 decoder by Christopher Wellons: -// https://github.com/skeeto/branchless-utf8 -/* Decode the next character, c, from s, reporting errors in e. - * - * Since this is a branchless decoder, four bytes will be read from the - * buffer regardless of the actual length of the next character. This - * means the buffer _must_ have at least three bytes of zero padding - * following the end of the data stream. - * - * Errors are reported in e, which will be non-zero if the parsed - * character was somehow invalid: invalid byte sequence, non-canonical - * encoding, or a surrogate half. - * - * The function returns a pointer to the next character. When an error - * occurs, this pointer will be a guess that depends on the particular - * error, but it will always advance at least one byte. - */ -FMT_CONSTEXPR inline auto utf8_decode(const char* s, uint32_t* c, int* e) - -> const char* { - constexpr int masks[] = {0x00, 0x7f, 0x1f, 0x0f, 0x07}; - constexpr uint32_t mins[] = {4194304, 0, 128, 2048, 65536}; - constexpr int shiftc[] = {0, 18, 12, 6, 0}; - constexpr int shifte[] = {0, 6, 4, 2, 0}; - - int len = "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0\0\0\2\2\2\2\3\3\4" - [static_cast(*s) >> 3]; - // Compute the pointer to the next character early so that the next - // iteration can start working on the next character. Neither Clang - // nor GCC figure out this reordering on their own. - const char* next = s + len + !len; - - using uchar = unsigned char; - - // Assume a four-byte character and load four bytes. Unused bits are - // shifted out. - *c = uint32_t(uchar(s[0]) & masks[len]) << 18; - *c |= uint32_t(uchar(s[1]) & 0x3f) << 12; - *c |= uint32_t(uchar(s[2]) & 0x3f) << 6; - *c |= uint32_t(uchar(s[3]) & 0x3f) << 0; - *c >>= shiftc[len]; - - // Accumulate the various error conditions. - *e = (*c < mins[len]) << 6; // non-canonical encoding - *e |= ((*c >> 11) == 0x1b) << 7; // surrogate half? - *e |= (*c > 0x10FFFF) << 8; // out of range? - *e |= (uchar(s[1]) & 0xc0) >> 2; - *e |= (uchar(s[2]) & 0xc0) >> 4; - *e |= uchar(s[3]) >> 6; - *e ^= 0x2a; // top two bits of each tail byte correct? - *e >>= shifte[len]; - - return next; -} - -constexpr FMT_INLINE_VARIABLE uint32_t invalid_code_point = ~uint32_t(); - -// Invokes f(cp, sv) for every code point cp in s with sv being the string view -// corresponding to the code point. cp is invalid_code_point on error. -template -FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { - auto decode = [f](const char* buf_ptr, const char* ptr) { - auto cp = uint32_t(); - auto error = 0; - auto end = utf8_decode(buf_ptr, &cp, &error); - bool result = f(error ? invalid_code_point : cp, - string_view(ptr, error ? 1 : to_unsigned(end - buf_ptr))); - return result ? (error ? buf_ptr + 1 : end) : nullptr; - }; - - auto p = s.data(); - const size_t block_size = 4; // utf8_decode always reads blocks of 4 chars. - if (s.size() >= block_size) { - for (auto end = p + s.size() - block_size + 1; p < end;) { - p = decode(p, p); - if (!p) return; - } - } - auto num_chars_left = to_unsigned(s.data() + s.size() - p); - if (num_chars_left == 0) return; - - // Suppress bogus -Wstringop-overflow. - if (FMT_GCC_VERSION) num_chars_left &= 3; - char buf[2 * block_size - 1] = {}; - copy(p, p + num_chars_left, buf); - const char* buf_ptr = buf; - do { - auto end = decode(buf_ptr, p); - if (!end) return; - p += end - buf_ptr; - buf_ptr = end; - } while (buf_ptr < buf + num_chars_left); -} - -FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) noexcept -> size_t { - return to_unsigned( - 1 + (cp >= 0x1100 && - (cp <= 0x115f || // Hangul Jamo init. consonants - cp == 0x2329 || // LEFT-POINTING ANGLE BRACKET - cp == 0x232a || // RIGHT-POINTING ANGLE BRACKET - // CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE: - (cp >= 0x2e80 && cp <= 0xa4cf && cp != 0x303f) || - (cp >= 0xac00 && cp <= 0xd7a3) || // Hangul Syllables - (cp >= 0xf900 && cp <= 0xfaff) || // CJK Compatibility Ideographs - (cp >= 0xfe10 && cp <= 0xfe19) || // Vertical Forms - (cp >= 0xfe30 && cp <= 0xfe6f) || // CJK Compatibility Forms - (cp >= 0xff00 && cp <= 0xff60) || // Fullwidth Forms - (cp >= 0xffe0 && cp <= 0xffe6) || // Fullwidth Forms - (cp >= 0x20000 && cp <= 0x2fffd) || // CJK - (cp >= 0x30000 && cp <= 0x3fffd) || - // Miscellaneous Symbols and Pictographs + Emoticons: - (cp >= 0x1f300 && cp <= 0x1f64f) || - // Supplemental Symbols and Pictographs: - (cp >= 0x1f900 && cp <= 0x1f9ff)))); -} - -template struct is_integral : std::is_integral {}; -template <> struct is_integral : std::true_type {}; -template <> struct is_integral : std::true_type {}; - -template -using is_signed = - std::integral_constant::is_signed || - std::is_same::value>; - -template -using is_integer = - bool_constant::value && !std::is_same::value && - !std::is_same::value && - !std::is_same::value>; - -#if defined(FMT_USE_FLOAT128) -// Use the provided definition. -#elif FMT_CLANG_VERSION >= 309 && FMT_HAS_INCLUDE() -# define FMT_USE_FLOAT128 1 -#elif FMT_GCC_VERSION && defined(_GLIBCXX_USE_FLOAT128) && \ - !defined(__STRICT_ANSI__) -# define FMT_USE_FLOAT128 1 -#else -# define FMT_USE_FLOAT128 0 -#endif -#if FMT_USE_FLOAT128 -using float128 = __float128; -#else -struct float128 {}; -#endif - -template using is_float128 = std::is_same; - -template struct is_floating_point : std::is_floating_point {}; -template <> struct is_floating_point : std::true_type {}; - -template ::value> -struct is_fast_float : bool_constant::is_iec559 && - sizeof(T) <= sizeof(double)> {}; -template struct is_fast_float : std::false_type {}; - -template -using fast_float_t = conditional_t; - -template -using is_double_double = bool_constant::digits == 106>; - -#ifndef FMT_USE_FULL_CACHE_DRAGONBOX -# define FMT_USE_FULL_CACHE_DRAGONBOX 0 -#endif - -// An allocator that uses malloc/free to allow removing dependency on the C++ -// standard libary runtime. std::decay is used for back_inserter to be found by -// ADL when applied to memory_buffer. -template struct allocator : private std::decay { - using value_type = T; - - auto allocate(size_t n) -> T* { - FMT_ASSERT(n <= max_value() / sizeof(T), ""); - T* p = static_cast(std::malloc(n * sizeof(T))); - if (!p) FMT_THROW(std::bad_alloc()); - return p; - } - - void deallocate(T* p, size_t) { std::free(p); } - - constexpr friend auto operator==(allocator, allocator) noexcept -> bool { - return true; // All instances of this allocator are equivalent. - } - constexpr friend auto operator!=(allocator, allocator) noexcept -> bool { - return false; - } -}; - -} // namespace detail - -FMT_BEGIN_EXPORT - -// The number of characters to store in the basic_memory_buffer object itself -// to avoid dynamic memory allocation. -enum { inline_buffer_size = 500 }; - -/** - * A dynamically growing memory buffer for trivially copyable/constructible - * types with the first `SIZE` elements stored in the object itself. Most - * commonly used via the `memory_buffer` alias for `char`. - * - * **Example**: - * - * auto out = fmt::memory_buffer(); - * fmt::format_to(std::back_inserter(out), "The answer is {}.", 42); - * - * This will append "The answer is 42." to `out`. The buffer content can be - * converted to `std::string` with `to_string(out)`. - */ -template > -class basic_memory_buffer : public detail::buffer { - private: - T store_[SIZE]; - - // Don't inherit from Allocator to avoid generating type_info for it. - FMT_NO_UNIQUE_ADDRESS Allocator alloc_; - - // Deallocate memory allocated by the buffer. - FMT_CONSTEXPR20 void deallocate() { - T* data = this->data(); - if (data != store_) alloc_.deallocate(data, this->capacity()); - } - - static FMT_CONSTEXPR20 void grow(detail::buffer& buf, size_t size) { - detail::abort_fuzzing_if(size > 5000); - auto& self = static_cast(buf); - const size_t max_size = - std::allocator_traits::max_size(self.alloc_); - size_t old_capacity = buf.capacity(); - size_t new_capacity = old_capacity + old_capacity / 2; - if (size > new_capacity) - new_capacity = size; - else if (new_capacity > max_size) - new_capacity = max_of(size, max_size); - T* old_data = buf.data(); - T* new_data = self.alloc_.allocate(new_capacity); - // Suppress a bogus -Wstringop-overflow in gcc 13.1 (#3481). - detail::assume(buf.size() <= new_capacity); - // The following code doesn't throw, so the raw pointer above doesn't leak. - memcpy(new_data, old_data, buf.size() * sizeof(T)); - self.set(new_data, new_capacity); - // deallocate must not throw according to the standard, but even if it does, - // the buffer already uses the new storage and will deallocate it in - // destructor. - if (old_data != self.store_) self.alloc_.deallocate(old_data, old_capacity); - } - - public: - using value_type = T; - using const_reference = const T&; - - FMT_CONSTEXPR explicit basic_memory_buffer( - const Allocator& alloc = Allocator()) - : detail::buffer(grow), alloc_(alloc) { - this->set(store_, SIZE); - if (detail::is_constant_evaluated()) detail::fill_n(store_, SIZE, T()); - } - FMT_CONSTEXPR20 ~basic_memory_buffer() { deallocate(); } - - private: - template :: - propagate_on_container_move_assignment::value)> - FMT_CONSTEXPR20 auto move_alloc(basic_memory_buffer& other) -> bool { - alloc_ = std::move(other.alloc_); - return true; - } - // If the allocator does not propagate then copy the data from other. - template :: - propagate_on_container_move_assignment::value)> - FMT_CONSTEXPR20 auto move_alloc(basic_memory_buffer& other) -> bool { - T* data = other.data(); - if (alloc_ == other.alloc_ || data == other.store_) return true; - size_t size = other.size(); - // Perform copy operation, allocators are different. - this->resize(size); - detail::copy(data, data + size, this->data()); - return false; - } - - // Move data from other to this buffer. - FMT_CONSTEXPR20 void move(basic_memory_buffer& other) { - T* data = other.data(); - size_t size = other.size(), capacity = other.capacity(); - if (!move_alloc(other)) return; - if (data == other.store_) { - this->set(store_, capacity); - detail::copy(other.store_, other.store_ + size, store_); - } else { - this->set(data, capacity); - // Set pointer to the inline array so that delete is not called - // when deallocating. - other.set(other.store_, 0); - other.clear(); - } - this->resize(size); - } - - public: - /// Constructs a `basic_memory_buffer` object moving the content of the other - /// object to it. - FMT_CONSTEXPR20 basic_memory_buffer(basic_memory_buffer&& other) noexcept - : detail::buffer(grow) { - move(other); - } - - /// Moves the content of the other `basic_memory_buffer` object to this one. - auto operator=(basic_memory_buffer&& other) noexcept -> basic_memory_buffer& { - FMT_ASSERT(this != &other, ""); - deallocate(); - move(other); - return *this; - } - - // Returns a copy of the allocator associated with this buffer. - auto get_allocator() const -> Allocator { return alloc_; } - - /// Resizes the buffer to contain `count` elements. If T is a POD type new - /// elements may not be initialized. - FMT_CONSTEXPR void resize(size_t count) { this->try_resize(count); } - - /// Increases the buffer capacity to `new_capacity`. - void reserve(size_t new_capacity) { this->try_reserve(new_capacity); } - - using detail::buffer::append; - template - FMT_CONSTEXPR20 void append(const ContiguousRange& range) { - append(range.data(), range.data() + range.size()); - } -}; - -using memory_buffer = basic_memory_buffer; - -template -FMT_NODISCARD auto to_string(const basic_memory_buffer& buf) - -> std::string { - auto size = buf.size(); - detail::assume(size < std::string().max_size()); - return {buf.data(), size}; -} - -// A writer to a buffered stream. It doesn't own the underlying stream. -class writer { - private: - detail::buffer* buf_; - - // We cannot create a file buffer in advance because any write to a FILE may - // invalidate it. - FILE* file_; - - public: - inline writer(FILE* f) : buf_(nullptr), file_(f) {} - inline writer(detail::buffer& buf) : buf_(&buf) {} - - /// Formats `args` according to specifications in `fmt` and writes the - /// output to the file. - template void print(format_string fmt, T&&... args) { - if (buf_) - fmt::format_to(appender(*buf_), fmt, std::forward(args)...); - else - fmt::print(file_, fmt, std::forward(args)...); - } -}; - -class string_buffer { - private: - std::string str_; - detail::container_buffer buf_; - - public: - inline string_buffer() : buf_(str_) {} - - inline operator writer() { return buf_; } - inline auto str() -> std::string& { return str_; } -}; - -template -struct is_contiguous> : std::true_type { -}; - -// Suppress a misleading warning in older versions of clang. -FMT_PRAGMA_CLANG(diagnostic ignored "-Wweak-vtables") - -/// An error reported from a formatting function. -class FMT_SO_VISIBILITY("default") format_error : public std::runtime_error { - public: - using std::runtime_error::runtime_error; -}; - -class loc_value; - -FMT_END_EXPORT -namespace detail { -FMT_API auto write_console(int fd, string_view text) -> bool; -FMT_API void print(FILE*, string_view); -} // namespace detail - -namespace detail { -template struct fixed_string { - FMT_CONSTEXPR20 fixed_string(const Char (&s)[N]) { - detail::copy(static_cast(s), s + N, - data); - } - Char data[N] = {}; -}; - -// Converts a compile-time string to basic_string_view. -FMT_EXPORT template -constexpr auto compile_string_to_view(const Char (&s)[N]) - -> basic_string_view { - // Remove trailing NUL character if needed. Won't be present if this is used - // with a raw character array (i.e. not defined as a string). - return {s, N - (std::char_traits::to_int_type(s[N - 1]) == 0 ? 1 : 0)}; -} -FMT_EXPORT template -constexpr auto compile_string_to_view(basic_string_view s) - -> basic_string_view { - return s; -} - -// Returns true if value is negative, false otherwise. -// Same as `value < 0` but doesn't produce warnings if T is an unsigned type. -template ::value)> -constexpr auto is_negative(T value) -> bool { - return value < 0; -} -template ::value)> -constexpr auto is_negative(T) -> bool { - return false; -} - -// Smallest of uint32_t, uint64_t, uint128_t that is large enough to -// represent all values of an integral type T. -template -using uint32_or_64_or_128_t = - conditional_t() <= 32 && !FMT_REDUCE_INT_INSTANTIATIONS, - uint32_t, - conditional_t() <= 64, uint64_t, uint128_t>>; -template -using uint64_or_128_t = conditional_t() <= 64, uint64_t, uint128_t>; - -#define FMT_POWERS_OF_10(factor) \ - factor * 10, (factor) * 100, (factor) * 1000, (factor) * 10000, \ - (factor) * 100000, (factor) * 1000000, (factor) * 10000000, \ - (factor) * 100000000, (factor) * 1000000000 - -// Converts value in the range [0, 100) to a string. -// GCC generates slightly better code when value is pointer-size. -inline auto digits2(size_t value) -> const char* { - // Align data since unaligned access may be slower when crossing a - // hardware-specific boundary. - alignas(2) static const char data[] = - "0001020304050607080910111213141516171819" - "2021222324252627282930313233343536373839" - "4041424344454647484950515253545556575859" - "6061626364656667686970717273747576777879" - "8081828384858687888990919293949596979899"; - return &data[value * 2]; -} - -template constexpr auto getsign(sign s) -> Char { - return static_cast(((' ' << 24) | ('+' << 16) | ('-' << 8)) >> - (static_cast(s) * 8)); -} - -template FMT_CONSTEXPR auto count_digits_fallback(T n) -> int { - int count = 1; - for (;;) { - // Integer division is slow so do it for a group of four digits instead - // of for every digit. The idea comes from the talk by Alexandrescu - // "Three Optimization Tips for C++". See speed-test for a comparison. - if (n < 10) return count; - if (n < 100) return count + 1; - if (n < 1000) return count + 2; - if (n < 10000) return count + 3; - n /= 10000u; - count += 4; - } -} -#if FMT_USE_INT128 -FMT_CONSTEXPR inline auto count_digits(uint128_opt n) -> int { - return count_digits_fallback(n); -} -#endif - -#ifdef FMT_BUILTIN_CLZLL -// It is a separate function rather than a part of count_digits to workaround -// the lack of static constexpr in constexpr functions. -inline auto do_count_digits(uint64_t n) -> int { - // This has comparable performance to the version by Kendall Willets - // (https://github.com/fmtlib/format-benchmark/blob/master/digits10) - // but uses smaller tables. - // Maps bsr(n) to ceil(log10(pow(2, bsr(n) + 1) - 1)). - static constexpr uint8_t bsr2log10[] = { - 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, - 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, - 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15, 15, - 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20}; - auto t = bsr2log10[FMT_BUILTIN_CLZLL(n | 1) ^ 63]; - static constexpr uint64_t zero_or_powers_of_10[] = { - 0, 0, FMT_POWERS_OF_10(1U), FMT_POWERS_OF_10(1000000000ULL), - 10000000000000000000ULL}; - return t - (n < zero_or_powers_of_10[t]); -} -#endif - -// Returns the number of decimal digits in n. Leading zeros are not counted -// except for n == 0 in which case count_digits returns 1. -FMT_CONSTEXPR20 inline auto count_digits(uint64_t n) -> int { -#ifdef FMT_BUILTIN_CLZLL - if (!is_constant_evaluated() && !FMT_OPTIMIZE_SIZE) return do_count_digits(n); -#endif - return count_digits_fallback(n); -} - -// Counts the number of digits in n. BITS = log2(radix). -template -FMT_CONSTEXPR auto count_digits(UInt n) -> int { -#ifdef FMT_BUILTIN_CLZ - if (!is_constant_evaluated() && num_bits() == 32) - return (FMT_BUILTIN_CLZ(static_cast(n) | 1) ^ 31) / BITS + 1; -#endif - // Lambda avoids unreachable code warnings from NVHPC. - return [](UInt m) { - int num_digits = 0; - do { - ++num_digits; - } while ((m >>= BITS) != 0); - return num_digits; - }(n); -} - -#ifdef FMT_BUILTIN_CLZ -// It is a separate function rather than a part of count_digits to workaround -// the lack of static constexpr in constexpr functions. -FMT_INLINE auto do_count_digits(uint32_t n) -> int { -// An optimization by Kendall Willets from https://bit.ly/3uOIQrB. -// This increments the upper 32 bits (log10(T) - 1) when >= T is added. -# define FMT_INC(T) (((sizeof(#T) - 1ull) << 32) - T) - static constexpr uint64_t table[] = { - FMT_INC(0), FMT_INC(0), FMT_INC(0), // 8 - FMT_INC(10), FMT_INC(10), FMT_INC(10), // 64 - FMT_INC(100), FMT_INC(100), FMT_INC(100), // 512 - FMT_INC(1000), FMT_INC(1000), FMT_INC(1000), // 4096 - FMT_INC(10000), FMT_INC(10000), FMT_INC(10000), // 32k - FMT_INC(100000), FMT_INC(100000), FMT_INC(100000), // 256k - FMT_INC(1000000), FMT_INC(1000000), FMT_INC(1000000), // 2048k - FMT_INC(10000000), FMT_INC(10000000), FMT_INC(10000000), // 16M - FMT_INC(100000000), FMT_INC(100000000), FMT_INC(100000000), // 128M - FMT_INC(1000000000), FMT_INC(1000000000), FMT_INC(1000000000), // 1024M - FMT_INC(1000000000), FMT_INC(1000000000) // 4B - }; - auto inc = table[FMT_BUILTIN_CLZ(n | 1) ^ 31]; - return static_cast((n + inc) >> 32); -} -#endif - -// Optional version of count_digits for better performance on 32-bit platforms. -FMT_CONSTEXPR20 inline auto count_digits(uint32_t n) -> int { -#ifdef FMT_BUILTIN_CLZ - if (!is_constant_evaluated() && !FMT_OPTIMIZE_SIZE) return do_count_digits(n); -#endif - return count_digits_fallback(n); -} - -template constexpr auto digits10() noexcept -> int { - return std::numeric_limits::digits10; -} -template <> constexpr auto digits10() noexcept -> int { return 38; } -template <> constexpr auto digits10() noexcept -> int { return 38; } - -template struct thousands_sep_result { - std::string grouping; - Char thousands_sep; -}; - -template -FMT_API auto thousands_sep_impl(locale_ref loc) -> thousands_sep_result; -template -inline auto thousands_sep(locale_ref loc) -> thousands_sep_result { - auto result = thousands_sep_impl(loc); - return {result.grouping, Char(result.thousands_sep)}; -} -template <> -inline auto thousands_sep(locale_ref loc) -> thousands_sep_result { - return thousands_sep_impl(loc); -} - -template -FMT_API auto decimal_point_impl(locale_ref loc) -> Char; -template inline auto decimal_point(locale_ref loc) -> Char { - return Char(decimal_point_impl(loc)); -} -template <> inline auto decimal_point(locale_ref loc) -> wchar_t { - return decimal_point_impl(loc); -} - -#ifndef FMT_HEADER_ONLY -FMT_BEGIN_EXPORT -extern template FMT_API auto thousands_sep_impl(locale_ref) - -> thousands_sep_result; -extern template FMT_API auto thousands_sep_impl(locale_ref) - -> thousands_sep_result; -extern template FMT_API auto decimal_point_impl(locale_ref) -> char; -extern template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t; -FMT_END_EXPORT -#endif // FMT_HEADER_ONLY - -// Compares two characters for equality. -template auto equal2(const Char* lhs, const char* rhs) -> bool { - return lhs[0] == Char(rhs[0]) && lhs[1] == Char(rhs[1]); -} -inline auto equal2(const char* lhs, const char* rhs) -> bool { - return memcmp(lhs, rhs, 2) == 0; -} - -// Writes a two-digit value to out. -template -FMT_CONSTEXPR20 FMT_INLINE void write2digits(Char* out, size_t value) { - if (!is_constant_evaluated() && std::is_same::value && - !FMT_OPTIMIZE_SIZE) { - memcpy(out, digits2(value), 2); - return; - } - *out++ = static_cast('0' + value / 10); - *out = static_cast('0' + value % 10); -} - -// Formats a decimal unsigned integer value writing to out pointing to a buffer -// of specified size. The caller must ensure that the buffer is large enough. -template -FMT_CONSTEXPR20 auto do_format_decimal(Char* out, UInt value, int size) - -> Char* { - FMT_ASSERT(size >= count_digits(value), "invalid digit count"); - unsigned n = to_unsigned(size); - while (value >= 100) { - // Integer division is slow so do it for a group of two digits instead - // of for every digit. The idea comes from the talk by Alexandrescu - // "Three Optimization Tips for C++". See speed-test for a comparison. - n -= 2; - write2digits(out + n, static_cast(value % 100)); - value /= 100; - } - if (value >= 10) { - n -= 2; - write2digits(out + n, static_cast(value)); - } else { - out[--n] = static_cast('0' + value); - } - return out + n; -} - -template -FMT_CONSTEXPR FMT_INLINE auto format_decimal(Char* out, UInt value, - int num_digits) -> Char* { - do_format_decimal(out, value, num_digits); - return out + num_digits; -} - -template >::value)> -FMT_CONSTEXPR auto format_decimal(OutputIt out, UInt value, int num_digits) - -> OutputIt { - if (auto ptr = to_pointer(out, to_unsigned(num_digits))) { - do_format_decimal(ptr, value, num_digits); - return out; - } - // Buffer is large enough to hold all digits (digits10 + 1). - char buffer[digits10() + 1]; - if (is_constant_evaluated()) fill_n(buffer, sizeof(buffer), '\0'); - do_format_decimal(buffer, value, num_digits); - return copy_noinline(buffer, buffer + num_digits, out); -} - -template -FMT_CONSTEXPR auto do_format_base2e(int base_bits, Char* out, UInt value, - int size, bool upper = false) -> Char* { - out += size; - do { - const char* digits = upper ? "0123456789ABCDEF" : "0123456789abcdef"; - unsigned digit = static_cast(value & ((1u << base_bits) - 1)); - *--out = static_cast(base_bits < 4 ? static_cast('0' + digit) - : digits[digit]); - } while ((value >>= base_bits) != 0); - return out; -} - -// Formats an unsigned integer in the power of two base (binary, octal, hex). -template -FMT_CONSTEXPR auto format_base2e(int base_bits, Char* out, UInt value, - int num_digits, bool upper = false) -> Char* { - do_format_base2e(base_bits, out, value, num_digits, upper); - return out + num_digits; -} - -template ::value)> -FMT_CONSTEXPR inline auto format_base2e(int base_bits, OutputIt out, UInt value, - int num_digits, bool upper = false) - -> OutputIt { - if (auto ptr = to_pointer(out, to_unsigned(num_digits))) { - format_base2e(base_bits, ptr, value, num_digits, upper); - return out; - } - // Make buffer large enough for any base. - char buffer[num_bits()]; - if (is_constant_evaluated()) fill_n(buffer, sizeof(buffer), '\0'); - format_base2e(base_bits, buffer, value, num_digits, upper); - return detail::copy_noinline(buffer, buffer + num_digits, out); -} - -// A converter from UTF-8 to UTF-16. -class utf8_to_utf16 { - private: - basic_memory_buffer buffer_; - - public: - FMT_API explicit utf8_to_utf16(string_view s); - inline operator basic_string_view() const { - return {&buffer_[0], size()}; - } - inline auto size() const -> size_t { return buffer_.size() - 1; } - inline auto c_str() const -> const wchar_t* { return &buffer_[0]; } - inline auto str() const -> std::wstring { return {&buffer_[0], size()}; } -}; - -enum class to_utf8_error_policy { abort, replace }; - -// A converter from UTF-16/UTF-32 (host endian) to UTF-8. -template class to_utf8 { - private: - Buffer buffer_; - - public: - to_utf8() {} - explicit to_utf8(basic_string_view s, - to_utf8_error_policy policy = to_utf8_error_policy::abort) { - static_assert(sizeof(WChar) == 2 || sizeof(WChar) == 4, - "expected utf16 or utf32"); - if (!convert(s, policy)) { - FMT_THROW(std::runtime_error(sizeof(WChar) == 2 ? "invalid utf16" - : "invalid utf32")); - } - } - operator string_view() const { return string_view(&buffer_[0], size()); } - auto size() const -> size_t { return buffer_.size() - 1; } - auto c_str() const -> const char* { return &buffer_[0]; } - auto str() const -> std::string { return std::string(&buffer_[0], size()); } - - // Performs conversion returning a bool instead of throwing exception on - // conversion error. This method may still throw in case of memory allocation - // error. - auto convert(basic_string_view s, - to_utf8_error_policy policy = to_utf8_error_policy::abort) - -> bool { - if (!convert(buffer_, s, policy)) return false; - buffer_.push_back(0); - return true; - } - static auto convert(Buffer& buf, basic_string_view s, - to_utf8_error_policy policy = to_utf8_error_policy::abort) - -> bool { - for (auto p = s.begin(); p != s.end(); ++p) { - uint32_t c = static_cast(*p); - if (sizeof(WChar) == 2 && c >= 0xd800 && c <= 0xdfff) { - // Handle a surrogate pair. - ++p; - if (p == s.end() || (c & 0xfc00) != 0xd800 || (*p & 0xfc00) != 0xdc00) { - if (policy == to_utf8_error_policy::abort) return false; - buf.append(string_view("\xEF\xBF\xBD")); - --p; - continue; - } - c = (c << 10) + static_cast(*p) - 0x35fdc00; - } - if (c < 0x80) { - buf.push_back(static_cast(c)); - } else if (c < 0x800) { - buf.push_back(static_cast(0xc0 | (c >> 6))); - buf.push_back(static_cast(0x80 | (c & 0x3f))); - } else if ((c >= 0x800 && c <= 0xd7ff) || (c >= 0xe000 && c <= 0xffff)) { - buf.push_back(static_cast(0xe0 | (c >> 12))); - buf.push_back(static_cast(0x80 | ((c & 0xfff) >> 6))); - buf.push_back(static_cast(0x80 | (c & 0x3f))); - } else if (c >= 0x10000 && c <= 0x10ffff) { - buf.push_back(static_cast(0xf0 | (c >> 18))); - buf.push_back(static_cast(0x80 | ((c & 0x3ffff) >> 12))); - buf.push_back(static_cast(0x80 | ((c & 0xfff) >> 6))); - buf.push_back(static_cast(0x80 | (c & 0x3f))); - } else { - return false; - } - } - return true; - } -}; - -// Computes 128-bit result of multiplication of two 64-bit unsigned integers. -FMT_INLINE auto umul128(uint64_t x, uint64_t y) noexcept -> uint128_fallback { -#if FMT_USE_INT128 - auto p = static_cast(x) * static_cast(y); - return {static_cast(p >> 64), static_cast(p)}; -#elif defined(_MSC_VER) && defined(_M_X64) - auto hi = uint64_t(); - auto lo = _umul128(x, y, &hi); - return {hi, lo}; -#else - const uint64_t mask = static_cast(max_value()); - - uint64_t a = x >> 32; - uint64_t b = x & mask; - uint64_t c = y >> 32; - uint64_t d = y & mask; - - uint64_t ac = a * c; - uint64_t bc = b * c; - uint64_t ad = a * d; - uint64_t bd = b * d; - - uint64_t intermediate = (bd >> 32) + (ad & mask) + (bc & mask); - - return {ac + (intermediate >> 32) + (ad >> 32) + (bc >> 32), - (intermediate << 32) + (bd & mask)}; -#endif -} - -namespace dragonbox { -// Computes floor(log10(pow(2, e))) for e in [-2620, 2620] using the method from -// https://fmt.dev/papers/Dragonbox.pdf#page=28, section 6.1. -inline auto floor_log10_pow2(int e) noexcept -> int { - FMT_ASSERT(e <= 2620 && e >= -2620, "too large exponent"); - static_assert((-1 >> 1) == -1, "right shift is not arithmetic"); - return (e * 315653) >> 20; -} - -inline auto floor_log2_pow10(int e) noexcept -> int { - FMT_ASSERT(e <= 1233 && e >= -1233, "too large exponent"); - return (e * 1741647) >> 19; -} - -// Computes upper 64 bits of multiplication of two 64-bit unsigned integers. -inline auto umul128_upper64(uint64_t x, uint64_t y) noexcept -> uint64_t { -#if FMT_USE_INT128 - auto p = static_cast(x) * static_cast(y); - return static_cast(p >> 64); -#elif defined(_MSC_VER) && defined(_M_X64) - return __umulh(x, y); -#else - return umul128(x, y).high(); -#endif -} - -// Computes upper 128 bits of multiplication of a 64-bit unsigned integer and a -// 128-bit unsigned integer. -inline auto umul192_upper128(uint64_t x, uint128_fallback y) noexcept - -> uint128_fallback { - uint128_fallback r = umul128(x, y.high()); - r += umul128_upper64(x, y.low()); - return r; -} - -FMT_API auto get_cached_power(int k) noexcept -> uint128_fallback; - -// Type-specific information that Dragonbox uses. -template struct float_info; - -template <> struct float_info { - using carrier_uint = uint32_t; - static const int exponent_bits = 8; - static const int kappa = 1; - static const int big_divisor = 100; - static const int small_divisor = 10; - static const int min_k = -31; - static const int max_k = 46; - static const int shorter_interval_tie_lower_threshold = -35; - static const int shorter_interval_tie_upper_threshold = -35; -}; - -template <> struct float_info { - using carrier_uint = uint64_t; - static const int exponent_bits = 11; - static const int kappa = 2; - static const int big_divisor = 1000; - static const int small_divisor = 100; - static const int min_k = -292; - static const int max_k = 341; - static const int shorter_interval_tie_lower_threshold = -77; - static const int shorter_interval_tie_upper_threshold = -77; -}; - -// An 80- or 128-bit floating point number. -template -struct float_info::digits == 64 || - std::numeric_limits::digits == 113 || - is_float128::value>> { - using carrier_uint = detail::uint128_t; - static const int exponent_bits = 15; -}; - -// A double-double floating point number. -template -struct float_info::value>> { - using carrier_uint = detail::uint128_t; -}; - -template struct decimal_fp { - using significand_type = typename float_info::carrier_uint; - significand_type significand; - int exponent; -}; - -template FMT_API auto to_decimal(T x) noexcept -> decimal_fp; -} // namespace dragonbox - -// Returns true iff Float has the implicit bit which is not stored. -template constexpr auto has_implicit_bit() -> bool { - // An 80-bit FP number has a 64-bit significand an no implicit bit. - return std::numeric_limits::digits != 64; -} - -// Returns the number of significand bits stored in Float. The implicit bit is -// not counted since it is not stored. -template constexpr auto num_significand_bits() -> int { - // std::numeric_limits may not support __float128. - return is_float128() ? 112 - : (std::numeric_limits::digits - - (has_implicit_bit() ? 1 : 0)); -} - -template -constexpr auto exponent_mask() -> - typename dragonbox::float_info::carrier_uint { - using float_uint = typename dragonbox::float_info::carrier_uint; - return ((float_uint(1) << dragonbox::float_info::exponent_bits) - 1) - << num_significand_bits(); -} -template constexpr auto exponent_bias() -> int { - // std::numeric_limits may not support __float128. - return is_float128() ? 16383 - : std::numeric_limits::max_exponent - 1; -} - -FMT_CONSTEXPR inline auto compute_exp_size(int exp) -> int { - auto prefix_size = 2; // sign + 'e' - auto abs_exp = exp >= 0 ? exp : -exp; - if (abs_exp < 100) return prefix_size + 2; - return prefix_size + (abs_exp >= 1000 ? 4 : 3); -} - -// Writes the exponent exp in the form "[+-]d{2,3}" to buffer. -template -FMT_CONSTEXPR auto write_exponent(int exp, OutputIt out) -> OutputIt { - FMT_ASSERT(-10000 < exp && exp < 10000, "exponent out of range"); - if (exp < 0) { - *out++ = static_cast('-'); - exp = -exp; - } else { - *out++ = static_cast('+'); - } - auto uexp = static_cast(exp); - if (is_constant_evaluated()) { - if (uexp < 10) *out++ = '0'; - return format_decimal(out, uexp, count_digits(uexp)); - } - if (uexp >= 100u) { - const char* top = digits2(uexp / 100); - if (uexp >= 1000u) *out++ = static_cast(top[0]); - *out++ = static_cast(top[1]); - uexp %= 100; - } - const char* d = digits2(uexp); - *out++ = static_cast(d[0]); - *out++ = static_cast(d[1]); - return out; -} - -// A floating-point number f * pow(2, e) where F is an unsigned type. -template struct basic_fp { - F f; - int e; - - static constexpr int num_significand_bits = - static_cast(sizeof(F) * num_bits()); - - constexpr basic_fp() : f(0), e(0) {} - constexpr basic_fp(uint64_t f_val, int e_val) : f(f_val), e(e_val) {} - - // Constructs fp from an IEEE754 floating-point number. - template FMT_CONSTEXPR basic_fp(Float n) { assign(n); } - - // Assigns n to this and return true iff predecessor is closer than successor. - template ::value)> - FMT_CONSTEXPR auto assign(Float n) -> bool { - static_assert(std::numeric_limits::digits <= 113, "unsupported FP"); - // Assume Float is in the format [sign][exponent][significand]. - using carrier_uint = typename dragonbox::float_info::carrier_uint; - const auto num_float_significand_bits = - detail::num_significand_bits(); - const auto implicit_bit = carrier_uint(1) << num_float_significand_bits; - const auto significand_mask = implicit_bit - 1; - auto u = bit_cast(n); - f = static_cast(u & significand_mask); - auto biased_e = static_cast((u & exponent_mask()) >> - num_float_significand_bits); - // The predecessor is closer if n is a normalized power of 2 (f == 0) - // other than the smallest normalized number (biased_e > 1). - auto is_predecessor_closer = f == 0 && biased_e > 1; - if (biased_e == 0) - biased_e = 1; // Subnormals use biased exponent 1 (min exponent). - else if (has_implicit_bit()) - f += static_cast(implicit_bit); - e = biased_e - exponent_bias() - num_float_significand_bits; - if (!has_implicit_bit()) ++e; - return is_predecessor_closer; - } - - template ::value)> - FMT_CONSTEXPR auto assign(Float n) -> bool { - static_assert(std::numeric_limits::is_iec559, "unsupported FP"); - return assign(static_cast(n)); - } -}; - -using fp = basic_fp; - -// Normalizes the value converted from double and multiplied by (1 << SHIFT). -template -FMT_CONSTEXPR auto normalize(basic_fp value) -> basic_fp { - // Handle subnormals. - const auto implicit_bit = F(1) << num_significand_bits(); - const auto shifted_implicit_bit = implicit_bit << SHIFT; - while ((value.f & shifted_implicit_bit) == 0) { - value.f <<= 1; - --value.e; - } - // Subtract 1 to account for hidden bit. - const auto offset = basic_fp::num_significand_bits - - num_significand_bits() - SHIFT - 1; - value.f <<= offset; - value.e -= offset; - return value; -} - -// Computes lhs * rhs / pow(2, 64) rounded to nearest with half-up tie breaking. -FMT_CONSTEXPR inline auto multiply(uint64_t lhs, uint64_t rhs) -> uint64_t { -#if FMT_USE_INT128 - auto product = static_cast<__uint128_t>(lhs) * rhs; - auto f = static_cast(product >> 64); - return (static_cast(product) & (1ULL << 63)) != 0 ? f + 1 : f; -#else - // Multiply 32-bit parts of significands. - uint64_t mask = (1ULL << 32) - 1; - uint64_t a = lhs >> 32, b = lhs & mask; - uint64_t c = rhs >> 32, d = rhs & mask; - uint64_t ac = a * c, bc = b * c, ad = a * d, bd = b * d; - // Compute mid 64-bit of result and round. - uint64_t mid = (bd >> 32) + (ad & mask) + (bc & mask) + (1U << 31); - return ac + (ad >> 32) + (bc >> 32) + (mid >> 32); -#endif -} - -FMT_CONSTEXPR inline auto operator*(fp x, fp y) -> fp { - return {multiply(x.f, y.f), x.e + y.e + 64}; -} - -template () == num_bits()> -using convert_float_result = - conditional_t::value || doublish, double, T>; - -template -constexpr auto convert_float(T value) -> convert_float_result { - return static_cast>(value); -} - -template -auto select(T true_value, F) -> T { - return true_value; -} -template -auto select(T, F false_value) -> F { - return false_value; -} - -template -FMT_CONSTEXPR FMT_NOINLINE auto fill(OutputIt it, size_t n, - const basic_specs& specs) -> OutputIt { - auto fill_size = specs.fill_size(); - if (fill_size == 1) return detail::fill_n(it, n, specs.fill_unit()); - if (const Char* data = specs.fill()) { - for (size_t i = 0; i < n; ++i) it = copy(data, data + fill_size, it); - } - return it; -} - -// Writes the output of f, padded according to format specifications in specs. -// size: output size in code units. -// width: output display width in (terminal) column positions. -template -FMT_CONSTEXPR auto write_padded(OutputIt out, const format_specs& specs, - size_t size, size_t width, F&& f) -> OutputIt { - static_assert(default_align == align::left || default_align == align::right, - ""); - unsigned spec_width = to_unsigned(specs.width); - size_t padding = spec_width > width ? spec_width - width : 0; - // Shifts are encoded as string literals because static constexpr is not - // supported in constexpr functions. - auto* shifts = - default_align == align::left ? "\x1f\x1f\x00\x01" : "\x00\x1f\x00\x01"; - size_t left_padding = padding >> shifts[static_cast(specs.align())]; - size_t right_padding = padding - left_padding; - auto it = reserve(out, size + padding * specs.fill_size()); - if (left_padding != 0) it = fill(it, left_padding, specs); - it = f(it); - if (right_padding != 0) it = fill(it, right_padding, specs); - return base_iterator(out, it); -} - -template -constexpr auto write_padded(OutputIt out, const format_specs& specs, - size_t size, F&& f) -> OutputIt { - return write_padded(out, specs, size, size, f); -} - -template -FMT_CONSTEXPR auto write_bytes(OutputIt out, string_view bytes, - const format_specs& specs = {}) -> OutputIt { - return write_padded( - out, specs, bytes.size(), [bytes](reserve_iterator it) { - const char* data = bytes.data(); - return copy(data, data + bytes.size(), it); - }); -} - -template -auto write_ptr(OutputIt out, UIntPtr value, const format_specs* specs) - -> OutputIt { - int num_digits = count_digits<4>(value); - auto size = to_unsigned(num_digits) + size_t(2); - auto write = [=](reserve_iterator it) { - *it++ = static_cast('0'); - *it++ = static_cast('x'); - return format_base2e(4, it, value, num_digits); - }; - return specs ? write_padded(out, *specs, size, write) - : base_iterator(out, write(reserve(out, size))); -} - -// Returns true iff the code point cp is printable. -FMT_API auto is_printable(uint32_t cp) -> bool; - -inline auto needs_escape(uint32_t cp) -> bool { - if (cp < 0x20 || cp == 0x7f || cp == '"' || cp == '\\') return true; - if (const_check(FMT_OPTIMIZE_SIZE > 1)) return false; - return !is_printable(cp); -} - -template struct find_escape_result { - const Char* begin; - const Char* end; - uint32_t cp; -}; - -template -auto find_escape(const Char* begin, const Char* end) - -> find_escape_result { - for (; begin != end; ++begin) { - uint32_t cp = static_cast>(*begin); - if (const_check(sizeof(Char) == 1) && cp >= 0x80) continue; - if (needs_escape(cp)) return {begin, begin + 1, cp}; - } - return {begin, nullptr, 0}; -} - -inline auto find_escape(const char* begin, const char* end) - -> find_escape_result { - if (const_check(!use_utf8)) return find_escape(begin, end); - auto result = find_escape_result{end, nullptr, 0}; - for_each_codepoint(string_view(begin, to_unsigned(end - begin)), - [&](uint32_t cp, string_view sv) { - if (needs_escape(cp)) { - result = {sv.begin(), sv.end(), cp}; - return false; - } - return true; - }); - return result; -} - -template -auto write_codepoint(OutputIt out, char prefix, uint32_t cp) -> OutputIt { - *out++ = static_cast('\\'); - *out++ = static_cast(prefix); - Char buf[width]; - fill_n(buf, width, static_cast('0')); - format_base2e(4, buf, cp, width); - return copy(buf, buf + width, out); -} - -template -auto write_escaped_cp(OutputIt out, const find_escape_result& escape) - -> OutputIt { - auto c = static_cast(escape.cp); - switch (escape.cp) { - case '\n': - *out++ = static_cast('\\'); - c = static_cast('n'); - break; - case '\r': - *out++ = static_cast('\\'); - c = static_cast('r'); - break; - case '\t': - *out++ = static_cast('\\'); - c = static_cast('t'); - break; - case '"': FMT_FALLTHROUGH; - case '\'': FMT_FALLTHROUGH; - case '\\': *out++ = static_cast('\\'); break; - default: - if (escape.cp < 0x100) return write_codepoint<2, Char>(out, 'x', escape.cp); - if (escape.cp < 0x10000) - return write_codepoint<4, Char>(out, 'u', escape.cp); - if (escape.cp < 0x110000) - return write_codepoint<8, Char>(out, 'U', escape.cp); - for (Char escape_char : basic_string_view( - escape.begin, to_unsigned(escape.end - escape.begin))) { - out = write_codepoint<2, Char>(out, 'x', - static_cast(escape_char) & 0xFF); - } - return out; - } - *out++ = c; - return out; -} - -template -auto write_escaped_string(OutputIt out, basic_string_view str) - -> OutputIt { - *out++ = static_cast('"'); - auto begin = str.begin(), end = str.end(); - do { - auto escape = find_escape(begin, end); - out = copy(begin, escape.begin, out); - begin = escape.end; - if (!begin) break; - out = write_escaped_cp(out, escape); - } while (begin != end); - *out++ = static_cast('"'); - return out; -} - -template -auto write_escaped_char(OutputIt out, Char v) -> OutputIt { - Char v_array[1] = {v}; - *out++ = static_cast('\''); - if ((needs_escape(static_cast(v)) && v != static_cast('"')) || - v == static_cast('\'')) { - out = write_escaped_cp(out, - find_escape_result{v_array, v_array + 1, - static_cast(v)}); - } else { - *out++ = v; - } - *out++ = static_cast('\''); - return out; -} - -template -FMT_CONSTEXPR auto write_char(OutputIt out, Char value, - const format_specs& specs) -> OutputIt { - bool is_debug = specs.type() == presentation_type::debug; - return write_padded(out, specs, 1, [=](reserve_iterator it) { - if (is_debug) return write_escaped_char(it, value); - *it++ = value; - return it; - }); -} - -template class digit_grouping { - private: - std::string grouping_; - std::basic_string thousands_sep_; - - struct next_state { - std::string::const_iterator group; - int pos; - }; - auto initial_state() const -> next_state { return {grouping_.begin(), 0}; } - - // Returns the next digit group separator position. - auto next(next_state& state) const -> int { - if (thousands_sep_.empty()) return max_value(); - if (state.group == grouping_.end()) return state.pos += grouping_.back(); - if (*state.group <= 0 || *state.group == max_value()) - return max_value(); - state.pos += *state.group++; - return state.pos; - } - - public: - explicit digit_grouping(locale_ref loc, bool localized = true) { - if (!localized) return; - auto sep = thousands_sep(loc); - grouping_ = sep.grouping; - if (sep.thousands_sep) thousands_sep_.assign(1, sep.thousands_sep); - } - digit_grouping(std::string grouping, std::basic_string sep) - : grouping_(std::move(grouping)), thousands_sep_(std::move(sep)) {} - - auto has_separator() const -> bool { return !thousands_sep_.empty(); } - - auto count_separators(int num_digits) const -> int { - int count = 0; - auto state = initial_state(); - while (num_digits > next(state)) ++count; - return count; - } - - // Applies grouping to digits and writes the output to out. - template - auto apply(Out out, basic_string_view digits) const -> Out { - auto num_digits = static_cast(digits.size()); - auto separators = basic_memory_buffer(); - separators.push_back(0); - auto state = initial_state(); - while (int i = next(state)) { - if (i >= num_digits) break; - separators.push_back(i); - } - for (int i = 0, sep_index = static_cast(separators.size() - 1); - i < num_digits; ++i) { - if (num_digits - i == separators[sep_index]) { - out = copy(thousands_sep_.data(), - thousands_sep_.data() + thousands_sep_.size(), out); - --sep_index; - } - *out++ = static_cast(digits[to_unsigned(i)]); - } - return out; - } -}; - -FMT_CONSTEXPR inline void prefix_append(unsigned& prefix, unsigned value) { - prefix |= prefix != 0 ? value << 8 : value; - prefix += (1u + (value > 0xff ? 1 : 0)) << 24; -} - -// Writes a decimal integer with digit grouping. -template -auto write_int(OutputIt out, UInt value, unsigned prefix, - const format_specs& specs, const digit_grouping& grouping) - -> OutputIt { - static_assert(std::is_same, UInt>::value, ""); - int num_digits = 0; - auto buffer = memory_buffer(); - switch (specs.type()) { - default: FMT_ASSERT(false, ""); FMT_FALLTHROUGH; - case presentation_type::none: - case presentation_type::dec: - num_digits = count_digits(value); - format_decimal(appender(buffer), value, num_digits); - break; - case presentation_type::hex: - if (specs.alt()) - prefix_append(prefix, unsigned(specs.upper() ? 'X' : 'x') << 8 | '0'); - num_digits = count_digits<4>(value); - format_base2e(4, appender(buffer), value, num_digits, specs.upper()); - break; - case presentation_type::oct: - num_digits = count_digits<3>(value); - // Octal prefix '0' is counted as a digit, so only add it if precision - // is not greater than the number of digits. - if (specs.alt() && specs.precision <= num_digits && value != 0) - prefix_append(prefix, '0'); - format_base2e(3, appender(buffer), value, num_digits); - break; - case presentation_type::bin: - if (specs.alt()) - prefix_append(prefix, unsigned(specs.upper() ? 'B' : 'b') << 8 | '0'); - num_digits = count_digits<1>(value); - format_base2e(1, appender(buffer), value, num_digits); - break; - case presentation_type::chr: - return write_char(out, static_cast(value), specs); - } - - unsigned size = (prefix != 0 ? prefix >> 24 : 0) + to_unsigned(num_digits) + - to_unsigned(grouping.count_separators(num_digits)); - return write_padded( - out, specs, size, size, [&](reserve_iterator it) { - for (unsigned p = prefix & 0xffffff; p != 0; p >>= 8) - *it++ = static_cast(p & 0xff); - return grouping.apply(it, string_view(buffer.data(), buffer.size())); - }); -} - -#if FMT_USE_LOCALE -// Writes a localized value. -FMT_API auto write_loc(appender out, loc_value value, const format_specs& specs, - locale_ref loc) -> bool; -auto write_loc(basic_appender out, loc_value value, - const format_specs& specs, locale_ref loc) -> bool; -#endif -template -inline auto write_loc(OutputIt, const loc_value&, const format_specs&, - locale_ref) -> bool { - return false; -} - -template struct write_int_arg { - UInt abs_value; - unsigned prefix; -}; - -template -FMT_CONSTEXPR auto make_write_int_arg(T value, sign s) - -> write_int_arg> { - auto prefix = 0u; - auto abs_value = static_cast>(value); - if (is_negative(value)) { - prefix = 0x01000000 | '-'; - abs_value = 0 - abs_value; - } else { - constexpr unsigned prefixes[4] = {0, 0, 0x1000000u | '+', 0x1000000u | ' '}; - prefix = prefixes[static_cast(s)]; - } - return {abs_value, prefix}; -} - -template struct loc_writer { - basic_appender out; - const format_specs& specs; - std::basic_string sep; - std::string grouping; - std::basic_string decimal_point; - - template ::value)> - auto operator()(T value) -> bool { - auto arg = make_write_int_arg(value, specs.sign()); - write_int(out, static_cast>(arg.abs_value), arg.prefix, - specs, digit_grouping(grouping, sep)); - return true; - } - - template ::value)> - auto operator()(T) -> bool { - return false; - } -}; - -// Size and padding computation separate from write_int to avoid template bloat. -struct size_padding { - unsigned size; - unsigned padding; - - FMT_CONSTEXPR size_padding(int num_digits, unsigned prefix, - const format_specs& specs) - : size((prefix >> 24) + to_unsigned(num_digits)), padding(0) { - if (specs.align() == align::numeric) { - auto width = to_unsigned(specs.width); - if (width > size) { - padding = width - size; - size = width; - } - } else if (specs.precision > num_digits) { - size = (prefix >> 24) + to_unsigned(specs.precision); - padding = to_unsigned(specs.precision - num_digits); - } - } -}; - -template -FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg arg, - const format_specs& specs) -> OutputIt { - static_assert(std::is_same>::value, ""); - - constexpr size_t buffer_size = num_bits(); - char buffer[buffer_size]; - if (is_constant_evaluated()) fill_n(buffer, buffer_size, '\0'); - const char* begin = nullptr; - const char* end = buffer + buffer_size; - - auto abs_value = arg.abs_value; - auto prefix = arg.prefix; - switch (specs.type()) { - default: FMT_ASSERT(false, ""); FMT_FALLTHROUGH; - case presentation_type::none: - case presentation_type::dec: - begin = do_format_decimal(buffer, abs_value, buffer_size); - break; - case presentation_type::hex: - begin = do_format_base2e(4, buffer, abs_value, buffer_size, specs.upper()); - if (specs.alt()) - prefix_append(prefix, unsigned(specs.upper() ? 'X' : 'x') << 8 | '0'); - break; - case presentation_type::oct: { - begin = do_format_base2e(3, buffer, abs_value, buffer_size); - // Octal prefix '0' is counted as a digit, so only add it if precision - // is not greater than the number of digits. - auto num_digits = end - begin; - if (specs.alt() && specs.precision <= num_digits && abs_value != 0) - prefix_append(prefix, '0'); - break; - } - case presentation_type::bin: - begin = do_format_base2e(1, buffer, abs_value, buffer_size); - if (specs.alt()) - prefix_append(prefix, unsigned(specs.upper() ? 'B' : 'b') << 8 | '0'); - break; - case presentation_type::chr: - return write_char(out, static_cast(abs_value), specs); - } - - // Write an integer in the format - // - // prefix contains chars in three lower bytes and the size in the fourth byte. - int num_digits = static_cast(end - begin); - // Slightly faster check for specs.width == 0 && specs.precision == -1. - if ((specs.width | (specs.precision + 1)) == 0) { - auto it = reserve(out, to_unsigned(num_digits) + (prefix >> 24)); - for (unsigned p = prefix & 0xffffff; p != 0; p >>= 8) - *it++ = static_cast(p & 0xff); - return base_iterator(out, copy(begin, end, it)); - } - auto sp = size_padding(num_digits, prefix, specs); - unsigned padding = sp.padding; - return write_padded( - out, specs, sp.size, [=](reserve_iterator it) { - for (unsigned p = prefix & 0xffffff; p != 0; p >>= 8) - *it++ = static_cast(p & 0xff); - it = detail::fill_n(it, padding, static_cast('0')); - return copy(begin, end, it); - }); -} - -template -FMT_CONSTEXPR FMT_NOINLINE auto write_int_noinline(OutputIt out, - write_int_arg arg, - const format_specs& specs) - -> OutputIt { - return write_int(out, arg, specs); -} - -template ::value && - !std::is_same::value && - !std::is_same::value)> -FMT_CONSTEXPR FMT_INLINE auto write(basic_appender out, T value, - const format_specs& specs, locale_ref loc) - -> basic_appender { - if (specs.localized() && write_loc(out, value, specs, loc)) return out; - return write_int_noinline(out, make_write_int_arg(value, specs.sign()), - specs); -} - -// An inlined version of write used in format string compilation. -template ::value && - !std::is_same::value && - !std::is_same::value && - !std::is_same>::value)> -FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value, - const format_specs& specs, locale_ref loc) - -> OutputIt { - if (specs.localized() && write_loc(out, value, specs, loc)) return out; - return write_int(out, make_write_int_arg(value, specs.sign()), specs); -} - -template -FMT_CONSTEXPR auto write(OutputIt out, Char value, const format_specs& specs, - locale_ref loc = {}) -> OutputIt { - // char is formatted as unsigned char for consistency across platforms. - using unsigned_type = - conditional_t::value, unsigned char, unsigned>; - return check_char_specs(specs) - ? write_char(out, value, specs) - : write(out, static_cast(value), specs, loc); -} - -template ::value)> -FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, - const format_specs& specs) -> OutputIt { - bool is_debug = specs.type() == presentation_type::debug; - if (specs.precision < 0 && specs.width == 0) { - auto&& it = reserve(out, s.size()); - return is_debug ? write_escaped_string(it, s) : copy(s, it); - } - - size_t display_width_limit = - specs.precision < 0 ? SIZE_MAX : to_unsigned(specs.precision); - size_t display_width = - !is_debug || specs.precision == 0 ? 0 : 1; // Account for opening '"'. - size_t size = !is_debug || specs.precision == 0 ? 0 : 1; - for_each_codepoint(s, [&](uint32_t cp, string_view sv) { - if (is_debug && needs_escape(cp)) { - counting_buffer buf; - write_escaped_cp(basic_appender(buf), - find_escape_result{sv.begin(), sv.end(), cp}); - // We're reinterpreting bytes as display width. That's okay - // because write_escaped_cp() only writes ASCII characters. - size_t cp_width = buf.count(); - if (display_width + cp_width <= display_width_limit) { - display_width += cp_width; - size += cp_width; - // If this is the end of the string, account for closing '"'. - if (display_width < display_width_limit && sv.end() == s.end()) { - ++display_width; - ++size; - } - return true; - } - - size += display_width_limit - display_width; - display_width = display_width_limit; - return false; - } - - size_t cp_width = display_width_of(cp); - if (cp_width + display_width <= display_width_limit) { - display_width += cp_width; - size += sv.size(); - // If this is the end of the string, account for closing '"'. - if (is_debug && display_width < display_width_limit && - sv.end() == s.end()) { - ++display_width; - ++size; - } - return true; - } - - return false; - }); - - struct bounded_output_iterator { - reserve_iterator underlying_iterator; - size_t bound; - - FMT_CONSTEXPR auto operator*() -> bounded_output_iterator& { return *this; } - FMT_CONSTEXPR auto operator++() -> bounded_output_iterator& { - return *this; - } - FMT_CONSTEXPR auto operator++(int) -> bounded_output_iterator& { - return *this; - } - FMT_CONSTEXPR auto operator=(char c) -> bounded_output_iterator& { - if (bound > 0) { - *underlying_iterator++ = c; - --bound; - } - return *this; - } - }; - - return write_padded( - out, specs, size, display_width, [=](reserve_iterator it) { - return is_debug - ? write_escaped_string(bounded_output_iterator{it, size}, s) - .underlying_iterator - : copy(s.data(), s.data() + size, it); - }); -} - -template ::value)> -FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, - const format_specs& specs) -> OutputIt { - auto data = s.data(); - auto size = s.size(); - if (specs.precision >= 0 && to_unsigned(specs.precision) < size) - size = to_unsigned(specs.precision); - - bool is_debug = specs.type() == presentation_type::debug; - if (is_debug) { - auto buf = counting_buffer(); - write_escaped_string(basic_appender(buf), s); - size = buf.count(); - } - - return write_padded( - out, specs, size, [=](reserve_iterator it) { - return is_debug ? write_escaped_string(it, s) - : copy(data, data + size, it); - }); -} - -template -FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, - const format_specs& specs, locale_ref) -> OutputIt { - return write(out, s, specs); -} - -template -FMT_CONSTEXPR auto write(OutputIt out, const Char* s, const format_specs& specs, - locale_ref) -> OutputIt { - if (specs.type() == presentation_type::pointer) - return write_ptr(out, bit_cast(s), &specs); - if (!s) report_error("string pointer is null"); - return write(out, basic_string_view(s), specs, {}); -} - -template ::value && - !std::is_same::value && - !std::is_same::value)> -FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt { - auto abs_value = static_cast>(value); - bool negative = is_negative(value); - // Don't do -abs_value since it trips unsigned-integer-overflow sanitizer. - if (negative) abs_value = ~abs_value + 1; - int num_digits = count_digits(abs_value); - auto size = (negative ? 1 : 0) + static_cast(num_digits); - if (auto ptr = to_pointer(out, size)) { - if (negative) *ptr++ = static_cast('-'); - format_decimal(ptr, abs_value, num_digits); - return out; - } - if (negative) *out++ = static_cast('-'); - return format_decimal(out, abs_value, num_digits); -} - -template -FMT_CONSTEXPR auto parse_align(const Char* begin, const Char* end, - format_specs& specs) -> const Char* { - FMT_ASSERT(begin != end, ""); - auto alignment = align::none; - auto p = begin + code_point_length(begin); - if (end - p <= 0) p = begin; - for (;;) { - switch (to_ascii(*p)) { - case '<': alignment = align::left; break; - case '>': alignment = align::right; break; - case '^': alignment = align::center; break; - } - if (alignment != align::none) { - if (p != begin) { - auto c = *begin; - if (c == '}') return begin; - if (c == '{') { - report_error("invalid fill character '{'"); - return begin; - } - specs.set_fill(basic_string_view(begin, to_unsigned(p - begin))); - begin = p + 1; - } else { - ++begin; - } - break; - } else if (p == begin) { - break; - } - p = begin; - } - specs.set_align(alignment); - return begin; -} - -template -FMT_CONSTEXPR20 auto write_nonfinite(OutputIt out, bool isnan, - format_specs specs, sign s) -> OutputIt { - auto str = - isnan ? (specs.upper() ? "NAN" : "nan") : (specs.upper() ? "INF" : "inf"); - constexpr size_t str_size = 3; - auto size = str_size + (s != sign::none ? 1 : 0); - // Replace '0'-padding with space for non-finite values. - const bool is_zero_fill = - specs.fill_size() == 1 && specs.fill_unit() == '0'; - if (is_zero_fill) specs.set_fill(' '); - return write_padded(out, specs, size, - [=](reserve_iterator it) { - if (s != sign::none) - *it++ = detail::getsign(s); - return copy(str, str + str_size, it); - }); -} - -// A decimal floating-point number significand * pow(10, exp). -struct big_decimal_fp { - const char* significand; - int significand_size; - int exponent; -}; - -constexpr auto get_significand_size(const big_decimal_fp& f) -> int { - return f.significand_size; -} -template -inline auto get_significand_size(const dragonbox::decimal_fp& f) -> int { - return count_digits(f.significand); -} - -template -constexpr auto write_significand(OutputIt out, const char* significand, - int significand_size) -> OutputIt { - return copy(significand, significand + significand_size, out); -} -template -inline auto write_significand(OutputIt out, UInt significand, - int significand_size) -> OutputIt { - return format_decimal(out, significand, significand_size); -} -template -FMT_CONSTEXPR20 auto write_significand(OutputIt out, T significand, - int significand_size, int exponent, - const Grouping& grouping) -> OutputIt { - if (!grouping.has_separator()) { - out = write_significand(out, significand, significand_size); - return detail::fill_n(out, exponent, static_cast('0')); - } - auto buffer = memory_buffer(); - write_significand(appender(buffer), significand, significand_size); - detail::fill_n(appender(buffer), exponent, '0'); - return grouping.apply(out, string_view(buffer.data(), buffer.size())); -} - -template ::value)> -inline auto write_significand(Char* out, UInt significand, int significand_size, - int integral_size, Char decimal_point) -> Char* { - if (!decimal_point) return format_decimal(out, significand, significand_size); - out += significand_size + 1; - Char* end = out; - int floating_size = significand_size - integral_size; - for (int i = floating_size / 2; i > 0; --i) { - out -= 2; - write2digits(out, static_cast(significand % 100)); - significand /= 100; - } - if (floating_size % 2 != 0) { - *--out = static_cast('0' + significand % 10); - significand /= 10; - } - *--out = decimal_point; - format_decimal(out - integral_size, significand, integral_size); - return end; -} - -template >::value)> -inline auto write_significand(OutputIt out, UInt significand, - int significand_size, int integral_size, - Char decimal_point) -> OutputIt { - // Buffer is large enough to hold digits (digits10 + 1) and a decimal point. - Char buffer[digits10() + 2]; - auto end = write_significand(buffer, significand, significand_size, - integral_size, decimal_point); - return detail::copy_noinline(buffer, end, out); -} - -template -FMT_CONSTEXPR auto write_significand(OutputIt out, const char* significand, - int significand_size, int integral_size, - Char decimal_point) -> OutputIt { - out = detail::copy_noinline(significand, significand + integral_size, - out); - if (!decimal_point) return out; - *out++ = decimal_point; - return detail::copy_noinline(significand + integral_size, - significand + significand_size, out); -} - -template -FMT_CONSTEXPR20 auto write_significand(OutputIt out, T significand, - int significand_size, int integral_size, - Char decimal_point, - const Grouping& grouping) -> OutputIt { - if (!grouping.has_separator()) { - return write_significand(out, significand, significand_size, integral_size, - decimal_point); - } - auto buffer = basic_memory_buffer(); - write_significand(basic_appender(buffer), significand, significand_size, - integral_size, decimal_point); - grouping.apply( - out, basic_string_view(buffer.data(), to_unsigned(integral_size))); - return detail::copy_noinline(buffer.data() + integral_size, - buffer.end(), out); -} - -// Numbers with exponents greater or equal to the returned value will use -// the exponential notation. -template FMT_CONSTEVAL auto exp_upper() -> int { - return std::numeric_limits::digits10 != 0 - ? min_of(16, std::numeric_limits::digits10 + 1) - : 16; -} - -// Use the fixed notation if the exponent is in [-4, exp_upper), -// e.g. 0.0001 instead of 1e-04. Otherwise use the exponent notation. -constexpr auto use_fixed(int exp, int exp_upper) -> bool { - return exp >= -4 && exp < exp_upper; -} - -template class fallback_digit_grouping { - public: - constexpr fallback_digit_grouping(locale_ref, bool) {} - - constexpr auto has_separator() const -> bool { return false; } - - constexpr auto count_separators(int) const -> int { return 0; } - - template - constexpr auto apply(Out out, basic_string_view) const -> Out { - return out; - } -}; - -template -FMT_CONSTEXPR20 auto write_fixed(OutputIt out, const DecimalFP& f, - int significand_size, Char decimal_point, - const format_specs& specs, sign s, - locale_ref loc = {}) -> OutputIt { - using iterator = reserve_iterator; - - int exp = f.exponent + significand_size; - long long size = significand_size + (s != sign::none ? 1 : 0); - if (f.exponent >= 0) { - // 1234e5 -> 123400000[.0+] - size += f.exponent; - int num_zeros = specs.precision - exp; - abort_fuzzing_if(num_zeros > 5000); - if (specs.alt()) { - ++size; - if (num_zeros <= 0 && specs.type() != presentation_type::fixed) - num_zeros = 0; - if (num_zeros > 0) size += num_zeros; - } - auto grouping = Grouping(loc, specs.localized()); - size += grouping.count_separators(exp); - return write_padded( - out, specs, to_unsigned(size), [&](iterator it) { - if (s != sign::none) *it++ = detail::getsign(s); - it = write_significand(it, f.significand, significand_size, - f.exponent, grouping); - if (!specs.alt()) return it; - *it++ = decimal_point; - return num_zeros > 0 ? detail::fill_n(it, num_zeros, Char('0')) : it; - }); - } - if (exp > 0) { - // 1234e-2 -> 12.34[0+] - int num_zeros = specs.alt() ? specs.precision - significand_size : 0; - size += 1 + max_of(num_zeros, 0); - auto grouping = Grouping(loc, specs.localized()); - size += grouping.count_separators(exp); - return write_padded( - out, specs, to_unsigned(size), [&](iterator it) { - if (s != sign::none) *it++ = detail::getsign(s); - it = write_significand(it, f.significand, significand_size, exp, - decimal_point, grouping); - return num_zeros > 0 ? detail::fill_n(it, num_zeros, Char('0')) : it; - }); - } - // 1234e-6 -> 0.001234 - int num_zeros = -exp; - if (significand_size == 0 && specs.precision >= 0 && - specs.precision < num_zeros) { - num_zeros = specs.precision; - } - bool pointy = num_zeros != 0 || significand_size != 0 || specs.alt(); - size += 1 + (pointy ? 1 : 0) + num_zeros; - return write_padded( - out, specs, to_unsigned(size), [&](iterator it) { - if (s != sign::none) *it++ = detail::getsign(s); - *it++ = Char('0'); - if (!pointy) return it; - *it++ = decimal_point; - it = detail::fill_n(it, num_zeros, Char('0')); - return write_significand(it, f.significand, significand_size); - }); -} - -template -FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f, - const format_specs& specs, sign s, - int exp_upper, locale_ref loc) -> OutputIt { - Char point = specs.localized() ? detail::decimal_point(loc) : Char('.'); - int significand_size = get_significand_size(f); - int exp = f.exponent + significand_size - 1; - if (specs.type() == presentation_type::fixed || - (specs.type() != presentation_type::exp && - use_fixed(exp, specs.precision > 0 ? specs.precision : exp_upper))) { - return write_fixed(out, f, significand_size, point, specs, - s, loc); - } - - // Write value in the exponential format. - int num_zeros = 0; - long long size = significand_size + (s != sign::none ? 1 : 0); - if (specs.alt()) { - num_zeros = max_of(specs.precision - significand_size, 0); - size += num_zeros; - } else if (significand_size == 1) { - point = Char(); - } - size += (point ? 1 : 0) + compute_exp_size(exp); - char exp_char = specs.upper() ? 'E' : 'e'; - auto write = [=](reserve_iterator it) { - if (s != sign::none) *it++ = detail::getsign(s); - // Insert a decimal point after the first digit and add an exponent. - it = write_significand(it, f.significand, significand_size, 1, point); - if (num_zeros > 0) it = detail::fill_n(it, num_zeros, Char('0')); - *it++ = Char(exp_char); - return write_exponent(exp, it); - }; - auto usize = to_unsigned(size); - return specs.width > 0 - ? write_padded(out, specs, usize, write) - : base_iterator(out, write(reserve(out, usize))); -} - -template -FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f, - const format_specs& specs, sign s, - int exp_upper, locale_ref loc) -> OutputIt { - if (is_constant_evaluated()) { - return do_write_float>(out, f, specs, s, - exp_upper, loc); - } else { - return do_write_float>(out, f, specs, s, - exp_upper, loc); - } -} - -template constexpr auto isnan(T value) -> bool { - return value != value; // std::isnan doesn't support __float128. -} - -template -struct has_isfinite : std::false_type {}; - -template -struct has_isfinite> - : std::true_type {}; - -template ::value&& has_isfinite::value)> -FMT_CONSTEXPR20 auto isfinite(T value) -> bool { - constexpr T inf = T(std::numeric_limits::infinity()); - if (is_constant_evaluated()) - return !detail::isnan(value) && value < inf && value > -inf; - return std::isfinite(value); -} -template ::value)> -FMT_CONSTEXPR auto isfinite(T value) -> bool { - T inf = T(std::numeric_limits::infinity()); - // std::isfinite doesn't support __float128. - return !detail::isnan(value) && value < inf && value > -inf; -} - -template ::value)> -FMT_INLINE FMT_CONSTEXPR auto signbit(T value) -> bool { - if (is_constant_evaluated()) { -#ifdef __cpp_if_constexpr - if constexpr (std::numeric_limits::is_iec559) { - auto bits = detail::bit_cast(static_cast(value)); - return (bits >> (num_bits() - 1)) != 0; - } -#endif - } - return std::signbit(static_cast(value)); -} - -inline FMT_CONSTEXPR20 void adjust_precision(int& precision, int exp10) { - // Adjust fixed precision by exponent because it is relative to decimal - // point. - if (exp10 > 0 && precision > max_value() - exp10) - FMT_THROW(format_error("number is too big")); - precision += exp10; -} - -class bigint { - private: - // A bigint is a number in the form bigit_[N - 1] ... bigit_[0] * 32^exp_. - using bigit = uint32_t; // A big digit. - using double_bigit = uint64_t; - enum { bigit_bits = num_bits() }; - enum { bigits_capacity = 32 }; - basic_memory_buffer bigits_; - int exp_; - - friend struct formatter; - - FMT_CONSTEXPR auto get_bigit(int i) const -> bigit { - return i >= exp_ && i < num_bigits() ? bigits_[i - exp_] : 0; - } - - FMT_CONSTEXPR void subtract_bigits(int index, bigit other, bigit& borrow) { - auto result = double_bigit(bigits_[index]) - other - borrow; - bigits_[index] = static_cast(result); - borrow = static_cast(result >> (bigit_bits * 2 - 1)); - } - - FMT_CONSTEXPR void remove_leading_zeros() { - int num_bigits = static_cast(bigits_.size()) - 1; - while (num_bigits > 0 && bigits_[num_bigits] == 0) --num_bigits; - bigits_.resize(to_unsigned(num_bigits + 1)); - } - - // Computes *this -= other assuming aligned bigints and *this >= other. - FMT_CONSTEXPR void subtract_aligned(const bigint& other) { - FMT_ASSERT(other.exp_ >= exp_, "unaligned bigints"); - FMT_ASSERT(compare(*this, other) >= 0, ""); - bigit borrow = 0; - int i = other.exp_ - exp_; - for (size_t j = 0, n = other.bigits_.size(); j != n; ++i, ++j) - subtract_bigits(i, other.bigits_[j], borrow); - if (borrow != 0) subtract_bigits(i, 0, borrow); - FMT_ASSERT(borrow == 0, ""); - remove_leading_zeros(); - } - - FMT_CONSTEXPR void multiply(uint32_t value) { - bigit carry = 0; - const double_bigit wide_value = value; - for (size_t i = 0, n = bigits_.size(); i < n; ++i) { - double_bigit result = bigits_[i] * wide_value + carry; - bigits_[i] = static_cast(result); - carry = static_cast(result >> bigit_bits); - } - if (carry != 0) bigits_.push_back(carry); - } - - template ::value || - std::is_same::value)> - FMT_CONSTEXPR void multiply(UInt value) { - using half_uint = - conditional_t::value, uint64_t, uint32_t>; - const int shift = num_bits() - bigit_bits; - const UInt lower = static_cast(value); - const UInt upper = value >> num_bits(); - UInt carry = 0; - for (size_t i = 0, n = bigits_.size(); i < n; ++i) { - UInt result = lower * bigits_[i] + static_cast(carry); - carry = (upper * bigits_[i] << shift) + (result >> bigit_bits) + - (carry >> bigit_bits); - bigits_[i] = static_cast(result); - } - while (carry != 0) { - bigits_.push_back(static_cast(carry)); - carry >>= bigit_bits; - } - } - - template ::value || - std::is_same::value)> - FMT_CONSTEXPR void assign(UInt n) { - size_t num_bigits = 0; - do { - bigits_[num_bigits++] = static_cast(n); - n >>= bigit_bits; - } while (n != 0); - bigits_.resize(num_bigits); - exp_ = 0; - } - - public: - FMT_CONSTEXPR bigint() : exp_(0) {} - explicit bigint(uint64_t n) { assign(n); } - - bigint(const bigint&) = delete; - void operator=(const bigint&) = delete; - - FMT_CONSTEXPR void assign(const bigint& other) { - auto size = other.bigits_.size(); - bigits_.resize(size); - auto data = other.bigits_.data(); - copy(data, data + size, bigits_.data()); - exp_ = other.exp_; - } - - template FMT_CONSTEXPR void operator=(Int n) { - FMT_ASSERT(n > 0, ""); - assign(uint64_or_128_t(n)); - } - - FMT_CONSTEXPR auto num_bigits() const -> int { - return static_cast(bigits_.size()) + exp_; - } - - FMT_CONSTEXPR auto operator<<=(int shift) -> bigint& { - FMT_ASSERT(shift >= 0, ""); - exp_ += shift / bigit_bits; - shift %= bigit_bits; - if (shift == 0) return *this; - bigit carry = 0; - for (size_t i = 0, n = bigits_.size(); i < n; ++i) { - bigit c = bigits_[i] >> (bigit_bits - shift); - bigits_[i] = (bigits_[i] << shift) + carry; - carry = c; - } - if (carry != 0) bigits_.push_back(carry); - return *this; - } - - template FMT_CONSTEXPR auto operator*=(Int value) -> bigint& { - FMT_ASSERT(value > 0, ""); - multiply(uint32_or_64_or_128_t(value)); - return *this; - } - - friend FMT_CONSTEXPR auto compare(const bigint& b1, const bigint& b2) -> int { - int num_bigits1 = b1.num_bigits(), num_bigits2 = b2.num_bigits(); - if (num_bigits1 != num_bigits2) return num_bigits1 > num_bigits2 ? 1 : -1; - int i = static_cast(b1.bigits_.size()) - 1; - int j = static_cast(b2.bigits_.size()) - 1; - int end = i - j; - if (end < 0) end = 0; - for (; i >= end; --i, --j) { - bigit b1_bigit = b1.bigits_[i], b2_bigit = b2.bigits_[j]; - if (b1_bigit != b2_bigit) return b1_bigit > b2_bigit ? 1 : -1; - } - if (i != j) return i > j ? 1 : -1; - return 0; - } - - // Returns compare(lhs1 + lhs2, rhs). - friend FMT_CONSTEXPR auto add_compare(const bigint& lhs1, const bigint& lhs2, - const bigint& rhs) -> int { - int max_lhs_bigits = max_of(lhs1.num_bigits(), lhs2.num_bigits()); - int num_rhs_bigits = rhs.num_bigits(); - if (max_lhs_bigits + 1 < num_rhs_bigits) return -1; - if (max_lhs_bigits > num_rhs_bigits) return 1; - double_bigit borrow = 0; - int min_exp = min_of(min_of(lhs1.exp_, lhs2.exp_), rhs.exp_); - for (int i = num_rhs_bigits - 1; i >= min_exp; --i) { - double_bigit sum = double_bigit(lhs1.get_bigit(i)) + lhs2.get_bigit(i); - bigit rhs_bigit = rhs.get_bigit(i); - if (sum > rhs_bigit + borrow) return 1; - borrow = rhs_bigit + borrow - sum; - if (borrow > 1) return -1; - borrow <<= bigit_bits; - } - return borrow != 0 ? -1 : 0; - } - - // Assigns pow(10, exp) to this bigint. - FMT_CONSTEXPR20 void assign_pow10(int exp) { - FMT_ASSERT(exp >= 0, ""); - if (exp == 0) return *this = 1; - int bitmask = 1 << (num_bits() - - countl_zero(static_cast(exp)) - 1); - // pow(10, exp) = pow(5, exp) * pow(2, exp). First compute pow(5, exp) by - // repeated squaring and multiplication. - *this = 5; - bitmask >>= 1; - while (bitmask != 0) { - square(); - if ((exp & bitmask) != 0) *this *= 5; - bitmask >>= 1; - } - *this <<= exp; // Multiply by pow(2, exp) by shifting. - } - - FMT_CONSTEXPR20 void square() { - int num_bigits = static_cast(bigits_.size()); - int num_result_bigits = 2 * num_bigits; - basic_memory_buffer n(std::move(bigits_)); - bigits_.resize(to_unsigned(num_result_bigits)); - auto sum = uint128_t(); - for (int bigit_index = 0; bigit_index < num_bigits; ++bigit_index) { - // Compute bigit at position bigit_index of the result by adding - // cross-product terms n[i] * n[j] such that i + j == bigit_index. - for (int i = 0, j = bigit_index; j >= 0; ++i, --j) { - // Most terms are multiplied twice which can be optimized in the future. - sum += double_bigit(n[i]) * n[j]; - } - bigits_[bigit_index] = static_cast(sum); - sum >>= num_bits(); // Compute the carry. - } - // Do the same for the top half. - for (int bigit_index = num_bigits; bigit_index < num_result_bigits; - ++bigit_index) { - for (int j = num_bigits - 1, i = bigit_index - j; i < num_bigits;) - sum += double_bigit(n[i++]) * n[j--]; - bigits_[bigit_index] = static_cast(sum); - sum >>= num_bits(); - } - remove_leading_zeros(); - exp_ *= 2; - } - - // If this bigint has a bigger exponent than other, adds trailing zero to make - // exponents equal. This simplifies some operations such as subtraction. - FMT_CONSTEXPR void align(const bigint& other) { - int exp_difference = exp_ - other.exp_; - if (exp_difference <= 0) return; - int num_bigits = static_cast(bigits_.size()); - bigits_.resize(to_unsigned(num_bigits + exp_difference)); - for (int i = num_bigits - 1, j = i + exp_difference; i >= 0; --i, --j) - bigits_[j] = bigits_[i]; - fill_n(bigits_.data(), to_unsigned(exp_difference), 0U); - exp_ -= exp_difference; - } - - // Divides this bignum by divisor, assigning the remainder to this and - // returning the quotient. - FMT_CONSTEXPR auto divmod_assign(const bigint& divisor) -> int { - FMT_ASSERT(this != &divisor, ""); - if (compare(*this, divisor) < 0) return 0; - FMT_ASSERT(divisor.bigits_[divisor.bigits_.size() - 1u] != 0, ""); - align(divisor); - int quotient = 0; - do { - subtract_aligned(divisor); - ++quotient; - } while (compare(*this, divisor) >= 0); - return quotient; - } -}; - -// format_dragon flags. -enum dragon { - predecessor_closer = 1, - fixup = 2, // Run fixup to correct exp10 which can be off by one. - fixed = 4, -}; - -// Formats a floating-point number using a variation of the Fixed-Precision -// Positive Floating-Point Printout ((FPP)^2) algorithm by Steele & White: -// https://fmt.dev/papers/p372-steele.pdf. -FMT_CONSTEXPR20 inline void format_dragon(basic_fp value, - unsigned flags, int num_digits, - buffer& buf, int& exp10) { - bigint numerator; // 2 * R in (FPP)^2. - bigint denominator; // 2 * S in (FPP)^2. - // lower and upper are differences between value and corresponding boundaries. - bigint lower; // (M^- in (FPP)^2). - bigint upper_store; // upper's value if different from lower. - bigint* upper = nullptr; // (M^+ in (FPP)^2). - // Shift numerator and denominator by an extra bit or two (if lower boundary - // is closer) to make lower and upper integers. This eliminates multiplication - // by 2 during later computations. - bool is_predecessor_closer = (flags & dragon::predecessor_closer) != 0; - int shift = is_predecessor_closer ? 2 : 1; - if (value.e >= 0) { - numerator = value.f; - numerator <<= value.e + shift; - lower = 1; - lower <<= value.e; - if (is_predecessor_closer) { - upper_store = 1; - upper_store <<= value.e + 1; - upper = &upper_store; - } - denominator.assign_pow10(exp10); - denominator <<= shift; - } else if (exp10 < 0) { - numerator.assign_pow10(-exp10); - lower.assign(numerator); - if (is_predecessor_closer) { - upper_store.assign(numerator); - upper_store <<= 1; - upper = &upper_store; - } - numerator *= value.f; - numerator <<= shift; - denominator = 1; - denominator <<= shift - value.e; - } else { - numerator = value.f; - numerator <<= shift; - denominator.assign_pow10(exp10); - denominator <<= shift - value.e; - lower = 1; - if (is_predecessor_closer) { - upper_store = 1ULL << 1; - upper = &upper_store; - } - } - int even = static_cast((value.f & 1) == 0); - if (!upper) upper = &lower; - bool shortest = num_digits < 0; - if ((flags & dragon::fixup) != 0) { - if (add_compare(numerator, *upper, denominator) + even <= 0) { - --exp10; - numerator *= 10; - if (num_digits < 0) { - lower *= 10; - if (upper != &lower) *upper *= 10; - } - } - if ((flags & dragon::fixed) != 0) adjust_precision(num_digits, exp10 + 1); - } - // Invariant: value == (numerator / denominator) * pow(10, exp10). - if (shortest) { - // Generate the shortest representation. - num_digits = 0; - char* data = buf.data(); - for (;;) { - int digit = numerator.divmod_assign(denominator); - bool low = compare(numerator, lower) - even < 0; // numerator <[=] lower. - // numerator + upper >[=] pow10: - bool high = add_compare(numerator, *upper, denominator) + even > 0; - data[num_digits++] = static_cast('0' + digit); - if (low || high) { - if (!low) { - ++data[num_digits - 1]; - } else if (high) { - int result = add_compare(numerator, numerator, denominator); - // Round half to even. - if (result > 0 || (result == 0 && (digit % 2) != 0)) - ++data[num_digits - 1]; - } - buf.try_resize(to_unsigned(num_digits)); - exp10 -= num_digits - 1; - return; - } - numerator *= 10; - lower *= 10; - if (upper != &lower) *upper *= 10; - } - } - // Generate the given number of digits. - exp10 -= num_digits - 1; - if (num_digits <= 0) { - auto digit = '0'; - if (num_digits == 0) { - denominator *= 10; - digit = add_compare(numerator, numerator, denominator) > 0 ? '1' : '0'; - } - buf.push_back(digit); - return; - } - buf.try_resize(to_unsigned(num_digits)); - for (int i = 0; i < num_digits - 1; ++i) { - int digit = numerator.divmod_assign(denominator); - buf[i] = static_cast('0' + digit); - numerator *= 10; - } - int digit = numerator.divmod_assign(denominator); - auto result = add_compare(numerator, numerator, denominator); - if (result > 0 || (result == 0 && (digit % 2) != 0)) { - if (digit == 9) { - const auto overflow = '0' + 10; - buf[num_digits - 1] = overflow; - // Propagate the carry. - for (int i = num_digits - 1; i > 0 && buf[i] == overflow; --i) { - buf[i] = '0'; - ++buf[i - 1]; - } - if (buf[0] == overflow) { - buf[0] = '1'; - if ((flags & dragon::fixed) != 0) - buf.push_back('0'); - else - ++exp10; - } - return; - } - ++digit; - } - buf[num_digits - 1] = static_cast('0' + digit); -} - -// Formats a floating-point number using the hexfloat format. -template ::value)> -FMT_CONSTEXPR20 void format_hexfloat(Float value, format_specs specs, - buffer& buf) { - // float is passed as double to reduce the number of instantiations and to - // simplify implementation. - static_assert(!std::is_same::value, ""); - - using info = dragonbox::float_info; - - // Assume Float is in the format [sign][exponent][significand]. - using carrier_uint = typename info::carrier_uint; - - const auto num_float_significand_bits = detail::num_significand_bits(); - - basic_fp f(value); - f.e += num_float_significand_bits; - if (!has_implicit_bit()) --f.e; - - const auto num_fraction_bits = - num_float_significand_bits + (has_implicit_bit() ? 1 : 0); - const auto num_xdigits = (num_fraction_bits + 3) / 4; - - const auto leading_shift = ((num_xdigits - 1) * 4); - const auto leading_mask = carrier_uint(0xF) << leading_shift; - const auto leading_xdigit = - static_cast((f.f & leading_mask) >> leading_shift); - if (leading_xdigit > 1) f.e -= (32 - countl_zero(leading_xdigit) - 1); - - int print_xdigits = num_xdigits - 1; - if (specs.precision >= 0 && print_xdigits > specs.precision) { - const int shift = ((print_xdigits - specs.precision - 1) * 4); - const auto mask = carrier_uint(0xF) << shift; - const auto v = static_cast((f.f & mask) >> shift); - - if (v >= 8) { - const auto inc = carrier_uint(1) << (shift + 4); - f.f += inc; - f.f &= ~(inc - 1); - } - - // Check long double overflow - if (!has_implicit_bit()) { - const auto implicit_bit = carrier_uint(1) << num_float_significand_bits; - if ((f.f & implicit_bit) == implicit_bit) { - f.f >>= 4; - f.e += 4; - } - } - - print_xdigits = specs.precision; - } - - char xdigits[num_bits() / 4]; - detail::fill_n(xdigits, sizeof(xdigits), '0'); - format_base2e(4, xdigits, f.f, num_xdigits, specs.upper()); - - // Remove zero tail - while (print_xdigits > 0 && xdigits[print_xdigits] == '0') --print_xdigits; - - buf.push_back('0'); - buf.push_back(specs.upper() ? 'X' : 'x'); - buf.push_back(xdigits[0]); - if (specs.alt() || print_xdigits > 0 || print_xdigits < specs.precision) - buf.push_back('.'); - buf.append(xdigits + 1, xdigits + 1 + print_xdigits); - for (; print_xdigits < specs.precision; ++print_xdigits) buf.push_back('0'); - - buf.push_back(specs.upper() ? 'P' : 'p'); - - uint32_t abs_e; - if (f.e < 0) { - buf.push_back('-'); - abs_e = static_cast(-f.e); - } else { - buf.push_back('+'); - abs_e = static_cast(f.e); - } - format_decimal(appender(buf), abs_e, detail::count_digits(abs_e)); -} - -template ::value)> -FMT_CONSTEXPR20 void format_hexfloat(Float value, format_specs specs, - buffer& buf) { - format_hexfloat(static_cast(value), specs, buf); -} - -constexpr auto fractional_part_rounding_thresholds(int index) -> uint32_t { - // For checking rounding thresholds. - // The kth entry is chosen to be the smallest integer such that the - // upper 32-bits of 10^(k+1) times it is strictly bigger than 5 * 10^k. - // It is equal to ceil(2^31 + 2^32/10^(k + 1)). - // These are stored in a string literal because we cannot have static arrays - // in constexpr functions and non-static ones are poorly optimized. - return U"\x9999999a\x828f5c29\x80418938\x80068db9\x8000a7c6\x800010c7" - U"\x800001ae\x8000002b"[index]; -} - -template -FMT_CONSTEXPR20 auto format_float(Float value, int precision, - const format_specs& specs, bool binary32, - buffer& buf) -> int { - // float is passed as double to reduce the number of instantiations. - static_assert(!std::is_same::value, ""); - auto converted_value = convert_float(value); - - const bool fixed = specs.type() == presentation_type::fixed; - if (value == 0) { - if (precision <= 0 || !fixed) { - buf.push_back('0'); - return 0; - } - buf.try_resize(to_unsigned(precision)); - fill_n(buf.data(), precision, '0'); - return -precision; - } - - int exp = 0; - bool use_dragon = true; - unsigned dragon_flags = 0; - if (!is_fast_float() || is_constant_evaluated()) { - const auto inv_log2_10 = 0.3010299956639812; // 1 / log2(10) - using info = dragonbox::float_info; - const auto f = basic_fp(converted_value); - // Compute exp, an approximate power of 10, such that - // 10^(exp - 1) <= value < 10^exp or 10^exp <= value < 10^(exp + 1). - // This is based on log10(value) == log2(value) / log2(10) and approximation - // of log2(value) by e + num_fraction_bits idea from double-conversion. - auto e = (f.e + count_digits<1>(f.f) - 1) * inv_log2_10 - 1e-10; - exp = static_cast(e); - if (e > exp) ++exp; // Compute ceil. - dragon_flags = dragon::fixup; - } else { - // Extract significand bits and exponent bits. - using info = dragonbox::float_info; - auto br = bit_cast(static_cast(value)); - - const uint64_t significand_mask = - (static_cast(1) << num_significand_bits()) - 1; - uint64_t significand = (br & significand_mask); - int exponent = static_cast((br & exponent_mask()) >> - num_significand_bits()); - - if (exponent != 0) { // Check if normal. - exponent -= exponent_bias() + num_significand_bits(); - significand |= - (static_cast(1) << num_significand_bits()); - significand <<= 1; - } else { - // Normalize subnormal inputs. - FMT_ASSERT(significand != 0, "zeros should not appear here"); - int shift = countl_zero(significand); - FMT_ASSERT(shift >= num_bits() - num_significand_bits(), - ""); - shift -= (num_bits() - num_significand_bits() - 2); - exponent = (std::numeric_limits::min_exponent - - num_significand_bits()) - - shift; - significand <<= shift; - } - - // Compute the first several nonzero decimal significand digits. - // We call the number we get the first segment. - const int k = info::kappa - dragonbox::floor_log10_pow2(exponent); - exp = -k; - const int beta = exponent + dragonbox::floor_log2_pow10(k); - uint64_t first_segment; - bool has_more_segments; - int digits_in_the_first_segment; - { - const auto r = dragonbox::umul192_upper128( - significand << beta, dragonbox::get_cached_power(k)); - first_segment = r.high(); - has_more_segments = r.low() != 0; - - // The first segment can have 18 ~ 19 digits. - if (first_segment >= 1000000000000000000ULL) { - digits_in_the_first_segment = 19; - } else { - // When it is of 18-digits, we align it to 19-digits by adding a bogus - // zero at the end. - digits_in_the_first_segment = 18; - first_segment *= 10; - } - } - - // Compute the actual number of decimal digits to print. - if (fixed) adjust_precision(precision, exp + digits_in_the_first_segment); - - // Use Dragon4 only when there might be not enough digits in the first - // segment. - if (digits_in_the_first_segment > precision) { - use_dragon = false; - - if (precision <= 0) { - exp += digits_in_the_first_segment; - - if (precision < 0) { - // Nothing to do, since all we have are just leading zeros. - buf.try_resize(0); - } else { - // We may need to round-up. - buf.try_resize(1); - if ((first_segment | static_cast(has_more_segments)) > - 5000000000000000000ULL) { - buf[0] = '1'; - } else { - buf[0] = '0'; - } - } - } // precision <= 0 - else { - exp += digits_in_the_first_segment - precision; - - // When precision > 0, we divide the first segment into three - // subsegments, each with 9, 9, and 0 ~ 1 digits so that each fits - // in 32-bits which usually allows faster calculation than in - // 64-bits. Since some compiler (e.g. MSVC) doesn't know how to optimize - // division-by-constant for large 64-bit divisors, we do it here - // manually. The magic number 7922816251426433760 below is equal to - // ceil(2^(64+32) / 10^10). - const uint32_t first_subsegment = static_cast( - dragonbox::umul128_upper64(first_segment, 7922816251426433760ULL) >> - 32); - const uint64_t second_third_subsegments = - first_segment - first_subsegment * 10000000000ULL; - - uint64_t prod; - uint32_t digits; - bool should_round_up; - int number_of_digits_to_print = min_of(precision, 9); - - // Print a 9-digits subsegment, either the first or the second. - auto print_subsegment = [&](uint32_t subsegment, char* buffer) { - int number_of_digits_printed = 0; - - // If we want to print an odd number of digits from the subsegment, - if ((number_of_digits_to_print & 1) != 0) { - // Convert to 64-bit fixed-point fractional form with 1-digit - // integer part. The magic number 720575941 is a good enough - // approximation of 2^(32 + 24) / 10^8; see - // https://jk-jeon.github.io/posts/2022/12/fixed-precision-formatting/#fixed-length-case - // for details. - prod = ((subsegment * static_cast(720575941)) >> 24) + 1; - digits = static_cast(prod >> 32); - *buffer = static_cast('0' + digits); - number_of_digits_printed++; - } - // If we want to print an even number of digits from the - // first_subsegment, - else { - // Convert to 64-bit fixed-point fractional form with 2-digits - // integer part. The magic number 450359963 is a good enough - // approximation of 2^(32 + 20) / 10^7; see - // https://jk-jeon.github.io/posts/2022/12/fixed-precision-formatting/#fixed-length-case - // for details. - prod = ((subsegment * static_cast(450359963)) >> 20) + 1; - digits = static_cast(prod >> 32); - write2digits(buffer, digits); - number_of_digits_printed += 2; - } - - // Print all digit pairs. - while (number_of_digits_printed < number_of_digits_to_print) { - prod = static_cast(prod) * static_cast(100); - digits = static_cast(prod >> 32); - write2digits(buffer + number_of_digits_printed, digits); - number_of_digits_printed += 2; - } - }; - - // Print first subsegment. - print_subsegment(first_subsegment, buf.data()); - - // Perform rounding if the first subsegment is the last subsegment to - // print. - if (precision <= 9) { - // Rounding inside the subsegment. - // We round-up if: - // - either the fractional part is strictly larger than 1/2, or - // - the fractional part is exactly 1/2 and the last digit is odd. - // We rely on the following observations: - // - If fractional_part >= threshold, then the fractional part is - // strictly larger than 1/2. - // - If the MSB of fractional_part is set, then the fractional part - // must be at least 1/2. - // - When the MSB of fractional_part is set, either - // second_third_subsegments being nonzero or has_more_segments - // being true means there are further digits not printed, so the - // fractional part is strictly larger than 1/2. - if (precision < 9) { - uint32_t fractional_part = static_cast(prod); - should_round_up = - fractional_part >= fractional_part_rounding_thresholds( - 8 - number_of_digits_to_print) || - ((fractional_part >> 31) & - ((digits & 1) | (second_third_subsegments != 0) | - has_more_segments)) != 0; - } - // Rounding at the subsegment boundary. - // In this case, the fractional part is at least 1/2 if and only if - // second_third_subsegments >= 5000000000ULL, and is strictly larger - // than 1/2 if we further have either second_third_subsegments > - // 5000000000ULL or has_more_segments == true. - else { - should_round_up = second_third_subsegments > 5000000000ULL || - (second_third_subsegments == 5000000000ULL && - ((digits & 1) != 0 || has_more_segments)); - } - } - // Otherwise, print the second subsegment. - else { - // Compilers are not aware of how to leverage the maximum value of - // second_third_subsegments to find out a better magic number which - // allows us to eliminate an additional shift. 1844674407370955162 = - // ceil(2^64/10) < ceil(2^64*(10^9/(10^10 - 1))). - const uint32_t second_subsegment = - static_cast(dragonbox::umul128_upper64( - second_third_subsegments, 1844674407370955162ULL)); - const uint32_t third_subsegment = - static_cast(second_third_subsegments) - - second_subsegment * 10; - - number_of_digits_to_print = precision - 9; - print_subsegment(second_subsegment, buf.data() + 9); - - // Rounding inside the subsegment. - if (precision < 18) { - // The condition third_subsegment != 0 implies that the segment was - // of 19 digits, so in this case the third segment should be - // consisting of a genuine digit from the input. - uint32_t fractional_part = static_cast(prod); - should_round_up = - fractional_part >= fractional_part_rounding_thresholds( - 8 - number_of_digits_to_print) || - ((fractional_part >> 31) & - ((digits & 1) | (third_subsegment != 0) | - has_more_segments)) != 0; - } - // Rounding at the subsegment boundary. - else { - // In this case, the segment must be of 19 digits, thus - // the third subsegment should be consisting of a genuine digit from - // the input. - should_round_up = third_subsegment > 5 || - (third_subsegment == 5 && - ((digits & 1) != 0 || has_more_segments)); - } - } - - // Round-up if necessary. - if (should_round_up) { - ++buf[precision - 1]; - for (int i = precision - 1; i > 0 && buf[i] > '9'; --i) { - buf[i] = '0'; - ++buf[i - 1]; - } - if (buf[0] > '9') { - buf[0] = '1'; - if (fixed) - buf[precision++] = '0'; - else - ++exp; - } - } - buf.try_resize(to_unsigned(precision)); - } - } // if (digits_in_the_first_segment > precision) - else { - // Adjust the exponent for its use in Dragon4. - exp += digits_in_the_first_segment - 1; - } - } - if (use_dragon) { - auto f = basic_fp(); - bool is_predecessor_closer = binary32 ? f.assign(static_cast(value)) - : f.assign(converted_value); - if (is_predecessor_closer) dragon_flags |= dragon::predecessor_closer; - if (fixed) dragon_flags |= dragon::fixed; - // Limit precision to the maximum possible number of significant digits in - // an IEEE754 double because we don't need to generate zeros. - const int max_double_digits = 767; - if (precision > max_double_digits) precision = max_double_digits; - format_dragon(f, dragon_flags, precision, buf, exp); - } - if (!fixed && !specs.alt()) { - // Remove trailing zeros. - auto num_digits = buf.size(); - while (num_digits > 0 && buf[num_digits - 1] == '0') { - --num_digits; - ++exp; - } - buf.try_resize(num_digits); - } - return exp; -} - -template ::value)> -FMT_CONSTEXPR20 auto write(OutputIt out, T value, format_specs specs, - locale_ref loc = {}) -> OutputIt { - if (specs.localized() && write_loc(out, value, specs, loc)) return out; - - // Use signbit because value < 0 is false for NaN. - sign s = detail::signbit(value) ? sign::minus : specs.sign(); - - if (!detail::isfinite(value)) - return write_nonfinite(out, detail::isnan(value), specs, s); - - if (specs.align() == align::numeric && s != sign::none) { - *out++ = detail::getsign(s); - s = sign::none; - if (specs.width != 0) --specs.width; - } - - const int exp_upper = detail::exp_upper(); - int precision = specs.precision; - if (precision < 0) { - if (specs.type() != presentation_type::none) { - precision = 6; - } else if (is_fast_float::value && !is_constant_evaluated()) { - // Use Dragonbox for the shortest format. - auto dec = dragonbox::to_decimal(static_cast>(value)); - return write_float(out, dec, specs, s, exp_upper, loc); - } - } - - memory_buffer buffer; - if (specs.type() == presentation_type::hexfloat) { - if (s != sign::none) buffer.push_back(detail::getsign(s)); - format_hexfloat(convert_float(value), specs, buffer); - return write_bytes(out, {buffer.data(), buffer.size()}, - specs); - } - - if (specs.type() == presentation_type::exp) { - if (precision == max_value()) - report_error("number is too big"); - else - ++precision; - if (specs.precision != 0) specs.set_alt(); - } else if (specs.type() == presentation_type::fixed) { - if (specs.precision != 0) specs.set_alt(); - } else if (precision == 0) { - precision = 1; - } - int exp = format_float(convert_float(value), precision, specs, - std::is_same(), buffer); - - specs.precision = precision; - auto f = big_decimal_fp{buffer.data(), static_cast(buffer.size()), exp}; - return write_float(out, f, specs, s, exp_upper, loc); -} - -template ::value)> -FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt { - if (is_constant_evaluated()) return write(out, value, format_specs()); - - auto s = detail::signbit(value) ? sign::minus : sign::none; - auto mask = exponent_mask>(); - if ((bit_cast(value) & mask) == mask) - return write_nonfinite(out, std::isnan(value), {}, s); - - auto dec = dragonbox::to_decimal(static_cast>(value)); - auto significand = dec.significand; - int significand_size = count_digits(significand); - int exponent = dec.exponent + significand_size - 1; - if (use_fixed(exponent, detail::exp_upper())) { - return write_fixed>( - out, dec, significand_size, Char('.'), {}, s); - } - - // Write value in the exponential format. - const char* prefix = "e+"; - int abs_exponent = exponent; - if (exponent < 0) { - abs_exponent = -exponent; - prefix = "e-"; - } - auto has_decimal_point = significand_size != 1; - size_t size = std::is_pointer::value - ? 0u - : to_unsigned((s != sign::none ? 1 : 0) + significand_size + - (has_decimal_point ? 1 : 0) + - (abs_exponent >= 100 ? 5 : 4)); - if (auto ptr = to_pointer(out, size)) { - if (s != sign::none) *ptr++ = Char('-'); - if (has_decimal_point) { - auto begin = ptr; - ptr = format_decimal(ptr, significand, significand_size + 1); - *begin = begin[1]; - begin[1] = '.'; - } else { - *ptr++ = static_cast('0' + significand); - } - if (std::is_same::value) { - memcpy(ptr, prefix, 2); - ptr += 2; - } else { - *ptr++ = prefix[0]; - *ptr++ = prefix[1]; - } - if (abs_exponent >= 100) { - *ptr++ = static_cast('0' + abs_exponent / 100); - abs_exponent %= 100; - } - write2digits(ptr, static_cast(abs_exponent)); - return select::value>(ptr + 2, out); - } - auto it = reserve(out, size); - if (s != sign::none) *it++ = Char('-'); - // Insert a decimal point after the first digit and add an exponent. - it = write_significand(it, significand, significand_size, 1, - has_decimal_point ? Char('.') : Char()); - *it++ = Char('e'); - it = write_exponent(exponent, it); - return base_iterator(out, it); -} - -template ::value && - !is_fast_float::value)> -inline auto write(OutputIt out, T value) -> OutputIt { - return write(out, value, {}); -} - -template -auto write(OutputIt out, monostate, format_specs = {}, locale_ref = {}) - -> OutputIt { - FMT_ASSERT(false, ""); - return out; -} - -template -FMT_CONSTEXPR auto write(OutputIt out, basic_string_view value) - -> OutputIt { - return copy_noinline(value.begin(), value.end(), out); -} - -template ::value)> -constexpr auto write(OutputIt out, const T& value) -> OutputIt { - return write(out, to_string_view(value)); -} - -// FMT_ENABLE_IF() condition separated to workaround an MSVC bug. -template < - typename Char, typename OutputIt, typename T, - bool check = std::is_enum::value && !std::is_same::value && - mapped_type_constant::value != type::custom_type, - FMT_ENABLE_IF(check)> -FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt { - return write(out, static_cast>(value)); -} - -template ::value)> -FMT_CONSTEXPR auto write(OutputIt out, T value, const format_specs& specs = {}, - locale_ref = {}) -> OutputIt { - return specs.type() != presentation_type::none && - specs.type() != presentation_type::string - ? write(out, value ? 1 : 0, specs, {}) - : write_bytes(out, value ? "true" : "false", specs); -} - -template -FMT_CONSTEXPR auto write(OutputIt out, Char value) -> OutputIt { - auto it = reserve(out, 1); - *it++ = value; - return base_iterator(out, it); -} - -template -FMT_CONSTEXPR20 auto write(OutputIt out, const Char* value) -> OutputIt { - if (value) return write(out, basic_string_view(value)); - report_error("string pointer is null"); - return out; -} - -template ::value)> -auto write(OutputIt out, const T* value, const format_specs& specs = {}, - locale_ref = {}) -> OutputIt { - return write_ptr(out, bit_cast(value), &specs); -} - -template ::value == - type::custom_type && - !std::is_fundamental::value)> -FMT_CONSTEXPR auto write(OutputIt out, const T& value) -> OutputIt { - auto f = formatter(); - auto parse_ctx = parse_context({}); - f.parse(parse_ctx); - auto ctx = basic_format_context(out, {}, {}); - return f.format(value, ctx); -} - -template -using is_builtin = - bool_constant::value || FMT_BUILTIN_TYPES>; - -// An argument visitor that formats the argument and writes it via the output -// iterator. It's a class and not a generic lambda for compatibility with C++11. -template struct default_arg_formatter { - using context = buffered_context; - - basic_appender out; - - void operator()(monostate) { report_error("argument not found"); } - - template ::value)> - void operator()(T value) { - write(out, value); - } - - template ::value)> - void operator()(T) { - FMT_ASSERT(false, ""); - } - - void operator()(typename basic_format_arg::handle h) { - // Use a null locale since the default format must be unlocalized. - auto parse_ctx = parse_context({}); - auto format_ctx = context(out, {}, {}); - h.format(parse_ctx, format_ctx); - } -}; - -template struct arg_formatter { - basic_appender out; - const format_specs& specs; - FMT_NO_UNIQUE_ADDRESS locale_ref locale; - - template ::value)> - FMT_CONSTEXPR FMT_INLINE void operator()(T value) { - detail::write(out, value, specs, locale); - } - - template ::value)> - void operator()(T) { - FMT_ASSERT(false, ""); - } - - void operator()(typename basic_format_arg>::handle) { - // User-defined types are handled separately because they require access - // to the parse context. - } -}; - -struct dynamic_spec_getter { - template ::value)> - FMT_CONSTEXPR auto operator()(T value) -> unsigned long long { - return is_negative(value) ? ~0ull : static_cast(value); - } - - template ::value)> - FMT_CONSTEXPR auto operator()(T) -> unsigned long long { - report_error("width/precision is not integer"); - return 0; - } -}; - -template -FMT_CONSTEXPR void handle_dynamic_spec( - arg_id_kind kind, int& value, - const arg_ref& ref, Context& ctx) { - if (kind == arg_id_kind::none) return; - auto arg = - kind == arg_id_kind::index ? ctx.arg(ref.index) : ctx.arg(ref.name); - if (!arg) report_error("argument not found"); - unsigned long long result = arg.visit(dynamic_spec_getter()); - if (result > to_unsigned(max_value())) - report_error("width/precision is out of range"); - value = static_cast(result); -} - -#if FMT_USE_NONTYPE_TEMPLATE_ARGS -template Str> -struct static_named_arg : view { - static constexpr auto name = Str.data; - - const T& value; - static_named_arg(const T& v) : value(v) {} -}; - -template Str> -struct is_named_arg> : std::true_type {}; - -template Str> -struct is_static_named_arg> : std::true_type { -}; - -template Str> -struct udl_arg { - template auto operator=(T&& value) const { - return static_named_arg(std::forward(value)); - } -}; -#else -template struct udl_arg { - const Char* str; - - template auto operator=(T&& value) const -> named_arg { - return {str, std::forward(value)}; - } -}; -#endif // FMT_USE_NONTYPE_TEMPLATE_ARGS - -template struct format_handler { - parse_context parse_ctx; - buffered_context ctx; - - void on_text(const Char* begin, const Char* end) { - copy_noinline(begin, end, ctx.out()); - } - - FMT_CONSTEXPR auto on_arg_id() -> int { return parse_ctx.next_arg_id(); } - FMT_CONSTEXPR auto on_arg_id(int id) -> int { - parse_ctx.check_arg_id(id); - return id; - } - FMT_CONSTEXPR auto on_arg_id(basic_string_view id) -> int { - parse_ctx.check_arg_id(id); - int arg_id = ctx.arg_id(id); - if (arg_id < 0) report_error("argument not found"); - return arg_id; - } - - FMT_INLINE void on_replacement_field(int id, const Char*) { - ctx.arg(id).visit(default_arg_formatter{ctx.out()}); - } - - auto on_format_specs(int id, const Char* begin, const Char* end) - -> const Char* { - auto arg = ctx.arg(id); - if (!arg) report_error("argument not found"); - // Not using a visitor for custom types gives better codegen. - if (arg.format_custom(begin, parse_ctx, ctx)) return parse_ctx.begin(); - - auto specs = dynamic_format_specs(); - begin = parse_format_specs(begin, end, specs, parse_ctx, arg.type()); - if (specs.dynamic()) { - handle_dynamic_spec(specs.dynamic_width(), specs.width, specs.width_ref, - ctx); - handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs.precision_ref, ctx); - } - - arg.visit(arg_formatter{ctx.out(), specs, ctx.locale()}); - return begin; - } - - FMT_NORETURN void on_error(const char* message) { report_error(message); } -}; - -// It is used in format-inl.h and os.cc. -using format_func = void (*)(detail::buffer&, int, const char*); -FMT_API void do_report_error(format_func func, int error_code, - const char* message) noexcept; - -FMT_API void format_error_code(buffer& out, int error_code, - string_view message) noexcept; - -template -template -FMT_CONSTEXPR auto native_formatter::format( - const T& val, FormatContext& ctx) const -> decltype(ctx.out()) { - if (!specs_.dynamic()) - return write(ctx.out(), val, specs_, ctx.locale()); - auto specs = format_specs(specs_); - handle_dynamic_spec(specs.dynamic_width(), specs.width, specs_.width_ref, - ctx); - handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs_.precision_ref, ctx); - return write(ctx.out(), val, specs, ctx.locale()); -} -} // namespace detail - -FMT_BEGIN_EXPORT - -// A generic formatting context with custom output iterator and character -// (code unit) support. Char is the format string code unit type which can be -// different from OutputIt::value_type. -template class generic_context { - private: - OutputIt out_; - basic_format_args args_; - locale_ref loc_; - - public: - using char_type = Char; - using iterator = OutputIt; - enum { builtin_types = FMT_BUILTIN_TYPES }; - - constexpr generic_context(OutputIt out, - basic_format_args args, - locale_ref loc = {}) - : out_(out), args_(args), loc_(loc) {} - generic_context(generic_context&&) = default; - generic_context(const generic_context&) = delete; - void operator=(const generic_context&) = delete; - - constexpr auto arg(int id) const -> basic_format_arg { - return args_.get(id); - } - auto arg(basic_string_view name) const - -> basic_format_arg { - return args_.get(name); - } - constexpr auto arg_id(basic_string_view name) const -> int { - return args_.get_id(name); - } - - constexpr auto out() const -> iterator { return out_; } - - void advance_to(iterator it) { - if (!detail::is_back_insert_iterator()) out_ = it; - } - - constexpr auto locale() const -> locale_ref { return loc_; } -}; - -class loc_value { - private: - basic_format_arg value_; - - public: - template ::value)> - loc_value(T value) : value_(value) {} - - template ::value)> - loc_value(T) {} - - template auto visit(Visitor&& vis) -> decltype(vis(0)) { - return value_.visit(vis); - } -}; - -// A locale facet that formats values in UTF-8. -// It is parameterized on the locale to avoid the heavy include. -template class format_facet : public Locale::facet { - private: - std::string separator_; - std::string grouping_; - std::string decimal_point_; - - protected: - virtual auto do_put(appender out, loc_value val, - const format_specs& specs) const -> bool; - - public: - static FMT_API typename Locale::id id; - - explicit format_facet(Locale& loc); - explicit format_facet(string_view sep = "", std::string grouping = "\3", - std::string decimal_point = ".") - : separator_(sep.data(), sep.size()), - grouping_(grouping), - decimal_point_(decimal_point) {} - - auto put(appender out, loc_value val, const format_specs& specs) const - -> bool { - return do_put(out, val, specs); - } -}; - -#define FMT_FORMAT_AS(Type, Base) \ - template \ - struct formatter : formatter { \ - template \ - FMT_CONSTEXPR auto format(Type value, FormatContext& ctx) const \ - -> decltype(ctx.out()) { \ - return formatter::format(value, ctx); \ - } \ - } - -FMT_FORMAT_AS(signed char, int); -FMT_FORMAT_AS(unsigned char, unsigned); -FMT_FORMAT_AS(short, int); -FMT_FORMAT_AS(unsigned short, unsigned); -FMT_FORMAT_AS(long, detail::long_type); -FMT_FORMAT_AS(unsigned long, detail::ulong_type); -FMT_FORMAT_AS(Char*, const Char*); -FMT_FORMAT_AS(detail::std_string_view, basic_string_view); -FMT_FORMAT_AS(std::nullptr_t, const void*); -FMT_FORMAT_AS(void*, const void*); - -template -struct formatter : formatter, Char> {}; - -template -class formatter, Char> - : public formatter, Char> {}; - -template -struct formatter, Char> : formatter {}; -template -struct formatter, Char> - : formatter {}; - -template -struct formatter - : detail::native_formatter {}; - -template -struct formatter>> - : formatter, Char> { - template - FMT_CONSTEXPR auto format(const T& value, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto&& val = format_as(value); // Make an lvalue reference for format. - return formatter, Char>::format(val, ctx); - } -}; - -/** - * Converts `p` to `const void*` for pointer formatting. - * - * **Example**: - * - * auto s = fmt::format("{}", fmt::ptr(p)); - */ -template auto ptr(T p) -> const void* { - static_assert(std::is_pointer::value, "fmt::ptr used with non-pointer"); - return detail::bit_cast(p); -} - -/** - * Converts `e` to the underlying type. - * - * **Example**: - * - * enum class color { red, green, blue }; - * auto s = fmt::format("{}", fmt::underlying(color::red)); // s == "0" - */ -template -constexpr auto underlying(Enum e) noexcept -> underlying_t { - return static_cast>(e); -} - -namespace enums { -template ::value)> -constexpr auto format_as(Enum e) noexcept -> underlying_t { - return static_cast>(e); -} -} // namespace enums - -#ifdef __cpp_lib_byte -template -struct formatter : formatter { - static auto format_as(std::byte b) -> unsigned char { - return static_cast(b); - } - template - auto format(std::byte b, Context& ctx) const -> decltype(ctx.out()) { - return formatter::format(format_as(b), ctx); - } -}; -#endif - -struct bytes { - string_view data; - - inline explicit bytes(string_view s) : data(s) {} -}; - -template <> struct formatter { - private: - detail::dynamic_format_specs<> specs_; - - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - return parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, - detail::type::string_type); - } - - template - auto format(bytes b, FormatContext& ctx) const -> decltype(ctx.out()) { - auto specs = specs_; - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs.precision_ref, ctx); - return detail::write_bytes(ctx.out(), b.data, specs); - } -}; - -// group_digits_view is not derived from view because it copies the argument. -template struct group_digits_view { - T value; -}; - -/** - * Returns a view that formats an integer value using ',' as a - * locale-independent thousands separator. - * - * **Example**: - * - * fmt::print("{}", fmt::group_digits(12345)); - * // Output: "12,345" - */ -template auto group_digits(T value) -> group_digits_view { - return {value}; -} - -template struct formatter> : formatter { - private: - detail::dynamic_format_specs<> specs_; - - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - return parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, - detail::type::int_type); - } - - template - auto format(group_digits_view view, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto specs = specs_; - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs.precision_ref, ctx); - auto arg = detail::make_write_int_arg(view.value, specs.sign()); - return detail::write_int( - ctx.out(), static_cast>(arg.abs_value), - arg.prefix, specs, detail::digit_grouping("\3", ",")); - } -}; - -template struct nested_view { - const formatter* fmt; - const T* value; -}; - -template -struct formatter, Char> { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return ctx.begin(); - } - template - auto format(nested_view view, FormatContext& ctx) const - -> decltype(ctx.out()) { - return view.fmt->format(*view.value, ctx); - } -}; - -template struct nested_formatter { - private: - basic_specs specs_; - int width_; - formatter formatter_; - - public: - constexpr nested_formatter() : width_(0) {} - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it == end) return it; - auto specs = format_specs(); - it = detail::parse_align(it, end, specs); - specs_ = specs; - Char c = *it; - auto width_ref = detail::arg_ref(); - if ((c >= '0' && c <= '9') || c == '{') { - it = detail::parse_width(it, end, specs, width_ref, ctx); - width_ = specs.width; - } - ctx.advance_to(it); - return formatter_.parse(ctx); - } - - template - auto write_padded(FormatContext& ctx, F write) const -> decltype(ctx.out()) { - if (width_ == 0) return write(ctx.out()); - auto buf = basic_memory_buffer(); - write(basic_appender(buf)); - auto specs = format_specs(); - specs.width = width_; - specs.copy_fill_from(specs_); - specs.set_align(specs_.align()); - return detail::write( - ctx.out(), basic_string_view(buf.data(), buf.size()), specs); - } - - auto nested(const T& value) const -> nested_view { - return nested_view{&formatter_, &value}; - } -}; - -inline namespace literals { -#if FMT_USE_NONTYPE_TEMPLATE_ARGS -template constexpr auto operator""_a() { - using char_t = remove_cvref_t; - return detail::udl_arg(); -} -#else -/** - * User-defined literal equivalent of `fmt::arg`. - * - * **Example**: - * - * using namespace fmt::literals; - * fmt::print("The answer is {answer}.", "answer"_a=42); - */ -constexpr auto operator""_a(const char* s, size_t) -> detail::udl_arg { - return {s}; -} -#endif // FMT_USE_NONTYPE_TEMPLATE_ARGS -} // namespace literals - -/// A fast integer formatter. -class format_int { - private: - // Buffer should be large enough to hold all digits (digits10 + 1), - // a sign and a null character. - enum { buffer_size = std::numeric_limits::digits10 + 3 }; - mutable char buffer_[buffer_size]; - char* str_; - - template - FMT_CONSTEXPR20 auto format_unsigned(UInt value) -> char* { - auto n = static_cast>(value); - return detail::do_format_decimal(buffer_, n, buffer_size - 1); - } - - template - FMT_CONSTEXPR20 auto format_signed(Int value) -> char* { - auto abs_value = static_cast>(value); - bool negative = value < 0; - if (negative) abs_value = 0 - abs_value; - auto begin = format_unsigned(abs_value); - if (negative) *--begin = '-'; - return begin; - } - - public: - FMT_CONSTEXPR20 explicit format_int(int value) : str_(format_signed(value)) {} - FMT_CONSTEXPR20 explicit format_int(long value) - : str_(format_signed(value)) {} - FMT_CONSTEXPR20 explicit format_int(long long value) - : str_(format_signed(value)) {} - FMT_CONSTEXPR20 explicit format_int(unsigned value) - : str_(format_unsigned(value)) {} - FMT_CONSTEXPR20 explicit format_int(unsigned long value) - : str_(format_unsigned(value)) {} - FMT_CONSTEXPR20 explicit format_int(unsigned long long value) - : str_(format_unsigned(value)) {} - - /// Returns the number of characters written to the output buffer. - FMT_CONSTEXPR20 auto size() const -> size_t { - return detail::to_unsigned(buffer_ - str_ + buffer_size - 1); - } - - /// Returns a pointer to the output buffer content. No terminating null - /// character is appended. - FMT_CONSTEXPR20 auto data() const -> const char* { return str_; } - - /// Returns a pointer to the output buffer content with terminating null - /// character appended. - FMT_CONSTEXPR20 auto c_str() const -> const char* { - buffer_[buffer_size - 1] = '\0'; - return str_; - } - - /// Returns the content of the output buffer as an `std::string`. - inline auto str() const -> std::string { return {str_, size()}; } -}; - -#if FMT_CLANG_ANALYZER -# define FMT_STRING_IMPL(s, base) s -#else -# define FMT_STRING_IMPL(s, base) \ - [] { \ - /* Use the hidden visibility as a workaround for a GCC bug (#1973). */ \ - /* Use a macro-like name to avoid shadowing warnings. */ \ - struct FMT_VISIBILITY("hidden") FMT_COMPILE_STRING : base { \ - using char_type = fmt::remove_cvref_t; \ - constexpr explicit operator fmt::basic_string_view() \ - const { \ - return fmt::detail::compile_string_to_view(s); \ - } \ - }; \ - using FMT_STRING_VIEW = \ - fmt::basic_string_view; \ - fmt::detail::ignore_unused(FMT_STRING_VIEW(FMT_COMPILE_STRING())); \ - return FMT_COMPILE_STRING(); \ - }() -#endif // FMT_CLANG_ANALYZER - -/** - * Constructs a legacy compile-time format string from a string literal `s`. - * - * **Example**: - * - * // A compile-time error because 'd' is an invalid specifier for strings. - * std::string s = fmt::format(FMT_STRING("{:d}"), "foo"); - */ -#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string) - -FMT_API auto vsystem_error(int error_code, string_view fmt, format_args args) - -> std::system_error; - -/** - * Constructs `std::system_error` with a message formatted with - * `fmt::format(fmt, args...)`. - * `error_code` is a system error code as given by `errno`. - * - * **Example**: - * - * // This throws std::system_error with the description - * // cannot open file 'madeup': No such file or directory - * // or similar (system message may vary). - * const char* filename = "madeup"; - * FILE* file = fopen(filename, "r"); - * if (!file) - * throw fmt::system_error(errno, "cannot open file '{}'", filename); - */ -template -auto system_error(int error_code, format_string fmt, T&&... args) - -> std::system_error { - return vsystem_error(error_code, fmt.str, vargs{{args...}}); -} - -/** - * Formats an error message for an error returned by an operating system or a - * language runtime, for example a file opening error, and writes it to `out`. - * The format is the same as the one used by `std::system_error(ec, message)` - * where `ec` is `std::error_code(error_code, std::generic_category())`. - * It is implementation-defined but normally looks like: - * - * : - * - * where `` is the passed message and `` is the system - * message corresponding to the error code. - * `error_code` is a system error code as given by `errno`. - */ -FMT_API void format_system_error(detail::buffer& out, int error_code, - const char* message) noexcept; - -// Reports a system error without throwing an exception. -// Can be used to report errors from destructors. -FMT_API void report_system_error(int error_code, const char* message) noexcept; - -inline auto vformat(locale_ref loc, string_view fmt, format_args args) - -> std::string { - auto buf = memory_buffer(); - detail::vformat_to(buf, fmt, args, loc); - return {buf.data(), buf.size()}; -} - -template -FMT_INLINE auto format(locale_ref loc, format_string fmt, T&&... args) - -> std::string { - return vformat(loc, fmt.str, vargs{{args...}}); -} - -template ::value)> -auto vformat_to(OutputIt out, locale_ref loc, string_view fmt, format_args args) - -> OutputIt { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, fmt, args, loc); - return detail::get_iterator(buf, out); -} - -template ::value)> -FMT_INLINE auto format_to(OutputIt out, locale_ref loc, format_string fmt, - T&&... args) -> OutputIt { - return fmt::vformat_to(out, loc, fmt.str, vargs{{args...}}); -} - -template -FMT_NODISCARD FMT_INLINE auto formatted_size(locale_ref loc, - format_string fmt, - T&&... args) -> size_t { - auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, fmt.str, vargs{{args...}}, loc); - return buf.count(); -} - -FMT_API auto vformat(string_view fmt, format_args args) -> std::string; - -/** - * Formats `args` according to specifications in `fmt` and returns the result - * as a string. - * - * **Example**: - * - * #include - * std::string message = fmt::format("The answer is {}.", 42); - */ -template -FMT_NODISCARD FMT_INLINE auto format(format_string fmt, T&&... args) - -> std::string { - return vformat(fmt.str, vargs{{args...}}); -} - -/** - * Converts `value` to `std::string` using the default format for type `T`. - * - * **Example**: - * - * std::string answer = fmt::to_string(42); - */ -template ::value)> -FMT_NODISCARD FMT_CONSTEXPR_STRING auto to_string(T value) -> std::string { - // The buffer should be large enough to store the number including the sign - // or "false" for bool. - char buffer[max_of(detail::digits10() + 2, 5)]; - return {buffer, detail::write(buffer, value)}; -} - -template ::value)> -FMT_NODISCARD FMT_CONSTEXPR_STRING auto to_string(const T& value) - -> std::string { - return to_string(format_as(value)); -} - -template ::value && - !detail::use_format_as::value)> -FMT_NODISCARD FMT_CONSTEXPR_STRING auto to_string(const T& value) - -> std::string { - auto buffer = memory_buffer(); - detail::write(appender(buffer), value); - return {buffer.data(), buffer.size()}; -} - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#ifdef FMT_HEADER_ONLY -# define FMT_FUNC inline -# include "format-inl.h" -#endif - -// Restore _LIBCPP_REMOVE_TRANSITIVE_INCLUDES. -#ifdef FMT_REMOVE_TRANSITIVE_INCLUDES -# undef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES -#endif - -#endif // FMT_FORMAT_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/os.h b/examples/blueprints-example/external/fmt/bundled/os.h deleted file mode 100644 index 40cdcdd..0000000 --- a/examples/blueprints-example/external/fmt/bundled/os.h +++ /dev/null @@ -1,428 +0,0 @@ -// Formatting library for C++ - optional OS-specific functionality -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_OS_H_ -#define FMT_OS_H_ - -#include "format.h" - -#ifndef FMT_MODULE -# include -# include -# include -# include // std::system_error - -# if FMT_HAS_INCLUDE() -# include // LC_NUMERIC_MASK on macOS -# endif -#endif // FMT_MODULE - -#ifndef FMT_USE_FCNTL -// UWP doesn't provide _pipe. -# if FMT_HAS_INCLUDE("winapifamily.h") -# include -# endif -# if (FMT_HAS_INCLUDE() || defined(__APPLE__) || \ - defined(__linux__)) && \ - (!defined(WINAPI_FAMILY) || \ - (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) && \ - !defined(__wasm__) -# include // for O_RDONLY -# define FMT_USE_FCNTL 1 -# else -# define FMT_USE_FCNTL 0 -# endif -#endif - -#ifndef FMT_POSIX -# if defined(_WIN32) && !defined(__MINGW32__) -// Fix warnings about deprecated symbols. -# define FMT_POSIX(call) _##call -# else -# define FMT_POSIX(call) call -# endif -#endif - -// Calls to system functions are wrapped in FMT_SYSTEM for testability. -#ifdef FMT_SYSTEM -# define FMT_HAS_SYSTEM -# define FMT_POSIX_CALL(call) FMT_SYSTEM(call) -#else -# define FMT_SYSTEM(call) ::call -# ifdef _WIN32 -// Fix warnings about deprecated symbols. -# define FMT_POSIX_CALL(call) ::_##call -# else -# define FMT_POSIX_CALL(call) ::call -# endif -#endif - -// Retries the expression while it evaluates to error_result and errno -// equals to EINTR. -#ifndef _WIN32 -# define FMT_RETRY_VAL(result, expression, error_result) \ - do { \ - (result) = (expression); \ - } while ((result) == (error_result) && errno == EINTR) -#else -# define FMT_RETRY_VAL(result, expression, error_result) result = (expression) -#endif - -#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1) - -FMT_BEGIN_NAMESPACE -FMT_BEGIN_EXPORT - -/** - * A reference to a null-terminated string. It can be constructed from a C - * string or `std::string`. - * - * You can use one of the following type aliases for common character types: - * - * +---------------+-----------------------------+ - * | Type | Definition | - * +===============+=============================+ - * | cstring_view | basic_cstring_view | - * +---------------+-----------------------------+ - * | wcstring_view | basic_cstring_view | - * +---------------+-----------------------------+ - * - * This class is most useful as a parameter type for functions that wrap C APIs. - */ -template class basic_cstring_view { - private: - const Char* data_; - - public: - /// Constructs a string reference object from a C string. - basic_cstring_view(const Char* s) : data_(s) {} - - /// Constructs a string reference from an `std::string` object. - basic_cstring_view(const std::basic_string& s) : data_(s.c_str()) {} - - /// Returns the pointer to a C string. - auto c_str() const -> const Char* { return data_; } -}; - -using cstring_view = basic_cstring_view; -using wcstring_view = basic_cstring_view; - -#ifdef _WIN32 -FMT_API const std::error_category& system_category() noexcept; - -namespace detail { -FMT_API void format_windows_error(buffer& out, int error_code, - const char* message) noexcept; -} - -FMT_API std::system_error vwindows_error(int error_code, string_view fmt, - format_args args); - -/** - * Constructs a `std::system_error` object with the description of the form - * - * : - * - * where `` is the formatted message and `` is the - * system message corresponding to the error code. - * `error_code` is a Windows error code as given by `GetLastError`. - * If `error_code` is not a valid error code such as -1, the system message - * will look like "error -1". - * - * **Example**: - * - * // This throws a system_error with the description - * // cannot open file 'madeup': The system cannot find the file - * specified. - * // or similar (system message may vary). - * const char *filename = "madeup"; - * LPOFSTRUCT of = LPOFSTRUCT(); - * HFILE file = OpenFile(filename, &of, OF_READ); - * if (file == HFILE_ERROR) { - * throw fmt::windows_error(GetLastError(), - * "cannot open file '{}'", filename); - * } - */ -template -auto windows_error(int error_code, string_view message, const T&... args) - -> std::system_error { - return vwindows_error(error_code, message, vargs{{args...}}); -} - -// Reports a Windows error without throwing an exception. -// Can be used to report errors from destructors. -FMT_API void report_windows_error(int error_code, const char* message) noexcept; -#else -inline auto system_category() noexcept -> const std::error_category& { - return std::system_category(); -} -#endif // _WIN32 - -// std::system is not available on some platforms such as iOS (#2248). -#ifdef __OSX__ -template > -void say(const S& fmt, Args&&... args) { - std::system(format("say \"{}\"", format(fmt, args...)).c_str()); -} -#endif - -// A buffered file. -class buffered_file { - private: - FILE* file_; - - friend class file; - - inline explicit buffered_file(FILE* f) : file_(f) {} - - public: - buffered_file(const buffered_file&) = delete; - void operator=(const buffered_file&) = delete; - - // Constructs a buffered_file object which doesn't represent any file. - inline buffered_file() noexcept : file_(nullptr) {} - - // Destroys the object closing the file it represents if any. - FMT_API ~buffered_file() noexcept; - - public: - inline buffered_file(buffered_file&& other) noexcept : file_(other.file_) { - other.file_ = nullptr; - } - - inline auto operator=(buffered_file&& other) -> buffered_file& { - close(); - file_ = other.file_; - other.file_ = nullptr; - return *this; - } - - // Opens a file. - FMT_API buffered_file(cstring_view filename, cstring_view mode); - - // Closes the file. - FMT_API void close(); - - // Returns the pointer to a FILE object representing this file. - inline auto get() const noexcept -> FILE* { return file_; } - - FMT_API auto descriptor() const -> int; - - template - inline void print(string_view fmt, const T&... args) { - fmt::vargs vargs = {{args...}}; - detail::is_locking() ? fmt::vprint_buffered(file_, fmt, vargs) - : fmt::vprint(file_, fmt, vargs); - } -}; - -#if FMT_USE_FCNTL - -// A file. Closed file is represented by a file object with descriptor -1. -// Methods that are not declared with noexcept may throw -// fmt::system_error in case of failure. Note that some errors such as -// closing the file multiple times will cause a crash on Windows rather -// than an exception. You can get standard behavior by overriding the -// invalid parameter handler with _set_invalid_parameter_handler. -class FMT_API file { - private: - int fd_; // File descriptor. - - // Constructs a file object with a given descriptor. - explicit file(int fd) : fd_(fd) {} - - friend struct pipe; - - public: - // Possible values for the oflag argument to the constructor. - enum { - RDONLY = FMT_POSIX(O_RDONLY), // Open for reading only. - WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only. - RDWR = FMT_POSIX(O_RDWR), // Open for reading and writing. - CREATE = FMT_POSIX(O_CREAT), // Create if the file doesn't exist. - APPEND = FMT_POSIX(O_APPEND), // Open in append mode. - TRUNC = FMT_POSIX(O_TRUNC) // Truncate the content of the file. - }; - - // Constructs a file object which doesn't represent any file. - inline file() noexcept : fd_(-1) {} - - // Opens a file and constructs a file object representing this file. - file(cstring_view path, int oflag); - - public: - file(const file&) = delete; - void operator=(const file&) = delete; - - inline file(file&& other) noexcept : fd_(other.fd_) { other.fd_ = -1; } - - // Move assignment is not noexcept because close may throw. - inline auto operator=(file&& other) -> file& { - close(); - fd_ = other.fd_; - other.fd_ = -1; - return *this; - } - - // Destroys the object closing the file it represents if any. - ~file() noexcept; - - // Returns the file descriptor. - inline auto descriptor() const noexcept -> int { return fd_; } - - // Closes the file. - void close(); - - // Returns the file size. The size has signed type for consistency with - // stat::st_size. - auto size() const -> long long; - - // Attempts to read count bytes from the file into the specified buffer. - auto read(void* buffer, size_t count) -> size_t; - - // Attempts to write count bytes from the specified buffer to the file. - auto write(const void* buffer, size_t count) -> size_t; - - // Duplicates a file descriptor with the dup function and returns - // the duplicate as a file object. - static auto dup(int fd) -> file; - - // Makes fd be the copy of this file descriptor, closing fd first if - // necessary. - void dup2(int fd); - - // Makes fd be the copy of this file descriptor, closing fd first if - // necessary. - void dup2(int fd, std::error_code& ec) noexcept; - - // Creates a buffered_file object associated with this file and detaches - // this file object from the file. - auto fdopen(const char* mode) -> buffered_file; - -# if defined(_WIN32) && !defined(__MINGW32__) - // Opens a file and constructs a file object representing this file by - // wcstring_view filename. Windows only. - static file open_windows_file(wcstring_view path, int oflag); -# endif -}; - -struct FMT_API pipe { - file read_end; - file write_end; - - // Creates a pipe setting up read_end and write_end file objects for reading - // and writing respectively. - pipe(); -}; - -// Returns the memory page size. -auto getpagesize() -> long; - -namespace detail { - -struct buffer_size { - constexpr buffer_size() = default; - size_t value = 0; - FMT_CONSTEXPR auto operator=(size_t val) const -> buffer_size { - auto bs = buffer_size(); - bs.value = val; - return bs; - } -}; - -struct ostream_params { - int oflag = file::WRONLY | file::CREATE | file::TRUNC; - size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768; - - constexpr ostream_params() {} - - template - ostream_params(T... params, int new_oflag) : ostream_params(params...) { - oflag = new_oflag; - } - - template - ostream_params(T... params, detail::buffer_size bs) - : ostream_params(params...) { - this->buffer_size = bs.value; - } - -// Intel has a bug that results in failure to deduce a constructor -// for empty parameter packs. -# if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000 - ostream_params(int new_oflag) : oflag(new_oflag) {} - ostream_params(detail::buffer_size bs) : buffer_size(bs.value) {} -# endif -}; - -} // namespace detail - -FMT_INLINE_VARIABLE constexpr auto buffer_size = detail::buffer_size(); - -/// A fast buffered output stream for writing from a single thread. Writing from -/// multiple threads without external synchronization may result in a data race. -class FMT_API ostream : private detail::buffer { - private: - file file_; - - ostream(cstring_view path, const detail::ostream_params& params); - - static void grow(buffer& buf, size_t); - - public: - ostream(ostream&& other) noexcept; - ~ostream(); - - operator writer() { - detail::buffer& buf = *this; - return buf; - } - - inline void flush() { - if (size() == 0) return; - file_.write(data(), size() * sizeof(data()[0])); - clear(); - } - - template - friend auto output_file(cstring_view path, T... params) -> ostream; - - inline void close() { - flush(); - file_.close(); - } - - /// Formats `args` according to specifications in `fmt` and writes the - /// output to the file. - template void print(format_string fmt, T&&... args) { - vformat_to(appender(*this), fmt.str, vargs{{args...}}); - } -}; - -/** - * Opens a file for writing. Supported parameters passed in `params`: - * - * - ``: Flags passed to [open]( - * https://pubs.opengroup.org/onlinepubs/007904875/functions/open.html) - * (`file::WRONLY | file::CREATE | file::TRUNC` by default) - * - `buffer_size=`: Output buffer size - * - * **Example**: - * - * auto out = fmt::output_file("guide.txt"); - * out.print("Don't {}", "Panic"); - */ -template -inline auto output_file(cstring_view path, T... params) -> ostream { - return {path, detail::ostream_params(params...)}; -} -#endif // FMT_USE_FCNTL - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_OS_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/ostream.h b/examples/blueprints-example/external/fmt/bundled/ostream.h deleted file mode 100644 index bf2371b..0000000 --- a/examples/blueprints-example/external/fmt/bundled/ostream.h +++ /dev/null @@ -1,167 +0,0 @@ -// Formatting library for C++ - std::ostream support -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_OSTREAM_H_ -#define FMT_OSTREAM_H_ - -#ifndef FMT_MODULE -# include // std::filebuf -#endif - -#ifdef _WIN32 -# ifdef __GLIBCXX__ -# include -# include -# endif -# include -#endif - -#include "chrono.h" // formatbuf - -#ifdef _MSVC_STL_UPDATE -# define FMT_MSVC_STL_UPDATE _MSVC_STL_UPDATE -#elif defined(_MSC_VER) && _MSC_VER < 1912 // VS 15.5 -# define FMT_MSVC_STL_UPDATE _MSVC_LANG -#else -# define FMT_MSVC_STL_UPDATE 0 -#endif - -FMT_BEGIN_NAMESPACE -namespace detail { - -// Generate a unique explicit instantiation in every translation unit using a -// tag type in an anonymous namespace. -namespace { -struct file_access_tag {}; -} // namespace -template -class file_access { - friend auto get_file(BufType& obj) -> FILE* { return obj.*FileMemberPtr; } -}; - -#if FMT_MSVC_STL_UPDATE -template class file_access; -auto get_file(std::filebuf&) -> FILE*; -#endif - -// Write the content of buf to os. -// It is a separate function rather than a part of vprint to simplify testing. -template -void write_buffer(std::basic_ostream& os, buffer& buf) { - const Char* buf_data = buf.data(); - using unsigned_streamsize = make_unsigned_t; - unsigned_streamsize size = buf.size(); - unsigned_streamsize max_size = to_unsigned(max_value()); - do { - unsigned_streamsize n = size <= max_size ? size : max_size; - os.write(buf_data, static_cast(n)); - buf_data += n; - size -= n; - } while (size != 0); -} - -template struct streamed_view { - const T& value; -}; -} // namespace detail - -// Formats an object of type T that has an overloaded ostream operator<<. -template -struct basic_ostream_formatter : formatter, Char> { - void set_debug_format() = delete; - - template - auto format(const T& value, Context& ctx) const -> decltype(ctx.out()) { - auto buffer = basic_memory_buffer(); - auto&& formatbuf = detail::formatbuf>(buffer); - auto&& output = std::basic_ostream(&formatbuf); - output.imbue(std::locale::classic()); // The default is always unlocalized. - output << value; - output.exceptions(std::ios_base::failbit | std::ios_base::badbit); - return formatter, Char>::format( - {buffer.data(), buffer.size()}, ctx); - } -}; - -using ostream_formatter = basic_ostream_formatter; - -template -struct formatter, Char> - : basic_ostream_formatter { - template - auto format(detail::streamed_view view, Context& ctx) const - -> decltype(ctx.out()) { - return basic_ostream_formatter::format(view.value, ctx); - } -}; - -/** - * Returns a view that formats `value` via an ostream `operator<<`. - * - * **Example**: - * - * fmt::print("Current thread id: {}\n", - * fmt::streamed(std::this_thread::get_id())); - */ -template -constexpr auto streamed(const T& value) -> detail::streamed_view { - return {value}; -} - -inline void vprint(std::ostream& os, string_view fmt, format_args args) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - FILE* f = nullptr; -#if FMT_MSVC_STL_UPDATE && FMT_USE_RTTI - if (auto* buf = dynamic_cast(os.rdbuf())) - f = detail::get_file(*buf); -#elif defined(_WIN32) && defined(__GLIBCXX__) && FMT_USE_RTTI - auto* rdbuf = os.rdbuf(); - if (auto* sfbuf = dynamic_cast<__gnu_cxx::stdio_sync_filebuf*>(rdbuf)) - f = sfbuf->file(); - else if (auto* fbuf = dynamic_cast<__gnu_cxx::stdio_filebuf*>(rdbuf)) - f = fbuf->file(); -#endif -#ifdef _WIN32 - if (f) { - int fd = _fileno(f); - if (_isatty(fd)) { - os.flush(); - if (detail::write_console(fd, {buffer.data(), buffer.size()})) return; - } - } -#endif - detail::ignore_unused(f); - detail::write_buffer(os, buffer); -} - -/** - * Prints formatted data to the stream `os`. - * - * **Example**: - * - * fmt::print(cerr, "Don't {}!", "panic"); - */ -FMT_EXPORT template -void print(std::ostream& os, format_string fmt, T&&... args) { - fmt::vargs vargs = {{args...}}; - if (detail::const_check(detail::use_utf8)) return vprint(os, fmt.str, vargs); - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt.str, vargs); - detail::write_buffer(os, buffer); -} - -FMT_EXPORT template -void println(std::ostream& os, format_string fmt, T&&... args) { - fmt::print(os, FMT_STRING("{}\n"), - fmt::format(fmt, std::forward(args)...)); -} - -FMT_END_NAMESPACE - -#endif // FMT_OSTREAM_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/printf.h b/examples/blueprints-example/external/fmt/bundled/printf.h deleted file mode 100644 index cc066d8..0000000 --- a/examples/blueprints-example/external/fmt/bundled/printf.h +++ /dev/null @@ -1,624 +0,0 @@ -// Formatting library for C++ - legacy printf implementation -// -// Copyright (c) 2012 - 2016, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_PRINTF_H_ -#define FMT_PRINTF_H_ - -#ifndef FMT_MODULE -# include // std::find -# include // std::numeric_limits -#endif - -#include "format.h" - -FMT_BEGIN_NAMESPACE -FMT_BEGIN_EXPORT - -template class basic_printf_context { - private: - basic_appender out_; - basic_format_args args_; - - static_assert(std::is_same::value || - std::is_same::value, - "Unsupported code unit type."); - - public: - using char_type = Char; - enum { builtin_types = 1 }; - - /// Constructs a `printf_context` object. References to the arguments are - /// stored in the context object so make sure they have appropriate lifetimes. - basic_printf_context(basic_appender out, - basic_format_args args) - : out_(out), args_(args) {} - - auto out() -> basic_appender { return out_; } - void advance_to(basic_appender) {} - - auto locale() -> locale_ref { return {}; } - - auto arg(int id) const -> basic_format_arg { - return args_.get(id); - } -}; - -namespace detail { - -// Return the result via the out param to workaround gcc bug 77539. -template -FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr& out) -> bool { - for (out = first; out != last; ++out) { - if (*out == value) return true; - } - return false; -} - -template <> -inline auto find(const char* first, const char* last, char value, - const char*& out) -> bool { - out = - static_cast(memchr(first, value, to_unsigned(last - first))); - return out != nullptr; -} - -// Checks if a value fits in int - used to avoid warnings about comparing -// signed and unsigned integers. -template struct int_checker { - template static auto fits_in_int(T value) -> bool { - return value <= to_unsigned(max_value()); - } - inline static auto fits_in_int(bool) -> bool { return true; } -}; - -template <> struct int_checker { - template static auto fits_in_int(T value) -> bool { - return value >= (std::numeric_limits::min)() && - value <= max_value(); - } - inline static auto fits_in_int(int) -> bool { return true; } -}; - -struct printf_precision_handler { - template ::value)> - auto operator()(T value) -> int { - if (!int_checker::is_signed>::fits_in_int(value)) - report_error("number is too big"); - return max_of(static_cast(value), 0); - } - - template ::value)> - auto operator()(T) -> int { - report_error("precision is not integer"); - return 0; - } -}; - -// An argument visitor that returns true iff arg is a zero integer. -struct is_zero_int { - template ::value)> - auto operator()(T value) -> bool { - return value == 0; - } - - template ::value)> - auto operator()(T) -> bool { - return false; - } -}; - -template struct make_unsigned_or_bool : std::make_unsigned {}; - -template <> struct make_unsigned_or_bool { - using type = bool; -}; - -template class arg_converter { - private: - using char_type = typename Context::char_type; - - basic_format_arg& arg_; - char_type type_; - - public: - arg_converter(basic_format_arg& arg, char_type type) - : arg_(arg), type_(type) {} - - void operator()(bool value) { - if (type_ != 's') operator()(value); - } - - template ::value)> - void operator()(U value) { - bool is_signed = type_ == 'd' || type_ == 'i'; - using target_type = conditional_t::value, U, T>; - if (const_check(sizeof(target_type) <= sizeof(int))) { - // Extra casts are used to silence warnings. - using unsigned_type = typename make_unsigned_or_bool::type; - if (is_signed) - arg_ = static_cast(static_cast(value)); - else - arg_ = static_cast(static_cast(value)); - } else { - // glibc's printf doesn't sign extend arguments of smaller types: - // std::printf("%lld", -42); // prints "4294967254" - // but we don't have to do the same because it's a UB. - if (is_signed) - arg_ = static_cast(value); - else - arg_ = static_cast::type>(value); - } - } - - template ::value)> - void operator()(U) {} // No conversion needed for non-integral types. -}; - -// Converts an integer argument to T for printf, if T is an integral type. -// If T is void, the argument is converted to corresponding signed or unsigned -// type depending on the type specifier: 'd' and 'i' - signed, other - -// unsigned). -template -void convert_arg(basic_format_arg& arg, Char type) { - arg.visit(arg_converter(arg, type)); -} - -// Converts an integer argument to char for printf. -template class char_converter { - private: - basic_format_arg& arg_; - - public: - explicit char_converter(basic_format_arg& arg) : arg_(arg) {} - - template ::value)> - void operator()(T value) { - arg_ = static_cast(value); - } - - template ::value)> - void operator()(T) {} // No conversion needed for non-integral types. -}; - -// An argument visitor that return a pointer to a C string if argument is a -// string or null otherwise. -template struct get_cstring { - template auto operator()(T) -> const Char* { return nullptr; } - auto operator()(const Char* s) -> const Char* { return s; } -}; - -// Checks if an argument is a valid printf width specifier and sets -// left alignment if it is negative. -class printf_width_handler { - private: - format_specs& specs_; - - public: - inline explicit printf_width_handler(format_specs& specs) : specs_(specs) {} - - template ::value)> - auto operator()(T value) -> unsigned { - auto width = static_cast>(value); - if (detail::is_negative(value)) { - specs_.set_align(align::left); - width = 0 - width; - } - unsigned int_max = to_unsigned(max_value()); - if (width > int_max) report_error("number is too big"); - return static_cast(width); - } - - template ::value)> - auto operator()(T) -> unsigned { - report_error("width is not integer"); - return 0; - } -}; - -// Workaround for a bug with the XL compiler when initializing -// printf_arg_formatter's base class. -template -auto make_arg_formatter(basic_appender iter, format_specs& s) - -> arg_formatter { - return {iter, s, locale_ref()}; -} - -// The `printf` argument formatter. -template -class printf_arg_formatter : public arg_formatter { - private: - using base = arg_formatter; - using context_type = basic_printf_context; - - context_type& context_; - - void write_null_pointer(bool is_string = false) { - auto s = this->specs; - s.set_type(presentation_type::none); - write_bytes(this->out, is_string ? "(null)" : "(nil)", s); - } - - template void write(T value) { - detail::write(this->out, value, this->specs, this->locale); - } - - public: - printf_arg_formatter(basic_appender iter, format_specs& s, - context_type& ctx) - : base(make_arg_formatter(iter, s)), context_(ctx) {} - - void operator()(monostate value) { write(value); } - - template ::value)> - void operator()(T value) { - // MSVC2013 fails to compile separate overloads for bool and Char so use - // std::is_same instead. - if (!std::is_same::value) { - write(value); - return; - } - format_specs s = this->specs; - if (s.type() != presentation_type::none && - s.type() != presentation_type::chr) { - return (*this)(static_cast(value)); - } - s.set_sign(sign::none); - s.clear_alt(); - s.set_fill(' '); // Ignore '0' flag for char types. - // align::numeric needs to be overwritten here since the '0' flag is - // ignored for non-numeric types - if (s.align() == align::none || s.align() == align::numeric) - s.set_align(align::right); - detail::write(this->out, static_cast(value), s); - } - - template ::value)> - void operator()(T value) { - write(value); - } - - void operator()(const char* value) { - if (value) - write(value); - else - write_null_pointer(this->specs.type() != presentation_type::pointer); - } - - void operator()(const wchar_t* value) { - if (value) - write(value); - else - write_null_pointer(this->specs.type() != presentation_type::pointer); - } - - void operator()(basic_string_view value) { write(value); } - - void operator()(const void* value) { - if (value) - write(value); - else - write_null_pointer(); - } - - void operator()(typename basic_format_arg::handle handle) { - auto parse_ctx = parse_context({}); - handle.format(parse_ctx, context_); - } -}; - -template -void parse_flags(format_specs& specs, const Char*& it, const Char* end) { - for (; it != end; ++it) { - switch (*it) { - case '-': specs.set_align(align::left); break; - case '+': specs.set_sign(sign::plus); break; - case '0': specs.set_fill('0'); break; - case ' ': - if (specs.sign() != sign::plus) specs.set_sign(sign::space); - break; - case '#': specs.set_alt(); break; - default: return; - } - } -} - -template -auto parse_header(const Char*& it, const Char* end, format_specs& specs, - GetArg get_arg) -> int { - int arg_index = -1; - Char c = *it; - if (c >= '0' && c <= '9') { - // Parse an argument index (if followed by '$') or a width possibly - // preceded with '0' flag(s). - int value = parse_nonnegative_int(it, end, -1); - if (it != end && *it == '$') { // value is an argument index - ++it; - arg_index = value != -1 ? value : max_value(); - } else { - if (c == '0') specs.set_fill('0'); - if (value != 0) { - // Nonzero value means that we parsed width and don't need to - // parse it or flags again, so return now. - if (value == -1) report_error("number is too big"); - specs.width = value; - return arg_index; - } - } - } - parse_flags(specs, it, end); - // Parse width. - if (it != end) { - if (*it >= '0' && *it <= '9') { - specs.width = parse_nonnegative_int(it, end, -1); - if (specs.width == -1) report_error("number is too big"); - } else if (*it == '*') { - ++it; - specs.width = static_cast( - get_arg(-1).visit(detail::printf_width_handler(specs))); - } - } - return arg_index; -} - -inline auto parse_printf_presentation_type(char c, type t, bool& upper) - -> presentation_type { - using pt = presentation_type; - constexpr auto integral_set = sint_set | uint_set | bool_set | char_set; - switch (c) { - case 'd': return in(t, integral_set) ? pt::dec : pt::none; - case 'o': return in(t, integral_set) ? pt::oct : pt::none; - case 'X': upper = true; FMT_FALLTHROUGH; - case 'x': return in(t, integral_set) ? pt::hex : pt::none; - case 'E': upper = true; FMT_FALLTHROUGH; - case 'e': return in(t, float_set) ? pt::exp : pt::none; - case 'F': upper = true; FMT_FALLTHROUGH; - case 'f': return in(t, float_set) ? pt::fixed : pt::none; - case 'G': upper = true; FMT_FALLTHROUGH; - case 'g': return in(t, float_set) ? pt::general : pt::none; - case 'A': upper = true; FMT_FALLTHROUGH; - case 'a': return in(t, float_set) ? pt::hexfloat : pt::none; - case 'c': return in(t, integral_set) ? pt::chr : pt::none; - case 's': return in(t, string_set | cstring_set) ? pt::string : pt::none; - case 'p': return in(t, pointer_set | cstring_set) ? pt::pointer : pt::none; - default: return pt::none; - } -} - -template -void vprintf(buffer& buf, basic_string_view format, - basic_format_args args) { - using iterator = basic_appender; - auto out = iterator(buf); - auto context = basic_printf_context(out, args); - auto parse_ctx = parse_context(format); - - // Returns the argument with specified index or, if arg_index is -1, the next - // argument. - auto get_arg = [&](int arg_index) { - if (arg_index < 0) - arg_index = parse_ctx.next_arg_id(); - else - parse_ctx.check_arg_id(--arg_index); - auto arg = context.arg(arg_index); - if (!arg) report_error("argument not found"); - return arg; - }; - - const Char* start = parse_ctx.begin(); - const Char* end = parse_ctx.end(); - auto it = start; - while (it != end) { - if (!find(it, end, '%', it)) { - it = end; // find leaves it == nullptr if it doesn't find '%'. - break; - } - Char c = *it++; - if (it != end && *it == c) { - write(out, basic_string_view(start, to_unsigned(it - start))); - start = ++it; - continue; - } - write(out, basic_string_view(start, to_unsigned(it - 1 - start))); - - auto specs = format_specs(); - specs.set_align(align::right); - - // Parse argument index, flags and width. - int arg_index = parse_header(it, end, specs, get_arg); - if (arg_index == 0) report_error("argument not found"); - - // Parse precision. - if (it != end && *it == '.') { - ++it; - c = it != end ? *it : 0; - if ('0' <= c && c <= '9') { - specs.precision = parse_nonnegative_int(it, end, 0); - } else if (c == '*') { - ++it; - specs.precision = - static_cast(get_arg(-1).visit(printf_precision_handler())); - } else { - specs.precision = 0; - } - } - - auto arg = get_arg(arg_index); - // For d, i, o, u, x, and X conversion specifiers, if a precision is - // specified, the '0' flag is ignored - if (specs.precision >= 0 && is_integral_type(arg.type())) { - // Ignore '0' for non-numeric types or if '-' present. - specs.set_fill(' '); - } - if (specs.precision >= 0 && arg.type() == type::cstring_type) { - auto str = arg.visit(get_cstring()); - auto str_end = str + specs.precision; - auto nul = std::find(str, str_end, Char()); - auto sv = basic_string_view( - str, to_unsigned(nul != str_end ? nul - str : specs.precision)); - arg = sv; - } - if (specs.alt() && arg.visit(is_zero_int())) specs.clear_alt(); - if (specs.fill_unit() == '0') { - if (is_arithmetic_type(arg.type()) && specs.align() != align::left) { - specs.set_align(align::numeric); - } else { - // Ignore '0' flag for non-numeric types or if '-' flag is also present. - specs.set_fill(' '); - } - } - - // Parse length and convert the argument to the required type. - c = it != end ? *it++ : 0; - Char t = it != end ? *it : 0; - switch (c) { - case 'h': - if (t == 'h') { - ++it; - t = it != end ? *it : 0; - convert_arg(arg, t); - } else { - convert_arg(arg, t); - } - break; - case 'l': - if (t == 'l') { - ++it; - t = it != end ? *it : 0; - convert_arg(arg, t); - } else { - convert_arg(arg, t); - } - break; - case 'j': convert_arg(arg, t); break; - case 'z': convert_arg(arg, t); break; - case 't': convert_arg(arg, t); break; - case 'L': - // printf produces garbage when 'L' is omitted for long double, no - // need to do the same. - break; - default: --it; convert_arg(arg, c); - } - - // Parse type. - if (it == end) report_error("invalid format string"); - char type = static_cast(*it++); - if (is_integral_type(arg.type())) { - // Normalize type. - switch (type) { - case 'i': - case 'u': type = 'd'; break; - case 'c': - arg.visit(char_converter>(arg)); - break; - } - } - bool upper = false; - specs.set_type(parse_printf_presentation_type(type, arg.type(), upper)); - if (specs.type() == presentation_type::none) - report_error("invalid format specifier"); - if (upper) specs.set_upper(); - - start = it; - - // Format argument. - arg.visit(printf_arg_formatter(out, specs, context)); - } - write(out, basic_string_view(start, to_unsigned(it - start))); -} -} // namespace detail - -using printf_context = basic_printf_context; -using wprintf_context = basic_printf_context; - -using printf_args = basic_format_args; -using wprintf_args = basic_format_args; - -/// Constructs an `format_arg_store` object that contains references to -/// arguments and can be implicitly converted to `printf_args`. -template -inline auto make_printf_args(T&... args) - -> decltype(fmt::make_format_args>(args...)) { - return fmt::make_format_args>(args...); -} - -template struct vprintf_args { - using type = basic_format_args>; -}; - -template -inline auto vsprintf(basic_string_view fmt, - typename vprintf_args::type args) - -> std::basic_string { - auto buf = basic_memory_buffer(); - detail::vprintf(buf, fmt, args); - return {buf.data(), buf.size()}; -} - -/** - * Formats `args` according to specifications in `fmt` and returns the result - * as as string. - * - * **Example**: - * - * std::string message = fmt::sprintf("The answer is %d", 42); - */ -template -inline auto sprintf(string_view fmt, const T&... args) -> std::string { - return vsprintf(fmt, make_printf_args(args...)); -} -template -FMT_DEPRECATED auto sprintf(basic_string_view fmt, const T&... args) - -> std::wstring { - return vsprintf(fmt, make_printf_args(args...)); -} - -template -auto vfprintf(std::FILE* f, basic_string_view fmt, - typename vprintf_args::type args) -> int { - auto buf = basic_memory_buffer(); - detail::vprintf(buf, fmt, args); - size_t size = buf.size(); - return std::fwrite(buf.data(), sizeof(Char), size, f) < size - ? -1 - : static_cast(size); -} - -/** - * Formats `args` according to specifications in `fmt` and writes the output - * to `f`. - * - * **Example**: - * - * fmt::fprintf(stderr, "Don't %s!", "panic"); - */ -template -inline auto fprintf(std::FILE* f, string_view fmt, const T&... args) -> int { - return vfprintf(f, fmt, make_printf_args(args...)); -} -template -FMT_DEPRECATED auto fprintf(std::FILE* f, basic_string_view fmt, - const T&... args) -> int { - return vfprintf(f, fmt, make_printf_args(args...)); -} - -/** - * Formats `args` according to specifications in `fmt` and writes the output - * to `stdout`. - * - * **Example**: - * - * fmt::printf("Elapsed time: %.2f seconds", 1.23); - */ -template -inline auto printf(string_view fmt, const T&... args) -> int { - return vfprintf(stdout, fmt, make_printf_args(args...)); -} - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_PRINTF_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/ranges.h b/examples/blueprints-example/external/fmt/bundled/ranges.h deleted file mode 100644 index 24c61e9..0000000 --- a/examples/blueprints-example/external/fmt/bundled/ranges.h +++ /dev/null @@ -1,852 +0,0 @@ -// Formatting library for C++ - range and tuple support -// -// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_RANGES_H_ -#define FMT_RANGES_H_ - -#ifndef FMT_MODULE -# include -# include -# include -# include -# include -#endif - -#include "format.h" - -FMT_BEGIN_NAMESPACE - -FMT_EXPORT -enum class range_format { disabled, map, set, sequence, string, debug_string }; - -namespace detail { - -template class is_map { - template static auto check(U*) -> typename U::mapped_type; - template static void check(...); - - public: - static constexpr bool value = - !std::is_void(nullptr))>::value; -}; - -template class is_set { - template static auto check(U*) -> typename U::key_type; - template static void check(...); - - public: - static constexpr bool value = - !std::is_void(nullptr))>::value && !is_map::value; -}; - -// C array overload -template -auto range_begin(const T (&arr)[N]) -> const T* { - return arr; -} -template auto range_end(const T (&arr)[N]) -> const T* { - return arr + N; -} - -template -struct has_member_fn_begin_end_t : std::false_type {}; - -template -struct has_member_fn_begin_end_t().begin()), - decltype(std::declval().end())>> - : std::true_type {}; - -// Member function overloads. -template -auto range_begin(T&& rng) -> decltype(static_cast(rng).begin()) { - return static_cast(rng).begin(); -} -template -auto range_end(T&& rng) -> decltype(static_cast(rng).end()) { - return static_cast(rng).end(); -} - -// ADL overloads. Only participate in overload resolution if member functions -// are not found. -template -auto range_begin(T&& rng) - -> enable_if_t::value, - decltype(begin(static_cast(rng)))> { - return begin(static_cast(rng)); -} -template -auto range_end(T&& rng) -> enable_if_t::value, - decltype(end(static_cast(rng)))> { - return end(static_cast(rng)); -} - -template -struct has_const_begin_end : std::false_type {}; -template -struct has_mutable_begin_end : std::false_type {}; - -template -struct has_const_begin_end< - T, void_t&>())), - decltype(detail::range_end( - std::declval&>()))>> - : std::true_type {}; - -template -struct has_mutable_begin_end< - T, void_t())), - decltype(detail::range_end(std::declval())), - // the extra int here is because older versions of MSVC don't - // SFINAE properly unless there are distinct types - int>> : std::true_type {}; - -template struct is_range_ : std::false_type {}; -template -struct is_range_ - : std::integral_constant::value || - has_mutable_begin_end::value)> {}; - -// tuple_size and tuple_element check. -template class is_tuple_like_ { - template ::type> - static auto check(U* p) -> decltype(std::tuple_size::value, 0); - template static void check(...); - - public: - static constexpr bool value = - !std::is_void(nullptr))>::value; -}; - -// Check for integer_sequence -#if defined(__cpp_lib_integer_sequence) || FMT_MSC_VERSION >= 1900 -template -using integer_sequence = std::integer_sequence; -template using index_sequence = std::index_sequence; -template using make_index_sequence = std::make_index_sequence; -#else -template struct integer_sequence { - using value_type = T; - - static FMT_CONSTEXPR auto size() -> size_t { return sizeof...(N); } -}; - -template using index_sequence = integer_sequence; - -template -struct make_integer_sequence : make_integer_sequence {}; -template -struct make_integer_sequence : integer_sequence {}; - -template -using make_index_sequence = make_integer_sequence; -#endif - -template -using tuple_index_sequence = make_index_sequence::value>; - -template ::value> -class is_tuple_formattable_ { - public: - static constexpr bool value = false; -}; -template class is_tuple_formattable_ { - template - static auto all_true(index_sequence, - integer_sequence= 0)...>) -> std::true_type; - static auto all_true(...) -> std::false_type; - - template - static auto check(index_sequence) -> decltype(all_true( - index_sequence{}, - integer_sequence::type, - C>::value)...>{})); - - public: - static constexpr bool value = - decltype(check(tuple_index_sequence{}))::value; -}; - -template -FMT_CONSTEXPR void for_each(index_sequence, Tuple&& t, F&& f) { - using std::get; - // Using a free function get(Tuple) now. - const int unused[] = {0, ((void)f(get(t)), 0)...}; - ignore_unused(unused); -} - -template -FMT_CONSTEXPR void for_each(Tuple&& t, F&& f) { - for_each(tuple_index_sequence>(), - std::forward(t), std::forward(f)); -} - -template -void for_each2(index_sequence, Tuple1&& t1, Tuple2&& t2, F&& f) { - using std::get; - const int unused[] = {0, ((void)f(get(t1), get(t2)), 0)...}; - ignore_unused(unused); -} - -template -void for_each2(Tuple1&& t1, Tuple2&& t2, F&& f) { - for_each2(tuple_index_sequence>(), - std::forward(t1), std::forward(t2), - std::forward(f)); -} - -namespace tuple { -// Workaround a bug in MSVC 2019 (v140). -template -using result_t = std::tuple, Char>...>; - -using std::get; -template -auto get_formatters(index_sequence) - -> result_t(std::declval()))...>; -} // namespace tuple - -#if FMT_MSC_VERSION && FMT_MSC_VERSION < 1920 -// Older MSVC doesn't get the reference type correctly for arrays. -template struct range_reference_type_impl { - using type = decltype(*detail::range_begin(std::declval())); -}; - -template struct range_reference_type_impl { - using type = T&; -}; - -template -using range_reference_type = typename range_reference_type_impl::type; -#else -template -using range_reference_type = - decltype(*detail::range_begin(std::declval())); -#endif - -// We don't use the Range's value_type for anything, but we do need the Range's -// reference type, with cv-ref stripped. -template -using uncvref_type = remove_cvref_t>; - -template -FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set) - -> decltype(f.set_debug_format(set)) { - f.set_debug_format(set); -} -template -FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {} - -template -struct range_format_kind_ - : std::integral_constant, T>::value - ? range_format::disabled - : is_map::value ? range_format::map - : is_set::value ? range_format::set - : range_format::sequence> {}; - -template -using range_format_constant = std::integral_constant; - -// These are not generic lambdas for compatibility with C++11. -template struct parse_empty_specs { - template FMT_CONSTEXPR void operator()(Formatter& f) { - f.parse(ctx); - detail::maybe_set_debug_format(f, true); - } - parse_context& ctx; -}; -template struct format_tuple_element { - using char_type = typename FormatContext::char_type; - - template - void operator()(const formatter& f, const T& v) { - if (i > 0) ctx.advance_to(detail::copy(separator, ctx.out())); - ctx.advance_to(f.format(v, ctx)); - ++i; - } - - int i; - FormatContext& ctx; - basic_string_view separator; -}; - -} // namespace detail - -FMT_EXPORT -template struct is_tuple_like { - static constexpr bool value = - detail::is_tuple_like_::value && !detail::is_range_::value; -}; - -FMT_EXPORT -template struct is_tuple_formattable { - static constexpr bool value = detail::is_tuple_formattable_::value; -}; - -template -struct formatter::value && - fmt::is_tuple_formattable::value>> { - private: - decltype(detail::tuple::get_formatters( - detail::tuple_index_sequence())) formatters_; - - basic_string_view separator_ = detail::string_literal{}; - basic_string_view opening_bracket_ = - detail::string_literal{}; - basic_string_view closing_bracket_ = - detail::string_literal{}; - - public: - FMT_CONSTEXPR formatter() {} - - FMT_CONSTEXPR void set_separator(basic_string_view sep) { - separator_ = sep; - } - - FMT_CONSTEXPR void set_brackets(basic_string_view open, - basic_string_view close) { - opening_bracket_ = open; - closing_bracket_ = close; - } - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(); - auto end = ctx.end(); - if (it != end && detail::to_ascii(*it) == 'n') { - ++it; - set_brackets({}, {}); - set_separator({}); - } - if (it != end && *it != '}') report_error("invalid format specifier"); - ctx.advance_to(it); - detail::for_each(formatters_, detail::parse_empty_specs{ctx}); - return it; - } - - template - auto format(const Tuple& value, FormatContext& ctx) const - -> decltype(ctx.out()) { - ctx.advance_to(detail::copy(opening_bracket_, ctx.out())); - detail::for_each2( - formatters_, value, - detail::format_tuple_element{0, ctx, separator_}); - return detail::copy(closing_bracket_, ctx.out()); - } -}; - -FMT_EXPORT -template struct is_range { - static constexpr bool value = - detail::is_range_::value && !detail::has_to_string_view::value; -}; - -namespace detail { - -template -using range_formatter_type = formatter, Char>; - -template -using maybe_const_range = - conditional_t::value, const R, R>; - -template -struct is_formattable_delayed - : is_formattable>, Char> {}; -} // namespace detail - -template struct conjunction : std::true_type {}; -template struct conjunction

: P {}; -template -struct conjunction - : conditional_t, P1> {}; - -FMT_EXPORT -template -struct range_formatter; - -template -struct range_formatter< - T, Char, - enable_if_t>, - is_formattable>::value>> { - private: - detail::range_formatter_type underlying_; - basic_string_view separator_ = detail::string_literal{}; - basic_string_view opening_bracket_ = - detail::string_literal{}; - basic_string_view closing_bracket_ = - detail::string_literal{}; - bool is_debug = false; - - template ::value)> - auto write_debug_string(Output& out, It it, Sentinel end) const -> Output { - auto buf = basic_memory_buffer(); - for (; it != end; ++it) buf.push_back(*it); - auto specs = format_specs(); - specs.set_type(presentation_type::debug); - return detail::write( - out, basic_string_view(buf.data(), buf.size()), specs); - } - - template ::value)> - auto write_debug_string(Output& out, It, Sentinel) const -> Output { - return out; - } - - public: - FMT_CONSTEXPR range_formatter() {} - - FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type& { - return underlying_; - } - - FMT_CONSTEXPR void set_separator(basic_string_view sep) { - separator_ = sep; - } - - FMT_CONSTEXPR void set_brackets(basic_string_view open, - basic_string_view close) { - opening_bracket_ = open; - closing_bracket_ = close; - } - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(); - auto end = ctx.end(); - detail::maybe_set_debug_format(underlying_, true); - if (it == end) return underlying_.parse(ctx); - - switch (detail::to_ascii(*it)) { - case 'n': - set_brackets({}, {}); - ++it; - break; - case '?': - is_debug = true; - set_brackets({}, {}); - ++it; - if (it == end || *it != 's') report_error("invalid format specifier"); - FMT_FALLTHROUGH; - case 's': - if (!std::is_same::value) - report_error("invalid format specifier"); - if (!is_debug) { - set_brackets(detail::string_literal{}, - detail::string_literal{}); - set_separator({}); - detail::maybe_set_debug_format(underlying_, false); - } - ++it; - return it; - } - - if (it != end && *it != '}') { - if (*it != ':') report_error("invalid format specifier"); - detail::maybe_set_debug_format(underlying_, false); - ++it; - } - - ctx.advance_to(it); - return underlying_.parse(ctx); - } - - template - auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) { - auto out = ctx.out(); - auto it = detail::range_begin(range); - auto end = detail::range_end(range); - if (is_debug) return write_debug_string(out, std::move(it), end); - - out = detail::copy(opening_bracket_, out); - int i = 0; - for (; it != end; ++it) { - if (i > 0) out = detail::copy(separator_, out); - ctx.advance_to(out); - auto&& item = *it; // Need an lvalue - out = underlying_.format(item, ctx); - ++i; - } - out = detail::copy(closing_bracket_, out); - return out; - } -}; - -FMT_EXPORT -template -struct range_format_kind - : conditional_t< - is_range::value, detail::range_format_kind_, - std::integral_constant> {}; - -template -struct formatter< - R, Char, - enable_if_t::value != range_format::disabled && - range_format_kind::value != range_format::map && - range_format_kind::value != range_format::string && - range_format_kind::value != range_format::debug_string>, - detail::is_formattable_delayed>::value>> { - private: - using range_type = detail::maybe_const_range; - range_formatter, Char> range_formatter_; - - public: - using nonlocking = void; - - FMT_CONSTEXPR formatter() { - if (detail::const_check(range_format_kind::value != - range_format::set)) - return; - range_formatter_.set_brackets(detail::string_literal{}, - detail::string_literal{}); - } - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return range_formatter_.parse(ctx); - } - - template - auto format(range_type& range, FormatContext& ctx) const - -> decltype(ctx.out()) { - return range_formatter_.format(range, ctx); - } -}; - -// A map formatter. -template -struct formatter< - R, Char, - enable_if_t::value == range_format::map>, - detail::is_formattable_delayed>::value>> { - private: - using map_type = detail::maybe_const_range; - using element_type = detail::uncvref_type; - - decltype(detail::tuple::get_formatters( - detail::tuple_index_sequence())) formatters_; - bool no_delimiters_ = false; - - public: - FMT_CONSTEXPR formatter() {} - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(); - auto end = ctx.end(); - if (it != end) { - if (detail::to_ascii(*it) == 'n') { - no_delimiters_ = true; - ++it; - } - if (it != end && *it != '}') { - if (*it != ':') report_error("invalid format specifier"); - ++it; - } - ctx.advance_to(it); - } - detail::for_each(formatters_, detail::parse_empty_specs{ctx}); - return it; - } - - template - auto format(map_type& map, FormatContext& ctx) const -> decltype(ctx.out()) { - auto out = ctx.out(); - basic_string_view open = detail::string_literal{}; - if (!no_delimiters_) out = detail::copy(open, out); - int i = 0; - basic_string_view sep = detail::string_literal{}; - for (auto&& value : map) { - if (i > 0) out = detail::copy(sep, out); - ctx.advance_to(out); - detail::for_each2(formatters_, value, - detail::format_tuple_element{ - 0, ctx, detail::string_literal{}}); - ++i; - } - basic_string_view close = detail::string_literal{}; - if (!no_delimiters_) out = detail::copy(close, out); - return out; - } -}; - -// A (debug_)string formatter. -template -struct formatter< - R, Char, - enable_if_t::value == range_format::string || - range_format_kind::value == - range_format::debug_string>> { - private: - using range_type = detail::maybe_const_range; - using string_type = - conditional_t, - decltype(detail::range_begin(std::declval())), - decltype(detail::range_end(std::declval()))>::value, - detail::std_string_view, std::basic_string>; - - formatter underlying_; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return underlying_.parse(ctx); - } - - template - auto format(range_type& range, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); - if (detail::const_check(range_format_kind::value == - range_format::debug_string)) - *out++ = '"'; - out = underlying_.format( - string_type{detail::range_begin(range), detail::range_end(range)}, ctx); - if (detail::const_check(range_format_kind::value == - range_format::debug_string)) - *out++ = '"'; - return out; - } -}; - -template -struct join_view : detail::view { - It begin; - Sentinel end; - basic_string_view sep; - - join_view(It b, Sentinel e, basic_string_view s) - : begin(std::move(b)), end(e), sep(s) {} -}; - -template -struct formatter, Char> { - private: - using value_type = -#ifdef __cpp_lib_ranges - std::iter_value_t; -#else - typename std::iterator_traits::value_type; -#endif - formatter, Char> value_formatter_; - - using view = conditional_t::value, - const join_view, - join_view>; - - public: - using nonlocking = void; - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return value_formatter_.parse(ctx); - } - - template - auto format(view& value, FormatContext& ctx) const -> decltype(ctx.out()) { - using iter = - conditional_t::value, It, It&>; - iter it = value.begin; - auto out = ctx.out(); - if (it == value.end) return out; - out = value_formatter_.format(*it, ctx); - ++it; - while (it != value.end) { - out = detail::copy(value.sep.begin(), value.sep.end(), out); - ctx.advance_to(out); - out = value_formatter_.format(*it, ctx); - ++it; - } - return out; - } -}; - -FMT_EXPORT -template struct tuple_join_view : detail::view { - const Tuple& tuple; - basic_string_view sep; - - tuple_join_view(const Tuple& t, basic_string_view s) - : tuple(t), sep{s} {} -}; - -// Define FMT_TUPLE_JOIN_SPECIFIERS to enable experimental format specifiers -// support in tuple_join. It is disabled by default because of issues with -// the dynamic width and precision. -#ifndef FMT_TUPLE_JOIN_SPECIFIERS -# define FMT_TUPLE_JOIN_SPECIFIERS 0 -#endif - -template -struct formatter, Char, - enable_if_t::value>> { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return do_parse(ctx, std::tuple_size()); - } - - template - auto format(const tuple_join_view& value, - FormatContext& ctx) const -> typename FormatContext::iterator { - return do_format(value, ctx, std::tuple_size()); - } - - private: - decltype(detail::tuple::get_formatters( - detail::tuple_index_sequence())) formatters_; - - FMT_CONSTEXPR auto do_parse(parse_context& ctx, - std::integral_constant) - -> const Char* { - return ctx.begin(); - } - - template - FMT_CONSTEXPR auto do_parse(parse_context& ctx, - std::integral_constant) - -> const Char* { - auto end = ctx.begin(); -#if FMT_TUPLE_JOIN_SPECIFIERS - end = std::get::value - N>(formatters_).parse(ctx); - if (N > 1) { - auto end1 = do_parse(ctx, std::integral_constant()); - if (end != end1) - report_error("incompatible format specs for tuple elements"); - } -#endif - return end; - } - - template - auto do_format(const tuple_join_view&, FormatContext& ctx, - std::integral_constant) const -> - typename FormatContext::iterator { - return ctx.out(); - } - - template - auto do_format(const tuple_join_view& value, FormatContext& ctx, - std::integral_constant) const -> - typename FormatContext::iterator { - using std::get; - auto out = - std::get::value - N>(formatters_) - .format(get::value - N>(value.tuple), ctx); - if (N <= 1) return out; - out = detail::copy(value.sep, out); - ctx.advance_to(out); - return do_format(value, ctx, std::integral_constant()); - } -}; - -namespace detail { -// Check if T has an interface like a container adaptor (e.g. std::stack, -// std::queue, std::priority_queue). -template class is_container_adaptor_like { - template static auto check(U* p) -> typename U::container_type; - template static void check(...); - - public: - static constexpr bool value = - !std::is_void(nullptr))>::value; -}; - -template struct all { - const Container& c; - auto begin() const -> typename Container::const_iterator { return c.begin(); } - auto end() const -> typename Container::const_iterator { return c.end(); } -}; -} // namespace detail - -template -struct formatter< - T, Char, - enable_if_t, - bool_constant::value == - range_format::disabled>>::value>> - : formatter, Char> { - using all = detail::all; - template - auto format(const T& value, FormatContext& ctx) const -> decltype(ctx.out()) { - struct getter : T { - static auto get(const T& v) -> all { - return {v.*(&getter::c)}; // Access c through the derived class. - } - }; - return formatter::format(getter::get(value), ctx); - } -}; - -FMT_BEGIN_EXPORT - -/// Returns a view that formats the iterator range `[begin, end)` with elements -/// separated by `sep`. -template -auto join(It begin, Sentinel end, string_view sep) -> join_view { - return {std::move(begin), end, sep}; -} - -/** - * Returns a view that formats `range` with elements separated by `sep`. - * - * **Example**: - * - * auto v = std::vector{1, 2, 3}; - * fmt::print("{}", fmt::join(v, ", ")); - * // Output: 1, 2, 3 - * - * `fmt::join` applies passed format specifiers to the range elements: - * - * fmt::print("{:02}", fmt::join(v, ", ")); - * // Output: 01, 02, 03 - */ -template ::value)> -auto join(Range&& r, string_view sep) - -> join_view { - return {detail::range_begin(r), detail::range_end(r), sep}; -} - -/** - * Returns an object that formats `std::tuple` with elements separated by `sep`. - * - * **Example**: - * - * auto t = std::tuple{1, 'a'}; - * fmt::print("{}", fmt::join(t, ", ")); - * // Output: 1, a - */ -template ::value)> -FMT_CONSTEXPR auto join(const Tuple& tuple, string_view sep) - -> tuple_join_view { - return {tuple, sep}; -} - -/** - * Returns an object that formats `std::initializer_list` with elements - * separated by `sep`. - * - * **Example**: - * - * fmt::print("{}", fmt::join({1, 2, 3}, ", ")); - * // Output: "1, 2, 3" - */ -template -auto join(std::initializer_list list, string_view sep) - -> join_view { - return join(std::begin(list), std::end(list), sep); -} - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_RANGES_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/std.h b/examples/blueprints-example/external/fmt/bundled/std.h deleted file mode 100644 index 5cf1061..0000000 --- a/examples/blueprints-example/external/fmt/bundled/std.h +++ /dev/null @@ -1,707 +0,0 @@ -// Formatting library for C++ - formatters for standard library types -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_STD_H_ -#define FMT_STD_H_ - -#include "format.h" -#include "ostream.h" - -#ifndef FMT_MODULE -# include -# include -# include -# include -# include // std::reference_wrapper -# include -# include -# include -# include // std::type_info -# include // std::make_index_sequence - -// Check FMT_CPLUSPLUS to suppress a bogus warning in MSVC. -# if FMT_CPLUSPLUS >= 201703L -# if FMT_HAS_INCLUDE() && \ - (!defined(FMT_CPP_LIB_FILESYSTEM) || FMT_CPP_LIB_FILESYSTEM != 0) -# include -# endif -# if FMT_HAS_INCLUDE() -# include -# endif -# if FMT_HAS_INCLUDE() -# include -# endif -# endif -// Use > instead of >= in the version check because may be -// available after C++17 but before C++20 is marked as implemented. -# if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE() -# include -# endif -# if FMT_CPLUSPLUS > 202002L && FMT_HAS_INCLUDE() -# include -# endif -#endif // FMT_MODULE - -#if FMT_HAS_INCLUDE() -# include -#endif - -// GCC 4 does not support FMT_HAS_INCLUDE. -#if FMT_HAS_INCLUDE() || defined(__GLIBCXX__) -# include -// Android NDK with gabi++ library on some architectures does not implement -// abi::__cxa_demangle(). -# ifndef __GABIXX_CXXABI_H__ -# define FMT_HAS_ABI_CXA_DEMANGLE -# endif -#endif - -#ifdef FMT_CPP_LIB_FILESYSTEM -// Use the provided definition. -#elif defined(__cpp_lib_filesystem) -# define FMT_CPP_LIB_FILESYSTEM __cpp_lib_filesystem -#else -# define FMT_CPP_LIB_FILESYSTEM 0 -#endif - -#ifdef FMT_CPP_LIB_VARIANT -// Use the provided definition. -#elif defined(__cpp_lib_variant) -# define FMT_CPP_LIB_VARIANT __cpp_lib_variant -#else -# define FMT_CPP_LIB_VARIANT 0 -#endif - -FMT_BEGIN_NAMESPACE -namespace detail { - -#if FMT_CPP_LIB_FILESYSTEM - -template -auto get_path_string(const std::filesystem::path& p, - const std::basic_string& native) { - if constexpr (std::is_same_v && std::is_same_v) - return to_utf8(native, to_utf8_error_policy::replace); - else - return p.string(); -} - -template -void write_escaped_path(basic_memory_buffer& quoted, - const std::filesystem::path& p, - const std::basic_string& native) { - if constexpr (std::is_same_v && - std::is_same_v) { - auto buf = basic_memory_buffer(); - write_escaped_string(std::back_inserter(buf), native); - bool valid = to_utf8::convert(quoted, {buf.data(), buf.size()}); - FMT_ASSERT(valid, "invalid utf16"); - } else if constexpr (std::is_same_v) { - write_escaped_string( - std::back_inserter(quoted), native); - } else { - write_escaped_string(std::back_inserter(quoted), p.string()); - } -} - -#endif // FMT_CPP_LIB_FILESYSTEM - -#if defined(__cpp_lib_expected) || FMT_CPP_LIB_VARIANT -template -auto write_escaped_alternative(OutputIt out, const T& v) -> OutputIt { - if constexpr (has_to_string_view::value) - return write_escaped_string(out, detail::to_string_view(v)); - if constexpr (std::is_same_v) return write_escaped_char(out, v); - return write(out, v); -} -#endif - -#if FMT_CPP_LIB_VARIANT - -template struct is_variant_like_ : std::false_type {}; -template -struct is_variant_like_> : std::true_type {}; - -template class is_variant_formattable { - template - static auto check(std::index_sequence) -> std::conjunction< - is_formattable, Char>...>; - - public: - static constexpr bool value = decltype(check( - std::make_index_sequence::value>()))::value; -}; - -#endif // FMT_CPP_LIB_VARIANT - -#if FMT_USE_RTTI - -template -auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt { -# ifdef FMT_HAS_ABI_CXA_DEMANGLE - int status = 0; - size_t size = 0; - std::unique_ptr demangled_name_ptr( - abi::__cxa_demangle(ti.name(), nullptr, &size, &status), &std::free); - - string_view demangled_name_view; - if (demangled_name_ptr) { - demangled_name_view = demangled_name_ptr.get(); - - // Normalization of stdlib inline namespace names. - // libc++ inline namespaces. - // std::__1::* -> std::* - // std::__1::__fs::* -> std::* - // libstdc++ inline namespaces. - // std::__cxx11::* -> std::* - // std::filesystem::__cxx11::* -> std::filesystem::* - if (demangled_name_view.starts_with("std::")) { - char* begin = demangled_name_ptr.get(); - char* to = begin + 5; // std:: - for (char *from = to, *end = begin + demangled_name_view.size(); - from < end;) { - // This is safe, because demangled_name is NUL-terminated. - if (from[0] == '_' && from[1] == '_') { - char* next = from + 1; - while (next < end && *next != ':') next++; - if (next[0] == ':' && next[1] == ':') { - from = next + 2; - continue; - } - } - *to++ = *from++; - } - demangled_name_view = {begin, detail::to_unsigned(to - begin)}; - } - } else { - demangled_name_view = string_view(ti.name()); - } - return detail::write_bytes(out, demangled_name_view); -# elif FMT_MSC_VERSION - const string_view demangled_name(ti.name()); - for (size_t i = 0; i < demangled_name.size(); ++i) { - auto sub = demangled_name; - sub.remove_prefix(i); - if (sub.starts_with("enum ")) { - i += 4; - continue; - } - if (sub.starts_with("class ") || sub.starts_with("union ")) { - i += 5; - continue; - } - if (sub.starts_with("struct ")) { - i += 6; - continue; - } - if (*sub.begin() != ' ') *out++ = *sub.begin(); - } - return out; -# else - return detail::write_bytes(out, string_view(ti.name())); -# endif -} - -#endif // FMT_USE_RTTI - -template -struct has_flip : std::false_type {}; - -template -struct has_flip().flip())>> - : std::true_type {}; - -template struct is_bit_reference_like { - static constexpr bool value = std::is_convertible::value && - std::is_nothrow_assignable::value && - has_flip::value; -}; - -// Workaround for libc++ incompatibility with C++ standard. -// According to the Standard, `bitset::operator[] const` returns bool. -#if defined(_LIBCPP_VERSION) && !defined(FMT_IMPORT_STD) -template -struct is_bit_reference_like> { - static constexpr bool value = true; -}; -#endif - -template -struct has_format_as : std::false_type {}; -template -struct has_format_as()))>> - : std::true_type {}; - -template -struct has_format_as_member : std::false_type {}; -template -struct has_format_as_member< - T, void_t::format_as(std::declval()))>> - : std::true_type {}; - -} // namespace detail - -template -auto ptr(const std::unique_ptr& p) -> const void* { - return p.get(); -} -template auto ptr(const std::shared_ptr& p) -> const void* { - return p.get(); -} - -#if FMT_CPP_LIB_FILESYSTEM - -class path : public std::filesystem::path { - public: - auto display_string() const -> std::string { - const std::filesystem::path& base = *this; - return fmt::format(FMT_STRING("{}"), base); - } - auto system_string() const -> std::string { return string(); } - - auto generic_display_string() const -> std::string { - const std::filesystem::path& base = *this; - return fmt::format(FMT_STRING("{:g}"), base); - } - auto generic_system_string() const -> std::string { return generic_string(); } -}; - -template struct formatter { - private: - format_specs specs_; - detail::arg_ref width_ref_; - bool debug_ = false; - char path_type_ = 0; - - public: - FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; } - - FMT_CONSTEXPR auto parse(parse_context& ctx) { - auto it = ctx.begin(), end = ctx.end(); - if (it == end) return it; - - it = detail::parse_align(it, end, specs_); - if (it == end) return it; - - Char c = *it; - if ((c >= '0' && c <= '9') || c == '{') - it = detail::parse_width(it, end, specs_, width_ref_, ctx); - if (it != end && *it == '?') { - debug_ = true; - ++it; - } - if (it != end && (*it == 'g')) path_type_ = detail::to_ascii(*it++); - return it; - } - - template - auto format(const std::filesystem::path& p, FormatContext& ctx) const { - auto specs = specs_; - auto path_string = - !path_type_ ? p.native() - : p.generic_string(); - - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, - ctx); - if (!debug_) { - auto s = detail::get_path_string(p, path_string); - return detail::write(ctx.out(), basic_string_view(s), specs); - } - auto quoted = basic_memory_buffer(); - detail::write_escaped_path(quoted, p, path_string); - return detail::write(ctx.out(), - basic_string_view(quoted.data(), quoted.size()), - specs); - } -}; - -#endif // FMT_CPP_LIB_FILESYSTEM - -template -struct formatter, Char> - : nested_formatter, Char> { - private: - // This is a functor because C++11 doesn't support generic lambdas. - struct writer { - const std::bitset& bs; - - template - FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt { - for (auto pos = N; pos > 0; --pos) - out = detail::write(out, bs[pos - 1] ? Char('1') : Char('0')); - return out; - } - }; - - public: - template - auto format(const std::bitset& bs, FormatContext& ctx) const - -> decltype(ctx.out()) { - return this->write_padded(ctx, writer{bs}); - } -}; - -template -struct formatter : basic_ostream_formatter {}; - -#ifdef __cpp_lib_optional -template -struct formatter, Char, - std::enable_if_t::value>> { - private: - formatter underlying_; - static constexpr basic_string_view optional = - detail::string_literal{}; - static constexpr basic_string_view none = - detail::string_literal{}; - - template - FMT_CONSTEXPR static auto maybe_set_debug_format(U& u, bool set) - -> decltype(u.set_debug_format(set)) { - u.set_debug_format(set); - } - - template - FMT_CONSTEXPR static void maybe_set_debug_format(U&, ...) {} - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) { - maybe_set_debug_format(underlying_, true); - return underlying_.parse(ctx); - } - - template - auto format(const std::optional& opt, FormatContext& ctx) const - -> decltype(ctx.out()) { - if (!opt) return detail::write(ctx.out(), none); - - auto out = ctx.out(); - out = detail::write(out, optional); - ctx.advance_to(out); - out = underlying_.format(*opt, ctx); - return detail::write(out, ')'); - } -}; -#endif // __cpp_lib_optional - -#ifdef __cpp_lib_expected -template -struct formatter, Char, - std::enable_if_t<(std::is_void::value || - is_formattable::value) && - is_formattable::value>> { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return ctx.begin(); - } - - template - auto format(const std::expected& value, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); - - if (value.has_value()) { - out = detail::write(out, "expected("); - if constexpr (!std::is_void::value) - out = detail::write_escaped_alternative(out, *value); - } else { - out = detail::write(out, "unexpected("); - out = detail::write_escaped_alternative(out, value.error()); - } - *out++ = ')'; - return out; - } -}; -#endif // __cpp_lib_expected - -#ifdef __cpp_lib_source_location -template <> struct formatter { - FMT_CONSTEXPR auto parse(parse_context<>& ctx) { return ctx.begin(); } - - template - auto format(const std::source_location& loc, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); - out = detail::write(out, loc.file_name()); - out = detail::write(out, ':'); - out = detail::write(out, loc.line()); - out = detail::write(out, ':'); - out = detail::write(out, loc.column()); - out = detail::write(out, ": "); - out = detail::write(out, loc.function_name()); - return out; - } -}; -#endif - -#if FMT_CPP_LIB_VARIANT - -template struct is_variant_like { - static constexpr bool value = detail::is_variant_like_::value; -}; - -template struct formatter { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return ctx.begin(); - } - - template - auto format(const std::monostate&, FormatContext& ctx) const - -> decltype(ctx.out()) { - return detail::write(ctx.out(), "monostate"); - } -}; - -template -struct formatter, - detail::is_variant_formattable>>> { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return ctx.begin(); - } - - template - auto format(const Variant& value, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); - - out = detail::write(out, "variant("); - FMT_TRY { - std::visit( - [&](const auto& v) { - out = detail::write_escaped_alternative(out, v); - }, - value); - } - FMT_CATCH(const std::bad_variant_access&) { - detail::write(out, "valueless by exception"); - } - *out++ = ')'; - return out; - } -}; - -#endif // FMT_CPP_LIB_VARIANT - -template <> struct formatter { - private: - format_specs specs_; - detail::arg_ref width_ref_; - bool debug_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - auto it = ctx.begin(), end = ctx.end(); - if (it == end) return it; - - it = detail::parse_align(it, end, specs_); - - char c = *it; - if (it != end && ((c >= '0' && c <= '9') || c == '{')) - it = detail::parse_width(it, end, specs_, width_ref_, ctx); - - if (it != end && *it == '?') { - debug_ = true; - ++it; - } - if (it != end && *it == 's') { - specs_.set_type(presentation_type::string); - ++it; - } - return it; - } - - template - FMT_CONSTEXPR20 auto format(const std::error_code& ec, - FormatContext& ctx) const -> decltype(ctx.out()) { - auto specs = specs_; - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, - ctx); - auto buf = memory_buffer(); - if (specs_.type() == presentation_type::string) { - buf.append(ec.message()); - } else { - buf.append(string_view(ec.category().name())); - buf.push_back(':'); - detail::write(appender(buf), ec.value()); - } - auto quoted = memory_buffer(); - auto str = string_view(buf.data(), buf.size()); - if (debug_) { - detail::write_escaped_string(std::back_inserter(quoted), str); - str = string_view(quoted.data(), quoted.size()); - } - return detail::write(ctx.out(), str, specs); - } -}; - -#if FMT_USE_RTTI -template <> struct formatter { - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - return ctx.begin(); - } - - template - auto format(const std::type_info& ti, Context& ctx) const - -> decltype(ctx.out()) { - return detail::write_demangled_name(ctx.out(), ti); - } -}; -#endif // FMT_USE_RTTI - -template -struct formatter< - T, char, - typename std::enable_if::value>::type> { - private: - bool with_typename_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - auto it = ctx.begin(); - auto end = ctx.end(); - if (it == end || *it == '}') return it; - if (*it == 't') { - ++it; - with_typename_ = FMT_USE_RTTI != 0; - } - return it; - } - - template - auto format(const std::exception& ex, Context& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); -#if FMT_USE_RTTI - if (with_typename_) { - out = detail::write_demangled_name(out, typeid(ex)); - *out++ = ':'; - *out++ = ' '; - } -#endif - return detail::write_bytes(out, string_view(ex.what())); - } -}; - -// We can't use std::vector::reference and -// std::bitset::reference because the compiler can't deduce Allocator and N -// in partial specialization. -template -struct formatter::value>> - : formatter { - template - FMT_CONSTEXPR auto format(const BitRef& v, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter::format(v, ctx); - } -}; - -template -struct formatter, Char, - enable_if_t::value>> - : formatter { - template - auto format(const std::atomic& v, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter::format(v.load(), ctx); - } -}; - -#ifdef __cpp_lib_atomic_flag_test -template -struct formatter : formatter { - template - auto format(const std::atomic_flag& v, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter::format(v.test(), ctx); - } -}; -#endif // __cpp_lib_atomic_flag_test - -template struct formatter, Char> { - private: - detail::dynamic_format_specs specs_; - - template - FMT_CONSTEXPR auto do_format(const std::complex& c, - detail::dynamic_format_specs& specs, - FormatContext& ctx, OutputIt out) const - -> OutputIt { - if (c.real() != 0) { - *out++ = Char('('); - out = detail::write(out, c.real(), specs, ctx.locale()); - specs.set_sign(sign::plus); - out = detail::write(out, c.imag(), specs, ctx.locale()); - if (!detail::isfinite(c.imag())) *out++ = Char(' '); - *out++ = Char('i'); - *out++ = Char(')'); - return out; - } - out = detail::write(out, c.imag(), specs, ctx.locale()); - if (!detail::isfinite(c.imag())) *out++ = Char(' '); - *out++ = Char('i'); - return out; - } - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); - return parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, - detail::type_constant::value); - } - - template - auto format(const std::complex& c, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto specs = specs_; - if (specs.dynamic()) { - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs.precision_ref, ctx); - } - - if (specs.width == 0) return do_format(c, specs, ctx, ctx.out()); - auto buf = basic_memory_buffer(); - - auto outer_specs = format_specs(); - outer_specs.width = specs.width; - outer_specs.copy_fill_from(specs); - outer_specs.set_align(specs.align()); - - specs.width = 0; - specs.set_fill({}); - specs.set_align(align::none); - - do_format(c, specs, ctx, basic_appender(buf)); - return detail::write(ctx.out(), - basic_string_view(buf.data(), buf.size()), - outer_specs); - } -}; - -template -struct formatter, Char, - // Guard against format_as because reference_wrapper is - // implicitly convertible to T&. - enable_if_t, Char>::value && - !detail::has_format_as::value && - !detail::has_format_as_member::value>> - : formatter, Char> { - template - auto format(std::reference_wrapper ref, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter, Char>::format(ref.get(), ctx); - } -}; - -FMT_END_NAMESPACE - -#endif // FMT_STD_H_ diff --git a/examples/blueprints-example/external/fmt/bundled/xchar.h b/examples/blueprints-example/external/fmt/bundled/xchar.h deleted file mode 100644 index 9334b87..0000000 --- a/examples/blueprints-example/external/fmt/bundled/xchar.h +++ /dev/null @@ -1,356 +0,0 @@ -// Formatting library for C++ - optional wchar_t and exotic character support -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_XCHAR_H_ -#define FMT_XCHAR_H_ - -#include "color.h" -#include "format.h" -#include "ostream.h" -#include "ranges.h" - -#ifndef FMT_MODULE -# include -# if FMT_USE_LOCALE -# include -# endif -#endif - -FMT_BEGIN_NAMESPACE -namespace detail { - -template -using is_exotic_char = bool_constant::value>; - -template struct format_string_char {}; - -template -struct format_string_char< - S, void_t())))>> { - using type = char_t; -}; - -template -struct format_string_char< - S, enable_if_t::value>> { - using type = typename S::char_type; -}; - -template -using format_string_char_t = typename format_string_char::type; - -inline auto write_loc(basic_appender out, loc_value value, - const format_specs& specs, locale_ref loc) -> bool { -#if FMT_USE_LOCALE - auto& numpunct = - std::use_facet>(loc.get()); - auto separator = std::wstring(); - auto grouping = numpunct.grouping(); - if (!grouping.empty()) separator = std::wstring(1, numpunct.thousands_sep()); - return value.visit(loc_writer{out, specs, separator, grouping, {}}); -#endif - return false; -} - -template -void vformat_to(buffer& buf, basic_string_view fmt, - basic_format_args> args, - locale_ref loc = {}) { - static_assert(!std::is_same::value, ""); - auto out = basic_appender(buf); - parse_format_string( - fmt, format_handler{parse_context(fmt), {out, args, loc}}); -} -} // namespace detail - -FMT_BEGIN_EXPORT - -using wstring_view = basic_string_view; -using wformat_parse_context = parse_context; -using wformat_context = buffered_context; -using wformat_args = basic_format_args; -using wmemory_buffer = basic_memory_buffer; - -template struct basic_fstring { - private: - basic_string_view str_; - - static constexpr int num_static_named_args = - detail::count_static_named_args(); - - using checker = detail::format_string_checker< - Char, static_cast(sizeof...(T)), num_static_named_args, - num_static_named_args != detail::count_named_args()>; - - using arg_pack = detail::arg_pack; - - public: - using t = basic_fstring; - - template >::value)> - FMT_CONSTEVAL FMT_ALWAYS_INLINE basic_fstring(const S& s) : str_(s) { - if (FMT_USE_CONSTEVAL) - detail::parse_format_string(s, checker(s, arg_pack())); - } - template ::value&& - std::is_same::value)> - FMT_ALWAYS_INLINE basic_fstring(const S&) : str_(S()) { - FMT_CONSTEXPR auto sv = basic_string_view(S()); - FMT_CONSTEXPR int ignore = - (parse_format_string(sv, checker(sv, arg_pack())), 0); - detail::ignore_unused(ignore); - } - basic_fstring(runtime_format_string fmt) : str_(fmt.str) {} - - operator basic_string_view() const { return str_; } - auto get() const -> basic_string_view { return str_; } -}; - -template -using basic_format_string = basic_fstring; - -template -using wformat_string = typename basic_format_string::t; -inline auto runtime(wstring_view s) -> runtime_format_string { - return {{s}}; -} - -template -constexpr auto make_wformat_args(T&... args) - -> decltype(fmt::make_format_args(args...)) { - return fmt::make_format_args(args...); -} - -#if !FMT_USE_NONTYPE_TEMPLATE_ARGS -inline namespace literals { -inline auto operator""_a(const wchar_t* s, size_t) -> detail::udl_arg { - return {s}; -} -} // namespace literals -#endif - -template -auto join(It begin, Sentinel end, wstring_view sep) - -> join_view { - return {begin, end, sep}; -} - -template ::value)> -auto join(Range&& range, wstring_view sep) - -> join_view { - return join(std::begin(range), std::end(range), sep); -} - -template -auto join(std::initializer_list list, wstring_view sep) - -> join_view { - return join(std::begin(list), std::end(list), sep); -} - -template ::value)> -auto join(const Tuple& tuple, basic_string_view sep) - -> tuple_join_view { - return {tuple, sep}; -} - -template ::value)> -auto vformat(basic_string_view fmt, - basic_format_args> args) - -> std::basic_string { - auto buf = basic_memory_buffer(); - detail::vformat_to(buf, fmt, args); - return {buf.data(), buf.size()}; -} - -template -auto format(wformat_string fmt, T&&... args) -> std::wstring { - return vformat(fmt::wstring_view(fmt), fmt::make_wformat_args(args...)); -} - -template -auto format_to(OutputIt out, wformat_string fmt, T&&... args) - -> OutputIt { - return vformat_to(out, fmt::wstring_view(fmt), - fmt::make_wformat_args(args...)); -} - -// Pass char_t as a default template parameter instead of using -// std::basic_string> to reduce the symbol size. -template , - FMT_ENABLE_IF(!std::is_same::value && - !std::is_same::value)> -auto format(const S& fmt, T&&... args) -> std::basic_string { - return vformat(detail::to_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template , - FMT_ENABLE_IF(detail::is_exotic_char::value)> -inline auto vformat(locale_ref loc, const S& fmt, - basic_format_args> args) - -> std::basic_string { - auto buf = basic_memory_buffer(); - detail::vformat_to(buf, detail::to_string_view(fmt), args, loc); - return {buf.data(), buf.size()}; -} - -template , - FMT_ENABLE_IF(detail::is_exotic_char::value)> -inline auto format(locale_ref loc, const S& fmt, T&&... args) - -> std::basic_string { - return vformat(loc, detail::to_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> -auto vformat_to(OutputIt out, const S& fmt, - basic_format_args> args) -> OutputIt { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, detail::to_string_view(fmt), args); - return detail::get_iterator(buf, out); -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value && - !std::is_same::value && - !std::is_same::value)> -inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt { - return vformat_to(out, detail::to_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> -inline auto vformat_to(OutputIt out, locale_ref loc, const S& fmt, - basic_format_args> args) - -> OutputIt { - auto&& buf = detail::get_buffer(out); - vformat_to(buf, detail::to_string_view(fmt), args, loc); - return detail::get_iterator(buf, out); -} - -template , - bool enable = detail::is_output_iterator::value && - detail::is_exotic_char::value> -inline auto format_to(OutputIt out, locale_ref loc, const S& fmt, T&&... args) - -> typename std::enable_if::type { - return vformat_to(out, loc, detail::to_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template ::value&& - detail::is_exotic_char::value)> -inline auto vformat_to_n(OutputIt out, size_t n, basic_string_view fmt, - basic_format_args> args) - -> format_to_n_result { - using traits = detail::fixed_buffer_traits; - auto buf = detail::iterator_buffer(out, n); - detail::vformat_to(buf, fmt, args); - return {buf.out(), buf.count()}; -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> -inline auto format_to_n(OutputIt out, size_t n, const S& fmt, T&&... args) - -> format_to_n_result { - return vformat_to_n(out, n, fmt::basic_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template , - FMT_ENABLE_IF(detail::is_exotic_char::value)> -inline auto formatted_size(const S& fmt, T&&... args) -> size_t { - auto buf = detail::counting_buffer(); - detail::vformat_to(buf, detail::to_string_view(fmt), - fmt::make_format_args>(args...)); - return buf.count(); -} - -inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) { - auto buf = wmemory_buffer(); - detail::vformat_to(buf, fmt, args); - buf.push_back(L'\0'); - if (std::fputws(buf.data(), f) == -1) - FMT_THROW(system_error(errno, FMT_STRING("cannot write to file"))); -} - -inline void vprint(wstring_view fmt, wformat_args args) { - vprint(stdout, fmt, args); -} - -template -void print(std::FILE* f, wformat_string fmt, T&&... args) { - return vprint(f, wstring_view(fmt), fmt::make_wformat_args(args...)); -} - -template void print(wformat_string fmt, T&&... args) { - return vprint(wstring_view(fmt), fmt::make_wformat_args(args...)); -} - -template -void println(std::FILE* f, wformat_string fmt, T&&... args) { - return print(f, L"{}\n", fmt::format(fmt, std::forward(args)...)); -} - -template void println(wformat_string fmt, T&&... args) { - return print(L"{}\n", fmt::format(fmt, std::forward(args)...)); -} - -inline auto vformat(text_style ts, wstring_view fmt, wformat_args args) - -> std::wstring { - auto buf = wmemory_buffer(); - detail::vformat_to(buf, ts, fmt, args); - return {buf.data(), buf.size()}; -} - -template -inline auto format(text_style ts, wformat_string fmt, T&&... args) - -> std::wstring { - return fmt::vformat(ts, fmt, fmt::make_wformat_args(args...)); -} - -inline void vprint(std::wostream& os, wstring_view fmt, wformat_args args) { - auto buffer = basic_memory_buffer(); - detail::vformat_to(buffer, fmt, args); - detail::write_buffer(os, buffer); -} - -template -void print(std::wostream& os, wformat_string fmt, T&&... args) { - vprint(os, fmt, fmt::make_format_args>(args...)); -} - -template -void println(std::wostream& os, wformat_string fmt, T&&... args) { - print(os, L"{}\n", fmt::format(fmt, std::forward(args)...)); -} - -/// Converts `value` to `std::wstring` using the default format for type `T`. -template inline auto to_wstring(const T& value) -> std::wstring { - return format(FMT_STRING(L"{}"), value); -} -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_XCHAR_H_ diff --git a/examples/blueprints-example/external/fmt/chrono.h b/examples/blueprints-example/external/fmt/chrono.h deleted file mode 100644 index a72a5bd..0000000 --- a/examples/blueprints-example/external/fmt/chrono.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's chrono support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/fmt/compile.h b/examples/blueprints-example/external/fmt/compile.h deleted file mode 100644 index 3c9c25d..0000000 --- a/examples/blueprints-example/external/fmt/compile.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's compile-time support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/fmt/fmt.h b/examples/blueprints-example/external/fmt/fmt.h deleted file mode 100644 index ba94a0c..0000000 --- a/examples/blueprints-example/external/fmt/fmt.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright(c) 2016-2018 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once - -// -// Include a bundled header-only copy of fmtlib or an external one. -// By default spdlog include its own copy. -// -#include - -#if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format - #include -#elif !defined(SPDLOG_FMT_EXTERNAL) - #if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY) - #define FMT_HEADER_ONLY - #endif - #ifndef FMT_USE_WINDOWS_H - #define FMT_USE_WINDOWS_H 0 - #endif - #include -#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib - #include -#endif diff --git a/examples/blueprints-example/external/fmt/ostr.h b/examples/blueprints-example/external/fmt/ostr.h deleted file mode 100644 index 2b90105..0000000 --- a/examples/blueprints-example/external/fmt/ostr.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's ostream support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/fmt/ranges.h b/examples/blueprints-example/external/fmt/ranges.h deleted file mode 100644 index 5bb91e9..0000000 --- a/examples/blueprints-example/external/fmt/ranges.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's ranges support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/fmt/std.h b/examples/blueprints-example/external/fmt/std.h deleted file mode 100644 index dabe6f6..0000000 --- a/examples/blueprints-example/external/fmt/std.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's std support (for formatting e.g. -// std::filesystem::path, std::thread::id, std::monostate, std::variant, ...) -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/fmt/xchar.h b/examples/blueprints-example/external/fmt/xchar.h deleted file mode 100644 index 2525f05..0000000 --- a/examples/blueprints-example/external/fmt/xchar.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's xchar support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/formatter.h b/examples/blueprints-example/external/formatter.h deleted file mode 100644 index 4d482f8..0000000 --- a/examples/blueprints-example/external/formatter.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { - -class formatter { -public: - virtual ~formatter() = default; - virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0; - virtual std::unique_ptr clone() const = 0; -}; -} // namespace spdlog diff --git a/examples/blueprints-example/external/fwd.h b/examples/blueprints-example/external/fwd.h deleted file mode 100644 index 647b16b..0000000 --- a/examples/blueprints-example/external/fwd.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -namespace spdlog { -class logger; -class formatter; - -namespace sinks { -class sink; -} - -namespace level { -enum level_enum : int; -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/logger-inl.h b/examples/blueprints-example/external/logger-inl.h deleted file mode 100644 index 6879273..0000000 --- a/examples/blueprints-example/external/logger-inl.h +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include -#include - -#include - -namespace spdlog { - -// public methods -SPDLOG_INLINE logger::logger(const logger &other) - : name_(other.name_), - sinks_(other.sinks_), - level_(other.level_.load(std::memory_order_relaxed)), - flush_level_(other.flush_level_.load(std::memory_order_relaxed)), - custom_err_handler_(other.custom_err_handler_), - tracer_(other.tracer_) {} - -SPDLOG_INLINE logger::logger(logger &&other) SPDLOG_NOEXCEPT - : name_(std::move(other.name_)), - sinks_(std::move(other.sinks_)), - level_(other.level_.load(std::memory_order_relaxed)), - flush_level_(other.flush_level_.load(std::memory_order_relaxed)), - custom_err_handler_(std::move(other.custom_err_handler_)), - tracer_(std::move(other.tracer_)) - -{} - -SPDLOG_INLINE logger &logger::operator=(logger other) SPDLOG_NOEXCEPT { - this->swap(other); - return *this; -} - -SPDLOG_INLINE void logger::swap(spdlog::logger &other) SPDLOG_NOEXCEPT { - name_.swap(other.name_); - sinks_.swap(other.sinks_); - - // swap level_ - auto other_level = other.level_.load(); - auto my_level = level_.exchange(other_level); - other.level_.store(my_level); - - // swap flush level_ - other_level = other.flush_level_.load(); - my_level = flush_level_.exchange(other_level); - other.flush_level_.store(my_level); - - custom_err_handler_.swap(other.custom_err_handler_); - std::swap(tracer_, other.tracer_); -} - -SPDLOG_INLINE void swap(logger &a, logger &b) noexcept { a.swap(b); } - -SPDLOG_INLINE void logger::set_level(level::level_enum log_level) { level_.store(log_level); } - -SPDLOG_INLINE level::level_enum logger::level() const { - return static_cast(level_.load(std::memory_order_relaxed)); -} - -SPDLOG_INLINE const std::string &logger::name() const { return name_; } - -// set formatting for the sinks in this logger. -// each sink will get a separate instance of the formatter object. -SPDLOG_INLINE void logger::set_formatter(std::unique_ptr f) { - for (auto it = sinks_.begin(); it != sinks_.end(); ++it) { - if (std::next(it) == sinks_.end()) { - // last element - we can be move it. - (*it)->set_formatter(std::move(f)); - break; // to prevent clang-tidy warning - } else { - (*it)->set_formatter(f->clone()); - } - } -} - -SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type time_type) { - auto new_formatter = details::make_unique(std::move(pattern), time_type); - set_formatter(std::move(new_formatter)); -} - -// create new backtrace sink and move to it all our child sinks -SPDLOG_INLINE void logger::enable_backtrace(size_t n_messages) { tracer_.enable(n_messages); } - -// restore orig sinks and level and delete the backtrace sink -SPDLOG_INLINE void logger::disable_backtrace() { tracer_.disable(); } - -SPDLOG_INLINE void logger::dump_backtrace() { dump_backtrace_(); } - -// flush functions -SPDLOG_INLINE void logger::flush() { flush_(); } - -SPDLOG_INLINE void logger::flush_on(level::level_enum log_level) { flush_level_.store(log_level); } - -SPDLOG_INLINE level::level_enum logger::flush_level() const { - return static_cast(flush_level_.load(std::memory_order_relaxed)); -} - -// sinks -SPDLOG_INLINE const std::vector &logger::sinks() const { return sinks_; } - -SPDLOG_INLINE std::vector &logger::sinks() { return sinks_; } - -// error handler -SPDLOG_INLINE void logger::set_error_handler(err_handler handler) { - custom_err_handler_ = std::move(handler); -} - -// create new logger with same sinks and configuration. -SPDLOG_INLINE std::shared_ptr logger::clone(std::string logger_name) { - auto cloned = std::make_shared(*this); - cloned->name_ = std::move(logger_name); - return cloned; -} - -// protected methods -SPDLOG_INLINE void logger::log_it_(const spdlog::details::log_msg &log_msg, - bool log_enabled, - bool traceback_enabled) { - if (log_enabled) { - sink_it_(log_msg); - } - if (traceback_enabled) { - tracer_.push_back(log_msg); - } -} - -SPDLOG_INLINE void logger::sink_it_(const details::log_msg &msg) { - for (auto &sink : sinks_) { - if (sink->should_log(msg.level)) { - SPDLOG_TRY { sink->log(msg); } - SPDLOG_LOGGER_CATCH(msg.source) - } - } - - if (should_flush_(msg)) { - flush_(); - } -} - -SPDLOG_INLINE void logger::flush_() { - for (auto &sink : sinks_) { - SPDLOG_TRY { sink->flush(); } - SPDLOG_LOGGER_CATCH(source_loc()) - } -} - -SPDLOG_INLINE void logger::dump_backtrace_() { - using details::log_msg; - if (tracer_.enabled() && !tracer_.empty()) { - sink_it_( - log_msg{name(), level::info, "****************** Backtrace Start ******************"}); - tracer_.foreach_pop([this](const log_msg &msg) { this->sink_it_(msg); }); - sink_it_( - log_msg{name(), level::info, "****************** Backtrace End ********************"}); - } -} - -SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg) const { - auto flush_level = flush_level_.load(std::memory_order_relaxed); - return (msg.level >= flush_level) && (msg.level != level::off); -} - -SPDLOG_INLINE void logger::err_handler_(const std::string &msg) const { - if (custom_err_handler_) { - custom_err_handler_(msg); - } else { - using std::chrono::system_clock; - static std::mutex mutex; - static std::chrono::system_clock::time_point last_report_time; - static size_t err_counter = 0; - std::lock_guard lk{mutex}; - auto now = system_clock::now(); - err_counter++; - if (now - last_report_time < std::chrono::seconds(1)) { - return; - } - last_report_time = now; - auto tm_time = details::os::localtime(system_clock::to_time_t(now)); - char date_buf[64]; - std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time); -#if defined(USING_R) && defined(R_R_H) // if in R environment - REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), - msg.c_str()); -#else - std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, - name().c_str(), msg.c_str()); -#endif - } -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/logger.h b/examples/blueprints-example/external/logger.h deleted file mode 100644 index 8c3cd91..0000000 --- a/examples/blueprints-example/external/logger.h +++ /dev/null @@ -1,379 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Thread safe logger (except for set_error_handler()) -// Has name, log level, vector of std::shared sink pointers and formatter -// Upon each log write the logger: -// 1. Checks if its log level is enough to log the message and if yes: -// 2. Call the underlying sinks to do the job. -// 3. Each sink use its own private copy of a formatter to format the message -// and send to its destination. -// -// The use of private formatter per sink provides the opportunity to cache some -// formatted data, and support for different format per sink. - -#include -#include -#include - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - #ifndef _WIN32 - #error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows - #endif - #include -#endif - -#include - -#ifndef SPDLOG_NO_EXCEPTIONS - #define SPDLOG_LOGGER_CATCH(location) \ - catch (const std::exception &ex) { \ - if (location.filename) { \ - err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), \ - location.filename, location.line)); \ - } else { \ - err_handler_(ex.what()); \ - } \ - } \ - catch (...) { \ - err_handler_("Rethrowing unknown exception in logger"); \ - throw; \ - } -#else - #define SPDLOG_LOGGER_CATCH(location) -#endif - -namespace spdlog { - -class SPDLOG_API logger { -public: - // Empty logger - explicit logger(std::string name) - : name_(std::move(name)), - sinks_() {} - - // Logger with range on sinks - template - logger(std::string name, It begin, It end) - : name_(std::move(name)), - sinks_(begin, end) {} - - // Logger with single sink - logger(std::string name, sink_ptr single_sink) - : logger(std::move(name), {std::move(single_sink)}) {} - - // Logger with sinks init list - logger(std::string name, sinks_init_list sinks) - : logger(std::move(name), sinks.begin(), sinks.end()) {} - - virtual ~logger() = default; - - logger(const logger &other); - logger(logger &&other) SPDLOG_NOEXCEPT; - logger &operator=(logger other) SPDLOG_NOEXCEPT; - void swap(spdlog::logger &other) SPDLOG_NOEXCEPT; - - template - void log(source_loc loc, level::level_enum lvl, format_string_t fmt, Args &&...args) { - log_(loc, lvl, details::to_string_view(fmt), std::forward(args)...); - } - - template - void log(level::level_enum lvl, format_string_t fmt, Args &&...args) { - log(source_loc{}, lvl, fmt, std::forward(args)...); - } - - template - void log(level::level_enum lvl, const T &msg) { - log(source_loc{}, lvl, msg); - } - - // T cannot be statically converted to format string (including string_view/wstring_view) - template ::value, - int>::type = 0> - void log(source_loc loc, level::level_enum lvl, const T &msg) { - log(loc, lvl, "{}", msg); - } - - void log(log_clock::time_point log_time, - source_loc loc, - level::level_enum lvl, - string_view_t msg) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - - details::log_msg log_msg(log_time, loc, name_, lvl, msg); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(source_loc loc, level::level_enum lvl, string_view_t msg) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - - details::log_msg log_msg(loc, name_, lvl, msg); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(level::level_enum lvl, string_view_t msg) { log(source_loc{}, lvl, msg); } - - template - void trace(format_string_t fmt, Args &&...args) { - log(level::trace, fmt, std::forward(args)...); - } - - template - void debug(format_string_t fmt, Args &&...args) { - log(level::debug, fmt, std::forward(args)...); - } - - template - void info(format_string_t fmt, Args &&...args) { - log(level::info, fmt, std::forward(args)...); - } - - template - void warn(format_string_t fmt, Args &&...args) { - log(level::warn, fmt, std::forward(args)...); - } - - template - void error(format_string_t fmt, Args &&...args) { - log(level::err, fmt, std::forward(args)...); - } - - template - void critical(format_string_t fmt, Args &&...args) { - log(level::critical, fmt, std::forward(args)...); - } - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - template - void log(source_loc loc, level::level_enum lvl, wformat_string_t fmt, Args &&...args) { - log_(loc, lvl, details::to_string_view(fmt), std::forward(args)...); - } - - template - void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) { - log(source_loc{}, lvl, fmt, std::forward(args)...); - } - - void log(log_clock::time_point log_time, - source_loc loc, - level::level_enum lvl, - wstring_view_t msg) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(msg.data(), msg.size()), buf); - details::log_msg log_msg(log_time, loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(source_loc loc, level::level_enum lvl, wstring_view_t msg) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(msg.data(), msg.size()), buf); - details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(level::level_enum lvl, wstring_view_t msg) { log(source_loc{}, lvl, msg); } - - template - void trace(wformat_string_t fmt, Args &&...args) { - log(level::trace, fmt, std::forward(args)...); - } - - template - void debug(wformat_string_t fmt, Args &&...args) { - log(level::debug, fmt, std::forward(args)...); - } - - template - void info(wformat_string_t fmt, Args &&...args) { - log(level::info, fmt, std::forward(args)...); - } - - template - void warn(wformat_string_t fmt, Args &&...args) { - log(level::warn, fmt, std::forward(args)...); - } - - template - void error(wformat_string_t fmt, Args &&...args) { - log(level::err, fmt, std::forward(args)...); - } - - template - void critical(wformat_string_t fmt, Args &&...args) { - log(level::critical, fmt, std::forward(args)...); - } -#endif - - template - void trace(const T &msg) { - log(level::trace, msg); - } - - template - void debug(const T &msg) { - log(level::debug, msg); - } - - template - void info(const T &msg) { - log(level::info, msg); - } - - template - void warn(const T &msg) { - log(level::warn, msg); - } - - template - void error(const T &msg) { - log(level::err, msg); - } - - template - void critical(const T &msg) { - log(level::critical, msg); - } - - // return true logging is enabled for the given level. - bool should_log(level::level_enum msg_level) const { - return msg_level >= level_.load(std::memory_order_relaxed); - } - - // return true if backtrace logging is enabled. - bool should_backtrace() const { return tracer_.enabled(); } - - void set_level(level::level_enum log_level); - - level::level_enum level() const; - - const std::string &name() const; - - // set formatting for the sinks in this logger. - // each sink will get a separate instance of the formatter object. - void set_formatter(std::unique_ptr f); - - // set formatting for the sinks in this logger. - // equivalent to - // set_formatter(make_unique(pattern, time_type)) - // Note: each sink will get a new instance of a formatter object, replacing the old one. - void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local); - - // backtrace support. - // efficiently store all debug/trace messages in a circular buffer until needed for debugging. - void enable_backtrace(size_t n_messages); - void disable_backtrace(); - void dump_backtrace(); - - // flush functions - void flush(); - void flush_on(level::level_enum log_level); - level::level_enum flush_level() const; - - // sinks - const std::vector &sinks() const; - - std::vector &sinks(); - - // error handler - void set_error_handler(err_handler); - - // create new logger with same sinks and configuration. - virtual std::shared_ptr clone(std::string logger_name); - -protected: - std::string name_; - std::vector sinks_; - spdlog::level_t level_{level::info}; - spdlog::level_t flush_level_{level::off}; - err_handler custom_err_handler_{nullptr}; - details::backtracer tracer_; - - // common implementation for after templated public api has been resolved - template - void log_(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&...args) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - SPDLOG_TRY { - memory_buf_t buf; -#ifdef SPDLOG_USE_STD_FORMAT - fmt_lib::vformat_to(std::back_inserter(buf), fmt, fmt_lib::make_format_args(args...)); -#else - fmt::vformat_to(fmt::appender(buf), fmt, fmt::make_format_args(args...)); -#endif - - details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - SPDLOG_LOGGER_CATCH(loc) - } - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - template - void log_(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args &&...args) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - SPDLOG_TRY { - // format to wmemory_buffer and convert to utf8 - wmemory_buf_t wbuf; - fmt_lib::vformat_to(std::back_inserter(wbuf), fmt, - fmt_lib::make_format_args(args...)); - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf); - details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - SPDLOG_LOGGER_CATCH(loc) - } -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT - - // log the given message (if the given log level is high enough), - // and save backtrace (if backtrace is enabled). - void log_it_(const details::log_msg &log_msg, bool log_enabled, bool traceback_enabled); - virtual void sink_it_(const details::log_msg &msg); - virtual void flush_(); - void dump_backtrace_(); - bool should_flush_(const details::log_msg &msg) const; - - // handle errors during logging. - // default handler prints the error to stderr at max rate of 1 message/sec. - void err_handler_(const std::string &msg) const; -}; - -void swap(logger &a, logger &b) noexcept; - -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "logger-inl.h" -#endif diff --git a/examples/blueprints-example/external/mdc.h b/examples/blueprints-example/external/mdc.h deleted file mode 100644 index bc13174..0000000 --- a/examples/blueprints-example/external/mdc.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#if defined(SPDLOG_NO_TLS) - #error "This header requires thread local storage support, but SPDLOG_NO_TLS is defined." -#endif - -#include -#include - -#include - -// MDC is a simple map of key->string values stored in thread local storage whose content will be -// printed by the loggers. Note: Not supported in async mode (thread local storage - so the async -// thread pool have different copy). -// -// Usage example: -// spdlog::mdc::put("mdc_key_1", "mdc_value_1"); -// spdlog::info("Hello, {}", "World!"); // => [2024-04-26 02:08:05.040] [info] -// [mdc_key_1:mdc_value_1] Hello, World! - -namespace spdlog { -class SPDLOG_API mdc { -public: - using mdc_map_t = std::map; - - static void put(const std::string &key, const std::string &value) { - get_context()[key] = value; - } - - static std::string get(const std::string &key) { - auto &context = get_context(); - auto it = context.find(key); - if (it != context.end()) { - return it->second; - } - return ""; - } - - static void remove(const std::string &key) { get_context().erase(key); } - - static void clear() { get_context().clear(); } - - static mdc_map_t &get_context() { - static thread_local mdc_map_t context; - return context; - } -}; - -} // namespace spdlog diff --git a/examples/blueprints-example/external/pattern_formatter-inl.h b/examples/blueprints-example/external/pattern_formatter-inl.h deleted file mode 100644 index fd408ed..0000000 --- a/examples/blueprints-example/external/pattern_formatter-inl.h +++ /dev/null @@ -1,1340 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include -#include - -#ifndef SPDLOG_NO_TLS - #include -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace spdlog { -namespace details { - -/////////////////////////////////////////////////////////////////////// -// name & level pattern appender -/////////////////////////////////////////////////////////////////////// - -class scoped_padder { -public: - scoped_padder(size_t wrapped_size, const padding_info &padinfo, memory_buf_t &dest) - : padinfo_(padinfo), - dest_(dest) { - remaining_pad_ = static_cast(padinfo.width_) - static_cast(wrapped_size); - if (remaining_pad_ <= 0) { - return; - } - - if (padinfo_.side_ == padding_info::pad_side::left) { - pad_it(remaining_pad_); - remaining_pad_ = 0; - } else if (padinfo_.side_ == padding_info::pad_side::center) { - auto half_pad = remaining_pad_ / 2; - auto reminder = remaining_pad_ & 1; - pad_it(half_pad); - remaining_pad_ = half_pad + reminder; // for the right side - } - } - - template - static unsigned int count_digits(T n) { - return fmt_helper::count_digits(n); - } - - ~scoped_padder() { - if (remaining_pad_ >= 0) { - pad_it(remaining_pad_); - } else if (padinfo_.truncate_) { - long new_size = static_cast(dest_.size()) + remaining_pad_; - if (new_size < 0) { - new_size = 0; - } - dest_.resize(static_cast(new_size)); - } - } - -private: - void pad_it(long count) { - fmt_helper::append_string_view(string_view_t(spaces_.data(), static_cast(count)), - dest_); - } - - const padding_info &padinfo_; - memory_buf_t &dest_; - long remaining_pad_; - string_view_t spaces_{" ", 64}; -}; - -struct null_scoped_padder { - null_scoped_padder(size_t /*wrapped_size*/, - const padding_info & /*padinfo*/, - memory_buf_t & /*dest*/) {} - - template - static unsigned int count_digits(T /* number */) { - return 0; - } -}; - -template -class name_formatter final : public flag_formatter { -public: - explicit name_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - ScopedPadder p(msg.logger_name.size(), padinfo_, dest); - fmt_helper::append_string_view(msg.logger_name, dest); - } -}; - -// log level appender -template -class level_formatter final : public flag_formatter { -public: - explicit level_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - const string_view_t &level_name = level::to_string_view(msg.level); - ScopedPadder p(level_name.size(), padinfo_, dest); - fmt_helper::append_string_view(level_name, dest); - } -}; - -// short log level appender -template -class short_level_formatter final : public flag_formatter { -public: - explicit short_level_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - string_view_t level_name{level::to_short_c_str(msg.level)}; - ScopedPadder p(level_name.size(), padinfo_, dest); - fmt_helper::append_string_view(level_name, dest); - } -}; - -/////////////////////////////////////////////////////////////////////// -// Date time pattern appenders -/////////////////////////////////////////////////////////////////////// - -static const char *ampm(const tm &t) { return t.tm_hour >= 12 ? "PM" : "AM"; } - -static int to12h(const tm &t) { return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour; } - -// Abbreviated weekday name -static std::array days{{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}}; - -template -class a_formatter final : public flag_formatter { -public: - explicit a_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - string_view_t field_value{days[static_cast(tm_time.tm_wday)]}; - ScopedPadder p(field_value.size(), padinfo_, dest); - fmt_helper::append_string_view(field_value, dest); - } -}; - -// Full weekday name -static std::array full_days{ - {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}}; - -template -class A_formatter : public flag_formatter { -public: - explicit A_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - string_view_t field_value{full_days[static_cast(tm_time.tm_wday)]}; - ScopedPadder p(field_value.size(), padinfo_, dest); - fmt_helper::append_string_view(field_value, dest); - } -}; - -// Abbreviated month -static const std::array months{ - {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}}; - -template -class b_formatter final : public flag_formatter { -public: - explicit b_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - string_view_t field_value{months[static_cast(tm_time.tm_mon)]}; - ScopedPadder p(field_value.size(), padinfo_, dest); - fmt_helper::append_string_view(field_value, dest); - } -}; - -// Full month name -static const std::array full_months{{"January", "February", "March", "April", - "May", "June", "July", "August", "September", - "October", "November", "December"}}; - -template -class B_formatter final : public flag_formatter { -public: - explicit B_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - string_view_t field_value{full_months[static_cast(tm_time.tm_mon)]}; - ScopedPadder p(field_value.size(), padinfo_, dest); - fmt_helper::append_string_view(field_value, dest); - } -}; - -// Date and time representation (Thu Aug 23 15:35:46 2014) -template -class c_formatter final : public flag_formatter { -public: - explicit c_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 24; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::append_string_view(days[static_cast(tm_time.tm_wday)], dest); - dest.push_back(' '); - fmt_helper::append_string_view(months[static_cast(tm_time.tm_mon)], dest); - dest.push_back(' '); - fmt_helper::append_int(tm_time.tm_mday, dest); - dest.push_back(' '); - // time - - fmt_helper::pad2(tm_time.tm_hour, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_min, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_sec, dest); - dest.push_back(' '); - fmt_helper::append_int(tm_time.tm_year + 1900, dest); - } -}; - -// year - 2 digit -template -class C_formatter final : public flag_formatter { -public: - explicit C_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_year % 100, dest); - } -}; - -// Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01 -template -class D_formatter final : public flag_formatter { -public: - explicit D_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 8; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::pad2(tm_time.tm_mon + 1, dest); - dest.push_back('/'); - fmt_helper::pad2(tm_time.tm_mday, dest); - dest.push_back('/'); - fmt_helper::pad2(tm_time.tm_year % 100, dest); - } -}; - -// year - 4 digit -template -class Y_formatter final : public flag_formatter { -public: - explicit Y_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 4; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_int(tm_time.tm_year + 1900, dest); - } -}; - -// month 1-12 -template -class m_formatter final : public flag_formatter { -public: - explicit m_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_mon + 1, dest); - } -}; - -// day of month 1-31 -template -class d_formatter final : public flag_formatter { -public: - explicit d_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_mday, dest); - } -}; - -// hours in 24 format 0-23 -template -class H_formatter final : public flag_formatter { -public: - explicit H_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_hour, dest); - } -}; - -// hours in 12 format 1-12 -template -class I_formatter final : public flag_formatter { -public: - explicit I_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(to12h(tm_time), dest); - } -}; - -// minutes 0-59 -template -class M_formatter final : public flag_formatter { -public: - explicit M_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_min, dest); - } -}; - -// seconds 0-59 -template -class S_formatter final : public flag_formatter { -public: - explicit S_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_sec, dest); - } -}; - -// milliseconds -template -class e_formatter final : public flag_formatter { -public: - explicit e_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - auto millis = fmt_helper::time_fraction(msg.time); - const size_t field_size = 3; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad3(static_cast(millis.count()), dest); - } -}; - -// microseconds -template -class f_formatter final : public flag_formatter { -public: - explicit f_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - auto micros = fmt_helper::time_fraction(msg.time); - - const size_t field_size = 6; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad6(static_cast(micros.count()), dest); - } -}; - -// nanoseconds -template -class F_formatter final : public flag_formatter { -public: - explicit F_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - auto ns = fmt_helper::time_fraction(msg.time); - const size_t field_size = 9; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad9(static_cast(ns.count()), dest); - } -}; - -// seconds since epoch -template -class E_formatter final : public flag_formatter { -public: - explicit E_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - const size_t field_size = 10; - ScopedPadder p(field_size, padinfo_, dest); - auto duration = msg.time.time_since_epoch(); - auto seconds = std::chrono::duration_cast(duration).count(); - fmt_helper::append_int(seconds, dest); - } -}; - -// AM/PM -template -class p_formatter final : public flag_formatter { -public: - explicit p_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_string_view(ampm(tm_time), dest); - } -}; - -// 12 hour clock 02:55:02 pm -template -class r_formatter final : public flag_formatter { -public: - explicit r_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 11; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::pad2(to12h(tm_time), dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_min, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_sec, dest); - dest.push_back(' '); - fmt_helper::append_string_view(ampm(tm_time), dest); - } -}; - -// 24-hour HH:MM time, equivalent to %H:%M -template -class R_formatter final : public flag_formatter { -public: - explicit R_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 5; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::pad2(tm_time.tm_hour, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_min, dest); - } -}; - -// ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S -template -class T_formatter final : public flag_formatter { -public: - explicit T_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 8; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::pad2(tm_time.tm_hour, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_min, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_sec, dest); - } -}; - -// ISO 8601 offset from UTC in timezone (+-HH:MM) -template -class z_formatter final : public flag_formatter { -public: - explicit z_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - z_formatter() = default; - z_formatter(const z_formatter &) = delete; - z_formatter &operator=(const z_formatter &) = delete; - - void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 6; - ScopedPadder p(field_size, padinfo_, dest); - - auto total_minutes = get_cached_offset(msg, tm_time); - bool is_negative = total_minutes < 0; - if (is_negative) { - total_minutes = -total_minutes; - dest.push_back('-'); - } else { - dest.push_back('+'); - } - - fmt_helper::pad2(total_minutes / 60, dest); // hours - dest.push_back(':'); - fmt_helper::pad2(total_minutes % 60, dest); // minutes - } - -private: - log_clock::time_point last_update_{std::chrono::seconds(0)}; - int offset_minutes_{0}; - - int get_cached_offset(const log_msg &msg, const std::tm &tm_time) { - // refresh every 10 seconds - if (msg.time - last_update_ >= std::chrono::seconds(10)) { - offset_minutes_ = os::utc_minutes_offset(tm_time); - last_update_ = msg.time; - } - return offset_minutes_; - } -}; - -// Thread id -template -class t_formatter final : public flag_formatter { -public: - explicit t_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - const auto field_size = ScopedPadder::count_digits(msg.thread_id); - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_int(msg.thread_id, dest); - } -}; - -// Current pid -template -class pid_formatter final : public flag_formatter { -public: - explicit pid_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { - const auto pid = static_cast(details::os::pid()); - auto field_size = ScopedPadder::count_digits(pid); - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_int(pid, dest); - } -}; - -template -class v_formatter final : public flag_formatter { -public: - explicit v_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - ScopedPadder p(msg.payload.size(), padinfo_, dest); - fmt_helper::append_string_view(msg.payload, dest); - } -}; - -class ch_formatter final : public flag_formatter { -public: - explicit ch_formatter(char ch) - : ch_(ch) {} - - void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { - dest.push_back(ch_); - } - -private: - char ch_; -}; - -// aggregate user chars to display as is -class aggregate_formatter final : public flag_formatter { -public: - aggregate_formatter() = default; - - void add_ch(char ch) { str_ += ch; } - void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { - fmt_helper::append_string_view(str_, dest); - } - -private: - std::string str_; -}; - -// mark the color range. expect it to be in the form of "%^colored text%$" -class color_start_formatter final : public flag_formatter { -public: - explicit color_start_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - msg.color_range_start = dest.size(); - } -}; - -class color_stop_formatter final : public flag_formatter { -public: - explicit color_stop_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - msg.color_range_end = dest.size(); - } -}; - -// print source location -template -class source_location_formatter final : public flag_formatter { -public: - explicit source_location_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - - size_t text_size; - if (padinfo_.enabled()) { - // calc text size for padding based on "filename:line" - text_size = std::char_traits::length(msg.source.filename) + - ScopedPadder::count_digits(msg.source.line) + 1; - } else { - text_size = 0; - } - - ScopedPadder p(text_size, padinfo_, dest); - fmt_helper::append_string_view(msg.source.filename, dest); - dest.push_back(':'); - fmt_helper::append_int(msg.source.line, dest); - } -}; - -// print source filename -template -class source_filename_formatter final : public flag_formatter { -public: - explicit source_filename_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - size_t text_size = - padinfo_.enabled() ? std::char_traits::length(msg.source.filename) : 0; - ScopedPadder p(text_size, padinfo_, dest); - fmt_helper::append_string_view(msg.source.filename, dest); - } -}; - -template -class short_filename_formatter final : public flag_formatter { -public: - explicit short_filename_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - -#ifdef _MSC_VER - #pragma warning(push) - #pragma warning(disable : 4127) // consider using 'if constexpr' instead -#endif // _MSC_VER - static const char *basename(const char *filename) { - // if the size is 2 (1 character + null terminator) we can use the more efficient strrchr - // the branch will be elided by optimizations - if (sizeof(os::folder_seps) == 2) { - const char *rv = std::strrchr(filename, os::folder_seps[0]); - return rv != nullptr ? rv + 1 : filename; - } else { - const std::reverse_iterator begin(filename + std::strlen(filename)); - const std::reverse_iterator end(filename); - - const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), - std::end(os::folder_seps) - 1); - return it != end ? it.base() : filename; - } - } -#ifdef _MSC_VER - #pragma warning(pop) -#endif // _MSC_VER - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - auto filename = basename(msg.source.filename); - size_t text_size = padinfo_.enabled() ? std::char_traits::length(filename) : 0; - ScopedPadder p(text_size, padinfo_, dest); - fmt_helper::append_string_view(filename, dest); - } -}; - -template -class source_linenum_formatter final : public flag_formatter { -public: - explicit source_linenum_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - - auto field_size = ScopedPadder::count_digits(msg.source.line); - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_int(msg.source.line, dest); - } -}; - -// print source funcname -template -class source_funcname_formatter final : public flag_formatter { -public: - explicit source_funcname_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - size_t text_size = - padinfo_.enabled() ? std::char_traits::length(msg.source.funcname) : 0; - ScopedPadder p(text_size, padinfo_, dest); - fmt_helper::append_string_view(msg.source.funcname, dest); - } -}; - -// print elapsed time since last message -template -class elapsed_formatter final : public flag_formatter { -public: - using DurationUnits = Units; - - explicit elapsed_formatter(padding_info padinfo) - : flag_formatter(padinfo), - last_message_time_(log_clock::now()) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); - auto delta_units = std::chrono::duration_cast(delta); - last_message_time_ = msg.time; - auto delta_count = static_cast(delta_units.count()); - auto n_digits = static_cast(ScopedPadder::count_digits(delta_count)); - ScopedPadder p(n_digits, padinfo_, dest); - fmt_helper::append_int(delta_count, dest); - } - -private: - log_clock::time_point last_message_time_; -}; - -// Class for formatting Mapped Diagnostic Context (MDC) in log messages. -// Example: [logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message -#ifndef SPDLOG_NO_TLS -template -class mdc_formatter : public flag_formatter { -public: - explicit mdc_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { - auto &mdc_map = mdc::get_context(); - if (mdc_map.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } else { - format_mdc(mdc_map, dest); - } - } - - void format_mdc(const mdc::mdc_map_t &mdc_map, memory_buf_t &dest) { - auto last_element = --mdc_map.end(); - for (auto it = mdc_map.begin(); it != mdc_map.end(); ++it) { - auto &pair = *it; - const auto &key = pair.first; - const auto &value = pair.second; - size_t content_size = key.size() + value.size() + 1; // 1 for ':' - - if (it != last_element) { - content_size++; // 1 for ' ' - } - - ScopedPadder p(content_size, padinfo_, dest); - fmt_helper::append_string_view(key, dest); - fmt_helper::append_string_view(":", dest); - fmt_helper::append_string_view(value, dest); - if (it != last_element) { - fmt_helper::append_string_view(" ", dest); - } - } - } -}; -#endif - -// Full info formatter -// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v -class full_formatter final : public flag_formatter { -public: - explicit full_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override { - using std::chrono::duration_cast; - using std::chrono::milliseconds; - using std::chrono::seconds; - - // cache the date/time part for the next second. - auto duration = msg.time.time_since_epoch(); - auto secs = duration_cast(duration); - - if (cache_timestamp_ != secs || cached_datetime_.size() == 0) { - cached_datetime_.clear(); - cached_datetime_.push_back('['); - fmt_helper::append_int(tm_time.tm_year + 1900, cached_datetime_); - cached_datetime_.push_back('-'); - - fmt_helper::pad2(tm_time.tm_mon + 1, cached_datetime_); - cached_datetime_.push_back('-'); - - fmt_helper::pad2(tm_time.tm_mday, cached_datetime_); - cached_datetime_.push_back(' '); - - fmt_helper::pad2(tm_time.tm_hour, cached_datetime_); - cached_datetime_.push_back(':'); - - fmt_helper::pad2(tm_time.tm_min, cached_datetime_); - cached_datetime_.push_back(':'); - - fmt_helper::pad2(tm_time.tm_sec, cached_datetime_); - cached_datetime_.push_back('.'); - - cache_timestamp_ = secs; - } - dest.append(cached_datetime_.begin(), cached_datetime_.end()); - - auto millis = fmt_helper::time_fraction(msg.time); - fmt_helper::pad3(static_cast(millis.count()), dest); - dest.push_back(']'); - dest.push_back(' '); - - // append logger name if exists - if (msg.logger_name.size() > 0) { - dest.push_back('['); - fmt_helper::append_string_view(msg.logger_name, dest); - dest.push_back(']'); - dest.push_back(' '); - } - - dest.push_back('['); - // wrap the level name with color - msg.color_range_start = dest.size(); - // fmt_helper::append_string_view(level::to_c_str(msg.level), dest); - fmt_helper::append_string_view(level::to_string_view(msg.level), dest); - msg.color_range_end = dest.size(); - dest.push_back(']'); - dest.push_back(' '); - - // add source location if present - if (!msg.source.empty()) { - dest.push_back('['); - const char *filename = - details::short_filename_formatter::basename( - msg.source.filename); - fmt_helper::append_string_view(filename, dest); - dest.push_back(':'); - fmt_helper::append_int(msg.source.line, dest); - dest.push_back(']'); - dest.push_back(' '); - } - -#ifndef SPDLOG_NO_TLS - // add mdc if present - auto &mdc_map = mdc::get_context(); - if (!mdc_map.empty()) { - dest.push_back('['); - mdc_formatter_.format_mdc(mdc_map, dest); - dest.push_back(']'); - dest.push_back(' '); - } -#endif - // fmt_helper::append_string_view(msg.msg(), dest); - fmt_helper::append_string_view(msg.payload, dest); - } - -private: - std::chrono::seconds cache_timestamp_{0}; - memory_buf_t cached_datetime_; - -#ifndef SPDLOG_NO_TLS - mdc_formatter mdc_formatter_{padding_info {}}; -#endif -}; - -} // namespace details - -SPDLOG_INLINE pattern_formatter::pattern_formatter(std::string pattern, - pattern_time_type time_type, - std::string eol, - custom_flags custom_user_flags) - : pattern_(std::move(pattern)), - eol_(std::move(eol)), - pattern_time_type_(time_type), - need_localtime_(false), - last_log_secs_(0), - custom_handlers_(std::move(custom_user_flags)) { - std::memset(&cached_tm_, 0, sizeof(cached_tm_)); - compile_pattern_(pattern_); -} - -// use by default full formatter for if pattern is not given -SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type, std::string eol) - : pattern_("%+"), - eol_(std::move(eol)), - pattern_time_type_(time_type), - need_localtime_(true), - last_log_secs_(0) { - std::memset(&cached_tm_, 0, sizeof(cached_tm_)); - formatters_.push_back(details::make_unique(details::padding_info{})); -} - -SPDLOG_INLINE std::unique_ptr pattern_formatter::clone() const { - custom_flags cloned_custom_formatters; - for (auto &it : custom_handlers_) { - cloned_custom_formatters[it.first] = it.second->clone(); - } - auto cloned = details::make_unique(pattern_, pattern_time_type_, eol_, - std::move(cloned_custom_formatters)); - cloned->need_localtime(need_localtime_); -#if defined(__GNUC__) && __GNUC__ < 5 - return std::move(cloned); -#else - return cloned; -#endif -} - -SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest) { - if (need_localtime_) { - const auto secs = - std::chrono::duration_cast(msg.time.time_since_epoch()); - if (secs != last_log_secs_) { - cached_tm_ = get_time_(msg); - last_log_secs_ = secs; - } - } - - for (auto &f : formatters_) { - f->format(msg, cached_tm_, dest); - } - // write eol - details::fmt_helper::append_string_view(eol_, dest); -} - -SPDLOG_INLINE void pattern_formatter::set_pattern(std::string pattern) { - pattern_ = std::move(pattern); - need_localtime_ = false; - compile_pattern_(pattern_); -} - -SPDLOG_INLINE void pattern_formatter::need_localtime(bool need) { need_localtime_ = need; } - -SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg) { - if (pattern_time_type_ == pattern_time_type::local) { - return details::os::localtime(log_clock::to_time_t(msg.time)); - } - return details::os::gmtime(log_clock::to_time_t(msg.time)); -} - -template -SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding) { - // process custom flags - auto it = custom_handlers_.find(flag); - if (it != custom_handlers_.end()) { - auto custom_handler = it->second->clone(); - custom_handler->set_padding_info(padding); - formatters_.push_back(std::move(custom_handler)); - return; - } - - // process built-in flags - switch (flag) { - case ('+'): // default formatter - formatters_.push_back(details::make_unique(padding)); - need_localtime_ = true; - break; - - case 'n': // logger name - formatters_.push_back(details::make_unique>(padding)); - break; - - case 'l': // level - formatters_.push_back(details::make_unique>(padding)); - break; - - case 'L': // short level - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('t'): // thread id - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('v'): // the message text - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('a'): // weekday - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('A'): // short weekday - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('b'): - case ('h'): // month - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('B'): // short month - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('c'): // datetime - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('C'): // year 2 digits - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('Y'): // year 4 digits - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('D'): - case ('x'): // datetime MM/DD/YY - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('m'): // month 1-12 - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('d'): // day of month 1-31 - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('H'): // hours 24 - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('I'): // hours 12 - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('M'): // minutes - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('S'): // seconds - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('e'): // milliseconds - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('f'): // microseconds - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('F'): // nanoseconds - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('E'): // seconds since epoch - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('p'): // am/pm - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('r'): // 12 hour clock 02:55:02 pm - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('R'): // 24-hour HH:MM time - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('T'): - case ('X'): // ISO 8601 time format (HH:MM:SS) - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('z'): // timezone - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('P'): // pid - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('^'): // color range start - formatters_.push_back(details::make_unique(padding)); - break; - - case ('$'): // color range end - formatters_.push_back(details::make_unique(padding)); - break; - - case ('@'): // source location (filename:filenumber) - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('s'): // short source filename - without directory name - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('g'): // full source filename - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('#'): // source line number - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('!'): // source funcname - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('%'): // % char - formatters_.push_back(details::make_unique('%')); - break; - - case ('u'): // elapsed time since last log message in nanos - formatters_.push_back( - details::make_unique>( - padding)); - break; - - case ('i'): // elapsed time since last log message in micros - formatters_.push_back( - details::make_unique>( - padding)); - break; - - case ('o'): // elapsed time since last log message in millis - formatters_.push_back( - details::make_unique>( - padding)); - break; - - case ('O'): // elapsed time since last log message in seconds - formatters_.push_back( - details::make_unique>( - padding)); - break; - -#ifndef SPDLOG_NO_TLS // mdc formatter requires TLS support - case ('&'): - formatters_.push_back(details::make_unique>(padding)); - break; -#endif - - default: // Unknown flag appears as is - auto unknown_flag = details::make_unique(); - - if (!padding.truncate_) { - unknown_flag->add_ch('%'); - unknown_flag->add_ch(flag); - formatters_.push_back((std::move(unknown_flag))); - } - // fix issue #1617 (prev char was '!' and should have been treated as funcname flag - // instead of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some - // message" spdlog::set_pattern("[%3!!] %v") => "[mai] some message" - else { - padding.truncate_ = false; - formatters_.push_back( - details::make_unique>(padding)); - unknown_flag->add_ch(flag); - formatters_.push_back((std::move(unknown_flag))); - } - - break; - } -} - -// Extract given pad spec (e.g. %8X, %=8X, %-8!X, %8!X, %=8!X, %-8!X, %+8!X) -// Advance the given it pass the end of the padding spec found (if any) -// Return padding. -SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_( - std::string::const_iterator &it, std::string::const_iterator end) { - using details::padding_info; - using details::scoped_padder; - const size_t max_width = 64; - if (it == end) { - return padding_info{}; - } - - padding_info::pad_side side; - switch (*it) { - case '-': - side = padding_info::pad_side::right; - ++it; - break; - case '=': - side = padding_info::pad_side::center; - ++it; - break; - default: - side = details::padding_info::pad_side::left; - break; - } - - if (it == end || !std::isdigit(static_cast(*it))) { - return padding_info{}; // no padding if no digit found here - } - - auto width = static_cast(*it) - '0'; - for (++it; it != end && std::isdigit(static_cast(*it)); ++it) { - auto digit = static_cast(*it) - '0'; - width = width * 10 + digit; - } - - // search for the optional truncate marker '!' - bool truncate; - if (it != end && *it == '!') { - truncate = true; - ++it; - } else { - truncate = false; - } - return details::padding_info{std::min(width, max_width), side, truncate}; -} - -SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &pattern) { - auto end = pattern.end(); - std::unique_ptr user_chars; - formatters_.clear(); - for (auto it = pattern.begin(); it != end; ++it) { - if (*it == '%') { - if (user_chars) // append user chars found so far - { - formatters_.push_back(std::move(user_chars)); - } - - auto padding = handle_padspec_(++it, end); - - if (it != end) { - if (padding.enabled()) { - handle_flag_(*it, padding); - } else { - handle_flag_(*it, padding); - } - } else { - break; - } - } else // chars not following the % sign should be displayed as is - { - if (!user_chars) { - user_chars = details::make_unique(); - } - user_chars->add_ch(*it); - } - } - if (user_chars) // append raw chars found so far - { - formatters_.push_back(std::move(user_chars)); - } -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/pattern_formatter.h b/examples/blueprints-example/external/pattern_formatter.h deleted file mode 100644 index ececd67..0000000 --- a/examples/blueprints-example/external/pattern_formatter.h +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -namespace spdlog { -namespace details { - -// padding information. -struct padding_info { - enum class pad_side { left, right, center }; - - padding_info() = default; - padding_info(size_t width, padding_info::pad_side side, bool truncate) - : width_(width), - side_(side), - truncate_(truncate), - enabled_(true) {} - - bool enabled() const { return enabled_; } - size_t width_ = 0; - pad_side side_ = pad_side::left; - bool truncate_ = false; - bool enabled_ = false; -}; - -class SPDLOG_API flag_formatter { -public: - explicit flag_formatter(padding_info padinfo) - : padinfo_(padinfo) {} - flag_formatter() = default; - virtual ~flag_formatter() = default; - virtual void format(const details::log_msg &msg, - const std::tm &tm_time, - memory_buf_t &dest) = 0; - -protected: - padding_info padinfo_; -}; - -} // namespace details - -class SPDLOG_API custom_flag_formatter : public details::flag_formatter { -public: - virtual std::unique_ptr clone() const = 0; - - void set_padding_info(const details::padding_info &padding) { - flag_formatter::padinfo_ = padding; - } -}; - -class SPDLOG_API pattern_formatter final : public formatter { -public: - using custom_flags = std::unordered_map>; - - explicit pattern_formatter(std::string pattern, - pattern_time_type time_type = pattern_time_type::local, - std::string eol = spdlog::details::os::default_eol, - custom_flags custom_user_flags = custom_flags()); - - // use default pattern is not given - explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, - std::string eol = spdlog::details::os::default_eol); - - pattern_formatter(const pattern_formatter &other) = delete; - pattern_formatter &operator=(const pattern_formatter &other) = delete; - - std::unique_ptr clone() const override; - void format(const details::log_msg &msg, memory_buf_t &dest) override; - - template - pattern_formatter &add_flag(char flag, Args &&...args) { - custom_handlers_[flag] = details::make_unique(std::forward(args)...); - return *this; - } - void set_pattern(std::string pattern); - void need_localtime(bool need = true); - -private: - std::string pattern_; - std::string eol_; - pattern_time_type pattern_time_type_; - bool need_localtime_; - std::tm cached_tm_; - std::chrono::seconds last_log_secs_; - std::vector> formatters_; - custom_flags custom_handlers_; - - std::tm get_time_(const details::log_msg &msg); - template - void handle_flag_(char flag, details::padding_info padding); - - // Extract given pad spec (e.g. %8X) - // Advance the given it pass the end of the padding spec found (if any) - // Return padding. - static details::padding_info handle_padspec_(std::string::const_iterator &it, - std::string::const_iterator end); - - void compile_pattern_(const std::string &pattern); -}; -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "pattern_formatter-inl.h" -#endif diff --git a/examples/blueprints-example/external/sinks/android_sink.h b/examples/blueprints-example/external/sinks/android_sink.h deleted file mode 100644 index 4435a56..0000000 --- a/examples/blueprints-example/external/sinks/android_sink.h +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifdef __ANDROID__ - - #include - #include - #include - #include - #include - - #include - #include - #include - #include - #include - #include - - #if !defined(SPDLOG_ANDROID_RETRIES) - #define SPDLOG_ANDROID_RETRIES 2 - #endif - -namespace spdlog { -namespace sinks { - -/* - * Android sink - * (logging using __android_log_write or __android_log_buf_write depending on the specified - * BufferID) - */ -template -class android_sink final : public base_sink { -public: - explicit android_sink(std::string tag = "spdlog", bool use_raw_msg = false) - : tag_(std::move(tag)), - use_raw_msg_(use_raw_msg) {} - -protected: - void sink_it_(const details::log_msg &msg) override { - const android_LogPriority priority = convert_to_android_(msg.level); - memory_buf_t formatted; - if (use_raw_msg_) { - details::fmt_helper::append_string_view(msg.payload, formatted); - } else { - base_sink::formatter_->format(msg, formatted); - } - formatted.push_back('\0'); - const char *msg_output = formatted.data(); - - // See system/core/liblog/logger_write.c for explanation of return value - int ret = android_log(priority, tag_.c_str(), msg_output); - if (ret == -EPERM) { - return; // !__android_log_is_loggable - } - int retry_count = 0; - while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES)) { - details::os::sleep_for_millis(5); - ret = android_log(priority, tag_.c_str(), msg_output); - retry_count++; - } - - if (ret < 0) { - throw_spdlog_ex("logging to Android failed", ret); - } - } - - void flush_() override {} - -private: - // There might be liblog versions used, that do not support __android_log_buf_write. So we only - // compile and link against - // __android_log_buf_write, if user explicitly provides a non-default log buffer. Otherwise, - // when using the default log buffer, always log via __android_log_write. - template - typename std::enable_if(log_id::LOG_ID_MAIN), int>::type android_log( - int prio, const char *tag, const char *text) { - return __android_log_write(prio, tag, text); - } - - template - typename std::enable_if(log_id::LOG_ID_MAIN), int>::type android_log( - int prio, const char *tag, const char *text) { - return __android_log_buf_write(ID, prio, tag, text); - } - - static android_LogPriority convert_to_android_(spdlog::level::level_enum level) { - switch (level) { - case spdlog::level::trace: - return ANDROID_LOG_VERBOSE; - case spdlog::level::debug: - return ANDROID_LOG_DEBUG; - case spdlog::level::info: - return ANDROID_LOG_INFO; - case spdlog::level::warn: - return ANDROID_LOG_WARN; - case spdlog::level::err: - return ANDROID_LOG_ERROR; - case spdlog::level::critical: - return ANDROID_LOG_FATAL; - default: - return ANDROID_LOG_DEFAULT; - } - } - - std::string tag_; - bool use_raw_msg_; -}; - -using android_sink_mt = android_sink; -using android_sink_st = android_sink; - -template -using android_sink_buf_mt = android_sink; -template -using android_sink_buf_st = android_sink; - -} // namespace sinks - -// Create and register android syslog logger - -template -inline std::shared_ptr android_logger_mt(const std::string &logger_name, - const std::string &tag = "spdlog") { - return Factory::template create(logger_name, tag); -} - -template -inline std::shared_ptr android_logger_st(const std::string &logger_name, - const std::string &tag = "spdlog") { - return Factory::template create(logger_name, tag); -} - -} // namespace spdlog - -#endif // __ANDROID__ diff --git a/examples/blueprints-example/external/sinks/ansicolor_sink-inl.h b/examples/blueprints-example/external/sinks/ansicolor_sink-inl.h deleted file mode 100644 index 6a23f6c..0000000 --- a/examples/blueprints-example/external/sinks/ansicolor_sink-inl.h +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { -namespace sinks { - -template -SPDLOG_INLINE ansicolor_sink::ansicolor_sink(FILE *target_file, color_mode mode) - : target_file_(target_file), - mutex_(ConsoleMutex::mutex()), - formatter_(details::make_unique()) - -{ - set_color_mode_(mode); - colors_.at(level::trace) = to_string_(white); - colors_.at(level::debug) = to_string_(cyan); - colors_.at(level::info) = to_string_(green); - colors_.at(level::warn) = to_string_(yellow_bold); - colors_.at(level::err) = to_string_(red_bold); - colors_.at(level::critical) = to_string_(bold_on_red); - colors_.at(level::off) = to_string_(reset); -} - -template -SPDLOG_INLINE void ansicolor_sink::set_color(level::level_enum color_level, - string_view_t color) { - std::lock_guard lock(mutex_); - colors_.at(static_cast(color_level)) = to_string_(color); -} - -template -SPDLOG_INLINE void ansicolor_sink::log(const details::log_msg &msg) { - // Wrap the originally formatted message in color codes. - // If color is not supported in the terminal, log as is instead. - std::lock_guard lock(mutex_); - msg.color_range_start = 0; - msg.color_range_end = 0; - memory_buf_t formatted; - formatter_->format(msg, formatted); - if (should_do_colors_ && msg.color_range_end > msg.color_range_start) { - // before color range - print_range_(formatted, 0, msg.color_range_start); - // in color range - print_ccode_(colors_.at(static_cast(msg.level))); - print_range_(formatted, msg.color_range_start, msg.color_range_end); - print_ccode_(reset); - // after color range - print_range_(formatted, msg.color_range_end, formatted.size()); - } else // no color - { - print_range_(formatted, 0, formatted.size()); - } - fflush(target_file_); -} - -template -SPDLOG_INLINE void ansicolor_sink::flush() { - std::lock_guard lock(mutex_); - fflush(target_file_); -} - -template -SPDLOG_INLINE void ansicolor_sink::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); -} - -template -SPDLOG_INLINE void ansicolor_sink::set_formatter( - std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); -} - -template -SPDLOG_INLINE bool ansicolor_sink::should_color() const { - return should_do_colors_; -} - -template -SPDLOG_INLINE void ansicolor_sink::set_color_mode(color_mode mode) { - std::lock_guard lock(mutex_); - set_color_mode_(mode); -} - -template -SPDLOG_INLINE void ansicolor_sink::set_color_mode_(color_mode mode) { - switch (mode) { - case color_mode::always: - should_do_colors_ = true; - return; - case color_mode::automatic: - should_do_colors_ = - details::os::in_terminal(target_file_) && details::os::is_color_terminal(); - return; - case color_mode::never: - should_do_colors_ = false; - return; - default: - should_do_colors_ = false; - } -} - -template -SPDLOG_INLINE void ansicolor_sink::print_ccode_( - const string_view_t &color_code) const { - details::os::fwrite_bytes(color_code.data(), color_code.size(), target_file_); -} - -template -SPDLOG_INLINE void ansicolor_sink::print_range_(const memory_buf_t &formatted, - size_t start, - size_t end) const { - details::os::fwrite_bytes(formatted.data() + start, end - start, target_file_); -} - -template -SPDLOG_INLINE std::string ansicolor_sink::to_string_(const string_view_t &sv) { - return std::string(sv.data(), sv.size()); -} - -// ansicolor_stdout_sink -template -SPDLOG_INLINE ansicolor_stdout_sink::ansicolor_stdout_sink(color_mode mode) - : ansicolor_sink(stdout, mode) {} - -// ansicolor_stderr_sink -template -SPDLOG_INLINE ansicolor_stderr_sink::ansicolor_stderr_sink(color_mode mode) - : ansicolor_sink(stderr, mode) {} - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/ansicolor_sink.h b/examples/blueprints-example/external/sinks/ansicolor_sink.h deleted file mode 100644 index 47cea91..0000000 --- a/examples/blueprints-example/external/sinks/ansicolor_sink.h +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { - -/** - * This sink prefixes the output with an ANSI escape sequence color code - * depending on the severity - * of the message. - * If no color terminal detected, omit the escape codes. - */ - -template -class ansicolor_sink : public sink { -public: - using mutex_t = typename ConsoleMutex::mutex_t; - ansicolor_sink(FILE *target_file, color_mode mode); - ~ansicolor_sink() override = default; - - ansicolor_sink(const ansicolor_sink &other) = delete; - ansicolor_sink(ansicolor_sink &&other) = delete; - - ansicolor_sink &operator=(const ansicolor_sink &other) = delete; - ansicolor_sink &operator=(ansicolor_sink &&other) = delete; - - void set_color(level::level_enum color_level, string_view_t color); - void set_color_mode(color_mode mode); - bool should_color() const; - - void log(const details::log_msg &msg) override; - void flush() override; - void set_pattern(const std::string &pattern) override; - void set_formatter(std::unique_ptr sink_formatter) override; - - // Formatting codes - const string_view_t reset = "\033[m"; - const string_view_t bold = "\033[1m"; - const string_view_t dark = "\033[2m"; - const string_view_t underline = "\033[4m"; - const string_view_t blink = "\033[5m"; - const string_view_t reverse = "\033[7m"; - const string_view_t concealed = "\033[8m"; - const string_view_t clear_line = "\033[K"; - - // Foreground colors - const string_view_t black = "\033[30m"; - const string_view_t red = "\033[31m"; - const string_view_t green = "\033[32m"; - const string_view_t yellow = "\033[33m"; - const string_view_t blue = "\033[34m"; - const string_view_t magenta = "\033[35m"; - const string_view_t cyan = "\033[36m"; - const string_view_t white = "\033[37m"; - - /// Background colors - const string_view_t on_black = "\033[40m"; - const string_view_t on_red = "\033[41m"; - const string_view_t on_green = "\033[42m"; - const string_view_t on_yellow = "\033[43m"; - const string_view_t on_blue = "\033[44m"; - const string_view_t on_magenta = "\033[45m"; - const string_view_t on_cyan = "\033[46m"; - const string_view_t on_white = "\033[47m"; - - /// Bold colors - const string_view_t yellow_bold = "\033[33m\033[1m"; - const string_view_t red_bold = "\033[31m\033[1m"; - const string_view_t bold_on_red = "\033[1m\033[41m"; - -private: - FILE *target_file_; - mutex_t &mutex_; - bool should_do_colors_; - std::unique_ptr formatter_; - std::array colors_; - void set_color_mode_(color_mode mode); - void print_ccode_(const string_view_t &color_code) const; - void print_range_(const memory_buf_t &formatted, size_t start, size_t end) const; - static std::string to_string_(const string_view_t &sv); -}; - -template -class ansicolor_stdout_sink : public ansicolor_sink { -public: - explicit ansicolor_stdout_sink(color_mode mode = color_mode::automatic); -}; - -template -class ansicolor_stderr_sink : public ansicolor_sink { -public: - explicit ansicolor_stderr_sink(color_mode mode = color_mode::automatic); -}; - -using ansicolor_stdout_sink_mt = ansicolor_stdout_sink; -using ansicolor_stdout_sink_st = ansicolor_stdout_sink; - -using ansicolor_stderr_sink_mt = ansicolor_stderr_sink; -using ansicolor_stderr_sink_st = ansicolor_stderr_sink; - -} // namespace sinks -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "ansicolor_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/sinks/base_sink-inl.h b/examples/blueprints-example/external/sinks/base_sink-inl.h deleted file mode 100644 index ada161b..0000000 --- a/examples/blueprints-example/external/sinks/base_sink-inl.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include - -template -SPDLOG_INLINE spdlog::sinks::base_sink::base_sink() - : formatter_{details::make_unique()} {} - -template -SPDLOG_INLINE spdlog::sinks::base_sink::base_sink( - std::unique_ptr formatter) - : formatter_{std::move(formatter)} {} - -template -void SPDLOG_INLINE spdlog::sinks::base_sink::log(const details::log_msg &msg) { - std::lock_guard lock(mutex_); - sink_it_(msg); -} - -template -void SPDLOG_INLINE spdlog::sinks::base_sink::flush() { - std::lock_guard lock(mutex_); - flush_(); -} - -template -void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - set_pattern_(pattern); -} - -template -void SPDLOG_INLINE -spdlog::sinks::base_sink::set_formatter(std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - set_formatter_(std::move(sink_formatter)); -} - -template -void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern_(const std::string &pattern) { - set_formatter_(details::make_unique(pattern)); -} - -template -void SPDLOG_INLINE -spdlog::sinks::base_sink::set_formatter_(std::unique_ptr sink_formatter) { - formatter_ = std::move(sink_formatter); -} diff --git a/examples/blueprints-example/external/sinks/base_sink.h b/examples/blueprints-example/external/sinks/base_sink.h deleted file mode 100644 index 1b4bb06..0000000 --- a/examples/blueprints-example/external/sinks/base_sink.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once -// -// base sink templated over a mutex (either dummy or real) -// concrete implementation should override the sink_it_() and flush_() methods. -// locking is taken care of in this class - no locking needed by the -// implementers.. -// - -#include -#include -#include - -namespace spdlog { -namespace sinks { -template -class SPDLOG_API base_sink : public sink { -public: - base_sink(); - explicit base_sink(std::unique_ptr formatter); - ~base_sink() override = default; - - base_sink(const base_sink &) = delete; - base_sink(base_sink &&) = delete; - - base_sink &operator=(const base_sink &) = delete; - base_sink &operator=(base_sink &&) = delete; - - void log(const details::log_msg &msg) final override; - void flush() final override; - void set_pattern(const std::string &pattern) final override; - void set_formatter(std::unique_ptr sink_formatter) final override; - -protected: - // sink formatter - std::unique_ptr formatter_; - Mutex mutex_; - - virtual void sink_it_(const details::log_msg &msg) = 0; - virtual void flush_() = 0; - virtual void set_pattern_(const std::string &pattern); - virtual void set_formatter_(std::unique_ptr sink_formatter); -}; -} // namespace sinks -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "base_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/sinks/basic_file_sink-inl.h b/examples/blueprints-example/external/sinks/basic_file_sink-inl.h deleted file mode 100644 index ce0ddad..0000000 --- a/examples/blueprints-example/external/sinks/basic_file_sink-inl.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { -namespace sinks { - -template -SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, - bool truncate, - const file_event_handlers &event_handlers) - : file_helper_{event_handlers} { - file_helper_.open(filename, truncate); -} - -template -SPDLOG_INLINE const filename_t &basic_file_sink::filename() const { - return file_helper_.filename(); -} - -template -SPDLOG_INLINE void basic_file_sink::truncate() { - std::lock_guard lock(base_sink::mutex_); - file_helper_.reopen(true); -} - -template -SPDLOG_INLINE void basic_file_sink::sink_it_(const details::log_msg &msg) { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - file_helper_.write(formatted); -} - -template -SPDLOG_INLINE void basic_file_sink::flush_() { - file_helper_.flush(); -} - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/basic_file_sink.h b/examples/blueprints-example/external/sinks/basic_file_sink.h deleted file mode 100644 index 48c0767..0000000 --- a/examples/blueprints-example/external/sinks/basic_file_sink.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace spdlog { -namespace sinks { -/* - * Trivial file sink with single file as target - */ -template -class basic_file_sink final : public base_sink { -public: - explicit basic_file_sink(const filename_t &filename, - bool truncate = false, - const file_event_handlers &event_handlers = {}); - const filename_t &filename() const; - void truncate(); - -protected: - void sink_it_(const details::log_msg &msg) override; - void flush_() override; - -private: - details::file_helper file_helper_; -}; - -using basic_file_sink_mt = basic_file_sink; -using basic_file_sink_st = basic_file_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr basic_logger_mt(const std::string &logger_name, - const filename_t &filename, - bool truncate = false, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, - event_handlers); -} - -template -inline std::shared_ptr basic_logger_st(const std::string &logger_name, - const filename_t &filename, - bool truncate = false, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, - event_handlers); -} - -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "basic_file_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/sinks/callback_sink.h b/examples/blueprints-example/external/sinks/callback_sink.h deleted file mode 100644 index 8f0c8d4..0000000 --- a/examples/blueprints-example/external/sinks/callback_sink.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include - -#include -#include - -namespace spdlog { - -// callbacks type -typedef std::function custom_log_callback; - -namespace sinks { -/* - * Trivial callback sink, gets a callback function and calls it on each log - */ -template -class callback_sink final : public base_sink { -public: - explicit callback_sink(const custom_log_callback &callback) - : callback_{callback} {} - -protected: - void sink_it_(const details::log_msg &msg) override { callback_(msg); } - void flush_() override {} - -private: - custom_log_callback callback_; -}; - -using callback_sink_mt = callback_sink; -using callback_sink_st = callback_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr callback_logger_mt(const std::string &logger_name, - const custom_log_callback &callback) { - return Factory::template create(logger_name, callback); -} - -template -inline std::shared_ptr callback_logger_st(const std::string &logger_name, - const custom_log_callback &callback) { - return Factory::template create(logger_name, callback); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/daily_file_sink.h b/examples/blueprints-example/external/sinks/daily_file_sink.h deleted file mode 100644 index 615c9f7..0000000 --- a/examples/blueprints-example/external/sinks/daily_file_sink.h +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { - -/* - * Generator of daily log file names in format basename.YYYY-MM-DD.ext - */ -struct daily_filename_calculator { - // Create filename for the form basename.YYYY-MM-DD - static filename_t calc_filename(const filename_t &filename, const tm &now_tm) { - filename_t basename, ext; - std::tie(basename, ext) = details::file_helper::split_by_extension(filename); - return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}")), - basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, - ext); - } -}; - -/* - * Generator of daily log file names with strftime format. - * Usages: - * auto sink = - * std::make_shared("myapp-%Y-%m-%d:%H:%M:%S.log", hour, - * minute);" auto logger = spdlog::daily_logger_format_mt("loggername, "myapp-%Y-%m-%d:%X.log", - * hour, minute)" - * - */ -struct daily_filename_format_calculator { - static filename_t calc_filename(const filename_t &file_path, const tm &now_tm) { -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) - std::wstringstream stream; -#else - std::stringstream stream; -#endif - stream << std::put_time(&now_tm, file_path.c_str()); - return stream.str(); - } -}; - -/* - * Rotating file sink based on date. - * If truncate != false , the created file will be truncated. - * If max_files > 0, retain only the last max_files and delete previous. - * Note that old log files from previous executions will not be deleted by this class, - * rotation and deletion is only applied while the program is running. - */ -template -class daily_file_sink final : public base_sink { -public: - // create daily file sink which rotates on given time - daily_file_sink(filename_t base_filename, - int rotation_hour, - int rotation_minute, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) - : base_filename_(std::move(base_filename)), - rotation_h_(rotation_hour), - rotation_m_(rotation_minute), - file_helper_{event_handlers}, - truncate_(truncate), - max_files_(max_files), - filenames_q_() { - if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || - rotation_minute > 59) { - throw_spdlog_ex("daily_file_sink: Invalid rotation time in ctor"); - } - - auto now = log_clock::now(); - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now)); - file_helper_.open(filename, truncate_); - rotation_tp_ = next_rotation_tp_(); - - if (max_files_ > 0) { - init_filenames_q_(); - } - } - - filename_t filename() { - std::lock_guard lock(base_sink::mutex_); - return file_helper_.filename(); - } - -protected: - void sink_it_(const details::log_msg &msg) override { - auto time = msg.time; - bool should_rotate = time >= rotation_tp_; - if (should_rotate) { - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(time)); - file_helper_.open(filename, truncate_); - rotation_tp_ = next_rotation_tp_(); - } - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - file_helper_.write(formatted); - - // Do the cleaning only at the end because it might throw on failure. - if (should_rotate && max_files_ > 0) { - delete_old_(); - } - } - - void flush_() override { file_helper_.flush(); } - -private: - void init_filenames_q_() { - using details::os::path_exists; - - filenames_q_ = details::circular_q(static_cast(max_files_)); - std::vector filenames; - auto now = log_clock::now(); - while (filenames.size() < max_files_) { - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now)); - if (!path_exists(filename)) { - break; - } - filenames.emplace_back(filename); - now -= std::chrono::hours(24); - } - for (auto iter = filenames.rbegin(); iter != filenames.rend(); ++iter) { - filenames_q_.push_back(std::move(*iter)); - } - } - - tm now_tm(log_clock::time_point tp) { - time_t tnow = log_clock::to_time_t(tp); - return spdlog::details::os::localtime(tnow); - } - - log_clock::time_point next_rotation_tp_() { - auto now = log_clock::now(); - tm date = now_tm(now); - date.tm_hour = rotation_h_; - date.tm_min = rotation_m_; - date.tm_sec = 0; - auto rotation_time = log_clock::from_time_t(std::mktime(&date)); - if (rotation_time > now) { - return rotation_time; - } - return {rotation_time + std::chrono::hours(24)}; - } - - // Delete the file N rotations ago. - // Throw spdlog_ex on failure to delete the old file. - void delete_old_() { - using details::os::filename_to_str; - using details::os::remove_if_exists; - - filename_t current_file = file_helper_.filename(); - if (filenames_q_.full()) { - auto old_filename = std::move(filenames_q_.front()); - filenames_q_.pop_front(); - bool ok = remove_if_exists(old_filename) == 0; - if (!ok) { - filenames_q_.push_back(std::move(current_file)); - throw_spdlog_ex("Failed removing daily file " + filename_to_str(old_filename), - errno); - } - } - filenames_q_.push_back(std::move(current_file)); - } - - filename_t base_filename_; - int rotation_h_; - int rotation_m_; - log_clock::time_point rotation_tp_; - details::file_helper file_helper_; - bool truncate_; - uint16_t max_files_; - details::circular_q filenames_q_; -}; - -using daily_file_sink_mt = daily_file_sink; -using daily_file_sink_st = daily_file_sink; -using daily_file_format_sink_mt = daily_file_sink; -using daily_file_format_sink_st = - daily_file_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr daily_logger_mt(const std::string &logger_name, - const filename_t &filename, - int hour = 0, - int minute = 0, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, hour, minute, - truncate, max_files, event_handlers); -} - -template -inline std::shared_ptr daily_logger_format_mt( - const std::string &logger_name, - const filename_t &filename, - int hour = 0, - int minute = 0, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create( - logger_name, filename, hour, minute, truncate, max_files, event_handlers); -} - -template -inline std::shared_ptr daily_logger_st(const std::string &logger_name, - const filename_t &filename, - int hour = 0, - int minute = 0, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, hour, minute, - truncate, max_files, event_handlers); -} - -template -inline std::shared_ptr daily_logger_format_st( - const std::string &logger_name, - const filename_t &filename, - int hour = 0, - int minute = 0, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create( - logger_name, filename, hour, minute, truncate, max_files, event_handlers); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/dist_sink.h b/examples/blueprints-example/external/sinks/dist_sink.h deleted file mode 100644 index 69c4971..0000000 --- a/examples/blueprints-example/external/sinks/dist_sink.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include "base_sink.h" -#include -#include -#include - -#include -#include -#include -#include - -// Distribution sink (mux). Stores a vector of sinks which get called when log -// is called - -namespace spdlog { -namespace sinks { - -template -class dist_sink : public base_sink { -public: - dist_sink() = default; - explicit dist_sink(std::vector> sinks) - : sinks_(sinks) {} - - dist_sink(const dist_sink &) = delete; - dist_sink &operator=(const dist_sink &) = delete; - - void add_sink(std::shared_ptr sub_sink) { - std::lock_guard lock(base_sink::mutex_); - sinks_.push_back(sub_sink); - } - - void remove_sink(std::shared_ptr sub_sink) { - std::lock_guard lock(base_sink::mutex_); - sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sub_sink), sinks_.end()); - } - - void set_sinks(std::vector> sinks) { - std::lock_guard lock(base_sink::mutex_); - sinks_ = std::move(sinks); - } - - std::vector> &sinks() { return sinks_; } - -protected: - void sink_it_(const details::log_msg &msg) override { - for (auto &sub_sink : sinks_) { - if (sub_sink->should_log(msg.level)) { - sub_sink->log(msg); - } - } - } - - void flush_() override { - for (auto &sub_sink : sinks_) { - sub_sink->flush(); - } - } - - void set_pattern_(const std::string &pattern) override { - set_formatter_(details::make_unique(pattern)); - } - - void set_formatter_(std::unique_ptr sink_formatter) override { - base_sink::formatter_ = std::move(sink_formatter); - for (auto &sub_sink : sinks_) { - sub_sink->set_formatter(base_sink::formatter_->clone()); - } - } - std::vector> sinks_; -}; - -using dist_sink_mt = dist_sink; -using dist_sink_st = dist_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/dup_filter_sink.h b/examples/blueprints-example/external/sinks/dup_filter_sink.h deleted file mode 100644 index 0588d77..0000000 --- a/examples/blueprints-example/external/sinks/dup_filter_sink.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include "dist_sink.h" -#include -#include - -#include -#include -#include -#include - -// Duplicate message removal sink. -// Skip the message if previous one is identical and less than "max_skip_duration" have passed -// -// Example: -// -// #include -// -// int main() { -// auto dup_filter = std::make_shared(std::chrono::seconds(5), -// level::info); dup_filter->add_sink(std::make_shared()); -// spdlog::logger l("logger", dup_filter); -// l.info("Hello"); -// l.info("Hello"); -// l.info("Hello"); -// l.info("Different Hello"); -// } -// -// Will produce: -// [2019-06-25 17:50:56.511] [logger] [info] Hello -// [2019-06-25 17:50:56.512] [logger] [info] Skipped 3 duplicate messages.. -// [2019-06-25 17:50:56.512] [logger] [info] Different Hello - -namespace spdlog { -namespace sinks { -template -class dup_filter_sink : public dist_sink { -public: - template - explicit dup_filter_sink(std::chrono::duration max_skip_duration) - : max_skip_duration_{max_skip_duration} {} - -protected: - std::chrono::microseconds max_skip_duration_; - log_clock::time_point last_msg_time_; - std::string last_msg_payload_; - size_t skip_counter_ = 0; - level::level_enum skipped_msg_log_level_ = spdlog::level::level_enum::off; - - void sink_it_(const details::log_msg &msg) override { - bool filtered = filter_(msg); - if (!filtered) { - skip_counter_ += 1; - skipped_msg_log_level_ = msg.level; - return; - } - - // log the "skipped.." message - if (skip_counter_ > 0) { - char buf[64]; - auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", - static_cast(skip_counter_)); - if (msg_size > 0 && static_cast(msg_size) < sizeof(buf)) { - details::log_msg skipped_msg{msg.source, msg.logger_name, skipped_msg_log_level_, - string_view_t{buf, static_cast(msg_size)}}; - dist_sink::sink_it_(skipped_msg); - } - } - - // log current message - dist_sink::sink_it_(msg); - last_msg_time_ = msg.time; - skip_counter_ = 0; - last_msg_payload_.assign(msg.payload.data(), msg.payload.data() + msg.payload.size()); - } - - // return whether the log msg should be displayed (true) or skipped (false) - bool filter_(const details::log_msg &msg) { - auto filter_duration = msg.time - last_msg_time_; - return (filter_duration > max_skip_duration_) || (msg.payload != last_msg_payload_); - } -}; - -using dup_filter_sink_mt = dup_filter_sink; -using dup_filter_sink_st = dup_filter_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/hourly_file_sink.h b/examples/blueprints-example/external/sinks/hourly_file_sink.h deleted file mode 100644 index 3e61872..0000000 --- a/examples/blueprints-example/external/sinks/hourly_file_sink.h +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { - -/* - * Generator of Hourly log file names in format basename.YYYY-MM-DD-HH.ext - */ -struct hourly_filename_calculator { - // Create filename for the form basename.YYYY-MM-DD-H - static filename_t calc_filename(const filename_t &filename, const tm &now_tm) { - filename_t basename, ext; - std::tie(basename, ext) = details::file_helper::split_by_extension(filename); - return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}_{:02d}{}"), basename, - now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, - now_tm.tm_hour, ext); - } -}; - -/* - * Rotating file sink based on time. - * If truncate != false , the created file will be truncated. - * If max_files > 0, retain only the last max_files and delete previous. - * Note that old log files from previous executions will not be deleted by this class, - * rotation and deletion is only applied while the program is running. - */ -template -class hourly_file_sink final : public base_sink { -public: - // create hourly file sink which rotates on given time - hourly_file_sink(filename_t base_filename, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) - : base_filename_(std::move(base_filename)), - file_helper_{event_handlers}, - truncate_(truncate), - max_files_(max_files), - filenames_q_() { - auto now = log_clock::now(); - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now)); - file_helper_.open(filename, truncate_); - remove_init_file_ = file_helper_.size() == 0; - rotation_tp_ = next_rotation_tp_(); - - if (max_files_ > 0) { - init_filenames_q_(); - } - } - - filename_t filename() { - std::lock_guard lock(base_sink::mutex_); - return file_helper_.filename(); - } - -protected: - void sink_it_(const details::log_msg &msg) override { - auto time = msg.time; - bool should_rotate = time >= rotation_tp_; - if (should_rotate) { - if (remove_init_file_) { - file_helper_.close(); - details::os::remove(file_helper_.filename()); - } - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(time)); - file_helper_.open(filename, truncate_); - rotation_tp_ = next_rotation_tp_(); - } - remove_init_file_ = false; - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - file_helper_.write(formatted); - - // Do the cleaning only at the end because it might throw on failure. - if (should_rotate && max_files_ > 0) { - delete_old_(); - } - } - - void flush_() override { file_helper_.flush(); } - -private: - void init_filenames_q_() { - using details::os::path_exists; - - filenames_q_ = details::circular_q(static_cast(max_files_)); - std::vector filenames; - auto now = log_clock::now(); - while (filenames.size() < max_files_) { - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now)); - if (!path_exists(filename)) { - break; - } - filenames.emplace_back(filename); - now -= std::chrono::hours(1); - } - for (auto iter = filenames.rbegin(); iter != filenames.rend(); ++iter) { - filenames_q_.push_back(std::move(*iter)); - } - } - - tm now_tm(log_clock::time_point tp) { - time_t tnow = log_clock::to_time_t(tp); - return spdlog::details::os::localtime(tnow); - } - - log_clock::time_point next_rotation_tp_() { - auto now = log_clock::now(); - tm date = now_tm(now); - date.tm_min = 0; - date.tm_sec = 0; - auto rotation_time = log_clock::from_time_t(std::mktime(&date)); - if (rotation_time > now) { - return rotation_time; - } - return {rotation_time + std::chrono::hours(1)}; - } - - // Delete the file N rotations ago. - // Throw spdlog_ex on failure to delete the old file. - void delete_old_() { - using details::os::filename_to_str; - using details::os::remove_if_exists; - - filename_t current_file = file_helper_.filename(); - if (filenames_q_.full()) { - auto old_filename = std::move(filenames_q_.front()); - filenames_q_.pop_front(); - bool ok = remove_if_exists(old_filename) == 0; - if (!ok) { - filenames_q_.push_back(std::move(current_file)); - SPDLOG_THROW(spdlog_ex( - "Failed removing hourly file " + filename_to_str(old_filename), errno)); - } - } - filenames_q_.push_back(std::move(current_file)); - } - - filename_t base_filename_; - log_clock::time_point rotation_tp_; - details::file_helper file_helper_; - bool truncate_; - uint16_t max_files_; - details::circular_q filenames_q_; - bool remove_init_file_; -}; - -using hourly_file_sink_mt = hourly_file_sink; -using hourly_file_sink_st = hourly_file_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr hourly_logger_mt(const std::string &logger_name, - const filename_t &filename, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, - max_files, event_handlers); -} - -template -inline std::shared_ptr hourly_logger_st(const std::string &logger_name, - const filename_t &filename, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, - max_files, event_handlers); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/kafka_sink.h b/examples/blueprints-example/external/sinks/kafka_sink.h deleted file mode 100644 index 91e9878..0000000 --- a/examples/blueprints-example/external/sinks/kafka_sink.h +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// -// Custom sink for kafka -// Building and using requires librdkafka library. -// For building librdkafka library check the url below -// https://github.com/confluentinc/librdkafka -// - -#include "spdlog/async.h" -#include "spdlog/details/log_msg.h" -#include "spdlog/details/null_mutex.h" -#include "spdlog/details/synchronous_factory.h" -#include "spdlog/sinks/base_sink.h" -#include -#include - -// kafka header -#include - -namespace spdlog { -namespace sinks { - -struct kafka_sink_config { - std::string server_addr; - std::string produce_topic; - int32_t flush_timeout_ms = 1000; - - kafka_sink_config(std::string addr, std::string topic, int flush_timeout_ms = 1000) - : server_addr{std::move(addr)}, - produce_topic{std::move(topic)}, - flush_timeout_ms(flush_timeout_ms) {} -}; - -template -class kafka_sink : public base_sink { -public: - kafka_sink(kafka_sink_config config) - : config_{std::move(config)} { - try { - std::string errstr; - conf_.reset(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL)); - RdKafka::Conf::ConfResult confRes = - conf_->set("bootstrap.servers", config_.server_addr, errstr); - if (confRes != RdKafka::Conf::CONF_OK) { - throw_spdlog_ex( - fmt_lib::format("conf set bootstrap.servers failed err:{}", errstr)); - } - - tconf_.reset(RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC)); - if (tconf_ == nullptr) { - throw_spdlog_ex(fmt_lib::format("create topic config failed")); - } - - producer_.reset(RdKafka::Producer::create(conf_.get(), errstr)); - if (producer_ == nullptr) { - throw_spdlog_ex(fmt_lib::format("create producer failed err:{}", errstr)); - } - topic_.reset(RdKafka::Topic::create(producer_.get(), config_.produce_topic, - tconf_.get(), errstr)); - if (topic_ == nullptr) { - throw_spdlog_ex(fmt_lib::format("create topic failed err:{}", errstr)); - } - } catch (const std::exception &e) { - throw_spdlog_ex(fmt_lib::format("error create kafka instance: {}", e.what())); - } - } - - ~kafka_sink() { producer_->flush(config_.flush_timeout_ms); } - -protected: - void sink_it_(const details::log_msg &msg) override { - producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY, - (void *)msg.payload.data(), msg.payload.size(), NULL, NULL); - } - - void flush_() override { producer_->flush(config_.flush_timeout_ms); } - -private: - kafka_sink_config config_; - std::unique_ptr producer_ = nullptr; - std::unique_ptr conf_ = nullptr; - std::unique_ptr tconf_ = nullptr; - std::unique_ptr topic_ = nullptr; -}; - -using kafka_sink_mt = kafka_sink; -using kafka_sink_st = kafka_sink; - -} // namespace sinks - -template -inline std::shared_ptr kafka_logger_mt(const std::string &logger_name, - spdlog::sinks::kafka_sink_config config) { - return Factory::template create(logger_name, config); -} - -template -inline std::shared_ptr kafka_logger_st(const std::string &logger_name, - spdlog::sinks::kafka_sink_config config) { - return Factory::template create(logger_name, config); -} - -template -inline std::shared_ptr kafka_logger_async_mt( - std::string logger_name, spdlog::sinks::kafka_sink_config config) { - return Factory::template create(logger_name, config); -} - -template -inline std::shared_ptr kafka_logger_async_st( - std::string logger_name, spdlog::sinks::kafka_sink_config config) { - return Factory::template create(logger_name, config); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/mongo_sink.h b/examples/blueprints-example/external/sinks/mongo_sink.h deleted file mode 100644 index c5b38ab..0000000 --- a/examples/blueprints-example/external/sinks/mongo_sink.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// -// Custom sink for mongodb -// Building and using requires mongocxx library. -// For building mongocxx library check the url below -// http://mongocxx.org/mongocxx-v3/installation/ -// - -#include "spdlog/common.h" -#include "spdlog/details/log_msg.h" -#include "spdlog/sinks/base_sink.h" -#include - -#include -#include -#include - -#include -#include -#include - -namespace spdlog { -namespace sinks { -template -class mongo_sink : public base_sink { -public: - mongo_sink(const std::string &db_name, - const std::string &collection_name, - const std::string &uri = "mongodb://localhost:27017") try - : mongo_sink(std::make_shared(), db_name, collection_name, uri) { - } catch (const std::exception &e) { - throw_spdlog_ex(fmt_lib::format("Error opening database: {}", e.what())); - } - - mongo_sink(std::shared_ptr instance, - const std::string &db_name, - const std::string &collection_name, - const std::string &uri = "mongodb://localhost:27017") - : instance_(std::move(instance)), - db_name_(db_name), - coll_name_(collection_name) { - try { - client_ = spdlog::details::make_unique(mongocxx::uri{uri}); - } catch (const std::exception &e) { - throw_spdlog_ex(fmt_lib::format("Error opening database: {}", e.what())); - } - } - - ~mongo_sink() { flush_(); } - -protected: - void sink_it_(const details::log_msg &msg) override { - using bsoncxx::builder::stream::document; - using bsoncxx::builder::stream::finalize; - - if (client_ != nullptr) { - auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" - << level::to_string_view(msg.level).data() << "level_num" - << msg.level << "message" - << std::string(msg.payload.begin(), msg.payload.end()) - << "logger_name" - << std::string(msg.logger_name.begin(), msg.logger_name.end()) - << "thread_id" << static_cast(msg.thread_id) << finalize; - client_->database(db_name_).collection(coll_name_).insert_one(doc.view()); - } - } - - void flush_() override {} - -private: - std::shared_ptr instance_; - std::string db_name_; - std::string coll_name_; - std::unique_ptr client_ = nullptr; -}; - -#include "spdlog/details/null_mutex.h" -#include -using mongo_sink_mt = mongo_sink; -using mongo_sink_st = mongo_sink; - -} // namespace sinks - -template -inline std::shared_ptr mongo_logger_mt( - const std::string &logger_name, - const std::string &db_name, - const std::string &collection_name, - const std::string &uri = "mongodb://localhost:27017") { - return Factory::template create(logger_name, db_name, collection_name, - uri); -} - -template -inline std::shared_ptr mongo_logger_st( - const std::string &logger_name, - const std::string &db_name, - const std::string &collection_name, - const std::string &uri = "mongodb://localhost:27017") { - return Factory::template create(logger_name, db_name, collection_name, - uri); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/msvc_sink.h b/examples/blueprints-example/external/sinks/msvc_sink.h deleted file mode 100644 index c28d6eb..0000000 --- a/examples/blueprints-example/external/sinks/msvc_sink.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright(c) 2016 Alexander Dalshov & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#if defined(_WIN32) - - #include - #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) - #include - #endif - #include - - #include - #include - - // Avoid including windows.h (https://stackoverflow.com/a/30741042) - #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -extern "C" __declspec(dllimport) void __stdcall OutputDebugStringW(const wchar_t *lpOutputString); - #else -extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); - #endif -extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - -namespace spdlog { -namespace sinks { -/* - * MSVC sink (logging using OutputDebugStringA) - */ -template -class msvc_sink : public base_sink { -public: - msvc_sink() = default; - msvc_sink(bool check_debugger_present) - : check_debugger_present_{check_debugger_present} {} - -protected: - void sink_it_(const details::log_msg &msg) override { - if (check_debugger_present_ && !IsDebuggerPresent()) { - return; - } - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - formatted.push_back('\0'); // add a null terminator for OutputDebugString - #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) - wmemory_buf_t wformatted; - details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted); - OutputDebugStringW(wformatted.data()); - #else - OutputDebugStringA(formatted.data()); - #endif - } - - void flush_() override {} - - bool check_debugger_present_ = true; -}; - -using msvc_sink_mt = msvc_sink; -using msvc_sink_st = msvc_sink; - -using windebug_sink_mt = msvc_sink_mt; -using windebug_sink_st = msvc_sink_st; - -} // namespace sinks -} // namespace spdlog - -#endif diff --git a/examples/blueprints-example/external/sinks/null_sink.h b/examples/blueprints-example/external/sinks/null_sink.h deleted file mode 100644 index 74530b5..0000000 --- a/examples/blueprints-example/external/sinks/null_sink.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include - -#include - -namespace spdlog { -namespace sinks { - -template -class null_sink final : public base_sink { -protected: - void sink_it_(const details::log_msg &) override {} - void flush_() override {} -}; - -using null_sink_mt = null_sink; -using null_sink_st = null_sink; - -} // namespace sinks - -template -inline std::shared_ptr null_logger_mt(const std::string &logger_name) { - auto null_logger = Factory::template create(logger_name); - null_logger->set_level(level::off); - return null_logger; -} - -template -inline std::shared_ptr null_logger_st(const std::string &logger_name) { - auto null_logger = Factory::template create(logger_name); - null_logger->set_level(level::off); - return null_logger; -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/ostream_sink.h b/examples/blueprints-example/external/sinks/ostream_sink.h deleted file mode 100644 index 6af9dd0..0000000 --- a/examples/blueprints-example/external/sinks/ostream_sink.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -#include -#include - -namespace spdlog { -namespace sinks { -template -class ostream_sink final : public base_sink { -public: - explicit ostream_sink(std::ostream &os, bool force_flush = false) - : ostream_(os), - force_flush_(force_flush) {} - ostream_sink(const ostream_sink &) = delete; - ostream_sink &operator=(const ostream_sink &) = delete; - -protected: - void sink_it_(const details::log_msg &msg) override { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - ostream_.write(formatted.data(), static_cast(formatted.size())); - if (force_flush_) { - ostream_.flush(); - } - } - - void flush_() override { ostream_.flush(); } - - std::ostream &ostream_; - bool force_flush_; -}; - -using ostream_sink_mt = ostream_sink; -using ostream_sink_st = ostream_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/qt_sinks.h b/examples/blueprints-example/external/sinks/qt_sinks.h deleted file mode 100644 index d319e84..0000000 --- a/examples/blueprints-example/external/sinks/qt_sinks.h +++ /dev/null @@ -1,304 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// -// Custom sink for QPlainTextEdit or QTextEdit and its children (QTextBrowser... -// etc) Building and using requires Qt library. -// -// Warning: the qt_sink won't be notified if the target widget is destroyed. -// If the widget's lifetime can be shorter than the logger's one, you should provide some permanent -// QObject, and then use a standard signal/slot. -// - -#include "spdlog/common.h" -#include "spdlog/details/log_msg.h" -#include "spdlog/details/synchronous_factory.h" -#include "spdlog/sinks/base_sink.h" -#include - -#include -#include - -// -// qt_sink class -// -namespace spdlog { -namespace sinks { -template -class qt_sink : public base_sink { -public: - qt_sink(QObject *qt_object, std::string meta_method) - : qt_object_(qt_object), - meta_method_(std::move(meta_method)) { - if (!qt_object_) { - throw_spdlog_ex("qt_sink: qt_object is null"); - } - } - - ~qt_sink() { flush_(); } - -protected: - void sink_it_(const details::log_msg &msg) override { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - const string_view_t str = string_view_t(formatted.data(), formatted.size()); - QMetaObject::invokeMethod( - qt_object_, meta_method_.c_str(), Qt::AutoConnection, - Q_ARG(QString, QString::fromUtf8(str.data(), static_cast(str.size())).trimmed())); - } - - void flush_() override {} - -private: - QObject *qt_object_ = nullptr; - std::string meta_method_; -}; - -// Qt color sink to QTextEdit. -// Color location is determined by the sink log pattern like in the rest of spdlog sinks. -// Colors can be modified if needed using sink->set_color(level, qtTextCharFormat). -// max_lines is the maximum number of lines that the sink will hold before removing the oldest -// lines. By default, only ascii (latin1) is supported by this sink. Set is_utf8 to true if utf8 -// support is needed. -template -class qt_color_sink : public base_sink { -public: - qt_color_sink(QTextEdit *qt_text_edit, - int max_lines, - bool dark_colors = false, - bool is_utf8 = false) - : qt_text_edit_(qt_text_edit), - max_lines_(max_lines), - is_utf8_(is_utf8) { - if (!qt_text_edit_) { - throw_spdlog_ex("qt_color_text_sink: text_edit is null"); - } - - default_color_ = qt_text_edit_->currentCharFormat(); - // set colors - QTextCharFormat format; - // trace - format.setForeground(dark_colors ? Qt::darkGray : Qt::gray); - colors_.at(level::trace) = format; - // debug - format.setForeground(dark_colors ? Qt::darkCyan : Qt::cyan); - colors_.at(level::debug) = format; - // info - format.setForeground(dark_colors ? Qt::darkGreen : Qt::green); - colors_.at(level::info) = format; - // warn - format.setForeground(dark_colors ? Qt::darkYellow : Qt::yellow); - colors_.at(level::warn) = format; - // err - format.setForeground(Qt::red); - colors_.at(level::err) = format; - // critical - format.setForeground(Qt::white); - format.setBackground(Qt::red); - colors_.at(level::critical) = format; - } - - ~qt_color_sink() { flush_(); } - - void set_default_color(QTextCharFormat format) { - // std::lock_guard lock(base_sink::mutex_); - default_color_ = format; - } - - void set_level_color(level::level_enum color_level, QTextCharFormat format) { - // std::lock_guard lock(base_sink::mutex_); - colors_.at(static_cast(color_level)) = format; - } - - QTextCharFormat &get_level_color(level::level_enum color_level) { - std::lock_guard lock(base_sink::mutex_); - return colors_.at(static_cast(color_level)); - } - - QTextCharFormat &get_default_color() { - std::lock_guard lock(base_sink::mutex_); - return default_color_; - } - -protected: - struct invoke_params { - invoke_params(int max_lines, - QTextEdit *q_text_edit, - QString payload, - QTextCharFormat default_color, - QTextCharFormat level_color, - int color_range_start, - int color_range_end) - : max_lines(max_lines), - q_text_edit(q_text_edit), - payload(std::move(payload)), - default_color(default_color), - level_color(level_color), - color_range_start(color_range_start), - color_range_end(color_range_end) {} - int max_lines; - QTextEdit *q_text_edit; - QString payload; - QTextCharFormat default_color; - QTextCharFormat level_color; - int color_range_start; - int color_range_end; - }; - - void sink_it_(const details::log_msg &msg) override { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - - const string_view_t str = string_view_t(formatted.data(), formatted.size()); - // apply the color to the color range in the formatted message. - QString payload; - int color_range_start = static_cast(msg.color_range_start); - int color_range_end = static_cast(msg.color_range_end); - if (is_utf8_) { - payload = QString::fromUtf8(str.data(), static_cast(str.size())); - // convert color ranges from byte index to character index. - if (msg.color_range_start < msg.color_range_end) { - color_range_start = QString::fromUtf8(str.data(), msg.color_range_start).size(); - color_range_end = QString::fromUtf8(str.data(), msg.color_range_end).size(); - } - } else { - payload = QString::fromLatin1(str.data(), static_cast(str.size())); - } - - invoke_params params{max_lines_, // max lines - qt_text_edit_, // text edit to append to - std::move(payload), // text to append - default_color_, // default color - colors_.at(msg.level), // color to apply - color_range_start, // color range start - color_range_end}; // color range end - - QMetaObject::invokeMethod( - qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection); - } - - void flush_() override {} - - // Add colored text to the text edit widget. This method is invoked in the GUI thread. - // It is a static method to ensure that it is handled correctly even if the sink is destroyed - // prematurely before it is invoked. - - static void invoke_method_(invoke_params params) { - auto *document = params.q_text_edit->document(); - QTextCursor cursor(document); - - // remove first blocks if number of blocks exceeds max_lines - while (document->blockCount() > params.max_lines) { - cursor.select(QTextCursor::BlockUnderCursor); - cursor.removeSelectedText(); - cursor.deleteChar(); // delete the newline after the block - } - - cursor.movePosition(QTextCursor::End); - cursor.setCharFormat(params.default_color); - - // if color range not specified or not not valid, just append the text with default color - if (params.color_range_end <= params.color_range_start) { - cursor.insertText(params.payload); - return; - } - - // insert the text before the color range - cursor.insertText(params.payload.left(params.color_range_start)); - - // insert the colorized text - cursor.setCharFormat(params.level_color); - cursor.insertText(params.payload.mid(params.color_range_start, - params.color_range_end - params.color_range_start)); - - // insert the text after the color range with default format - cursor.setCharFormat(params.default_color); - cursor.insertText(params.payload.mid(params.color_range_end)); - } - - QTextEdit *qt_text_edit_; - int max_lines_; - bool is_utf8_; - QTextCharFormat default_color_; - std::array colors_; -}; - -#include "spdlog/details/null_mutex.h" -#include - -using qt_sink_mt = qt_sink; -using qt_sink_st = qt_sink; -using qt_color_sink_mt = qt_color_sink; -using qt_color_sink_st = qt_color_sink; -} // namespace sinks - -// -// Factory functions -// - -// log to QTextEdit -template -inline std::shared_ptr qt_logger_mt(const std::string &logger_name, - QTextEdit *qt_object, - const std::string &meta_method = "append") { - return Factory::template create(logger_name, qt_object, meta_method); -} - -template -inline std::shared_ptr qt_logger_st(const std::string &logger_name, - QTextEdit *qt_object, - const std::string &meta_method = "append") { - return Factory::template create(logger_name, qt_object, meta_method); -} - -// log to QPlainTextEdit -template -inline std::shared_ptr qt_logger_mt(const std::string &logger_name, - QPlainTextEdit *qt_object, - const std::string &meta_method = "appendPlainText") { - return Factory::template create(logger_name, qt_object, meta_method); -} - -template -inline std::shared_ptr qt_logger_st(const std::string &logger_name, - QPlainTextEdit *qt_object, - const std::string &meta_method = "appendPlainText") { - return Factory::template create(logger_name, qt_object, meta_method); -} -// log to QObject -template -inline std::shared_ptr qt_logger_mt(const std::string &logger_name, - QObject *qt_object, - const std::string &meta_method) { - return Factory::template create(logger_name, qt_object, meta_method); -} - -template -inline std::shared_ptr qt_logger_st(const std::string &logger_name, - QObject *qt_object, - const std::string &meta_method) { - return Factory::template create(logger_name, qt_object, meta_method); -} - -// log to QTextEdit with colorized output -template -inline std::shared_ptr qt_color_logger_mt(const std::string &logger_name, - QTextEdit *qt_text_edit, - int max_lines, - bool is_utf8 = false) { - return Factory::template create(logger_name, qt_text_edit, max_lines, - false, is_utf8); -} - -template -inline std::shared_ptr qt_color_logger_st(const std::string &logger_name, - QTextEdit *qt_text_edit, - int max_lines, - bool is_utf8 = false) { - return Factory::template create(logger_name, qt_text_edit, max_lines, - false, is_utf8); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/ringbuffer_sink.h b/examples/blueprints-example/external/sinks/ringbuffer_sink.h deleted file mode 100644 index bcdf0ff..0000000 --- a/examples/blueprints-example/external/sinks/ringbuffer_sink.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include "spdlog/details/circular_q.h" -#include "spdlog/details/log_msg_buffer.h" -#include "spdlog/details/null_mutex.h" -#include "spdlog/sinks/base_sink.h" - -#include -#include -#include - -namespace spdlog { -namespace sinks { -/* - * Ring buffer sink - */ -template -class ringbuffer_sink final : public base_sink { -public: - explicit ringbuffer_sink(size_t n_items) - : q_{n_items} { - if (n_items == 0) { - throw_spdlog_ex("ringbuffer_sink: n_items cannot be zero"); - } - } - - std::vector last_raw(size_t lim = 0) { - std::lock_guard lock(base_sink::mutex_); - auto items_available = q_.size(); - auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available; - std::vector ret; - ret.reserve(n_items); - for (size_t i = (items_available - n_items); i < items_available; i++) { - ret.push_back(q_.at(i)); - } - return ret; - } - - std::vector last_formatted(size_t lim = 0) { - std::lock_guard lock(base_sink::mutex_); - auto items_available = q_.size(); - auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available; - std::vector ret; - ret.reserve(n_items); - for (size_t i = (items_available - n_items); i < items_available; i++) { - memory_buf_t formatted; - base_sink::formatter_->format(q_.at(i), formatted); - ret.push_back(SPDLOG_BUF_TO_STRING(formatted)); - } - return ret; - } - -protected: - void sink_it_(const details::log_msg &msg) override { - q_.push_back(details::log_msg_buffer{msg}); - } - void flush_() override {} - -private: - details::circular_q q_; -}; - -using ringbuffer_sink_mt = ringbuffer_sink; -using ringbuffer_sink_st = ringbuffer_sink; - -} // namespace sinks - -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/rotating_file_sink-inl.h b/examples/blueprints-example/external/sinks/rotating_file_sink-inl.h deleted file mode 100644 index a3694d8..0000000 --- a/examples/blueprints-example/external/sinks/rotating_file_sink-inl.h +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { - -template -SPDLOG_INLINE rotating_file_sink::rotating_file_sink( - filename_t base_filename, - std::size_t max_size, - std::size_t max_files, - bool rotate_on_open, - const file_event_handlers &event_handlers) - : base_filename_(std::move(base_filename)), - max_size_(max_size), - max_files_(max_files), - file_helper_{event_handlers} { - if (max_size == 0) { - throw_spdlog_ex("rotating sink constructor: max_size arg cannot be zero"); - } - - if (max_files > MaxFiles) { - throw_spdlog_ex("rotating sink constructor: max_files arg cannot exceed MaxFiles"); - } - file_helper_.open(calc_filename(base_filename_, 0)); - current_size_ = file_helper_.size(); // expensive. called only once - if (rotate_on_open && current_size_ > 0) { - rotate_(); - current_size_ = 0; - } -} - -// calc filename according to index and file extension if exists. -// e.g. calc_filename("logs/mylog.txt, 3) => "logs/mylog.3.txt". -template -SPDLOG_INLINE filename_t rotating_file_sink::calc_filename(const filename_t &filename, - std::size_t index) { - if (index == 0U) { - return filename; - } - - filename_t basename; - filename_t ext; - std::tie(basename, ext) = details::file_helper::split_by_extension(filename); - return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}.{}{}")), basename, index, ext); -} - -template -SPDLOG_INLINE filename_t rotating_file_sink::filename() { - std::lock_guard lock(base_sink::mutex_); - return file_helper_.filename(); -} - -template -SPDLOG_INLINE void rotating_file_sink::rotate_now() { - std::lock_guard lock(base_sink::mutex_); - rotate_(); -} -template -SPDLOG_INLINE void rotating_file_sink::set_max_size(std::size_t max_size) { - std::lock_guard lock(base_sink::mutex_); - if (max_size == 0) { - throw_spdlog_ex("rotating sink set_max_size: max_size arg cannot be zero"); - } - max_size_ = max_size; -} - -template -SPDLOG_INLINE std::size_t rotating_file_sink::get_max_size() { - std::lock_guard lock(base_sink::mutex_); - return max_size_; -} - -template -SPDLOG_INLINE void rotating_file_sink::set_max_files(std::size_t max_files) { - std::lock_guard lock(base_sink::mutex_); - if (max_files > MaxFiles) { - throw_spdlog_ex("rotating sink set_max_files: max_files arg cannot exceed 200000"); - } - max_files_ = max_files; -} - -template -std::size_t rotating_file_sink::get_max_files() { - std::lock_guard lock(base_sink::mutex_); - return max_files_; -} - -template -SPDLOG_INLINE void rotating_file_sink::sink_it_(const details::log_msg &msg) { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - auto new_size = current_size_ + formatted.size(); - - // rotate if the new estimated file size exceeds max size. - // rotate only if the real size > 0 to better deal with full disk (see issue #2261). - // we only check the real size when new_size > max_size_ because it is relatively expensive. - if (new_size > max_size_) { - file_helper_.flush(); - if (file_helper_.size() > 0) { - rotate_(); - new_size = formatted.size(); - } - } - file_helper_.write(formatted); - current_size_ = new_size; -} - -template -SPDLOG_INLINE void rotating_file_sink::flush_() { - file_helper_.flush(); -} - -// Rotate files: -// log.txt -> log.1.txt -// log.1.txt -> log.2.txt -// log.2.txt -> log.3.txt -// log.3.txt -> delete -template -SPDLOG_INLINE void rotating_file_sink::rotate_() { - using details::os::filename_to_str; - using details::os::path_exists; - - file_helper_.close(); - for (auto i = max_files_; i > 0; --i) { - filename_t src = calc_filename(base_filename_, i - 1); - if (!path_exists(src)) { - continue; - } - filename_t target = calc_filename(base_filename_, i); - - if (!rename_file_(src, target)) { - // if failed try again after a small delay. - // this is a workaround to a windows issue, where very high rotation - // rates can cause the rename to fail with permission denied (because of antivirus?). - details::os::sleep_for_millis(100); - if (!rename_file_(src, target)) { - file_helper_.reopen( - true); // truncate the log file anyway to prevent it to grow beyond its limit! - current_size_ = 0; - throw_spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + - " to " + filename_to_str(target), - errno); - } - } - } - file_helper_.reopen(true); -} - -// delete the target if exists, and rename the src file to target -// return true on success, false otherwise. -template -SPDLOG_INLINE bool rotating_file_sink::rename_file_(const filename_t &src_filename, - const filename_t &target_filename) { - // try to delete the target file in case it already exists. - (void)details::os::remove(target_filename); - return details::os::rename(src_filename, target_filename) == 0; -} - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/rotating_file_sink.h b/examples/blueprints-example/external/sinks/rotating_file_sink.h deleted file mode 100644 index 72302e6..0000000 --- a/examples/blueprints-example/external/sinks/rotating_file_sink.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace spdlog { -namespace sinks { - -// -// Rotating file sink based on size -// -template -class rotating_file_sink final : public base_sink { -public: - static constexpr size_t MaxFiles = 200000; - rotating_file_sink(filename_t base_filename, - std::size_t max_size, - std::size_t max_files, - bool rotate_on_open = false, - const file_event_handlers &event_handlers = {}); - static filename_t calc_filename(const filename_t &filename, std::size_t index); - filename_t filename(); - void rotate_now(); - void set_max_size(std::size_t max_size); - std::size_t get_max_size(); - void set_max_files(std::size_t max_files); - std::size_t get_max_files(); - -protected: - void sink_it_(const details::log_msg &msg) override; - void flush_() override; - -private: - // Rotate files: - // log.txt -> log.1.txt - // log.1.txt -> log.2.txt - // log.2.txt -> log.3.txt - // log.3.txt -> delete - void rotate_(); - - // delete the target if exists, and rename the src file to target - // return true on success, false otherwise. - bool rename_file_(const filename_t &src_filename, const filename_t &target_filename); - - filename_t base_filename_; - std::size_t max_size_; - std::size_t max_files_; - std::size_t current_size_; - details::file_helper file_helper_; -}; - -using rotating_file_sink_mt = rotating_file_sink; -using rotating_file_sink_st = rotating_file_sink; - -} // namespace sinks - -// -// factory functions -// -template -std::shared_ptr rotating_logger_mt(const std::string &logger_name, - const filename_t &filename, - size_t max_file_size, - size_t max_files, - bool rotate_on_open = false, - const file_event_handlers &event_handlers = {}) { - return Factory::template create( - logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers); -} - -template -std::shared_ptr rotating_logger_st(const std::string &logger_name, - const filename_t &filename, - size_t max_file_size, - size_t max_files, - bool rotate_on_open = false, - const file_event_handlers &event_handlers = {}) { - return Factory::template create( - logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers); -} -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "rotating_file_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/sinks/sink-inl.h b/examples/blueprints-example/external/sinks/sink-inl.h deleted file mode 100644 index e4b2714..0000000 --- a/examples/blueprints-example/external/sinks/sink-inl.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include - -SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const { - return msg_level >= level_.load(std::memory_order_relaxed); -} - -SPDLOG_INLINE void spdlog::sinks::sink::set_level(level::level_enum log_level) { - level_.store(log_level, std::memory_order_relaxed); -} - -SPDLOG_INLINE spdlog::level::level_enum spdlog::sinks::sink::level() const { - return static_cast(level_.load(std::memory_order_relaxed)); -} diff --git a/examples/blueprints-example/external/sinks/sink.h b/examples/blueprints-example/external/sinks/sink.h deleted file mode 100644 index 5850685..0000000 --- a/examples/blueprints-example/external/sinks/sink.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { - -namespace sinks { -class SPDLOG_API sink { -public: - virtual ~sink() = default; - virtual void log(const details::log_msg &msg) = 0; - virtual void flush() = 0; - virtual void set_pattern(const std::string &pattern) = 0; - virtual void set_formatter(std::unique_ptr sink_formatter) = 0; - - void set_level(level::level_enum log_level); - level::level_enum level() const; - bool should_log(level::level_enum msg_level) const; - -protected: - // sink log level - default is all - level_t level_{level::trace}; -}; - -} // namespace sinks -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/sinks/stdout_color_sinks-inl.h b/examples/blueprints-example/external/sinks/stdout_color_sinks-inl.h deleted file mode 100644 index 166e386..0000000 --- a/examples/blueprints-example/external/sinks/stdout_color_sinks-inl.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { - -template -SPDLOG_INLINE std::shared_ptr stdout_color_mt(const std::string &logger_name, - color_mode mode) { - return Factory::template create(logger_name, mode); -} - -template -SPDLOG_INLINE std::shared_ptr stdout_color_st(const std::string &logger_name, - color_mode mode) { - return Factory::template create(logger_name, mode); -} - -template -SPDLOG_INLINE std::shared_ptr stderr_color_mt(const std::string &logger_name, - color_mode mode) { - return Factory::template create(logger_name, mode); -} - -template -SPDLOG_INLINE std::shared_ptr stderr_color_st(const std::string &logger_name, - color_mode mode) { - return Factory::template create(logger_name, mode); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/stdout_color_sinks.h b/examples/blueprints-example/external/sinks/stdout_color_sinks.h deleted file mode 100644 index 72991fe..0000000 --- a/examples/blueprints-example/external/sinks/stdout_color_sinks.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifdef _WIN32 - #include -#else - #include -#endif - -#include - -namespace spdlog { -namespace sinks { -#ifdef _WIN32 -using stdout_color_sink_mt = wincolor_stdout_sink_mt; -using stdout_color_sink_st = wincolor_stdout_sink_st; -using stderr_color_sink_mt = wincolor_stderr_sink_mt; -using stderr_color_sink_st = wincolor_stderr_sink_st; -#else -using stdout_color_sink_mt = ansicolor_stdout_sink_mt; -using stdout_color_sink_st = ansicolor_stdout_sink_st; -using stderr_color_sink_mt = ansicolor_stderr_sink_mt; -using stderr_color_sink_st = ansicolor_stderr_sink_st; -#endif -} // namespace sinks - -template -std::shared_ptr stdout_color_mt(const std::string &logger_name, - color_mode mode = color_mode::automatic); - -template -std::shared_ptr stdout_color_st(const std::string &logger_name, - color_mode mode = color_mode::automatic); - -template -std::shared_ptr stderr_color_mt(const std::string &logger_name, - color_mode mode = color_mode::automatic); - -template -std::shared_ptr stderr_color_st(const std::string &logger_name, - color_mode mode = color_mode::automatic); - -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "stdout_color_sinks-inl.h" -#endif diff --git a/examples/blueprints-example/external/sinks/stdout_sinks-inl.h b/examples/blueprints-example/external/sinks/stdout_sinks-inl.h deleted file mode 100644 index dcb21d8..0000000 --- a/examples/blueprints-example/external/sinks/stdout_sinks-inl.h +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include -#include -#include - -#ifdef _WIN32 - // under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675) - // so instead we use ::FileWrite - #include - - #ifndef _USING_V110_SDK71_ // fileapi.h doesn't exist in winxp - #include // WriteFile (..) - #endif - - #include // _get_osfhandle(..) - #include // _fileno(..) -#endif // _WIN32 - -namespace spdlog { - -namespace sinks { - -template -SPDLOG_INLINE stdout_sink_base::stdout_sink_base(FILE *file) - : mutex_(ConsoleMutex::mutex()), - file_(file), - formatter_(details::make_unique()) { -#ifdef _WIN32 - // get windows handle from the FILE* object - - handle_ = reinterpret_cast(::_get_osfhandle(::_fileno(file_))); - - // don't throw to support cases where no console is attached, - // and let the log method to do nothing if (handle_ == INVALID_HANDLE_VALUE). - // throw only if non stdout/stderr target is requested (probably regular file and not console). - if (handle_ == INVALID_HANDLE_VALUE && file != stdout && file != stderr) { - throw_spdlog_ex("spdlog::stdout_sink_base: _get_osfhandle() failed", errno); - } -#endif // _WIN32 -} - -template -SPDLOG_INLINE void stdout_sink_base::log(const details::log_msg &msg) { -#ifdef _WIN32 - if (handle_ == INVALID_HANDLE_VALUE) { - return; - } - std::lock_guard lock(mutex_); - memory_buf_t formatted; - formatter_->format(msg, formatted); - auto size = static_cast(formatted.size()); - DWORD bytes_written = 0; - bool ok = ::WriteFile(handle_, formatted.data(), size, &bytes_written, nullptr) != 0; - if (!ok) { - throw_spdlog_ex("stdout_sink_base: WriteFile() failed. GetLastError(): " + - std::to_string(::GetLastError())); - } -#else - std::lock_guard lock(mutex_); - memory_buf_t formatted; - formatter_->format(msg, formatted); - details::os::fwrite_bytes(formatted.data(), formatted.size(), file_); -#endif // _WIN32 - ::fflush(file_); // flush every line to terminal -} - -template -SPDLOG_INLINE void stdout_sink_base::flush() { - std::lock_guard lock(mutex_); - fflush(file_); -} - -template -SPDLOG_INLINE void stdout_sink_base::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); -} - -template -SPDLOG_INLINE void stdout_sink_base::set_formatter( - std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); -} - -// stdout sink -template -SPDLOG_INLINE stdout_sink::stdout_sink() - : stdout_sink_base(stdout) {} - -// stderr sink -template -SPDLOG_INLINE stderr_sink::stderr_sink() - : stdout_sink_base(stderr) {} - -} // namespace sinks - -// factory methods -template -SPDLOG_INLINE std::shared_ptr stdout_logger_mt(const std::string &logger_name) { - return Factory::template create(logger_name); -} - -template -SPDLOG_INLINE std::shared_ptr stdout_logger_st(const std::string &logger_name) { - return Factory::template create(logger_name); -} - -template -SPDLOG_INLINE std::shared_ptr stderr_logger_mt(const std::string &logger_name) { - return Factory::template create(logger_name); -} - -template -SPDLOG_INLINE std::shared_ptr stderr_logger_st(const std::string &logger_name) { - return Factory::template create(logger_name); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/stdout_sinks.h b/examples/blueprints-example/external/sinks/stdout_sinks.h deleted file mode 100644 index 6ef0996..0000000 --- a/examples/blueprints-example/external/sinks/stdout_sinks.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#ifdef _WIN32 - #include -#endif - -namespace spdlog { - -namespace sinks { - -template -class stdout_sink_base : public sink { -public: - using mutex_t = typename ConsoleMutex::mutex_t; - explicit stdout_sink_base(FILE *file); - ~stdout_sink_base() override = default; - - stdout_sink_base(const stdout_sink_base &other) = delete; - stdout_sink_base(stdout_sink_base &&other) = delete; - - stdout_sink_base &operator=(const stdout_sink_base &other) = delete; - stdout_sink_base &operator=(stdout_sink_base &&other) = delete; - - void log(const details::log_msg &msg) override; - void flush() override; - void set_pattern(const std::string &pattern) override; - - void set_formatter(std::unique_ptr sink_formatter) override; - -protected: - mutex_t &mutex_; - FILE *file_; - std::unique_ptr formatter_; -#ifdef _WIN32 - HANDLE handle_; -#endif // WIN32 -}; - -template -class stdout_sink : public stdout_sink_base { -public: - stdout_sink(); -}; - -template -class stderr_sink : public stdout_sink_base { -public: - stderr_sink(); -}; - -using stdout_sink_mt = stdout_sink; -using stdout_sink_st = stdout_sink; - -using stderr_sink_mt = stderr_sink; -using stderr_sink_st = stderr_sink; - -} // namespace sinks - -// factory methods -template -std::shared_ptr stdout_logger_mt(const std::string &logger_name); - -template -std::shared_ptr stdout_logger_st(const std::string &logger_name); - -template -std::shared_ptr stderr_logger_mt(const std::string &logger_name); - -template -std::shared_ptr stderr_logger_st(const std::string &logger_name); - -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "stdout_sinks-inl.h" -#endif diff --git a/examples/blueprints-example/external/sinks/syslog_sink.h b/examples/blueprints-example/external/sinks/syslog_sink.h deleted file mode 100644 index 913d41b..0000000 --- a/examples/blueprints-example/external/sinks/syslog_sink.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include - -#include -#include -#include - -namespace spdlog { -namespace sinks { -/** - * Sink that write to syslog using the `syscall()` library call. - */ -template -class syslog_sink : public base_sink { -public: - syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting) - : enable_formatting_{enable_formatting}, - syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, - /* spdlog::level::debug */ LOG_DEBUG, - /* spdlog::level::info */ LOG_INFO, - /* spdlog::level::warn */ LOG_WARNING, - /* spdlog::level::err */ LOG_ERR, - /* spdlog::level::critical */ LOG_CRIT, - /* spdlog::level::off */ LOG_INFO}}, - ident_{std::move(ident)} { - // set ident to be program name if empty - ::openlog(ident_.empty() ? nullptr : ident_.c_str(), syslog_option, syslog_facility); - } - - ~syslog_sink() override { ::closelog(); } - - syslog_sink(const syslog_sink &) = delete; - syslog_sink &operator=(const syslog_sink &) = delete; - -protected: - void sink_it_(const details::log_msg &msg) override { - string_view_t payload; - memory_buf_t formatted; - if (enable_formatting_) { - base_sink::formatter_->format(msg, formatted); - payload = string_view_t(formatted.data(), formatted.size()); - } else { - payload = msg.payload; - } - - size_t length = payload.size(); - // limit to max int - if (length > static_cast(std::numeric_limits::max())) { - length = static_cast(std::numeric_limits::max()); - } - - ::syslog(syslog_prio_from_level(msg), "%.*s", static_cast(length), payload.data()); - } - - void flush_() override {} - bool enable_formatting_ = false; - - // - // Simply maps spdlog's log level to syslog priority level. - // - virtual int syslog_prio_from_level(const details::log_msg &msg) const { - return syslog_levels_.at(static_cast(msg.level)); - } - - using levels_array = std::array; - levels_array syslog_levels_; - -private: - // must store the ident because the man says openlog might use the pointer as - // is and not a string copy - const std::string ident_; -}; - -using syslog_sink_mt = syslog_sink; -using syslog_sink_st = syslog_sink; -} // namespace sinks - -// Create and register a syslog logger -template -inline std::shared_ptr syslog_logger_mt(const std::string &logger_name, - const std::string &syslog_ident = "", - int syslog_option = 0, - int syslog_facility = LOG_USER, - bool enable_formatting = false) { - return Factory::template create(logger_name, syslog_ident, syslog_option, - syslog_facility, enable_formatting); -} - -template -inline std::shared_ptr syslog_logger_st(const std::string &logger_name, - const std::string &syslog_ident = "", - int syslog_option = 0, - int syslog_facility = LOG_USER, - bool enable_formatting = false) { - return Factory::template create(logger_name, syslog_ident, syslog_option, - syslog_facility, enable_formatting); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/systemd_sink.h b/examples/blueprints-example/external/sinks/systemd_sink.h deleted file mode 100644 index d2cd55f..0000000 --- a/examples/blueprints-example/external/sinks/systemd_sink.h +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright(c) 2019 ZVYAGIN.Alexander@gmail.com -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#ifndef SD_JOURNAL_SUPPRESS_LOCATION - #define SD_JOURNAL_SUPPRESS_LOCATION -#endif -#include - -namespace spdlog { -namespace sinks { - -/** - * Sink that write to systemd journal using the `sd_journal_send()` library call. - */ -template -class systemd_sink : public base_sink { -public: - systemd_sink(std::string ident = "", bool enable_formatting = false) - : ident_{std::move(ident)}, - enable_formatting_{enable_formatting}, - syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, - /* spdlog::level::debug */ LOG_DEBUG, - /* spdlog::level::info */ LOG_INFO, - /* spdlog::level::warn */ LOG_WARNING, - /* spdlog::level::err */ LOG_ERR, - /* spdlog::level::critical */ LOG_CRIT, - /* spdlog::level::off */ LOG_INFO}} {} - - ~systemd_sink() override {} - - systemd_sink(const systemd_sink &) = delete; - systemd_sink &operator=(const systemd_sink &) = delete; - -protected: - const std::string ident_; - bool enable_formatting_ = false; - using levels_array = std::array; - levels_array syslog_levels_; - - void sink_it_(const details::log_msg &msg) override { - int err; - string_view_t payload; - memory_buf_t formatted; - if (enable_formatting_) { - base_sink::formatter_->format(msg, formatted); - payload = string_view_t(formatted.data(), formatted.size()); - } else { - payload = msg.payload; - } - - size_t length = payload.size(); - // limit to max int - if (length > static_cast(std::numeric_limits::max())) { - length = static_cast(std::numeric_limits::max()); - } - - const string_view_t syslog_identifier = ident_.empty() ? msg.logger_name : ident_; - - // Do not send source location if not available - if (msg.source.empty()) { - // Note: function call inside '()' to avoid macro expansion - err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), payload.data(), - "PRIORITY=%d", syslog_level(msg.level), -#ifndef SPDLOG_NO_THREAD_ID - "TID=%zu", msg.thread_id, -#endif - "SYSLOG_IDENTIFIER=%.*s", - static_cast(syslog_identifier.size()), - syslog_identifier.data(), nullptr); - } else { - err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), payload.data(), - "PRIORITY=%d", syslog_level(msg.level), -#ifndef SPDLOG_NO_THREAD_ID - "TID=%zu", msg.thread_id, -#endif - "SYSLOG_IDENTIFIER=%.*s", - static_cast(syslog_identifier.size()), - syslog_identifier.data(), "CODE_FILE=%s", msg.source.filename, - "CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s", - msg.source.funcname, nullptr); - } - - if (err) { - throw_spdlog_ex("Failed writing to systemd", errno); - } - } - - int syslog_level(level::level_enum l) { - return syslog_levels_.at(static_cast(l)); - } - - void flush_() override {} -}; - -using systemd_sink_mt = systemd_sink; -using systemd_sink_st = systemd_sink; -} // namespace sinks - -// Create and register a syslog logger -template -inline std::shared_ptr systemd_logger_mt(const std::string &logger_name, - const std::string &ident = "", - bool enable_formatting = false) { - return Factory::template create(logger_name, ident, enable_formatting); -} - -template -inline std::shared_ptr systemd_logger_st(const std::string &logger_name, - const std::string &ident = "", - bool enable_formatting = false) { - return Factory::template create(logger_name, ident, enable_formatting); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/tcp_sink.h b/examples/blueprints-example/external/sinks/tcp_sink.h deleted file mode 100644 index 5d9ef82..0000000 --- a/examples/blueprints-example/external/sinks/tcp_sink.h +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#ifdef _WIN32 - #include -#else - #include -#endif - -#include -#include -#include -#include - -#pragma once - -// Simple tcp client sink -// Connects to remote address and send the formatted log. -// Will attempt to reconnect if connection drops. -// If more complicated behaviour is needed (i.e get responses), you can inherit it and override the -// sink_it_ method. - -namespace spdlog { -namespace sinks { - -struct tcp_sink_config { - std::string server_host; - int server_port; - int timeout_ms = - 0; // The timeout for all 3 major socket operations that is connect, send, and recv - bool lazy_connect = false; // if true connect on first log call instead of on construction - - tcp_sink_config(std::string host, int port) - : server_host{std::move(host)}, - server_port{port} {} -}; - -template -class tcp_sink : public spdlog::sinks::base_sink { -public: - // connect to tcp host/port or throw if failed - // host can be hostname or ip address - - explicit tcp_sink(const std::string &host, - int port, - int timeout_ms = 0, - bool lazy_connect = false) - : config_{host, port} { - config_.timeout_ms = timeout_ms; - config_.lazy_connect = lazy_connect; - if (!config_.lazy_connect) { - client_.connect(config_.server_host, config_.server_port, config_.timeout_ms); - } - } - - explicit tcp_sink(tcp_sink_config sink_config) - : config_{std::move(sink_config)} { - if (!config_.lazy_connect) { - client_.connect(config_.server_host, config_.server_port, config_.timeout_ms); - } - } - - ~tcp_sink() override = default; - -protected: - void sink_it_(const spdlog::details::log_msg &msg) override { - spdlog::memory_buf_t formatted; - spdlog::sinks::base_sink::formatter_->format(msg, formatted); - if (!client_.is_connected()) { - client_.connect(config_.server_host, config_.server_port, config_.timeout_ms); - } - client_.send(formatted.data(), formatted.size()); - } - - void flush_() override {} - tcp_sink_config config_; - details::tcp_client client_; -}; - -using tcp_sink_mt = tcp_sink; -using tcp_sink_st = tcp_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/udp_sink.h b/examples/blueprints-example/external/sinks/udp_sink.h deleted file mode 100644 index 4bff0fd..0000000 --- a/examples/blueprints-example/external/sinks/udp_sink.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#ifdef _WIN32 - #include -#else - #include -#endif - -#include -#include -#include -#include - -// Simple udp client sink -// Sends formatted log via udp - -namespace spdlog { -namespace sinks { - -struct udp_sink_config { - std::string server_host; - uint16_t server_port; - - udp_sink_config(std::string host, uint16_t port) - : server_host{std::move(host)}, - server_port{port} {} -}; - -template -class udp_sink : public spdlog::sinks::base_sink { -public: - // host can be hostname or ip address - explicit udp_sink(udp_sink_config sink_config) - : client_{sink_config.server_host, sink_config.server_port} {} - - ~udp_sink() override = default; - -protected: - void sink_it_(const spdlog::details::log_msg &msg) override { - spdlog::memory_buf_t formatted; - spdlog::sinks::base_sink::formatter_->format(msg, formatted); - client_.send(formatted.data(), formatted.size()); - } - - void flush_() override {} - details::udp_client client_; -}; - -using udp_sink_mt = udp_sink; -using udp_sink_st = udp_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr udp_logger_mt(const std::string &logger_name, - sinks::udp_sink_config skin_config) { - return Factory::template create(logger_name, skin_config); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/win_eventlog_sink.h b/examples/blueprints-example/external/sinks/win_eventlog_sink.h deleted file mode 100644 index 2c9b582..0000000 --- a/examples/blueprints-example/external/sinks/win_eventlog_sink.h +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// Writing to Windows Event Log requires the registry entries below to be present, with the -// following modifications: -// 1. should be replaced with your log name (e.g. your application name) -// 2. should be replaced with the specific source name and the key should be -// duplicated for -// each source used in the application -// -// Since typically modifications of this kind require elevation, it's better to do it as a part of -// setup procedure. The snippet below uses mscoree.dll as the message file as it exists on most of -// the Windows systems anyway and happens to contain the needed resource. -// -// You can also specify a custom message file if needed. -// Please refer to Event Log functions descriptions in MSDN for more details on custom message -// files. - -/*--------------------------------------------------------------------------------------- - -Windows Registry Editor Version 5.00 - -[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\] - -[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\\] -"TypesSupported"=dword:00000007 -"EventMessageFile"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,\ - 00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,\ - 5c,00,6d,00,73,00,63,00,6f,00,72,00,65,00,65,00,2e,00,64,00,6c,00,6c,00,00,\ - 00 - ------------------------------------------------------------------------------------------*/ - -#pragma once - -#include -#include - -#include -#include - -#include -#include -#include - -namespace spdlog { -namespace sinks { - -namespace win_eventlog { - -namespace internal { - -struct local_alloc_t { - HLOCAL hlocal_; - - SPDLOG_CONSTEXPR local_alloc_t() SPDLOG_NOEXCEPT : hlocal_(nullptr) {} - - local_alloc_t(local_alloc_t const &) = delete; - local_alloc_t &operator=(local_alloc_t const &) = delete; - - ~local_alloc_t() SPDLOG_NOEXCEPT { - if (hlocal_) { - LocalFree(hlocal_); - } - } -}; - -/** Windows error */ -struct win32_error : public spdlog_ex { - /** Formats an error report line: "user-message: error-code (system message)" */ - static std::string format(std::string const &user_message, DWORD error_code = GetLastError()) { - std::string system_message; - - local_alloc_t format_message_result{}; - auto format_message_succeeded = - ::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&format_message_result.hlocal_, 0, nullptr); - - if (format_message_succeeded && format_message_result.hlocal_) { - system_message = fmt_lib::format(" ({})", (LPSTR)format_message_result.hlocal_); - } - - return fmt_lib::format("{}: {}{}", user_message, error_code, system_message); - } - - explicit win32_error(std::string const &func_name, DWORD error = GetLastError()) - : spdlog_ex(format(func_name, error)) {} -}; - -/** Wrapper for security identifiers (SID) on Windows */ -struct sid_t { - std::vector buffer_; - -public: - sid_t() {} - - /** creates a wrapped SID copy */ - static sid_t duplicate_sid(PSID psid) { - if (!::IsValidSid(psid)) { - throw_spdlog_ex("sid_t::sid_t(): invalid SID received"); - } - - auto const sid_length{::GetLengthSid(psid)}; - - sid_t result; - result.buffer_.resize(sid_length); - if (!::CopySid(sid_length, (PSID)result.as_sid(), psid)) { - SPDLOG_THROW(win32_error("CopySid")); - } - - return result; - } - - /** Retrieves pointer to the internal buffer contents as SID* */ - SID *as_sid() const { return buffer_.empty() ? nullptr : (SID *)buffer_.data(); } - - /** Get SID for the current user */ - static sid_t get_current_user_sid() { - /* create and init RAII holder for process token */ - struct process_token_t { - HANDLE token_handle_ = INVALID_HANDLE_VALUE; - explicit process_token_t(HANDLE process) { - if (!::OpenProcessToken(process, TOKEN_QUERY, &token_handle_)) { - SPDLOG_THROW(win32_error("OpenProcessToken")); - } - } - - ~process_token_t() { ::CloseHandle(token_handle_); } - - } current_process_token( - ::GetCurrentProcess()); // GetCurrentProcess returns pseudohandle, no leak here! - - // Get the required size, this is expected to fail with ERROR_INSUFFICIENT_BUFFER and return - // the token size - DWORD tusize = 0; - if (::GetTokenInformation(current_process_token.token_handle_, TokenUser, NULL, 0, - &tusize)) { - SPDLOG_THROW(win32_error("GetTokenInformation should fail")); - } - - // get user token - std::vector buffer(static_cast(tusize)); - if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, - (LPVOID)buffer.data(), tusize, &tusize)) { - SPDLOG_THROW(win32_error("GetTokenInformation")); - } - - // create a wrapper of the SID data as stored in the user token - return sid_t::duplicate_sid(((TOKEN_USER *)buffer.data())->User.Sid); - } -}; - -struct eventlog { - static WORD get_event_type(details::log_msg const &msg) { - switch (msg.level) { - case level::trace: - case level::debug: - return EVENTLOG_SUCCESS; - - case level::info: - return EVENTLOG_INFORMATION_TYPE; - - case level::warn: - return EVENTLOG_WARNING_TYPE; - - case level::err: - case level::critical: - case level::off: - return EVENTLOG_ERROR_TYPE; - - default: - return EVENTLOG_INFORMATION_TYPE; - } - } - - static WORD get_event_category(details::log_msg const &msg) { return (WORD)msg.level; } -}; - -} // namespace internal - -/* - * Windows Event Log sink - */ -template -class win_eventlog_sink : public base_sink { -private: - HANDLE hEventLog_{NULL}; - internal::sid_t current_user_sid_; - std::string source_; - DWORD event_id_; - - HANDLE event_log_handle() { - if (!hEventLog_) { - hEventLog_ = ::RegisterEventSourceA(nullptr, source_.c_str()); - if (!hEventLog_ || hEventLog_ == (HANDLE)ERROR_ACCESS_DENIED) { - SPDLOG_THROW(internal::win32_error("RegisterEventSource")); - } - } - - return hEventLog_; - } - -protected: - void sink_it_(const details::log_msg &msg) override { - using namespace internal; - - bool succeeded; - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - formatted.push_back('\0'); - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - wmemory_buf_t buf; - details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), buf); - - LPCWSTR lp_wstr = buf.data(); - succeeded = static_cast(::ReportEventW( - event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), - event_id_, current_user_sid_.as_sid(), 1, 0, &lp_wstr, nullptr)); -#else - LPCSTR lp_str = formatted.data(); - succeeded = static_cast(::ReportEventA( - event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), - event_id_, current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr)); -#endif - - if (!succeeded) { - SPDLOG_THROW(win32_error("ReportEvent")); - } - } - - void flush_() override {} - -public: - win_eventlog_sink(std::string const &source, - DWORD event_id = 1000 /* according to mscoree.dll */) - : source_(source), - event_id_(event_id) { - try { - current_user_sid_ = internal::sid_t::get_current_user_sid(); - } catch (...) { - // get_current_user_sid() is unlikely to fail and if it does, we can still proceed - // without current_user_sid but in the event log the record will have no user name - } - } - - ~win_eventlog_sink() { - if (hEventLog_) DeregisterEventSource(hEventLog_); - } -}; - -} // namespace win_eventlog - -using win_eventlog_sink_mt = win_eventlog::win_eventlog_sink; -using win_eventlog_sink_st = win_eventlog::win_eventlog_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/wincolor_sink-inl.h b/examples/blueprints-example/external/sinks/wincolor_sink-inl.h deleted file mode 100644 index a9c0fa2..0000000 --- a/examples/blueprints-example/external/sinks/wincolor_sink-inl.h +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include - -namespace spdlog { -namespace sinks { -template -SPDLOG_INLINE wincolor_sink::wincolor_sink(void *out_handle, color_mode mode) - : out_handle_(out_handle), - mutex_(ConsoleMutex::mutex()), - formatter_(details::make_unique()) { - set_color_mode_impl(mode); - // set level colors - colors_[level::trace] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white - colors_[level::debug] = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan - colors_[level::info] = FOREGROUND_GREEN; // green - colors_[level::warn] = - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow - colors_[level::err] = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red - colors_[level::critical] = BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | - FOREGROUND_BLUE | - FOREGROUND_INTENSITY; // intense white on red background - colors_[level::off] = 0; -} - -template -SPDLOG_INLINE wincolor_sink::~wincolor_sink() { - this->flush(); -} - -// change the color for the given level -template -void SPDLOG_INLINE wincolor_sink::set_color(level::level_enum level, - std::uint16_t color) { - std::lock_guard lock(mutex_); - colors_[static_cast(level)] = color; -} - -template -void SPDLOG_INLINE wincolor_sink::log(const details::log_msg &msg) { - if (out_handle_ == nullptr || out_handle_ == INVALID_HANDLE_VALUE) { - return; - } - - std::lock_guard lock(mutex_); - msg.color_range_start = 0; - msg.color_range_end = 0; - memory_buf_t formatted; - formatter_->format(msg, formatted); - if (should_do_colors_ && msg.color_range_end > msg.color_range_start) { - // before color range - print_range_(formatted, 0, msg.color_range_start); - // in color range - auto orig_attribs = - static_cast(set_foreground_color_(colors_[static_cast(msg.level)])); - print_range_(formatted, msg.color_range_start, msg.color_range_end); - // reset to orig colors - ::SetConsoleTextAttribute(static_cast(out_handle_), orig_attribs); - print_range_(formatted, msg.color_range_end, formatted.size()); - } else // print without colors if color range is invalid (or color is disabled) - { - write_to_file_(formatted); - } -} - -template -void SPDLOG_INLINE wincolor_sink::flush() { - // windows console always flushed? -} - -template -void SPDLOG_INLINE wincolor_sink::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); -} - -template -void SPDLOG_INLINE -wincolor_sink::set_formatter(std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); -} - -template -void SPDLOG_INLINE wincolor_sink::set_color_mode(color_mode mode) { - std::lock_guard lock(mutex_); - set_color_mode_impl(mode); -} - -template -void SPDLOG_INLINE wincolor_sink::set_color_mode_impl(color_mode mode) { - if (mode == color_mode::automatic) { - // should do colors only if out_handle_ points to actual console. - DWORD console_mode; - bool in_console = ::GetConsoleMode(static_cast(out_handle_), &console_mode) != 0; - should_do_colors_ = in_console; - } else { - should_do_colors_ = mode == color_mode::always ? true : false; - } -} - -// set foreground color and return the orig console attributes (for resetting later) -template -std::uint16_t SPDLOG_INLINE -wincolor_sink::set_foreground_color_(std::uint16_t attribs) { - CONSOLE_SCREEN_BUFFER_INFO orig_buffer_info; - if (!::GetConsoleScreenBufferInfo(static_cast(out_handle_), &orig_buffer_info)) { - // just return white if failed getting console info - return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; - } - - // change only the foreground bits (lowest 4 bits) - auto new_attribs = static_cast(attribs) | (orig_buffer_info.wAttributes & 0xfff0); - auto ignored = - ::SetConsoleTextAttribute(static_cast(out_handle_), static_cast(new_attribs)); - (void)(ignored); - return static_cast(orig_buffer_info.wAttributes); // return orig attribs -} - -// print a range of formatted message to console -template -void SPDLOG_INLINE wincolor_sink::print_range_(const memory_buf_t &formatted, - size_t start, - size_t end) { - if (end > start) { -#if defined(SPDLOG_UTF8_TO_WCHAR_CONSOLE) - wmemory_buf_t wformatted; - details::os::utf8_to_wstrbuf(string_view_t(formatted.data() + start, end - start), - wformatted); - auto size = static_cast(wformatted.size()); - auto ignored = ::WriteConsoleW(static_cast(out_handle_), wformatted.data(), size, - nullptr, nullptr); -#else - auto size = static_cast(end - start); - auto ignored = ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, - size, nullptr, nullptr); -#endif - (void)(ignored); - } -} - -template -void SPDLOG_INLINE wincolor_sink::write_to_file_(const memory_buf_t &formatted) { - auto size = static_cast(formatted.size()); - DWORD bytes_written = 0; - auto ignored = ::WriteFile(static_cast(out_handle_), formatted.data(), size, - &bytes_written, nullptr); - (void)(ignored); -} - -// wincolor_stdout_sink -template -SPDLOG_INLINE wincolor_stdout_sink::wincolor_stdout_sink(color_mode mode) - : wincolor_sink(::GetStdHandle(STD_OUTPUT_HANDLE), mode) {} - -// wincolor_stderr_sink -template -SPDLOG_INLINE wincolor_stderr_sink::wincolor_stderr_sink(color_mode mode) - : wincolor_sink(::GetStdHandle(STD_ERROR_HANDLE), mode) {} -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/sinks/wincolor_sink.h b/examples/blueprints-example/external/sinks/wincolor_sink.h deleted file mode 100644 index e62d14d..0000000 --- a/examples/blueprints-example/external/sinks/wincolor_sink.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { -/* - * Windows color console sink. Uses WriteConsoleA to write to the console with - * colors - */ -template -class wincolor_sink : public sink { -public: - wincolor_sink(void *out_handle, color_mode mode); - ~wincolor_sink() override; - - wincolor_sink(const wincolor_sink &other) = delete; - wincolor_sink &operator=(const wincolor_sink &other) = delete; - - // change the color for the given level - void set_color(level::level_enum level, std::uint16_t color); - void log(const details::log_msg &msg) override; - void flush() override; - void set_pattern(const std::string &pattern) override; - void set_formatter(std::unique_ptr sink_formatter) override; - void set_color_mode(color_mode mode); - -protected: - using mutex_t = typename ConsoleMutex::mutex_t; - void *out_handle_; - mutex_t &mutex_; - bool should_do_colors_; - std::unique_ptr formatter_; - std::array colors_; - - // set foreground color and return the orig console attributes (for resetting later) - std::uint16_t set_foreground_color_(std::uint16_t attribs); - - // print a range of formatted message to console - void print_range_(const memory_buf_t &formatted, size_t start, size_t end); - - // in case we are redirected to file (not in console mode) - void write_to_file_(const memory_buf_t &formatted); - - void set_color_mode_impl(color_mode mode); -}; - -template -class wincolor_stdout_sink : public wincolor_sink { -public: - explicit wincolor_stdout_sink(color_mode mode = color_mode::automatic); -}; - -template -class wincolor_stderr_sink : public wincolor_sink { -public: - explicit wincolor_stderr_sink(color_mode mode = color_mode::automatic); -}; - -using wincolor_stdout_sink_mt = wincolor_stdout_sink; -using wincolor_stdout_sink_st = wincolor_stdout_sink; - -using wincolor_stderr_sink_mt = wincolor_stderr_sink; -using wincolor_stderr_sink_st = wincolor_stderr_sink; -} // namespace sinks -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "wincolor_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog-inl.h b/examples/blueprints-example/external/spdlog-inl.h deleted file mode 100644 index e02081f..0000000 --- a/examples/blueprints-example/external/spdlog-inl.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { - -SPDLOG_INLINE void initialize_logger(std::shared_ptr logger) { - details::registry::instance().initialize_logger(std::move(logger)); -} - -SPDLOG_INLINE std::shared_ptr get(const std::string &name) { - return details::registry::instance().get(name); -} - -SPDLOG_INLINE void set_formatter(std::unique_ptr formatter) { - details::registry::instance().set_formatter(std::move(formatter)); -} - -SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type) { - set_formatter( - std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); -} - -SPDLOG_INLINE void enable_backtrace(size_t n_messages) { - details::registry::instance().enable_backtrace(n_messages); -} - -SPDLOG_INLINE void disable_backtrace() { details::registry::instance().disable_backtrace(); } - -SPDLOG_INLINE void dump_backtrace() { default_logger_raw()->dump_backtrace(); } - -SPDLOG_INLINE level::level_enum get_level() { return default_logger_raw()->level(); } - -SPDLOG_INLINE bool should_log(level::level_enum log_level) { - return default_logger_raw()->should_log(log_level); -} - -SPDLOG_INLINE void set_level(level::level_enum log_level) { - details::registry::instance().set_level(log_level); -} - -SPDLOG_INLINE void flush_on(level::level_enum log_level) { - details::registry::instance().flush_on(log_level); -} - -SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg)) { - details::registry::instance().set_error_handler(handler); -} - -SPDLOG_INLINE void register_logger(std::shared_ptr logger) { - details::registry::instance().register_logger(std::move(logger)); -} - -SPDLOG_INLINE void register_or_replace(std::shared_ptr logger) { - details::registry::instance().register_or_replace(std::move(logger)); -} - -SPDLOG_INLINE void apply_all(const std::function)> &fun) { - details::registry::instance().apply_all(fun); -} - -SPDLOG_INLINE void drop(const std::string &name) { details::registry::instance().drop(name); } - -SPDLOG_INLINE void drop_all() { details::registry::instance().drop_all(); } - -SPDLOG_INLINE void shutdown() { details::registry::instance().shutdown(); } - -SPDLOG_INLINE void set_automatic_registration(bool automatic_registration) { - details::registry::instance().set_automatic_registration(automatic_registration); -} - -SPDLOG_INLINE std::shared_ptr default_logger() { - return details::registry::instance().default_logger(); -} - -SPDLOG_INLINE spdlog::logger *default_logger_raw() { - return details::registry::instance().get_default_raw(); -} - -SPDLOG_INLINE void set_default_logger(std::shared_ptr default_logger) { - details::registry::instance().set_default_logger(std::move(default_logger)); -} - -SPDLOG_INLINE void apply_logger_env_levels(std::shared_ptr logger) { - details::registry::instance().apply_logger_env_levels(std::move(logger)); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog.h b/examples/blueprints-example/external/spdlog.h deleted file mode 100644 index 1a927ff..0000000 --- a/examples/blueprints-example/external/spdlog.h +++ /dev/null @@ -1,357 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// spdlog main header file. -// see example.cpp for usage example - -#ifndef SPDLOG_H -#define SPDLOG_H - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace spdlog { - -using default_factory = synchronous_factory; - -// Create and register a logger with a templated sink type -// The logger's level, formatter and flush level will be set according to the -// global settings. -// -// Example: -// spdlog::create("logger_name", "dailylog_filename", 11, 59); -template -inline std::shared_ptr create(std::string logger_name, SinkArgs &&...sink_args) { - return default_factory::create(std::move(logger_name), - std::forward(sink_args)...); -} - -// Initialize and register a logger, -// formatter and flush level will be set according the global settings. -// -// Useful for initializing manually created loggers with the global settings. -// -// Example: -// auto mylogger = std::make_shared("mylogger", ...); -// spdlog::initialize_logger(mylogger); -SPDLOG_API void initialize_logger(std::shared_ptr logger); - -// Return an existing logger or nullptr if a logger with such a name doesn't -// exist. -// example: spdlog::get("my_logger")->info("hello {}", "world"); -SPDLOG_API std::shared_ptr get(const std::string &name); - -// Set global formatter. Each sink in each logger will get a clone of this object -SPDLOG_API void set_formatter(std::unique_ptr formatter); - -// Set global format string. -// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v"); -SPDLOG_API void set_pattern(std::string pattern, - pattern_time_type time_type = pattern_time_type::local); - -// enable global backtrace support -SPDLOG_API void enable_backtrace(size_t n_messages); - -// disable global backtrace support -SPDLOG_API void disable_backtrace(); - -// call dump backtrace on default logger -SPDLOG_API void dump_backtrace(); - -// Get global logging level -SPDLOG_API level::level_enum get_level(); - -// Set the global logging level -SPDLOG_API void set_level(level::level_enum log_level); - -// Determine whether the default logger should log messages with a certain level -SPDLOG_API bool should_log(level::level_enum lvl); - -// Set a global flush level -SPDLOG_API void flush_on(level::level_enum log_level); - -// Start/Restart a periodic flusher thread -// Warning: Use only if all your loggers are thread safe! -template -inline void flush_every(std::chrono::duration interval) { - details::registry::instance().flush_every(interval); -} - -// Set global error handler -SPDLOG_API void set_error_handler(void (*handler)(const std::string &msg)); - -// Register the given logger with the given name -// Will throw if a logger with the same name already exists. -SPDLOG_API void register_logger(std::shared_ptr logger); - -// Register the given logger with the given name -// Will replace any existing logger with the same name. -SPDLOG_API void register_or_replace(std::shared_ptr logger); - -// Apply a user-defined function on all registered loggers -// Example: -// spdlog::apply_all([&](std::shared_ptr l) {l->flush();}); -SPDLOG_API void apply_all(const std::function)> &fun); - -// Drop the reference to the given logger -SPDLOG_API void drop(const std::string &name); - -// Drop all references from the registry -SPDLOG_API void drop_all(); - -// stop any running threads started by spdlog and clean registry loggers -SPDLOG_API void shutdown(); - -// Automatic registration of loggers when using spdlog::create() or spdlog::create_async -SPDLOG_API void set_automatic_registration(bool automatic_registration); - -// API for using default logger (stdout_color_mt), -// e.g.: spdlog::info("Message {}", 1); -// -// The default logger object can be accessed using the spdlog::default_logger(): -// For example, to add another sink to it: -// spdlog::default_logger()->sinks().push_back(some_sink); -// -// The default logger can be replaced using spdlog::set_default_logger(new_logger). -// For example, to replace it with a file logger. -// -// IMPORTANT: -// The default API is thread safe (for _mt loggers), but: -// set_default_logger() *should not* be used concurrently with the default API. -// e.g., do not call set_default_logger() from one thread while calling spdlog::info() from another. - -SPDLOG_API std::shared_ptr default_logger(); - -SPDLOG_API spdlog::logger *default_logger_raw(); - -SPDLOG_API void set_default_logger(std::shared_ptr default_logger); - -// Initialize logger level based on environment configs. -// -// Useful for applying SPDLOG_LEVEL to manually created loggers. -// -// Example: -// auto mylogger = std::make_shared("mylogger", ...); -// spdlog::apply_logger_env_levels(mylogger); -SPDLOG_API void apply_logger_env_levels(std::shared_ptr logger); - -template -inline void log(source_loc source, - level::level_enum lvl, - format_string_t fmt, - Args &&...args) { - default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); -} - -template -inline void log(level::level_enum lvl, format_string_t fmt, Args &&...args) { - default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); -} - -template -inline void trace(format_string_t fmt, Args &&...args) { - default_logger_raw()->trace(fmt, std::forward(args)...); -} - -template -inline void debug(format_string_t fmt, Args &&...args) { - default_logger_raw()->debug(fmt, std::forward(args)...); -} - -template -inline void info(format_string_t fmt, Args &&...args) { - default_logger_raw()->info(fmt, std::forward(args)...); -} - -template -inline void warn(format_string_t fmt, Args &&...args) { - default_logger_raw()->warn(fmt, std::forward(args)...); -} - -template -inline void error(format_string_t fmt, Args &&...args) { - default_logger_raw()->error(fmt, std::forward(args)...); -} - -template -inline void critical(format_string_t fmt, Args &&...args) { - default_logger_raw()->critical(fmt, std::forward(args)...); -} - -template -inline void log(source_loc source, level::level_enum lvl, const T &msg) { - default_logger_raw()->log(source, lvl, msg); -} - -template -inline void log(level::level_enum lvl, const T &msg) { - default_logger_raw()->log(lvl, msg); -} - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT -template -inline void log(source_loc source, - level::level_enum lvl, - wformat_string_t fmt, - Args &&...args) { - default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); -} - -template -inline void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) { - default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); -} - -template -inline void trace(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->trace(fmt, std::forward(args)...); -} - -template -inline void debug(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->debug(fmt, std::forward(args)...); -} - -template -inline void info(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->info(fmt, std::forward(args)...); -} - -template -inline void warn(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->warn(fmt, std::forward(args)...); -} - -template -inline void error(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->error(fmt, std::forward(args)...); -} - -template -inline void critical(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->critical(fmt, std::forward(args)...); -} -#endif - -template -inline void trace(const T &msg) { - default_logger_raw()->trace(msg); -} - -template -inline void debug(const T &msg) { - default_logger_raw()->debug(msg); -} - -template -inline void info(const T &msg) { - default_logger_raw()->info(msg); -} - -template -inline void warn(const T &msg) { - default_logger_raw()->warn(msg); -} - -template -inline void error(const T &msg) { - default_logger_raw()->error(msg); -} - -template -inline void critical(const T &msg) { - default_logger_raw()->critical(msg); -} - -} // namespace spdlog - -// -// enable/disable log calls at compile time according to global level. -// -// define SPDLOG_ACTIVE_LEVEL to one of those (before including spdlog.h): -// SPDLOG_LEVEL_TRACE, -// SPDLOG_LEVEL_DEBUG, -// SPDLOG_LEVEL_INFO, -// SPDLOG_LEVEL_WARN, -// SPDLOG_LEVEL_ERROR, -// SPDLOG_LEVEL_CRITICAL, -// SPDLOG_LEVEL_OFF -// - -#ifndef SPDLOG_NO_SOURCE_LOC - #define SPDLOG_LOGGER_CALL(logger, level, ...) \ - (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) -#else - #define SPDLOG_LOGGER_CALL(logger, level, ...) \ - (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__) -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE - #define SPDLOG_LOGGER_TRACE(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) - #define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_TRACE(logger, ...) (void)0 - #define SPDLOG_TRACE(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG - #define SPDLOG_LOGGER_DEBUG(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__) - #define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0 - #define SPDLOG_DEBUG(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO - #define SPDLOG_LOGGER_INFO(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__) - #define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_INFO(logger, ...) (void)0 - #define SPDLOG_INFO(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN - #define SPDLOG_LOGGER_WARN(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__) - #define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_WARN(logger, ...) (void)0 - #define SPDLOG_WARN(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR - #define SPDLOG_LOGGER_ERROR(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__) - #define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_ERROR(logger, ...) (void)0 - #define SPDLOG_ERROR(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL - #define SPDLOG_LOGGER_CRITICAL(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__) - #define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0 - #define SPDLOG_CRITICAL(...) (void)0 -#endif - -#ifdef SPDLOG_HEADER_ONLY - #include "spdlog-inl.h" -#endif - -#endif // SPDLOG_H diff --git a/examples/blueprints-example/external/spdlog/async.h b/examples/blueprints-example/external/spdlog/async.h deleted file mode 100644 index 92fcd9a..0000000 --- a/examples/blueprints-example/external/spdlog/async.h +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// -// Async logging using global thread pool -// All loggers created here share same global thread pool. -// Each log message is pushed to a queue along with a shared pointer to the -// logger. -// If a logger deleted while having pending messages in the queue, it's actual -// destruction will defer -// until all its messages are processed by the thread pool. -// This is because each message in the queue holds a shared_ptr to the -// originating logger. - -#include -#include -#include - -#include -#include -#include - -namespace spdlog { - -namespace details { -static const size_t default_async_q_size = 8192; -} - -// async logger factory - creates async loggers backed with thread pool. -// if a global thread pool doesn't already exist, create it with default queue -// size of 8192 items and single thread. -template -struct async_factory_impl { - template - static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) { - auto ®istry_inst = details::registry::instance(); - - // create global thread pool if not already exists.. - - auto &mutex = registry_inst.tp_mutex(); - std::lock_guard tp_lock(mutex); - auto tp = registry_inst.get_tp(); - if (tp == nullptr) { - tp = std::make_shared(details::default_async_q_size, 1U); - registry_inst.set_tp(tp); - } - - auto sink = std::make_shared(std::forward(args)...); - auto new_logger = std::make_shared(std::move(logger_name), std::move(sink), - std::move(tp), OverflowPolicy); - registry_inst.initialize_logger(new_logger); - return new_logger; - } -}; - -using async_factory = async_factory_impl; -using async_factory_nonblock = async_factory_impl; - -template -inline std::shared_ptr create_async(std::string logger_name, - SinkArgs &&...sink_args) { - return async_factory::create(std::move(logger_name), - std::forward(sink_args)...); -} - -template -inline std::shared_ptr create_async_nb(std::string logger_name, - SinkArgs &&...sink_args) { - return async_factory_nonblock::create(std::move(logger_name), - std::forward(sink_args)...); -} - -// set global thread pool. -inline void init_thread_pool(size_t q_size, - size_t thread_count, - std::function on_thread_start, - std::function on_thread_stop) { - auto tp = std::make_shared(q_size, thread_count, on_thread_start, - on_thread_stop); - details::registry::instance().set_tp(std::move(tp)); -} - -inline void init_thread_pool(size_t q_size, - size_t thread_count, - std::function on_thread_start) { - init_thread_pool(q_size, thread_count, on_thread_start, [] {}); -} - -inline void init_thread_pool(size_t q_size, size_t thread_count) { - init_thread_pool(q_size, thread_count, [] {}, [] {}); -} - -// get the global thread pool. -inline std::shared_ptr thread_pool() { - return details::registry::instance().get_tp(); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/async_logger-inl.h b/examples/blueprints-example/external/spdlog/async_logger-inl.h deleted file mode 100644 index a681d97..0000000 --- a/examples/blueprints-example/external/spdlog/async_logger-inl.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include - -SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name, - sinks_init_list sinks_list, - std::weak_ptr tp, - async_overflow_policy overflow_policy) - : async_logger(std::move(logger_name), - sinks_list.begin(), - sinks_list.end(), - std::move(tp), - overflow_policy) {} - -SPDLOG_INLINE spdlog::async_logger::async_logger(std::string logger_name, - sink_ptr single_sink, - std::weak_ptr tp, - async_overflow_policy overflow_policy) - : async_logger( - std::move(logger_name), {std::move(single_sink)}, std::move(tp), overflow_policy) {} - -// send the log message to the thread pool -SPDLOG_INLINE void spdlog::async_logger::sink_it_(const details::log_msg &msg){ - SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){ - pool_ptr -> post_log(shared_from_this(), msg, overflow_policy_); -} -else { - throw_spdlog_ex("async log: thread pool doesn't exist anymore"); -} -} -SPDLOG_LOGGER_CATCH(msg.source) -} - -// send flush request to the thread pool -SPDLOG_INLINE void spdlog::async_logger::flush_(){ - SPDLOG_TRY{if (auto pool_ptr = thread_pool_.lock()){ - pool_ptr -> post_flush(shared_from_this(), overflow_policy_); -} -else { - throw_spdlog_ex("async flush: thread pool doesn't exist anymore"); -} -} -SPDLOG_LOGGER_CATCH(source_loc()) -} - -// -// backend functions - called from the thread pool to do the actual job -// -SPDLOG_INLINE void spdlog::async_logger::backend_sink_it_(const details::log_msg &msg) { - for (auto &sink : sinks_) { - if (sink->should_log(msg.level)) { - SPDLOG_TRY { sink->log(msg); } - SPDLOG_LOGGER_CATCH(msg.source) - } - } - - if (should_flush_(msg)) { - backend_flush_(); - } -} - -SPDLOG_INLINE void spdlog::async_logger::backend_flush_() { - for (auto &sink : sinks_) { - SPDLOG_TRY { sink->flush(); } - SPDLOG_LOGGER_CATCH(source_loc()) - } -} - -SPDLOG_INLINE std::shared_ptr spdlog::async_logger::clone(std::string new_name) { - auto cloned = std::make_shared(*this); - cloned->name_ = std::move(new_name); - return cloned; -} diff --git a/examples/blueprints-example/external/spdlog/async_logger.h b/examples/blueprints-example/external/spdlog/async_logger.h deleted file mode 100644 index 846c4c6..0000000 --- a/examples/blueprints-example/external/spdlog/async_logger.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Fast asynchronous logger. -// Uses pre allocated queue. -// Creates a single back thread to pop messages from the queue and log them. -// -// Upon each log write the logger: -// 1. Checks if its log level is enough to log the message -// 2. Push a new copy of the message to a queue (or block the caller until -// space is available in the queue) -// Upon destruction, logs all remaining messages in the queue before -// destructing.. - -#include - -namespace spdlog { - -// Async overflow policy - block by default. -enum class async_overflow_policy { - block, // Block until message can be enqueued - overrun_oldest, // Discard oldest message in the queue if full when trying to - // add new item. - discard_new // Discard new message if the queue is full when trying to add new item. -}; - -namespace details { -class thread_pool; -} - -class SPDLOG_API async_logger final : public std::enable_shared_from_this, - public logger { - friend class details::thread_pool; - -public: - template - async_logger(std::string logger_name, - It begin, - It end, - std::weak_ptr tp, - async_overflow_policy overflow_policy = async_overflow_policy::block) - : logger(std::move(logger_name), begin, end), - thread_pool_(std::move(tp)), - overflow_policy_(overflow_policy) {} - - async_logger(std::string logger_name, - sinks_init_list sinks_list, - std::weak_ptr tp, - async_overflow_policy overflow_policy = async_overflow_policy::block); - - async_logger(std::string logger_name, - sink_ptr single_sink, - std::weak_ptr tp, - async_overflow_policy overflow_policy = async_overflow_policy::block); - - std::shared_ptr clone(std::string new_name) override; - -protected: - void sink_it_(const details::log_msg &msg) override; - void flush_() override; - void backend_sink_it_(const details::log_msg &incoming_log_msg); - void backend_flush_(); - -private: - std::weak_ptr thread_pool_; - async_overflow_policy overflow_policy_; -}; -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "async_logger-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/cfg/argv.h b/examples/blueprints-example/external/spdlog/cfg/argv.h deleted file mode 100644 index 7de2f83..0000000 --- a/examples/blueprints-example/external/spdlog/cfg/argv.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once -#include -#include - -// -// Init log levels using each argv entry that starts with "SPDLOG_LEVEL=" -// -// set all loggers to debug level: -// example.exe "SPDLOG_LEVEL=debug" - -// set logger1 to trace level -// example.exe "SPDLOG_LEVEL=logger1=trace" - -// turn off all logging except for logger1 and logger2: -// example.exe "SPDLOG_LEVEL=off,logger1=debug,logger2=info" - -namespace spdlog { -namespace cfg { - -// search for SPDLOG_LEVEL= in the args and use it to init the levels -inline void load_argv_levels(int argc, const char **argv) { - const std::string spdlog_level_prefix = "SPDLOG_LEVEL="; - for (int i = 1; i < argc; i++) { - std::string arg = argv[i]; - if (arg.find(spdlog_level_prefix) == 0) { - auto levels_string = arg.substr(spdlog_level_prefix.size()); - helpers::load_levels(levels_string); - } - } -} - -inline void load_argv_levels(int argc, char **argv) { - load_argv_levels(argc, const_cast(argv)); -} - -} // namespace cfg -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/cfg/env.h b/examples/blueprints-example/external/spdlog/cfg/env.h deleted file mode 100644 index 47bf61c..0000000 --- a/examples/blueprints-example/external/spdlog/cfg/env.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once -#include -#include -#include - -// -// Init levels and patterns from env variables SPDLOG_LEVEL -// Inspired from Rust's "env_logger" crate (https://crates.io/crates/env_logger). -// Note - fallback to "info" level on unrecognized levels -// -// Examples: -// -// set global level to debug: -// export SPDLOG_LEVEL=debug -// -// turn off all logging except for logger1: -// export SPDLOG_LEVEL="*=off,logger1=debug" -// - -// turn off all logging except for logger1 and logger2: -// export SPDLOG_LEVEL="off,logger1=debug,logger2=info" - -namespace spdlog { -namespace cfg { -inline void load_env_levels(const char* var = "SPDLOG_LEVEL") { - auto env_val = details::os::getenv(var); - if (!env_val.empty()) { - helpers::load_levels(env_val); - } -} - -} // namespace cfg -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/cfg/helpers-inl.h b/examples/blueprints-example/external/spdlog/cfg/helpers-inl.h deleted file mode 100644 index 61b9b9f..0000000 --- a/examples/blueprints-example/external/spdlog/cfg/helpers-inl.h +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include -#include -#include - -namespace spdlog { -namespace cfg { -namespace helpers { - -// inplace convert to lowercase -inline std::string &to_lower_(std::string &str) { - std::transform(str.begin(), str.end(), str.begin(), [](char ch) { - return static_cast((ch >= 'A' && ch <= 'Z') ? ch + ('a' - 'A') : ch); - }); - return str; -} - -// inplace trim spaces -inline std::string &trim_(std::string &str) { - const char *spaces = " \n\r\t"; - str.erase(str.find_last_not_of(spaces) + 1); - str.erase(0, str.find_first_not_of(spaces)); - return str; -} - -// return (name,value) trimmed pair from the given "name = value" string. -// return empty string on missing parts -// "key=val" => ("key", "val") -// " key = val " => ("key", "val") -// "key=" => ("key", "") -// "val" => ("", "val") - -inline std::pair extract_kv_(char sep, const std::string &str) { - auto n = str.find(sep); - std::string k, v; - if (n == std::string::npos) { - v = str; - } else { - k = str.substr(0, n); - v = str.substr(n + 1); - } - return std::make_pair(trim_(k), trim_(v)); -} - -// return vector of key/value pairs from a sequence of "K1=V1,K2=V2,.." -// "a=AAA,b=BBB,c=CCC,.." => {("a","AAA"),("b","BBB"),("c", "CCC"),...} -inline std::unordered_map extract_key_vals_(const std::string &str) { - std::string token; - std::istringstream token_stream(str); - std::unordered_map rv{}; - while (std::getline(token_stream, token, ',')) { - if (token.empty()) { - continue; - } - auto kv = extract_kv_('=', token); - rv[kv.first] = kv.second; - } - return rv; -} - -SPDLOG_INLINE void load_levels(const std::string &input) { - if (input.empty() || input.size() >= 32768) { - return; - } - - auto key_vals = extract_key_vals_(input); - std::unordered_map levels; - level::level_enum global_level = level::info; - bool global_level_found = false; - - for (auto &name_level : key_vals) { - const auto &logger_name = name_level.first; - const auto &level_name = to_lower_(name_level.second); - auto level = level::from_str(level_name); - // ignore unrecognized level names - if (level == level::off && level_name != "off") { - continue; - } - if (logger_name.empty()) // no logger name indicates global level - { - global_level_found = true; - global_level = level; - } else { - levels[logger_name] = level; - } - } - - details::registry::instance().set_levels(std::move(levels), - global_level_found ? &global_level : nullptr); -} - -} // namespace helpers -} // namespace cfg -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/cfg/helpers.h b/examples/blueprints-example/external/spdlog/cfg/helpers.h deleted file mode 100644 index c023818..0000000 --- a/examples/blueprints-example/external/spdlog/cfg/helpers.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { -namespace cfg { -namespace helpers { -// -// Init levels from given string -// -// Examples: -// -// set global level to debug: "debug" -// turn off all logging except for logger1: "off,logger1=debug" -// turn off all logging except for logger1 and logger2: "off,logger1=debug,logger2=info" -// -SPDLOG_API void load_levels(const std::string &txt); -} // namespace helpers - -} // namespace cfg -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "helpers-inl.h" -#endif // SPDLOG_HEADER_ONLY diff --git a/examples/blueprints-example/external/spdlog/common-inl.h b/examples/blueprints-example/external/spdlog/common-inl.h deleted file mode 100644 index a8a0453..0000000 --- a/examples/blueprints-example/external/spdlog/common-inl.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { -namespace level { - -#if __cplusplus >= 201703L -constexpr -#endif - static string_view_t level_string_views[] SPDLOG_LEVEL_NAMES; - -static const char *short_level_names[] SPDLOG_SHORT_LEVEL_NAMES; - -SPDLOG_INLINE const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { - return level_string_views[l]; -} - -SPDLOG_INLINE const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT { - return short_level_names[l]; -} - -SPDLOG_INLINE spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT { - auto it = std::find(std::begin(level_string_views), std::end(level_string_views), name); - if (it != std::end(level_string_views)) - return static_cast(std::distance(std::begin(level_string_views), it)); - - // check also for "warn" and "err" before giving up.. - if (name == "warn") { - return level::warn; - } - if (name == "err") { - return level::err; - } - return level::off; -} -} // namespace level - -SPDLOG_INLINE spdlog_ex::spdlog_ex(std::string msg) - : msg_(std::move(msg)) {} - -SPDLOG_INLINE spdlog_ex::spdlog_ex(const std::string &msg, int last_errno) { -#ifdef SPDLOG_USE_STD_FORMAT - msg_ = std::system_error(std::error_code(last_errno, std::generic_category()), msg).what(); -#else - memory_buf_t outbuf; - fmt::format_system_error(outbuf, last_errno, msg.c_str()); - msg_ = fmt::to_string(outbuf); -#endif -} - -SPDLOG_INLINE const char *spdlog_ex::what() const SPDLOG_NOEXCEPT { return msg_.c_str(); } - -SPDLOG_INLINE void throw_spdlog_ex(const std::string &msg, int last_errno) { - SPDLOG_THROW(spdlog_ex(msg, last_errno)); -} - -SPDLOG_INLINE void throw_spdlog_ex(std::string msg) { SPDLOG_THROW(spdlog_ex(std::move(msg))); } - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/common.h b/examples/blueprints-example/external/spdlog/common.h deleted file mode 100644 index ba9a2e7..0000000 --- a/examples/blueprints-example/external/spdlog/common.h +++ /dev/null @@ -1,406 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef SPDLOG_USE_STD_FORMAT - #include - #if __cpp_lib_format >= 202207L - #include - #else - #include - #endif -#endif - -#ifdef SPDLOG_COMPILED_LIB - #undef SPDLOG_HEADER_ONLY - #if defined(SPDLOG_SHARED_LIB) - #if defined(_WIN32) - #ifdef spdlog_EXPORTS - #define SPDLOG_API __declspec(dllexport) - #else // !spdlog_EXPORTS - #define SPDLOG_API __declspec(dllimport) - #endif - #else // !defined(_WIN32) - #define SPDLOG_API __attribute__((visibility("default"))) - #endif - #else // !defined(SPDLOG_SHARED_LIB) - #define SPDLOG_API - #endif - #define SPDLOG_INLINE -#else // !defined(SPDLOG_COMPILED_LIB) - #define SPDLOG_API - #define SPDLOG_HEADER_ONLY - #define SPDLOG_INLINE inline -#endif // #ifdef SPDLOG_COMPILED_LIB - -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) && \ - FMT_VERSION >= 80000 // backward compatibility with fmt versions older than 8 - #define SPDLOG_FMT_RUNTIME(format_string) fmt::runtime(format_string) - #define SPDLOG_FMT_STRING(format_string) FMT_STRING(format_string) - #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) - #include - #endif -#else - #define SPDLOG_FMT_RUNTIME(format_string) format_string - #define SPDLOG_FMT_STRING(format_string) format_string -#endif - -// visual studio up to 2013 does not support noexcept nor constexpr -#if defined(_MSC_VER) && (_MSC_VER < 1900) - #define SPDLOG_NOEXCEPT _NOEXCEPT - #define SPDLOG_CONSTEXPR -#else - #define SPDLOG_NOEXCEPT noexcept - #define SPDLOG_CONSTEXPR constexpr -#endif - -// If building with std::format, can just use constexpr, otherwise if building with fmt -// SPDLOG_CONSTEXPR_FUNC needs to be set the same as FMT_CONSTEXPR to avoid situations where -// a constexpr function in spdlog could end up calling a non-constexpr function in fmt -// depending on the compiler -// If fmt determines it can't use constexpr, we should inline the function instead -#ifdef SPDLOG_USE_STD_FORMAT - #define SPDLOG_CONSTEXPR_FUNC constexpr -#else // Being built with fmt - #if FMT_USE_CONSTEXPR - #define SPDLOG_CONSTEXPR_FUNC FMT_CONSTEXPR - #else - #define SPDLOG_CONSTEXPR_FUNC inline - #endif -#endif - -#if defined(__GNUC__) || defined(__clang__) - #define SPDLOG_DEPRECATED __attribute__((deprecated)) -#elif defined(_MSC_VER) - #define SPDLOG_DEPRECATED __declspec(deprecated) -#else - #define SPDLOG_DEPRECATED -#endif - -// disable thread local on msvc 2013 -#ifndef SPDLOG_NO_TLS - #if (defined(_MSC_VER) && (_MSC_VER < 1900)) || defined(__cplusplus_winrt) - #define SPDLOG_NO_TLS 1 - #endif -#endif - -#ifndef SPDLOG_FUNCTION - #define SPDLOG_FUNCTION static_cast(__FUNCTION__) -#endif - -#ifdef SPDLOG_NO_EXCEPTIONS - #define SPDLOG_TRY - #define SPDLOG_THROW(ex) \ - do { \ - printf("spdlog fatal error: %s\n", ex.what()); \ - std::abort(); \ - } while (0) - #define SPDLOG_CATCH_STD -#else - #define SPDLOG_TRY try - #define SPDLOG_THROW(ex) throw(ex) - #define SPDLOG_CATCH_STD \ - catch (const std::exception &) { \ - } -#endif - -namespace spdlog { - -class formatter; - -namespace sinks { -class sink; -} - -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) -using filename_t = std::wstring; - // allow macro expansion to occur in SPDLOG_FILENAME_T - #define SPDLOG_FILENAME_T_INNER(s) L##s - #define SPDLOG_FILENAME_T(s) SPDLOG_FILENAME_T_INNER(s) -#else -using filename_t = std::string; - #define SPDLOG_FILENAME_T(s) s -#endif - -using log_clock = std::chrono::system_clock; -using sink_ptr = std::shared_ptr; -using sinks_init_list = std::initializer_list; -using err_handler = std::function; -#ifdef SPDLOG_USE_STD_FORMAT -namespace fmt_lib = std; - -using string_view_t = std::string_view; -using memory_buf_t = std::string; - -template - #if __cpp_lib_format >= 202207L -using format_string_t = std::format_string; - #else -using format_string_t = std::string_view; - #endif - -template -struct is_convertible_to_basic_format_string - : std::integral_constant>::value> {}; - - #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -using wstring_view_t = std::wstring_view; -using wmemory_buf_t = std::wstring; - -template - #if __cpp_lib_format >= 202207L -using wformat_string_t = std::wformat_string; - #else -using wformat_string_t = std::wstring_view; - #endif - #endif - #define SPDLOG_BUF_TO_STRING(x) x -#else // use fmt lib instead of std::format -namespace fmt_lib = fmt; - -using string_view_t = fmt::basic_string_view; -using memory_buf_t = fmt::basic_memory_buffer; - -template -using format_string_t = fmt::format_string; - -template -using remove_cvref_t = typename std::remove_cv::type>::type; - -template - #if FMT_VERSION >= 90101 -using fmt_runtime_string = fmt::runtime_format_string; - #else -using fmt_runtime_string = fmt::basic_runtime; - #endif - -// clang doesn't like SFINAE disabled constructor in std::is_convertible<> so have to repeat the -// condition from basic_format_string here, in addition, fmt::basic_runtime is only -// convertible to basic_format_string but not basic_string_view -template -struct is_convertible_to_basic_format_string - : std::integral_constant>::value || - std::is_same, fmt_runtime_string>::value> { -}; - - #if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -using wstring_view_t = fmt::basic_string_view; -using wmemory_buf_t = fmt::basic_memory_buffer; - -template -using wformat_string_t = fmt::wformat_string; - #endif - #define SPDLOG_BUF_TO_STRING(x) fmt::to_string(x) -#endif - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - #ifndef _WIN32 - #error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows - #endif // _WIN32 -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT - -template -struct is_convertible_to_any_format_string - : std::integral_constant::value || - is_convertible_to_basic_format_string::value> {}; - -#if defined(SPDLOG_NO_ATOMIC_LEVELS) -using level_t = details::null_atomic_int; -#else -using level_t = std::atomic; -#endif - -#define SPDLOG_LEVEL_TRACE 0 -#define SPDLOG_LEVEL_DEBUG 1 -#define SPDLOG_LEVEL_INFO 2 -#define SPDLOG_LEVEL_WARN 3 -#define SPDLOG_LEVEL_ERROR 4 -#define SPDLOG_LEVEL_CRITICAL 5 -#define SPDLOG_LEVEL_OFF 6 - -#if !defined(SPDLOG_ACTIVE_LEVEL) - #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO -#endif - -// Log level enum -namespace level { -enum level_enum : int { - trace = SPDLOG_LEVEL_TRACE, - debug = SPDLOG_LEVEL_DEBUG, - info = SPDLOG_LEVEL_INFO, - warn = SPDLOG_LEVEL_WARN, - err = SPDLOG_LEVEL_ERROR, - critical = SPDLOG_LEVEL_CRITICAL, - off = SPDLOG_LEVEL_OFF, - n_levels -}; - -#define SPDLOG_LEVEL_NAME_TRACE spdlog::string_view_t("trace", 5) -#define SPDLOG_LEVEL_NAME_DEBUG spdlog::string_view_t("debug", 5) -#define SPDLOG_LEVEL_NAME_INFO spdlog::string_view_t("info", 4) -#define SPDLOG_LEVEL_NAME_WARNING spdlog::string_view_t("warning", 7) -#define SPDLOG_LEVEL_NAME_ERROR spdlog::string_view_t("error", 5) -#define SPDLOG_LEVEL_NAME_CRITICAL spdlog::string_view_t("critical", 8) -#define SPDLOG_LEVEL_NAME_OFF spdlog::string_view_t("off", 3) - -#if !defined(SPDLOG_LEVEL_NAMES) - #define SPDLOG_LEVEL_NAMES \ - { \ - SPDLOG_LEVEL_NAME_TRACE, SPDLOG_LEVEL_NAME_DEBUG, SPDLOG_LEVEL_NAME_INFO, \ - SPDLOG_LEVEL_NAME_WARNING, SPDLOG_LEVEL_NAME_ERROR, SPDLOG_LEVEL_NAME_CRITICAL, \ - SPDLOG_LEVEL_NAME_OFF \ - } -#endif - -#if !defined(SPDLOG_SHORT_LEVEL_NAMES) - - #define SPDLOG_SHORT_LEVEL_NAMES \ - { "T", "D", "I", "W", "E", "C", "O" } -#endif - -SPDLOG_API const string_view_t &to_string_view(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; -SPDLOG_API const char *to_short_c_str(spdlog::level::level_enum l) SPDLOG_NOEXCEPT; -SPDLOG_API spdlog::level::level_enum from_str(const std::string &name) SPDLOG_NOEXCEPT; - -} // namespace level - -// -// Color mode used by sinks with color support. -// -enum class color_mode { always, automatic, never }; - -// -// Pattern time - specific time getting to use for pattern_formatter. -// local time by default -// -enum class pattern_time_type { - local, // log localtime - utc // log utc -}; - -// -// Log exception -// -class SPDLOG_API spdlog_ex : public std::exception { -public: - explicit spdlog_ex(std::string msg); - spdlog_ex(const std::string &msg, int last_errno); - const char *what() const SPDLOG_NOEXCEPT override; - -private: - std::string msg_; -}; - -[[noreturn]] SPDLOG_API void throw_spdlog_ex(const std::string &msg, int last_errno); -[[noreturn]] SPDLOG_API void throw_spdlog_ex(std::string msg); - -struct source_loc { - SPDLOG_CONSTEXPR source_loc() = default; - SPDLOG_CONSTEXPR source_loc(const char *filename_in, int line_in, const char *funcname_in) - : filename{filename_in}, - line{line_in}, - funcname{funcname_in} {} - - SPDLOG_CONSTEXPR bool empty() const SPDLOG_NOEXCEPT { return line <= 0; } - const char *filename{nullptr}; - int line{0}; - const char *funcname{nullptr}; -}; - -struct file_event_handlers { - file_event_handlers() - : before_open(nullptr), - after_open(nullptr), - before_close(nullptr), - after_close(nullptr) {} - - std::function before_open; - std::function after_open; - std::function before_close; - std::function after_close; -}; - -namespace details { - -// to_string_view - -SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view(const memory_buf_t &buf) - SPDLOG_NOEXCEPT { - return spdlog::string_view_t{buf.data(), buf.size()}; -} - -SPDLOG_CONSTEXPR_FUNC spdlog::string_view_t to_string_view(spdlog::string_view_t str) - SPDLOG_NOEXCEPT { - return str; -} - -#if defined(SPDLOG_WCHAR_FILENAMES) || defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view(const wmemory_buf_t &buf) - SPDLOG_NOEXCEPT { - return spdlog::wstring_view_t{buf.data(), buf.size()}; -} - -SPDLOG_CONSTEXPR_FUNC spdlog::wstring_view_t to_string_view(spdlog::wstring_view_t str) - SPDLOG_NOEXCEPT { - return str; -} -#endif - -#if defined(SPDLOG_USE_STD_FORMAT) && __cpp_lib_format >= 202207L -template -SPDLOG_CONSTEXPR_FUNC std::basic_string_view to_string_view( - std::basic_format_string fmt) SPDLOG_NOEXCEPT { - return fmt.get(); -} -#endif - -// make_unique support for pre c++14 -#if __cplusplus >= 201402L // C++14 and beyond -using std::enable_if_t; -using std::make_unique; -#else -template -using enable_if_t = typename std::enable_if::type; - -template -std::unique_ptr make_unique(Args &&...args) { - static_assert(!std::is_array::value, "arrays not supported"); - return std::unique_ptr(new T(std::forward(args)...)); -} -#endif - -// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) -template ::value, int> = 0> -constexpr T conditional_static_cast(U value) { - return static_cast(value); -} - -template ::value, int> = 0> -constexpr T conditional_static_cast(U value) { - return value; -} - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "common-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/backtracer-inl.h b/examples/blueprints-example/external/spdlog/details/backtracer-inl.h deleted file mode 100644 index 43d1002..0000000 --- a/examples/blueprints-example/external/spdlog/details/backtracer-inl.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif -namespace spdlog { -namespace details { -SPDLOG_INLINE backtracer::backtracer(const backtracer &other) { - std::lock_guard lock(other.mutex_); - enabled_ = other.enabled(); - messages_ = other.messages_; -} - -SPDLOG_INLINE backtracer::backtracer(backtracer &&other) SPDLOG_NOEXCEPT { - std::lock_guard lock(other.mutex_); - enabled_ = other.enabled(); - messages_ = std::move(other.messages_); -} - -SPDLOG_INLINE backtracer &backtracer::operator=(backtracer other) { - std::lock_guard lock(mutex_); - enabled_ = other.enabled(); - messages_ = std::move(other.messages_); - return *this; -} - -SPDLOG_INLINE void backtracer::enable(size_t size) { - std::lock_guard lock{mutex_}; - enabled_.store(true, std::memory_order_relaxed); - messages_ = circular_q{size}; -} - -SPDLOG_INLINE void backtracer::disable() { - std::lock_guard lock{mutex_}; - enabled_.store(false, std::memory_order_relaxed); -} - -SPDLOG_INLINE bool backtracer::enabled() const { return enabled_.load(std::memory_order_relaxed); } - -SPDLOG_INLINE void backtracer::push_back(const log_msg &msg) { - std::lock_guard lock{mutex_}; - messages_.push_back(log_msg_buffer{msg}); -} - -SPDLOG_INLINE bool backtracer::empty() const { - std::lock_guard lock{mutex_}; - return messages_.empty(); -} - -// pop all items in the q and apply the given fun on each of them. -SPDLOG_INLINE void backtracer::foreach_pop(std::function fun) { - std::lock_guard lock{mutex_}; - while (!messages_.empty()) { - auto &front_msg = messages_.front(); - fun(front_msg); - messages_.pop_front(); - } -} -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/backtracer.h b/examples/blueprints-example/external/spdlog/details/backtracer.h deleted file mode 100644 index 541339c..0000000 --- a/examples/blueprints-example/external/spdlog/details/backtracer.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -#include -#include -#include - -// Store log messages in circular buffer. -// Useful for storing debug data in case of error/warning happens. - -namespace spdlog { -namespace details { -class SPDLOG_API backtracer { - mutable std::mutex mutex_; - std::atomic enabled_{false}; - circular_q messages_; - -public: - backtracer() = default; - backtracer(const backtracer &other); - - backtracer(backtracer &&other) SPDLOG_NOEXCEPT; - backtracer &operator=(backtracer other); - - void enable(size_t size); - void disable(); - bool enabled() const; - void push_back(const log_msg &msg); - bool empty() const; - - // pop all items in the q and apply the given fun on each of them. - void foreach_pop(std::function fun); -}; - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "backtracer-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/circular_q.h b/examples/blueprints-example/external/spdlog/details/circular_q.h deleted file mode 100644 index 29e9d25..0000000 --- a/examples/blueprints-example/external/spdlog/details/circular_q.h +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// circular q view of std::vector. -#pragma once - -#include -#include - -#include "spdlog/common.h" - -namespace spdlog { -namespace details { -template -class circular_q { - size_t max_items_ = 0; - typename std::vector::size_type head_ = 0; - typename std::vector::size_type tail_ = 0; - size_t overrun_counter_ = 0; - std::vector v_; - -public: - using value_type = T; - - // empty ctor - create a disabled queue with no elements allocated at all - circular_q() = default; - - explicit circular_q(size_t max_items) - : max_items_(max_items + 1) // one item is reserved as marker for full q - , - v_(max_items_) {} - - circular_q(const circular_q &) = default; - circular_q &operator=(const circular_q &) = default; - - // move cannot be default, - // since we need to reset head_, tail_, etc to zero in the moved object - circular_q(circular_q &&other) SPDLOG_NOEXCEPT { copy_moveable(std::move(other)); } - - circular_q &operator=(circular_q &&other) SPDLOG_NOEXCEPT { - copy_moveable(std::move(other)); - return *this; - } - - // push back, overrun (oldest) item if no room left - void push_back(T &&item) { - if (max_items_ > 0) { - v_[tail_] = std::move(item); - tail_ = (tail_ + 1) % max_items_; - - if (tail_ == head_) // overrun last item if full - { - head_ = (head_ + 1) % max_items_; - ++overrun_counter_; - } - } - } - - // Return reference to the front item. - // If there are no elements in the container, the behavior is undefined. - const T &front() const { return v_[head_]; } - - T &front() { return v_[head_]; } - - // Return number of elements actually stored - size_t size() const { - if (tail_ >= head_) { - return tail_ - head_; - } else { - return max_items_ - (head_ - tail_); - } - } - - // Return const reference to item by index. - // If index is out of range 0…size()-1, the behavior is undefined. - const T &at(size_t i) const { - assert(i < size()); - return v_[(head_ + i) % max_items_]; - } - - // Pop item from front. - // If there are no elements in the container, the behavior is undefined. - void pop_front() { head_ = (head_ + 1) % max_items_; } - - bool empty() const { return tail_ == head_; } - - bool full() const { - // head is ahead of the tail by 1 - if (max_items_ > 0) { - return ((tail_ + 1) % max_items_) == head_; - } - return false; - } - - size_t overrun_counter() const { return overrun_counter_; } - - void reset_overrun_counter() { overrun_counter_ = 0; } - -private: - // copy from other&& and reset it to disabled state - void copy_moveable(circular_q &&other) SPDLOG_NOEXCEPT { - max_items_ = other.max_items_; - head_ = other.head_; - tail_ = other.tail_; - overrun_counter_ = other.overrun_counter_; - v_ = std::move(other.v_); - - // put &&other in disabled, but valid state - other.max_items_ = 0; - other.head_ = other.tail_ = 0; - other.overrun_counter_ = 0; - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/console_globals.h b/examples/blueprints-example/external/spdlog/details/console_globals.h deleted file mode 100644 index 9c55210..0000000 --- a/examples/blueprints-example/external/spdlog/details/console_globals.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { -namespace details { - -struct console_mutex { - using mutex_t = std::mutex; - static mutex_t &mutex() { - static mutex_t s_mutex; - return s_mutex; - } -}; - -struct console_nullmutex { - using mutex_t = null_mutex; - static mutex_t &mutex() { - static mutex_t s_mutex; - return s_mutex; - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/file_helper-inl.h b/examples/blueprints-example/external/spdlog/details/file_helper-inl.h deleted file mode 100644 index 0c514ef..0000000 --- a/examples/blueprints-example/external/spdlog/details/file_helper-inl.h +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include -#include -#include - -namespace spdlog { -namespace details { - -SPDLOG_INLINE file_helper::file_helper(const file_event_handlers &event_handlers) - : event_handlers_(event_handlers) {} - -SPDLOG_INLINE file_helper::~file_helper() { close(); } - -SPDLOG_INLINE void file_helper::open(const filename_t &fname, bool truncate) { - close(); - filename_ = fname; - - auto *mode = SPDLOG_FILENAME_T("ab"); - auto *trunc_mode = SPDLOG_FILENAME_T("wb"); - - if (event_handlers_.before_open) { - event_handlers_.before_open(filename_); - } - for (int tries = 0; tries < open_tries_; ++tries) { - // create containing folder if not exists already. - os::create_dir(os::dir_name(fname)); - if (truncate) { - // Truncate by opening-and-closing a tmp file in "wb" mode, always - // opening the actual log-we-write-to in "ab" mode, since that - // interacts more politely with eternal processes that might - // rotate/truncate the file underneath us. - std::FILE *tmp; - if (os::fopen_s(&tmp, fname, trunc_mode)) { - continue; - } - std::fclose(tmp); - } - if (!os::fopen_s(&fd_, fname, mode)) { - if (event_handlers_.after_open) { - event_handlers_.after_open(filename_, fd_); - } - return; - } - - details::os::sleep_for_millis(open_interval_); - } - - throw_spdlog_ex("Failed opening file " + os::filename_to_str(filename_) + " for writing", - errno); -} - -SPDLOG_INLINE void file_helper::reopen(bool truncate) { - if (filename_.empty()) { - throw_spdlog_ex("Failed re opening file - was not opened before"); - } - this->open(filename_, truncate); -} - -SPDLOG_INLINE void file_helper::flush() { - if (std::fflush(fd_) != 0) { - throw_spdlog_ex("Failed flush to file " + os::filename_to_str(filename_), errno); - } -} - -SPDLOG_INLINE void file_helper::sync() { - if (!os::fsync(fd_)) { - throw_spdlog_ex("Failed to fsync file " + os::filename_to_str(filename_), errno); - } -} - -SPDLOG_INLINE void file_helper::close() { - if (fd_ != nullptr) { - if (event_handlers_.before_close) { - event_handlers_.before_close(filename_, fd_); - } - - std::fclose(fd_); - fd_ = nullptr; - - if (event_handlers_.after_close) { - event_handlers_.after_close(filename_); - } - } -} - -SPDLOG_INLINE void file_helper::write(const memory_buf_t &buf) { - if (fd_ == nullptr) return; - size_t msg_size = buf.size(); - auto data = buf.data(); - - if (!details::os::fwrite_bytes(data, msg_size, fd_)) { - throw_spdlog_ex("Failed writing to file " + os::filename_to_str(filename_), errno); - } -} - -SPDLOG_INLINE size_t file_helper::size() const { - if (fd_ == nullptr) { - throw_spdlog_ex("Cannot use size() on closed file " + os::filename_to_str(filename_)); - } - return os::filesize(fd_); -} - -SPDLOG_INLINE const filename_t &file_helper::filename() const { return filename_; } - -// -// return file path and its extension: -// -// "mylog.txt" => ("mylog", ".txt") -// "mylog" => ("mylog", "") -// "mylog." => ("mylog.", "") -// "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") -// -// the starting dot in filenames is ignored (hidden files): -// -// ".mylog" => (".mylog". "") -// "my_folder/.mylog" => ("my_folder/.mylog", "") -// "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") -SPDLOG_INLINE std::tuple file_helper::split_by_extension( - const filename_t &fname) { - auto ext_index = fname.rfind('.'); - - // no valid extension found - return whole path and empty string as - // extension - if (ext_index == filename_t::npos || ext_index == 0 || ext_index == fname.size() - 1) { - return std::make_tuple(fname, filename_t()); - } - - // treat cases like "/etc/rc.d/somelogfile or "/abc/.hiddenfile" - auto folder_index = fname.find_last_of(details::os::folder_seps_filename); - if (folder_index != filename_t::npos && folder_index >= ext_index - 1) { - return std::make_tuple(fname, filename_t()); - } - - // finally - return a valid base and extension tuple - return std::make_tuple(fname.substr(0, ext_index), fname.substr(ext_index)); -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/file_helper.h b/examples/blueprints-example/external/spdlog/details/file_helper.h deleted file mode 100644 index f0e5d18..0000000 --- a/examples/blueprints-example/external/spdlog/details/file_helper.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { -namespace details { - -// Helper class for file sinks. -// When failing to open a file, retry several times(5) with a delay interval(10 ms). -// Throw spdlog_ex exception on errors. - -class SPDLOG_API file_helper { -public: - file_helper() = default; - explicit file_helper(const file_event_handlers &event_handlers); - - file_helper(const file_helper &) = delete; - file_helper &operator=(const file_helper &) = delete; - ~file_helper(); - - void open(const filename_t &fname, bool truncate = false); - void reopen(bool truncate); - void flush(); - void sync(); - void close(); - void write(const memory_buf_t &buf); - size_t size() const; - const filename_t &filename() const; - - // - // return file path and its extension: - // - // "mylog.txt" => ("mylog", ".txt") - // "mylog" => ("mylog", "") - // "mylog." => ("mylog.", "") - // "/dir1/dir2/mylog.txt" => ("/dir1/dir2/mylog", ".txt") - // - // the starting dot in filenames is ignored (hidden files): - // - // ".mylog" => (".mylog". "") - // "my_folder/.mylog" => ("my_folder/.mylog", "") - // "my_folder/.mylog.txt" => ("my_folder/.mylog", ".txt") - static std::tuple split_by_extension(const filename_t &fname); - -private: - const int open_tries_ = 5; - const unsigned int open_interval_ = 10; - std::FILE *fd_{nullptr}; - filename_t filename_; - file_event_handlers event_handlers_; -}; -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "file_helper-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/fmt_helper.h b/examples/blueprints-example/external/spdlog/details/fmt_helper.h deleted file mode 100644 index 6130600..0000000 --- a/examples/blueprints-example/external/spdlog/details/fmt_helper.h +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -#pragma once - -#include -#include -#include -#include -#include - -#ifdef SPDLOG_USE_STD_FORMAT - #include - #include -#endif - -// Some fmt helpers to efficiently format and pad ints and strings -namespace spdlog { -namespace details { -namespace fmt_helper { - -inline void append_string_view(spdlog::string_view_t view, memory_buf_t &dest) { - auto *buf_ptr = view.data(); - dest.append(buf_ptr, buf_ptr + view.size()); -} - -#ifdef SPDLOG_USE_STD_FORMAT -template -inline void append_int(T n, memory_buf_t &dest) { - // Buffer should be large enough to hold all digits (digits10 + 1) and a sign - SPDLOG_CONSTEXPR const auto BUF_SIZE = std::numeric_limits::digits10 + 2; - char buf[BUF_SIZE]; - - auto [ptr, ec] = std::to_chars(buf, buf + BUF_SIZE, n, 10); - if (ec == std::errc()) { - dest.append(buf, ptr); - } else { - throw_spdlog_ex("Failed to format int", static_cast(ec)); - } -} -#else -template -inline void append_int(T n, memory_buf_t &dest) { - fmt::format_int i(n); - dest.append(i.data(), i.data() + i.size()); -} -#endif - -template -SPDLOG_CONSTEXPR_FUNC unsigned int count_digits_fallback(T n) { - // taken from fmt: https://github.com/fmtlib/fmt/blob/8.0.1/include/fmt/format.h#L899-L912 - unsigned int count = 1; - for (;;) { - // Integer division is slow so do it for a group of four digits instead - // of for every digit. The idea comes from the talk by Alexandrescu - // "Three Optimization Tips for C++". See speed-test for a comparison. - if (n < 10) return count; - if (n < 100) return count + 1; - if (n < 1000) return count + 2; - if (n < 10000) return count + 3; - n /= 10000u; - count += 4; - } -} - -template -inline unsigned int count_digits(T n) { - using count_type = - typename std::conditional<(sizeof(T) > sizeof(uint32_t)), uint64_t, uint32_t>::type; -#ifdef SPDLOG_USE_STD_FORMAT - return count_digits_fallback(static_cast(n)); -#else - return static_cast(fmt:: - // fmt 7.0.0 renamed the internal namespace to detail. - // See: https://github.com/fmtlib/fmt/issues/1538 - #if FMT_VERSION < 70000 - internal - #else - detail - #endif - ::count_digits(static_cast(n))); -#endif -} - -inline void pad2(int n, memory_buf_t &dest) { - if (n >= 0 && n < 100) // 0-99 - { - dest.push_back(static_cast('0' + n / 10)); - dest.push_back(static_cast('0' + n % 10)); - } else // unlikely, but just in case, let fmt deal with it - { - fmt_lib::format_to(std::back_inserter(dest), SPDLOG_FMT_STRING("{:02}"), n); - } -} - -template -inline void pad_uint(T n, unsigned int width, memory_buf_t &dest) { - static_assert(std::is_unsigned::value, "pad_uint must get unsigned T"); - for (auto digits = count_digits(n); digits < width; digits++) { - dest.push_back('0'); - } - append_int(n, dest); -} - -template -inline void pad3(T n, memory_buf_t &dest) { - static_assert(std::is_unsigned::value, "pad3 must get unsigned T"); - if (n < 1000) { - dest.push_back(static_cast(n / 100 + '0')); - n = n % 100; - dest.push_back(static_cast((n / 10) + '0')); - dest.push_back(static_cast((n % 10) + '0')); - } else { - append_int(n, dest); - } -} - -template -inline void pad6(T n, memory_buf_t &dest) { - pad_uint(n, 6, dest); -} - -template -inline void pad9(T n, memory_buf_t &dest) { - pad_uint(n, 9, dest); -} - -// return fraction of a second of the given time_point. -// e.g. -// fraction(tp) -> will return the millis part of the second -template -inline ToDuration time_fraction(log_clock::time_point tp) { - using std::chrono::duration_cast; - using std::chrono::seconds; - auto duration = tp.time_since_epoch(); - auto secs = duration_cast(duration); - return duration_cast(duration) - duration_cast(secs); -} - -} // namespace fmt_helper -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/log_msg-inl.h b/examples/blueprints-example/external/spdlog/details/log_msg-inl.h deleted file mode 100644 index aa3a957..0000000 --- a/examples/blueprints-example/external/spdlog/details/log_msg-inl.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include - -namespace spdlog { -namespace details { - -SPDLOG_INLINE log_msg::log_msg(spdlog::log_clock::time_point log_time, - spdlog::source_loc loc, - string_view_t a_logger_name, - spdlog::level::level_enum lvl, - spdlog::string_view_t msg) - : logger_name(a_logger_name), - level(lvl), - time(log_time) -#ifndef SPDLOG_NO_THREAD_ID - , - thread_id(os::thread_id()) -#endif - , - source(loc), - payload(msg) { -} - -SPDLOG_INLINE log_msg::log_msg(spdlog::source_loc loc, - string_view_t a_logger_name, - spdlog::level::level_enum lvl, - spdlog::string_view_t msg) - : log_msg(os::now(), loc, a_logger_name, lvl, msg) {} - -SPDLOG_INLINE log_msg::log_msg(string_view_t a_logger_name, - spdlog::level::level_enum lvl, - spdlog::string_view_t msg) - : log_msg(os::now(), source_loc{}, a_logger_name, lvl, msg) {} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/log_msg.h b/examples/blueprints-example/external/spdlog/details/log_msg.h deleted file mode 100644 index 87df1e8..0000000 --- a/examples/blueprints-example/external/spdlog/details/log_msg.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { -namespace details { -struct SPDLOG_API log_msg { - log_msg() = default; - log_msg(log_clock::time_point log_time, - source_loc loc, - string_view_t logger_name, - level::level_enum lvl, - string_view_t msg); - log_msg(source_loc loc, string_view_t logger_name, level::level_enum lvl, string_view_t msg); - log_msg(string_view_t logger_name, level::level_enum lvl, string_view_t msg); - log_msg(const log_msg &other) = default; - log_msg &operator=(const log_msg &other) = default; - - string_view_t logger_name; - level::level_enum level{level::off}; - log_clock::time_point time; - size_t thread_id{0}; - - // wrapping the formatted text with color (updated by pattern_formatter). - mutable size_t color_range_start{0}; - mutable size_t color_range_end{0}; - - source_loc source; - string_view_t payload; -}; -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "log_msg-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/log_msg_buffer-inl.h b/examples/blueprints-example/external/spdlog/details/log_msg_buffer-inl.h deleted file mode 100644 index 2eb2428..0000000 --- a/examples/blueprints-example/external/spdlog/details/log_msg_buffer-inl.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -namespace spdlog { -namespace details { - -SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg &orig_msg) - : log_msg{orig_msg} { - buffer.append(logger_name.begin(), logger_name.end()); - buffer.append(payload.begin(), payload.end()); - update_string_views(); -} - -SPDLOG_INLINE log_msg_buffer::log_msg_buffer(const log_msg_buffer &other) - : log_msg{other} { - buffer.append(logger_name.begin(), logger_name.end()); - buffer.append(payload.begin(), payload.end()); - update_string_views(); -} - -SPDLOG_INLINE log_msg_buffer::log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT - : log_msg{other}, - buffer{std::move(other.buffer)} { - update_string_views(); -} - -SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(const log_msg_buffer &other) { - log_msg::operator=(other); - buffer.clear(); - buffer.append(other.buffer.data(), other.buffer.data() + other.buffer.size()); - update_string_views(); - return *this; -} - -SPDLOG_INLINE log_msg_buffer &log_msg_buffer::operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT { - log_msg::operator=(other); - buffer = std::move(other.buffer); - update_string_views(); - return *this; -} - -SPDLOG_INLINE void log_msg_buffer::update_string_views() { - logger_name = string_view_t{buffer.data(), logger_name.size()}; - payload = string_view_t{buffer.data() + logger_name.size(), payload.size()}; -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/log_msg_buffer.h b/examples/blueprints-example/external/spdlog/details/log_msg_buffer.h deleted file mode 100644 index 1143b3b..0000000 --- a/examples/blueprints-example/external/spdlog/details/log_msg_buffer.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include - -namespace spdlog { -namespace details { - -// Extend log_msg with internal buffer to store its payload. -// This is needed since log_msg holds string_views that points to stack data. - -class SPDLOG_API log_msg_buffer : public log_msg { - memory_buf_t buffer; - void update_string_views(); - -public: - log_msg_buffer() = default; - explicit log_msg_buffer(const log_msg &orig_msg); - log_msg_buffer(const log_msg_buffer &other); - log_msg_buffer(log_msg_buffer &&other) SPDLOG_NOEXCEPT; - log_msg_buffer &operator=(const log_msg_buffer &other); - log_msg_buffer &operator=(log_msg_buffer &&other) SPDLOG_NOEXCEPT; -}; - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "log_msg_buffer-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/mpmc_blocking_q.h b/examples/blueprints-example/external/spdlog/details/mpmc_blocking_q.h deleted file mode 100644 index 5848cca..0000000 --- a/examples/blueprints-example/external/spdlog/details/mpmc_blocking_q.h +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// multi producer-multi consumer blocking queue. -// enqueue(..) - will block until room found to put the new message. -// enqueue_nowait(..) - will return immediately with false if no room left in -// the queue. -// dequeue_for(..) - will block until the queue is not empty or timeout have -// passed. - -#include - -#include -#include -#include - -namespace spdlog { -namespace details { - -template -class mpmc_blocking_queue { -public: - using item_type = T; - explicit mpmc_blocking_queue(size_t max_items) - : q_(max_items) {} - -#ifndef __MINGW32__ - // try to enqueue and block if no room left - void enqueue(T &&item) { - { - std::unique_lock lock(queue_mutex_); - pop_cv_.wait(lock, [this] { return !this->q_.full(); }); - q_.push_back(std::move(item)); - } - push_cv_.notify_one(); - } - - // enqueue immediately. overrun oldest message in the queue if no room left. - void enqueue_nowait(T &&item) { - { - std::unique_lock lock(queue_mutex_); - q_.push_back(std::move(item)); - } - push_cv_.notify_one(); - } - - void enqueue_if_have_room(T &&item) { - bool pushed = false; - { - std::unique_lock lock(queue_mutex_); - if (!q_.full()) { - q_.push_back(std::move(item)); - pushed = true; - } - } - - if (pushed) { - push_cv_.notify_one(); - } else { - ++discard_counter_; - } - } - - // dequeue with a timeout. - // Return true, if succeeded dequeue item, false otherwise - bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration) { - { - std::unique_lock lock(queue_mutex_); - if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); })) { - return false; - } - popped_item = std::move(q_.front()); - q_.pop_front(); - } - pop_cv_.notify_one(); - return true; - } - - // blocking dequeue without a timeout. - void dequeue(T &popped_item) { - { - std::unique_lock lock(queue_mutex_); - push_cv_.wait(lock, [this] { return !this->q_.empty(); }); - popped_item = std::move(q_.front()); - q_.pop_front(); - } - pop_cv_.notify_one(); - } - -#else - // apparently mingw deadlocks if the mutex is released before cv.notify_one(), - // so release the mutex at the very end each function. - - // try to enqueue and block if no room left - void enqueue(T &&item) { - std::unique_lock lock(queue_mutex_); - pop_cv_.wait(lock, [this] { return !this->q_.full(); }); - q_.push_back(std::move(item)); - push_cv_.notify_one(); - } - - // enqueue immediately. overrun oldest message in the queue if no room left. - void enqueue_nowait(T &&item) { - std::unique_lock lock(queue_mutex_); - q_.push_back(std::move(item)); - push_cv_.notify_one(); - } - - void enqueue_if_have_room(T &&item) { - bool pushed = false; - std::unique_lock lock(queue_mutex_); - if (!q_.full()) { - q_.push_back(std::move(item)); - pushed = true; - } - - if (pushed) { - push_cv_.notify_one(); - } else { - ++discard_counter_; - } - } - - // dequeue with a timeout. - // Return true, if succeeded dequeue item, false otherwise - bool dequeue_for(T &popped_item, std::chrono::milliseconds wait_duration) { - std::unique_lock lock(queue_mutex_); - if (!push_cv_.wait_for(lock, wait_duration, [this] { return !this->q_.empty(); })) { - return false; - } - popped_item = std::move(q_.front()); - q_.pop_front(); - pop_cv_.notify_one(); - return true; - } - - // blocking dequeue without a timeout. - void dequeue(T &popped_item) { - std::unique_lock lock(queue_mutex_); - push_cv_.wait(lock, [this] { return !this->q_.empty(); }); - popped_item = std::move(q_.front()); - q_.pop_front(); - pop_cv_.notify_one(); - } - -#endif - - size_t overrun_counter() { - std::lock_guard lock(queue_mutex_); - return q_.overrun_counter(); - } - - size_t discard_counter() { return discard_counter_.load(std::memory_order_relaxed); } - - size_t size() { - std::lock_guard lock(queue_mutex_); - return q_.size(); - } - - void reset_overrun_counter() { - std::lock_guard lock(queue_mutex_); - q_.reset_overrun_counter(); - } - - void reset_discard_counter() { discard_counter_.store(0, std::memory_order_relaxed); } - -private: - std::mutex queue_mutex_; - std::condition_variable push_cv_; - std::condition_variable pop_cv_; - spdlog::details::circular_q q_; - std::atomic discard_counter_{0}; -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/null_mutex.h b/examples/blueprints-example/external/spdlog/details/null_mutex.h deleted file mode 100644 index e3b3220..0000000 --- a/examples/blueprints-example/external/spdlog/details/null_mutex.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -// null, no cost dummy "mutex" and dummy "atomic" int - -namespace spdlog { -namespace details { -struct null_mutex { - void lock() const {} - void unlock() const {} -}; - -struct null_atomic_int { - int value; - null_atomic_int() = default; - - explicit null_atomic_int(int new_value) - : value(new_value) {} - - int load(std::memory_order = std::memory_order_relaxed) const { return value; } - - void store(int new_value, std::memory_order = std::memory_order_relaxed) { value = new_value; } - - int exchange(int new_value, std::memory_order = std::memory_order_relaxed) { - std::swap(new_value, value); - return new_value; // return value before the call - } -}; - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/os-inl.h b/examples/blueprints-example/external/spdlog/details/os-inl.h deleted file mode 100644 index 8a2e203..0000000 --- a/examples/blueprints-example/external/spdlog/details/os-inl.h +++ /dev/null @@ -1,605 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _WIN32 - #include - #include // for _get_osfhandle, _isatty, _fileno - #include // for _get_pid - - #ifdef __MINGW32__ - #include - #endif - - #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES) - #include - #include - #endif - - #include // for _mkdir/_wmkdir - -#else // unix - - #include - #include - - #ifdef __linux__ - #include //Use gettid() syscall under linux to get thread id - - #elif defined(_AIX) - #include // for pthread_getthrds_np - - #elif defined(__DragonFly__) || defined(__FreeBSD__) - #include // for pthread_getthreadid_np - - #elif defined(__NetBSD__) - #include // for _lwp_self - - #elif defined(__sun) - #include // for thr_self - #endif - -#endif // unix - -#if defined __APPLE__ - #include -#endif - -#ifndef __has_feature // Clang - feature checking macros. - #define __has_feature(x) 0 // Compatibility with non-clang compilers. -#endif - -namespace spdlog { -namespace details { -namespace os { - -SPDLOG_INLINE spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT { -#if defined __linux__ && defined SPDLOG_CLOCK_COARSE - timespec ts; - ::clock_gettime(CLOCK_REALTIME_COARSE, &ts); - return std::chrono::time_point( - std::chrono::duration_cast( - std::chrono::seconds(ts.tv_sec) + std::chrono::nanoseconds(ts.tv_nsec))); - -#else - return log_clock::now(); -#endif -} -SPDLOG_INLINE std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT { -#ifdef _WIN32 - std::tm tm; - ::localtime_s(&tm, &time_tt); -#else - std::tm tm; - ::localtime_r(&time_tt, &tm); -#endif - return tm; -} - -SPDLOG_INLINE std::tm localtime() SPDLOG_NOEXCEPT { - std::time_t now_t = ::time(nullptr); - return localtime(now_t); -} - -SPDLOG_INLINE std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT { -#ifdef _WIN32 - std::tm tm; - ::gmtime_s(&tm, &time_tt); -#else - std::tm tm; - ::gmtime_r(&time_tt, &tm); -#endif - return tm; -} - -SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT { - std::time_t now_t = ::time(nullptr); - return gmtime(now_t); -} - -// fopen_s on non windows for writing -SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) { -#ifdef _WIN32 - #ifdef SPDLOG_WCHAR_FILENAMES - *fp = ::_wfsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); - #else - *fp = ::_fsopen((filename.c_str()), mode.c_str(), _SH_DENYNO); - #endif - #if defined(SPDLOG_PREVENT_CHILD_FD) - if (*fp != nullptr) { - auto file_handle = reinterpret_cast(_get_osfhandle(::_fileno(*fp))); - if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0)) { - ::fclose(*fp); - *fp = nullptr; - } - } - #endif -#else // unix - #if defined(SPDLOG_PREVENT_CHILD_FD) - const int mode_flag = mode == SPDLOG_FILENAME_T("ab") ? O_APPEND : O_TRUNC; - const int fd = - ::open((filename.c_str()), O_CREAT | O_WRONLY | O_CLOEXEC | mode_flag, mode_t(0644)); - if (fd == -1) { - return true; - } - *fp = ::fdopen(fd, mode.c_str()); - if (*fp == nullptr) { - ::close(fd); - } - #else - *fp = ::fopen((filename.c_str()), mode.c_str()); - #endif -#endif - - return *fp == nullptr; -} - -SPDLOG_INLINE int remove(const filename_t &filename) SPDLOG_NOEXCEPT { -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) - return ::_wremove(filename.c_str()); -#else - return std::remove(filename.c_str()); -#endif -} - -SPDLOG_INLINE int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT { - return path_exists(filename) ? remove(filename) : 0; -} - -SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT { -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) - return ::_wrename(filename1.c_str(), filename2.c_str()); -#else - return std::rename(filename1.c_str(), filename2.c_str()); -#endif -} - -// Return true if path exists (file or directory) -SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT { -#ifdef _WIN32 - struct _stat buffer; - #ifdef SPDLOG_WCHAR_FILENAMES - return (::_wstat(filename.c_str(), &buffer) == 0); - #else - return (::_stat(filename.c_str(), &buffer) == 0); - #endif -#else // common linux/unix all have the stat system call - struct stat buffer; - return (::stat(filename.c_str(), &buffer) == 0); -#endif -} - -#ifdef _MSC_VER - // avoid warning about unreachable statement at the end of filesize() - #pragma warning(push) - #pragma warning(disable : 4702) -#endif - -// Return file size according to open FILE* object -SPDLOG_INLINE size_t filesize(FILE *f) { - if (f == nullptr) { - throw_spdlog_ex("Failed getting file size. fd is null"); - } -#if defined(_WIN32) && !defined(__CYGWIN__) - int fd = ::_fileno(f); - #if defined(_WIN64) // 64 bits - __int64 ret = ::_filelengthi64(fd); - if (ret >= 0) { - return static_cast(ret); - } - - #else // windows 32 bits - long ret = ::_filelength(fd); - if (ret >= 0) { - return static_cast(ret); - } - #endif - -#else // unix - // OpenBSD and AIX doesn't compile with :: before the fileno(..) - #if defined(__OpenBSD__) || defined(_AIX) - int fd = fileno(f); - #else - int fd = ::fileno(f); - #endif - // 64 bits(but not in osx, linux/musl or cygwin, where fstat64 is deprecated) - #if ((defined(__linux__) && defined(__GLIBC__)) || defined(__sun) || defined(_AIX)) && \ - (defined(__LP64__) || defined(_LP64)) - struct stat64 st; - if (::fstat64(fd, &st) == 0) { - return static_cast(st.st_size); - } - #else // other unix or linux 32 bits or cygwin - struct stat st; - if (::fstat(fd, &st) == 0) { - return static_cast(st.st_size); - } - #endif -#endif - throw_spdlog_ex("Failed getting file size from fd", errno); - return 0; // will not be reached. -} - -#ifdef _MSC_VER - #pragma warning(pop) -#endif - -// Return utc offset in minutes or throw spdlog_ex on failure -SPDLOG_INLINE int utc_minutes_offset(const std::tm &tm) { -#ifdef _WIN32 - #if _WIN32_WINNT < _WIN32_WINNT_WS08 - TIME_ZONE_INFORMATION tzinfo; - auto rv = ::GetTimeZoneInformation(&tzinfo); - #else - DYNAMIC_TIME_ZONE_INFORMATION tzinfo; - auto rv = ::GetDynamicTimeZoneInformation(&tzinfo); - #endif - if (rv == TIME_ZONE_ID_INVALID) throw_spdlog_ex("Failed getting timezone info. ", errno); - - int offset = -tzinfo.Bias; - if (tm.tm_isdst) { - offset -= tzinfo.DaylightBias; - } else { - offset -= tzinfo.StandardBias; - } - return offset; -#else - - #if defined(sun) || defined(__sun) || defined(_AIX) || \ - (defined(__NEWLIB__) && !defined(__TM_GMTOFF)) || \ - (!defined(__APPLE__) && !defined(_BSD_SOURCE) && !defined(_GNU_SOURCE) && \ - (!defined(_POSIX_VERSION) || (_POSIX_VERSION < 202405L))) - // 'tm_gmtoff' field is BSD extension and it's missing on SunOS/Solaris - struct helper { - static long int calculate_gmt_offset(const std::tm &localtm = details::os::localtime(), - const std::tm &gmtm = details::os::gmtime()) { - int local_year = localtm.tm_year + (1900 - 1); - int gmt_year = gmtm.tm_year + (1900 - 1); - - long int days = ( - // difference in day of year - localtm.tm_yday - - gmtm.tm_yday - - // + intervening leap days - + ((local_year >> 2) - (gmt_year >> 2)) - (local_year / 100 - gmt_year / 100) + - ((local_year / 100 >> 2) - (gmt_year / 100 >> 2)) - - // + difference in years * 365 */ - + static_cast(local_year - gmt_year) * 365); - - long int hours = (24 * days) + (localtm.tm_hour - gmtm.tm_hour); - long int mins = (60 * hours) + (localtm.tm_min - gmtm.tm_min); - long int secs = (60 * mins) + (localtm.tm_sec - gmtm.tm_sec); - - return secs; - } - }; - - auto offset_seconds = helper::calculate_gmt_offset(tm); - #else - auto offset_seconds = tm.tm_gmtoff; - #endif - - return static_cast(offset_seconds / 60); -#endif -} - -// Return current thread id as size_t -// It exists because the std::this_thread::get_id() is much slower(especially -// under VS 2013) -SPDLOG_INLINE size_t _thread_id() SPDLOG_NOEXCEPT { -#ifdef _WIN32 - return static_cast(::GetCurrentThreadId()); -#elif defined(__linux__) - #if defined(__ANDROID__) && defined(__ANDROID_API__) && (__ANDROID_API__ < 21) - #define SYS_gettid __NR_gettid - #endif - return static_cast(::syscall(SYS_gettid)); -#elif defined(_AIX) - struct __pthrdsinfo buf; - int reg_size = 0; - pthread_t pt = pthread_self(); - int retval = pthread_getthrds_np(&pt, PTHRDSINFO_QUERY_TID, &buf, sizeof(buf), NULL, ®_size); - int tid = (!retval) ? buf.__pi_tid : 0; - return static_cast(tid); -#elif defined(__DragonFly__) || defined(__FreeBSD__) - return static_cast(::pthread_getthreadid_np()); -#elif defined(__NetBSD__) - return static_cast(::_lwp_self()); -#elif defined(__OpenBSD__) - return static_cast(::getthrid()); -#elif defined(__sun) - return static_cast(::thr_self()); -#elif __APPLE__ - uint64_t tid; - // There is no pthread_threadid_np prior to Mac OS X 10.6, and it is not supported on any PPC, - // including 10.6.8 Rosetta. __POWERPC__ is Apple-specific define encompassing ppc and ppc64. - #ifdef MAC_OS_X_VERSION_MAX_ALLOWED - { - #if (MAC_OS_X_VERSION_MAX_ALLOWED < 1060) || defined(__POWERPC__) - tid = pthread_mach_thread_np(pthread_self()); - #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1060 - if (&pthread_threadid_np) { - pthread_threadid_np(nullptr, &tid); - } else { - tid = pthread_mach_thread_np(pthread_self()); - } - #else - pthread_threadid_np(nullptr, &tid); - #endif - } - #else - pthread_threadid_np(nullptr, &tid); - #endif - return static_cast(tid); -#else // Default to standard C++11 (other Unix) - return static_cast(std::hash()(std::this_thread::get_id())); -#endif -} - -// Return current thread id as size_t (from thread local storage) -SPDLOG_INLINE size_t thread_id() SPDLOG_NOEXCEPT { -#if defined(SPDLOG_NO_TLS) - return _thread_id(); -#else // cache thread id in tls - static thread_local const size_t tid = _thread_id(); - return tid; -#endif -} - -// This is avoid msvc issue in sleep_for that happens if the clock changes. -// See https://github.com/gabime/spdlog/issues/609 -SPDLOG_INLINE void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT { -#if defined(_WIN32) - ::Sleep(milliseconds); -#else - std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); -#endif -} - -// wchar support for windows file names (SPDLOG_WCHAR_FILENAMES must be defined) -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) -SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) { - memory_buf_t buf; - wstr_to_utf8buf(filename, buf); - return SPDLOG_BUF_TO_STRING(buf); -} -#else -SPDLOG_INLINE std::string filename_to_str(const filename_t &filename) { return filename; } -#endif - -SPDLOG_INLINE int pid() SPDLOG_NOEXCEPT { -#ifdef _WIN32 - return conditional_static_cast(::GetCurrentProcessId()); -#else - return conditional_static_cast(::getpid()); -#endif -} - -// Determine if the terminal supports colors -// Based on: https://github.com/agauniyal/rang/ -SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT { -#ifdef _WIN32 - return true; -#else - - static const bool result = []() { - const char *env_colorterm_p = std::getenv("COLORTERM"); - if (env_colorterm_p != nullptr) { - return true; - } - - static constexpr std::array terms = { - {"ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", - "putty", "rxvt", "screen", "vt100", "xterm", "alacritty", "vt102"}}; - - const char *env_term_p = std::getenv("TERM"); - if (env_term_p == nullptr) { - return false; - } - - return std::any_of(terms.begin(), terms.end(), [&](const char *term) { - return std::strstr(env_term_p, term) != nullptr; - }); - }(); - - return result; -#endif -} - -// Determine if the terminal attached -// Source: https://github.com/agauniyal/rang/ -SPDLOG_INLINE bool in_terminal(FILE *file) SPDLOG_NOEXCEPT { -#ifdef _WIN32 - return ::_isatty(_fileno(file)) != 0; -#else - return ::isatty(fileno(file)) != 0; -#endif -} - -#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) -SPDLOG_INLINE void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target) { - if (wstr.size() > static_cast((std::numeric_limits::max)()) / 4 - 1) { - throw_spdlog_ex("UTF-16 string is too big to be converted to UTF-8"); - } - - int wstr_size = static_cast(wstr.size()); - if (wstr_size == 0) { - target.resize(0); - return; - } - - int result_size = static_cast(target.capacity()); - if ((wstr_size + 1) * 4 > result_size) { - result_size = - ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, NULL, 0, NULL, NULL); - } - - if (result_size > 0) { - target.resize(result_size); - result_size = ::WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr_size, target.data(), - result_size, NULL, NULL); - - if (result_size > 0) { - target.resize(result_size); - return; - } - } - - throw_spdlog_ex( - fmt_lib::format("WideCharToMultiByte failed. Last error: {}", ::GetLastError())); -} - -SPDLOG_INLINE void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target) { - if (str.size() > static_cast((std::numeric_limits::max)()) - 1) { - throw_spdlog_ex("UTF-8 string is too big to be converted to UTF-16"); - } - - int str_size = static_cast(str.size()); - if (str_size == 0) { - target.resize(0); - return; - } - - // find the size to allocate for the result buffer - int result_size = ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, NULL, 0); - - if (result_size > 0) { - target.resize(result_size); - result_size = - ::MultiByteToWideChar(CP_UTF8, 0, str.data(), str_size, target.data(), result_size); - if (result_size > 0) { - assert(result_size == static_cast(target.size())); - return; - } - } - - throw_spdlog_ex( - fmt_lib::format("MultiByteToWideChar failed. Last error: {}", ::GetLastError())); -} -#endif // (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && - // defined(_WIN32) - -// return true on success -static SPDLOG_INLINE bool mkdir_(const filename_t &path) { -#ifdef _WIN32 - #ifdef SPDLOG_WCHAR_FILENAMES - return ::_wmkdir(path.c_str()) == 0; - #else - return ::_mkdir(path.c_str()) == 0; - #endif -#else - return ::mkdir(path.c_str(), mode_t(0755)) == 0; -#endif -} - -// create the given directory - and all directories leading to it -// return true on success or if the directory already exists -SPDLOG_INLINE bool create_dir(const filename_t &path) { - if (path_exists(path)) { - return true; - } - - if (path.empty()) { - return false; - } - - size_t search_offset = 0; - do { - auto token_pos = path.find_first_of(folder_seps_filename, search_offset); - // treat the entire path as a folder if no folder separator not found - if (token_pos == filename_t::npos) { - token_pos = path.size(); - } - - auto subdir = path.substr(0, token_pos); -#ifdef _WIN32 - // if subdir is just a drive letter, add a slash e.g. "c:"=>"c:\", - // otherwise path_exists(subdir) returns false (issue #3079) - const bool is_drive = subdir.length() == 2 && subdir[1] == ':'; - if (is_drive) { - subdir += '\\'; - token_pos++; - } -#endif - - if (!subdir.empty() && !path_exists(subdir) && !mkdir_(subdir)) { - return false; // return error if failed creating dir - } - search_offset = token_pos + 1; - } while (search_offset < path.size()); - - return true; -} - -// Return directory name from given path or empty string -// "abc/file" => "abc" -// "abc/" => "abc" -// "abc" => "" -// "abc///" => "abc//" -SPDLOG_INLINE filename_t dir_name(const filename_t &path) { - auto pos = path.find_last_of(folder_seps_filename); - return pos != filename_t::npos ? path.substr(0, pos) : filename_t{}; -} - -#ifdef _MSC_VER - #pragma warning(push) - #pragma warning(disable : 4996) -#endif // _MSC_VER -std::string SPDLOG_INLINE getenv(const char *field) { -#if defined(_MSC_VER) && defined(__cplusplus_winrt) - return std::string{}; // not supported under uwp -#else - char *buf = std::getenv(field); - return buf ? buf : std::string{}; -#endif -} -#ifdef _MSC_VER - #pragma warning(pop) -#endif // _MSC_VER - -// Do fsync by FILE handlerpointer -// Return true on success -SPDLOG_INLINE bool fsync(FILE *fp) { -#ifdef _WIN32 - return FlushFileBuffers(reinterpret_cast(_get_osfhandle(_fileno(fp)))) != 0; -#else - return ::fsync(fileno(fp)) == 0; -#endif -} - -// Do non-locking fwrite if possible by the os or use the regular locking fwrite -// Return true on success. -SPDLOG_INLINE bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp) { -#if defined(_WIN32) && defined(SPDLOG_FWRITE_UNLOCKED) - return _fwrite_nolock(ptr, 1, n_bytes, fp) == n_bytes; -#elif defined(SPDLOG_FWRITE_UNLOCKED) - return ::fwrite_unlocked(ptr, 1, n_bytes, fp) == n_bytes; -#else - return std::fwrite(ptr, 1, n_bytes, fp) == n_bytes; -#endif -} - -} // namespace os -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/os.h b/examples/blueprints-example/external/spdlog/details/os.h deleted file mode 100644 index 5fd12ba..0000000 --- a/examples/blueprints-example/external/spdlog/details/os.h +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include // std::time_t -#include - -namespace spdlog { -namespace details { -namespace os { - -SPDLOG_API spdlog::log_clock::time_point now() SPDLOG_NOEXCEPT; - -SPDLOG_API std::tm localtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; - -SPDLOG_API std::tm localtime() SPDLOG_NOEXCEPT; - -SPDLOG_API std::tm gmtime(const std::time_t &time_tt) SPDLOG_NOEXCEPT; - -SPDLOG_API std::tm gmtime() SPDLOG_NOEXCEPT; - -// eol definition -#if !defined(SPDLOG_EOL) - #ifdef _WIN32 - #define SPDLOG_EOL "\r\n" - #else - #define SPDLOG_EOL "\n" - #endif -#endif - -SPDLOG_CONSTEXPR static const char *default_eol = SPDLOG_EOL; - -// folder separator -#if !defined(SPDLOG_FOLDER_SEPS) - #ifdef _WIN32 - #define SPDLOG_FOLDER_SEPS "\\/" - #else - #define SPDLOG_FOLDER_SEPS "/" - #endif -#endif - -SPDLOG_CONSTEXPR static const char folder_seps[] = SPDLOG_FOLDER_SEPS; -SPDLOG_CONSTEXPR static const filename_t::value_type folder_seps_filename[] = - SPDLOG_FILENAME_T(SPDLOG_FOLDER_SEPS); - -// fopen_s on non windows for writing -SPDLOG_API bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); - -// Remove filename. return 0 on success -SPDLOG_API int remove(const filename_t &filename) SPDLOG_NOEXCEPT; - -// Remove file if exists. return 0 on success -// Note: Non atomic (might return failure to delete if concurrently deleted by other process/thread) -SPDLOG_API int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT; - -SPDLOG_API int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT; - -// Return if file exists. -SPDLOG_API bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT; - -// Return file size according to open FILE* object -SPDLOG_API size_t filesize(FILE *f); - -// Return utc offset in minutes or throw spdlog_ex on failure -SPDLOG_API int utc_minutes_offset(const std::tm &tm = details::os::localtime()); - -// Return current thread id as size_t -// It exists because the std::this_thread::get_id() is much slower(especially -// under VS 2013) -SPDLOG_API size_t _thread_id() SPDLOG_NOEXCEPT; - -// Return current thread id as size_t (from thread local storage) -SPDLOG_API size_t thread_id() SPDLOG_NOEXCEPT; - -// This is avoid msvc issue in sleep_for that happens if the clock changes. -// See https://github.com/gabime/spdlog/issues/609 -SPDLOG_API void sleep_for_millis(unsigned int milliseconds) SPDLOG_NOEXCEPT; - -SPDLOG_API std::string filename_to_str(const filename_t &filename); - -SPDLOG_API int pid() SPDLOG_NOEXCEPT; - -// Determine if the terminal supports colors -// Source: https://github.com/agauniyal/rang/ -SPDLOG_API bool is_color_terminal() SPDLOG_NOEXCEPT; - -// Determine if the terminal attached -// Source: https://github.com/agauniyal/rang/ -SPDLOG_API bool in_terminal(FILE *file) SPDLOG_NOEXCEPT; - -#if (defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) || defined(SPDLOG_WCHAR_FILENAMES)) && defined(_WIN32) -SPDLOG_API void wstr_to_utf8buf(wstring_view_t wstr, memory_buf_t &target); - -SPDLOG_API void utf8_to_wstrbuf(string_view_t str, wmemory_buf_t &target); -#endif - -// Return directory name from given path or empty string -// "abc/file" => "abc" -// "abc/" => "abc" -// "abc" => "" -// "abc///" => "abc//" -SPDLOG_API filename_t dir_name(const filename_t &path); - -// Create a dir from the given path. -// Return true if succeeded or if this dir already exists. -SPDLOG_API bool create_dir(const filename_t &path); - -// non thread safe, cross platform getenv/getenv_s -// return empty string if field not found -SPDLOG_API std::string getenv(const char *field); - -// Do fsync by FILE objectpointer. -// Return true on success. -SPDLOG_API bool fsync(FILE *fp); - -// Do non-locking fwrite if possible by the os or use the regular locking fwrite -// Return true on success. -SPDLOG_API bool fwrite_bytes(const void *ptr, const size_t n_bytes, FILE *fp); - -} // namespace os -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "os-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/periodic_worker-inl.h b/examples/blueprints-example/external/spdlog/details/periodic_worker-inl.h deleted file mode 100644 index 18f11fb..0000000 --- a/examples/blueprints-example/external/spdlog/details/periodic_worker-inl.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -namespace spdlog { -namespace details { - -// stop the worker thread and join it -SPDLOG_INLINE periodic_worker::~periodic_worker() { - if (worker_thread_.joinable()) { - { - std::lock_guard lock(mutex_); - active_ = false; - } - cv_.notify_one(); - worker_thread_.join(); - } -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/periodic_worker.h b/examples/blueprints-example/external/spdlog/details/periodic_worker.h deleted file mode 100644 index d647b66..0000000 --- a/examples/blueprints-example/external/spdlog/details/periodic_worker.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// periodic worker thread - periodically executes the given callback function. -// -// RAII over the owned thread: -// creates the thread on construction. -// stops and joins the thread on destruction (if the thread is executing a callback, wait for it -// to finish first). - -#include -#include -#include -#include -#include -namespace spdlog { -namespace details { - -class SPDLOG_API periodic_worker { -public: - template - periodic_worker(const std::function &callback_fun, - std::chrono::duration interval) { - active_ = (interval > std::chrono::duration::zero()); - if (!active_) { - return; - } - - worker_thread_ = std::thread([this, callback_fun, interval]() { - for (;;) { - std::unique_lock lock(this->mutex_); - if (this->cv_.wait_for(lock, interval, [this] { return !this->active_; })) { - return; // active_ == false, so exit this thread - } - callback_fun(); - } - }); - } - std::thread &get_thread() { return worker_thread_; } - periodic_worker(const periodic_worker &) = delete; - periodic_worker &operator=(const periodic_worker &) = delete; - // stop the worker thread and join it - ~periodic_worker(); - -private: - bool active_; - std::thread worker_thread_; - std::mutex mutex_; - std::condition_variable cv_; -}; -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "periodic_worker-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/registry-inl.h b/examples/blueprints-example/external/spdlog/details/registry-inl.h deleted file mode 100644 index 272bebb..0000000 --- a/examples/blueprints-example/external/spdlog/details/registry-inl.h +++ /dev/null @@ -1,270 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include -#include -#include - -#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER - // support for the default stdout color logger - #ifdef _WIN32 - #include - #else - #include - #endif -#endif // SPDLOG_DISABLE_DEFAULT_LOGGER - -#include -#include -#include -#include -#include - -namespace spdlog { -namespace details { - -SPDLOG_INLINE registry::registry() - : formatter_(new pattern_formatter()) { -#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER - // create default logger (ansicolor_stdout_sink_mt or wincolor_stdout_sink_mt in windows). - #ifdef _WIN32 - auto color_sink = std::make_shared(); - #else - auto color_sink = std::make_shared(); - #endif - - const char *default_logger_name = ""; - default_logger_ = std::make_shared(default_logger_name, std::move(color_sink)); - loggers_[default_logger_name] = default_logger_; - -#endif // SPDLOG_DISABLE_DEFAULT_LOGGER -} - -SPDLOG_INLINE registry::~registry() = default; - -SPDLOG_INLINE void registry::register_logger(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - register_logger_(std::move(new_logger)); -} - -SPDLOG_INLINE void registry::register_or_replace(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - register_or_replace_(std::move(new_logger)); -} - -SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - new_logger->set_formatter(formatter_->clone()); - - if (err_handler_) { - new_logger->set_error_handler(err_handler_); - } - - // set new level according to previously configured level or default level - auto it = log_levels_.find(new_logger->name()); - auto new_level = it != log_levels_.end() ? it->second : global_log_level_; - new_logger->set_level(new_level); - - new_logger->flush_on(flush_level_); - - if (backtrace_n_messages_ > 0) { - new_logger->enable_backtrace(backtrace_n_messages_); - } - - if (automatic_registration_) { - register_logger_(std::move(new_logger)); - } -} - -SPDLOG_INLINE std::shared_ptr registry::get(const std::string &logger_name) { - std::lock_guard lock(logger_map_mutex_); - auto found = loggers_.find(logger_name); - return found == loggers_.end() ? nullptr : found->second; -} - -SPDLOG_INLINE std::shared_ptr registry::default_logger() { - std::lock_guard lock(logger_map_mutex_); - return default_logger_; -} - -// Return raw ptr to the default logger. -// To be used directly by the spdlog default api (e.g. spdlog::info) -// This make the default API faster, but cannot be used concurrently with set_default_logger(). -// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another. -SPDLOG_INLINE logger *registry::get_default_raw() { return default_logger_.get(); } - -// set default logger. -// the default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. -SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr new_default_logger) { - std::lock_guard lock(logger_map_mutex_); - if (new_default_logger != nullptr) { - loggers_[new_default_logger->name()] = new_default_logger; - } - default_logger_ = std::move(new_default_logger); -} - -SPDLOG_INLINE void registry::set_tp(std::shared_ptr tp) { - std::lock_guard lock(tp_mutex_); - tp_ = std::move(tp); -} - -SPDLOG_INLINE std::shared_ptr registry::get_tp() { - std::lock_guard lock(tp_mutex_); - return tp_; -} - -// Set global formatter. Each sink in each logger will get a clone of this object -SPDLOG_INLINE void registry::set_formatter(std::unique_ptr formatter) { - std::lock_guard lock(logger_map_mutex_); - formatter_ = std::move(formatter); - for (auto &l : loggers_) { - l.second->set_formatter(formatter_->clone()); - } -} - -SPDLOG_INLINE void registry::enable_backtrace(size_t n_messages) { - std::lock_guard lock(logger_map_mutex_); - backtrace_n_messages_ = n_messages; - - for (auto &l : loggers_) { - l.second->enable_backtrace(n_messages); - } -} - -SPDLOG_INLINE void registry::disable_backtrace() { - std::lock_guard lock(logger_map_mutex_); - backtrace_n_messages_ = 0; - for (auto &l : loggers_) { - l.second->disable_backtrace(); - } -} - -SPDLOG_INLINE void registry::set_level(level::level_enum log_level) { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - l.second->set_level(log_level); - } - global_log_level_ = log_level; -} - -SPDLOG_INLINE void registry::flush_on(level::level_enum log_level) { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - l.second->flush_on(log_level); - } - flush_level_ = log_level; -} - -SPDLOG_INLINE void registry::set_error_handler(err_handler handler) { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - l.second->set_error_handler(handler); - } - err_handler_ = std::move(handler); -} - -SPDLOG_INLINE void registry::apply_all( - const std::function)> &fun) { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - fun(l.second); - } -} - -SPDLOG_INLINE void registry::flush_all() { - std::lock_guard lock(logger_map_mutex_); - for (auto &l : loggers_) { - l.second->flush(); - } -} - -SPDLOG_INLINE void registry::drop(const std::string &logger_name) { - std::lock_guard lock(logger_map_mutex_); - auto is_default_logger = default_logger_ && default_logger_->name() == logger_name; - loggers_.erase(logger_name); - if (is_default_logger) { - default_logger_.reset(); - } -} - -SPDLOG_INLINE void registry::drop_all() { - std::lock_guard lock(logger_map_mutex_); - loggers_.clear(); - default_logger_.reset(); -} - -// clean all resources and threads started by the registry -SPDLOG_INLINE void registry::shutdown() { - { - std::lock_guard lock(flusher_mutex_); - periodic_flusher_.reset(); - } - - drop_all(); - - { - std::lock_guard lock(tp_mutex_); - tp_.reset(); - } -} - -SPDLOG_INLINE std::recursive_mutex ®istry::tp_mutex() { return tp_mutex_; } - -SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registration) { - std::lock_guard lock(logger_map_mutex_); - automatic_registration_ = automatic_registration; -} - -SPDLOG_INLINE void registry::set_levels(log_levels levels, level::level_enum *global_level) { - std::lock_guard lock(logger_map_mutex_); - log_levels_ = std::move(levels); - auto global_level_requested = global_level != nullptr; - global_log_level_ = global_level_requested ? *global_level : global_log_level_; - - for (auto &logger : loggers_) { - auto logger_entry = log_levels_.find(logger.first); - if (logger_entry != log_levels_.end()) { - logger.second->set_level(logger_entry->second); - } else if (global_level_requested) { - logger.second->set_level(*global_level); - } - } -} - -SPDLOG_INLINE registry ®istry::instance() { - static registry s_instance; - return s_instance; -} - -SPDLOG_INLINE void registry::apply_logger_env_levels(std::shared_ptr new_logger) { - std::lock_guard lock(logger_map_mutex_); - auto it = log_levels_.find(new_logger->name()); - auto new_level = it != log_levels_.end() ? it->second : global_log_level_; - new_logger->set_level(new_level); -} - -SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name) { - if (loggers_.find(logger_name) != loggers_.end()) { - throw_spdlog_ex("logger with name '" + logger_name + "' already exists"); - } -} - -SPDLOG_INLINE void registry::register_logger_(std::shared_ptr new_logger) { - auto &logger_name = new_logger->name(); - throw_if_exists_(logger_name); - loggers_[logger_name] = std::move(new_logger); -} - -SPDLOG_INLINE void registry::register_or_replace_(std::shared_ptr new_logger) { - loggers_[new_logger->name()] = std::move(new_logger); -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/registry.h b/examples/blueprints-example/external/spdlog/details/registry.h deleted file mode 100644 index 72c70b8..0000000 --- a/examples/blueprints-example/external/spdlog/details/registry.h +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Loggers registry of unique name->logger pointer -// An attempt to create a logger with an already existing name will result with spdlog_ex exception. -// If user requests a non existing logger, nullptr will be returned -// This class is thread safe - -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace spdlog { -class logger; - -namespace details { -class thread_pool; - -class SPDLOG_API registry { -public: - using log_levels = std::unordered_map; - registry(const registry &) = delete; - registry &operator=(const registry &) = delete; - - void register_logger(std::shared_ptr new_logger); - void register_or_replace(std::shared_ptr new_logger); - void initialize_logger(std::shared_ptr new_logger); - std::shared_ptr get(const std::string &logger_name); - std::shared_ptr default_logger(); - - // Return raw ptr to the default logger. - // To be used directly by the spdlog default api (e.g. spdlog::info) - // This make the default API faster, but cannot be used concurrently with set_default_logger(). - // e.g do not call set_default_logger() from one thread while calling spdlog::info() from - // another. - logger *get_default_raw(); - - // set default logger and add it to the registry if not registered already. - // default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map. - // Note: Make sure to unregister it when no longer needed or before calling again with a new - // logger. - void set_default_logger(std::shared_ptr new_default_logger); - - void set_tp(std::shared_ptr tp); - - std::shared_ptr get_tp(); - - // Set global formatter. Each sink in each logger will get a clone of this object - void set_formatter(std::unique_ptr formatter); - - void enable_backtrace(size_t n_messages); - - void disable_backtrace(); - - void set_level(level::level_enum log_level); - - void flush_on(level::level_enum log_level); - - template - void flush_every(std::chrono::duration interval) { - std::lock_guard lock(flusher_mutex_); - auto clbk = [this]() { this->flush_all(); }; - periodic_flusher_ = details::make_unique(clbk, interval); - } - - std::unique_ptr &get_flusher() { - std::lock_guard lock(flusher_mutex_); - return periodic_flusher_; - } - - void set_error_handler(err_handler handler); - - void apply_all(const std::function)> &fun); - - void flush_all(); - - void drop(const std::string &logger_name); - - void drop_all(); - - // clean all resources and threads started by the registry - void shutdown(); - - std::recursive_mutex &tp_mutex(); - - void set_automatic_registration(bool automatic_registration); - - // set levels for all existing/future loggers. global_level can be null if should not set. - void set_levels(log_levels levels, level::level_enum *global_level); - - static registry &instance(); - - void apply_logger_env_levels(std::shared_ptr new_logger); - -private: - registry(); - ~registry(); - - void throw_if_exists_(const std::string &logger_name); - void register_logger_(std::shared_ptr new_logger); - void register_or_replace_(std::shared_ptr new_logger); - bool set_level_from_cfg_(logger *logger); - std::mutex logger_map_mutex_, flusher_mutex_; - std::recursive_mutex tp_mutex_; - std::unordered_map> loggers_; - log_levels log_levels_; - std::unique_ptr formatter_; - spdlog::level::level_enum global_log_level_ = level::info; - level::level_enum flush_level_ = level::off; - err_handler err_handler_; - std::shared_ptr tp_; - std::unique_ptr periodic_flusher_; - std::shared_ptr default_logger_; - bool automatic_registration_ = true; - size_t backtrace_n_messages_ = 0; -}; - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "registry-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/synchronous_factory.h b/examples/blueprints-example/external/spdlog/details/synchronous_factory.h deleted file mode 100644 index 4bd5a51..0000000 --- a/examples/blueprints-example/external/spdlog/details/synchronous_factory.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include "registry.h" - -namespace spdlog { - -// Default logger factory- creates synchronous loggers -class logger; - -struct synchronous_factory { - template - static std::shared_ptr create(std::string logger_name, SinkArgs &&...args) { - auto sink = std::make_shared(std::forward(args)...); - auto new_logger = std::make_shared(std::move(logger_name), std::move(sink)); - details::registry::instance().initialize_logger(new_logger); - return new_logger; - } -}; -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/tcp_client-windows.h b/examples/blueprints-example/external/spdlog/details/tcp_client-windows.h deleted file mode 100644 index 956f9f9..0000000 --- a/examples/blueprints-example/external/spdlog/details/tcp_client-windows.h +++ /dev/null @@ -1,217 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#define WIN32_LEAN_AND_MEAN -// tcp client helper -#include -#include - -#include -#include -#include -#include -#include -#include - -#pragma comment(lib, "Ws2_32.lib") -#pragma comment(lib, "Mswsock.lib") -#pragma comment(lib, "AdvApi32.lib") - -namespace spdlog { -namespace details { -class tcp_client { - SOCKET socket_ = INVALID_SOCKET; - - static void init_winsock_() { - WSADATA wsaData; - auto rv = WSAStartup(MAKEWORD(2, 2), &wsaData); - if (rv != 0) { - throw_winsock_error_("WSAStartup failed", ::WSAGetLastError()); - } - } - - static void throw_winsock_error_(const std::string &msg, int last_error) { - char buf[512]; - ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, - (sizeof(buf) / sizeof(char)), NULL); - - throw_spdlog_ex(fmt_lib::format("tcp_sink - {}: {}", msg, buf)); - } - -public: - tcp_client() { init_winsock_(); } - - ~tcp_client() { - close(); - ::WSACleanup(); - } - - bool is_connected() const { return socket_ != INVALID_SOCKET; } - - void close() { - ::closesocket(socket_); - socket_ = INVALID_SOCKET; - } - - SOCKET fd() const { return socket_; } - - int connect_socket_with_timeout(SOCKET sockfd, - const struct sockaddr *addr, - int addrlen, - const timeval &tv) { - // If no timeout requested, do a normal blocking connect. - if (tv.tv_sec == 0 && tv.tv_usec == 0) { - int rv = ::connect(sockfd, addr, addrlen); - if (rv == SOCKET_ERROR && WSAGetLastError() == WSAEISCONN) { - return 0; - } - return rv; - } - - // Switch to nonâ€blocking mode - u_long mode = 1UL; - if (::ioctlsocket(sockfd, FIONBIO, &mode) == SOCKET_ERROR) { - return SOCKET_ERROR; - } - - int rv = ::connect(sockfd, addr, addrlen); - int last_error = WSAGetLastError(); - if (rv == 0 || last_error == WSAEISCONN) { - mode = 0UL; - if (::ioctlsocket(sockfd, FIONBIO, &mode) == SOCKET_ERROR) { - return SOCKET_ERROR; - } - return 0; - } - if (last_error != WSAEWOULDBLOCK) { - // Real error - mode = 0UL; - if (::ioctlsocket(sockfd, FIONBIO, &mode)) { - return SOCKET_ERROR; - } - return SOCKET_ERROR; - } - - // Wait until socket is writable or timeout expires - fd_set wfds; - FD_ZERO(&wfds); - FD_SET(sockfd, &wfds); - - rv = ::select(0, nullptr, &wfds, nullptr, const_cast(&tv)); - - // Restore blocking mode regardless of select result - mode = 0UL; - if (::ioctlsocket(sockfd, FIONBIO, &mode) == SOCKET_ERROR) { - return SOCKET_ERROR; - } - - if (rv == 0) { - WSASetLastError(WSAETIMEDOUT); - return SOCKET_ERROR; - } - if (rv == SOCKET_ERROR) { - return SOCKET_ERROR; - } - - int so_error = 0; - int len = sizeof(so_error); - if (::getsockopt(sockfd, SOL_SOCKET, SO_ERROR, reinterpret_cast(&so_error), &len) == - SOCKET_ERROR) { - return SOCKET_ERROR; - } - if (so_error != 0 && so_error != WSAEISCONN) { - // connection failed - WSASetLastError(so_error); - return SOCKET_ERROR; - } - - return 0; // success - } - - // try to connect or throw on failure - void connect(const std::string &host, int port, int timeout_ms = 0) { - if (is_connected()) { - close(); - } - struct addrinfo hints {}; - ZeroMemory(&hints, sizeof(hints)); - - hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on - hints.ai_socktype = SOCK_STREAM; // TCP - hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value - hints.ai_protocol = 0; - - timeval tv; - tv.tv_sec = timeout_ms / 1000; - tv.tv_usec = (timeout_ms % 1000) * 1000; - - auto port_str = std::to_string(port); - struct addrinfo *addrinfo_result; - auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result); - int last_error = 0; - if (rv != 0) { - last_error = ::WSAGetLastError(); - WSACleanup(); - throw_winsock_error_("getaddrinfo failed", last_error); - } - - // Try each address until we successfully connect(2). - for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) { - socket_ = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - if (socket_ == INVALID_SOCKET) { - last_error = ::WSAGetLastError(); - WSACleanup(); - continue; - } - if (connect_socket_with_timeout(socket_, rp->ai_addr, (int)rp->ai_addrlen, tv) == 0) { - last_error = 0; - break; - } - last_error = WSAGetLastError(); - ::closesocket(socket_); - socket_ = INVALID_SOCKET; - } - ::freeaddrinfo(addrinfo_result); - if (socket_ == INVALID_SOCKET) { - WSACleanup(); - throw_winsock_error_("connect failed", last_error); - } - if (timeout_ms > 0) { - DWORD tv = static_cast(timeout_ms); - ::setsockopt(socket_, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv)); - ::setsockopt(socket_, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tv, sizeof(tv)); - } - - // set TCP_NODELAY - int enable_flag = 1; - ::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&enable_flag), - sizeof(enable_flag)); - } - - // Send exactly n_bytes of the given data. - // On error close the connection and throw. - void send(const char *data, size_t n_bytes) { - size_t bytes_sent = 0; - while (bytes_sent < n_bytes) { - const int send_flags = 0; - auto write_result = - ::send(socket_, data + bytes_sent, (int)(n_bytes - bytes_sent), send_flags); - if (write_result == SOCKET_ERROR) { - int last_error = ::WSAGetLastError(); - close(); - throw_winsock_error_("send failed", last_error); - } - - if (write_result == 0) // (probably should not happen but in any case..) - { - break; - } - bytes_sent += static_cast(write_result); - } - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/tcp_client.h b/examples/blueprints-example/external/spdlog/details/tcp_client.h deleted file mode 100644 index 1eaa3cb..0000000 --- a/examples/blueprints-example/external/spdlog/details/tcp_client.h +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifdef _WIN32 - #error include tcp_client-windows.h instead -#endif - -// tcp client helper -#include -#include - -#include -#include -#include -#include -#include -#include - -#include - -namespace spdlog { -namespace details { -class tcp_client { - int socket_ = -1; - -public: - bool is_connected() const { return socket_ != -1; } - - void close() { - if (is_connected()) { - ::close(socket_); - socket_ = -1; - } - } - - int fd() const { return socket_; } - - ~tcp_client() { close(); } - - int connect_socket_with_timeout(int sockfd, - const struct sockaddr *addr, - socklen_t addrlen, - const timeval &tv) { - // Blocking connect if timeout is zero - if (tv.tv_sec == 0 && tv.tv_usec == 0) { - int rv = ::connect(sockfd, addr, addrlen); - if (rv < 0 && errno == EISCONN) { - // already connected, treat as success - return 0; - } - return rv; - } - - // Non-blocking path - int orig_flags = ::fcntl(sockfd, F_GETFL, 0); - if (orig_flags < 0) { - return -1; - } - if (::fcntl(sockfd, F_SETFL, orig_flags | O_NONBLOCK) < 0) { - return -1; - } - - int rv = ::connect(sockfd, addr, addrlen); - if (rv == 0 || (rv < 0 && errno == EISCONN)) { - // immediate connect or already connected - ::fcntl(sockfd, F_SETFL, orig_flags); - return 0; - } - if (errno != EINPROGRESS) { - ::fcntl(sockfd, F_SETFL, orig_flags); - return -1; - } - - // wait for writability - fd_set wfds; - FD_ZERO(&wfds); - FD_SET(sockfd, &wfds); - - struct timeval tv_copy = tv; - rv = ::select(sockfd + 1, nullptr, &wfds, nullptr, &tv_copy); - if (rv <= 0) { - // timeout or error - ::fcntl(sockfd, F_SETFL, orig_flags); - if (rv == 0) errno = ETIMEDOUT; - return -1; - } - - // check socket error - int so_error = 0; - socklen_t len = sizeof(so_error); - if (::getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &so_error, &len) < 0) { - ::fcntl(sockfd, F_SETFL, orig_flags); - return -1; - } - ::fcntl(sockfd, F_SETFL, orig_flags); - if (so_error != 0 && so_error != EISCONN) { - errno = so_error; - return -1; - } - - return 0; - } - - // try to connect or throw on failure - void connect(const std::string &host, int port, int timeout_ms = 0) { - close(); - struct addrinfo hints {}; - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; // To work with IPv4, IPv6, and so on - hints.ai_socktype = SOCK_STREAM; // TCP - hints.ai_flags = AI_NUMERICSERV; // port passed as as numeric value - hints.ai_protocol = 0; - - struct timeval tv; - tv.tv_sec = timeout_ms / 1000; - tv.tv_usec = (timeout_ms % 1000) * 1000; - - auto port_str = std::to_string(port); - struct addrinfo *addrinfo_result; - auto rv = ::getaddrinfo(host.c_str(), port_str.c_str(), &hints, &addrinfo_result); - if (rv != 0) { - throw_spdlog_ex(fmt_lib::format("::getaddrinfo failed: {}", gai_strerror(rv))); - } - - // Try each address until we successfully connect(2). - int last_errno = 0; - for (auto *rp = addrinfo_result; rp != nullptr; rp = rp->ai_next) { -#if defined(SOCK_CLOEXEC) - const int flags = SOCK_CLOEXEC; -#else - const int flags = 0; -#endif - socket_ = ::socket(rp->ai_family, rp->ai_socktype | flags, rp->ai_protocol); - if (socket_ == -1) { - last_errno = errno; - continue; - } - ::fcntl(socket_, F_SETFD, FD_CLOEXEC); - if (connect_socket_with_timeout(socket_, rp->ai_addr, rp->ai_addrlen, tv) == 0) { - last_errno = 0; - break; - } - last_errno = errno; - ::close(socket_); - socket_ = -1; - } - ::freeaddrinfo(addrinfo_result); - if (socket_ == -1) { - throw_spdlog_ex("::connect failed", last_errno); - } - - if (timeout_ms > 0) { - // Set timeouts for send and recv - ::setsockopt(socket_, SOL_SOCKET, SO_RCVTIMEO, (const char *)&tv, sizeof(tv)); - ::setsockopt(socket_, SOL_SOCKET, SO_SNDTIMEO, (const char *)&tv, sizeof(tv)); - } - - // set TCP_NODELAY - int enable_flag = 1; - ::setsockopt(socket_, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&enable_flag), - sizeof(enable_flag)); - - // prevent sigpipe on systems where MSG_NOSIGNAL is not available -#if defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) - ::setsockopt(socket_, SOL_SOCKET, SO_NOSIGPIPE, reinterpret_cast(&enable_flag), - sizeof(enable_flag)); -#endif - -#if !defined(SO_NOSIGPIPE) && !defined(MSG_NOSIGNAL) - #error "tcp_sink would raise SIGPIPE since neither SO_NOSIGPIPE nor MSG_NOSIGNAL are available" -#endif - } - - // Send exactly n_bytes of the given data. - // On error close the connection and throw. - void send(const char *data, size_t n_bytes) { - size_t bytes_sent = 0; - while (bytes_sent < n_bytes) { -#if defined(MSG_NOSIGNAL) - const int send_flags = MSG_NOSIGNAL; -#else - const int send_flags = 0; -#endif - auto write_result = - ::send(socket_, data + bytes_sent, n_bytes - bytes_sent, send_flags); - if (write_result < 0) { - close(); - throw_spdlog_ex("write(2) failed", errno); - } - - if (write_result == 0) // (probably should not happen but in any case..) - { - break; - } - bytes_sent += static_cast(write_result); - } - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/thread_pool-inl.h b/examples/blueprints-example/external/spdlog/details/thread_pool-inl.h deleted file mode 100644 index b172b28..0000000 --- a/examples/blueprints-example/external/spdlog/details/thread_pool-inl.h +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { -namespace details { - -SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, - size_t threads_n, - std::function on_thread_start, - std::function on_thread_stop) - : q_(q_max_items) { - if (threads_n == 0 || threads_n > 1000) { - throw_spdlog_ex( - "spdlog::thread_pool(): invalid threads_n param (valid " - "range is 1-1000)"); - } - for (size_t i = 0; i < threads_n; i++) { - threads_.emplace_back([this, on_thread_start, on_thread_stop] { - on_thread_start(); - this->thread_pool::worker_loop_(); - on_thread_stop(); - }); - } -} - -SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, - size_t threads_n, - std::function on_thread_start) - : thread_pool(q_max_items, threads_n, std::move(on_thread_start), [] {}) {} - -SPDLOG_INLINE thread_pool::thread_pool(size_t q_max_items, size_t threads_n) - : thread_pool(q_max_items, threads_n, [] {}, [] {}) {} - -// message all threads to terminate gracefully join them -SPDLOG_INLINE thread_pool::~thread_pool() { - SPDLOG_TRY { - for (size_t i = 0; i < threads_.size(); i++) { - post_async_msg_(async_msg(async_msg_type::terminate), async_overflow_policy::block); - } - - for (auto &t : threads_) { - t.join(); - } - } - SPDLOG_CATCH_STD -} - -void SPDLOG_INLINE thread_pool::post_log(async_logger_ptr &&worker_ptr, - const details::log_msg &msg, - async_overflow_policy overflow_policy) { - async_msg async_m(std::move(worker_ptr), async_msg_type::log, msg); - post_async_msg_(std::move(async_m), overflow_policy); -} - -void SPDLOG_INLINE thread_pool::post_flush(async_logger_ptr &&worker_ptr, - async_overflow_policy overflow_policy) { - post_async_msg_(async_msg(std::move(worker_ptr), async_msg_type::flush), overflow_policy); -} - -size_t SPDLOG_INLINE thread_pool::overrun_counter() { return q_.overrun_counter(); } - -void SPDLOG_INLINE thread_pool::reset_overrun_counter() { q_.reset_overrun_counter(); } - -size_t SPDLOG_INLINE thread_pool::discard_counter() { return q_.discard_counter(); } - -void SPDLOG_INLINE thread_pool::reset_discard_counter() { q_.reset_discard_counter(); } - -size_t SPDLOG_INLINE thread_pool::queue_size() { return q_.size(); } - -void SPDLOG_INLINE thread_pool::post_async_msg_(async_msg &&new_msg, - async_overflow_policy overflow_policy) { - if (overflow_policy == async_overflow_policy::block) { - q_.enqueue(std::move(new_msg)); - } else if (overflow_policy == async_overflow_policy::overrun_oldest) { - q_.enqueue_nowait(std::move(new_msg)); - } else { - assert(overflow_policy == async_overflow_policy::discard_new); - q_.enqueue_if_have_room(std::move(new_msg)); - } -} - -void SPDLOG_INLINE thread_pool::worker_loop_() { - while (process_next_msg_()) { - } -} - -// process next message in the queue -// returns true if this thread should still be active (while no terminated msg was received) -bool SPDLOG_INLINE thread_pool::process_next_msg_() { - async_msg incoming_async_msg; - q_.dequeue(incoming_async_msg); - - switch (incoming_async_msg.msg_type) { - case async_msg_type::log: { - incoming_async_msg.worker_ptr->backend_sink_it_(incoming_async_msg); - return true; - } - case async_msg_type::flush: { - incoming_async_msg.worker_ptr->backend_flush_(); - return true; - } - - case async_msg_type::terminate: { - return false; - } - - default: { - assert(false); - } - } - - return true; -} - -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/thread_pool.h b/examples/blueprints-example/external/spdlog/details/thread_pool.h deleted file mode 100644 index f22b078..0000000 --- a/examples/blueprints-example/external/spdlog/details/thread_pool.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace spdlog { -class async_logger; - -namespace details { - -using async_logger_ptr = std::shared_ptr; - -enum class async_msg_type { log, flush, terminate }; - -// Async msg to move to/from the queue -// Movable only. should never be copied -struct async_msg : log_msg_buffer { - async_msg_type msg_type{async_msg_type::log}; - async_logger_ptr worker_ptr; - - async_msg() = default; - ~async_msg() = default; - - // should only be moved in or out of the queue.. - async_msg(const async_msg &) = delete; - -// support for vs2013 move -#if defined(_MSC_VER) && _MSC_VER <= 1800 - async_msg(async_msg &&other) - : log_msg_buffer(std::move(other)), - msg_type(other.msg_type), - worker_ptr(std::move(other.worker_ptr)) {} - - async_msg &operator=(async_msg &&other) { - *static_cast(this) = std::move(other); - msg_type = other.msg_type; - worker_ptr = std::move(other.worker_ptr); - return *this; - } -#else // (_MSC_VER) && _MSC_VER <= 1800 - async_msg(async_msg &&) = default; - async_msg &operator=(async_msg &&) = default; -#endif - - // construct from log_msg with given type - async_msg(async_logger_ptr &&worker, async_msg_type the_type, const details::log_msg &m) - : log_msg_buffer{m}, - msg_type{the_type}, - worker_ptr{std::move(worker)} {} - - async_msg(async_logger_ptr &&worker, async_msg_type the_type) - : log_msg_buffer{}, - msg_type{the_type}, - worker_ptr{std::move(worker)} {} - - explicit async_msg(async_msg_type the_type) - : async_msg{nullptr, the_type} {} -}; - -class SPDLOG_API thread_pool { -public: - using item_type = async_msg; - using q_type = details::mpmc_blocking_queue; - - thread_pool(size_t q_max_items, - size_t threads_n, - std::function on_thread_start, - std::function on_thread_stop); - thread_pool(size_t q_max_items, size_t threads_n, std::function on_thread_start); - thread_pool(size_t q_max_items, size_t threads_n); - - // message all threads to terminate gracefully and join them - ~thread_pool(); - - thread_pool(const thread_pool &) = delete; - thread_pool &operator=(thread_pool &&) = delete; - - void post_log(async_logger_ptr &&worker_ptr, - const details::log_msg &msg, - async_overflow_policy overflow_policy); - void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy); - size_t overrun_counter(); - void reset_overrun_counter(); - size_t discard_counter(); - void reset_discard_counter(); - size_t queue_size(); - -private: - q_type q_; - - std::vector threads_; - - void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy); - void worker_loop_(); - - // process next message in the queue - // return true if this thread should still be active (while no terminate msg - // was received) - bool process_next_msg_(); -}; - -} // namespace details -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "thread_pool-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/details/udp_client-windows.h b/examples/blueprints-example/external/spdlog/details/udp_client-windows.h deleted file mode 100644 index 8b7c223..0000000 --- a/examples/blueprints-example/external/spdlog/details/udp_client-windows.h +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Helper RAII over winsock udp client socket. -// Will throw on construction if socket creation failed. - -#include -#include -#include -#include -#include -#include -#include -#include - -#if defined(_MSC_VER) - #pragma comment(lib, "Ws2_32.lib") - #pragma comment(lib, "Mswsock.lib") - #pragma comment(lib, "AdvApi32.lib") -#endif - -namespace spdlog { -namespace details { -class udp_client { - static constexpr int TX_BUFFER_SIZE = 1024 * 10; - SOCKET socket_ = INVALID_SOCKET; - sockaddr_in addr_ = {}; - - static void init_winsock_() { - WSADATA wsaData; - auto rv = ::WSAStartup(MAKEWORD(2, 2), &wsaData); - if (rv != 0) { - throw_winsock_error_("WSAStartup failed", ::WSAGetLastError()); - } - } - - static void throw_winsock_error_(const std::string &msg, int last_error) { - char buf[512]; - ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, - last_error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, - (sizeof(buf) / sizeof(char)), NULL); - - throw_spdlog_ex(fmt_lib::format("udp_sink - {}: {}", msg, buf)); - } - - void cleanup_() { - if (socket_ != INVALID_SOCKET) { - ::closesocket(socket_); - } - socket_ = INVALID_SOCKET; - ::WSACleanup(); - } - -public: - udp_client(const std::string &host, uint16_t port) { - init_winsock_(); - - addr_.sin_family = PF_INET; - addr_.sin_port = htons(port); - addr_.sin_addr.s_addr = INADDR_ANY; - if (InetPtonA(PF_INET, host.c_str(), &addr_.sin_addr.s_addr) != 1) { - int last_error = ::WSAGetLastError(); - ::WSACleanup(); - throw_winsock_error_("error: Invalid address!", last_error); - } - - socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); - if (socket_ == INVALID_SOCKET) { - int last_error = ::WSAGetLastError(); - ::WSACleanup(); - throw_winsock_error_("error: Create Socket failed", last_error); - } - - int option_value = TX_BUFFER_SIZE; - if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, - reinterpret_cast(&option_value), sizeof(option_value)) < 0) { - int last_error = ::WSAGetLastError(); - cleanup_(); - throw_winsock_error_("error: setsockopt(SO_SNDBUF) Failed!", last_error); - } - } - - ~udp_client() { cleanup_(); } - - SOCKET fd() const { return socket_; } - - void send(const char *data, size_t n_bytes) { - socklen_t tolen = sizeof(struct sockaddr); - if (::sendto(socket_, data, static_cast(n_bytes), 0, (struct sockaddr *)&addr_, - tolen) == -1) { - throw_spdlog_ex("sendto(2) failed", errno); - } - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/udp_client.h b/examples/blueprints-example/external/spdlog/details/udp_client.h deleted file mode 100644 index 95826f5..0000000 --- a/examples/blueprints-example/external/spdlog/details/udp_client.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Helper RAII over unix udp client socket. -// Will throw on construction if the socket creation failed. - -#ifdef _WIN32 - #error "include udp_client-windows.h instead" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -namespace spdlog { -namespace details { - -class udp_client { - static constexpr int TX_BUFFER_SIZE = 1024 * 10; - int socket_ = -1; - struct sockaddr_in sockAddr_; - - void cleanup_() { - if (socket_ != -1) { - ::close(socket_); - socket_ = -1; - } - } - -public: - udp_client(const std::string &host, uint16_t port) { - socket_ = ::socket(PF_INET, SOCK_DGRAM, 0); - if (socket_ < 0) { - throw_spdlog_ex("error: Create Socket Failed!"); - } - - int option_value = TX_BUFFER_SIZE; - if (::setsockopt(socket_, SOL_SOCKET, SO_SNDBUF, - reinterpret_cast(&option_value), sizeof(option_value)) < 0) { - cleanup_(); - throw_spdlog_ex("error: setsockopt(SO_SNDBUF) Failed!"); - } - - sockAddr_.sin_family = AF_INET; - sockAddr_.sin_port = htons(port); - - if (::inet_aton(host.c_str(), &sockAddr_.sin_addr) == 0) { - cleanup_(); - throw_spdlog_ex("error: Invalid address!"); - } - - ::memset(sockAddr_.sin_zero, 0x00, sizeof(sockAddr_.sin_zero)); - } - - ~udp_client() { cleanup_(); } - - int fd() const { return socket_; } - - // Send exactly n_bytes of the given data. - // On error close the connection and throw. - void send(const char *data, size_t n_bytes) { - ssize_t toslen = 0; - socklen_t tolen = sizeof(struct sockaddr); - if ((toslen = ::sendto(socket_, data, n_bytes, 0, (struct sockaddr *)&sockAddr_, tolen)) == - -1) { - throw_spdlog_ex("sendto(2) failed", errno); - } - } -}; -} // namespace details -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/details/windows_include.h b/examples/blueprints-example/external/spdlog/details/windows_include.h deleted file mode 100644 index bbab59b..0000000 --- a/examples/blueprints-example/external/spdlog/details/windows_include.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifndef NOMINMAX - #define NOMINMAX // prevent windows redefining min/max -#endif - -#ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN -#endif - -#include diff --git a/examples/blueprints-example/external/spdlog/example.cpp b/examples/blueprints-example/external/spdlog/example.cpp deleted file mode 100644 index 16575d1..0000000 --- a/examples/blueprints-example/external/spdlog/example.cpp +++ /dev/null @@ -1,401 +0,0 @@ -// -// Copyright(c) 2015 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// spdlog usage example - -#include -#include - -void load_levels_example(); -void stdout_logger_example(); -void basic_example(); -void rotating_example(); -void daily_example(); -void callback_example(); -void async_example(); -void binary_example(); -void vector_example(); -void stopwatch_example(); -void trace_example(); -void multi_sink_example(); -void user_defined_example(); -void err_handler_example(); -void syslog_example(); -void udp_example(); -void custom_flags_example(); -void file_events_example(); -void replace_default_logger_example(); -void mdc_example(); - -#include "spdlog/spdlog.h" -#include "spdlog/cfg/env.h" // support for loading levels from the environment variable -#include "spdlog/fmt/ostr.h" // support for user defined types - -int main(int, char *[]) { - try { - // Log levels can be loaded from argv/env using "SPDLOG_LEVEL" - load_levels_example(); - - spdlog::info("Welcome to spdlog version {}.{}.{} !", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, - SPDLOG_VER_PATCH); - - spdlog::warn("Easy padding in numbers like {:08d}", 12); - spdlog::critical("Support for int: {0:d}; hex: {0:x}; oct: {0:o}; bin: {0:b}", 42); - spdlog::info("Support for floats {:03.2f}", 1.23456); - spdlog::info("Positional args are {1} {0}..", "too", "supported"); - spdlog::info("{:>8} aligned, {:<8} aligned", "right", "left"); - - // Runtime log levels - spdlog::set_level(spdlog::level::info); // Set global log level to info - spdlog::debug("This message should not be displayed!"); - spdlog::set_level(spdlog::level::trace); // Set specific logger's log level - spdlog::debug("This message should be displayed.."); - - // Customize msg format for all loggers - spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [thread %t] %v"); - spdlog::info("This an info message with custom format"); - spdlog::set_pattern("%+"); // back to default format - spdlog::set_level(spdlog::level::info); - - // Backtrace support - // Loggers can store in a ring buffer all messages (including debug/trace) for later - // inspection. When needed, call dump_backtrace() to see what happened: - spdlog::enable_backtrace(10); // create ring buffer with capacity of 10 messages - for (int i = 0; i < 100; i++) { - spdlog::debug("Backtrace message {}", i); // not logged.. - } - // e.g. if some error happened: - spdlog::dump_backtrace(); // log them now! - - stdout_logger_example(); - basic_example(); - rotating_example(); - daily_example(); - callback_example(); - async_example(); - binary_example(); - vector_example(); - multi_sink_example(); - user_defined_example(); - err_handler_example(); - trace_example(); - stopwatch_example(); - udp_example(); - custom_flags_example(); - file_events_example(); - replace_default_logger_example(); - mdc_example(); - - // Flush all *registered* loggers using a worker thread every 3 seconds. - // note: registered loggers *must* be thread safe for this to work correctly! - spdlog::flush_every(std::chrono::seconds(3)); - - // Apply some function on all registered loggers - spdlog::apply_all([&](std::shared_ptr l) { l->info("End of example."); }); - - // Release all spdlog resources, and drop all loggers in the registry. - // This is optional (only mandatory if using windows + async log). - spdlog::shutdown(); - } - - // Exceptions will only be thrown upon failed logger or sink construction (not during logging). - catch (const spdlog::spdlog_ex &ex) { - std::printf("Log initialization failed: %s\n", ex.what()); - return 1; - } -} - -#include "spdlog/sinks/stdout_color_sinks.h" -// or #include "spdlog/sinks/stdout_sinks.h" if no colors needed. -void stdout_logger_example() { - // Create color multi threaded logger. - auto console = spdlog::stdout_color_mt("console"); - // or for stderr: - // auto console = spdlog::stderr_color_mt("error-logger"); -} - -#include "spdlog/sinks/basic_file_sink.h" -void basic_example() { - // Create basic file logger (not rotated). - auto my_logger = spdlog::basic_logger_mt("file_logger", "logs/basic-log.txt", true); -} - -#include "spdlog/sinks/rotating_file_sink.h" -void rotating_example() { - // Create a file rotating logger with 5mb size max and 3 rotated files. - auto rotating_logger = - spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3); -} - -#include "spdlog/sinks/daily_file_sink.h" -void daily_example() { - // Create a daily logger - a new file is created every day on 2:30am. - auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30); -} - -#include "spdlog/sinks/callback_sink.h" -void callback_example() { - // Create the logger - auto logger = spdlog::callback_logger_mt("custom_callback_logger", - [](const spdlog::details::log_msg & /*msg*/) { - // do what you need to do with msg - }); -} - -#include "spdlog/cfg/env.h" -void load_levels_example() { - // Set the log level to "info" and mylogger to "trace": - // SPDLOG_LEVEL=info,mylogger=trace && ./example - spdlog::cfg::load_env_levels(); - // or specify the env variable name: - // MYAPP_LEVEL=info,mylogger=trace && ./example - // spdlog::cfg::load_env_levels("MYAPP_LEVEL"); - // or from command line: - // ./example SPDLOG_LEVEL=info,mylogger=trace - // #include "spdlog/cfg/argv.h" // for loading levels from argv - // spdlog::cfg::load_argv_levels(args, argv); -} - -#include "spdlog/async.h" -void async_example() { - // Default thread pool settings can be modified *before* creating the async logger: - // spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread. - auto async_file = - spdlog::basic_logger_mt("async_file_logger", "logs/async_log.txt"); - // alternatively: - // auto async_file = - // spdlog::create_async("async_file_logger", - // "logs/async_log.txt"); - - for (int i = 1; i < 101; ++i) { - async_file->info("Async message #{}", i); - } -} - -// Log binary data as hex. -// Many types of std::container types can be used. -// Iterator ranges are supported too. -// Format flags: -// {:X} - print in uppercase. -// {:s} - don't separate each byte with space. -// {:p} - don't print the position on each line start. -// {:n} - don't split the output to lines. - -#if !defined SPDLOG_USE_STD_FORMAT || defined(_MSC_VER) - #include "spdlog/fmt/bin_to_hex.h" -void binary_example() { - std::vector buf; - for (int i = 0; i < 80; i++) { - buf.push_back(static_cast(i & 0xff)); - } - spdlog::info("Binary example: {}", spdlog::to_hex(buf)); - spdlog::info("Another binary example:{:n}", - spdlog::to_hex(std::begin(buf), std::begin(buf) + 10)); - // more examples: - // logger->info("uppercase: {:X}", spdlog::to_hex(buf)); - // logger->info("uppercase, no delimiters: {:Xs}", spdlog::to_hex(buf)); - // logger->info("uppercase, no delimiters, no position info: {:Xsp}", spdlog::to_hex(buf)); - // logger->info("hexdump style: {:a}", spdlog::to_hex(buf)); - // logger->info("hexdump style, 20 chars per line {:a}", spdlog::to_hex(buf, 20)); -} -#else -void binary_example() { - // not supported with std::format yet -} -#endif - -// Log a vector of numbers -#ifndef SPDLOG_USE_STD_FORMAT - #include "spdlog/fmt/ranges.h" -void vector_example() { - std::vector vec = {1, 2, 3}; - spdlog::info("Vector example: {}", vec); -} - -#else -void vector_example() {} -#endif - -// ! DSPDLOG_USE_STD_FORMAT - -// Compile time log levels. -// define SPDLOG_ACTIVE_LEVEL to required level (e.g. SPDLOG_LEVEL_TRACE) -void trace_example() { - // trace from default logger - SPDLOG_TRACE("Some trace message.. {} ,{}", 1, 3.23); - // debug from default logger - SPDLOG_DEBUG("Some debug message.. {} ,{}", 1, 3.23); - - // trace from logger object - auto logger = spdlog::get("file_logger"); - SPDLOG_LOGGER_TRACE(logger, "another trace message"); -} - -// stopwatch example -#include "spdlog/stopwatch.h" -#include -void stopwatch_example() { - spdlog::stopwatch sw; - std::this_thread::sleep_for(std::chrono::milliseconds(123)); - spdlog::info("Stopwatch: {} seconds", sw); -} - -#include "spdlog/sinks/udp_sink.h" -void udp_example() { - spdlog::sinks::udp_sink_config cfg("127.0.0.1", 11091); - auto my_logger = spdlog::udp_logger_mt("udplog", cfg); - my_logger->set_level(spdlog::level::debug); - my_logger->info("hello world"); -} - -// A logger with multiple sinks (stdout and file) - each with a different format and log level. -void multi_sink_example() { - auto console_sink = std::make_shared(); - console_sink->set_level(spdlog::level::warn); - console_sink->set_pattern("[multi_sink_example] [%^%l%$] %v"); - - auto file_sink = - std::make_shared("logs/multisink.txt", true); - file_sink->set_level(spdlog::level::trace); - - spdlog::logger logger("multi_sink", {console_sink, file_sink}); - logger.set_level(spdlog::level::debug); - logger.warn("this should appear in both console and file"); - logger.info("this message should not appear in the console, only in the file"); -} - -// User defined types logging -struct my_type { - int i = 0; - explicit my_type(int i) - : i(i) {} -}; - -#ifndef SPDLOG_USE_STD_FORMAT // when using fmtlib -template <> -struct fmt::formatter : fmt::formatter { - auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) { - return fmt::format_to(ctx.out(), "[my_type i={}]", my.i); - } -}; - -#else // when using std::format -template <> -struct std::formatter : std::formatter { - auto format(my_type my, format_context &ctx) const -> decltype(ctx.out()) { - return std::format_to(ctx.out(), "[my_type i={}]", my.i); - } -}; -#endif - -void user_defined_example() { spdlog::info("user defined type: {}", my_type(14)); } - -// Custom error handler. Will be triggered on log failure. -void err_handler_example() { - // can be set globally or per logger(logger->set_error_handler(..)) - spdlog::set_error_handler([](const std::string &msg) { - printf("*** Custom log error handler: %s ***\n", msg.c_str()); - }); -} - -// syslog example (linux/osx/freebsd) -#ifndef _WIN32 - #include "spdlog/sinks/syslog_sink.h" -void syslog_example() { - std::string ident = "spdlog-example"; - auto syslog_logger = spdlog::syslog_logger_mt("syslog", ident, LOG_PID); - syslog_logger->warn("This is warning that will end up in syslog."); -} -#endif - -// Android example. -#if defined(__ANDROID__) - #include "spdlog/sinks/android_sink.h" -void android_example() { - std::string tag = "spdlog-android"; - auto android_logger = spdlog::android_logger_mt("android", tag); - android_logger->critical("Use \"adb shell logcat\" to view this message."); -} -#endif - -// Log patterns can contain custom flags. -// this will add custom flag '%*' which will be bound to a instance -#include "spdlog/pattern_formatter.h" -class my_formatter_flag : public spdlog::custom_flag_formatter { -public: - void format(const spdlog::details::log_msg &, - const std::tm &, - spdlog::memory_buf_t &dest) override { - std::string some_txt = "custom-flag"; - dest.append(some_txt.data(), some_txt.data() + some_txt.size()); - } - - std::unique_ptr clone() const override { - return spdlog::details::make_unique(); - } -}; - -void custom_flags_example() { - using spdlog::details::make_unique; // for pre c++14 - auto formatter = make_unique(); - formatter->add_flag('*').set_pattern("[%n] [%*] [%^%l%$] %v"); - // set the new formatter using spdlog::set_formatter(formatter) or - // logger->set_formatter(formatter) spdlog::set_formatter(std::move(formatter)); -} - -void file_events_example() { - // pass the spdlog::file_event_handlers to file sinks for open/close log file notifications - spdlog::file_event_handlers handlers; - handlers.before_open = [](spdlog::filename_t filename) { - spdlog::info("Before opening {}", filename); - }; - handlers.after_open = [](spdlog::filename_t filename, std::FILE *fstream) { - spdlog::info("After opening {}", filename); - fputs("After opening\n", fstream); - }; - handlers.before_close = [](spdlog::filename_t filename, std::FILE *fstream) { - spdlog::info("Before closing {}", filename); - fputs("Before closing\n", fstream); - }; - handlers.after_close = [](spdlog::filename_t filename) { - spdlog::info("After closing {}", filename); - }; - auto file_sink = std::make_shared("logs/events-sample.txt", - true, handlers); - spdlog::logger my_logger("some_logger", file_sink); - my_logger.info("Some log line"); -} - -void replace_default_logger_example() { - // store the old logger so we don't break other examples. - auto old_logger = spdlog::default_logger(); - - auto new_logger = spdlog::basic_logger_mt("new_default_logger", "logs/somelog.txt", true); - spdlog::set_default_logger(std::move(new_logger)); - spdlog::set_level(spdlog::level::info); - spdlog::debug("This message should not be displayed!"); - spdlog::set_level(spdlog::level::trace); - spdlog::debug("This message should be displayed.."); - spdlog::set_default_logger(std::move(old_logger)); -} - -// Mapped Diagnostic Context (MDC) is a map that stores key-value pairs (string values) in thread -// local storage. Each thread maintains its own MDC, which loggers use to append diagnostic -// information to log outputs. Note: it is not supported in asynchronous mode due to its reliance on -// thread-local storage. - -#ifndef SPDLOG_NO_TLS - #include "spdlog/mdc.h" -void mdc_example() { - spdlog::mdc::put("key1", "value1"); - spdlog::mdc::put("key2", "value2"); - // if not using the default format, you can use the %& formatter to print mdc data as well - spdlog::set_pattern("[%H:%M:%S %z] [%^%L%$] [%&] %v"); - spdlog::info("Some log message with context"); -} -#else -void mdc_example() { - // if TLS feature is disabled -} -#endif diff --git a/examples/blueprints-example/external/spdlog/fmt/bin_to_hex.h b/examples/blueprints-example/external/spdlog/fmt/bin_to_hex.h deleted file mode 100644 index 6ed68e4..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bin_to_hex.h +++ /dev/null @@ -1,224 +0,0 @@ -// -// Copyright(c) 2015 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once - -#include -#include - -#if defined(__has_include) - #if __has_include() - #include - #endif -#endif - -#if __cpp_lib_span >= 202002L - #include -#endif - -// -// Support for logging binary data as hex -// format flags, any combination of the following: -// {:X} - print in uppercase. -// {:s} - don't separate each byte with space. -// {:p} - don't print the position on each line start. -// {:n} - don't split the output to lines. -// {:a} - show ASCII if :n is not set - -// -// Examples: -// -// std::vector v(200, 0x0b); -// logger->info("Some buffer {}", spdlog::to_hex(v)); -// char buf[128]; -// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf))); -// logger->info("Some buffer {:X}", spdlog::to_hex(std::begin(buf), std::end(buf), 16)); - -namespace spdlog { -namespace details { - -template -class dump_info { -public: - dump_info(It range_begin, It range_end, size_t size_per_line) - : begin_(range_begin), - end_(range_end), - size_per_line_(size_per_line) {} - - // do not use begin() and end() to avoid collision with fmt/ranges - It get_begin() const { return begin_; } - It get_end() const { return end_; } - size_t size_per_line() const { return size_per_line_; } - -private: - It begin_, end_; - size_t size_per_line_; -}; -} // namespace details - -// create a dump_info that wraps the given container -template -inline details::dump_info to_hex(const Container &container, - size_t size_per_line = 32) { - static_assert(sizeof(typename Container::value_type) == 1, - "sizeof(Container::value_type) != 1"); - using Iter = typename Container::const_iterator; - return details::dump_info(std::begin(container), std::end(container), size_per_line); -} - -#if __cpp_lib_span >= 202002L - -template -inline details::dump_info::iterator> to_hex( - const std::span &container, size_t size_per_line = 32) { - using Container = std::span; - static_assert(sizeof(typename Container::value_type) == 1, - "sizeof(Container::value_type) != 1"); - using Iter = typename Container::iterator; - return details::dump_info(std::begin(container), std::end(container), size_per_line); -} - -#endif - -// create dump_info from ranges -template -inline details::dump_info to_hex(const It range_begin, - const It range_end, - size_t size_per_line = 32) { - return details::dump_info(range_begin, range_end, size_per_line); -} - -} // namespace spdlog - -namespace -#ifdef SPDLOG_USE_STD_FORMAT - std -#else - fmt -#endif -{ - -template -struct formatter, char> { - char delimiter = ' '; - bool put_newlines = true; - bool put_delimiters = true; - bool use_uppercase = false; - bool put_positions = true; // position on start of each line - bool show_ascii = false; - - // parse the format string flags - template - SPDLOG_CONSTEXPR_FUNC auto parse(ParseContext &ctx) -> decltype(ctx.begin()) { - auto it = ctx.begin(); - while (it != ctx.end() && *it != '}') { - switch (*it) { - case 'X': - use_uppercase = true; - break; - case 's': - put_delimiters = false; - break; - case 'p': - put_positions = false; - break; - case 'n': - put_newlines = false; - show_ascii = false; - break; - case 'a': - if (put_newlines) { - show_ascii = true; - } - break; - } - - ++it; - } - return it; - } - - // format the given bytes range as hex - template - auto format(const spdlog::details::dump_info &the_range, - FormatContext &ctx) const -> decltype(ctx.out()) { - SPDLOG_CONSTEXPR const char *hex_upper = "0123456789ABCDEF"; - SPDLOG_CONSTEXPR const char *hex_lower = "0123456789abcdef"; - const char *hex_chars = use_uppercase ? hex_upper : hex_lower; - -#if !defined(SPDLOG_USE_STD_FORMAT) && FMT_VERSION < 60000 - auto inserter = ctx.begin(); -#else - auto inserter = ctx.out(); -#endif - - int size_per_line = static_cast(the_range.size_per_line()); - auto start_of_line = the_range.get_begin(); - for (auto i = the_range.get_begin(); i != the_range.get_end(); i++) { - auto ch = static_cast(*i); - - if (put_newlines && - (i == the_range.get_begin() || i - start_of_line >= size_per_line)) { - if (show_ascii && i != the_range.get_begin()) { - *inserter++ = delimiter; - *inserter++ = delimiter; - for (auto j = start_of_line; j < i; j++) { - auto pc = static_cast(*j); - *inserter++ = std::isprint(pc) ? static_cast(*j) : '.'; - } - } - - put_newline(inserter, static_cast(i - the_range.get_begin())); - - // put first byte without delimiter in front of it - *inserter++ = hex_chars[(ch >> 4) & 0x0f]; - *inserter++ = hex_chars[ch & 0x0f]; - start_of_line = i; - continue; - } - - if (put_delimiters && i != the_range.get_begin()) { - *inserter++ = delimiter; - } - - *inserter++ = hex_chars[(ch >> 4) & 0x0f]; - *inserter++ = hex_chars[ch & 0x0f]; - } - if (show_ascii) // add ascii to last line - { - if (the_range.get_end() - the_range.get_begin() > size_per_line) { - auto blank_num = size_per_line - (the_range.get_end() - start_of_line); - while (blank_num-- > 0) { - *inserter++ = delimiter; - *inserter++ = delimiter; - if (put_delimiters) { - *inserter++ = delimiter; - } - } - } - *inserter++ = delimiter; - *inserter++ = delimiter; - for (auto j = start_of_line; j != the_range.get_end(); j++) { - auto pc = static_cast(*j); - *inserter++ = std::isprint(pc) ? static_cast(*j) : '.'; - } - } - return inserter; - } - - // put newline(and position header) - template - void put_newline(It inserter, std::size_t pos) const { -#ifdef _WIN32 - *inserter++ = '\r'; -#endif - *inserter++ = '\n'; - - if (put_positions) { - spdlog::fmt_lib::format_to(inserter, SPDLOG_FMT_STRING("{:04X}: "), pos); - } - } -}; -} // namespace std diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/args.h b/examples/blueprints-example/external/spdlog/fmt/bundled/args.h deleted file mode 100644 index 5e5f40f..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/args.h +++ /dev/null @@ -1,220 +0,0 @@ -// Formatting library for C++ - dynamic argument lists -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_ARGS_H_ -#define FMT_ARGS_H_ - -#ifndef FMT_MODULE -# include // std::reference_wrapper -# include // std::unique_ptr -# include -#endif - -#include "format.h" // std_string_view - -FMT_BEGIN_NAMESPACE -namespace detail { - -template struct is_reference_wrapper : std::false_type {}; -template -struct is_reference_wrapper> : std::true_type {}; - -template auto unwrap(const T& v) -> const T& { return v; } -template -auto unwrap(const std::reference_wrapper& v) -> const T& { - return static_cast(v); -} - -// node is defined outside dynamic_arg_list to workaround a C2504 bug in MSVC -// 2022 (v17.10.0). -// -// Workaround for clang's -Wweak-vtables. Unlike for regular classes, for -// templates it doesn't complain about inability to deduce single translation -// unit for placing vtable. So node is made a fake template. -template struct node { - virtual ~node() = default; - std::unique_ptr> next; -}; - -class dynamic_arg_list { - template struct typed_node : node<> { - T value; - - template - FMT_CONSTEXPR typed_node(const Arg& arg) : value(arg) {} - - template - FMT_CONSTEXPR typed_node(const basic_string_view& arg) - : value(arg.data(), arg.size()) {} - }; - - std::unique_ptr> head_; - - public: - template auto push(const Arg& arg) -> const T& { - auto new_node = std::unique_ptr>(new typed_node(arg)); - auto& value = new_node->value; - new_node->next = std::move(head_); - head_ = std::move(new_node); - return value; - } -}; -} // namespace detail - -/** - * A dynamic list of formatting arguments with storage. - * - * It can be implicitly converted into `fmt::basic_format_args` for passing - * into type-erased formatting functions such as `fmt::vformat`. - */ -FMT_EXPORT template class dynamic_format_arg_store { - private: - using char_type = typename Context::char_type; - - template struct need_copy { - static constexpr detail::type mapped_type = - detail::mapped_type_constant::value; - - enum { - value = !(detail::is_reference_wrapper::value || - std::is_same>::value || - std::is_same>::value || - (mapped_type != detail::type::cstring_type && - mapped_type != detail::type::string_type && - mapped_type != detail::type::custom_type)) - }; - }; - - template - using stored_t = conditional_t< - std::is_convertible>::value && - !detail::is_reference_wrapper::value, - std::basic_string, T>; - - // Storage of basic_format_arg must be contiguous. - std::vector> data_; - std::vector> named_info_; - - // Storage of arguments not fitting into basic_format_arg must grow - // without relocation because items in data_ refer to it. - detail::dynamic_arg_list dynamic_args_; - - friend class basic_format_args; - - auto data() const -> const basic_format_arg* { - return named_info_.empty() ? data_.data() : data_.data() + 1; - } - - template void emplace_arg(const T& arg) { - data_.emplace_back(arg); - } - - template - void emplace_arg(const detail::named_arg& arg) { - if (named_info_.empty()) - data_.insert(data_.begin(), basic_format_arg(nullptr, 0)); - data_.emplace_back(detail::unwrap(arg.value)); - auto pop_one = [](std::vector>* data) { - data->pop_back(); - }; - std::unique_ptr>, decltype(pop_one)> - guard{&data_, pop_one}; - named_info_.push_back({arg.name, static_cast(data_.size() - 2u)}); - data_[0] = {named_info_.data(), named_info_.size()}; - guard.release(); - } - - public: - constexpr dynamic_format_arg_store() = default; - - operator basic_format_args() const { - return basic_format_args(data(), static_cast(data_.size()), - !named_info_.empty()); - } - - /** - * Adds an argument into the dynamic store for later passing to a formatting - * function. - * - * Note that custom types and string types (but not string views) are copied - * into the store dynamically allocating memory if necessary. - * - * **Example**: - * - * fmt::dynamic_format_arg_store store; - * store.push_back(42); - * store.push_back("abc"); - * store.push_back(1.5f); - * std::string result = fmt::vformat("{} and {} and {}", store); - */ - template void push_back(const T& arg) { - if (detail::const_check(need_copy::value)) - emplace_arg(dynamic_args_.push>(arg)); - else - emplace_arg(detail::unwrap(arg)); - } - - /** - * Adds a reference to the argument into the dynamic store for later passing - * to a formatting function. - * - * **Example**: - * - * fmt::dynamic_format_arg_store store; - * char band[] = "Rolling Stones"; - * store.push_back(std::cref(band)); - * band[9] = 'c'; // Changing str affects the output. - * std::string result = fmt::vformat("{}", store); - * // result == "Rolling Scones" - */ - template void push_back(std::reference_wrapper arg) { - static_assert( - need_copy::value, - "objects of built-in types and string views are always copied"); - emplace_arg(arg.get()); - } - - /** - * Adds named argument into the dynamic store for later passing to a - * formatting function. `std::reference_wrapper` is supported to avoid - * copying of the argument. The name is always copied into the store. - */ - template - void push_back(const detail::named_arg& arg) { - const char_type* arg_name = - dynamic_args_.push>(arg.name).c_str(); - if (detail::const_check(need_copy::value)) { - emplace_arg( - fmt::arg(arg_name, dynamic_args_.push>(arg.value))); - } else { - emplace_arg(fmt::arg(arg_name, arg.value)); - } - } - - /// Erase all elements from the store. - void clear() { - data_.clear(); - named_info_.clear(); - dynamic_args_ = {}; - } - - /// Reserves space to store at least `new_cap` arguments including - /// `new_cap_named` named arguments. - void reserve(size_t new_cap, size_t new_cap_named) { - FMT_ASSERT(new_cap >= new_cap_named, - "set of arguments includes set of named arguments"); - data_.reserve(new_cap); - named_info_.reserve(new_cap_named); - } - - /// Returns the number of elements in the store. - auto size() const noexcept -> size_t { return data_.size(); } -}; - -FMT_END_NAMESPACE - -#endif // FMT_ARGS_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/base.h b/examples/blueprints-example/external/spdlog/fmt/bundled/base.h deleted file mode 100644 index 42e192a..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/base.h +++ /dev/null @@ -1,2994 +0,0 @@ -// Formatting library for C++ - the base API for char/UTF-8 -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_BASE_H_ -#define FMT_BASE_H_ - -#if defined(FMT_IMPORT_STD) && !defined(FMT_MODULE) -# define FMT_MODULE -#endif - -#ifndef FMT_MODULE -# include // CHAR_BIT -# include // FILE -# include // memcmp - -# include // std::enable_if -#endif - -// The fmt library version in the form major * 10000 + minor * 100 + patch. -#define FMT_VERSION 120000 - -// Detect compiler versions. -#if defined(__clang__) && !defined(__ibmxl__) -# define FMT_CLANG_VERSION (__clang_major__ * 100 + __clang_minor__) -#else -# define FMT_CLANG_VERSION 0 -#endif -#if defined(__GNUC__) && !defined(__clang__) && !defined(__INTEL_COMPILER) -# define FMT_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) -#else -# define FMT_GCC_VERSION 0 -#endif -#if defined(__ICL) -# define FMT_ICC_VERSION __ICL -#elif defined(__INTEL_COMPILER) -# define FMT_ICC_VERSION __INTEL_COMPILER -#else -# define FMT_ICC_VERSION 0 -#endif -#if defined(_MSC_VER) -# define FMT_MSC_VERSION _MSC_VER -#else -# define FMT_MSC_VERSION 0 -#endif - -// Detect standard library versions. -#ifdef _GLIBCXX_RELEASE -# define FMT_GLIBCXX_RELEASE _GLIBCXX_RELEASE -#else -# define FMT_GLIBCXX_RELEASE 0 -#endif -#ifdef _LIBCPP_VERSION -# define FMT_LIBCPP_VERSION _LIBCPP_VERSION -#else -# define FMT_LIBCPP_VERSION 0 -#endif - -#ifdef _MSVC_LANG -# define FMT_CPLUSPLUS _MSVC_LANG -#else -# define FMT_CPLUSPLUS __cplusplus -#endif - -// Detect __has_*. -#ifdef __has_feature -# define FMT_HAS_FEATURE(x) __has_feature(x) -#else -# define FMT_HAS_FEATURE(x) 0 -#endif -#ifdef __has_include -# define FMT_HAS_INCLUDE(x) __has_include(x) -#else -# define FMT_HAS_INCLUDE(x) 0 -#endif -#ifdef __has_builtin -# define FMT_HAS_BUILTIN(x) __has_builtin(x) -#else -# define FMT_HAS_BUILTIN(x) 0 -#endif -#ifdef __has_cpp_attribute -# define FMT_HAS_CPP_ATTRIBUTE(x) __has_cpp_attribute(x) -#else -# define FMT_HAS_CPP_ATTRIBUTE(x) 0 -#endif - -#define FMT_HAS_CPP14_ATTRIBUTE(attribute) \ - (FMT_CPLUSPLUS >= 201402L && FMT_HAS_CPP_ATTRIBUTE(attribute)) - -#define FMT_HAS_CPP17_ATTRIBUTE(attribute) \ - (FMT_CPLUSPLUS >= 201703L && FMT_HAS_CPP_ATTRIBUTE(attribute)) - -// Detect C++14 relaxed constexpr. -#ifdef FMT_USE_CONSTEXPR -// Use the provided definition. -#elif FMT_GCC_VERSION >= 702 && FMT_CPLUSPLUS >= 201402L -// GCC only allows constexpr member functions in non-literal types since 7.2: -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66297. -# define FMT_USE_CONSTEXPR 1 -#elif FMT_ICC_VERSION -# define FMT_USE_CONSTEXPR 0 // https://github.com/fmtlib/fmt/issues/1628 -#elif FMT_HAS_FEATURE(cxx_relaxed_constexpr) || FMT_MSC_VERSION >= 1912 -# define FMT_USE_CONSTEXPR 1 -#else -# define FMT_USE_CONSTEXPR 0 -#endif -#if FMT_USE_CONSTEXPR -# define FMT_CONSTEXPR constexpr -#else -# define FMT_CONSTEXPR -#endif - -// Detect consteval, C++20 constexpr extensions and std::is_constant_evaluated. -#if !defined(__cpp_lib_is_constant_evaluated) -# define FMT_USE_CONSTEVAL 0 -#elif FMT_CPLUSPLUS < 201709L -# define FMT_USE_CONSTEVAL 0 -#elif FMT_GLIBCXX_RELEASE && FMT_GLIBCXX_RELEASE < 10 -# define FMT_USE_CONSTEVAL 0 -#elif FMT_LIBCPP_VERSION && FMT_LIBCPP_VERSION < 10000 -# define FMT_USE_CONSTEVAL 0 -#elif defined(__apple_build_version__) && __apple_build_version__ < 14000029L -# define FMT_USE_CONSTEVAL 0 // consteval is broken in Apple clang < 14. -#elif FMT_MSC_VERSION && FMT_MSC_VERSION < 1929 -# define FMT_USE_CONSTEVAL 0 // consteval is broken in MSVC VS2019 < 16.10. -#elif defined(__cpp_consteval) -# define FMT_USE_CONSTEVAL 1 -#elif FMT_GCC_VERSION >= 1002 || FMT_CLANG_VERSION >= 1101 -# define FMT_USE_CONSTEVAL 1 -#else -# define FMT_USE_CONSTEVAL 0 -#endif -#if FMT_USE_CONSTEVAL -# define FMT_CONSTEVAL consteval -# define FMT_CONSTEXPR20 constexpr -#else -# define FMT_CONSTEVAL -# define FMT_CONSTEXPR20 -#endif - -// Check if exceptions are disabled. -#ifdef FMT_USE_EXCEPTIONS -// Use the provided definition. -#elif defined(__GNUC__) && !defined(__EXCEPTIONS) -# define FMT_USE_EXCEPTIONS 0 -#elif defined(__clang__) && !defined(__cpp_exceptions) -# define FMT_USE_EXCEPTIONS 0 -#elif FMT_MSC_VERSION && !_HAS_EXCEPTIONS -# define FMT_USE_EXCEPTIONS 0 -#else -# define FMT_USE_EXCEPTIONS 1 -#endif -#if FMT_USE_EXCEPTIONS -# define FMT_TRY try -# define FMT_CATCH(x) catch (x) -#else -# define FMT_TRY if (true) -# define FMT_CATCH(x) if (false) -#endif - -#ifdef FMT_NO_UNIQUE_ADDRESS -// Use the provided definition. -#elif FMT_CPLUSPLUS < 202002L -// Not supported. -#elif FMT_HAS_CPP_ATTRIBUTE(no_unique_address) -# define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]] -// VS2019 v16.10 and later except clang-cl (https://reviews.llvm.org/D110485). -#elif FMT_MSC_VERSION >= 1929 && !FMT_CLANG_VERSION -# define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -#endif -#ifndef FMT_NO_UNIQUE_ADDRESS -# define FMT_NO_UNIQUE_ADDRESS -#endif - -#if FMT_HAS_CPP17_ATTRIBUTE(fallthrough) -# define FMT_FALLTHROUGH [[fallthrough]] -#elif defined(__clang__) -# define FMT_FALLTHROUGH [[clang::fallthrough]] -#elif FMT_GCC_VERSION >= 700 && \ - (!defined(__EDG_VERSION__) || __EDG_VERSION__ >= 520) -# define FMT_FALLTHROUGH [[gnu::fallthrough]] -#else -# define FMT_FALLTHROUGH -#endif - -// Disable [[noreturn]] on MSVC/NVCC because of bogus unreachable code warnings. -#if FMT_HAS_CPP_ATTRIBUTE(noreturn) && !FMT_MSC_VERSION && !defined(__NVCC__) -# define FMT_NORETURN [[noreturn]] -#else -# define FMT_NORETURN -#endif - -#ifdef FMT_NODISCARD -// Use the provided definition. -#elif FMT_HAS_CPP17_ATTRIBUTE(nodiscard) -# define FMT_NODISCARD [[nodiscard]] -#else -# define FMT_NODISCARD -#endif - -#if FMT_GCC_VERSION || FMT_CLANG_VERSION -# define FMT_VISIBILITY(value) __attribute__((visibility(value))) -#else -# define FMT_VISIBILITY(value) -#endif - -// Detect pragmas. -#define FMT_PRAGMA_IMPL(x) _Pragma(#x) -#if FMT_GCC_VERSION >= 504 && !defined(__NVCOMPILER) -// Workaround a _Pragma bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59884 -// and an nvhpc warning: https://github.com/fmtlib/fmt/pull/2582. -# define FMT_PRAGMA_GCC(x) FMT_PRAGMA_IMPL(GCC x) -#else -# define FMT_PRAGMA_GCC(x) -#endif -#if FMT_CLANG_VERSION -# define FMT_PRAGMA_CLANG(x) FMT_PRAGMA_IMPL(clang x) -#else -# define FMT_PRAGMA_CLANG(x) -#endif -#if FMT_MSC_VERSION -# define FMT_MSC_WARNING(...) __pragma(warning(__VA_ARGS__)) -#else -# define FMT_MSC_WARNING(...) -#endif - -// Enable minimal optimizations for more compact code in debug mode. -FMT_PRAGMA_GCC(push_options) -#if !defined(__OPTIMIZE__) && !defined(__CUDACC__) && !defined(FMT_MODULE) -FMT_PRAGMA_GCC(optimize("Og")) -# define FMT_GCC_OPTIMIZED -#endif -FMT_PRAGMA_CLANG(diagnostic push) - -#ifdef FMT_ALWAYS_INLINE -// Use the provided definition. -#elif FMT_GCC_VERSION || FMT_CLANG_VERSION -# define FMT_ALWAYS_INLINE inline __attribute__((always_inline)) -#else -# define FMT_ALWAYS_INLINE inline -#endif -// A version of FMT_ALWAYS_INLINE to prevent code bloat in debug mode. -#if defined(NDEBUG) || defined(FMT_GCC_OPTIMIZED) -# define FMT_INLINE FMT_ALWAYS_INLINE -#else -# define FMT_INLINE inline -#endif - -#ifndef FMT_BEGIN_NAMESPACE -# define FMT_BEGIN_NAMESPACE \ - namespace fmt { \ - inline namespace v12 { -# define FMT_END_NAMESPACE \ - } \ - } -#endif - -#ifndef FMT_EXPORT -# define FMT_EXPORT -# define FMT_BEGIN_EXPORT -# define FMT_END_EXPORT -#endif - -#ifdef _WIN32 -# define FMT_WIN32 1 -#else -# define FMT_WIN32 0 -#endif - -#if !defined(FMT_HEADER_ONLY) && FMT_WIN32 -# if defined(FMT_LIB_EXPORT) -# define FMT_API __declspec(dllexport) -# elif defined(FMT_SHARED) -# define FMT_API __declspec(dllimport) -# endif -#elif defined(FMT_LIB_EXPORT) || defined(FMT_SHARED) -# define FMT_API FMT_VISIBILITY("default") -#endif -#ifndef FMT_API -# define FMT_API -#endif - -#ifndef FMT_OPTIMIZE_SIZE -# define FMT_OPTIMIZE_SIZE 0 -#endif - -// FMT_BUILTIN_TYPE=0 may result in smaller library size at the cost of higher -// per-call binary size by passing built-in types through the extension API. -#ifndef FMT_BUILTIN_TYPES -# define FMT_BUILTIN_TYPES 1 -#endif - -#define FMT_APPLY_VARIADIC(expr) \ - using unused = int[]; \ - (void)unused { 0, (expr, 0)... } - -FMT_BEGIN_NAMESPACE - -// Implementations of enable_if_t and other metafunctions for older systems. -template -using enable_if_t = typename std::enable_if::type; -template -using conditional_t = typename std::conditional::type; -template using bool_constant = std::integral_constant; -template -using remove_reference_t = typename std::remove_reference::type; -template -using remove_const_t = typename std::remove_const::type; -template -using remove_cvref_t = typename std::remove_cv>::type; -template -using make_unsigned_t = typename std::make_unsigned::type; -template -using underlying_t = typename std::underlying_type::type; -template using decay_t = typename std::decay::type; -using nullptr_t = decltype(nullptr); - -#if (FMT_GCC_VERSION && FMT_GCC_VERSION < 500) || FMT_MSC_VERSION -// A workaround for gcc 4.9 & MSVC v141 to make void_t work in a SFINAE context. -template struct void_t_impl { - using type = void; -}; -template using void_t = typename void_t_impl::type; -#else -template using void_t = void; -#endif - -struct monostate { - constexpr monostate() {} -}; - -// An enable_if helper to be used in template parameters which results in much -// shorter symbols: https://godbolt.org/z/sWw4vP. Extra parentheses are needed -// to workaround a bug in MSVC 2019 (see #1140 and #1186). -#ifdef FMT_DOC -# define FMT_ENABLE_IF(...) -#else -# define FMT_ENABLE_IF(...) fmt::enable_if_t<(__VA_ARGS__), int> = 0 -#endif - -template constexpr auto min_of(T a, T b) -> T { - return a < b ? a : b; -} -template constexpr auto max_of(T a, T b) -> T { - return a > b ? a : b; -} - -FMT_NORETURN FMT_API void assert_fail(const char* file, int line, - const char* message); - -namespace detail { -// Suppresses "unused variable" warnings with the method described in -// https://herbsutter.com/2009/10/18/mailbag-shutting-up-compiler-warnings/. -// (void)var does not work on many Intel compilers. -template FMT_CONSTEXPR void ignore_unused(const T&...) {} - -constexpr auto is_constant_evaluated(bool default_value = false) noexcept - -> bool { -// Workaround for incompatibility between clang 14 and libstdc++ consteval-based -// std::is_constant_evaluated: https://github.com/fmtlib/fmt/issues/3247. -#if FMT_CPLUSPLUS >= 202002L && FMT_GLIBCXX_RELEASE >= 12 && \ - (FMT_CLANG_VERSION >= 1400 && FMT_CLANG_VERSION < 1500) - ignore_unused(default_value); - return __builtin_is_constant_evaluated(); -#elif defined(__cpp_lib_is_constant_evaluated) - ignore_unused(default_value); - return std::is_constant_evaluated(); -#else - return default_value; -#endif -} - -// Suppresses "conditional expression is constant" warnings. -template FMT_ALWAYS_INLINE constexpr auto const_check(T val) -> T { - return val; -} - -FMT_NORETURN FMT_API void assert_fail(const char* file, int line, - const char* message); - -#if defined(FMT_ASSERT) -// Use the provided definition. -#elif defined(NDEBUG) -// FMT_ASSERT is not empty to avoid -Wempty-body. -# define FMT_ASSERT(condition, message) \ - fmt::detail::ignore_unused((condition), (message)) -#else -# define FMT_ASSERT(condition, message) \ - ((condition) /* void() fails with -Winvalid-constexpr on clang 4.0.1 */ \ - ? (void)0 \ - : ::fmt::assert_fail(__FILE__, __LINE__, (message))) -#endif - -#ifdef FMT_USE_INT128 -// Use the provided definition. -#elif defined(__SIZEOF_INT128__) && !defined(__NVCC__) && \ - !(FMT_CLANG_VERSION && FMT_MSC_VERSION) -# define FMT_USE_INT128 1 -using int128_opt = __int128_t; // An optional native 128-bit integer. -using uint128_opt = __uint128_t; -inline auto map(int128_opt x) -> int128_opt { return x; } -inline auto map(uint128_opt x) -> uint128_opt { return x; } -#else -# define FMT_USE_INT128 0 -#endif -#if !FMT_USE_INT128 -enum class int128_opt {}; -enum class uint128_opt {}; -// Reduce template instantiations. -inline auto map(int128_opt) -> monostate { return {}; } -inline auto map(uint128_opt) -> monostate { return {}; } -#endif - -#ifndef FMT_USE_BITINT -# define FMT_USE_BITINT (FMT_CLANG_VERSION >= 1500) -#endif - -#if FMT_USE_BITINT -FMT_PRAGMA_CLANG(diagnostic ignored "-Wbit-int-extension") -template using bitint = _BitInt(N); -template using ubitint = unsigned _BitInt(N); -#else -template struct bitint {}; -template struct ubitint {}; -#endif // FMT_USE_BITINT - -// Casts a nonnegative integer to unsigned. -template -FMT_CONSTEXPR auto to_unsigned(Int value) -> make_unsigned_t { - FMT_ASSERT(std::is_unsigned::value || value >= 0, "negative value"); - return static_cast>(value); -} - -template -using unsigned_char = conditional_t; - -// A heuristic to detect std::string and std::[experimental::]string_view. -// It is mainly used to avoid dependency on <[experimental/]string_view>. -template -struct is_std_string_like : std::false_type {}; -template -struct is_std_string_like().find_first_of( - typename T::value_type(), 0))>> - : std::is_convertible().data()), - const typename T::value_type*> {}; - -// Check if the literal encoding is UTF-8. -enum { is_utf8_enabled = "\u00A7"[1] == '\xA7' }; -enum { use_utf8 = !FMT_WIN32 || is_utf8_enabled }; - -#ifndef FMT_UNICODE -# define FMT_UNICODE 1 -#endif - -static_assert(!FMT_UNICODE || use_utf8, - "Unicode support requires compiling with /utf-8"); - -template constexpr auto narrow(T*) -> char* { return nullptr; } -constexpr FMT_ALWAYS_INLINE auto narrow(const char* s) -> const char* { - return s; -} - -template -FMT_CONSTEXPR auto compare(const Char* s1, const Char* s2, size_t n) -> int { - if (!is_constant_evaluated() && sizeof(Char) == 1) return memcmp(s1, s2, n); - for (; n != 0; ++s1, ++s2, --n) { - if (*s1 < *s2) return -1; - if (*s1 > *s2) return 1; - } - return 0; -} - -namespace adl { -using namespace std; - -template -auto invoke_back_inserter() - -> decltype(back_inserter(std::declval())); -} // namespace adl - -template -struct is_back_insert_iterator : std::false_type {}; - -template -struct is_back_insert_iterator< - It, bool_constant()), - It>::value>> : std::true_type {}; - -// Extracts a reference to the container from *insert_iterator. -template -inline FMT_CONSTEXPR20 auto get_container(OutputIt it) -> - typename OutputIt::container_type& { - struct accessor : OutputIt { - FMT_CONSTEXPR20 accessor(OutputIt base) : OutputIt(base) {} - using OutputIt::container; - }; - return *accessor(it).container; -} -} // namespace detail - -// Parsing-related public API and forward declarations. -FMT_BEGIN_EXPORT - -/** - * An implementation of `std::basic_string_view` for pre-C++17. It provides a - * subset of the API. `fmt::basic_string_view` is used for format strings even - * if `std::basic_string_view` is available to prevent issues when a library is - * compiled with a different `-std` option than the client code (which is not - * recommended). - */ -template class basic_string_view { - private: - const Char* data_; - size_t size_; - - public: - using value_type = Char; - using iterator = const Char*; - - constexpr basic_string_view() noexcept : data_(nullptr), size_(0) {} - - /// Constructs a string view object from a C string and a size. - constexpr basic_string_view(const Char* s, size_t count) noexcept - : data_(s), size_(count) {} - - constexpr basic_string_view(nullptr_t) = delete; - - /// Constructs a string view object from a C string. -#if FMT_GCC_VERSION - FMT_ALWAYS_INLINE -#endif - FMT_CONSTEXPR20 basic_string_view(const Char* s) : data_(s) { -#if FMT_HAS_BUILTIN(__builtin_strlen) || FMT_GCC_VERSION || FMT_CLANG_VERSION - if (std::is_same::value && !detail::is_constant_evaluated()) { - size_ = __builtin_strlen(detail::narrow(s)); // strlen is not constexpr. - return; - } -#endif - size_t len = 0; - while (*s++) ++len; - size_ = len; - } - - /// Constructs a string view from a `std::basic_string` or a - /// `std::basic_string_view` object. - template ::value&& std::is_same< - typename S::value_type, Char>::value)> - FMT_CONSTEXPR basic_string_view(const S& s) noexcept - : data_(s.data()), size_(s.size()) {} - - /// Returns a pointer to the string data. - constexpr auto data() const noexcept -> const Char* { return data_; } - - /// Returns the string size. - constexpr auto size() const noexcept -> size_t { return size_; } - - constexpr auto begin() const noexcept -> iterator { return data_; } - constexpr auto end() const noexcept -> iterator { return data_ + size_; } - - constexpr auto operator[](size_t pos) const noexcept -> const Char& { - return data_[pos]; - } - - FMT_CONSTEXPR void remove_prefix(size_t n) noexcept { - data_ += n; - size_ -= n; - } - - FMT_CONSTEXPR auto starts_with(basic_string_view sv) const noexcept - -> bool { - return size_ >= sv.size_ && detail::compare(data_, sv.data_, sv.size_) == 0; - } - FMT_CONSTEXPR auto starts_with(Char c) const noexcept -> bool { - return size_ >= 1 && *data_ == c; - } - FMT_CONSTEXPR auto starts_with(const Char* s) const -> bool { - return starts_with(basic_string_view(s)); - } - - FMT_CONSTEXPR auto compare(basic_string_view other) const -> int { - int result = - detail::compare(data_, other.data_, min_of(size_, other.size_)); - if (result != 0) return result; - return size_ == other.size_ ? 0 : (size_ < other.size_ ? -1 : 1); - } - - FMT_CONSTEXPR friend auto operator==(basic_string_view lhs, - basic_string_view rhs) -> bool { - return lhs.compare(rhs) == 0; - } - friend auto operator!=(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) != 0; - } - friend auto operator<(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) < 0; - } - friend auto operator<=(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) <= 0; - } - friend auto operator>(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) > 0; - } - friend auto operator>=(basic_string_view lhs, basic_string_view rhs) -> bool { - return lhs.compare(rhs) >= 0; - } -}; - -using string_view = basic_string_view; - -template class basic_appender; -using appender = basic_appender; - -// Checks whether T is a container with contiguous storage. -template struct is_contiguous : std::false_type {}; - -class context; -template class generic_context; -template class parse_context; - -// Longer aliases for C++20 compatibility. -template using basic_format_parse_context = parse_context; -using format_parse_context = parse_context; -template -using basic_format_context = - conditional_t::value, context, - generic_context>; -using format_context = context; - -template -using buffered_context = - conditional_t::value, context, - generic_context, Char>>; - -template class basic_format_arg; -template class basic_format_args; - -// A separate type would result in shorter symbols but break ABI compatibility -// between clang and gcc on ARM (#1919). -using format_args = basic_format_args; - -// A formatter for objects of type T. -template -struct formatter { - // A deleted default constructor indicates a disabled formatter. - formatter() = delete; -}; - -/// Reports a format error at compile time or, via a `format_error` exception, -/// at runtime. -// This function is intentionally not constexpr to give a compile-time error. -FMT_NORETURN FMT_API void report_error(const char* message); - -enum class presentation_type : unsigned char { - // Common specifiers: - none = 0, - debug = 1, // '?' - string = 2, // 's' (string, bool) - - // Integral, bool and character specifiers: - dec = 3, // 'd' - hex, // 'x' or 'X' - oct, // 'o' - bin, // 'b' or 'B' - chr, // 'c' - - // String and pointer specifiers: - pointer = 3, // 'p' - - // Floating-point specifiers: - exp = 1, // 'e' or 'E' (1 since there is no FP debug presentation) - fixed, // 'f' or 'F' - general, // 'g' or 'G' - hexfloat // 'a' or 'A' -}; - -enum class align { none, left, right, center, numeric }; -enum class sign { none, minus, plus, space }; -enum class arg_id_kind { none, index, name }; - -// Basic format specifiers for built-in and string types. -class basic_specs { - private: - // Data is arranged as follows: - // - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // |type |align| w | p | s |u|#|L| f | unused | - // +-----+-----+---+---+---+-+-+-+-----+---------------------------+ - // - // w - dynamic width info - // p - dynamic precision info - // s - sign - // u - uppercase (e.g. 'X' for 'x') - // # - alternate form ('#') - // L - localized - // f - fill size - // - // Bitfields are not used because of compiler bugs such as gcc bug 61414. - enum : unsigned { - type_mask = 0x00007, - align_mask = 0x00038, - width_mask = 0x000C0, - precision_mask = 0x00300, - sign_mask = 0x00C00, - uppercase_mask = 0x01000, - alternate_mask = 0x02000, - localized_mask = 0x04000, - fill_size_mask = 0x38000, - - align_shift = 3, - width_shift = 6, - precision_shift = 8, - sign_shift = 10, - fill_size_shift = 15, - - max_fill_size = 4 - }; - - unsigned data_ = 1 << fill_size_shift; - static_assert(sizeof(basic_specs::data_) * CHAR_BIT >= 18, ""); - - // Character (code unit) type is erased to prevent template bloat. - char fill_data_[max_fill_size] = {' '}; - - FMT_CONSTEXPR void set_fill_size(size_t size) { - data_ = (data_ & ~fill_size_mask) | - (static_cast(size) << fill_size_shift); - } - - public: - constexpr auto type() const -> presentation_type { - return static_cast(data_ & type_mask); - } - FMT_CONSTEXPR void set_type(presentation_type t) { - data_ = (data_ & ~type_mask) | static_cast(t); - } - - constexpr auto align() const -> align { - return static_cast((data_ & align_mask) >> align_shift); - } - FMT_CONSTEXPR void set_align(fmt::align a) { - data_ = (data_ & ~align_mask) | (static_cast(a) << align_shift); - } - - constexpr auto dynamic_width() const -> arg_id_kind { - return static_cast((data_ & width_mask) >> width_shift); - } - FMT_CONSTEXPR void set_dynamic_width(arg_id_kind w) { - data_ = (data_ & ~width_mask) | (static_cast(w) << width_shift); - } - - FMT_CONSTEXPR auto dynamic_precision() const -> arg_id_kind { - return static_cast((data_ & precision_mask) >> - precision_shift); - } - FMT_CONSTEXPR void set_dynamic_precision(arg_id_kind p) { - data_ = (data_ & ~precision_mask) | - (static_cast(p) << precision_shift); - } - - constexpr auto dynamic() const -> bool { - return (data_ & (width_mask | precision_mask)) != 0; - } - - constexpr auto sign() const -> sign { - return static_cast((data_ & sign_mask) >> sign_shift); - } - FMT_CONSTEXPR void set_sign(fmt::sign s) { - data_ = (data_ & ~sign_mask) | (static_cast(s) << sign_shift); - } - - constexpr auto upper() const -> bool { return (data_ & uppercase_mask) != 0; } - FMT_CONSTEXPR void set_upper() { data_ |= uppercase_mask; } - - constexpr auto alt() const -> bool { return (data_ & alternate_mask) != 0; } - FMT_CONSTEXPR void set_alt() { data_ |= alternate_mask; } - FMT_CONSTEXPR void clear_alt() { data_ &= ~alternate_mask; } - - constexpr auto localized() const -> bool { - return (data_ & localized_mask) != 0; - } - FMT_CONSTEXPR void set_localized() { data_ |= localized_mask; } - - constexpr auto fill_size() const -> size_t { - return (data_ & fill_size_mask) >> fill_size_shift; - } - - template ::value)> - constexpr auto fill() const -> const Char* { - return fill_data_; - } - template ::value)> - constexpr auto fill() const -> const Char* { - return nullptr; - } - - template constexpr auto fill_unit() const -> Char { - using uchar = unsigned char; - return static_cast(static_cast(fill_data_[0]) | - (static_cast(fill_data_[1]) << 8) | - (static_cast(fill_data_[2]) << 16)); - } - - FMT_CONSTEXPR void set_fill(char c) { - fill_data_[0] = c; - set_fill_size(1); - } - - template - FMT_CONSTEXPR void set_fill(basic_string_view s) { - auto size = s.size(); - set_fill_size(size); - if (size == 1) { - unsigned uchar = static_cast>(s[0]); - fill_data_[0] = static_cast(uchar); - fill_data_[1] = static_cast(uchar >> 8); - fill_data_[2] = static_cast(uchar >> 16); - return; - } - FMT_ASSERT(size <= max_fill_size, "invalid fill"); - for (size_t i = 0; i < size; ++i) - fill_data_[i & 3] = static_cast(s[i]); - } - - FMT_CONSTEXPR void copy_fill_from(const basic_specs& specs) { - set_fill_size(specs.fill_size()); - for (size_t i = 0; i < max_fill_size; ++i) - fill_data_[i] = specs.fill_data_[i]; - } -}; - -// Format specifiers for built-in and string types. -struct format_specs : basic_specs { - int width; - int precision; - - constexpr format_specs() : width(0), precision(-1) {} -}; - -/** - * Parsing context consisting of a format string range being parsed and an - * argument counter for automatic indexing. - */ -template class parse_context { - private: - basic_string_view fmt_; - int next_arg_id_; - - enum { use_constexpr_cast = !FMT_GCC_VERSION || FMT_GCC_VERSION >= 1200 }; - - FMT_CONSTEXPR void do_check_arg_id(int arg_id); - - public: - using char_type = Char; - using iterator = const Char*; - - constexpr explicit parse_context(basic_string_view fmt, - int next_arg_id = 0) - : fmt_(fmt), next_arg_id_(next_arg_id) {} - - /// Returns an iterator to the beginning of the format string range being - /// parsed. - constexpr auto begin() const noexcept -> iterator { return fmt_.begin(); } - - /// Returns an iterator past the end of the format string range being parsed. - constexpr auto end() const noexcept -> iterator { return fmt_.end(); } - - /// Advances the begin iterator to `it`. - FMT_CONSTEXPR void advance_to(iterator it) { - fmt_.remove_prefix(detail::to_unsigned(it - begin())); - } - - /// Reports an error if using the manual argument indexing; otherwise returns - /// the next argument index and switches to the automatic indexing. - FMT_CONSTEXPR auto next_arg_id() -> int { - if (next_arg_id_ < 0) { - report_error("cannot switch from manual to automatic argument indexing"); - return 0; - } - int id = next_arg_id_++; - do_check_arg_id(id); - return id; - } - - /// Reports an error if using the automatic argument indexing; otherwise - /// switches to the manual indexing. - FMT_CONSTEXPR void check_arg_id(int id) { - if (next_arg_id_ > 0) { - report_error("cannot switch from automatic to manual argument indexing"); - return; - } - next_arg_id_ = -1; - do_check_arg_id(id); - } - FMT_CONSTEXPR void check_arg_id(basic_string_view) { - next_arg_id_ = -1; - } - FMT_CONSTEXPR void check_dynamic_spec(int arg_id); -}; - -#ifndef FMT_USE_LOCALE -# define FMT_USE_LOCALE (FMT_OPTIMIZE_SIZE <= 1) -#endif - -// A type-erased reference to std::locale to avoid the heavy include. -class locale_ref { -#if FMT_USE_LOCALE - private: - const void* locale_; // A type-erased pointer to std::locale. - - public: - constexpr locale_ref() : locale_(nullptr) {} - - template - locale_ref(const Locale& loc); - - inline explicit operator bool() const noexcept { return locale_ != nullptr; } -#endif // FMT_USE_LOCALE - - public: - template auto get() const -> Locale; -}; - -FMT_END_EXPORT - -namespace detail { - -// Specifies if `T` is a code unit type. -template struct is_code_unit : std::false_type {}; -template <> struct is_code_unit : std::true_type {}; -template <> struct is_code_unit : std::true_type {}; -template <> struct is_code_unit : std::true_type {}; -template <> struct is_code_unit : std::true_type {}; -#ifdef __cpp_char8_t -template <> struct is_code_unit : bool_constant {}; -#endif - -// Constructs fmt::basic_string_view from types implicitly convertible -// to it, deducing Char. Explicitly convertible types such as the ones returned -// from FMT_STRING are intentionally excluded. -template ::value)> -constexpr auto to_string_view(const Char* s) -> basic_string_view { - return s; -} -template ::value)> -constexpr auto to_string_view(const T& s) - -> basic_string_view { - return s; -} -template -constexpr auto to_string_view(basic_string_view s) - -> basic_string_view { - return s; -} - -template -struct has_to_string_view : std::false_type {}; -// detail:: is intentional since to_string_view is not an extension point. -template -struct has_to_string_view< - T, void_t()))>> - : std::true_type {}; - -/// String's character (code unit) type. detail:: is intentional to prevent ADL. -template ()))> -using char_t = typename V::value_type; - -enum class type { - none_type, - // Integer types should go first, - int_type, - uint_type, - long_long_type, - ulong_long_type, - int128_type, - uint128_type, - bool_type, - char_type, - last_integer_type = char_type, - // followed by floating-point types. - float_type, - double_type, - long_double_type, - last_numeric_type = long_double_type, - cstring_type, - string_type, - pointer_type, - custom_type -}; - -// Maps core type T to the corresponding type enum constant. -template -struct type_constant : std::integral_constant {}; - -#define FMT_TYPE_CONSTANT(Type, constant) \ - template \ - struct type_constant \ - : std::integral_constant {} - -FMT_TYPE_CONSTANT(int, int_type); -FMT_TYPE_CONSTANT(unsigned, uint_type); -FMT_TYPE_CONSTANT(long long, long_long_type); -FMT_TYPE_CONSTANT(unsigned long long, ulong_long_type); -FMT_TYPE_CONSTANT(int128_opt, int128_type); -FMT_TYPE_CONSTANT(uint128_opt, uint128_type); -FMT_TYPE_CONSTANT(bool, bool_type); -FMT_TYPE_CONSTANT(Char, char_type); -FMT_TYPE_CONSTANT(float, float_type); -FMT_TYPE_CONSTANT(double, double_type); -FMT_TYPE_CONSTANT(long double, long_double_type); -FMT_TYPE_CONSTANT(const Char*, cstring_type); -FMT_TYPE_CONSTANT(basic_string_view, string_type); -FMT_TYPE_CONSTANT(const void*, pointer_type); - -constexpr auto is_integral_type(type t) -> bool { - return t > type::none_type && t <= type::last_integer_type; -} -constexpr auto is_arithmetic_type(type t) -> bool { - return t > type::none_type && t <= type::last_numeric_type; -} - -constexpr auto set(type rhs) -> int { return 1 << static_cast(rhs); } -constexpr auto in(type t, int set) -> bool { - return ((set >> static_cast(t)) & 1) != 0; -} - -// Bitsets of types. -enum { - sint_set = - set(type::int_type) | set(type::long_long_type) | set(type::int128_type), - uint_set = set(type::uint_type) | set(type::ulong_long_type) | - set(type::uint128_type), - bool_set = set(type::bool_type), - char_set = set(type::char_type), - float_set = set(type::float_type) | set(type::double_type) | - set(type::long_double_type), - string_set = set(type::string_type), - cstring_set = set(type::cstring_type), - pointer_set = set(type::pointer_type) -}; - -struct view {}; - -template -struct is_view : std::false_type {}; -template -struct is_view> : std::is_base_of {}; - -template struct named_arg; -template struct is_named_arg : std::false_type {}; -template struct is_static_named_arg : std::false_type {}; - -template -struct is_named_arg> : std::true_type {}; - -template struct named_arg : view { - const Char* name; - const T& value; - - named_arg(const Char* n, const T& v) : name(n), value(v) {} - static_assert(!is_named_arg::value, "nested named arguments"); -}; - -template constexpr auto count() -> int { return B ? 1 : 0; } -template constexpr auto count() -> int { - return (B1 ? 1 : 0) + count(); -} - -template constexpr auto count_named_args() -> int { - return count::value...>(); -} -template constexpr auto count_static_named_args() -> int { - return count::value...>(); -} - -template struct named_arg_info { - const Char* name; - int id; -}; - -// named_args is non-const to suppress a bogus -Wmaybe-uninitialized in gcc 13. -template -FMT_CONSTEXPR void check_for_duplicate(named_arg_info* named_args, - int named_arg_index, - basic_string_view arg_name) { - for (int i = 0; i < named_arg_index; ++i) { - if (named_args[i].name == arg_name) report_error("duplicate named arg"); - } -} - -template ::value)> -void init_named_arg(named_arg_info*, int& arg_index, int&, const T&) { - ++arg_index; -} -template ::value)> -void init_named_arg(named_arg_info* named_args, int& arg_index, - int& named_arg_index, const T& arg) { - check_for_duplicate(named_args, named_arg_index, arg.name); - named_args[named_arg_index++] = {arg.name, arg_index++}; -} - -template ::value)> -FMT_CONSTEXPR void init_static_named_arg(named_arg_info*, int& arg_index, - int&) { - ++arg_index; -} -template ::value)> -FMT_CONSTEXPR void init_static_named_arg(named_arg_info* named_args, - int& arg_index, int& named_arg_index) { - check_for_duplicate(named_args, named_arg_index, T::name); - named_args[named_arg_index++] = {T::name, arg_index++}; -} - -// To minimize the number of types we need to deal with, long is translated -// either to int or to long long depending on its size. -enum { long_short = sizeof(long) == sizeof(int) && FMT_BUILTIN_TYPES }; -using long_type = conditional_t; -using ulong_type = conditional_t; - -template -using format_as_result = - remove_cvref_t()))>; -template -using format_as_member_result = - remove_cvref_t::format_as(std::declval()))>; - -template -struct use_format_as : std::false_type {}; -// format_as member is only used to avoid injection into the std namespace. -template -struct use_format_as_member : std::false_type {}; - -// Only map owning types because mapping views can be unsafe. -template -struct use_format_as< - T, bool_constant>::value>> - : std::true_type {}; -template -struct use_format_as_member< - T, bool_constant>::value>> - : std::true_type {}; - -template > -using use_formatter = - bool_constant<(std::is_class::value || std::is_enum::value || - std::is_union::value || std::is_array::value) && - !has_to_string_view::value && !is_named_arg::value && - !use_format_as::value && !use_format_as_member::value>; - -template > -auto has_formatter_impl(T* p, buffered_context* ctx = nullptr) - -> decltype(formatter().format(*p, *ctx), std::true_type()); -template auto has_formatter_impl(...) -> std::false_type; - -// T can be const-qualified to check if it is const-formattable. -template constexpr auto has_formatter() -> bool { - return decltype(has_formatter_impl(static_cast(nullptr)))::value; -} - -// Maps formatting argument types to natively supported types or user-defined -// types with formatters. Returns void on errors to be SFINAE-friendly. -template struct type_mapper { - static auto map(signed char) -> int; - static auto map(unsigned char) -> unsigned; - static auto map(short) -> int; - static auto map(unsigned short) -> unsigned; - static auto map(int) -> int; - static auto map(unsigned) -> unsigned; - static auto map(long) -> long_type; - static auto map(unsigned long) -> ulong_type; - static auto map(long long) -> long long; - static auto map(unsigned long long) -> unsigned long long; - static auto map(int128_opt) -> int128_opt; - static auto map(uint128_opt) -> uint128_opt; - static auto map(bool) -> bool; - - template - static auto map(bitint) -> conditional_t; - template - static auto map(ubitint) - -> conditional_t; - - template ::value)> - static auto map(T) -> conditional_t< - std::is_same::value || std::is_same::value, Char, void>; - - static auto map(float) -> float; - static auto map(double) -> double; - static auto map(long double) -> long double; - - static auto map(Char*) -> const Char*; - static auto map(const Char*) -> const Char*; - template , - FMT_ENABLE_IF(!std::is_pointer::value)> - static auto map(const T&) -> conditional_t::value, - basic_string_view, void>; - - static auto map(void*) -> const void*; - static auto map(const void*) -> const void*; - static auto map(volatile void*) -> const void*; - static auto map(const volatile void*) -> const void*; - static auto map(nullptr_t) -> const void*; - template ::value || - std::is_member_pointer::value)> - static auto map(const T&) -> void; - - template ::value)> - static auto map(const T& x) -> decltype(map(format_as(x))); - template ::value)> - static auto map(const T& x) -> decltype(map(formatter::format_as(x))); - - template ::value)> - static auto map(T&) -> conditional_t(), T&, void>; - - template ::value)> - static auto map(const T& named_arg) -> decltype(map(named_arg.value)); -}; - -// detail:: is used to workaround a bug in MSVC 2017. -template -using mapped_t = decltype(detail::type_mapper::map(std::declval())); - -// A type constant after applying type_mapper. -template -using mapped_type_constant = type_constant, Char>; - -template ::value> -using stored_type_constant = std::integral_constant< - type, Context::builtin_types || TYPE == type::int_type ? TYPE - : type::custom_type>; -// A parse context with extra data used only in compile-time checks. -template -class compile_parse_context : public parse_context { - private: - int num_args_; - const type* types_; - using base = parse_context; - - public: - FMT_CONSTEXPR explicit compile_parse_context(basic_string_view fmt, - int num_args, const type* types, - int next_arg_id = 0) - : base(fmt, next_arg_id), num_args_(num_args), types_(types) {} - - constexpr auto num_args() const -> int { return num_args_; } - constexpr auto arg_type(int id) const -> type { return types_[id]; } - - FMT_CONSTEXPR auto next_arg_id() -> int { - int id = base::next_arg_id(); - if (id >= num_args_) report_error("argument not found"); - return id; - } - - FMT_CONSTEXPR void check_arg_id(int id) { - base::check_arg_id(id); - if (id >= num_args_) report_error("argument not found"); - } - using base::check_arg_id; - - FMT_CONSTEXPR void check_dynamic_spec(int arg_id) { - ignore_unused(arg_id); - if (arg_id < num_args_ && types_ && !is_integral_type(types_[arg_id])) - report_error("width/precision is not integer"); - } -}; - -// An argument reference. -template union arg_ref { - FMT_CONSTEXPR arg_ref(int idx = 0) : index(idx) {} - FMT_CONSTEXPR arg_ref(basic_string_view n) : name(n) {} - - int index; - basic_string_view name; -}; - -// Format specifiers with width and precision resolved at formatting rather -// than parsing time to allow reusing the same parsed specifiers with -// different sets of arguments (precompilation of format strings). -template struct dynamic_format_specs : format_specs { - arg_ref width_ref; - arg_ref precision_ref; -}; - -// Converts a character to ASCII. Returns '\0' on conversion failure. -template ::value)> -constexpr auto to_ascii(Char c) -> char { - return c <= 0xff ? static_cast(c) : '\0'; -} - -// Returns the number of code units in a code point or 1 on error. -template -FMT_CONSTEXPR auto code_point_length(const Char* begin) -> int { - if (const_check(sizeof(Char) != 1)) return 1; - auto c = static_cast(*begin); - return static_cast((0x3a55000000000000ull >> (2 * (c >> 3))) & 3) + 1; -} - -// Parses the range [begin, end) as an unsigned integer. This function assumes -// that the range is non-empty and the first character is a digit. -template -FMT_CONSTEXPR auto parse_nonnegative_int(const Char*& begin, const Char* end, - int error_value) noexcept -> int { - FMT_ASSERT(begin != end && '0' <= *begin && *begin <= '9', ""); - unsigned value = 0, prev = 0; - auto p = begin; - do { - prev = value; - value = value * 10 + unsigned(*p - '0'); - ++p; - } while (p != end && '0' <= *p && *p <= '9'); - auto num_digits = p - begin; - begin = p; - int digits10 = static_cast(sizeof(int) * CHAR_BIT * 3 / 10); - if (num_digits <= digits10) return static_cast(value); - // Check for overflow. - unsigned max = INT_MAX; - return num_digits == digits10 + 1 && - prev * 10ull + unsigned(p[-1] - '0') <= max - ? static_cast(value) - : error_value; -} - -FMT_CONSTEXPR inline auto parse_align(char c) -> align { - switch (c) { - case '<': return align::left; - case '>': return align::right; - case '^': return align::center; - } - return align::none; -} - -template constexpr auto is_name_start(Char c) -> bool { - return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_'; -} - -template -FMT_CONSTEXPR auto parse_arg_id(const Char* begin, const Char* end, - Handler&& handler) -> const Char* { - Char c = *begin; - if (c >= '0' && c <= '9') { - int index = 0; - if (c != '0') - index = parse_nonnegative_int(begin, end, INT_MAX); - else - ++begin; - if (begin == end || (*begin != '}' && *begin != ':')) - report_error("invalid format string"); - else - handler.on_index(index); - return begin; - } - if (FMT_OPTIMIZE_SIZE > 1 || !is_name_start(c)) { - report_error("invalid format string"); - return begin; - } - auto it = begin; - do { - ++it; - } while (it != end && (is_name_start(*it) || ('0' <= *it && *it <= '9'))); - handler.on_name({begin, to_unsigned(it - begin)}); - return it; -} - -template struct dynamic_spec_handler { - parse_context& ctx; - arg_ref& ref; - arg_id_kind& kind; - - FMT_CONSTEXPR void on_index(int id) { - ref = id; - kind = arg_id_kind::index; - ctx.check_arg_id(id); - ctx.check_dynamic_spec(id); - } - FMT_CONSTEXPR void on_name(basic_string_view id) { - ref = id; - kind = arg_id_kind::name; - ctx.check_arg_id(id); - } -}; - -template struct parse_dynamic_spec_result { - const Char* end; - arg_id_kind kind; -}; - -// Parses integer | "{" [arg_id] "}". -template -FMT_CONSTEXPR auto parse_dynamic_spec(const Char* begin, const Char* end, - int& value, arg_ref& ref, - parse_context& ctx) - -> parse_dynamic_spec_result { - FMT_ASSERT(begin != end, ""); - auto kind = arg_id_kind::none; - if ('0' <= *begin && *begin <= '9') { - int val = parse_nonnegative_int(begin, end, -1); - if (val == -1) report_error("number is too big"); - value = val; - } else { - if (*begin == '{') { - ++begin; - if (begin != end) { - Char c = *begin; - if (c == '}' || c == ':') { - int id = ctx.next_arg_id(); - ref = id; - kind = arg_id_kind::index; - ctx.check_dynamic_spec(id); - } else { - begin = parse_arg_id(begin, end, - dynamic_spec_handler{ctx, ref, kind}); - } - } - if (begin != end && *begin == '}') return {++begin, kind}; - } - report_error("invalid format string"); - } - return {begin, kind}; -} - -template -FMT_CONSTEXPR auto parse_width(const Char* begin, const Char* end, - format_specs& specs, arg_ref& width_ref, - parse_context& ctx) -> const Char* { - auto result = parse_dynamic_spec(begin, end, specs.width, width_ref, ctx); - specs.set_dynamic_width(result.kind); - return result.end; -} - -template -FMT_CONSTEXPR auto parse_precision(const Char* begin, const Char* end, - format_specs& specs, - arg_ref& precision_ref, - parse_context& ctx) -> const Char* { - ++begin; - if (begin == end) { - report_error("invalid precision"); - return begin; - } - auto result = - parse_dynamic_spec(begin, end, specs.precision, precision_ref, ctx); - specs.set_dynamic_precision(result.kind); - return result.end; -} - -enum class state { start, align, sign, hash, zero, width, precision, locale }; - -// Parses standard format specifiers. -template -FMT_CONSTEXPR auto parse_format_specs(const Char* begin, const Char* end, - dynamic_format_specs& specs, - parse_context& ctx, type arg_type) - -> const Char* { - auto c = '\0'; - if (end - begin > 1) { - auto next = to_ascii(begin[1]); - c = parse_align(next) == align::none ? to_ascii(*begin) : '\0'; - } else { - if (begin == end) return begin; - c = to_ascii(*begin); - } - - struct { - state current_state = state::start; - FMT_CONSTEXPR void operator()(state s, bool valid = true) { - if (current_state >= s || !valid) - report_error("invalid format specifier"); - current_state = s; - } - } enter_state; - - using pres = presentation_type; - constexpr auto integral_set = sint_set | uint_set | bool_set | char_set; - struct { - const Char*& begin; - format_specs& specs; - type arg_type; - - FMT_CONSTEXPR auto operator()(pres pres_type, int set) -> const Char* { - if (!in(arg_type, set)) report_error("invalid format specifier"); - specs.set_type(pres_type); - return begin + 1; - } - } parse_presentation_type{begin, specs, arg_type}; - - for (;;) { - switch (c) { - case '<': - case '>': - case '^': - enter_state(state::align); - specs.set_align(parse_align(c)); - ++begin; - break; - case '+': - case ' ': - specs.set_sign(c == ' ' ? sign::space : sign::plus); - FMT_FALLTHROUGH; - case '-': - enter_state(state::sign, in(arg_type, sint_set | float_set)); - ++begin; - break; - case '#': - enter_state(state::hash, is_arithmetic_type(arg_type)); - specs.set_alt(); - ++begin; - break; - case '0': - enter_state(state::zero); - if (!is_arithmetic_type(arg_type)) - report_error("format specifier requires numeric argument"); - if (specs.align() == align::none) { - // Ignore 0 if align is specified for compatibility with std::format. - specs.set_align(align::numeric); - specs.set_fill('0'); - } - ++begin; - break; - // clang-format off - case '1': case '2': case '3': case '4': case '5': - case '6': case '7': case '8': case '9': case '{': - // clang-format on - enter_state(state::width); - begin = parse_width(begin, end, specs, specs.width_ref, ctx); - break; - case '.': - enter_state(state::precision, - in(arg_type, float_set | string_set | cstring_set)); - begin = parse_precision(begin, end, specs, specs.precision_ref, ctx); - break; - case 'L': - enter_state(state::locale, is_arithmetic_type(arg_type)); - specs.set_localized(); - ++begin; - break; - case 'd': return parse_presentation_type(pres::dec, integral_set); - case 'X': specs.set_upper(); FMT_FALLTHROUGH; - case 'x': return parse_presentation_type(pres::hex, integral_set); - case 'o': return parse_presentation_type(pres::oct, integral_set); - case 'B': specs.set_upper(); FMT_FALLTHROUGH; - case 'b': return parse_presentation_type(pres::bin, integral_set); - case 'E': specs.set_upper(); FMT_FALLTHROUGH; - case 'e': return parse_presentation_type(pres::exp, float_set); - case 'F': specs.set_upper(); FMT_FALLTHROUGH; - case 'f': return parse_presentation_type(pres::fixed, float_set); - case 'G': specs.set_upper(); FMT_FALLTHROUGH; - case 'g': return parse_presentation_type(pres::general, float_set); - case 'A': specs.set_upper(); FMT_FALLTHROUGH; - case 'a': return parse_presentation_type(pres::hexfloat, float_set); - case 'c': - if (arg_type == type::bool_type) report_error("invalid format specifier"); - return parse_presentation_type(pres::chr, integral_set); - case 's': - return parse_presentation_type(pres::string, - bool_set | string_set | cstring_set); - case 'p': - return parse_presentation_type(pres::pointer, pointer_set | cstring_set); - case '?': - return parse_presentation_type(pres::debug, - char_set | string_set | cstring_set); - case '}': return begin; - default: { - if (*begin == '}') return begin; - // Parse fill and alignment. - auto fill_end = begin + code_point_length(begin); - if (end - fill_end <= 0) { - report_error("invalid format specifier"); - return begin; - } - if (*begin == '{') { - report_error("invalid fill character '{'"); - return begin; - } - auto alignment = parse_align(to_ascii(*fill_end)); - enter_state(state::align, alignment != align::none); - specs.set_fill( - basic_string_view(begin, to_unsigned(fill_end - begin))); - specs.set_align(alignment); - begin = fill_end + 1; - } - } - if (begin == end) return begin; - c = to_ascii(*begin); - } -} - -template -FMT_CONSTEXPR FMT_INLINE auto parse_replacement_field(const Char* begin, - const Char* end, - Handler&& handler) - -> const Char* { - ++begin; - if (begin == end) { - handler.on_error("invalid format string"); - return end; - } - int arg_id = 0; - switch (*begin) { - case '}': - handler.on_replacement_field(handler.on_arg_id(), begin); - return begin + 1; - case '{': handler.on_text(begin, begin + 1); return begin + 1; - case ':': arg_id = handler.on_arg_id(); break; - default: { - struct id_adapter { - Handler& handler; - int arg_id; - - FMT_CONSTEXPR void on_index(int id) { arg_id = handler.on_arg_id(id); } - FMT_CONSTEXPR void on_name(basic_string_view id) { - arg_id = handler.on_arg_id(id); - } - } adapter = {handler, 0}; - begin = parse_arg_id(begin, end, adapter); - arg_id = adapter.arg_id; - Char c = begin != end ? *begin : Char(); - if (c == '}') { - handler.on_replacement_field(arg_id, begin); - return begin + 1; - } - if (c != ':') { - handler.on_error("missing '}' in format string"); - return end; - } - break; - } - } - begin = handler.on_format_specs(arg_id, begin + 1, end); - if (begin == end || *begin != '}') - return handler.on_error("unknown format specifier"), end; - return begin + 1; -} - -template -FMT_CONSTEXPR void parse_format_string(basic_string_view fmt, - Handler&& handler) { - auto begin = fmt.data(), end = begin + fmt.size(); - auto p = begin; - while (p != end) { - auto c = *p++; - if (c == '{') { - handler.on_text(begin, p - 1); - begin = p = parse_replacement_field(p - 1, end, handler); - } else if (c == '}') { - if (p == end || *p != '}') - return handler.on_error("unmatched '}' in format string"); - handler.on_text(begin, p); - begin = ++p; - } - } - handler.on_text(begin, end); -} - -// Checks char specs and returns true iff the presentation type is char-like. -FMT_CONSTEXPR inline auto check_char_specs(const format_specs& specs) -> bool { - auto type = specs.type(); - if (type != presentation_type::none && type != presentation_type::chr && - type != presentation_type::debug) { - return false; - } - if (specs.align() == align::numeric || specs.sign() != sign::none || - specs.alt()) { - report_error("invalid format specifier for char"); - } - return true; -} - -// A base class for compile-time strings. -struct compile_string {}; - -template -FMT_VISIBILITY("hidden") // Suppress an ld warning on macOS (#3769). -FMT_CONSTEXPR auto invoke_parse(parse_context& ctx) -> const Char* { - using mapped_type = remove_cvref_t>; - constexpr bool formattable = - std::is_constructible>::value; - if (!formattable) return ctx.begin(); // Error is reported in the value ctor. - using formatted_type = conditional_t; - return formatter().parse(ctx); -} - -template struct arg_pack {}; - -template -class format_string_checker { - private: - type types_[max_of(1, NUM_ARGS)]; - named_arg_info named_args_[max_of(1, NUM_NAMED_ARGS)]; - compile_parse_context context_; - - using parse_func = auto (*)(parse_context&) -> const Char*; - parse_func parse_funcs_[max_of(1, NUM_ARGS)]; - - public: - template - FMT_CONSTEXPR explicit format_string_checker(basic_string_view fmt, - arg_pack) - : types_{mapped_type_constant::value...}, - named_args_{}, - context_(fmt, NUM_ARGS, types_), - parse_funcs_{&invoke_parse...} { - int arg_index = 0, named_arg_index = 0; - FMT_APPLY_VARIADIC( - init_static_named_arg(named_args_, arg_index, named_arg_index)); - ignore_unused(arg_index, named_arg_index); - } - - FMT_CONSTEXPR void on_text(const Char*, const Char*) {} - - FMT_CONSTEXPR auto on_arg_id() -> int { return context_.next_arg_id(); } - FMT_CONSTEXPR auto on_arg_id(int id) -> int { - context_.check_arg_id(id); - return id; - } - FMT_CONSTEXPR auto on_arg_id(basic_string_view id) -> int { - for (int i = 0; i < NUM_NAMED_ARGS; ++i) { - if (named_args_[i].name == id) return named_args_[i].id; - } - if (!DYNAMIC_NAMES) on_error("argument not found"); - return -1; - } - - FMT_CONSTEXPR void on_replacement_field(int id, const Char* begin) { - on_format_specs(id, begin, begin); // Call parse() on empty specs. - } - - FMT_CONSTEXPR auto on_format_specs(int id, const Char* begin, const Char* end) - -> const Char* { - context_.advance_to(begin); - if (id >= 0 && id < NUM_ARGS) return parse_funcs_[id](context_); - - // If id is out of range, it means we do not know the type and cannot parse - // the format at compile time. Instead, skip over content until we finish - // the format spec, accounting for any nested replacements. - for (int bracket_count = 0; - begin != end && (bracket_count > 0 || *begin != '}'); ++begin) { - if (*begin == '{') - ++bracket_count; - else if (*begin == '}') - --bracket_count; - } - return begin; - } - - FMT_NORETURN FMT_CONSTEXPR void on_error(const char* message) { - report_error(message); - } -}; - -/// A contiguous memory buffer with an optional growing ability. It is an -/// internal class and shouldn't be used directly, only via `memory_buffer`. -template class buffer { - private: - T* ptr_; - size_t size_; - size_t capacity_; - - using grow_fun = void (*)(buffer& buf, size_t capacity); - grow_fun grow_; - - protected: - // Don't initialize ptr_ since it is not accessed to save a few cycles. - FMT_MSC_WARNING(suppress : 26495) - FMT_CONSTEXPR buffer(grow_fun grow, size_t sz) noexcept - : size_(sz), capacity_(sz), grow_(grow) {} - - constexpr buffer(grow_fun grow, T* p = nullptr, size_t sz = 0, - size_t cap = 0) noexcept - : ptr_(p), size_(sz), capacity_(cap), grow_(grow) {} - - FMT_CONSTEXPR20 ~buffer() = default; - buffer(buffer&&) = default; - - /// Sets the buffer data and capacity. - FMT_CONSTEXPR void set(T* buf_data, size_t buf_capacity) noexcept { - ptr_ = buf_data; - capacity_ = buf_capacity; - } - - public: - using value_type = T; - using const_reference = const T&; - - buffer(const buffer&) = delete; - void operator=(const buffer&) = delete; - - auto begin() noexcept -> T* { return ptr_; } - auto end() noexcept -> T* { return ptr_ + size_; } - - auto begin() const noexcept -> const T* { return ptr_; } - auto end() const noexcept -> const T* { return ptr_ + size_; } - - /// Returns the size of this buffer. - constexpr auto size() const noexcept -> size_t { return size_; } - - /// Returns the capacity of this buffer. - constexpr auto capacity() const noexcept -> size_t { return capacity_; } - - /// Returns a pointer to the buffer data (not null-terminated). - FMT_CONSTEXPR auto data() noexcept -> T* { return ptr_; } - FMT_CONSTEXPR auto data() const noexcept -> const T* { return ptr_; } - - /// Clears this buffer. - FMT_CONSTEXPR void clear() { size_ = 0; } - - // Tries resizing the buffer to contain `count` elements. If T is a POD type - // the new elements may not be initialized. - FMT_CONSTEXPR void try_resize(size_t count) { - try_reserve(count); - size_ = min_of(count, capacity_); - } - - // Tries increasing the buffer capacity to `new_capacity`. It can increase the - // capacity by a smaller amount than requested but guarantees there is space - // for at least one additional element either by increasing the capacity or by - // flushing the buffer if it is full. - FMT_CONSTEXPR void try_reserve(size_t new_capacity) { - if (new_capacity > capacity_) grow_(*this, new_capacity); - } - - FMT_CONSTEXPR void push_back(const T& value) { - try_reserve(size_ + 1); - ptr_[size_++] = value; - } - - /// Appends data to the end of the buffer. - template -// Workaround for MSVC2019 to fix error C2893: Failed to specialize function -// template 'void fmt::v11::detail::buffer::append(const U *,const U *)'. -#if !FMT_MSC_VERSION || FMT_MSC_VERSION >= 1940 - FMT_CONSTEXPR20 -#endif - void - append(const U* begin, const U* end) { - while (begin != end) { - auto count = to_unsigned(end - begin); - try_reserve(size_ + count); - auto free_cap = capacity_ - size_; - if (free_cap < count) count = free_cap; - // A loop is faster than memcpy on small sizes. - T* out = ptr_ + size_; - for (size_t i = 0; i < count; ++i) out[i] = begin[i]; - size_ += count; - begin += count; - } - } - - template FMT_CONSTEXPR auto operator[](Idx index) -> T& { - return ptr_[index]; - } - template - FMT_CONSTEXPR auto operator[](Idx index) const -> const T& { - return ptr_[index]; - } -}; - -struct buffer_traits { - constexpr explicit buffer_traits(size_t) {} - constexpr auto count() const -> size_t { return 0; } - constexpr auto limit(size_t size) const -> size_t { return size; } -}; - -class fixed_buffer_traits { - private: - size_t count_ = 0; - size_t limit_; - - public: - constexpr explicit fixed_buffer_traits(size_t limit) : limit_(limit) {} - constexpr auto count() const -> size_t { return count_; } - FMT_CONSTEXPR auto limit(size_t size) -> size_t { - size_t n = limit_ > count_ ? limit_ - count_ : 0; - count_ += size; - return min_of(size, n); - } -}; - -// A buffer that writes to an output iterator when flushed. -template -class iterator_buffer : public Traits, public buffer { - private: - OutputIt out_; - enum { buffer_size = 256 }; - T data_[buffer_size]; - - static FMT_CONSTEXPR void grow(buffer& buf, size_t) { - if (buf.size() == buffer_size) static_cast(buf).flush(); - } - - void flush() { - auto size = this->size(); - this->clear(); - const T* begin = data_; - const T* end = begin + this->limit(size); - while (begin != end) *out_++ = *begin++; - } - - public: - explicit iterator_buffer(OutputIt out, size_t n = buffer_size) - : Traits(n), buffer(grow, data_, 0, buffer_size), out_(out) {} - iterator_buffer(iterator_buffer&& other) noexcept - : Traits(other), - buffer(grow, data_, 0, buffer_size), - out_(other.out_) {} - ~iterator_buffer() { - // Don't crash if flush fails during unwinding. - FMT_TRY { flush(); } - FMT_CATCH(...) {} - } - - auto out() -> OutputIt { - flush(); - return out_; - } - auto count() const -> size_t { return Traits::count() + this->size(); } -}; - -template -class iterator_buffer : public fixed_buffer_traits, - public buffer { - private: - T* out_; - enum { buffer_size = 256 }; - T data_[buffer_size]; - - static FMT_CONSTEXPR void grow(buffer& buf, size_t) { - if (buf.size() == buf.capacity()) - static_cast(buf).flush(); - } - - void flush() { - size_t n = this->limit(this->size()); - if (this->data() == out_) { - out_ += n; - this->set(data_, buffer_size); - } - this->clear(); - } - - public: - explicit iterator_buffer(T* out, size_t n = buffer_size) - : fixed_buffer_traits(n), buffer(grow, out, 0, n), out_(out) {} - iterator_buffer(iterator_buffer&& other) noexcept - : fixed_buffer_traits(other), - buffer(static_cast(other)), - out_(other.out_) { - if (this->data() != out_) { - this->set(data_, buffer_size); - this->clear(); - } - } - ~iterator_buffer() { flush(); } - - auto out() -> T* { - flush(); - return out_; - } - auto count() const -> size_t { - return fixed_buffer_traits::count() + this->size(); - } -}; - -template class iterator_buffer : public buffer { - public: - explicit iterator_buffer(T* out, size_t = 0) - : buffer([](buffer&, size_t) {}, out, 0, ~size_t()) {} - - auto out() -> T* { return &*this->end(); } -}; - -template -class container_buffer : public buffer { - private: - using value_type = typename Container::value_type; - - static FMT_CONSTEXPR void grow(buffer& buf, size_t capacity) { - auto& self = static_cast(buf); - self.container.resize(capacity); - self.set(&self.container[0], capacity); - } - - public: - Container& container; - - explicit container_buffer(Container& c) - : buffer(grow, c.size()), container(c) {} -}; - -// A buffer that writes to a container with the contiguous storage. -template -class iterator_buffer< - OutputIt, - enable_if_t::value && - is_contiguous::value, - typename OutputIt::container_type::value_type>> - : public container_buffer { - private: - using base = container_buffer; - - public: - explicit iterator_buffer(typename OutputIt::container_type& c) : base(c) {} - explicit iterator_buffer(OutputIt out, size_t = 0) - : base(get_container(out)) {} - - auto out() -> OutputIt { return OutputIt(this->container); } -}; - -// A buffer that counts the number of code units written discarding the output. -template class counting_buffer : public buffer { - private: - enum { buffer_size = 256 }; - T data_[buffer_size]; - size_t count_ = 0; - - static FMT_CONSTEXPR void grow(buffer& buf, size_t) { - if (buf.size() != buffer_size) return; - static_cast(buf).count_ += buf.size(); - buf.clear(); - } - - public: - FMT_CONSTEXPR counting_buffer() : buffer(grow, data_, 0, buffer_size) {} - - constexpr auto count() const noexcept -> size_t { - return count_ + this->size(); - } -}; - -template -struct is_back_insert_iterator> : std::true_type {}; - -template -struct has_back_insert_iterator_container_append : std::false_type {}; -template -struct has_back_insert_iterator_container_append< - OutputIt, InputIt, - void_t()) - .append(std::declval(), - std::declval()))>> : std::true_type {}; - -template -struct has_back_insert_iterator_container_insert_at_end : std::false_type {}; - -template -struct has_back_insert_iterator_container_insert_at_end< - OutputIt, InputIt, - void_t()) - .insert(get_container(std::declval()).end(), - std::declval(), - std::declval()))>> : std::true_type {}; - -// An optimized version of std::copy with the output value type (T). -template ::value&& - has_back_insert_iterator_container_append< - OutputIt, InputIt>::value)> -FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out) - -> OutputIt { - get_container(out).append(begin, end); - return out; -} - -template ::value && - !has_back_insert_iterator_container_append< - OutputIt, InputIt>::value && - has_back_insert_iterator_container_insert_at_end< - OutputIt, InputIt>::value)> -FMT_CONSTEXPR20 auto copy(InputIt begin, InputIt end, OutputIt out) - -> OutputIt { - auto& c = get_container(out); - c.insert(c.end(), begin, end); - return out; -} - -template ::value && - (has_back_insert_iterator_container_append< - OutputIt, InputIt>::value || - has_back_insert_iterator_container_insert_at_end< - OutputIt, InputIt>::value)))> -FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt { - while (begin != end) *out++ = static_cast(*begin++); - return out; -} - -template -FMT_CONSTEXPR auto copy(basic_string_view s, OutputIt out) -> OutputIt { - return copy(s.begin(), s.end(), out); -} - -template -struct is_buffer_appender : std::false_type {}; -template -struct is_buffer_appender< - It, bool_constant< - is_back_insert_iterator::value && - std::is_base_of, - typename It::container_type>::value>> - : std::true_type {}; - -// Maps an output iterator to a buffer. -template ::value)> -auto get_buffer(OutputIt out) -> iterator_buffer { - return iterator_buffer(out); -} -template ::value)> -auto get_buffer(OutputIt out) -> buffer& { - return get_container(out); -} - -template -auto get_iterator(Buf& buf, OutputIt) -> decltype(buf.out()) { - return buf.out(); -} -template -auto get_iterator(buffer&, OutputIt out) -> OutputIt { - return out; -} - -// This type is intentionally undefined, only used for errors. -template struct type_is_unformattable_for; - -template struct string_value { - const Char* data; - size_t size; - auto str() const -> basic_string_view { return {data, size}; } -}; - -template struct custom_value { - using char_type = typename Context::char_type; - void* value; - void (*format)(void* arg, parse_context& parse_ctx, Context& ctx); -}; - -template struct named_arg_value { - const named_arg_info* data; - size_t size; -}; - -struct custom_tag {}; - -#if !FMT_BUILTIN_TYPES -# define FMT_BUILTIN , monostate -#else -# define FMT_BUILTIN -#endif - -// A formatting argument value. -template class value { - public: - using char_type = typename Context::char_type; - - union { - monostate no_value; - int int_value; - unsigned uint_value; - long long long_long_value; - unsigned long long ulong_long_value; - int128_opt int128_value; - uint128_opt uint128_value; - bool bool_value; - char_type char_value; - float float_value; - double double_value; - long double long_double_value; - const void* pointer; - string_value string; - custom_value custom; - named_arg_value named_args; - }; - - constexpr FMT_INLINE value() : no_value() {} - constexpr FMT_INLINE value(signed char x) : int_value(x) {} - constexpr FMT_INLINE value(unsigned char x FMT_BUILTIN) : uint_value(x) {} - constexpr FMT_INLINE value(signed short x) : int_value(x) {} - constexpr FMT_INLINE value(unsigned short x FMT_BUILTIN) : uint_value(x) {} - constexpr FMT_INLINE value(int x) : int_value(x) {} - constexpr FMT_INLINE value(unsigned x FMT_BUILTIN) : uint_value(x) {} - FMT_CONSTEXPR FMT_INLINE value(long x FMT_BUILTIN) : value(long_type(x)) {} - FMT_CONSTEXPR FMT_INLINE value(unsigned long x FMT_BUILTIN) - : value(ulong_type(x)) {} - constexpr FMT_INLINE value(long long x FMT_BUILTIN) : long_long_value(x) {} - constexpr FMT_INLINE value(unsigned long long x FMT_BUILTIN) - : ulong_long_value(x) {} - FMT_INLINE value(int128_opt x FMT_BUILTIN) : int128_value(x) {} - FMT_INLINE value(uint128_opt x FMT_BUILTIN) : uint128_value(x) {} - constexpr FMT_INLINE value(bool x FMT_BUILTIN) : bool_value(x) {} - - template - constexpr FMT_INLINE value(bitint x FMT_BUILTIN) : long_long_value(x) { - static_assert(N <= 64, "unsupported _BitInt"); - } - template - constexpr FMT_INLINE value(ubitint x FMT_BUILTIN) : ulong_long_value(x) { - static_assert(N <= 64, "unsupported _BitInt"); - } - - template ::value)> - constexpr FMT_INLINE value(T x FMT_BUILTIN) : char_value(x) { - static_assert( - std::is_same::value || std::is_same::value, - "mixing character types is disallowed"); - } - - constexpr FMT_INLINE value(float x FMT_BUILTIN) : float_value(x) {} - constexpr FMT_INLINE value(double x FMT_BUILTIN) : double_value(x) {} - FMT_INLINE value(long double x FMT_BUILTIN) : long_double_value(x) {} - - FMT_CONSTEXPR FMT_INLINE value(char_type* x FMT_BUILTIN) { - string.data = x; - if (is_constant_evaluated()) string.size = 0; - } - FMT_CONSTEXPR FMT_INLINE value(const char_type* x FMT_BUILTIN) { - string.data = x; - if (is_constant_evaluated()) string.size = 0; - } - template , - FMT_ENABLE_IF(!std::is_pointer::value)> - FMT_CONSTEXPR value(const T& x FMT_BUILTIN) { - static_assert(std::is_same::value, - "mixing character types is disallowed"); - auto sv = to_string_view(x); - string.data = sv.data(); - string.size = sv.size(); - } - FMT_INLINE value(void* x FMT_BUILTIN) : pointer(x) {} - FMT_INLINE value(const void* x FMT_BUILTIN) : pointer(x) {} - FMT_INLINE value(volatile void* x FMT_BUILTIN) - : pointer(const_cast(x)) {} - FMT_INLINE value(const volatile void* x FMT_BUILTIN) - : pointer(const_cast(x)) {} - FMT_INLINE value(nullptr_t) : pointer(nullptr) {} - - template ::value || - std::is_member_pointer::value)> - value(const T&) { - // Formatting of arbitrary pointers is disallowed. If you want to format a - // pointer cast it to `void*` or `const void*`. In particular, this forbids - // formatting of `[const] volatile char*` printed as bool by iostreams. - static_assert(sizeof(T) == 0, - "formatting of non-void pointers is disallowed"); - } - - template ::value)> - value(const T& x) : value(format_as(x)) {} - template ::value)> - value(const T& x) : value(formatter::format_as(x)) {} - - template ::value)> - value(const T& named_arg) : value(named_arg.value) {} - - template ::value || !FMT_BUILTIN_TYPES)> - FMT_CONSTEXPR20 FMT_INLINE value(T& x) : value(x, custom_tag()) {} - - FMT_ALWAYS_INLINE value(const named_arg_info* args, size_t size) - : named_args{args, size} {} - - private: - template ())> - FMT_CONSTEXPR value(T& x, custom_tag) { - using value_type = remove_const_t; - // T may overload operator& e.g. std::vector::reference in libc++. - if (!is_constant_evaluated()) { - custom.value = - const_cast(&reinterpret_cast(x)); - } else { - custom.value = nullptr; -#if defined(__cpp_if_constexpr) - if constexpr (std::is_same*>::value) - custom.value = const_cast(&x); -#endif - } - custom.format = format_custom; - } - - template ())> - FMT_CONSTEXPR value(const T&, custom_tag) { - // Cannot format an argument; to make type T formattable provide a - // formatter specialization: https://fmt.dev/latest/api.html#udt. - type_is_unformattable_for _; - } - - // Formats an argument of a custom type, such as a user-defined class. - template - static void format_custom(void* arg, parse_context& parse_ctx, - Context& ctx) { - auto f = formatter(); - parse_ctx.advance_to(f.parse(parse_ctx)); - using qualified_type = - conditional_t(), const T, T>; - // format must be const for compatibility with std::format and compilation. - const auto& cf = f; - ctx.advance_to(cf.format(*static_cast(arg), ctx)); - } -}; - -enum { packed_arg_bits = 4 }; -// Maximum number of arguments with packed types. -enum { max_packed_args = 62 / packed_arg_bits }; -enum : unsigned long long { is_unpacked_bit = 1ULL << 63 }; -enum : unsigned long long { has_named_args_bit = 1ULL << 62 }; - -template -struct is_output_iterator : std::false_type {}; - -template <> struct is_output_iterator : std::true_type {}; - -template -struct is_output_iterator< - It, T, - enable_if_t&>()++), - T>::value>> : std::true_type {}; - -template constexpr auto encode_types() -> unsigned long long { - return 0; -} - -template -constexpr auto encode_types() -> unsigned long long { - return static_cast(stored_type_constant::value) | - (encode_types() << packed_arg_bits); -} - -template -constexpr auto make_descriptor() -> unsigned long long { - return NUM_ARGS <= max_packed_args ? encode_types() - : is_unpacked_bit | NUM_ARGS; -} - -template -using arg_t = conditional_t, - basic_format_arg>; - -template -struct named_arg_store { - // args_[0].named_args points to named_args to avoid bloating format_args. - arg_t args[1u + NUM_ARGS]; - named_arg_info - named_args[static_cast(NUM_NAMED_ARGS)]; - - template - FMT_CONSTEXPR FMT_ALWAYS_INLINE named_arg_store(T&... values) - : args{{named_args, NUM_NAMED_ARGS}, values...} { - int arg_index = 0, named_arg_index = 0; - FMT_APPLY_VARIADIC( - init_named_arg(named_args, arg_index, named_arg_index, values)); - } - - named_arg_store(named_arg_store&& rhs) { - args[0] = {named_args, NUM_NAMED_ARGS}; - for (size_t i = 1; i < sizeof(args) / sizeof(*args); ++i) - args[i] = rhs.args[i]; - for (size_t i = 0; i < NUM_NAMED_ARGS; ++i) - named_args[i] = rhs.named_args[i]; - } - - named_arg_store(const named_arg_store& rhs) = delete; - auto operator=(const named_arg_store& rhs) -> named_arg_store& = delete; - auto operator=(named_arg_store&& rhs) -> named_arg_store& = delete; - operator const arg_t*() const { return args + 1; } -}; - -// An array of references to arguments. It can be implicitly converted to -// `basic_format_args` for passing into type-erased formatting functions -// such as `vformat`. It is a plain struct to reduce binary size in debug mode. -template -struct format_arg_store { - // +1 to workaround a bug in gcc 7.5 that causes duplicated-branches warning. - using type = - conditional_t[max_of(1, NUM_ARGS)], - named_arg_store>; - type args; -}; - -// TYPE can be different from type_constant, e.g. for __float128. -template struct native_formatter { - private: - dynamic_format_specs specs_; - - public: - using nonlocking = void; - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); - auto end = parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, TYPE); - if (const_check(TYPE == type::char_type)) check_char_specs(specs_); - return end; - } - - template - FMT_CONSTEXPR void set_debug_format(bool set = true) { - specs_.set_type(set ? presentation_type::debug : presentation_type::none); - } - - FMT_PRAGMA_CLANG(diagnostic ignored "-Wundefined-inline") - template - FMT_CONSTEXPR auto format(const T& val, FormatContext& ctx) const - -> decltype(ctx.out()); -}; - -template -struct locking - : bool_constant::value == type::custom_type> {}; -template -struct locking>::nonlocking>> - : std::false_type {}; - -template FMT_CONSTEXPR inline auto is_locking() -> bool { - return locking::value; -} -template -FMT_CONSTEXPR inline auto is_locking() -> bool { - return locking::value || is_locking(); -} - -FMT_API void vformat_to(buffer& buf, string_view fmt, format_args args, - locale_ref loc = {}); - -#if FMT_WIN32 -FMT_API void vprint_mojibake(FILE*, string_view, format_args, bool); -#else // format_args is passed by reference since it is defined later. -inline void vprint_mojibake(FILE*, string_view, const format_args&, bool) {} -#endif -} // namespace detail - -// The main public API. - -template -FMT_CONSTEXPR void parse_context::do_check_arg_id(int arg_id) { - // Argument id is only checked at compile time during parsing because - // formatting has its own validation. - if (detail::is_constant_evaluated() && use_constexpr_cast) { - auto ctx = static_cast*>(this); - if (arg_id >= ctx->num_args()) report_error("argument not found"); - } -} - -template -FMT_CONSTEXPR void parse_context::check_dynamic_spec(int arg_id) { - using detail::compile_parse_context; - if (detail::is_constant_evaluated() && use_constexpr_cast) - static_cast*>(this)->check_dynamic_spec(arg_id); -} - -FMT_BEGIN_EXPORT - -// An output iterator that appends to a buffer. It is used instead of -// back_insert_iterator to reduce symbol sizes and avoid dependency. -template class basic_appender { - protected: - detail::buffer* container; - - public: - using container_type = detail::buffer; - - FMT_CONSTEXPR basic_appender(detail::buffer& buf) : container(&buf) {} - - FMT_CONSTEXPR20 auto operator=(T c) -> basic_appender& { - container->push_back(c); - return *this; - } - FMT_CONSTEXPR20 auto operator*() -> basic_appender& { return *this; } - FMT_CONSTEXPR20 auto operator++() -> basic_appender& { return *this; } - FMT_CONSTEXPR20 auto operator++(int) -> basic_appender { return *this; } -}; - -// A formatting argument. Context is a template parameter for the compiled API -// where output can be unbuffered. -template class basic_format_arg { - private: - detail::value value_; - detail::type type_; - - friend class basic_format_args; - - using char_type = typename Context::char_type; - - public: - class handle { - private: - detail::custom_value custom_; - - public: - explicit handle(detail::custom_value custom) : custom_(custom) {} - - void format(parse_context& parse_ctx, Context& ctx) const { - custom_.format(custom_.value, parse_ctx, ctx); - } - }; - - constexpr basic_format_arg() : type_(detail::type::none_type) {} - basic_format_arg(const detail::named_arg_info* args, size_t size) - : value_(args, size) {} - template - basic_format_arg(T&& val) - : value_(val), type_(detail::stored_type_constant::value) {} - - constexpr explicit operator bool() const noexcept { - return type_ != detail::type::none_type; - } - auto type() const -> detail::type { return type_; } - - /** - * Visits an argument dispatching to the appropriate visit method based on - * the argument type. For example, if the argument type is `double` then - * `vis(value)` will be called with the value of type `double`. - */ - template - FMT_CONSTEXPR FMT_INLINE auto visit(Visitor&& vis) const -> decltype(vis(0)) { - using detail::map; - switch (type_) { - case detail::type::none_type: break; - case detail::type::int_type: return vis(value_.int_value); - case detail::type::uint_type: return vis(value_.uint_value); - case detail::type::long_long_type: return vis(value_.long_long_value); - case detail::type::ulong_long_type: return vis(value_.ulong_long_value); - case detail::type::int128_type: return vis(map(value_.int128_value)); - case detail::type::uint128_type: return vis(map(value_.uint128_value)); - case detail::type::bool_type: return vis(value_.bool_value); - case detail::type::char_type: return vis(value_.char_value); - case detail::type::float_type: return vis(value_.float_value); - case detail::type::double_type: return vis(value_.double_value); - case detail::type::long_double_type: return vis(value_.long_double_value); - case detail::type::cstring_type: return vis(value_.string.data); - case detail::type::string_type: return vis(value_.string.str()); - case detail::type::pointer_type: return vis(value_.pointer); - case detail::type::custom_type: return vis(handle(value_.custom)); - } - return vis(monostate()); - } - - auto format_custom(const char_type* parse_begin, - parse_context& parse_ctx, Context& ctx) - -> bool { - if (type_ != detail::type::custom_type) return false; - parse_ctx.advance_to(parse_begin); - value_.custom.format(value_.custom.value, parse_ctx, ctx); - return true; - } -}; - -/** - * A view of a collection of formatting arguments. To avoid lifetime issues it - * should only be used as a parameter type in type-erased functions such as - * `vformat`: - * - * void vlog(fmt::string_view fmt, fmt::format_args args); // OK - * fmt::format_args args = fmt::make_format_args(); // Dangling reference - */ -template class basic_format_args { - private: - // A descriptor that contains information about formatting arguments. - // If the number of arguments is less or equal to max_packed_args then - // argument types are passed in the descriptor. This reduces binary code size - // per formatting function call. - unsigned long long desc_; - union { - // If is_packed() returns true then argument values are stored in values_; - // otherwise they are stored in args_. This is done to improve cache - // locality and reduce compiled code size since storing larger objects - // may require more code (at least on x86-64) even if the same amount of - // data is actually copied to stack. It saves ~10% on the bloat test. - const detail::value* values_; - const basic_format_arg* args_; - }; - - constexpr auto is_packed() const -> bool { - return (desc_ & detail::is_unpacked_bit) == 0; - } - constexpr auto has_named_args() const -> bool { - return (desc_ & detail::has_named_args_bit) != 0; - } - - FMT_CONSTEXPR auto type(int index) const -> detail::type { - int shift = index * detail::packed_arg_bits; - unsigned mask = (1 << detail::packed_arg_bits) - 1; - return static_cast((desc_ >> shift) & mask); - } - - template - using store = - detail::format_arg_store; - - public: - using format_arg = basic_format_arg; - - constexpr basic_format_args() : desc_(0), args_(nullptr) {} - - /// Constructs a `basic_format_args` object from `format_arg_store`. - template - constexpr FMT_ALWAYS_INLINE basic_format_args( - const store& s) - : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)), - values_(s.args) {} - - template detail::max_packed_args)> - constexpr basic_format_args(const store& s) - : desc_(DESC | (NUM_NAMED_ARGS != 0 ? +detail::has_named_args_bit : 0)), - args_(s.args) {} - - /// Constructs a `basic_format_args` object from a dynamic list of arguments. - constexpr basic_format_args(const format_arg* args, int count, - bool has_named = false) - : desc_(detail::is_unpacked_bit | detail::to_unsigned(count) | - (has_named ? +detail::has_named_args_bit : 0)), - args_(args) {} - - /// Returns the argument with the specified id. - FMT_CONSTEXPR auto get(int id) const -> format_arg { - auto arg = format_arg(); - if (!is_packed()) { - if (id < max_size()) arg = args_[id]; - return arg; - } - if (static_cast(id) >= detail::max_packed_args) return arg; - arg.type_ = type(id); - if (arg.type_ != detail::type::none_type) arg.value_ = values_[id]; - return arg; - } - - template - auto get(basic_string_view name) const -> format_arg { - int id = get_id(name); - return id >= 0 ? get(id) : format_arg(); - } - - template - FMT_CONSTEXPR auto get_id(basic_string_view name) const -> int { - if (!has_named_args()) return -1; - const auto& named_args = - (is_packed() ? values_[-1] : args_[-1].value_).named_args; - for (size_t i = 0; i < named_args.size; ++i) { - if (named_args.data[i].name == name) return named_args.data[i].id; - } - return -1; - } - - auto max_size() const -> int { - unsigned long long max_packed = detail::max_packed_args; - return static_cast(is_packed() ? max_packed - : desc_ & ~detail::is_unpacked_bit); - } -}; - -// A formatting context. -class context { - private: - appender out_; - format_args args_; - FMT_NO_UNIQUE_ADDRESS locale_ref loc_; - - public: - using char_type = char; ///< The character type for the output. - using iterator = appender; - using format_arg = basic_format_arg; - enum { builtin_types = FMT_BUILTIN_TYPES }; - - /// Constructs a `context` object. References to the arguments are stored - /// in the object so make sure they have appropriate lifetimes. - FMT_CONSTEXPR context(iterator out, format_args args, locale_ref loc = {}) - : out_(out), args_(args), loc_(loc) {} - context(context&&) = default; - context(const context&) = delete; - void operator=(const context&) = delete; - - FMT_CONSTEXPR auto arg(int id) const -> format_arg { return args_.get(id); } - inline auto arg(string_view name) const -> format_arg { - return args_.get(name); - } - FMT_CONSTEXPR auto arg_id(string_view name) const -> int { - return args_.get_id(name); - } - auto args() const -> const format_args& { return args_; } - - // Returns an iterator to the beginning of the output range. - FMT_CONSTEXPR auto out() const -> iterator { return out_; } - - // Advances the begin iterator to `it`. - FMT_CONSTEXPR void advance_to(iterator) {} - - FMT_CONSTEXPR auto locale() const -> locale_ref { return loc_; } -}; - -template struct runtime_format_string { - basic_string_view str; -}; - -/** - * Creates a runtime format string. - * - * **Example**: - * - * // Check format string at runtime instead of compile-time. - * fmt::print(fmt::runtime("{:d}"), "I am not a number"); - */ -inline auto runtime(string_view s) -> runtime_format_string<> { return {{s}}; } - -/// A compile-time format string. Use `format_string` in the public API to -/// prevent type deduction. -template struct fstring { - private: - static constexpr int num_static_named_args = - detail::count_static_named_args(); - - using checker = detail::format_string_checker< - char, static_cast(sizeof...(T)), num_static_named_args, - num_static_named_args != detail::count_named_args()>; - - using arg_pack = detail::arg_pack; - - public: - string_view str; - using t = fstring; - - // Reports a compile-time error if S is not a valid format string for T. - template - FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const char (&s)[N]) : str(s, N - 1) { - using namespace detail; - static_assert(count<(is_view>::value && - std::is_reference::value)...>() == 0, - "passing views as lvalues is disallowed"); - if (FMT_USE_CONSTEVAL) parse_format_string(s, checker(s, arg_pack())); -#ifdef FMT_ENFORCE_COMPILE_STRING - static_assert( - FMT_USE_CONSTEVAL && sizeof(s) != 0, - "FMT_ENFORCE_COMPILE_STRING requires format strings to use FMT_STRING"); -#endif - } - template ::value)> - FMT_CONSTEVAL FMT_ALWAYS_INLINE fstring(const S& s) : str(s) { - auto sv = string_view(str); - if (FMT_USE_CONSTEVAL) - detail::parse_format_string(sv, checker(sv, arg_pack())); -#ifdef FMT_ENFORCE_COMPILE_STRING - static_assert( - FMT_USE_CONSTEVAL && sizeof(s) != 0, - "FMT_ENFORCE_COMPILE_STRING requires format strings to use FMT_STRING"); -#endif - } - template ::value&& - std::is_same::value)> - FMT_ALWAYS_INLINE fstring(const S&) : str(S()) { - FMT_CONSTEXPR auto sv = string_view(S()); - FMT_CONSTEXPR int unused = - (parse_format_string(sv, checker(sv, arg_pack())), 0); - detail::ignore_unused(unused); - } - fstring(runtime_format_string<> fmt) : str(fmt.str) {} - - // Returning by reference generates better code in debug mode. - FMT_ALWAYS_INLINE operator const string_view&() const { return str; } - auto get() const -> string_view { return str; } -}; - -template using format_string = typename fstring::t; - -template -using is_formattable = bool_constant::value, int*, T>, Char>, - void>::value>; -#ifdef __cpp_concepts -template -concept formattable = is_formattable, Char>::value; -#endif - -// A formatter specialization for natively supported types. -template -struct formatter::value != - detail::type::custom_type>> - : detail::native_formatter::value> { -}; - -/** - * Constructs an object that stores references to arguments and can be - * implicitly converted to `format_args`. `Context` can be omitted in which case - * it defaults to `context`. See `arg` for lifetime considerations. - */ -// Take arguments by lvalue references to avoid some lifetime issues, e.g. -// auto args = make_format_args(std::string()); -template (), - unsigned long long DESC = detail::make_descriptor()> -constexpr FMT_ALWAYS_INLINE auto make_format_args(T&... args) - -> detail::format_arg_store { - // Suppress warnings for pathological types convertible to detail::value. - FMT_PRAGMA_GCC(diagnostic ignored "-Wconversion") - return {{args...}}; -} - -template -using vargs = - detail::format_arg_store(), - detail::make_descriptor()>; - -/** - * Returns a named argument to be used in a formatting function. - * It should only be used in a call to a formatting function. - * - * **Example**: - * - * fmt::print("The answer is {answer}.", fmt::arg("answer", 42)); - */ -template -inline auto arg(const Char* name, const T& arg) -> detail::named_arg { - return {name, arg}; -} - -/// Formats a string and writes the output to `out`. -template , - char>::value)> -auto vformat_to(OutputIt&& out, string_view fmt, format_args args) - -> remove_cvref_t { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, fmt, args, {}); - return detail::get_iterator(buf, out); -} - -/** - * Formats `args` according to specifications in `fmt`, writes the result to - * the output iterator `out` and returns the iterator past the end of the output - * range. `format_to` does not append a terminating null character. - * - * **Example**: - * - * auto out = std::vector(); - * fmt::format_to(std::back_inserter(out), "{}", 42); - */ -template , - char>::value)> -FMT_INLINE auto format_to(OutputIt&& out, format_string fmt, T&&... args) - -> remove_cvref_t { - return vformat_to(out, fmt.str, vargs{{args...}}); -} - -template struct format_to_n_result { - /// Iterator past the end of the output range. - OutputIt out; - /// Total (not truncated) output size. - size_t size; -}; - -template ::value)> -auto vformat_to_n(OutputIt out, size_t n, string_view fmt, format_args args) - -> format_to_n_result { - using traits = detail::fixed_buffer_traits; - auto buf = detail::iterator_buffer(out, n); - detail::vformat_to(buf, fmt, args, {}); - return {buf.out(), buf.count()}; -} - -/** - * Formats `args` according to specifications in `fmt`, writes up to `n` - * characters of the result to the output iterator `out` and returns the total - * (not truncated) output size and the iterator past the end of the output - * range. `format_to_n` does not append a terminating null character. - */ -template ::value)> -FMT_INLINE auto format_to_n(OutputIt out, size_t n, format_string fmt, - T&&... args) -> format_to_n_result { - return vformat_to_n(out, n, fmt.str, vargs{{args...}}); -} - -struct format_to_result { - /// Pointer to just after the last successful write in the array. - char* out; - /// Specifies if the output was truncated. - bool truncated; - - FMT_CONSTEXPR operator char*() const { - // Report truncation to prevent silent data loss. - if (truncated) report_error("output is truncated"); - return out; - } -}; - -template -auto vformat_to(char (&out)[N], string_view fmt, format_args args) - -> format_to_result { - auto result = vformat_to_n(out, N, fmt, args); - return {result.out, result.size > N}; -} - -template -FMT_INLINE auto format_to(char (&out)[N], format_string fmt, T&&... args) - -> format_to_result { - auto result = vformat_to_n(out, N, fmt.str, vargs{{args...}}); - return {result.out, result.size > N}; -} - -/// Returns the number of chars in the output of `format(fmt, args...)`. -template -FMT_NODISCARD FMT_INLINE auto formatted_size(format_string fmt, - T&&... args) -> size_t { - auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, fmt.str, vargs{{args...}}, {}); - return buf.count(); -} - -FMT_API void vprint(string_view fmt, format_args args); -FMT_API void vprint(FILE* f, string_view fmt, format_args args); -FMT_API void vprintln(FILE* f, string_view fmt, format_args args); -FMT_API void vprint_buffered(FILE* f, string_view fmt, format_args args); - -/** - * Formats `args` according to specifications in `fmt` and writes the output - * to `stdout`. - * - * **Example**: - * - * fmt::print("The answer is {}.", 42); - */ -template -FMT_INLINE void print(format_string fmt, T&&... args) { - vargs va = {{args...}}; - if (detail::const_check(!detail::use_utf8)) - return detail::vprint_mojibake(stdout, fmt.str, va, false); - return detail::is_locking() ? vprint_buffered(stdout, fmt.str, va) - : vprint(fmt.str, va); -} - -/** - * Formats `args` according to specifications in `fmt` and writes the - * output to the file `f`. - * - * **Example**: - * - * fmt::print(stderr, "Don't {}!", "panic"); - */ -template -FMT_INLINE void print(FILE* f, format_string fmt, T&&... args) { - vargs va = {{args...}}; - if (detail::const_check(!detail::use_utf8)) - return detail::vprint_mojibake(f, fmt.str, va, false); - return detail::is_locking() ? vprint_buffered(f, fmt.str, va) - : vprint(f, fmt.str, va); -} - -/// Formats `args` according to specifications in `fmt` and writes the output -/// to the file `f` followed by a newline. -template -FMT_INLINE void println(FILE* f, format_string fmt, T&&... args) { - vargs va = {{args...}}; - return detail::const_check(detail::use_utf8) - ? vprintln(f, fmt.str, va) - : detail::vprint_mojibake(f, fmt.str, va, true); -} - -/// Formats `args` according to specifications in `fmt` and writes the output -/// to `stdout` followed by a newline. -template -FMT_INLINE void println(format_string fmt, T&&... args) { - return fmt::println(stdout, fmt, static_cast(args)...); -} - -FMT_PRAGMA_CLANG(diagnostic pop) -FMT_PRAGMA_GCC(pop_options) -FMT_END_EXPORT -FMT_END_NAMESPACE - -#ifdef FMT_HEADER_ONLY -# include "format.h" -#endif -#endif // FMT_BASE_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/chrono.h b/examples/blueprints-example/external/spdlog/fmt/bundled/chrono.h deleted file mode 100644 index a788d3e..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/chrono.h +++ /dev/null @@ -1,2241 +0,0 @@ -// Formatting library for C++ - chrono support -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_CHRONO_H_ -#define FMT_CHRONO_H_ - -#ifndef FMT_MODULE -# include -# include -# include // std::isfinite -# include // std::memcpy -# include -# include -# include -# include -# include -#endif - -#include "format.h" - -FMT_BEGIN_NAMESPACE - -// Enable safe chrono durations, unless explicitly disabled. -#ifndef FMT_SAFE_DURATION_CAST -# define FMT_SAFE_DURATION_CAST 1 -#endif -#if FMT_SAFE_DURATION_CAST - -// For conversion between std::chrono::durations without undefined -// behaviour or erroneous results. -// This is a stripped down version of duration_cast, for inclusion in fmt. -// See https://github.com/pauldreik/safe_duration_cast -// -// Copyright Paul Dreik 2019 -namespace safe_duration_cast { - -// DEPRECATED! -template ::value && - std::numeric_limits::is_signed == - std::numeric_limits::is_signed)> -FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec) - -> To { - ec = 0; - using F = std::numeric_limits; - using T = std::numeric_limits; - static_assert(F::is_integer, "From must be integral"); - static_assert(T::is_integer, "To must be integral"); - - // A and B are both signed, or both unsigned. - if (detail::const_check(F::digits <= T::digits)) { - // From fits in To without any problem. - } else { - // From does not always fit in To, resort to a dynamic check. - if (from < (T::min)() || from > (T::max)()) { - // outside range. - ec = 1; - return {}; - } - } - return static_cast(from); -} - -/// Converts From to To, without loss. If the dynamic value of from -/// can't be converted to To without loss, ec is set. -template ::value && - std::numeric_limits::is_signed != - std::numeric_limits::is_signed)> -FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec) - -> To { - ec = 0; - using F = std::numeric_limits; - using T = std::numeric_limits; - static_assert(F::is_integer, "From must be integral"); - static_assert(T::is_integer, "To must be integral"); - - if (detail::const_check(F::is_signed && !T::is_signed)) { - // From may be negative, not allowed! - if (fmt::detail::is_negative(from)) { - ec = 1; - return {}; - } - // From is positive. Can it always fit in To? - if (detail::const_check(F::digits > T::digits) && - from > static_cast(detail::max_value())) { - ec = 1; - return {}; - } - } - - if (detail::const_check(!F::is_signed && T::is_signed && - F::digits >= T::digits) && - from > static_cast(detail::max_value())) { - ec = 1; - return {}; - } - return static_cast(from); // Lossless conversion. -} - -template ::value)> -FMT_CONSTEXPR auto lossless_integral_conversion(const From from, int& ec) - -> To { - ec = 0; - return from; -} // function - -// clang-format off -/** - * converts From to To if possible, otherwise ec is set. - * - * input | output - * ---------------------------------|--------------- - * NaN | NaN - * Inf | Inf - * normal, fits in output | converted (possibly lossy) - * normal, does not fit in output | ec is set - * subnormal | best effort - * -Inf | -Inf - */ -// clang-format on -template ::value)> -FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To { - ec = 0; - using T = std::numeric_limits; - static_assert(std::is_floating_point::value, "From must be floating"); - static_assert(std::is_floating_point::value, "To must be floating"); - - // catch the only happy case - if (std::isfinite(from)) { - if (from >= T::lowest() && from <= (T::max)()) { - return static_cast(from); - } - // not within range. - ec = 1; - return {}; - } - - // nan and inf will be preserved - return static_cast(from); -} // function - -template ::value)> -FMT_CONSTEXPR auto safe_float_conversion(const From from, int& ec) -> To { - ec = 0; - static_assert(std::is_floating_point::value, "From must be floating"); - return from; -} - -/// Safe duration_cast between floating point durations -template ::value), - FMT_ENABLE_IF(std::is_floating_point::value)> -auto safe_duration_cast(std::chrono::duration from, - int& ec) -> To { - using From = std::chrono::duration; - ec = 0; - - // the basic idea is that we need to convert from count() in the from type - // to count() in the To type, by multiplying it with this: - struct Factor - : std::ratio_divide {}; - - static_assert(Factor::num > 0, "num must be positive"); - static_assert(Factor::den > 0, "den must be positive"); - - // the conversion is like this: multiply from.count() with Factor::num - // /Factor::den and convert it to To::rep, all this without - // overflow/underflow. let's start by finding a suitable type that can hold - // both To, From and Factor::num - using IntermediateRep = - typename std::common_type::type; - - // force conversion of From::rep -> IntermediateRep to be safe, - // even if it will never happen be narrowing in this context. - IntermediateRep count = - safe_float_conversion(from.count(), ec); - if (ec) { - return {}; - } - - // multiply with Factor::num without overflow or underflow - if (detail::const_check(Factor::num != 1)) { - constexpr auto max1 = detail::max_value() / - static_cast(Factor::num); - if (count > max1) { - ec = 1; - return {}; - } - constexpr auto min1 = std::numeric_limits::lowest() / - static_cast(Factor::num); - if (count < min1) { - ec = 1; - return {}; - } - count *= static_cast(Factor::num); - } - - // this can't go wrong, right? den>0 is checked earlier. - if (detail::const_check(Factor::den != 1)) { - using common_t = typename std::common_type::type; - count /= static_cast(Factor::den); - } - - // convert to the to type, safely - using ToRep = typename To::rep; - - const ToRep tocount = safe_float_conversion(count, ec); - if (ec) { - return {}; - } - return To{tocount}; -} -} // namespace safe_duration_cast -#endif - -namespace detail { - -// Check if std::chrono::utc_time is available. -#ifdef FMT_USE_UTC_TIME -// Use the provided definition. -#elif defined(__cpp_lib_chrono) -# define FMT_USE_UTC_TIME (__cpp_lib_chrono >= 201907L) -#else -# define FMT_USE_UTC_TIME 0 -#endif -#if FMT_USE_UTC_TIME -using utc_clock = std::chrono::utc_clock; -#else -struct utc_clock { - template void to_sys(T); -}; -#endif - -// Check if std::chrono::local_time is available. -#ifdef FMT_USE_LOCAL_TIME -// Use the provided definition. -#elif defined(__cpp_lib_chrono) -# define FMT_USE_LOCAL_TIME (__cpp_lib_chrono >= 201907L) -#else -# define FMT_USE_LOCAL_TIME 0 -#endif -#if FMT_USE_LOCAL_TIME -using local_t = std::chrono::local_t; -#else -struct local_t {}; -#endif - -} // namespace detail - -template -using sys_time = std::chrono::time_point; - -template -using utc_time = std::chrono::time_point; - -template -using local_time = std::chrono::time_point; - -namespace detail { - -// Prevents expansion of a preceding token as a function-style macro. -// Usage: f FMT_NOMACRO() -#define FMT_NOMACRO - -template struct null {}; -inline auto gmtime_r(...) -> null<> { return null<>(); } -inline auto gmtime_s(...) -> null<> { return null<>(); } - -// It is defined here and not in ostream.h because the latter has expensive -// includes. -template class formatbuf : public StreamBuf { - private: - using char_type = typename StreamBuf::char_type; - using streamsize = decltype(std::declval().sputn(nullptr, 0)); - using int_type = typename StreamBuf::int_type; - using traits_type = typename StreamBuf::traits_type; - - buffer& buffer_; - - public: - explicit formatbuf(buffer& buf) : buffer_(buf) {} - - protected: - // The put area is always empty. This makes the implementation simpler and has - // the advantage that the streambuf and the buffer are always in sync and - // sputc never writes into uninitialized memory. A disadvantage is that each - // call to sputc always results in a (virtual) call to overflow. There is no - // disadvantage here for sputn since this always results in a call to xsputn. - - auto overflow(int_type ch) -> int_type override { - if (!traits_type::eq_int_type(ch, traits_type::eof())) - buffer_.push_back(static_cast(ch)); - return ch; - } - - auto xsputn(const char_type* s, streamsize count) -> streamsize override { - buffer_.append(s, s + count); - return count; - } -}; - -inline auto get_classic_locale() -> const std::locale& { - static const auto& locale = std::locale::classic(); - return locale; -} - -template struct codecvt_result { - static constexpr size_t max_size = 32; - CodeUnit buf[max_size]; - CodeUnit* end; -}; - -template -void write_codecvt(codecvt_result& out, string_view in, - const std::locale& loc) { - FMT_PRAGMA_CLANG(diagnostic push) - FMT_PRAGMA_CLANG(diagnostic ignored "-Wdeprecated") - auto& f = std::use_facet>(loc); - FMT_PRAGMA_CLANG(diagnostic pop) - auto mb = std::mbstate_t(); - const char* from_next = nullptr; - auto result = f.in(mb, in.begin(), in.end(), from_next, std::begin(out.buf), - std::end(out.buf), out.end); - if (result != std::codecvt_base::ok) - FMT_THROW(format_error("failed to format time")); -} - -template -auto write_encoded_tm_str(OutputIt out, string_view in, const std::locale& loc) - -> OutputIt { - if (const_check(detail::use_utf8) && loc != get_classic_locale()) { - // char16_t and char32_t codecvts are broken in MSVC (linkage errors) and - // gcc-4. -#if FMT_MSC_VERSION != 0 || \ - (defined(__GLIBCXX__) && \ - (!defined(_GLIBCXX_USE_DUAL_ABI) || _GLIBCXX_USE_DUAL_ABI == 0)) - // The _GLIBCXX_USE_DUAL_ABI macro is always defined in libstdc++ from gcc-5 - // and newer. - using code_unit = wchar_t; -#else - using code_unit = char32_t; -#endif - - using unit_t = codecvt_result; - unit_t unit; - write_codecvt(unit, in, loc); - // In UTF-8 is used one to four one-byte code units. - auto u = - to_utf8>(); - if (!u.convert({unit.buf, to_unsigned(unit.end - unit.buf)})) - FMT_THROW(format_error("failed to format time")); - return copy(u.c_str(), u.c_str() + u.size(), out); - } - return copy(in.data(), in.data() + in.size(), out); -} - -template ::value)> -auto write_tm_str(OutputIt out, string_view sv, const std::locale& loc) - -> OutputIt { - codecvt_result unit; - write_codecvt(unit, sv, loc); - return copy(unit.buf, unit.end, out); -} - -template ::value)> -auto write_tm_str(OutputIt out, string_view sv, const std::locale& loc) - -> OutputIt { - return write_encoded_tm_str(out, sv, loc); -} - -template -inline void do_write(buffer& buf, const std::tm& time, - const std::locale& loc, char format, char modifier) { - auto&& format_buf = formatbuf>(buf); - auto&& os = std::basic_ostream(&format_buf); - os.imbue(loc); - const auto& facet = std::use_facet>(loc); - auto end = facet.put(os, os, Char(' '), &time, format, modifier); - if (end.failed()) FMT_THROW(format_error("failed to format time")); -} - -template ::value)> -auto write(OutputIt out, const std::tm& time, const std::locale& loc, - char format, char modifier = 0) -> OutputIt { - auto&& buf = get_buffer(out); - do_write(buf, time, loc, format, modifier); - return get_iterator(buf, out); -} - -template ::value)> -auto write(OutputIt out, const std::tm& time, const std::locale& loc, - char format, char modifier = 0) -> OutputIt { - auto&& buf = basic_memory_buffer(); - do_write(buf, time, loc, format, modifier); - return write_encoded_tm_str(out, string_view(buf.data(), buf.size()), loc); -} - -template -using is_similar_arithmetic_type = - bool_constant<(std::is_integral::value && std::is_integral::value) || - (std::is_floating_point::value && - std::is_floating_point::value)>; - -FMT_NORETURN inline void throw_duration_error() { - FMT_THROW(format_error("cannot format duration")); -} - -// Cast one integral duration to another with an overflow check. -template ::value&& - std::is_integral::value)> -auto duration_cast(std::chrono::duration from) -> To { -#if !FMT_SAFE_DURATION_CAST - return std::chrono::duration_cast(from); -#else - // The conversion factor: to.count() == factor * from.count(). - using factor = std::ratio_divide; - - using common_rep = typename std::common_type::type; - common_rep count = from.count(); // This conversion is lossless. - - // Multiply from.count() by factor and check for overflow. - if (const_check(factor::num != 1)) { - if (count > max_value() / factor::num) throw_duration_error(); - const auto min = (std::numeric_limits::min)() / factor::num; - if (const_check(!std::is_unsigned::value) && count < min) - throw_duration_error(); - count *= factor::num; - } - if (const_check(factor::den != 1)) count /= factor::den; - int ec = 0; - auto to = - To(safe_duration_cast::lossless_integral_conversion( - count, ec)); - if (ec) throw_duration_error(); - return to; -#endif -} - -template ::value&& - std::is_floating_point::value)> -auto duration_cast(std::chrono::duration from) -> To { -#if FMT_SAFE_DURATION_CAST - // Preserve infinity and NaN. - if (!isfinite(from.count())) return static_cast(from.count()); - // Throwing version of safe_duration_cast is only available for - // integer to integer or float to float casts. - int ec; - To to = safe_duration_cast::safe_duration_cast(from, ec); - if (ec) throw_duration_error(); - return to; -#else - // Standard duration cast, may overflow. - return std::chrono::duration_cast(from); -#endif -} - -template ::value)> -auto duration_cast(std::chrono::duration from) -> To { - // Mixed integer <-> float cast is not supported by safe duration_cast. - return std::chrono::duration_cast(from); -} - -template -auto to_time_t(sys_time time_point) -> std::time_t { - // Cannot use std::chrono::system_clock::to_time_t since this would first - // require a cast to std::chrono::system_clock::time_point, which could - // overflow. - return detail::duration_cast>( - time_point.time_since_epoch()) - .count(); -} - -} // namespace detail - -FMT_BEGIN_EXPORT - -/** - * Converts given time since epoch as `std::time_t` value into calendar time, - * expressed in Coordinated Universal Time (UTC). Unlike `std::gmtime`, this - * function is thread-safe on most platforms. - */ -inline auto gmtime(std::time_t time) -> std::tm { - struct dispatcher { - std::time_t time_; - std::tm tm_; - - inline dispatcher(std::time_t t) : time_(t) {} - - inline auto run() -> bool { - using namespace fmt::detail; - return handle(gmtime_r(&time_, &tm_)); - } - - inline auto handle(std::tm* tm) -> bool { return tm != nullptr; } - - inline auto handle(detail::null<>) -> bool { - using namespace fmt::detail; - return fallback(gmtime_s(&tm_, &time_)); - } - - inline auto fallback(int res) -> bool { return res == 0; } - -#if !FMT_MSC_VERSION - inline auto fallback(detail::null<>) -> bool { - std::tm* tm = std::gmtime(&time_); - if (tm) tm_ = *tm; - return tm != nullptr; - } -#endif - }; - auto gt = dispatcher(time); - // Too big time values may be unsupported. - if (!gt.run()) FMT_THROW(format_error("time_t value out of range")); - return gt.tm_; -} - -template -inline auto gmtime(sys_time time_point) -> std::tm { - return gmtime(detail::to_time_t(time_point)); -} - -namespace detail { - -// Writes two-digit numbers a, b and c separated by sep to buf. -// The method by Pavel Novikov based on -// https://johnnylee-sde.github.io/Fast-unsigned-integer-to-time-string/. -inline void write_digit2_separated(char* buf, unsigned a, unsigned b, - unsigned c, char sep) { - unsigned long long digits = - a | (b << 24) | (static_cast(c) << 48); - // Convert each value to BCD. - // We have x = a * 10 + b and we want to convert it to BCD y = a * 16 + b. - // The difference is - // y - x = a * 6 - // a can be found from x: - // a = floor(x / 10) - // then - // y = x + a * 6 = x + floor(x / 10) * 6 - // floor(x / 10) is (x * 205) >> 11 (needs 16 bits). - digits += (((digits * 205) >> 11) & 0x000f00000f00000f) * 6; - // Put low nibbles to high bytes and high nibbles to low bytes. - digits = ((digits & 0x00f00000f00000f0) >> 4) | - ((digits & 0x000f00000f00000f) << 8); - auto usep = static_cast(sep); - // Add ASCII '0' to each digit byte and insert separators. - digits |= 0x3030003030003030 | (usep << 16) | (usep << 40); - - constexpr size_t len = 8; - if (const_check(is_big_endian())) { - char tmp[len]; - std::memcpy(tmp, &digits, len); - std::reverse_copy(tmp, tmp + len, buf); - } else { - std::memcpy(buf, &digits, len); - } -} - -template -FMT_CONSTEXPR inline auto get_units() -> const char* { - if (std::is_same::value) return "as"; - if (std::is_same::value) return "fs"; - if (std::is_same::value) return "ps"; - if (std::is_same::value) return "ns"; - if (std::is_same::value) - return detail::use_utf8 ? "µs" : "us"; - if (std::is_same::value) return "ms"; - if (std::is_same::value) return "cs"; - if (std::is_same::value) return "ds"; - if (std::is_same>::value) return "s"; - if (std::is_same::value) return "das"; - if (std::is_same::value) return "hs"; - if (std::is_same::value) return "ks"; - if (std::is_same::value) return "Ms"; - if (std::is_same::value) return "Gs"; - if (std::is_same::value) return "Ts"; - if (std::is_same::value) return "Ps"; - if (std::is_same::value) return "Es"; - if (std::is_same>::value) return "min"; - if (std::is_same>::value) return "h"; - if (std::is_same>::value) return "d"; - return nullptr; -} - -enum class numeric_system { - standard, - // Alternative numeric system, e.g. å二 instead of 12 in ja_JP locale. - alternative -}; - -// Glibc extensions for formatting numeric values. -enum class pad_type { - // Pad a numeric result string with zeros (the default). - zero, - // Do not pad a numeric result string. - none, - // Pad a numeric result string with spaces. - space, -}; - -template -auto write_padding(OutputIt out, pad_type pad, int width) -> OutputIt { - if (pad == pad_type::none) return out; - return detail::fill_n(out, width, pad == pad_type::space ? ' ' : '0'); -} - -template -auto write_padding(OutputIt out, pad_type pad) -> OutputIt { - if (pad != pad_type::none) *out++ = pad == pad_type::space ? ' ' : '0'; - return out; -} - -// Parses a put_time-like format string and invokes handler actions. -template -FMT_CONSTEXPR auto parse_chrono_format(const Char* begin, const Char* end, - Handler&& handler) -> const Char* { - if (begin == end || *begin == '}') return begin; - if (*begin != '%') FMT_THROW(format_error("invalid format")); - auto ptr = begin; - while (ptr != end) { - pad_type pad = pad_type::zero; - auto c = *ptr; - if (c == '}') break; - if (c != '%') { - ++ptr; - continue; - } - if (begin != ptr) handler.on_text(begin, ptr); - ++ptr; // consume '%' - if (ptr == end) FMT_THROW(format_error("invalid format")); - c = *ptr; - switch (c) { - case '_': - pad = pad_type::space; - ++ptr; - break; - case '-': - pad = pad_type::none; - ++ptr; - break; - } - if (ptr == end) FMT_THROW(format_error("invalid format")); - c = *ptr++; - switch (c) { - case '%': handler.on_text(ptr - 1, ptr); break; - case 'n': { - const Char newline[] = {'\n'}; - handler.on_text(newline, newline + 1); - break; - } - case 't': { - const Char tab[] = {'\t'}; - handler.on_text(tab, tab + 1); - break; - } - // Year: - case 'Y': handler.on_year(numeric_system::standard, pad); break; - case 'y': handler.on_short_year(numeric_system::standard); break; - case 'C': handler.on_century(numeric_system::standard); break; - case 'G': handler.on_iso_week_based_year(); break; - case 'g': handler.on_iso_week_based_short_year(); break; - // Day of the week: - case 'a': handler.on_abbr_weekday(); break; - case 'A': handler.on_full_weekday(); break; - case 'w': handler.on_dec0_weekday(numeric_system::standard); break; - case 'u': handler.on_dec1_weekday(numeric_system::standard); break; - // Month: - case 'b': - case 'h': handler.on_abbr_month(); break; - case 'B': handler.on_full_month(); break; - case 'm': handler.on_dec_month(numeric_system::standard, pad); break; - // Day of the year/month: - case 'U': - handler.on_dec0_week_of_year(numeric_system::standard, pad); - break; - case 'W': - handler.on_dec1_week_of_year(numeric_system::standard, pad); - break; - case 'V': handler.on_iso_week_of_year(numeric_system::standard, pad); break; - case 'j': handler.on_day_of_year(pad); break; - case 'd': handler.on_day_of_month(numeric_system::standard, pad); break; - case 'e': - handler.on_day_of_month(numeric_system::standard, pad_type::space); - break; - // Hour, minute, second: - case 'H': handler.on_24_hour(numeric_system::standard, pad); break; - case 'I': handler.on_12_hour(numeric_system::standard, pad); break; - case 'M': handler.on_minute(numeric_system::standard, pad); break; - case 'S': handler.on_second(numeric_system::standard, pad); break; - // Other: - case 'c': handler.on_datetime(numeric_system::standard); break; - case 'x': handler.on_loc_date(numeric_system::standard); break; - case 'X': handler.on_loc_time(numeric_system::standard); break; - case 'D': handler.on_us_date(); break; - case 'F': handler.on_iso_date(); break; - case 'r': handler.on_12_hour_time(); break; - case 'R': handler.on_24_hour_time(); break; - case 'T': handler.on_iso_time(); break; - case 'p': handler.on_am_pm(); break; - case 'Q': handler.on_duration_value(); break; - case 'q': handler.on_duration_unit(); break; - case 'z': handler.on_utc_offset(numeric_system::standard); break; - case 'Z': handler.on_tz_name(); break; - // Alternative representation: - case 'E': { - if (ptr == end) FMT_THROW(format_error("invalid format")); - c = *ptr++; - switch (c) { - case 'Y': handler.on_year(numeric_system::alternative, pad); break; - case 'y': handler.on_offset_year(); break; - case 'C': handler.on_century(numeric_system::alternative); break; - case 'c': handler.on_datetime(numeric_system::alternative); break; - case 'x': handler.on_loc_date(numeric_system::alternative); break; - case 'X': handler.on_loc_time(numeric_system::alternative); break; - case 'z': handler.on_utc_offset(numeric_system::alternative); break; - default: FMT_THROW(format_error("invalid format")); - } - break; - } - case 'O': - if (ptr == end) FMT_THROW(format_error("invalid format")); - c = *ptr++; - switch (c) { - case 'y': handler.on_short_year(numeric_system::alternative); break; - case 'm': handler.on_dec_month(numeric_system::alternative, pad); break; - case 'U': - handler.on_dec0_week_of_year(numeric_system::alternative, pad); - break; - case 'W': - handler.on_dec1_week_of_year(numeric_system::alternative, pad); - break; - case 'V': - handler.on_iso_week_of_year(numeric_system::alternative, pad); - break; - case 'd': - handler.on_day_of_month(numeric_system::alternative, pad); - break; - case 'e': - handler.on_day_of_month(numeric_system::alternative, pad_type::space); - break; - case 'w': handler.on_dec0_weekday(numeric_system::alternative); break; - case 'u': handler.on_dec1_weekday(numeric_system::alternative); break; - case 'H': handler.on_24_hour(numeric_system::alternative, pad); break; - case 'I': handler.on_12_hour(numeric_system::alternative, pad); break; - case 'M': handler.on_minute(numeric_system::alternative, pad); break; - case 'S': handler.on_second(numeric_system::alternative, pad); break; - case 'z': handler.on_utc_offset(numeric_system::alternative); break; - default: FMT_THROW(format_error("invalid format")); - } - break; - default: FMT_THROW(format_error("invalid format")); - } - begin = ptr; - } - if (begin != ptr) handler.on_text(begin, ptr); - return ptr; -} - -template struct null_chrono_spec_handler { - FMT_CONSTEXPR void unsupported() { - static_cast(this)->unsupported(); - } - FMT_CONSTEXPR void on_year(numeric_system, pad_type) { unsupported(); } - FMT_CONSTEXPR void on_short_year(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_offset_year() { unsupported(); } - FMT_CONSTEXPR void on_century(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_iso_week_based_year() { unsupported(); } - FMT_CONSTEXPR void on_iso_week_based_short_year() { unsupported(); } - FMT_CONSTEXPR void on_abbr_weekday() { unsupported(); } - FMT_CONSTEXPR void on_full_weekday() { unsupported(); } - FMT_CONSTEXPR void on_dec0_weekday(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_dec1_weekday(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_abbr_month() { unsupported(); } - FMT_CONSTEXPR void on_full_month() { unsupported(); } - FMT_CONSTEXPR void on_dec_month(numeric_system, pad_type) { unsupported(); } - FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system, pad_type) { - unsupported(); - } - FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system, pad_type) { - unsupported(); - } - FMT_CONSTEXPR void on_iso_week_of_year(numeric_system, pad_type) { - unsupported(); - } - FMT_CONSTEXPR void on_day_of_year(pad_type) { unsupported(); } - FMT_CONSTEXPR void on_day_of_month(numeric_system, pad_type) { - unsupported(); - } - FMT_CONSTEXPR void on_24_hour(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_12_hour(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_minute(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_second(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_datetime(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_loc_date(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_loc_time(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_us_date() { unsupported(); } - FMT_CONSTEXPR void on_iso_date() { unsupported(); } - FMT_CONSTEXPR void on_12_hour_time() { unsupported(); } - FMT_CONSTEXPR void on_24_hour_time() { unsupported(); } - FMT_CONSTEXPR void on_iso_time() { unsupported(); } - FMT_CONSTEXPR void on_am_pm() { unsupported(); } - FMT_CONSTEXPR void on_duration_value() { unsupported(); } - FMT_CONSTEXPR void on_duration_unit() { unsupported(); } - FMT_CONSTEXPR void on_utc_offset(numeric_system) { unsupported(); } - FMT_CONSTEXPR void on_tz_name() { unsupported(); } -}; - -class tm_format_checker : public null_chrono_spec_handler { - private: - bool has_timezone_ = false; - - public: - constexpr explicit tm_format_checker(bool has_timezone) - : has_timezone_(has_timezone) {} - - FMT_NORETURN inline void unsupported() { - FMT_THROW(format_error("no format")); - } - - template - FMT_CONSTEXPR void on_text(const Char*, const Char*) {} - FMT_CONSTEXPR void on_year(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_short_year(numeric_system) {} - FMT_CONSTEXPR void on_offset_year() {} - FMT_CONSTEXPR void on_century(numeric_system) {} - FMT_CONSTEXPR void on_iso_week_based_year() {} - FMT_CONSTEXPR void on_iso_week_based_short_year() {} - FMT_CONSTEXPR void on_abbr_weekday() {} - FMT_CONSTEXPR void on_full_weekday() {} - FMT_CONSTEXPR void on_dec0_weekday(numeric_system) {} - FMT_CONSTEXPR void on_dec1_weekday(numeric_system) {} - FMT_CONSTEXPR void on_abbr_month() {} - FMT_CONSTEXPR void on_full_month() {} - FMT_CONSTEXPR void on_dec_month(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_dec0_week_of_year(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_dec1_week_of_year(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_iso_week_of_year(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_day_of_year(pad_type) {} - FMT_CONSTEXPR void on_day_of_month(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_24_hour(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_12_hour(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_minute(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_second(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_datetime(numeric_system) {} - FMT_CONSTEXPR void on_loc_date(numeric_system) {} - FMT_CONSTEXPR void on_loc_time(numeric_system) {} - FMT_CONSTEXPR void on_us_date() {} - FMT_CONSTEXPR void on_iso_date() {} - FMT_CONSTEXPR void on_12_hour_time() {} - FMT_CONSTEXPR void on_24_hour_time() {} - FMT_CONSTEXPR void on_iso_time() {} - FMT_CONSTEXPR void on_am_pm() {} - FMT_CONSTEXPR void on_utc_offset(numeric_system) { - if (!has_timezone_) FMT_THROW(format_error("no timezone")); - } - FMT_CONSTEXPR void on_tz_name() { - if (!has_timezone_) FMT_THROW(format_error("no timezone")); - } -}; - -inline auto tm_wday_full_name(int wday) -> const char* { - static constexpr const char* full_name_list[] = { - "Sunday", "Monday", "Tuesday", "Wednesday", - "Thursday", "Friday", "Saturday"}; - return wday >= 0 && wday <= 6 ? full_name_list[wday] : "?"; -} -inline auto tm_wday_short_name(int wday) -> const char* { - static constexpr const char* short_name_list[] = {"Sun", "Mon", "Tue", "Wed", - "Thu", "Fri", "Sat"}; - return wday >= 0 && wday <= 6 ? short_name_list[wday] : "???"; -} - -inline auto tm_mon_full_name(int mon) -> const char* { - static constexpr const char* full_name_list[] = { - "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December"}; - return mon >= 0 && mon <= 11 ? full_name_list[mon] : "?"; -} -inline auto tm_mon_short_name(int mon) -> const char* { - static constexpr const char* short_name_list[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", - }; - return mon >= 0 && mon <= 11 ? short_name_list[mon] : "???"; -} - -template -struct has_tm_gmtoff : std::false_type {}; -template -struct has_tm_gmtoff> : std::true_type {}; - -template struct has_tm_zone : std::false_type {}; -template -struct has_tm_zone> : std::true_type {}; - -template ::value)> -auto set_tm_zone(T& time, char* tz) -> bool { - time.tm_zone = tz; - return true; -} -template ::value)> -auto set_tm_zone(T&, char*) -> bool { - return false; -} - -inline auto utc() -> char* { - static char tz[] = "UTC"; - return tz; -} - -// Converts value to Int and checks that it's in the range [0, upper). -template ::value)> -inline auto to_nonnegative_int(T value, Int upper) -> Int { - if (!std::is_unsigned::value && - (value < 0 || to_unsigned(value) > to_unsigned(upper))) { - FMT_THROW(format_error("chrono value is out of range")); - } - return static_cast(value); -} -template ::value)> -inline auto to_nonnegative_int(T value, Int upper) -> Int { - auto int_value = static_cast(value); - if (int_value < 0 || value > static_cast(upper)) - FMT_THROW(format_error("invalid value")); - return int_value; -} - -constexpr auto pow10(std::uint32_t n) -> long long { - return n == 0 ? 1 : 10 * pow10(n - 1); -} - -// Counts the number of fractional digits in the range [0, 18] according to the -// C++20 spec. If more than 18 fractional digits are required then returns 6 for -// microseconds precision. -template () / 10)> -struct count_fractional_digits { - static constexpr int value = - Num % Den == 0 ? N : count_fractional_digits::value; -}; - -// Base case that doesn't instantiate any more templates -// in order to avoid overflow. -template -struct count_fractional_digits { - static constexpr int value = (Num % Den == 0) ? N : 6; -}; - -// Format subseconds which are given as an integer type with an appropriate -// number of digits. -template -void write_fractional_seconds(OutputIt& out, Duration d, int precision = -1) { - constexpr auto num_fractional_digits = - count_fractional_digits::value; - - using subsecond_precision = std::chrono::duration< - typename std::common_type::type, - std::ratio<1, pow10(num_fractional_digits)>>; - - const auto fractional = d - detail::duration_cast(d); - const auto subseconds = - std::chrono::treat_as_floating_point< - typename subsecond_precision::rep>::value - ? fractional.count() - : detail::duration_cast(fractional).count(); - auto n = static_cast>(subseconds); - const int num_digits = count_digits(n); - - int leading_zeroes = (std::max)(0, num_fractional_digits - num_digits); - if (precision < 0) { - FMT_ASSERT(!std::is_floating_point::value, ""); - if (std::ratio_less::value) { - *out++ = '.'; - out = detail::fill_n(out, leading_zeroes, '0'); - out = format_decimal(out, n, num_digits); - } - } else if (precision > 0) { - *out++ = '.'; - leading_zeroes = min_of(leading_zeroes, precision); - int remaining = precision - leading_zeroes; - out = detail::fill_n(out, leading_zeroes, '0'); - if (remaining < num_digits) { - int num_truncated_digits = num_digits - remaining; - n /= to_unsigned(pow10(to_unsigned(num_truncated_digits))); - if (n != 0) out = format_decimal(out, n, remaining); - return; - } - if (n != 0) { - out = format_decimal(out, n, num_digits); - remaining -= num_digits; - } - out = detail::fill_n(out, remaining, '0'); - } -} - -// Format subseconds which are given as a floating point type with an -// appropriate number of digits. We cannot pass the Duration here, as we -// explicitly need to pass the Rep value in the duration_formatter. -template -void write_floating_seconds(memory_buffer& buf, Duration duration, - int num_fractional_digits = -1) { - using rep = typename Duration::rep; - FMT_ASSERT(std::is_floating_point::value, ""); - - auto val = duration.count(); - - if (num_fractional_digits < 0) { - // For `std::round` with fallback to `round`: - // On some toolchains `std::round` is not available (e.g. GCC 6). - using namespace std; - num_fractional_digits = - count_fractional_digits::value; - if (num_fractional_digits < 6 && static_cast(round(val)) != val) - num_fractional_digits = 6; - } - - fmt::format_to(std::back_inserter(buf), FMT_STRING("{:.{}f}"), - std::fmod(val * static_cast(Duration::period::num) / - static_cast(Duration::period::den), - static_cast(60)), - num_fractional_digits); -} - -template -class tm_writer { - private: - static constexpr int days_per_week = 7; - - const std::locale& loc_; - bool is_classic_; - OutputIt out_; - const Duration* subsecs_; - const std::tm& tm_; - - auto tm_sec() const noexcept -> int { - FMT_ASSERT(tm_.tm_sec >= 0 && tm_.tm_sec <= 61, ""); - return tm_.tm_sec; - } - auto tm_min() const noexcept -> int { - FMT_ASSERT(tm_.tm_min >= 0 && tm_.tm_min <= 59, ""); - return tm_.tm_min; - } - auto tm_hour() const noexcept -> int { - FMT_ASSERT(tm_.tm_hour >= 0 && tm_.tm_hour <= 23, ""); - return tm_.tm_hour; - } - auto tm_mday() const noexcept -> int { - FMT_ASSERT(tm_.tm_mday >= 1 && tm_.tm_mday <= 31, ""); - return tm_.tm_mday; - } - auto tm_mon() const noexcept -> int { - FMT_ASSERT(tm_.tm_mon >= 0 && tm_.tm_mon <= 11, ""); - return tm_.tm_mon; - } - auto tm_year() const noexcept -> long long { return 1900ll + tm_.tm_year; } - auto tm_wday() const noexcept -> int { - FMT_ASSERT(tm_.tm_wday >= 0 && tm_.tm_wday <= 6, ""); - return tm_.tm_wday; - } - auto tm_yday() const noexcept -> int { - FMT_ASSERT(tm_.tm_yday >= 0 && tm_.tm_yday <= 365, ""); - return tm_.tm_yday; - } - - auto tm_hour12() const noexcept -> int { - auto h = tm_hour(); - auto z = h < 12 ? h : h - 12; - return z == 0 ? 12 : z; - } - - // POSIX and the C Standard are unclear or inconsistent about what %C and %y - // do if the year is negative or exceeds 9999. Use the convention that %C - // concatenated with %y yields the same output as %Y, and that %Y contains at - // least 4 characters, with more only if necessary. - auto split_year_lower(long long year) const noexcept -> int { - auto l = year % 100; - if (l < 0) l = -l; // l in [0, 99] - return static_cast(l); - } - - // Algorithm: https://en.wikipedia.org/wiki/ISO_week_date. - auto iso_year_weeks(long long curr_year) const noexcept -> int { - auto prev_year = curr_year - 1; - auto curr_p = - (curr_year + curr_year / 4 - curr_year / 100 + curr_year / 400) % - days_per_week; - auto prev_p = - (prev_year + prev_year / 4 - prev_year / 100 + prev_year / 400) % - days_per_week; - return 52 + ((curr_p == 4 || prev_p == 3) ? 1 : 0); - } - auto iso_week_num(int tm_yday, int tm_wday) const noexcept -> int { - return (tm_yday + 11 - (tm_wday == 0 ? days_per_week : tm_wday)) / - days_per_week; - } - auto tm_iso_week_year() const noexcept -> long long { - auto year = tm_year(); - auto w = iso_week_num(tm_yday(), tm_wday()); - if (w < 1) return year - 1; - if (w > iso_year_weeks(year)) return year + 1; - return year; - } - auto tm_iso_week_of_year() const noexcept -> int { - auto year = tm_year(); - auto w = iso_week_num(tm_yday(), tm_wday()); - if (w < 1) return iso_year_weeks(year - 1); - if (w > iso_year_weeks(year)) return 1; - return w; - } - - void write1(int value) { - *out_++ = static_cast('0' + to_unsigned(value) % 10); - } - void write2(int value) { - const char* d = digits2(to_unsigned(value) % 100); - *out_++ = *d++; - *out_++ = *d; - } - void write2(int value, pad_type pad) { - unsigned int v = to_unsigned(value) % 100; - if (v >= 10) { - const char* d = digits2(v); - *out_++ = *d++; - *out_++ = *d; - } else { - out_ = detail::write_padding(out_, pad); - *out_++ = static_cast('0' + v); - } - } - - void write_year_extended(long long year, pad_type pad) { - // At least 4 characters. - int width = 4; - bool negative = year < 0; - if (negative) { - year = 0 - year; - --width; - } - uint32_or_64_or_128_t n = to_unsigned(year); - const int num_digits = count_digits(n); - if (negative && pad == pad_type::zero) *out_++ = '-'; - if (width > num_digits) - out_ = detail::write_padding(out_, pad, width - num_digits); - if (negative && pad != pad_type::zero) *out_++ = '-'; - out_ = format_decimal(out_, n, num_digits); - } - void write_year(long long year, pad_type pad) { - write_year_extended(year, pad); - } - - void write_utc_offset(long long offset, numeric_system ns) { - if (offset < 0) { - *out_++ = '-'; - offset = -offset; - } else { - *out_++ = '+'; - } - offset /= 60; - write2(static_cast(offset / 60)); - if (ns != numeric_system::standard) *out_++ = ':'; - write2(static_cast(offset % 60)); - } - - template ::value)> - void format_utc_offset(const T& tm, numeric_system ns) { - write_utc_offset(tm.tm_gmtoff, ns); - } - template ::value)> - void format_utc_offset(const T&, numeric_system ns) { - write_utc_offset(0, ns); - } - - template ::value)> - void format_tz_name(const T& tm) { - out_ = write_tm_str(out_, tm.tm_zone, loc_); - } - template ::value)> - void format_tz_name(const T&) { - out_ = std::copy_n(utc(), 3, out_); - } - - void format_localized(char format, char modifier = 0) { - out_ = write(out_, tm_, loc_, format, modifier); - } - - public: - tm_writer(const std::locale& loc, OutputIt out, const std::tm& tm, - const Duration* subsecs = nullptr) - : loc_(loc), - is_classic_(loc_ == get_classic_locale()), - out_(out), - subsecs_(subsecs), - tm_(tm) {} - - auto out() const -> OutputIt { return out_; } - - FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) { - out_ = copy(begin, end, out_); - } - - void on_abbr_weekday() { - if (is_classic_) - out_ = write(out_, tm_wday_short_name(tm_wday())); - else - format_localized('a'); - } - void on_full_weekday() { - if (is_classic_) - out_ = write(out_, tm_wday_full_name(tm_wday())); - else - format_localized('A'); - } - void on_dec0_weekday(numeric_system ns) { - if (is_classic_ || ns == numeric_system::standard) return write1(tm_wday()); - format_localized('w', 'O'); - } - void on_dec1_weekday(numeric_system ns) { - if (is_classic_ || ns == numeric_system::standard) { - auto wday = tm_wday(); - write1(wday == 0 ? days_per_week : wday); - } else { - format_localized('u', 'O'); - } - } - - void on_abbr_month() { - if (is_classic_) - out_ = write(out_, tm_mon_short_name(tm_mon())); - else - format_localized('b'); - } - void on_full_month() { - if (is_classic_) - out_ = write(out_, tm_mon_full_name(tm_mon())); - else - format_localized('B'); - } - - void on_datetime(numeric_system ns) { - if (is_classic_) { - on_abbr_weekday(); - *out_++ = ' '; - on_abbr_month(); - *out_++ = ' '; - on_day_of_month(numeric_system::standard, pad_type::space); - *out_++ = ' '; - on_iso_time(); - *out_++ = ' '; - on_year(numeric_system::standard, pad_type::space); - } else { - format_localized('c', ns == numeric_system::standard ? '\0' : 'E'); - } - } - void on_loc_date(numeric_system ns) { - if (is_classic_) - on_us_date(); - else - format_localized('x', ns == numeric_system::standard ? '\0' : 'E'); - } - void on_loc_time(numeric_system ns) { - if (is_classic_) - on_iso_time(); - else - format_localized('X', ns == numeric_system::standard ? '\0' : 'E'); - } - void on_us_date() { - char buf[8]; - write_digit2_separated(buf, to_unsigned(tm_mon() + 1), - to_unsigned(tm_mday()), - to_unsigned(split_year_lower(tm_year())), '/'); - out_ = copy(std::begin(buf), std::end(buf), out_); - } - void on_iso_date() { - auto year = tm_year(); - char buf[10]; - size_t offset = 0; - if (year >= 0 && year < 10000) { - write2digits(buf, static_cast(year / 100)); - } else { - offset = 4; - write_year_extended(year, pad_type::zero); - year = 0; - } - write_digit2_separated(buf + 2, static_cast(year % 100), - to_unsigned(tm_mon() + 1), to_unsigned(tm_mday()), - '-'); - out_ = copy(std::begin(buf) + offset, std::end(buf), out_); - } - - void on_utc_offset(numeric_system ns) { format_utc_offset(tm_, ns); } - void on_tz_name() { format_tz_name(tm_); } - - void on_year(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write_year(tm_year(), pad); - format_localized('Y', 'E'); - } - void on_short_year(numeric_system ns) { - if (is_classic_ || ns == numeric_system::standard) - return write2(split_year_lower(tm_year())); - format_localized('y', 'O'); - } - void on_offset_year() { - if (is_classic_) return write2(split_year_lower(tm_year())); - format_localized('y', 'E'); - } - - void on_century(numeric_system ns) { - if (is_classic_ || ns == numeric_system::standard) { - auto year = tm_year(); - auto upper = year / 100; - if (year >= -99 && year < 0) { - // Zero upper on negative year. - *out_++ = '-'; - *out_++ = '0'; - } else if (upper >= 0 && upper < 100) { - write2(static_cast(upper)); - } else { - out_ = write(out_, upper); - } - } else { - format_localized('C', 'E'); - } - } - - void on_dec_month(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_mon() + 1, pad); - format_localized('m', 'O'); - } - - void on_dec0_week_of_year(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2((tm_yday() + days_per_week - tm_wday()) / days_per_week, - pad); - format_localized('U', 'O'); - } - void on_dec1_week_of_year(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) { - auto wday = tm_wday(); - write2((tm_yday() + days_per_week - - (wday == 0 ? (days_per_week - 1) : (wday - 1))) / - days_per_week, - pad); - } else { - format_localized('W', 'O'); - } - } - void on_iso_week_of_year(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_iso_week_of_year(), pad); - format_localized('V', 'O'); - } - - void on_iso_week_based_year() { - write_year(tm_iso_week_year(), pad_type::zero); - } - void on_iso_week_based_short_year() { - write2(split_year_lower(tm_iso_week_year())); - } - - void on_day_of_year(pad_type pad) { - auto yday = tm_yday() + 1; - auto digit1 = yday / 100; - if (digit1 != 0) - write1(digit1); - else - out_ = detail::write_padding(out_, pad); - write2(yday % 100, pad); - } - - void on_day_of_month(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_mday(), pad); - format_localized('d', 'O'); - } - - void on_24_hour(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_hour(), pad); - format_localized('H', 'O'); - } - void on_12_hour(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_hour12(), pad); - format_localized('I', 'O'); - } - void on_minute(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) - return write2(tm_min(), pad); - format_localized('M', 'O'); - } - - void on_second(numeric_system ns, pad_type pad) { - if (is_classic_ || ns == numeric_system::standard) { - write2(tm_sec(), pad); - if (subsecs_) { - if (std::is_floating_point::value) { - auto buf = memory_buffer(); - write_floating_seconds(buf, *subsecs_); - if (buf.size() > 1) { - // Remove the leading "0", write something like ".123". - out_ = copy(buf.begin() + 1, buf.end(), out_); - } - } else { - write_fractional_seconds(out_, *subsecs_); - } - } - } else { - // Currently no formatting of subseconds when a locale is set. - format_localized('S', 'O'); - } - } - - void on_12_hour_time() { - if (is_classic_) { - char buf[8]; - write_digit2_separated(buf, to_unsigned(tm_hour12()), - to_unsigned(tm_min()), to_unsigned(tm_sec()), ':'); - out_ = copy(std::begin(buf), std::end(buf), out_); - *out_++ = ' '; - on_am_pm(); - } else { - format_localized('r'); - } - } - void on_24_hour_time() { - write2(tm_hour()); - *out_++ = ':'; - write2(tm_min()); - } - void on_iso_time() { - on_24_hour_time(); - *out_++ = ':'; - on_second(numeric_system::standard, pad_type::zero); - } - - void on_am_pm() { - if (is_classic_) { - *out_++ = tm_hour() < 12 ? 'A' : 'P'; - *out_++ = 'M'; - } else { - format_localized('p'); - } - } - - // These apply to chrono durations but not tm. - void on_duration_value() {} - void on_duration_unit() {} -}; - -struct chrono_format_checker : null_chrono_spec_handler { - bool has_precision_integral = false; - - FMT_NORETURN inline void unsupported() { FMT_THROW(format_error("no date")); } - - template - FMT_CONSTEXPR void on_text(const Char*, const Char*) {} - FMT_CONSTEXPR void on_day_of_year(pad_type) {} - FMT_CONSTEXPR void on_24_hour(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_12_hour(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_minute(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_second(numeric_system, pad_type) {} - FMT_CONSTEXPR void on_12_hour_time() {} - FMT_CONSTEXPR void on_24_hour_time() {} - FMT_CONSTEXPR void on_iso_time() {} - FMT_CONSTEXPR void on_am_pm() {} - FMT_CONSTEXPR void on_duration_value() const { - if (has_precision_integral) - FMT_THROW(format_error("precision not allowed for this argument type")); - } - FMT_CONSTEXPR void on_duration_unit() {} -}; - -template ::value&& has_isfinite::value)> -inline auto isfinite(T) -> bool { - return true; -} - -template ::value)> -inline auto mod(T x, int y) -> T { - return x % static_cast(y); -} -template ::value)> -inline auto mod(T x, int y) -> T { - return std::fmod(x, static_cast(y)); -} - -// If T is an integral type, maps T to its unsigned counterpart, otherwise -// leaves it unchanged (unlike std::make_unsigned). -template ::value> -struct make_unsigned_or_unchanged { - using type = T; -}; - -template struct make_unsigned_or_unchanged { - using type = typename std::make_unsigned::type; -}; - -template ::value)> -inline auto get_milliseconds(std::chrono::duration d) - -> std::chrono::duration { - // This may overflow and/or the result may not fit in the target type. -#if FMT_SAFE_DURATION_CAST - using common_seconds_type = - typename std::common_type::type; - auto d_as_common = detail::duration_cast(d); - auto d_as_whole_seconds = - detail::duration_cast(d_as_common); - // This conversion should be nonproblematic. - auto diff = d_as_common - d_as_whole_seconds; - auto ms = detail::duration_cast>(diff); - return ms; -#else - auto s = detail::duration_cast(d); - return detail::duration_cast(d - s); -#endif -} - -template ::value)> -auto format_duration_value(OutputIt out, Rep val, int) -> OutputIt { - return write(out, val); -} - -template ::value)> -auto format_duration_value(OutputIt out, Rep val, int precision) -> OutputIt { - auto specs = format_specs(); - specs.precision = precision; - specs.set_type(precision >= 0 ? presentation_type::fixed - : presentation_type::general); - return write(out, val, specs); -} - -template -auto copy_unit(string_view unit, OutputIt out, Char) -> OutputIt { - return copy(unit.begin(), unit.end(), out); -} - -template -auto copy_unit(string_view unit, OutputIt out, wchar_t) -> OutputIt { - // This works when wchar_t is UTF-32 because units only contain characters - // that have the same representation in UTF-16 and UTF-32. - utf8_to_utf16 u(unit); - return copy(u.c_str(), u.c_str() + u.size(), out); -} - -template -auto format_duration_unit(OutputIt out) -> OutputIt { - if (const char* unit = get_units()) - return copy_unit(string_view(unit), out, Char()); - *out++ = '['; - out = write(out, Period::num); - if (const_check(Period::den != 1)) { - *out++ = '/'; - out = write(out, Period::den); - } - *out++ = ']'; - *out++ = 's'; - return out; -} - -class get_locale { - private: - union { - std::locale locale_; - }; - bool has_locale_ = false; - - public: - inline get_locale(bool localized, locale_ref loc) : has_locale_(localized) { - if (localized) - ::new (&locale_) std::locale(loc.template get()); - } - inline ~get_locale() { - if (has_locale_) locale_.~locale(); - } - inline operator const std::locale&() const { - return has_locale_ ? locale_ : get_classic_locale(); - } -}; - -template -struct duration_formatter { - using iterator = basic_appender; - iterator out; - // rep is unsigned to avoid overflow. - using rep = - conditional_t::value && sizeof(Rep) < sizeof(int), - unsigned, typename make_unsigned_or_unchanged::type>; - rep val; - int precision; - locale_ref locale; - bool localized = false; - using seconds = std::chrono::duration; - seconds s; - using milliseconds = std::chrono::duration; - bool negative; - - using tm_writer_type = tm_writer; - - duration_formatter(iterator o, std::chrono::duration d, - locale_ref loc) - : out(o), val(static_cast(d.count())), locale(loc), negative(false) { - if (d.count() < 0) { - val = 0 - val; - negative = true; - } - - // this may overflow and/or the result may not fit in the - // target type. - // might need checked conversion (rep!=Rep) - s = detail::duration_cast(std::chrono::duration(val)); - } - - // returns true if nan or inf, writes to out. - auto handle_nan_inf() -> bool { - if (isfinite(val)) return false; - if (isnan(val)) { - write_nan(); - return true; - } - // must be +-inf - if (val > 0) - std::copy_n("inf", 3, out); - else - std::copy_n("-inf", 4, out); - return true; - } - - auto days() const -> Rep { return static_cast(s.count() / 86400); } - auto hour() const -> Rep { - return static_cast(mod((s.count() / 3600), 24)); - } - - auto hour12() const -> Rep { - Rep hour = static_cast(mod((s.count() / 3600), 12)); - return hour <= 0 ? 12 : hour; - } - - auto minute() const -> Rep { - return static_cast(mod((s.count() / 60), 60)); - } - auto second() const -> Rep { return static_cast(mod(s.count(), 60)); } - - auto time() const -> std::tm { - auto time = std::tm(); - time.tm_hour = to_nonnegative_int(hour(), 24); - time.tm_min = to_nonnegative_int(minute(), 60); - time.tm_sec = to_nonnegative_int(second(), 60); - return time; - } - - void write_sign() { - if (!negative) return; - *out++ = '-'; - negative = false; - } - - void write(Rep value, int width, pad_type pad = pad_type::zero) { - write_sign(); - if (isnan(value)) return write_nan(); - uint32_or_64_or_128_t n = - to_unsigned(to_nonnegative_int(value, max_value())); - int num_digits = detail::count_digits(n); - if (width > num_digits) { - out = detail::write_padding(out, pad, width - num_digits); - } - out = format_decimal(out, n, num_digits); - } - - void write_nan() { std::copy_n("nan", 3, out); } - - template - void format_tm(const tm& time, Callback cb, Args... args) { - if (isnan(val)) return write_nan(); - get_locale loc(localized, locale); - auto w = tm_writer_type(loc, out, time); - (w.*cb)(args...); - out = w.out(); - } - - void on_text(const Char* begin, const Char* end) { - copy(begin, end, out); - } - - // These are not implemented because durations don't have date information. - void on_abbr_weekday() {} - void on_full_weekday() {} - void on_dec0_weekday(numeric_system) {} - void on_dec1_weekday(numeric_system) {} - void on_abbr_month() {} - void on_full_month() {} - void on_datetime(numeric_system) {} - void on_loc_date(numeric_system) {} - void on_loc_time(numeric_system) {} - void on_us_date() {} - void on_iso_date() {} - void on_utc_offset(numeric_system) {} - void on_tz_name() {} - void on_year(numeric_system, pad_type) {} - void on_short_year(numeric_system) {} - void on_offset_year() {} - void on_century(numeric_system) {} - void on_iso_week_based_year() {} - void on_iso_week_based_short_year() {} - void on_dec_month(numeric_system, pad_type) {} - void on_dec0_week_of_year(numeric_system, pad_type) {} - void on_dec1_week_of_year(numeric_system, pad_type) {} - void on_iso_week_of_year(numeric_system, pad_type) {} - void on_day_of_month(numeric_system, pad_type) {} - - void on_day_of_year(pad_type) { - if (handle_nan_inf()) return; - write(days(), 0); - } - - void on_24_hour(numeric_system ns, pad_type pad) { - if (handle_nan_inf()) return; - - if (ns == numeric_system::standard) return write(hour(), 2, pad); - auto time = tm(); - time.tm_hour = to_nonnegative_int(hour(), 24); - format_tm(time, &tm_writer_type::on_24_hour, ns, pad); - } - - void on_12_hour(numeric_system ns, pad_type pad) { - if (handle_nan_inf()) return; - - if (ns == numeric_system::standard) return write(hour12(), 2, pad); - auto time = tm(); - time.tm_hour = to_nonnegative_int(hour12(), 12); - format_tm(time, &tm_writer_type::on_12_hour, ns, pad); - } - - void on_minute(numeric_system ns, pad_type pad) { - if (handle_nan_inf()) return; - - if (ns == numeric_system::standard) return write(minute(), 2, pad); - auto time = tm(); - time.tm_min = to_nonnegative_int(minute(), 60); - format_tm(time, &tm_writer_type::on_minute, ns, pad); - } - - void on_second(numeric_system ns, pad_type pad) { - if (handle_nan_inf()) return; - - if (ns == numeric_system::standard) { - if (std::is_floating_point::value) { - auto buf = memory_buffer(); - write_floating_seconds(buf, std::chrono::duration(val), - precision); - if (negative) *out++ = '-'; - if (buf.size() < 2 || buf[1] == '.') - out = detail::write_padding(out, pad); - out = copy(buf.begin(), buf.end(), out); - } else { - write(second(), 2, pad); - write_fractional_seconds( - out, std::chrono::duration(val), precision); - } - return; - } - auto time = tm(); - time.tm_sec = to_nonnegative_int(second(), 60); - format_tm(time, &tm_writer_type::on_second, ns, pad); - } - - void on_12_hour_time() { - if (handle_nan_inf()) return; - format_tm(time(), &tm_writer_type::on_12_hour_time); - } - - void on_24_hour_time() { - if (handle_nan_inf()) { - *out++ = ':'; - handle_nan_inf(); - return; - } - - write(hour(), 2); - *out++ = ':'; - write(minute(), 2); - } - - void on_iso_time() { - on_24_hour_time(); - *out++ = ':'; - if (handle_nan_inf()) return; - on_second(numeric_system::standard, pad_type::zero); - } - - void on_am_pm() { - if (handle_nan_inf()) return; - format_tm(time(), &tm_writer_type::on_am_pm); - } - - void on_duration_value() { - if (handle_nan_inf()) return; - write_sign(); - out = format_duration_value(out, val, precision); - } - - void on_duration_unit() { out = format_duration_unit(out); } -}; - -} // namespace detail - -#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907 -using weekday = std::chrono::weekday; -using day = std::chrono::day; -using month = std::chrono::month; -using year = std::chrono::year; -using year_month_day = std::chrono::year_month_day; -#else -// A fallback version of weekday. -class weekday { - private: - unsigned char value_; - - public: - weekday() = default; - constexpr explicit weekday(unsigned wd) noexcept - : value_(static_cast(wd != 7 ? wd : 0)) {} - constexpr auto c_encoding() const noexcept -> unsigned { return value_; } -}; - -class day { - private: - unsigned char value_; - - public: - day() = default; - constexpr explicit day(unsigned d) noexcept - : value_(static_cast(d)) {} - constexpr explicit operator unsigned() const noexcept { return value_; } -}; - -class month { - private: - unsigned char value_; - - public: - month() = default; - constexpr explicit month(unsigned m) noexcept - : value_(static_cast(m)) {} - constexpr explicit operator unsigned() const noexcept { return value_; } -}; - -class year { - private: - int value_; - - public: - year() = default; - constexpr explicit year(int y) noexcept : value_(y) {} - constexpr explicit operator int() const noexcept { return value_; } -}; - -class year_month_day { - private: - fmt::year year_; - fmt::month month_; - fmt::day day_; - - public: - year_month_day() = default; - constexpr year_month_day(const year& y, const month& m, const day& d) noexcept - : year_(y), month_(m), day_(d) {} - constexpr auto year() const noexcept -> fmt::year { return year_; } - constexpr auto month() const noexcept -> fmt::month { return month_; } - constexpr auto day() const noexcept -> fmt::day { return day_; } -}; -#endif // __cpp_lib_chrono >= 201907 - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it != end && *it == 'L') { - ++it; - this->set_localized(); - } - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(weekday wd, FormatContext& ctx) const -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_wday = static_cast(wd.c_encoding()); - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(this->localized(), ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_abbr_weekday(); - return w.out(); - } -}; - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(day d, FormatContext& ctx) const -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_mday = static_cast(static_cast(d)); - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(false, ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_day_of_month(detail::numeric_system::standard, detail::pad_type::zero); - return w.out(); - } -}; - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it != end && *it == 'L') { - ++it; - this->set_localized(); - } - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(month m, FormatContext& ctx) const -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_mon = static_cast(static_cast(m)) - 1; - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(this->localized(), ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_abbr_month(); - return w.out(); - } -}; - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(year y, FormatContext& ctx) const -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_year = static_cast(y) - 1900; - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(false, ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_year(detail::numeric_system::standard, detail::pad_type::zero); - return w.out(); - } -}; - -template -struct formatter : private formatter { - private: - bool use_tm_formatter_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - use_tm_formatter_ = it != end && *it != '}'; - return use_tm_formatter_ ? formatter::parse(ctx) : it; - } - - template - auto format(year_month_day val, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto time = std::tm(); - time.tm_year = static_cast(val.year()) - 1900; - time.tm_mon = static_cast(static_cast(val.month())) - 1; - time.tm_mday = static_cast(static_cast(val.day())); - if (use_tm_formatter_) return formatter::format(time, ctx); - detail::get_locale loc(true, ctx.locale()); - auto w = detail::tm_writer(loc, ctx.out(), time); - w.on_iso_date(); - return w.out(); - } -}; - -template -struct formatter, Char> { - private: - format_specs specs_; - detail::arg_ref width_ref_; - detail::arg_ref precision_ref_; - basic_string_view fmt_; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it == end || *it == '}') return it; - - it = detail::parse_align(it, end, specs_); - if (it == end) return it; - - Char c = *it; - if ((c >= '0' && c <= '9') || c == '{') { - it = detail::parse_width(it, end, specs_, width_ref_, ctx); - if (it == end) return it; - } - - auto checker = detail::chrono_format_checker(); - if (*it == '.') { - checker.has_precision_integral = !std::is_floating_point::value; - it = detail::parse_precision(it, end, specs_, precision_ref_, ctx); - } - if (it != end && *it == 'L') { - specs_.set_localized(); - ++it; - } - end = detail::parse_chrono_format(it, end, checker); - fmt_ = {it, detail::to_unsigned(end - it)}; - return end; - } - - template - auto format(std::chrono::duration d, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto specs = specs_; - auto precision = specs.precision; - specs.precision = -1; - auto begin = fmt_.begin(), end = fmt_.end(); - // As a possible future optimization, we could avoid extra copying if width - // is not specified. - auto buf = basic_memory_buffer(); - auto out = basic_appender(buf); - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, - ctx); - detail::handle_dynamic_spec(specs.dynamic_precision(), precision, - precision_ref_, ctx); - if (begin == end || *begin == '}') { - out = detail::format_duration_value(out, d.count(), precision); - detail::format_duration_unit(out); - } else { - auto f = - detail::duration_formatter(out, d, ctx.locale()); - f.precision = precision; - f.localized = specs_.localized(); - detail::parse_chrono_format(begin, end, f); - } - return detail::write( - ctx.out(), basic_string_view(buf.data(), buf.size()), specs); - } -}; - -template struct formatter { - private: - format_specs specs_; - detail::arg_ref width_ref_; - basic_string_view fmt_ = - detail::string_literal(); - - protected: - auto localized() const -> bool { return specs_.localized(); } - FMT_CONSTEXPR void set_localized() { specs_.set_localized(); } - - FMT_CONSTEXPR auto do_parse(parse_context& ctx, bool has_timezone) - -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it == end || *it == '}') return it; - - it = detail::parse_align(it, end, specs_); - if (it == end) return it; - - Char c = *it; - if ((c >= '0' && c <= '9') || c == '{') { - it = detail::parse_width(it, end, specs_, width_ref_, ctx); - if (it == end) return it; - } - - if (*it == 'L') { - specs_.set_localized(); - ++it; - } - - end = detail::parse_chrono_format(it, end, - detail::tm_format_checker(has_timezone)); - // Replace the default format string only if the new spec is not empty. - if (end != it) fmt_ = {it, detail::to_unsigned(end - it)}; - return end; - } - - template - auto do_format(const std::tm& tm, FormatContext& ctx, - const Duration* subsecs) const -> decltype(ctx.out()) { - auto specs = specs_; - auto buf = basic_memory_buffer(); - auto out = basic_appender(buf); - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, - ctx); - - auto loc_ref = specs.localized() ? ctx.locale() : locale_ref(); - detail::get_locale loc(static_cast(loc_ref), loc_ref); - auto w = detail::tm_writer, Char, Duration>( - loc, out, tm, subsecs); - detail::parse_chrono_format(fmt_.begin(), fmt_.end(), w); - return detail::write( - ctx.out(), basic_string_view(buf.data(), buf.size()), specs); - } - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return do_parse(ctx, detail::has_tm_gmtoff::value); - } - - template - auto format(const std::tm& tm, FormatContext& ctx) const - -> decltype(ctx.out()) { - return do_format(tm, ctx, nullptr); - } -}; - -// DEPRECATED! Reversed order of template parameters. -template -struct formatter, Char> : private formatter { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return this->do_parse(ctx, true); - } - - template - auto format(sys_time val, FormatContext& ctx) const - -> decltype(ctx.out()) { - std::tm tm = gmtime(val); - using period = typename Duration::period; - if (detail::const_check( - period::num == 1 && period::den == 1 && - !std::is_floating_point::value)) { - detail::set_tm_zone(tm, detail::utc()); - return formatter::format(tm, ctx); - } - Duration epoch = val.time_since_epoch(); - Duration subsecs = detail::duration_cast( - epoch - detail::duration_cast(epoch)); - if (subsecs.count() < 0) { - auto second = detail::duration_cast(std::chrono::seconds(1)); - if (tm.tm_sec != 0) { - --tm.tm_sec; - } else { - tm = gmtime(val - second); - detail::set_tm_zone(tm, detail::utc()); - } - subsecs += second; - } - return formatter::do_format(tm, ctx, &subsecs); - } -}; - -template -struct formatter, Char> - : formatter, Char> { - template - auto format(utc_time val, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter, Char>::format( - detail::utc_clock::to_sys(val), ctx); - } -}; - -template -struct formatter, Char> - : private formatter { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return this->do_parse(ctx, false); - } - - template - auto format(local_time val, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto time_since_epoch = val.time_since_epoch(); - auto seconds_since_epoch = - detail::duration_cast(time_since_epoch); - // Use gmtime to prevent time zone conversion since local_time has an - // unspecified time zone. - std::tm t = gmtime(seconds_since_epoch.count()); - using period = typename Duration::period; - if (period::num == 1 && period::den == 1 && - !std::is_floating_point::value) { - return formatter::format(t, ctx); - } - auto subsecs = - detail::duration_cast(time_since_epoch - seconds_since_epoch); - return formatter::do_format(t, ctx, &subsecs); - } -}; - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_CHRONO_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/color.h b/examples/blueprints-example/external/spdlog/fmt/bundled/color.h deleted file mode 100644 index b69c148..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/color.h +++ /dev/null @@ -1,637 +0,0 @@ -// Formatting library for C++ - color support -// -// Copyright (c) 2018 - present, Victor Zverovich and fmt contributors -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_COLOR_H_ -#define FMT_COLOR_H_ - -#include "format.h" - -FMT_BEGIN_NAMESPACE -FMT_BEGIN_EXPORT - -enum class color : uint32_t { - alice_blue = 0xF0F8FF, // rgb(240,248,255) - antique_white = 0xFAEBD7, // rgb(250,235,215) - aqua = 0x00FFFF, // rgb(0,255,255) - aquamarine = 0x7FFFD4, // rgb(127,255,212) - azure = 0xF0FFFF, // rgb(240,255,255) - beige = 0xF5F5DC, // rgb(245,245,220) - bisque = 0xFFE4C4, // rgb(255,228,196) - black = 0x000000, // rgb(0,0,0) - blanched_almond = 0xFFEBCD, // rgb(255,235,205) - blue = 0x0000FF, // rgb(0,0,255) - blue_violet = 0x8A2BE2, // rgb(138,43,226) - brown = 0xA52A2A, // rgb(165,42,42) - burly_wood = 0xDEB887, // rgb(222,184,135) - cadet_blue = 0x5F9EA0, // rgb(95,158,160) - chartreuse = 0x7FFF00, // rgb(127,255,0) - chocolate = 0xD2691E, // rgb(210,105,30) - coral = 0xFF7F50, // rgb(255,127,80) - cornflower_blue = 0x6495ED, // rgb(100,149,237) - cornsilk = 0xFFF8DC, // rgb(255,248,220) - crimson = 0xDC143C, // rgb(220,20,60) - cyan = 0x00FFFF, // rgb(0,255,255) - dark_blue = 0x00008B, // rgb(0,0,139) - dark_cyan = 0x008B8B, // rgb(0,139,139) - dark_golden_rod = 0xB8860B, // rgb(184,134,11) - dark_gray = 0xA9A9A9, // rgb(169,169,169) - dark_green = 0x006400, // rgb(0,100,0) - dark_khaki = 0xBDB76B, // rgb(189,183,107) - dark_magenta = 0x8B008B, // rgb(139,0,139) - dark_olive_green = 0x556B2F, // rgb(85,107,47) - dark_orange = 0xFF8C00, // rgb(255,140,0) - dark_orchid = 0x9932CC, // rgb(153,50,204) - dark_red = 0x8B0000, // rgb(139,0,0) - dark_salmon = 0xE9967A, // rgb(233,150,122) - dark_sea_green = 0x8FBC8F, // rgb(143,188,143) - dark_slate_blue = 0x483D8B, // rgb(72,61,139) - dark_slate_gray = 0x2F4F4F, // rgb(47,79,79) - dark_turquoise = 0x00CED1, // rgb(0,206,209) - dark_violet = 0x9400D3, // rgb(148,0,211) - deep_pink = 0xFF1493, // rgb(255,20,147) - deep_sky_blue = 0x00BFFF, // rgb(0,191,255) - dim_gray = 0x696969, // rgb(105,105,105) - dodger_blue = 0x1E90FF, // rgb(30,144,255) - fire_brick = 0xB22222, // rgb(178,34,34) - floral_white = 0xFFFAF0, // rgb(255,250,240) - forest_green = 0x228B22, // rgb(34,139,34) - fuchsia = 0xFF00FF, // rgb(255,0,255) - gainsboro = 0xDCDCDC, // rgb(220,220,220) - ghost_white = 0xF8F8FF, // rgb(248,248,255) - gold = 0xFFD700, // rgb(255,215,0) - golden_rod = 0xDAA520, // rgb(218,165,32) - gray = 0x808080, // rgb(128,128,128) - green = 0x008000, // rgb(0,128,0) - green_yellow = 0xADFF2F, // rgb(173,255,47) - honey_dew = 0xF0FFF0, // rgb(240,255,240) - hot_pink = 0xFF69B4, // rgb(255,105,180) - indian_red = 0xCD5C5C, // rgb(205,92,92) - indigo = 0x4B0082, // rgb(75,0,130) - ivory = 0xFFFFF0, // rgb(255,255,240) - khaki = 0xF0E68C, // rgb(240,230,140) - lavender = 0xE6E6FA, // rgb(230,230,250) - lavender_blush = 0xFFF0F5, // rgb(255,240,245) - lawn_green = 0x7CFC00, // rgb(124,252,0) - lemon_chiffon = 0xFFFACD, // rgb(255,250,205) - light_blue = 0xADD8E6, // rgb(173,216,230) - light_coral = 0xF08080, // rgb(240,128,128) - light_cyan = 0xE0FFFF, // rgb(224,255,255) - light_golden_rod_yellow = 0xFAFAD2, // rgb(250,250,210) - light_gray = 0xD3D3D3, // rgb(211,211,211) - light_green = 0x90EE90, // rgb(144,238,144) - light_pink = 0xFFB6C1, // rgb(255,182,193) - light_salmon = 0xFFA07A, // rgb(255,160,122) - light_sea_green = 0x20B2AA, // rgb(32,178,170) - light_sky_blue = 0x87CEFA, // rgb(135,206,250) - light_slate_gray = 0x778899, // rgb(119,136,153) - light_steel_blue = 0xB0C4DE, // rgb(176,196,222) - light_yellow = 0xFFFFE0, // rgb(255,255,224) - lime = 0x00FF00, // rgb(0,255,0) - lime_green = 0x32CD32, // rgb(50,205,50) - linen = 0xFAF0E6, // rgb(250,240,230) - magenta = 0xFF00FF, // rgb(255,0,255) - maroon = 0x800000, // rgb(128,0,0) - medium_aquamarine = 0x66CDAA, // rgb(102,205,170) - medium_blue = 0x0000CD, // rgb(0,0,205) - medium_orchid = 0xBA55D3, // rgb(186,85,211) - medium_purple = 0x9370DB, // rgb(147,112,219) - medium_sea_green = 0x3CB371, // rgb(60,179,113) - medium_slate_blue = 0x7B68EE, // rgb(123,104,238) - medium_spring_green = 0x00FA9A, // rgb(0,250,154) - medium_turquoise = 0x48D1CC, // rgb(72,209,204) - medium_violet_red = 0xC71585, // rgb(199,21,133) - midnight_blue = 0x191970, // rgb(25,25,112) - mint_cream = 0xF5FFFA, // rgb(245,255,250) - misty_rose = 0xFFE4E1, // rgb(255,228,225) - moccasin = 0xFFE4B5, // rgb(255,228,181) - navajo_white = 0xFFDEAD, // rgb(255,222,173) - navy = 0x000080, // rgb(0,0,128) - old_lace = 0xFDF5E6, // rgb(253,245,230) - olive = 0x808000, // rgb(128,128,0) - olive_drab = 0x6B8E23, // rgb(107,142,35) - orange = 0xFFA500, // rgb(255,165,0) - orange_red = 0xFF4500, // rgb(255,69,0) - orchid = 0xDA70D6, // rgb(218,112,214) - pale_golden_rod = 0xEEE8AA, // rgb(238,232,170) - pale_green = 0x98FB98, // rgb(152,251,152) - pale_turquoise = 0xAFEEEE, // rgb(175,238,238) - pale_violet_red = 0xDB7093, // rgb(219,112,147) - papaya_whip = 0xFFEFD5, // rgb(255,239,213) - peach_puff = 0xFFDAB9, // rgb(255,218,185) - peru = 0xCD853F, // rgb(205,133,63) - pink = 0xFFC0CB, // rgb(255,192,203) - plum = 0xDDA0DD, // rgb(221,160,221) - powder_blue = 0xB0E0E6, // rgb(176,224,230) - purple = 0x800080, // rgb(128,0,128) - rebecca_purple = 0x663399, // rgb(102,51,153) - red = 0xFF0000, // rgb(255,0,0) - rosy_brown = 0xBC8F8F, // rgb(188,143,143) - royal_blue = 0x4169E1, // rgb(65,105,225) - saddle_brown = 0x8B4513, // rgb(139,69,19) - salmon = 0xFA8072, // rgb(250,128,114) - sandy_brown = 0xF4A460, // rgb(244,164,96) - sea_green = 0x2E8B57, // rgb(46,139,87) - sea_shell = 0xFFF5EE, // rgb(255,245,238) - sienna = 0xA0522D, // rgb(160,82,45) - silver = 0xC0C0C0, // rgb(192,192,192) - sky_blue = 0x87CEEB, // rgb(135,206,235) - slate_blue = 0x6A5ACD, // rgb(106,90,205) - slate_gray = 0x708090, // rgb(112,128,144) - snow = 0xFFFAFA, // rgb(255,250,250) - spring_green = 0x00FF7F, // rgb(0,255,127) - steel_blue = 0x4682B4, // rgb(70,130,180) - tan = 0xD2B48C, // rgb(210,180,140) - teal = 0x008080, // rgb(0,128,128) - thistle = 0xD8BFD8, // rgb(216,191,216) - tomato = 0xFF6347, // rgb(255,99,71) - turquoise = 0x40E0D0, // rgb(64,224,208) - violet = 0xEE82EE, // rgb(238,130,238) - wheat = 0xF5DEB3, // rgb(245,222,179) - white = 0xFFFFFF, // rgb(255,255,255) - white_smoke = 0xF5F5F5, // rgb(245,245,245) - yellow = 0xFFFF00, // rgb(255,255,0) - yellow_green = 0x9ACD32 // rgb(154,205,50) -}; // enum class color - -enum class terminal_color : uint8_t { - black = 30, - red, - green, - yellow, - blue, - magenta, - cyan, - white, - bright_black = 90, - bright_red, - bright_green, - bright_yellow, - bright_blue, - bright_magenta, - bright_cyan, - bright_white -}; - -enum class emphasis : uint8_t { - bold = 1, - faint = 1 << 1, - italic = 1 << 2, - underline = 1 << 3, - blink = 1 << 4, - reverse = 1 << 5, - conceal = 1 << 6, - strikethrough = 1 << 7, -}; - -// rgb is a struct for red, green and blue colors. -// Using the name "rgb" makes some editors show the color in a tooltip. -struct rgb { - constexpr rgb() : r(0), g(0), b(0) {} - constexpr rgb(uint8_t r_, uint8_t g_, uint8_t b_) : r(r_), g(g_), b(b_) {} - constexpr rgb(uint32_t hex) - : r((hex >> 16) & 0xFF), g((hex >> 8) & 0xFF), b(hex & 0xFF) {} - constexpr rgb(color hex) - : r((uint32_t(hex) >> 16) & 0xFF), - g((uint32_t(hex) >> 8) & 0xFF), - b(uint32_t(hex) & 0xFF) {} - uint8_t r; - uint8_t g; - uint8_t b; -}; - -namespace detail { - -// A bit-packed variant of an RGB color, a terminal color, or unset color. -// see text_style for the bit-packing scheme. -struct color_type { - constexpr color_type() noexcept = default; - constexpr color_type(color rgb_color) noexcept - : value_(static_cast(rgb_color) | (1 << 24)) {} - constexpr color_type(rgb rgb_color) noexcept - : color_type(static_cast( - (static_cast(rgb_color.r) << 16) | - (static_cast(rgb_color.g) << 8) | rgb_color.b)) {} - constexpr color_type(terminal_color term_color) noexcept - : value_(static_cast(term_color) | (3 << 24)) {} - - constexpr auto is_terminal_color() const noexcept -> bool { - return (value_ & (1 << 25)) != 0; - } - - constexpr auto value() const noexcept -> uint32_t { - return value_ & 0xFFFFFF; - } - - constexpr color_type(uint32_t value) noexcept : value_(value) {} - - uint32_t value_ = 0; -}; -} // namespace detail - -/// A text style consisting of foreground and background colors and emphasis. -class text_style { - // The information is packed as follows: - // ┌──┠- // │ 0│─┠- // │..│ ├── foreground color value - // │23│─┘ - // ├──┤ - // │24│─┬── discriminator for the above value. 00 if unset, 01 if it's - // │25│─┘ an RGB color, or 11 if it's a terminal color (10 is unused) - // ├──┤ - // │26│──── overflow bit, always zero (see below) - // ├──┤ - // │27│─┠- // │..│ │ - // │50│ │ - // ├──┤ │ - // │51│ ├── background color (same format as the foreground color) - // │52│ │ - // ├──┤ │ - // │53│─┘ - // ├──┤ - // │54│─┠- // │..│ ├── emphases - // │61│─┘ - // ├──┤ - // │62│─┬── unused - // │63│─┘ - // └──┘ - // The overflow bits are there to make operator|= efficient. - // When ORing, we must throw if, for either the foreground or background, - // one style specifies a terminal color and the other specifies any color - // (terminal or RGB); in other words, if one discriminator is 11 and the - // other is 11 or 01. - // - // We do that check by adding the styles. Consider what adding does to each - // possible pair of discriminators: - // 00 + 00 = 000 - // 01 + 00 = 001 - // 11 + 00 = 011 - // 01 + 01 = 010 - // 11 + 01 = 100 (!!) - // 11 + 11 = 110 (!!) - // In the last two cases, the ones we want to catch, the third bit——the - // overflow bit——is set. Bingo. - // - // We must take into account the possible carry bit from the bits - // before the discriminator. The only potentially problematic case is - // 11 + 00 = 011 (a carry bit would make it 100, not good!), but a carry - // bit is impossible in that case, because 00 (unset color) means the - // 24 bits that precede the discriminator are all zero. - // - // This test can be applied to both colors simultaneously. - - public: - FMT_CONSTEXPR text_style(emphasis em = emphasis()) noexcept - : style_(static_cast(em) << 54) {} - - FMT_CONSTEXPR auto operator|=(text_style rhs) -> text_style& { - if (((style_ + rhs.style_) & ((1ULL << 26) | (1ULL << 53))) != 0) - report_error("can't OR a terminal color"); - style_ |= rhs.style_; - return *this; - } - - friend FMT_CONSTEXPR auto operator|(text_style lhs, text_style rhs) - -> text_style { - return lhs |= rhs; - } - - FMT_CONSTEXPR auto operator==(text_style rhs) const noexcept -> bool { - return style_ == rhs.style_; - } - - FMT_CONSTEXPR auto operator!=(text_style rhs) const noexcept -> bool { - return !(*this == rhs); - } - - FMT_CONSTEXPR auto has_foreground() const noexcept -> bool { - return (style_ & (1 << 24)) != 0; - } - FMT_CONSTEXPR auto has_background() const noexcept -> bool { - return (style_ & (1ULL << 51)) != 0; - } - FMT_CONSTEXPR auto has_emphasis() const noexcept -> bool { - return (style_ >> 54) != 0; - } - FMT_CONSTEXPR auto get_foreground() const noexcept -> detail::color_type { - FMT_ASSERT(has_foreground(), "no foreground specified for this style"); - return style_ & 0x3FFFFFF; - } - FMT_CONSTEXPR auto get_background() const noexcept -> detail::color_type { - FMT_ASSERT(has_background(), "no background specified for this style"); - return (style_ >> 27) & 0x3FFFFFF; - } - FMT_CONSTEXPR auto get_emphasis() const noexcept -> emphasis { - FMT_ASSERT(has_emphasis(), "no emphasis specified for this style"); - return static_cast(style_ >> 54); - } - - private: - FMT_CONSTEXPR text_style(uint64_t style) noexcept : style_(style) {} - - friend FMT_CONSTEXPR auto fg(detail::color_type foreground) noexcept - -> text_style; - - friend FMT_CONSTEXPR auto bg(detail::color_type background) noexcept - -> text_style; - - uint64_t style_ = 0; -}; - -/// Creates a text style from the foreground (text) color. -FMT_CONSTEXPR inline auto fg(detail::color_type foreground) noexcept - -> text_style { - return foreground.value_; -} - -/// Creates a text style from the background color. -FMT_CONSTEXPR inline auto bg(detail::color_type background) noexcept - -> text_style { - return static_cast(background.value_) << 27; -} - -FMT_CONSTEXPR inline auto operator|(emphasis lhs, emphasis rhs) noexcept - -> text_style { - return text_style(lhs) | rhs; -} - -namespace detail { - -template struct ansi_color_escape { - FMT_CONSTEXPR ansi_color_escape(color_type text_color, - const char* esc) noexcept { - // If we have a terminal color, we need to output another escape code - // sequence. - if (text_color.is_terminal_color()) { - bool is_background = esc == string_view("\x1b[48;2;"); - uint32_t value = text_color.value(); - // Background ASCII codes are the same as the foreground ones but with - // 10 more. - if (is_background) value += 10u; - - buffer[size++] = static_cast('\x1b'); - buffer[size++] = static_cast('['); - - if (value >= 100u) { - buffer[size++] = static_cast('1'); - value %= 100u; - } - buffer[size++] = static_cast('0' + value / 10u); - buffer[size++] = static_cast('0' + value % 10u); - - buffer[size++] = static_cast('m'); - return; - } - - for (int i = 0; i < 7; i++) { - buffer[i] = static_cast(esc[i]); - } - rgb color(text_color.value()); - to_esc(color.r, buffer + 7, ';'); - to_esc(color.g, buffer + 11, ';'); - to_esc(color.b, buffer + 15, 'm'); - size = 19; - } - FMT_CONSTEXPR ansi_color_escape(emphasis em) noexcept { - uint8_t em_codes[num_emphases] = {}; - if (has_emphasis(em, emphasis::bold)) em_codes[0] = 1; - if (has_emphasis(em, emphasis::faint)) em_codes[1] = 2; - if (has_emphasis(em, emphasis::italic)) em_codes[2] = 3; - if (has_emphasis(em, emphasis::underline)) em_codes[3] = 4; - if (has_emphasis(em, emphasis::blink)) em_codes[4] = 5; - if (has_emphasis(em, emphasis::reverse)) em_codes[5] = 7; - if (has_emphasis(em, emphasis::conceal)) em_codes[6] = 8; - if (has_emphasis(em, emphasis::strikethrough)) em_codes[7] = 9; - - buffer[size++] = static_cast('\x1b'); - buffer[size++] = static_cast('['); - - for (size_t i = 0; i < num_emphases; ++i) { - if (!em_codes[i]) continue; - buffer[size++] = static_cast('0' + em_codes[i]); - buffer[size++] = static_cast(';'); - } - - buffer[size - 1] = static_cast('m'); - } - FMT_CONSTEXPR operator const Char*() const noexcept { return buffer; } - - FMT_CONSTEXPR auto begin() const noexcept -> const Char* { return buffer; } - FMT_CONSTEXPR auto end() const noexcept -> const Char* { - return buffer + size; - } - - private: - static constexpr size_t num_emphases = 8; - Char buffer[7u + 4u * num_emphases]; - size_t size = 0; - - static FMT_CONSTEXPR void to_esc(uint8_t c, Char* out, - char delimiter) noexcept { - out[0] = static_cast('0' + c / 100); - out[1] = static_cast('0' + c / 10 % 10); - out[2] = static_cast('0' + c % 10); - out[3] = static_cast(delimiter); - } - static FMT_CONSTEXPR auto has_emphasis(emphasis em, emphasis mask) noexcept - -> bool { - return static_cast(em) & static_cast(mask); - } -}; - -template -FMT_CONSTEXPR auto make_foreground_color(color_type foreground) noexcept - -> ansi_color_escape { - return ansi_color_escape(foreground, "\x1b[38;2;"); -} - -template -FMT_CONSTEXPR auto make_background_color(color_type background) noexcept - -> ansi_color_escape { - return ansi_color_escape(background, "\x1b[48;2;"); -} - -template -FMT_CONSTEXPR auto make_emphasis(emphasis em) noexcept - -> ansi_color_escape { - return ansi_color_escape(em); -} - -template inline void reset_color(buffer& buffer) { - auto reset_color = string_view("\x1b[0m"); - buffer.append(reset_color.begin(), reset_color.end()); -} - -template struct styled_arg : view { - const T& value; - text_style style; - styled_arg(const T& v, text_style s) : value(v), style(s) {} -}; - -template -void vformat_to(buffer& buf, text_style ts, basic_string_view fmt, - basic_format_args> args) { - if (ts.has_emphasis()) { - auto emphasis = make_emphasis(ts.get_emphasis()); - buf.append(emphasis.begin(), emphasis.end()); - } - if (ts.has_foreground()) { - auto foreground = make_foreground_color(ts.get_foreground()); - buf.append(foreground.begin(), foreground.end()); - } - if (ts.has_background()) { - auto background = make_background_color(ts.get_background()); - buf.append(background.begin(), background.end()); - } - vformat_to(buf, fmt, args); - if (ts != text_style()) reset_color(buf); -} -} // namespace detail - -inline void vprint(FILE* f, text_style ts, string_view fmt, format_args args) { - auto buf = memory_buffer(); - detail::vformat_to(buf, ts, fmt, args); - print(f, FMT_STRING("{}"), string_view(buf.begin(), buf.size())); -} - -/** - * Formats a string and prints it to the specified file stream using ANSI - * escape sequences to specify text formatting. - * - * **Example**: - * - * fmt::print(fmt::emphasis::bold | fg(fmt::color::red), - * "Elapsed time: {0:.2f} seconds", 1.23); - */ -template -void print(FILE* f, text_style ts, format_string fmt, T&&... args) { - vprint(f, ts, fmt.str, vargs{{args...}}); -} - -/** - * Formats a string and prints it to stdout using ANSI escape sequences to - * specify text formatting. - * - * **Example**: - * - * fmt::print(fmt::emphasis::bold | fg(fmt::color::red), - * "Elapsed time: {0:.2f} seconds", 1.23); - */ -template -void print(text_style ts, format_string fmt, T&&... args) { - return print(stdout, ts, fmt, std::forward(args)...); -} - -inline auto vformat(text_style ts, string_view fmt, format_args args) - -> std::string { - auto buf = memory_buffer(); - detail::vformat_to(buf, ts, fmt, args); - return fmt::to_string(buf); -} - -/** - * Formats arguments and returns the result as a string using ANSI escape - * sequences to specify text formatting. - * - * **Example**: - * - * ``` - * #include - * std::string message = fmt::format(fmt::emphasis::bold | fg(fmt::color::red), - * "The answer is {}", 42); - * ``` - */ -template -inline auto format(text_style ts, format_string fmt, T&&... args) - -> std::string { - return fmt::vformat(ts, fmt.str, vargs{{args...}}); -} - -/// Formats a string with the given text_style and writes the output to `out`. -template ::value)> -auto vformat_to(OutputIt out, text_style ts, string_view fmt, format_args args) - -> OutputIt { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, ts, fmt, args); - return detail::get_iterator(buf, out); -} - -/** - * Formats arguments with the given text style, writes the result to the output - * iterator `out` and returns the iterator past the end of the output range. - * - * **Example**: - * - * std::vector out; - * fmt::format_to(std::back_inserter(out), - * fmt::emphasis::bold | fg(fmt::color::red), "{}", 42); - */ -template ::value)> -inline auto format_to(OutputIt out, text_style ts, format_string fmt, - T&&... args) -> OutputIt { - return vformat_to(out, ts, fmt.str, vargs{{args...}}); -} - -template -struct formatter, Char> : formatter { - template - auto format(const detail::styled_arg& arg, FormatContext& ctx) const - -> decltype(ctx.out()) { - const auto& ts = arg.style; - auto out = ctx.out(); - - bool has_style = false; - if (ts.has_emphasis()) { - has_style = true; - auto emphasis = detail::make_emphasis(ts.get_emphasis()); - out = detail::copy(emphasis.begin(), emphasis.end(), out); - } - if (ts.has_foreground()) { - has_style = true; - auto foreground = - detail::make_foreground_color(ts.get_foreground()); - out = detail::copy(foreground.begin(), foreground.end(), out); - } - if (ts.has_background()) { - has_style = true; - auto background = - detail::make_background_color(ts.get_background()); - out = detail::copy(background.begin(), background.end(), out); - } - out = formatter::format(arg.value, ctx); - if (has_style) { - auto reset_color = string_view("\x1b[0m"); - out = detail::copy(reset_color.begin(), reset_color.end(), out); - } - return out; - } -}; - -/** - * Returns an argument that will be formatted using ANSI escape sequences, - * to be used in a formatting function. - * - * **Example**: - * - * fmt::print("Elapsed time: {0:.2f} seconds", - * fmt::styled(1.23, fmt::fg(fmt::color::green) | - * fmt::bg(fmt::color::blue))); - */ -template -FMT_CONSTEXPR auto styled(const T& value, text_style ts) - -> detail::styled_arg> { - return detail::styled_arg>{value, ts}; -} - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_COLOR_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/compile.h b/examples/blueprints-example/external/spdlog/fmt/bundled/compile.h deleted file mode 100644 index f711ba4..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/compile.h +++ /dev/null @@ -1,585 +0,0 @@ -// Formatting library for C++ - experimental format string compilation -// -// Copyright (c) 2012 - present, Victor Zverovich and fmt contributors -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_COMPILE_H_ -#define FMT_COMPILE_H_ - -#ifndef FMT_MODULE -# include // std::back_inserter -#endif - -#include "format.h" - -FMT_BEGIN_NAMESPACE - -// A compile-time string which is compiled into fast formatting code. -FMT_EXPORT class compiled_string {}; - -template -struct is_compiled_string : std::is_base_of {}; - -/** - * Converts a string literal `s` into a format string that will be parsed at - * compile time and converted into efficient formatting code. Requires C++17 - * `constexpr if` compiler support. - * - * **Example**: - * - * // Converts 42 into std::string using the most efficient method and no - * // runtime format string processing. - * std::string s = fmt::format(FMT_COMPILE("{}"), 42); - */ -#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) -# define FMT_COMPILE(s) FMT_STRING_IMPL(s, fmt::compiled_string) -#else -# define FMT_COMPILE(s) FMT_STRING(s) -#endif - -/** - * Converts a string literal into a format string that will be parsed at - * compile time and converted into efficient formatting code. Requires support - * for class types in constant template parameters (a C++20 feature). - * - * **Example**: - * - * // Converts 42 into std::string using the most efficient method and no - * // runtime format string processing. - * using namespace fmt::literals; - * std::string s = fmt::format("{}"_cf, 42); - */ -#if FMT_USE_NONTYPE_TEMPLATE_ARGS -inline namespace literals { -template constexpr auto operator""_cf() { - return FMT_COMPILE(Str.data); -} -} // namespace literals -#endif - -namespace detail { - -template -constexpr auto first(const T& value, const Tail&...) -> const T& { - return value; -} - -#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) -template struct type_list {}; - -// Returns a reference to the argument at index N from [first, rest...]. -template -constexpr auto get([[maybe_unused]] const T& first, - [[maybe_unused]] const Args&... rest) -> const auto& { - static_assert(N < 1 + sizeof...(Args), "index is out of bounds"); - if constexpr (N == 0) - return first; - else - return detail::get(rest...); -} - -# if FMT_USE_NONTYPE_TEMPLATE_ARGS -template -constexpr auto get_arg_index_by_name(basic_string_view name) -> int { - if constexpr (is_static_named_arg()) { - if (name == T::name) return N; - } - if constexpr (sizeof...(Args) > 0) - return get_arg_index_by_name(name); - (void)name; // Workaround an MSVC bug about "unused" parameter. - return -1; -} -# endif - -template -FMT_CONSTEXPR auto get_arg_index_by_name(basic_string_view name) -> int { -# if FMT_USE_NONTYPE_TEMPLATE_ARGS - if constexpr (sizeof...(Args) > 0) - return get_arg_index_by_name<0, Args...>(name); -# endif - (void)name; - return -1; -} - -template -constexpr auto get_arg_index_by_name(basic_string_view name, - type_list) -> int { - return get_arg_index_by_name(name); -} - -template struct get_type_impl; - -template struct get_type_impl> { - using type = - remove_cvref_t(std::declval()...))>; -}; - -template -using get_type = typename get_type_impl::type; - -template struct is_compiled_format : std::false_type {}; - -template struct text { - basic_string_view data; - using char_type = Char; - - template - constexpr auto format(OutputIt out, const T&...) const -> OutputIt { - return write(out, data); - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -template -constexpr auto make_text(basic_string_view s, size_t pos, size_t size) - -> text { - return {{&s[pos], size}}; -} - -template struct code_unit { - Char value; - using char_type = Char; - - template - constexpr auto format(OutputIt out, const T&...) const -> OutputIt { - *out++ = value; - return out; - } -}; - -// This ensures that the argument type is convertible to `const T&`. -template -constexpr auto get_arg_checked(const Args&... args) -> const T& { - const auto& arg = detail::get(args...); - if constexpr (detail::is_named_arg>()) { - return arg.value; - } else { - return arg; - } -} - -template -struct is_compiled_format> : std::true_type {}; - -// A replacement field that refers to argument N. -template struct field { - using char_type = Char; - - template - constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { - const V& arg = get_arg_checked(args...); - if constexpr (std::is_convertible>::value) { - auto s = basic_string_view(arg); - return copy(s.begin(), s.end(), out); - } else { - return write(out, arg); - } - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -// A replacement field that refers to argument with name. -template struct runtime_named_field { - using char_type = Char; - basic_string_view name; - - template - constexpr static auto try_format_argument( - OutputIt& out, - // [[maybe_unused]] due to unused-but-set-parameter warning in GCC 7,8,9 - [[maybe_unused]] basic_string_view arg_name, const T& arg) -> bool { - if constexpr (is_named_arg::type>::value) { - if (arg_name == arg.name) { - out = write(out, arg.value); - return true; - } - } - return false; - } - - template - constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { - bool found = (try_format_argument(out, name, args) || ...); - if (!found) { - FMT_THROW(format_error("argument with specified name is not found")); - } - return out; - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -// A replacement field that refers to argument N and has format specifiers. -template struct spec_field { - using char_type = Char; - formatter fmt; - - template - constexpr FMT_INLINE auto format(OutputIt out, const T&... args) const - -> OutputIt { - const auto& vargs = - fmt::make_format_args>(args...); - basic_format_context ctx(out, vargs); - return fmt.format(get_arg_checked(args...), ctx); - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -template struct concat { - L lhs; - R rhs; - using char_type = typename L::char_type; - - template - constexpr auto format(OutputIt out, const T&... args) const -> OutputIt { - out = lhs.format(out, args...); - return rhs.format(out, args...); - } -}; - -template -struct is_compiled_format> : std::true_type {}; - -template -constexpr auto make_concat(L lhs, R rhs) -> concat { - return {lhs, rhs}; -} - -struct unknown_format {}; - -template -constexpr auto parse_text(basic_string_view str, size_t pos) -> size_t { - for (size_t size = str.size(); pos != size; ++pos) { - if (str[pos] == '{' || str[pos] == '}') break; - } - return pos; -} - -template -constexpr auto compile_format_string(S fmt); - -template -constexpr auto parse_tail(T head, S fmt) { - if constexpr (POS != basic_string_view(fmt).size()) { - constexpr auto tail = compile_format_string(fmt); - if constexpr (std::is_same, - unknown_format>()) - return tail; - else - return make_concat(head, tail); - } else { - return head; - } -} - -template struct parse_specs_result { - formatter fmt; - size_t end; - int next_arg_id; -}; - -enum { manual_indexing_id = -1 }; - -template -constexpr auto parse_specs(basic_string_view str, size_t pos, - int next_arg_id) -> parse_specs_result { - str.remove_prefix(pos); - auto ctx = - compile_parse_context(str, max_value(), nullptr, next_arg_id); - auto f = formatter(); - auto end = f.parse(ctx); - return {f, pos + fmt::detail::to_unsigned(end - str.data()), - next_arg_id == 0 ? manual_indexing_id : ctx.next_arg_id()}; -} - -template struct arg_id_handler { - arg_id_kind kind; - arg_ref arg_id; - - constexpr auto on_auto() -> int { - FMT_ASSERT(false, "handler cannot be used with automatic indexing"); - return 0; - } - constexpr auto on_index(int id) -> int { - kind = arg_id_kind::index; - arg_id = arg_ref(id); - return 0; - } - constexpr auto on_name(basic_string_view id) -> int { - kind = arg_id_kind::name; - arg_id = arg_ref(id); - return 0; - } -}; - -template struct parse_arg_id_result { - arg_id_kind kind; - arg_ref arg_id; - const Char* arg_id_end; -}; - -template -constexpr auto parse_arg_id(const Char* begin, const Char* end) { - auto handler = arg_id_handler{arg_id_kind::none, arg_ref{}}; - auto arg_id_end = parse_arg_id(begin, end, handler); - return parse_arg_id_result{handler.kind, handler.arg_id, arg_id_end}; -} - -template struct field_type { - using type = remove_cvref_t; -}; - -template -struct field_type::value>> { - using type = remove_cvref_t; -}; - -template -constexpr auto parse_replacement_field_then_tail(S fmt) { - using char_type = typename S::char_type; - constexpr auto str = basic_string_view(fmt); - constexpr char_type c = END_POS != str.size() ? str[END_POS] : char_type(); - if constexpr (c == '}') { - return parse_tail( - field::type, ARG_INDEX>(), fmt); - } else if constexpr (c != ':') { - FMT_THROW(format_error("expected ':'")); - } else { - constexpr auto result = parse_specs::type>( - str, END_POS + 1, NEXT_ID == manual_indexing_id ? 0 : NEXT_ID); - if constexpr (result.end >= str.size() || str[result.end] != '}') { - FMT_THROW(format_error("expected '}'")); - return 0; - } else { - return parse_tail( - spec_field::type, ARG_INDEX>{ - result.fmt}, - fmt); - } - } -} - -// Compiles a non-empty format string and returns the compiled representation -// or unknown_format() on unrecognized input. -template -constexpr auto compile_format_string(S fmt) { - using char_type = typename S::char_type; - constexpr auto str = basic_string_view(fmt); - if constexpr (str[POS] == '{') { - if constexpr (POS + 1 == str.size()) - FMT_THROW(format_error("unmatched '{' in format string")); - if constexpr (str[POS + 1] == '{') { - return parse_tail(make_text(str, POS, 1), fmt); - } else if constexpr (str[POS + 1] == '}' || str[POS + 1] == ':') { - static_assert(ID != manual_indexing_id, - "cannot switch from manual to automatic argument indexing"); - constexpr auto next_id = - ID != manual_indexing_id ? ID + 1 : manual_indexing_id; - return parse_replacement_field_then_tail, Args, - POS + 1, ID, next_id>(fmt); - } else { - constexpr auto arg_id_result = - parse_arg_id(str.data() + POS + 1, str.data() + str.size()); - constexpr auto arg_id_end_pos = arg_id_result.arg_id_end - str.data(); - constexpr char_type c = - arg_id_end_pos != str.size() ? str[arg_id_end_pos] : char_type(); - static_assert(c == '}' || c == ':', "missing '}' in format string"); - if constexpr (arg_id_result.kind == arg_id_kind::index) { - static_assert( - ID == manual_indexing_id || ID == 0, - "cannot switch from automatic to manual argument indexing"); - constexpr auto arg_index = arg_id_result.arg_id.index; - return parse_replacement_field_then_tail, - Args, arg_id_end_pos, - arg_index, manual_indexing_id>( - fmt); - } else if constexpr (arg_id_result.kind == arg_id_kind::name) { - constexpr auto arg_index = - get_arg_index_by_name(arg_id_result.arg_id.name, Args{}); - if constexpr (arg_index >= 0) { - constexpr auto next_id = - ID != manual_indexing_id ? ID + 1 : manual_indexing_id; - return parse_replacement_field_then_tail< - decltype(get_type::value), Args, arg_id_end_pos, - arg_index, next_id>(fmt); - } else if constexpr (c == '}') { - return parse_tail( - runtime_named_field{arg_id_result.arg_id.name}, fmt); - } else if constexpr (c == ':') { - return unknown_format(); // no type info for specs parsing - } - } - } - } else if constexpr (str[POS] == '}') { - if constexpr (POS + 1 == str.size()) - FMT_THROW(format_error("unmatched '}' in format string")); - return parse_tail(make_text(str, POS, 1), fmt); - } else { - constexpr auto end = parse_text(str, POS + 1); - if constexpr (end - POS > 1) { - return parse_tail(make_text(str, POS, end - POS), fmt); - } else { - return parse_tail(code_unit{str[POS]}, fmt); - } - } -} - -template ::value)> -constexpr auto compile(S fmt) { - constexpr auto str = basic_string_view(fmt); - if constexpr (str.size() == 0) { - return detail::make_text(str, 0, 0); - } else { - constexpr auto result = - detail::compile_format_string, 0, 0>(fmt); - return result; - } -} -#endif // defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) -} // namespace detail - -FMT_BEGIN_EXPORT - -#if defined(__cpp_if_constexpr) && defined(__cpp_return_type_deduction) - -template ::value)> -FMT_INLINE FMT_CONSTEXPR_STRING auto format(const CompiledFormat& cf, - const T&... args) - -> std::basic_string { - auto s = std::basic_string(); - cf.format(std::back_inserter(s), args...); - return s; -} - -template ::value)> -constexpr FMT_INLINE auto format_to(OutputIt out, const CompiledFormat& cf, - const T&... args) -> OutputIt { - return cf.format(out, args...); -} - -template ::value)> -FMT_INLINE FMT_CONSTEXPR_STRING auto format(const S&, T&&... args) - -> std::basic_string { - if constexpr (std::is_same::value) { - constexpr auto str = basic_string_view(S()); - if constexpr (str.size() == 2 && str[0] == '{' && str[1] == '}') { - const auto& first = detail::first(args...); - if constexpr (detail::is_named_arg< - remove_cvref_t>::value) { - return fmt::to_string(first.value); - } else { - return fmt::to_string(first); - } - } - } - constexpr auto compiled = detail::compile(S()); - if constexpr (std::is_same, - detail::unknown_format>()) { - return fmt::format( - static_cast>(S()), - std::forward(args)...); - } else { - return fmt::format(compiled, std::forward(args)...); - } -} - -template ::value)> -FMT_CONSTEXPR auto format_to(OutputIt out, const S&, T&&... args) -> OutputIt { - constexpr auto compiled = detail::compile(S()); - if constexpr (std::is_same, - detail::unknown_format>()) { - return fmt::format_to( - out, static_cast>(S()), - std::forward(args)...); - } else { - return fmt::format_to(out, compiled, std::forward(args)...); - } -} -#endif - -template ::value)> -auto format_to_n(OutputIt out, size_t n, const S& fmt, T&&... args) - -> format_to_n_result { - using traits = detail::fixed_buffer_traits; - auto buf = detail::iterator_buffer(out, n); - fmt::format_to(std::back_inserter(buf), fmt, std::forward(args)...); - return {buf.out(), buf.count()}; -} - -template ::value)> -FMT_CONSTEXPR20 auto formatted_size(const S& fmt, T&&... args) -> size_t { - auto buf = detail::counting_buffer<>(); - fmt::format_to(appender(buf), fmt, std::forward(args)...); - return buf.count(); -} - -template ::value)> -void print(std::FILE* f, const S& fmt, T&&... args) { - auto buf = memory_buffer(); - fmt::format_to(appender(buf), fmt, std::forward(args)...); - detail::print(f, {buf.data(), buf.size()}); -} - -template ::value)> -void print(const S& fmt, T&&... args) { - print(stdout, fmt, std::forward(args)...); -} - -template class static_format_result { - private: - char data[N]; - - public: - template ::value)> - explicit FMT_CONSTEXPR static_format_result(const S& fmt, T&&... args) { - *fmt::format_to(data, fmt, std::forward(args)...) = '\0'; - } - - auto str() const -> fmt::string_view { return {data, N - 1}; } - auto c_str() const -> const char* { return data; } -}; - -/** - * Formats arguments according to the format string `fmt_str` and produces - * a string of the exact required size at compile time. Both the format string - * and the arguments must be compile-time expressions. - * - * The resulting string can be accessed as a C string via `c_str()` or as - * a `fmt::string_view` via `str()`. - * - * **Example**: - * - * // Produces the static string "42" at compile time. - * static constexpr auto result = FMT_STATIC_FORMAT("{}", 42); - * const char* s = result.c_str(); - */ -#define FMT_STATIC_FORMAT(fmt_str, ...) \ - fmt::static_format_result< \ - fmt::formatted_size(FMT_COMPILE(fmt_str), __VA_ARGS__) + 1>( \ - FMT_COMPILE(fmt_str), __VA_ARGS__) - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_COMPILE_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/core.h b/examples/blueprints-example/external/spdlog/fmt/bundled/core.h deleted file mode 100644 index 8ca735f..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/core.h +++ /dev/null @@ -1,5 +0,0 @@ -// This file is only provided for compatibility and may be removed in future -// versions. Use fmt/base.h if you don't need fmt::format and fmt/format.h -// otherwise. - -#include "format.h" diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/fmt.license.rst b/examples/blueprints-example/external/spdlog/fmt/bundled/fmt.license.rst deleted file mode 100644 index 1cd1ef9..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/fmt.license.rst +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ---- Optional exception to the license --- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into a machine-executable object form of such -source code, you may redistribute such embedded portions in such object form -without including the above copyright and permission notices. diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/format-inl.h b/examples/blueprints-example/external/spdlog/fmt/bundled/format-inl.h deleted file mode 100644 index 9d568dc..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/format-inl.h +++ /dev/null @@ -1,1953 +0,0 @@ -// Formatting library for C++ - implementation -// -// Copyright (c) 2012 - 2016, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_FORMAT_INL_H_ -#define FMT_FORMAT_INL_H_ - -#ifndef FMT_MODULE -# include -# include // errno -# include -# include -# include -#endif - -#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE) -# include // _isatty -#endif - -#include "format.h" - -#if FMT_USE_LOCALE && !defined(FMT_MODULE) -# include -#endif - -#ifndef FMT_FUNC -# define FMT_FUNC -#endif - -FMT_BEGIN_NAMESPACE - -#ifndef FMT_CUSTOM_ASSERT_FAIL -FMT_FUNC void assert_fail(const char* file, int line, const char* message) { - // Use unchecked std::fprintf to avoid triggering another assertion when - // writing to stderr fails. - fprintf(stderr, "%s:%d: assertion failed: %s", file, line, message); - abort(); -} -#endif - -#if FMT_USE_LOCALE -namespace detail { -using std::locale; -using std::numpunct; -using std::use_facet; -} // namespace detail - -template > -locale_ref::locale_ref(const Locale& loc) : locale_(&loc) { - static_assert(std::is_same::value, ""); -} -#else -namespace detail { -struct locale {}; -template struct numpunct { - auto grouping() const -> std::string { return "\03"; } - auto thousands_sep() const -> Char { return ','; } - auto decimal_point() const -> Char { return '.'; } -}; -template Facet use_facet(locale) { return {}; } -} // namespace detail -#endif // FMT_USE_LOCALE - -template auto locale_ref::get() const -> Locale { - using namespace detail; - static_assert(std::is_same::value, ""); -#if FMT_USE_LOCALE - if (locale_) return *static_cast(locale_); -#endif - return locale(); -} - -namespace detail { - -FMT_FUNC void format_error_code(detail::buffer& out, int error_code, - string_view message) noexcept { - // Report error code making sure that the output fits into - // inline_buffer_size to avoid dynamic memory allocation and potential - // bad_alloc. - out.try_resize(0); - static const char SEP[] = ": "; - static const char ERROR_STR[] = "error "; - // Subtract 2 to account for terminating null characters in SEP and ERROR_STR. - size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2; - auto abs_value = static_cast>(error_code); - if (detail::is_negative(error_code)) { - abs_value = 0 - abs_value; - ++error_code_size; - } - error_code_size += detail::to_unsigned(detail::count_digits(abs_value)); - auto it = appender(out); - if (message.size() <= inline_buffer_size - error_code_size) - fmt::format_to(it, FMT_STRING("{}{}"), message, SEP); - fmt::format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code); - FMT_ASSERT(out.size() <= inline_buffer_size, ""); -} - -FMT_FUNC void do_report_error(format_func func, int error_code, - const char* message) noexcept { - memory_buffer full_message; - func(full_message, error_code, message); - // Don't use fwrite_all because the latter may throw. - if (std::fwrite(full_message.data(), full_message.size(), 1, stderr) > 0) - std::fputc('\n', stderr); -} - -// A wrapper around fwrite that throws on error. -inline void fwrite_all(const void* ptr, size_t count, FILE* stream) { - size_t written = std::fwrite(ptr, 1, count, stream); - if (written < count) - FMT_THROW(system_error(errno, FMT_STRING("cannot write to file"))); -} - -template -FMT_FUNC auto thousands_sep_impl(locale_ref loc) -> thousands_sep_result { - auto&& facet = use_facet>(loc.get()); - auto grouping = facet.grouping(); - auto thousands_sep = grouping.empty() ? Char() : facet.thousands_sep(); - return {std::move(grouping), thousands_sep}; -} -template -FMT_FUNC auto decimal_point_impl(locale_ref loc) -> Char { - return use_facet>(loc.get()).decimal_point(); -} - -#if FMT_USE_LOCALE -FMT_FUNC auto write_loc(appender out, loc_value value, - const format_specs& specs, locale_ref loc) -> bool { - auto locale = loc.get(); - // We cannot use the num_put facet because it may produce output in - // a wrong encoding. - using facet = format_facet; - if (std::has_facet(locale)) - return use_facet(locale).put(out, value, specs); - return facet(locale).put(out, value, specs); -} -#endif -} // namespace detail - -FMT_FUNC void report_error(const char* message) { -#if FMT_MSC_VERSION || defined(__NVCC__) - // Silence unreachable code warnings in MSVC and NVCC because these - // are nearly impossible to fix in a generic code. - volatile bool b = true; - if (!b) return; -#endif - FMT_THROW(format_error(message)); -} - -template typename Locale::id format_facet::id; - -template format_facet::format_facet(Locale& loc) { - auto& np = detail::use_facet>(loc); - grouping_ = np.grouping(); - if (!grouping_.empty()) separator_ = std::string(1, np.thousands_sep()); -} - -#if FMT_USE_LOCALE -template <> -FMT_API FMT_FUNC auto format_facet::do_put( - appender out, loc_value val, const format_specs& specs) const -> bool { - return val.visit( - detail::loc_writer<>{out, specs, separator_, grouping_, decimal_point_}); -} -#endif - -FMT_FUNC auto vsystem_error(int error_code, string_view fmt, format_args args) - -> std::system_error { - auto ec = std::error_code(error_code, std::generic_category()); - return std::system_error(ec, vformat(fmt, args)); -} - -namespace detail { - -template -inline auto operator==(basic_fp x, basic_fp y) -> bool { - return x.f == y.f && x.e == y.e; -} - -// Compilers should be able to optimize this into the ror instruction. -FMT_INLINE auto rotr(uint32_t n, uint32_t r) noexcept -> uint32_t { - r &= 31; - return (n >> r) | (n << (32 - r)); -} -FMT_INLINE auto rotr(uint64_t n, uint32_t r) noexcept -> uint64_t { - r &= 63; - return (n >> r) | (n << (64 - r)); -} - -// Implementation of Dragonbox algorithm: https://github.com/jk-jeon/dragonbox. -namespace dragonbox { -// Computes upper 64 bits of multiplication of a 32-bit unsigned integer and a -// 64-bit unsigned integer. -inline auto umul96_upper64(uint32_t x, uint64_t y) noexcept -> uint64_t { - return umul128_upper64(static_cast(x) << 32, y); -} - -// Computes lower 128 bits of multiplication of a 64-bit unsigned integer and a -// 128-bit unsigned integer. -inline auto umul192_lower128(uint64_t x, uint128_fallback y) noexcept - -> uint128_fallback { - uint64_t high = x * y.high(); - uint128_fallback high_low = umul128(x, y.low()); - return {high + high_low.high(), high_low.low()}; -} - -// Computes lower 64 bits of multiplication of a 32-bit unsigned integer and a -// 64-bit unsigned integer. -inline auto umul96_lower64(uint32_t x, uint64_t y) noexcept -> uint64_t { - return x * y; -} - -// Various fast log computations. -inline auto floor_log10_pow2_minus_log10_4_over_3(int e) noexcept -> int { - FMT_ASSERT(e <= 2936 && e >= -2985, "too large exponent"); - return (e * 631305 - 261663) >> 21; -} - -FMT_INLINE_VARIABLE constexpr struct div_small_pow10_infos_struct { - uint32_t divisor; - int shift_amount; -} div_small_pow10_infos[] = {{10, 16}, {100, 16}}; - -// Replaces n by floor(n / pow(10, N)) returning true if and only if n is -// divisible by pow(10, N). -// Precondition: n <= pow(10, N + 1). -template -auto check_divisibility_and_divide_by_pow10(uint32_t& n) noexcept -> bool { - // The numbers below are chosen such that: - // 1. floor(n/d) = floor(nm / 2^k) where d=10 or d=100, - // 2. nm mod 2^k < m if and only if n is divisible by d, - // where m is magic_number, k is shift_amount - // and d is divisor. - // - // Item 1 is a common technique of replacing division by a constant with - // multiplication, see e.g. "Division by Invariant Integers Using - // Multiplication" by Granlund and Montgomery (1994). magic_number (m) is set - // to ceil(2^k/d) for large enough k. - // The idea for item 2 originates from Schubfach. - constexpr auto info = div_small_pow10_infos[N - 1]; - FMT_ASSERT(n <= info.divisor * 10, "n is too large"); - constexpr uint32_t magic_number = - (1u << info.shift_amount) / info.divisor + 1; - n *= magic_number; - const uint32_t comparison_mask = (1u << info.shift_amount) - 1; - bool result = (n & comparison_mask) < magic_number; - n >>= info.shift_amount; - return result; -} - -// Computes floor(n / pow(10, N)) for small n and N. -// Precondition: n <= pow(10, N + 1). -template auto small_division_by_pow10(uint32_t n) noexcept -> uint32_t { - constexpr auto info = div_small_pow10_infos[N - 1]; - FMT_ASSERT(n <= info.divisor * 10, "n is too large"); - constexpr uint32_t magic_number = - (1u << info.shift_amount) / info.divisor + 1; - return (n * magic_number) >> info.shift_amount; -} - -// Computes floor(n / 10^(kappa + 1)) (float) -inline auto divide_by_10_to_kappa_plus_1(uint32_t n) noexcept -> uint32_t { - // 1374389535 = ceil(2^37/100) - return static_cast((static_cast(n) * 1374389535) >> 37); -} -// Computes floor(n / 10^(kappa + 1)) (double) -inline auto divide_by_10_to_kappa_plus_1(uint64_t n) noexcept -> uint64_t { - // 2361183241434822607 = ceil(2^(64+7)/1000) - return umul128_upper64(n, 2361183241434822607ull) >> 7; -} - -// Various subroutines using pow10 cache -template struct cache_accessor; - -template <> struct cache_accessor { - using carrier_uint = float_info::carrier_uint; - using cache_entry_type = uint64_t; - - static auto get_cached_power(int k) noexcept -> uint64_t { - FMT_ASSERT(k >= float_info::min_k && k <= float_info::max_k, - "k is out of range"); - static constexpr uint64_t pow10_significands[] = { - 0x81ceb32c4b43fcf5, 0xa2425ff75e14fc32, 0xcad2f7f5359a3b3f, - 0xfd87b5f28300ca0e, 0x9e74d1b791e07e49, 0xc612062576589ddb, - 0xf79687aed3eec552, 0x9abe14cd44753b53, 0xc16d9a0095928a28, - 0xf1c90080baf72cb2, 0x971da05074da7bef, 0xbce5086492111aeb, - 0xec1e4a7db69561a6, 0x9392ee8e921d5d08, 0xb877aa3236a4b44a, - 0xe69594bec44de15c, 0x901d7cf73ab0acda, 0xb424dc35095cd810, - 0xe12e13424bb40e14, 0x8cbccc096f5088cc, 0xafebff0bcb24aaff, - 0xdbe6fecebdedd5bf, 0x89705f4136b4a598, 0xabcc77118461cefd, - 0xd6bf94d5e57a42bd, 0x8637bd05af6c69b6, 0xa7c5ac471b478424, - 0xd1b71758e219652c, 0x83126e978d4fdf3c, 0xa3d70a3d70a3d70b, - 0xcccccccccccccccd, 0x8000000000000000, 0xa000000000000000, - 0xc800000000000000, 0xfa00000000000000, 0x9c40000000000000, - 0xc350000000000000, 0xf424000000000000, 0x9896800000000000, - 0xbebc200000000000, 0xee6b280000000000, 0x9502f90000000000, - 0xba43b74000000000, 0xe8d4a51000000000, 0x9184e72a00000000, - 0xb5e620f480000000, 0xe35fa931a0000000, 0x8e1bc9bf04000000, - 0xb1a2bc2ec5000000, 0xde0b6b3a76400000, 0x8ac7230489e80000, - 0xad78ebc5ac620000, 0xd8d726b7177a8000, 0x878678326eac9000, - 0xa968163f0a57b400, 0xd3c21bcecceda100, 0x84595161401484a0, - 0xa56fa5b99019a5c8, 0xcecb8f27f4200f3a, 0x813f3978f8940985, - 0xa18f07d736b90be6, 0xc9f2c9cd04674edf, 0xfc6f7c4045812297, - 0x9dc5ada82b70b59e, 0xc5371912364ce306, 0xf684df56c3e01bc7, - 0x9a130b963a6c115d, 0xc097ce7bc90715b4, 0xf0bdc21abb48db21, - 0x96769950b50d88f5, 0xbc143fa4e250eb32, 0xeb194f8e1ae525fe, - 0x92efd1b8d0cf37bf, 0xb7abc627050305ae, 0xe596b7b0c643c71a, - 0x8f7e32ce7bea5c70, 0xb35dbf821ae4f38c, 0xe0352f62a19e306f}; - return pow10_significands[k - float_info::min_k]; - } - - struct compute_mul_result { - carrier_uint result; - bool is_integer; - }; - struct compute_mul_parity_result { - bool parity; - bool is_integer; - }; - - static auto compute_mul(carrier_uint u, - const cache_entry_type& cache) noexcept - -> compute_mul_result { - auto r = umul96_upper64(u, cache); - return {static_cast(r >> 32), - static_cast(r) == 0}; - } - - static auto compute_delta(const cache_entry_type& cache, int beta) noexcept - -> uint32_t { - return static_cast(cache >> (64 - 1 - beta)); - } - - static auto compute_mul_parity(carrier_uint two_f, - const cache_entry_type& cache, - int beta) noexcept - -> compute_mul_parity_result { - FMT_ASSERT(beta >= 1, ""); - FMT_ASSERT(beta < 64, ""); - - auto r = umul96_lower64(two_f, cache); - return {((r >> (64 - beta)) & 1) != 0, - static_cast(r >> (32 - beta)) == 0}; - } - - static auto compute_left_endpoint_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return static_cast( - (cache - (cache >> (num_significand_bits() + 2))) >> - (64 - num_significand_bits() - 1 - beta)); - } - - static auto compute_right_endpoint_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return static_cast( - (cache + (cache >> (num_significand_bits() + 1))) >> - (64 - num_significand_bits() - 1 - beta)); - } - - static auto compute_round_up_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return (static_cast( - cache >> (64 - num_significand_bits() - 2 - beta)) + - 1) / - 2; - } -}; - -template <> struct cache_accessor { - using carrier_uint = float_info::carrier_uint; - using cache_entry_type = uint128_fallback; - - static auto get_cached_power(int k) noexcept -> uint128_fallback { - FMT_ASSERT(k >= float_info::min_k && k <= float_info::max_k, - "k is out of range"); - - static constexpr uint128_fallback pow10_significands[] = { -#if FMT_USE_FULL_CACHE_DRAGONBOX - {0xff77b1fcbebcdc4f, 0x25e8e89c13bb0f7b}, - {0x9faacf3df73609b1, 0x77b191618c54e9ad}, - {0xc795830d75038c1d, 0xd59df5b9ef6a2418}, - {0xf97ae3d0d2446f25, 0x4b0573286b44ad1e}, - {0x9becce62836ac577, 0x4ee367f9430aec33}, - {0xc2e801fb244576d5, 0x229c41f793cda740}, - {0xf3a20279ed56d48a, 0x6b43527578c11110}, - {0x9845418c345644d6, 0x830a13896b78aaaa}, - {0xbe5691ef416bd60c, 0x23cc986bc656d554}, - {0xedec366b11c6cb8f, 0x2cbfbe86b7ec8aa9}, - {0x94b3a202eb1c3f39, 0x7bf7d71432f3d6aa}, - {0xb9e08a83a5e34f07, 0xdaf5ccd93fb0cc54}, - {0xe858ad248f5c22c9, 0xd1b3400f8f9cff69}, - {0x91376c36d99995be, 0x23100809b9c21fa2}, - {0xb58547448ffffb2d, 0xabd40a0c2832a78b}, - {0xe2e69915b3fff9f9, 0x16c90c8f323f516d}, - {0x8dd01fad907ffc3b, 0xae3da7d97f6792e4}, - {0xb1442798f49ffb4a, 0x99cd11cfdf41779d}, - {0xdd95317f31c7fa1d, 0x40405643d711d584}, - {0x8a7d3eef7f1cfc52, 0x482835ea666b2573}, - {0xad1c8eab5ee43b66, 0xda3243650005eed0}, - {0xd863b256369d4a40, 0x90bed43e40076a83}, - {0x873e4f75e2224e68, 0x5a7744a6e804a292}, - {0xa90de3535aaae202, 0x711515d0a205cb37}, - {0xd3515c2831559a83, 0x0d5a5b44ca873e04}, - {0x8412d9991ed58091, 0xe858790afe9486c3}, - {0xa5178fff668ae0b6, 0x626e974dbe39a873}, - {0xce5d73ff402d98e3, 0xfb0a3d212dc81290}, - {0x80fa687f881c7f8e, 0x7ce66634bc9d0b9a}, - {0xa139029f6a239f72, 0x1c1fffc1ebc44e81}, - {0xc987434744ac874e, 0xa327ffb266b56221}, - {0xfbe9141915d7a922, 0x4bf1ff9f0062baa9}, - {0x9d71ac8fada6c9b5, 0x6f773fc3603db4aa}, - {0xc4ce17b399107c22, 0xcb550fb4384d21d4}, - {0xf6019da07f549b2b, 0x7e2a53a146606a49}, - {0x99c102844f94e0fb, 0x2eda7444cbfc426e}, - {0xc0314325637a1939, 0xfa911155fefb5309}, - {0xf03d93eebc589f88, 0x793555ab7eba27cb}, - {0x96267c7535b763b5, 0x4bc1558b2f3458df}, - {0xbbb01b9283253ca2, 0x9eb1aaedfb016f17}, - {0xea9c227723ee8bcb, 0x465e15a979c1cadd}, - {0x92a1958a7675175f, 0x0bfacd89ec191eca}, - {0xb749faed14125d36, 0xcef980ec671f667c}, - {0xe51c79a85916f484, 0x82b7e12780e7401b}, - {0x8f31cc0937ae58d2, 0xd1b2ecb8b0908811}, - {0xb2fe3f0b8599ef07, 0x861fa7e6dcb4aa16}, - {0xdfbdcece67006ac9, 0x67a791e093e1d49b}, - {0x8bd6a141006042bd, 0xe0c8bb2c5c6d24e1}, - {0xaecc49914078536d, 0x58fae9f773886e19}, - {0xda7f5bf590966848, 0xaf39a475506a899f}, - {0x888f99797a5e012d, 0x6d8406c952429604}, - {0xaab37fd7d8f58178, 0xc8e5087ba6d33b84}, - {0xd5605fcdcf32e1d6, 0xfb1e4a9a90880a65}, - {0x855c3be0a17fcd26, 0x5cf2eea09a550680}, - {0xa6b34ad8c9dfc06f, 0xf42faa48c0ea481f}, - {0xd0601d8efc57b08b, 0xf13b94daf124da27}, - {0x823c12795db6ce57, 0x76c53d08d6b70859}, - {0xa2cb1717b52481ed, 0x54768c4b0c64ca6f}, - {0xcb7ddcdda26da268, 0xa9942f5dcf7dfd0a}, - {0xfe5d54150b090b02, 0xd3f93b35435d7c4d}, - {0x9efa548d26e5a6e1, 0xc47bc5014a1a6db0}, - {0xc6b8e9b0709f109a, 0x359ab6419ca1091c}, - {0xf867241c8cc6d4c0, 0xc30163d203c94b63}, - {0x9b407691d7fc44f8, 0x79e0de63425dcf1e}, - {0xc21094364dfb5636, 0x985915fc12f542e5}, - {0xf294b943e17a2bc4, 0x3e6f5b7b17b2939e}, - {0x979cf3ca6cec5b5a, 0xa705992ceecf9c43}, - {0xbd8430bd08277231, 0x50c6ff782a838354}, - {0xece53cec4a314ebd, 0xa4f8bf5635246429}, - {0x940f4613ae5ed136, 0x871b7795e136be9a}, - {0xb913179899f68584, 0x28e2557b59846e40}, - {0xe757dd7ec07426e5, 0x331aeada2fe589d0}, - {0x9096ea6f3848984f, 0x3ff0d2c85def7622}, - {0xb4bca50b065abe63, 0x0fed077a756b53aa}, - {0xe1ebce4dc7f16dfb, 0xd3e8495912c62895}, - {0x8d3360f09cf6e4bd, 0x64712dd7abbbd95d}, - {0xb080392cc4349dec, 0xbd8d794d96aacfb4}, - {0xdca04777f541c567, 0xecf0d7a0fc5583a1}, - {0x89e42caaf9491b60, 0xf41686c49db57245}, - {0xac5d37d5b79b6239, 0x311c2875c522ced6}, - {0xd77485cb25823ac7, 0x7d633293366b828c}, - {0x86a8d39ef77164bc, 0xae5dff9c02033198}, - {0xa8530886b54dbdeb, 0xd9f57f830283fdfd}, - {0xd267caa862a12d66, 0xd072df63c324fd7c}, - {0x8380dea93da4bc60, 0x4247cb9e59f71e6e}, - {0xa46116538d0deb78, 0x52d9be85f074e609}, - {0xcd795be870516656, 0x67902e276c921f8c}, - {0x806bd9714632dff6, 0x00ba1cd8a3db53b7}, - {0xa086cfcd97bf97f3, 0x80e8a40eccd228a5}, - {0xc8a883c0fdaf7df0, 0x6122cd128006b2ce}, - {0xfad2a4b13d1b5d6c, 0x796b805720085f82}, - {0x9cc3a6eec6311a63, 0xcbe3303674053bb1}, - {0xc3f490aa77bd60fc, 0xbedbfc4411068a9d}, - {0xf4f1b4d515acb93b, 0xee92fb5515482d45}, - {0x991711052d8bf3c5, 0x751bdd152d4d1c4b}, - {0xbf5cd54678eef0b6, 0xd262d45a78a0635e}, - {0xef340a98172aace4, 0x86fb897116c87c35}, - {0x9580869f0e7aac0e, 0xd45d35e6ae3d4da1}, - {0xbae0a846d2195712, 0x8974836059cca10a}, - {0xe998d258869facd7, 0x2bd1a438703fc94c}, - {0x91ff83775423cc06, 0x7b6306a34627ddd0}, - {0xb67f6455292cbf08, 0x1a3bc84c17b1d543}, - {0xe41f3d6a7377eeca, 0x20caba5f1d9e4a94}, - {0x8e938662882af53e, 0x547eb47b7282ee9d}, - {0xb23867fb2a35b28d, 0xe99e619a4f23aa44}, - {0xdec681f9f4c31f31, 0x6405fa00e2ec94d5}, - {0x8b3c113c38f9f37e, 0xde83bc408dd3dd05}, - {0xae0b158b4738705e, 0x9624ab50b148d446}, - {0xd98ddaee19068c76, 0x3badd624dd9b0958}, - {0x87f8a8d4cfa417c9, 0xe54ca5d70a80e5d7}, - {0xa9f6d30a038d1dbc, 0x5e9fcf4ccd211f4d}, - {0xd47487cc8470652b, 0x7647c32000696720}, - {0x84c8d4dfd2c63f3b, 0x29ecd9f40041e074}, - {0xa5fb0a17c777cf09, 0xf468107100525891}, - {0xcf79cc9db955c2cc, 0x7182148d4066eeb5}, - {0x81ac1fe293d599bf, 0xc6f14cd848405531}, - {0xa21727db38cb002f, 0xb8ada00e5a506a7d}, - {0xca9cf1d206fdc03b, 0xa6d90811f0e4851d}, - {0xfd442e4688bd304a, 0x908f4a166d1da664}, - {0x9e4a9cec15763e2e, 0x9a598e4e043287ff}, - {0xc5dd44271ad3cdba, 0x40eff1e1853f29fe}, - {0xf7549530e188c128, 0xd12bee59e68ef47d}, - {0x9a94dd3e8cf578b9, 0x82bb74f8301958cf}, - {0xc13a148e3032d6e7, 0xe36a52363c1faf02}, - {0xf18899b1bc3f8ca1, 0xdc44e6c3cb279ac2}, - {0x96f5600f15a7b7e5, 0x29ab103a5ef8c0ba}, - {0xbcb2b812db11a5de, 0x7415d448f6b6f0e8}, - {0xebdf661791d60f56, 0x111b495b3464ad22}, - {0x936b9fcebb25c995, 0xcab10dd900beec35}, - {0xb84687c269ef3bfb, 0x3d5d514f40eea743}, - {0xe65829b3046b0afa, 0x0cb4a5a3112a5113}, - {0x8ff71a0fe2c2e6dc, 0x47f0e785eaba72ac}, - {0xb3f4e093db73a093, 0x59ed216765690f57}, - {0xe0f218b8d25088b8, 0x306869c13ec3532d}, - {0x8c974f7383725573, 0x1e414218c73a13fc}, - {0xafbd2350644eeacf, 0xe5d1929ef90898fb}, - {0xdbac6c247d62a583, 0xdf45f746b74abf3a}, - {0x894bc396ce5da772, 0x6b8bba8c328eb784}, - {0xab9eb47c81f5114f, 0x066ea92f3f326565}, - {0xd686619ba27255a2, 0xc80a537b0efefebe}, - {0x8613fd0145877585, 0xbd06742ce95f5f37}, - {0xa798fc4196e952e7, 0x2c48113823b73705}, - {0xd17f3b51fca3a7a0, 0xf75a15862ca504c6}, - {0x82ef85133de648c4, 0x9a984d73dbe722fc}, - {0xa3ab66580d5fdaf5, 0xc13e60d0d2e0ebbb}, - {0xcc963fee10b7d1b3, 0x318df905079926a9}, - {0xffbbcfe994e5c61f, 0xfdf17746497f7053}, - {0x9fd561f1fd0f9bd3, 0xfeb6ea8bedefa634}, - {0xc7caba6e7c5382c8, 0xfe64a52ee96b8fc1}, - {0xf9bd690a1b68637b, 0x3dfdce7aa3c673b1}, - {0x9c1661a651213e2d, 0x06bea10ca65c084f}, - {0xc31bfa0fe5698db8, 0x486e494fcff30a63}, - {0xf3e2f893dec3f126, 0x5a89dba3c3efccfb}, - {0x986ddb5c6b3a76b7, 0xf89629465a75e01d}, - {0xbe89523386091465, 0xf6bbb397f1135824}, - {0xee2ba6c0678b597f, 0x746aa07ded582e2d}, - {0x94db483840b717ef, 0xa8c2a44eb4571cdd}, - {0xba121a4650e4ddeb, 0x92f34d62616ce414}, - {0xe896a0d7e51e1566, 0x77b020baf9c81d18}, - {0x915e2486ef32cd60, 0x0ace1474dc1d122f}, - {0xb5b5ada8aaff80b8, 0x0d819992132456bb}, - {0xe3231912d5bf60e6, 0x10e1fff697ed6c6a}, - {0x8df5efabc5979c8f, 0xca8d3ffa1ef463c2}, - {0xb1736b96b6fd83b3, 0xbd308ff8a6b17cb3}, - {0xddd0467c64bce4a0, 0xac7cb3f6d05ddbdf}, - {0x8aa22c0dbef60ee4, 0x6bcdf07a423aa96c}, - {0xad4ab7112eb3929d, 0x86c16c98d2c953c7}, - {0xd89d64d57a607744, 0xe871c7bf077ba8b8}, - {0x87625f056c7c4a8b, 0x11471cd764ad4973}, - {0xa93af6c6c79b5d2d, 0xd598e40d3dd89bd0}, - {0xd389b47879823479, 0x4aff1d108d4ec2c4}, - {0x843610cb4bf160cb, 0xcedf722a585139bb}, - {0xa54394fe1eedb8fe, 0xc2974eb4ee658829}, - {0xce947a3da6a9273e, 0x733d226229feea33}, - {0x811ccc668829b887, 0x0806357d5a3f5260}, - {0xa163ff802a3426a8, 0xca07c2dcb0cf26f8}, - {0xc9bcff6034c13052, 0xfc89b393dd02f0b6}, - {0xfc2c3f3841f17c67, 0xbbac2078d443ace3}, - {0x9d9ba7832936edc0, 0xd54b944b84aa4c0e}, - {0xc5029163f384a931, 0x0a9e795e65d4df12}, - {0xf64335bcf065d37d, 0x4d4617b5ff4a16d6}, - {0x99ea0196163fa42e, 0x504bced1bf8e4e46}, - {0xc06481fb9bcf8d39, 0xe45ec2862f71e1d7}, - {0xf07da27a82c37088, 0x5d767327bb4e5a4d}, - {0x964e858c91ba2655, 0x3a6a07f8d510f870}, - {0xbbe226efb628afea, 0x890489f70a55368c}, - {0xeadab0aba3b2dbe5, 0x2b45ac74ccea842f}, - {0x92c8ae6b464fc96f, 0x3b0b8bc90012929e}, - {0xb77ada0617e3bbcb, 0x09ce6ebb40173745}, - {0xe55990879ddcaabd, 0xcc420a6a101d0516}, - {0x8f57fa54c2a9eab6, 0x9fa946824a12232e}, - {0xb32df8e9f3546564, 0x47939822dc96abfa}, - {0xdff9772470297ebd, 0x59787e2b93bc56f8}, - {0x8bfbea76c619ef36, 0x57eb4edb3c55b65b}, - {0xaefae51477a06b03, 0xede622920b6b23f2}, - {0xdab99e59958885c4, 0xe95fab368e45ecee}, - {0x88b402f7fd75539b, 0x11dbcb0218ebb415}, - {0xaae103b5fcd2a881, 0xd652bdc29f26a11a}, - {0xd59944a37c0752a2, 0x4be76d3346f04960}, - {0x857fcae62d8493a5, 0x6f70a4400c562ddc}, - {0xa6dfbd9fb8e5b88e, 0xcb4ccd500f6bb953}, - {0xd097ad07a71f26b2, 0x7e2000a41346a7a8}, - {0x825ecc24c873782f, 0x8ed400668c0c28c9}, - {0xa2f67f2dfa90563b, 0x728900802f0f32fb}, - {0xcbb41ef979346bca, 0x4f2b40a03ad2ffba}, - {0xfea126b7d78186bc, 0xe2f610c84987bfa9}, - {0x9f24b832e6b0f436, 0x0dd9ca7d2df4d7ca}, - {0xc6ede63fa05d3143, 0x91503d1c79720dbc}, - {0xf8a95fcf88747d94, 0x75a44c6397ce912b}, - {0x9b69dbe1b548ce7c, 0xc986afbe3ee11abb}, - {0xc24452da229b021b, 0xfbe85badce996169}, - {0xf2d56790ab41c2a2, 0xfae27299423fb9c4}, - {0x97c560ba6b0919a5, 0xdccd879fc967d41b}, - {0xbdb6b8e905cb600f, 0x5400e987bbc1c921}, - {0xed246723473e3813, 0x290123e9aab23b69}, - {0x9436c0760c86e30b, 0xf9a0b6720aaf6522}, - {0xb94470938fa89bce, 0xf808e40e8d5b3e6a}, - {0xe7958cb87392c2c2, 0xb60b1d1230b20e05}, - {0x90bd77f3483bb9b9, 0xb1c6f22b5e6f48c3}, - {0xb4ecd5f01a4aa828, 0x1e38aeb6360b1af4}, - {0xe2280b6c20dd5232, 0x25c6da63c38de1b1}, - {0x8d590723948a535f, 0x579c487e5a38ad0f}, - {0xb0af48ec79ace837, 0x2d835a9df0c6d852}, - {0xdcdb1b2798182244, 0xf8e431456cf88e66}, - {0x8a08f0f8bf0f156b, 0x1b8e9ecb641b5900}, - {0xac8b2d36eed2dac5, 0xe272467e3d222f40}, - {0xd7adf884aa879177, 0x5b0ed81dcc6abb10}, - {0x86ccbb52ea94baea, 0x98e947129fc2b4ea}, - {0xa87fea27a539e9a5, 0x3f2398d747b36225}, - {0xd29fe4b18e88640e, 0x8eec7f0d19a03aae}, - {0x83a3eeeef9153e89, 0x1953cf68300424ad}, - {0xa48ceaaab75a8e2b, 0x5fa8c3423c052dd8}, - {0xcdb02555653131b6, 0x3792f412cb06794e}, - {0x808e17555f3ebf11, 0xe2bbd88bbee40bd1}, - {0xa0b19d2ab70e6ed6, 0x5b6aceaeae9d0ec5}, - {0xc8de047564d20a8b, 0xf245825a5a445276}, - {0xfb158592be068d2e, 0xeed6e2f0f0d56713}, - {0x9ced737bb6c4183d, 0x55464dd69685606c}, - {0xc428d05aa4751e4c, 0xaa97e14c3c26b887}, - {0xf53304714d9265df, 0xd53dd99f4b3066a9}, - {0x993fe2c6d07b7fab, 0xe546a8038efe402a}, - {0xbf8fdb78849a5f96, 0xde98520472bdd034}, - {0xef73d256a5c0f77c, 0x963e66858f6d4441}, - {0x95a8637627989aad, 0xdde7001379a44aa9}, - {0xbb127c53b17ec159, 0x5560c018580d5d53}, - {0xe9d71b689dde71af, 0xaab8f01e6e10b4a7}, - {0x9226712162ab070d, 0xcab3961304ca70e9}, - {0xb6b00d69bb55c8d1, 0x3d607b97c5fd0d23}, - {0xe45c10c42a2b3b05, 0x8cb89a7db77c506b}, - {0x8eb98a7a9a5b04e3, 0x77f3608e92adb243}, - {0xb267ed1940f1c61c, 0x55f038b237591ed4}, - {0xdf01e85f912e37a3, 0x6b6c46dec52f6689}, - {0x8b61313bbabce2c6, 0x2323ac4b3b3da016}, - {0xae397d8aa96c1b77, 0xabec975e0a0d081b}, - {0xd9c7dced53c72255, 0x96e7bd358c904a22}, - {0x881cea14545c7575, 0x7e50d64177da2e55}, - {0xaa242499697392d2, 0xdde50bd1d5d0b9ea}, - {0xd4ad2dbfc3d07787, 0x955e4ec64b44e865}, - {0x84ec3c97da624ab4, 0xbd5af13bef0b113f}, - {0xa6274bbdd0fadd61, 0xecb1ad8aeacdd58f}, - {0xcfb11ead453994ba, 0x67de18eda5814af3}, - {0x81ceb32c4b43fcf4, 0x80eacf948770ced8}, - {0xa2425ff75e14fc31, 0xa1258379a94d028e}, - {0xcad2f7f5359a3b3e, 0x096ee45813a04331}, - {0xfd87b5f28300ca0d, 0x8bca9d6e188853fd}, - {0x9e74d1b791e07e48, 0x775ea264cf55347e}, - {0xc612062576589dda, 0x95364afe032a819e}, - {0xf79687aed3eec551, 0x3a83ddbd83f52205}, - {0x9abe14cd44753b52, 0xc4926a9672793543}, - {0xc16d9a0095928a27, 0x75b7053c0f178294}, - {0xf1c90080baf72cb1, 0x5324c68b12dd6339}, - {0x971da05074da7bee, 0xd3f6fc16ebca5e04}, - {0xbce5086492111aea, 0x88f4bb1ca6bcf585}, - {0xec1e4a7db69561a5, 0x2b31e9e3d06c32e6}, - {0x9392ee8e921d5d07, 0x3aff322e62439fd0}, - {0xb877aa3236a4b449, 0x09befeb9fad487c3}, - {0xe69594bec44de15b, 0x4c2ebe687989a9b4}, - {0x901d7cf73ab0acd9, 0x0f9d37014bf60a11}, - {0xb424dc35095cd80f, 0x538484c19ef38c95}, - {0xe12e13424bb40e13, 0x2865a5f206b06fba}, - {0x8cbccc096f5088cb, 0xf93f87b7442e45d4}, - {0xafebff0bcb24aafe, 0xf78f69a51539d749}, - {0xdbe6fecebdedd5be, 0xb573440e5a884d1c}, - {0x89705f4136b4a597, 0x31680a88f8953031}, - {0xabcc77118461cefc, 0xfdc20d2b36ba7c3e}, - {0xd6bf94d5e57a42bc, 0x3d32907604691b4d}, - {0x8637bd05af6c69b5, 0xa63f9a49c2c1b110}, - {0xa7c5ac471b478423, 0x0fcf80dc33721d54}, - {0xd1b71758e219652b, 0xd3c36113404ea4a9}, - {0x83126e978d4fdf3b, 0x645a1cac083126ea}, - {0xa3d70a3d70a3d70a, 0x3d70a3d70a3d70a4}, - {0xcccccccccccccccc, 0xcccccccccccccccd}, - {0x8000000000000000, 0x0000000000000000}, - {0xa000000000000000, 0x0000000000000000}, - {0xc800000000000000, 0x0000000000000000}, - {0xfa00000000000000, 0x0000000000000000}, - {0x9c40000000000000, 0x0000000000000000}, - {0xc350000000000000, 0x0000000000000000}, - {0xf424000000000000, 0x0000000000000000}, - {0x9896800000000000, 0x0000000000000000}, - {0xbebc200000000000, 0x0000000000000000}, - {0xee6b280000000000, 0x0000000000000000}, - {0x9502f90000000000, 0x0000000000000000}, - {0xba43b74000000000, 0x0000000000000000}, - {0xe8d4a51000000000, 0x0000000000000000}, - {0x9184e72a00000000, 0x0000000000000000}, - {0xb5e620f480000000, 0x0000000000000000}, - {0xe35fa931a0000000, 0x0000000000000000}, - {0x8e1bc9bf04000000, 0x0000000000000000}, - {0xb1a2bc2ec5000000, 0x0000000000000000}, - {0xde0b6b3a76400000, 0x0000000000000000}, - {0x8ac7230489e80000, 0x0000000000000000}, - {0xad78ebc5ac620000, 0x0000000000000000}, - {0xd8d726b7177a8000, 0x0000000000000000}, - {0x878678326eac9000, 0x0000000000000000}, - {0xa968163f0a57b400, 0x0000000000000000}, - {0xd3c21bcecceda100, 0x0000000000000000}, - {0x84595161401484a0, 0x0000000000000000}, - {0xa56fa5b99019a5c8, 0x0000000000000000}, - {0xcecb8f27f4200f3a, 0x0000000000000000}, - {0x813f3978f8940984, 0x4000000000000000}, - {0xa18f07d736b90be5, 0x5000000000000000}, - {0xc9f2c9cd04674ede, 0xa400000000000000}, - {0xfc6f7c4045812296, 0x4d00000000000000}, - {0x9dc5ada82b70b59d, 0xf020000000000000}, - {0xc5371912364ce305, 0x6c28000000000000}, - {0xf684df56c3e01bc6, 0xc732000000000000}, - {0x9a130b963a6c115c, 0x3c7f400000000000}, - {0xc097ce7bc90715b3, 0x4b9f100000000000}, - {0xf0bdc21abb48db20, 0x1e86d40000000000}, - {0x96769950b50d88f4, 0x1314448000000000}, - {0xbc143fa4e250eb31, 0x17d955a000000000}, - {0xeb194f8e1ae525fd, 0x5dcfab0800000000}, - {0x92efd1b8d0cf37be, 0x5aa1cae500000000}, - {0xb7abc627050305ad, 0xf14a3d9e40000000}, - {0xe596b7b0c643c719, 0x6d9ccd05d0000000}, - {0x8f7e32ce7bea5c6f, 0xe4820023a2000000}, - {0xb35dbf821ae4f38b, 0xdda2802c8a800000}, - {0xe0352f62a19e306e, 0xd50b2037ad200000}, - {0x8c213d9da502de45, 0x4526f422cc340000}, - {0xaf298d050e4395d6, 0x9670b12b7f410000}, - {0xdaf3f04651d47b4c, 0x3c0cdd765f114000}, - {0x88d8762bf324cd0f, 0xa5880a69fb6ac800}, - {0xab0e93b6efee0053, 0x8eea0d047a457a00}, - {0xd5d238a4abe98068, 0x72a4904598d6d880}, - {0x85a36366eb71f041, 0x47a6da2b7f864750}, - {0xa70c3c40a64e6c51, 0x999090b65f67d924}, - {0xd0cf4b50cfe20765, 0xfff4b4e3f741cf6d}, - {0x82818f1281ed449f, 0xbff8f10e7a8921a5}, - {0xa321f2d7226895c7, 0xaff72d52192b6a0e}, - {0xcbea6f8ceb02bb39, 0x9bf4f8a69f764491}, - {0xfee50b7025c36a08, 0x02f236d04753d5b5}, - {0x9f4f2726179a2245, 0x01d762422c946591}, - {0xc722f0ef9d80aad6, 0x424d3ad2b7b97ef6}, - {0xf8ebad2b84e0d58b, 0xd2e0898765a7deb3}, - {0x9b934c3b330c8577, 0x63cc55f49f88eb30}, - {0xc2781f49ffcfa6d5, 0x3cbf6b71c76b25fc}, - {0xf316271c7fc3908a, 0x8bef464e3945ef7b}, - {0x97edd871cfda3a56, 0x97758bf0e3cbb5ad}, - {0xbde94e8e43d0c8ec, 0x3d52eeed1cbea318}, - {0xed63a231d4c4fb27, 0x4ca7aaa863ee4bde}, - {0x945e455f24fb1cf8, 0x8fe8caa93e74ef6b}, - {0xb975d6b6ee39e436, 0xb3e2fd538e122b45}, - {0xe7d34c64a9c85d44, 0x60dbbca87196b617}, - {0x90e40fbeea1d3a4a, 0xbc8955e946fe31ce}, - {0xb51d13aea4a488dd, 0x6babab6398bdbe42}, - {0xe264589a4dcdab14, 0xc696963c7eed2dd2}, - {0x8d7eb76070a08aec, 0xfc1e1de5cf543ca3}, - {0xb0de65388cc8ada8, 0x3b25a55f43294bcc}, - {0xdd15fe86affad912, 0x49ef0eb713f39ebf}, - {0x8a2dbf142dfcc7ab, 0x6e3569326c784338}, - {0xacb92ed9397bf996, 0x49c2c37f07965405}, - {0xd7e77a8f87daf7fb, 0xdc33745ec97be907}, - {0x86f0ac99b4e8dafd, 0x69a028bb3ded71a4}, - {0xa8acd7c0222311bc, 0xc40832ea0d68ce0d}, - {0xd2d80db02aabd62b, 0xf50a3fa490c30191}, - {0x83c7088e1aab65db, 0x792667c6da79e0fb}, - {0xa4b8cab1a1563f52, 0x577001b891185939}, - {0xcde6fd5e09abcf26, 0xed4c0226b55e6f87}, - {0x80b05e5ac60b6178, 0x544f8158315b05b5}, - {0xa0dc75f1778e39d6, 0x696361ae3db1c722}, - {0xc913936dd571c84c, 0x03bc3a19cd1e38ea}, - {0xfb5878494ace3a5f, 0x04ab48a04065c724}, - {0x9d174b2dcec0e47b, 0x62eb0d64283f9c77}, - {0xc45d1df942711d9a, 0x3ba5d0bd324f8395}, - {0xf5746577930d6500, 0xca8f44ec7ee3647a}, - {0x9968bf6abbe85f20, 0x7e998b13cf4e1ecc}, - {0xbfc2ef456ae276e8, 0x9e3fedd8c321a67f}, - {0xefb3ab16c59b14a2, 0xc5cfe94ef3ea101f}, - {0x95d04aee3b80ece5, 0xbba1f1d158724a13}, - {0xbb445da9ca61281f, 0x2a8a6e45ae8edc98}, - {0xea1575143cf97226, 0xf52d09d71a3293be}, - {0x924d692ca61be758, 0x593c2626705f9c57}, - {0xb6e0c377cfa2e12e, 0x6f8b2fb00c77836d}, - {0xe498f455c38b997a, 0x0b6dfb9c0f956448}, - {0x8edf98b59a373fec, 0x4724bd4189bd5ead}, - {0xb2977ee300c50fe7, 0x58edec91ec2cb658}, - {0xdf3d5e9bc0f653e1, 0x2f2967b66737e3ee}, - {0x8b865b215899f46c, 0xbd79e0d20082ee75}, - {0xae67f1e9aec07187, 0xecd8590680a3aa12}, - {0xda01ee641a708de9, 0xe80e6f4820cc9496}, - {0x884134fe908658b2, 0x3109058d147fdcde}, - {0xaa51823e34a7eede, 0xbd4b46f0599fd416}, - {0xd4e5e2cdc1d1ea96, 0x6c9e18ac7007c91b}, - {0x850fadc09923329e, 0x03e2cf6bc604ddb1}, - {0xa6539930bf6bff45, 0x84db8346b786151d}, - {0xcfe87f7cef46ff16, 0xe612641865679a64}, - {0x81f14fae158c5f6e, 0x4fcb7e8f3f60c07f}, - {0xa26da3999aef7749, 0xe3be5e330f38f09e}, - {0xcb090c8001ab551c, 0x5cadf5bfd3072cc6}, - {0xfdcb4fa002162a63, 0x73d9732fc7c8f7f7}, - {0x9e9f11c4014dda7e, 0x2867e7fddcdd9afb}, - {0xc646d63501a1511d, 0xb281e1fd541501b9}, - {0xf7d88bc24209a565, 0x1f225a7ca91a4227}, - {0x9ae757596946075f, 0x3375788de9b06959}, - {0xc1a12d2fc3978937, 0x0052d6b1641c83af}, - {0xf209787bb47d6b84, 0xc0678c5dbd23a49b}, - {0x9745eb4d50ce6332, 0xf840b7ba963646e1}, - {0xbd176620a501fbff, 0xb650e5a93bc3d899}, - {0xec5d3fa8ce427aff, 0xa3e51f138ab4cebf}, - {0x93ba47c980e98cdf, 0xc66f336c36b10138}, - {0xb8a8d9bbe123f017, 0xb80b0047445d4185}, - {0xe6d3102ad96cec1d, 0xa60dc059157491e6}, - {0x9043ea1ac7e41392, 0x87c89837ad68db30}, - {0xb454e4a179dd1877, 0x29babe4598c311fc}, - {0xe16a1dc9d8545e94, 0xf4296dd6fef3d67b}, - {0x8ce2529e2734bb1d, 0x1899e4a65f58660d}, - {0xb01ae745b101e9e4, 0x5ec05dcff72e7f90}, - {0xdc21a1171d42645d, 0x76707543f4fa1f74}, - {0x899504ae72497eba, 0x6a06494a791c53a9}, - {0xabfa45da0edbde69, 0x0487db9d17636893}, - {0xd6f8d7509292d603, 0x45a9d2845d3c42b7}, - {0x865b86925b9bc5c2, 0x0b8a2392ba45a9b3}, - {0xa7f26836f282b732, 0x8e6cac7768d7141f}, - {0xd1ef0244af2364ff, 0x3207d795430cd927}, - {0x8335616aed761f1f, 0x7f44e6bd49e807b9}, - {0xa402b9c5a8d3a6e7, 0x5f16206c9c6209a7}, - {0xcd036837130890a1, 0x36dba887c37a8c10}, - {0x802221226be55a64, 0xc2494954da2c978a}, - {0xa02aa96b06deb0fd, 0xf2db9baa10b7bd6d}, - {0xc83553c5c8965d3d, 0x6f92829494e5acc8}, - {0xfa42a8b73abbf48c, 0xcb772339ba1f17fa}, - {0x9c69a97284b578d7, 0xff2a760414536efc}, - {0xc38413cf25e2d70d, 0xfef5138519684abb}, - {0xf46518c2ef5b8cd1, 0x7eb258665fc25d6a}, - {0x98bf2f79d5993802, 0xef2f773ffbd97a62}, - {0xbeeefb584aff8603, 0xaafb550ffacfd8fb}, - {0xeeaaba2e5dbf6784, 0x95ba2a53f983cf39}, - {0x952ab45cfa97a0b2, 0xdd945a747bf26184}, - {0xba756174393d88df, 0x94f971119aeef9e5}, - {0xe912b9d1478ceb17, 0x7a37cd5601aab85e}, - {0x91abb422ccb812ee, 0xac62e055c10ab33b}, - {0xb616a12b7fe617aa, 0x577b986b314d600a}, - {0xe39c49765fdf9d94, 0xed5a7e85fda0b80c}, - {0x8e41ade9fbebc27d, 0x14588f13be847308}, - {0xb1d219647ae6b31c, 0x596eb2d8ae258fc9}, - {0xde469fbd99a05fe3, 0x6fca5f8ed9aef3bc}, - {0x8aec23d680043bee, 0x25de7bb9480d5855}, - {0xada72ccc20054ae9, 0xaf561aa79a10ae6b}, - {0xd910f7ff28069da4, 0x1b2ba1518094da05}, - {0x87aa9aff79042286, 0x90fb44d2f05d0843}, - {0xa99541bf57452b28, 0x353a1607ac744a54}, - {0xd3fa922f2d1675f2, 0x42889b8997915ce9}, - {0x847c9b5d7c2e09b7, 0x69956135febada12}, - {0xa59bc234db398c25, 0x43fab9837e699096}, - {0xcf02b2c21207ef2e, 0x94f967e45e03f4bc}, - {0x8161afb94b44f57d, 0x1d1be0eebac278f6}, - {0xa1ba1ba79e1632dc, 0x6462d92a69731733}, - {0xca28a291859bbf93, 0x7d7b8f7503cfdcff}, - {0xfcb2cb35e702af78, 0x5cda735244c3d43f}, - {0x9defbf01b061adab, 0x3a0888136afa64a8}, - {0xc56baec21c7a1916, 0x088aaa1845b8fdd1}, - {0xf6c69a72a3989f5b, 0x8aad549e57273d46}, - {0x9a3c2087a63f6399, 0x36ac54e2f678864c}, - {0xc0cb28a98fcf3c7f, 0x84576a1bb416a7de}, - {0xf0fdf2d3f3c30b9f, 0x656d44a2a11c51d6}, - {0x969eb7c47859e743, 0x9f644ae5a4b1b326}, - {0xbc4665b596706114, 0x873d5d9f0dde1fef}, - {0xeb57ff22fc0c7959, 0xa90cb506d155a7eb}, - {0x9316ff75dd87cbd8, 0x09a7f12442d588f3}, - {0xb7dcbf5354e9bece, 0x0c11ed6d538aeb30}, - {0xe5d3ef282a242e81, 0x8f1668c8a86da5fb}, - {0x8fa475791a569d10, 0xf96e017d694487bd}, - {0xb38d92d760ec4455, 0x37c981dcc395a9ad}, - {0xe070f78d3927556a, 0x85bbe253f47b1418}, - {0x8c469ab843b89562, 0x93956d7478ccec8f}, - {0xaf58416654a6babb, 0x387ac8d1970027b3}, - {0xdb2e51bfe9d0696a, 0x06997b05fcc0319f}, - {0x88fcf317f22241e2, 0x441fece3bdf81f04}, - {0xab3c2fddeeaad25a, 0xd527e81cad7626c4}, - {0xd60b3bd56a5586f1, 0x8a71e223d8d3b075}, - {0x85c7056562757456, 0xf6872d5667844e4a}, - {0xa738c6bebb12d16c, 0xb428f8ac016561dc}, - {0xd106f86e69d785c7, 0xe13336d701beba53}, - {0x82a45b450226b39c, 0xecc0024661173474}, - {0xa34d721642b06084, 0x27f002d7f95d0191}, - {0xcc20ce9bd35c78a5, 0x31ec038df7b441f5}, - {0xff290242c83396ce, 0x7e67047175a15272}, - {0x9f79a169bd203e41, 0x0f0062c6e984d387}, - {0xc75809c42c684dd1, 0x52c07b78a3e60869}, - {0xf92e0c3537826145, 0xa7709a56ccdf8a83}, - {0x9bbcc7a142b17ccb, 0x88a66076400bb692}, - {0xc2abf989935ddbfe, 0x6acff893d00ea436}, - {0xf356f7ebf83552fe, 0x0583f6b8c4124d44}, - {0x98165af37b2153de, 0xc3727a337a8b704b}, - {0xbe1bf1b059e9a8d6, 0x744f18c0592e4c5d}, - {0xeda2ee1c7064130c, 0x1162def06f79df74}, - {0x9485d4d1c63e8be7, 0x8addcb5645ac2ba9}, - {0xb9a74a0637ce2ee1, 0x6d953e2bd7173693}, - {0xe8111c87c5c1ba99, 0xc8fa8db6ccdd0438}, - {0x910ab1d4db9914a0, 0x1d9c9892400a22a3}, - {0xb54d5e4a127f59c8, 0x2503beb6d00cab4c}, - {0xe2a0b5dc971f303a, 0x2e44ae64840fd61e}, - {0x8da471a9de737e24, 0x5ceaecfed289e5d3}, - {0xb10d8e1456105dad, 0x7425a83e872c5f48}, - {0xdd50f1996b947518, 0xd12f124e28f7771a}, - {0x8a5296ffe33cc92f, 0x82bd6b70d99aaa70}, - {0xace73cbfdc0bfb7b, 0x636cc64d1001550c}, - {0xd8210befd30efa5a, 0x3c47f7e05401aa4f}, - {0x8714a775e3e95c78, 0x65acfaec34810a72}, - {0xa8d9d1535ce3b396, 0x7f1839a741a14d0e}, - {0xd31045a8341ca07c, 0x1ede48111209a051}, - {0x83ea2b892091e44d, 0x934aed0aab460433}, - {0xa4e4b66b68b65d60, 0xf81da84d56178540}, - {0xce1de40642e3f4b9, 0x36251260ab9d668f}, - {0x80d2ae83e9ce78f3, 0xc1d72b7c6b42601a}, - {0xa1075a24e4421730, 0xb24cf65b8612f820}, - {0xc94930ae1d529cfc, 0xdee033f26797b628}, - {0xfb9b7cd9a4a7443c, 0x169840ef017da3b2}, - {0x9d412e0806e88aa5, 0x8e1f289560ee864f}, - {0xc491798a08a2ad4e, 0xf1a6f2bab92a27e3}, - {0xf5b5d7ec8acb58a2, 0xae10af696774b1dc}, - {0x9991a6f3d6bf1765, 0xacca6da1e0a8ef2a}, - {0xbff610b0cc6edd3f, 0x17fd090a58d32af4}, - {0xeff394dcff8a948e, 0xddfc4b4cef07f5b1}, - {0x95f83d0a1fb69cd9, 0x4abdaf101564f98f}, - {0xbb764c4ca7a4440f, 0x9d6d1ad41abe37f2}, - {0xea53df5fd18d5513, 0x84c86189216dc5ee}, - {0x92746b9be2f8552c, 0x32fd3cf5b4e49bb5}, - {0xb7118682dbb66a77, 0x3fbc8c33221dc2a2}, - {0xe4d5e82392a40515, 0x0fabaf3feaa5334b}, - {0x8f05b1163ba6832d, 0x29cb4d87f2a7400f}, - {0xb2c71d5bca9023f8, 0x743e20e9ef511013}, - {0xdf78e4b2bd342cf6, 0x914da9246b255417}, - {0x8bab8eefb6409c1a, 0x1ad089b6c2f7548f}, - {0xae9672aba3d0c320, 0xa184ac2473b529b2}, - {0xda3c0f568cc4f3e8, 0xc9e5d72d90a2741f}, - {0x8865899617fb1871, 0x7e2fa67c7a658893}, - {0xaa7eebfb9df9de8d, 0xddbb901b98feeab8}, - {0xd51ea6fa85785631, 0x552a74227f3ea566}, - {0x8533285c936b35de, 0xd53a88958f872760}, - {0xa67ff273b8460356, 0x8a892abaf368f138}, - {0xd01fef10a657842c, 0x2d2b7569b0432d86}, - {0x8213f56a67f6b29b, 0x9c3b29620e29fc74}, - {0xa298f2c501f45f42, 0x8349f3ba91b47b90}, - {0xcb3f2f7642717713, 0x241c70a936219a74}, - {0xfe0efb53d30dd4d7, 0xed238cd383aa0111}, - {0x9ec95d1463e8a506, 0xf4363804324a40ab}, - {0xc67bb4597ce2ce48, 0xb143c6053edcd0d6}, - {0xf81aa16fdc1b81da, 0xdd94b7868e94050b}, - {0x9b10a4e5e9913128, 0xca7cf2b4191c8327}, - {0xc1d4ce1f63f57d72, 0xfd1c2f611f63a3f1}, - {0xf24a01a73cf2dccf, 0xbc633b39673c8ced}, - {0x976e41088617ca01, 0xd5be0503e085d814}, - {0xbd49d14aa79dbc82, 0x4b2d8644d8a74e19}, - {0xec9c459d51852ba2, 0xddf8e7d60ed1219f}, - {0x93e1ab8252f33b45, 0xcabb90e5c942b504}, - {0xb8da1662e7b00a17, 0x3d6a751f3b936244}, - {0xe7109bfba19c0c9d, 0x0cc512670a783ad5}, - {0x906a617d450187e2, 0x27fb2b80668b24c6}, - {0xb484f9dc9641e9da, 0xb1f9f660802dedf7}, - {0xe1a63853bbd26451, 0x5e7873f8a0396974}, - {0x8d07e33455637eb2, 0xdb0b487b6423e1e9}, - {0xb049dc016abc5e5f, 0x91ce1a9a3d2cda63}, - {0xdc5c5301c56b75f7, 0x7641a140cc7810fc}, - {0x89b9b3e11b6329ba, 0xa9e904c87fcb0a9e}, - {0xac2820d9623bf429, 0x546345fa9fbdcd45}, - {0xd732290fbacaf133, 0xa97c177947ad4096}, - {0x867f59a9d4bed6c0, 0x49ed8eabcccc485e}, - {0xa81f301449ee8c70, 0x5c68f256bfff5a75}, - {0xd226fc195c6a2f8c, 0x73832eec6fff3112}, - {0x83585d8fd9c25db7, 0xc831fd53c5ff7eac}, - {0xa42e74f3d032f525, 0xba3e7ca8b77f5e56}, - {0xcd3a1230c43fb26f, 0x28ce1bd2e55f35ec}, - {0x80444b5e7aa7cf85, 0x7980d163cf5b81b4}, - {0xa0555e361951c366, 0xd7e105bcc3326220}, - {0xc86ab5c39fa63440, 0x8dd9472bf3fefaa8}, - {0xfa856334878fc150, 0xb14f98f6f0feb952}, - {0x9c935e00d4b9d8d2, 0x6ed1bf9a569f33d4}, - {0xc3b8358109e84f07, 0x0a862f80ec4700c9}, - {0xf4a642e14c6262c8, 0xcd27bb612758c0fb}, - {0x98e7e9cccfbd7dbd, 0x8038d51cb897789d}, - {0xbf21e44003acdd2c, 0xe0470a63e6bd56c4}, - {0xeeea5d5004981478, 0x1858ccfce06cac75}, - {0x95527a5202df0ccb, 0x0f37801e0c43ebc9}, - {0xbaa718e68396cffd, 0xd30560258f54e6bb}, - {0xe950df20247c83fd, 0x47c6b82ef32a206a}, - {0x91d28b7416cdd27e, 0x4cdc331d57fa5442}, - {0xb6472e511c81471d, 0xe0133fe4adf8e953}, - {0xe3d8f9e563a198e5, 0x58180fddd97723a7}, - {0x8e679c2f5e44ff8f, 0x570f09eaa7ea7649}, - {0xb201833b35d63f73, 0x2cd2cc6551e513db}, - {0xde81e40a034bcf4f, 0xf8077f7ea65e58d2}, - {0x8b112e86420f6191, 0xfb04afaf27faf783}, - {0xadd57a27d29339f6, 0x79c5db9af1f9b564}, - {0xd94ad8b1c7380874, 0x18375281ae7822bd}, - {0x87cec76f1c830548, 0x8f2293910d0b15b6}, - {0xa9c2794ae3a3c69a, 0xb2eb3875504ddb23}, - {0xd433179d9c8cb841, 0x5fa60692a46151ec}, - {0x849feec281d7f328, 0xdbc7c41ba6bcd334}, - {0xa5c7ea73224deff3, 0x12b9b522906c0801}, - {0xcf39e50feae16bef, 0xd768226b34870a01}, - {0x81842f29f2cce375, 0xe6a1158300d46641}, - {0xa1e53af46f801c53, 0x60495ae3c1097fd1}, - {0xca5e89b18b602368, 0x385bb19cb14bdfc5}, - {0xfcf62c1dee382c42, 0x46729e03dd9ed7b6}, - {0x9e19db92b4e31ba9, 0x6c07a2c26a8346d2}, - {0xc5a05277621be293, 0xc7098b7305241886}, - {0xf70867153aa2db38, 0xb8cbee4fc66d1ea8}, - {0x9a65406d44a5c903, 0x737f74f1dc043329}, - {0xc0fe908895cf3b44, 0x505f522e53053ff3}, - {0xf13e34aabb430a15, 0x647726b9e7c68ff0}, - {0x96c6e0eab509e64d, 0x5eca783430dc19f6}, - {0xbc789925624c5fe0, 0xb67d16413d132073}, - {0xeb96bf6ebadf77d8, 0xe41c5bd18c57e890}, - {0x933e37a534cbaae7, 0x8e91b962f7b6f15a}, - {0xb80dc58e81fe95a1, 0x723627bbb5a4adb1}, - {0xe61136f2227e3b09, 0xcec3b1aaa30dd91d}, - {0x8fcac257558ee4e6, 0x213a4f0aa5e8a7b2}, - {0xb3bd72ed2af29e1f, 0xa988e2cd4f62d19e}, - {0xe0accfa875af45a7, 0x93eb1b80a33b8606}, - {0x8c6c01c9498d8b88, 0xbc72f130660533c4}, - {0xaf87023b9bf0ee6a, 0xeb8fad7c7f8680b5}, - {0xdb68c2ca82ed2a05, 0xa67398db9f6820e2}, -#else - {0xff77b1fcbebcdc4f, 0x25e8e89c13bb0f7b}, - {0xce5d73ff402d98e3, 0xfb0a3d212dc81290}, - {0xa6b34ad8c9dfc06f, 0xf42faa48c0ea481f}, - {0x86a8d39ef77164bc, 0xae5dff9c02033198}, - {0xd98ddaee19068c76, 0x3badd624dd9b0958}, - {0xafbd2350644eeacf, 0xe5d1929ef90898fb}, - {0x8df5efabc5979c8f, 0xca8d3ffa1ef463c2}, - {0xe55990879ddcaabd, 0xcc420a6a101d0516}, - {0xb94470938fa89bce, 0xf808e40e8d5b3e6a}, - {0x95a8637627989aad, 0xdde7001379a44aa9}, - {0xf1c90080baf72cb1, 0x5324c68b12dd6339}, - {0xc350000000000000, 0x0000000000000000}, - {0x9dc5ada82b70b59d, 0xf020000000000000}, - {0xfee50b7025c36a08, 0x02f236d04753d5b5}, - {0xcde6fd5e09abcf26, 0xed4c0226b55e6f87}, - {0xa6539930bf6bff45, 0x84db8346b786151d}, - {0x865b86925b9bc5c2, 0x0b8a2392ba45a9b3}, - {0xd910f7ff28069da4, 0x1b2ba1518094da05}, - {0xaf58416654a6babb, 0x387ac8d1970027b3}, - {0x8da471a9de737e24, 0x5ceaecfed289e5d3}, - {0xe4d5e82392a40515, 0x0fabaf3feaa5334b}, - {0xb8da1662e7b00a17, 0x3d6a751f3b936244}, - {0x95527a5202df0ccb, 0x0f37801e0c43ebc9}, - {0xf13e34aabb430a15, 0x647726b9e7c68ff0} -#endif - }; - -#if FMT_USE_FULL_CACHE_DRAGONBOX - return pow10_significands[k - float_info::min_k]; -#else - static constexpr uint64_t powers_of_5_64[] = { - 0x0000000000000001, 0x0000000000000005, 0x0000000000000019, - 0x000000000000007d, 0x0000000000000271, 0x0000000000000c35, - 0x0000000000003d09, 0x000000000001312d, 0x000000000005f5e1, - 0x00000000001dcd65, 0x00000000009502f9, 0x0000000002e90edd, - 0x000000000e8d4a51, 0x0000000048c27395, 0x000000016bcc41e9, - 0x000000071afd498d, 0x0000002386f26fc1, 0x000000b1a2bc2ec5, - 0x000003782dace9d9, 0x00001158e460913d, 0x000056bc75e2d631, - 0x0001b1ae4d6e2ef5, 0x000878678326eac9, 0x002a5a058fc295ed, - 0x00d3c21bcecceda1, 0x0422ca8b0a00a425, 0x14adf4b7320334b9}; - - static const int compression_ratio = 27; - - // Compute base index. - int cache_index = (k - float_info::min_k) / compression_ratio; - int kb = cache_index * compression_ratio + float_info::min_k; - int offset = k - kb; - - // Get base cache. - uint128_fallback base_cache = pow10_significands[cache_index]; - if (offset == 0) return base_cache; - - // Compute the required amount of bit-shift. - int alpha = floor_log2_pow10(kb + offset) - floor_log2_pow10(kb) - offset; - FMT_ASSERT(alpha > 0 && alpha < 64, "shifting error detected"); - - // Try to recover the real cache. - uint64_t pow5 = powers_of_5_64[offset]; - uint128_fallback recovered_cache = umul128(base_cache.high(), pow5); - uint128_fallback middle_low = umul128(base_cache.low(), pow5); - - recovered_cache += middle_low.high(); - - uint64_t high_to_middle = recovered_cache.high() << (64 - alpha); - uint64_t middle_to_low = recovered_cache.low() << (64 - alpha); - - recovered_cache = - uint128_fallback{(recovered_cache.low() >> alpha) | high_to_middle, - ((middle_low.low() >> alpha) | middle_to_low)}; - FMT_ASSERT(recovered_cache.low() + 1 != 0, ""); - return {recovered_cache.high(), recovered_cache.low() + 1}; -#endif - } - - struct compute_mul_result { - carrier_uint result; - bool is_integer; - }; - struct compute_mul_parity_result { - bool parity; - bool is_integer; - }; - - static auto compute_mul(carrier_uint u, - const cache_entry_type& cache) noexcept - -> compute_mul_result { - auto r = umul192_upper128(u, cache); - return {r.high(), r.low() == 0}; - } - - static auto compute_delta(const cache_entry_type& cache, int beta) noexcept - -> uint32_t { - return static_cast(cache.high() >> (64 - 1 - beta)); - } - - static auto compute_mul_parity(carrier_uint two_f, - const cache_entry_type& cache, - int beta) noexcept - -> compute_mul_parity_result { - FMT_ASSERT(beta >= 1, ""); - FMT_ASSERT(beta < 64, ""); - - auto r = umul192_lower128(two_f, cache); - return {((r.high() >> (64 - beta)) & 1) != 0, - ((r.high() << beta) | (r.low() >> (64 - beta))) == 0}; - } - - static auto compute_left_endpoint_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return (cache.high() - - (cache.high() >> (num_significand_bits() + 2))) >> - (64 - num_significand_bits() - 1 - beta); - } - - static auto compute_right_endpoint_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return (cache.high() + - (cache.high() >> (num_significand_bits() + 1))) >> - (64 - num_significand_bits() - 1 - beta); - } - - static auto compute_round_up_for_shorter_interval_case( - const cache_entry_type& cache, int beta) noexcept -> carrier_uint { - return ((cache.high() >> (64 - num_significand_bits() - 2 - beta)) + - 1) / - 2; - } -}; - -FMT_FUNC auto get_cached_power(int k) noexcept -> uint128_fallback { - return cache_accessor::get_cached_power(k); -} - -// Various integer checks -template -auto is_left_endpoint_integer_shorter_interval(int exponent) noexcept -> bool { - const int case_shorter_interval_left_endpoint_lower_threshold = 2; - const int case_shorter_interval_left_endpoint_upper_threshold = 3; - return exponent >= case_shorter_interval_left_endpoint_lower_threshold && - exponent <= case_shorter_interval_left_endpoint_upper_threshold; -} - -// Remove trailing zeros from n and return the number of zeros removed (float). -FMT_INLINE auto remove_trailing_zeros(uint32_t& n, int s = 0) noexcept -> int { - FMT_ASSERT(n != 0, ""); - // Modular inverse of 5 (mod 2^32): (mod_inv_5 * 5) mod 2^32 = 1. - constexpr uint32_t mod_inv_5 = 0xcccccccd; - constexpr uint32_t mod_inv_25 = 0xc28f5c29; // = mod_inv_5 * mod_inv_5 - - while (true) { - auto q = rotr(n * mod_inv_25, 2); - if (q > max_value() / 100) break; - n = q; - s += 2; - } - auto q = rotr(n * mod_inv_5, 1); - if (q <= max_value() / 10) { - n = q; - s |= 1; - } - return s; -} - -// Removes trailing zeros and returns the number of zeros removed (double). -FMT_INLINE auto remove_trailing_zeros(uint64_t& n) noexcept -> int { - FMT_ASSERT(n != 0, ""); - - // Is n is divisible by 10^8? - constexpr uint32_t ten_pow_8 = 100000000u; - if ((n % ten_pow_8) == 0) { - // If yes, work with the quotient... - auto n32 = static_cast(n / ten_pow_8); - // ... and use the 32 bit variant of the function - int num_zeros = remove_trailing_zeros(n32, 8); - n = n32; - return num_zeros; - } - - // If n is not divisible by 10^8, work with n itself. - constexpr uint64_t mod_inv_5 = 0xcccccccccccccccd; - constexpr uint64_t mod_inv_25 = 0x8f5c28f5c28f5c29; // mod_inv_5 * mod_inv_5 - - int s = 0; - while (true) { - auto q = rotr(n * mod_inv_25, 2); - if (q > max_value() / 100) break; - n = q; - s += 2; - } - auto q = rotr(n * mod_inv_5, 1); - if (q <= max_value() / 10) { - n = q; - s |= 1; - } - - return s; -} - -// The main algorithm for shorter interval case -template -FMT_INLINE auto shorter_interval_case(int exponent) noexcept -> decimal_fp { - decimal_fp ret_value; - // Compute k and beta - const int minus_k = floor_log10_pow2_minus_log10_4_over_3(exponent); - const int beta = exponent + floor_log2_pow10(-minus_k); - - // Compute xi and zi - using cache_entry_type = typename cache_accessor::cache_entry_type; - const cache_entry_type cache = cache_accessor::get_cached_power(-minus_k); - - auto xi = cache_accessor::compute_left_endpoint_for_shorter_interval_case( - cache, beta); - auto zi = cache_accessor::compute_right_endpoint_for_shorter_interval_case( - cache, beta); - - // If the left endpoint is not an integer, increase it - if (!is_left_endpoint_integer_shorter_interval(exponent)) ++xi; - - // Try bigger divisor - ret_value.significand = zi / 10; - - // If succeed, remove trailing zeros if necessary and return - if (ret_value.significand * 10 >= xi) { - ret_value.exponent = minus_k + 1; - ret_value.exponent += remove_trailing_zeros(ret_value.significand); - return ret_value; - } - - // Otherwise, compute the round-up of y - ret_value.significand = - cache_accessor::compute_round_up_for_shorter_interval_case(cache, - beta); - ret_value.exponent = minus_k; - - // When tie occurs, choose one of them according to the rule - if (exponent >= float_info::shorter_interval_tie_lower_threshold && - exponent <= float_info::shorter_interval_tie_upper_threshold) { - ret_value.significand = ret_value.significand % 2 == 0 - ? ret_value.significand - : ret_value.significand - 1; - } else if (ret_value.significand < xi) { - ++ret_value.significand; - } - return ret_value; -} - -template auto to_decimal(T x) noexcept -> decimal_fp { - // Step 1: integer promotion & Schubfach multiplier calculation. - - using carrier_uint = typename float_info::carrier_uint; - using cache_entry_type = typename cache_accessor::cache_entry_type; - auto br = bit_cast(x); - - // Extract significand bits and exponent bits. - const carrier_uint significand_mask = - (static_cast(1) << num_significand_bits()) - 1; - carrier_uint significand = (br & significand_mask); - int exponent = - static_cast((br & exponent_mask()) >> num_significand_bits()); - - if (exponent != 0) { // Check if normal. - exponent -= exponent_bias() + num_significand_bits(); - - // Shorter interval case; proceed like Schubfach. - // In fact, when exponent == 1 and significand == 0, the interval is - // regular. However, it can be shown that the end-results are anyway same. - if (significand == 0) return shorter_interval_case(exponent); - - significand |= (static_cast(1) << num_significand_bits()); - } else { - // Subnormal case; the interval is always regular. - if (significand == 0) return {0, 0}; - exponent = - std::numeric_limits::min_exponent - num_significand_bits() - 1; - } - - const bool include_left_endpoint = (significand % 2 == 0); - const bool include_right_endpoint = include_left_endpoint; - - // Compute k and beta. - const int minus_k = floor_log10_pow2(exponent) - float_info::kappa; - const cache_entry_type cache = cache_accessor::get_cached_power(-minus_k); - const int beta = exponent + floor_log2_pow10(-minus_k); - - // Compute zi and deltai. - // 10^kappa <= deltai < 10^(kappa + 1) - const uint32_t deltai = cache_accessor::compute_delta(cache, beta); - const carrier_uint two_fc = significand << 1; - - // For the case of binary32, the result of integer check is not correct for - // 29711844 * 2^-82 - // = 6.1442653300000000008655037797566933477355632930994033813476... * 10^-18 - // and 29711844 * 2^-81 - // = 1.2288530660000000001731007559513386695471126586198806762695... * 10^-17, - // and they are the unique counterexamples. However, since 29711844 is even, - // this does not cause any problem for the endpoints calculations; it can only - // cause a problem when we need to perform integer check for the center. - // Fortunately, with these inputs, that branch is never executed, so we are - // fine. - const typename cache_accessor::compute_mul_result z_mul = - cache_accessor::compute_mul((two_fc | 1) << beta, cache); - - // Step 2: Try larger divisor; remove trailing zeros if necessary. - - // Using an upper bound on zi, we might be able to optimize the division - // better than the compiler; we are computing zi / big_divisor here. - decimal_fp ret_value; - ret_value.significand = divide_by_10_to_kappa_plus_1(z_mul.result); - uint32_t r = static_cast(z_mul.result - float_info::big_divisor * - ret_value.significand); - - if (r < deltai) { - // Exclude the right endpoint if necessary. - if (r == 0 && (z_mul.is_integer & !include_right_endpoint)) { - --ret_value.significand; - r = float_info::big_divisor; - goto small_divisor_case_label; - } - } else if (r > deltai) { - goto small_divisor_case_label; - } else { - // r == deltai; compare fractional parts. - const typename cache_accessor::compute_mul_parity_result x_mul = - cache_accessor::compute_mul_parity(two_fc - 1, cache, beta); - - if (!(x_mul.parity | (x_mul.is_integer & include_left_endpoint))) - goto small_divisor_case_label; - } - ret_value.exponent = minus_k + float_info::kappa + 1; - - // We may need to remove trailing zeros. - ret_value.exponent += remove_trailing_zeros(ret_value.significand); - return ret_value; - - // Step 3: Find the significand with the smaller divisor. - -small_divisor_case_label: - ret_value.significand *= 10; - ret_value.exponent = minus_k + float_info::kappa; - - uint32_t dist = r - (deltai / 2) + (float_info::small_divisor / 2); - const bool approx_y_parity = - ((dist ^ (float_info::small_divisor / 2)) & 1) != 0; - - // Is dist divisible by 10^kappa? - const bool divisible_by_small_divisor = - check_divisibility_and_divide_by_pow10::kappa>(dist); - - // Add dist / 10^kappa to the significand. - ret_value.significand += dist; - - if (!divisible_by_small_divisor) return ret_value; - - // Check z^(f) >= epsilon^(f). - // We have either yi == zi - epsiloni or yi == (zi - epsiloni) - 1, - // where yi == zi - epsiloni if and only if z^(f) >= epsilon^(f). - // Since there are only 2 possibilities, we only need to care about the - // parity. Also, zi and r should have the same parity since the divisor - // is an even number. - const auto y_mul = cache_accessor::compute_mul_parity(two_fc, cache, beta); - - // If z^(f) >= epsilon^(f), we might have a tie when z^(f) == epsilon^(f), - // or equivalently, when y is an integer. - if (y_mul.parity != approx_y_parity) - --ret_value.significand; - else if (y_mul.is_integer & (ret_value.significand % 2 != 0)) - --ret_value.significand; - return ret_value; -} -} // namespace dragonbox -} // namespace detail - -template <> struct formatter { - FMT_CONSTEXPR auto parse(format_parse_context& ctx) - -> format_parse_context::iterator { - return ctx.begin(); - } - - auto format(const detail::bigint& n, format_context& ctx) const - -> format_context::iterator { - auto out = ctx.out(); - bool first = true; - for (auto i = n.bigits_.size(); i > 0; --i) { - auto value = n.bigits_[i - 1u]; - if (first) { - out = fmt::format_to(out, FMT_STRING("{:x}"), value); - first = false; - continue; - } - out = fmt::format_to(out, FMT_STRING("{:08x}"), value); - } - if (n.exp_ > 0) - out = fmt::format_to(out, FMT_STRING("p{}"), - n.exp_ * detail::bigint::bigit_bits); - return out; - } -}; - -FMT_FUNC detail::utf8_to_utf16::utf8_to_utf16(string_view s) { - for_each_codepoint(s, [this](uint32_t cp, string_view) { - if (cp == invalid_code_point) FMT_THROW(std::runtime_error("invalid utf8")); - if (cp <= 0xFFFF) { - buffer_.push_back(static_cast(cp)); - } else { - cp -= 0x10000; - buffer_.push_back(static_cast(0xD800 + (cp >> 10))); - buffer_.push_back(static_cast(0xDC00 + (cp & 0x3FF))); - } - return true; - }); - buffer_.push_back(0); -} - -FMT_FUNC void format_system_error(detail::buffer& out, int error_code, - const char* message) noexcept { - FMT_TRY { - auto ec = std::error_code(error_code, std::generic_category()); - detail::write(appender(out), std::system_error(ec, message).what()); - return; - } - FMT_CATCH(...) {} - format_error_code(out, error_code, message); -} - -FMT_FUNC void report_system_error(int error_code, - const char* message) noexcept { - do_report_error(format_system_error, error_code, message); -} - -FMT_FUNC auto vformat(string_view fmt, format_args args) -> std::string { - // Don't optimize the "{}" case to keep the binary size small and because it - // can be better optimized in fmt::format anyway. - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - return to_string(buffer); -} - -namespace detail { - -FMT_FUNC void vformat_to(buffer& buf, string_view fmt, format_args args, - locale_ref loc) { - auto out = appender(buf); - if (fmt.size() == 2 && equal2(fmt.data(), "{}")) - return args.get(0).visit(default_arg_formatter{out}); - parse_format_string(fmt, - format_handler<>{parse_context<>(fmt), {out, args, loc}}); -} - -template struct span { - T* data; - size_t size; -}; - -template auto flockfile(F* f) -> decltype(_lock_file(f)) { - _lock_file(f); -} -template auto funlockfile(F* f) -> decltype(_unlock_file(f)) { - _unlock_file(f); -} - -#ifndef getc_unlocked -template auto getc_unlocked(F* f) -> decltype(_fgetc_nolock(f)) { - return _fgetc_nolock(f); -} -#endif - -template -struct has_flockfile : std::false_type {}; - -template -struct has_flockfile()))>> - : std::true_type {}; - -// A FILE wrapper. F is FILE defined as a template parameter to make system API -// detection work. -template class file_base { - public: - F* file_; - - public: - file_base(F* file) : file_(file) {} - operator F*() const { return file_; } - - // Reads a code unit from the stream. - auto get() -> int { - int result = getc_unlocked(file_); - if (result == EOF && ferror(file_) != 0) - FMT_THROW(system_error(errno, FMT_STRING("getc failed"))); - return result; - } - - // Puts the code unit back into the stream buffer. - void unget(char c) { - if (ungetc(c, file_) == EOF) - FMT_THROW(system_error(errno, FMT_STRING("ungetc failed"))); - } - - void flush() { fflush(this->file_); } -}; - -// A FILE wrapper for glibc. -template class glibc_file : public file_base { - private: - enum { - line_buffered = 0x200, // _IO_LINE_BUF - unbuffered = 2 // _IO_UNBUFFERED - }; - - public: - using file_base::file_base; - - auto is_buffered() const -> bool { - return (this->file_->_flags & unbuffered) == 0; - } - - void init_buffer() { - if (this->file_->_IO_write_ptr < this->file_->_IO_write_end) return; - // Force buffer initialization by placing and removing a char in a buffer. - putc_unlocked(0, this->file_); - --this->file_->_IO_write_ptr; - } - - // Returns the file's read buffer. - auto get_read_buffer() const -> span { - auto ptr = this->file_->_IO_read_ptr; - return {ptr, to_unsigned(this->file_->_IO_read_end - ptr)}; - } - - // Returns the file's write buffer. - auto get_write_buffer() const -> span { - auto ptr = this->file_->_IO_write_ptr; - return {ptr, to_unsigned(this->file_->_IO_buf_end - ptr)}; - } - - void advance_write_buffer(size_t size) { this->file_->_IO_write_ptr += size; } - - auto needs_flush() const -> bool { - if ((this->file_->_flags & line_buffered) == 0) return false; - char* end = this->file_->_IO_write_end; - auto size = max_of(this->file_->_IO_write_ptr - end, 0); - return memchr(end, '\n', static_cast(size)); - } - - void flush() { fflush_unlocked(this->file_); } -}; - -// A FILE wrapper for Apple's libc. -template class apple_file : public file_base { - private: - enum { - line_buffered = 1, // __SNBF - unbuffered = 2 // __SLBF - }; - - public: - using file_base::file_base; - - auto is_buffered() const -> bool { - return (this->file_->_flags & unbuffered) == 0; - } - - void init_buffer() { - if (this->file_->_p) return; - // Force buffer initialization by placing and removing a char in a buffer. - if (!FMT_CLANG_ANALYZER) putc_unlocked(0, this->file_); - --this->file_->_p; - ++this->file_->_w; - } - - auto get_read_buffer() const -> span { - return {reinterpret_cast(this->file_->_p), - to_unsigned(this->file_->_r)}; - } - - auto get_write_buffer() const -> span { - return {reinterpret_cast(this->file_->_p), - to_unsigned(this->file_->_bf._base + this->file_->_bf._size - - this->file_->_p)}; - } - - void advance_write_buffer(size_t size) { - this->file_->_p += size; - this->file_->_w -= size; - } - - auto needs_flush() const -> bool { - if ((this->file_->_flags & line_buffered) == 0) return false; - return memchr(this->file_->_p + this->file_->_w, '\n', - to_unsigned(-this->file_->_w)); - } -}; - -// A fallback FILE wrapper. -template class fallback_file : public file_base { - private: - char next_; // The next unconsumed character in the buffer. - bool has_next_ = false; - - public: - using file_base::file_base; - - auto is_buffered() const -> bool { return false; } - auto needs_flush() const -> bool { return false; } - void init_buffer() {} - - auto get_read_buffer() const -> span { - return {&next_, has_next_ ? 1u : 0u}; - } - - auto get_write_buffer() const -> span { return {nullptr, 0}; } - - void advance_write_buffer(size_t) {} - - auto get() -> int { - has_next_ = false; - return file_base::get(); - } - - void unget(char c) { - file_base::unget(c); - next_ = c; - has_next_ = true; - } -}; - -#ifndef FMT_USE_FALLBACK_FILE -# define FMT_USE_FALLBACK_FILE 0 -#endif - -template -auto get_file(F* f, int) -> apple_file { - return f; -} -template -inline auto get_file(F* f, int) -> glibc_file { - return f; -} - -inline auto get_file(FILE* f, ...) -> fallback_file { return f; } - -using file_ref = decltype(get_file(static_cast(nullptr), 0)); - -template -class file_print_buffer : public buffer { - public: - explicit file_print_buffer(F*) : buffer(nullptr, size_t()) {} -}; - -template -class file_print_buffer::value>> - : public buffer { - private: - file_ref file_; - - static void grow(buffer& base, size_t) { - auto& self = static_cast(base); - self.file_.advance_write_buffer(self.size()); - if (self.file_.get_write_buffer().size == 0) self.file_.flush(); - auto buf = self.file_.get_write_buffer(); - FMT_ASSERT(buf.size > 0, ""); - self.set(buf.data, buf.size); - self.clear(); - } - - public: - explicit file_print_buffer(F* f) : buffer(grow, size_t()), file_(f) { - flockfile(f); - file_.init_buffer(); - auto buf = file_.get_write_buffer(); - set(buf.data, buf.size); - } - ~file_print_buffer() { - file_.advance_write_buffer(size()); - bool flush = file_.needs_flush(); - F* f = file_; // Make funlockfile depend on the template parameter F - funlockfile(f); // for the system API detection to work. - if (flush) fflush(file_); - } -}; - -#if !defined(_WIN32) || defined(FMT_USE_WRITE_CONSOLE) -FMT_FUNC auto write_console(int, string_view) -> bool { return false; } -#else -using dword = conditional_t; -extern "C" __declspec(dllimport) int __stdcall WriteConsoleW( // - void*, const void*, dword, dword*, void*); - -FMT_FUNC bool write_console(int fd, string_view text) { - auto u16 = utf8_to_utf16(text); - return WriteConsoleW(reinterpret_cast(_get_osfhandle(fd)), u16.c_str(), - static_cast(u16.size()), nullptr, nullptr) != 0; -} -#endif - -#ifdef _WIN32 -// Print assuming legacy (non-Unicode) encoding. -FMT_FUNC void vprint_mojibake(std::FILE* f, string_view fmt, format_args args, - bool newline) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - if (newline) buffer.push_back('\n'); - fwrite_all(buffer.data(), buffer.size(), f); -} -#endif - -FMT_FUNC void print(std::FILE* f, string_view text) { -#if defined(_WIN32) && !defined(FMT_USE_WRITE_CONSOLE) - int fd = _fileno(f); - if (_isatty(fd)) { - std::fflush(f); - if (write_console(fd, text)) return; - } -#endif - fwrite_all(text.data(), text.size(), f); -} -} // namespace detail - -FMT_FUNC void vprint_buffered(std::FILE* f, string_view fmt, format_args args) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - detail::print(f, {buffer.data(), buffer.size()}); -} - -FMT_FUNC void vprint(std::FILE* f, string_view fmt, format_args args) { - if (!detail::file_ref(f).is_buffered() || !detail::has_flockfile<>()) - return vprint_buffered(f, fmt, args); - auto&& buffer = detail::file_print_buffer<>(f); - return detail::vformat_to(buffer, fmt, args); -} - -FMT_FUNC void vprintln(std::FILE* f, string_view fmt, format_args args) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - buffer.push_back('\n'); - detail::print(f, {buffer.data(), buffer.size()}); -} - -FMT_FUNC void vprint(string_view fmt, format_args args) { - vprint(stdout, fmt, args); -} - -namespace detail { - -struct singleton { - unsigned char upper; - unsigned char lower_count; -}; - -inline auto is_printable(uint16_t x, const singleton* singletons, - size_t singletons_size, - const unsigned char* singleton_lowers, - const unsigned char* normal, size_t normal_size) - -> bool { - auto upper = x >> 8; - auto lower_start = 0; - for (size_t i = 0; i < singletons_size; ++i) { - auto s = singletons[i]; - auto lower_end = lower_start + s.lower_count; - if (upper < s.upper) break; - if (upper == s.upper) { - for (auto j = lower_start; j < lower_end; ++j) { - if (singleton_lowers[j] == (x & 0xff)) return false; - } - } - lower_start = lower_end; - } - - auto xsigned = static_cast(x); - auto current = true; - for (size_t i = 0; i < normal_size; ++i) { - auto v = static_cast(normal[i]); - auto len = (v & 0x80) != 0 ? (v & 0x7f) << 8 | normal[++i] : v; - xsigned -= len; - if (xsigned < 0) break; - current = !current; - } - return current; -} - -// This code is generated by support/printable.py. -FMT_FUNC auto is_printable(uint32_t cp) -> bool { - static constexpr singleton singletons0[] = { - {0x00, 1}, {0x03, 5}, {0x05, 6}, {0x06, 3}, {0x07, 6}, {0x08, 8}, - {0x09, 17}, {0x0a, 28}, {0x0b, 25}, {0x0c, 20}, {0x0d, 16}, {0x0e, 13}, - {0x0f, 4}, {0x10, 3}, {0x12, 18}, {0x13, 9}, {0x16, 1}, {0x17, 5}, - {0x18, 2}, {0x19, 3}, {0x1a, 7}, {0x1c, 2}, {0x1d, 1}, {0x1f, 22}, - {0x20, 3}, {0x2b, 3}, {0x2c, 2}, {0x2d, 11}, {0x2e, 1}, {0x30, 3}, - {0x31, 2}, {0x32, 1}, {0xa7, 2}, {0xa9, 2}, {0xaa, 4}, {0xab, 8}, - {0xfa, 2}, {0xfb, 5}, {0xfd, 4}, {0xfe, 3}, {0xff, 9}, - }; - static constexpr unsigned char singletons0_lower[] = { - 0xad, 0x78, 0x79, 0x8b, 0x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d, 0x71, 0xde, 0xdf, 0x0e, 0x0f, 0x1f, 0x6e, - 0x6f, 0x1c, 0x1d, 0x5f, 0x7d, 0x7e, 0xae, 0xaf, 0xbb, 0xbc, 0xfa, 0x16, - 0x17, 0x1e, 0x1f, 0x46, 0x47, 0x4e, 0x4f, 0x58, 0x5a, 0x5c, 0x5e, 0x7e, - 0x7f, 0xb5, 0xc5, 0xd4, 0xd5, 0xdc, 0xf0, 0xf1, 0xf5, 0x72, 0x73, 0x8f, - 0x74, 0x75, 0x96, 0x2f, 0x5f, 0x26, 0x2e, 0x2f, 0xa7, 0xaf, 0xb7, 0xbf, - 0xc7, 0xcf, 0xd7, 0xdf, 0x9a, 0x40, 0x97, 0x98, 0x30, 0x8f, 0x1f, 0xc0, - 0xc1, 0xce, 0xff, 0x4e, 0x4f, 0x5a, 0x5b, 0x07, 0x08, 0x0f, 0x10, 0x27, - 0x2f, 0xee, 0xef, 0x6e, 0x6f, 0x37, 0x3d, 0x3f, 0x42, 0x45, 0x90, 0x91, - 0xfe, 0xff, 0x53, 0x67, 0x75, 0xc8, 0xc9, 0xd0, 0xd1, 0xd8, 0xd9, 0xe7, - 0xfe, 0xff, - }; - static constexpr singleton singletons1[] = { - {0x00, 6}, {0x01, 1}, {0x03, 1}, {0x04, 2}, {0x08, 8}, {0x09, 2}, - {0x0a, 5}, {0x0b, 2}, {0x0e, 4}, {0x10, 1}, {0x11, 2}, {0x12, 5}, - {0x13, 17}, {0x14, 1}, {0x15, 2}, {0x17, 2}, {0x19, 13}, {0x1c, 5}, - {0x1d, 8}, {0x24, 1}, {0x6a, 3}, {0x6b, 2}, {0xbc, 2}, {0xd1, 2}, - {0xd4, 12}, {0xd5, 9}, {0xd6, 2}, {0xd7, 2}, {0xda, 1}, {0xe0, 5}, - {0xe1, 2}, {0xe8, 2}, {0xee, 32}, {0xf0, 4}, {0xf8, 2}, {0xf9, 2}, - {0xfa, 2}, {0xfb, 1}, - }; - static constexpr unsigned char singletons1_lower[] = { - 0x0c, 0x27, 0x3b, 0x3e, 0x4e, 0x4f, 0x8f, 0x9e, 0x9e, 0x9f, 0x06, 0x07, - 0x09, 0x36, 0x3d, 0x3e, 0x56, 0xf3, 0xd0, 0xd1, 0x04, 0x14, 0x18, 0x36, - 0x37, 0x56, 0x57, 0x7f, 0xaa, 0xae, 0xaf, 0xbd, 0x35, 0xe0, 0x12, 0x87, - 0x89, 0x8e, 0x9e, 0x04, 0x0d, 0x0e, 0x11, 0x12, 0x29, 0x31, 0x34, 0x3a, - 0x45, 0x46, 0x49, 0x4a, 0x4e, 0x4f, 0x64, 0x65, 0x5c, 0xb6, 0xb7, 0x1b, - 0x1c, 0x07, 0x08, 0x0a, 0x0b, 0x14, 0x17, 0x36, 0x39, 0x3a, 0xa8, 0xa9, - 0xd8, 0xd9, 0x09, 0x37, 0x90, 0x91, 0xa8, 0x07, 0x0a, 0x3b, 0x3e, 0x66, - 0x69, 0x8f, 0x92, 0x6f, 0x5f, 0xee, 0xef, 0x5a, 0x62, 0x9a, 0x9b, 0x27, - 0x28, 0x55, 0x9d, 0xa0, 0xa1, 0xa3, 0xa4, 0xa7, 0xa8, 0xad, 0xba, 0xbc, - 0xc4, 0x06, 0x0b, 0x0c, 0x15, 0x1d, 0x3a, 0x3f, 0x45, 0x51, 0xa6, 0xa7, - 0xcc, 0xcd, 0xa0, 0x07, 0x19, 0x1a, 0x22, 0x25, 0x3e, 0x3f, 0xc5, 0xc6, - 0x04, 0x20, 0x23, 0x25, 0x26, 0x28, 0x33, 0x38, 0x3a, 0x48, 0x4a, 0x4c, - 0x50, 0x53, 0x55, 0x56, 0x58, 0x5a, 0x5c, 0x5e, 0x60, 0x63, 0x65, 0x66, - 0x6b, 0x73, 0x78, 0x7d, 0x7f, 0x8a, 0xa4, 0xaa, 0xaf, 0xb0, 0xc0, 0xd0, - 0xae, 0xaf, 0x79, 0xcc, 0x6e, 0x6f, 0x93, - }; - static constexpr unsigned char normal0[] = { - 0x00, 0x20, 0x5f, 0x22, 0x82, 0xdf, 0x04, 0x82, 0x44, 0x08, 0x1b, 0x04, - 0x06, 0x11, 0x81, 0xac, 0x0e, 0x80, 0xab, 0x35, 0x28, 0x0b, 0x80, 0xe0, - 0x03, 0x19, 0x08, 0x01, 0x04, 0x2f, 0x04, 0x34, 0x04, 0x07, 0x03, 0x01, - 0x07, 0x06, 0x07, 0x11, 0x0a, 0x50, 0x0f, 0x12, 0x07, 0x55, 0x07, 0x03, - 0x04, 0x1c, 0x0a, 0x09, 0x03, 0x08, 0x03, 0x07, 0x03, 0x02, 0x03, 0x03, - 0x03, 0x0c, 0x04, 0x05, 0x03, 0x0b, 0x06, 0x01, 0x0e, 0x15, 0x05, 0x3a, - 0x03, 0x11, 0x07, 0x06, 0x05, 0x10, 0x07, 0x57, 0x07, 0x02, 0x07, 0x15, - 0x0d, 0x50, 0x04, 0x43, 0x03, 0x2d, 0x03, 0x01, 0x04, 0x11, 0x06, 0x0f, - 0x0c, 0x3a, 0x04, 0x1d, 0x25, 0x5f, 0x20, 0x6d, 0x04, 0x6a, 0x25, 0x80, - 0xc8, 0x05, 0x82, 0xb0, 0x03, 0x1a, 0x06, 0x82, 0xfd, 0x03, 0x59, 0x07, - 0x15, 0x0b, 0x17, 0x09, 0x14, 0x0c, 0x14, 0x0c, 0x6a, 0x06, 0x0a, 0x06, - 0x1a, 0x06, 0x59, 0x07, 0x2b, 0x05, 0x46, 0x0a, 0x2c, 0x04, 0x0c, 0x04, - 0x01, 0x03, 0x31, 0x0b, 0x2c, 0x04, 0x1a, 0x06, 0x0b, 0x03, 0x80, 0xac, - 0x06, 0x0a, 0x06, 0x21, 0x3f, 0x4c, 0x04, 0x2d, 0x03, 0x74, 0x08, 0x3c, - 0x03, 0x0f, 0x03, 0x3c, 0x07, 0x38, 0x08, 0x2b, 0x05, 0x82, 0xff, 0x11, - 0x18, 0x08, 0x2f, 0x11, 0x2d, 0x03, 0x20, 0x10, 0x21, 0x0f, 0x80, 0x8c, - 0x04, 0x82, 0x97, 0x19, 0x0b, 0x15, 0x88, 0x94, 0x05, 0x2f, 0x05, 0x3b, - 0x07, 0x02, 0x0e, 0x18, 0x09, 0x80, 0xb3, 0x2d, 0x74, 0x0c, 0x80, 0xd6, - 0x1a, 0x0c, 0x05, 0x80, 0xff, 0x05, 0x80, 0xdf, 0x0c, 0xee, 0x0d, 0x03, - 0x84, 0x8d, 0x03, 0x37, 0x09, 0x81, 0x5c, 0x14, 0x80, 0xb8, 0x08, 0x80, - 0xcb, 0x2a, 0x38, 0x03, 0x0a, 0x06, 0x38, 0x08, 0x46, 0x08, 0x0c, 0x06, - 0x74, 0x0b, 0x1e, 0x03, 0x5a, 0x04, 0x59, 0x09, 0x80, 0x83, 0x18, 0x1c, - 0x0a, 0x16, 0x09, 0x4c, 0x04, 0x80, 0x8a, 0x06, 0xab, 0xa4, 0x0c, 0x17, - 0x04, 0x31, 0xa1, 0x04, 0x81, 0xda, 0x26, 0x07, 0x0c, 0x05, 0x05, 0x80, - 0xa5, 0x11, 0x81, 0x6d, 0x10, 0x78, 0x28, 0x2a, 0x06, 0x4c, 0x04, 0x80, - 0x8d, 0x04, 0x80, 0xbe, 0x03, 0x1b, 0x03, 0x0f, 0x0d, - }; - static constexpr unsigned char normal1[] = { - 0x5e, 0x22, 0x7b, 0x05, 0x03, 0x04, 0x2d, 0x03, 0x66, 0x03, 0x01, 0x2f, - 0x2e, 0x80, 0x82, 0x1d, 0x03, 0x31, 0x0f, 0x1c, 0x04, 0x24, 0x09, 0x1e, - 0x05, 0x2b, 0x05, 0x44, 0x04, 0x0e, 0x2a, 0x80, 0xaa, 0x06, 0x24, 0x04, - 0x24, 0x04, 0x28, 0x08, 0x34, 0x0b, 0x01, 0x80, 0x90, 0x81, 0x37, 0x09, - 0x16, 0x0a, 0x08, 0x80, 0x98, 0x39, 0x03, 0x63, 0x08, 0x09, 0x30, 0x16, - 0x05, 0x21, 0x03, 0x1b, 0x05, 0x01, 0x40, 0x38, 0x04, 0x4b, 0x05, 0x2f, - 0x04, 0x0a, 0x07, 0x09, 0x07, 0x40, 0x20, 0x27, 0x04, 0x0c, 0x09, 0x36, - 0x03, 0x3a, 0x05, 0x1a, 0x07, 0x04, 0x0c, 0x07, 0x50, 0x49, 0x37, 0x33, - 0x0d, 0x33, 0x07, 0x2e, 0x08, 0x0a, 0x81, 0x26, 0x52, 0x4e, 0x28, 0x08, - 0x2a, 0x56, 0x1c, 0x14, 0x17, 0x09, 0x4e, 0x04, 0x1e, 0x0f, 0x43, 0x0e, - 0x19, 0x07, 0x0a, 0x06, 0x48, 0x08, 0x27, 0x09, 0x75, 0x0b, 0x3f, 0x41, - 0x2a, 0x06, 0x3b, 0x05, 0x0a, 0x06, 0x51, 0x06, 0x01, 0x05, 0x10, 0x03, - 0x05, 0x80, 0x8b, 0x62, 0x1e, 0x48, 0x08, 0x0a, 0x80, 0xa6, 0x5e, 0x22, - 0x45, 0x0b, 0x0a, 0x06, 0x0d, 0x13, 0x39, 0x07, 0x0a, 0x36, 0x2c, 0x04, - 0x10, 0x80, 0xc0, 0x3c, 0x64, 0x53, 0x0c, 0x48, 0x09, 0x0a, 0x46, 0x45, - 0x1b, 0x48, 0x08, 0x53, 0x1d, 0x39, 0x81, 0x07, 0x46, 0x0a, 0x1d, 0x03, - 0x47, 0x49, 0x37, 0x03, 0x0e, 0x08, 0x0a, 0x06, 0x39, 0x07, 0x0a, 0x81, - 0x36, 0x19, 0x80, 0xb7, 0x01, 0x0f, 0x32, 0x0d, 0x83, 0x9b, 0x66, 0x75, - 0x0b, 0x80, 0xc4, 0x8a, 0xbc, 0x84, 0x2f, 0x8f, 0xd1, 0x82, 0x47, 0xa1, - 0xb9, 0x82, 0x39, 0x07, 0x2a, 0x04, 0x02, 0x60, 0x26, 0x0a, 0x46, 0x0a, - 0x28, 0x05, 0x13, 0x82, 0xb0, 0x5b, 0x65, 0x4b, 0x04, 0x39, 0x07, 0x11, - 0x40, 0x05, 0x0b, 0x02, 0x0e, 0x97, 0xf8, 0x08, 0x84, 0xd6, 0x2a, 0x09, - 0xa2, 0xf7, 0x81, 0x1f, 0x31, 0x03, 0x11, 0x04, 0x08, 0x81, 0x8c, 0x89, - 0x04, 0x6b, 0x05, 0x0d, 0x03, 0x09, 0x07, 0x10, 0x93, 0x60, 0x80, 0xf6, - 0x0a, 0x73, 0x08, 0x6e, 0x17, 0x46, 0x80, 0x9a, 0x14, 0x0c, 0x57, 0x09, - 0x19, 0x80, 0x87, 0x81, 0x47, 0x03, 0x85, 0x42, 0x0f, 0x15, 0x85, 0x50, - 0x2b, 0x80, 0xd5, 0x2d, 0x03, 0x1a, 0x04, 0x02, 0x81, 0x70, 0x3a, 0x05, - 0x01, 0x85, 0x00, 0x80, 0xd7, 0x29, 0x4c, 0x04, 0x0a, 0x04, 0x02, 0x83, - 0x11, 0x44, 0x4c, 0x3d, 0x80, 0xc2, 0x3c, 0x06, 0x01, 0x04, 0x55, 0x05, - 0x1b, 0x34, 0x02, 0x81, 0x0e, 0x2c, 0x04, 0x64, 0x0c, 0x56, 0x0a, 0x80, - 0xae, 0x38, 0x1d, 0x0d, 0x2c, 0x04, 0x09, 0x07, 0x02, 0x0e, 0x06, 0x80, - 0x9a, 0x83, 0xd8, 0x08, 0x0d, 0x03, 0x0d, 0x03, 0x74, 0x0c, 0x59, 0x07, - 0x0c, 0x14, 0x0c, 0x04, 0x38, 0x08, 0x0a, 0x06, 0x28, 0x08, 0x22, 0x4e, - 0x81, 0x54, 0x0c, 0x15, 0x03, 0x03, 0x05, 0x07, 0x09, 0x19, 0x07, 0x07, - 0x09, 0x03, 0x0d, 0x07, 0x29, 0x80, 0xcb, 0x25, 0x0a, 0x84, 0x06, - }; - auto lower = static_cast(cp); - if (cp < 0x10000) { - return is_printable(lower, singletons0, - sizeof(singletons0) / sizeof(*singletons0), - singletons0_lower, normal0, sizeof(normal0)); - } - if (cp < 0x20000) { - return is_printable(lower, singletons1, - sizeof(singletons1) / sizeof(*singletons1), - singletons1_lower, normal1, sizeof(normal1)); - } - if (0x2a6de <= cp && cp < 0x2a700) return false; - if (0x2b735 <= cp && cp < 0x2b740) return false; - if (0x2b81e <= cp && cp < 0x2b820) return false; - if (0x2cea2 <= cp && cp < 0x2ceb0) return false; - if (0x2ebe1 <= cp && cp < 0x2f800) return false; - if (0x2fa1e <= cp && cp < 0x30000) return false; - if (0x3134b <= cp && cp < 0xe0100) return false; - if (0xe01f0 <= cp && cp < 0x110000) return false; - return cp < 0x110000; -} - -} // namespace detail - -FMT_END_NAMESPACE - -#endif // FMT_FORMAT_INL_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/format.h b/examples/blueprints-example/external/spdlog/fmt/bundled/format.h deleted file mode 100644 index c3a1bda..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/format.h +++ /dev/null @@ -1,4383 +0,0 @@ -/* - Formatting library for C++ - - Copyright (c) 2012 - present, Victor Zverovich - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - --- Optional exception to the license --- - - As an exception, if, as a result of your compiling your source code, portions - of this Software are embedded into a machine-executable object form of such - source code, you may redistribute such embedded portions in such object form - without including the above copyright and permission notices. - */ - -#ifndef FMT_FORMAT_H_ -#define FMT_FORMAT_H_ - -#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES -# define _LIBCPP_REMOVE_TRANSITIVE_INCLUDES -# define FMT_REMOVE_TRANSITIVE_INCLUDES -#endif - -#include "base.h" - -#ifndef FMT_MODULE -# include // std::signbit -# include // std::byte -# include // uint32_t -# include // std::malloc, std::free -# include // std::memcpy -# include // std::numeric_limits -# include // std::bad_alloc -# if defined(__GLIBCXX__) && !defined(_GLIBCXX_USE_DUAL_ABI) -// Workaround for pre gcc 5 libstdc++. -# include // std::allocator_traits -# endif -# include // std::runtime_error -# include // std::string -# include // std::system_error - -// Check FMT_CPLUSPLUS to avoid a warning in MSVC. -# if FMT_HAS_INCLUDE() && FMT_CPLUSPLUS > 201703L -# include // std::bit_cast -# endif - -// libc++ supports string_view in pre-c++17. -# if FMT_HAS_INCLUDE() && \ - (FMT_CPLUSPLUS >= 201703L || defined(_LIBCPP_VERSION)) -# include -# define FMT_USE_STRING_VIEW -# endif - -# if FMT_MSC_VERSION -# include // _BitScanReverse[64], _umul128 -# endif -#endif // FMT_MODULE - -#if defined(FMT_USE_NONTYPE_TEMPLATE_ARGS) -// Use the provided definition. -#elif defined(__NVCOMPILER) -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0 -#elif FMT_GCC_VERSION >= 903 && FMT_CPLUSPLUS >= 201709L -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 -#elif defined(__cpp_nontype_template_args) && \ - __cpp_nontype_template_args >= 201911L -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 -#elif FMT_CLANG_VERSION >= 1200 && FMT_CPLUSPLUS >= 202002L -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 1 -#else -# define FMT_USE_NONTYPE_TEMPLATE_ARGS 0 -#endif - -#if defined __cpp_inline_variables && __cpp_inline_variables >= 201606L -# define FMT_INLINE_VARIABLE inline -#else -# define FMT_INLINE_VARIABLE -#endif - -// Check if RTTI is disabled. -#ifdef FMT_USE_RTTI -// Use the provided definition. -#elif defined(__GXX_RTTI) || FMT_HAS_FEATURE(cxx_rtti) || defined(_CPPRTTI) || \ - defined(__INTEL_RTTI__) || defined(__RTTI) -// __RTTI is for EDG compilers. _CPPRTTI is for MSVC. -# define FMT_USE_RTTI 1 -#else -# define FMT_USE_RTTI 0 -#endif - -// Visibility when compiled as a shared library/object. -#if defined(FMT_LIB_EXPORT) || defined(FMT_SHARED) -# define FMT_SO_VISIBILITY(value) FMT_VISIBILITY(value) -#else -# define FMT_SO_VISIBILITY(value) -#endif - -#if FMT_GCC_VERSION || FMT_CLANG_VERSION -# define FMT_NOINLINE __attribute__((noinline)) -#else -# define FMT_NOINLINE -#endif - -#ifdef FMT_DEPRECATED -// Use the provided definition. -#elif FMT_HAS_CPP14_ATTRIBUTE(deprecated) -# define FMT_DEPRECATED [[deprecated]] -#else -# define FMT_DEPRECATED /* deprecated */ -#endif - -// Detect constexpr std::string. -#if !FMT_USE_CONSTEVAL -# define FMT_USE_CONSTEXPR_STRING 0 -#elif defined(__cpp_lib_constexpr_string) && \ - __cpp_lib_constexpr_string >= 201907L -# if FMT_CLANG_VERSION && FMT_GLIBCXX_RELEASE -// clang + libstdc++ are able to work only starting with gcc13.3 -// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113294 -# if FMT_GLIBCXX_RELEASE < 13 -# define FMT_USE_CONSTEXPR_STRING 0 -# elif FMT_GLIBCXX_RELEASE == 13 && __GLIBCXX__ < 20240521 -# define FMT_USE_CONSTEXPR_STRING 0 -# else -# define FMT_USE_CONSTEXPR_STRING 1 -# endif -# else -# define FMT_USE_CONSTEXPR_STRING 1 -# endif -#else -# define FMT_USE_CONSTEXPR_STRING 0 -#endif -#if FMT_USE_CONSTEXPR_STRING -# define FMT_CONSTEXPR_STRING constexpr -#else -# define FMT_CONSTEXPR_STRING -#endif - -// GCC 4.9 doesn't support qualified names in specializations. -namespace std { -template struct iterator_traits> { - using iterator_category = output_iterator_tag; - using value_type = T; - using difference_type = - decltype(static_cast(nullptr) - static_cast(nullptr)); - using pointer = void; - using reference = void; -}; -} // namespace std - -#ifdef FMT_THROW -// Use the provided definition. -#elif FMT_USE_EXCEPTIONS -# define FMT_THROW(x) throw x -#else -# define FMT_THROW(x) ::fmt::assert_fail(__FILE__, __LINE__, (x).what()) -#endif - -#ifdef __clang_analyzer__ -# define FMT_CLANG_ANALYZER 1 -#else -# define FMT_CLANG_ANALYZER 0 -#endif - -// Defining FMT_REDUCE_INT_INSTANTIATIONS to 1, will reduce the number of -// integer formatter template instantiations to just one by only using the -// largest integer type. This results in a reduction in binary size but will -// cause a decrease in integer formatting performance. -#if !defined(FMT_REDUCE_INT_INSTANTIATIONS) -# define FMT_REDUCE_INT_INSTANTIATIONS 0 -#endif - -FMT_BEGIN_NAMESPACE - -template -struct is_contiguous> - : std::true_type {}; - -namespace detail { - -// __builtin_clz is broken in clang with Microsoft codegen: -// https://github.com/fmtlib/fmt/issues/519. -#if !FMT_MSC_VERSION -# if FMT_HAS_BUILTIN(__builtin_clz) || FMT_GCC_VERSION || FMT_ICC_VERSION -# define FMT_BUILTIN_CLZ(n) __builtin_clz(n) -# endif -# if FMT_HAS_BUILTIN(__builtin_clzll) || FMT_GCC_VERSION || FMT_ICC_VERSION -# define FMT_BUILTIN_CLZLL(n) __builtin_clzll(n) -# endif -#endif - -// Some compilers masquerade as both MSVC and GCC but otherwise support -// __builtin_clz and __builtin_clzll, so only define FMT_BUILTIN_CLZ using the -// MSVC intrinsics if the clz and clzll builtins are not available. -#if FMT_MSC_VERSION && !defined(FMT_BUILTIN_CLZLL) -// Avoid Clang with Microsoft CodeGen's -Wunknown-pragmas warning. -# ifndef __clang__ -# pragma intrinsic(_BitScanReverse) -# ifdef _WIN64 -# pragma intrinsic(_BitScanReverse64) -# endif -# endif - -inline auto clz(uint32_t x) -> int { - FMT_ASSERT(x != 0, ""); - FMT_MSC_WARNING(suppress : 6102) // Suppress a bogus static analysis warning. - unsigned long r = 0; - _BitScanReverse(&r, x); - return 31 ^ static_cast(r); -} -# define FMT_BUILTIN_CLZ(n) detail::clz(n) - -inline auto clzll(uint64_t x) -> int { - FMT_ASSERT(x != 0, ""); - FMT_MSC_WARNING(suppress : 6102) // Suppress a bogus static analysis warning. - unsigned long r = 0; -# ifdef _WIN64 - _BitScanReverse64(&r, x); -# else - // Scan the high 32 bits. - if (_BitScanReverse(&r, static_cast(x >> 32))) - return 63 ^ static_cast(r + 32); - // Scan the low 32 bits. - _BitScanReverse(&r, static_cast(x)); -# endif - return 63 ^ static_cast(r); -} -# define FMT_BUILTIN_CLZLL(n) detail::clzll(n) -#endif // FMT_MSC_VERSION && !defined(FMT_BUILTIN_CLZLL) - -FMT_CONSTEXPR inline void abort_fuzzing_if(bool condition) { - ignore_unused(condition); -#ifdef FMT_FUZZ - if (condition) throw std::runtime_error("fuzzing limit reached"); -#endif -} - -#if defined(FMT_USE_STRING_VIEW) -template using std_string_view = std::basic_string_view; -#else -template struct std_string_view { - operator basic_string_view() const; -}; -#endif - -template struct string_literal { - static constexpr Char value[sizeof...(C)] = {C...}; - constexpr operator basic_string_view() const { - return {value, sizeof...(C)}; - } -}; -#if FMT_CPLUSPLUS < 201703L -template -constexpr Char string_literal::value[sizeof...(C)]; -#endif - -// Implementation of std::bit_cast for pre-C++20. -template -FMT_CONSTEXPR20 auto bit_cast(const From& from) -> To { -#ifdef __cpp_lib_bit_cast - if (is_constant_evaluated()) return std::bit_cast(from); -#endif - auto to = To(); - // The cast suppresses a bogus -Wclass-memaccess on GCC. - std::memcpy(static_cast(&to), &from, sizeof(to)); - return to; -} - -inline auto is_big_endian() -> bool { -#ifdef _WIN32 - return false; -#elif defined(__BIG_ENDIAN__) - return true; -#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) - return __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__; -#else - struct bytes { - char data[sizeof(int)]; - }; - return bit_cast(1).data[0] == 0; -#endif -} - -class uint128_fallback { - private: - uint64_t lo_, hi_; - - public: - constexpr uint128_fallback(uint64_t hi, uint64_t lo) : lo_(lo), hi_(hi) {} - constexpr uint128_fallback(uint64_t value = 0) : lo_(value), hi_(0) {} - - constexpr auto high() const noexcept -> uint64_t { return hi_; } - constexpr auto low() const noexcept -> uint64_t { return lo_; } - - template ::value)> - constexpr explicit operator T() const { - return static_cast(lo_); - } - - friend constexpr auto operator==(const uint128_fallback& lhs, - const uint128_fallback& rhs) -> bool { - return lhs.hi_ == rhs.hi_ && lhs.lo_ == rhs.lo_; - } - friend constexpr auto operator!=(const uint128_fallback& lhs, - const uint128_fallback& rhs) -> bool { - return !(lhs == rhs); - } - friend constexpr auto operator>(const uint128_fallback& lhs, - const uint128_fallback& rhs) -> bool { - return lhs.hi_ != rhs.hi_ ? lhs.hi_ > rhs.hi_ : lhs.lo_ > rhs.lo_; - } - friend constexpr auto operator|(const uint128_fallback& lhs, - const uint128_fallback& rhs) - -> uint128_fallback { - return {lhs.hi_ | rhs.hi_, lhs.lo_ | rhs.lo_}; - } - friend constexpr auto operator&(const uint128_fallback& lhs, - const uint128_fallback& rhs) - -> uint128_fallback { - return {lhs.hi_ & rhs.hi_, lhs.lo_ & rhs.lo_}; - } - friend constexpr auto operator~(const uint128_fallback& n) - -> uint128_fallback { - return {~n.hi_, ~n.lo_}; - } - friend FMT_CONSTEXPR auto operator+(const uint128_fallback& lhs, - const uint128_fallback& rhs) - -> uint128_fallback { - auto result = uint128_fallback(lhs); - result += rhs; - return result; - } - friend FMT_CONSTEXPR auto operator*(const uint128_fallback& lhs, uint32_t rhs) - -> uint128_fallback { - FMT_ASSERT(lhs.hi_ == 0, ""); - uint64_t hi = (lhs.lo_ >> 32) * rhs; - uint64_t lo = (lhs.lo_ & ~uint32_t()) * rhs; - uint64_t new_lo = (hi << 32) + lo; - return {(hi >> 32) + (new_lo < lo ? 1 : 0), new_lo}; - } - friend constexpr auto operator-(const uint128_fallback& lhs, uint64_t rhs) - -> uint128_fallback { - return {lhs.hi_ - (lhs.lo_ < rhs ? 1 : 0), lhs.lo_ - rhs}; - } - FMT_CONSTEXPR auto operator>>(int shift) const -> uint128_fallback { - if (shift == 64) return {0, hi_}; - if (shift > 64) return uint128_fallback(0, hi_) >> (shift - 64); - return {hi_ >> shift, (hi_ << (64 - shift)) | (lo_ >> shift)}; - } - FMT_CONSTEXPR auto operator<<(int shift) const -> uint128_fallback { - if (shift == 64) return {lo_, 0}; - if (shift > 64) return uint128_fallback(lo_, 0) << (shift - 64); - return {hi_ << shift | (lo_ >> (64 - shift)), (lo_ << shift)}; - } - FMT_CONSTEXPR auto operator>>=(int shift) -> uint128_fallback& { - return *this = *this >> shift; - } - FMT_CONSTEXPR void operator+=(uint128_fallback n) { - uint64_t new_lo = lo_ + n.lo_; - uint64_t new_hi = hi_ + n.hi_ + (new_lo < lo_ ? 1 : 0); - FMT_ASSERT(new_hi >= hi_, ""); - lo_ = new_lo; - hi_ = new_hi; - } - FMT_CONSTEXPR void operator&=(uint128_fallback n) { - lo_ &= n.lo_; - hi_ &= n.hi_; - } - - FMT_CONSTEXPR20 auto operator+=(uint64_t n) noexcept -> uint128_fallback& { - if (is_constant_evaluated()) { - lo_ += n; - hi_ += (lo_ < n ? 1 : 0); - return *this; - } -#if FMT_HAS_BUILTIN(__builtin_addcll) && !defined(__ibmxl__) - unsigned long long carry; - lo_ = __builtin_addcll(lo_, n, 0, &carry); - hi_ += carry; -#elif FMT_HAS_BUILTIN(__builtin_ia32_addcarryx_u64) && !defined(__ibmxl__) - unsigned long long result; - auto carry = __builtin_ia32_addcarryx_u64(0, lo_, n, &result); - lo_ = result; - hi_ += carry; -#elif defined(_MSC_VER) && defined(_M_X64) - auto carry = _addcarry_u64(0, lo_, n, &lo_); - _addcarry_u64(carry, hi_, 0, &hi_); -#else - lo_ += n; - hi_ += (lo_ < n ? 1 : 0); -#endif - return *this; - } -}; - -using uint128_t = conditional_t; - -#ifdef UINTPTR_MAX -using uintptr_t = ::uintptr_t; -#else -using uintptr_t = uint128_t; -#endif - -// Returns the largest possible value for type T. Same as -// std::numeric_limits::max() but shorter and not affected by the max macro. -template constexpr auto max_value() -> T { - return (std::numeric_limits::max)(); -} -template constexpr auto num_bits() -> int { - return std::numeric_limits::digits; -} -// std::numeric_limits::digits may return 0 for 128-bit ints. -template <> constexpr auto num_bits() -> int { return 128; } -template <> constexpr auto num_bits() -> int { return 128; } -template <> constexpr auto num_bits() -> int { return 128; } - -// A heterogeneous bit_cast used for converting 96-bit long double to uint128_t -// and 128-bit pointers to uint128_fallback. -template sizeof(From))> -inline auto bit_cast(const From& from) -> To { - constexpr auto size = static_cast(sizeof(From) / sizeof(unsigned short)); - struct data_t { - unsigned short value[static_cast(size)]; - } data = bit_cast(from); - auto result = To(); - if (const_check(is_big_endian())) { - for (int i = 0; i < size; ++i) - result = (result << num_bits()) | data.value[i]; - } else { - for (int i = size - 1; i >= 0; --i) - result = (result << num_bits()) | data.value[i]; - } - return result; -} - -template -FMT_CONSTEXPR20 inline auto countl_zero_fallback(UInt n) -> int { - int lz = 0; - constexpr UInt msb_mask = static_cast(1) << (num_bits() - 1); - for (; (n & msb_mask) == 0; n <<= 1) lz++; - return lz; -} - -FMT_CONSTEXPR20 inline auto countl_zero(uint32_t n) -> int { -#ifdef FMT_BUILTIN_CLZ - if (!is_constant_evaluated()) return FMT_BUILTIN_CLZ(n); -#endif - return countl_zero_fallback(n); -} - -FMT_CONSTEXPR20 inline auto countl_zero(uint64_t n) -> int { -#ifdef FMT_BUILTIN_CLZLL - if (!is_constant_evaluated()) return FMT_BUILTIN_CLZLL(n); -#endif - return countl_zero_fallback(n); -} - -FMT_INLINE void assume(bool condition) { - (void)condition; -#if FMT_HAS_BUILTIN(__builtin_assume) && !FMT_ICC_VERSION - __builtin_assume(condition); -#elif FMT_GCC_VERSION - if (!condition) __builtin_unreachable(); -#endif -} - -// Attempts to reserve space for n extra characters in the output range. -// Returns a pointer to the reserved range or a reference to it. -template ::value&& - is_contiguous::value)> -#if FMT_CLANG_VERSION >= 307 && !FMT_ICC_VERSION -__attribute__((no_sanitize("undefined"))) -#endif -FMT_CONSTEXPR20 inline auto -reserve(OutputIt it, size_t n) -> typename OutputIt::value_type* { - auto& c = get_container(it); - size_t size = c.size(); - c.resize(size + n); - return &c[size]; -} - -template -FMT_CONSTEXPR20 inline auto reserve(basic_appender it, size_t n) - -> basic_appender { - buffer& buf = get_container(it); - buf.try_reserve(buf.size() + n); - return it; -} - -template -constexpr auto reserve(Iterator& it, size_t) -> Iterator& { - return it; -} - -template -using reserve_iterator = - remove_reference_t(), 0))>; - -template -constexpr auto to_pointer(OutputIt, size_t) -> T* { - return nullptr; -} -template FMT_CONSTEXPR auto to_pointer(T*& ptr, size_t n) -> T* { - T* begin = ptr; - ptr += n; - return begin; -} -template -FMT_CONSTEXPR20 auto to_pointer(basic_appender it, size_t n) -> T* { - buffer& buf = get_container(it); - buf.try_reserve(buf.size() + n); - auto size = buf.size(); - if (buf.capacity() < size + n) return nullptr; - buf.try_resize(size + n); - return buf.data() + size; -} - -template ::value&& - is_contiguous::value)> -inline auto base_iterator(OutputIt it, - typename OutputIt::container_type::value_type*) - -> OutputIt { - return it; -} - -template -constexpr auto base_iterator(Iterator, Iterator it) -> Iterator { - return it; -} - -// is spectacularly slow to compile in C++20 so use a simple fill_n -// instead (#1998). -template -FMT_CONSTEXPR auto fill_n(OutputIt out, Size count, const T& value) - -> OutputIt { - for (Size i = 0; i < count; ++i) *out++ = value; - return out; -} -template -FMT_CONSTEXPR20 auto fill_n(T* out, Size count, char value) -> T* { - if (is_constant_evaluated()) return fill_n(out, count, value); - static_assert(sizeof(T) == 1, - "sizeof(T) must be 1 to use char for initialization"); - std::memset(out, value, to_unsigned(count)); - return out + count; -} - -template -FMT_CONSTEXPR FMT_NOINLINE auto copy_noinline(InputIt begin, InputIt end, - OutputIt out) -> OutputIt { - return copy(begin, end, out); -} - -// A public domain branchless UTF-8 decoder by Christopher Wellons: -// https://github.com/skeeto/branchless-utf8 -/* Decode the next character, c, from s, reporting errors in e. - * - * Since this is a branchless decoder, four bytes will be read from the - * buffer regardless of the actual length of the next character. This - * means the buffer _must_ have at least three bytes of zero padding - * following the end of the data stream. - * - * Errors are reported in e, which will be non-zero if the parsed - * character was somehow invalid: invalid byte sequence, non-canonical - * encoding, or a surrogate half. - * - * The function returns a pointer to the next character. When an error - * occurs, this pointer will be a guess that depends on the particular - * error, but it will always advance at least one byte. - */ -FMT_CONSTEXPR inline auto utf8_decode(const char* s, uint32_t* c, int* e) - -> const char* { - constexpr int masks[] = {0x00, 0x7f, 0x1f, 0x0f, 0x07}; - constexpr uint32_t mins[] = {4194304, 0, 128, 2048, 65536}; - constexpr int shiftc[] = {0, 18, 12, 6, 0}; - constexpr int shifte[] = {0, 6, 4, 2, 0}; - - int len = "\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\0\0\0\0\0\0\0\0\2\2\2\2\3\3\4" - [static_cast(*s) >> 3]; - // Compute the pointer to the next character early so that the next - // iteration can start working on the next character. Neither Clang - // nor GCC figure out this reordering on their own. - const char* next = s + len + !len; - - using uchar = unsigned char; - - // Assume a four-byte character and load four bytes. Unused bits are - // shifted out. - *c = uint32_t(uchar(s[0]) & masks[len]) << 18; - *c |= uint32_t(uchar(s[1]) & 0x3f) << 12; - *c |= uint32_t(uchar(s[2]) & 0x3f) << 6; - *c |= uint32_t(uchar(s[3]) & 0x3f) << 0; - *c >>= shiftc[len]; - - // Accumulate the various error conditions. - *e = (*c < mins[len]) << 6; // non-canonical encoding - *e |= ((*c >> 11) == 0x1b) << 7; // surrogate half? - *e |= (*c > 0x10FFFF) << 8; // out of range? - *e |= (uchar(s[1]) & 0xc0) >> 2; - *e |= (uchar(s[2]) & 0xc0) >> 4; - *e |= uchar(s[3]) >> 6; - *e ^= 0x2a; // top two bits of each tail byte correct? - *e >>= shifte[len]; - - return next; -} - -constexpr FMT_INLINE_VARIABLE uint32_t invalid_code_point = ~uint32_t(); - -// Invokes f(cp, sv) for every code point cp in s with sv being the string view -// corresponding to the code point. cp is invalid_code_point on error. -template -FMT_CONSTEXPR void for_each_codepoint(string_view s, F f) { - auto decode = [f](const char* buf_ptr, const char* ptr) { - auto cp = uint32_t(); - auto error = 0; - auto end = utf8_decode(buf_ptr, &cp, &error); - bool result = f(error ? invalid_code_point : cp, - string_view(ptr, error ? 1 : to_unsigned(end - buf_ptr))); - return result ? (error ? buf_ptr + 1 : end) : nullptr; - }; - - auto p = s.data(); - const size_t block_size = 4; // utf8_decode always reads blocks of 4 chars. - if (s.size() >= block_size) { - for (auto end = p + s.size() - block_size + 1; p < end;) { - p = decode(p, p); - if (!p) return; - } - } - auto num_chars_left = to_unsigned(s.data() + s.size() - p); - if (num_chars_left == 0) return; - - // Suppress bogus -Wstringop-overflow. - if (FMT_GCC_VERSION) num_chars_left &= 3; - char buf[2 * block_size - 1] = {}; - copy(p, p + num_chars_left, buf); - const char* buf_ptr = buf; - do { - auto end = decode(buf_ptr, p); - if (!end) return; - p += end - buf_ptr; - buf_ptr = end; - } while (buf_ptr < buf + num_chars_left); -} - -FMT_CONSTEXPR inline auto display_width_of(uint32_t cp) noexcept -> size_t { - return to_unsigned( - 1 + (cp >= 0x1100 && - (cp <= 0x115f || // Hangul Jamo init. consonants - cp == 0x2329 || // LEFT-POINTING ANGLE BRACKET - cp == 0x232a || // RIGHT-POINTING ANGLE BRACKET - // CJK ... Yi except IDEOGRAPHIC HALF FILL SPACE: - (cp >= 0x2e80 && cp <= 0xa4cf && cp != 0x303f) || - (cp >= 0xac00 && cp <= 0xd7a3) || // Hangul Syllables - (cp >= 0xf900 && cp <= 0xfaff) || // CJK Compatibility Ideographs - (cp >= 0xfe10 && cp <= 0xfe19) || // Vertical Forms - (cp >= 0xfe30 && cp <= 0xfe6f) || // CJK Compatibility Forms - (cp >= 0xff00 && cp <= 0xff60) || // Fullwidth Forms - (cp >= 0xffe0 && cp <= 0xffe6) || // Fullwidth Forms - (cp >= 0x20000 && cp <= 0x2fffd) || // CJK - (cp >= 0x30000 && cp <= 0x3fffd) || - // Miscellaneous Symbols and Pictographs + Emoticons: - (cp >= 0x1f300 && cp <= 0x1f64f) || - // Supplemental Symbols and Pictographs: - (cp >= 0x1f900 && cp <= 0x1f9ff)))); -} - -template struct is_integral : std::is_integral {}; -template <> struct is_integral : std::true_type {}; -template <> struct is_integral : std::true_type {}; - -template -using is_signed = - std::integral_constant::is_signed || - std::is_same::value>; - -template -using is_integer = - bool_constant::value && !std::is_same::value && - !std::is_same::value && - !std::is_same::value>; - -#if defined(FMT_USE_FLOAT128) -// Use the provided definition. -#elif FMT_CLANG_VERSION >= 309 && FMT_HAS_INCLUDE() -# define FMT_USE_FLOAT128 1 -#elif FMT_GCC_VERSION && defined(_GLIBCXX_USE_FLOAT128) && \ - !defined(__STRICT_ANSI__) -# define FMT_USE_FLOAT128 1 -#else -# define FMT_USE_FLOAT128 0 -#endif -#if FMT_USE_FLOAT128 -using float128 = __float128; -#else -struct float128 {}; -#endif - -template using is_float128 = std::is_same; - -template struct is_floating_point : std::is_floating_point {}; -template <> struct is_floating_point : std::true_type {}; - -template ::value> -struct is_fast_float : bool_constant::is_iec559 && - sizeof(T) <= sizeof(double)> {}; -template struct is_fast_float : std::false_type {}; - -template -using fast_float_t = conditional_t; - -template -using is_double_double = bool_constant::digits == 106>; - -#ifndef FMT_USE_FULL_CACHE_DRAGONBOX -# define FMT_USE_FULL_CACHE_DRAGONBOX 0 -#endif - -// An allocator that uses malloc/free to allow removing dependency on the C++ -// standard libary runtime. std::decay is used for back_inserter to be found by -// ADL when applied to memory_buffer. -template struct allocator : private std::decay { - using value_type = T; - - auto allocate(size_t n) -> T* { - FMT_ASSERT(n <= max_value() / sizeof(T), ""); - T* p = static_cast(std::malloc(n * sizeof(T))); - if (!p) FMT_THROW(std::bad_alloc()); - return p; - } - - void deallocate(T* p, size_t) { std::free(p); } - - constexpr friend auto operator==(allocator, allocator) noexcept -> bool { - return true; // All instances of this allocator are equivalent. - } - constexpr friend auto operator!=(allocator, allocator) noexcept -> bool { - return false; - } -}; - -} // namespace detail - -FMT_BEGIN_EXPORT - -// The number of characters to store in the basic_memory_buffer object itself -// to avoid dynamic memory allocation. -enum { inline_buffer_size = 500 }; - -/** - * A dynamically growing memory buffer for trivially copyable/constructible - * types with the first `SIZE` elements stored in the object itself. Most - * commonly used via the `memory_buffer` alias for `char`. - * - * **Example**: - * - * auto out = fmt::memory_buffer(); - * fmt::format_to(std::back_inserter(out), "The answer is {}.", 42); - * - * This will append "The answer is 42." to `out`. The buffer content can be - * converted to `std::string` with `to_string(out)`. - */ -template > -class basic_memory_buffer : public detail::buffer { - private: - T store_[SIZE]; - - // Don't inherit from Allocator to avoid generating type_info for it. - FMT_NO_UNIQUE_ADDRESS Allocator alloc_; - - // Deallocate memory allocated by the buffer. - FMT_CONSTEXPR20 void deallocate() { - T* data = this->data(); - if (data != store_) alloc_.deallocate(data, this->capacity()); - } - - static FMT_CONSTEXPR20 void grow(detail::buffer& buf, size_t size) { - detail::abort_fuzzing_if(size > 5000); - auto& self = static_cast(buf); - const size_t max_size = - std::allocator_traits::max_size(self.alloc_); - size_t old_capacity = buf.capacity(); - size_t new_capacity = old_capacity + old_capacity / 2; - if (size > new_capacity) - new_capacity = size; - else if (new_capacity > max_size) - new_capacity = max_of(size, max_size); - T* old_data = buf.data(); - T* new_data = self.alloc_.allocate(new_capacity); - // Suppress a bogus -Wstringop-overflow in gcc 13.1 (#3481). - detail::assume(buf.size() <= new_capacity); - // The following code doesn't throw, so the raw pointer above doesn't leak. - memcpy(new_data, old_data, buf.size() * sizeof(T)); - self.set(new_data, new_capacity); - // deallocate must not throw according to the standard, but even if it does, - // the buffer already uses the new storage and will deallocate it in - // destructor. - if (old_data != self.store_) self.alloc_.deallocate(old_data, old_capacity); - } - - public: - using value_type = T; - using const_reference = const T&; - - FMT_CONSTEXPR explicit basic_memory_buffer( - const Allocator& alloc = Allocator()) - : detail::buffer(grow), alloc_(alloc) { - this->set(store_, SIZE); - if (detail::is_constant_evaluated()) detail::fill_n(store_, SIZE, T()); - } - FMT_CONSTEXPR20 ~basic_memory_buffer() { deallocate(); } - - private: - template :: - propagate_on_container_move_assignment::value)> - FMT_CONSTEXPR20 auto move_alloc(basic_memory_buffer& other) -> bool { - alloc_ = std::move(other.alloc_); - return true; - } - // If the allocator does not propagate then copy the data from other. - template :: - propagate_on_container_move_assignment::value)> - FMT_CONSTEXPR20 auto move_alloc(basic_memory_buffer& other) -> bool { - T* data = other.data(); - if (alloc_ == other.alloc_ || data == other.store_) return true; - size_t size = other.size(); - // Perform copy operation, allocators are different. - this->resize(size); - detail::copy(data, data + size, this->data()); - return false; - } - - // Move data from other to this buffer. - FMT_CONSTEXPR20 void move(basic_memory_buffer& other) { - T* data = other.data(); - size_t size = other.size(), capacity = other.capacity(); - if (!move_alloc(other)) return; - if (data == other.store_) { - this->set(store_, capacity); - detail::copy(other.store_, other.store_ + size, store_); - } else { - this->set(data, capacity); - // Set pointer to the inline array so that delete is not called - // when deallocating. - other.set(other.store_, 0); - other.clear(); - } - this->resize(size); - } - - public: - /// Constructs a `basic_memory_buffer` object moving the content of the other - /// object to it. - FMT_CONSTEXPR20 basic_memory_buffer(basic_memory_buffer&& other) noexcept - : detail::buffer(grow) { - move(other); - } - - /// Moves the content of the other `basic_memory_buffer` object to this one. - auto operator=(basic_memory_buffer&& other) noexcept -> basic_memory_buffer& { - FMT_ASSERT(this != &other, ""); - deallocate(); - move(other); - return *this; - } - - // Returns a copy of the allocator associated with this buffer. - auto get_allocator() const -> Allocator { return alloc_; } - - /// Resizes the buffer to contain `count` elements. If T is a POD type new - /// elements may not be initialized. - FMT_CONSTEXPR void resize(size_t count) { this->try_resize(count); } - - /// Increases the buffer capacity to `new_capacity`. - void reserve(size_t new_capacity) { this->try_reserve(new_capacity); } - - using detail::buffer::append; - template - FMT_CONSTEXPR20 void append(const ContiguousRange& range) { - append(range.data(), range.data() + range.size()); - } -}; - -using memory_buffer = basic_memory_buffer; - -template -FMT_NODISCARD auto to_string(const basic_memory_buffer& buf) - -> std::string { - auto size = buf.size(); - detail::assume(size < std::string().max_size()); - return {buf.data(), size}; -} - -// A writer to a buffered stream. It doesn't own the underlying stream. -class writer { - private: - detail::buffer* buf_; - - // We cannot create a file buffer in advance because any write to a FILE may - // invalidate it. - FILE* file_; - - public: - inline writer(FILE* f) : buf_(nullptr), file_(f) {} - inline writer(detail::buffer& buf) : buf_(&buf) {} - - /// Formats `args` according to specifications in `fmt` and writes the - /// output to the file. - template void print(format_string fmt, T&&... args) { - if (buf_) - fmt::format_to(appender(*buf_), fmt, std::forward(args)...); - else - fmt::print(file_, fmt, std::forward(args)...); - } -}; - -class string_buffer { - private: - std::string str_; - detail::container_buffer buf_; - - public: - inline string_buffer() : buf_(str_) {} - - inline operator writer() { return buf_; } - inline auto str() -> std::string& { return str_; } -}; - -template -struct is_contiguous> : std::true_type { -}; - -// Suppress a misleading warning in older versions of clang. -FMT_PRAGMA_CLANG(diagnostic ignored "-Wweak-vtables") - -/// An error reported from a formatting function. -class FMT_SO_VISIBILITY("default") format_error : public std::runtime_error { - public: - using std::runtime_error::runtime_error; -}; - -class loc_value; - -FMT_END_EXPORT -namespace detail { -FMT_API auto write_console(int fd, string_view text) -> bool; -FMT_API void print(FILE*, string_view); -} // namespace detail - -namespace detail { -template struct fixed_string { - FMT_CONSTEXPR20 fixed_string(const Char (&s)[N]) { - detail::copy(static_cast(s), s + N, - data); - } - Char data[N] = {}; -}; - -// Converts a compile-time string to basic_string_view. -FMT_EXPORT template -constexpr auto compile_string_to_view(const Char (&s)[N]) - -> basic_string_view { - // Remove trailing NUL character if needed. Won't be present if this is used - // with a raw character array (i.e. not defined as a string). - return {s, N - (std::char_traits::to_int_type(s[N - 1]) == 0 ? 1 : 0)}; -} -FMT_EXPORT template -constexpr auto compile_string_to_view(basic_string_view s) - -> basic_string_view { - return s; -} - -// Returns true if value is negative, false otherwise. -// Same as `value < 0` but doesn't produce warnings if T is an unsigned type. -template ::value)> -constexpr auto is_negative(T value) -> bool { - return value < 0; -} -template ::value)> -constexpr auto is_negative(T) -> bool { - return false; -} - -// Smallest of uint32_t, uint64_t, uint128_t that is large enough to -// represent all values of an integral type T. -template -using uint32_or_64_or_128_t = - conditional_t() <= 32 && !FMT_REDUCE_INT_INSTANTIATIONS, - uint32_t, - conditional_t() <= 64, uint64_t, uint128_t>>; -template -using uint64_or_128_t = conditional_t() <= 64, uint64_t, uint128_t>; - -#define FMT_POWERS_OF_10(factor) \ - factor * 10, (factor) * 100, (factor) * 1000, (factor) * 10000, \ - (factor) * 100000, (factor) * 1000000, (factor) * 10000000, \ - (factor) * 100000000, (factor) * 1000000000 - -// Converts value in the range [0, 100) to a string. -// GCC generates slightly better code when value is pointer-size. -inline auto digits2(size_t value) -> const char* { - // Align data since unaligned access may be slower when crossing a - // hardware-specific boundary. - alignas(2) static const char data[] = - "0001020304050607080910111213141516171819" - "2021222324252627282930313233343536373839" - "4041424344454647484950515253545556575859" - "6061626364656667686970717273747576777879" - "8081828384858687888990919293949596979899"; - return &data[value * 2]; -} - -template constexpr auto getsign(sign s) -> Char { - return static_cast(((' ' << 24) | ('+' << 16) | ('-' << 8)) >> - (static_cast(s) * 8)); -} - -template FMT_CONSTEXPR auto count_digits_fallback(T n) -> int { - int count = 1; - for (;;) { - // Integer division is slow so do it for a group of four digits instead - // of for every digit. The idea comes from the talk by Alexandrescu - // "Three Optimization Tips for C++". See speed-test for a comparison. - if (n < 10) return count; - if (n < 100) return count + 1; - if (n < 1000) return count + 2; - if (n < 10000) return count + 3; - n /= 10000u; - count += 4; - } -} -#if FMT_USE_INT128 -FMT_CONSTEXPR inline auto count_digits(uint128_opt n) -> int { - return count_digits_fallback(n); -} -#endif - -#ifdef FMT_BUILTIN_CLZLL -// It is a separate function rather than a part of count_digits to workaround -// the lack of static constexpr in constexpr functions. -inline auto do_count_digits(uint64_t n) -> int { - // This has comparable performance to the version by Kendall Willets - // (https://github.com/fmtlib/format-benchmark/blob/master/digits10) - // but uses smaller tables. - // Maps bsr(n) to ceil(log10(pow(2, bsr(n) + 1) - 1)). - static constexpr uint8_t bsr2log10[] = { - 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, - 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, - 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15, 15, - 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, 20}; - auto t = bsr2log10[FMT_BUILTIN_CLZLL(n | 1) ^ 63]; - static constexpr uint64_t zero_or_powers_of_10[] = { - 0, 0, FMT_POWERS_OF_10(1U), FMT_POWERS_OF_10(1000000000ULL), - 10000000000000000000ULL}; - return t - (n < zero_or_powers_of_10[t]); -} -#endif - -// Returns the number of decimal digits in n. Leading zeros are not counted -// except for n == 0 in which case count_digits returns 1. -FMT_CONSTEXPR20 inline auto count_digits(uint64_t n) -> int { -#ifdef FMT_BUILTIN_CLZLL - if (!is_constant_evaluated() && !FMT_OPTIMIZE_SIZE) return do_count_digits(n); -#endif - return count_digits_fallback(n); -} - -// Counts the number of digits in n. BITS = log2(radix). -template -FMT_CONSTEXPR auto count_digits(UInt n) -> int { -#ifdef FMT_BUILTIN_CLZ - if (!is_constant_evaluated() && num_bits() == 32) - return (FMT_BUILTIN_CLZ(static_cast(n) | 1) ^ 31) / BITS + 1; -#endif - // Lambda avoids unreachable code warnings from NVHPC. - return [](UInt m) { - int num_digits = 0; - do { - ++num_digits; - } while ((m >>= BITS) != 0); - return num_digits; - }(n); -} - -#ifdef FMT_BUILTIN_CLZ -// It is a separate function rather than a part of count_digits to workaround -// the lack of static constexpr in constexpr functions. -FMT_INLINE auto do_count_digits(uint32_t n) -> int { -// An optimization by Kendall Willets from https://bit.ly/3uOIQrB. -// This increments the upper 32 bits (log10(T) - 1) when >= T is added. -# define FMT_INC(T) (((sizeof(#T) - 1ull) << 32) - T) - static constexpr uint64_t table[] = { - FMT_INC(0), FMT_INC(0), FMT_INC(0), // 8 - FMT_INC(10), FMT_INC(10), FMT_INC(10), // 64 - FMT_INC(100), FMT_INC(100), FMT_INC(100), // 512 - FMT_INC(1000), FMT_INC(1000), FMT_INC(1000), // 4096 - FMT_INC(10000), FMT_INC(10000), FMT_INC(10000), // 32k - FMT_INC(100000), FMT_INC(100000), FMT_INC(100000), // 256k - FMT_INC(1000000), FMT_INC(1000000), FMT_INC(1000000), // 2048k - FMT_INC(10000000), FMT_INC(10000000), FMT_INC(10000000), // 16M - FMT_INC(100000000), FMT_INC(100000000), FMT_INC(100000000), // 128M - FMT_INC(1000000000), FMT_INC(1000000000), FMT_INC(1000000000), // 1024M - FMT_INC(1000000000), FMT_INC(1000000000) // 4B - }; - auto inc = table[FMT_BUILTIN_CLZ(n | 1) ^ 31]; - return static_cast((n + inc) >> 32); -} -#endif - -// Optional version of count_digits for better performance on 32-bit platforms. -FMT_CONSTEXPR20 inline auto count_digits(uint32_t n) -> int { -#ifdef FMT_BUILTIN_CLZ - if (!is_constant_evaluated() && !FMT_OPTIMIZE_SIZE) return do_count_digits(n); -#endif - return count_digits_fallback(n); -} - -template constexpr auto digits10() noexcept -> int { - return std::numeric_limits::digits10; -} -template <> constexpr auto digits10() noexcept -> int { return 38; } -template <> constexpr auto digits10() noexcept -> int { return 38; } - -template struct thousands_sep_result { - std::string grouping; - Char thousands_sep; -}; - -template -FMT_API auto thousands_sep_impl(locale_ref loc) -> thousands_sep_result; -template -inline auto thousands_sep(locale_ref loc) -> thousands_sep_result { - auto result = thousands_sep_impl(loc); - return {result.grouping, Char(result.thousands_sep)}; -} -template <> -inline auto thousands_sep(locale_ref loc) -> thousands_sep_result { - return thousands_sep_impl(loc); -} - -template -FMT_API auto decimal_point_impl(locale_ref loc) -> Char; -template inline auto decimal_point(locale_ref loc) -> Char { - return Char(decimal_point_impl(loc)); -} -template <> inline auto decimal_point(locale_ref loc) -> wchar_t { - return decimal_point_impl(loc); -} - -#ifndef FMT_HEADER_ONLY -FMT_BEGIN_EXPORT -extern template FMT_API auto thousands_sep_impl(locale_ref) - -> thousands_sep_result; -extern template FMT_API auto thousands_sep_impl(locale_ref) - -> thousands_sep_result; -extern template FMT_API auto decimal_point_impl(locale_ref) -> char; -extern template FMT_API auto decimal_point_impl(locale_ref) -> wchar_t; -FMT_END_EXPORT -#endif // FMT_HEADER_ONLY - -// Compares two characters for equality. -template auto equal2(const Char* lhs, const char* rhs) -> bool { - return lhs[0] == Char(rhs[0]) && lhs[1] == Char(rhs[1]); -} -inline auto equal2(const char* lhs, const char* rhs) -> bool { - return memcmp(lhs, rhs, 2) == 0; -} - -// Writes a two-digit value to out. -template -FMT_CONSTEXPR20 FMT_INLINE void write2digits(Char* out, size_t value) { - if (!is_constant_evaluated() && std::is_same::value && - !FMT_OPTIMIZE_SIZE) { - memcpy(out, digits2(value), 2); - return; - } - *out++ = static_cast('0' + value / 10); - *out = static_cast('0' + value % 10); -} - -// Formats a decimal unsigned integer value writing to out pointing to a buffer -// of specified size. The caller must ensure that the buffer is large enough. -template -FMT_CONSTEXPR20 auto do_format_decimal(Char* out, UInt value, int size) - -> Char* { - FMT_ASSERT(size >= count_digits(value), "invalid digit count"); - unsigned n = to_unsigned(size); - while (value >= 100) { - // Integer division is slow so do it for a group of two digits instead - // of for every digit. The idea comes from the talk by Alexandrescu - // "Three Optimization Tips for C++". See speed-test for a comparison. - n -= 2; - write2digits(out + n, static_cast(value % 100)); - value /= 100; - } - if (value >= 10) { - n -= 2; - write2digits(out + n, static_cast(value)); - } else { - out[--n] = static_cast('0' + value); - } - return out + n; -} - -template -FMT_CONSTEXPR FMT_INLINE auto format_decimal(Char* out, UInt value, - int num_digits) -> Char* { - do_format_decimal(out, value, num_digits); - return out + num_digits; -} - -template >::value)> -FMT_CONSTEXPR auto format_decimal(OutputIt out, UInt value, int num_digits) - -> OutputIt { - if (auto ptr = to_pointer(out, to_unsigned(num_digits))) { - do_format_decimal(ptr, value, num_digits); - return out; - } - // Buffer is large enough to hold all digits (digits10 + 1). - char buffer[digits10() + 1]; - if (is_constant_evaluated()) fill_n(buffer, sizeof(buffer), '\0'); - do_format_decimal(buffer, value, num_digits); - return copy_noinline(buffer, buffer + num_digits, out); -} - -template -FMT_CONSTEXPR auto do_format_base2e(int base_bits, Char* out, UInt value, - int size, bool upper = false) -> Char* { - out += size; - do { - const char* digits = upper ? "0123456789ABCDEF" : "0123456789abcdef"; - unsigned digit = static_cast(value & ((1u << base_bits) - 1)); - *--out = static_cast(base_bits < 4 ? static_cast('0' + digit) - : digits[digit]); - } while ((value >>= base_bits) != 0); - return out; -} - -// Formats an unsigned integer in the power of two base (binary, octal, hex). -template -FMT_CONSTEXPR auto format_base2e(int base_bits, Char* out, UInt value, - int num_digits, bool upper = false) -> Char* { - do_format_base2e(base_bits, out, value, num_digits, upper); - return out + num_digits; -} - -template ::value)> -FMT_CONSTEXPR inline auto format_base2e(int base_bits, OutputIt out, UInt value, - int num_digits, bool upper = false) - -> OutputIt { - if (auto ptr = to_pointer(out, to_unsigned(num_digits))) { - format_base2e(base_bits, ptr, value, num_digits, upper); - return out; - } - // Make buffer large enough for any base. - char buffer[num_bits()]; - if (is_constant_evaluated()) fill_n(buffer, sizeof(buffer), '\0'); - format_base2e(base_bits, buffer, value, num_digits, upper); - return detail::copy_noinline(buffer, buffer + num_digits, out); -} - -// A converter from UTF-8 to UTF-16. -class utf8_to_utf16 { - private: - basic_memory_buffer buffer_; - - public: - FMT_API explicit utf8_to_utf16(string_view s); - inline operator basic_string_view() const { - return {&buffer_[0], size()}; - } - inline auto size() const -> size_t { return buffer_.size() - 1; } - inline auto c_str() const -> const wchar_t* { return &buffer_[0]; } - inline auto str() const -> std::wstring { return {&buffer_[0], size()}; } -}; - -enum class to_utf8_error_policy { abort, replace }; - -// A converter from UTF-16/UTF-32 (host endian) to UTF-8. -template class to_utf8 { - private: - Buffer buffer_; - - public: - to_utf8() {} - explicit to_utf8(basic_string_view s, - to_utf8_error_policy policy = to_utf8_error_policy::abort) { - static_assert(sizeof(WChar) == 2 || sizeof(WChar) == 4, - "expected utf16 or utf32"); - if (!convert(s, policy)) { - FMT_THROW(std::runtime_error(sizeof(WChar) == 2 ? "invalid utf16" - : "invalid utf32")); - } - } - operator string_view() const { return string_view(&buffer_[0], size()); } - auto size() const -> size_t { return buffer_.size() - 1; } - auto c_str() const -> const char* { return &buffer_[0]; } - auto str() const -> std::string { return std::string(&buffer_[0], size()); } - - // Performs conversion returning a bool instead of throwing exception on - // conversion error. This method may still throw in case of memory allocation - // error. - auto convert(basic_string_view s, - to_utf8_error_policy policy = to_utf8_error_policy::abort) - -> bool { - if (!convert(buffer_, s, policy)) return false; - buffer_.push_back(0); - return true; - } - static auto convert(Buffer& buf, basic_string_view s, - to_utf8_error_policy policy = to_utf8_error_policy::abort) - -> bool { - for (auto p = s.begin(); p != s.end(); ++p) { - uint32_t c = static_cast(*p); - if (sizeof(WChar) == 2 && c >= 0xd800 && c <= 0xdfff) { - // Handle a surrogate pair. - ++p; - if (p == s.end() || (c & 0xfc00) != 0xd800 || (*p & 0xfc00) != 0xdc00) { - if (policy == to_utf8_error_policy::abort) return false; - buf.append(string_view("\xEF\xBF\xBD")); - --p; - continue; - } - c = (c << 10) + static_cast(*p) - 0x35fdc00; - } - if (c < 0x80) { - buf.push_back(static_cast(c)); - } else if (c < 0x800) { - buf.push_back(static_cast(0xc0 | (c >> 6))); - buf.push_back(static_cast(0x80 | (c & 0x3f))); - } else if ((c >= 0x800 && c <= 0xd7ff) || (c >= 0xe000 && c <= 0xffff)) { - buf.push_back(static_cast(0xe0 | (c >> 12))); - buf.push_back(static_cast(0x80 | ((c & 0xfff) >> 6))); - buf.push_back(static_cast(0x80 | (c & 0x3f))); - } else if (c >= 0x10000 && c <= 0x10ffff) { - buf.push_back(static_cast(0xf0 | (c >> 18))); - buf.push_back(static_cast(0x80 | ((c & 0x3ffff) >> 12))); - buf.push_back(static_cast(0x80 | ((c & 0xfff) >> 6))); - buf.push_back(static_cast(0x80 | (c & 0x3f))); - } else { - return false; - } - } - return true; - } -}; - -// Computes 128-bit result of multiplication of two 64-bit unsigned integers. -FMT_INLINE auto umul128(uint64_t x, uint64_t y) noexcept -> uint128_fallback { -#if FMT_USE_INT128 - auto p = static_cast(x) * static_cast(y); - return {static_cast(p >> 64), static_cast(p)}; -#elif defined(_MSC_VER) && defined(_M_X64) - auto hi = uint64_t(); - auto lo = _umul128(x, y, &hi); - return {hi, lo}; -#else - const uint64_t mask = static_cast(max_value()); - - uint64_t a = x >> 32; - uint64_t b = x & mask; - uint64_t c = y >> 32; - uint64_t d = y & mask; - - uint64_t ac = a * c; - uint64_t bc = b * c; - uint64_t ad = a * d; - uint64_t bd = b * d; - - uint64_t intermediate = (bd >> 32) + (ad & mask) + (bc & mask); - - return {ac + (intermediate >> 32) + (ad >> 32) + (bc >> 32), - (intermediate << 32) + (bd & mask)}; -#endif -} - -namespace dragonbox { -// Computes floor(log10(pow(2, e))) for e in [-2620, 2620] using the method from -// https://fmt.dev/papers/Dragonbox.pdf#page=28, section 6.1. -inline auto floor_log10_pow2(int e) noexcept -> int { - FMT_ASSERT(e <= 2620 && e >= -2620, "too large exponent"); - static_assert((-1 >> 1) == -1, "right shift is not arithmetic"); - return (e * 315653) >> 20; -} - -inline auto floor_log2_pow10(int e) noexcept -> int { - FMT_ASSERT(e <= 1233 && e >= -1233, "too large exponent"); - return (e * 1741647) >> 19; -} - -// Computes upper 64 bits of multiplication of two 64-bit unsigned integers. -inline auto umul128_upper64(uint64_t x, uint64_t y) noexcept -> uint64_t { -#if FMT_USE_INT128 - auto p = static_cast(x) * static_cast(y); - return static_cast(p >> 64); -#elif defined(_MSC_VER) && defined(_M_X64) - return __umulh(x, y); -#else - return umul128(x, y).high(); -#endif -} - -// Computes upper 128 bits of multiplication of a 64-bit unsigned integer and a -// 128-bit unsigned integer. -inline auto umul192_upper128(uint64_t x, uint128_fallback y) noexcept - -> uint128_fallback { - uint128_fallback r = umul128(x, y.high()); - r += umul128_upper64(x, y.low()); - return r; -} - -FMT_API auto get_cached_power(int k) noexcept -> uint128_fallback; - -// Type-specific information that Dragonbox uses. -template struct float_info; - -template <> struct float_info { - using carrier_uint = uint32_t; - static const int exponent_bits = 8; - static const int kappa = 1; - static const int big_divisor = 100; - static const int small_divisor = 10; - static const int min_k = -31; - static const int max_k = 46; - static const int shorter_interval_tie_lower_threshold = -35; - static const int shorter_interval_tie_upper_threshold = -35; -}; - -template <> struct float_info { - using carrier_uint = uint64_t; - static const int exponent_bits = 11; - static const int kappa = 2; - static const int big_divisor = 1000; - static const int small_divisor = 100; - static const int min_k = -292; - static const int max_k = 341; - static const int shorter_interval_tie_lower_threshold = -77; - static const int shorter_interval_tie_upper_threshold = -77; -}; - -// An 80- or 128-bit floating point number. -template -struct float_info::digits == 64 || - std::numeric_limits::digits == 113 || - is_float128::value>> { - using carrier_uint = detail::uint128_t; - static const int exponent_bits = 15; -}; - -// A double-double floating point number. -template -struct float_info::value>> { - using carrier_uint = detail::uint128_t; -}; - -template struct decimal_fp { - using significand_type = typename float_info::carrier_uint; - significand_type significand; - int exponent; -}; - -template FMT_API auto to_decimal(T x) noexcept -> decimal_fp; -} // namespace dragonbox - -// Returns true iff Float has the implicit bit which is not stored. -template constexpr auto has_implicit_bit() -> bool { - // An 80-bit FP number has a 64-bit significand an no implicit bit. - return std::numeric_limits::digits != 64; -} - -// Returns the number of significand bits stored in Float. The implicit bit is -// not counted since it is not stored. -template constexpr auto num_significand_bits() -> int { - // std::numeric_limits may not support __float128. - return is_float128() ? 112 - : (std::numeric_limits::digits - - (has_implicit_bit() ? 1 : 0)); -} - -template -constexpr auto exponent_mask() -> - typename dragonbox::float_info::carrier_uint { - using float_uint = typename dragonbox::float_info::carrier_uint; - return ((float_uint(1) << dragonbox::float_info::exponent_bits) - 1) - << num_significand_bits(); -} -template constexpr auto exponent_bias() -> int { - // std::numeric_limits may not support __float128. - return is_float128() ? 16383 - : std::numeric_limits::max_exponent - 1; -} - -FMT_CONSTEXPR inline auto compute_exp_size(int exp) -> int { - auto prefix_size = 2; // sign + 'e' - auto abs_exp = exp >= 0 ? exp : -exp; - if (abs_exp < 100) return prefix_size + 2; - return prefix_size + (abs_exp >= 1000 ? 4 : 3); -} - -// Writes the exponent exp in the form "[+-]d{2,3}" to buffer. -template -FMT_CONSTEXPR auto write_exponent(int exp, OutputIt out) -> OutputIt { - FMT_ASSERT(-10000 < exp && exp < 10000, "exponent out of range"); - if (exp < 0) { - *out++ = static_cast('-'); - exp = -exp; - } else { - *out++ = static_cast('+'); - } - auto uexp = static_cast(exp); - if (is_constant_evaluated()) { - if (uexp < 10) *out++ = '0'; - return format_decimal(out, uexp, count_digits(uexp)); - } - if (uexp >= 100u) { - const char* top = digits2(uexp / 100); - if (uexp >= 1000u) *out++ = static_cast(top[0]); - *out++ = static_cast(top[1]); - uexp %= 100; - } - const char* d = digits2(uexp); - *out++ = static_cast(d[0]); - *out++ = static_cast(d[1]); - return out; -} - -// A floating-point number f * pow(2, e) where F is an unsigned type. -template struct basic_fp { - F f; - int e; - - static constexpr int num_significand_bits = - static_cast(sizeof(F) * num_bits()); - - constexpr basic_fp() : f(0), e(0) {} - constexpr basic_fp(uint64_t f_val, int e_val) : f(f_val), e(e_val) {} - - // Constructs fp from an IEEE754 floating-point number. - template FMT_CONSTEXPR basic_fp(Float n) { assign(n); } - - // Assigns n to this and return true iff predecessor is closer than successor. - template ::value)> - FMT_CONSTEXPR auto assign(Float n) -> bool { - static_assert(std::numeric_limits::digits <= 113, "unsupported FP"); - // Assume Float is in the format [sign][exponent][significand]. - using carrier_uint = typename dragonbox::float_info::carrier_uint; - const auto num_float_significand_bits = - detail::num_significand_bits(); - const auto implicit_bit = carrier_uint(1) << num_float_significand_bits; - const auto significand_mask = implicit_bit - 1; - auto u = bit_cast(n); - f = static_cast(u & significand_mask); - auto biased_e = static_cast((u & exponent_mask()) >> - num_float_significand_bits); - // The predecessor is closer if n is a normalized power of 2 (f == 0) - // other than the smallest normalized number (biased_e > 1). - auto is_predecessor_closer = f == 0 && biased_e > 1; - if (biased_e == 0) - biased_e = 1; // Subnormals use biased exponent 1 (min exponent). - else if (has_implicit_bit()) - f += static_cast(implicit_bit); - e = biased_e - exponent_bias() - num_float_significand_bits; - if (!has_implicit_bit()) ++e; - return is_predecessor_closer; - } - - template ::value)> - FMT_CONSTEXPR auto assign(Float n) -> bool { - static_assert(std::numeric_limits::is_iec559, "unsupported FP"); - return assign(static_cast(n)); - } -}; - -using fp = basic_fp; - -// Normalizes the value converted from double and multiplied by (1 << SHIFT). -template -FMT_CONSTEXPR auto normalize(basic_fp value) -> basic_fp { - // Handle subnormals. - const auto implicit_bit = F(1) << num_significand_bits(); - const auto shifted_implicit_bit = implicit_bit << SHIFT; - while ((value.f & shifted_implicit_bit) == 0) { - value.f <<= 1; - --value.e; - } - // Subtract 1 to account for hidden bit. - const auto offset = basic_fp::num_significand_bits - - num_significand_bits() - SHIFT - 1; - value.f <<= offset; - value.e -= offset; - return value; -} - -// Computes lhs * rhs / pow(2, 64) rounded to nearest with half-up tie breaking. -FMT_CONSTEXPR inline auto multiply(uint64_t lhs, uint64_t rhs) -> uint64_t { -#if FMT_USE_INT128 - auto product = static_cast<__uint128_t>(lhs) * rhs; - auto f = static_cast(product >> 64); - return (static_cast(product) & (1ULL << 63)) != 0 ? f + 1 : f; -#else - // Multiply 32-bit parts of significands. - uint64_t mask = (1ULL << 32) - 1; - uint64_t a = lhs >> 32, b = lhs & mask; - uint64_t c = rhs >> 32, d = rhs & mask; - uint64_t ac = a * c, bc = b * c, ad = a * d, bd = b * d; - // Compute mid 64-bit of result and round. - uint64_t mid = (bd >> 32) + (ad & mask) + (bc & mask) + (1U << 31); - return ac + (ad >> 32) + (bc >> 32) + (mid >> 32); -#endif -} - -FMT_CONSTEXPR inline auto operator*(fp x, fp y) -> fp { - return {multiply(x.f, y.f), x.e + y.e + 64}; -} - -template () == num_bits()> -using convert_float_result = - conditional_t::value || doublish, double, T>; - -template -constexpr auto convert_float(T value) -> convert_float_result { - return static_cast>(value); -} - -template -auto select(T true_value, F) -> T { - return true_value; -} -template -auto select(T, F false_value) -> F { - return false_value; -} - -template -FMT_CONSTEXPR FMT_NOINLINE auto fill(OutputIt it, size_t n, - const basic_specs& specs) -> OutputIt { - auto fill_size = specs.fill_size(); - if (fill_size == 1) return detail::fill_n(it, n, specs.fill_unit()); - if (const Char* data = specs.fill()) { - for (size_t i = 0; i < n; ++i) it = copy(data, data + fill_size, it); - } - return it; -} - -// Writes the output of f, padded according to format specifications in specs. -// size: output size in code units. -// width: output display width in (terminal) column positions. -template -FMT_CONSTEXPR auto write_padded(OutputIt out, const format_specs& specs, - size_t size, size_t width, F&& f) -> OutputIt { - static_assert(default_align == align::left || default_align == align::right, - ""); - unsigned spec_width = to_unsigned(specs.width); - size_t padding = spec_width > width ? spec_width - width : 0; - // Shifts are encoded as string literals because static constexpr is not - // supported in constexpr functions. - auto* shifts = - default_align == align::left ? "\x1f\x1f\x00\x01" : "\x00\x1f\x00\x01"; - size_t left_padding = padding >> shifts[static_cast(specs.align())]; - size_t right_padding = padding - left_padding; - auto it = reserve(out, size + padding * specs.fill_size()); - if (left_padding != 0) it = fill(it, left_padding, specs); - it = f(it); - if (right_padding != 0) it = fill(it, right_padding, specs); - return base_iterator(out, it); -} - -template -constexpr auto write_padded(OutputIt out, const format_specs& specs, - size_t size, F&& f) -> OutputIt { - return write_padded(out, specs, size, size, f); -} - -template -FMT_CONSTEXPR auto write_bytes(OutputIt out, string_view bytes, - const format_specs& specs = {}) -> OutputIt { - return write_padded( - out, specs, bytes.size(), [bytes](reserve_iterator it) { - const char* data = bytes.data(); - return copy(data, data + bytes.size(), it); - }); -} - -template -auto write_ptr(OutputIt out, UIntPtr value, const format_specs* specs) - -> OutputIt { - int num_digits = count_digits<4>(value); - auto size = to_unsigned(num_digits) + size_t(2); - auto write = [=](reserve_iterator it) { - *it++ = static_cast('0'); - *it++ = static_cast('x'); - return format_base2e(4, it, value, num_digits); - }; - return specs ? write_padded(out, *specs, size, write) - : base_iterator(out, write(reserve(out, size))); -} - -// Returns true iff the code point cp is printable. -FMT_API auto is_printable(uint32_t cp) -> bool; - -inline auto needs_escape(uint32_t cp) -> bool { - if (cp < 0x20 || cp == 0x7f || cp == '"' || cp == '\\') return true; - if (const_check(FMT_OPTIMIZE_SIZE > 1)) return false; - return !is_printable(cp); -} - -template struct find_escape_result { - const Char* begin; - const Char* end; - uint32_t cp; -}; - -template -auto find_escape(const Char* begin, const Char* end) - -> find_escape_result { - for (; begin != end; ++begin) { - uint32_t cp = static_cast>(*begin); - if (const_check(sizeof(Char) == 1) && cp >= 0x80) continue; - if (needs_escape(cp)) return {begin, begin + 1, cp}; - } - return {begin, nullptr, 0}; -} - -inline auto find_escape(const char* begin, const char* end) - -> find_escape_result { - if (const_check(!use_utf8)) return find_escape(begin, end); - auto result = find_escape_result{end, nullptr, 0}; - for_each_codepoint(string_view(begin, to_unsigned(end - begin)), - [&](uint32_t cp, string_view sv) { - if (needs_escape(cp)) { - result = {sv.begin(), sv.end(), cp}; - return false; - } - return true; - }); - return result; -} - -template -auto write_codepoint(OutputIt out, char prefix, uint32_t cp) -> OutputIt { - *out++ = static_cast('\\'); - *out++ = static_cast(prefix); - Char buf[width]; - fill_n(buf, width, static_cast('0')); - format_base2e(4, buf, cp, width); - return copy(buf, buf + width, out); -} - -template -auto write_escaped_cp(OutputIt out, const find_escape_result& escape) - -> OutputIt { - auto c = static_cast(escape.cp); - switch (escape.cp) { - case '\n': - *out++ = static_cast('\\'); - c = static_cast('n'); - break; - case '\r': - *out++ = static_cast('\\'); - c = static_cast('r'); - break; - case '\t': - *out++ = static_cast('\\'); - c = static_cast('t'); - break; - case '"': FMT_FALLTHROUGH; - case '\'': FMT_FALLTHROUGH; - case '\\': *out++ = static_cast('\\'); break; - default: - if (escape.cp < 0x100) return write_codepoint<2, Char>(out, 'x', escape.cp); - if (escape.cp < 0x10000) - return write_codepoint<4, Char>(out, 'u', escape.cp); - if (escape.cp < 0x110000) - return write_codepoint<8, Char>(out, 'U', escape.cp); - for (Char escape_char : basic_string_view( - escape.begin, to_unsigned(escape.end - escape.begin))) { - out = write_codepoint<2, Char>(out, 'x', - static_cast(escape_char) & 0xFF); - } - return out; - } - *out++ = c; - return out; -} - -template -auto write_escaped_string(OutputIt out, basic_string_view str) - -> OutputIt { - *out++ = static_cast('"'); - auto begin = str.begin(), end = str.end(); - do { - auto escape = find_escape(begin, end); - out = copy(begin, escape.begin, out); - begin = escape.end; - if (!begin) break; - out = write_escaped_cp(out, escape); - } while (begin != end); - *out++ = static_cast('"'); - return out; -} - -template -auto write_escaped_char(OutputIt out, Char v) -> OutputIt { - Char v_array[1] = {v}; - *out++ = static_cast('\''); - if ((needs_escape(static_cast(v)) && v != static_cast('"')) || - v == static_cast('\'')) { - out = write_escaped_cp(out, - find_escape_result{v_array, v_array + 1, - static_cast(v)}); - } else { - *out++ = v; - } - *out++ = static_cast('\''); - return out; -} - -template -FMT_CONSTEXPR auto write_char(OutputIt out, Char value, - const format_specs& specs) -> OutputIt { - bool is_debug = specs.type() == presentation_type::debug; - return write_padded(out, specs, 1, [=](reserve_iterator it) { - if (is_debug) return write_escaped_char(it, value); - *it++ = value; - return it; - }); -} - -template class digit_grouping { - private: - std::string grouping_; - std::basic_string thousands_sep_; - - struct next_state { - std::string::const_iterator group; - int pos; - }; - auto initial_state() const -> next_state { return {grouping_.begin(), 0}; } - - // Returns the next digit group separator position. - auto next(next_state& state) const -> int { - if (thousands_sep_.empty()) return max_value(); - if (state.group == grouping_.end()) return state.pos += grouping_.back(); - if (*state.group <= 0 || *state.group == max_value()) - return max_value(); - state.pos += *state.group++; - return state.pos; - } - - public: - explicit digit_grouping(locale_ref loc, bool localized = true) { - if (!localized) return; - auto sep = thousands_sep(loc); - grouping_ = sep.grouping; - if (sep.thousands_sep) thousands_sep_.assign(1, sep.thousands_sep); - } - digit_grouping(std::string grouping, std::basic_string sep) - : grouping_(std::move(grouping)), thousands_sep_(std::move(sep)) {} - - auto has_separator() const -> bool { return !thousands_sep_.empty(); } - - auto count_separators(int num_digits) const -> int { - int count = 0; - auto state = initial_state(); - while (num_digits > next(state)) ++count; - return count; - } - - // Applies grouping to digits and writes the output to out. - template - auto apply(Out out, basic_string_view digits) const -> Out { - auto num_digits = static_cast(digits.size()); - auto separators = basic_memory_buffer(); - separators.push_back(0); - auto state = initial_state(); - while (int i = next(state)) { - if (i >= num_digits) break; - separators.push_back(i); - } - for (int i = 0, sep_index = static_cast(separators.size() - 1); - i < num_digits; ++i) { - if (num_digits - i == separators[sep_index]) { - out = copy(thousands_sep_.data(), - thousands_sep_.data() + thousands_sep_.size(), out); - --sep_index; - } - *out++ = static_cast(digits[to_unsigned(i)]); - } - return out; - } -}; - -FMT_CONSTEXPR inline void prefix_append(unsigned& prefix, unsigned value) { - prefix |= prefix != 0 ? value << 8 : value; - prefix += (1u + (value > 0xff ? 1 : 0)) << 24; -} - -// Writes a decimal integer with digit grouping. -template -auto write_int(OutputIt out, UInt value, unsigned prefix, - const format_specs& specs, const digit_grouping& grouping) - -> OutputIt { - static_assert(std::is_same, UInt>::value, ""); - int num_digits = 0; - auto buffer = memory_buffer(); - switch (specs.type()) { - default: FMT_ASSERT(false, ""); FMT_FALLTHROUGH; - case presentation_type::none: - case presentation_type::dec: - num_digits = count_digits(value); - format_decimal(appender(buffer), value, num_digits); - break; - case presentation_type::hex: - if (specs.alt()) - prefix_append(prefix, unsigned(specs.upper() ? 'X' : 'x') << 8 | '0'); - num_digits = count_digits<4>(value); - format_base2e(4, appender(buffer), value, num_digits, specs.upper()); - break; - case presentation_type::oct: - num_digits = count_digits<3>(value); - // Octal prefix '0' is counted as a digit, so only add it if precision - // is not greater than the number of digits. - if (specs.alt() && specs.precision <= num_digits && value != 0) - prefix_append(prefix, '0'); - format_base2e(3, appender(buffer), value, num_digits); - break; - case presentation_type::bin: - if (specs.alt()) - prefix_append(prefix, unsigned(specs.upper() ? 'B' : 'b') << 8 | '0'); - num_digits = count_digits<1>(value); - format_base2e(1, appender(buffer), value, num_digits); - break; - case presentation_type::chr: - return write_char(out, static_cast(value), specs); - } - - unsigned size = (prefix != 0 ? prefix >> 24 : 0) + to_unsigned(num_digits) + - to_unsigned(grouping.count_separators(num_digits)); - return write_padded( - out, specs, size, size, [&](reserve_iterator it) { - for (unsigned p = prefix & 0xffffff; p != 0; p >>= 8) - *it++ = static_cast(p & 0xff); - return grouping.apply(it, string_view(buffer.data(), buffer.size())); - }); -} - -#if FMT_USE_LOCALE -// Writes a localized value. -FMT_API auto write_loc(appender out, loc_value value, const format_specs& specs, - locale_ref loc) -> bool; -auto write_loc(basic_appender out, loc_value value, - const format_specs& specs, locale_ref loc) -> bool; -#endif -template -inline auto write_loc(OutputIt, const loc_value&, const format_specs&, - locale_ref) -> bool { - return false; -} - -template struct write_int_arg { - UInt abs_value; - unsigned prefix; -}; - -template -FMT_CONSTEXPR auto make_write_int_arg(T value, sign s) - -> write_int_arg> { - auto prefix = 0u; - auto abs_value = static_cast>(value); - if (is_negative(value)) { - prefix = 0x01000000 | '-'; - abs_value = 0 - abs_value; - } else { - constexpr unsigned prefixes[4] = {0, 0, 0x1000000u | '+', 0x1000000u | ' '}; - prefix = prefixes[static_cast(s)]; - } - return {abs_value, prefix}; -} - -template struct loc_writer { - basic_appender out; - const format_specs& specs; - std::basic_string sep; - std::string grouping; - std::basic_string decimal_point; - - template ::value)> - auto operator()(T value) -> bool { - auto arg = make_write_int_arg(value, specs.sign()); - write_int(out, static_cast>(arg.abs_value), arg.prefix, - specs, digit_grouping(grouping, sep)); - return true; - } - - template ::value)> - auto operator()(T) -> bool { - return false; - } -}; - -// Size and padding computation separate from write_int to avoid template bloat. -struct size_padding { - unsigned size; - unsigned padding; - - FMT_CONSTEXPR size_padding(int num_digits, unsigned prefix, - const format_specs& specs) - : size((prefix >> 24) + to_unsigned(num_digits)), padding(0) { - if (specs.align() == align::numeric) { - auto width = to_unsigned(specs.width); - if (width > size) { - padding = width - size; - size = width; - } - } else if (specs.precision > num_digits) { - size = (prefix >> 24) + to_unsigned(specs.precision); - padding = to_unsigned(specs.precision - num_digits); - } - } -}; - -template -FMT_CONSTEXPR FMT_INLINE auto write_int(OutputIt out, write_int_arg arg, - const format_specs& specs) -> OutputIt { - static_assert(std::is_same>::value, ""); - - constexpr size_t buffer_size = num_bits(); - char buffer[buffer_size]; - if (is_constant_evaluated()) fill_n(buffer, buffer_size, '\0'); - const char* begin = nullptr; - const char* end = buffer + buffer_size; - - auto abs_value = arg.abs_value; - auto prefix = arg.prefix; - switch (specs.type()) { - default: FMT_ASSERT(false, ""); FMT_FALLTHROUGH; - case presentation_type::none: - case presentation_type::dec: - begin = do_format_decimal(buffer, abs_value, buffer_size); - break; - case presentation_type::hex: - begin = do_format_base2e(4, buffer, abs_value, buffer_size, specs.upper()); - if (specs.alt()) - prefix_append(prefix, unsigned(specs.upper() ? 'X' : 'x') << 8 | '0'); - break; - case presentation_type::oct: { - begin = do_format_base2e(3, buffer, abs_value, buffer_size); - // Octal prefix '0' is counted as a digit, so only add it if precision - // is not greater than the number of digits. - auto num_digits = end - begin; - if (specs.alt() && specs.precision <= num_digits && abs_value != 0) - prefix_append(prefix, '0'); - break; - } - case presentation_type::bin: - begin = do_format_base2e(1, buffer, abs_value, buffer_size); - if (specs.alt()) - prefix_append(prefix, unsigned(specs.upper() ? 'B' : 'b') << 8 | '0'); - break; - case presentation_type::chr: - return write_char(out, static_cast(abs_value), specs); - } - - // Write an integer in the format - // - // prefix contains chars in three lower bytes and the size in the fourth byte. - int num_digits = static_cast(end - begin); - // Slightly faster check for specs.width == 0 && specs.precision == -1. - if ((specs.width | (specs.precision + 1)) == 0) { - auto it = reserve(out, to_unsigned(num_digits) + (prefix >> 24)); - for (unsigned p = prefix & 0xffffff; p != 0; p >>= 8) - *it++ = static_cast(p & 0xff); - return base_iterator(out, copy(begin, end, it)); - } - auto sp = size_padding(num_digits, prefix, specs); - unsigned padding = sp.padding; - return write_padded( - out, specs, sp.size, [=](reserve_iterator it) { - for (unsigned p = prefix & 0xffffff; p != 0; p >>= 8) - *it++ = static_cast(p & 0xff); - it = detail::fill_n(it, padding, static_cast('0')); - return copy(begin, end, it); - }); -} - -template -FMT_CONSTEXPR FMT_NOINLINE auto write_int_noinline(OutputIt out, - write_int_arg arg, - const format_specs& specs) - -> OutputIt { - return write_int(out, arg, specs); -} - -template ::value && - !std::is_same::value && - !std::is_same::value)> -FMT_CONSTEXPR FMT_INLINE auto write(basic_appender out, T value, - const format_specs& specs, locale_ref loc) - -> basic_appender { - if (specs.localized() && write_loc(out, value, specs, loc)) return out; - return write_int_noinline(out, make_write_int_arg(value, specs.sign()), - specs); -} - -// An inlined version of write used in format string compilation. -template ::value && - !std::is_same::value && - !std::is_same::value && - !std::is_same>::value)> -FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value, - const format_specs& specs, locale_ref loc) - -> OutputIt { - if (specs.localized() && write_loc(out, value, specs, loc)) return out; - return write_int(out, make_write_int_arg(value, specs.sign()), specs); -} - -template -FMT_CONSTEXPR auto write(OutputIt out, Char value, const format_specs& specs, - locale_ref loc = {}) -> OutputIt { - // char is formatted as unsigned char for consistency across platforms. - using unsigned_type = - conditional_t::value, unsigned char, unsigned>; - return check_char_specs(specs) - ? write_char(out, value, specs) - : write(out, static_cast(value), specs, loc); -} - -template ::value)> -FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, - const format_specs& specs) -> OutputIt { - bool is_debug = specs.type() == presentation_type::debug; - if (specs.precision < 0 && specs.width == 0) { - auto&& it = reserve(out, s.size()); - return is_debug ? write_escaped_string(it, s) : copy(s, it); - } - - size_t display_width_limit = - specs.precision < 0 ? SIZE_MAX : to_unsigned(specs.precision); - size_t display_width = - !is_debug || specs.precision == 0 ? 0 : 1; // Account for opening '"'. - size_t size = !is_debug || specs.precision == 0 ? 0 : 1; - for_each_codepoint(s, [&](uint32_t cp, string_view sv) { - if (is_debug && needs_escape(cp)) { - counting_buffer buf; - write_escaped_cp(basic_appender(buf), - find_escape_result{sv.begin(), sv.end(), cp}); - // We're reinterpreting bytes as display width. That's okay - // because write_escaped_cp() only writes ASCII characters. - size_t cp_width = buf.count(); - if (display_width + cp_width <= display_width_limit) { - display_width += cp_width; - size += cp_width; - // If this is the end of the string, account for closing '"'. - if (display_width < display_width_limit && sv.end() == s.end()) { - ++display_width; - ++size; - } - return true; - } - - size += display_width_limit - display_width; - display_width = display_width_limit; - return false; - } - - size_t cp_width = display_width_of(cp); - if (cp_width + display_width <= display_width_limit) { - display_width += cp_width; - size += sv.size(); - // If this is the end of the string, account for closing '"'. - if (is_debug && display_width < display_width_limit && - sv.end() == s.end()) { - ++display_width; - ++size; - } - return true; - } - - return false; - }); - - struct bounded_output_iterator { - reserve_iterator underlying_iterator; - size_t bound; - - FMT_CONSTEXPR auto operator*() -> bounded_output_iterator& { return *this; } - FMT_CONSTEXPR auto operator++() -> bounded_output_iterator& { - return *this; - } - FMT_CONSTEXPR auto operator++(int) -> bounded_output_iterator& { - return *this; - } - FMT_CONSTEXPR auto operator=(char c) -> bounded_output_iterator& { - if (bound > 0) { - *underlying_iterator++ = c; - --bound; - } - return *this; - } - }; - - return write_padded( - out, specs, size, display_width, [=](reserve_iterator it) { - return is_debug - ? write_escaped_string(bounded_output_iterator{it, size}, s) - .underlying_iterator - : copy(s.data(), s.data() + size, it); - }); -} - -template ::value)> -FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, - const format_specs& specs) -> OutputIt { - auto data = s.data(); - auto size = s.size(); - if (specs.precision >= 0 && to_unsigned(specs.precision) < size) - size = to_unsigned(specs.precision); - - bool is_debug = specs.type() == presentation_type::debug; - if (is_debug) { - auto buf = counting_buffer(); - write_escaped_string(basic_appender(buf), s); - size = buf.count(); - } - - return write_padded( - out, specs, size, [=](reserve_iterator it) { - return is_debug ? write_escaped_string(it, s) - : copy(data, data + size, it); - }); -} - -template -FMT_CONSTEXPR auto write(OutputIt out, basic_string_view s, - const format_specs& specs, locale_ref) -> OutputIt { - return write(out, s, specs); -} - -template -FMT_CONSTEXPR auto write(OutputIt out, const Char* s, const format_specs& specs, - locale_ref) -> OutputIt { - if (specs.type() == presentation_type::pointer) - return write_ptr(out, bit_cast(s), &specs); - if (!s) report_error("string pointer is null"); - return write(out, basic_string_view(s), specs, {}); -} - -template ::value && - !std::is_same::value && - !std::is_same::value)> -FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt { - auto abs_value = static_cast>(value); - bool negative = is_negative(value); - // Don't do -abs_value since it trips unsigned-integer-overflow sanitizer. - if (negative) abs_value = ~abs_value + 1; - int num_digits = count_digits(abs_value); - auto size = (negative ? 1 : 0) + static_cast(num_digits); - if (auto ptr = to_pointer(out, size)) { - if (negative) *ptr++ = static_cast('-'); - format_decimal(ptr, abs_value, num_digits); - return out; - } - if (negative) *out++ = static_cast('-'); - return format_decimal(out, abs_value, num_digits); -} - -template -FMT_CONSTEXPR auto parse_align(const Char* begin, const Char* end, - format_specs& specs) -> const Char* { - FMT_ASSERT(begin != end, ""); - auto alignment = align::none; - auto p = begin + code_point_length(begin); - if (end - p <= 0) p = begin; - for (;;) { - switch (to_ascii(*p)) { - case '<': alignment = align::left; break; - case '>': alignment = align::right; break; - case '^': alignment = align::center; break; - } - if (alignment != align::none) { - if (p != begin) { - auto c = *begin; - if (c == '}') return begin; - if (c == '{') { - report_error("invalid fill character '{'"); - return begin; - } - specs.set_fill(basic_string_view(begin, to_unsigned(p - begin))); - begin = p + 1; - } else { - ++begin; - } - break; - } else if (p == begin) { - break; - } - p = begin; - } - specs.set_align(alignment); - return begin; -} - -template -FMT_CONSTEXPR20 auto write_nonfinite(OutputIt out, bool isnan, - format_specs specs, sign s) -> OutputIt { - auto str = - isnan ? (specs.upper() ? "NAN" : "nan") : (specs.upper() ? "INF" : "inf"); - constexpr size_t str_size = 3; - auto size = str_size + (s != sign::none ? 1 : 0); - // Replace '0'-padding with space for non-finite values. - const bool is_zero_fill = - specs.fill_size() == 1 && specs.fill_unit() == '0'; - if (is_zero_fill) specs.set_fill(' '); - return write_padded(out, specs, size, - [=](reserve_iterator it) { - if (s != sign::none) - *it++ = detail::getsign(s); - return copy(str, str + str_size, it); - }); -} - -// A decimal floating-point number significand * pow(10, exp). -struct big_decimal_fp { - const char* significand; - int significand_size; - int exponent; -}; - -constexpr auto get_significand_size(const big_decimal_fp& f) -> int { - return f.significand_size; -} -template -inline auto get_significand_size(const dragonbox::decimal_fp& f) -> int { - return count_digits(f.significand); -} - -template -constexpr auto write_significand(OutputIt out, const char* significand, - int significand_size) -> OutputIt { - return copy(significand, significand + significand_size, out); -} -template -inline auto write_significand(OutputIt out, UInt significand, - int significand_size) -> OutputIt { - return format_decimal(out, significand, significand_size); -} -template -FMT_CONSTEXPR20 auto write_significand(OutputIt out, T significand, - int significand_size, int exponent, - const Grouping& grouping) -> OutputIt { - if (!grouping.has_separator()) { - out = write_significand(out, significand, significand_size); - return detail::fill_n(out, exponent, static_cast('0')); - } - auto buffer = memory_buffer(); - write_significand(appender(buffer), significand, significand_size); - detail::fill_n(appender(buffer), exponent, '0'); - return grouping.apply(out, string_view(buffer.data(), buffer.size())); -} - -template ::value)> -inline auto write_significand(Char* out, UInt significand, int significand_size, - int integral_size, Char decimal_point) -> Char* { - if (!decimal_point) return format_decimal(out, significand, significand_size); - out += significand_size + 1; - Char* end = out; - int floating_size = significand_size - integral_size; - for (int i = floating_size / 2; i > 0; --i) { - out -= 2; - write2digits(out, static_cast(significand % 100)); - significand /= 100; - } - if (floating_size % 2 != 0) { - *--out = static_cast('0' + significand % 10); - significand /= 10; - } - *--out = decimal_point; - format_decimal(out - integral_size, significand, integral_size); - return end; -} - -template >::value)> -inline auto write_significand(OutputIt out, UInt significand, - int significand_size, int integral_size, - Char decimal_point) -> OutputIt { - // Buffer is large enough to hold digits (digits10 + 1) and a decimal point. - Char buffer[digits10() + 2]; - auto end = write_significand(buffer, significand, significand_size, - integral_size, decimal_point); - return detail::copy_noinline(buffer, end, out); -} - -template -FMT_CONSTEXPR auto write_significand(OutputIt out, const char* significand, - int significand_size, int integral_size, - Char decimal_point) -> OutputIt { - out = detail::copy_noinline(significand, significand + integral_size, - out); - if (!decimal_point) return out; - *out++ = decimal_point; - return detail::copy_noinline(significand + integral_size, - significand + significand_size, out); -} - -template -FMT_CONSTEXPR20 auto write_significand(OutputIt out, T significand, - int significand_size, int integral_size, - Char decimal_point, - const Grouping& grouping) -> OutputIt { - if (!grouping.has_separator()) { - return write_significand(out, significand, significand_size, integral_size, - decimal_point); - } - auto buffer = basic_memory_buffer(); - write_significand(basic_appender(buffer), significand, significand_size, - integral_size, decimal_point); - grouping.apply( - out, basic_string_view(buffer.data(), to_unsigned(integral_size))); - return detail::copy_noinline(buffer.data() + integral_size, - buffer.end(), out); -} - -// Numbers with exponents greater or equal to the returned value will use -// the exponential notation. -template FMT_CONSTEVAL auto exp_upper() -> int { - return std::numeric_limits::digits10 != 0 - ? min_of(16, std::numeric_limits::digits10 + 1) - : 16; -} - -// Use the fixed notation if the exponent is in [-4, exp_upper), -// e.g. 0.0001 instead of 1e-04. Otherwise use the exponent notation. -constexpr auto use_fixed(int exp, int exp_upper) -> bool { - return exp >= -4 && exp < exp_upper; -} - -template class fallback_digit_grouping { - public: - constexpr fallback_digit_grouping(locale_ref, bool) {} - - constexpr auto has_separator() const -> bool { return false; } - - constexpr auto count_separators(int) const -> int { return 0; } - - template - constexpr auto apply(Out out, basic_string_view) const -> Out { - return out; - } -}; - -template -FMT_CONSTEXPR20 auto write_fixed(OutputIt out, const DecimalFP& f, - int significand_size, Char decimal_point, - const format_specs& specs, sign s, - locale_ref loc = {}) -> OutputIt { - using iterator = reserve_iterator; - - int exp = f.exponent + significand_size; - long long size = significand_size + (s != sign::none ? 1 : 0); - if (f.exponent >= 0) { - // 1234e5 -> 123400000[.0+] - size += f.exponent; - int num_zeros = specs.precision - exp; - abort_fuzzing_if(num_zeros > 5000); - if (specs.alt()) { - ++size; - if (num_zeros <= 0 && specs.type() != presentation_type::fixed) - num_zeros = 0; - if (num_zeros > 0) size += num_zeros; - } - auto grouping = Grouping(loc, specs.localized()); - size += grouping.count_separators(exp); - return write_padded( - out, specs, to_unsigned(size), [&](iterator it) { - if (s != sign::none) *it++ = detail::getsign(s); - it = write_significand(it, f.significand, significand_size, - f.exponent, grouping); - if (!specs.alt()) return it; - *it++ = decimal_point; - return num_zeros > 0 ? detail::fill_n(it, num_zeros, Char('0')) : it; - }); - } - if (exp > 0) { - // 1234e-2 -> 12.34[0+] - int num_zeros = specs.alt() ? specs.precision - significand_size : 0; - size += 1 + max_of(num_zeros, 0); - auto grouping = Grouping(loc, specs.localized()); - size += grouping.count_separators(exp); - return write_padded( - out, specs, to_unsigned(size), [&](iterator it) { - if (s != sign::none) *it++ = detail::getsign(s); - it = write_significand(it, f.significand, significand_size, exp, - decimal_point, grouping); - return num_zeros > 0 ? detail::fill_n(it, num_zeros, Char('0')) : it; - }); - } - // 1234e-6 -> 0.001234 - int num_zeros = -exp; - if (significand_size == 0 && specs.precision >= 0 && - specs.precision < num_zeros) { - num_zeros = specs.precision; - } - bool pointy = num_zeros != 0 || significand_size != 0 || specs.alt(); - size += 1 + (pointy ? 1 : 0) + num_zeros; - return write_padded( - out, specs, to_unsigned(size), [&](iterator it) { - if (s != sign::none) *it++ = detail::getsign(s); - *it++ = Char('0'); - if (!pointy) return it; - *it++ = decimal_point; - it = detail::fill_n(it, num_zeros, Char('0')); - return write_significand(it, f.significand, significand_size); - }); -} - -template -FMT_CONSTEXPR20 auto do_write_float(OutputIt out, const DecimalFP& f, - const format_specs& specs, sign s, - int exp_upper, locale_ref loc) -> OutputIt { - Char point = specs.localized() ? detail::decimal_point(loc) : Char('.'); - int significand_size = get_significand_size(f); - int exp = f.exponent + significand_size - 1; - if (specs.type() == presentation_type::fixed || - (specs.type() != presentation_type::exp && - use_fixed(exp, specs.precision > 0 ? specs.precision : exp_upper))) { - return write_fixed(out, f, significand_size, point, specs, - s, loc); - } - - // Write value in the exponential format. - int num_zeros = 0; - long long size = significand_size + (s != sign::none ? 1 : 0); - if (specs.alt()) { - num_zeros = max_of(specs.precision - significand_size, 0); - size += num_zeros; - } else if (significand_size == 1) { - point = Char(); - } - size += (point ? 1 : 0) + compute_exp_size(exp); - char exp_char = specs.upper() ? 'E' : 'e'; - auto write = [=](reserve_iterator it) { - if (s != sign::none) *it++ = detail::getsign(s); - // Insert a decimal point after the first digit and add an exponent. - it = write_significand(it, f.significand, significand_size, 1, point); - if (num_zeros > 0) it = detail::fill_n(it, num_zeros, Char('0')); - *it++ = Char(exp_char); - return write_exponent(exp, it); - }; - auto usize = to_unsigned(size); - return specs.width > 0 - ? write_padded(out, specs, usize, write) - : base_iterator(out, write(reserve(out, usize))); -} - -template -FMT_CONSTEXPR20 auto write_float(OutputIt out, const DecimalFP& f, - const format_specs& specs, sign s, - int exp_upper, locale_ref loc) -> OutputIt { - if (is_constant_evaluated()) { - return do_write_float>(out, f, specs, s, - exp_upper, loc); - } else { - return do_write_float>(out, f, specs, s, - exp_upper, loc); - } -} - -template constexpr auto isnan(T value) -> bool { - return value != value; // std::isnan doesn't support __float128. -} - -template -struct has_isfinite : std::false_type {}; - -template -struct has_isfinite> - : std::true_type {}; - -template ::value&& has_isfinite::value)> -FMT_CONSTEXPR20 auto isfinite(T value) -> bool { - constexpr T inf = T(std::numeric_limits::infinity()); - if (is_constant_evaluated()) - return !detail::isnan(value) && value < inf && value > -inf; - return std::isfinite(value); -} -template ::value)> -FMT_CONSTEXPR auto isfinite(T value) -> bool { - T inf = T(std::numeric_limits::infinity()); - // std::isfinite doesn't support __float128. - return !detail::isnan(value) && value < inf && value > -inf; -} - -template ::value)> -FMT_INLINE FMT_CONSTEXPR auto signbit(T value) -> bool { - if (is_constant_evaluated()) { -#ifdef __cpp_if_constexpr - if constexpr (std::numeric_limits::is_iec559) { - auto bits = detail::bit_cast(static_cast(value)); - return (bits >> (num_bits() - 1)) != 0; - } -#endif - } - return std::signbit(static_cast(value)); -} - -inline FMT_CONSTEXPR20 void adjust_precision(int& precision, int exp10) { - // Adjust fixed precision by exponent because it is relative to decimal - // point. - if (exp10 > 0 && precision > max_value() - exp10) - FMT_THROW(format_error("number is too big")); - precision += exp10; -} - -class bigint { - private: - // A bigint is a number in the form bigit_[N - 1] ... bigit_[0] * 32^exp_. - using bigit = uint32_t; // A big digit. - using double_bigit = uint64_t; - enum { bigit_bits = num_bits() }; - enum { bigits_capacity = 32 }; - basic_memory_buffer bigits_; - int exp_; - - friend struct formatter; - - FMT_CONSTEXPR auto get_bigit(int i) const -> bigit { - return i >= exp_ && i < num_bigits() ? bigits_[i - exp_] : 0; - } - - FMT_CONSTEXPR void subtract_bigits(int index, bigit other, bigit& borrow) { - auto result = double_bigit(bigits_[index]) - other - borrow; - bigits_[index] = static_cast(result); - borrow = static_cast(result >> (bigit_bits * 2 - 1)); - } - - FMT_CONSTEXPR void remove_leading_zeros() { - int num_bigits = static_cast(bigits_.size()) - 1; - while (num_bigits > 0 && bigits_[num_bigits] == 0) --num_bigits; - bigits_.resize(to_unsigned(num_bigits + 1)); - } - - // Computes *this -= other assuming aligned bigints and *this >= other. - FMT_CONSTEXPR void subtract_aligned(const bigint& other) { - FMT_ASSERT(other.exp_ >= exp_, "unaligned bigints"); - FMT_ASSERT(compare(*this, other) >= 0, ""); - bigit borrow = 0; - int i = other.exp_ - exp_; - for (size_t j = 0, n = other.bigits_.size(); j != n; ++i, ++j) - subtract_bigits(i, other.bigits_[j], borrow); - if (borrow != 0) subtract_bigits(i, 0, borrow); - FMT_ASSERT(borrow == 0, ""); - remove_leading_zeros(); - } - - FMT_CONSTEXPR void multiply(uint32_t value) { - bigit carry = 0; - const double_bigit wide_value = value; - for (size_t i = 0, n = bigits_.size(); i < n; ++i) { - double_bigit result = bigits_[i] * wide_value + carry; - bigits_[i] = static_cast(result); - carry = static_cast(result >> bigit_bits); - } - if (carry != 0) bigits_.push_back(carry); - } - - template ::value || - std::is_same::value)> - FMT_CONSTEXPR void multiply(UInt value) { - using half_uint = - conditional_t::value, uint64_t, uint32_t>; - const int shift = num_bits() - bigit_bits; - const UInt lower = static_cast(value); - const UInt upper = value >> num_bits(); - UInt carry = 0; - for (size_t i = 0, n = bigits_.size(); i < n; ++i) { - UInt result = lower * bigits_[i] + static_cast(carry); - carry = (upper * bigits_[i] << shift) + (result >> bigit_bits) + - (carry >> bigit_bits); - bigits_[i] = static_cast(result); - } - while (carry != 0) { - bigits_.push_back(static_cast(carry)); - carry >>= bigit_bits; - } - } - - template ::value || - std::is_same::value)> - FMT_CONSTEXPR void assign(UInt n) { - size_t num_bigits = 0; - do { - bigits_[num_bigits++] = static_cast(n); - n >>= bigit_bits; - } while (n != 0); - bigits_.resize(num_bigits); - exp_ = 0; - } - - public: - FMT_CONSTEXPR bigint() : exp_(0) {} - explicit bigint(uint64_t n) { assign(n); } - - bigint(const bigint&) = delete; - void operator=(const bigint&) = delete; - - FMT_CONSTEXPR void assign(const bigint& other) { - auto size = other.bigits_.size(); - bigits_.resize(size); - auto data = other.bigits_.data(); - copy(data, data + size, bigits_.data()); - exp_ = other.exp_; - } - - template FMT_CONSTEXPR void operator=(Int n) { - FMT_ASSERT(n > 0, ""); - assign(uint64_or_128_t(n)); - } - - FMT_CONSTEXPR auto num_bigits() const -> int { - return static_cast(bigits_.size()) + exp_; - } - - FMT_CONSTEXPR auto operator<<=(int shift) -> bigint& { - FMT_ASSERT(shift >= 0, ""); - exp_ += shift / bigit_bits; - shift %= bigit_bits; - if (shift == 0) return *this; - bigit carry = 0; - for (size_t i = 0, n = bigits_.size(); i < n; ++i) { - bigit c = bigits_[i] >> (bigit_bits - shift); - bigits_[i] = (bigits_[i] << shift) + carry; - carry = c; - } - if (carry != 0) bigits_.push_back(carry); - return *this; - } - - template FMT_CONSTEXPR auto operator*=(Int value) -> bigint& { - FMT_ASSERT(value > 0, ""); - multiply(uint32_or_64_or_128_t(value)); - return *this; - } - - friend FMT_CONSTEXPR auto compare(const bigint& b1, const bigint& b2) -> int { - int num_bigits1 = b1.num_bigits(), num_bigits2 = b2.num_bigits(); - if (num_bigits1 != num_bigits2) return num_bigits1 > num_bigits2 ? 1 : -1; - int i = static_cast(b1.bigits_.size()) - 1; - int j = static_cast(b2.bigits_.size()) - 1; - int end = i - j; - if (end < 0) end = 0; - for (; i >= end; --i, --j) { - bigit b1_bigit = b1.bigits_[i], b2_bigit = b2.bigits_[j]; - if (b1_bigit != b2_bigit) return b1_bigit > b2_bigit ? 1 : -1; - } - if (i != j) return i > j ? 1 : -1; - return 0; - } - - // Returns compare(lhs1 + lhs2, rhs). - friend FMT_CONSTEXPR auto add_compare(const bigint& lhs1, const bigint& lhs2, - const bigint& rhs) -> int { - int max_lhs_bigits = max_of(lhs1.num_bigits(), lhs2.num_bigits()); - int num_rhs_bigits = rhs.num_bigits(); - if (max_lhs_bigits + 1 < num_rhs_bigits) return -1; - if (max_lhs_bigits > num_rhs_bigits) return 1; - double_bigit borrow = 0; - int min_exp = min_of(min_of(lhs1.exp_, lhs2.exp_), rhs.exp_); - for (int i = num_rhs_bigits - 1; i >= min_exp; --i) { - double_bigit sum = double_bigit(lhs1.get_bigit(i)) + lhs2.get_bigit(i); - bigit rhs_bigit = rhs.get_bigit(i); - if (sum > rhs_bigit + borrow) return 1; - borrow = rhs_bigit + borrow - sum; - if (borrow > 1) return -1; - borrow <<= bigit_bits; - } - return borrow != 0 ? -1 : 0; - } - - // Assigns pow(10, exp) to this bigint. - FMT_CONSTEXPR20 void assign_pow10(int exp) { - FMT_ASSERT(exp >= 0, ""); - if (exp == 0) return *this = 1; - int bitmask = 1 << (num_bits() - - countl_zero(static_cast(exp)) - 1); - // pow(10, exp) = pow(5, exp) * pow(2, exp). First compute pow(5, exp) by - // repeated squaring and multiplication. - *this = 5; - bitmask >>= 1; - while (bitmask != 0) { - square(); - if ((exp & bitmask) != 0) *this *= 5; - bitmask >>= 1; - } - *this <<= exp; // Multiply by pow(2, exp) by shifting. - } - - FMT_CONSTEXPR20 void square() { - int num_bigits = static_cast(bigits_.size()); - int num_result_bigits = 2 * num_bigits; - basic_memory_buffer n(std::move(bigits_)); - bigits_.resize(to_unsigned(num_result_bigits)); - auto sum = uint128_t(); - for (int bigit_index = 0; bigit_index < num_bigits; ++bigit_index) { - // Compute bigit at position bigit_index of the result by adding - // cross-product terms n[i] * n[j] such that i + j == bigit_index. - for (int i = 0, j = bigit_index; j >= 0; ++i, --j) { - // Most terms are multiplied twice which can be optimized in the future. - sum += double_bigit(n[i]) * n[j]; - } - bigits_[bigit_index] = static_cast(sum); - sum >>= num_bits(); // Compute the carry. - } - // Do the same for the top half. - for (int bigit_index = num_bigits; bigit_index < num_result_bigits; - ++bigit_index) { - for (int j = num_bigits - 1, i = bigit_index - j; i < num_bigits;) - sum += double_bigit(n[i++]) * n[j--]; - bigits_[bigit_index] = static_cast(sum); - sum >>= num_bits(); - } - remove_leading_zeros(); - exp_ *= 2; - } - - // If this bigint has a bigger exponent than other, adds trailing zero to make - // exponents equal. This simplifies some operations such as subtraction. - FMT_CONSTEXPR void align(const bigint& other) { - int exp_difference = exp_ - other.exp_; - if (exp_difference <= 0) return; - int num_bigits = static_cast(bigits_.size()); - bigits_.resize(to_unsigned(num_bigits + exp_difference)); - for (int i = num_bigits - 1, j = i + exp_difference; i >= 0; --i, --j) - bigits_[j] = bigits_[i]; - fill_n(bigits_.data(), to_unsigned(exp_difference), 0U); - exp_ -= exp_difference; - } - - // Divides this bignum by divisor, assigning the remainder to this and - // returning the quotient. - FMT_CONSTEXPR auto divmod_assign(const bigint& divisor) -> int { - FMT_ASSERT(this != &divisor, ""); - if (compare(*this, divisor) < 0) return 0; - FMT_ASSERT(divisor.bigits_[divisor.bigits_.size() - 1u] != 0, ""); - align(divisor); - int quotient = 0; - do { - subtract_aligned(divisor); - ++quotient; - } while (compare(*this, divisor) >= 0); - return quotient; - } -}; - -// format_dragon flags. -enum dragon { - predecessor_closer = 1, - fixup = 2, // Run fixup to correct exp10 which can be off by one. - fixed = 4, -}; - -// Formats a floating-point number using a variation of the Fixed-Precision -// Positive Floating-Point Printout ((FPP)^2) algorithm by Steele & White: -// https://fmt.dev/papers/p372-steele.pdf. -FMT_CONSTEXPR20 inline void format_dragon(basic_fp value, - unsigned flags, int num_digits, - buffer& buf, int& exp10) { - bigint numerator; // 2 * R in (FPP)^2. - bigint denominator; // 2 * S in (FPP)^2. - // lower and upper are differences between value and corresponding boundaries. - bigint lower; // (M^- in (FPP)^2). - bigint upper_store; // upper's value if different from lower. - bigint* upper = nullptr; // (M^+ in (FPP)^2). - // Shift numerator and denominator by an extra bit or two (if lower boundary - // is closer) to make lower and upper integers. This eliminates multiplication - // by 2 during later computations. - bool is_predecessor_closer = (flags & dragon::predecessor_closer) != 0; - int shift = is_predecessor_closer ? 2 : 1; - if (value.e >= 0) { - numerator = value.f; - numerator <<= value.e + shift; - lower = 1; - lower <<= value.e; - if (is_predecessor_closer) { - upper_store = 1; - upper_store <<= value.e + 1; - upper = &upper_store; - } - denominator.assign_pow10(exp10); - denominator <<= shift; - } else if (exp10 < 0) { - numerator.assign_pow10(-exp10); - lower.assign(numerator); - if (is_predecessor_closer) { - upper_store.assign(numerator); - upper_store <<= 1; - upper = &upper_store; - } - numerator *= value.f; - numerator <<= shift; - denominator = 1; - denominator <<= shift - value.e; - } else { - numerator = value.f; - numerator <<= shift; - denominator.assign_pow10(exp10); - denominator <<= shift - value.e; - lower = 1; - if (is_predecessor_closer) { - upper_store = 1ULL << 1; - upper = &upper_store; - } - } - int even = static_cast((value.f & 1) == 0); - if (!upper) upper = &lower; - bool shortest = num_digits < 0; - if ((flags & dragon::fixup) != 0) { - if (add_compare(numerator, *upper, denominator) + even <= 0) { - --exp10; - numerator *= 10; - if (num_digits < 0) { - lower *= 10; - if (upper != &lower) *upper *= 10; - } - } - if ((flags & dragon::fixed) != 0) adjust_precision(num_digits, exp10 + 1); - } - // Invariant: value == (numerator / denominator) * pow(10, exp10). - if (shortest) { - // Generate the shortest representation. - num_digits = 0; - char* data = buf.data(); - for (;;) { - int digit = numerator.divmod_assign(denominator); - bool low = compare(numerator, lower) - even < 0; // numerator <[=] lower. - // numerator + upper >[=] pow10: - bool high = add_compare(numerator, *upper, denominator) + even > 0; - data[num_digits++] = static_cast('0' + digit); - if (low || high) { - if (!low) { - ++data[num_digits - 1]; - } else if (high) { - int result = add_compare(numerator, numerator, denominator); - // Round half to even. - if (result > 0 || (result == 0 && (digit % 2) != 0)) - ++data[num_digits - 1]; - } - buf.try_resize(to_unsigned(num_digits)); - exp10 -= num_digits - 1; - return; - } - numerator *= 10; - lower *= 10; - if (upper != &lower) *upper *= 10; - } - } - // Generate the given number of digits. - exp10 -= num_digits - 1; - if (num_digits <= 0) { - auto digit = '0'; - if (num_digits == 0) { - denominator *= 10; - digit = add_compare(numerator, numerator, denominator) > 0 ? '1' : '0'; - } - buf.push_back(digit); - return; - } - buf.try_resize(to_unsigned(num_digits)); - for (int i = 0; i < num_digits - 1; ++i) { - int digit = numerator.divmod_assign(denominator); - buf[i] = static_cast('0' + digit); - numerator *= 10; - } - int digit = numerator.divmod_assign(denominator); - auto result = add_compare(numerator, numerator, denominator); - if (result > 0 || (result == 0 && (digit % 2) != 0)) { - if (digit == 9) { - const auto overflow = '0' + 10; - buf[num_digits - 1] = overflow; - // Propagate the carry. - for (int i = num_digits - 1; i > 0 && buf[i] == overflow; --i) { - buf[i] = '0'; - ++buf[i - 1]; - } - if (buf[0] == overflow) { - buf[0] = '1'; - if ((flags & dragon::fixed) != 0) - buf.push_back('0'); - else - ++exp10; - } - return; - } - ++digit; - } - buf[num_digits - 1] = static_cast('0' + digit); -} - -// Formats a floating-point number using the hexfloat format. -template ::value)> -FMT_CONSTEXPR20 void format_hexfloat(Float value, format_specs specs, - buffer& buf) { - // float is passed as double to reduce the number of instantiations and to - // simplify implementation. - static_assert(!std::is_same::value, ""); - - using info = dragonbox::float_info; - - // Assume Float is in the format [sign][exponent][significand]. - using carrier_uint = typename info::carrier_uint; - - const auto num_float_significand_bits = detail::num_significand_bits(); - - basic_fp f(value); - f.e += num_float_significand_bits; - if (!has_implicit_bit()) --f.e; - - const auto num_fraction_bits = - num_float_significand_bits + (has_implicit_bit() ? 1 : 0); - const auto num_xdigits = (num_fraction_bits + 3) / 4; - - const auto leading_shift = ((num_xdigits - 1) * 4); - const auto leading_mask = carrier_uint(0xF) << leading_shift; - const auto leading_xdigit = - static_cast((f.f & leading_mask) >> leading_shift); - if (leading_xdigit > 1) f.e -= (32 - countl_zero(leading_xdigit) - 1); - - int print_xdigits = num_xdigits - 1; - if (specs.precision >= 0 && print_xdigits > specs.precision) { - const int shift = ((print_xdigits - specs.precision - 1) * 4); - const auto mask = carrier_uint(0xF) << shift; - const auto v = static_cast((f.f & mask) >> shift); - - if (v >= 8) { - const auto inc = carrier_uint(1) << (shift + 4); - f.f += inc; - f.f &= ~(inc - 1); - } - - // Check long double overflow - if (!has_implicit_bit()) { - const auto implicit_bit = carrier_uint(1) << num_float_significand_bits; - if ((f.f & implicit_bit) == implicit_bit) { - f.f >>= 4; - f.e += 4; - } - } - - print_xdigits = specs.precision; - } - - char xdigits[num_bits() / 4]; - detail::fill_n(xdigits, sizeof(xdigits), '0'); - format_base2e(4, xdigits, f.f, num_xdigits, specs.upper()); - - // Remove zero tail - while (print_xdigits > 0 && xdigits[print_xdigits] == '0') --print_xdigits; - - buf.push_back('0'); - buf.push_back(specs.upper() ? 'X' : 'x'); - buf.push_back(xdigits[0]); - if (specs.alt() || print_xdigits > 0 || print_xdigits < specs.precision) - buf.push_back('.'); - buf.append(xdigits + 1, xdigits + 1 + print_xdigits); - for (; print_xdigits < specs.precision; ++print_xdigits) buf.push_back('0'); - - buf.push_back(specs.upper() ? 'P' : 'p'); - - uint32_t abs_e; - if (f.e < 0) { - buf.push_back('-'); - abs_e = static_cast(-f.e); - } else { - buf.push_back('+'); - abs_e = static_cast(f.e); - } - format_decimal(appender(buf), abs_e, detail::count_digits(abs_e)); -} - -template ::value)> -FMT_CONSTEXPR20 void format_hexfloat(Float value, format_specs specs, - buffer& buf) { - format_hexfloat(static_cast(value), specs, buf); -} - -constexpr auto fractional_part_rounding_thresholds(int index) -> uint32_t { - // For checking rounding thresholds. - // The kth entry is chosen to be the smallest integer such that the - // upper 32-bits of 10^(k+1) times it is strictly bigger than 5 * 10^k. - // It is equal to ceil(2^31 + 2^32/10^(k + 1)). - // These are stored in a string literal because we cannot have static arrays - // in constexpr functions and non-static ones are poorly optimized. - return U"\x9999999a\x828f5c29\x80418938\x80068db9\x8000a7c6\x800010c7" - U"\x800001ae\x8000002b"[index]; -} - -template -FMT_CONSTEXPR20 auto format_float(Float value, int precision, - const format_specs& specs, bool binary32, - buffer& buf) -> int { - // float is passed as double to reduce the number of instantiations. - static_assert(!std::is_same::value, ""); - auto converted_value = convert_float(value); - - const bool fixed = specs.type() == presentation_type::fixed; - if (value == 0) { - if (precision <= 0 || !fixed) { - buf.push_back('0'); - return 0; - } - buf.try_resize(to_unsigned(precision)); - fill_n(buf.data(), precision, '0'); - return -precision; - } - - int exp = 0; - bool use_dragon = true; - unsigned dragon_flags = 0; - if (!is_fast_float() || is_constant_evaluated()) { - const auto inv_log2_10 = 0.3010299956639812; // 1 / log2(10) - using info = dragonbox::float_info; - const auto f = basic_fp(converted_value); - // Compute exp, an approximate power of 10, such that - // 10^(exp - 1) <= value < 10^exp or 10^exp <= value < 10^(exp + 1). - // This is based on log10(value) == log2(value) / log2(10) and approximation - // of log2(value) by e + num_fraction_bits idea from double-conversion. - auto e = (f.e + count_digits<1>(f.f) - 1) * inv_log2_10 - 1e-10; - exp = static_cast(e); - if (e > exp) ++exp; // Compute ceil. - dragon_flags = dragon::fixup; - } else { - // Extract significand bits and exponent bits. - using info = dragonbox::float_info; - auto br = bit_cast(static_cast(value)); - - const uint64_t significand_mask = - (static_cast(1) << num_significand_bits()) - 1; - uint64_t significand = (br & significand_mask); - int exponent = static_cast((br & exponent_mask()) >> - num_significand_bits()); - - if (exponent != 0) { // Check if normal. - exponent -= exponent_bias() + num_significand_bits(); - significand |= - (static_cast(1) << num_significand_bits()); - significand <<= 1; - } else { - // Normalize subnormal inputs. - FMT_ASSERT(significand != 0, "zeros should not appear here"); - int shift = countl_zero(significand); - FMT_ASSERT(shift >= num_bits() - num_significand_bits(), - ""); - shift -= (num_bits() - num_significand_bits() - 2); - exponent = (std::numeric_limits::min_exponent - - num_significand_bits()) - - shift; - significand <<= shift; - } - - // Compute the first several nonzero decimal significand digits. - // We call the number we get the first segment. - const int k = info::kappa - dragonbox::floor_log10_pow2(exponent); - exp = -k; - const int beta = exponent + dragonbox::floor_log2_pow10(k); - uint64_t first_segment; - bool has_more_segments; - int digits_in_the_first_segment; - { - const auto r = dragonbox::umul192_upper128( - significand << beta, dragonbox::get_cached_power(k)); - first_segment = r.high(); - has_more_segments = r.low() != 0; - - // The first segment can have 18 ~ 19 digits. - if (first_segment >= 1000000000000000000ULL) { - digits_in_the_first_segment = 19; - } else { - // When it is of 18-digits, we align it to 19-digits by adding a bogus - // zero at the end. - digits_in_the_first_segment = 18; - first_segment *= 10; - } - } - - // Compute the actual number of decimal digits to print. - if (fixed) adjust_precision(precision, exp + digits_in_the_first_segment); - - // Use Dragon4 only when there might be not enough digits in the first - // segment. - if (digits_in_the_first_segment > precision) { - use_dragon = false; - - if (precision <= 0) { - exp += digits_in_the_first_segment; - - if (precision < 0) { - // Nothing to do, since all we have are just leading zeros. - buf.try_resize(0); - } else { - // We may need to round-up. - buf.try_resize(1); - if ((first_segment | static_cast(has_more_segments)) > - 5000000000000000000ULL) { - buf[0] = '1'; - } else { - buf[0] = '0'; - } - } - } // precision <= 0 - else { - exp += digits_in_the_first_segment - precision; - - // When precision > 0, we divide the first segment into three - // subsegments, each with 9, 9, and 0 ~ 1 digits so that each fits - // in 32-bits which usually allows faster calculation than in - // 64-bits. Since some compiler (e.g. MSVC) doesn't know how to optimize - // division-by-constant for large 64-bit divisors, we do it here - // manually. The magic number 7922816251426433760 below is equal to - // ceil(2^(64+32) / 10^10). - const uint32_t first_subsegment = static_cast( - dragonbox::umul128_upper64(first_segment, 7922816251426433760ULL) >> - 32); - const uint64_t second_third_subsegments = - first_segment - first_subsegment * 10000000000ULL; - - uint64_t prod; - uint32_t digits; - bool should_round_up; - int number_of_digits_to_print = min_of(precision, 9); - - // Print a 9-digits subsegment, either the first or the second. - auto print_subsegment = [&](uint32_t subsegment, char* buffer) { - int number_of_digits_printed = 0; - - // If we want to print an odd number of digits from the subsegment, - if ((number_of_digits_to_print & 1) != 0) { - // Convert to 64-bit fixed-point fractional form with 1-digit - // integer part. The magic number 720575941 is a good enough - // approximation of 2^(32 + 24) / 10^8; see - // https://jk-jeon.github.io/posts/2022/12/fixed-precision-formatting/#fixed-length-case - // for details. - prod = ((subsegment * static_cast(720575941)) >> 24) + 1; - digits = static_cast(prod >> 32); - *buffer = static_cast('0' + digits); - number_of_digits_printed++; - } - // If we want to print an even number of digits from the - // first_subsegment, - else { - // Convert to 64-bit fixed-point fractional form with 2-digits - // integer part. The magic number 450359963 is a good enough - // approximation of 2^(32 + 20) / 10^7; see - // https://jk-jeon.github.io/posts/2022/12/fixed-precision-formatting/#fixed-length-case - // for details. - prod = ((subsegment * static_cast(450359963)) >> 20) + 1; - digits = static_cast(prod >> 32); - write2digits(buffer, digits); - number_of_digits_printed += 2; - } - - // Print all digit pairs. - while (number_of_digits_printed < number_of_digits_to_print) { - prod = static_cast(prod) * static_cast(100); - digits = static_cast(prod >> 32); - write2digits(buffer + number_of_digits_printed, digits); - number_of_digits_printed += 2; - } - }; - - // Print first subsegment. - print_subsegment(first_subsegment, buf.data()); - - // Perform rounding if the first subsegment is the last subsegment to - // print. - if (precision <= 9) { - // Rounding inside the subsegment. - // We round-up if: - // - either the fractional part is strictly larger than 1/2, or - // - the fractional part is exactly 1/2 and the last digit is odd. - // We rely on the following observations: - // - If fractional_part >= threshold, then the fractional part is - // strictly larger than 1/2. - // - If the MSB of fractional_part is set, then the fractional part - // must be at least 1/2. - // - When the MSB of fractional_part is set, either - // second_third_subsegments being nonzero or has_more_segments - // being true means there are further digits not printed, so the - // fractional part is strictly larger than 1/2. - if (precision < 9) { - uint32_t fractional_part = static_cast(prod); - should_round_up = - fractional_part >= fractional_part_rounding_thresholds( - 8 - number_of_digits_to_print) || - ((fractional_part >> 31) & - ((digits & 1) | (second_third_subsegments != 0) | - has_more_segments)) != 0; - } - // Rounding at the subsegment boundary. - // In this case, the fractional part is at least 1/2 if and only if - // second_third_subsegments >= 5000000000ULL, and is strictly larger - // than 1/2 if we further have either second_third_subsegments > - // 5000000000ULL or has_more_segments == true. - else { - should_round_up = second_third_subsegments > 5000000000ULL || - (second_third_subsegments == 5000000000ULL && - ((digits & 1) != 0 || has_more_segments)); - } - } - // Otherwise, print the second subsegment. - else { - // Compilers are not aware of how to leverage the maximum value of - // second_third_subsegments to find out a better magic number which - // allows us to eliminate an additional shift. 1844674407370955162 = - // ceil(2^64/10) < ceil(2^64*(10^9/(10^10 - 1))). - const uint32_t second_subsegment = - static_cast(dragonbox::umul128_upper64( - second_third_subsegments, 1844674407370955162ULL)); - const uint32_t third_subsegment = - static_cast(second_third_subsegments) - - second_subsegment * 10; - - number_of_digits_to_print = precision - 9; - print_subsegment(second_subsegment, buf.data() + 9); - - // Rounding inside the subsegment. - if (precision < 18) { - // The condition third_subsegment != 0 implies that the segment was - // of 19 digits, so in this case the third segment should be - // consisting of a genuine digit from the input. - uint32_t fractional_part = static_cast(prod); - should_round_up = - fractional_part >= fractional_part_rounding_thresholds( - 8 - number_of_digits_to_print) || - ((fractional_part >> 31) & - ((digits & 1) | (third_subsegment != 0) | - has_more_segments)) != 0; - } - // Rounding at the subsegment boundary. - else { - // In this case, the segment must be of 19 digits, thus - // the third subsegment should be consisting of a genuine digit from - // the input. - should_round_up = third_subsegment > 5 || - (third_subsegment == 5 && - ((digits & 1) != 0 || has_more_segments)); - } - } - - // Round-up if necessary. - if (should_round_up) { - ++buf[precision - 1]; - for (int i = precision - 1; i > 0 && buf[i] > '9'; --i) { - buf[i] = '0'; - ++buf[i - 1]; - } - if (buf[0] > '9') { - buf[0] = '1'; - if (fixed) - buf[precision++] = '0'; - else - ++exp; - } - } - buf.try_resize(to_unsigned(precision)); - } - } // if (digits_in_the_first_segment > precision) - else { - // Adjust the exponent for its use in Dragon4. - exp += digits_in_the_first_segment - 1; - } - } - if (use_dragon) { - auto f = basic_fp(); - bool is_predecessor_closer = binary32 ? f.assign(static_cast(value)) - : f.assign(converted_value); - if (is_predecessor_closer) dragon_flags |= dragon::predecessor_closer; - if (fixed) dragon_flags |= dragon::fixed; - // Limit precision to the maximum possible number of significant digits in - // an IEEE754 double because we don't need to generate zeros. - const int max_double_digits = 767; - if (precision > max_double_digits) precision = max_double_digits; - format_dragon(f, dragon_flags, precision, buf, exp); - } - if (!fixed && !specs.alt()) { - // Remove trailing zeros. - auto num_digits = buf.size(); - while (num_digits > 0 && buf[num_digits - 1] == '0') { - --num_digits; - ++exp; - } - buf.try_resize(num_digits); - } - return exp; -} - -template ::value)> -FMT_CONSTEXPR20 auto write(OutputIt out, T value, format_specs specs, - locale_ref loc = {}) -> OutputIt { - if (specs.localized() && write_loc(out, value, specs, loc)) return out; - - // Use signbit because value < 0 is false for NaN. - sign s = detail::signbit(value) ? sign::minus : specs.sign(); - - if (!detail::isfinite(value)) - return write_nonfinite(out, detail::isnan(value), specs, s); - - if (specs.align() == align::numeric && s != sign::none) { - *out++ = detail::getsign(s); - s = sign::none; - if (specs.width != 0) --specs.width; - } - - const int exp_upper = detail::exp_upper(); - int precision = specs.precision; - if (precision < 0) { - if (specs.type() != presentation_type::none) { - precision = 6; - } else if (is_fast_float::value && !is_constant_evaluated()) { - // Use Dragonbox for the shortest format. - auto dec = dragonbox::to_decimal(static_cast>(value)); - return write_float(out, dec, specs, s, exp_upper, loc); - } - } - - memory_buffer buffer; - if (specs.type() == presentation_type::hexfloat) { - if (s != sign::none) buffer.push_back(detail::getsign(s)); - format_hexfloat(convert_float(value), specs, buffer); - return write_bytes(out, {buffer.data(), buffer.size()}, - specs); - } - - if (specs.type() == presentation_type::exp) { - if (precision == max_value()) - report_error("number is too big"); - else - ++precision; - if (specs.precision != 0) specs.set_alt(); - } else if (specs.type() == presentation_type::fixed) { - if (specs.precision != 0) specs.set_alt(); - } else if (precision == 0) { - precision = 1; - } - int exp = format_float(convert_float(value), precision, specs, - std::is_same(), buffer); - - specs.precision = precision; - auto f = big_decimal_fp{buffer.data(), static_cast(buffer.size()), exp}; - return write_float(out, f, specs, s, exp_upper, loc); -} - -template ::value)> -FMT_CONSTEXPR20 auto write(OutputIt out, T value) -> OutputIt { - if (is_constant_evaluated()) return write(out, value, format_specs()); - - auto s = detail::signbit(value) ? sign::minus : sign::none; - auto mask = exponent_mask>(); - if ((bit_cast(value) & mask) == mask) - return write_nonfinite(out, std::isnan(value), {}, s); - - auto dec = dragonbox::to_decimal(static_cast>(value)); - auto significand = dec.significand; - int significand_size = count_digits(significand); - int exponent = dec.exponent + significand_size - 1; - if (use_fixed(exponent, detail::exp_upper())) { - return write_fixed>( - out, dec, significand_size, Char('.'), {}, s); - } - - // Write value in the exponential format. - const char* prefix = "e+"; - int abs_exponent = exponent; - if (exponent < 0) { - abs_exponent = -exponent; - prefix = "e-"; - } - auto has_decimal_point = significand_size != 1; - size_t size = std::is_pointer::value - ? 0u - : to_unsigned((s != sign::none ? 1 : 0) + significand_size + - (has_decimal_point ? 1 : 0) + - (abs_exponent >= 100 ? 5 : 4)); - if (auto ptr = to_pointer(out, size)) { - if (s != sign::none) *ptr++ = Char('-'); - if (has_decimal_point) { - auto begin = ptr; - ptr = format_decimal(ptr, significand, significand_size + 1); - *begin = begin[1]; - begin[1] = '.'; - } else { - *ptr++ = static_cast('0' + significand); - } - if (std::is_same::value) { - memcpy(ptr, prefix, 2); - ptr += 2; - } else { - *ptr++ = prefix[0]; - *ptr++ = prefix[1]; - } - if (abs_exponent >= 100) { - *ptr++ = static_cast('0' + abs_exponent / 100); - abs_exponent %= 100; - } - write2digits(ptr, static_cast(abs_exponent)); - return select::value>(ptr + 2, out); - } - auto it = reserve(out, size); - if (s != sign::none) *it++ = Char('-'); - // Insert a decimal point after the first digit and add an exponent. - it = write_significand(it, significand, significand_size, 1, - has_decimal_point ? Char('.') : Char()); - *it++ = Char('e'); - it = write_exponent(exponent, it); - return base_iterator(out, it); -} - -template ::value && - !is_fast_float::value)> -inline auto write(OutputIt out, T value) -> OutputIt { - return write(out, value, {}); -} - -template -auto write(OutputIt out, monostate, format_specs = {}, locale_ref = {}) - -> OutputIt { - FMT_ASSERT(false, ""); - return out; -} - -template -FMT_CONSTEXPR auto write(OutputIt out, basic_string_view value) - -> OutputIt { - return copy_noinline(value.begin(), value.end(), out); -} - -template ::value)> -constexpr auto write(OutputIt out, const T& value) -> OutputIt { - return write(out, to_string_view(value)); -} - -// FMT_ENABLE_IF() condition separated to workaround an MSVC bug. -template < - typename Char, typename OutputIt, typename T, - bool check = std::is_enum::value && !std::is_same::value && - mapped_type_constant::value != type::custom_type, - FMT_ENABLE_IF(check)> -FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt { - return write(out, static_cast>(value)); -} - -template ::value)> -FMT_CONSTEXPR auto write(OutputIt out, T value, const format_specs& specs = {}, - locale_ref = {}) -> OutputIt { - return specs.type() != presentation_type::none && - specs.type() != presentation_type::string - ? write(out, value ? 1 : 0, specs, {}) - : write_bytes(out, value ? "true" : "false", specs); -} - -template -FMT_CONSTEXPR auto write(OutputIt out, Char value) -> OutputIt { - auto it = reserve(out, 1); - *it++ = value; - return base_iterator(out, it); -} - -template -FMT_CONSTEXPR20 auto write(OutputIt out, const Char* value) -> OutputIt { - if (value) return write(out, basic_string_view(value)); - report_error("string pointer is null"); - return out; -} - -template ::value)> -auto write(OutputIt out, const T* value, const format_specs& specs = {}, - locale_ref = {}) -> OutputIt { - return write_ptr(out, bit_cast(value), &specs); -} - -template ::value == - type::custom_type && - !std::is_fundamental::value)> -FMT_CONSTEXPR auto write(OutputIt out, const T& value) -> OutputIt { - auto f = formatter(); - auto parse_ctx = parse_context({}); - f.parse(parse_ctx); - auto ctx = basic_format_context(out, {}, {}); - return f.format(value, ctx); -} - -template -using is_builtin = - bool_constant::value || FMT_BUILTIN_TYPES>; - -// An argument visitor that formats the argument and writes it via the output -// iterator. It's a class and not a generic lambda for compatibility with C++11. -template struct default_arg_formatter { - using context = buffered_context; - - basic_appender out; - - void operator()(monostate) { report_error("argument not found"); } - - template ::value)> - void operator()(T value) { - write(out, value); - } - - template ::value)> - void operator()(T) { - FMT_ASSERT(false, ""); - } - - void operator()(typename basic_format_arg::handle h) { - // Use a null locale since the default format must be unlocalized. - auto parse_ctx = parse_context({}); - auto format_ctx = context(out, {}, {}); - h.format(parse_ctx, format_ctx); - } -}; - -template struct arg_formatter { - basic_appender out; - const format_specs& specs; - FMT_NO_UNIQUE_ADDRESS locale_ref locale; - - template ::value)> - FMT_CONSTEXPR FMT_INLINE void operator()(T value) { - detail::write(out, value, specs, locale); - } - - template ::value)> - void operator()(T) { - FMT_ASSERT(false, ""); - } - - void operator()(typename basic_format_arg>::handle) { - // User-defined types are handled separately because they require access - // to the parse context. - } -}; - -struct dynamic_spec_getter { - template ::value)> - FMT_CONSTEXPR auto operator()(T value) -> unsigned long long { - return is_negative(value) ? ~0ull : static_cast(value); - } - - template ::value)> - FMT_CONSTEXPR auto operator()(T) -> unsigned long long { - report_error("width/precision is not integer"); - return 0; - } -}; - -template -FMT_CONSTEXPR void handle_dynamic_spec( - arg_id_kind kind, int& value, - const arg_ref& ref, Context& ctx) { - if (kind == arg_id_kind::none) return; - auto arg = - kind == arg_id_kind::index ? ctx.arg(ref.index) : ctx.arg(ref.name); - if (!arg) report_error("argument not found"); - unsigned long long result = arg.visit(dynamic_spec_getter()); - if (result > to_unsigned(max_value())) - report_error("width/precision is out of range"); - value = static_cast(result); -} - -#if FMT_USE_NONTYPE_TEMPLATE_ARGS -template Str> -struct static_named_arg : view { - static constexpr auto name = Str.data; - - const T& value; - static_named_arg(const T& v) : value(v) {} -}; - -template Str> -struct is_named_arg> : std::true_type {}; - -template Str> -struct is_static_named_arg> : std::true_type { -}; - -template Str> -struct udl_arg { - template auto operator=(T&& value) const { - return static_named_arg(std::forward(value)); - } -}; -#else -template struct udl_arg { - const Char* str; - - template auto operator=(T&& value) const -> named_arg { - return {str, std::forward(value)}; - } -}; -#endif // FMT_USE_NONTYPE_TEMPLATE_ARGS - -template struct format_handler { - parse_context parse_ctx; - buffered_context ctx; - - void on_text(const Char* begin, const Char* end) { - copy_noinline(begin, end, ctx.out()); - } - - FMT_CONSTEXPR auto on_arg_id() -> int { return parse_ctx.next_arg_id(); } - FMT_CONSTEXPR auto on_arg_id(int id) -> int { - parse_ctx.check_arg_id(id); - return id; - } - FMT_CONSTEXPR auto on_arg_id(basic_string_view id) -> int { - parse_ctx.check_arg_id(id); - int arg_id = ctx.arg_id(id); - if (arg_id < 0) report_error("argument not found"); - return arg_id; - } - - FMT_INLINE void on_replacement_field(int id, const Char*) { - ctx.arg(id).visit(default_arg_formatter{ctx.out()}); - } - - auto on_format_specs(int id, const Char* begin, const Char* end) - -> const Char* { - auto arg = ctx.arg(id); - if (!arg) report_error("argument not found"); - // Not using a visitor for custom types gives better codegen. - if (arg.format_custom(begin, parse_ctx, ctx)) return parse_ctx.begin(); - - auto specs = dynamic_format_specs(); - begin = parse_format_specs(begin, end, specs, parse_ctx, arg.type()); - if (specs.dynamic()) { - handle_dynamic_spec(specs.dynamic_width(), specs.width, specs.width_ref, - ctx); - handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs.precision_ref, ctx); - } - - arg.visit(arg_formatter{ctx.out(), specs, ctx.locale()}); - return begin; - } - - FMT_NORETURN void on_error(const char* message) { report_error(message); } -}; - -// It is used in format-inl.h and os.cc. -using format_func = void (*)(detail::buffer&, int, const char*); -FMT_API void do_report_error(format_func func, int error_code, - const char* message) noexcept; - -FMT_API void format_error_code(buffer& out, int error_code, - string_view message) noexcept; - -template -template -FMT_CONSTEXPR auto native_formatter::format( - const T& val, FormatContext& ctx) const -> decltype(ctx.out()) { - if (!specs_.dynamic()) - return write(ctx.out(), val, specs_, ctx.locale()); - auto specs = format_specs(specs_); - handle_dynamic_spec(specs.dynamic_width(), specs.width, specs_.width_ref, - ctx); - handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs_.precision_ref, ctx); - return write(ctx.out(), val, specs, ctx.locale()); -} -} // namespace detail - -FMT_BEGIN_EXPORT - -// A generic formatting context with custom output iterator and character -// (code unit) support. Char is the format string code unit type which can be -// different from OutputIt::value_type. -template class generic_context { - private: - OutputIt out_; - basic_format_args args_; - locale_ref loc_; - - public: - using char_type = Char; - using iterator = OutputIt; - enum { builtin_types = FMT_BUILTIN_TYPES }; - - constexpr generic_context(OutputIt out, - basic_format_args args, - locale_ref loc = {}) - : out_(out), args_(args), loc_(loc) {} - generic_context(generic_context&&) = default; - generic_context(const generic_context&) = delete; - void operator=(const generic_context&) = delete; - - constexpr auto arg(int id) const -> basic_format_arg { - return args_.get(id); - } - auto arg(basic_string_view name) const - -> basic_format_arg { - return args_.get(name); - } - constexpr auto arg_id(basic_string_view name) const -> int { - return args_.get_id(name); - } - - constexpr auto out() const -> iterator { return out_; } - - void advance_to(iterator it) { - if (!detail::is_back_insert_iterator()) out_ = it; - } - - constexpr auto locale() const -> locale_ref { return loc_; } -}; - -class loc_value { - private: - basic_format_arg value_; - - public: - template ::value)> - loc_value(T value) : value_(value) {} - - template ::value)> - loc_value(T) {} - - template auto visit(Visitor&& vis) -> decltype(vis(0)) { - return value_.visit(vis); - } -}; - -// A locale facet that formats values in UTF-8. -// It is parameterized on the locale to avoid the heavy include. -template class format_facet : public Locale::facet { - private: - std::string separator_; - std::string grouping_; - std::string decimal_point_; - - protected: - virtual auto do_put(appender out, loc_value val, - const format_specs& specs) const -> bool; - - public: - static FMT_API typename Locale::id id; - - explicit format_facet(Locale& loc); - explicit format_facet(string_view sep = "", std::string grouping = "\3", - std::string decimal_point = ".") - : separator_(sep.data(), sep.size()), - grouping_(grouping), - decimal_point_(decimal_point) {} - - auto put(appender out, loc_value val, const format_specs& specs) const - -> bool { - return do_put(out, val, specs); - } -}; - -#define FMT_FORMAT_AS(Type, Base) \ - template \ - struct formatter : formatter { \ - template \ - FMT_CONSTEXPR auto format(Type value, FormatContext& ctx) const \ - -> decltype(ctx.out()) { \ - return formatter::format(value, ctx); \ - } \ - } - -FMT_FORMAT_AS(signed char, int); -FMT_FORMAT_AS(unsigned char, unsigned); -FMT_FORMAT_AS(short, int); -FMT_FORMAT_AS(unsigned short, unsigned); -FMT_FORMAT_AS(long, detail::long_type); -FMT_FORMAT_AS(unsigned long, detail::ulong_type); -FMT_FORMAT_AS(Char*, const Char*); -FMT_FORMAT_AS(detail::std_string_view, basic_string_view); -FMT_FORMAT_AS(std::nullptr_t, const void*); -FMT_FORMAT_AS(void*, const void*); - -template -struct formatter : formatter, Char> {}; - -template -class formatter, Char> - : public formatter, Char> {}; - -template -struct formatter, Char> : formatter {}; -template -struct formatter, Char> - : formatter {}; - -template -struct formatter - : detail::native_formatter {}; - -template -struct formatter>> - : formatter, Char> { - template - FMT_CONSTEXPR auto format(const T& value, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto&& val = format_as(value); // Make an lvalue reference for format. - return formatter, Char>::format(val, ctx); - } -}; - -/** - * Converts `p` to `const void*` for pointer formatting. - * - * **Example**: - * - * auto s = fmt::format("{}", fmt::ptr(p)); - */ -template auto ptr(T p) -> const void* { - static_assert(std::is_pointer::value, "fmt::ptr used with non-pointer"); - return detail::bit_cast(p); -} - -/** - * Converts `e` to the underlying type. - * - * **Example**: - * - * enum class color { red, green, blue }; - * auto s = fmt::format("{}", fmt::underlying(color::red)); // s == "0" - */ -template -constexpr auto underlying(Enum e) noexcept -> underlying_t { - return static_cast>(e); -} - -namespace enums { -template ::value)> -constexpr auto format_as(Enum e) noexcept -> underlying_t { - return static_cast>(e); -} -} // namespace enums - -#ifdef __cpp_lib_byte -template -struct formatter : formatter { - static auto format_as(std::byte b) -> unsigned char { - return static_cast(b); - } - template - auto format(std::byte b, Context& ctx) const -> decltype(ctx.out()) { - return formatter::format(format_as(b), ctx); - } -}; -#endif - -struct bytes { - string_view data; - - inline explicit bytes(string_view s) : data(s) {} -}; - -template <> struct formatter { - private: - detail::dynamic_format_specs<> specs_; - - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - return parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, - detail::type::string_type); - } - - template - auto format(bytes b, FormatContext& ctx) const -> decltype(ctx.out()) { - auto specs = specs_; - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs.precision_ref, ctx); - return detail::write_bytes(ctx.out(), b.data, specs); - } -}; - -// group_digits_view is not derived from view because it copies the argument. -template struct group_digits_view { - T value; -}; - -/** - * Returns a view that formats an integer value using ',' as a - * locale-independent thousands separator. - * - * **Example**: - * - * fmt::print("{}", fmt::group_digits(12345)); - * // Output: "12,345" - */ -template auto group_digits(T value) -> group_digits_view { - return {value}; -} - -template struct formatter> : formatter { - private: - detail::dynamic_format_specs<> specs_; - - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - return parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, - detail::type::int_type); - } - - template - auto format(group_digits_view view, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto specs = specs_; - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs.precision_ref, ctx); - auto arg = detail::make_write_int_arg(view.value, specs.sign()); - return detail::write_int( - ctx.out(), static_cast>(arg.abs_value), - arg.prefix, specs, detail::digit_grouping("\3", ",")); - } -}; - -template struct nested_view { - const formatter* fmt; - const T* value; -}; - -template -struct formatter, Char> { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return ctx.begin(); - } - template - auto format(nested_view view, FormatContext& ctx) const - -> decltype(ctx.out()) { - return view.fmt->format(*view.value, ctx); - } -}; - -template struct nested_formatter { - private: - basic_specs specs_; - int width_; - formatter formatter_; - - public: - constexpr nested_formatter() : width_(0) {} - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(), end = ctx.end(); - if (it == end) return it; - auto specs = format_specs(); - it = detail::parse_align(it, end, specs); - specs_ = specs; - Char c = *it; - auto width_ref = detail::arg_ref(); - if ((c >= '0' && c <= '9') || c == '{') { - it = detail::parse_width(it, end, specs, width_ref, ctx); - width_ = specs.width; - } - ctx.advance_to(it); - return formatter_.parse(ctx); - } - - template - auto write_padded(FormatContext& ctx, F write) const -> decltype(ctx.out()) { - if (width_ == 0) return write(ctx.out()); - auto buf = basic_memory_buffer(); - write(basic_appender(buf)); - auto specs = format_specs(); - specs.width = width_; - specs.copy_fill_from(specs_); - specs.set_align(specs_.align()); - return detail::write( - ctx.out(), basic_string_view(buf.data(), buf.size()), specs); - } - - auto nested(const T& value) const -> nested_view { - return nested_view{&formatter_, &value}; - } -}; - -inline namespace literals { -#if FMT_USE_NONTYPE_TEMPLATE_ARGS -template constexpr auto operator""_a() { - using char_t = remove_cvref_t; - return detail::udl_arg(); -} -#else -/** - * User-defined literal equivalent of `fmt::arg`. - * - * **Example**: - * - * using namespace fmt::literals; - * fmt::print("The answer is {answer}.", "answer"_a=42); - */ -constexpr auto operator""_a(const char* s, size_t) -> detail::udl_arg { - return {s}; -} -#endif // FMT_USE_NONTYPE_TEMPLATE_ARGS -} // namespace literals - -/// A fast integer formatter. -class format_int { - private: - // Buffer should be large enough to hold all digits (digits10 + 1), - // a sign and a null character. - enum { buffer_size = std::numeric_limits::digits10 + 3 }; - mutable char buffer_[buffer_size]; - char* str_; - - template - FMT_CONSTEXPR20 auto format_unsigned(UInt value) -> char* { - auto n = static_cast>(value); - return detail::do_format_decimal(buffer_, n, buffer_size - 1); - } - - template - FMT_CONSTEXPR20 auto format_signed(Int value) -> char* { - auto abs_value = static_cast>(value); - bool negative = value < 0; - if (negative) abs_value = 0 - abs_value; - auto begin = format_unsigned(abs_value); - if (negative) *--begin = '-'; - return begin; - } - - public: - FMT_CONSTEXPR20 explicit format_int(int value) : str_(format_signed(value)) {} - FMT_CONSTEXPR20 explicit format_int(long value) - : str_(format_signed(value)) {} - FMT_CONSTEXPR20 explicit format_int(long long value) - : str_(format_signed(value)) {} - FMT_CONSTEXPR20 explicit format_int(unsigned value) - : str_(format_unsigned(value)) {} - FMT_CONSTEXPR20 explicit format_int(unsigned long value) - : str_(format_unsigned(value)) {} - FMT_CONSTEXPR20 explicit format_int(unsigned long long value) - : str_(format_unsigned(value)) {} - - /// Returns the number of characters written to the output buffer. - FMT_CONSTEXPR20 auto size() const -> size_t { - return detail::to_unsigned(buffer_ - str_ + buffer_size - 1); - } - - /// Returns a pointer to the output buffer content. No terminating null - /// character is appended. - FMT_CONSTEXPR20 auto data() const -> const char* { return str_; } - - /// Returns a pointer to the output buffer content with terminating null - /// character appended. - FMT_CONSTEXPR20 auto c_str() const -> const char* { - buffer_[buffer_size - 1] = '\0'; - return str_; - } - - /// Returns the content of the output buffer as an `std::string`. - inline auto str() const -> std::string { return {str_, size()}; } -}; - -#if FMT_CLANG_ANALYZER -# define FMT_STRING_IMPL(s, base) s -#else -# define FMT_STRING_IMPL(s, base) \ - [] { \ - /* Use the hidden visibility as a workaround for a GCC bug (#1973). */ \ - /* Use a macro-like name to avoid shadowing warnings. */ \ - struct FMT_VISIBILITY("hidden") FMT_COMPILE_STRING : base { \ - using char_type = fmt::remove_cvref_t; \ - constexpr explicit operator fmt::basic_string_view() \ - const { \ - return fmt::detail::compile_string_to_view(s); \ - } \ - }; \ - using FMT_STRING_VIEW = \ - fmt::basic_string_view; \ - fmt::detail::ignore_unused(FMT_STRING_VIEW(FMT_COMPILE_STRING())); \ - return FMT_COMPILE_STRING(); \ - }() -#endif // FMT_CLANG_ANALYZER - -/** - * Constructs a legacy compile-time format string from a string literal `s`. - * - * **Example**: - * - * // A compile-time error because 'd' is an invalid specifier for strings. - * std::string s = fmt::format(FMT_STRING("{:d}"), "foo"); - */ -#define FMT_STRING(s) FMT_STRING_IMPL(s, fmt::detail::compile_string) - -FMT_API auto vsystem_error(int error_code, string_view fmt, format_args args) - -> std::system_error; - -/** - * Constructs `std::system_error` with a message formatted with - * `fmt::format(fmt, args...)`. - * `error_code` is a system error code as given by `errno`. - * - * **Example**: - * - * // This throws std::system_error with the description - * // cannot open file 'madeup': No such file or directory - * // or similar (system message may vary). - * const char* filename = "madeup"; - * FILE* file = fopen(filename, "r"); - * if (!file) - * throw fmt::system_error(errno, "cannot open file '{}'", filename); - */ -template -auto system_error(int error_code, format_string fmt, T&&... args) - -> std::system_error { - return vsystem_error(error_code, fmt.str, vargs{{args...}}); -} - -/** - * Formats an error message for an error returned by an operating system or a - * language runtime, for example a file opening error, and writes it to `out`. - * The format is the same as the one used by `std::system_error(ec, message)` - * where `ec` is `std::error_code(error_code, std::generic_category())`. - * It is implementation-defined but normally looks like: - * - * : - * - * where `` is the passed message and `` is the system - * message corresponding to the error code. - * `error_code` is a system error code as given by `errno`. - */ -FMT_API void format_system_error(detail::buffer& out, int error_code, - const char* message) noexcept; - -// Reports a system error without throwing an exception. -// Can be used to report errors from destructors. -FMT_API void report_system_error(int error_code, const char* message) noexcept; - -inline auto vformat(locale_ref loc, string_view fmt, format_args args) - -> std::string { - auto buf = memory_buffer(); - detail::vformat_to(buf, fmt, args, loc); - return {buf.data(), buf.size()}; -} - -template -FMT_INLINE auto format(locale_ref loc, format_string fmt, T&&... args) - -> std::string { - return vformat(loc, fmt.str, vargs{{args...}}); -} - -template ::value)> -auto vformat_to(OutputIt out, locale_ref loc, string_view fmt, format_args args) - -> OutputIt { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, fmt, args, loc); - return detail::get_iterator(buf, out); -} - -template ::value)> -FMT_INLINE auto format_to(OutputIt out, locale_ref loc, format_string fmt, - T&&... args) -> OutputIt { - return fmt::vformat_to(out, loc, fmt.str, vargs{{args...}}); -} - -template -FMT_NODISCARD FMT_INLINE auto formatted_size(locale_ref loc, - format_string fmt, - T&&... args) -> size_t { - auto buf = detail::counting_buffer<>(); - detail::vformat_to(buf, fmt.str, vargs{{args...}}, loc); - return buf.count(); -} - -FMT_API auto vformat(string_view fmt, format_args args) -> std::string; - -/** - * Formats `args` according to specifications in `fmt` and returns the result - * as a string. - * - * **Example**: - * - * #include - * std::string message = fmt::format("The answer is {}.", 42); - */ -template -FMT_NODISCARD FMT_INLINE auto format(format_string fmt, T&&... args) - -> std::string { - return vformat(fmt.str, vargs{{args...}}); -} - -/** - * Converts `value` to `std::string` using the default format for type `T`. - * - * **Example**: - * - * std::string answer = fmt::to_string(42); - */ -template ::value)> -FMT_NODISCARD FMT_CONSTEXPR_STRING auto to_string(T value) -> std::string { - // The buffer should be large enough to store the number including the sign - // or "false" for bool. - char buffer[max_of(detail::digits10() + 2, 5)]; - return {buffer, detail::write(buffer, value)}; -} - -template ::value)> -FMT_NODISCARD FMT_CONSTEXPR_STRING auto to_string(const T& value) - -> std::string { - return to_string(format_as(value)); -} - -template ::value && - !detail::use_format_as::value)> -FMT_NODISCARD FMT_CONSTEXPR_STRING auto to_string(const T& value) - -> std::string { - auto buffer = memory_buffer(); - detail::write(appender(buffer), value); - return {buffer.data(), buffer.size()}; -} - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#ifdef FMT_HEADER_ONLY -# define FMT_FUNC inline -# include "format-inl.h" -#endif - -// Restore _LIBCPP_REMOVE_TRANSITIVE_INCLUDES. -#ifdef FMT_REMOVE_TRANSITIVE_INCLUDES -# undef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES -#endif - -#endif // FMT_FORMAT_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/os.h b/examples/blueprints-example/external/spdlog/fmt/bundled/os.h deleted file mode 100644 index 40cdcdd..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/os.h +++ /dev/null @@ -1,428 +0,0 @@ -// Formatting library for C++ - optional OS-specific functionality -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_OS_H_ -#define FMT_OS_H_ - -#include "format.h" - -#ifndef FMT_MODULE -# include -# include -# include -# include // std::system_error - -# if FMT_HAS_INCLUDE() -# include // LC_NUMERIC_MASK on macOS -# endif -#endif // FMT_MODULE - -#ifndef FMT_USE_FCNTL -// UWP doesn't provide _pipe. -# if FMT_HAS_INCLUDE("winapifamily.h") -# include -# endif -# if (FMT_HAS_INCLUDE() || defined(__APPLE__) || \ - defined(__linux__)) && \ - (!defined(WINAPI_FAMILY) || \ - (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)) && \ - !defined(__wasm__) -# include // for O_RDONLY -# define FMT_USE_FCNTL 1 -# else -# define FMT_USE_FCNTL 0 -# endif -#endif - -#ifndef FMT_POSIX -# if defined(_WIN32) && !defined(__MINGW32__) -// Fix warnings about deprecated symbols. -# define FMT_POSIX(call) _##call -# else -# define FMT_POSIX(call) call -# endif -#endif - -// Calls to system functions are wrapped in FMT_SYSTEM for testability. -#ifdef FMT_SYSTEM -# define FMT_HAS_SYSTEM -# define FMT_POSIX_CALL(call) FMT_SYSTEM(call) -#else -# define FMT_SYSTEM(call) ::call -# ifdef _WIN32 -// Fix warnings about deprecated symbols. -# define FMT_POSIX_CALL(call) ::_##call -# else -# define FMT_POSIX_CALL(call) ::call -# endif -#endif - -// Retries the expression while it evaluates to error_result and errno -// equals to EINTR. -#ifndef _WIN32 -# define FMT_RETRY_VAL(result, expression, error_result) \ - do { \ - (result) = (expression); \ - } while ((result) == (error_result) && errno == EINTR) -#else -# define FMT_RETRY_VAL(result, expression, error_result) result = (expression) -#endif - -#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1) - -FMT_BEGIN_NAMESPACE -FMT_BEGIN_EXPORT - -/** - * A reference to a null-terminated string. It can be constructed from a C - * string or `std::string`. - * - * You can use one of the following type aliases for common character types: - * - * +---------------+-----------------------------+ - * | Type | Definition | - * +===============+=============================+ - * | cstring_view | basic_cstring_view | - * +---------------+-----------------------------+ - * | wcstring_view | basic_cstring_view | - * +---------------+-----------------------------+ - * - * This class is most useful as a parameter type for functions that wrap C APIs. - */ -template class basic_cstring_view { - private: - const Char* data_; - - public: - /// Constructs a string reference object from a C string. - basic_cstring_view(const Char* s) : data_(s) {} - - /// Constructs a string reference from an `std::string` object. - basic_cstring_view(const std::basic_string& s) : data_(s.c_str()) {} - - /// Returns the pointer to a C string. - auto c_str() const -> const Char* { return data_; } -}; - -using cstring_view = basic_cstring_view; -using wcstring_view = basic_cstring_view; - -#ifdef _WIN32 -FMT_API const std::error_category& system_category() noexcept; - -namespace detail { -FMT_API void format_windows_error(buffer& out, int error_code, - const char* message) noexcept; -} - -FMT_API std::system_error vwindows_error(int error_code, string_view fmt, - format_args args); - -/** - * Constructs a `std::system_error` object with the description of the form - * - * : - * - * where `` is the formatted message and `` is the - * system message corresponding to the error code. - * `error_code` is a Windows error code as given by `GetLastError`. - * If `error_code` is not a valid error code such as -1, the system message - * will look like "error -1". - * - * **Example**: - * - * // This throws a system_error with the description - * // cannot open file 'madeup': The system cannot find the file - * specified. - * // or similar (system message may vary). - * const char *filename = "madeup"; - * LPOFSTRUCT of = LPOFSTRUCT(); - * HFILE file = OpenFile(filename, &of, OF_READ); - * if (file == HFILE_ERROR) { - * throw fmt::windows_error(GetLastError(), - * "cannot open file '{}'", filename); - * } - */ -template -auto windows_error(int error_code, string_view message, const T&... args) - -> std::system_error { - return vwindows_error(error_code, message, vargs{{args...}}); -} - -// Reports a Windows error without throwing an exception. -// Can be used to report errors from destructors. -FMT_API void report_windows_error(int error_code, const char* message) noexcept; -#else -inline auto system_category() noexcept -> const std::error_category& { - return std::system_category(); -} -#endif // _WIN32 - -// std::system is not available on some platforms such as iOS (#2248). -#ifdef __OSX__ -template > -void say(const S& fmt, Args&&... args) { - std::system(format("say \"{}\"", format(fmt, args...)).c_str()); -} -#endif - -// A buffered file. -class buffered_file { - private: - FILE* file_; - - friend class file; - - inline explicit buffered_file(FILE* f) : file_(f) {} - - public: - buffered_file(const buffered_file&) = delete; - void operator=(const buffered_file&) = delete; - - // Constructs a buffered_file object which doesn't represent any file. - inline buffered_file() noexcept : file_(nullptr) {} - - // Destroys the object closing the file it represents if any. - FMT_API ~buffered_file() noexcept; - - public: - inline buffered_file(buffered_file&& other) noexcept : file_(other.file_) { - other.file_ = nullptr; - } - - inline auto operator=(buffered_file&& other) -> buffered_file& { - close(); - file_ = other.file_; - other.file_ = nullptr; - return *this; - } - - // Opens a file. - FMT_API buffered_file(cstring_view filename, cstring_view mode); - - // Closes the file. - FMT_API void close(); - - // Returns the pointer to a FILE object representing this file. - inline auto get() const noexcept -> FILE* { return file_; } - - FMT_API auto descriptor() const -> int; - - template - inline void print(string_view fmt, const T&... args) { - fmt::vargs vargs = {{args...}}; - detail::is_locking() ? fmt::vprint_buffered(file_, fmt, vargs) - : fmt::vprint(file_, fmt, vargs); - } -}; - -#if FMT_USE_FCNTL - -// A file. Closed file is represented by a file object with descriptor -1. -// Methods that are not declared with noexcept may throw -// fmt::system_error in case of failure. Note that some errors such as -// closing the file multiple times will cause a crash on Windows rather -// than an exception. You can get standard behavior by overriding the -// invalid parameter handler with _set_invalid_parameter_handler. -class FMT_API file { - private: - int fd_; // File descriptor. - - // Constructs a file object with a given descriptor. - explicit file(int fd) : fd_(fd) {} - - friend struct pipe; - - public: - // Possible values for the oflag argument to the constructor. - enum { - RDONLY = FMT_POSIX(O_RDONLY), // Open for reading only. - WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only. - RDWR = FMT_POSIX(O_RDWR), // Open for reading and writing. - CREATE = FMT_POSIX(O_CREAT), // Create if the file doesn't exist. - APPEND = FMT_POSIX(O_APPEND), // Open in append mode. - TRUNC = FMT_POSIX(O_TRUNC) // Truncate the content of the file. - }; - - // Constructs a file object which doesn't represent any file. - inline file() noexcept : fd_(-1) {} - - // Opens a file and constructs a file object representing this file. - file(cstring_view path, int oflag); - - public: - file(const file&) = delete; - void operator=(const file&) = delete; - - inline file(file&& other) noexcept : fd_(other.fd_) { other.fd_ = -1; } - - // Move assignment is not noexcept because close may throw. - inline auto operator=(file&& other) -> file& { - close(); - fd_ = other.fd_; - other.fd_ = -1; - return *this; - } - - // Destroys the object closing the file it represents if any. - ~file() noexcept; - - // Returns the file descriptor. - inline auto descriptor() const noexcept -> int { return fd_; } - - // Closes the file. - void close(); - - // Returns the file size. The size has signed type for consistency with - // stat::st_size. - auto size() const -> long long; - - // Attempts to read count bytes from the file into the specified buffer. - auto read(void* buffer, size_t count) -> size_t; - - // Attempts to write count bytes from the specified buffer to the file. - auto write(const void* buffer, size_t count) -> size_t; - - // Duplicates a file descriptor with the dup function and returns - // the duplicate as a file object. - static auto dup(int fd) -> file; - - // Makes fd be the copy of this file descriptor, closing fd first if - // necessary. - void dup2(int fd); - - // Makes fd be the copy of this file descriptor, closing fd first if - // necessary. - void dup2(int fd, std::error_code& ec) noexcept; - - // Creates a buffered_file object associated with this file and detaches - // this file object from the file. - auto fdopen(const char* mode) -> buffered_file; - -# if defined(_WIN32) && !defined(__MINGW32__) - // Opens a file and constructs a file object representing this file by - // wcstring_view filename. Windows only. - static file open_windows_file(wcstring_view path, int oflag); -# endif -}; - -struct FMT_API pipe { - file read_end; - file write_end; - - // Creates a pipe setting up read_end and write_end file objects for reading - // and writing respectively. - pipe(); -}; - -// Returns the memory page size. -auto getpagesize() -> long; - -namespace detail { - -struct buffer_size { - constexpr buffer_size() = default; - size_t value = 0; - FMT_CONSTEXPR auto operator=(size_t val) const -> buffer_size { - auto bs = buffer_size(); - bs.value = val; - return bs; - } -}; - -struct ostream_params { - int oflag = file::WRONLY | file::CREATE | file::TRUNC; - size_t buffer_size = BUFSIZ > 32768 ? BUFSIZ : 32768; - - constexpr ostream_params() {} - - template - ostream_params(T... params, int new_oflag) : ostream_params(params...) { - oflag = new_oflag; - } - - template - ostream_params(T... params, detail::buffer_size bs) - : ostream_params(params...) { - this->buffer_size = bs.value; - } - -// Intel has a bug that results in failure to deduce a constructor -// for empty parameter packs. -# if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 2000 - ostream_params(int new_oflag) : oflag(new_oflag) {} - ostream_params(detail::buffer_size bs) : buffer_size(bs.value) {} -# endif -}; - -} // namespace detail - -FMT_INLINE_VARIABLE constexpr auto buffer_size = detail::buffer_size(); - -/// A fast buffered output stream for writing from a single thread. Writing from -/// multiple threads without external synchronization may result in a data race. -class FMT_API ostream : private detail::buffer { - private: - file file_; - - ostream(cstring_view path, const detail::ostream_params& params); - - static void grow(buffer& buf, size_t); - - public: - ostream(ostream&& other) noexcept; - ~ostream(); - - operator writer() { - detail::buffer& buf = *this; - return buf; - } - - inline void flush() { - if (size() == 0) return; - file_.write(data(), size() * sizeof(data()[0])); - clear(); - } - - template - friend auto output_file(cstring_view path, T... params) -> ostream; - - inline void close() { - flush(); - file_.close(); - } - - /// Formats `args` according to specifications in `fmt` and writes the - /// output to the file. - template void print(format_string fmt, T&&... args) { - vformat_to(appender(*this), fmt.str, vargs{{args...}}); - } -}; - -/** - * Opens a file for writing. Supported parameters passed in `params`: - * - * - ``: Flags passed to [open]( - * https://pubs.opengroup.org/onlinepubs/007904875/functions/open.html) - * (`file::WRONLY | file::CREATE | file::TRUNC` by default) - * - `buffer_size=`: Output buffer size - * - * **Example**: - * - * auto out = fmt::output_file("guide.txt"); - * out.print("Don't {}", "Panic"); - */ -template -inline auto output_file(cstring_view path, T... params) -> ostream { - return {path, detail::ostream_params(params...)}; -} -#endif // FMT_USE_FCNTL - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_OS_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/ostream.h b/examples/blueprints-example/external/spdlog/fmt/bundled/ostream.h deleted file mode 100644 index bf2371b..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/ostream.h +++ /dev/null @@ -1,167 +0,0 @@ -// Formatting library for C++ - std::ostream support -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_OSTREAM_H_ -#define FMT_OSTREAM_H_ - -#ifndef FMT_MODULE -# include // std::filebuf -#endif - -#ifdef _WIN32 -# ifdef __GLIBCXX__ -# include -# include -# endif -# include -#endif - -#include "chrono.h" // formatbuf - -#ifdef _MSVC_STL_UPDATE -# define FMT_MSVC_STL_UPDATE _MSVC_STL_UPDATE -#elif defined(_MSC_VER) && _MSC_VER < 1912 // VS 15.5 -# define FMT_MSVC_STL_UPDATE _MSVC_LANG -#else -# define FMT_MSVC_STL_UPDATE 0 -#endif - -FMT_BEGIN_NAMESPACE -namespace detail { - -// Generate a unique explicit instantiation in every translation unit using a -// tag type in an anonymous namespace. -namespace { -struct file_access_tag {}; -} // namespace -template -class file_access { - friend auto get_file(BufType& obj) -> FILE* { return obj.*FileMemberPtr; } -}; - -#if FMT_MSVC_STL_UPDATE -template class file_access; -auto get_file(std::filebuf&) -> FILE*; -#endif - -// Write the content of buf to os. -// It is a separate function rather than a part of vprint to simplify testing. -template -void write_buffer(std::basic_ostream& os, buffer& buf) { - const Char* buf_data = buf.data(); - using unsigned_streamsize = make_unsigned_t; - unsigned_streamsize size = buf.size(); - unsigned_streamsize max_size = to_unsigned(max_value()); - do { - unsigned_streamsize n = size <= max_size ? size : max_size; - os.write(buf_data, static_cast(n)); - buf_data += n; - size -= n; - } while (size != 0); -} - -template struct streamed_view { - const T& value; -}; -} // namespace detail - -// Formats an object of type T that has an overloaded ostream operator<<. -template -struct basic_ostream_formatter : formatter, Char> { - void set_debug_format() = delete; - - template - auto format(const T& value, Context& ctx) const -> decltype(ctx.out()) { - auto buffer = basic_memory_buffer(); - auto&& formatbuf = detail::formatbuf>(buffer); - auto&& output = std::basic_ostream(&formatbuf); - output.imbue(std::locale::classic()); // The default is always unlocalized. - output << value; - output.exceptions(std::ios_base::failbit | std::ios_base::badbit); - return formatter, Char>::format( - {buffer.data(), buffer.size()}, ctx); - } -}; - -using ostream_formatter = basic_ostream_formatter; - -template -struct formatter, Char> - : basic_ostream_formatter { - template - auto format(detail::streamed_view view, Context& ctx) const - -> decltype(ctx.out()) { - return basic_ostream_formatter::format(view.value, ctx); - } -}; - -/** - * Returns a view that formats `value` via an ostream `operator<<`. - * - * **Example**: - * - * fmt::print("Current thread id: {}\n", - * fmt::streamed(std::this_thread::get_id())); - */ -template -constexpr auto streamed(const T& value) -> detail::streamed_view { - return {value}; -} - -inline void vprint(std::ostream& os, string_view fmt, format_args args) { - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt, args); - FILE* f = nullptr; -#if FMT_MSVC_STL_UPDATE && FMT_USE_RTTI - if (auto* buf = dynamic_cast(os.rdbuf())) - f = detail::get_file(*buf); -#elif defined(_WIN32) && defined(__GLIBCXX__) && FMT_USE_RTTI - auto* rdbuf = os.rdbuf(); - if (auto* sfbuf = dynamic_cast<__gnu_cxx::stdio_sync_filebuf*>(rdbuf)) - f = sfbuf->file(); - else if (auto* fbuf = dynamic_cast<__gnu_cxx::stdio_filebuf*>(rdbuf)) - f = fbuf->file(); -#endif -#ifdef _WIN32 - if (f) { - int fd = _fileno(f); - if (_isatty(fd)) { - os.flush(); - if (detail::write_console(fd, {buffer.data(), buffer.size()})) return; - } - } -#endif - detail::ignore_unused(f); - detail::write_buffer(os, buffer); -} - -/** - * Prints formatted data to the stream `os`. - * - * **Example**: - * - * fmt::print(cerr, "Don't {}!", "panic"); - */ -FMT_EXPORT template -void print(std::ostream& os, format_string fmt, T&&... args) { - fmt::vargs vargs = {{args...}}; - if (detail::const_check(detail::use_utf8)) return vprint(os, fmt.str, vargs); - auto buffer = memory_buffer(); - detail::vformat_to(buffer, fmt.str, vargs); - detail::write_buffer(os, buffer); -} - -FMT_EXPORT template -void println(std::ostream& os, format_string fmt, T&&... args) { - fmt::print(os, FMT_STRING("{}\n"), - fmt::format(fmt, std::forward(args)...)); -} - -FMT_END_NAMESPACE - -#endif // FMT_OSTREAM_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/printf.h b/examples/blueprints-example/external/spdlog/fmt/bundled/printf.h deleted file mode 100644 index cc066d8..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/printf.h +++ /dev/null @@ -1,624 +0,0 @@ -// Formatting library for C++ - legacy printf implementation -// -// Copyright (c) 2012 - 2016, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_PRINTF_H_ -#define FMT_PRINTF_H_ - -#ifndef FMT_MODULE -# include // std::find -# include // std::numeric_limits -#endif - -#include "format.h" - -FMT_BEGIN_NAMESPACE -FMT_BEGIN_EXPORT - -template class basic_printf_context { - private: - basic_appender out_; - basic_format_args args_; - - static_assert(std::is_same::value || - std::is_same::value, - "Unsupported code unit type."); - - public: - using char_type = Char; - enum { builtin_types = 1 }; - - /// Constructs a `printf_context` object. References to the arguments are - /// stored in the context object so make sure they have appropriate lifetimes. - basic_printf_context(basic_appender out, - basic_format_args args) - : out_(out), args_(args) {} - - auto out() -> basic_appender { return out_; } - void advance_to(basic_appender) {} - - auto locale() -> locale_ref { return {}; } - - auto arg(int id) const -> basic_format_arg { - return args_.get(id); - } -}; - -namespace detail { - -// Return the result via the out param to workaround gcc bug 77539. -template -FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr& out) -> bool { - for (out = first; out != last; ++out) { - if (*out == value) return true; - } - return false; -} - -template <> -inline auto find(const char* first, const char* last, char value, - const char*& out) -> bool { - out = - static_cast(memchr(first, value, to_unsigned(last - first))); - return out != nullptr; -} - -// Checks if a value fits in int - used to avoid warnings about comparing -// signed and unsigned integers. -template struct int_checker { - template static auto fits_in_int(T value) -> bool { - return value <= to_unsigned(max_value()); - } - inline static auto fits_in_int(bool) -> bool { return true; } -}; - -template <> struct int_checker { - template static auto fits_in_int(T value) -> bool { - return value >= (std::numeric_limits::min)() && - value <= max_value(); - } - inline static auto fits_in_int(int) -> bool { return true; } -}; - -struct printf_precision_handler { - template ::value)> - auto operator()(T value) -> int { - if (!int_checker::is_signed>::fits_in_int(value)) - report_error("number is too big"); - return max_of(static_cast(value), 0); - } - - template ::value)> - auto operator()(T) -> int { - report_error("precision is not integer"); - return 0; - } -}; - -// An argument visitor that returns true iff arg is a zero integer. -struct is_zero_int { - template ::value)> - auto operator()(T value) -> bool { - return value == 0; - } - - template ::value)> - auto operator()(T) -> bool { - return false; - } -}; - -template struct make_unsigned_or_bool : std::make_unsigned {}; - -template <> struct make_unsigned_or_bool { - using type = bool; -}; - -template class arg_converter { - private: - using char_type = typename Context::char_type; - - basic_format_arg& arg_; - char_type type_; - - public: - arg_converter(basic_format_arg& arg, char_type type) - : arg_(arg), type_(type) {} - - void operator()(bool value) { - if (type_ != 's') operator()(value); - } - - template ::value)> - void operator()(U value) { - bool is_signed = type_ == 'd' || type_ == 'i'; - using target_type = conditional_t::value, U, T>; - if (const_check(sizeof(target_type) <= sizeof(int))) { - // Extra casts are used to silence warnings. - using unsigned_type = typename make_unsigned_or_bool::type; - if (is_signed) - arg_ = static_cast(static_cast(value)); - else - arg_ = static_cast(static_cast(value)); - } else { - // glibc's printf doesn't sign extend arguments of smaller types: - // std::printf("%lld", -42); // prints "4294967254" - // but we don't have to do the same because it's a UB. - if (is_signed) - arg_ = static_cast(value); - else - arg_ = static_cast::type>(value); - } - } - - template ::value)> - void operator()(U) {} // No conversion needed for non-integral types. -}; - -// Converts an integer argument to T for printf, if T is an integral type. -// If T is void, the argument is converted to corresponding signed or unsigned -// type depending on the type specifier: 'd' and 'i' - signed, other - -// unsigned). -template -void convert_arg(basic_format_arg& arg, Char type) { - arg.visit(arg_converter(arg, type)); -} - -// Converts an integer argument to char for printf. -template class char_converter { - private: - basic_format_arg& arg_; - - public: - explicit char_converter(basic_format_arg& arg) : arg_(arg) {} - - template ::value)> - void operator()(T value) { - arg_ = static_cast(value); - } - - template ::value)> - void operator()(T) {} // No conversion needed for non-integral types. -}; - -// An argument visitor that return a pointer to a C string if argument is a -// string or null otherwise. -template struct get_cstring { - template auto operator()(T) -> const Char* { return nullptr; } - auto operator()(const Char* s) -> const Char* { return s; } -}; - -// Checks if an argument is a valid printf width specifier and sets -// left alignment if it is negative. -class printf_width_handler { - private: - format_specs& specs_; - - public: - inline explicit printf_width_handler(format_specs& specs) : specs_(specs) {} - - template ::value)> - auto operator()(T value) -> unsigned { - auto width = static_cast>(value); - if (detail::is_negative(value)) { - specs_.set_align(align::left); - width = 0 - width; - } - unsigned int_max = to_unsigned(max_value()); - if (width > int_max) report_error("number is too big"); - return static_cast(width); - } - - template ::value)> - auto operator()(T) -> unsigned { - report_error("width is not integer"); - return 0; - } -}; - -// Workaround for a bug with the XL compiler when initializing -// printf_arg_formatter's base class. -template -auto make_arg_formatter(basic_appender iter, format_specs& s) - -> arg_formatter { - return {iter, s, locale_ref()}; -} - -// The `printf` argument formatter. -template -class printf_arg_formatter : public arg_formatter { - private: - using base = arg_formatter; - using context_type = basic_printf_context; - - context_type& context_; - - void write_null_pointer(bool is_string = false) { - auto s = this->specs; - s.set_type(presentation_type::none); - write_bytes(this->out, is_string ? "(null)" : "(nil)", s); - } - - template void write(T value) { - detail::write(this->out, value, this->specs, this->locale); - } - - public: - printf_arg_formatter(basic_appender iter, format_specs& s, - context_type& ctx) - : base(make_arg_formatter(iter, s)), context_(ctx) {} - - void operator()(monostate value) { write(value); } - - template ::value)> - void operator()(T value) { - // MSVC2013 fails to compile separate overloads for bool and Char so use - // std::is_same instead. - if (!std::is_same::value) { - write(value); - return; - } - format_specs s = this->specs; - if (s.type() != presentation_type::none && - s.type() != presentation_type::chr) { - return (*this)(static_cast(value)); - } - s.set_sign(sign::none); - s.clear_alt(); - s.set_fill(' '); // Ignore '0' flag for char types. - // align::numeric needs to be overwritten here since the '0' flag is - // ignored for non-numeric types - if (s.align() == align::none || s.align() == align::numeric) - s.set_align(align::right); - detail::write(this->out, static_cast(value), s); - } - - template ::value)> - void operator()(T value) { - write(value); - } - - void operator()(const char* value) { - if (value) - write(value); - else - write_null_pointer(this->specs.type() != presentation_type::pointer); - } - - void operator()(const wchar_t* value) { - if (value) - write(value); - else - write_null_pointer(this->specs.type() != presentation_type::pointer); - } - - void operator()(basic_string_view value) { write(value); } - - void operator()(const void* value) { - if (value) - write(value); - else - write_null_pointer(); - } - - void operator()(typename basic_format_arg::handle handle) { - auto parse_ctx = parse_context({}); - handle.format(parse_ctx, context_); - } -}; - -template -void parse_flags(format_specs& specs, const Char*& it, const Char* end) { - for (; it != end; ++it) { - switch (*it) { - case '-': specs.set_align(align::left); break; - case '+': specs.set_sign(sign::plus); break; - case '0': specs.set_fill('0'); break; - case ' ': - if (specs.sign() != sign::plus) specs.set_sign(sign::space); - break; - case '#': specs.set_alt(); break; - default: return; - } - } -} - -template -auto parse_header(const Char*& it, const Char* end, format_specs& specs, - GetArg get_arg) -> int { - int arg_index = -1; - Char c = *it; - if (c >= '0' && c <= '9') { - // Parse an argument index (if followed by '$') or a width possibly - // preceded with '0' flag(s). - int value = parse_nonnegative_int(it, end, -1); - if (it != end && *it == '$') { // value is an argument index - ++it; - arg_index = value != -1 ? value : max_value(); - } else { - if (c == '0') specs.set_fill('0'); - if (value != 0) { - // Nonzero value means that we parsed width and don't need to - // parse it or flags again, so return now. - if (value == -1) report_error("number is too big"); - specs.width = value; - return arg_index; - } - } - } - parse_flags(specs, it, end); - // Parse width. - if (it != end) { - if (*it >= '0' && *it <= '9') { - specs.width = parse_nonnegative_int(it, end, -1); - if (specs.width == -1) report_error("number is too big"); - } else if (*it == '*') { - ++it; - specs.width = static_cast( - get_arg(-1).visit(detail::printf_width_handler(specs))); - } - } - return arg_index; -} - -inline auto parse_printf_presentation_type(char c, type t, bool& upper) - -> presentation_type { - using pt = presentation_type; - constexpr auto integral_set = sint_set | uint_set | bool_set | char_set; - switch (c) { - case 'd': return in(t, integral_set) ? pt::dec : pt::none; - case 'o': return in(t, integral_set) ? pt::oct : pt::none; - case 'X': upper = true; FMT_FALLTHROUGH; - case 'x': return in(t, integral_set) ? pt::hex : pt::none; - case 'E': upper = true; FMT_FALLTHROUGH; - case 'e': return in(t, float_set) ? pt::exp : pt::none; - case 'F': upper = true; FMT_FALLTHROUGH; - case 'f': return in(t, float_set) ? pt::fixed : pt::none; - case 'G': upper = true; FMT_FALLTHROUGH; - case 'g': return in(t, float_set) ? pt::general : pt::none; - case 'A': upper = true; FMT_FALLTHROUGH; - case 'a': return in(t, float_set) ? pt::hexfloat : pt::none; - case 'c': return in(t, integral_set) ? pt::chr : pt::none; - case 's': return in(t, string_set | cstring_set) ? pt::string : pt::none; - case 'p': return in(t, pointer_set | cstring_set) ? pt::pointer : pt::none; - default: return pt::none; - } -} - -template -void vprintf(buffer& buf, basic_string_view format, - basic_format_args args) { - using iterator = basic_appender; - auto out = iterator(buf); - auto context = basic_printf_context(out, args); - auto parse_ctx = parse_context(format); - - // Returns the argument with specified index or, if arg_index is -1, the next - // argument. - auto get_arg = [&](int arg_index) { - if (arg_index < 0) - arg_index = parse_ctx.next_arg_id(); - else - parse_ctx.check_arg_id(--arg_index); - auto arg = context.arg(arg_index); - if (!arg) report_error("argument not found"); - return arg; - }; - - const Char* start = parse_ctx.begin(); - const Char* end = parse_ctx.end(); - auto it = start; - while (it != end) { - if (!find(it, end, '%', it)) { - it = end; // find leaves it == nullptr if it doesn't find '%'. - break; - } - Char c = *it++; - if (it != end && *it == c) { - write(out, basic_string_view(start, to_unsigned(it - start))); - start = ++it; - continue; - } - write(out, basic_string_view(start, to_unsigned(it - 1 - start))); - - auto specs = format_specs(); - specs.set_align(align::right); - - // Parse argument index, flags and width. - int arg_index = parse_header(it, end, specs, get_arg); - if (arg_index == 0) report_error("argument not found"); - - // Parse precision. - if (it != end && *it == '.') { - ++it; - c = it != end ? *it : 0; - if ('0' <= c && c <= '9') { - specs.precision = parse_nonnegative_int(it, end, 0); - } else if (c == '*') { - ++it; - specs.precision = - static_cast(get_arg(-1).visit(printf_precision_handler())); - } else { - specs.precision = 0; - } - } - - auto arg = get_arg(arg_index); - // For d, i, o, u, x, and X conversion specifiers, if a precision is - // specified, the '0' flag is ignored - if (specs.precision >= 0 && is_integral_type(arg.type())) { - // Ignore '0' for non-numeric types or if '-' present. - specs.set_fill(' '); - } - if (specs.precision >= 0 && arg.type() == type::cstring_type) { - auto str = arg.visit(get_cstring()); - auto str_end = str + specs.precision; - auto nul = std::find(str, str_end, Char()); - auto sv = basic_string_view( - str, to_unsigned(nul != str_end ? nul - str : specs.precision)); - arg = sv; - } - if (specs.alt() && arg.visit(is_zero_int())) specs.clear_alt(); - if (specs.fill_unit() == '0') { - if (is_arithmetic_type(arg.type()) && specs.align() != align::left) { - specs.set_align(align::numeric); - } else { - // Ignore '0' flag for non-numeric types or if '-' flag is also present. - specs.set_fill(' '); - } - } - - // Parse length and convert the argument to the required type. - c = it != end ? *it++ : 0; - Char t = it != end ? *it : 0; - switch (c) { - case 'h': - if (t == 'h') { - ++it; - t = it != end ? *it : 0; - convert_arg(arg, t); - } else { - convert_arg(arg, t); - } - break; - case 'l': - if (t == 'l') { - ++it; - t = it != end ? *it : 0; - convert_arg(arg, t); - } else { - convert_arg(arg, t); - } - break; - case 'j': convert_arg(arg, t); break; - case 'z': convert_arg(arg, t); break; - case 't': convert_arg(arg, t); break; - case 'L': - // printf produces garbage when 'L' is omitted for long double, no - // need to do the same. - break; - default: --it; convert_arg(arg, c); - } - - // Parse type. - if (it == end) report_error("invalid format string"); - char type = static_cast(*it++); - if (is_integral_type(arg.type())) { - // Normalize type. - switch (type) { - case 'i': - case 'u': type = 'd'; break; - case 'c': - arg.visit(char_converter>(arg)); - break; - } - } - bool upper = false; - specs.set_type(parse_printf_presentation_type(type, arg.type(), upper)); - if (specs.type() == presentation_type::none) - report_error("invalid format specifier"); - if (upper) specs.set_upper(); - - start = it; - - // Format argument. - arg.visit(printf_arg_formatter(out, specs, context)); - } - write(out, basic_string_view(start, to_unsigned(it - start))); -} -} // namespace detail - -using printf_context = basic_printf_context; -using wprintf_context = basic_printf_context; - -using printf_args = basic_format_args; -using wprintf_args = basic_format_args; - -/// Constructs an `format_arg_store` object that contains references to -/// arguments and can be implicitly converted to `printf_args`. -template -inline auto make_printf_args(T&... args) - -> decltype(fmt::make_format_args>(args...)) { - return fmt::make_format_args>(args...); -} - -template struct vprintf_args { - using type = basic_format_args>; -}; - -template -inline auto vsprintf(basic_string_view fmt, - typename vprintf_args::type args) - -> std::basic_string { - auto buf = basic_memory_buffer(); - detail::vprintf(buf, fmt, args); - return {buf.data(), buf.size()}; -} - -/** - * Formats `args` according to specifications in `fmt` and returns the result - * as as string. - * - * **Example**: - * - * std::string message = fmt::sprintf("The answer is %d", 42); - */ -template -inline auto sprintf(string_view fmt, const T&... args) -> std::string { - return vsprintf(fmt, make_printf_args(args...)); -} -template -FMT_DEPRECATED auto sprintf(basic_string_view fmt, const T&... args) - -> std::wstring { - return vsprintf(fmt, make_printf_args(args...)); -} - -template -auto vfprintf(std::FILE* f, basic_string_view fmt, - typename vprintf_args::type args) -> int { - auto buf = basic_memory_buffer(); - detail::vprintf(buf, fmt, args); - size_t size = buf.size(); - return std::fwrite(buf.data(), sizeof(Char), size, f) < size - ? -1 - : static_cast(size); -} - -/** - * Formats `args` according to specifications in `fmt` and writes the output - * to `f`. - * - * **Example**: - * - * fmt::fprintf(stderr, "Don't %s!", "panic"); - */ -template -inline auto fprintf(std::FILE* f, string_view fmt, const T&... args) -> int { - return vfprintf(f, fmt, make_printf_args(args...)); -} -template -FMT_DEPRECATED auto fprintf(std::FILE* f, basic_string_view fmt, - const T&... args) -> int { - return vfprintf(f, fmt, make_printf_args(args...)); -} - -/** - * Formats `args` according to specifications in `fmt` and writes the output - * to `stdout`. - * - * **Example**: - * - * fmt::printf("Elapsed time: %.2f seconds", 1.23); - */ -template -inline auto printf(string_view fmt, const T&... args) -> int { - return vfprintf(stdout, fmt, make_printf_args(args...)); -} - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_PRINTF_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/ranges.h b/examples/blueprints-example/external/spdlog/fmt/bundled/ranges.h deleted file mode 100644 index 24c61e9..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/ranges.h +++ /dev/null @@ -1,852 +0,0 @@ -// Formatting library for C++ - range and tuple support -// -// Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_RANGES_H_ -#define FMT_RANGES_H_ - -#ifndef FMT_MODULE -# include -# include -# include -# include -# include -#endif - -#include "format.h" - -FMT_BEGIN_NAMESPACE - -FMT_EXPORT -enum class range_format { disabled, map, set, sequence, string, debug_string }; - -namespace detail { - -template class is_map { - template static auto check(U*) -> typename U::mapped_type; - template static void check(...); - - public: - static constexpr bool value = - !std::is_void(nullptr))>::value; -}; - -template class is_set { - template static auto check(U*) -> typename U::key_type; - template static void check(...); - - public: - static constexpr bool value = - !std::is_void(nullptr))>::value && !is_map::value; -}; - -// C array overload -template -auto range_begin(const T (&arr)[N]) -> const T* { - return arr; -} -template auto range_end(const T (&arr)[N]) -> const T* { - return arr + N; -} - -template -struct has_member_fn_begin_end_t : std::false_type {}; - -template -struct has_member_fn_begin_end_t().begin()), - decltype(std::declval().end())>> - : std::true_type {}; - -// Member function overloads. -template -auto range_begin(T&& rng) -> decltype(static_cast(rng).begin()) { - return static_cast(rng).begin(); -} -template -auto range_end(T&& rng) -> decltype(static_cast(rng).end()) { - return static_cast(rng).end(); -} - -// ADL overloads. Only participate in overload resolution if member functions -// are not found. -template -auto range_begin(T&& rng) - -> enable_if_t::value, - decltype(begin(static_cast(rng)))> { - return begin(static_cast(rng)); -} -template -auto range_end(T&& rng) -> enable_if_t::value, - decltype(end(static_cast(rng)))> { - return end(static_cast(rng)); -} - -template -struct has_const_begin_end : std::false_type {}; -template -struct has_mutable_begin_end : std::false_type {}; - -template -struct has_const_begin_end< - T, void_t&>())), - decltype(detail::range_end( - std::declval&>()))>> - : std::true_type {}; - -template -struct has_mutable_begin_end< - T, void_t())), - decltype(detail::range_end(std::declval())), - // the extra int here is because older versions of MSVC don't - // SFINAE properly unless there are distinct types - int>> : std::true_type {}; - -template struct is_range_ : std::false_type {}; -template -struct is_range_ - : std::integral_constant::value || - has_mutable_begin_end::value)> {}; - -// tuple_size and tuple_element check. -template class is_tuple_like_ { - template ::type> - static auto check(U* p) -> decltype(std::tuple_size::value, 0); - template static void check(...); - - public: - static constexpr bool value = - !std::is_void(nullptr))>::value; -}; - -// Check for integer_sequence -#if defined(__cpp_lib_integer_sequence) || FMT_MSC_VERSION >= 1900 -template -using integer_sequence = std::integer_sequence; -template using index_sequence = std::index_sequence; -template using make_index_sequence = std::make_index_sequence; -#else -template struct integer_sequence { - using value_type = T; - - static FMT_CONSTEXPR auto size() -> size_t { return sizeof...(N); } -}; - -template using index_sequence = integer_sequence; - -template -struct make_integer_sequence : make_integer_sequence {}; -template -struct make_integer_sequence : integer_sequence {}; - -template -using make_index_sequence = make_integer_sequence; -#endif - -template -using tuple_index_sequence = make_index_sequence::value>; - -template ::value> -class is_tuple_formattable_ { - public: - static constexpr bool value = false; -}; -template class is_tuple_formattable_ { - template - static auto all_true(index_sequence, - integer_sequence= 0)...>) -> std::true_type; - static auto all_true(...) -> std::false_type; - - template - static auto check(index_sequence) -> decltype(all_true( - index_sequence{}, - integer_sequence::type, - C>::value)...>{})); - - public: - static constexpr bool value = - decltype(check(tuple_index_sequence{}))::value; -}; - -template -FMT_CONSTEXPR void for_each(index_sequence, Tuple&& t, F&& f) { - using std::get; - // Using a free function get(Tuple) now. - const int unused[] = {0, ((void)f(get(t)), 0)...}; - ignore_unused(unused); -} - -template -FMT_CONSTEXPR void for_each(Tuple&& t, F&& f) { - for_each(tuple_index_sequence>(), - std::forward(t), std::forward(f)); -} - -template -void for_each2(index_sequence, Tuple1&& t1, Tuple2&& t2, F&& f) { - using std::get; - const int unused[] = {0, ((void)f(get(t1), get(t2)), 0)...}; - ignore_unused(unused); -} - -template -void for_each2(Tuple1&& t1, Tuple2&& t2, F&& f) { - for_each2(tuple_index_sequence>(), - std::forward(t1), std::forward(t2), - std::forward(f)); -} - -namespace tuple { -// Workaround a bug in MSVC 2019 (v140). -template -using result_t = std::tuple, Char>...>; - -using std::get; -template -auto get_formatters(index_sequence) - -> result_t(std::declval()))...>; -} // namespace tuple - -#if FMT_MSC_VERSION && FMT_MSC_VERSION < 1920 -// Older MSVC doesn't get the reference type correctly for arrays. -template struct range_reference_type_impl { - using type = decltype(*detail::range_begin(std::declval())); -}; - -template struct range_reference_type_impl { - using type = T&; -}; - -template -using range_reference_type = typename range_reference_type_impl::type; -#else -template -using range_reference_type = - decltype(*detail::range_begin(std::declval())); -#endif - -// We don't use the Range's value_type for anything, but we do need the Range's -// reference type, with cv-ref stripped. -template -using uncvref_type = remove_cvref_t>; - -template -FMT_CONSTEXPR auto maybe_set_debug_format(Formatter& f, bool set) - -> decltype(f.set_debug_format(set)) { - f.set_debug_format(set); -} -template -FMT_CONSTEXPR void maybe_set_debug_format(Formatter&, ...) {} - -template -struct range_format_kind_ - : std::integral_constant, T>::value - ? range_format::disabled - : is_map::value ? range_format::map - : is_set::value ? range_format::set - : range_format::sequence> {}; - -template -using range_format_constant = std::integral_constant; - -// These are not generic lambdas for compatibility with C++11. -template struct parse_empty_specs { - template FMT_CONSTEXPR void operator()(Formatter& f) { - f.parse(ctx); - detail::maybe_set_debug_format(f, true); - } - parse_context& ctx; -}; -template struct format_tuple_element { - using char_type = typename FormatContext::char_type; - - template - void operator()(const formatter& f, const T& v) { - if (i > 0) ctx.advance_to(detail::copy(separator, ctx.out())); - ctx.advance_to(f.format(v, ctx)); - ++i; - } - - int i; - FormatContext& ctx; - basic_string_view separator; -}; - -} // namespace detail - -FMT_EXPORT -template struct is_tuple_like { - static constexpr bool value = - detail::is_tuple_like_::value && !detail::is_range_::value; -}; - -FMT_EXPORT -template struct is_tuple_formattable { - static constexpr bool value = detail::is_tuple_formattable_::value; -}; - -template -struct formatter::value && - fmt::is_tuple_formattable::value>> { - private: - decltype(detail::tuple::get_formatters( - detail::tuple_index_sequence())) formatters_; - - basic_string_view separator_ = detail::string_literal{}; - basic_string_view opening_bracket_ = - detail::string_literal{}; - basic_string_view closing_bracket_ = - detail::string_literal{}; - - public: - FMT_CONSTEXPR formatter() {} - - FMT_CONSTEXPR void set_separator(basic_string_view sep) { - separator_ = sep; - } - - FMT_CONSTEXPR void set_brackets(basic_string_view open, - basic_string_view close) { - opening_bracket_ = open; - closing_bracket_ = close; - } - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(); - auto end = ctx.end(); - if (it != end && detail::to_ascii(*it) == 'n') { - ++it; - set_brackets({}, {}); - set_separator({}); - } - if (it != end && *it != '}') report_error("invalid format specifier"); - ctx.advance_to(it); - detail::for_each(formatters_, detail::parse_empty_specs{ctx}); - return it; - } - - template - auto format(const Tuple& value, FormatContext& ctx) const - -> decltype(ctx.out()) { - ctx.advance_to(detail::copy(opening_bracket_, ctx.out())); - detail::for_each2( - formatters_, value, - detail::format_tuple_element{0, ctx, separator_}); - return detail::copy(closing_bracket_, ctx.out()); - } -}; - -FMT_EXPORT -template struct is_range { - static constexpr bool value = - detail::is_range_::value && !detail::has_to_string_view::value; -}; - -namespace detail { - -template -using range_formatter_type = formatter, Char>; - -template -using maybe_const_range = - conditional_t::value, const R, R>; - -template -struct is_formattable_delayed - : is_formattable>, Char> {}; -} // namespace detail - -template struct conjunction : std::true_type {}; -template struct conjunction

: P {}; -template -struct conjunction - : conditional_t, P1> {}; - -FMT_EXPORT -template -struct range_formatter; - -template -struct range_formatter< - T, Char, - enable_if_t>, - is_formattable>::value>> { - private: - detail::range_formatter_type underlying_; - basic_string_view separator_ = detail::string_literal{}; - basic_string_view opening_bracket_ = - detail::string_literal{}; - basic_string_view closing_bracket_ = - detail::string_literal{}; - bool is_debug = false; - - template ::value)> - auto write_debug_string(Output& out, It it, Sentinel end) const -> Output { - auto buf = basic_memory_buffer(); - for (; it != end; ++it) buf.push_back(*it); - auto specs = format_specs(); - specs.set_type(presentation_type::debug); - return detail::write( - out, basic_string_view(buf.data(), buf.size()), specs); - } - - template ::value)> - auto write_debug_string(Output& out, It, Sentinel) const -> Output { - return out; - } - - public: - FMT_CONSTEXPR range_formatter() {} - - FMT_CONSTEXPR auto underlying() -> detail::range_formatter_type& { - return underlying_; - } - - FMT_CONSTEXPR void set_separator(basic_string_view sep) { - separator_ = sep; - } - - FMT_CONSTEXPR void set_brackets(basic_string_view open, - basic_string_view close) { - opening_bracket_ = open; - closing_bracket_ = close; - } - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(); - auto end = ctx.end(); - detail::maybe_set_debug_format(underlying_, true); - if (it == end) return underlying_.parse(ctx); - - switch (detail::to_ascii(*it)) { - case 'n': - set_brackets({}, {}); - ++it; - break; - case '?': - is_debug = true; - set_brackets({}, {}); - ++it; - if (it == end || *it != 's') report_error("invalid format specifier"); - FMT_FALLTHROUGH; - case 's': - if (!std::is_same::value) - report_error("invalid format specifier"); - if (!is_debug) { - set_brackets(detail::string_literal{}, - detail::string_literal{}); - set_separator({}); - detail::maybe_set_debug_format(underlying_, false); - } - ++it; - return it; - } - - if (it != end && *it != '}') { - if (*it != ':') report_error("invalid format specifier"); - detail::maybe_set_debug_format(underlying_, false); - ++it; - } - - ctx.advance_to(it); - return underlying_.parse(ctx); - } - - template - auto format(R&& range, FormatContext& ctx) const -> decltype(ctx.out()) { - auto out = ctx.out(); - auto it = detail::range_begin(range); - auto end = detail::range_end(range); - if (is_debug) return write_debug_string(out, std::move(it), end); - - out = detail::copy(opening_bracket_, out); - int i = 0; - for (; it != end; ++it) { - if (i > 0) out = detail::copy(separator_, out); - ctx.advance_to(out); - auto&& item = *it; // Need an lvalue - out = underlying_.format(item, ctx); - ++i; - } - out = detail::copy(closing_bracket_, out); - return out; - } -}; - -FMT_EXPORT -template -struct range_format_kind - : conditional_t< - is_range::value, detail::range_format_kind_, - std::integral_constant> {}; - -template -struct formatter< - R, Char, - enable_if_t::value != range_format::disabled && - range_format_kind::value != range_format::map && - range_format_kind::value != range_format::string && - range_format_kind::value != range_format::debug_string>, - detail::is_formattable_delayed>::value>> { - private: - using range_type = detail::maybe_const_range; - range_formatter, Char> range_formatter_; - - public: - using nonlocking = void; - - FMT_CONSTEXPR formatter() { - if (detail::const_check(range_format_kind::value != - range_format::set)) - return; - range_formatter_.set_brackets(detail::string_literal{}, - detail::string_literal{}); - } - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return range_formatter_.parse(ctx); - } - - template - auto format(range_type& range, FormatContext& ctx) const - -> decltype(ctx.out()) { - return range_formatter_.format(range, ctx); - } -}; - -// A map formatter. -template -struct formatter< - R, Char, - enable_if_t::value == range_format::map>, - detail::is_formattable_delayed>::value>> { - private: - using map_type = detail::maybe_const_range; - using element_type = detail::uncvref_type; - - decltype(detail::tuple::get_formatters( - detail::tuple_index_sequence())) formatters_; - bool no_delimiters_ = false; - - public: - FMT_CONSTEXPR formatter() {} - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - auto it = ctx.begin(); - auto end = ctx.end(); - if (it != end) { - if (detail::to_ascii(*it) == 'n') { - no_delimiters_ = true; - ++it; - } - if (it != end && *it != '}') { - if (*it != ':') report_error("invalid format specifier"); - ++it; - } - ctx.advance_to(it); - } - detail::for_each(formatters_, detail::parse_empty_specs{ctx}); - return it; - } - - template - auto format(map_type& map, FormatContext& ctx) const -> decltype(ctx.out()) { - auto out = ctx.out(); - basic_string_view open = detail::string_literal{}; - if (!no_delimiters_) out = detail::copy(open, out); - int i = 0; - basic_string_view sep = detail::string_literal{}; - for (auto&& value : map) { - if (i > 0) out = detail::copy(sep, out); - ctx.advance_to(out); - detail::for_each2(formatters_, value, - detail::format_tuple_element{ - 0, ctx, detail::string_literal{}}); - ++i; - } - basic_string_view close = detail::string_literal{}; - if (!no_delimiters_) out = detail::copy(close, out); - return out; - } -}; - -// A (debug_)string formatter. -template -struct formatter< - R, Char, - enable_if_t::value == range_format::string || - range_format_kind::value == - range_format::debug_string>> { - private: - using range_type = detail::maybe_const_range; - using string_type = - conditional_t, - decltype(detail::range_begin(std::declval())), - decltype(detail::range_end(std::declval()))>::value, - detail::std_string_view, std::basic_string>; - - formatter underlying_; - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return underlying_.parse(ctx); - } - - template - auto format(range_type& range, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); - if (detail::const_check(range_format_kind::value == - range_format::debug_string)) - *out++ = '"'; - out = underlying_.format( - string_type{detail::range_begin(range), detail::range_end(range)}, ctx); - if (detail::const_check(range_format_kind::value == - range_format::debug_string)) - *out++ = '"'; - return out; - } -}; - -template -struct join_view : detail::view { - It begin; - Sentinel end; - basic_string_view sep; - - join_view(It b, Sentinel e, basic_string_view s) - : begin(std::move(b)), end(e), sep(s) {} -}; - -template -struct formatter, Char> { - private: - using value_type = -#ifdef __cpp_lib_ranges - std::iter_value_t; -#else - typename std::iterator_traits::value_type; -#endif - formatter, Char> value_formatter_; - - using view = conditional_t::value, - const join_view, - join_view>; - - public: - using nonlocking = void; - - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return value_formatter_.parse(ctx); - } - - template - auto format(view& value, FormatContext& ctx) const -> decltype(ctx.out()) { - using iter = - conditional_t::value, It, It&>; - iter it = value.begin; - auto out = ctx.out(); - if (it == value.end) return out; - out = value_formatter_.format(*it, ctx); - ++it; - while (it != value.end) { - out = detail::copy(value.sep.begin(), value.sep.end(), out); - ctx.advance_to(out); - out = value_formatter_.format(*it, ctx); - ++it; - } - return out; - } -}; - -FMT_EXPORT -template struct tuple_join_view : detail::view { - const Tuple& tuple; - basic_string_view sep; - - tuple_join_view(const Tuple& t, basic_string_view s) - : tuple(t), sep{s} {} -}; - -// Define FMT_TUPLE_JOIN_SPECIFIERS to enable experimental format specifiers -// support in tuple_join. It is disabled by default because of issues with -// the dynamic width and precision. -#ifndef FMT_TUPLE_JOIN_SPECIFIERS -# define FMT_TUPLE_JOIN_SPECIFIERS 0 -#endif - -template -struct formatter, Char, - enable_if_t::value>> { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return do_parse(ctx, std::tuple_size()); - } - - template - auto format(const tuple_join_view& value, - FormatContext& ctx) const -> typename FormatContext::iterator { - return do_format(value, ctx, std::tuple_size()); - } - - private: - decltype(detail::tuple::get_formatters( - detail::tuple_index_sequence())) formatters_; - - FMT_CONSTEXPR auto do_parse(parse_context& ctx, - std::integral_constant) - -> const Char* { - return ctx.begin(); - } - - template - FMT_CONSTEXPR auto do_parse(parse_context& ctx, - std::integral_constant) - -> const Char* { - auto end = ctx.begin(); -#if FMT_TUPLE_JOIN_SPECIFIERS - end = std::get::value - N>(formatters_).parse(ctx); - if (N > 1) { - auto end1 = do_parse(ctx, std::integral_constant()); - if (end != end1) - report_error("incompatible format specs for tuple elements"); - } -#endif - return end; - } - - template - auto do_format(const tuple_join_view&, FormatContext& ctx, - std::integral_constant) const -> - typename FormatContext::iterator { - return ctx.out(); - } - - template - auto do_format(const tuple_join_view& value, FormatContext& ctx, - std::integral_constant) const -> - typename FormatContext::iterator { - using std::get; - auto out = - std::get::value - N>(formatters_) - .format(get::value - N>(value.tuple), ctx); - if (N <= 1) return out; - out = detail::copy(value.sep, out); - ctx.advance_to(out); - return do_format(value, ctx, std::integral_constant()); - } -}; - -namespace detail { -// Check if T has an interface like a container adaptor (e.g. std::stack, -// std::queue, std::priority_queue). -template class is_container_adaptor_like { - template static auto check(U* p) -> typename U::container_type; - template static void check(...); - - public: - static constexpr bool value = - !std::is_void(nullptr))>::value; -}; - -template struct all { - const Container& c; - auto begin() const -> typename Container::const_iterator { return c.begin(); } - auto end() const -> typename Container::const_iterator { return c.end(); } -}; -} // namespace detail - -template -struct formatter< - T, Char, - enable_if_t, - bool_constant::value == - range_format::disabled>>::value>> - : formatter, Char> { - using all = detail::all; - template - auto format(const T& value, FormatContext& ctx) const -> decltype(ctx.out()) { - struct getter : T { - static auto get(const T& v) -> all { - return {v.*(&getter::c)}; // Access c through the derived class. - } - }; - return formatter::format(getter::get(value), ctx); - } -}; - -FMT_BEGIN_EXPORT - -/// Returns a view that formats the iterator range `[begin, end)` with elements -/// separated by `sep`. -template -auto join(It begin, Sentinel end, string_view sep) -> join_view { - return {std::move(begin), end, sep}; -} - -/** - * Returns a view that formats `range` with elements separated by `sep`. - * - * **Example**: - * - * auto v = std::vector{1, 2, 3}; - * fmt::print("{}", fmt::join(v, ", ")); - * // Output: 1, 2, 3 - * - * `fmt::join` applies passed format specifiers to the range elements: - * - * fmt::print("{:02}", fmt::join(v, ", ")); - * // Output: 01, 02, 03 - */ -template ::value)> -auto join(Range&& r, string_view sep) - -> join_view { - return {detail::range_begin(r), detail::range_end(r), sep}; -} - -/** - * Returns an object that formats `std::tuple` with elements separated by `sep`. - * - * **Example**: - * - * auto t = std::tuple{1, 'a'}; - * fmt::print("{}", fmt::join(t, ", ")); - * // Output: 1, a - */ -template ::value)> -FMT_CONSTEXPR auto join(const Tuple& tuple, string_view sep) - -> tuple_join_view { - return {tuple, sep}; -} - -/** - * Returns an object that formats `std::initializer_list` with elements - * separated by `sep`. - * - * **Example**: - * - * fmt::print("{}", fmt::join({1, 2, 3}, ", ")); - * // Output: "1, 2, 3" - */ -template -auto join(std::initializer_list list, string_view sep) - -> join_view { - return join(std::begin(list), std::end(list), sep); -} - -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_RANGES_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/std.h b/examples/blueprints-example/external/spdlog/fmt/bundled/std.h deleted file mode 100644 index 5cf1061..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/std.h +++ /dev/null @@ -1,707 +0,0 @@ -// Formatting library for C++ - formatters for standard library types -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_STD_H_ -#define FMT_STD_H_ - -#include "format.h" -#include "ostream.h" - -#ifndef FMT_MODULE -# include -# include -# include -# include -# include // std::reference_wrapper -# include -# include -# include -# include // std::type_info -# include // std::make_index_sequence - -// Check FMT_CPLUSPLUS to suppress a bogus warning in MSVC. -# if FMT_CPLUSPLUS >= 201703L -# if FMT_HAS_INCLUDE() && \ - (!defined(FMT_CPP_LIB_FILESYSTEM) || FMT_CPP_LIB_FILESYSTEM != 0) -# include -# endif -# if FMT_HAS_INCLUDE() -# include -# endif -# if FMT_HAS_INCLUDE() -# include -# endif -# endif -// Use > instead of >= in the version check because may be -// available after C++17 but before C++20 is marked as implemented. -# if FMT_CPLUSPLUS > 201703L && FMT_HAS_INCLUDE() -# include -# endif -# if FMT_CPLUSPLUS > 202002L && FMT_HAS_INCLUDE() -# include -# endif -#endif // FMT_MODULE - -#if FMT_HAS_INCLUDE() -# include -#endif - -// GCC 4 does not support FMT_HAS_INCLUDE. -#if FMT_HAS_INCLUDE() || defined(__GLIBCXX__) -# include -// Android NDK with gabi++ library on some architectures does not implement -// abi::__cxa_demangle(). -# ifndef __GABIXX_CXXABI_H__ -# define FMT_HAS_ABI_CXA_DEMANGLE -# endif -#endif - -#ifdef FMT_CPP_LIB_FILESYSTEM -// Use the provided definition. -#elif defined(__cpp_lib_filesystem) -# define FMT_CPP_LIB_FILESYSTEM __cpp_lib_filesystem -#else -# define FMT_CPP_LIB_FILESYSTEM 0 -#endif - -#ifdef FMT_CPP_LIB_VARIANT -// Use the provided definition. -#elif defined(__cpp_lib_variant) -# define FMT_CPP_LIB_VARIANT __cpp_lib_variant -#else -# define FMT_CPP_LIB_VARIANT 0 -#endif - -FMT_BEGIN_NAMESPACE -namespace detail { - -#if FMT_CPP_LIB_FILESYSTEM - -template -auto get_path_string(const std::filesystem::path& p, - const std::basic_string& native) { - if constexpr (std::is_same_v && std::is_same_v) - return to_utf8(native, to_utf8_error_policy::replace); - else - return p.string(); -} - -template -void write_escaped_path(basic_memory_buffer& quoted, - const std::filesystem::path& p, - const std::basic_string& native) { - if constexpr (std::is_same_v && - std::is_same_v) { - auto buf = basic_memory_buffer(); - write_escaped_string(std::back_inserter(buf), native); - bool valid = to_utf8::convert(quoted, {buf.data(), buf.size()}); - FMT_ASSERT(valid, "invalid utf16"); - } else if constexpr (std::is_same_v) { - write_escaped_string( - std::back_inserter(quoted), native); - } else { - write_escaped_string(std::back_inserter(quoted), p.string()); - } -} - -#endif // FMT_CPP_LIB_FILESYSTEM - -#if defined(__cpp_lib_expected) || FMT_CPP_LIB_VARIANT -template -auto write_escaped_alternative(OutputIt out, const T& v) -> OutputIt { - if constexpr (has_to_string_view::value) - return write_escaped_string(out, detail::to_string_view(v)); - if constexpr (std::is_same_v) return write_escaped_char(out, v); - return write(out, v); -} -#endif - -#if FMT_CPP_LIB_VARIANT - -template struct is_variant_like_ : std::false_type {}; -template -struct is_variant_like_> : std::true_type {}; - -template class is_variant_formattable { - template - static auto check(std::index_sequence) -> std::conjunction< - is_formattable, Char>...>; - - public: - static constexpr bool value = decltype(check( - std::make_index_sequence::value>()))::value; -}; - -#endif // FMT_CPP_LIB_VARIANT - -#if FMT_USE_RTTI - -template -auto write_demangled_name(OutputIt out, const std::type_info& ti) -> OutputIt { -# ifdef FMT_HAS_ABI_CXA_DEMANGLE - int status = 0; - size_t size = 0; - std::unique_ptr demangled_name_ptr( - abi::__cxa_demangle(ti.name(), nullptr, &size, &status), &std::free); - - string_view demangled_name_view; - if (demangled_name_ptr) { - demangled_name_view = demangled_name_ptr.get(); - - // Normalization of stdlib inline namespace names. - // libc++ inline namespaces. - // std::__1::* -> std::* - // std::__1::__fs::* -> std::* - // libstdc++ inline namespaces. - // std::__cxx11::* -> std::* - // std::filesystem::__cxx11::* -> std::filesystem::* - if (demangled_name_view.starts_with("std::")) { - char* begin = demangled_name_ptr.get(); - char* to = begin + 5; // std:: - for (char *from = to, *end = begin + demangled_name_view.size(); - from < end;) { - // This is safe, because demangled_name is NUL-terminated. - if (from[0] == '_' && from[1] == '_') { - char* next = from + 1; - while (next < end && *next != ':') next++; - if (next[0] == ':' && next[1] == ':') { - from = next + 2; - continue; - } - } - *to++ = *from++; - } - demangled_name_view = {begin, detail::to_unsigned(to - begin)}; - } - } else { - demangled_name_view = string_view(ti.name()); - } - return detail::write_bytes(out, demangled_name_view); -# elif FMT_MSC_VERSION - const string_view demangled_name(ti.name()); - for (size_t i = 0; i < demangled_name.size(); ++i) { - auto sub = demangled_name; - sub.remove_prefix(i); - if (sub.starts_with("enum ")) { - i += 4; - continue; - } - if (sub.starts_with("class ") || sub.starts_with("union ")) { - i += 5; - continue; - } - if (sub.starts_with("struct ")) { - i += 6; - continue; - } - if (*sub.begin() != ' ') *out++ = *sub.begin(); - } - return out; -# else - return detail::write_bytes(out, string_view(ti.name())); -# endif -} - -#endif // FMT_USE_RTTI - -template -struct has_flip : std::false_type {}; - -template -struct has_flip().flip())>> - : std::true_type {}; - -template struct is_bit_reference_like { - static constexpr bool value = std::is_convertible::value && - std::is_nothrow_assignable::value && - has_flip::value; -}; - -// Workaround for libc++ incompatibility with C++ standard. -// According to the Standard, `bitset::operator[] const` returns bool. -#if defined(_LIBCPP_VERSION) && !defined(FMT_IMPORT_STD) -template -struct is_bit_reference_like> { - static constexpr bool value = true; -}; -#endif - -template -struct has_format_as : std::false_type {}; -template -struct has_format_as()))>> - : std::true_type {}; - -template -struct has_format_as_member : std::false_type {}; -template -struct has_format_as_member< - T, void_t::format_as(std::declval()))>> - : std::true_type {}; - -} // namespace detail - -template -auto ptr(const std::unique_ptr& p) -> const void* { - return p.get(); -} -template auto ptr(const std::shared_ptr& p) -> const void* { - return p.get(); -} - -#if FMT_CPP_LIB_FILESYSTEM - -class path : public std::filesystem::path { - public: - auto display_string() const -> std::string { - const std::filesystem::path& base = *this; - return fmt::format(FMT_STRING("{}"), base); - } - auto system_string() const -> std::string { return string(); } - - auto generic_display_string() const -> std::string { - const std::filesystem::path& base = *this; - return fmt::format(FMT_STRING("{:g}"), base); - } - auto generic_system_string() const -> std::string { return generic_string(); } -}; - -template struct formatter { - private: - format_specs specs_; - detail::arg_ref width_ref_; - bool debug_ = false; - char path_type_ = 0; - - public: - FMT_CONSTEXPR void set_debug_format(bool set = true) { debug_ = set; } - - FMT_CONSTEXPR auto parse(parse_context& ctx) { - auto it = ctx.begin(), end = ctx.end(); - if (it == end) return it; - - it = detail::parse_align(it, end, specs_); - if (it == end) return it; - - Char c = *it; - if ((c >= '0' && c <= '9') || c == '{') - it = detail::parse_width(it, end, specs_, width_ref_, ctx); - if (it != end && *it == '?') { - debug_ = true; - ++it; - } - if (it != end && (*it == 'g')) path_type_ = detail::to_ascii(*it++); - return it; - } - - template - auto format(const std::filesystem::path& p, FormatContext& ctx) const { - auto specs = specs_; - auto path_string = - !path_type_ ? p.native() - : p.generic_string(); - - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, - ctx); - if (!debug_) { - auto s = detail::get_path_string(p, path_string); - return detail::write(ctx.out(), basic_string_view(s), specs); - } - auto quoted = basic_memory_buffer(); - detail::write_escaped_path(quoted, p, path_string); - return detail::write(ctx.out(), - basic_string_view(quoted.data(), quoted.size()), - specs); - } -}; - -#endif // FMT_CPP_LIB_FILESYSTEM - -template -struct formatter, Char> - : nested_formatter, Char> { - private: - // This is a functor because C++11 doesn't support generic lambdas. - struct writer { - const std::bitset& bs; - - template - FMT_CONSTEXPR auto operator()(OutputIt out) -> OutputIt { - for (auto pos = N; pos > 0; --pos) - out = detail::write(out, bs[pos - 1] ? Char('1') : Char('0')); - return out; - } - }; - - public: - template - auto format(const std::bitset& bs, FormatContext& ctx) const - -> decltype(ctx.out()) { - return this->write_padded(ctx, writer{bs}); - } -}; - -template -struct formatter : basic_ostream_formatter {}; - -#ifdef __cpp_lib_optional -template -struct formatter, Char, - std::enable_if_t::value>> { - private: - formatter underlying_; - static constexpr basic_string_view optional = - detail::string_literal{}; - static constexpr basic_string_view none = - detail::string_literal{}; - - template - FMT_CONSTEXPR static auto maybe_set_debug_format(U& u, bool set) - -> decltype(u.set_debug_format(set)) { - u.set_debug_format(set); - } - - template - FMT_CONSTEXPR static void maybe_set_debug_format(U&, ...) {} - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) { - maybe_set_debug_format(underlying_, true); - return underlying_.parse(ctx); - } - - template - auto format(const std::optional& opt, FormatContext& ctx) const - -> decltype(ctx.out()) { - if (!opt) return detail::write(ctx.out(), none); - - auto out = ctx.out(); - out = detail::write(out, optional); - ctx.advance_to(out); - out = underlying_.format(*opt, ctx); - return detail::write(out, ')'); - } -}; -#endif // __cpp_lib_optional - -#ifdef __cpp_lib_expected -template -struct formatter, Char, - std::enable_if_t<(std::is_void::value || - is_formattable::value) && - is_formattable::value>> { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return ctx.begin(); - } - - template - auto format(const std::expected& value, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); - - if (value.has_value()) { - out = detail::write(out, "expected("); - if constexpr (!std::is_void::value) - out = detail::write_escaped_alternative(out, *value); - } else { - out = detail::write(out, "unexpected("); - out = detail::write_escaped_alternative(out, value.error()); - } - *out++ = ')'; - return out; - } -}; -#endif // __cpp_lib_expected - -#ifdef __cpp_lib_source_location -template <> struct formatter { - FMT_CONSTEXPR auto parse(parse_context<>& ctx) { return ctx.begin(); } - - template - auto format(const std::source_location& loc, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); - out = detail::write(out, loc.file_name()); - out = detail::write(out, ':'); - out = detail::write(out, loc.line()); - out = detail::write(out, ':'); - out = detail::write(out, loc.column()); - out = detail::write(out, ": "); - out = detail::write(out, loc.function_name()); - return out; - } -}; -#endif - -#if FMT_CPP_LIB_VARIANT - -template struct is_variant_like { - static constexpr bool value = detail::is_variant_like_::value; -}; - -template struct formatter { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return ctx.begin(); - } - - template - auto format(const std::monostate&, FormatContext& ctx) const - -> decltype(ctx.out()) { - return detail::write(ctx.out(), "monostate"); - } -}; - -template -struct formatter, - detail::is_variant_formattable>>> { - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - return ctx.begin(); - } - - template - auto format(const Variant& value, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); - - out = detail::write(out, "variant("); - FMT_TRY { - std::visit( - [&](const auto& v) { - out = detail::write_escaped_alternative(out, v); - }, - value); - } - FMT_CATCH(const std::bad_variant_access&) { - detail::write(out, "valueless by exception"); - } - *out++ = ')'; - return out; - } -}; - -#endif // FMT_CPP_LIB_VARIANT - -template <> struct formatter { - private: - format_specs specs_; - detail::arg_ref width_ref_; - bool debug_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - auto it = ctx.begin(), end = ctx.end(); - if (it == end) return it; - - it = detail::parse_align(it, end, specs_); - - char c = *it; - if (it != end && ((c >= '0' && c <= '9') || c == '{')) - it = detail::parse_width(it, end, specs_, width_ref_, ctx); - - if (it != end && *it == '?') { - debug_ = true; - ++it; - } - if (it != end && *it == 's') { - specs_.set_type(presentation_type::string); - ++it; - } - return it; - } - - template - FMT_CONSTEXPR20 auto format(const std::error_code& ec, - FormatContext& ctx) const -> decltype(ctx.out()) { - auto specs = specs_; - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, width_ref_, - ctx); - auto buf = memory_buffer(); - if (specs_.type() == presentation_type::string) { - buf.append(ec.message()); - } else { - buf.append(string_view(ec.category().name())); - buf.push_back(':'); - detail::write(appender(buf), ec.value()); - } - auto quoted = memory_buffer(); - auto str = string_view(buf.data(), buf.size()); - if (debug_) { - detail::write_escaped_string(std::back_inserter(quoted), str); - str = string_view(quoted.data(), quoted.size()); - } - return detail::write(ctx.out(), str, specs); - } -}; - -#if FMT_USE_RTTI -template <> struct formatter { - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - return ctx.begin(); - } - - template - auto format(const std::type_info& ti, Context& ctx) const - -> decltype(ctx.out()) { - return detail::write_demangled_name(ctx.out(), ti); - } -}; -#endif // FMT_USE_RTTI - -template -struct formatter< - T, char, - typename std::enable_if::value>::type> { - private: - bool with_typename_ = false; - - public: - FMT_CONSTEXPR auto parse(parse_context<>& ctx) -> const char* { - auto it = ctx.begin(); - auto end = ctx.end(); - if (it == end || *it == '}') return it; - if (*it == 't') { - ++it; - with_typename_ = FMT_USE_RTTI != 0; - } - return it; - } - - template - auto format(const std::exception& ex, Context& ctx) const - -> decltype(ctx.out()) { - auto out = ctx.out(); -#if FMT_USE_RTTI - if (with_typename_) { - out = detail::write_demangled_name(out, typeid(ex)); - *out++ = ':'; - *out++ = ' '; - } -#endif - return detail::write_bytes(out, string_view(ex.what())); - } -}; - -// We can't use std::vector::reference and -// std::bitset::reference because the compiler can't deduce Allocator and N -// in partial specialization. -template -struct formatter::value>> - : formatter { - template - FMT_CONSTEXPR auto format(const BitRef& v, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter::format(v, ctx); - } -}; - -template -struct formatter, Char, - enable_if_t::value>> - : formatter { - template - auto format(const std::atomic& v, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter::format(v.load(), ctx); - } -}; - -#ifdef __cpp_lib_atomic_flag_test -template -struct formatter : formatter { - template - auto format(const std::atomic_flag& v, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter::format(v.test(), ctx); - } -}; -#endif // __cpp_lib_atomic_flag_test - -template struct formatter, Char> { - private: - detail::dynamic_format_specs specs_; - - template - FMT_CONSTEXPR auto do_format(const std::complex& c, - detail::dynamic_format_specs& specs, - FormatContext& ctx, OutputIt out) const - -> OutputIt { - if (c.real() != 0) { - *out++ = Char('('); - out = detail::write(out, c.real(), specs, ctx.locale()); - specs.set_sign(sign::plus); - out = detail::write(out, c.imag(), specs, ctx.locale()); - if (!detail::isfinite(c.imag())) *out++ = Char(' '); - *out++ = Char('i'); - *out++ = Char(')'); - return out; - } - out = detail::write(out, c.imag(), specs, ctx.locale()); - if (!detail::isfinite(c.imag())) *out++ = Char(' '); - *out++ = Char('i'); - return out; - } - - public: - FMT_CONSTEXPR auto parse(parse_context& ctx) -> const Char* { - if (ctx.begin() == ctx.end() || *ctx.begin() == '}') return ctx.begin(); - return parse_format_specs(ctx.begin(), ctx.end(), specs_, ctx, - detail::type_constant::value); - } - - template - auto format(const std::complex& c, FormatContext& ctx) const - -> decltype(ctx.out()) { - auto specs = specs_; - if (specs.dynamic()) { - detail::handle_dynamic_spec(specs.dynamic_width(), specs.width, - specs.width_ref, ctx); - detail::handle_dynamic_spec(specs.dynamic_precision(), specs.precision, - specs.precision_ref, ctx); - } - - if (specs.width == 0) return do_format(c, specs, ctx, ctx.out()); - auto buf = basic_memory_buffer(); - - auto outer_specs = format_specs(); - outer_specs.width = specs.width; - outer_specs.copy_fill_from(specs); - outer_specs.set_align(specs.align()); - - specs.width = 0; - specs.set_fill({}); - specs.set_align(align::none); - - do_format(c, specs, ctx, basic_appender(buf)); - return detail::write(ctx.out(), - basic_string_view(buf.data(), buf.size()), - outer_specs); - } -}; - -template -struct formatter, Char, - // Guard against format_as because reference_wrapper is - // implicitly convertible to T&. - enable_if_t, Char>::value && - !detail::has_format_as::value && - !detail::has_format_as_member::value>> - : formatter, Char> { - template - auto format(std::reference_wrapper ref, FormatContext& ctx) const - -> decltype(ctx.out()) { - return formatter, Char>::format(ref.get(), ctx); - } -}; - -FMT_END_NAMESPACE - -#endif // FMT_STD_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/bundled/xchar.h b/examples/blueprints-example/external/spdlog/fmt/bundled/xchar.h deleted file mode 100644 index 9334b87..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/bundled/xchar.h +++ /dev/null @@ -1,356 +0,0 @@ -// Formatting library for C++ - optional wchar_t and exotic character support -// -// Copyright (c) 2012 - present, Victor Zverovich -// All rights reserved. -// -// For the license information refer to format.h. - -#ifndef FMT_XCHAR_H_ -#define FMT_XCHAR_H_ - -#include "color.h" -#include "format.h" -#include "ostream.h" -#include "ranges.h" - -#ifndef FMT_MODULE -# include -# if FMT_USE_LOCALE -# include -# endif -#endif - -FMT_BEGIN_NAMESPACE -namespace detail { - -template -using is_exotic_char = bool_constant::value>; - -template struct format_string_char {}; - -template -struct format_string_char< - S, void_t())))>> { - using type = char_t; -}; - -template -struct format_string_char< - S, enable_if_t::value>> { - using type = typename S::char_type; -}; - -template -using format_string_char_t = typename format_string_char::type; - -inline auto write_loc(basic_appender out, loc_value value, - const format_specs& specs, locale_ref loc) -> bool { -#if FMT_USE_LOCALE - auto& numpunct = - std::use_facet>(loc.get()); - auto separator = std::wstring(); - auto grouping = numpunct.grouping(); - if (!grouping.empty()) separator = std::wstring(1, numpunct.thousands_sep()); - return value.visit(loc_writer{out, specs, separator, grouping, {}}); -#endif - return false; -} - -template -void vformat_to(buffer& buf, basic_string_view fmt, - basic_format_args> args, - locale_ref loc = {}) { - static_assert(!std::is_same::value, ""); - auto out = basic_appender(buf); - parse_format_string( - fmt, format_handler{parse_context(fmt), {out, args, loc}}); -} -} // namespace detail - -FMT_BEGIN_EXPORT - -using wstring_view = basic_string_view; -using wformat_parse_context = parse_context; -using wformat_context = buffered_context; -using wformat_args = basic_format_args; -using wmemory_buffer = basic_memory_buffer; - -template struct basic_fstring { - private: - basic_string_view str_; - - static constexpr int num_static_named_args = - detail::count_static_named_args(); - - using checker = detail::format_string_checker< - Char, static_cast(sizeof...(T)), num_static_named_args, - num_static_named_args != detail::count_named_args()>; - - using arg_pack = detail::arg_pack; - - public: - using t = basic_fstring; - - template >::value)> - FMT_CONSTEVAL FMT_ALWAYS_INLINE basic_fstring(const S& s) : str_(s) { - if (FMT_USE_CONSTEVAL) - detail::parse_format_string(s, checker(s, arg_pack())); - } - template ::value&& - std::is_same::value)> - FMT_ALWAYS_INLINE basic_fstring(const S&) : str_(S()) { - FMT_CONSTEXPR auto sv = basic_string_view(S()); - FMT_CONSTEXPR int ignore = - (parse_format_string(sv, checker(sv, arg_pack())), 0); - detail::ignore_unused(ignore); - } - basic_fstring(runtime_format_string fmt) : str_(fmt.str) {} - - operator basic_string_view() const { return str_; } - auto get() const -> basic_string_view { return str_; } -}; - -template -using basic_format_string = basic_fstring; - -template -using wformat_string = typename basic_format_string::t; -inline auto runtime(wstring_view s) -> runtime_format_string { - return {{s}}; -} - -template -constexpr auto make_wformat_args(T&... args) - -> decltype(fmt::make_format_args(args...)) { - return fmt::make_format_args(args...); -} - -#if !FMT_USE_NONTYPE_TEMPLATE_ARGS -inline namespace literals { -inline auto operator""_a(const wchar_t* s, size_t) -> detail::udl_arg { - return {s}; -} -} // namespace literals -#endif - -template -auto join(It begin, Sentinel end, wstring_view sep) - -> join_view { - return {begin, end, sep}; -} - -template ::value)> -auto join(Range&& range, wstring_view sep) - -> join_view { - return join(std::begin(range), std::end(range), sep); -} - -template -auto join(std::initializer_list list, wstring_view sep) - -> join_view { - return join(std::begin(list), std::end(list), sep); -} - -template ::value)> -auto join(const Tuple& tuple, basic_string_view sep) - -> tuple_join_view { - return {tuple, sep}; -} - -template ::value)> -auto vformat(basic_string_view fmt, - basic_format_args> args) - -> std::basic_string { - auto buf = basic_memory_buffer(); - detail::vformat_to(buf, fmt, args); - return {buf.data(), buf.size()}; -} - -template -auto format(wformat_string fmt, T&&... args) -> std::wstring { - return vformat(fmt::wstring_view(fmt), fmt::make_wformat_args(args...)); -} - -template -auto format_to(OutputIt out, wformat_string fmt, T&&... args) - -> OutputIt { - return vformat_to(out, fmt::wstring_view(fmt), - fmt::make_wformat_args(args...)); -} - -// Pass char_t as a default template parameter instead of using -// std::basic_string> to reduce the symbol size. -template , - FMT_ENABLE_IF(!std::is_same::value && - !std::is_same::value)> -auto format(const S& fmt, T&&... args) -> std::basic_string { - return vformat(detail::to_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template , - FMT_ENABLE_IF(detail::is_exotic_char::value)> -inline auto vformat(locale_ref loc, const S& fmt, - basic_format_args> args) - -> std::basic_string { - auto buf = basic_memory_buffer(); - detail::vformat_to(buf, detail::to_string_view(fmt), args, loc); - return {buf.data(), buf.size()}; -} - -template , - FMT_ENABLE_IF(detail::is_exotic_char::value)> -inline auto format(locale_ref loc, const S& fmt, T&&... args) - -> std::basic_string { - return vformat(loc, detail::to_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> -auto vformat_to(OutputIt out, const S& fmt, - basic_format_args> args) -> OutputIt { - auto&& buf = detail::get_buffer(out); - detail::vformat_to(buf, detail::to_string_view(fmt), args); - return detail::get_iterator(buf, out); -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value && - !std::is_same::value && - !std::is_same::value)> -inline auto format_to(OutputIt out, const S& fmt, T&&... args) -> OutputIt { - return vformat_to(out, detail::to_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> -inline auto vformat_to(OutputIt out, locale_ref loc, const S& fmt, - basic_format_args> args) - -> OutputIt { - auto&& buf = detail::get_buffer(out); - vformat_to(buf, detail::to_string_view(fmt), args, loc); - return detail::get_iterator(buf, out); -} - -template , - bool enable = detail::is_output_iterator::value && - detail::is_exotic_char::value> -inline auto format_to(OutputIt out, locale_ref loc, const S& fmt, T&&... args) - -> typename std::enable_if::type { - return vformat_to(out, loc, detail::to_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template ::value&& - detail::is_exotic_char::value)> -inline auto vformat_to_n(OutputIt out, size_t n, basic_string_view fmt, - basic_format_args> args) - -> format_to_n_result { - using traits = detail::fixed_buffer_traits; - auto buf = detail::iterator_buffer(out, n); - detail::vformat_to(buf, fmt, args); - return {buf.out(), buf.count()}; -} - -template , - FMT_ENABLE_IF(detail::is_output_iterator::value&& - detail::is_exotic_char::value)> -inline auto format_to_n(OutputIt out, size_t n, const S& fmt, T&&... args) - -> format_to_n_result { - return vformat_to_n(out, n, fmt::basic_string_view(fmt), - fmt::make_format_args>(args...)); -} - -template , - FMT_ENABLE_IF(detail::is_exotic_char::value)> -inline auto formatted_size(const S& fmt, T&&... args) -> size_t { - auto buf = detail::counting_buffer(); - detail::vformat_to(buf, detail::to_string_view(fmt), - fmt::make_format_args>(args...)); - return buf.count(); -} - -inline void vprint(std::FILE* f, wstring_view fmt, wformat_args args) { - auto buf = wmemory_buffer(); - detail::vformat_to(buf, fmt, args); - buf.push_back(L'\0'); - if (std::fputws(buf.data(), f) == -1) - FMT_THROW(system_error(errno, FMT_STRING("cannot write to file"))); -} - -inline void vprint(wstring_view fmt, wformat_args args) { - vprint(stdout, fmt, args); -} - -template -void print(std::FILE* f, wformat_string fmt, T&&... args) { - return vprint(f, wstring_view(fmt), fmt::make_wformat_args(args...)); -} - -template void print(wformat_string fmt, T&&... args) { - return vprint(wstring_view(fmt), fmt::make_wformat_args(args...)); -} - -template -void println(std::FILE* f, wformat_string fmt, T&&... args) { - return print(f, L"{}\n", fmt::format(fmt, std::forward(args)...)); -} - -template void println(wformat_string fmt, T&&... args) { - return print(L"{}\n", fmt::format(fmt, std::forward(args)...)); -} - -inline auto vformat(text_style ts, wstring_view fmt, wformat_args args) - -> std::wstring { - auto buf = wmemory_buffer(); - detail::vformat_to(buf, ts, fmt, args); - return {buf.data(), buf.size()}; -} - -template -inline auto format(text_style ts, wformat_string fmt, T&&... args) - -> std::wstring { - return fmt::vformat(ts, fmt, fmt::make_wformat_args(args...)); -} - -inline void vprint(std::wostream& os, wstring_view fmt, wformat_args args) { - auto buffer = basic_memory_buffer(); - detail::vformat_to(buffer, fmt, args); - detail::write_buffer(os, buffer); -} - -template -void print(std::wostream& os, wformat_string fmt, T&&... args) { - vprint(os, fmt, fmt::make_format_args>(args...)); -} - -template -void println(std::wostream& os, wformat_string fmt, T&&... args) { - print(os, L"{}\n", fmt::format(fmt, std::forward(args)...)); -} - -/// Converts `value` to `std::wstring` using the default format for type `T`. -template inline auto to_wstring(const T& value) -> std::wstring { - return format(FMT_STRING(L"{}"), value); -} -FMT_END_EXPORT -FMT_END_NAMESPACE - -#endif // FMT_XCHAR_H_ diff --git a/examples/blueprints-example/external/spdlog/fmt/chrono.h b/examples/blueprints-example/external/spdlog/fmt/chrono.h deleted file mode 100644 index a72a5bd..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/chrono.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's chrono support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/spdlog/fmt/compile.h b/examples/blueprints-example/external/spdlog/fmt/compile.h deleted file mode 100644 index 3c9c25d..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/compile.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's compile-time support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/spdlog/fmt/fmt.h b/examples/blueprints-example/external/spdlog/fmt/fmt.h deleted file mode 100644 index ba94a0c..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/fmt.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// Copyright(c) 2016-2018 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once - -// -// Include a bundled header-only copy of fmtlib or an external one. -// By default spdlog include its own copy. -// -#include - -#if defined(SPDLOG_USE_STD_FORMAT) // SPDLOG_USE_STD_FORMAT is defined - use std::format - #include -#elif !defined(SPDLOG_FMT_EXTERNAL) - #if !defined(SPDLOG_COMPILED_LIB) && !defined(FMT_HEADER_ONLY) - #define FMT_HEADER_ONLY - #endif - #ifndef FMT_USE_WINDOWS_H - #define FMT_USE_WINDOWS_H 0 - #endif - #include -#else // SPDLOG_FMT_EXTERNAL is defined - use external fmtlib - #include -#endif diff --git a/examples/blueprints-example/external/spdlog/fmt/ostr.h b/examples/blueprints-example/external/spdlog/fmt/ostr.h deleted file mode 100644 index 2b90105..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/ostr.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's ostream support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/spdlog/fmt/ranges.h b/examples/blueprints-example/external/spdlog/fmt/ranges.h deleted file mode 100644 index 5bb91e9..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/ranges.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's ranges support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/spdlog/fmt/std.h b/examples/blueprints-example/external/spdlog/fmt/std.h deleted file mode 100644 index dabe6f6..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/std.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's std support (for formatting e.g. -// std::filesystem::path, std::thread::id, std::monostate, std::variant, ...) -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/spdlog/fmt/xchar.h b/examples/blueprints-example/external/spdlog/fmt/xchar.h deleted file mode 100644 index 2525f05..0000000 --- a/examples/blueprints-example/external/spdlog/fmt/xchar.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright(c) 2016 Gabi Melman. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) -// - -#pragma once -// -// include bundled or external copy of fmtlib's xchar support -// -#include - -#if !defined(SPDLOG_USE_STD_FORMAT) - #if !defined(SPDLOG_FMT_EXTERNAL) - #ifdef SPDLOG_HEADER_ONLY - #ifndef FMT_HEADER_ONLY - #define FMT_HEADER_ONLY - #endif - #endif - #include - #else - #include - #endif -#endif diff --git a/examples/blueprints-example/external/spdlog/formatter.h b/examples/blueprints-example/external/spdlog/formatter.h deleted file mode 100644 index 4d482f8..0000000 --- a/examples/blueprints-example/external/spdlog/formatter.h +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { - -class formatter { -public: - virtual ~formatter() = default; - virtual void format(const details::log_msg &msg, memory_buf_t &dest) = 0; - virtual std::unique_ptr clone() const = 0; -}; -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/fwd.h b/examples/blueprints-example/external/spdlog/fwd.h deleted file mode 100644 index 647b16b..0000000 --- a/examples/blueprints-example/external/spdlog/fwd.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -namespace spdlog { -class logger; -class formatter; - -namespace sinks { -class sink; -} - -namespace level { -enum level_enum : int; -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/logger-inl.h b/examples/blueprints-example/external/spdlog/logger-inl.h deleted file mode 100644 index 6879273..0000000 --- a/examples/blueprints-example/external/spdlog/logger-inl.h +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include -#include - -#include - -namespace spdlog { - -// public methods -SPDLOG_INLINE logger::logger(const logger &other) - : name_(other.name_), - sinks_(other.sinks_), - level_(other.level_.load(std::memory_order_relaxed)), - flush_level_(other.flush_level_.load(std::memory_order_relaxed)), - custom_err_handler_(other.custom_err_handler_), - tracer_(other.tracer_) {} - -SPDLOG_INLINE logger::logger(logger &&other) SPDLOG_NOEXCEPT - : name_(std::move(other.name_)), - sinks_(std::move(other.sinks_)), - level_(other.level_.load(std::memory_order_relaxed)), - flush_level_(other.flush_level_.load(std::memory_order_relaxed)), - custom_err_handler_(std::move(other.custom_err_handler_)), - tracer_(std::move(other.tracer_)) - -{} - -SPDLOG_INLINE logger &logger::operator=(logger other) SPDLOG_NOEXCEPT { - this->swap(other); - return *this; -} - -SPDLOG_INLINE void logger::swap(spdlog::logger &other) SPDLOG_NOEXCEPT { - name_.swap(other.name_); - sinks_.swap(other.sinks_); - - // swap level_ - auto other_level = other.level_.load(); - auto my_level = level_.exchange(other_level); - other.level_.store(my_level); - - // swap flush level_ - other_level = other.flush_level_.load(); - my_level = flush_level_.exchange(other_level); - other.flush_level_.store(my_level); - - custom_err_handler_.swap(other.custom_err_handler_); - std::swap(tracer_, other.tracer_); -} - -SPDLOG_INLINE void swap(logger &a, logger &b) noexcept { a.swap(b); } - -SPDLOG_INLINE void logger::set_level(level::level_enum log_level) { level_.store(log_level); } - -SPDLOG_INLINE level::level_enum logger::level() const { - return static_cast(level_.load(std::memory_order_relaxed)); -} - -SPDLOG_INLINE const std::string &logger::name() const { return name_; } - -// set formatting for the sinks in this logger. -// each sink will get a separate instance of the formatter object. -SPDLOG_INLINE void logger::set_formatter(std::unique_ptr f) { - for (auto it = sinks_.begin(); it != sinks_.end(); ++it) { - if (std::next(it) == sinks_.end()) { - // last element - we can be move it. - (*it)->set_formatter(std::move(f)); - break; // to prevent clang-tidy warning - } else { - (*it)->set_formatter(f->clone()); - } - } -} - -SPDLOG_INLINE void logger::set_pattern(std::string pattern, pattern_time_type time_type) { - auto new_formatter = details::make_unique(std::move(pattern), time_type); - set_formatter(std::move(new_formatter)); -} - -// create new backtrace sink and move to it all our child sinks -SPDLOG_INLINE void logger::enable_backtrace(size_t n_messages) { tracer_.enable(n_messages); } - -// restore orig sinks and level and delete the backtrace sink -SPDLOG_INLINE void logger::disable_backtrace() { tracer_.disable(); } - -SPDLOG_INLINE void logger::dump_backtrace() { dump_backtrace_(); } - -// flush functions -SPDLOG_INLINE void logger::flush() { flush_(); } - -SPDLOG_INLINE void logger::flush_on(level::level_enum log_level) { flush_level_.store(log_level); } - -SPDLOG_INLINE level::level_enum logger::flush_level() const { - return static_cast(flush_level_.load(std::memory_order_relaxed)); -} - -// sinks -SPDLOG_INLINE const std::vector &logger::sinks() const { return sinks_; } - -SPDLOG_INLINE std::vector &logger::sinks() { return sinks_; } - -// error handler -SPDLOG_INLINE void logger::set_error_handler(err_handler handler) { - custom_err_handler_ = std::move(handler); -} - -// create new logger with same sinks and configuration. -SPDLOG_INLINE std::shared_ptr logger::clone(std::string logger_name) { - auto cloned = std::make_shared(*this); - cloned->name_ = std::move(logger_name); - return cloned; -} - -// protected methods -SPDLOG_INLINE void logger::log_it_(const spdlog::details::log_msg &log_msg, - bool log_enabled, - bool traceback_enabled) { - if (log_enabled) { - sink_it_(log_msg); - } - if (traceback_enabled) { - tracer_.push_back(log_msg); - } -} - -SPDLOG_INLINE void logger::sink_it_(const details::log_msg &msg) { - for (auto &sink : sinks_) { - if (sink->should_log(msg.level)) { - SPDLOG_TRY { sink->log(msg); } - SPDLOG_LOGGER_CATCH(msg.source) - } - } - - if (should_flush_(msg)) { - flush_(); - } -} - -SPDLOG_INLINE void logger::flush_() { - for (auto &sink : sinks_) { - SPDLOG_TRY { sink->flush(); } - SPDLOG_LOGGER_CATCH(source_loc()) - } -} - -SPDLOG_INLINE void logger::dump_backtrace_() { - using details::log_msg; - if (tracer_.enabled() && !tracer_.empty()) { - sink_it_( - log_msg{name(), level::info, "****************** Backtrace Start ******************"}); - tracer_.foreach_pop([this](const log_msg &msg) { this->sink_it_(msg); }); - sink_it_( - log_msg{name(), level::info, "****************** Backtrace End ********************"}); - } -} - -SPDLOG_INLINE bool logger::should_flush_(const details::log_msg &msg) const { - auto flush_level = flush_level_.load(std::memory_order_relaxed); - return (msg.level >= flush_level) && (msg.level != level::off); -} - -SPDLOG_INLINE void logger::err_handler_(const std::string &msg) const { - if (custom_err_handler_) { - custom_err_handler_(msg); - } else { - using std::chrono::system_clock; - static std::mutex mutex; - static std::chrono::system_clock::time_point last_report_time; - static size_t err_counter = 0; - std::lock_guard lk{mutex}; - auto now = system_clock::now(); - err_counter++; - if (now - last_report_time < std::chrono::seconds(1)) { - return; - } - last_report_time = now; - auto tm_time = details::os::localtime(system_clock::to_time_t(now)); - char date_buf[64]; - std::strftime(date_buf, sizeof(date_buf), "%Y-%m-%d %H:%M:%S", &tm_time); -#if defined(USING_R) && defined(R_R_H) // if in R environment - REprintf("[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, name().c_str(), - msg.c_str()); -#else - std::fprintf(stderr, "[*** LOG ERROR #%04zu ***] [%s] [%s] %s\n", err_counter, date_buf, - name().c_str(), msg.c_str()); -#endif - } -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/logger.h b/examples/blueprints-example/external/spdlog/logger.h deleted file mode 100644 index 8c3cd91..0000000 --- a/examples/blueprints-example/external/spdlog/logger.h +++ /dev/null @@ -1,379 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// Thread safe logger (except for set_error_handler()) -// Has name, log level, vector of std::shared sink pointers and formatter -// Upon each log write the logger: -// 1. Checks if its log level is enough to log the message and if yes: -// 2. Call the underlying sinks to do the job. -// 3. Each sink use its own private copy of a formatter to format the message -// and send to its destination. -// -// The use of private formatter per sink provides the opportunity to cache some -// formatted data, and support for different format per sink. - -#include -#include -#include - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - #ifndef _WIN32 - #error SPDLOG_WCHAR_TO_UTF8_SUPPORT only supported on windows - #endif - #include -#endif - -#include - -#ifndef SPDLOG_NO_EXCEPTIONS - #define SPDLOG_LOGGER_CATCH(location) \ - catch (const std::exception &ex) { \ - if (location.filename) { \ - err_handler_(fmt_lib::format(SPDLOG_FMT_STRING("{} [{}({})]"), ex.what(), \ - location.filename, location.line)); \ - } else { \ - err_handler_(ex.what()); \ - } \ - } \ - catch (...) { \ - err_handler_("Rethrowing unknown exception in logger"); \ - throw; \ - } -#else - #define SPDLOG_LOGGER_CATCH(location) -#endif - -namespace spdlog { - -class SPDLOG_API logger { -public: - // Empty logger - explicit logger(std::string name) - : name_(std::move(name)), - sinks_() {} - - // Logger with range on sinks - template - logger(std::string name, It begin, It end) - : name_(std::move(name)), - sinks_(begin, end) {} - - // Logger with single sink - logger(std::string name, sink_ptr single_sink) - : logger(std::move(name), {std::move(single_sink)}) {} - - // Logger with sinks init list - logger(std::string name, sinks_init_list sinks) - : logger(std::move(name), sinks.begin(), sinks.end()) {} - - virtual ~logger() = default; - - logger(const logger &other); - logger(logger &&other) SPDLOG_NOEXCEPT; - logger &operator=(logger other) SPDLOG_NOEXCEPT; - void swap(spdlog::logger &other) SPDLOG_NOEXCEPT; - - template - void log(source_loc loc, level::level_enum lvl, format_string_t fmt, Args &&...args) { - log_(loc, lvl, details::to_string_view(fmt), std::forward(args)...); - } - - template - void log(level::level_enum lvl, format_string_t fmt, Args &&...args) { - log(source_loc{}, lvl, fmt, std::forward(args)...); - } - - template - void log(level::level_enum lvl, const T &msg) { - log(source_loc{}, lvl, msg); - } - - // T cannot be statically converted to format string (including string_view/wstring_view) - template ::value, - int>::type = 0> - void log(source_loc loc, level::level_enum lvl, const T &msg) { - log(loc, lvl, "{}", msg); - } - - void log(log_clock::time_point log_time, - source_loc loc, - level::level_enum lvl, - string_view_t msg) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - - details::log_msg log_msg(log_time, loc, name_, lvl, msg); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(source_loc loc, level::level_enum lvl, string_view_t msg) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - - details::log_msg log_msg(loc, name_, lvl, msg); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(level::level_enum lvl, string_view_t msg) { log(source_loc{}, lvl, msg); } - - template - void trace(format_string_t fmt, Args &&...args) { - log(level::trace, fmt, std::forward(args)...); - } - - template - void debug(format_string_t fmt, Args &&...args) { - log(level::debug, fmt, std::forward(args)...); - } - - template - void info(format_string_t fmt, Args &&...args) { - log(level::info, fmt, std::forward(args)...); - } - - template - void warn(format_string_t fmt, Args &&...args) { - log(level::warn, fmt, std::forward(args)...); - } - - template - void error(format_string_t fmt, Args &&...args) { - log(level::err, fmt, std::forward(args)...); - } - - template - void critical(format_string_t fmt, Args &&...args) { - log(level::critical, fmt, std::forward(args)...); - } - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - template - void log(source_loc loc, level::level_enum lvl, wformat_string_t fmt, Args &&...args) { - log_(loc, lvl, details::to_string_view(fmt), std::forward(args)...); - } - - template - void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) { - log(source_loc{}, lvl, fmt, std::forward(args)...); - } - - void log(log_clock::time_point log_time, - source_loc loc, - level::level_enum lvl, - wstring_view_t msg) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(msg.data(), msg.size()), buf); - details::log_msg log_msg(log_time, loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(source_loc loc, level::level_enum lvl, wstring_view_t msg) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(msg.data(), msg.size()), buf); - details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - - void log(level::level_enum lvl, wstring_view_t msg) { log(source_loc{}, lvl, msg); } - - template - void trace(wformat_string_t fmt, Args &&...args) { - log(level::trace, fmt, std::forward(args)...); - } - - template - void debug(wformat_string_t fmt, Args &&...args) { - log(level::debug, fmt, std::forward(args)...); - } - - template - void info(wformat_string_t fmt, Args &&...args) { - log(level::info, fmt, std::forward(args)...); - } - - template - void warn(wformat_string_t fmt, Args &&...args) { - log(level::warn, fmt, std::forward(args)...); - } - - template - void error(wformat_string_t fmt, Args &&...args) { - log(level::err, fmt, std::forward(args)...); - } - - template - void critical(wformat_string_t fmt, Args &&...args) { - log(level::critical, fmt, std::forward(args)...); - } -#endif - - template - void trace(const T &msg) { - log(level::trace, msg); - } - - template - void debug(const T &msg) { - log(level::debug, msg); - } - - template - void info(const T &msg) { - log(level::info, msg); - } - - template - void warn(const T &msg) { - log(level::warn, msg); - } - - template - void error(const T &msg) { - log(level::err, msg); - } - - template - void critical(const T &msg) { - log(level::critical, msg); - } - - // return true logging is enabled for the given level. - bool should_log(level::level_enum msg_level) const { - return msg_level >= level_.load(std::memory_order_relaxed); - } - - // return true if backtrace logging is enabled. - bool should_backtrace() const { return tracer_.enabled(); } - - void set_level(level::level_enum log_level); - - level::level_enum level() const; - - const std::string &name() const; - - // set formatting for the sinks in this logger. - // each sink will get a separate instance of the formatter object. - void set_formatter(std::unique_ptr f); - - // set formatting for the sinks in this logger. - // equivalent to - // set_formatter(make_unique(pattern, time_type)) - // Note: each sink will get a new instance of a formatter object, replacing the old one. - void set_pattern(std::string pattern, pattern_time_type time_type = pattern_time_type::local); - - // backtrace support. - // efficiently store all debug/trace messages in a circular buffer until needed for debugging. - void enable_backtrace(size_t n_messages); - void disable_backtrace(); - void dump_backtrace(); - - // flush functions - void flush(); - void flush_on(level::level_enum log_level); - level::level_enum flush_level() const; - - // sinks - const std::vector &sinks() const; - - std::vector &sinks(); - - // error handler - void set_error_handler(err_handler); - - // create new logger with same sinks and configuration. - virtual std::shared_ptr clone(std::string logger_name); - -protected: - std::string name_; - std::vector sinks_; - spdlog::level_t level_{level::info}; - spdlog::level_t flush_level_{level::off}; - err_handler custom_err_handler_{nullptr}; - details::backtracer tracer_; - - // common implementation for after templated public api has been resolved - template - void log_(source_loc loc, level::level_enum lvl, string_view_t fmt, Args &&...args) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - SPDLOG_TRY { - memory_buf_t buf; -#ifdef SPDLOG_USE_STD_FORMAT - fmt_lib::vformat_to(std::back_inserter(buf), fmt, fmt_lib::make_format_args(args...)); -#else - fmt::vformat_to(fmt::appender(buf), fmt, fmt::make_format_args(args...)); -#endif - - details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - SPDLOG_LOGGER_CATCH(loc) - } - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - template - void log_(source_loc loc, level::level_enum lvl, wstring_view_t fmt, Args &&...args) { - bool log_enabled = should_log(lvl); - bool traceback_enabled = tracer_.enabled(); - if (!log_enabled && !traceback_enabled) { - return; - } - SPDLOG_TRY { - // format to wmemory_buffer and convert to utf8 - wmemory_buf_t wbuf; - fmt_lib::vformat_to(std::back_inserter(wbuf), fmt, - fmt_lib::make_format_args(args...)); - - memory_buf_t buf; - details::os::wstr_to_utf8buf(wstring_view_t(wbuf.data(), wbuf.size()), buf); - details::log_msg log_msg(loc, name_, lvl, string_view_t(buf.data(), buf.size())); - log_it_(log_msg, log_enabled, traceback_enabled); - } - SPDLOG_LOGGER_CATCH(loc) - } -#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT - - // log the given message (if the given log level is high enough), - // and save backtrace (if backtrace is enabled). - void log_it_(const details::log_msg &log_msg, bool log_enabled, bool traceback_enabled); - virtual void sink_it_(const details::log_msg &msg); - virtual void flush_(); - void dump_backtrace_(); - bool should_flush_(const details::log_msg &msg) const; - - // handle errors during logging. - // default handler prints the error to stderr at max rate of 1 message/sec. - void err_handler_(const std::string &msg) const; -}; - -void swap(logger &a, logger &b) noexcept; - -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "logger-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/mdc.h b/examples/blueprints-example/external/spdlog/mdc.h deleted file mode 100644 index bc13174..0000000 --- a/examples/blueprints-example/external/spdlog/mdc.h +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#if defined(SPDLOG_NO_TLS) - #error "This header requires thread local storage support, but SPDLOG_NO_TLS is defined." -#endif - -#include -#include - -#include - -// MDC is a simple map of key->string values stored in thread local storage whose content will be -// printed by the loggers. Note: Not supported in async mode (thread local storage - so the async -// thread pool have different copy). -// -// Usage example: -// spdlog::mdc::put("mdc_key_1", "mdc_value_1"); -// spdlog::info("Hello, {}", "World!"); // => [2024-04-26 02:08:05.040] [info] -// [mdc_key_1:mdc_value_1] Hello, World! - -namespace spdlog { -class SPDLOG_API mdc { -public: - using mdc_map_t = std::map; - - static void put(const std::string &key, const std::string &value) { - get_context()[key] = value; - } - - static std::string get(const std::string &key) { - auto &context = get_context(); - auto it = context.find(key); - if (it != context.end()) { - return it->second; - } - return ""; - } - - static void remove(const std::string &key) { get_context().erase(key); } - - static void clear() { get_context().clear(); } - - static mdc_map_t &get_context() { - static thread_local mdc_map_t context; - return context; - } -}; - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/pattern_formatter-inl.h b/examples/blueprints-example/external/spdlog/pattern_formatter-inl.h deleted file mode 100644 index fd408ed..0000000 --- a/examples/blueprints-example/external/spdlog/pattern_formatter-inl.h +++ /dev/null @@ -1,1340 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include -#include - -#ifndef SPDLOG_NO_TLS - #include -#endif - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace spdlog { -namespace details { - -/////////////////////////////////////////////////////////////////////// -// name & level pattern appender -/////////////////////////////////////////////////////////////////////// - -class scoped_padder { -public: - scoped_padder(size_t wrapped_size, const padding_info &padinfo, memory_buf_t &dest) - : padinfo_(padinfo), - dest_(dest) { - remaining_pad_ = static_cast(padinfo.width_) - static_cast(wrapped_size); - if (remaining_pad_ <= 0) { - return; - } - - if (padinfo_.side_ == padding_info::pad_side::left) { - pad_it(remaining_pad_); - remaining_pad_ = 0; - } else if (padinfo_.side_ == padding_info::pad_side::center) { - auto half_pad = remaining_pad_ / 2; - auto reminder = remaining_pad_ & 1; - pad_it(half_pad); - remaining_pad_ = half_pad + reminder; // for the right side - } - } - - template - static unsigned int count_digits(T n) { - return fmt_helper::count_digits(n); - } - - ~scoped_padder() { - if (remaining_pad_ >= 0) { - pad_it(remaining_pad_); - } else if (padinfo_.truncate_) { - long new_size = static_cast(dest_.size()) + remaining_pad_; - if (new_size < 0) { - new_size = 0; - } - dest_.resize(static_cast(new_size)); - } - } - -private: - void pad_it(long count) { - fmt_helper::append_string_view(string_view_t(spaces_.data(), static_cast(count)), - dest_); - } - - const padding_info &padinfo_; - memory_buf_t &dest_; - long remaining_pad_; - string_view_t spaces_{" ", 64}; -}; - -struct null_scoped_padder { - null_scoped_padder(size_t /*wrapped_size*/, - const padding_info & /*padinfo*/, - memory_buf_t & /*dest*/) {} - - template - static unsigned int count_digits(T /* number */) { - return 0; - } -}; - -template -class name_formatter final : public flag_formatter { -public: - explicit name_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - ScopedPadder p(msg.logger_name.size(), padinfo_, dest); - fmt_helper::append_string_view(msg.logger_name, dest); - } -}; - -// log level appender -template -class level_formatter final : public flag_formatter { -public: - explicit level_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - const string_view_t &level_name = level::to_string_view(msg.level); - ScopedPadder p(level_name.size(), padinfo_, dest); - fmt_helper::append_string_view(level_name, dest); - } -}; - -// short log level appender -template -class short_level_formatter final : public flag_formatter { -public: - explicit short_level_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - string_view_t level_name{level::to_short_c_str(msg.level)}; - ScopedPadder p(level_name.size(), padinfo_, dest); - fmt_helper::append_string_view(level_name, dest); - } -}; - -/////////////////////////////////////////////////////////////////////// -// Date time pattern appenders -/////////////////////////////////////////////////////////////////////// - -static const char *ampm(const tm &t) { return t.tm_hour >= 12 ? "PM" : "AM"; } - -static int to12h(const tm &t) { return t.tm_hour > 12 ? t.tm_hour - 12 : t.tm_hour; } - -// Abbreviated weekday name -static std::array days{{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}}; - -template -class a_formatter final : public flag_formatter { -public: - explicit a_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - string_view_t field_value{days[static_cast(tm_time.tm_wday)]}; - ScopedPadder p(field_value.size(), padinfo_, dest); - fmt_helper::append_string_view(field_value, dest); - } -}; - -// Full weekday name -static std::array full_days{ - {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}}; - -template -class A_formatter : public flag_formatter { -public: - explicit A_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - string_view_t field_value{full_days[static_cast(tm_time.tm_wday)]}; - ScopedPadder p(field_value.size(), padinfo_, dest); - fmt_helper::append_string_view(field_value, dest); - } -}; - -// Abbreviated month -static const std::array months{ - {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}}; - -template -class b_formatter final : public flag_formatter { -public: - explicit b_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - string_view_t field_value{months[static_cast(tm_time.tm_mon)]}; - ScopedPadder p(field_value.size(), padinfo_, dest); - fmt_helper::append_string_view(field_value, dest); - } -}; - -// Full month name -static const std::array full_months{{"January", "February", "March", "April", - "May", "June", "July", "August", "September", - "October", "November", "December"}}; - -template -class B_formatter final : public flag_formatter { -public: - explicit B_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - string_view_t field_value{full_months[static_cast(tm_time.tm_mon)]}; - ScopedPadder p(field_value.size(), padinfo_, dest); - fmt_helper::append_string_view(field_value, dest); - } -}; - -// Date and time representation (Thu Aug 23 15:35:46 2014) -template -class c_formatter final : public flag_formatter { -public: - explicit c_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 24; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::append_string_view(days[static_cast(tm_time.tm_wday)], dest); - dest.push_back(' '); - fmt_helper::append_string_view(months[static_cast(tm_time.tm_mon)], dest); - dest.push_back(' '); - fmt_helper::append_int(tm_time.tm_mday, dest); - dest.push_back(' '); - // time - - fmt_helper::pad2(tm_time.tm_hour, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_min, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_sec, dest); - dest.push_back(' '); - fmt_helper::append_int(tm_time.tm_year + 1900, dest); - } -}; - -// year - 2 digit -template -class C_formatter final : public flag_formatter { -public: - explicit C_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_year % 100, dest); - } -}; - -// Short MM/DD/YY date, equivalent to %m/%d/%y 08/23/01 -template -class D_formatter final : public flag_formatter { -public: - explicit D_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 8; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::pad2(tm_time.tm_mon + 1, dest); - dest.push_back('/'); - fmt_helper::pad2(tm_time.tm_mday, dest); - dest.push_back('/'); - fmt_helper::pad2(tm_time.tm_year % 100, dest); - } -}; - -// year - 4 digit -template -class Y_formatter final : public flag_formatter { -public: - explicit Y_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 4; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_int(tm_time.tm_year + 1900, dest); - } -}; - -// month 1-12 -template -class m_formatter final : public flag_formatter { -public: - explicit m_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_mon + 1, dest); - } -}; - -// day of month 1-31 -template -class d_formatter final : public flag_formatter { -public: - explicit d_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_mday, dest); - } -}; - -// hours in 24 format 0-23 -template -class H_formatter final : public flag_formatter { -public: - explicit H_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_hour, dest); - } -}; - -// hours in 12 format 1-12 -template -class I_formatter final : public flag_formatter { -public: - explicit I_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(to12h(tm_time), dest); - } -}; - -// minutes 0-59 -template -class M_formatter final : public flag_formatter { -public: - explicit M_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_min, dest); - } -}; - -// seconds 0-59 -template -class S_formatter final : public flag_formatter { -public: - explicit S_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad2(tm_time.tm_sec, dest); - } -}; - -// milliseconds -template -class e_formatter final : public flag_formatter { -public: - explicit e_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - auto millis = fmt_helper::time_fraction(msg.time); - const size_t field_size = 3; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad3(static_cast(millis.count()), dest); - } -}; - -// microseconds -template -class f_formatter final : public flag_formatter { -public: - explicit f_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - auto micros = fmt_helper::time_fraction(msg.time); - - const size_t field_size = 6; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad6(static_cast(micros.count()), dest); - } -}; - -// nanoseconds -template -class F_formatter final : public flag_formatter { -public: - explicit F_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - auto ns = fmt_helper::time_fraction(msg.time); - const size_t field_size = 9; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::pad9(static_cast(ns.count()), dest); - } -}; - -// seconds since epoch -template -class E_formatter final : public flag_formatter { -public: - explicit E_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - const size_t field_size = 10; - ScopedPadder p(field_size, padinfo_, dest); - auto duration = msg.time.time_since_epoch(); - auto seconds = std::chrono::duration_cast(duration).count(); - fmt_helper::append_int(seconds, dest); - } -}; - -// AM/PM -template -class p_formatter final : public flag_formatter { -public: - explicit p_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 2; - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_string_view(ampm(tm_time), dest); - } -}; - -// 12 hour clock 02:55:02 pm -template -class r_formatter final : public flag_formatter { -public: - explicit r_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 11; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::pad2(to12h(tm_time), dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_min, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_sec, dest); - dest.push_back(' '); - fmt_helper::append_string_view(ampm(tm_time), dest); - } -}; - -// 24-hour HH:MM time, equivalent to %H:%M -template -class R_formatter final : public flag_formatter { -public: - explicit R_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 5; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::pad2(tm_time.tm_hour, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_min, dest); - } -}; - -// ISO 8601 time format (HH:MM:SS), equivalent to %H:%M:%S -template -class T_formatter final : public flag_formatter { -public: - explicit T_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 8; - ScopedPadder p(field_size, padinfo_, dest); - - fmt_helper::pad2(tm_time.tm_hour, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_min, dest); - dest.push_back(':'); - fmt_helper::pad2(tm_time.tm_sec, dest); - } -}; - -// ISO 8601 offset from UTC in timezone (+-HH:MM) -template -class z_formatter final : public flag_formatter { -public: - explicit z_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - z_formatter() = default; - z_formatter(const z_formatter &) = delete; - z_formatter &operator=(const z_formatter &) = delete; - - void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override { - const size_t field_size = 6; - ScopedPadder p(field_size, padinfo_, dest); - - auto total_minutes = get_cached_offset(msg, tm_time); - bool is_negative = total_minutes < 0; - if (is_negative) { - total_minutes = -total_minutes; - dest.push_back('-'); - } else { - dest.push_back('+'); - } - - fmt_helper::pad2(total_minutes / 60, dest); // hours - dest.push_back(':'); - fmt_helper::pad2(total_minutes % 60, dest); // minutes - } - -private: - log_clock::time_point last_update_{std::chrono::seconds(0)}; - int offset_minutes_{0}; - - int get_cached_offset(const log_msg &msg, const std::tm &tm_time) { - // refresh every 10 seconds - if (msg.time - last_update_ >= std::chrono::seconds(10)) { - offset_minutes_ = os::utc_minutes_offset(tm_time); - last_update_ = msg.time; - } - return offset_minutes_; - } -}; - -// Thread id -template -class t_formatter final : public flag_formatter { -public: - explicit t_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - const auto field_size = ScopedPadder::count_digits(msg.thread_id); - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_int(msg.thread_id, dest); - } -}; - -// Current pid -template -class pid_formatter final : public flag_formatter { -public: - explicit pid_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { - const auto pid = static_cast(details::os::pid()); - auto field_size = ScopedPadder::count_digits(pid); - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_int(pid, dest); - } -}; - -template -class v_formatter final : public flag_formatter { -public: - explicit v_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - ScopedPadder p(msg.payload.size(), padinfo_, dest); - fmt_helper::append_string_view(msg.payload, dest); - } -}; - -class ch_formatter final : public flag_formatter { -public: - explicit ch_formatter(char ch) - : ch_(ch) {} - - void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { - dest.push_back(ch_); - } - -private: - char ch_; -}; - -// aggregate user chars to display as is -class aggregate_formatter final : public flag_formatter { -public: - aggregate_formatter() = default; - - void add_ch(char ch) { str_ += ch; } - void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { - fmt_helper::append_string_view(str_, dest); - } - -private: - std::string str_; -}; - -// mark the color range. expect it to be in the form of "%^colored text%$" -class color_start_formatter final : public flag_formatter { -public: - explicit color_start_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - msg.color_range_start = dest.size(); - } -}; - -class color_stop_formatter final : public flag_formatter { -public: - explicit color_stop_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - msg.color_range_end = dest.size(); - } -}; - -// print source location -template -class source_location_formatter final : public flag_formatter { -public: - explicit source_location_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - - size_t text_size; - if (padinfo_.enabled()) { - // calc text size for padding based on "filename:line" - text_size = std::char_traits::length(msg.source.filename) + - ScopedPadder::count_digits(msg.source.line) + 1; - } else { - text_size = 0; - } - - ScopedPadder p(text_size, padinfo_, dest); - fmt_helper::append_string_view(msg.source.filename, dest); - dest.push_back(':'); - fmt_helper::append_int(msg.source.line, dest); - } -}; - -// print source filename -template -class source_filename_formatter final : public flag_formatter { -public: - explicit source_filename_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - size_t text_size = - padinfo_.enabled() ? std::char_traits::length(msg.source.filename) : 0; - ScopedPadder p(text_size, padinfo_, dest); - fmt_helper::append_string_view(msg.source.filename, dest); - } -}; - -template -class short_filename_formatter final : public flag_formatter { -public: - explicit short_filename_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - -#ifdef _MSC_VER - #pragma warning(push) - #pragma warning(disable : 4127) // consider using 'if constexpr' instead -#endif // _MSC_VER - static const char *basename(const char *filename) { - // if the size is 2 (1 character + null terminator) we can use the more efficient strrchr - // the branch will be elided by optimizations - if (sizeof(os::folder_seps) == 2) { - const char *rv = std::strrchr(filename, os::folder_seps[0]); - return rv != nullptr ? rv + 1 : filename; - } else { - const std::reverse_iterator begin(filename + std::strlen(filename)); - const std::reverse_iterator end(filename); - - const auto it = std::find_first_of(begin, end, std::begin(os::folder_seps), - std::end(os::folder_seps) - 1); - return it != end ? it.base() : filename; - } - } -#ifdef _MSC_VER - #pragma warning(pop) -#endif // _MSC_VER - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - auto filename = basename(msg.source.filename); - size_t text_size = padinfo_.enabled() ? std::char_traits::length(filename) : 0; - ScopedPadder p(text_size, padinfo_, dest); - fmt_helper::append_string_view(filename, dest); - } -}; - -template -class source_linenum_formatter final : public flag_formatter { -public: - explicit source_linenum_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - - auto field_size = ScopedPadder::count_digits(msg.source.line); - ScopedPadder p(field_size, padinfo_, dest); - fmt_helper::append_int(msg.source.line, dest); - } -}; - -// print source funcname -template -class source_funcname_formatter final : public flag_formatter { -public: - explicit source_funcname_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - if (msg.source.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } - size_t text_size = - padinfo_.enabled() ? std::char_traits::length(msg.source.funcname) : 0; - ScopedPadder p(text_size, padinfo_, dest); - fmt_helper::append_string_view(msg.source.funcname, dest); - } -}; - -// print elapsed time since last message -template -class elapsed_formatter final : public flag_formatter { -public: - using DurationUnits = Units; - - explicit elapsed_formatter(padding_info padinfo) - : flag_formatter(padinfo), - last_message_time_(log_clock::now()) {} - - void format(const details::log_msg &msg, const std::tm &, memory_buf_t &dest) override { - auto delta = (std::max)(msg.time - last_message_time_, log_clock::duration::zero()); - auto delta_units = std::chrono::duration_cast(delta); - last_message_time_ = msg.time; - auto delta_count = static_cast(delta_units.count()); - auto n_digits = static_cast(ScopedPadder::count_digits(delta_count)); - ScopedPadder p(n_digits, padinfo_, dest); - fmt_helper::append_int(delta_count, dest); - } - -private: - log_clock::time_point last_message_time_; -}; - -// Class for formatting Mapped Diagnostic Context (MDC) in log messages. -// Example: [logger-name] [info] [mdc_key_1:mdc_value_1 mdc_key_2:mdc_value_2] some message -#ifndef SPDLOG_NO_TLS -template -class mdc_formatter : public flag_formatter { -public: - explicit mdc_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &, const std::tm &, memory_buf_t &dest) override { - auto &mdc_map = mdc::get_context(); - if (mdc_map.empty()) { - ScopedPadder p(0, padinfo_, dest); - return; - } else { - format_mdc(mdc_map, dest); - } - } - - void format_mdc(const mdc::mdc_map_t &mdc_map, memory_buf_t &dest) { - auto last_element = --mdc_map.end(); - for (auto it = mdc_map.begin(); it != mdc_map.end(); ++it) { - auto &pair = *it; - const auto &key = pair.first; - const auto &value = pair.second; - size_t content_size = key.size() + value.size() + 1; // 1 for ':' - - if (it != last_element) { - content_size++; // 1 for ' ' - } - - ScopedPadder p(content_size, padinfo_, dest); - fmt_helper::append_string_view(key, dest); - fmt_helper::append_string_view(":", dest); - fmt_helper::append_string_view(value, dest); - if (it != last_element) { - fmt_helper::append_string_view(" ", dest); - } - } - } -}; -#endif - -// Full info formatter -// pattern: [%Y-%m-%d %H:%M:%S.%e] [%n] [%l] [%s:%#] %v -class full_formatter final : public flag_formatter { -public: - explicit full_formatter(padding_info padinfo) - : flag_formatter(padinfo) {} - - void format(const details::log_msg &msg, const std::tm &tm_time, memory_buf_t &dest) override { - using std::chrono::duration_cast; - using std::chrono::milliseconds; - using std::chrono::seconds; - - // cache the date/time part for the next second. - auto duration = msg.time.time_since_epoch(); - auto secs = duration_cast(duration); - - if (cache_timestamp_ != secs || cached_datetime_.size() == 0) { - cached_datetime_.clear(); - cached_datetime_.push_back('['); - fmt_helper::append_int(tm_time.tm_year + 1900, cached_datetime_); - cached_datetime_.push_back('-'); - - fmt_helper::pad2(tm_time.tm_mon + 1, cached_datetime_); - cached_datetime_.push_back('-'); - - fmt_helper::pad2(tm_time.tm_mday, cached_datetime_); - cached_datetime_.push_back(' '); - - fmt_helper::pad2(tm_time.tm_hour, cached_datetime_); - cached_datetime_.push_back(':'); - - fmt_helper::pad2(tm_time.tm_min, cached_datetime_); - cached_datetime_.push_back(':'); - - fmt_helper::pad2(tm_time.tm_sec, cached_datetime_); - cached_datetime_.push_back('.'); - - cache_timestamp_ = secs; - } - dest.append(cached_datetime_.begin(), cached_datetime_.end()); - - auto millis = fmt_helper::time_fraction(msg.time); - fmt_helper::pad3(static_cast(millis.count()), dest); - dest.push_back(']'); - dest.push_back(' '); - - // append logger name if exists - if (msg.logger_name.size() > 0) { - dest.push_back('['); - fmt_helper::append_string_view(msg.logger_name, dest); - dest.push_back(']'); - dest.push_back(' '); - } - - dest.push_back('['); - // wrap the level name with color - msg.color_range_start = dest.size(); - // fmt_helper::append_string_view(level::to_c_str(msg.level), dest); - fmt_helper::append_string_view(level::to_string_view(msg.level), dest); - msg.color_range_end = dest.size(); - dest.push_back(']'); - dest.push_back(' '); - - // add source location if present - if (!msg.source.empty()) { - dest.push_back('['); - const char *filename = - details::short_filename_formatter::basename( - msg.source.filename); - fmt_helper::append_string_view(filename, dest); - dest.push_back(':'); - fmt_helper::append_int(msg.source.line, dest); - dest.push_back(']'); - dest.push_back(' '); - } - -#ifndef SPDLOG_NO_TLS - // add mdc if present - auto &mdc_map = mdc::get_context(); - if (!mdc_map.empty()) { - dest.push_back('['); - mdc_formatter_.format_mdc(mdc_map, dest); - dest.push_back(']'); - dest.push_back(' '); - } -#endif - // fmt_helper::append_string_view(msg.msg(), dest); - fmt_helper::append_string_view(msg.payload, dest); - } - -private: - std::chrono::seconds cache_timestamp_{0}; - memory_buf_t cached_datetime_; - -#ifndef SPDLOG_NO_TLS - mdc_formatter mdc_formatter_{padding_info {}}; -#endif -}; - -} // namespace details - -SPDLOG_INLINE pattern_formatter::pattern_formatter(std::string pattern, - pattern_time_type time_type, - std::string eol, - custom_flags custom_user_flags) - : pattern_(std::move(pattern)), - eol_(std::move(eol)), - pattern_time_type_(time_type), - need_localtime_(false), - last_log_secs_(0), - custom_handlers_(std::move(custom_user_flags)) { - std::memset(&cached_tm_, 0, sizeof(cached_tm_)); - compile_pattern_(pattern_); -} - -// use by default full formatter for if pattern is not given -SPDLOG_INLINE pattern_formatter::pattern_formatter(pattern_time_type time_type, std::string eol) - : pattern_("%+"), - eol_(std::move(eol)), - pattern_time_type_(time_type), - need_localtime_(true), - last_log_secs_(0) { - std::memset(&cached_tm_, 0, sizeof(cached_tm_)); - formatters_.push_back(details::make_unique(details::padding_info{})); -} - -SPDLOG_INLINE std::unique_ptr pattern_formatter::clone() const { - custom_flags cloned_custom_formatters; - for (auto &it : custom_handlers_) { - cloned_custom_formatters[it.first] = it.second->clone(); - } - auto cloned = details::make_unique(pattern_, pattern_time_type_, eol_, - std::move(cloned_custom_formatters)); - cloned->need_localtime(need_localtime_); -#if defined(__GNUC__) && __GNUC__ < 5 - return std::move(cloned); -#else - return cloned; -#endif -} - -SPDLOG_INLINE void pattern_formatter::format(const details::log_msg &msg, memory_buf_t &dest) { - if (need_localtime_) { - const auto secs = - std::chrono::duration_cast(msg.time.time_since_epoch()); - if (secs != last_log_secs_) { - cached_tm_ = get_time_(msg); - last_log_secs_ = secs; - } - } - - for (auto &f : formatters_) { - f->format(msg, cached_tm_, dest); - } - // write eol - details::fmt_helper::append_string_view(eol_, dest); -} - -SPDLOG_INLINE void pattern_formatter::set_pattern(std::string pattern) { - pattern_ = std::move(pattern); - need_localtime_ = false; - compile_pattern_(pattern_); -} - -SPDLOG_INLINE void pattern_formatter::need_localtime(bool need) { need_localtime_ = need; } - -SPDLOG_INLINE std::tm pattern_formatter::get_time_(const details::log_msg &msg) { - if (pattern_time_type_ == pattern_time_type::local) { - return details::os::localtime(log_clock::to_time_t(msg.time)); - } - return details::os::gmtime(log_clock::to_time_t(msg.time)); -} - -template -SPDLOG_INLINE void pattern_formatter::handle_flag_(char flag, details::padding_info padding) { - // process custom flags - auto it = custom_handlers_.find(flag); - if (it != custom_handlers_.end()) { - auto custom_handler = it->second->clone(); - custom_handler->set_padding_info(padding); - formatters_.push_back(std::move(custom_handler)); - return; - } - - // process built-in flags - switch (flag) { - case ('+'): // default formatter - formatters_.push_back(details::make_unique(padding)); - need_localtime_ = true; - break; - - case 'n': // logger name - formatters_.push_back(details::make_unique>(padding)); - break; - - case 'l': // level - formatters_.push_back(details::make_unique>(padding)); - break; - - case 'L': // short level - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('t'): // thread id - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('v'): // the message text - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('a'): // weekday - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('A'): // short weekday - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('b'): - case ('h'): // month - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('B'): // short month - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('c'): // datetime - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('C'): // year 2 digits - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('Y'): // year 4 digits - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('D'): - case ('x'): // datetime MM/DD/YY - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('m'): // month 1-12 - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('d'): // day of month 1-31 - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('H'): // hours 24 - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('I'): // hours 12 - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('M'): // minutes - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('S'): // seconds - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('e'): // milliseconds - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('f'): // microseconds - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('F'): // nanoseconds - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('E'): // seconds since epoch - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('p'): // am/pm - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('r'): // 12 hour clock 02:55:02 pm - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('R'): // 24-hour HH:MM time - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('T'): - case ('X'): // ISO 8601 time format (HH:MM:SS) - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('z'): // timezone - formatters_.push_back(details::make_unique>(padding)); - need_localtime_ = true; - break; - - case ('P'): // pid - formatters_.push_back(details::make_unique>(padding)); - break; - - case ('^'): // color range start - formatters_.push_back(details::make_unique(padding)); - break; - - case ('$'): // color range end - formatters_.push_back(details::make_unique(padding)); - break; - - case ('@'): // source location (filename:filenumber) - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('s'): // short source filename - without directory name - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('g'): // full source filename - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('#'): // source line number - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('!'): // source funcname - formatters_.push_back( - details::make_unique>(padding)); - break; - - case ('%'): // % char - formatters_.push_back(details::make_unique('%')); - break; - - case ('u'): // elapsed time since last log message in nanos - formatters_.push_back( - details::make_unique>( - padding)); - break; - - case ('i'): // elapsed time since last log message in micros - formatters_.push_back( - details::make_unique>( - padding)); - break; - - case ('o'): // elapsed time since last log message in millis - formatters_.push_back( - details::make_unique>( - padding)); - break; - - case ('O'): // elapsed time since last log message in seconds - formatters_.push_back( - details::make_unique>( - padding)); - break; - -#ifndef SPDLOG_NO_TLS // mdc formatter requires TLS support - case ('&'): - formatters_.push_back(details::make_unique>(padding)); - break; -#endif - - default: // Unknown flag appears as is - auto unknown_flag = details::make_unique(); - - if (!padding.truncate_) { - unknown_flag->add_ch('%'); - unknown_flag->add_ch(flag); - formatters_.push_back((std::move(unknown_flag))); - } - // fix issue #1617 (prev char was '!' and should have been treated as funcname flag - // instead of truncating flag) spdlog::set_pattern("[%10!] %v") => "[ main] some - // message" spdlog::set_pattern("[%3!!] %v") => "[mai] some message" - else { - padding.truncate_ = false; - formatters_.push_back( - details::make_unique>(padding)); - unknown_flag->add_ch(flag); - formatters_.push_back((std::move(unknown_flag))); - } - - break; - } -} - -// Extract given pad spec (e.g. %8X, %=8X, %-8!X, %8!X, %=8!X, %-8!X, %+8!X) -// Advance the given it pass the end of the padding spec found (if any) -// Return padding. -SPDLOG_INLINE details::padding_info pattern_formatter::handle_padspec_( - std::string::const_iterator &it, std::string::const_iterator end) { - using details::padding_info; - using details::scoped_padder; - const size_t max_width = 64; - if (it == end) { - return padding_info{}; - } - - padding_info::pad_side side; - switch (*it) { - case '-': - side = padding_info::pad_side::right; - ++it; - break; - case '=': - side = padding_info::pad_side::center; - ++it; - break; - default: - side = details::padding_info::pad_side::left; - break; - } - - if (it == end || !std::isdigit(static_cast(*it))) { - return padding_info{}; // no padding if no digit found here - } - - auto width = static_cast(*it) - '0'; - for (++it; it != end && std::isdigit(static_cast(*it)); ++it) { - auto digit = static_cast(*it) - '0'; - width = width * 10 + digit; - } - - // search for the optional truncate marker '!' - bool truncate; - if (it != end && *it == '!') { - truncate = true; - ++it; - } else { - truncate = false; - } - return details::padding_info{std::min(width, max_width), side, truncate}; -} - -SPDLOG_INLINE void pattern_formatter::compile_pattern_(const std::string &pattern) { - auto end = pattern.end(); - std::unique_ptr user_chars; - formatters_.clear(); - for (auto it = pattern.begin(); it != end; ++it) { - if (*it == '%') { - if (user_chars) // append user chars found so far - { - formatters_.push_back(std::move(user_chars)); - } - - auto padding = handle_padspec_(++it, end); - - if (it != end) { - if (padding.enabled()) { - handle_flag_(*it, padding); - } else { - handle_flag_(*it, padding); - } - } else { - break; - } - } else // chars not following the % sign should be displayed as is - { - if (!user_chars) { - user_chars = details::make_unique(); - } - user_chars->add_ch(*it); - } - } - if (user_chars) // append raw chars found so far - { - formatters_.push_back(std::move(user_chars)); - } -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/pattern_formatter.h b/examples/blueprints-example/external/spdlog/pattern_formatter.h deleted file mode 100644 index ececd67..0000000 --- a/examples/blueprints-example/external/spdlog/pattern_formatter.h +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include - -namespace spdlog { -namespace details { - -// padding information. -struct padding_info { - enum class pad_side { left, right, center }; - - padding_info() = default; - padding_info(size_t width, padding_info::pad_side side, bool truncate) - : width_(width), - side_(side), - truncate_(truncate), - enabled_(true) {} - - bool enabled() const { return enabled_; } - size_t width_ = 0; - pad_side side_ = pad_side::left; - bool truncate_ = false; - bool enabled_ = false; -}; - -class SPDLOG_API flag_formatter { -public: - explicit flag_formatter(padding_info padinfo) - : padinfo_(padinfo) {} - flag_formatter() = default; - virtual ~flag_formatter() = default; - virtual void format(const details::log_msg &msg, - const std::tm &tm_time, - memory_buf_t &dest) = 0; - -protected: - padding_info padinfo_; -}; - -} // namespace details - -class SPDLOG_API custom_flag_formatter : public details::flag_formatter { -public: - virtual std::unique_ptr clone() const = 0; - - void set_padding_info(const details::padding_info &padding) { - flag_formatter::padinfo_ = padding; - } -}; - -class SPDLOG_API pattern_formatter final : public formatter { -public: - using custom_flags = std::unordered_map>; - - explicit pattern_formatter(std::string pattern, - pattern_time_type time_type = pattern_time_type::local, - std::string eol = spdlog::details::os::default_eol, - custom_flags custom_user_flags = custom_flags()); - - // use default pattern is not given - explicit pattern_formatter(pattern_time_type time_type = pattern_time_type::local, - std::string eol = spdlog::details::os::default_eol); - - pattern_formatter(const pattern_formatter &other) = delete; - pattern_formatter &operator=(const pattern_formatter &other) = delete; - - std::unique_ptr clone() const override; - void format(const details::log_msg &msg, memory_buf_t &dest) override; - - template - pattern_formatter &add_flag(char flag, Args &&...args) { - custom_handlers_[flag] = details::make_unique(std::forward(args)...); - return *this; - } - void set_pattern(std::string pattern); - void need_localtime(bool need = true); - -private: - std::string pattern_; - std::string eol_; - pattern_time_type pattern_time_type_; - bool need_localtime_; - std::tm cached_tm_; - std::chrono::seconds last_log_secs_; - std::vector> formatters_; - custom_flags custom_handlers_; - - std::tm get_time_(const details::log_msg &msg); - template - void handle_flag_(char flag, details::padding_info padding); - - // Extract given pad spec (e.g. %8X) - // Advance the given it pass the end of the padding spec found (if any) - // Return padding. - static details::padding_info handle_padspec_(std::string::const_iterator &it, - std::string::const_iterator end); - - void compile_pattern_(const std::string &pattern); -}; -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "pattern_formatter-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/android_sink.h b/examples/blueprints-example/external/spdlog/sinks/android_sink.h deleted file mode 100644 index 4435a56..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/android_sink.h +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifdef __ANDROID__ - - #include - #include - #include - #include - #include - - #include - #include - #include - #include - #include - #include - - #if !defined(SPDLOG_ANDROID_RETRIES) - #define SPDLOG_ANDROID_RETRIES 2 - #endif - -namespace spdlog { -namespace sinks { - -/* - * Android sink - * (logging using __android_log_write or __android_log_buf_write depending on the specified - * BufferID) - */ -template -class android_sink final : public base_sink { -public: - explicit android_sink(std::string tag = "spdlog", bool use_raw_msg = false) - : tag_(std::move(tag)), - use_raw_msg_(use_raw_msg) {} - -protected: - void sink_it_(const details::log_msg &msg) override { - const android_LogPriority priority = convert_to_android_(msg.level); - memory_buf_t formatted; - if (use_raw_msg_) { - details::fmt_helper::append_string_view(msg.payload, formatted); - } else { - base_sink::formatter_->format(msg, formatted); - } - formatted.push_back('\0'); - const char *msg_output = formatted.data(); - - // See system/core/liblog/logger_write.c for explanation of return value - int ret = android_log(priority, tag_.c_str(), msg_output); - if (ret == -EPERM) { - return; // !__android_log_is_loggable - } - int retry_count = 0; - while ((ret == -11 /*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES)) { - details::os::sleep_for_millis(5); - ret = android_log(priority, tag_.c_str(), msg_output); - retry_count++; - } - - if (ret < 0) { - throw_spdlog_ex("logging to Android failed", ret); - } - } - - void flush_() override {} - -private: - // There might be liblog versions used, that do not support __android_log_buf_write. So we only - // compile and link against - // __android_log_buf_write, if user explicitly provides a non-default log buffer. Otherwise, - // when using the default log buffer, always log via __android_log_write. - template - typename std::enable_if(log_id::LOG_ID_MAIN), int>::type android_log( - int prio, const char *tag, const char *text) { - return __android_log_write(prio, tag, text); - } - - template - typename std::enable_if(log_id::LOG_ID_MAIN), int>::type android_log( - int prio, const char *tag, const char *text) { - return __android_log_buf_write(ID, prio, tag, text); - } - - static android_LogPriority convert_to_android_(spdlog::level::level_enum level) { - switch (level) { - case spdlog::level::trace: - return ANDROID_LOG_VERBOSE; - case spdlog::level::debug: - return ANDROID_LOG_DEBUG; - case spdlog::level::info: - return ANDROID_LOG_INFO; - case spdlog::level::warn: - return ANDROID_LOG_WARN; - case spdlog::level::err: - return ANDROID_LOG_ERROR; - case spdlog::level::critical: - return ANDROID_LOG_FATAL; - default: - return ANDROID_LOG_DEFAULT; - } - } - - std::string tag_; - bool use_raw_msg_; -}; - -using android_sink_mt = android_sink; -using android_sink_st = android_sink; - -template -using android_sink_buf_mt = android_sink; -template -using android_sink_buf_st = android_sink; - -} // namespace sinks - -// Create and register android syslog logger - -template -inline std::shared_ptr android_logger_mt(const std::string &logger_name, - const std::string &tag = "spdlog") { - return Factory::template create(logger_name, tag); -} - -template -inline std::shared_ptr android_logger_st(const std::string &logger_name, - const std::string &tag = "spdlog") { - return Factory::template create(logger_name, tag); -} - -} // namespace spdlog - -#endif // __ANDROID__ diff --git a/examples/blueprints-example/external/spdlog/sinks/ansicolor_sink-inl.h b/examples/blueprints-example/external/spdlog/sinks/ansicolor_sink-inl.h deleted file mode 100644 index 6a23f6c..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/ansicolor_sink-inl.h +++ /dev/null @@ -1,142 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { -namespace sinks { - -template -SPDLOG_INLINE ansicolor_sink::ansicolor_sink(FILE *target_file, color_mode mode) - : target_file_(target_file), - mutex_(ConsoleMutex::mutex()), - formatter_(details::make_unique()) - -{ - set_color_mode_(mode); - colors_.at(level::trace) = to_string_(white); - colors_.at(level::debug) = to_string_(cyan); - colors_.at(level::info) = to_string_(green); - colors_.at(level::warn) = to_string_(yellow_bold); - colors_.at(level::err) = to_string_(red_bold); - colors_.at(level::critical) = to_string_(bold_on_red); - colors_.at(level::off) = to_string_(reset); -} - -template -SPDLOG_INLINE void ansicolor_sink::set_color(level::level_enum color_level, - string_view_t color) { - std::lock_guard lock(mutex_); - colors_.at(static_cast(color_level)) = to_string_(color); -} - -template -SPDLOG_INLINE void ansicolor_sink::log(const details::log_msg &msg) { - // Wrap the originally formatted message in color codes. - // If color is not supported in the terminal, log as is instead. - std::lock_guard lock(mutex_); - msg.color_range_start = 0; - msg.color_range_end = 0; - memory_buf_t formatted; - formatter_->format(msg, formatted); - if (should_do_colors_ && msg.color_range_end > msg.color_range_start) { - // before color range - print_range_(formatted, 0, msg.color_range_start); - // in color range - print_ccode_(colors_.at(static_cast(msg.level))); - print_range_(formatted, msg.color_range_start, msg.color_range_end); - print_ccode_(reset); - // after color range - print_range_(formatted, msg.color_range_end, formatted.size()); - } else // no color - { - print_range_(formatted, 0, formatted.size()); - } - fflush(target_file_); -} - -template -SPDLOG_INLINE void ansicolor_sink::flush() { - std::lock_guard lock(mutex_); - fflush(target_file_); -} - -template -SPDLOG_INLINE void ansicolor_sink::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); -} - -template -SPDLOG_INLINE void ansicolor_sink::set_formatter( - std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); -} - -template -SPDLOG_INLINE bool ansicolor_sink::should_color() const { - return should_do_colors_; -} - -template -SPDLOG_INLINE void ansicolor_sink::set_color_mode(color_mode mode) { - std::lock_guard lock(mutex_); - set_color_mode_(mode); -} - -template -SPDLOG_INLINE void ansicolor_sink::set_color_mode_(color_mode mode) { - switch (mode) { - case color_mode::always: - should_do_colors_ = true; - return; - case color_mode::automatic: - should_do_colors_ = - details::os::in_terminal(target_file_) && details::os::is_color_terminal(); - return; - case color_mode::never: - should_do_colors_ = false; - return; - default: - should_do_colors_ = false; - } -} - -template -SPDLOG_INLINE void ansicolor_sink::print_ccode_( - const string_view_t &color_code) const { - details::os::fwrite_bytes(color_code.data(), color_code.size(), target_file_); -} - -template -SPDLOG_INLINE void ansicolor_sink::print_range_(const memory_buf_t &formatted, - size_t start, - size_t end) const { - details::os::fwrite_bytes(formatted.data() + start, end - start, target_file_); -} - -template -SPDLOG_INLINE std::string ansicolor_sink::to_string_(const string_view_t &sv) { - return std::string(sv.data(), sv.size()); -} - -// ansicolor_stdout_sink -template -SPDLOG_INLINE ansicolor_stdout_sink::ansicolor_stdout_sink(color_mode mode) - : ansicolor_sink(stdout, mode) {} - -// ansicolor_stderr_sink -template -SPDLOG_INLINE ansicolor_stderr_sink::ansicolor_stderr_sink(color_mode mode) - : ansicolor_sink(stderr, mode) {} - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/ansicolor_sink.h b/examples/blueprints-example/external/spdlog/sinks/ansicolor_sink.h deleted file mode 100644 index 47cea91..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/ansicolor_sink.h +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { - -/** - * This sink prefixes the output with an ANSI escape sequence color code - * depending on the severity - * of the message. - * If no color terminal detected, omit the escape codes. - */ - -template -class ansicolor_sink : public sink { -public: - using mutex_t = typename ConsoleMutex::mutex_t; - ansicolor_sink(FILE *target_file, color_mode mode); - ~ansicolor_sink() override = default; - - ansicolor_sink(const ansicolor_sink &other) = delete; - ansicolor_sink(ansicolor_sink &&other) = delete; - - ansicolor_sink &operator=(const ansicolor_sink &other) = delete; - ansicolor_sink &operator=(ansicolor_sink &&other) = delete; - - void set_color(level::level_enum color_level, string_view_t color); - void set_color_mode(color_mode mode); - bool should_color() const; - - void log(const details::log_msg &msg) override; - void flush() override; - void set_pattern(const std::string &pattern) override; - void set_formatter(std::unique_ptr sink_formatter) override; - - // Formatting codes - const string_view_t reset = "\033[m"; - const string_view_t bold = "\033[1m"; - const string_view_t dark = "\033[2m"; - const string_view_t underline = "\033[4m"; - const string_view_t blink = "\033[5m"; - const string_view_t reverse = "\033[7m"; - const string_view_t concealed = "\033[8m"; - const string_view_t clear_line = "\033[K"; - - // Foreground colors - const string_view_t black = "\033[30m"; - const string_view_t red = "\033[31m"; - const string_view_t green = "\033[32m"; - const string_view_t yellow = "\033[33m"; - const string_view_t blue = "\033[34m"; - const string_view_t magenta = "\033[35m"; - const string_view_t cyan = "\033[36m"; - const string_view_t white = "\033[37m"; - - /// Background colors - const string_view_t on_black = "\033[40m"; - const string_view_t on_red = "\033[41m"; - const string_view_t on_green = "\033[42m"; - const string_view_t on_yellow = "\033[43m"; - const string_view_t on_blue = "\033[44m"; - const string_view_t on_magenta = "\033[45m"; - const string_view_t on_cyan = "\033[46m"; - const string_view_t on_white = "\033[47m"; - - /// Bold colors - const string_view_t yellow_bold = "\033[33m\033[1m"; - const string_view_t red_bold = "\033[31m\033[1m"; - const string_view_t bold_on_red = "\033[1m\033[41m"; - -private: - FILE *target_file_; - mutex_t &mutex_; - bool should_do_colors_; - std::unique_ptr formatter_; - std::array colors_; - void set_color_mode_(color_mode mode); - void print_ccode_(const string_view_t &color_code) const; - void print_range_(const memory_buf_t &formatted, size_t start, size_t end) const; - static std::string to_string_(const string_view_t &sv); -}; - -template -class ansicolor_stdout_sink : public ansicolor_sink { -public: - explicit ansicolor_stdout_sink(color_mode mode = color_mode::automatic); -}; - -template -class ansicolor_stderr_sink : public ansicolor_sink { -public: - explicit ansicolor_stderr_sink(color_mode mode = color_mode::automatic); -}; - -using ansicolor_stdout_sink_mt = ansicolor_stdout_sink; -using ansicolor_stdout_sink_st = ansicolor_stdout_sink; - -using ansicolor_stderr_sink_mt = ansicolor_stderr_sink; -using ansicolor_stderr_sink_st = ansicolor_stderr_sink; - -} // namespace sinks -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "ansicolor_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/base_sink-inl.h b/examples/blueprints-example/external/spdlog/sinks/base_sink-inl.h deleted file mode 100644 index ada161b..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/base_sink-inl.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include - -template -SPDLOG_INLINE spdlog::sinks::base_sink::base_sink() - : formatter_{details::make_unique()} {} - -template -SPDLOG_INLINE spdlog::sinks::base_sink::base_sink( - std::unique_ptr formatter) - : formatter_{std::move(formatter)} {} - -template -void SPDLOG_INLINE spdlog::sinks::base_sink::log(const details::log_msg &msg) { - std::lock_guard lock(mutex_); - sink_it_(msg); -} - -template -void SPDLOG_INLINE spdlog::sinks::base_sink::flush() { - std::lock_guard lock(mutex_); - flush_(); -} - -template -void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - set_pattern_(pattern); -} - -template -void SPDLOG_INLINE -spdlog::sinks::base_sink::set_formatter(std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - set_formatter_(std::move(sink_formatter)); -} - -template -void SPDLOG_INLINE spdlog::sinks::base_sink::set_pattern_(const std::string &pattern) { - set_formatter_(details::make_unique(pattern)); -} - -template -void SPDLOG_INLINE -spdlog::sinks::base_sink::set_formatter_(std::unique_ptr sink_formatter) { - formatter_ = std::move(sink_formatter); -} diff --git a/examples/blueprints-example/external/spdlog/sinks/base_sink.h b/examples/blueprints-example/external/spdlog/sinks/base_sink.h deleted file mode 100644 index 1b4bb06..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/base_sink.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once -// -// base sink templated over a mutex (either dummy or real) -// concrete implementation should override the sink_it_() and flush_() methods. -// locking is taken care of in this class - no locking needed by the -// implementers.. -// - -#include -#include -#include - -namespace spdlog { -namespace sinks { -template -class SPDLOG_API base_sink : public sink { -public: - base_sink(); - explicit base_sink(std::unique_ptr formatter); - ~base_sink() override = default; - - base_sink(const base_sink &) = delete; - base_sink(base_sink &&) = delete; - - base_sink &operator=(const base_sink &) = delete; - base_sink &operator=(base_sink &&) = delete; - - void log(const details::log_msg &msg) final override; - void flush() final override; - void set_pattern(const std::string &pattern) final override; - void set_formatter(std::unique_ptr sink_formatter) final override; - -protected: - // sink formatter - std::unique_ptr formatter_; - Mutex mutex_; - - virtual void sink_it_(const details::log_msg &msg) = 0; - virtual void flush_() = 0; - virtual void set_pattern_(const std::string &pattern); - virtual void set_formatter_(std::unique_ptr sink_formatter); -}; -} // namespace sinks -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "base_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/basic_file_sink-inl.h b/examples/blueprints-example/external/spdlog/sinks/basic_file_sink-inl.h deleted file mode 100644 index ce0ddad..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/basic_file_sink-inl.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { -namespace sinks { - -template -SPDLOG_INLINE basic_file_sink::basic_file_sink(const filename_t &filename, - bool truncate, - const file_event_handlers &event_handlers) - : file_helper_{event_handlers} { - file_helper_.open(filename, truncate); -} - -template -SPDLOG_INLINE const filename_t &basic_file_sink::filename() const { - return file_helper_.filename(); -} - -template -SPDLOG_INLINE void basic_file_sink::truncate() { - std::lock_guard lock(base_sink::mutex_); - file_helper_.reopen(true); -} - -template -SPDLOG_INLINE void basic_file_sink::sink_it_(const details::log_msg &msg) { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - file_helper_.write(formatted); -} - -template -SPDLOG_INLINE void basic_file_sink::flush_() { - file_helper_.flush(); -} - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/basic_file_sink.h b/examples/blueprints-example/external/spdlog/sinks/basic_file_sink.h deleted file mode 100644 index 48c0767..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/basic_file_sink.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace spdlog { -namespace sinks { -/* - * Trivial file sink with single file as target - */ -template -class basic_file_sink final : public base_sink { -public: - explicit basic_file_sink(const filename_t &filename, - bool truncate = false, - const file_event_handlers &event_handlers = {}); - const filename_t &filename() const; - void truncate(); - -protected: - void sink_it_(const details::log_msg &msg) override; - void flush_() override; - -private: - details::file_helper file_helper_; -}; - -using basic_file_sink_mt = basic_file_sink; -using basic_file_sink_st = basic_file_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr basic_logger_mt(const std::string &logger_name, - const filename_t &filename, - bool truncate = false, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, - event_handlers); -} - -template -inline std::shared_ptr basic_logger_st(const std::string &logger_name, - const filename_t &filename, - bool truncate = false, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, - event_handlers); -} - -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "basic_file_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/callback_sink.h b/examples/blueprints-example/external/spdlog/sinks/callback_sink.h deleted file mode 100644 index 8f0c8d4..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/callback_sink.h +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include - -#include -#include - -namespace spdlog { - -// callbacks type -typedef std::function custom_log_callback; - -namespace sinks { -/* - * Trivial callback sink, gets a callback function and calls it on each log - */ -template -class callback_sink final : public base_sink { -public: - explicit callback_sink(const custom_log_callback &callback) - : callback_{callback} {} - -protected: - void sink_it_(const details::log_msg &msg) override { callback_(msg); } - void flush_() override {} - -private: - custom_log_callback callback_; -}; - -using callback_sink_mt = callback_sink; -using callback_sink_st = callback_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr callback_logger_mt(const std::string &logger_name, - const custom_log_callback &callback) { - return Factory::template create(logger_name, callback); -} - -template -inline std::shared_ptr callback_logger_st(const std::string &logger_name, - const custom_log_callback &callback) { - return Factory::template create(logger_name, callback); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/daily_file_sink.h b/examples/blueprints-example/external/spdlog/sinks/daily_file_sink.h deleted file mode 100644 index 615c9f7..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/daily_file_sink.h +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { - -/* - * Generator of daily log file names in format basename.YYYY-MM-DD.ext - */ -struct daily_filename_calculator { - // Create filename for the form basename.YYYY-MM-DD - static filename_t calc_filename(const filename_t &filename, const tm &now_tm) { - filename_t basename, ext; - std::tie(basename, ext) = details::file_helper::split_by_extension(filename); - return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}{}")), - basename, now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, - ext); - } -}; - -/* - * Generator of daily log file names with strftime format. - * Usages: - * auto sink = - * std::make_shared("myapp-%Y-%m-%d:%H:%M:%S.log", hour, - * minute);" auto logger = spdlog::daily_logger_format_mt("loggername, "myapp-%Y-%m-%d:%X.log", - * hour, minute)" - * - */ -struct daily_filename_format_calculator { - static filename_t calc_filename(const filename_t &file_path, const tm &now_tm) { -#if defined(_WIN32) && defined(SPDLOG_WCHAR_FILENAMES) - std::wstringstream stream; -#else - std::stringstream stream; -#endif - stream << std::put_time(&now_tm, file_path.c_str()); - return stream.str(); - } -}; - -/* - * Rotating file sink based on date. - * If truncate != false , the created file will be truncated. - * If max_files > 0, retain only the last max_files and delete previous. - * Note that old log files from previous executions will not be deleted by this class, - * rotation and deletion is only applied while the program is running. - */ -template -class daily_file_sink final : public base_sink { -public: - // create daily file sink which rotates on given time - daily_file_sink(filename_t base_filename, - int rotation_hour, - int rotation_minute, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) - : base_filename_(std::move(base_filename)), - rotation_h_(rotation_hour), - rotation_m_(rotation_minute), - file_helper_{event_handlers}, - truncate_(truncate), - max_files_(max_files), - filenames_q_() { - if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || - rotation_minute > 59) { - throw_spdlog_ex("daily_file_sink: Invalid rotation time in ctor"); - } - - auto now = log_clock::now(); - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now)); - file_helper_.open(filename, truncate_); - rotation_tp_ = next_rotation_tp_(); - - if (max_files_ > 0) { - init_filenames_q_(); - } - } - - filename_t filename() { - std::lock_guard lock(base_sink::mutex_); - return file_helper_.filename(); - } - -protected: - void sink_it_(const details::log_msg &msg) override { - auto time = msg.time; - bool should_rotate = time >= rotation_tp_; - if (should_rotate) { - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(time)); - file_helper_.open(filename, truncate_); - rotation_tp_ = next_rotation_tp_(); - } - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - file_helper_.write(formatted); - - // Do the cleaning only at the end because it might throw on failure. - if (should_rotate && max_files_ > 0) { - delete_old_(); - } - } - - void flush_() override { file_helper_.flush(); } - -private: - void init_filenames_q_() { - using details::os::path_exists; - - filenames_q_ = details::circular_q(static_cast(max_files_)); - std::vector filenames; - auto now = log_clock::now(); - while (filenames.size() < max_files_) { - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now)); - if (!path_exists(filename)) { - break; - } - filenames.emplace_back(filename); - now -= std::chrono::hours(24); - } - for (auto iter = filenames.rbegin(); iter != filenames.rend(); ++iter) { - filenames_q_.push_back(std::move(*iter)); - } - } - - tm now_tm(log_clock::time_point tp) { - time_t tnow = log_clock::to_time_t(tp); - return spdlog::details::os::localtime(tnow); - } - - log_clock::time_point next_rotation_tp_() { - auto now = log_clock::now(); - tm date = now_tm(now); - date.tm_hour = rotation_h_; - date.tm_min = rotation_m_; - date.tm_sec = 0; - auto rotation_time = log_clock::from_time_t(std::mktime(&date)); - if (rotation_time > now) { - return rotation_time; - } - return {rotation_time + std::chrono::hours(24)}; - } - - // Delete the file N rotations ago. - // Throw spdlog_ex on failure to delete the old file. - void delete_old_() { - using details::os::filename_to_str; - using details::os::remove_if_exists; - - filename_t current_file = file_helper_.filename(); - if (filenames_q_.full()) { - auto old_filename = std::move(filenames_q_.front()); - filenames_q_.pop_front(); - bool ok = remove_if_exists(old_filename) == 0; - if (!ok) { - filenames_q_.push_back(std::move(current_file)); - throw_spdlog_ex("Failed removing daily file " + filename_to_str(old_filename), - errno); - } - } - filenames_q_.push_back(std::move(current_file)); - } - - filename_t base_filename_; - int rotation_h_; - int rotation_m_; - log_clock::time_point rotation_tp_; - details::file_helper file_helper_; - bool truncate_; - uint16_t max_files_; - details::circular_q filenames_q_; -}; - -using daily_file_sink_mt = daily_file_sink; -using daily_file_sink_st = daily_file_sink; -using daily_file_format_sink_mt = daily_file_sink; -using daily_file_format_sink_st = - daily_file_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr daily_logger_mt(const std::string &logger_name, - const filename_t &filename, - int hour = 0, - int minute = 0, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, hour, minute, - truncate, max_files, event_handlers); -} - -template -inline std::shared_ptr daily_logger_format_mt( - const std::string &logger_name, - const filename_t &filename, - int hour = 0, - int minute = 0, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create( - logger_name, filename, hour, minute, truncate, max_files, event_handlers); -} - -template -inline std::shared_ptr daily_logger_st(const std::string &logger_name, - const filename_t &filename, - int hour = 0, - int minute = 0, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, hour, minute, - truncate, max_files, event_handlers); -} - -template -inline std::shared_ptr daily_logger_format_st( - const std::string &logger_name, - const filename_t &filename, - int hour = 0, - int minute = 0, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create( - logger_name, filename, hour, minute, truncate, max_files, event_handlers); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/dist_sink.h b/examples/blueprints-example/external/spdlog/sinks/dist_sink.h deleted file mode 100644 index 69c4971..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/dist_sink.h +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include "base_sink.h" -#include -#include -#include - -#include -#include -#include -#include - -// Distribution sink (mux). Stores a vector of sinks which get called when log -// is called - -namespace spdlog { -namespace sinks { - -template -class dist_sink : public base_sink { -public: - dist_sink() = default; - explicit dist_sink(std::vector> sinks) - : sinks_(sinks) {} - - dist_sink(const dist_sink &) = delete; - dist_sink &operator=(const dist_sink &) = delete; - - void add_sink(std::shared_ptr sub_sink) { - std::lock_guard lock(base_sink::mutex_); - sinks_.push_back(sub_sink); - } - - void remove_sink(std::shared_ptr sub_sink) { - std::lock_guard lock(base_sink::mutex_); - sinks_.erase(std::remove(sinks_.begin(), sinks_.end(), sub_sink), sinks_.end()); - } - - void set_sinks(std::vector> sinks) { - std::lock_guard lock(base_sink::mutex_); - sinks_ = std::move(sinks); - } - - std::vector> &sinks() { return sinks_; } - -protected: - void sink_it_(const details::log_msg &msg) override { - for (auto &sub_sink : sinks_) { - if (sub_sink->should_log(msg.level)) { - sub_sink->log(msg); - } - } - } - - void flush_() override { - for (auto &sub_sink : sinks_) { - sub_sink->flush(); - } - } - - void set_pattern_(const std::string &pattern) override { - set_formatter_(details::make_unique(pattern)); - } - - void set_formatter_(std::unique_ptr sink_formatter) override { - base_sink::formatter_ = std::move(sink_formatter); - for (auto &sub_sink : sinks_) { - sub_sink->set_formatter(base_sink::formatter_->clone()); - } - } - std::vector> sinks_; -}; - -using dist_sink_mt = dist_sink; -using dist_sink_st = dist_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/dup_filter_sink.h b/examples/blueprints-example/external/spdlog/sinks/dup_filter_sink.h deleted file mode 100644 index 0588d77..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/dup_filter_sink.h +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include "dist_sink.h" -#include -#include - -#include -#include -#include -#include - -// Duplicate message removal sink. -// Skip the message if previous one is identical and less than "max_skip_duration" have passed -// -// Example: -// -// #include -// -// int main() { -// auto dup_filter = std::make_shared(std::chrono::seconds(5), -// level::info); dup_filter->add_sink(std::make_shared()); -// spdlog::logger l("logger", dup_filter); -// l.info("Hello"); -// l.info("Hello"); -// l.info("Hello"); -// l.info("Different Hello"); -// } -// -// Will produce: -// [2019-06-25 17:50:56.511] [logger] [info] Hello -// [2019-06-25 17:50:56.512] [logger] [info] Skipped 3 duplicate messages.. -// [2019-06-25 17:50:56.512] [logger] [info] Different Hello - -namespace spdlog { -namespace sinks { -template -class dup_filter_sink : public dist_sink { -public: - template - explicit dup_filter_sink(std::chrono::duration max_skip_duration) - : max_skip_duration_{max_skip_duration} {} - -protected: - std::chrono::microseconds max_skip_duration_; - log_clock::time_point last_msg_time_; - std::string last_msg_payload_; - size_t skip_counter_ = 0; - level::level_enum skipped_msg_log_level_ = spdlog::level::level_enum::off; - - void sink_it_(const details::log_msg &msg) override { - bool filtered = filter_(msg); - if (!filtered) { - skip_counter_ += 1; - skipped_msg_log_level_ = msg.level; - return; - } - - // log the "skipped.." message - if (skip_counter_ > 0) { - char buf[64]; - auto msg_size = ::snprintf(buf, sizeof(buf), "Skipped %u duplicate messages..", - static_cast(skip_counter_)); - if (msg_size > 0 && static_cast(msg_size) < sizeof(buf)) { - details::log_msg skipped_msg{msg.source, msg.logger_name, skipped_msg_log_level_, - string_view_t{buf, static_cast(msg_size)}}; - dist_sink::sink_it_(skipped_msg); - } - } - - // log current message - dist_sink::sink_it_(msg); - last_msg_time_ = msg.time; - skip_counter_ = 0; - last_msg_payload_.assign(msg.payload.data(), msg.payload.data() + msg.payload.size()); - } - - // return whether the log msg should be displayed (true) or skipped (false) - bool filter_(const details::log_msg &msg) { - auto filter_duration = msg.time - last_msg_time_; - return (filter_duration > max_skip_duration_) || (msg.payload != last_msg_payload_); - } -}; - -using dup_filter_sink_mt = dup_filter_sink; -using dup_filter_sink_st = dup_filter_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/hourly_file_sink.h b/examples/blueprints-example/external/spdlog/sinks/hourly_file_sink.h deleted file mode 100644 index 3e61872..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/hourly_file_sink.h +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { - -/* - * Generator of Hourly log file names in format basename.YYYY-MM-DD-HH.ext - */ -struct hourly_filename_calculator { - // Create filename for the form basename.YYYY-MM-DD-H - static filename_t calc_filename(const filename_t &filename, const tm &now_tm) { - filename_t basename, ext; - std::tie(basename, ext) = details::file_helper::split_by_extension(filename); - return fmt_lib::format(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}_{:02d}{}"), basename, - now_tm.tm_year + 1900, now_tm.tm_mon + 1, now_tm.tm_mday, - now_tm.tm_hour, ext); - } -}; - -/* - * Rotating file sink based on time. - * If truncate != false , the created file will be truncated. - * If max_files > 0, retain only the last max_files and delete previous. - * Note that old log files from previous executions will not be deleted by this class, - * rotation and deletion is only applied while the program is running. - */ -template -class hourly_file_sink final : public base_sink { -public: - // create hourly file sink which rotates on given time - hourly_file_sink(filename_t base_filename, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) - : base_filename_(std::move(base_filename)), - file_helper_{event_handlers}, - truncate_(truncate), - max_files_(max_files), - filenames_q_() { - auto now = log_clock::now(); - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now)); - file_helper_.open(filename, truncate_); - remove_init_file_ = file_helper_.size() == 0; - rotation_tp_ = next_rotation_tp_(); - - if (max_files_ > 0) { - init_filenames_q_(); - } - } - - filename_t filename() { - std::lock_guard lock(base_sink::mutex_); - return file_helper_.filename(); - } - -protected: - void sink_it_(const details::log_msg &msg) override { - auto time = msg.time; - bool should_rotate = time >= rotation_tp_; - if (should_rotate) { - if (remove_init_file_) { - file_helper_.close(); - details::os::remove(file_helper_.filename()); - } - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(time)); - file_helper_.open(filename, truncate_); - rotation_tp_ = next_rotation_tp_(); - } - remove_init_file_ = false; - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - file_helper_.write(formatted); - - // Do the cleaning only at the end because it might throw on failure. - if (should_rotate && max_files_ > 0) { - delete_old_(); - } - } - - void flush_() override { file_helper_.flush(); } - -private: - void init_filenames_q_() { - using details::os::path_exists; - - filenames_q_ = details::circular_q(static_cast(max_files_)); - std::vector filenames; - auto now = log_clock::now(); - while (filenames.size() < max_files_) { - auto filename = FileNameCalc::calc_filename(base_filename_, now_tm(now)); - if (!path_exists(filename)) { - break; - } - filenames.emplace_back(filename); - now -= std::chrono::hours(1); - } - for (auto iter = filenames.rbegin(); iter != filenames.rend(); ++iter) { - filenames_q_.push_back(std::move(*iter)); - } - } - - tm now_tm(log_clock::time_point tp) { - time_t tnow = log_clock::to_time_t(tp); - return spdlog::details::os::localtime(tnow); - } - - log_clock::time_point next_rotation_tp_() { - auto now = log_clock::now(); - tm date = now_tm(now); - date.tm_min = 0; - date.tm_sec = 0; - auto rotation_time = log_clock::from_time_t(std::mktime(&date)); - if (rotation_time > now) { - return rotation_time; - } - return {rotation_time + std::chrono::hours(1)}; - } - - // Delete the file N rotations ago. - // Throw spdlog_ex on failure to delete the old file. - void delete_old_() { - using details::os::filename_to_str; - using details::os::remove_if_exists; - - filename_t current_file = file_helper_.filename(); - if (filenames_q_.full()) { - auto old_filename = std::move(filenames_q_.front()); - filenames_q_.pop_front(); - bool ok = remove_if_exists(old_filename) == 0; - if (!ok) { - filenames_q_.push_back(std::move(current_file)); - SPDLOG_THROW(spdlog_ex( - "Failed removing hourly file " + filename_to_str(old_filename), errno)); - } - } - filenames_q_.push_back(std::move(current_file)); - } - - filename_t base_filename_; - log_clock::time_point rotation_tp_; - details::file_helper file_helper_; - bool truncate_; - uint16_t max_files_; - details::circular_q filenames_q_; - bool remove_init_file_; -}; - -using hourly_file_sink_mt = hourly_file_sink; -using hourly_file_sink_st = hourly_file_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr hourly_logger_mt(const std::string &logger_name, - const filename_t &filename, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, - max_files, event_handlers); -} - -template -inline std::shared_ptr hourly_logger_st(const std::string &logger_name, - const filename_t &filename, - bool truncate = false, - uint16_t max_files = 0, - const file_event_handlers &event_handlers = {}) { - return Factory::template create(logger_name, filename, truncate, - max_files, event_handlers); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/kafka_sink.h b/examples/blueprints-example/external/spdlog/sinks/kafka_sink.h deleted file mode 100644 index 91e9878..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/kafka_sink.h +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// -// Custom sink for kafka -// Building and using requires librdkafka library. -// For building librdkafka library check the url below -// https://github.com/confluentinc/librdkafka -// - -#include "spdlog/async.h" -#include "spdlog/details/log_msg.h" -#include "spdlog/details/null_mutex.h" -#include "spdlog/details/synchronous_factory.h" -#include "spdlog/sinks/base_sink.h" -#include -#include - -// kafka header -#include - -namespace spdlog { -namespace sinks { - -struct kafka_sink_config { - std::string server_addr; - std::string produce_topic; - int32_t flush_timeout_ms = 1000; - - kafka_sink_config(std::string addr, std::string topic, int flush_timeout_ms = 1000) - : server_addr{std::move(addr)}, - produce_topic{std::move(topic)}, - flush_timeout_ms(flush_timeout_ms) {} -}; - -template -class kafka_sink : public base_sink { -public: - kafka_sink(kafka_sink_config config) - : config_{std::move(config)} { - try { - std::string errstr; - conf_.reset(RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL)); - RdKafka::Conf::ConfResult confRes = - conf_->set("bootstrap.servers", config_.server_addr, errstr); - if (confRes != RdKafka::Conf::CONF_OK) { - throw_spdlog_ex( - fmt_lib::format("conf set bootstrap.servers failed err:{}", errstr)); - } - - tconf_.reset(RdKafka::Conf::create(RdKafka::Conf::CONF_TOPIC)); - if (tconf_ == nullptr) { - throw_spdlog_ex(fmt_lib::format("create topic config failed")); - } - - producer_.reset(RdKafka::Producer::create(conf_.get(), errstr)); - if (producer_ == nullptr) { - throw_spdlog_ex(fmt_lib::format("create producer failed err:{}", errstr)); - } - topic_.reset(RdKafka::Topic::create(producer_.get(), config_.produce_topic, - tconf_.get(), errstr)); - if (topic_ == nullptr) { - throw_spdlog_ex(fmt_lib::format("create topic failed err:{}", errstr)); - } - } catch (const std::exception &e) { - throw_spdlog_ex(fmt_lib::format("error create kafka instance: {}", e.what())); - } - } - - ~kafka_sink() { producer_->flush(config_.flush_timeout_ms); } - -protected: - void sink_it_(const details::log_msg &msg) override { - producer_->produce(topic_.get(), 0, RdKafka::Producer::RK_MSG_COPY, - (void *)msg.payload.data(), msg.payload.size(), NULL, NULL); - } - - void flush_() override { producer_->flush(config_.flush_timeout_ms); } - -private: - kafka_sink_config config_; - std::unique_ptr producer_ = nullptr; - std::unique_ptr conf_ = nullptr; - std::unique_ptr tconf_ = nullptr; - std::unique_ptr topic_ = nullptr; -}; - -using kafka_sink_mt = kafka_sink; -using kafka_sink_st = kafka_sink; - -} // namespace sinks - -template -inline std::shared_ptr kafka_logger_mt(const std::string &logger_name, - spdlog::sinks::kafka_sink_config config) { - return Factory::template create(logger_name, config); -} - -template -inline std::shared_ptr kafka_logger_st(const std::string &logger_name, - spdlog::sinks::kafka_sink_config config) { - return Factory::template create(logger_name, config); -} - -template -inline std::shared_ptr kafka_logger_async_mt( - std::string logger_name, spdlog::sinks::kafka_sink_config config) { - return Factory::template create(logger_name, config); -} - -template -inline std::shared_ptr kafka_logger_async_st( - std::string logger_name, spdlog::sinks::kafka_sink_config config) { - return Factory::template create(logger_name, config); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/mongo_sink.h b/examples/blueprints-example/external/spdlog/sinks/mongo_sink.h deleted file mode 100644 index c5b38ab..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/mongo_sink.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// -// Custom sink for mongodb -// Building and using requires mongocxx library. -// For building mongocxx library check the url below -// http://mongocxx.org/mongocxx-v3/installation/ -// - -#include "spdlog/common.h" -#include "spdlog/details/log_msg.h" -#include "spdlog/sinks/base_sink.h" -#include - -#include -#include -#include - -#include -#include -#include - -namespace spdlog { -namespace sinks { -template -class mongo_sink : public base_sink { -public: - mongo_sink(const std::string &db_name, - const std::string &collection_name, - const std::string &uri = "mongodb://localhost:27017") try - : mongo_sink(std::make_shared(), db_name, collection_name, uri) { - } catch (const std::exception &e) { - throw_spdlog_ex(fmt_lib::format("Error opening database: {}", e.what())); - } - - mongo_sink(std::shared_ptr instance, - const std::string &db_name, - const std::string &collection_name, - const std::string &uri = "mongodb://localhost:27017") - : instance_(std::move(instance)), - db_name_(db_name), - coll_name_(collection_name) { - try { - client_ = spdlog::details::make_unique(mongocxx::uri{uri}); - } catch (const std::exception &e) { - throw_spdlog_ex(fmt_lib::format("Error opening database: {}", e.what())); - } - } - - ~mongo_sink() { flush_(); } - -protected: - void sink_it_(const details::log_msg &msg) override { - using bsoncxx::builder::stream::document; - using bsoncxx::builder::stream::finalize; - - if (client_ != nullptr) { - auto doc = document{} << "timestamp" << bsoncxx::types::b_date(msg.time) << "level" - << level::to_string_view(msg.level).data() << "level_num" - << msg.level << "message" - << std::string(msg.payload.begin(), msg.payload.end()) - << "logger_name" - << std::string(msg.logger_name.begin(), msg.logger_name.end()) - << "thread_id" << static_cast(msg.thread_id) << finalize; - client_->database(db_name_).collection(coll_name_).insert_one(doc.view()); - } - } - - void flush_() override {} - -private: - std::shared_ptr instance_; - std::string db_name_; - std::string coll_name_; - std::unique_ptr client_ = nullptr; -}; - -#include "spdlog/details/null_mutex.h" -#include -using mongo_sink_mt = mongo_sink; -using mongo_sink_st = mongo_sink; - -} // namespace sinks - -template -inline std::shared_ptr mongo_logger_mt( - const std::string &logger_name, - const std::string &db_name, - const std::string &collection_name, - const std::string &uri = "mongodb://localhost:27017") { - return Factory::template create(logger_name, db_name, collection_name, - uri); -} - -template -inline std::shared_ptr mongo_logger_st( - const std::string &logger_name, - const std::string &db_name, - const std::string &collection_name, - const std::string &uri = "mongodb://localhost:27017") { - return Factory::template create(logger_name, db_name, collection_name, - uri); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/msvc_sink.h b/examples/blueprints-example/external/spdlog/sinks/msvc_sink.h deleted file mode 100644 index c28d6eb..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/msvc_sink.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright(c) 2016 Alexander Dalshov & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#if defined(_WIN32) - - #include - #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) - #include - #endif - #include - - #include - #include - - // Avoid including windows.h (https://stackoverflow.com/a/30741042) - #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) -extern "C" __declspec(dllimport) void __stdcall OutputDebugStringW(const wchar_t *lpOutputString); - #else -extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA(const char *lpOutputString); - #endif -extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); - -namespace spdlog { -namespace sinks { -/* - * MSVC sink (logging using OutputDebugStringA) - */ -template -class msvc_sink : public base_sink { -public: - msvc_sink() = default; - msvc_sink(bool check_debugger_present) - : check_debugger_present_{check_debugger_present} {} - -protected: - void sink_it_(const details::log_msg &msg) override { - if (check_debugger_present_ && !IsDebuggerPresent()) { - return; - } - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - formatted.push_back('\0'); // add a null terminator for OutputDebugString - #if defined(SPDLOG_WCHAR_TO_UTF8_SUPPORT) - wmemory_buf_t wformatted; - details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), wformatted); - OutputDebugStringW(wformatted.data()); - #else - OutputDebugStringA(formatted.data()); - #endif - } - - void flush_() override {} - - bool check_debugger_present_ = true; -}; - -using msvc_sink_mt = msvc_sink; -using msvc_sink_st = msvc_sink; - -using windebug_sink_mt = msvc_sink_mt; -using windebug_sink_st = msvc_sink_st; - -} // namespace sinks -} // namespace spdlog - -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/null_sink.h b/examples/blueprints-example/external/spdlog/sinks/null_sink.h deleted file mode 100644 index 74530b5..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/null_sink.h +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include - -#include - -namespace spdlog { -namespace sinks { - -template -class null_sink final : public base_sink { -protected: - void sink_it_(const details::log_msg &) override {} - void flush_() override {} -}; - -using null_sink_mt = null_sink; -using null_sink_st = null_sink; - -} // namespace sinks - -template -inline std::shared_ptr null_logger_mt(const std::string &logger_name) { - auto null_logger = Factory::template create(logger_name); - null_logger->set_level(level::off); - return null_logger; -} - -template -inline std::shared_ptr null_logger_st(const std::string &logger_name) { - auto null_logger = Factory::template create(logger_name); - null_logger->set_level(level::off); - return null_logger; -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/ostream_sink.h b/examples/blueprints-example/external/spdlog/sinks/ostream_sink.h deleted file mode 100644 index 6af9dd0..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/ostream_sink.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -#include -#include - -namespace spdlog { -namespace sinks { -template -class ostream_sink final : public base_sink { -public: - explicit ostream_sink(std::ostream &os, bool force_flush = false) - : ostream_(os), - force_flush_(force_flush) {} - ostream_sink(const ostream_sink &) = delete; - ostream_sink &operator=(const ostream_sink &) = delete; - -protected: - void sink_it_(const details::log_msg &msg) override { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - ostream_.write(formatted.data(), static_cast(formatted.size())); - if (force_flush_) { - ostream_.flush(); - } - } - - void flush_() override { ostream_.flush(); } - - std::ostream &ostream_; - bool force_flush_; -}; - -using ostream_sink_mt = ostream_sink; -using ostream_sink_st = ostream_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/qt_sinks.h b/examples/blueprints-example/external/spdlog/sinks/qt_sinks.h deleted file mode 100644 index d319e84..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/qt_sinks.h +++ /dev/null @@ -1,304 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman, mguludag and spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -// -// Custom sink for QPlainTextEdit or QTextEdit and its children (QTextBrowser... -// etc) Building and using requires Qt library. -// -// Warning: the qt_sink won't be notified if the target widget is destroyed. -// If the widget's lifetime can be shorter than the logger's one, you should provide some permanent -// QObject, and then use a standard signal/slot. -// - -#include "spdlog/common.h" -#include "spdlog/details/log_msg.h" -#include "spdlog/details/synchronous_factory.h" -#include "spdlog/sinks/base_sink.h" -#include - -#include -#include - -// -// qt_sink class -// -namespace spdlog { -namespace sinks { -template -class qt_sink : public base_sink { -public: - qt_sink(QObject *qt_object, std::string meta_method) - : qt_object_(qt_object), - meta_method_(std::move(meta_method)) { - if (!qt_object_) { - throw_spdlog_ex("qt_sink: qt_object is null"); - } - } - - ~qt_sink() { flush_(); } - -protected: - void sink_it_(const details::log_msg &msg) override { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - const string_view_t str = string_view_t(formatted.data(), formatted.size()); - QMetaObject::invokeMethod( - qt_object_, meta_method_.c_str(), Qt::AutoConnection, - Q_ARG(QString, QString::fromUtf8(str.data(), static_cast(str.size())).trimmed())); - } - - void flush_() override {} - -private: - QObject *qt_object_ = nullptr; - std::string meta_method_; -}; - -// Qt color sink to QTextEdit. -// Color location is determined by the sink log pattern like in the rest of spdlog sinks. -// Colors can be modified if needed using sink->set_color(level, qtTextCharFormat). -// max_lines is the maximum number of lines that the sink will hold before removing the oldest -// lines. By default, only ascii (latin1) is supported by this sink. Set is_utf8 to true if utf8 -// support is needed. -template -class qt_color_sink : public base_sink { -public: - qt_color_sink(QTextEdit *qt_text_edit, - int max_lines, - bool dark_colors = false, - bool is_utf8 = false) - : qt_text_edit_(qt_text_edit), - max_lines_(max_lines), - is_utf8_(is_utf8) { - if (!qt_text_edit_) { - throw_spdlog_ex("qt_color_text_sink: text_edit is null"); - } - - default_color_ = qt_text_edit_->currentCharFormat(); - // set colors - QTextCharFormat format; - // trace - format.setForeground(dark_colors ? Qt::darkGray : Qt::gray); - colors_.at(level::trace) = format; - // debug - format.setForeground(dark_colors ? Qt::darkCyan : Qt::cyan); - colors_.at(level::debug) = format; - // info - format.setForeground(dark_colors ? Qt::darkGreen : Qt::green); - colors_.at(level::info) = format; - // warn - format.setForeground(dark_colors ? Qt::darkYellow : Qt::yellow); - colors_.at(level::warn) = format; - // err - format.setForeground(Qt::red); - colors_.at(level::err) = format; - // critical - format.setForeground(Qt::white); - format.setBackground(Qt::red); - colors_.at(level::critical) = format; - } - - ~qt_color_sink() { flush_(); } - - void set_default_color(QTextCharFormat format) { - // std::lock_guard lock(base_sink::mutex_); - default_color_ = format; - } - - void set_level_color(level::level_enum color_level, QTextCharFormat format) { - // std::lock_guard lock(base_sink::mutex_); - colors_.at(static_cast(color_level)) = format; - } - - QTextCharFormat &get_level_color(level::level_enum color_level) { - std::lock_guard lock(base_sink::mutex_); - return colors_.at(static_cast(color_level)); - } - - QTextCharFormat &get_default_color() { - std::lock_guard lock(base_sink::mutex_); - return default_color_; - } - -protected: - struct invoke_params { - invoke_params(int max_lines, - QTextEdit *q_text_edit, - QString payload, - QTextCharFormat default_color, - QTextCharFormat level_color, - int color_range_start, - int color_range_end) - : max_lines(max_lines), - q_text_edit(q_text_edit), - payload(std::move(payload)), - default_color(default_color), - level_color(level_color), - color_range_start(color_range_start), - color_range_end(color_range_end) {} - int max_lines; - QTextEdit *q_text_edit; - QString payload; - QTextCharFormat default_color; - QTextCharFormat level_color; - int color_range_start; - int color_range_end; - }; - - void sink_it_(const details::log_msg &msg) override { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - - const string_view_t str = string_view_t(formatted.data(), formatted.size()); - // apply the color to the color range in the formatted message. - QString payload; - int color_range_start = static_cast(msg.color_range_start); - int color_range_end = static_cast(msg.color_range_end); - if (is_utf8_) { - payload = QString::fromUtf8(str.data(), static_cast(str.size())); - // convert color ranges from byte index to character index. - if (msg.color_range_start < msg.color_range_end) { - color_range_start = QString::fromUtf8(str.data(), msg.color_range_start).size(); - color_range_end = QString::fromUtf8(str.data(), msg.color_range_end).size(); - } - } else { - payload = QString::fromLatin1(str.data(), static_cast(str.size())); - } - - invoke_params params{max_lines_, // max lines - qt_text_edit_, // text edit to append to - std::move(payload), // text to append - default_color_, // default color - colors_.at(msg.level), // color to apply - color_range_start, // color range start - color_range_end}; // color range end - - QMetaObject::invokeMethod( - qt_text_edit_, [params]() { invoke_method_(params); }, Qt::AutoConnection); - } - - void flush_() override {} - - // Add colored text to the text edit widget. This method is invoked in the GUI thread. - // It is a static method to ensure that it is handled correctly even if the sink is destroyed - // prematurely before it is invoked. - - static void invoke_method_(invoke_params params) { - auto *document = params.q_text_edit->document(); - QTextCursor cursor(document); - - // remove first blocks if number of blocks exceeds max_lines - while (document->blockCount() > params.max_lines) { - cursor.select(QTextCursor::BlockUnderCursor); - cursor.removeSelectedText(); - cursor.deleteChar(); // delete the newline after the block - } - - cursor.movePosition(QTextCursor::End); - cursor.setCharFormat(params.default_color); - - // if color range not specified or not not valid, just append the text with default color - if (params.color_range_end <= params.color_range_start) { - cursor.insertText(params.payload); - return; - } - - // insert the text before the color range - cursor.insertText(params.payload.left(params.color_range_start)); - - // insert the colorized text - cursor.setCharFormat(params.level_color); - cursor.insertText(params.payload.mid(params.color_range_start, - params.color_range_end - params.color_range_start)); - - // insert the text after the color range with default format - cursor.setCharFormat(params.default_color); - cursor.insertText(params.payload.mid(params.color_range_end)); - } - - QTextEdit *qt_text_edit_; - int max_lines_; - bool is_utf8_; - QTextCharFormat default_color_; - std::array colors_; -}; - -#include "spdlog/details/null_mutex.h" -#include - -using qt_sink_mt = qt_sink; -using qt_sink_st = qt_sink; -using qt_color_sink_mt = qt_color_sink; -using qt_color_sink_st = qt_color_sink; -} // namespace sinks - -// -// Factory functions -// - -// log to QTextEdit -template -inline std::shared_ptr qt_logger_mt(const std::string &logger_name, - QTextEdit *qt_object, - const std::string &meta_method = "append") { - return Factory::template create(logger_name, qt_object, meta_method); -} - -template -inline std::shared_ptr qt_logger_st(const std::string &logger_name, - QTextEdit *qt_object, - const std::string &meta_method = "append") { - return Factory::template create(logger_name, qt_object, meta_method); -} - -// log to QPlainTextEdit -template -inline std::shared_ptr qt_logger_mt(const std::string &logger_name, - QPlainTextEdit *qt_object, - const std::string &meta_method = "appendPlainText") { - return Factory::template create(logger_name, qt_object, meta_method); -} - -template -inline std::shared_ptr qt_logger_st(const std::string &logger_name, - QPlainTextEdit *qt_object, - const std::string &meta_method = "appendPlainText") { - return Factory::template create(logger_name, qt_object, meta_method); -} -// log to QObject -template -inline std::shared_ptr qt_logger_mt(const std::string &logger_name, - QObject *qt_object, - const std::string &meta_method) { - return Factory::template create(logger_name, qt_object, meta_method); -} - -template -inline std::shared_ptr qt_logger_st(const std::string &logger_name, - QObject *qt_object, - const std::string &meta_method) { - return Factory::template create(logger_name, qt_object, meta_method); -} - -// log to QTextEdit with colorized output -template -inline std::shared_ptr qt_color_logger_mt(const std::string &logger_name, - QTextEdit *qt_text_edit, - int max_lines, - bool is_utf8 = false) { - return Factory::template create(logger_name, qt_text_edit, max_lines, - false, is_utf8); -} - -template -inline std::shared_ptr qt_color_logger_st(const std::string &logger_name, - QTextEdit *qt_text_edit, - int max_lines, - bool is_utf8 = false) { - return Factory::template create(logger_name, qt_text_edit, max_lines, - false, is_utf8); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/ringbuffer_sink.h b/examples/blueprints-example/external/spdlog/sinks/ringbuffer_sink.h deleted file mode 100644 index bcdf0ff..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/ringbuffer_sink.h +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include "spdlog/details/circular_q.h" -#include "spdlog/details/log_msg_buffer.h" -#include "spdlog/details/null_mutex.h" -#include "spdlog/sinks/base_sink.h" - -#include -#include -#include - -namespace spdlog { -namespace sinks { -/* - * Ring buffer sink - */ -template -class ringbuffer_sink final : public base_sink { -public: - explicit ringbuffer_sink(size_t n_items) - : q_{n_items} { - if (n_items == 0) { - throw_spdlog_ex("ringbuffer_sink: n_items cannot be zero"); - } - } - - std::vector last_raw(size_t lim = 0) { - std::lock_guard lock(base_sink::mutex_); - auto items_available = q_.size(); - auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available; - std::vector ret; - ret.reserve(n_items); - for (size_t i = (items_available - n_items); i < items_available; i++) { - ret.push_back(q_.at(i)); - } - return ret; - } - - std::vector last_formatted(size_t lim = 0) { - std::lock_guard lock(base_sink::mutex_); - auto items_available = q_.size(); - auto n_items = lim > 0 ? (std::min)(lim, items_available) : items_available; - std::vector ret; - ret.reserve(n_items); - for (size_t i = (items_available - n_items); i < items_available; i++) { - memory_buf_t formatted; - base_sink::formatter_->format(q_.at(i), formatted); - ret.push_back(SPDLOG_BUF_TO_STRING(formatted)); - } - return ret; - } - -protected: - void sink_it_(const details::log_msg &msg) override { - q_.push_back(details::log_msg_buffer{msg}); - } - void flush_() override {} - -private: - details::circular_q q_; -}; - -using ringbuffer_sink_mt = ringbuffer_sink; -using ringbuffer_sink_st = ringbuffer_sink; - -} // namespace sinks - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/rotating_file_sink-inl.h b/examples/blueprints-example/external/spdlog/sinks/rotating_file_sink-inl.h deleted file mode 100644 index a3694d8..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/rotating_file_sink-inl.h +++ /dev/null @@ -1,179 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { - -template -SPDLOG_INLINE rotating_file_sink::rotating_file_sink( - filename_t base_filename, - std::size_t max_size, - std::size_t max_files, - bool rotate_on_open, - const file_event_handlers &event_handlers) - : base_filename_(std::move(base_filename)), - max_size_(max_size), - max_files_(max_files), - file_helper_{event_handlers} { - if (max_size == 0) { - throw_spdlog_ex("rotating sink constructor: max_size arg cannot be zero"); - } - - if (max_files > MaxFiles) { - throw_spdlog_ex("rotating sink constructor: max_files arg cannot exceed MaxFiles"); - } - file_helper_.open(calc_filename(base_filename_, 0)); - current_size_ = file_helper_.size(); // expensive. called only once - if (rotate_on_open && current_size_ > 0) { - rotate_(); - current_size_ = 0; - } -} - -// calc filename according to index and file extension if exists. -// e.g. calc_filename("logs/mylog.txt, 3) => "logs/mylog.3.txt". -template -SPDLOG_INLINE filename_t rotating_file_sink::calc_filename(const filename_t &filename, - std::size_t index) { - if (index == 0U) { - return filename; - } - - filename_t basename; - filename_t ext; - std::tie(basename, ext) = details::file_helper::split_by_extension(filename); - return fmt_lib::format(SPDLOG_FMT_STRING(SPDLOG_FILENAME_T("{}.{}{}")), basename, index, ext); -} - -template -SPDLOG_INLINE filename_t rotating_file_sink::filename() { - std::lock_guard lock(base_sink::mutex_); - return file_helper_.filename(); -} - -template -SPDLOG_INLINE void rotating_file_sink::rotate_now() { - std::lock_guard lock(base_sink::mutex_); - rotate_(); -} -template -SPDLOG_INLINE void rotating_file_sink::set_max_size(std::size_t max_size) { - std::lock_guard lock(base_sink::mutex_); - if (max_size == 0) { - throw_spdlog_ex("rotating sink set_max_size: max_size arg cannot be zero"); - } - max_size_ = max_size; -} - -template -SPDLOG_INLINE std::size_t rotating_file_sink::get_max_size() { - std::lock_guard lock(base_sink::mutex_); - return max_size_; -} - -template -SPDLOG_INLINE void rotating_file_sink::set_max_files(std::size_t max_files) { - std::lock_guard lock(base_sink::mutex_); - if (max_files > MaxFiles) { - throw_spdlog_ex("rotating sink set_max_files: max_files arg cannot exceed 200000"); - } - max_files_ = max_files; -} - -template -std::size_t rotating_file_sink::get_max_files() { - std::lock_guard lock(base_sink::mutex_); - return max_files_; -} - -template -SPDLOG_INLINE void rotating_file_sink::sink_it_(const details::log_msg &msg) { - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - auto new_size = current_size_ + formatted.size(); - - // rotate if the new estimated file size exceeds max size. - // rotate only if the real size > 0 to better deal with full disk (see issue #2261). - // we only check the real size when new_size > max_size_ because it is relatively expensive. - if (new_size > max_size_) { - file_helper_.flush(); - if (file_helper_.size() > 0) { - rotate_(); - new_size = formatted.size(); - } - } - file_helper_.write(formatted); - current_size_ = new_size; -} - -template -SPDLOG_INLINE void rotating_file_sink::flush_() { - file_helper_.flush(); -} - -// Rotate files: -// log.txt -> log.1.txt -// log.1.txt -> log.2.txt -// log.2.txt -> log.3.txt -// log.3.txt -> delete -template -SPDLOG_INLINE void rotating_file_sink::rotate_() { - using details::os::filename_to_str; - using details::os::path_exists; - - file_helper_.close(); - for (auto i = max_files_; i > 0; --i) { - filename_t src = calc_filename(base_filename_, i - 1); - if (!path_exists(src)) { - continue; - } - filename_t target = calc_filename(base_filename_, i); - - if (!rename_file_(src, target)) { - // if failed try again after a small delay. - // this is a workaround to a windows issue, where very high rotation - // rates can cause the rename to fail with permission denied (because of antivirus?). - details::os::sleep_for_millis(100); - if (!rename_file_(src, target)) { - file_helper_.reopen( - true); // truncate the log file anyway to prevent it to grow beyond its limit! - current_size_ = 0; - throw_spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + - " to " + filename_to_str(target), - errno); - } - } - } - file_helper_.reopen(true); -} - -// delete the target if exists, and rename the src file to target -// return true on success, false otherwise. -template -SPDLOG_INLINE bool rotating_file_sink::rename_file_(const filename_t &src_filename, - const filename_t &target_filename) { - // try to delete the target file in case it already exists. - (void)details::os::remove(target_filename); - return details::os::rename(src_filename, target_filename) == 0; -} - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/rotating_file_sink.h b/examples/blueprints-example/external/spdlog/sinks/rotating_file_sink.h deleted file mode 100644 index 72302e6..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/rotating_file_sink.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace spdlog { -namespace sinks { - -// -// Rotating file sink based on size -// -template -class rotating_file_sink final : public base_sink { -public: - static constexpr size_t MaxFiles = 200000; - rotating_file_sink(filename_t base_filename, - std::size_t max_size, - std::size_t max_files, - bool rotate_on_open = false, - const file_event_handlers &event_handlers = {}); - static filename_t calc_filename(const filename_t &filename, std::size_t index); - filename_t filename(); - void rotate_now(); - void set_max_size(std::size_t max_size); - std::size_t get_max_size(); - void set_max_files(std::size_t max_files); - std::size_t get_max_files(); - -protected: - void sink_it_(const details::log_msg &msg) override; - void flush_() override; - -private: - // Rotate files: - // log.txt -> log.1.txt - // log.1.txt -> log.2.txt - // log.2.txt -> log.3.txt - // log.3.txt -> delete - void rotate_(); - - // delete the target if exists, and rename the src file to target - // return true on success, false otherwise. - bool rename_file_(const filename_t &src_filename, const filename_t &target_filename); - - filename_t base_filename_; - std::size_t max_size_; - std::size_t max_files_; - std::size_t current_size_; - details::file_helper file_helper_; -}; - -using rotating_file_sink_mt = rotating_file_sink; -using rotating_file_sink_st = rotating_file_sink; - -} // namespace sinks - -// -// factory functions -// -template -std::shared_ptr rotating_logger_mt(const std::string &logger_name, - const filename_t &filename, - size_t max_file_size, - size_t max_files, - bool rotate_on_open = false, - const file_event_handlers &event_handlers = {}) { - return Factory::template create( - logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers); -} - -template -std::shared_ptr rotating_logger_st(const std::string &logger_name, - const filename_t &filename, - size_t max_file_size, - size_t max_files, - bool rotate_on_open = false, - const file_event_handlers &event_handlers = {}) { - return Factory::template create( - logger_name, filename, max_file_size, max_files, rotate_on_open, event_handlers); -} -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "rotating_file_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/sink-inl.h b/examples/blueprints-example/external/spdlog/sinks/sink-inl.h deleted file mode 100644 index e4b2714..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/sink-inl.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include - -SPDLOG_INLINE bool spdlog::sinks::sink::should_log(spdlog::level::level_enum msg_level) const { - return msg_level >= level_.load(std::memory_order_relaxed); -} - -SPDLOG_INLINE void spdlog::sinks::sink::set_level(level::level_enum log_level) { - level_.store(log_level, std::memory_order_relaxed); -} - -SPDLOG_INLINE spdlog::level::level_enum spdlog::sinks::sink::level() const { - return static_cast(level_.load(std::memory_order_relaxed)); -} diff --git a/examples/blueprints-example/external/spdlog/sinks/sink.h b/examples/blueprints-example/external/spdlog/sinks/sink.h deleted file mode 100644 index 5850685..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/sink.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -namespace spdlog { - -namespace sinks { -class SPDLOG_API sink { -public: - virtual ~sink() = default; - virtual void log(const details::log_msg &msg) = 0; - virtual void flush() = 0; - virtual void set_pattern(const std::string &pattern) = 0; - virtual void set_formatter(std::unique_ptr sink_formatter) = 0; - - void set_level(level::level_enum log_level); - level::level_enum level() const; - bool should_log(level::level_enum msg_level) const; - -protected: - // sink log level - default is all - level_t level_{level::trace}; -}; - -} // namespace sinks -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/stdout_color_sinks-inl.h b/examples/blueprints-example/external/spdlog/sinks/stdout_color_sinks-inl.h deleted file mode 100644 index 166e386..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/stdout_color_sinks-inl.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { - -template -SPDLOG_INLINE std::shared_ptr stdout_color_mt(const std::string &logger_name, - color_mode mode) { - return Factory::template create(logger_name, mode); -} - -template -SPDLOG_INLINE std::shared_ptr stdout_color_st(const std::string &logger_name, - color_mode mode) { - return Factory::template create(logger_name, mode); -} - -template -SPDLOG_INLINE std::shared_ptr stderr_color_mt(const std::string &logger_name, - color_mode mode) { - return Factory::template create(logger_name, mode); -} - -template -SPDLOG_INLINE std::shared_ptr stderr_color_st(const std::string &logger_name, - color_mode mode) { - return Factory::template create(logger_name, mode); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/stdout_color_sinks.h b/examples/blueprints-example/external/spdlog/sinks/stdout_color_sinks.h deleted file mode 100644 index 72991fe..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/stdout_color_sinks.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifdef _WIN32 - #include -#else - #include -#endif - -#include - -namespace spdlog { -namespace sinks { -#ifdef _WIN32 -using stdout_color_sink_mt = wincolor_stdout_sink_mt; -using stdout_color_sink_st = wincolor_stdout_sink_st; -using stderr_color_sink_mt = wincolor_stderr_sink_mt; -using stderr_color_sink_st = wincolor_stderr_sink_st; -#else -using stdout_color_sink_mt = ansicolor_stdout_sink_mt; -using stdout_color_sink_st = ansicolor_stdout_sink_st; -using stderr_color_sink_mt = ansicolor_stderr_sink_mt; -using stderr_color_sink_st = ansicolor_stderr_sink_st; -#endif -} // namespace sinks - -template -std::shared_ptr stdout_color_mt(const std::string &logger_name, - color_mode mode = color_mode::automatic); - -template -std::shared_ptr stdout_color_st(const std::string &logger_name, - color_mode mode = color_mode::automatic); - -template -std::shared_ptr stderr_color_mt(const std::string &logger_name, - color_mode mode = color_mode::automatic); - -template -std::shared_ptr stderr_color_st(const std::string &logger_name, - color_mode mode = color_mode::automatic); - -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "stdout_color_sinks-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/stdout_sinks-inl.h b/examples/blueprints-example/external/spdlog/sinks/stdout_sinks-inl.h deleted file mode 100644 index dcb21d8..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/stdout_sinks-inl.h +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include -#include -#include - -#ifdef _WIN32 - // under windows using fwrite to non-binary stream results in \r\r\n (see issue #1675) - // so instead we use ::FileWrite - #include - - #ifndef _USING_V110_SDK71_ // fileapi.h doesn't exist in winxp - #include // WriteFile (..) - #endif - - #include // _get_osfhandle(..) - #include // _fileno(..) -#endif // _WIN32 - -namespace spdlog { - -namespace sinks { - -template -SPDLOG_INLINE stdout_sink_base::stdout_sink_base(FILE *file) - : mutex_(ConsoleMutex::mutex()), - file_(file), - formatter_(details::make_unique()) { -#ifdef _WIN32 - // get windows handle from the FILE* object - - handle_ = reinterpret_cast(::_get_osfhandle(::_fileno(file_))); - - // don't throw to support cases where no console is attached, - // and let the log method to do nothing if (handle_ == INVALID_HANDLE_VALUE). - // throw only if non stdout/stderr target is requested (probably regular file and not console). - if (handle_ == INVALID_HANDLE_VALUE && file != stdout && file != stderr) { - throw_spdlog_ex("spdlog::stdout_sink_base: _get_osfhandle() failed", errno); - } -#endif // _WIN32 -} - -template -SPDLOG_INLINE void stdout_sink_base::log(const details::log_msg &msg) { -#ifdef _WIN32 - if (handle_ == INVALID_HANDLE_VALUE) { - return; - } - std::lock_guard lock(mutex_); - memory_buf_t formatted; - formatter_->format(msg, formatted); - auto size = static_cast(formatted.size()); - DWORD bytes_written = 0; - bool ok = ::WriteFile(handle_, formatted.data(), size, &bytes_written, nullptr) != 0; - if (!ok) { - throw_spdlog_ex("stdout_sink_base: WriteFile() failed. GetLastError(): " + - std::to_string(::GetLastError())); - } -#else - std::lock_guard lock(mutex_); - memory_buf_t formatted; - formatter_->format(msg, formatted); - details::os::fwrite_bytes(formatted.data(), formatted.size(), file_); -#endif // _WIN32 - ::fflush(file_); // flush every line to terminal -} - -template -SPDLOG_INLINE void stdout_sink_base::flush() { - std::lock_guard lock(mutex_); - fflush(file_); -} - -template -SPDLOG_INLINE void stdout_sink_base::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); -} - -template -SPDLOG_INLINE void stdout_sink_base::set_formatter( - std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); -} - -// stdout sink -template -SPDLOG_INLINE stdout_sink::stdout_sink() - : stdout_sink_base(stdout) {} - -// stderr sink -template -SPDLOG_INLINE stderr_sink::stderr_sink() - : stdout_sink_base(stderr) {} - -} // namespace sinks - -// factory methods -template -SPDLOG_INLINE std::shared_ptr stdout_logger_mt(const std::string &logger_name) { - return Factory::template create(logger_name); -} - -template -SPDLOG_INLINE std::shared_ptr stdout_logger_st(const std::string &logger_name) { - return Factory::template create(logger_name); -} - -template -SPDLOG_INLINE std::shared_ptr stderr_logger_mt(const std::string &logger_name) { - return Factory::template create(logger_name); -} - -template -SPDLOG_INLINE std::shared_ptr stderr_logger_st(const std::string &logger_name) { - return Factory::template create(logger_name); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/stdout_sinks.h b/examples/blueprints-example/external/spdlog/sinks/stdout_sinks.h deleted file mode 100644 index 6ef0996..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/stdout_sinks.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#ifdef _WIN32 - #include -#endif - -namespace spdlog { - -namespace sinks { - -template -class stdout_sink_base : public sink { -public: - using mutex_t = typename ConsoleMutex::mutex_t; - explicit stdout_sink_base(FILE *file); - ~stdout_sink_base() override = default; - - stdout_sink_base(const stdout_sink_base &other) = delete; - stdout_sink_base(stdout_sink_base &&other) = delete; - - stdout_sink_base &operator=(const stdout_sink_base &other) = delete; - stdout_sink_base &operator=(stdout_sink_base &&other) = delete; - - void log(const details::log_msg &msg) override; - void flush() override; - void set_pattern(const std::string &pattern) override; - - void set_formatter(std::unique_ptr sink_formatter) override; - -protected: - mutex_t &mutex_; - FILE *file_; - std::unique_ptr formatter_; -#ifdef _WIN32 - HANDLE handle_; -#endif // WIN32 -}; - -template -class stdout_sink : public stdout_sink_base { -public: - stdout_sink(); -}; - -template -class stderr_sink : public stdout_sink_base { -public: - stderr_sink(); -}; - -using stdout_sink_mt = stdout_sink; -using stdout_sink_st = stdout_sink; - -using stderr_sink_mt = stderr_sink; -using stderr_sink_st = stderr_sink; - -} // namespace sinks - -// factory methods -template -std::shared_ptr stdout_logger_mt(const std::string &logger_name); - -template -std::shared_ptr stdout_logger_st(const std::string &logger_name); - -template -std::shared_ptr stderr_logger_mt(const std::string &logger_name); - -template -std::shared_ptr stderr_logger_st(const std::string &logger_name); - -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "stdout_sinks-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/sinks/syslog_sink.h b/examples/blueprints-example/external/spdlog/sinks/syslog_sink.h deleted file mode 100644 index 913d41b..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/syslog_sink.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include - -#include -#include -#include - -namespace spdlog { -namespace sinks { -/** - * Sink that write to syslog using the `syscall()` library call. - */ -template -class syslog_sink : public base_sink { -public: - syslog_sink(std::string ident, int syslog_option, int syslog_facility, bool enable_formatting) - : enable_formatting_{enable_formatting}, - syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, - /* spdlog::level::debug */ LOG_DEBUG, - /* spdlog::level::info */ LOG_INFO, - /* spdlog::level::warn */ LOG_WARNING, - /* spdlog::level::err */ LOG_ERR, - /* spdlog::level::critical */ LOG_CRIT, - /* spdlog::level::off */ LOG_INFO}}, - ident_{std::move(ident)} { - // set ident to be program name if empty - ::openlog(ident_.empty() ? nullptr : ident_.c_str(), syslog_option, syslog_facility); - } - - ~syslog_sink() override { ::closelog(); } - - syslog_sink(const syslog_sink &) = delete; - syslog_sink &operator=(const syslog_sink &) = delete; - -protected: - void sink_it_(const details::log_msg &msg) override { - string_view_t payload; - memory_buf_t formatted; - if (enable_formatting_) { - base_sink::formatter_->format(msg, formatted); - payload = string_view_t(formatted.data(), formatted.size()); - } else { - payload = msg.payload; - } - - size_t length = payload.size(); - // limit to max int - if (length > static_cast(std::numeric_limits::max())) { - length = static_cast(std::numeric_limits::max()); - } - - ::syslog(syslog_prio_from_level(msg), "%.*s", static_cast(length), payload.data()); - } - - void flush_() override {} - bool enable_formatting_ = false; - - // - // Simply maps spdlog's log level to syslog priority level. - // - virtual int syslog_prio_from_level(const details::log_msg &msg) const { - return syslog_levels_.at(static_cast(msg.level)); - } - - using levels_array = std::array; - levels_array syslog_levels_; - -private: - // must store the ident because the man says openlog might use the pointer as - // is and not a string copy - const std::string ident_; -}; - -using syslog_sink_mt = syslog_sink; -using syslog_sink_st = syslog_sink; -} // namespace sinks - -// Create and register a syslog logger -template -inline std::shared_ptr syslog_logger_mt(const std::string &logger_name, - const std::string &syslog_ident = "", - int syslog_option = 0, - int syslog_facility = LOG_USER, - bool enable_formatting = false) { - return Factory::template create(logger_name, syslog_ident, syslog_option, - syslog_facility, enable_formatting); -} - -template -inline std::shared_ptr syslog_logger_st(const std::string &logger_name, - const std::string &syslog_ident = "", - int syslog_option = 0, - int syslog_facility = LOG_USER, - bool enable_formatting = false) { - return Factory::template create(logger_name, syslog_ident, syslog_option, - syslog_facility, enable_formatting); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/systemd_sink.h b/examples/blueprints-example/external/spdlog/sinks/systemd_sink.h deleted file mode 100644 index d2cd55f..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/systemd_sink.h +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright(c) 2019 ZVYAGIN.Alexander@gmail.com -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#ifndef SD_JOURNAL_SUPPRESS_LOCATION - #define SD_JOURNAL_SUPPRESS_LOCATION -#endif -#include - -namespace spdlog { -namespace sinks { - -/** - * Sink that write to systemd journal using the `sd_journal_send()` library call. - */ -template -class systemd_sink : public base_sink { -public: - systemd_sink(std::string ident = "", bool enable_formatting = false) - : ident_{std::move(ident)}, - enable_formatting_{enable_formatting}, - syslog_levels_{{/* spdlog::level::trace */ LOG_DEBUG, - /* spdlog::level::debug */ LOG_DEBUG, - /* spdlog::level::info */ LOG_INFO, - /* spdlog::level::warn */ LOG_WARNING, - /* spdlog::level::err */ LOG_ERR, - /* spdlog::level::critical */ LOG_CRIT, - /* spdlog::level::off */ LOG_INFO}} {} - - ~systemd_sink() override {} - - systemd_sink(const systemd_sink &) = delete; - systemd_sink &operator=(const systemd_sink &) = delete; - -protected: - const std::string ident_; - bool enable_formatting_ = false; - using levels_array = std::array; - levels_array syslog_levels_; - - void sink_it_(const details::log_msg &msg) override { - int err; - string_view_t payload; - memory_buf_t formatted; - if (enable_formatting_) { - base_sink::formatter_->format(msg, formatted); - payload = string_view_t(formatted.data(), formatted.size()); - } else { - payload = msg.payload; - } - - size_t length = payload.size(); - // limit to max int - if (length > static_cast(std::numeric_limits::max())) { - length = static_cast(std::numeric_limits::max()); - } - - const string_view_t syslog_identifier = ident_.empty() ? msg.logger_name : ident_; - - // Do not send source location if not available - if (msg.source.empty()) { - // Note: function call inside '()' to avoid macro expansion - err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), payload.data(), - "PRIORITY=%d", syslog_level(msg.level), -#ifndef SPDLOG_NO_THREAD_ID - "TID=%zu", msg.thread_id, -#endif - "SYSLOG_IDENTIFIER=%.*s", - static_cast(syslog_identifier.size()), - syslog_identifier.data(), nullptr); - } else { - err = (sd_journal_send)("MESSAGE=%.*s", static_cast(length), payload.data(), - "PRIORITY=%d", syslog_level(msg.level), -#ifndef SPDLOG_NO_THREAD_ID - "TID=%zu", msg.thread_id, -#endif - "SYSLOG_IDENTIFIER=%.*s", - static_cast(syslog_identifier.size()), - syslog_identifier.data(), "CODE_FILE=%s", msg.source.filename, - "CODE_LINE=%d", msg.source.line, "CODE_FUNC=%s", - msg.source.funcname, nullptr); - } - - if (err) { - throw_spdlog_ex("Failed writing to systemd", errno); - } - } - - int syslog_level(level::level_enum l) { - return syslog_levels_.at(static_cast(l)); - } - - void flush_() override {} -}; - -using systemd_sink_mt = systemd_sink; -using systemd_sink_st = systemd_sink; -} // namespace sinks - -// Create and register a syslog logger -template -inline std::shared_ptr systemd_logger_mt(const std::string &logger_name, - const std::string &ident = "", - bool enable_formatting = false) { - return Factory::template create(logger_name, ident, enable_formatting); -} - -template -inline std::shared_ptr systemd_logger_st(const std::string &logger_name, - const std::string &ident = "", - bool enable_formatting = false) { - return Factory::template create(logger_name, ident, enable_formatting); -} -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/tcp_sink.h b/examples/blueprints-example/external/spdlog/sinks/tcp_sink.h deleted file mode 100644 index 5d9ef82..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/tcp_sink.h +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#ifdef _WIN32 - #include -#else - #include -#endif - -#include -#include -#include -#include - -#pragma once - -// Simple tcp client sink -// Connects to remote address and send the formatted log. -// Will attempt to reconnect if connection drops. -// If more complicated behaviour is needed (i.e get responses), you can inherit it and override the -// sink_it_ method. - -namespace spdlog { -namespace sinks { - -struct tcp_sink_config { - std::string server_host; - int server_port; - int timeout_ms = - 0; // The timeout for all 3 major socket operations that is connect, send, and recv - bool lazy_connect = false; // if true connect on first log call instead of on construction - - tcp_sink_config(std::string host, int port) - : server_host{std::move(host)}, - server_port{port} {} -}; - -template -class tcp_sink : public spdlog::sinks::base_sink { -public: - // connect to tcp host/port or throw if failed - // host can be hostname or ip address - - explicit tcp_sink(const std::string &host, - int port, - int timeout_ms = 0, - bool lazy_connect = false) - : config_{host, port} { - config_.timeout_ms = timeout_ms; - config_.lazy_connect = lazy_connect; - if (!config_.lazy_connect) { - client_.connect(config_.server_host, config_.server_port, config_.timeout_ms); - } - } - - explicit tcp_sink(tcp_sink_config sink_config) - : config_{std::move(sink_config)} { - if (!config_.lazy_connect) { - client_.connect(config_.server_host, config_.server_port, config_.timeout_ms); - } - } - - ~tcp_sink() override = default; - -protected: - void sink_it_(const spdlog::details::log_msg &msg) override { - spdlog::memory_buf_t formatted; - spdlog::sinks::base_sink::formatter_->format(msg, formatted); - if (!client_.is_connected()) { - client_.connect(config_.server_host, config_.server_port, config_.timeout_ms); - } - client_.send(formatted.data(), formatted.size()); - } - - void flush_() override {} - tcp_sink_config config_; - details::tcp_client client_; -}; - -using tcp_sink_mt = tcp_sink; -using tcp_sink_st = tcp_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/udp_sink.h b/examples/blueprints-example/external/spdlog/sinks/udp_sink.h deleted file mode 100644 index 4bff0fd..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/udp_sink.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#ifdef _WIN32 - #include -#else - #include -#endif - -#include -#include -#include -#include - -// Simple udp client sink -// Sends formatted log via udp - -namespace spdlog { -namespace sinks { - -struct udp_sink_config { - std::string server_host; - uint16_t server_port; - - udp_sink_config(std::string host, uint16_t port) - : server_host{std::move(host)}, - server_port{port} {} -}; - -template -class udp_sink : public spdlog::sinks::base_sink { -public: - // host can be hostname or ip address - explicit udp_sink(udp_sink_config sink_config) - : client_{sink_config.server_host, sink_config.server_port} {} - - ~udp_sink() override = default; - -protected: - void sink_it_(const spdlog::details::log_msg &msg) override { - spdlog::memory_buf_t formatted; - spdlog::sinks::base_sink::formatter_->format(msg, formatted); - client_.send(formatted.data(), formatted.size()); - } - - void flush_() override {} - details::udp_client client_; -}; - -using udp_sink_mt = udp_sink; -using udp_sink_st = udp_sink; - -} // namespace sinks - -// -// factory functions -// -template -inline std::shared_ptr udp_logger_mt(const std::string &logger_name, - sinks::udp_sink_config skin_config) { - return Factory::template create(logger_name, skin_config); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/win_eventlog_sink.h b/examples/blueprints-example/external/spdlog/sinks/win_eventlog_sink.h deleted file mode 100644 index 2c9b582..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/win_eventlog_sink.h +++ /dev/null @@ -1,260 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// Writing to Windows Event Log requires the registry entries below to be present, with the -// following modifications: -// 1. should be replaced with your log name (e.g. your application name) -// 2. should be replaced with the specific source name and the key should be -// duplicated for -// each source used in the application -// -// Since typically modifications of this kind require elevation, it's better to do it as a part of -// setup procedure. The snippet below uses mscoree.dll as the message file as it exists on most of -// the Windows systems anyway and happens to contain the needed resource. -// -// You can also specify a custom message file if needed. -// Please refer to Event Log functions descriptions in MSDN for more details on custom message -// files. - -/*--------------------------------------------------------------------------------------- - -Windows Registry Editor Version 5.00 - -[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\] - -[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\\] -"TypesSupported"=dword:00000007 -"EventMessageFile"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,\ - 00,6f,00,74,00,25,00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,\ - 5c,00,6d,00,73,00,63,00,6f,00,72,00,65,00,65,00,2e,00,64,00,6c,00,6c,00,00,\ - 00 - ------------------------------------------------------------------------------------------*/ - -#pragma once - -#include -#include - -#include -#include - -#include -#include -#include - -namespace spdlog { -namespace sinks { - -namespace win_eventlog { - -namespace internal { - -struct local_alloc_t { - HLOCAL hlocal_; - - SPDLOG_CONSTEXPR local_alloc_t() SPDLOG_NOEXCEPT : hlocal_(nullptr) {} - - local_alloc_t(local_alloc_t const &) = delete; - local_alloc_t &operator=(local_alloc_t const &) = delete; - - ~local_alloc_t() SPDLOG_NOEXCEPT { - if (hlocal_) { - LocalFree(hlocal_); - } - } -}; - -/** Windows error */ -struct win32_error : public spdlog_ex { - /** Formats an error report line: "user-message: error-code (system message)" */ - static std::string format(std::string const &user_message, DWORD error_code = GetLastError()) { - std::string system_message; - - local_alloc_t format_message_result{}; - auto format_message_succeeded = - ::FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - nullptr, error_code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPSTR)&format_message_result.hlocal_, 0, nullptr); - - if (format_message_succeeded && format_message_result.hlocal_) { - system_message = fmt_lib::format(" ({})", (LPSTR)format_message_result.hlocal_); - } - - return fmt_lib::format("{}: {}{}", user_message, error_code, system_message); - } - - explicit win32_error(std::string const &func_name, DWORD error = GetLastError()) - : spdlog_ex(format(func_name, error)) {} -}; - -/** Wrapper for security identifiers (SID) on Windows */ -struct sid_t { - std::vector buffer_; - -public: - sid_t() {} - - /** creates a wrapped SID copy */ - static sid_t duplicate_sid(PSID psid) { - if (!::IsValidSid(psid)) { - throw_spdlog_ex("sid_t::sid_t(): invalid SID received"); - } - - auto const sid_length{::GetLengthSid(psid)}; - - sid_t result; - result.buffer_.resize(sid_length); - if (!::CopySid(sid_length, (PSID)result.as_sid(), psid)) { - SPDLOG_THROW(win32_error("CopySid")); - } - - return result; - } - - /** Retrieves pointer to the internal buffer contents as SID* */ - SID *as_sid() const { return buffer_.empty() ? nullptr : (SID *)buffer_.data(); } - - /** Get SID for the current user */ - static sid_t get_current_user_sid() { - /* create and init RAII holder for process token */ - struct process_token_t { - HANDLE token_handle_ = INVALID_HANDLE_VALUE; - explicit process_token_t(HANDLE process) { - if (!::OpenProcessToken(process, TOKEN_QUERY, &token_handle_)) { - SPDLOG_THROW(win32_error("OpenProcessToken")); - } - } - - ~process_token_t() { ::CloseHandle(token_handle_); } - - } current_process_token( - ::GetCurrentProcess()); // GetCurrentProcess returns pseudohandle, no leak here! - - // Get the required size, this is expected to fail with ERROR_INSUFFICIENT_BUFFER and return - // the token size - DWORD tusize = 0; - if (::GetTokenInformation(current_process_token.token_handle_, TokenUser, NULL, 0, - &tusize)) { - SPDLOG_THROW(win32_error("GetTokenInformation should fail")); - } - - // get user token - std::vector buffer(static_cast(tusize)); - if (!::GetTokenInformation(current_process_token.token_handle_, TokenUser, - (LPVOID)buffer.data(), tusize, &tusize)) { - SPDLOG_THROW(win32_error("GetTokenInformation")); - } - - // create a wrapper of the SID data as stored in the user token - return sid_t::duplicate_sid(((TOKEN_USER *)buffer.data())->User.Sid); - } -}; - -struct eventlog { - static WORD get_event_type(details::log_msg const &msg) { - switch (msg.level) { - case level::trace: - case level::debug: - return EVENTLOG_SUCCESS; - - case level::info: - return EVENTLOG_INFORMATION_TYPE; - - case level::warn: - return EVENTLOG_WARNING_TYPE; - - case level::err: - case level::critical: - case level::off: - return EVENTLOG_ERROR_TYPE; - - default: - return EVENTLOG_INFORMATION_TYPE; - } - } - - static WORD get_event_category(details::log_msg const &msg) { return (WORD)msg.level; } -}; - -} // namespace internal - -/* - * Windows Event Log sink - */ -template -class win_eventlog_sink : public base_sink { -private: - HANDLE hEventLog_{NULL}; - internal::sid_t current_user_sid_; - std::string source_; - DWORD event_id_; - - HANDLE event_log_handle() { - if (!hEventLog_) { - hEventLog_ = ::RegisterEventSourceA(nullptr, source_.c_str()); - if (!hEventLog_ || hEventLog_ == (HANDLE)ERROR_ACCESS_DENIED) { - SPDLOG_THROW(internal::win32_error("RegisterEventSource")); - } - } - - return hEventLog_; - } - -protected: - void sink_it_(const details::log_msg &msg) override { - using namespace internal; - - bool succeeded; - memory_buf_t formatted; - base_sink::formatter_->format(msg, formatted); - formatted.push_back('\0'); - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT - wmemory_buf_t buf; - details::os::utf8_to_wstrbuf(string_view_t(formatted.data(), formatted.size()), buf); - - LPCWSTR lp_wstr = buf.data(); - succeeded = static_cast(::ReportEventW( - event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), - event_id_, current_user_sid_.as_sid(), 1, 0, &lp_wstr, nullptr)); -#else - LPCSTR lp_str = formatted.data(); - succeeded = static_cast(::ReportEventA( - event_log_handle(), eventlog::get_event_type(msg), eventlog::get_event_category(msg), - event_id_, current_user_sid_.as_sid(), 1, 0, &lp_str, nullptr)); -#endif - - if (!succeeded) { - SPDLOG_THROW(win32_error("ReportEvent")); - } - } - - void flush_() override {} - -public: - win_eventlog_sink(std::string const &source, - DWORD event_id = 1000 /* according to mscoree.dll */) - : source_(source), - event_id_(event_id) { - try { - current_user_sid_ = internal::sid_t::get_current_user_sid(); - } catch (...) { - // get_current_user_sid() is unlikely to fail and if it does, we can still proceed - // without current_user_sid but in the event log the record will have no user name - } - } - - ~win_eventlog_sink() { - if (hEventLog_) DeregisterEventSource(hEventLog_); - } -}; - -} // namespace win_eventlog - -using win_eventlog_sink_mt = win_eventlog::win_eventlog_sink; -using win_eventlog_sink_st = win_eventlog::win_eventlog_sink; - -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/wincolor_sink-inl.h b/examples/blueprints-example/external/spdlog/sinks/wincolor_sink-inl.h deleted file mode 100644 index a9c0fa2..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/wincolor_sink-inl.h +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -#include -#include - -namespace spdlog { -namespace sinks { -template -SPDLOG_INLINE wincolor_sink::wincolor_sink(void *out_handle, color_mode mode) - : out_handle_(out_handle), - mutex_(ConsoleMutex::mutex()), - formatter_(details::make_unique()) { - set_color_mode_impl(mode); - // set level colors - colors_[level::trace] = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; // white - colors_[level::debug] = FOREGROUND_GREEN | FOREGROUND_BLUE; // cyan - colors_[level::info] = FOREGROUND_GREEN; // green - colors_[level::warn] = - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; // intense yellow - colors_[level::err] = FOREGROUND_RED | FOREGROUND_INTENSITY; // intense red - colors_[level::critical] = BACKGROUND_RED | FOREGROUND_RED | FOREGROUND_GREEN | - FOREGROUND_BLUE | - FOREGROUND_INTENSITY; // intense white on red background - colors_[level::off] = 0; -} - -template -SPDLOG_INLINE wincolor_sink::~wincolor_sink() { - this->flush(); -} - -// change the color for the given level -template -void SPDLOG_INLINE wincolor_sink::set_color(level::level_enum level, - std::uint16_t color) { - std::lock_guard lock(mutex_); - colors_[static_cast(level)] = color; -} - -template -void SPDLOG_INLINE wincolor_sink::log(const details::log_msg &msg) { - if (out_handle_ == nullptr || out_handle_ == INVALID_HANDLE_VALUE) { - return; - } - - std::lock_guard lock(mutex_); - msg.color_range_start = 0; - msg.color_range_end = 0; - memory_buf_t formatted; - formatter_->format(msg, formatted); - if (should_do_colors_ && msg.color_range_end > msg.color_range_start) { - // before color range - print_range_(formatted, 0, msg.color_range_start); - // in color range - auto orig_attribs = - static_cast(set_foreground_color_(colors_[static_cast(msg.level)])); - print_range_(formatted, msg.color_range_start, msg.color_range_end); - // reset to orig colors - ::SetConsoleTextAttribute(static_cast(out_handle_), orig_attribs); - print_range_(formatted, msg.color_range_end, formatted.size()); - } else // print without colors if color range is invalid (or color is disabled) - { - write_to_file_(formatted); - } -} - -template -void SPDLOG_INLINE wincolor_sink::flush() { - // windows console always flushed? -} - -template -void SPDLOG_INLINE wincolor_sink::set_pattern(const std::string &pattern) { - std::lock_guard lock(mutex_); - formatter_ = std::unique_ptr(new pattern_formatter(pattern)); -} - -template -void SPDLOG_INLINE -wincolor_sink::set_formatter(std::unique_ptr sink_formatter) { - std::lock_guard lock(mutex_); - formatter_ = std::move(sink_formatter); -} - -template -void SPDLOG_INLINE wincolor_sink::set_color_mode(color_mode mode) { - std::lock_guard lock(mutex_); - set_color_mode_impl(mode); -} - -template -void SPDLOG_INLINE wincolor_sink::set_color_mode_impl(color_mode mode) { - if (mode == color_mode::automatic) { - // should do colors only if out_handle_ points to actual console. - DWORD console_mode; - bool in_console = ::GetConsoleMode(static_cast(out_handle_), &console_mode) != 0; - should_do_colors_ = in_console; - } else { - should_do_colors_ = mode == color_mode::always ? true : false; - } -} - -// set foreground color and return the orig console attributes (for resetting later) -template -std::uint16_t SPDLOG_INLINE -wincolor_sink::set_foreground_color_(std::uint16_t attribs) { - CONSOLE_SCREEN_BUFFER_INFO orig_buffer_info; - if (!::GetConsoleScreenBufferInfo(static_cast(out_handle_), &orig_buffer_info)) { - // just return white if failed getting console info - return FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; - } - - // change only the foreground bits (lowest 4 bits) - auto new_attribs = static_cast(attribs) | (orig_buffer_info.wAttributes & 0xfff0); - auto ignored = - ::SetConsoleTextAttribute(static_cast(out_handle_), static_cast(new_attribs)); - (void)(ignored); - return static_cast(orig_buffer_info.wAttributes); // return orig attribs -} - -// print a range of formatted message to console -template -void SPDLOG_INLINE wincolor_sink::print_range_(const memory_buf_t &formatted, - size_t start, - size_t end) { - if (end > start) { -#if defined(SPDLOG_UTF8_TO_WCHAR_CONSOLE) - wmemory_buf_t wformatted; - details::os::utf8_to_wstrbuf(string_view_t(formatted.data() + start, end - start), - wformatted); - auto size = static_cast(wformatted.size()); - auto ignored = ::WriteConsoleW(static_cast(out_handle_), wformatted.data(), size, - nullptr, nullptr); -#else - auto size = static_cast(end - start); - auto ignored = ::WriteConsoleA(static_cast(out_handle_), formatted.data() + start, - size, nullptr, nullptr); -#endif - (void)(ignored); - } -} - -template -void SPDLOG_INLINE wincolor_sink::write_to_file_(const memory_buf_t &formatted) { - auto size = static_cast(formatted.size()); - DWORD bytes_written = 0; - auto ignored = ::WriteFile(static_cast(out_handle_), formatted.data(), size, - &bytes_written, nullptr); - (void)(ignored); -} - -// wincolor_stdout_sink -template -SPDLOG_INLINE wincolor_stdout_sink::wincolor_stdout_sink(color_mode mode) - : wincolor_sink(::GetStdHandle(STD_OUTPUT_HANDLE), mode) {} - -// wincolor_stderr_sink -template -SPDLOG_INLINE wincolor_stderr_sink::wincolor_stderr_sink(color_mode mode) - : wincolor_sink(::GetStdHandle(STD_ERROR_HANDLE), mode) {} -} // namespace sinks -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/sinks/wincolor_sink.h b/examples/blueprints-example/external/spdlog/sinks/wincolor_sink.h deleted file mode 100644 index e62d14d..0000000 --- a/examples/blueprints-example/external/spdlog/sinks/wincolor_sink.h +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -namespace spdlog { -namespace sinks { -/* - * Windows color console sink. Uses WriteConsoleA to write to the console with - * colors - */ -template -class wincolor_sink : public sink { -public: - wincolor_sink(void *out_handle, color_mode mode); - ~wincolor_sink() override; - - wincolor_sink(const wincolor_sink &other) = delete; - wincolor_sink &operator=(const wincolor_sink &other) = delete; - - // change the color for the given level - void set_color(level::level_enum level, std::uint16_t color); - void log(const details::log_msg &msg) override; - void flush() override; - void set_pattern(const std::string &pattern) override; - void set_formatter(std::unique_ptr sink_formatter) override; - void set_color_mode(color_mode mode); - -protected: - using mutex_t = typename ConsoleMutex::mutex_t; - void *out_handle_; - mutex_t &mutex_; - bool should_do_colors_; - std::unique_ptr formatter_; - std::array colors_; - - // set foreground color and return the orig console attributes (for resetting later) - std::uint16_t set_foreground_color_(std::uint16_t attribs); - - // print a range of formatted message to console - void print_range_(const memory_buf_t &formatted, size_t start, size_t end); - - // in case we are redirected to file (not in console mode) - void write_to_file_(const memory_buf_t &formatted); - - void set_color_mode_impl(color_mode mode); -}; - -template -class wincolor_stdout_sink : public wincolor_sink { -public: - explicit wincolor_stdout_sink(color_mode mode = color_mode::automatic); -}; - -template -class wincolor_stderr_sink : public wincolor_sink { -public: - explicit wincolor_stderr_sink(color_mode mode = color_mode::automatic); -}; - -using wincolor_stdout_sink_mt = wincolor_stdout_sink; -using wincolor_stdout_sink_st = wincolor_stdout_sink; - -using wincolor_stderr_sink_mt = wincolor_stderr_sink; -using wincolor_stderr_sink_st = wincolor_stderr_sink; -} // namespace sinks -} // namespace spdlog - -#ifdef SPDLOG_HEADER_ONLY - #include "wincolor_sink-inl.h" -#endif diff --git a/examples/blueprints-example/external/spdlog/spdlog-inl.h b/examples/blueprints-example/external/spdlog/spdlog-inl.h deleted file mode 100644 index e02081f..0000000 --- a/examples/blueprints-example/external/spdlog/spdlog-inl.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#ifndef SPDLOG_HEADER_ONLY - #include -#endif - -#include -#include - -namespace spdlog { - -SPDLOG_INLINE void initialize_logger(std::shared_ptr logger) { - details::registry::instance().initialize_logger(std::move(logger)); -} - -SPDLOG_INLINE std::shared_ptr get(const std::string &name) { - return details::registry::instance().get(name); -} - -SPDLOG_INLINE void set_formatter(std::unique_ptr formatter) { - details::registry::instance().set_formatter(std::move(formatter)); -} - -SPDLOG_INLINE void set_pattern(std::string pattern, pattern_time_type time_type) { - set_formatter( - std::unique_ptr(new pattern_formatter(std::move(pattern), time_type))); -} - -SPDLOG_INLINE void enable_backtrace(size_t n_messages) { - details::registry::instance().enable_backtrace(n_messages); -} - -SPDLOG_INLINE void disable_backtrace() { details::registry::instance().disable_backtrace(); } - -SPDLOG_INLINE void dump_backtrace() { default_logger_raw()->dump_backtrace(); } - -SPDLOG_INLINE level::level_enum get_level() { return default_logger_raw()->level(); } - -SPDLOG_INLINE bool should_log(level::level_enum log_level) { - return default_logger_raw()->should_log(log_level); -} - -SPDLOG_INLINE void set_level(level::level_enum log_level) { - details::registry::instance().set_level(log_level); -} - -SPDLOG_INLINE void flush_on(level::level_enum log_level) { - details::registry::instance().flush_on(log_level); -} - -SPDLOG_INLINE void set_error_handler(void (*handler)(const std::string &msg)) { - details::registry::instance().set_error_handler(handler); -} - -SPDLOG_INLINE void register_logger(std::shared_ptr logger) { - details::registry::instance().register_logger(std::move(logger)); -} - -SPDLOG_INLINE void register_or_replace(std::shared_ptr logger) { - details::registry::instance().register_or_replace(std::move(logger)); -} - -SPDLOG_INLINE void apply_all(const std::function)> &fun) { - details::registry::instance().apply_all(fun); -} - -SPDLOG_INLINE void drop(const std::string &name) { details::registry::instance().drop(name); } - -SPDLOG_INLINE void drop_all() { details::registry::instance().drop_all(); } - -SPDLOG_INLINE void shutdown() { details::registry::instance().shutdown(); } - -SPDLOG_INLINE void set_automatic_registration(bool automatic_registration) { - details::registry::instance().set_automatic_registration(automatic_registration); -} - -SPDLOG_INLINE std::shared_ptr default_logger() { - return details::registry::instance().default_logger(); -} - -SPDLOG_INLINE spdlog::logger *default_logger_raw() { - return details::registry::instance().get_default_raw(); -} - -SPDLOG_INLINE void set_default_logger(std::shared_ptr default_logger) { - details::registry::instance().set_default_logger(std::move(default_logger)); -} - -SPDLOG_INLINE void apply_logger_env_levels(std::shared_ptr logger) { - details::registry::instance().apply_logger_env_levels(std::move(logger)); -} - -} // namespace spdlog diff --git a/examples/blueprints-example/external/spdlog/spdlog.h b/examples/blueprints-example/external/spdlog/spdlog.h deleted file mode 100644 index 1a927ff..0000000 --- a/examples/blueprints-example/external/spdlog/spdlog.h +++ /dev/null @@ -1,357 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -// spdlog main header file. -// see example.cpp for usage example - -#ifndef SPDLOG_H -#define SPDLOG_H - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -namespace spdlog { - -using default_factory = synchronous_factory; - -// Create and register a logger with a templated sink type -// The logger's level, formatter and flush level will be set according to the -// global settings. -// -// Example: -// spdlog::create("logger_name", "dailylog_filename", 11, 59); -template -inline std::shared_ptr create(std::string logger_name, SinkArgs &&...sink_args) { - return default_factory::create(std::move(logger_name), - std::forward(sink_args)...); -} - -// Initialize and register a logger, -// formatter and flush level will be set according the global settings. -// -// Useful for initializing manually created loggers with the global settings. -// -// Example: -// auto mylogger = std::make_shared("mylogger", ...); -// spdlog::initialize_logger(mylogger); -SPDLOG_API void initialize_logger(std::shared_ptr logger); - -// Return an existing logger or nullptr if a logger with such a name doesn't -// exist. -// example: spdlog::get("my_logger")->info("hello {}", "world"); -SPDLOG_API std::shared_ptr get(const std::string &name); - -// Set global formatter. Each sink in each logger will get a clone of this object -SPDLOG_API void set_formatter(std::unique_ptr formatter); - -// Set global format string. -// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v"); -SPDLOG_API void set_pattern(std::string pattern, - pattern_time_type time_type = pattern_time_type::local); - -// enable global backtrace support -SPDLOG_API void enable_backtrace(size_t n_messages); - -// disable global backtrace support -SPDLOG_API void disable_backtrace(); - -// call dump backtrace on default logger -SPDLOG_API void dump_backtrace(); - -// Get global logging level -SPDLOG_API level::level_enum get_level(); - -// Set the global logging level -SPDLOG_API void set_level(level::level_enum log_level); - -// Determine whether the default logger should log messages with a certain level -SPDLOG_API bool should_log(level::level_enum lvl); - -// Set a global flush level -SPDLOG_API void flush_on(level::level_enum log_level); - -// Start/Restart a periodic flusher thread -// Warning: Use only if all your loggers are thread safe! -template -inline void flush_every(std::chrono::duration interval) { - details::registry::instance().flush_every(interval); -} - -// Set global error handler -SPDLOG_API void set_error_handler(void (*handler)(const std::string &msg)); - -// Register the given logger with the given name -// Will throw if a logger with the same name already exists. -SPDLOG_API void register_logger(std::shared_ptr logger); - -// Register the given logger with the given name -// Will replace any existing logger with the same name. -SPDLOG_API void register_or_replace(std::shared_ptr logger); - -// Apply a user-defined function on all registered loggers -// Example: -// spdlog::apply_all([&](std::shared_ptr l) {l->flush();}); -SPDLOG_API void apply_all(const std::function)> &fun); - -// Drop the reference to the given logger -SPDLOG_API void drop(const std::string &name); - -// Drop all references from the registry -SPDLOG_API void drop_all(); - -// stop any running threads started by spdlog and clean registry loggers -SPDLOG_API void shutdown(); - -// Automatic registration of loggers when using spdlog::create() or spdlog::create_async -SPDLOG_API void set_automatic_registration(bool automatic_registration); - -// API for using default logger (stdout_color_mt), -// e.g.: spdlog::info("Message {}", 1); -// -// The default logger object can be accessed using the spdlog::default_logger(): -// For example, to add another sink to it: -// spdlog::default_logger()->sinks().push_back(some_sink); -// -// The default logger can be replaced using spdlog::set_default_logger(new_logger). -// For example, to replace it with a file logger. -// -// IMPORTANT: -// The default API is thread safe (for _mt loggers), but: -// set_default_logger() *should not* be used concurrently with the default API. -// e.g., do not call set_default_logger() from one thread while calling spdlog::info() from another. - -SPDLOG_API std::shared_ptr default_logger(); - -SPDLOG_API spdlog::logger *default_logger_raw(); - -SPDLOG_API void set_default_logger(std::shared_ptr default_logger); - -// Initialize logger level based on environment configs. -// -// Useful for applying SPDLOG_LEVEL to manually created loggers. -// -// Example: -// auto mylogger = std::make_shared("mylogger", ...); -// spdlog::apply_logger_env_levels(mylogger); -SPDLOG_API void apply_logger_env_levels(std::shared_ptr logger); - -template -inline void log(source_loc source, - level::level_enum lvl, - format_string_t fmt, - Args &&...args) { - default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); -} - -template -inline void log(level::level_enum lvl, format_string_t fmt, Args &&...args) { - default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); -} - -template -inline void trace(format_string_t fmt, Args &&...args) { - default_logger_raw()->trace(fmt, std::forward(args)...); -} - -template -inline void debug(format_string_t fmt, Args &&...args) { - default_logger_raw()->debug(fmt, std::forward(args)...); -} - -template -inline void info(format_string_t fmt, Args &&...args) { - default_logger_raw()->info(fmt, std::forward(args)...); -} - -template -inline void warn(format_string_t fmt, Args &&...args) { - default_logger_raw()->warn(fmt, std::forward(args)...); -} - -template -inline void error(format_string_t fmt, Args &&...args) { - default_logger_raw()->error(fmt, std::forward(args)...); -} - -template -inline void critical(format_string_t fmt, Args &&...args) { - default_logger_raw()->critical(fmt, std::forward(args)...); -} - -template -inline void log(source_loc source, level::level_enum lvl, const T &msg) { - default_logger_raw()->log(source, lvl, msg); -} - -template -inline void log(level::level_enum lvl, const T &msg) { - default_logger_raw()->log(lvl, msg); -} - -#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT -template -inline void log(source_loc source, - level::level_enum lvl, - wformat_string_t fmt, - Args &&...args) { - default_logger_raw()->log(source, lvl, fmt, std::forward(args)...); -} - -template -inline void log(level::level_enum lvl, wformat_string_t fmt, Args &&...args) { - default_logger_raw()->log(source_loc{}, lvl, fmt, std::forward(args)...); -} - -template -inline void trace(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->trace(fmt, std::forward(args)...); -} - -template -inline void debug(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->debug(fmt, std::forward(args)...); -} - -template -inline void info(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->info(fmt, std::forward(args)...); -} - -template -inline void warn(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->warn(fmt, std::forward(args)...); -} - -template -inline void error(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->error(fmt, std::forward(args)...); -} - -template -inline void critical(wformat_string_t fmt, Args &&...args) { - default_logger_raw()->critical(fmt, std::forward(args)...); -} -#endif - -template -inline void trace(const T &msg) { - default_logger_raw()->trace(msg); -} - -template -inline void debug(const T &msg) { - default_logger_raw()->debug(msg); -} - -template -inline void info(const T &msg) { - default_logger_raw()->info(msg); -} - -template -inline void warn(const T &msg) { - default_logger_raw()->warn(msg); -} - -template -inline void error(const T &msg) { - default_logger_raw()->error(msg); -} - -template -inline void critical(const T &msg) { - default_logger_raw()->critical(msg); -} - -} // namespace spdlog - -// -// enable/disable log calls at compile time according to global level. -// -// define SPDLOG_ACTIVE_LEVEL to one of those (before including spdlog.h): -// SPDLOG_LEVEL_TRACE, -// SPDLOG_LEVEL_DEBUG, -// SPDLOG_LEVEL_INFO, -// SPDLOG_LEVEL_WARN, -// SPDLOG_LEVEL_ERROR, -// SPDLOG_LEVEL_CRITICAL, -// SPDLOG_LEVEL_OFF -// - -#ifndef SPDLOG_NO_SOURCE_LOC - #define SPDLOG_LOGGER_CALL(logger, level, ...) \ - (logger)->log(spdlog::source_loc{__FILE__, __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__) -#else - #define SPDLOG_LOGGER_CALL(logger, level, ...) \ - (logger)->log(spdlog::source_loc{}, level, __VA_ARGS__) -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE - #define SPDLOG_LOGGER_TRACE(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::trace, __VA_ARGS__) - #define SPDLOG_TRACE(...) SPDLOG_LOGGER_TRACE(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_TRACE(logger, ...) (void)0 - #define SPDLOG_TRACE(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG - #define SPDLOG_LOGGER_DEBUG(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::debug, __VA_ARGS__) - #define SPDLOG_DEBUG(...) SPDLOG_LOGGER_DEBUG(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_DEBUG(logger, ...) (void)0 - #define SPDLOG_DEBUG(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_INFO - #define SPDLOG_LOGGER_INFO(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::info, __VA_ARGS__) - #define SPDLOG_INFO(...) SPDLOG_LOGGER_INFO(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_INFO(logger, ...) (void)0 - #define SPDLOG_INFO(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_WARN - #define SPDLOG_LOGGER_WARN(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::warn, __VA_ARGS__) - #define SPDLOG_WARN(...) SPDLOG_LOGGER_WARN(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_WARN(logger, ...) (void)0 - #define SPDLOG_WARN(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_ERROR - #define SPDLOG_LOGGER_ERROR(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::err, __VA_ARGS__) - #define SPDLOG_ERROR(...) SPDLOG_LOGGER_ERROR(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_ERROR(logger, ...) (void)0 - #define SPDLOG_ERROR(...) (void)0 -#endif - -#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_CRITICAL - #define SPDLOG_LOGGER_CRITICAL(logger, ...) \ - SPDLOG_LOGGER_CALL(logger, spdlog::level::critical, __VA_ARGS__) - #define SPDLOG_CRITICAL(...) SPDLOG_LOGGER_CRITICAL(spdlog::default_logger_raw(), __VA_ARGS__) -#else - #define SPDLOG_LOGGER_CRITICAL(logger, ...) (void)0 - #define SPDLOG_CRITICAL(...) (void)0 -#endif - -#ifdef SPDLOG_HEADER_ONLY - #include "spdlog-inl.h" -#endif - -#endif // SPDLOG_H diff --git a/examples/blueprints-example/external/spdlog/stopwatch.h b/examples/blueprints-example/external/spdlog/stopwatch.h deleted file mode 100644 index 54ab3d3..0000000 --- a/examples/blueprints-example/external/spdlog/stopwatch.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -// Stopwatch support for spdlog (using std::chrono::steady_clock). -// Displays elapsed seconds since construction as double. -// -// Usage: -// -// spdlog::stopwatch sw; -// ... -// spdlog::debug("Elapsed: {} seconds", sw); => "Elapsed 0.005116733 seconds" -// spdlog::info("Elapsed: {:.6} seconds", sw); => "Elapsed 0.005163 seconds" -// -// -// If other units are needed (e.g. millis instead of double), include "fmt/chrono.h" and use -// "duration_cast<..>(sw.elapsed())": -// -// #include -//.. -// using std::chrono::duration_cast; -// using std::chrono::milliseconds; -// spdlog::info("Elapsed {}", duration_cast(sw.elapsed())); => "Elapsed 5ms" - -namespace spdlog { -class stopwatch { - using clock = std::chrono::steady_clock; - std::chrono::time_point start_tp_; - -public: - stopwatch() - : start_tp_{clock::now()} {} - - std::chrono::duration elapsed() const { - return std::chrono::duration(clock::now() - start_tp_); - } - - std::chrono::milliseconds elapsed_ms() const { - return std::chrono::duration_cast(clock::now() - start_tp_); - } - - void reset() { start_tp_ = clock::now(); } -}; -} // namespace spdlog - -// Support for fmt formatting (e.g. "{:012.9}" or just "{}") -namespace -#ifdef SPDLOG_USE_STD_FORMAT - std -#else - fmt -#endif -{ - -template <> -struct formatter : formatter { - template - auto format(const spdlog::stopwatch &sw, FormatContext &ctx) const -> decltype(ctx.out()) { - return formatter::format(sw.elapsed().count(), ctx); - } -}; -} // namespace std diff --git a/examples/blueprints-example/external/spdlog/tweakme.h b/examples/blueprints-example/external/spdlog/tweakme.h deleted file mode 100644 index d609298..0000000 --- a/examples/blueprints-example/external/spdlog/tweakme.h +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -/////////////////////////////////////////////////////////////////////////////// -// -// Edit this file to squeeze more performance, and to customize supported -// features -// -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Under Linux, the much faster CLOCK_REALTIME_COARSE clock can be used. -// This clock is less accurate - can be off by dozens of millis - depending on -// the kernel HZ. -// Uncomment to use it instead of the regular clock. -// -// #define SPDLOG_CLOCK_COARSE -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment if source location logging is not needed. -// This will prevent spdlog from using __FILE__, __LINE__ and SPDLOG_FUNCTION -// -// #define SPDLOG_NO_SOURCE_LOC -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment if thread id logging is not needed (i.e. no %t in the log pattern). -// This will prevent spdlog from querying the thread id on each log call. -// -// WARNING: If the log pattern contains thread id (i.e, %t) while this flag is -// on, zero will be logged as thread id. -// -// #define SPDLOG_NO_THREAD_ID -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to prevent spdlog from using thread local storage. -// -// WARNING: if your program forks, UNCOMMENT this flag to prevent undefined -// thread ids in the children logs. -// -// #define SPDLOG_NO_TLS -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to avoid spdlog's usage of atomic log levels -// Use only if your code never modifies a logger's log levels concurrently by -// different threads. -// -// #define SPDLOG_NO_ATOMIC_LEVELS -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to enable usage of wchar_t for file names on Windows. -// -// #define SPDLOG_WCHAR_FILENAMES -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to override default eol ("\n" or "\r\n" under Linux/Windows) -// -// #define SPDLOG_EOL ";-)\n" -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to override default folder separators ("/" or "\\/" under -// Linux/Windows). Each character in the string is treated as a different -// separator. -// -// #define SPDLOG_FOLDER_SEPS "\\" -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to use your own copy of the fmt library instead of spdlog's copy. -// In this case spdlog will try to include so set your -I flag -// accordingly. -// -// #define SPDLOG_FMT_EXTERNAL -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to use C++20 std::format instead of fmt. -// -// #define SPDLOG_USE_STD_FORMAT -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to enable wchar_t support (convert to utf8) -// -// #define SPDLOG_WCHAR_TO_UTF8_SUPPORT -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to prevent child processes from inheriting log file descriptors -// -// #define SPDLOG_PREVENT_CHILD_FD -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to customize level names (e.g. "MY TRACE") -// -// #define SPDLOG_LEVEL_NAMES { "MY TRACE", "MY DEBUG", "MY INFO", "MY WARNING", "MY ERROR", "MY -// CRITICAL", "OFF" } -// -// For C++17 use string_view_literals: -// -// #include -// using namespace std::string_view_literals; -// #define SPDLOG_LEVEL_NAMES { "MY TRACE"sv, "MY DEBUG"sv, "MY INFO"sv, "MY WARNING"sv, "MY -// ERROR"sv, "MY CRITICAL"sv, "OFF"sv } -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to customize short level names (e.g. "MT") -// These can be longer than one character. -// -// #define SPDLOG_SHORT_LEVEL_NAMES { "T", "D", "I", "W", "E", "C", "O" } -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to disable default logger creation. -// This might save some (very) small initialization time if no default logger is needed. -// -// #define SPDLOG_DISABLE_DEFAULT_LOGGER -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment and set to compile time level with zero cost (default is INFO). -// Macros like SPDLOG_DEBUG(..), SPDLOG_INFO(..) will expand to empty statements if not enabled -// -// #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment (and change if desired) macro to use for function names. -// This is compiler dependent. -// __PRETTY_FUNCTION__ might be nicer in clang/gcc, and __FUNCTION__ in msvc. -// Defaults to __FUNCTION__ (should work on all compilers) if not defined. -// -// #ifdef __PRETTY_FUNCTION__ -// # define SPDLOG_FUNCTION __PRETTY_FUNCTION__ -// #else -// # define SPDLOG_FUNCTION __FUNCTION__ -// #endif -/////////////////////////////////////////////////////////////////////////////// diff --git a/examples/blueprints-example/external/spdlog/version.h b/examples/blueprints-example/external/spdlog/version.h deleted file mode 100644 index 69ff257..0000000 --- a/examples/blueprints-example/external/spdlog/version.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#define SPDLOG_VER_MAJOR 1 -#define SPDLOG_VER_MINOR 16 -#define SPDLOG_VER_PATCH 0 - -#define SPDLOG_TO_VERSION(major, minor, patch) (major * 10000 + minor * 100 + patch) -#define SPDLOG_VERSION SPDLOG_TO_VERSION(SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH) diff --git a/examples/blueprints-example/external/stopwatch.h b/examples/blueprints-example/external/stopwatch.h deleted file mode 100644 index 54ab3d3..0000000 --- a/examples/blueprints-example/external/stopwatch.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#include -#include - -// Stopwatch support for spdlog (using std::chrono::steady_clock). -// Displays elapsed seconds since construction as double. -// -// Usage: -// -// spdlog::stopwatch sw; -// ... -// spdlog::debug("Elapsed: {} seconds", sw); => "Elapsed 0.005116733 seconds" -// spdlog::info("Elapsed: {:.6} seconds", sw); => "Elapsed 0.005163 seconds" -// -// -// If other units are needed (e.g. millis instead of double), include "fmt/chrono.h" and use -// "duration_cast<..>(sw.elapsed())": -// -// #include -//.. -// using std::chrono::duration_cast; -// using std::chrono::milliseconds; -// spdlog::info("Elapsed {}", duration_cast(sw.elapsed())); => "Elapsed 5ms" - -namespace spdlog { -class stopwatch { - using clock = std::chrono::steady_clock; - std::chrono::time_point start_tp_; - -public: - stopwatch() - : start_tp_{clock::now()} {} - - std::chrono::duration elapsed() const { - return std::chrono::duration(clock::now() - start_tp_); - } - - std::chrono::milliseconds elapsed_ms() const { - return std::chrono::duration_cast(clock::now() - start_tp_); - } - - void reset() { start_tp_ = clock::now(); } -}; -} // namespace spdlog - -// Support for fmt formatting (e.g. "{:012.9}" or just "{}") -namespace -#ifdef SPDLOG_USE_STD_FORMAT - std -#else - fmt -#endif -{ - -template <> -struct formatter : formatter { - template - auto format(const spdlog::stopwatch &sw, FormatContext &ctx) const -> decltype(ctx.out()) { - return formatter::format(sw.elapsed().count(), ctx); - } -}; -} // namespace std diff --git a/examples/blueprints-example/external/tweakme.h b/examples/blueprints-example/external/tweakme.h deleted file mode 100644 index d609298..0000000 --- a/examples/blueprints-example/external/tweakme.h +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -/////////////////////////////////////////////////////////////////////////////// -// -// Edit this file to squeeze more performance, and to customize supported -// features -// -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Under Linux, the much faster CLOCK_REALTIME_COARSE clock can be used. -// This clock is less accurate - can be off by dozens of millis - depending on -// the kernel HZ. -// Uncomment to use it instead of the regular clock. -// -// #define SPDLOG_CLOCK_COARSE -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment if source location logging is not needed. -// This will prevent spdlog from using __FILE__, __LINE__ and SPDLOG_FUNCTION -// -// #define SPDLOG_NO_SOURCE_LOC -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment if thread id logging is not needed (i.e. no %t in the log pattern). -// This will prevent spdlog from querying the thread id on each log call. -// -// WARNING: If the log pattern contains thread id (i.e, %t) while this flag is -// on, zero will be logged as thread id. -// -// #define SPDLOG_NO_THREAD_ID -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to prevent spdlog from using thread local storage. -// -// WARNING: if your program forks, UNCOMMENT this flag to prevent undefined -// thread ids in the children logs. -// -// #define SPDLOG_NO_TLS -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to avoid spdlog's usage of atomic log levels -// Use only if your code never modifies a logger's log levels concurrently by -// different threads. -// -// #define SPDLOG_NO_ATOMIC_LEVELS -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to enable usage of wchar_t for file names on Windows. -// -// #define SPDLOG_WCHAR_FILENAMES -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to override default eol ("\n" or "\r\n" under Linux/Windows) -// -// #define SPDLOG_EOL ";-)\n" -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to override default folder separators ("/" or "\\/" under -// Linux/Windows). Each character in the string is treated as a different -// separator. -// -// #define SPDLOG_FOLDER_SEPS "\\" -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to use your own copy of the fmt library instead of spdlog's copy. -// In this case spdlog will try to include so set your -I flag -// accordingly. -// -// #define SPDLOG_FMT_EXTERNAL -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to use C++20 std::format instead of fmt. -// -// #define SPDLOG_USE_STD_FORMAT -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to enable wchar_t support (convert to utf8) -// -// #define SPDLOG_WCHAR_TO_UTF8_SUPPORT -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to prevent child processes from inheriting log file descriptors -// -// #define SPDLOG_PREVENT_CHILD_FD -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to customize level names (e.g. "MY TRACE") -// -// #define SPDLOG_LEVEL_NAMES { "MY TRACE", "MY DEBUG", "MY INFO", "MY WARNING", "MY ERROR", "MY -// CRITICAL", "OFF" } -// -// For C++17 use string_view_literals: -// -// #include -// using namespace std::string_view_literals; -// #define SPDLOG_LEVEL_NAMES { "MY TRACE"sv, "MY DEBUG"sv, "MY INFO"sv, "MY WARNING"sv, "MY -// ERROR"sv, "MY CRITICAL"sv, "OFF"sv } -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to customize short level names (e.g. "MT") -// These can be longer than one character. -// -// #define SPDLOG_SHORT_LEVEL_NAMES { "T", "D", "I", "W", "E", "C", "O" } -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment to disable default logger creation. -// This might save some (very) small initialization time if no default logger is needed. -// -// #define SPDLOG_DISABLE_DEFAULT_LOGGER -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment and set to compile time level with zero cost (default is INFO). -// Macros like SPDLOG_DEBUG(..), SPDLOG_INFO(..) will expand to empty statements if not enabled -// -// #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO -/////////////////////////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////////////////////////// -// Uncomment (and change if desired) macro to use for function names. -// This is compiler dependent. -// __PRETTY_FUNCTION__ might be nicer in clang/gcc, and __FUNCTION__ in msvc. -// Defaults to __FUNCTION__ (should work on all compilers) if not defined. -// -// #ifdef __PRETTY_FUNCTION__ -// # define SPDLOG_FUNCTION __PRETTY_FUNCTION__ -// #else -// # define SPDLOG_FUNCTION __FUNCTION__ -// #endif -/////////////////////////////////////////////////////////////////////////////// diff --git a/examples/blueprints-example/external/version.h b/examples/blueprints-example/external/version.h deleted file mode 100644 index 69ff257..0000000 --- a/examples/blueprints-example/external/version.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright(c) 2015-present, Gabi Melman & spdlog contributors. -// Distributed under the MIT License (http://opensource.org/licenses/MIT) - -#pragma once - -#define SPDLOG_VER_MAJOR 1 -#define SPDLOG_VER_MINOR 16 -#define SPDLOG_VER_PATCH 0 - -#define SPDLOG_TO_VERSION(major, minor, patch) (major * 10000 + minor * 100 + patch) -#define SPDLOG_VERSION SPDLOG_TO_VERSION(SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH) diff --git a/examples/blueprints-example/nodes.cpp b/examples/blueprints-example/nodes.cpp deleted file mode 100644 index a1af176..0000000 --- a/examples/blueprints-example/nodes.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "nodes.h" -#include "app.h" - -namespace NodeSpawner -{ - -// Helper macro to create and add node to container -#define SPAWN_NODE_IMPL(NAME, CONSTRUCTOR_ARGS, ...) \ -Node* NAME(App* app) \ -{ \ - int nodeId = app->GetNextId(); \ - Node newNode CONSTRUCTOR_ARGS; \ - __VA_ARGS__ \ - app->BuildNode(&newNode); \ - auto* rootContainer = app->GetActiveRootContainer(); \ - if (rootContainer) \ - return rootContainer->AddNode(newNode); \ - return nullptr; \ -} - -SPAWN_NODE_IMPL(SpawnInputActionNode, (nodeId, "InputAction Fire", ImColor(255, 128, 128)), - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Delegate); - newNode.Outputs.emplace_back(app->GetNextId(), "Pressed", PinType::Flow); - newNode.Outputs.emplace_back(app->GetNextId(), "Released", PinType::Flow); -) - -SPAWN_NODE_IMPL(SpawnBranchNode, (nodeId, "Branch"), - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); - newNode.Inputs.emplace_back(app->GetNextId(), "Condition", PinType::Bool); - newNode.Outputs.emplace_back(app->GetNextId(), "True", PinType::Flow); - newNode.Outputs.emplace_back(app->GetNextId(), "False", PinType::Flow); -) - -SPAWN_NODE_IMPL(SpawnDoNNode, (nodeId, "Do N"), - newNode.Inputs.emplace_back(app->GetNextId(), "Enter", PinType::Flow); - newNode.Inputs.emplace_back(app->GetNextId(), "N", PinType::Int); - newNode.Inputs.emplace_back(app->GetNextId(), "Reset", PinType::Flow); - newNode.Outputs.emplace_back(app->GetNextId(), "Exit", PinType::Flow); - newNode.Outputs.emplace_back(app->GetNextId(), "Counter", PinType::Int); -) - -SPAWN_NODE_IMPL(SpawnOutputActionNode, (nodeId, "OutputAction"), - newNode.Inputs.emplace_back(app->GetNextId(), "Sample", PinType::Float); - newNode.Outputs.emplace_back(app->GetNextId(), "Condition", PinType::Bool); - newNode.Inputs.emplace_back(app->GetNextId(), "Event", PinType::Delegate); -) - -SPAWN_NODE_IMPL(SpawnPrintStringNode, (nodeId, "Print String"), - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); - newNode.Inputs.emplace_back(app->GetNextId(), "In String", PinType::String); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Flow); -) - -SPAWN_NODE_IMPL(SpawnMessageNode, (nodeId, "", ImColor(128, 195, 248)), - newNode.Type = NodeType::Simple; - newNode.Outputs.emplace_back(app->GetNextId(), "Message", PinType::String); -) - -SPAWN_NODE_IMPL(SpawnSetTimerNode, (nodeId, "Set Timer", ImColor(128, 195, 248)), - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); - newNode.Inputs.emplace_back(app->GetNextId(), "Object", PinType::Object); - newNode.Inputs.emplace_back(app->GetNextId(), "Function Name", PinType::Function); - newNode.Inputs.emplace_back(app->GetNextId(), "Time", PinType::Float); - newNode.Inputs.emplace_back(app->GetNextId(), "Looping", PinType::Bool); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Flow); -) - -SPAWN_NODE_IMPL(SpawnLessNode, (nodeId, "<", ImColor(128, 195, 248)), - newNode.Type = NodeType::Simple; - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Float); - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Float); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Float); -) - -SPAWN_NODE_IMPL(SpawnWeirdNode, (nodeId, "o.O", ImColor(128, 195, 248)), - newNode.Type = NodeType::Simple; - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Float); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Float); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Float); -) - -SPAWN_NODE_IMPL(SpawnTraceByChannelNode, (nodeId, "Single Line Trace by Channel", ImColor(255, 128, 64)), - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); - newNode.Inputs.emplace_back(app->GetNextId(), "Start", PinType::Flow); - newNode.Inputs.emplace_back(app->GetNextId(), "End", PinType::Int); - newNode.Inputs.emplace_back(app->GetNextId(), "Trace Channel", PinType::Float); - newNode.Inputs.emplace_back(app->GetNextId(), "Trace Complex", PinType::Bool); - newNode.Inputs.emplace_back(app->GetNextId(), "Actors to Ignore", PinType::Int); - newNode.Inputs.emplace_back(app->GetNextId(), "Draw Debug Type", PinType::Bool); - newNode.Inputs.emplace_back(app->GetNextId(), "Ignore Self", PinType::Bool); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Flow); - newNode.Outputs.emplace_back(app->GetNextId(), "Out Hit", PinType::Float); - newNode.Outputs.emplace_back(app->GetNextId(), "Return Value", PinType::Bool); -) - -SPAWN_NODE_IMPL(SpawnTreeSequenceNode, (nodeId, "Sequence"), - newNode.Type = NodeType::Tree; - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Flow); -) - -SPAWN_NODE_IMPL(SpawnTreeTaskNode, (nodeId, "Move To"), - newNode.Type = NodeType::Tree; - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); -) - -SPAWN_NODE_IMPL(SpawnTreeTask2Node, (nodeId, "Random Wait"), - newNode.Type = NodeType::Tree; - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); -) - -SPAWN_NODE_IMPL(SpawnComment, (nodeId, "Test Comment"), - newNode.Type = NodeType::Comment; - newNode.Size = ImVec2(300, 200); -) - -SPAWN_NODE_IMPL(SpawnHoudiniTransformNode, (nodeId, "Transform"), - newNode.Type = NodeType::Houdini; - newNode.Inputs.emplace_back(app->GetNextId(), "Out", PinType::Flow); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Flow); -) - -SPAWN_NODE_IMPL(SpawnHoudiniGroupNode, (nodeId, "Group"), - newNode.Type = NodeType::Houdini; - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); - newNode.Inputs.emplace_back(app->GetNextId(), "", PinType::Flow); - newNode.Outputs.emplace_back(app->GetNextId(), "", PinType::Flow); -) - -#undef SPAWN_NODE_IMPL - -} // namespace NodeSpawner diff --git a/examples/blueprints-example/nodes.h b/examples/blueprints-example/nodes.h deleted file mode 100644 index 3e8b90d..0000000 --- a/examples/blueprints-example/nodes.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once -#include "types.h" - -class App; - -namespace NodeSpawner -{ - Node* SpawnInputActionNode(App* app); - Node* SpawnBranchNode(App* app); - Node* SpawnDoNNode(App* app); - Node* SpawnOutputActionNode(App* app); - Node* SpawnPrintStringNode(App* app); - Node* SpawnMessageNode(App* app); - Node* SpawnSetTimerNode(App* app); - Node* SpawnLessNode(App* app); - Node* SpawnWeirdNode(App* app); - Node* SpawnTraceByChannelNode(App* app); - Node* SpawnTreeSequenceNode(App* app); - Node* SpawnTreeTaskNode(App* app); - Node* SpawnTreeTask2Node(App* app); - Node* SpawnComment(App* app); - Node* SpawnHoudiniTransformNode(App* app); - Node* SpawnHoudiniGroupNode(App* app); -} - diff --git a/examples/blueprints-example/types.h b/examples/blueprints-example/types.h deleted file mode 100644 index 60f32e3..0000000 --- a/examples/blueprints-example/types.h +++ /dev/null @@ -1,191 +0,0 @@ -#pragma once -#define IMGUI_DEFINE_MATH_OPERATORS -#include -#include // For ImRect -#include -#include -#include -#include -#include "utilities/uuid_generator.h" - -namespace ed = ax::NodeEditor; - -// Return code constants -enum { - E_OK = 0 // Success return code -}; - -// Forward declarations -class ParameterNode; -enum class ParameterDisplayMode; - -// Block display modes -enum class BlockDisplayMode -{ - NameOnly, // Just block name (compact) - NameAndParameters // Block name + parameter labels (default) -}; - -enum class PinType -{ - Flow, - Bool, - Int, - Float, - String, - Object, - Function, - Delegate, -}; - -enum class PinKind -{ - Output, - Input -}; - -enum class NodeType -{ - Blueprint, - Simple, - Tree, - Comment, - Houdini, - Parameter, // Standalone parameter value node - Group // Group block node -}; - -struct Node; - -struct Pin -{ - ed::PinId ID; // Runtime ID (dynamic, for imgui-node-editor) - Uuid64 UUID; // Persistent ID (stable across sessions) - ::Node* Node; - std::string Name; - PinType Type; - PinKind Kind; - - // Position tracking (updated during rendering) - ImVec2 LastPivotPosition; // Where links connect (screen space) - ImRect LastRenderBounds; // Full pin area for hit testing - bool HasPositionData; // True after first render - - Pin(int id, const char* name, PinType type): - ID(id), UUID(0, 0), Node(nullptr), Name(name), Type(type), Kind(PinKind::Input), - LastPivotPosition(0, 0), LastRenderBounds(ImVec2(0,0), ImVec2(0,0)), HasPositionData(false) - { - } - - // Get pin position relative to its node (implementation after Node is defined) - ImVec2 GetRelativePivotPosition() const; -}; - -struct Node -{ - ed::NodeId ID; // Runtime ID (dynamic, for imgui-node-editor) - Uuid64 UUID; // Persistent ID (stable across sessions) - std::string Name; - std::vector Inputs; - std::vector Outputs; - ImColor Color; - NodeType Type; - ImVec2 Size; - - std::string State; - std::string SavedState; - - // Block metadata (only used when (Type == NodeType::Blueprint || Type == NodeType::Group) && IsBlockBased()) - std::string BlockType; // e.g. "Math.Add" or "Group" - empty for hardcoded nodes - bool IsBlockBased() const { return !BlockType.empty(); } - ::BlockDisplayMode BlockDisplay; // Display mode for blocks - class Block* BlockInstance; // Block class instance (owns rendering logic) - ONLY set for block-based nodes - - // Safe getter for BlockInstance - returns nullptr for non-block nodes - // Full validation (ID match, node type) should be done at call site after including block.h - class Block* GetBlockInstance() const { - // Only return BlockInstance for actual block-based nodes - if (Type == NodeType::Parameter || !IsBlockBased()) - return nullptr; - return BlockInstance; - } - - // Parameter node metadata (only used when Type == NodeType::Parameter) - PinType ParameterType; - union { - bool BoolValue; - int IntValue; - float FloatValue; - }; - std::string StringValue; // For string parameters - ParameterNode* ParameterInstance; // Parameter class instance (owned by node) - ONLY set for parameter nodes - - // Safe getter for ParameterInstance - returns nullptr for non-parameter nodes - ParameterNode* GetParameterInstance() const { - // Only return ParameterInstance for actual parameter nodes - if (Type != NodeType::Parameter) - return nullptr; - return ParameterInstance; - } - - // Unconnected parameter values (for block input parameters) - // Maps pin ID -> value (stored as string, parsed based on pin type) - std::map UnconnectedParamValues; - - Node(int id, const char* name, ImColor color = ImColor(255, 255, 255)): - ID(id), UUID(0, 0), Name(name), Color(color), Type(NodeType::Blueprint), Size(0, 0), BlockType(""), - BlockDisplay(::BlockDisplayMode::NameAndParameters), BlockInstance(nullptr), - ParameterType(PinType::Float), FloatValue(0.0f), StringValue(""), ParameterInstance(nullptr) - { - } -}; - -struct Link -{ - ed::LinkId ID; // Runtime ID (dynamic, for imgui-node-editor) - Uuid64 UUID; // Persistent ID (stable across sessions) - - ed::PinId StartPinID; - ed::PinId EndPinID; - - ImColor Color; - bool IsParameterLink; // True if parameter → block input (for styling) - bool UserManipulatedWaypoints; // True if user manually edited waypoints (preserve path, disable auto-adjust) - float Delay; // Custom delay unit (displayed on hover, editable via double-click) - - Link(ed::LinkId id, ed::PinId startPinId, ed::PinId endPinId): - ID(id), UUID(0, 0), StartPinID(startPinId), EndPinID(endPinId), Color(255, 255, 255), - IsParameterLink(false), UserManipulatedWaypoints(false), Delay(0.0f) - { - } -}; - -struct NodeIdLess -{ - bool operator()(const ed::NodeId& lhs, const ed::NodeId& rhs) const - { - return lhs.AsPointer() < rhs.AsPointer(); - } -}; - -struct LinkIdLess -{ - bool operator()(const ed::LinkId& lhs, const ed::LinkId& rhs) const - { - return lhs.AsPointer() < rhs.AsPointer(); - } -}; - -//------------------------------------------------------------------------------ -// Pin method implementations (after Node is fully defined) -//------------------------------------------------------------------------------ - -inline ImVec2 Pin::GetRelativePivotPosition() const -{ - if (Node && HasPositionData) - { - ImVec2 nodePos = ed::GetNodePosition(Node->ID); - return LastPivotPosition - nodePos; - } - return ImVec2(0, 0); -} diff --git a/examples/blueprints-example/utilities/LINK_FITTING.md b/examples/blueprints-example/utilities/LINK_FITTING.md deleted file mode 100644 index c59f464..0000000 --- a/examples/blueprints-example/utilities/LINK_FITTING.md +++ /dev/null @@ -1,172 +0,0 @@ -# Link Fitting - Horizontal Segment Alignment - -## Overview - -Link fitting is a **waypoint refinement pass** that automatically aligns horizontal link segments that are close together, creating a cleaner, more professional visual appearance in node graphs. - -## Feature - -When `ENABLE_LINK_FITTING` is defined (enabled by default), the system: - -1. **Detects horizontal segments** in link paths (segments where Y is constant, X changes) -2. **Analyzes ALL links** in the container (context-aware!) -3. **Groups segments** that are within 100 units vertically (across multiple links) -4. **Aligns grouped segments** to their average Y coordinate - -### Key Feature: Container-Aware Alignment - -The refinement pass is **context-aware** and looks at ALL links in the scene, not just the current link being processed. This means: -- When you create a second link, it will align with the first link's segments -- Multiple parallel links automatically align to create clean, professional layouts -- The alignment happens automatically as you create/modify links - -### Example - -**Before Link Fitting:** -``` -Int Node ─────────────┠(Y = 150) - │ - └──> Group Node - (Y = 180) -``` - -**After Link Fitting (when within 100 units):** -``` -Int Node ─────────────┠(Y = 165) - │ - └──> Group Node - (Y = 165) -``` - -## Configuration - -### Enable/Disable - -Configure in `examples/blueprints-example/utilities/pathfinding.cpp` (lines 9-12): - -```cpp -// Pathfinding feature flags (configure here) -#define WAYPOINT_DEBUG // Enable debug logging -#define ENABLE_LINK_FITTING // Align horizontal segments within 100 units -#define ENABLE_LINK_AUTO_COLLAPSE // Collapse waypoints to straight when within 100 units -``` - -**To disable a feature**, comment it out: -```cpp -// #define ENABLE_LINK_FITTING // Disabled -``` - -## Parameters - -### Alignment Tolerance - -Defined in `pathfinding.cpp` line 1002: - -```cpp -const float HORIZONTAL_ALIGNMENT_TOLERANCE = 100.0f; // Y-axis tolerance for alignment -``` - -**Adjust this value** to change how close segments must be to align: -- **Smaller** (e.g., 50.0f): Only very close segments align (stricter) -- **Larger** (e.g., 200.0f): More segments align (looser) - -## Implementation Details - -### Where It's Applied - -Link fitting is automatically applied in three scenarios: - -1. **New Link Creation** - When user drags a connection (line 2511) -2. **Auto-Adjustment** - When nodes move and waypoints regenerate (line 1386) -3. **Manual Guided Mode** - When user presses Space to switch to Guided mode (line 2087) - -### Algorithm - -The refinement pass: - -1. Builds full path for current link: `[StartPin] → [Waypoints] → [EndPin]` -2. Identifies horizontal segments in current link (Y constant, X differs by >1 pixel) -3. **Queries ALL other links** in the container via `RootContainer::GetAllLinks()` -4. Identifies horizontal segments in all other links (waypoint-to-waypoint) -5. Groups segments within `HORIZONTAL_ALIGNMENT_TOLERANCE` (across ALL links) -6. Calculates average Y for each group -7. Applies alignment ONLY to current link's segments (preserves other links) -8. Extracts refined waypoints (excludes start/end) - -### Performance - -- **O(n²)** worst case for grouping (n = number of horizontal segments) -- **Minimal overhead**: Only processes horizontal segments -- **Fast in practice**: Most links have 0-2 horizontal segments - -## Multi-Pass Architecture - -Link fitting is implemented as the **first refinement pass** in the multi-pass waypoint pipeline: - -```cpp -ctx.AddRefinementPass(PathFinding::RefinementPass_SmoothPath, nullptr, "Link Fitting"); -auto waypoints = PathFinding::GenerateWaypoints(ctx); -``` - -Additional passes can be chained: - -```cpp -ctx.AddRefinementPass(PathFinding::RefinementPass_SmoothPath, nullptr, "Link Fitting"); -ctx.AddRefinementPass(PathFinding::RefinementPass_AvoidLinkIntersections, nullptr, "Avoid Crossings"); -ctx.AddRefinementPass(PathFinding::RefinementPass_BundleParallelLinks, nullptr, "Bundle Links"); -``` - -## Debug Mode - -Enable debug logging with: - -```cpp -#define WAYPOINT_DEBUG -``` - -This will print: -- Number of horizontal segments found -- Number of segments in each alignment group -- Target Y coordinate for alignment - -## Auto-Collapse Feature - -### ENABLE_LINK_AUTO_COLLAPSE - -When enabled, automatically collapses guided links to straight lines when waypoints don't add significant routing value. - -**Collapse Conditions:** - -1. **Radius Check**: All waypoints fit within 100-unit bounding box -2. **Collinearity Check**: All waypoints lie on straight line (within 5 pixels) - -**Example:** - -``` -Guided Link: Pin1 ─→ WP1(10,10) ─→ WP2(15,15) ─→ Pin2 - (waypoints within 20 units) - ↓ -Collapsed: Pin1 ────────────────────────────→ Pin2 - (straight line, no waypoints) -``` - -**Parameters:** -- **Collapse Radius**: 100.0f (line 1225) -- **Collinear Tolerance**: 5.0f pixels (line 1274) - -## Future Enhancements - -Potential improvements: - -1. **Vertical segment alignment** (align segments at same X) -2. **Smart grid snapping** (align to multiples of grid size) -3. **Adaptive tolerance** (adjust based on zoom level) -4. **User preferences** (per-graph or per-link overrides) - -## Related Files - -- **Configuration**: `examples/blueprints-example/utilities/pathfinding.cpp` (lines 9-12) -- **Implementation**: `examples/blueprints-example/utilities/pathfinding.cpp` (lines 997, 1216) -- **Header**: `examples/blueprints-example/utilities/pathfinding.h` (lines 182, 201) -- **Usage**: `examples/blueprints-example/app-render.cpp` (lines 1384-1392, 2090-2098) - diff --git a/examples/blueprints-example/utilities/STANDARD_UUID_CONVERSION.md b/examples/blueprints-example/utilities/STANDARD_UUID_CONVERSION.md deleted file mode 100644 index 8f0c4bd..0000000 --- a/examples/blueprints-example/utilities/STANDARD_UUID_CONVERSION.md +++ /dev/null @@ -1,302 +0,0 @@ -# Standard UUID Format Conversion (RFC4122) - -Convert between standard UUID format (with dashes) and `Uuid64` structure. - -## Overview - -Standard UUIDs are **128-bit** (e.g., `9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d`) -Our `Uuid64` uses **64-bit** (two 32-bit words) - -**Conversion strategy**: Extract 64 bits from the 128-bit UUID - -## Quick Start - -```cpp -// Parse standard UUID string -ed::Uuid64 uuid = app->StandardStringToUuid("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"); - -// Convert back to standard format (zero-padded) -std::string standardStr = app->UuidToStandardString(uuid); -// Output: "00000000-0000-0000-9bdd2b0d-7b3dcb6d" -``` - -## Parsing Standard UUIDs - -### Example 1: Parse Full Standard UUID (Take Last 64 Bits) - -```cpp -// Standard UUID: "9b1deb4d-3b7d-4bad-9bdd-2b0d-7b3dcb6d" -// [--- 64 bits ---][--- 64 bits ---] -// ^^^^^^^^^^^^^^^^ -// We take these! - -ed::Uuid64 uuid = app->StandardStringToUuid("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"); - -printf("High: 0x%08x, Low: 0x%08x\n", uuid.high, uuid.low); -// Output: High: 0x9bdd2b0d, Low: 0x7b3dcb6d -``` - -### Example 2: Parse Full Standard UUID (Take First 64 Bits) - -```cpp -// Standard UUID: "9b1deb4d-3b7d-4bad-9bdd-2b0d-7b3dcb6d" -// [--- 64 bits ---][--- 64 bits ---] -// ^^^^^^^^^^^^^^^^ -// We take these! - -ed::Uuid64 uuid = app->StandardStringToUuid("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d", false); -// ^^^^^ -// takeLast64=false - -printf("High: 0x%08x, Low: 0x%08x\n", uuid.high, uuid.low); -// Output: High: 0x9b1deb4d, Low: 0x3b7d4bad -``` - -### Example 3: Direct Method Call - -```cpp -// Using Uuid64 static method directly -ed::Uuid64 uuid = ed::Uuid64::FromStandardUuidString("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"); - -// Or via app -ed::Uuid64 uuid2 = app->StandardStringToUuid("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"); -``` - -## Converting to Standard UUID Format - -### Example 1: Convert Uuid64 to Standard Format - -```cpp -ed::Uuid64 uuid(0x9bdd2b0d, 0x7b3dcb6d); - -std::string standardStr = app->UuidToStandardString(uuid); -printf("UUID: %s\n", standardStr.c_str()); -// Output: "00000000-0000-0000-9bdd2b0d-7b3dcb6d" - -// Or direct call -std::string standardStr2 = uuid.ToStandardUuidString(); -``` - -### Example 2: Zero-Padding Behavior - -```cpp -// Our 64-bit UUIDs are zero-padded in the upper 64 bits -ed::Uuid64 uuid(0x12345678, 0xabcdef90); - -std::string standardStr = uuid.ToStandardUuidString(); -printf("%s\n", standardStr.c_str()); -// Output: "00000000-0000-0000-12345678-abcdef90" -// ^^^^^^^^^^^^^^^^^^^^^^^ -// Always zero-padded -``` - -## Flexible Format Support - -The parser handles various formats: - -```cpp -// All of these work: -ed::Uuid64 uuid1 = app->StandardStringToUuid("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"); // Standard -ed::Uuid64 uuid2 = app->StandardStringToUuid("9b1deb4d3b7d4bad9bdd2b0d7b3dcb6d"); // No dashes -ed::Uuid64 uuid3 = app->StandardStringToUuid("9BDD2B0D7B3DCB6D"); // Uppercase, short -ed::Uuid64 uuid4 = app->StandardStringToUuid("9bdd2b0d-7b3dcb6d"); // Partial with dashes -``` - -## Real-World Use Cases - -### Use Case 1: Import from External System - -```cpp -// External system provides standard UUIDs -std::string externalUuid = "550e8400-e29b-41d4-a716-446655440000"; - -// Convert to our format -ed::Uuid64 internalId = app->StandardStringToUuid(externalUuid); - -// Use in our system -Node* node = new Node(); -node->SetId(internalId); - -printf("Imported node with ID: 0x%08x%08x\n", internalId.high, internalId.low); -``` - -### Use Case 2: Export for External Systems - -```cpp -// Our internal ID -ed::Uuid64 nodeId = app->GenerateRandomUuid64(); - -// Export as standard UUID for external API -std::string exportedUuid = app->UuidToStandardString(nodeId); - -// Send to external system -ExternalAPI::CreateResource(exportedUuid); -// They receive: "00000000-0000-0000-12345678-abcdef90" -``` - -### Use Case 3: Database Storage - -```cpp -// Store in database as standard UUID string -void SaveNode(Node* node) -{ - std::string uuidStr = app->UuidToStandardString(node->GetUuid64()); - - Database::Execute( - "INSERT INTO nodes (id, name) VALUES (?, ?)", - uuidStr, - node->GetName() - ); -} - -// Load from database -Node* LoadNode(const std::string& dbUuidStr) -{ - ed::Uuid64 uuid = app->StandardStringToUuid(dbUuidStr); - return FindNodeByUuid(uuid); -} -``` - -### Use Case 4: JSON Import/Export - -```cpp -// Export to JSON -json nodeData; -ed::Uuid64 id = node->GetUuid64(); -nodeData["id"] = app->UuidToStandardString(id); -// JSON: { "id": "00000000-0000-0000-12345678-abcdef90" } - -// Import from JSON -std::string uuidStr = nodeData["id"].get(); -ed::Uuid64 loadedId = app->StandardStringToUuid(uuidStr); -``` - -### Use Case 5: URL Parameters - -```cpp -// Generate shareable link with standard UUID -ed::Uuid64 sessionId = app->GenerateRandomUuid64(); -std::string shareUrl = "https://example.com/session/" + - app->UuidToStandardString(sessionId); -// URL: https://example.com/session/00000000-0000-0000-12345678-abcdef90 - -// Parse from URL -std::string uuidFromUrl = ExtractUuidFromUrl(url); -ed::Uuid64 session = app->StandardStringToUuid(uuidFromUrl); -``` - -## Format Details - -### Standard UUID Format (RFC4122) - -``` -9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d -├─────┤ ├──┤ ├──┤ ├──┤ ├──────────┤ -8 hex 4 4 4 12 hex chars -chars hex hex hex - -Total: 36 characters (32 hex + 4 dashes) -Represents: 128 bits (16 bytes) -``` - -### Our Uuid64 Format - -``` -Uuid64 { high: 0x9bdd2b0d, low: 0x7b3dcb6d } - ├──────────┤ ├──────────┤ - 32 bits 32 bits - -Total: 64 bits (8 bytes) -``` - -### Conversion Mapping - -``` -Standard UUID (128-bit): -9b1deb4d-3b7d-4bad-9bdd-2b0d-7b3dcb6d -└─────────────────┘└─────────────────┘ - First 64 bits Last 64 bits - (takeLast64=false) (takeLast64=true, default) - -takeLast64=true (default): - Input: "9b1deb4d-3b7d-4bad-9bdd-2b0d-7b3dcb6d" - Output: Uuid64(0x9bdd2b0d, 0x7b3dcb6d) - -takeLast64=false: - Input: "9b1deb4d-3b7d-4bad-9bdd-2b0d-7b3dcb6d" - Output: Uuid64(0x9b1deb4d, 0x3b7d4bad) -``` - -## Error Handling - -```cpp -// Invalid formats return zero UUID -ed::Uuid64 invalid1 = app->StandardStringToUuid(""); // Empty -ed::Uuid64 invalid2 = app->StandardStringToUuid("not-a-uuid"); // Invalid chars -ed::Uuid64 invalid3 = app->StandardStringToUuid("12345"); // Too short - -// Check if parsing succeeded -ed::Uuid64 uuid = app->StandardStringToUuid(someString); -if (!uuid.IsValid()) -{ - printf("Failed to parse UUID\n"); -} -``` - -## API Reference - -### App Class Methods - -```cpp -// Convert to standard UUID string (with dashes) -std::string UuidToStandardString(const ed::Uuid64& uuid); - -// Parse standard UUID string (with or without dashes) -// takeLast64: true = use last 64 bits, false = use first 64 bits -ed::Uuid64 StandardStringToUuid(const std::string& uuidStr, bool takeLast64 = true); -``` - -### Uuid64 Structure Methods - -```cpp -// Convert to standard UUID format -std::string ToStandardUuidString() const; - -// Parse from standard UUID format -static Uuid64 FromStandardUuidString(const std::string& uuidStr, bool takeLast64 = true); -``` - -## Best Practices - -### ✅ DO: -- Use `takeLast64=true` (default) for consistency -- Validate parsed UUIDs with `IsValid()` -- Document which 64 bits you're using in your API -- Store original 128-bit UUID if you need to preserve it - -### ⌠DON'T: -- Assume round-trip conversion preserves the original 128-bit UUID -- Mix `takeLast64=true` and `takeLast64=false` without documentation -- Use standard format for internal IDs (use hex format for efficiency) - -## Interoperability Matrix - -| External System | Provides | We Extract | Round-Trip? | -|----------------|----------|------------|-------------| -| UUIDv4 APIs | 128-bit | Last 64 bits | ⌠Lost upper 64 bits | -| PostgreSQL UUID | 128-bit | Last 64 bits | ⌠Lost upper 64 bits | -| MongoDB ObjectId | 96-bit | Last 64 bits | ⌠Lost upper 32 bits | -| Our System | 64-bit | All | ✅ Perfect | - -**Note**: Converting 128-bit UUIDs to 64-bit is **lossy**. The upper 64 bits are discarded. - -## Summary - -- ✅ Parse standard UUID format: `"9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"` -- ✅ Convert to standard format: `"00000000-0000-0000-HHHHHHHH-LLLLLLLL"` -- ✅ Flexible parsing (with/without dashes, any length) -- ✅ Choose which 64 bits to extract (`takeLast64` parameter) -- âš ï¸ **Lossy conversion**: 128-bit → 64-bit discards data -- ✅ Perfect for importing external UUIDs into your system -- ✅ Export format compatible with standard UUID parsers - diff --git a/examples/blueprints-example/utilities/UUID64_USAGE.md b/examples/blueprints-example/utilities/UUID64_USAGE.md deleted file mode 100644 index 26168f8..0000000 --- a/examples/blueprints-example/utilities/UUID64_USAGE.md +++ /dev/null @@ -1,324 +0,0 @@ -# 64-bit UUID using Dual 32-bit Words (Microcontroller Compatible) - -Perfect for **100,000+ items** while maintaining compatibility with 32-bit microcontrollers! - -## Why Dual 32-bit Words? - -- ✅ **Microcontroller Compatible**: Works on platforms without native 64-bit support -- ✅ **Zero Collisions**: ~0.0000000027% collision risk for 100k items -- ✅ **18 Quintillion Space**: 18,446,744,073,709,551,616 unique IDs -- ✅ **Efficient**: Only two 32-bit operations, no 64-bit arithmetic required -- ✅ **Serializable**: Easy to save/load as two separate fields - -## Uuid64 Structure - -```cpp -struct Uuid64 -{ - uint32_t high; // Upper 32 bits - uint32_t low; // Lower 32 bits -}; -``` - -## Basic Usage - -### Generate UUIDs - -```cpp -// Random 64-bit UUID (virtually collision-free) -ed::Uuid64 uuid = app->GenerateRandomUuid64(); -// Example: { high: 0x50626ea, low: 0x1b7c7646 } - -// Sequential 64-bit UUID (guaranteed unique) -ed::Uuid64 seqUuid = app->GenerateSequentialUuid64(); -// Example: { high: 0x1000000, low: 0x0 } -// { high: 0x1000000, low: 0x1 } -// { high: 0x1000000, low: 0x2 } -``` - -### Convert to/from Hex String - -```cpp -// Convert to string -ed::Uuid64 uuid = app->GenerateRandomUuid64(); -std::string hexStr = app->UuidToHexString64(uuid); -// Output: "0x50626ea1b7c7646" - -// Parse from string -ed::Uuid64 parsed = app->HexStringToUuid64("0x50626ea1b7c7646"); -// Result: { high: 0x50626ea, low: 0x1b7c7646 } -``` - -### Access Individual Words - -```cpp -ed::Uuid64 uuid = app->GenerateRandomUuid64(); - -// Access 32-bit words directly -uint32_t highWord = uuid.high; // Upper 32 bits -uint32_t lowWord = uuid.low; // Lower 32 bits - -// Construct from two 32-bit values -ed::Uuid64 custom(0x1234ABCD, 0x5678EF90); -``` - -### Validation - -```cpp -ed::Uuid64 uuid = app->GenerateRandomUuid64(); - -// Check if valid (non-zero) -if (uuid.IsValid()) -{ - printf("UUID is valid\n"); -} - -// Compare UUIDs -ed::Uuid64 uuid1 = app->GenerateRandomUuid64(); -ed::Uuid64 uuid2 = app->GenerateRandomUuid64(); - -if (uuid1 == uuid2) - printf("Same UUID\n"); - -if (uuid1 != uuid2) - printf("Different UUIDs\n"); -``` - -## Standard UUID Format (RFC4122) Conversion - -Convert between standard UUID format and `Uuid64`: - -```cpp -// Parse standard UUID format (with dashes) -ed::Uuid64 uuid = app->StandardStringToUuid("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"); -// Result: { high: 0x9bdd2b0d, low: 0x7b3dcb6d } (takes last 64 bits) - -// Convert to standard format (zero-padded) -std::string standardStr = app->UuidToStandardString(uuid); -// Output: "00000000-0000-0000-9bdd2b0d-7b3dcb6d" - -// Parse with first 64 bits instead -ed::Uuid64 uuid2 = app->StandardStringToUuid("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d", false); -// Result: { high: 0x9b1deb4d, low: 0x3b7d4bad } (takes first 64 bits) -``` - -**For detailed examples, see `STANDARD_UUID_CONVERSION.md`** - -## Use in Maps and Sets - -```cpp -// Uuid64 has comparison operators for std::map/std::set -std::map nodeMap; -std::set uniqueIds; - -ed::Uuid64 id = app->GenerateRandomUuid64(); -nodeMap[id] = myNode; -uniqueIds.insert(id); -``` - -## Microcontroller-Friendly Operations - -### Without 64-bit Arithmetic - -```cpp -// Generate on MCU - uses only 32-bit operations -ed::Uuid64 id = app->GenerateSequentialUuid64(); - -// Access as two 32-bit values -uint32_t high = id.high; -uint32_t low = id.low; - -// Send over network as two separate 32-bit packets -SendPacket(high); -SendPacket(low); - -// Receive and reconstruct -uint32_t receivedHigh = ReceivePacket(); -uint32_t receivedLow = ReceivePacket(); -ed::Uuid64 reconstructed(receivedHigh, receivedLow); -``` - -### With 64-bit Support (Optional) - -```cpp -// If platform supports uint64_t, you can convert -ed::Uuid64 uuid = app->GenerateRandomUuid64(); -uint64_t fullValue = uuid.ToUint64(); - -// And back -ed::Uuid64 reconstructed = ed::Uuid64::FromUint64(fullValue); -``` - -## JSON Serialization Examples - -### Option 1: Separate Fields (Recommended for MCU) - -```cpp -// Save -json nodeData; -ed::Uuid64 id = app->GenerateRandomUuid64(); -nodeData["id_high"] = id.high; -nodeData["id_low"] = id.low; - -// Load -ed::Uuid64 loadedId( - nodeData["id_high"].get(), - nodeData["id_low"].get() -); -``` - -### Option 2: Hex String - -```cpp -// Save -json nodeData; -ed::Uuid64 id = app->GenerateRandomUuid64(); -nodeData["id"] = app->UuidToHexString64(id); - -// Load -std::string hexId = nodeData["id"].get(); -ed::Uuid64 loadedId = app->HexStringToUuid64(hexId); -``` - -### Option 3: Single 64-bit Value (if platform supports) - -```cpp -// Save (requires uint64_t support) -json nodeData; -ed::Uuid64 id = app->GenerateRandomUuid64(); -nodeData["id"] = id.ToUint64(); - -// Load -uint64_t value = nodeData["id"].get(); -ed::Uuid64 loadedId = ed::Uuid64::FromUint64(value); -``` - -## Real-World Examples - -### Example 1: Node IDs for Large Graph (100k+ nodes) - -```cpp -// Use sequential for guaranteed uniqueness and debugging -ed::Uuid64 nodeId = app->GenerateSequentialUuid64(); -Node* node = new Node(); -node->SetUuid64(nodeId); - -printf("Created node: %s\n", app->UuidToHexString64(nodeId).c_str()); -// Output: Created node: 0x100000000000000 -``` - -### Example 2: Random IDs for Distributed System - -```cpp -// Each client generates random IDs - virtually no collision -ed::Uuid64 clientId = app->GenerateRandomUuid64(); -ed::Uuid64 sessionId = app->GenerateRandomUuid64(); - -// 100k items across 1000 clients = ~0% collision probability -``` - -### Example 3: Sending Over Serial (MCU) - -```cpp -// Transmit UUID as two 32-bit values -void SendUuid(const ed::Uuid64& uuid) -{ - Serial.write((uint8_t*)&uuid.high, 4); // Send 4 bytes - Serial.write((uint8_t*)&uuid.low, 4); // Send 4 bytes -} - -// Receive UUID as two 32-bit values -ed::Uuid64 ReceiveUuid() -{ - uint32_t high, low; - Serial.readBytes((uint8_t*)&high, 4); - Serial.readBytes((uint8_t*)&low, 4); - return ed::Uuid64(high, low); -} -``` - -### Example 4: Persistent Storage (EEPROM/Flash) - -```cpp -// Write to EEPROM (8 bytes total) -void SaveUuidToEEPROM(const ed::Uuid64& uuid, int address) -{ - EEPROM.put(address, uuid.high); // 4 bytes - EEPROM.put(address + 4, uuid.low); // 4 bytes -} - -// Read from EEPROM -ed::Uuid64 LoadUuidFromEEPROM(int address) -{ - uint32_t high, low; - EEPROM.get(address, high); - EEPROM.get(address + 4, low); - return ed::Uuid64(high, low); -} -``` - -## Collision Analysis for 100k Items - -| UUID Type | Space | Collision Risk | -|-----------|-------|----------------| -| 32-bit Random | 4.28 billion | **68.9% âŒ** | -| 32-bit Sequential | 4.28 billion | **0% ✅** | -| **64-bit Random** | **18.4 quintillion** | **~0% ✅** | -| **64-bit Sequential** | **18.4 quintillion** | **0% ✅** | - -**Calculation for 64-bit random UUIDs:** -``` -P(collision) = 1 - e^(-n²/(2d)) -n = 100,000 -d = 18,446,744,073,709,551,616 - -P(collision) ≈ 0.0000000027% (essentially zero) -``` - -## Performance Characteristics - -| Operation | 32-bit UUID | 64-bit UUID (Dual Word) | -|-----------|-------------|-------------------------| -| Generation | 1x random call | 2x random calls | -| Comparison | 1 compare | 2 compares | -| Storage | 4 bytes | 8 bytes | -| Collision Risk (100k) | 68.9% | ~0% | - -## When to Use - -### Use 64-bit (Dual 32-bit) UUIDs when: -- ✅ You need **100k+ items** with random IDs -- ✅ Working with **distributed systems** -- ✅ Collision risk must be **virtually zero** -- ✅ Still need **microcontroller compatibility** - -### Use 32-bit UUIDs when: -- ✅ Total items **< 10,000** -- ✅ Using **sequential generation** -- ✅ Need **minimal memory** (4 bytes vs 8 bytes) - -## Migration Path - -```cpp -// If you have existing 32-bit UUIDs -uint32_t oldId = 0x50626ea; - -// Convert to 64-bit format (backward compatible) -ed::Uuid64 newId(0, oldId); // high=0, low=old_id - -// Or use high word for type/category -ed::Uuid64 nodeId(0x0001, oldId); // Type: 0x0001 = Node -ed::Uuid64 linkId(0x0002, oldId); // Type: 0x0002 = Link -``` - -## Summary - -The **Uuid64** structure provides: -- 🎯 **Microcontroller compatibility** (no 64-bit math required) -- 🎯 **Zero collision risk** for 100k+ items -- 🎯 **Simple API** (just two uint32_t fields) -- 🎯 **Easy serialization** (8 bytes, or two separate fields) -- 🎯 **Comparison operators** for use in STL containers - -Perfect for embedded systems that need large-scale unique identifiers! - diff --git a/examples/blueprints-example/utilities/UUID_COLLISION_ANALYSIS.md b/examples/blueprints-example/utilities/UUID_COLLISION_ANALYSIS.md deleted file mode 100644 index 5ddb964..0000000 --- a/examples/blueprints-example/utilities/UUID_COLLISION_ANALYSIS.md +++ /dev/null @@ -1,252 +0,0 @@ -# UUID Collision Analysis - -## TL;DR - -For **100,000 items**: -- **Sequential UUIDs**: ✅ **0% collision risk** (guaranteed unique) -- **Random UUIDs**: âš ï¸ **~11.9% collision probability** (birthday paradox) - -## Detailed Analysis - -### Current Implementation: 32-bit UUIDs - -- **Total space**: `0x1000000` to `0xFFFFFFFF` -- **Available UUIDs**: ~4.28 billion (4,278,190,080 values) -- **Format**: 32-bit unsigned integers - -### Birthday Paradox Formula - -For random UUID generation, collision probability follows: - -``` -P(collision) ≈ 1 - e^(-n²/(2d)) - -Where: - n = number of items - d = total UUID space -``` - -### Collision Probabilities by Item Count - -| Items | Collision Probability | Risk Level | -|----------|----------------------|------------| -| 1,000 | ~0.012% | ✅ Very Low | -| 10,000 | ~1.17% | âš ï¸ Low | -| 50,000 | ~29.3% | ⌠High | -| 100,000 | ~68.9% | ⌠Very High| -| 200,000 | ~95.9% | ⌠Almost Certain | - -**Correction**: Let me recalculate more accurately: - -For 100,000 items in 4,278,190,080 space: -``` -n² = 10,000,000,000 -2d = 8,556,380,160 -n²/(2d) = 1.169 - -P(collision) ≈ 1 - e^(-1.169) ≈ 0.689 or ~68.9% -``` - -### Expected Collisions - -Using the formula for expected number of collisions: -``` -E(collisions) ≈ n²/(2d) - -For 100,000 items: -E(collisions) ≈ 100,000² / (2 × 4,278,190,080) -E(collisions) ≈ 1.169 collisions -``` - -## Solutions - -### Option 1: Use Sequential UUIDs (Recommended for 100k items) - -```cpp -// Zero collision risk -uint32_t id = app->GenerateSequentialUuid(); -``` - -**Pros:** -- ✅ 0% collision probability -- ✅ Predictable, debuggable -- ✅ Can generate 4.2+ billion unique IDs -- ✅ Fast (no random number generation) - -**Cons:** -- ⌠Predictable (not suitable for security) -- ⌠Ordering reveals creation sequence - -**Capacity**: Can handle up to **4,278,190,080** items before exhaustion. - -### Option 2: Upgrade to 64-bit UUIDs using Dual 32-bit Words â­ IMPLEMENTED - -**NOW AVAILABLE**: `Uuid64` structure using two 32-bit words: - -```cpp -// Generate 64-bit UUID using two 32-bit words -ed::Uuid64 uuid = app->GenerateRandomUuid64(); -// Structure: { high: uint32_t, low: uint32_t } -``` - -**Collision probability for 100,000 items with 64-bit UUIDs:** -- Space: ~18.4 quintillion (18,446,744,073,709,551,616) -- P(collision) ≈ 0.0000000027% (essentially zero) - -**Benefits:** -- ✅ **Microcontroller compatible** (no 64-bit arithmetic required) -- ✅ Uses only 32-bit operations -- ✅ Same API as 32-bit version -- ✅ Easy serialization (two separate fields) - -See `UUID64_USAGE.md` for detailed examples. - -### Option 3: Implement Collision Detection - -Add a hash set to track used UUIDs: - -```cpp -class UuidGenerator -{ -private: - std::unordered_set m_UsedUuids; - -public: - uint32_t GenerateRandomUnique() - { - uint32_t uuid; - int attempts = 0; - do { - uuid = GenerateRandom(); - attempts++; - if (attempts > 100) { - // Fallback to sequential if too many collisions - return GenerateSequential(); - } - } while (m_UsedUuids.count(uuid) > 0); - - m_UsedUuids.insert(uuid); - return uuid; - } -}; -``` - -**Pros:** -- ✅ Guarantees uniqueness -- ✅ Still random distribution - -**Cons:** -- ⌠Memory overhead (~400KB for 100k items) -- ⌠Slower (hash set lookup) -- ⌠Not persistent across restarts - -### Option 4: Hybrid Approach - -Use both sequential and random: - -```cpp -// Use sequential for persistent entities (nodes, links) -uint32_t nodeId = app->GenerateSequentialUuid(); - -// Use random for temporary entities (animations, transient effects) -uint32_t tempId = app->GenerateRandomUuid(); -``` - -## Recommendations - -### For Your Use Case (100k items): - -1. **Best for Random IDs**: Use **64-bit UUIDs (Dual 32-bit Words)** â­ - ```cpp - ed::Uuid64 id = app->GenerateRandomUuid64(); - ``` - - ✅ Virtually zero collision risk (~0.0000000027%) - - ✅ Microcontroller compatible - - ✅ Future-proof (18 quintillion IDs) - - ✅ Better for distributed systems - -2. **Best for Sequential IDs**: Use **Sequential 64-bit UUIDs** â­ - ```cpp - ed::Uuid64 id = app->GenerateSequentialUuid64(); - ``` - - ✅ Guaranteed unique - - ✅ 0% collision risk - - ✅ Can handle 18 quintillion items - - ✅ Debuggable and predictable - -3. **Legacy Option**: Use **Sequential 32-bit UUIDs** - ```cpp - uint32_t id = app->GenerateSequentialUuid(); - ``` - - ✅ Guaranteed unique - - ✅ Smaller memory footprint (4 bytes) - - âš ï¸ Limited to 4.2 billion items - -4. **Not Recommended**: Random 32-bit UUIDs for large datasets - - ⌠68.9% collision probability at 100k items - - ⌠Requires collision detection - -## Comparison with Standard UUIDs - -| Type | Bits | Space | 100k Collision Risk | -|------|------|-------|---------------------| -| Your Current | 32 | 4.28 billion | 68.9% | -| UUIDv4 (Standard) | 128 | 340 undecillion | ~0% | -| Your Sequential | 32 | 4.28 billion | 0% | -| Your 64-bit | 64 | 18.4 quintillion | ~0% | - -## Implementation: 64-bit UUID (ALREADY IMPLEMENTED! ✅) - -The system now includes `Uuid64` structure using dual 32-bit words: - -```cpp -// Available now in uuid_generator.h -struct Uuid64 -{ - uint32_t high; // Upper 32 bits - uint32_t low; // Lower 32 bits -}; - -// Usage: -ed::Uuid64 uuid = app->GenerateRandomUuid64(); -printf("UUID: high=0x%08x, low=0x%08x\n", uuid.high, uuid.low); -``` - -**Already implemented features:** -- ✅ Random generation: `GenerateRandom64()` -- ✅ Sequential generation: `GenerateSequential64()` -- ✅ Hex string conversion: `ToHexString64()` / `FromHexString64()` -- ✅ Comparison operators for maps/sets -- ✅ uint64_t conversion (for platforms that support it) -- ✅ Validation: `uuid.IsValid()` - -**Trade-offs:** -- More memory (8 bytes vs 4 bytes per UUID) -- Longer hex strings (e.g., `0x1a2b3c4d5e6f7890`) -- ✅ Virtually eliminates collision risk -- ✅ Microcontroller compatible (uses only 32-bit operations) - -## Conclusion - -For **100,000 items**: - -### â­ RECOMMENDED SOLUTION (Now Available!): -Use **64-bit UUIDs with dual 32-bit words** for random IDs: -```cpp -ed::Uuid64 id = app->GenerateRandomUuid64(); // ~0% collision risk -``` - -### Alternative: -Use **Sequential UUIDs** (32-bit or 64-bit) for guaranteed uniqueness: -```cpp -uint32_t id = app->GenerateSequentialUuid(); // 4 bytes, 0% collision -ed::Uuid64 id64 = app->GenerateSequentialUuid64(); // 8 bytes, 0% collision -``` - -### ⌠AVOID: -32-bit random UUIDs for datasets > 10k items (68.9% collision risk at 100k) - ---- - -**See `UUID64_USAGE.md` for complete usage examples and microcontroller-specific guidance.** - diff --git a/examples/blueprints-example/utilities/UUID_DUAL_ID_SYSTEM.md b/examples/blueprints-example/utilities/UUID_DUAL_ID_SYSTEM.md deleted file mode 100644 index 7467319..0000000 --- a/examples/blueprints-example/utilities/UUID_DUAL_ID_SYSTEM.md +++ /dev/null @@ -1,386 +0,0 @@ -# Dual-ID System: UUIDs + Runtime IDs - -## The Problem - -**imgui-node-editor** uses **dynamic integer IDs** for fast runtime access: -- `ed::NodeId` → int (e.g., 1, 2, 3, ...) -- `ed::LinkId` → int -- `ed::PinId` → int - -These IDs are: -- ✅ **Fast**: Direct array/map indexing -- ✅ **Efficient**: No string hashing -- ⌠**Dynamic**: Change between sessions -- ⌠**Unstable**: Not suitable for save/load - -**We need persistent IDs** for save/load that remain stable across sessions. - -## The Solution: Dual-ID System - -Each entity (Node/Link/Pin) has **TWO IDs**: - -| Type | Used For | Storage | Stability | -|------|----------|---------|-----------| -| **UUID** (`ed::Uuid64`) | Save/Load (persistent) | JSON files | ✅ Stable across sessions | -| **Runtime ID** (`int/ed::NodeId`) | Runtime lookups (fast) | Memory only | ⌠Changes each session | - -```cpp -struct Node { - ed::NodeId ID; // Runtime ID (dynamic) - for imgui-node-editor - ed::Uuid64 UUID; // Persistent ID (stable) - for save/load - // ... other fields -}; -``` - -## Architecture - -``` -┌─────────────────────────────────────────────────────────────┠-│ Application │ -│ │ -│ ┌────────────────┠┌────────────────────┠│ -│ │ UuidIdManager │◄──────────────►│ Node/Link/Pin │ │ -│ │ │ │ Structures │ │ -│ │ UUID ↔ ID Map │ │ │ │ -│ └────────────────┘ │ - UUID (persist) │ │ -│ â–² │ - ID (runtime) │ │ -│ │ └────────────────────┘ │ -│ │ │ │ -│ │ â–¼ │ -│ ┌──────┴────────────┠┌───────────────────────┠│ -│ │ Save/Load │ │ imgui-node-editor │ │ -│ │ (uses UUIDs) │ │ (uses Runtime IDs) │ │ -│ └───────────────────┘ └───────────────────────┘ │ -└──────────────────────────────────────────────────────────────┘ -``` - -## Workflow - -### 1. Creating New Nodes (Runtime) - -```cpp -// Generate runtime ID (from container ID generator) -int runtimeId = container->GetNextId(); - -// Generate persistent UUID -ed::Uuid64 uuid = app->m_UuidIdManager.GenerateUuid(); - -// Create node with both IDs -Node newNode(runtimeId, "MyNode"); -newNode.UUID = uuid; - -// Register mapping: UUID ↔ Runtime ID -app->m_UuidIdManager.RegisterNode(uuid, runtimeId); - -// imgui-node-editor uses Runtime ID -ed::BeginNode(newNode.ID); // Uses runtimeId -``` - -### 2. Saving Graph (Serialize UUIDs) - -```cpp -void SaveGraph(const std::string& filename) -{ - crude_json::value root; - - for (auto* node : nodes) - { - crude_json::value nodeData; - - // ✅ SAVE UUID (persistent, stable) - nodeData["uuid_high"] = (double)node->UUID.high; - nodeData["uuid_low"] = (double)node->UUID.low; - - // ⌠DON'T save runtime ID (changes each session) - // nodeData["id"] = node->ID.Get(); // WRONG! - - nodeData["name"] = node->Name; - nodeData["type"] = node->BlockType; - - // Save pins (also use UUIDs) - for (auto& pin : node->Inputs) - { - crude_json::value pinData; - pinData["uuid_high"] = (double)pin.UUID.high; - pinData["uuid_low"] = (double)pin.UUID.low; - pinData["name"] = pin.Name; - // ... etc - } - - root["nodes"].push_back(nodeData); - } - - // Save links with PIN UUIDs (not runtime pin IDs!) - for (auto* link : links) - { - crude_json::value linkData; - - linkData["uuid_high"] = (double)link->UUID.high; - linkData["uuid_low"] = (double)link->UUID.low; - - // Find start/end pins and save their UUIDs - Pin* startPin = FindPin(link->StartPinID); - Pin* endPin = FindPin(link->EndPinID); - - linkData["start_pin_uuid_high"] = (double)startPin->UUID.high; - linkData["start_pin_uuid_low"] = (double)startPin->UUID.low; - linkData["end_pin_uuid_high"] = (double)endPin->UUID.high; - linkData["end_pin_uuid_low"] = (double)endPin->UUID.low; - - root["links"].push_back(linkData); - } -} -``` - -### 3. Loading Graph (Resolve UUIDs → Generate New Runtime IDs) - -```cpp -void LoadGraph(const std::string& filename) -{ - // Clear old mappings - m_UuidIdManager.Clear(); - - crude_json::value root = crude_json::value::parse(fileData); - - // ========== Load Nodes ========== - for (auto& nodeData : root["nodes"]) - { - // ✅ Load UUID (persistent) - ed::Uuid64 uuid( - (uint32_t)nodeData["uuid_high"].get(), - (uint32_t)nodeData["uuid_low"].get() - ); - - // Generate NEW runtime ID (don't reuse old IDs!) - int runtimeId = container->GetNextId(); - - // Create node - Node newNode(runtimeId, nodeData["name"].get().c_str()); - newNode.UUID = uuid; - newNode.BlockType = nodeData["type"].get(); - - // Build node structure (adds pins) - BuildNodeStructure(newNode); - - // Load pin UUIDs and register them - for (size_t i = 0; i < newNode.Inputs.size(); ++i) - { - ed::Uuid64 pinUuid( - (uint32_t)nodeData["inputs"][i]["uuid_high"].get(), - (uint32_t)nodeData["inputs"][i]["uuid_low"].get() - ); - newNode.Inputs[i].UUID = pinUuid; - - // Register pin mapping - m_UuidIdManager.RegisterPin(pinUuid, newNode.Inputs[i].ID.Get()); - } - - // Add to container - Node* addedNode = container->AddNode(newNode); - - // ✅ Register mapping: UUID → Runtime ID - m_UuidIdManager.RegisterNode(uuid, runtimeId); - } - - // ========== Load Links ========== - for (auto& linkData : root["links"]) - { - // Load link UUID - ed::Uuid64 linkUuid( - (uint32_t)linkData["uuid_high"].get(), - (uint32_t)linkData["uuid_low"].get() - ); - - // Load start/end pin UUIDs - ed::Uuid64 startPinUuid( - (uint32_t)linkData["start_pin_uuid_high"].get(), - (uint32_t)linkData["start_pin_uuid_low"].get() - ); - ed::Uuid64 endPinUuid( - (uint32_t)linkData["end_pin_uuid_high"].get(), - (uint32_t)linkData["end_pin_uuid_low"].get() - ); - - // ✅ Resolve pin UUIDs → Runtime IDs - int startPinRuntimeId = m_UuidIdManager.GetPinRuntimeId(startPinUuid); - int endPinRuntimeId = m_UuidIdManager.GetPinRuntimeId(endPinUuid); - - if (startPinRuntimeId < 0 || endPinRuntimeId < 0) - { - printf("[LoadGraph] WARNING: Link references missing pin\n"); - continue; // Skip orphaned link - } - - // Generate new runtime ID for link - int linkRuntimeId = container->GetNextId(); - - // Create link with resolved runtime pin IDs - Link newLink(ed::LinkId(linkRuntimeId), - ed::PinId(startPinRuntimeId), - ed::PinId(endPinRuntimeId)); - newLink.UUID = linkUuid; - - // Add link - Link* addedLink = container->AddLink(newLink); - - // Register link mapping - m_UuidIdManager.RegisterLink(linkUuid, linkRuntimeId); - } -} -``` - -## Key Principles - -### ✅ DO: - -1. **Generate UUIDs on creation** (not on save!) - ```cpp - Node* SpawnNode() { - int runtimeId = GetNextId(); - ed::Uuid64 uuid = m_UuidIdManager.GenerateUuid(); // ✅ Assign immediately - Node node(runtimeId, "Name"); - node.UUID = uuid; - m_UuidIdManager.RegisterNode(uuid, runtimeId); - return addedNode; - } - ``` - -2. **Save UUIDs** (persistent identifiers) - ```cpp - nodeData["uuid_high"] = node->UUID.high; - nodeData["uuid_low"] = node->UUID.low; - ``` - -3. **Load UUIDs, generate new runtime IDs** - ```cpp - ed::Uuid64 uuid = LoadUuidFromJson(nodeData); - int newRuntimeId = container->GetNextId(); // Fresh ID! - m_UuidIdManager.RegisterNode(uuid, newRuntimeId); - ``` - -4. **Link via UUIDs in save files** (not runtime IDs) - ```cpp - linkData["start_pin_uuid"] = startPin->UUID; // ✅ - ``` - -### ⌠DON'T: - -1. **Don't save runtime IDs** - ```cpp - nodeData["id"] = node->ID.Get(); // ⌠Will change next session! - ``` - -2. **Don't reuse runtime IDs from save file** - ```cpp - int runtimeId = nodeData["id"].get(); // ⌠Conflicts! - ``` - -3. **Don't reference runtime IDs in save files** - ```cpp - linkData["start_pin_id"] = link->StartPinID.Get(); // ⌠Unstable! - ``` - -4. **Don't forget to register mappings** - ```cpp - Node node(runtimeId, "Name"); - node.UUID = uuid; - // m_UuidIdManager.RegisterNode(uuid, runtimeId); // ⌠FORGOT! - ``` - -## Benefits - -| Feature | Without UUIDs | With Dual-ID System | -|---------|---------------|---------------------| -| **Runtime Performance** | Fast ✅ | Fast ✅ (uses runtime IDs) | -| **Save/Load Stability** | ⌠Breaks on ID changes | ✅ Stable across sessions | -| **Node Reference Integrity** | ⌠Can break | ✅ Preserved | -| **Merge Graphs** | ⌠ID conflicts | ✅ UUIDs unique | -| **Debugging** | ⌠IDs change | ✅ UUIDs stable | - -## Migration Strategy - -### Phase 1: Add UUID fields (✅ DONE) -- Added `UUID` to `Node`, `Link`, `Pin` structures -- Created `UuidIdManager` class - -### Phase 2: Generate UUIDs on creation -- Modify `SpawnBlockNode()` to generate UUIDs -- Modify `SpawnParameterNode()` to generate UUIDs -- Register all UUID ↔ Runtime ID mappings - -### Phase 3: Update Save logic -- Save UUIDs instead of runtime IDs -- Use pin UUIDs for link serialization - -### Phase 4: Update Load logic -- Load UUIDs from file -- Generate fresh runtime IDs -- Populate UUID ↔ Runtime ID mappings -- Resolve pin UUIDs for links - -### Phase 5: Backward compatibility (optional) -- Detect old format (has runtime IDs) -- Auto-generate UUIDs for old saves -- Resave in new format - -## Example: Complete Node Lifecycle - -```cpp -// ========== CREATION ========== -// (Happens in SpawnBlockNode) -int runtimeId = container->GetNextId(); // e.g., 5 -ed::Uuid64 uuid = m_UuidIdManager.GenerateUuid(); // e.g., {0x1000000, 0x0} -Node node(runtimeId, "Add"); -node.UUID = uuid; -m_UuidIdManager.RegisterNode(uuid, runtimeId); - -// ========== RUNTIME ========== -// imgui-node-editor uses runtime ID -ed::BeginNode(node.ID); // Uses 5 -ed::EndNode(); - -// ========== SAVE ========== -nodeData["uuid_high"] = 0x1000000; -nodeData["uuid_low"] = 0x0; -// Runtime ID (5) is NOT saved - -// ========== LOAD (Next Session) ========== -ed::Uuid64 loadedUuid(0x1000000, 0x0); // Same as before ✅ -int newRuntimeId = container->GetNextId(); // Could be 12 now! -Node newNode(newRuntimeId, "Add"); -newNode.UUID = loadedUuid; -m_UuidIdManager.RegisterNode(loadedUuid, newRuntimeId); - -// Now: -// - Node has NEW runtime ID (12) -// - Node has SAME UUID ({0x1000000, 0x0}) -// - imgui-node-editor uses 12 -// - Next save will use UUID again -``` - -## FAQ - -**Q: Why not use UUIDs directly as imgui-node-editor IDs?** -A: imgui-node-editor expects `int` IDs for performance. Converting `Uuid64` to `int` would lose information or require hashing (slow). - -**Q: What happens if I forget to assign a UUID?** -A: Node will have `UUID{0,0}` (invalid). Detect with `uuid.IsValid()`. Save will fail or generate UUID on-the-fly. - -**Q: Can I use random UUIDs instead of sequential?** -A: Yes! Change `GenerateUuid()` to use `GenerateRandom64()`. Sequential is better for debugging. - -**Q: How do I migrate existing save files?** -A: Detect old format (has "id" field), auto-generate UUIDs, register mappings, resave. - -**Q: Do pins need UUIDs too?** -A: Yes! Links reference pins by UUID. Otherwise, link loading will break. - -## Summary - -- **Two IDs per entity**: UUID (persistent) + Runtime ID (dynamic) -- **Save UUIDs** to JSON (stable across sessions) -- **Generate new runtime IDs** on load (avoid conflicts) -- **UuidIdManager** maintains UUID ↔ Runtime ID mapping -- **imgui-node-editor** uses runtime IDs (no changes needed) -- **Result**: Stable save files + fast runtime performance - diff --git a/examples/blueprints-example/utilities/UUID_USAGE.md b/examples/blueprints-example/utilities/UUID_USAGE.md deleted file mode 100644 index 4e92687..0000000 --- a/examples/blueprints-example/utilities/UUID_USAGE.md +++ /dev/null @@ -1,151 +0,0 @@ -# UUID Generator Usage - -The `UuidGenerator` class provides methods for generating unique identifiers in hexadecimal format (e.g., `0x50626ea`, `0x1b7c7646`). - -## Features - -- **Random UUID Generation**: Generate cryptographically random 32-bit UUIDs -- **Sequential UUID Generation**: Generate incrementing UUIDs from a seed value -- **Hex String Conversion**: Convert between `uint32_t` and hex string formats -- **Validation**: Check if a UUID is valid (non-zero) - -## Basic Usage - -### Through App Class - -```cpp -// Generate a random UUID -uint32_t randomId = app->GenerateRandomUuid(); -// Example: 0x50626ea - -// Generate a sequential UUID -uint32_t sequentialId = app->GenerateSequentialUuid(); -// Example: 0x1000000, 0x1000001, 0x1000002, ... - -// Convert UUID to hex string -std::string hexStr = app->UuidToHexString(randomId); -// Output: "0x50626ea" - -// Parse hex string to UUID -uint32_t parsedId = app->HexStringToUuid("0x1b7c7646"); -// Result: 0x1b7c7646 (84411974 in decimal) -``` - -### Direct UuidGenerator Access - -```cpp -// Get direct access to the generator -ed::UuidGenerator& generator = app->GetUuidGenerator(); - -// Generate random UUID -uint32_t uuid1 = generator.GenerateRandom(); - -// Generate sequential UUID -uint32_t uuid2 = generator.GenerateSequential(); - -// Convert to hex string -std::string hexString = ed::UuidGenerator::ToHexString(uuid1); - -// Parse from hex string (supports both "0x50626ea" and "50626ea") -uint32_t parsed1 = ed::UuidGenerator::FromHexString("0x50626ea"); -uint32_t parsed2 = ed::UuidGenerator::FromHexString("50626ea"); // Same result - -// Validate UUID -bool isValid = ed::UuidGenerator::IsValid(uuid1); // true if non-zero - -// Reset sequential counter -generator.ResetSequential(0x2000000); // Start from custom seed - -// Set random seed for deterministic generation (useful for testing) -generator.SetRandomSeed(12345); -``` - -## Examples - -### Example 1: Generate Node IDs - -```cpp -// Generate unique node IDs -uint32_t nodeId1 = app->GenerateRandomUuid(); -uint32_t nodeId2 = app->GenerateRandomUuid(); -uint32_t nodeId3 = app->GenerateRandomUuid(); - -printf("Node IDs: %s, %s, %s\n", - app->UuidToHexString(nodeId1).c_str(), - app->UuidToHexString(nodeId2).c_str(), - app->UuidToHexString(nodeId3).c_str()); -// Output: Node IDs: 0x50626ea, 0x1b7c7646, 0xa3f2b891 -``` - -### Example 2: Sequential IDs for Ordered Items - -```cpp -// Generate sequential IDs for a list of items -std::vector itemIds; -for (int i = 0; i < 5; i++) -{ - itemIds.push_back(app->GenerateSequentialUuid()); -} - -// Output: 0x1000000, 0x1000001, 0x1000002, 0x1000003, 0x1000004 -``` - -### Example 3: Save/Load UUIDs from JSON - -```cpp -// Saving to JSON -json nodeData; -nodeData["id"] = app->UuidToHexString(nodeId); - -// Loading from JSON -std::string hexId = nodeData["id"].get(); -uint32_t loadedId = app->HexStringToUuid(hexId); -``` - -### Example 4: Using as NodeEditor IDs - -```cpp -// Generate UUID for node editor -uint32_t uuid = app->GenerateRandomUuid(); -ed::NodeId nodeId(uuid); - -// Or for links -uint32_t linkUuid = app->GenerateRandomUuid(); -ed::LinkId linkId(linkUuid); -``` - -## Technical Details - -- **Range**: UUIDs are generated in the range `0x1000000` to `0xFFFFFFFF` -- **Format**: 32-bit unsigned integers (4 bytes) -- **Hex String Format**: Always prefixed with "0x" (e.g., "0x50626ea") -- **Random Generation**: Uses Mersenne Twister (mt19937) for high-quality randomness -- **Sequential Generation**: Increments from seed value (default: 0x1000000) - -## When to Use - -- **Random UUIDs**: Use when you need globally unique identifiers with no ordering requirement -- **Sequential UUIDs**: Use when you need unique IDs with predictable ordering (useful for testing or debugging) - -## Standard UUID Format Support - -Convert between standard UUID format (RFC4122 with dashes) and our format: - -```cpp -// Parse standard UUID: "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d" -ed::Uuid64 uuid = app->StandardStringToUuid("9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d"); - -// Convert to standard format: "00000000-0000-0000-HHHHHHHH-LLLLLLLL" -std::string standardStr = app->UuidToStandardString(uuid); -``` - -**See `STANDARD_UUID_CONVERSION.md` for detailed examples.** - -## Notes - -- UUIDs are stored as `uint32_t` (32-bit integers) -- Format differs from standard RFC4122 UUIDs (those are 128-bit) -- Collision probability for random generation is very low (1 in 4 billion) -- Sequential UUIDs are guaranteed to be unique within the same generator instance -- Standard UUID conversion available for 64-bit UUIDs (128-bit → 64-bit is lossy) - diff --git a/examples/blueprints-example/utilities/WAYPOINT_REFINEMENT.md b/examples/blueprints-example/utilities/WAYPOINT_REFINEMENT.md deleted file mode 100644 index 9eade4d..0000000 --- a/examples/blueprints-example/utilities/WAYPOINT_REFINEMENT.md +++ /dev/null @@ -1,261 +0,0 @@ -# Waypoint Refinement System - -## Overview - -The waypoint refinement system provides **multi-pass, context-aware optimization** of link paths in the node editor. Each refinement pass can analyze the entire graph context (all nodes, links, obstacles) to make intelligent routing decisions. - -## Architecture - -### Multi-Pass Pipeline - -``` -Initial Waypoints (from routing strategy) - ↓ -[Pass 1: Link Fitting] ↠Align horizontal segments - ↓ -[Pass 2: Auto Collapse] ↠Remove unnecessary waypoints - ↓ -[Pass 3: Custom...] ↠User-defined passes - ↓ -Final Waypoints -``` - -Each pass: -- Receives waypoints from previous pass -- Has full access to routing context (container, links, obstacles, editor) -- Returns modified waypoints for next pass - -### Routing Context - -```cpp -struct RoutingContext { - PinContext StartPin; // Source pin - PinContext EndPin; // Target pin - NodeContext StartNode; // Source node bounds - NodeContext EndNode; // Target node bounds - float Margin; // Clearance margin - std::vector Obstacles; // Other nodes to avoid - EditorContext* EditorContext; // Editor state - Container* Container; // Active container (ALL nodes/links) - - // Refinement pipeline - std::vector RefinementPasses; -}; -``` - -## Configuration - -**All features are configured in `pathfinding.cpp` (lines 9-12):** - -```cpp -// Pathfinding feature flags (configure here) -#define WAYPOINT_DEBUG // Enable debug logging -#define ENABLE_LINK_FITTING // Align horizontal segments within 100 units -#define ENABLE_LINK_AUTO_COLLAPSE // Collapse waypoints to straight when within 100 units -``` - -**To disable a feature**, comment it out: -```cpp -// #define ENABLE_LINK_FITTING // Disabled -``` - -## Implemented Refinement Passes - -### Pass 1: Link Fitting (ENABLE_LINK_FITTING) - -**Purpose**: Align horizontal link segments that are close together - -**Algorithm**: -1. Analyzes horizontal segments in current link -2. Queries ALL other links in container (context-aware!) -3. Groups segments within 100 units vertically -4. Aligns new link to existing link's Y (anchor-based, not averaging) - -**Parameters**: -- `HORIZONTAL_ALIGNMENT_TOLERANCE`: 100.0f (line 1001) - -**Visual Effect**: -``` -Before: After: -Link1 ───── (Y=150) Link1 ───── (Y=150) -Link2 ───── (Y=180) → Link2 ───── (Y=150) ↠aligned! -``` - -**Benefits**: -- Creates professional, aligned layouts -- Reduces visual clutter -- Easier to trace link paths - ---- - -### Pass 2: Auto-Collapse (ENABLE_LINK_AUTO_COLLAPSE) - -**Purpose**: Simplify links to straight lines when waypoints don't add value - -**Algorithm**: -1. **Radius check**: If all waypoints fit in 100-unit bounding box → collapse -2. **Collinearity check**: If all waypoints lie on straight line (±5px) → collapse -3. Returns empty waypoints (triggers straight line mode) - -**Parameters**: -- `COLLAPSE_RADIUS`: 100.0f (line 1225) -- `COLLINEAR_TOLERANCE`: 5.0f pixels (line 1274) - -**Visual Effect**: -``` -Before (guided with tight waypoints): -Pin1 ─→ WP1(10,10) ─→ WP2(15,15) ─→ Pin2 - -After (collapsed to straight): -Pin1 ──────────────────────────→ Pin2 -``` - -**Benefits**: -- Reduces visual complexity for simple connections -- Improves performance (fewer waypoints to render) -- Automatically simplifies when nodes are moved closer - ---- - -## Usage Examples - -### Basic Usage (Auto-Enabled) - -Refinement passes are **automatically applied** when: -- Creating new links -- Moving nodes (auto-adjustment) -- Switching to guided mode (Space key) - -**No configuration needed** - just enable the defines! - -### Custom Refinement Pass - -```cpp -// Define custom pass -std::vector MyCustomPass( - const std::vector& waypoints, - const RoutingContext& ctx, - void* userData) -{ - // Access all links in scene - if (ctx.Container) - { - auto* root = ctx.Container->GetRootContainer(); - auto allLinks = root->GetAllLinks(); - - // Your custom logic here - // - Detect link crossings - // - Bundle parallel links - // - Apply custom constraints - } - - return modifiedWaypoints; -} - -// Add to pipeline -ctx.AddRefinementPass(MyCustomPass, myData, "My Custom Pass"); -``` - -### Chaining Multiple Passes - -```cpp -// Order matters! Each pass processes output of previous pass -ctx.AddRefinementPass(RefinementPass_SmoothPath, nullptr, "Link Fitting"); -ctx.AddRefinementPass(MyBundlingPass, bundleData, "Bundle Links"); -ctx.AddRefinementPass(RefinementPass_AutoCollapse, nullptr, "Auto Collapse"); - -auto waypoints = PathFinding::GenerateWaypoints(ctx); -``` - -## Debug Output - -With `WAYPOINT_DEBUG` enabled, you'll see: - -``` -[GenerateWaypoints] Applying refinement pass 1/2: Link Fitting (waypoints before: 2) -[RefinementPass_SmoothPath] Found 4 horizontal segments (current + other links) -[RefinementPass_SmoothPath] Aligning 2 horizontal segments to Y=150.0 - - Segment 0: Y=180.0 (current link: YES) - - Segment 1: Y=150.0 (current link: no) -[GenerateWaypoints] Refinement pass 1 complete (waypoints after: 2) - -[GenerateWaypoints] Applying refinement pass 2/2: Auto Collapse (waypoints before: 2) -[RefinementPass_AutoCollapse] Keeping 2 waypoints (max dimension: 450.0 > 100.0) -[GenerateWaypoints] Refinement pass 2 complete (waypoints after: 2) -``` - -## Performance - -### Link Fitting -- **O(L × S²)** where L = links, S = horizontal segments per link -- Typical: 10 links × 2 segments = ~40 comparisons -- Fast in practice (< 1ms) - -### Auto-Collapse -- **O(W)** where W = waypoints in current link -- Minimal overhead (bounding box + collinearity check) -- Negligible cost (< 0.1ms) - -## Feature Interactions - -### Combined Effect - -When **both** features are enabled: - -1. **Link Fitting** aligns horizontal segments across multiple links -2. **Auto-Collapse** then checks if aligned waypoints are redundant -3. If aligned waypoints become collinear → collapse to straight - -**Example Scenario:** -``` -Step 1: Create Link1 with waypoints at Y=100, Y=500 -Step 2: Create Link2 (initially Y=120, Y=480) -Step 3: Link Fitting aligns Link2 to Y=100, Y=500 -Step 4: Auto-Collapse checks if waypoints needed - If nodes close → collapses to straight! -``` - -## Tuning Guide - -### Make Fitting More Aggressive -```cpp -const float HORIZONTAL_ALIGNMENT_TOLERANCE = 200.0f; // Was 100.0f -``` -→ Aligns segments up to 200 units apart - -### Make Collapse More Conservative -```cpp -const float COLLAPSE_RADIUS = 50.0f; // Was 100.0f -``` -→ Only collapses very tight waypoints - -### Disable Collinearity Check -```cpp -// Comment out collinearity check (lines 1263-1312) -// if (inputWaypoints.size() >= 2) { ... } -``` -→ Only use radius-based collapse - -## Troubleshooting - -### "Links not aligning" -- Ensure `ENABLE_LINK_FITTING` is defined -- Check debug output for horizontal segment detection -- Verify segments are within 100 units (increase tolerance if needed) - -### "Links collapsing when they shouldn't" -- Reduce `COLLAPSE_RADIUS` (try 50.0f) -- Increase `COLLINEAR_TOLERANCE` (try 10.0f) -- Disable `ENABLE_LINK_AUTO_COLLAPSE` - -### "Debug output not showing" -- Ensure `WAYPOINT_DEBUG` is defined -- Check console/terminal output - -## Related Files - -- **Configuration & Implementation**: `utilities/pathfinding.cpp` -- **API & Types**: `utilities/pathfinding.h` -- **Usage**: `app-render.cpp` (3 locations) -- **Documentation**: `LINK_FITTING.md` (this file) - diff --git a/crude_json.cpp b/external/crude_json.cpp similarity index 100% rename from crude_json.cpp rename to external/crude_json.cpp diff --git a/crude_json.h b/external/crude_json.h similarity index 100% rename from crude_json.h rename to external/crude_json.h diff --git a/external/imgui/CMakeLists.txt b/external/imgui/CMakeLists.txt index d8f61b1..0f4fd9f 100644 --- a/external/imgui/CMakeLists.txt +++ b/external/imgui/CMakeLists.txt @@ -1,5 +1,8 @@ +# Declare the standalone imgui project (used when building this dependency). project(imgui VERSION 1.76) +# Collect the official ImGui distribution sources. Consumers compile these into +# a static library that mirrors upstream's default build configuration. set(_imgui_Sources imconfig.h imgui.cpp @@ -16,13 +19,20 @@ set(_imgui_Sources LICENSE.txt ) +# Build imgui as a static library so that downstream targets can link against +# it without relying on bundled prebuilt binaries. add_library(${PROJECT_NAME} STATIC ${_imgui_Sources}) +# Expose headers so downstream targets can simply `#include "imgui.h"`. target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -#target_compile_definitions(${PROJECT_NAME} PUBLIC "ImDrawIdx=unsigned int") +# Disable deprecated API branches to keep builds warning-free unless a project +# opts back in. target_compile_definitions(${PROJECT_NAME} PUBLIC IMGUI_DISABLE_OBSOLETE_FUNCTIONS) +# Organize files in IDEs that support virtual folders. source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${_imgui_Sources}) +# Group the target under an "external" folder when seen inside tools like +# Visual Studio's Solution Explorer. set_property(TARGET ${PROJECT_NAME} PROPERTY FOLDER "external") diff --git a/external/imgui/imgui_draw.cpp b/external/imgui/imgui_draw.cpp index 01373a9..4382e2e 100644 --- a/external/imgui/imgui_draw.cpp +++ b/external/imgui/imgui_draw.cpp @@ -2145,6 +2145,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0); if (!data) { + IMGUI_DEBUG_LOG("While loading '%s'\n", filename); IM_ASSERT_USER_ERROR(0, "Could not load font file!"); return NULL; } diff --git a/EditorContext.cpp b/external/imgui_node/EditorContext.cpp similarity index 100% rename from EditorContext.cpp rename to external/imgui_node/EditorContext.cpp diff --git a/EditorContext.h b/external/imgui_node/EditorContext.h similarity index 100% rename from EditorContext.h rename to external/imgui_node/EditorContext.h diff --git a/NodeEx.cpp b/external/imgui_node/NodeEx.cpp similarity index 100% rename from NodeEx.cpp rename to external/imgui_node/NodeEx.cpp diff --git a/examples/blueprints-example/blocks/NodeEx.h b/external/imgui_node/NodeEx.h similarity index 100% rename from examples/blueprints-example/blocks/NodeEx.h rename to external/imgui_node/NodeEx.h diff --git a/imgui_bezier_math.h b/external/imgui_node/imgui_bezier_math.h similarity index 100% rename from imgui_bezier_math.h rename to external/imgui_node/imgui_bezier_math.h diff --git a/imgui_bezier_math.inl b/external/imgui_node/imgui_bezier_math.inl similarity index 100% rename from imgui_bezier_math.inl rename to external/imgui_node/imgui_bezier_math.inl diff --git a/imgui_canvas.cpp b/external/imgui_node/imgui_canvas.cpp similarity index 100% rename from imgui_canvas.cpp rename to external/imgui_node/imgui_canvas.cpp diff --git a/imgui_canvas.h b/external/imgui_node/imgui_canvas.h similarity index 100% rename from imgui_canvas.h rename to external/imgui_node/imgui_canvas.h diff --git a/imgui_extra_math.h b/external/imgui_node/imgui_extra_math.h similarity index 100% rename from imgui_extra_math.h rename to external/imgui_node/imgui_extra_math.h diff --git a/imgui_extra_math.inl b/external/imgui_node/imgui_extra_math.inl similarity index 100% rename from imgui_extra_math.inl rename to external/imgui_node/imgui_extra_math.inl diff --git a/imgui_node_editor.cpp b/external/imgui_node/imgui_node_editor.cpp similarity index 99% rename from imgui_node_editor.cpp rename to external/imgui_node/imgui_node_editor.cpp index daa056e..2c38150 100644 --- a/imgui_node_editor.cpp +++ b/external/imgui_node/imgui_node_editor.cpp @@ -162,31 +162,7 @@ static void LogV(const char* fmt, va_list args) fprintf(stderr, "NodeEditor: %s\n", buffer); fflush(stderr); - // Log to file for real-time viewing with tail -f - static FILE* logFile = nullptr; - if (!logFile) - { - logFile = fopen("blueprints-log.md", "w"); - if (logFile) - { - fprintf(logFile, "# ImGui Node Editor Log\n\n"); - fprintf(logFile, "Logging session started\n\n"); - fprintf(logFile, "```\n"); - fflush(logFile); - } - } - if (logFile) - { - fprintf(logFile, "NodeEditor: %s\n", buffer); - fflush(logFile); // Immediate flush for tail -f - } - - // Also log to ImGui - ImGui::LogText("\nNode Editor: %s", buffer); - - // Log to in-app logger - Detail::AddInAppLog("%s\n", buffer); # if defined(_DEBUG) && defined(_WIN32) // Also log to Visual Studio debug output @@ -198,10 +174,7 @@ static void LogV(const char* fmt, va_list args) void ed::Log(const char* fmt, ...) { - va_list args; - va_start(args, fmt); - LogV(fmt, args); - va_end(args); + } diff --git a/imgui_node_editor.h b/external/imgui_node/imgui_node_editor.h similarity index 98% rename from imgui_node_editor.h rename to external/imgui_node/imgui_node_editor.h index 3cefea7..ef74184 100644 --- a/imgui_node_editor.h +++ b/external/imgui_node/imgui_node_editor.h @@ -39,12 +39,6 @@ namespace ax { namespace NodeEditor { -// Forward declarations -namespace Detail { - void DrawInAppLogger(float height); -} - - //------------------------------------------------------------------------------ /// @defgroup CoreTypes Core Types /// @brief Type-safe IDs and fundamental enums @@ -726,16 +720,6 @@ struct PinId final: Details::SafePointerType using SafePointerType::SafePointerType; }; -//------------------------------------------------------------------------------ -/// @defgroup Logger In-App Logger -/// @brief In-application logging widget -/// @{ - -IMGUI_NODE_EDITOR_API void AddInAppLog(const char* fmt, ...); ///< Add log message to in-app logger -IMGUI_NODE_EDITOR_API void DrawInAppLogger(float height); ///< Draw in-app logger inline (for use in panels) - -/// @} // Logger - //------------------------------------------------------------------------------ } // namespace Editor } // namespace ax diff --git a/imgui_node_editor_animation.cpp b/external/imgui_node/imgui_node_editor_animation.cpp similarity index 100% rename from imgui_node_editor_animation.cpp rename to external/imgui_node/imgui_node_editor_animation.cpp diff --git a/imgui_node_editor_api.cpp b/external/imgui_node/imgui_node_editor_api.cpp similarity index 99% rename from imgui_node_editor_api.cpp rename to external/imgui_node/imgui_node_editor_api.cpp index b548e64..d796cb8 100644 --- a/imgui_node_editor_api.cpp +++ b/external/imgui_node/imgui_node_editor_api.cpp @@ -367,18 +367,6 @@ bool ax::NodeEditor::QueryDeletedNode(NodeId* nodeId) return context.QueryNode(nodeId); } -void ax::NodeEditor::AddInAppLog(const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - Detail::AddInAppLog(fmt, args); - va_end(args); -} - -void ax::NodeEditor::DrawInAppLogger(float height) -{ - Detail::DrawInAppLogger(height); -} bool ax::NodeEditor::AcceptDeletedItem(bool deleteDependencies) { diff --git a/imgui_node_editor_internal.h b/external/imgui_node/imgui_node_editor_internal.h similarity index 99% rename from imgui_node_editor_internal.h rename to external/imgui_node/imgui_node_editor_internal.h index 542b8a1..57957fc 100644 --- a/imgui_node_editor_internal.h +++ b/external/imgui_node/imgui_node_editor_internal.h @@ -28,11 +28,10 @@ # include "imgui_bezier_math.h" # include "imgui_canvas.h" -# include "crude_json.h" +# include # include # include - # include @@ -56,8 +55,6 @@ using std::string; //------------------------------------------------------------------------------ void Log(const char* fmt, ...); -void AddInAppLog(const char* fmt, ...); // Add log message to in-app logger -void DrawInAppLogger(float height); // Draw in-app logger inline //------------------------------------------------------------------------------ @@ -670,7 +667,6 @@ struct CreateItemAction; struct DeleteItemsAction; struct ContextMenuAction; struct ShortcutAction; - struct AnimationController; struct FlowAnimationController; diff --git a/imgui_node_editor_internal.inl b/external/imgui_node/imgui_node_editor_internal.inl similarity index 100% rename from imgui_node_editor_internal.inl rename to external/imgui_node/imgui_node_editor_internal.inl diff --git a/imgui_node_editor_store.cpp b/external/imgui_node/imgui_node_editor_store.cpp similarity index 100% rename from imgui_node_editor_store.cpp rename to external/imgui_node/imgui_node_editor_store.cpp diff --git a/links-guided.cpp b/external/imgui_node/links-guided.cpp similarity index 100% rename from links-guided.cpp rename to external/imgui_node/links-guided.cpp diff --git a/links-guided.h b/external/imgui_node/links-guided.h similarity index 100% rename from links-guided.h rename to external/imgui_node/links-guided.h diff --git a/imgui_node_editor_edit.cpp b/imgui_node_editor_edit.cpp deleted file mode 100644 index 870b5ce..0000000 --- a/imgui_node_editor_edit.cpp +++ /dev/null @@ -1,45 +0,0 @@ -//------------------------------------------------------------------------------ -// VERSION 0.9.1 -// -// LICENSE -// This software is dual-licensed to the public domain and under the following -// license: you are granted a perpetual, irrevocable license to copy, modify, -// publish, and distribute this file as you see fit. -// -// CREDITS -// Written by Michal Cichon -//------------------------------------------------------------------------------ -# include "imgui_node_editor_internal.h" -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace ed = ax::NodeEditor::Detail; - -// Forward declarations -struct Node; -struct Pin; -struct Link; - -// Need to include app.h to access types, but we'll forward declare App -class App; - -//------------------------------------------------------------------------------ -// Block Edit Dialog -//------------------------------------------------------------------------------ -namespace ax { -namespace NodeEditor { -namespace Detail { - -bool ShowBlockEditDialog(Node* node, App* app); - -} // namespace Detail -} // namespace NodeEditor -} // namespace ax \ No newline at end of file diff --git a/imgui_node_editor_links.cpp b/imgui_node_editor_links.cpp deleted file mode 100644 index 561284a..0000000 --- a/imgui_node_editor_links.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//------------------------------------------------------------------------------ -// VERSION 0.9.1 -// -// LICENSE -// This software is dual-licensed to the public domain and under the following -// license: you are granted a perpetual, irrevocable license to copy, modify, -// publish, and distribute this file as you see fit. -// -// CREDITS -// Written by Michal Cichon -//------------------------------------------------------------------------------ -# include "imgui_node_editor_internal.h" -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace ed = ax::NodeEditor::Detail; diff --git a/imgui_node_editor_render.cpp b/imgui_node_editor_render.cpp deleted file mode 100644 index 561284a..0000000 --- a/imgui_node_editor_render.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//------------------------------------------------------------------------------ -// VERSION 0.9.1 -// -// LICENSE -// This software is dual-licensed to the public domain and under the following -// license: you are granted a perpetual, irrevocable license to copy, modify, -// publish, and distribute this file as you see fit. -// -// CREDITS -// Written by Michal Cichon -//------------------------------------------------------------------------------ -# include "imgui_node_editor_internal.h" -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace ed = ax::NodeEditor::Detail; diff --git a/imgui_node_editor_runtime.cpp b/imgui_node_editor_runtime.cpp deleted file mode 100644 index a47475e..0000000 --- a/imgui_node_editor_runtime.cpp +++ /dev/null @@ -1,15 +0,0 @@ -//------------------------------------------------------------------------------ -// Runtime execution system for node editor -// Executes blocks when their inputs are activated -//------------------------------------------------------------------------------ -#include "imgui_node_editor_internal.h" - -// Forward declaration - App class from blueprints-example -// We'll use a function pointer approach to avoid including app.h here -namespace { - typedef void (*ExecuteRuntimeCallback)(void* app); - static ExecuteRuntimeCallback s_RuntimeCallback = nullptr; - static void* s_RuntimeApp = nullptr; -} - -namespace ed = ax::NodeEditor::Detail; diff --git a/imgui_node_editor_selection.cpp b/imgui_node_editor_selection.cpp deleted file mode 100644 index 561284a..0000000 --- a/imgui_node_editor_selection.cpp +++ /dev/null @@ -1,23 +0,0 @@ -//------------------------------------------------------------------------------ -// VERSION 0.9.1 -// -// LICENSE -// This software is dual-licensed to the public domain and under the following -// license: you are granted a perpetual, irrevocable license to copy, modify, -// publish, and distribute this file as you see fit. -// -// CREDITS -// Written by Michal Cichon -//------------------------------------------------------------------------------ -# include "imgui_node_editor_internal.h" -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace ed = ax::NodeEditor::Detail; diff --git a/imgui_node_editor_tools.cpp b/imgui_node_editor_tools.cpp deleted file mode 100644 index ed979f6..0000000 --- a/imgui_node_editor_tools.cpp +++ /dev/null @@ -1,186 +0,0 @@ -//------------------------------------------------------------------------------ -// VERSION 0.9.1 -// -// LICENSE -// This software is dual-licensed to the public domain and under the following -// license: you are granted a perpetual, irrevocable license to copy, modify, -// publish, and distribute this file as you see fit. -// -// CREDITS -// Written by Michal Cichon -//------------------------------------------------------------------------------ - -# include "imgui_node_editor_internal.h" -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -namespace ed = ax::NodeEditor::Detail; - -//------------------------------------------------------------------------------ -// In-App Logger (similar to ImGui demo's ExampleAppLog) -//------------------------------------------------------------------------------ -class InAppLogger -{ -public: - ImGuiTextBuffer Buf; - ImGuiTextFilter Filter; - ImVector LineOffsets; // Index to lines offset. We maintain this with AddLog() calls. - bool AutoScroll; // Keep scrolling if already at the bottom. - int MaxLines; // Maximum number of lines to keep - - InAppLogger() - { - AutoScroll = true; - MaxLines = 1000; // Keep last 1000 lines - Clear(); - } - - void Clear() - { - Buf.clear(); - LineOffsets.clear(); - LineOffsets.push_back(0); - } - - void AddLog(const char* fmt, ...) IM_FMTARGS(2) - { - int old_size = Buf.size(); - va_list args; - va_start(args, fmt); - Buf.appendfv(fmt, args); - va_end(args); - UpdateLineOffsets(old_size); - } - - void AddLogV(const char* fmt, va_list args) - { - int old_size = Buf.size(); - Buf.appendfv(fmt, args); - UpdateLineOffsets(old_size); - } - - void DrawInline(float height); - -private: - void UpdateLineOffsets(int old_size) - { - for (int new_size = Buf.size(); old_size < new_size; old_size++) - if (Buf[old_size] == '\n') - LineOffsets.push_back(old_size + 1); - - // Trim to MaxLines if needed - if (LineOffsets.Size > MaxLines) - { - int linesToRemove = LineOffsets.Size - MaxLines; - int bytesToRemove = LineOffsets[linesToRemove]; - Buf.Buf.erase(Buf.Buf.Data, Buf.Buf.Data + bytesToRemove); - LineOffsets.erase(LineOffsets.Data, LineOffsets.Data + linesToRemove); - // Adjust remaining offsets - for (int i = 0; i < LineOffsets.Size; i++) - LineOffsets[i] -= bytesToRemove; - } - } -}; - -//------------------------------------------------------------------------------ -void InAppLogger::DrawInline(float height) -{ - // Header - ImGui::GetWindowDrawList()->AddRectFilled( - ImGui::GetCursorScreenPos(), - ImGui::GetCursorScreenPos() + ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetTextLineHeight()), - ImColor(ImGui::GetStyle().Colors[ImGuiCol_HeaderActive]), ImGui::GetTextLineHeight() * 0.25f); - ImGui::Spacing(); ImGui::SameLine(); - ImGui::TextUnformatted("Log"); - ImGui::SameLine(); - ImGui::TextDisabled("(%d)", LineOffsets.Size > 0 ? LineOffsets.Size - 1 : 0); - - // Options menu - ImGui::SameLine(); - if (ImGui::SmallButton("Clear")) - Clear(); - ImGui::SameLine(); - bool copy = ImGui::SmallButton("Copy"); - ImGui::SameLine(); - Filter.Draw("Filter", -60.0f); - - ImGui::Separator(); - - // Scrolling region - ImGui::BeginChild("scrolling_log", ImVec2(0, height), false, ImGuiWindowFlags_HorizontalScrollbar); - - if (copy) - ImGui::LogToClipboard(); - - ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); - const char* buf = Buf.begin(); - const char* buf_end = Buf.end(); - - if (Filter.IsActive()) - { - // Filter is active - show filtered lines - for (int line_no = 0; line_no < LineOffsets.Size; line_no++) - { - const char* line_start = buf + LineOffsets[line_no]; - const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end; - if (Filter.PassFilter(line_start, line_end)) - ImGui::TextUnformatted(line_start, line_end); - } - } - else - { - // No filter - use clipper for performance - ImGuiListClipper clipper; - clipper.Begin(LineOffsets.Size); - while (clipper.Step()) - { - for (int line_no = clipper.DisplayStart; line_no < clipper.DisplayEnd; line_no++) - { - const char* line_start = buf + LineOffsets[line_no]; - const char* line_end = (line_no + 1 < LineOffsets.Size) ? (buf + LineOffsets[line_no + 1] - 1) : buf_end; - ImGui::TextUnformatted(line_start, line_end); - } - } - clipper.End(); - } - ImGui::PopStyleVar(); - - // Keep up at the bottom of the scroll region if we were already at the bottom - if (AutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) - ImGui::SetScrollHereY(1.0f); - - ImGui::EndChild(); - - if (copy) - ImGui::LogFinish(); -} - -static InAppLogger g_InAppLogger; - -//------------------------------------------------------------------------------ -// Function to add log message from external code (like LogV) -//------------------------------------------------------------------------------ -void ed::AddInAppLog(const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - g_InAppLogger.AddLogV(fmt, args); - va_end(args); -} - -//------------------------------------------------------------------------------ -// Function to draw the in-app logger inline (for use in panels) -//------------------------------------------------------------------------------ -void ed::DrawInAppLogger(float height) -{ - g_InAppLogger.DrawInline(height); -} diff --git a/misc/cmake-modules/Findimgui_node_editor.cmake b/misc/cmake-modules/Findimgui_node_editor.cmake index 2b22ea2..c16b202 100644 --- a/misc/cmake-modules/Findimgui_node_editor.cmake +++ b/misc/cmake-modules/Findimgui_node_editor.cmake @@ -1,57 +1,61 @@ +# Prevent re-defining the target when this module is included multiple times. if (TARGET imgui_node_editor) return() endif() -#set(_imgui_node_editor_SourceDir ${IMGUI_NODE_EDITOR_ROOT_DIR}) -#set(_imgui_node_editor_BinaryDir ${CMAKE_BINARY_DIR}/NodeEditor) - -#add_subdirectory(${_imgui_node_editor_SourceDir} ${_imgui_node_editor_BinaryDir}) - +# ImGui node editor depends on dear imgui. Require the package so we can link +# against the imgui target that it provides. find_package(imgui REQUIRED) +# List every translation unit that belongs to the node editor library. The +# consuming project must pass `IMGUI_NODE_EDITOR_ROOT_DIR` when calling +# `find_package(imgui_node_editor)` so that each path resolves correctly. +# Duplicates are harmless but can be cleaned up later. set(_imgui_node_editor_Sources - ${IMGUI_NODE_EDITOR_ROOT_DIR}/crude_json.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/crude_json.h - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_bezier_math.h - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_bezier_math.inl - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_canvas.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_canvas.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_canvas.h - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_canvas.h - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_extra_math.h - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_extra_math.inl - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_api.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_tools.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_animation.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_store.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_edit.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_links.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_selection.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_render.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_runtime.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/EditorContext.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/EditorContext.h - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_internal.h - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor_internal.inl - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/imgui_node_editor.h - ${IMGUI_NODE_EDITOR_ROOT_DIR}/links-guided.cpp - ${IMGUI_NODE_EDITOR_ROOT_DIR}/links-guided.h + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/crude_json.cpp + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/crude_json.h + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_bezier_math.h + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_bezier_math.inl + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_canvas.cpp + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_canvas.h + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_extra_math.h + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_extra_math.inl + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_node_editor_api.cpp + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_node_editor_animation.cpp + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_node_editor_store.cpp + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/EditorContext.cpp + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/EditorContext.h + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_node_editor_internal.h + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_node_editor_internal.inl + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_node_editor.cpp + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/imgui_node_editor.h + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/links-guided.cpp + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node/links-guided.h ${IMGUI_NODE_EDITOR_ROOT_DIR}/misc/imgui_node_editor.natvis ) +# Build the editor implementation as a static library that downstream projects +# can link against. add_library(imgui_node_editor STATIC ${_imgui_node_editor_Sources} ) +# Expose the root directory so that depending targets can include headers with +# simple relative paths (e.g. `#include "imgui_node_editor.h"`). target_include_directories(imgui_node_editor PUBLIC - ${IMGUI_NODE_EDITOR_ROOT_DIR} + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external + ${IMGUI_NODE_EDITOR_ROOT_DIR}/external/imgui_node ) +# Link against dear imgui provided by the earlier `find_package` call. target_link_libraries(imgui_node_editor PUBLIC imgui) +# Arrange sources into folders in IDEs that support virtual source groups. source_group(TREE ${IMGUI_NODE_EDITOR_ROOT_DIR} FILES ${_imgui_node_editor_Sources}) +# Use CMake's helper to generate the usual `imgui_node_editor` package result: +# - `FOUND` variable +# - Optional diagnostic messages when variables are missing. include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) find_package_handle_standard_args( diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..0e1d419 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,1346 @@ +{ + "name": "NodeHub", + "version": "0.0.0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "NodeHub", + "version": "0.0.0.0.1", + "license": "Mars Limited", + "dependencies": { + "vitest": "^4.0.10" + } + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.12.tgz", + "integrity": "sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.12.tgz", + "integrity": "sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.12.tgz", + "integrity": "sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.12.tgz", + "integrity": "sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.12.tgz", + "integrity": "sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.12.tgz", + "integrity": "sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.12.tgz", + "integrity": "sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.12.tgz", + "integrity": "sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.12.tgz", + "integrity": "sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.12.tgz", + "integrity": "sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.12.tgz", + "integrity": "sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.12.tgz", + "integrity": "sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==", + "cpu": [ + "loong64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.12.tgz", + "integrity": "sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==", + "cpu": [ + "mips64el" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.12.tgz", + "integrity": "sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.12.tgz", + "integrity": "sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==", + "cpu": [ + "riscv64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.12.tgz", + "integrity": "sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==", + "cpu": [ + "s390x" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.12.tgz", + "integrity": "sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.12.tgz", + "integrity": "sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.12.tgz", + "integrity": "sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.12.tgz", + "integrity": "sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.12.tgz", + "integrity": "sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/openharmony-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/openharmony-arm64/-/openharmony-arm64-0.25.12.tgz", + "integrity": "sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.12.tgz", + "integrity": "sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.12.tgz", + "integrity": "sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.12.tgz", + "integrity": "sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.12.tgz", + "integrity": "sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=18" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.5.tgz", + "integrity": "sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==", + "license": "MIT" + }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.53.3.tgz", + "integrity": "sha512-mRSi+4cBjrRLoaal2PnqH82Wqyb+d3HsPUN/W+WslCXsZsyHa9ZeQQX/pQsZaVIWDkPcpV6jJ+3KLbTbgnwv8w==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.53.3.tgz", + "integrity": "sha512-CbDGaMpdE9sh7sCmTrTUyllhrg65t6SwhjlMJsLr+J8YjFuPmCEjbBSx4Z/e4SmDyH3aB5hGaJUP2ltV/vcs4w==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.53.3.tgz", + "integrity": "sha512-Nr7SlQeqIBpOV6BHHGZgYBuSdanCXuw09hon14MGOLGmXAFYjx1wNvquVPmpZnl0tLjg25dEdr4IQ6GgyToCUA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.53.3.tgz", + "integrity": "sha512-DZ8N4CSNfl965CmPktJ8oBnfYr3F8dTTNBQkRlffnUarJ2ohudQD17sZBa097J8xhQ26AwhHJ5mvUyQW8ddTsQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.53.3.tgz", + "integrity": "sha512-yMTrCrK92aGyi7GuDNtGn2sNW+Gdb4vErx4t3Gv/Tr+1zRb8ax4z8GWVRfr3Jw8zJWvpGHNpss3vVlbF58DZ4w==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.53.3.tgz", + "integrity": "sha512-lMfF8X7QhdQzseM6XaX0vbno2m3hlyZFhwcndRMw8fbAGUGL3WFMBdK0hbUBIUYcEcMhVLr1SIamDeuLBnXS+Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.53.3.tgz", + "integrity": "sha512-k9oD15soC/Ln6d2Wv/JOFPzZXIAIFLp6B+i14KhxAfnq76ajt0EhYc5YPeX6W1xJkAdItcVT+JhKl1QZh44/qw==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.53.3.tgz", + "integrity": "sha512-vTNlKq+N6CK/8UktsrFuc+/7NlEYVxgaEgRXVUVK258Z5ymho29skzW1sutgYjqNnquGwVUObAaxae8rZ6YMhg==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.53.3.tgz", + "integrity": "sha512-RGrFLWgMhSxRs/EWJMIFM1O5Mzuz3Xy3/mnxJp/5cVhZ2XoCAxJnmNsEyeMJtpK+wu0FJFWz+QF4mjCA7AUQ3w==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.53.3.tgz", + "integrity": "sha512-kASyvfBEWYPEwe0Qv4nfu6pNkITLTb32p4yTgzFCocHnJLAHs+9LjUu9ONIhvfT/5lv4YS5muBHyuV84epBo/A==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-gnu": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.53.3.tgz", + "integrity": "sha512-JiuKcp2teLJwQ7vkJ95EwESWkNRFJD7TQgYmCnrPtlu50b4XvT5MOmurWNrCj3IFdyjBQ5p9vnrX4JM6I8OE7g==", + "cpu": [ + "loong64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-gnu": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.53.3.tgz", + "integrity": "sha512-EoGSa8nd6d3T7zLuqdojxC20oBfNT8nexBbB/rkxgKj5T5vhpAQKKnD+h3UkoMuTyXkP5jTjK/ccNRmQrPNDuw==", + "cpu": [ + "ppc64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.53.3.tgz", + "integrity": "sha512-4s+Wped2IHXHPnAEbIB0YWBv7SDohqxobiiPA1FIWZpX+w9o2i4LezzH/NkFUl8LRci/8udci6cLq+jJQlh+0g==", + "cpu": [ + "riscv64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-musl": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.53.3.tgz", + "integrity": "sha512-68k2g7+0vs2u9CxDt5ktXTngsxOQkSEV/xBbwlqYcUrAVh6P9EgMZvFsnHy4SEiUl46Xf0IObWVbMvPrr2gw8A==", + "cpu": [ + "riscv64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.53.3.tgz", + "integrity": "sha512-VYsFMpULAz87ZW6BVYw3I6sWesGpsP9OPcyKe8ofdg9LHxSbRMd7zrVrr5xi/3kMZtpWL/wC+UIJWJYVX5uTKg==", + "cpu": [ + "s390x" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.53.3.tgz", + "integrity": "sha512-3EhFi1FU6YL8HTUJZ51imGJWEX//ajQPfqWLI3BQq4TlvHy4X0MOr5q3D2Zof/ka0d5FNdPwZXm3Yyib/UEd+w==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.53.3.tgz", + "integrity": "sha512-eoROhjcc6HbZCJr+tvVT8X4fW3/5g/WkGvvmwz/88sDtSJzO7r/blvoBDgISDiCjDRZmHpwud7h+6Q9JxFwq1Q==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-openharmony-arm64": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.53.3.tgz", + "integrity": "sha512-OueLAWgrNSPGAdUdIjSWXw+u/02BRTcnfw9PN41D2vq/JSEPnJnVuBgw18VkN8wcd4fjUs+jFHVM4t9+kBSNLw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.53.3.tgz", + "integrity": "sha512-GOFuKpsxR/whszbF/bzydebLiXIHSgsEUp6M0JI8dWvi+fFa1TD6YQa4aSZHtpmh2/uAlj/Dy+nmby3TJ3pkTw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.53.3.tgz", + "integrity": "sha512-iah+THLcBJdpfZ1TstDFbKNznlzoxa8fmnFYK4V67HvmuNYkVdAywJSoteUszvBQ9/HqN2+9AZghbajMsFT+oA==", + "cpu": [ + "ia32" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-gnu": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.53.3.tgz", + "integrity": "sha512-J9QDiOIZlZLdcot5NXEepDkstocktoVjkaKUtqzgzpt2yWjGlbYiKyp05rWwk4nypbYUNoFAztEgixoLaSETkg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.53.3.tgz", + "integrity": "sha512-UhTd8u31dXadv0MopwGgNOBpUVROFKWVQgAg5N1ESyCz8AuBcMqm4AuTjrwgQKGDfoFuz02EuMRHQIw/frmYKQ==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@standard-schema/spec": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@standard-schema/spec/-/spec-1.0.0.tgz", + "integrity": "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA==", + "license": "MIT" + }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.8.tgz", + "integrity": "sha512-dWHzHa2WqEXI/O1E9OjrocMTKJl2mSrEolh1Iomrv6U+JuNwaHXsXx9bLu5gG7BUWFIN0skIQJQ/L1rIex4X6w==", + "license": "MIT" + }, + "node_modules/@vitest/expect": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.0.10.tgz", + "integrity": "sha512-3QkTX/lK39FBNwARCQRSQr0TP9+ywSdxSX+LgbJ2M1WmveXP72anTbnp2yl5fH+dU6SUmBzNMrDHs80G8G2DZg==", + "license": "MIT", + "dependencies": { + "@standard-schema/spec": "^1.0.0", + "@types/chai": "^5.2.2", + "@vitest/spy": "4.0.10", + "@vitest/utils": "4.0.10", + "chai": "^6.2.1", + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-4.0.10.tgz", + "integrity": "sha512-e2OfdexYkjkg8Hh3L9NVEfbwGXq5IZbDovkf30qW2tOh7Rh9sVtmSr2ztEXOFbymNxS4qjzLXUQIvATvN4B+lg==", + "license": "MIT", + "dependencies": { + "@vitest/spy": "4.0.10", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.21" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^6.0.0 || ^7.0.0-0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/pretty-format": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-4.0.10.tgz", + "integrity": "sha512-99EQbpa/zuDnvVjthwz5bH9o8iPefoQZ63WV8+bsRJZNw3qQSvSltfut8yu1Jc9mqOYi7pEbsKxYTi/rjaq6PA==", + "license": "MIT", + "dependencies": { + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-4.0.10.tgz", + "integrity": "sha512-EXU2iSkKvNwtlL8L8doCpkyclw0mc/t4t9SeOnfOFPyqLmQwuceMPA4zJBa6jw0MKsZYbw7kAn+gl7HxrlB8UQ==", + "license": "MIT", + "dependencies": { + "@vitest/utils": "4.0.10", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-4.0.10.tgz", + "integrity": "sha512-2N4X2ZZl7kZw0qeGdQ41H0KND96L3qX1RgwuCfy6oUsF2ISGD/HpSbmms+CkIOsQmg2kulwfhJ4CI0asnZlvkg==", + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.0.10", + "magic-string": "^0.30.21", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-4.0.10.tgz", + "integrity": "sha512-AsY6sVS8OLb96GV5RoG8B6I35GAbNrC49AO+jNRF9YVGb/g9t+hzNm1H6kD0NDp8tt7VJLs6hb7YMkDXqu03iw==", + "license": "MIT", + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-4.0.10.tgz", + "integrity": "sha512-kOuqWnEwZNtQxMKg3WmPK1vmhZu9WcoX69iwWjVz+jvKTsF1emzsv3eoPcDr6ykA3qP2bsCQE7CwqfNtAVzsmg==", + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "4.0.10", + "tinyrainbow": "^3.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "license": "MIT", + "engines": { + "node": ">=12" + } + }, + "node_modules/chai": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/chai/-/chai-6.2.1.tgz", + "integrity": "sha512-p4Z49OGG5W/WBCPSS/dH3jQ73kD6tiMmUM+bckNK6Jr5JHMG3k9bg/BvKR8lKmtVBKmOiuVaV2ws8s9oSbwysg==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/es-module-lexer": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", + "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==", + "license": "MIT" + }, + "node_modules/esbuild": { + "version": "0.25.12", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.12.tgz", + "integrity": "sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==", + "hasInstallScript": true, + "license": "MIT", + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.25.12", + "@esbuild/android-arm": "0.25.12", + "@esbuild/android-arm64": "0.25.12", + "@esbuild/android-x64": "0.25.12", + "@esbuild/darwin-arm64": "0.25.12", + "@esbuild/darwin-x64": "0.25.12", + "@esbuild/freebsd-arm64": "0.25.12", + "@esbuild/freebsd-x64": "0.25.12", + "@esbuild/linux-arm": "0.25.12", + "@esbuild/linux-arm64": "0.25.12", + "@esbuild/linux-ia32": "0.25.12", + "@esbuild/linux-loong64": "0.25.12", + "@esbuild/linux-mips64el": "0.25.12", + "@esbuild/linux-ppc64": "0.25.12", + "@esbuild/linux-riscv64": "0.25.12", + "@esbuild/linux-s390x": "0.25.12", + "@esbuild/linux-x64": "0.25.12", + "@esbuild/netbsd-arm64": "0.25.12", + "@esbuild/netbsd-x64": "0.25.12", + "@esbuild/openbsd-arm64": "0.25.12", + "@esbuild/openbsd-x64": "0.25.12", + "@esbuild/openharmony-arm64": "0.25.12", + "@esbuild/sunos-x64": "0.25.12", + "@esbuild/win32-arm64": "0.25.12", + "@esbuild/win32-ia32": "0.25.12", + "@esbuild/win32-x64": "0.25.12" + } + }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/expect-type": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.2.2.tgz", + "integrity": "sha512-JhFGDVJ7tmDJItKhYgJCGLOWjuK9vPxiXoUFLwLDc99NlmklilbiQJwoctZtt13+xMw91MCk/REan6MWHqDjyA==", + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/nanoid": { + "version": "3.3.11", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.11.tgz", + "integrity": "sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "license": "MIT" + }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "license": "ISC" + }, + "node_modules/picomatch": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.3.tgz", + "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/postcss": { + "version": "8.5.6", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.6.tgz", + "integrity": "sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.11", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.1" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, + "node_modules/rollup": { + "version": "4.53.3", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.53.3.tgz", + "integrity": "sha512-w8GmOxZfBmKknvdXU1sdM9NHcoQejwF/4mNgj2JuEEdRaHwwF12K7e9eXn1nLZ07ad+du76mkVsyeb2rKGllsA==", + "license": "MIT", + "dependencies": { + "@types/estree": "1.0.8" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.53.3", + "@rollup/rollup-android-arm64": "4.53.3", + "@rollup/rollup-darwin-arm64": "4.53.3", + "@rollup/rollup-darwin-x64": "4.53.3", + "@rollup/rollup-freebsd-arm64": "4.53.3", + "@rollup/rollup-freebsd-x64": "4.53.3", + "@rollup/rollup-linux-arm-gnueabihf": "4.53.3", + "@rollup/rollup-linux-arm-musleabihf": "4.53.3", + "@rollup/rollup-linux-arm64-gnu": "4.53.3", + "@rollup/rollup-linux-arm64-musl": "4.53.3", + "@rollup/rollup-linux-loong64-gnu": "4.53.3", + "@rollup/rollup-linux-ppc64-gnu": "4.53.3", + "@rollup/rollup-linux-riscv64-gnu": "4.53.3", + "@rollup/rollup-linux-riscv64-musl": "4.53.3", + "@rollup/rollup-linux-s390x-gnu": "4.53.3", + "@rollup/rollup-linux-x64-gnu": "4.53.3", + "@rollup/rollup-linux-x64-musl": "4.53.3", + "@rollup/rollup-openharmony-arm64": "4.53.3", + "@rollup/rollup-win32-arm64-msvc": "4.53.3", + "@rollup/rollup-win32-ia32-msvc": "4.53.3", + "@rollup/rollup-win32-x64-gnu": "4.53.3", + "@rollup/rollup-win32-x64-msvc": "4.53.3", + "fsevents": "~2.3.2" + } + }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "license": "ISC" + }, + "node_modules/source-map-js": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", + "integrity": "sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==", + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "license": "MIT" + }, + "node_modules/std-env": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz", + "integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==", + "license": "MIT" + }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz", + "integrity": "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==", + "license": "MIT" + }, + "node_modules/tinyglobby": { + "version": "0.2.15", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.15.tgz", + "integrity": "sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==", + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.3" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tinyrainbow": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-3.0.3.tgz", + "integrity": "sha512-PSkbLUoxOFRzJYjjxHJt9xro7D+iilgMX/C9lawzVuYiIdcihh9DXmVibBe8lmcFrRi/VzlPjBxbN7rH24q8/Q==", + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/vite": { + "version": "7.2.2", + "resolved": "https://registry.npmjs.org/vite/-/vite-7.2.2.tgz", + "integrity": "sha512-BxAKBWmIbrDgrokdGZH1IgkIk/5mMHDreLDmCJ0qpyJaAteP8NvMhkwr/ZCQNqNH97bw/dANTE9PDzqwJghfMQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "esbuild": "^0.25.0", + "fdir": "^6.5.0", + "picomatch": "^4.0.3", + "postcss": "^8.5.6", + "rollup": "^4.43.0", + "tinyglobby": "^0.2.15" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "lightningcss": "^1.21.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vitest": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-4.0.10.tgz", + "integrity": "sha512-2Fqty3MM9CDwOVet/jaQalYlbcjATZwPYGcqpiYQqgQ/dLC7GuHdISKgTYIVF/kaishKxLzleKWWfbSDklyIKg==", + "license": "MIT", + "dependencies": { + "@vitest/expect": "4.0.10", + "@vitest/mocker": "4.0.10", + "@vitest/pretty-format": "4.0.10", + "@vitest/runner": "4.0.10", + "@vitest/snapshot": "4.0.10", + "@vitest/spy": "4.0.10", + "@vitest/utils": "4.0.10", + "debug": "^4.4.3", + "es-module-lexer": "^1.7.0", + "expect-type": "^1.2.2", + "magic-string": "^0.30.21", + "pathe": "^2.0.3", + "picomatch": "^4.0.3", + "std-env": "^3.10.0", + "tinybench": "^2.9.0", + "tinyexec": "^0.3.2", + "tinyglobby": "^0.2.15", + "tinyrainbow": "^3.0.3", + "vite": "^6.0.0 || ^7.0.0", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^20.0.0 || ^22.0.0 || >=24.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@types/debug": "^4.1.12", + "@types/node": "^20.0.0 || ^22.0.0 || >=24.0.0", + "@vitest/browser-playwright": "4.0.10", + "@vitest/browser-preview": "4.0.10", + "@vitest/browser-webdriverio": "4.0.10", + "@vitest/ui": "4.0.10", + "happy-dom": "*", + "jsdom": "*" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@types/debug": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser-playwright": { + "optional": true + }, + "@vitest/browser-preview": { + "optional": true + }, + "@vitest/browser-webdriverio": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + } + } + }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + } + } +} diff --git a/package.json b/package.json index e67de54..281e03b 100644 --- a/package.json +++ b/package.json @@ -1,45 +1,23 @@ { - "name": "@plastichub/template", - "description": "", - "version": "0.3.1", - "main": "main.js", - "typings": "index.d.ts", - "publishConfig": { - "access": "public" - }, - "bin": { - "osr-bin": "main.js" - }, - "dependencies": { - "@types/node": "^14.17.5", - "@types/yargs": "^17.0.2", - "chalk": "^2.4.1", - "convert-units": "^2.3.4", - "env-var": "^7.0.1", - "typescript": "^4.3.5", - "yargs": "^14.2.3", - "yargs-parser": "^15.0.3" - }, + "name": "NodeHub", + "version": "0.0.0.0.1", + "main": "index.js", "scripts": { - "test": "tsc; mocha --full-trace mocha \"spec/**/*.spec.js\"", - "test-with-coverage": "istanbul cover node_modules/.bin/_mocha -- 'spec/**/*.spec.js'", - "lint": "tslint --project=./tsconfig.json", - "build": "tsc -p .", - "dev": "tsc -p . --declaration -w", - "typings": "tsc --declaration", - "docs": "npx typedoc src/index.ts", - "dev-test-watch": "mocha-typescript-watch" + "test": "npm run test:core", + "test:core": "cmake --build build --config Debug --target core_tests && ctest --test-dir build/tests --output-on-failure", + "test:e2e:core": "vitest run", + "mcp-server": "computer-control-mcp server", + "docs": "doxygen", + "docs:serve": "cd docs/html && serve", + "build:init": "cmake -S applications -B build -DCMAKE_TOOLCHAIN_FILE=\"REPLACE_WITH_YOUR_PATH/vcpkg/scripts/buildsystems/vcpkg.cmake\"", + "build": "sh scripts/build.sh", + "build:clean": "cmake --build build --config Debug --target clean", + "run": "sh run.sh" }, - "homepage": "https://git.osr-plastic.org/plastichub/lib-content", - "repository": { - "type": "git", - "url": "https://git.osr-plastic.org/plastichub/lib-content.git" - }, - "engines": { - "node": ">= 14.0.0" - }, - "license": "BSD-3-Clause", - "keywords": [ - "typescript" - ] + "keywords": [], + "author": "", + "license": "Mars Limited", + "dependencies": { + "vitest": "^4.0.10" + } } diff --git a/ref/basic-interaction-example.cpp b/ref/basic-interaction-example.cpp index 2637365..1789e11 100644 --- a/ref/basic-interaction-example.cpp +++ b/ref/basic-interaction-example.cpp @@ -2,7 +2,7 @@ # include # include # include -# include +# include # include # include "NodeEx.h" diff --git a/ref/cpp/main.c b/ref/cpp/main.c new file mode 100644 index 0000000..b2250c8 --- /dev/null +++ b/ref/cpp/main.c @@ -0,0 +1,130 @@ +// component_networked_demo.cpp --------------------------------------------- +#include +#include +#include + +#include +#include + +/* ────────────────────────────────── 0. Build flag → constexpr ──────────── */ +#if defined(ENABLE_MODBUS) && ENABLE_MODBUS + #define kEnableModbus true +#else + +#endif + +/* ────────────────────────────────── 1. Helper: maybe‑base ──────────────── */ +struct dummy_base {}; + +template +using maybe_base_t = + typename std::conditional::type; + +/* ────────────────────────────────── 2. Core contracts ──────────────────── */ +struct Component { + virtual void setup() = 0; + virtual void loop() = 0; + virtual ~Component() = default; +}; + +struct RegisterMap { + const uint16_t* data; + std::size_t size; +}; + +struct Networked { + virtual RegisterMap registerMapping() const = 0; + virtual uint16_t deviceAddress() const { return 1; } + virtual void onRegisterWrite(uint16_t, uint16_t) {} + virtual ~Networked() = default; +}; + +/* ────────────────────────────────── 3. ComponentNetworked ──────────────── */ +// Carries Networked only when kEnableModbus == true +using NetworkBase = maybe_base_t; + +class ComponentNetworked : public Component, public NetworkBase { + /* purely a glue; still abstract if Networked is really inherited */ +}; + +/* ────────────────────────────────── 4. TemperatureSensorNetworked ─────── */ +// Two specialisations – the compiler picks one at translation time +template +class TemperatureSensorNetworkedImpl; + +/* ----- 4.a NON‑networked flavour --------------------------------------- */ +template <> +class TemperatureSensorNetworkedImpl : public ComponentNetworked +{ +public: + void setup() override { Log.notice(F("[Temp<%d>] setup (lean)\n"), kEnableModbus); } + void loop() override { /* Log.verb(F("[Temp<%d>] loop (lean)\n"), kEnableModbus); */ } + + float readCelsius() const { return 25.0f; } +}; + +/* ----- 4.b Network‑capable flavour ------------------------------------- */ +template <> +class TemperatureSensorNetworkedImpl : public Component, public Networked +{ + std::array regs_{ 250 /*25 °C×10*/, 0 }; + +public: + /* Component part */ + void setup() override { Log.notice(F("[Temp<%d>] setup (net)\n"), kEnableModbus); } + void loop() override { /* Log.verb(F("[Temp<%d>] loop (net)\n"), kEnableModbus); */ } + + /* Networked part */ + RegisterMap registerMapping() const override { + return { regs_.data(), regs_.size() }; + } + uint16_t deviceAddress() const override { return 42; } + void onRegisterWrite(uint16_t r, uint16_t v) override { + if (r < regs_.size()) regs_[r] = v; + } + + float readCelsius() const { return regs_[0] / 10.0f; } +}; + +/* ----- 4.c Public alias ------------------------------------------------- */ +using TemperatureSensorNetworked = + TemperatureSensorNetworkedImpl; + +/* ────────────────────────────────── 5. Arduino setup/loop ───────────── */ + +// Global instance of the sensor +TemperatureSensorNetworked dev; + +void setup() { + // Initialize Serial and Logging + Serial.begin(115200); + while (!Serial && millis() < 3000) { delay(100); } // Wait for serial port connection + + Log.begin(LOG_LEVEL_VERBOSE, &Serial); + Log.notice(F("\n--- Logging Initialized ---\n")); + Log.notice(F("kEnableModbus = %d\n"), kEnableModbus); + + dev.setup(); + + // Conditionally compile the network check using the preprocessor +#if kEnableModbus + Log.notice(F("Network features compiled.\n")); + // Check if the resolved type actually inherits from Networked + if (std::is_base_of::value) { + Log.notice(F(" Device IS Networked. Address: %d, Registers:"), dev.deviceAddress()); + auto map = dev.registerMapping(); + for (std::size_t i = 0; i < map.size; ++i) Log.notice(F(" %d"), map.data[i]); + Log.notice(F("\n")); + } else { + Log.warning(F(" Device IS NOT Networked (type check failed).\n")); + } +#else + Log.notice(F("Network features NOT compiled.\n")); + // Demonstrate accessing non-networked specific method + Log.notice(F(" Device reading (lean): %.1f C\n"), dev.readCelsius()); +#endif +} + +void loop() { + dev.loop(); +} \ No newline at end of file diff --git a/ref/cpp/main.cpp b/ref/cpp/main.cpp new file mode 100644 index 0000000..15f784e --- /dev/null +++ b/ref/cpp/main.cpp @@ -0,0 +1,217 @@ +// feature_di_component_demo.cpp ------------------------------------------- +// Build the "lean" variant : g++ -std=c++20 -O2 -DDEMO_MAIN feature_di_component_demo.cpp -o demo +// Build the "Modbus" variant: g++ -std=c++20 -O2 -DDEMO_MAIN -DENABLE_MODBUS feature_di_component_demo.cpp -o demo_net +// @link ://chatgpt.com/share/6803c6b7-0468-8001-857f-352a31c8c9bd +// ─────────────────────────────────────────────────────────────────────────── + +#include // Added for Serial +#include +#include +#include +// #include // Replaced by Arduino.h +#include +#include // For info() return type example +#include // For strcmp + +/*──────────────────── 1. Tiny utility -----------------------------------*/ +struct RegisterMap { + const uint16_t* data; + std::size_t size; +}; + +/*──────────────────── 2. "Feature" concept (any module that has setup/loop/info)*/ +// Renamed and updated SFINAE check +template> +struct is_valid_feature : std::false_type {}; + +template +struct is_valid_feature().setup()), + decltype(std::declval().loop()), + decltype(std::declval().info()) // Added const info() check +>> : std::true_type {}; + +// Updated helper function +template constexpr bool is_valid_feature_func() { return is_valid_feature::value; } + + +/*──────────────────── 3. Individual feature packs -----------------------*/ +// 3a. Core sensor logic ──────────────────────────────────────────────── +struct CoreFeature { + static constexpr bool has_network = false; + + void setup() { Serial.println(F("[Core] setup")); } // Use Serial + void loop () { /*Serial.println(F("[Core] loop"));*/ } // Commented out for less noise + // Added info method + void info() const { Serial.println(F("[Core] Info: Basic temperature sensing.")); } // Use Serial + + float readCelsius() const { return 25.0f; } +}; + +// 3b. Optional Modbus/Network feature ────────────────────────────────── +struct ModbusFeature { + static constexpr bool has_network = true; + + std::array regs{ 250 /*25 °C×10*/, 0 }; + + void setup() { Serial.println(F("[Modbus] setup")); } // Use Serial + void loop () { /*Serial.println(F("[Modbus] loop"));*/ } // Commented out for less noise + // Added info method + void info() const { // Use Serial + Serial.print(F("[Modbus] Info: Modbus TCP/IP enabled. Address: ")); + Serial.println(deviceAddress()); + } + + + RegisterMap registerMapping() const { return { regs.data(), regs.size() }; } + uint16_t deviceAddress() const { return 42; } + + void onRegisterWrite(uint16_t r, uint16_t v) { + if (r < regs.size()) regs[r] = v; + } +}; + +// 3c. Default Logger feature ───────────────────────────────────────────── +struct LoggerFeature { + static constexpr bool has_network = true; // Assuming logger might send logs over network + void setup() { Serial.println(F("[Logger] setup")); } // Use Serial + void loop () { /*Serial.println(F("[Logger] loop"));*/ } // Commented out for less noise + // Added info method + void info() const { Serial.println(F("[Logger] Info: Basic console logging active.")); } // Use Serial +}; + + +/*──────────────────── 4. Generic "Device" aggregator ───────────────────*/ +// Use static_assert with the updated SFINAE check +// Inherit LoggerFeature by default +template +class Device : public LoggerFeature, public Fs... +{ + // Ensure the default and all *additional* base classes Fs satisfy the requirements + static_assert(is_valid_feature_func(), "Default LoggerFeature must implement setup(), loop(), and info()"); + // Use C++17 fold expression within the static_assert for additional features + static_assert(sizeof...(Fs) == 0 || (is_valid_feature_func() && ...), "All additional features must implement setup(), loop(), and info()"); + + +public: + void setup() { + LoggerFeature::setup(); // Explicitly call setup for the default feature + if constexpr (sizeof...(Fs) > 0) { // Check if there are other features + (Fs::setup(), ...); // Call setup for the rest using fold-expression + } + } + + void loop () { + LoggerFeature::loop(); // Explicitly call loop for the default feature + if constexpr (sizeof...(Fs) > 0) { + (Fs::loop (), ...); // Call loop for the rest + } + } + + // Added aggregated info method + void info() const { + // Call info() for LoggerFeature and all Fs... using a fold expression + (LoggerFeature::info(), (Fs::info(), ...)); + } + + // Include LoggerFeature's network status in the calculation + static constexpr bool has_network = LoggerFeature::has_network || (false || ... || Fs::has_network); +}; + +/*──────────────────── 5. Choose the feature bundle (application layer) ───*/ +// LoggerFeature is now implicitly included by Device +#ifdef ENABLE_MODBUS +using TemperatureSensor = Device; +#else +using TemperatureSensor = Device; +#endif + +/*──────────────────── Arduino Entry Points -------------------------------*/ +// Instantiate the device globally +TemperatureSensor device; + +// Buffer for serial commands +#define SERIAL_CMD_BUFFER_SIZE 64 +char serialCmdBuffer[SERIAL_CMD_BUFFER_SIZE]; +uint8_t serialCmdBufferIdx = 0; + +// Helper function to print commands +void printHelp() { + Serial.println(F("--- Serial Commands ---")); + Serial.println(F("1 - Show device info")); + Serial.println(F("? - Print this help message")); +} + +void setup() { + // Initialize Serial for logging, if needed (optional) + Serial.begin(115200); + // Wait for serial port to connect (needed for native USB) + // On some boards, this delay is needed to allow the Serial Monitor to connect + // On others (like ESP32), Serial begins immediately. Adjust if needed. + delay(1000); + while (!Serial && millis() < 3000); // Wait up to 3 seconds + + Serial.println(F("\n--- Serial Interface Ready ---")); + printHelp(); + + // <<< Hypothetical serial connection point >>> + Serial.println(F("--- Device Info ---")); + device.info(); // Call the aggregated info method + Serial.println(F("--- Device Setup ---")); + device.setup(); // Call the aggregated setup + Serial.println(F("--- Setup Complete ---")); +} + +void loop() { + device.loop(); // Call the aggregated loop + + // --- Handle Serial Input --- + while (Serial.available() > 0) { + char receivedChar = Serial.read(); + + // Handle backspace + if (receivedChar == '\b' || receivedChar == 127) { + if (serialCmdBufferIdx > 0) { + serialCmdBufferIdx--; + Serial.print("\b \b"); // Move cursor back, print space, move back again + } + continue; // Continue to next character + } + + // Echo character back (optional, good for interactive use) + Serial.print(receivedChar); + + // Process command on newline or carriage return + if (receivedChar == '\n' || receivedChar == '\r') { + serialCmdBuffer[serialCmdBufferIdx] = '\0'; // Null-terminate the string + Serial.println(); // Move to next line after command received + + if (serialCmdBufferIdx > 0) { // Process if buffer is not empty + // --- Process Commands --- + if (strcmp(serialCmdBuffer, "1") == 0) { + Serial.println(F("--- Device Info ---")); + device.info(); + } else if (strcmp(serialCmdBuffer, "?") == 0) { + printHelp(); + } else { + Serial.print(F("Unknown command: '")); + Serial.print(serialCmdBuffer); + Serial.println(F("'")); + printHelp(); // Show help on unknown command + } + } + // Reset buffer index for the next command + serialCmdBufferIdx = 0; + serialCmdBuffer[0] = '\0'; + } else if (serialCmdBufferIdx < SERIAL_CMD_BUFFER_SIZE - 1) { + // Add character to buffer if it's not newline/CR and buffer has space + serialCmdBuffer[serialCmdBufferIdx++] = receivedChar; + } + // Ignore characters if buffer is full until newline/CR is received + } + + + // Add delay or other logic if needed for stability + // delay(10); +} +// ─────────────────────────────────────────────────────────────────────────── diff --git a/ref/virtools/Includes/CKObject.h b/ref/virtools/Includes/CKObject.h index 7271d93..0cba324 100644 --- a/ref/virtools/Includes/CKObject.h +++ b/ref/virtools/Includes/CKObject.h @@ -1,9 +1,9 @@ /*************************************************************************/ /* File : CKObject.h */ -/* Author : Romain Sididris */ -/* */ -/* Virtools SDK */ -/* Copyright (c) Virtools 2000, All Rights Reserved. */ +/* Author : Romain Sididris */ +/* */ +/* Virtools SDK */ +/* Copyright (c) Virtools 2000, All Rights Reserved. */ /*************************************************************************/ #ifndef CKOBJECT_H @@ -34,8 +34,8 @@ Remarks: CKObject, though this is possible. You usually create instances of classes derived of CKObject (See CKContext::CreateObject). CKObject provides functionnalities that are applicable to all its derived classes. - + CKObject and derived classes have no public (exported) constructors. Instances of CKObject and derived classes are created - with the CKContext::CreateObject method, and should be deleted with the CKContext::DestroyObject method. The CKContext::DestroyObject + + CKObject and derived classes have no public (exported) constructors. Instances of CKObject and derived classes are created + with the CKContext::CreateObject method, and should be deleted with the CKContext::DestroyObject method. The CKContext::DestroyObject function ensures that all Virtools objects using the to-be-deleted object take the necessary mesures to reflect the upcoming deletion. If you have created and used the object for your own needs and are sure that it has not been referenced anywhere else, you may delete the object without notifications spcifying CK_DESTROY_NONOTIFY. @@ -52,15 +52,15 @@ Remarks: + Each class derived from CKObject has a class ID associated to it. You can access this class ID through the instances. This is usefull for filtering or triggering different actions on objects according to their class. You access - the class ID through the GetClassID method. + the class ID through the GetClassID method. + A name can be attached to each instance of the CKObject class and derived classes. This name is a CKSTRING. - This functionnality is provided as a conveniency for debugging purposes. The Virtools library does not do any processing + This functionnality is provided as a conveniency for debugging purposes. The Virtools library does not do any processing on name except for loading purposes only (in the case of animation that should be attributed to objects for example). + It is possible to associate arbitrary data to each instance of CKObject and derived classes. This data is not taken into account by the CK library. It is a service provided to the client application. The client - application is responsible for the memory management of this data, for conflict resolution about the access to + application is responsible for the memory management of this data, for conflict resolution about the access to the data and for its internal organization. You attach the data with the SetAppData method and you get it back with the GetAppData method. You can remove the data with by calling SetAppData with a NULL argument. @@ -77,7 +77,7 @@ public : void SetName(CKSTRING Name,CKBOOL shared=FALSE); //---------------------------------------------------------- -// Application Data +// Application Data void *GetAppData(); void SetAppData(void *Data); @@ -91,7 +91,7 @@ virtual CKBOOL IsHiddenByParent(); virtual int CanBeHide(); /************************************************* -Summary: Returns whether this object is visible. +Summary: Returns whether this object is visible. Return value: TRUE if the object is visible, FALSE otherwise. Remarks: +Only CKRenderObject and derived classes(CK2dEntity,CK3dEntity),CKMesh and CKGroup return relevant information @@ -133,7 +133,7 @@ Return Value: CK_ID of this object Remarks: Returns the global ID for the object. The ID is globally unique. It is automatically assigned to the object when it is created -(with CKContext::CreateObject and CKContext::CopyObject). It is safer to always store +(with CKContext::CreateObject and CKContext::CopyObject). It is safer to always store references to CKObject by storing its ID instead of pointers to these objects. You can retrieve an object from its ID using the CKGetObject or CKContext::GetObject function. See also: CreateObject, CreateCopy, CKContext::GetObject, Object Identifiers @@ -145,17 +145,17 @@ Summary: Returns the name of the object. Return Value: A pointer to the object name or NULL if the object is unnamed. Remarks: +Provided as a conveniency for debugging purposes. -+The Virtools library does not do any processing corresponding to the name ++The Virtools library does not do any processing corresponding to the name but it can be used when loading animation on objects for example. See Also:GetName,CKContext::GetObjectByName,CKContext::GetObjectByNameAndClass *************************************************/ -CKSTRING GetName() { - return m_Name; +CKSTRING GetName() { + return m_Name; } /************************************************* -Summary: Returns the current object flags for this object. +Summary: Returns the current object flags for this object. Return Value: A combination of CK_OBJECT_FLAGS for this objet. Remarks: @@ -168,7 +168,7 @@ CKDWORD GetObjectFlags() { return m_ObjectFlags; } /************************************************* -Summary: Returns if the current object is dynamic (can be deleted or created at runtime). +Summary: Returns if the current object is dynamic (can be deleted or created at runtime). Return value: TRUE if object is dynamic. Remarks: @@ -176,7 +176,7 @@ Remarks: See also: CK_OBJECT_FLAGS,ModifyObjectFlags,Dynamic Objects *************************************************/ -CKBOOL IsDynamic() { return ((m_ObjectFlags & CK_OBJECT_DYNAMIC) == CK_OBJECT_DYNAMIC); } +CKBOOL IsDynamic() { return ((m_ObjectFlags & CK_OBJECT_DYNAMIC) == CK_OBJECT_DYNAMIC); } /************************************************* Summary: Returns if the current object is to be deleted. @@ -191,7 +191,7 @@ See also: CK_OBJECT_FLAGS,ModifyObjectFlags CKBOOL IsToBeDeleted() { return (m_ObjectFlags & CK_OBJECT_TOBEDELETED);} /************************************************* -Summary: Adds or Removes flags for this object. +Summary: Adds or Removes flags for this object. Arguments: add : A combination of CK_OBJECT_FLAGS to add. remove : A combination of CK_OBJECT_FLAGS to remove. @@ -207,64 +207,64 @@ void ModifyObjectFlags(CKDWORD add,CKDWORD remove) { m_ObjectFlags |= add; m_Obj //-------------------------------------------------------- -//// Private Part +//// Private Part #ifdef DOCJETDUMMY // Docjet secret macro #else - CKObject() {} - CKObject(CKContext *Context,CKSTRING name=NULL); - virtual ~CKObject(); + CKObject() {} + CKObject(CKContext *Context,CKSTRING name=NULL); + virtual ~CKObject(); virtual CK_CLASSID GetClassID(); - virtual void PreSave(CKFile *file,CKDWORD flags); - virtual CKStateChunk* Save(CKFile *file,CKDWORD flags); - virtual CKERROR Load(CKStateChunk *chunk,CKFile* file); - virtual void PostLoad(); + virtual void PreSave(CKFile *file,CKDWORD flags); + virtual CKStateChunk* Save(CKFile *file,CKDWORD flags); + virtual CKERROR Load(CKStateChunk *chunk,CKFile* file); + virtual void PostLoad(); - virtual void PreDelete(); - virtual void CheckPreDeletion(); - virtual void CheckPostDeletion(); + virtual void PreDelete(); + virtual void CheckPreDeletion(); + virtual void CheckPostDeletion(); - virtual int GetMemoryOccupation(); - virtual CKBOOL IsObjectUsed(CKObject* obj,CK_CLASSID cid); + virtual int GetMemoryOccupation(); + virtual CKBOOL IsObjectUsed(CKObject* obj,CK_CLASSID cid); //-------------------------------------------- - // Dependencies functions + // Dependencies functions virtual CKERROR PrepareDependencies(CKDependenciesContext& context, CKBOOL iCaller = TRUE); - virtual CKERROR RemapDependencies(CKDependenciesContext& context); + virtual CKERROR RemapDependencies(CKDependenciesContext& context); virtual CKERROR Copy(CKObject& o,CKDependenciesContext& context); XString& SmartRenameForCopy(const CKSTRING oldName, const XString& copyAppendString); //-------------------------------------------- // Class Registering - static CKSTRING GetClassName(); - static int GetDependenciesCount(int mode); - static CKSTRING GetDependencies(int i,int mode); - static void Register(); - static CKObject* CreateInstance(CKContext *Context); - static void ReleaseInstance(CKContext* iContext,CKObject*); - static CK_CLASSID m_ClassID; - static CKObject* Cast(CKObject* iO) + static CKSTRING GetClassName(); + static int GetDependenciesCount(int mode); + static CKSTRING GetDependencies(int i,int mode); + static void Register(); + static CKObject* CreateInstance(CKContext *Context); + static void ReleaseInstance(CKContext* iContext,CKObject*); + static CK_CLASSID m_ClassID; + static CKObject* Cast(CKObject* iO) { return CKIsChildClassOf(iO,CKCID_OBJECT)?(CKObject*)iO:NULL; } - + public: - CK_ID m_ID; - CKSTRING m_Name; - CKDWORD m_ObjectFlags; - CKContext *m_Context; + CK_ID m_ID; + CKSTRING m_Name; + CKDWORD m_ObjectFlags; + CKContext *m_Context; // Flags acces - CKBOOL IsUpToDate() { return (m_ObjectFlags & CK_OBJECT_UPTODATE);} - CKBOOL IsPrivate() { return (m_ObjectFlags & CK_OBJECT_PRIVATE);} + CKBOOL IsUpToDate() { return (m_ObjectFlags & CK_OBJECT_UPTODATE);} + CKBOOL IsPrivate() { return (m_ObjectFlags & CK_OBJECT_PRIVATE);} CKBOOL IsNotToBeSaved() { return (m_ObjectFlags & CK_OBJECT_NOTTOBESAVED);} CKBOOL IsInterfaceObj() { return (m_ObjectFlags & CK_OBJECT_INTERFACEOBJ);} -// Util acces to CKContext functions - CKERROR CKDestroyObject(CKObject *obj,DWORD Flags=0,CKDependencies* depoptions=NULL) { return m_Context->DestroyObject(obj,Flags,depoptions); } - CKERROR CKDestroyObject(CK_ID id,DWORD Flags=0,CKDependencies* depoptions=NULL) { return m_Context->DestroyObject(id,Flags,depoptions); } - CKERROR CKDestroyObjects(CK_ID* obj_ids,int Count,DWORD Flags=0,CKDependencies* depoptions=NULL) { return m_Context->DestroyObjects(obj_ids,Count,Flags,depoptions); } +// Util acces to CKContext functions + CKERROR CKDestroyObject(CKObject *obj,DWORD Flags=0,CKDependencies* depoptions=NULL) { return m_Context->DestroyObject(obj,Flags,depoptions); } + CKERROR CKDestroyObject(CK_ID id,DWORD Flags=0,CKDependencies* depoptions=NULL) { return m_Context->DestroyObject(id,Flags,depoptions); } + CKERROR CKDestroyObjects(CK_ID* obj_ids,int Count,DWORD Flags=0,CKDependencies* depoptions=NULL) { return m_Context->DestroyObjects(obj_ids,Count,Flags,depoptions); } CKObject *CKGetObject(CK_ID id) { return m_Context->GetObject(id); } CKObject *GetCKObject(CK_ID id){ return m_Context->GetObject(id);} #endif // Docjet secret macro diff --git a/ref/vt-ex/include/AutoLock.h b/ref/vt-ex/include/AutoLock.h new file mode 100644 index 0000000..8359086 --- /dev/null +++ b/ref/vt-ex/include/AutoLock.h @@ -0,0 +1,572 @@ +/******************************************************************** + created: 2005/01/07 + created: 7:1:2002 13:08 + filename: D:\public\base\AutoLock.h + file path: D:\public\base + file base: AutoLock + file ext: h + author: Günter Baumgart + + purpose: +*********************************************************************/ + +#pragma once + +#include // Required for ATLASSERT macro +#include + +namespace AutoLock +{ + // SWMR enum wait lock types + enum _LOCKTYPE { LT_WAITTOREAD = 0, LT_WAITTOWRITE = 1 } ; + +template +class CAutoLockT +{ +// Attributes +private: + T* m_pObject; // the locked object + +// Ctor/dtor +public: + // Critical Section Ctor + inline CAutoLockT( T* pObject ) throw() + : m_pObject(pObject) + { + ATLASSERT( NULL != pObject ); + m_pObject->Lock(); + } + + // Mutex Ctor + inline CAutoLockT( T* pObject, DWORD dwTimeout ) + : m_pObject(pObject) + { + ATLASSERT( NULL != pObject ); + m_pObject->Lock( dwTimeout ); + } + + // SRMR Ctor + inline CAutoLockT( T* pObject, + const _LOCKTYPE uLockType, + LPCTSTR szOperation = NULL ) throw() + : m_pObject(pObject) + { + ATLASSERT( NULL != pObject ); + m_pObject->Lock( uLockType, szOperation ); + } + + // dtor + inline ~CAutoLockT() + { + m_pObject->Unlock(); + } +}; + +//+---------------------------------------------------------------------------- +// Class: CAutoLockWaitExc +// +// Purpose: CLockableMutex::Lock() method will throw this exception when +// an error occurs. +// +// Comment: NOTE: Callers should catch this exception. +//+---------------------------------------------------------------------------- +class CAutoLockWaitExc +{ +// Ctor +public: + CAutoLockWaitExc( DWORD dwWaitResult, DWORD dwError ) + : m_dwWaitResult( dwWaitResult ) + , m_dwError( dwError ) {} + +// Public Accessors +public: + inline const DWORD GetWaitResult() { return m_dwWaitResult; }; + inline const DWORD GetLastError() { return m_dwError; }; + +// Attributes +private: + DWORD m_dwWaitResult; // WaitForSingleObject return + DWORD m_dwError; // GetLastError return code +}; + +//+---------------------------------------------------------------------------- +// Class: CAutoLockExc +// +// Purpose: CLockableMutex::Lock() method will throw this exception when +// an error occurs. +// +// Comment: NOTE: Callers should catch this exception. +//+---------------------------------------------------------------------------- +class CAutoLockExc +{ +// Ctor +public: + CAutoLockExc( DWORD dwError ) + : m_dwError( dwError ) {} + +// Public Accessors +public: + inline const DWORD GetLastError() { return m_dwError; }; + +// Attributes +private: + DWORD m_dwError; // GetLastError return code +}; + +//+---------------------------------------------------------------------------- +// Embedded Class: CAutoLockTimeoutExc +// +// Purpose: CLockableMutex::Lock() method will throw this timeout exception +// when the timeout period has been exceeded. +// +// Comment: NOTE: Callers should catch this exception. +//+---------------------------------------------------------------------------- +class CAutoLockTimeoutExc +{ +// Ctor +public: + CAutoLockTimeoutExc( DWORD dwTimeout ) : m_dwTimeout( dwTimeout ) {} + +// Public Accessors +public: + inline const DWORD GetTimeout() { return m_dwTimeout; }; + +// Attributes +private: + DWORD m_dwTimeout; // Timeout value (although passed in + // to the Lock method, we store it + // here and make it available in the + // exception for convenience +}; + +//+---------------------------------------------------------------------------- +// Class: CLockableCS +// +// Purpose: This class is intended to be used as a base class for a +// multithreaded Critical Section lockable object. +// +//+---------------------------------------------------------------------------- +class CLockableCS +{ +// Methods +public: + // Ctor / Dtor + inline CLockableCS() throw() { InitializeCriticalSection( &m_CS ); } + inline ~CLockableCS() throw() { DeleteCriticalSection( &m_CS ); } + + // Lock / Unlock + inline void Lock() throw() { EnterCriticalSection( &m_CS ); } + inline void Unlock() throw() { LeaveCriticalSection( &m_CS ); } + +// Attributes +private: + CRITICAL_SECTION m_CS; // Internal Critical Section +}; + +//+---------------------------------------------------------------------------- +// Class: CLockableMutex +// +// Purpose: This class is intended to be used as a base class for a +// Mutex lockable object. +// +// Comment: NOTE: The lock method for this class will throw a +// CMutexLockExc exception (see below for declaration). +// Callees should catch this exception when calling the Lock method. +// +// Scope: Single or Multiple Processes +//+---------------------------------------------------------------------------- + +class CLockableMutex +{ +public: + inline CLockableMutex( LPCTSTR szName ) //throw() + : m_hMutex( ::CreateMutex( NULL, FALSE, szName ) ) + , m_bAlreadyExists( FALSE ) + { + // If the call has succeeded, check if the named mutex has already existed + if( NULL != m_hMutex ) + { + m_bAlreadyExists = ( ERROR_ALREADY_EXISTS == ::GetLastError( ) ); + } + else + { + // The call has failed. + if( ERROR_ACCESS_DENIED == ::GetLastError( ) ) + { + // We'll get the Access denied error when the mutex + // exists and the user does not have sufficient permissions + // to create an existing mutex (as in above). + // So we retry using OpenMutex + + if( NULL == ( m_hMutex = ::OpenMutex( MUTEX_MODIFY_STATE, + FALSE, + szName ) )) + { + // OpenMutex failed also, so throw an exception + throw CAutoLockExc( ::GetLastError( ) ); + } + else + { + m_bAlreadyExists = TRUE; + } + } + else + { + // Other unknown error + throw CAutoLockExc( ::GetLastError( ) ); + } + } + } + + inline ~CLockableMutex() throw() + { + if(m_hMutex) ::CloseHandle( m_hMutex ); + } + + //+------------------------------------------------------------------- + // Method: AlreadyExists + // Purpose: Use this method when you want to use a mutex to limit + // an executable to a single instance. Declare a CLockableMutex + // variable and check this param to find out if it existed + // prior to instantiating this class. + // + // Params: void + // Return: void + // + // Comments: See msdn docs on CreateMutex. This + //+------------------------------------------------------------------- + const BOOL AlreadyExists() { return m_bAlreadyExists; }; + + //+------------------------------------------------------------------- + // Method: Lock + // Purpose: Used by the CAutoLockT class to limit inter-process + // access. + // + // Params: ms Timeout + // Return: void + // + // Comments: Throws CTimeoutException or CException exceptions + //+------------------------------------------------------------------- + inline void Lock( DWORD dwTimeout ) + { + DWORD dwWaitResult = 0; + dwWaitResult = ::WaitForSingleObject( m_hMutex, dwTimeout ); + switch( dwWaitResult ) + { + case WAIT_OBJECT_0: + break; + case WAIT_TIMEOUT: + throw CAutoLockTimeoutExc( dwTimeout ); + break; + default: + throw CAutoLockWaitExc( dwWaitResult, ::GetLastError() ); + } + } + + //+------------------------------------------------------------------- + // Method: Unlock + // Purpose: Used by the CAutoLockT class (CAutoLockT::dtor) to + // release the mutex + // + // Params: void + // Return: void + inline void Unlock() throw() + { + if(m_hMutex) + { + ::ReleaseMutex( m_hMutex ); + } + } + +private: + HANDLE m_hMutex; // Name Mutex Handle + BOOL m_bAlreadyExists; // TRUE if named mutex already exists +}; + +//+---------------------------------------------------------------------------- +// Class: CLockableSWMR +// +// Purpose: This class is intended to be used as a base class for a +// SWMR (Single Writer, Multiple Reader) lockable object. +// +// Acknowledgements: +// This class is base on work by Jeffrey Richter in his book +// "Programming Applications for Microsoft Windows" +// +// Usage: +// Create a class derived from this and another resource class (such as +// an std::list<> class) when you have a scenario where the list seldom +// gets updated, but is frequently read by multiple threads. Under this +// scenario, this class would be more efficient than the CLockableCS +// class because multiple threads could read simultaneously whereas a +// CLockableCS implementation would only allow a single thread to read +// or write. Conversely, because this class makes use of the kernel +// semaphore object, it is not as efficient a CLockableCS under single +// read thread scenarios. +// +// To Lock to Read: +// CAutoLock< CLockableSWMR_Derived > lock( &m_SWMR, LT_WAITTOREAD ); +// +// To Lock to Write: +// CAutoLock< CLockableSWMR_Derived > lock( &m_SWMR, LT_WAITTOWRITE ); +// +// Public Methods: +// Lock( enumLockType, ... ) +// Unlock() +// +// Private Methods: +// WaitToRead(...) +// WaitToWrite(...) + + +// Scope: Single Process +//+---------------------------------------------------------------------------- +class CLockableSWMR +{ +public: + CLockableSWMR( ) throw() + : m_hSemReaders( CreateSemaphore(NULL, 0, MAXLONG, NULL) ) + , m_hSemWriters( CreateSemaphore(NULL, 0, MAXLONG, NULL) ) + , m_nWaitingReaders( 0 ) + , m_nWaitingWriters( 0 ) + , m_nActive( 0 ) + , m_sName( _T("") ) + { + } + + CLockableSWMR( LPCTSTR szName ) throw() + : m_hSemReaders( CreateSemaphore(NULL, 0, MAXLONG, NULL) ) + , m_hSemWriters( CreateSemaphore(NULL, 0, MAXLONG, NULL) ) + , m_nWaitingReaders( 0 ) + , m_nWaitingWriters( 0 ) + , m_nActive( 0 ) + , m_sName( szName ) + { + } + + ~CLockableSWMR() throw() + { + m_nWaitingReaders = 0; + m_nWaitingWriters = 0; + m_nActive = 0; + CloseHandle(m_hSemReaders); + CloseHandle(m_hSemWriters); + } + +// Attributes +private: + CLockableCS m_InternalCS; // Ensures exclusive access + // to member variables + HANDLE m_hSemReaders; // Readers wait on if a writer has access + HANDLE m_hSemWriters; // Writers wait on if a reader has access + int m_nWaitingReaders; // # of readers waiting + int m_nWaitingWriters; // # of writers waiting + int m_nActive; // # of threads currently w/access + // (0 == no threads, + // >0 == # of readers, + // -1 == 1 writer) + + CString m_sName; // Debug diagnostic string + + // Thread tracking enum + enum _ACTIVETHREADS { AT_ONEWRITER = -1, AT_NONE = 0 }; + +// Operations +public: + //+------------------------------------------------------------------- + // Method: Lock + // Purpose: Used by the CAutoLockT class to provide thread safe access. + // + // Params: enumLockType, szOperation (debug operation string) + // Return: void + //+------------------------------------------------------------------- + void Lock(const _LOCKTYPE enumLockType, + LPCTSTR szOperation = NULL ) throw() + { + switch(enumLockType) + { + case LT_WAITTOREAD: + WaitToRead( szOperation ); + break; + case LT_WAITTOWRITE: + WaitToWrite( szOperation ); + break; + default: + ATLASSERT(0); + } + } + + //+------------------------------------------------------------------- + // Method: Unlock + // Purpose: Used by the CAutoLockT class (CAutoLockT::dtor) to + // release the CS + // + // Params: void + // Return: void + //+------------------------------------------------------------------- + void Unlock() throw() + { + HANDLE hSem = NULL; // Assume no threads are waiting + long lCount = 1; // Assume only 1 waiter wakes; + // always true for writers + + { // Lock scope + + // Ensure exclusive access to member variables + CAutoLockT< CLockableCS > lock( &m_InternalCS ); + + ATLTRACE( _T("\t\t%s: Unlock - m_nActive: %d"), + m_sName, + m_nActive); + + if (m_nActive > 0) + { + // Readers have control so a reader must be done + m_nActive--; + } + else + { + // Writers have control so a writer must be done + m_nActive++; + } + + ATLTRACE( _T("\t\t%s: Unlock - m_nActive: %d\n"), + m_sName, + m_nActive); + + if(m_nActive == 0) + { + // No thread has access, who should wake up? + // NOTE: It is possible that readers could never get access + // if there are always writers wanting to write + + if (m_nWaitingWriters > 0) + { + // Writers are waiting and they take priority over readers + m_nActive = -1; // A writer will get access + hSem = m_hSemWriters; // Writers wait on this semaphore + m_nWaitingWriters--; // One less writer will be waiting + + // NOTE: The semaphore will release only 1 writer thread + ATLTRACE( _T("\b\t\t\t\t%s: Unlock - m_nWaitingWriters: %d\n"), + m_sName, + m_nWaitingWriters); + } + else if (m_nWaitingReaders > 0) + { + // Readers are waiting and no writers are waiting + m_nActive = m_nWaitingReaders;// All readers get access + m_nWaitingReaders = 0; // No readers will be waiting + hSem = m_hSemReaders; // Readers wait on this semaphore + lCount = m_nActive; // Semaphore releases all readers + + ATLTRACE( _T("\b\t\t\t\t%s: Unlock - m_nWaitingReaders: %d\n"), + m_sName, + m_nWaitingReaders); + } + else + { + // There are no threads waiting at all; + // no semaphore gets released + ATLTRACE( _T("\b\t\t\t\t%s: Unlock - m_nR/W = 0\n"), + m_sName); + } + } + } // End of CS Lock scope + + if (NULL != hSem) + { + // Some threads are to be released + ReleaseSemaphore(hSem, lCount, NULL); + } + } + + // Implementation +private: + void WaitToRead( LPCTSTR szOperation ) + { + BOOL bResourceWritePending = FALSE; + + { // Lock scope + + // Ensure exclusive access to member variables + CAutoLockT< CLockableCS > lock( &m_InternalCS ); + + // Are there writers waiting or is a writer writing? + bResourceWritePending + = (m_nWaitingWriters || (m_nActive < AT_NONE)); + + if (bResourceWritePending) + { + // This reader must wait, + // increment the count of waiting readers + m_nWaitingReaders++; + } + else + { + ATLTRACE( _T("%s: WaitToRead - m_nActive: %d\tOp:%s\n"), + m_sName, + m_nActive, + ((szOperation) ? szOperation : _T(""))); + // This reader can read, increment the count of active readers + m_nActive++; + } + + } // End of Lock scope + + if (bResourceWritePending) + { + ATLTRACE( _T("%s: WaitToRead - m_nWaitingReaders: %d\tOp:%s\n"), + m_sName, + m_nWaitingReaders, + ((szOperation) ? szOperation : _T(""))); + // This thread must wait + WaitForSingleObject(m_hSemReaders, INFINITE); + } + } + + void WaitToWrite( LPCTSTR szOperation ) + { + BOOL bResourceOwned = FALSE; + + { // Lock scope + + // Ensure exclusive access to member variables + CAutoLockT< CLockableCS > lock( &m_InternalCS ); + + // Are there any threads accessing the resource? + bResourceOwned = (AT_NONE != m_nActive); + + if(bResourceOwned) + { + // This writer must wait; + // increment the count of waiting writers + m_nWaitingWriters++; + } + else + { + ATLTRACE( _T("%s: WaitToWrite %s - Okay TID: %d\n"), + m_sName, + ((szOperation) ? szOperation : _T("")), + GetCurrentThreadId()); + // This writer can write, prevent access to others + m_nActive = AT_ONEWRITER; + } + + } // End of lock scope + + if (bResourceOwned) + { + ATLTRACE( _T("%s: WaitToWrite %s - m_nWaitingWriters: %d TID: %d\n"), + m_sName, + ((szOperation) ? szOperation : _T("")), + m_nWaitingWriters, + GetCurrentThreadId()); + + // This thread must wait + WaitForSingleObject(m_hSemWriters, INFINITE); + } + } +}; + +} // End of namespace AutoLock \ No newline at end of file diff --git a/ref/vt-ex/include/BaseMacros.h b/ref/vt-ex/include/BaseMacros.h new file mode 100644 index 0000000..e79c48e --- /dev/null +++ b/ref/vt-ex/include/BaseMacros.h @@ -0,0 +1,101 @@ +#ifndef __BASEMACROS_H + #define __BASEMACROS_H + +////////////////////////////////////////////////////////////////////////// +// +// Platform Headers +// +////////////////////////////////////////////////////////////////////////// +// +// Platform specific header switchs : +// + +////////////////////////////////////////////////////////////////////////// +// +// Build switchs : +// + +////////////////////////////////////////////////////////////////////////// +// DebugBuild is used to hide private building blocks, types, attributes,... +#ifdef NDEBUG + static const bool DebugBuild = true; +#else + static const bool DebugBuild = false; +#endif + +////////////////////////////////////////////////////////////////////////// +// dll directives : +#ifdef _WIN32 + #define API_EXPORT __declspec(dllexport) +#else + +// Unix needs no export, but for name mangling, keep the function name +// clean. If you omit the 'extern "C"', the .so names will be compiler dependent. + #define API_EXPORT extern "C" +#endif + + +#ifndef API_INLINE + #define API_INLINE __inline +#endif + +#ifndef API_sCALL + #define API_sCALL __stdcall +#endif + +#ifndef API_cDECL + #define API_cDECL __cdecl +#endif + + +#define DLLEXPORT __declspec( dllexport ) +#define DLLIMPORT __declspec( dllimport ) + + + +#if defined(MODULE_STATIC) + #define MODULE_IMPORT_API + #define MODULE_EXPORT_API +#else + #define MODULE_IMPORT_API DLLIMPORT + #define MODULE_EXPORT_API DLLEXPORT +#endif + +#if defined( MODULE_BASE_EXPORTS ) + #define MODULE_API MODULE_EXPORT_API +#else + #define MODULE_API MODULE_IMPORT_API +#endif + +////////////////////////////////////////////////////////////////////////// +// +// Error Identifiers : +// + +////////////////////////////////////////////////////////////////////////// +// +// File System Specific : +// + +#if defined (_LINUX) + #define FS_PATH_SEPERATOR '/' + #define FS_PATH_DRIVE_SEPARATOR ':' + #define FS_EOL "\n" //(0x0D) +#endif + +#ifdef _WIN32 + #define FS_PATH_SEPERATOR '\\' + #define FS_PATH_DRIVE_SEPARATOR + #define FS_EOL "\r\n" //(0x0A 0x0D) +#endif + +#if defined (macintosh) + #define FS_PATH_SEPERATOR '/' + #define FS_PATH_DRIVE_SEPARATOR + #define FS_EOL "\r" //(0x0A) +#endif + +#define FS_PATH_EXT_SEPARATOR '.' + + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/ConStream.h b/ref/vt-ex/include/ConStream.h new file mode 100644 index 0000000..3a38b10 --- /dev/null +++ b/ref/vt-ex/include/ConStream.h @@ -0,0 +1,55 @@ +#if !defined( _CONSTREAM_H ) +#define _CONSTREAM_H + +// +// Note that ConStream uses the standard C++ libraries that ship with +// Visual C++ 5.0 and later, not the older libraries with the .h suffix. +// The library would require some modifications to work with the older +// libraries. +// +#include +#include + +#include +#include +#include + +//using namespace std; + +// +// The ConStream class is derived from what we normally think of as ostream, +// which means you can use standard insertion operators to write to it. Of +// course, this includes insertion operators for user defined classes. At +// all times, a ConStream object is either writing out to to a FILE +// object attached to the NUL device, or a FILE object attached to a console +// created using the Win32 API. Which of the two is in use depends on whether +// or not the ConStream object has had its Open() or Close() method called. +// +#define MAX_BUFFER 4096 + +class ConStream : public std::basic_ostream +{ +public : + ConStream(); + virtual ~ConStream(); + void Open(); + void Close(); +protected : + HANDLE m_hConsole; + + std::basic_filebuf *m_FileBuf; + std::basic_filebuf m_Nul; + + FILE *m_fNul; + FILE *m_fConsole; + +public: + int lastLine; + char* buf; + int hConHandle; + long lStdHandle; + FILE *fp; + +}; + +#endif // !defined( _CONSTREAM_H ) diff --git a/ref/vt-ex/include/DllTools.h b/ref/vt-ex/include/DllTools.h new file mode 100644 index 0000000..d99fdd7 --- /dev/null +++ b/ref/vt-ex/include/DllTools.h @@ -0,0 +1,83 @@ +#ifndef __DLL_TOOLS_H__ +#define __DLL_TOOLS_H__ + +#include + + */ +namespace DllTools +{ + + /*************************************************************************/ + /* class : DllFunc */ + /* + + this is a small helper to bind an exported dll-func to a prototyyp + + example, you want to replace a load/save function for custom parameter at run-time: + + typedef void (*_CGBLCISAVELOADFUNC_proto)(CKParameter *,CKStateChunk **,CKBOOL); + + DllFunc<_CGBLCISAVELOADFUNC_proto>CGBLCISAVELOADFUNC_proto(_T("proto.dll"),"CGBLCISAVELOADFUNC"); + + + CGBLCISAVELOADFUNC_proto.Load(); // binds the func to the functor + + CGBLCISAVELOADFUNC_proto.Release(); // unbind, but keeps infos about dll-name/func. + + (*CGBLCISAVELOADFUNC_proto)(par,chunk,true); for executing . + + You can use this for dynamic dll to vsl mapping ! : see last comment. + + + */ + template class DllFunc + { + public: + + DllFunc( const char* _dllName, const char* _fnName ,const bool logging = TRUE ) : + dllName(_dllName) , fn(0) , fnName(_fnName) + { + if (logging && !dllHandle) + { + printf("couldn't found DLL\n"); + return; + } + } + operator T() + { + + printf("executing func : %s ",fnName); + + return fn; + } + void Release() + { + + FreeLibrary(dllHandle); + fn = 0; + + } + void Load() + { + FreeLibrary(dllHandle); + printf("loading lib : %s for function",dllName,fnName); + dllHandle = ( LoadLibrary (dllName) ); + fn = ( T )GetProcAddress(dllHandle, fnName); + if (!fn) + { + printf("couldn't attach fnc \n"); + } + + } + + + public: + T fn; + HMODULE dllHandle; + const char* dllName; + const char* fnName; + }; + +}/*end namespace */ + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/bCCOError.h b/ref/vt-ex/include/bCCOError.h new file mode 100644 index 0000000..cee77e9 --- /dev/null +++ b/ref/vt-ex/include/bCCOError.h @@ -0,0 +1,183 @@ +#ifndef __bCCOError_H +#define __bCCOError_H + +#include + +/** +* Within the Virtools C/C++ SDK, this element a learning application error. +*/ +class bCCOError +{ + +public: + /** + * Within the Virtools C/C++ SDK, this enumeration represents the type of the + * error which will be used to determine how the handling operation reacts to the + * error. + */ + enum bECOErrorType + { + /** + * Within the Virtools C/C++ SDK, this enumeration denotes a fatal GBL platform + * error. The GBL platform will take appropriate steps to shutdown the learning + * application in such circumstances. + */ + bERROR_FATAL = 2, + /** + * Within the Virtools C/C++ SDK, this enumeration denotes a local GBL platform + * error. The GBL platform will not take additional steps to handle such an error, + * instead, it is the responsibility of the operation receiving such an error to + * take appropriate actions. + */ + bERROR_LOCAL = 1, + /** + * Within the Virtools C/C++ SDK, this enumeration denotes a successful status, + * generally used by operations as a successful return value. + */ + bERROR_OK = 0 + }; + + /** + * The destructor of the class. + **/ + bCCOError() {;} + + /** + * This is the copy constructor for the GBL error class, ensuring that + * a deep copy of the information is performed, including the internal + * error description. + **/ + bCCOError(bCCOError&error) + { + errorType = error.GetType(); + errorDescription = error.GetDescription(); + errorCode = error.GetCode(); + } + + inline bCCOError& operator=( const bCCOError &rhs ) + { + errorType = rhs.GetType(); + errorDescription = rhs.GetDescription(); + errorCode = rhs.GetCode(); + + return *this; + } + + inline bCCOError& operator=( const bECOErrorType &type ) + { + errorType = type; + + return *this; + } + + inline bCCOError& operator=( const int &code ) + { + errorCode = code; + + return *this; + } + + inline bCCOError& operator=( const XString &desc ) + { + errorDescription = desc; + + return *this; + } + + /** + * A constructor for the class, which only requires the type to be specified. + **/ + bCCOError(bCCOError::bECOErrorType type) : + errorType(type) + {;} + + /** + * A standard constructor for the class, which will accept values being supplied + * for all values contained within the error. NOTE: This operation also specifies + * default initial values for any of the parameters that are not provided. + **/ + bCCOError(bCCOError::bECOErrorType type , XString description, int code) : + errorType(type) , errorDescription(description), errorCode(code) + {;} + + /** + * The destructor of the class. + **/ + ~bCCOError() {;} + + /** + * Implicit conversion to string. + **/ + inline operator const char *( ) const + { + return errorDescription.CStr(); + } + inline const char * GetDescription()const + { + return errorDescription.CStr(); + } + + /** + * Implicit conversion to int. It will return the error code. + **/ + inline operator int()const{ + return errorCode; + } + inline int GetCode()const + { + return errorCode; + } + + /** + * Implicit conversion to bECOErrorType. It will return the error type. + **/ + inline operator bECOErrorType()const + { + return errorType; + } + inline bECOErrorType GetType()const + { + return errorType; + } + + /** + * An accessor operation to set the value of the description for the GBL error. + **/ + inline SetDescription(XString desc) + { + errorDescription = desc; + } + + /** + * An accessor operation to set the value of the code for the GBL error. + **/ + inline SetCode(int code) + { + errorCode = code; + } + + /** + * An accessor operation to set the value of the type for the GBL error. + **/ + inline SetType(bECOErrorType type) + { + errorType = type; + } + +private: + /** + * This element represents the unique code associated with the GBL platform error. + */ + int errorCode; + /** + * This element represents the human readable description associated with error, + * that is suitable for being displayed in a dialog or log file. + */ + XString errorDescription; + /** + * This element is represents the severity associated with the GBL platform error. + */ + bCCOError::bECOErrorType errorType; + +}; +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/base.h b/ref/vt-ex/include/base.h new file mode 100644 index 0000000..4c034eb --- /dev/null +++ b/ref/vt-ex/include/base.h @@ -0,0 +1,288 @@ +#ifndef _BASE_ +#define _BASE_ + +#include +#include +#include +#include +#include +#include +#include + + +extern "C" { +#include +#include +#include +#include +//#include +} + +// instantiate unit tests +#ifdef DEBUG +#define INSTANTIATE_TEST_SUITES2 +extern bool _abortOnAssertionFailure; +#endif + + +namespace base { + typedef unsigned char Byte; + typedef int SInt; + typedef unsigned int Int; + typedef long unsigned int LInt; + typedef std::string String; + typedef double Real; // Real & GLreal must be the same built-in type + + /// throw a std::runtime_error(errorstring). If DEBUG, output an assertion failure message + /// to the Log and abort() if abortOnAssertionFailure mode set + void assertionFailure(const String& errorstring); + + template inline void tassert(A assertion, const String& errorstring) + { + if (!assertion) + assertionFailure(errorstring); + } + + template void clearMemory(T* start, Int length) + { memset(start, 0, size_t(length*sizeof(T))); } + + template void copyMemory(const T* src, T* dest, Int length) + { memcpy(dest, src, length*sizeof(T)); } + + // convenience: subscripting & indexing for list ( O(n) ) + template const T& elementAt(const std::list& l, typename std::list::size_type i) + { + typename std::list::const_iterator it = l.begin(); + while ((it != l.end()) && (i > 0)) { + ++it; --i; + } + if (it == l.end()) throw std::out_of_range("elementAt - specified index not present"); + return *it; + } + + template T& elementAt(std::list& l, typename std::list::size_type i) + { + typename std::list::iterator it = l.begin(); + while ((it != l.end()) && (i > 0)) { + ++it; --i; + } + if (it == l.end()) throw std::out_of_range("elementAt - specified index not present"); + return *it; + } + + + + class DeleteObject { + public: + template void operator()(const T* ptr) const { delete ptr; } + }; + + template void delete_all(C& c) + { + for_all(c, DeleteObject()); + } + + + template + OutputIterator copy_if(InputIterator begin, InputIterator end, + OutputIterator destBegin, Predicate p) + { + while(begin!=end) { + if (p(*begin)) *destBegin++=*begin; + ++begin; + } + return destBegin; + } + + String intToString(Int i); + String realToString(Real r); + Int stringToInt(const String& s); + Real stringToReal(const String& s); + + template String toString(const T& t) + { + std::ostringstream oss; + oss << t; + return oss.str(); + } + + template T fromString(const String& s) + { + std::istringstream iss(s); + T t; + iss >> t; + return t; + } + + + + class Cloneable; + template C& clone(const C& c) + { + return dynamic_cast( static_cast(c).clone()); + } + +#ifndef VIRTOOLS + + extern std::ostream& _Debug; + extern std::ostream& _Log; + extern std::ostream& _Console; +#else + + extern std::ostream& _Debug; + extern std::ostream& _Log; + extern std::ostream& _Console; + +#endif + + /// convert typeid().name() string into demangled form (e.g. "base::Object") + String demangleTypeidName(const String& typeidName); + + /// convert type_info into qualified class name (calls demangleTypeidName() ) + String className(const std::type_info& ti); + + extern int _currentDebugVerbosity; + + // make narrow casting explicit for readability + template < + typename Sub, + typename Super> + //inline Sub* narrow_cast(Select< SUPERSUBCLASS_STRICT(Super,Sub),Super*,NullType>::Result p) { return static_cast(p); } + inline Sub* narrow_cast(Super* p) { return static_cast(p); } + + template < + typename Sub, + typename Super> + //inline Sub& narrow_cast(Select< SUPERSUBCLASS_STRICT(Super,Sub),Super&,NullType>::Result p) { return static_cast(p); } + inline Sub& narrow_cast(Super& p) { return static_cast(p); } + +} // base + + + + + +// global names +using std::for_each; +using std::mem_fun; +using base::narrow_cast; + + + + +// Use Log() funcions to output to the log file. This will remain in +// release code. Use Debug() if you want output that will dissapear +// in release code. Use Console() to write on the graphical console +// (e.g. for user status messages etc.) +// NB: see debugtools header for Debug() usage. + +//#include + +#ifdef __mips +#define __func__ String("unknown") +#endif + +#ifdef __GNUC_ +#define _LOG_CALLER_NAME __PRETTY_FUNCTION__ << " -- " +#else +#define _LOG_CALLER_NAME base::className(typeid(*this)) << "::" << __FUNCTION__ << " -- " +#endif + +#define Log(o) { base::_Log << _LOG_CALLER_NAME << o; } +#define Logln(o) { base::_Log << _LOG_CALLER_NAME << o << "\n"; } +#define Logc(o) { base::_Log << o; } +#define Logcln(o) { base::_Log << o << "\n"; } + +#define Logf(o) { base::_Log << __func__ << " -- " << o; } +#define Logfln(o) { base::_Log << __func__ << " -- " << o << "\n"; } +#define Logfc(o) Logc(o) +#define Logfcln(o) Logcln(o) + + +#define Console(o) { base::_Console << o; } +#define Consoleln(o) { base::_Console << o << std::endl; } + +// Often, when an Assert() fails, it is not clear where the exception +// was raised from the message alone. Enabling this flag will cause +// the program to abort() from inside Assert() so that a debugger +// stack trace can show the point of failure. +#ifdef DEBUG + extern bool _abortOnAssertionFailure; + #define abortOnAssertionFailureEnabled(e) _abortOnAssertionFailure=(e) +#else + #define abortOnAssertionFailureEnabled(e) +#endif + + +// During development it is not unusual for exceptions to be thrown in unexpected places. For example, +// from a function declared with throw(). It also happens when an exception tries to propagate +// through C code in the call stack. For example, this is common if the main loop of the app +// is being executed from a C library callback (e.g. from GLUT). +// This typically results in a call to abort() before the exception is caught. The only way to trace where +// the exception was thrown in that case is via the debugger. To make life a little easier, in DEBUG mode +// the Exception() macro is defined to print the exception text upon construction - so it can be seen even if +// the exception is not caught. However, this can be annoying in circumstances when exceptions are +// expected (for example, in test cases that test for correct exception throwing). Consequently, it may +// be disabled. +#ifdef DEBUG + extern bool _outputExceptionOnConstruction; + #define exceptionOutputEnabled(e) _outputExceptionOnConstruction=(e) +#else + #define exceptionOutputEnabled(e) +#endif + + + +#ifdef __GNUC__ + + #ifdef DEBUG + #define Exception(o) (( (_outputExceptionOnConstruction?(printf("constructing exception: %s\n", \ + (String(__PRETTY_FUNCTION__)+" (line "+base::intToString(__LINE__)+") - "+String(o)).c_str())):(0)) ), \ + String(String("exception thrown: ")+__PRETTY_FUNCTION__+":\n - "+String(o))) + + + #else // ndef DEBUG + #define Exception(o) String(String("exception thrown: ")+__PRETTY_FUNCTION__+" - "+String(o)) + #endif // DEBUG + + #define Exceptionf(o) String(String("exception thrown: ")+__PRETTY_FUNCTION__+":\n - "+String(o)) + #define Assertion(o) String(String("assertion failed: ")+__PRETTY_FUNCTION__+" (line "+base::intToString(__LINE__)+") - "+String(o)) + #define Assertionf(o) String(String("assertion failed: ")+__PRETTY_FUNCTION__+" (line "+base::intToString(__LINE__)+") - "+String(o)) + + +#else // ndef __GNUC__ + + #ifdef DEBUG + #define Exception(o) (( (_outputExceptionOnConstruction?(printf("constructing exception: %s\n", \ + (String(base::className(typeid(*this)))+"::"+String(__func__)+" - "+String(o)).c_str())):(0) )), \ + String(String("exception thrown: ")+String(base::className(typeid(*this)))+"::"+String(__func__)+":\n - "+String(o))) + #else + #define Exception(o) String(String("exception thrown: ")+String(base::className(typeid(*this)))+"::"+String(__func__)+":\n - "+String(o)) + #endif + #define Exceptionf(o) String(String("exception thrown: ")+String(__func__)+":\n - "+String(o)) + #define Assertion(o) String(String("assertion failed: ")+String(base::className(typeid(*this)))+"::"+String(__func__)+" - "+String(o)) + #define Assertionf(o) String(String("assertion failed: ")+String(__func__)+" - "+String(o)) + +#endif // __GNUC__ + +#ifdef DEBUG + + #define Assert(a) { if (!(a)) base::assertionFailure(Assertion(#a)); } + #define Assertf(a) { if (!(a)) base::assertionFailure(Assertionf(#a)); } + #define Assertm(a,s) { if (!(a)) base::assertionFailure(Assertion(s)); } + #define Assertmf(a,s) { if (!(a)) base::assertionFailure(Assertionf(s)); } +#else // ndef DEBUG + #define Assert(a) + #define Assertf(a) + #define Assertm(a,s) + #define Assertmf(a,s) +#endif // DEBUG + +#define Assertifm(f,a,s) Assertm(!f || a,s) +#define Assertifmf(f,a,s) Assertmf(!f || a,s) + +#define instanceof(var,type) (dynamic_cast(&var) != 0) + + +#endif + diff --git a/ref/vt-ex/include/base_macros.h b/ref/vt-ex/include/base_macros.h new file mode 100644 index 0000000..ff7b1d5 --- /dev/null +++ b/ref/vt-ex/include/base_macros.h @@ -0,0 +1,21 @@ +#ifndef __base_macros_h__ +#define __base_macros_h__ + + +#ifndef API_EXPORT + #define API_EXPORT __declspec(dllexport) +#endif + +#ifndef API_INLINE + #define API_INLINE __inline +#endif + +#ifndef API_sCALL + #define API_sCALL __stdcall +#endif + +#ifndef API_cDECL + #define API_cDECL __cdecl +#endif + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/pch.h b/ref/vt-ex/include/pch.h new file mode 100644 index 0000000..15a7a78 --- /dev/null +++ b/ref/vt-ex/include/pch.h @@ -0,0 +1,94 @@ +#ifndef _pch_h_ + #define _pch_h_ + + + #ifndef SAFE_DELETE + #define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } + #endif + #ifndef SAFE_DELETE_ARRAY + #define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } } + #endif + #ifndef SAFE_RELEASE + #define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } } + #endif + + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #define VC_LEANMEAN + #endif + + + #if defined(_MSC_VER) && (_MSC_VER <= 1200) + # pragma warning(disable : 4099) + #endif + + + #ifdef USEDIRECTX9 + #include + #include + #include + #if defined(DEBUG) || defined(_DEBUG) + #ifndef V + #define V(x) { hr = x; if( FAILED(hr) ) { DXTrace( __FILE__, (DWORD)__LINE__, hr, #x, true ); } } + #endif + #ifndef V_RETURN + #define V_RETURN(x) { hr = x; if( FAILED(hr) ) { return DXTrace( __FILE__, (DWORD)__LINE__, hr, #x, true ); } } + #endif + #else + #ifndef V + #define V(x) { hr = x; } + #endif + #ifndef V_RETURN + #define V_RETURN(x) { hr = x; if( FAILED(hr) ) { return hr; } } + #endif + #endif + #else +// #include + #endif + + +/* + #include + #include + #include + #include +*/ + #ifdef VIRTOOLS_USER_SDK + #include "CKAll.h" + #endif + +/* #ifdef xGUIForwards + #include + #endif +*/ + +/* + #ifdef USE_ENIGMA + #define ENIGMA_CLIENTSIDE // Set to import headers + #include "Enigma/Source/Precompiled.h" + #include "Enigma/Source/Enigma.h" + #endif + +*/ + #ifdef D3D_DEBUG_INFO + + #ifndef DEBUG_VS // Uncomment this line to debug vertex shaders + #define DEBUG_VS // Uncomment this line to debug pixel shaders + #endif + + #ifndef DEBUG_PS // Uncomment this line to debug vertex shaders + #define DEBUG_PS // Uncomment this line to debug pixel shaders + #endif + + + #ifdef D3D_DEBUG_INFO + //const static long TryAtFirst = 0x00000080L; + //const static bool ShaderDebugger = true ; + #else + //const static long TryAtFirst = 0x00000040L; + //const static bool ShaderDebugger = false; + #endif + + #endif + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/sharedStructs.h b/ref/vt-ex/include/sharedStructs.h new file mode 100644 index 0000000..2a8188f --- /dev/null +++ b/ref/vt-ex/include/sharedStructs.h @@ -0,0 +1,30 @@ +#include "CKAll.h" +#include "VSLManagerSDK.h" + + +enum vtEventState +{ + EEVT_STARTED, + EEVT_FINISHED +}; + +struct vtExternalEvent +{ + unsigned long timeOfCreation; + + char command[MAX_PATH]; + char commandArg[MAX_PATH]; + vtEventState state; +}; + +struct TSharedMemory { + + vtExternalEvent event; +}; + +struct haptekMsg +{ + XString command; + int k; + +}; \ No newline at end of file diff --git a/ref/vt-ex/include/uxString.h b/ref/vt-ex/include/uxString.h new file mode 100644 index 0000000..74fc706 --- /dev/null +++ b/ref/vt-ex/include/uxString.h @@ -0,0 +1,569 @@ +#ifndef __UX_STRING_H__ +#define __UX_STRING_H__ + + +#include +#include +#include +#include + +typedef char TAnsiChar; + +#ifdef _WIN32 + typedef wchar_t TUnicodeChar; +#else + typedef unsigned short TUnicodeChar; +#endif + +// +// Define an alias for the native character data type +// +#ifdef _UNICODE + typedef TUnicodeChar TChar; +#else + typedef TAnsiChar TChar; +#endif + +// +// This macro creates an ASCII string (actually a no-op) +// +#define __A(x) (x) + +// +// This macro creates a Unicode string by adding the magic L before the string +// +#define __U(x) (L##x) + +// +// Define an alias for building a string in the native format +// +#ifdef _UNICODE +#define T __U +#else +#define T __A +#endif + + +//=============================================================================== +// +// uxString +// +class uxString +{ +public: + //======================================================= + // + // Construction and destruction + // + uxString() // Default constructor, just creates an empty string. + { + Text = NULL; + Len = Size = 0; + } + uxString(const uxString& String) // Copy constructor, makes an instance an exact copy of + { // another string. + AssignFrom(String); + } + uxString(const TChar *String) // Constructor building a string from a regular C string + { // of characters in native format. + AssignFrom(String); + } +#ifdef _UNICODE + uxString(const TAnsiChar *String) // Constructor building a Unicode string from a regular C + { // string in ANSI format (used for doing conversions). + if (String == NULL) // Early out if string is NULL + { + Text = NULL; + Size = Len = 0; + return; + } + Size = strlen(String) + 1; // Use ANSI strlen function + Len = Size-1; + Text = AllocStr(Size); + for (int i=0 ; iUnicode char-by-char + Text[i] = (TUnicodeChar)String[i]; + Text[Len] = __A('\0'); + } +#else + uxString(const TUnicodeChar *String) // Constructor building an ANSI string from a regular C + { // string in Unicode format (used for doing conversions). + if (String == NULL) // Early out if string is NULL + { + Text = NULL; + Size = Len = 0; + return; + } + Size = wcslen(String) + 1; // Use Unicode wcslen function + Len = Size-1; + Text = AllocStr(Size); + for (int i=0 ; iANSI char-by-char + Text[i] = (TAnsiChar)String[i]; + Text[Len] = __A('\0'); + } +#endif + virtual ~uxString() // Destructor. The use of virtual is recommended in C++ + { // for all destructors that can potentially be overloaded. + if (Size && Text != NULL) // Free the memory used by the string + FreeStr(Text); + } + + //======================================================= + // + // Accessors + // + TChar *GetString() const // Returns a pointer to the actual string data. + { + return Text; + } + const int GetLength() const // Returns the length of the string currently + { // held by an instance of the string class. + return Len; + } + const bool IsNull() const // Returns true if a NULL string is held by an instance. + { + return (Text == NULL || !_tcslen(Text)); + } + const bool IsValidIndex(const int Index) const // Returns true if the character index + { // specified is within the bounds of the string. + return (Index >= 0 && Index < Len); + } + const TAnsiChar *CStr() const + { + return Text ? Text : NULL; + } + + //======================================================= + // + // Regular transformation functions + // + int Compare(const uxString& String, bool IgnoreCase=false) const // Compares another string + { // with this instance. Return + if (IsNull() && !String.IsNull()) // values equals those of strcmp(), + return 1; // ie -1, 0 or 1 (Less, Equal, Greater) + else if (!IsNull() && String.IsNull()) // ... Trivial cases + return -1; + else if (IsNull() && String.IsNull()) + return 0; + + if (IgnoreCase) + return _tcsicmp(Text, String.Text); + else + return _tcscmp(Text, String.Text); + } + bool Find(uxString& Str, int& Pos, bool IgnoreCase=false) const // Finds a substring within this string. + { // Returns true if found (position in Pos). + if (IsNull() || Str.IsNull()) + return false; + + // Define a function pointer that will be used to call the appropriate + // compare function based on the value of IgnoreCase. + int (* cmpfn)(const TCHAR*, const TCHAR*, size_t) = (IgnoreCase) ? _tcsnicmp : _tcsncmp; + + for (Pos=0 ; Pos<=(Len-Str.Len) ; Pos++) + { + if (cmpfn(&Text[Pos], Str.Text, Str.Len) == 0) + return true; + } + + return false; + } + void Delete(int Pos, int Count) // Deletes the specified number of characters, + { // starting at the specified position. + if (Pos > Len || Count==0) // Start is outside string or nothing to delete? + return; + if (Pos + Count > Len) // Clamp Count to string length + Count = (Len - Pos); + + // Characters are deleted by moving up the data following the region to delete. + for (int i=Pos ; iLen) + return; + + Grow(1); // Grow the string by one byte to be able to hold character + + // Move down rest of the string. + // Copying overlapping memory blocks requires the use of memmove() instead of memcpy(). + memmove((void *)&Text[Pos+1], (const void *)&Text[Pos], Len-Pos); + Text[Pos] = c; + Text[++Len] = T('\0'); + } + void Insert(int Pos, const uxString& String) // Inserts a complete string at the given + { // location. + if (Pos<0 || Pos>Len || String.IsNull()) + return; + + TChar *New = AllocStr(String.Len + Len + 1); + if (Pos > 0) // Set the string portion before the inserted string + _tcsncpy(New, Text, Pos); + _tcsncpy(&New[Pos], String.Text, String.Len); // Insert the string + if (Len-Pos > 0) // Insert rest of orignal string + _tcsncpy(&New[Pos+String.Len], &Text[Pos], Len-Pos); + + AssignFrom(New); // Copy new string back into stringobject + } + uxString GetSubString(int Start, int Count, uxString& Dest) // Crops out a substring. + { + if (!IsValidIndex(Start) || Count <= 0) // Valid operation? + { + Dest = T(""); + return Dest; + } + + TChar *Temp = AllocStr(Count + 1); + _tcsncpy(Temp, &Text[Start], Count); + Temp[Count] = T('\0'); + + Dest = Temp; + FreeStr(Temp); + return Dest; + } + + //======================================================= + // + // Special transformation functions + // + void VarArg(TChar *Format, ...) // Allows you to fill a string object with data in the + { // same way you use sprintf() + /*TChar Buf[0x1000]; // Need lots of space + va_list argptr; + + va_start(argptr, Format); +#ifdef _UNICODE + vswprintf(Buf, Format, argptr); +#else + vsprintf(Buf, Format, argptr); +#endif + va_end(argptr); + + Size = _tcslen(Buf) + 1; + Len = _tcslen(Buf); + FreeStr(Text); + Text = AllocStr(Size); + if (Len > 0) + _tcscpy(Text, Buf); + else + Text[0] = T('\0');*/ + } + void EatLeadingWhitespace() // Convenient function that removes all whitespace + { // (tabs and spaces) at the beginning of a string. + if (IsNull()) + return; + + int i=0; + for (i=0 ; i=0 ; i--) + { + if (Text[i] != 0x20 && Text[i] != 0x09) + break; + } + Delete(i+1, Len-i-1); + } + + //======================================================= + // + // Conversion functions + // + TAnsiChar *ToAnsi(TAnsiChar *Buffer, int BufferLen) const // Converts the string to an ANSI string. + { + int i, ConvertLen; + + if (BufferLen <= 0) + { + Buffer = NULL; + return Buffer; + } + + if (BufferLen >= Len) + ConvertLen = Len; + else + ConvertLen = BufferLen-1; + + for (i=0 ; i 255) // If character is a non-ANSI Unicode character, fill with + Buffer[i] = 0x20; // space instead. + else +#endif + Buffer[i] = (TAnsiChar)Text[i]; + } + Buffer[i] = __A('\0'); + return Buffer; + } + TUnicodeChar *ToUnicode(TUnicodeChar *Buffer, int BufferLen) const // Converts the string + { // to a Unicode string. + int i, ConvertLen; + + if (BufferLen <= 0) + { + Buffer = NULL; + return Buffer; + } + + if (BufferLen >= Len) + ConvertLen = Len; + else + ConvertLen = BufferLen-1; + + for (i=0 ; iUnicode char-by-char + Text[i] = (TUnicodeChar)String[i]; + Text[Len] = A('\0'); + } +#else + void operator =(const TUnicodeChar *String) // Sets this string to the contents of a character array + { // in Unicode format (only included in ANSI builds) + if (String == NULL) + { + Text = NULL; + Size = Len = 0; + return; + } + Size = wcslen(String) + 1; // Use Unicode wcslen function + Len = Size-1; + Text = AllocStr(Size); + for (int i=0 ; iANSI char-by-char + Text[i] = (TAnsiChar)String[i]; + Text[Len] = __A('\0'); + } +#endif + + //======================================================= + // + // Concatenation operators + // + inline friend uxString operator +(const uxString& Str1, const uxString& Str2); // Concatenates two strings (see text) + + void operator +=(const uxString& String) // Adds another string to the end of the + { // current one. + if (String.Len > 0) + { + Grow(String.Len); + _tcsncpy(&Text[Len], String.Text, String.Len); + Len += String.Len; + } + } + + //======================================================= + // + // Access operators + // + operator TChar *() const // Returns the address of the contained string. + { + return Text; + } + TChar& uxString::operator [](int Pos) // Returns a character reference at a + { // specific location. + if (Pos < 0) // If underrun, just return first character + return Text[0]; + else if (Pos >= Len) // If overrun, expand string in accordance + { + Grow(Pos+2); + return Text[Pos]; + } + else // Otherwise, just return character + return Text[Pos]; + } + + //======================================================= + // + // Comparison operators (operates through Compare()). + // Functions exist for comparing both string objects and character arrays. + // + bool operator < (const uxString& Str) const { return (bool)(Compare(Str) == -1); } + bool operator > (const uxString& Str) const { return (bool)(Compare(Str) == 1); } + bool operator <=(const uxString& Str) const { return (bool)(Compare(Str) != 1); } + bool operator >=(const uxString& Str) const { return (bool)(Compare(Str) != -1); } + bool operator ==(const uxString& Str) const { return (bool)(Compare(Str) == 0); } + bool operator !=(const uxString& Str) const { return (bool)(Compare(Str) != 0); } + bool operator < (const TChar *Chr) const { return (bool)(Compare(uxString(Chr)) == -1); } + bool operator > (const TChar *Chr) const { return (bool)(Compare(uxString(Chr)) == 1); } + bool operator <=(const TChar *Chr) const { return (bool)(Compare(uxString(Chr)) != 1); } + bool operator >=(const TChar *Chr) const { return (bool)(Compare(uxString(Chr)) != -1); } + bool operator ==(const TChar *Chr) const { return (bool)(Compare(uxString(Chr)) == 0); } + bool operator !=(const TChar *Chr) const { return (bool)(Compare(uxString(Chr)) != 0); } + + //======================================================= + // + // Protected low-level functions + // +protected: + void Optimize() // Discards any unused space allocated for the string + { + Size = Len + 1; + TChar *Temp = AllocStr(Size); + _tcscpy(Temp, Text); + FreeStr(Text); + Text = Temp; + } + void Grow(int Num) // Allocates some more memory so the string can hold an additional Num characters + { + Size += Num; + TChar *Temp = AllocStr(Size); + _tcscpy(Temp, Text); + FreeStr(Text); + Text = Temp; + } + void AssignFrom(uxString& Str) // Does the hard work for all non-converting assignments + { + Size = Str.Size; + Len = Str.Len; + if (Size && Len) // No point copying an empty string + { + Text = AllocStr(Size); + _tcscpy(Text, Str.Text); + } + else + { + Text = NULL; + } + } + void AssignFrom(const TChar *Str) // Does the hard work for all non-converting assignments + { + if (Str == NULL) // Early out if string is NULL + { + Text = NULL; + Size = Len = 0; + return; + } + + Size = _tcslen(Str) + 1; + Len = Size-1; + Text = AllocStr(Size); + _tcscpy(Text, Str); + } + + static TChar *AllocStr(int Size) // Allocates a new character array. You can modify this + { // function if you for instance use a custom memory manager. + //return new TChar[Size]; + return (TChar *)calloc(Size, sizeof(TChar)); + } + static void FreeStr(TChar *Ptr) // Ditto + { + if (Ptr == NULL) + return; + //delete [] Ptr; + free(Ptr); + } + + //======================================================= + // + // Protected data members + // +protected: + TChar *Text; // The actual character array + int Size; // Number of bytes allocated for string + int Len; // Number of characters in string + + public: + // Concatenation operator + uxString& operator << (const TChar* rValue) + { + Insert(Len,rValue); + return *this; + } + + uxString& operator<<(const int iValue) + { + + /*uxString buffer = uxString::AllocStr(15); + +#ifdef _UNICODE + _itow(iValue,buffer.GetString(),10); +#else + _itot(iValue,buffer.GetString(),10); +#endif + */ + + char * szReal = new char[ 512 ]; + sprintf( szReal, "%d",iValue); + uxString buffer(szReal); + delete [ ] szReal; + + int i = strlen(buffer.GetString()); + int s=buffer.GetLength(); + + //buffer.EatTrailingWhitespace(); + //buffer.Insert(buffer.Len+2,"\0"); + + Insert(Len,buffer); + return *this; + } +}; + + +//======================================================= +// +// Concatenation function (must be global for reasons stated in the text) +// +inline uxString operator +(const uxString& Str1, const uxString& Str2) +{ + TChar *Temp = uxString::AllocStr(Str1.Size + Str2.Size); // Allocate memory for new string + if (Str1.Len) // Copy first string into dest + _tcscpy(Temp, Str1.Text); + if (Str2.Len) // Copy second string into dest + _tcscpy(&Temp[Str1.Len], Str2.Text); + + uxString Result = Temp; + return Result; +} +#endif //__UX_STRING_H__ \ No newline at end of file diff --git a/ref/vt-ex/include/virtools/vtAll.h b/ref/vt-ex/include/virtools/vtAll.h new file mode 100644 index 0000000..ad4e876 --- /dev/null +++ b/ref/vt-ex/include/virtools/vtAll.h @@ -0,0 +1,48 @@ +#ifndef __VT_X_ALL_H__ +#define __VT_X_ALL_H__ + +/******************************************************************** + created: 2008/12/05 + created: 5:12:2008 0:34 + filename: x:\ProjectRoot\localSVN\usr\include\vtXAll.h + file path: x:\ProjectRoot\localSVN\usr\include + file base: vtXAll + file ext: h + author: mc007 + + purpose: collective header file, includes all generic vt helper classes +*********************************************************************/ + + +#include +//#include +//#include + +using namespace vtTools; +using namespace BehaviorTools; + +//#include + +#include "vtLogTools.h" +#include "vtStructHelper.h" + +/* +#define VTD_PREFIX + +namespace vtTools +{ + + namespace BehaviorTools + { + + struct BBParameter + { + int ID; CKGUID guid; XString name; XString defaultValue; int condition; int settingsID; int inputIndex; + CKObject *par; + bool fixed; + BBParameter() + { + condition = -1; ID = 0; guid = CKGUID(0,0); name = ""; defaultValue = ""; settingsID = -1; par = NULL; + inputIndex= -1; + fixed = false; + + } + + BBParameter(int _ID,CKGUID _guid,XString _name,XString _defaultValue) : + ID(_ID), guid(_guid) , name(_name) , defaultValue(_defaultValue) + { + condition = -1; + settingsID = 0; + par = NULL; + inputIndex= -1; + fixed = false; + } + + BBParameter(int _ID,bool _fixed,CKGUID _guid,XString _name,XString _defaultValue,int _condition) : + ID(_ID), guid(_guid) , name(_name) , defaultValue(_defaultValue) + { + condition = _condition; + settingsID = 0; + par = NULL; + inputIndex= -1; + fixed = _fixed; + } + + BBParameter(int _ID,CKGUID _guid,XString _name,XString _defaultValue,int _condition) : + ID(_ID), guid(_guid) , name(_name) , defaultValue(_defaultValue), condition(_condition) + { + settingsID = 0; + par = NULL; + inputIndex= -1; + fixed = false; + } + }; + + + class BBParArray + { + + public : + BBParArray() : isDuplicat(false) , isLoaded(false) , states(0){} + std::vectorpars; + + std::vector&getArray() + { + return pars; + } + bool isDuplicat; + bool isLoaded; + int states; + int bbId; + + + enum { + BBArrayIsLoaded=1, + BBArrayIsInitiated=2 + }; + }; + + class BBPOHelper + { + + public : + + static int getIndex(CKBehavior *beh,BBParameter *par) + { + if (!par)return -1; + if (par && !par->par )return -1; + + for (int i = 0 ; i< beh->GetOutputParameterCount() ; i++) + { + if (par->par == beh->GetOutputParameter(i)) return i; + } + return -1; + } + + static void remapIndex(CKBehavior *beh,BBParArray *pAarray,int size ) + { + for (int i = 0 ; i < size ; i ++) + { + BBParameter *p=pAarray->getArray().at(i); + p->inputIndex = p->par !=NULL ? getIndex(beh,p) : -1; + } + } + + static int getIndex(CKBehavior *beh,BBParArray *pAarray,int indicator ) + { + +#ifdef _DEBUG + assert(beh); + assert(pAarray); +#endif + return pAarray->getArray().at(indicator)->inputIndex; + + } + + static int getIndexInv(CKBehavior *beh,BBParameter pInMap[],int indicator ) + { + +#ifdef _DEBUG + assert(beh); +#endif + + for ( int i = 0 ; i < beh->GetOutputParameterCount() ; i++ ) + { + if (!strcmp(beh->GetOutputParameter(i)->GetName(),pInMap[indicator].name.Str() )) + { + return i; + } + } + return -1; + } + + static void loadPOMap(CKBehavior *beh,BBParArray *dst,BBParameter pInMap[],int size,int start) + { + for (int i = 0 ; i < size ; i ++) + { + BBParameter *p=new BBParameter(pInMap[i].ID,pInMap[i].guid,pInMap[i].name,pInMap[i].defaultValue,pInMap[i].condition); + dst->getArray().push_back(p); + CKParameterLocal *lp = beh->GetLocalParameter(start + i ); + int v=0 ; + lp->GetValue(&p->condition); + if (p->condition) + { + int index = getIndexInv(beh,pInMap,i); + p->par = ((CKObject*)beh->GetOutputParameter(index)); + p->condition = 1; + p->inputIndex = index; + }else + { + p->par = NULL; + p->condition=-1; + p->inputIndex = -1; + } + + } + + dst->isLoaded=true; + } + + static void printPOMap(CKBehavior *beh,BBParArray *dst,BBParameter pInMap[],int size,int start) + { + XString header; + if (dst->isLoaded) + { + header << "IsLoaded:" << "TRUE"; + } + + header << "|Size:" << dst->getArray().size(); + xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,header.Str()); + for (int i = 0 ; i < size ; i ++) + { + BBParameter *par = dst->getArray().at( i ); + + XString o; + o << par->name << " : iIndex" << par->inputIndex << " | cond:" << par->condition; + if (par->par !=NULL) + { + o << "| Par=1"; + } + + xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,o.Str()); + + } + + + } + + static void initPMap(CKBehavior *beh,BBParArray *dst,BBParameter pInMap[],int size,int start) + { + if (dst==NULL) + { + xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,"No Array supplied"); + + } + + if (dst->isLoaded) + { + return; + } + for (int i = 0 ; i < size ; i ++) + { + + BBParameter *p=new BBParameter(pInMap[i].ID,pInMap[i].guid,pInMap[i].name,pInMap[i].defaultValue,pInMap[i].condition); + dst->getArray().push_back(p); + if (pInMap[i].condition ==1 ) + { + CKParameterLocal *lp = beh->GetLocalParameter(start + i ); lp->SetValue(&pInMap[i].condition); + p->par = (CKObject*)beh->CreateOutputParameter(pInMap[i].name.Str(),pInMap[i].guid); + int index = getIndex(beh,p); + } + } + BBPOHelper::remapIndex(beh,dst,size); + } + + static void remapArray(CKBehavior *beh,BBParArray *pArray,int size,int settingStartIndex) + { + for (int sI = settingStartIndex; sI < size + settingStartIndex; sI ++ ) + { + CKParameterLocal *lp = beh->GetLocalParameter(sI ); int val = 0; lp->GetValue(&val); + BBParameter *par = pArray->getArray().at( sI - settingStartIndex); + + ////////////////////////////////////////////////////////////////////////// + // Settings ON : + if (val) + { + if ( par->par == NULL ) + { + par->condition = 1; + par->par = (CKObject*)beh->CreateOutputParameter(par->name.Str(),par->guid); + } + } + ////////////////////////////////////////////////////////////////////////// + // Settings ON : + if (!val) + { + if ( par->par ) + { + CKDestroyObject(par->par); + par->par = NULL; + par->condition = -1; + } + } + } + remapIndex(beh,pArray,size); + } + + static void destroyPMap(CKBehavior *beh,BBParArray *pArray) + { + BBParArray *pMap = static_cast(beh->GetAppData()); + if (pMap) + { + while ( pMap->getArray().size() ) + { + BBParameter *p=pMap->getArray().at(0); + pMap->getArray().erase(pMap->getArray().begin()); + if (p) + { + p->par = NULL; + delete p; + p = NULL; + } + } + beh->SetAppData(NULL); + pMap->getArray().clear(); + delete pMap; + pMap = NULL; + } + } + }; + + class BBHelper + { + + public : + + + + /************************************************************************/ + /* */ + /************************************************************************/ + static int getIndex(CKBehavior *beh,BBParameter *par) + { + if (!par)return -1; + if (par && !par->par )return -1; + + for (int i = 0 ; i< beh->GetInputParameterCount() ; i++) + { + if (par->par == beh->GetInputParameter(i)) return i; + } + return -1; + } + + /************************************************************************/ + /* */ + /************************************************************************/ + static void remapIndex(CKBehavior *beh,BBParArray *pAarray,int size ) + { + for (int i = 0 ; i < size ; i ++) + { + BBParameter *p=pAarray->getArray().at(i); + p->inputIndex = p->par !=NULL ? getIndex(beh,p) : -1; + } + } + + /************************************************************************/ + /* */ + /************************************************************************/ + static int getIndex(CKBehavior *beh,BBParArray *pAarray,int indicator ) + { + + #ifdef _DEBUG + assert(beh); + assert(pAarray); + #endif + return pAarray->getArray().at(indicator)->inputIndex; + + } + + /************************************************************************/ + /* */ + /************************************************************************/ + static int getIndexInv(CKBehavior *beh,BBParameter pInMap[],int indicator ) + { + + #ifdef _DEBUG + assert(beh); + #endif + + for ( int i = 0 ; i < beh->GetInputParameterCount() ; i++ ) + { + if (!strcmp(beh->GetInputParameter(i)->GetName(),pInMap[indicator].name.Str() )) + { + return i; + } + } + return -1; + } + + static void loadPIMap(CKBehavior *beh,BBParArray *dst,BBParameter pInMap[],int size,int start) + { + for (int i = 0 ; i < size ; i ++) + { + BBParameter *p=new BBParameter(pInMap[i].ID,pInMap[i].fixed,pInMap[i].guid,pInMap[i].name,pInMap[i].defaultValue,pInMap[i].condition); + dst->getArray().push_back(p); + + if (!p->fixed) + { + int d = i - start ; + CKParameterLocal *lp = beh->GetLocalParameter( i - start); + + lp->GetValue(&p->condition); + } + + if (p->condition) + { + + int index = getIndexInv(beh,pInMap,i); + p->par = ((CKObject*)beh->GetInputParameter(index)); + p->condition = 1; + p->inputIndex = index; + }else + { + p->par = NULL; + p->condition=-1; + p->inputIndex = -1; + } + + } + + dst->isLoaded = true; + } + /************************************************************************/ + /* */ + /************************************************************************/ + static void initPIMap(CKBehavior *beh,BBParArray *dst,BBParameter pInMap[],int size,int start) + { + if (dst->isLoaded) + { + return; + } + + for (int i = 0 ; i < size ; i ++) + { + + BBParameter *p=new BBParameter(pInMap[i].ID,pInMap[i].guid,pInMap[i].name,pInMap[i].defaultValue,pInMap[i].condition); + dst->getArray().push_back(p); + if (pInMap[i].condition ==1 ) + { + CKParameterLocal *lp = beh->GetLocalParameter(start + i ); lp->SetValue(&pInMap[i].condition); + p->par = (CKObject*)beh->CreateInputParameter(pInMap[i].name.Str(),pInMap[i].guid); + int index = getIndex(beh,p); + } + } + BBHelper::remapIndex(beh,dst,size); + } + + static void remapArray(CKBehavior *beh,BBParArray *pArray,int size,int settingStartIndex) + { + for (int sI = 0; sI < size ; sI ++ ) + { + BBParameter *par = pArray->getArray().at(sI); + if (par->fixed) + continue; + + CKParameterLocal *lp = beh->GetLocalParameter(sI - settingStartIndex ); int val = 0; lp->GetValue(&val); + + ////////////////////////////////////////////////////////////////////////// + // Settings ON : + if (val) + { + if ( par->par == NULL ) + { + par->condition = 1; + par->par = (CKObject*)beh->CreateInputParameter(par->name.Str(),par->guid); + } + } + ////////////////////////////////////////////////////////////////////////// + // Settings ON : + if (!val) + { + if ( par->par ) + { + CKDestroyObject(par->par); + par->par = NULL; + par->condition = -1; + } + } + } + remapIndex(beh,pArray,size); + } + + /************************************************************************/ + /* */ + /************************************************************************/ + static void destroyPIMap(CKBehavior *beh,BBParArray *pArray) + { + BBParArray *pIMap = static_cast(beh->GetAppData()); + if (pIMap) + { + while ( pIMap->getArray().size() ) + { + BBParameter *p=pIMap->getArray().at(0); + pIMap->getArray().erase(pIMap->getArray().begin()); + if (p) + { + p->par = NULL; + delete p; + p = NULL; + } + } + beh->SetAppData(NULL); + pIMap->getArray().clear(); + delete pIMap; + pIMap = NULL; + } + } + }; + } + +} +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/virtools/vtBBMacros.h b/ref/vt-ex/include/virtools/vtBBMacros.h new file mode 100644 index 0000000..fcd2225 --- /dev/null +++ b/ref/vt-ex/include/virtools/vtBBMacros.h @@ -0,0 +1,143 @@ +#ifndef __VT_BB_MACROS_H__ +#define __VT_BB_MACROS_H__ + +//#ifndef __VT_TOOLS_H__ +// #include +//#endif + +#ifndef __VT_BB_HELPER_H__ + #include +#endif + +//---------------------------------------------------------------- +// +// The directive _DOC_ONLY_ is just for forcing in/out- parameters creation in dynamic building blocks. +// This allows imagegen.exe to create the right pictures +// +//#define _DOC_ONLY_ 0 + + +#ifdef _DOC_ONLY_ + #define BB_SPIN(I,G,N,D) BBParameter(I,G,N,D,1) +#else + #define BB_SPIN(I,G,N,D) BBParameter(I,G,N,D) +#endif + +#define BB_PIN(I,G,N,D) BBParameter(I,TRUE,G,N,D,1) + +#define BB_SPIN_ON(I,G,N,D) BBParameter(I,G,N,D,1) + + +#define BB_DECLARE_PMAP BBParArray *pMap = static_cast(beh->GetAppData()) + + +#define BB_CREATE_PMAP BBParArray *pMap = static_cast(beh->GetAppData());\ + if(!pMap) pMap = new BBParArray(); \ + beh->SetAppData(pMap) + + +#define BB_DELETE_OLD_MAP if (beh->GetAppData()!=NULL){\ + pMap = NULL;\ + beh->SetAppData(NULL);\ +}\ + +#define BB_CKECK_MAP if (pMap==NULL)\ + {\ + pMap = new BBParArray();\ + }\ + + + + +#define BB_CLEANUP BB_DELETE_OLD_MAP;\ + BB_CKECK_MAP + + +#define BB_CREATE_PIMAP BBParArray *pIMap = new BBParArray(); \ + beh->SetAppData(pIMap) + +#define BB_DECLARE_PIMAP BBParArray *pIMap = static_cast(beh->GetAppData()) + +#define BB_PMAP_SIZE(SOURCE_MAP) (sizeof(SOURCE_MAP) / sizeof(SOURCE_MAP[0])) + + + + + + + + +#define BB_DESTROY_PIMAP BB_DECLARE_PIMAP; \ + BBHelper::destroyPIMap(beh,pIMap); \ + +#define BB_INIT_PIMAP(SOURCE_MAP,SETTING_START_INDEX) BB_CREATE_PMAP; \ + BBHelper::initPIMap(beh,pMap,SOURCE_MAP,BB_PMAP_SIZE(SOURCE_MAP),SETTING_START_INDEX); + + +#define BB_REMAP_PIMAP(SOURCE_MAP,SETTING_START_INDEX) BB_DECLARE_PIMAP;\ + BBHelper::remapArray(beh,pIMap,BB_PMAP_SIZE(SOURCE_MAP),SETTING_START_INDEX) + + +/************************************************************************/ +/* */ +/************************************************************************/ +#define BB_EVALUATE_SETTINGS(A) for (int i = 0 ; i < BB_PMAP_SIZE(A) ; i ++) { \ + if(!A[i].fixed)proto->DeclareSetting(A[i].name.Str(),CKPGUID_BOOL, A[i].condition==-1 ? "FALSE" : "TRUE" ); } \ + +#define BB_EVALUATE_PINS(A) for (int i = 0 ; i < BB_PMAP_SIZE(A) ; i ++) { \ + if(A[i].fixed)proto->DeclareInParameter(A[i].name.Str(),A[i].guid,A[i].defaultValue.Str()); } \ + +#define BB_EVALUATE_OUTPUTS(A) for (int i = 0 ; i < BB_PMAP_SIZE(A) ; i ++) { \ + proto->DeclareOutParameter(A[i].name.Str(),A[i].guid,A[i].defaultValue.Str()); } \ + +#define BB_EVALUATE_INPUTS(A) for (int i = 0 ; i < BB_PMAP_SIZE(A) ; i ++) { \ + proto->DeclareInParameter(A[i].name.Str(),A[i].guid,A[i].defaultValue.Str()); } \ + +//################################################################ +// +// +// +#define BB_LOAD_PIMAP(SOURCE_MAP,SETTING_START_INDEX) BB_CLEANUP;\ + BBHelper::loadPIMap(beh,pMap,SOURCE_MAP,BB_PMAP_SIZE(SOURCE_MAP),SETTING_START_INDEX); \ + beh->SetAppData(pMap) + + +#define BB_LOAD_POMAP(SOURCE_MAP,SETTING_START_INDEX) BB_CLEANUP;\ + BBPOHelper::loadPOMap(beh,pMap,SOURCE_MAP,BB_PMAP_SIZE(SOURCE_MAP),SETTING_START_INDEX);\ + beh->SetAppData(pMap) + + + +#define BB_IP_INDEX(A) BBHelper::getIndex(beh,pIMap,A) + +#define BBSParameter(A) int s##A;\ + beh->GetLocalParameterValue(A,&s##A) + +#define BBSParameterM(A,B) int s##A;\ + beh->GetLocalParameterValue(A-B,&s##A) + + +/************************************************************************/ +/* */ +/************************************************************************/ +#define BB_SPOUT(I,G,N,D) BBParameter(I,G,N,D) +#define BB_SPOUT_ON(I,G,N,D) BBParameter(I,G,N,D,1) + + +#define BB_INIT_PMAP(SOURCE_MAP,SETTING_START_INDEX) BB_CREATE_PMAP;\ + BBPOHelper::initPMap(beh,pMap,SOURCE_MAP,BB_PMAP_SIZE(SOURCE_MAP),SETTING_START_INDEX) + +#define BB_REMAP_PMAP(SOURCE_MAP,SETTING_START_INDEX) BB_DECLARE_PMAP;\ + BBPOHelper::remapArray(beh,pMap,BB_PMAP_SIZE(SOURCE_MAP),SETTING_START_INDEX) + +#define BB_DESTROY_PMAP BB_DECLARE_PMAP; \ + BBPOHelper::destroyPMap(beh,pMap); \ + +#define BB_OP_INDEX(A) BBPOHelper::getIndex(beh,pMap,A) + + +#define BB_O_SET_VALUE_IF(T,I,V) if (s##I)\ + SetOutputParameterValue(beh,BB_OP_INDEX(I),V) + + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/virtools/vtBase.h b/ref/vt-ex/include/virtools/vtBase.h new file mode 100644 index 0000000..ec82cd3 --- /dev/null +++ b/ref/vt-ex/include/virtools/vtBase.h @@ -0,0 +1,24 @@ +/******************************************************************** + created: 2009/02/16 + created: 16:2:2009 10:41 + filename: x:\ProjectRoot\svn\local\usr\include\virtools\vtBase.h + file path: x:\ProjectRoot\svn\local\usr\include\virtools + file base: vtBase + file ext: h + author: Günter Baumgart + + purpose: Includes of Virtools base types. + Do not include CKObjects !!! +*********************************************************************/ +#ifndef __VT_BASE_H__ +#define __VT_BASE_H__ + +//################################################################ +// +// Base types +// +#include "XString.h" +#include "CKTypes.h" +#include "XHashTable.h" + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/virtools/vtBaseMacros.h b/ref/vt-ex/include/virtools/vtBaseMacros.h new file mode 100644 index 0000000..84b8f63 --- /dev/null +++ b/ref/vt-ex/include/virtools/vtBaseMacros.h @@ -0,0 +1,20 @@ +#ifndef __VT_BASE_MACROS_H__ +#define __VT_BASE_MACROS_H__ + + +#include "vtModuleConstants.h" + +//################################################################ +// +// Universal macros +// + +#define VTCX_API_ENTRY(F) VTCX_API_PREFIX##F +#define VTCX_API_CUSTOM_BB_CATEGORY(F) VTCX_API_PREFIX##F + + +#ifndef XINLINE + #define XINLINE inline +#endif + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/virtools/vtCXGlobal.h b/ref/vt-ex/include/virtools/vtCXGlobal.h new file mode 100644 index 0000000..a8e6708 --- /dev/null +++ b/ref/vt-ex/include/virtools/vtCXGlobal.h @@ -0,0 +1,116 @@ +/******************************************************************** + created: 2009/01/05 + created: 5:1:2009 18:18 + filename: X:\ProjectRoot\svn\local\usr\include\virtools\vtCXGlobal.h + file path: X:\ProjectRoot\svn\local\usr\include\virtools + file base: vtCXGlobal + file ext: h + author: + + purpose: +*********************************************************************/ +#ifndef __VTCXGLOBAL_H__ + #define __VTCXGLOBAL_H__ + +////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +// +// Platform Headers +// + +//#include +////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +// +// Platform specific header switchs : +// +#ifdef _WIN32 + #include +#endif + + + +////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +// +// Build switchs : +// + + +////////////////////////////////////////////////////////////////////////// +// DebugBuild is used to hide private building blocks, types, attributes,... +#ifdef NDEBUG + static const bool vtCXDebugBuild = true; +#else + static const bool vtCXDebugBuild = false; +#endif + +////////////////////////////////////////////////////////////////////////// +// dll directives : +#ifndef VTCX_API_EXPORT + #define VTCX_API_EXPORT __declspec(dllexport) +#endif + +#ifndef VTCX_API_INLINE + #define VTCX_API_INLINE __inline +#endif + +#ifndef VTCX_API_sCALL + #define VTCX_API_sCALL __stdcall +#endif + +#ifndef VTCX_API_cDECL + #define VTCX_API_cDECL __cdecl +#endif + + +////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +// +// API Specific Constants : +// + +// #define MY_BB_CAT VTCX_API_CUSTOM_BB_CATEGORY(/MyPlug) leads to : "vtCX/MyPlug" + + +#ifndef VTCX_AUTHOR + #define VTCX_AUTHOR "Guenter Baumgart" +#endif + +#ifndef VTCX_AUTHOR_GUID + #define VTCX_AUTHOR_GUID CKGUID(0x79ba75dd,0x41d77c63) +#endif + +////////////////////////////////////////////////////////////////////////// +// +// Error Identifiers : +// + +////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +// +// File System Specific : +// + +#if defined (_LINUX) + #define VTCX_FS_PATH_SEPERATOR '/' + #define VTCX_FS_PATH_DRIVE_SEPARATOR ':' + #define VTCX_FS_EOL "\n" //(0x0D) +#endif + +#ifdef _WIN32 + #define VTCX_FS_PATH_SEPERATOR '\\' + #define VTCX_FS_PATH_DRIVE_SEPARATOR + #define VTCX_FS_EOL "\r\n" //(0x0A 0x0D) +#endif + +#if defined (macintosh) + #define VTCX_FS_PATH_SEPERATOR '/' + #define VTCX_FS_PATH_DRIVE_SEPARATOR + #define VTCX_FS_EOL "\r" //(0x0A) +#endif + +#define VTCX_FS_PATH_EXT_SEPARATOR '.' + +////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +// + + + + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/virtools/vtCXPlatform32.h b/ref/vt-ex/include/virtools/vtCXPlatform32.h new file mode 100644 index 0000000..3534a2e --- /dev/null +++ b/ref/vt-ex/include/virtools/vtCXPlatform32.h @@ -0,0 +1,22 @@ +#include + +////////////////////////////////////////////////////////////////////////// +//Macros : +/* + From winnt.h : +*/ +#ifndef MAKEWORD + #define MAKEWORD(a, b) ((WORD)(((BYTE)((DWORD_PTR)(a) & 0xff)) | ((WORD)((BYTE)((DWORD_PTR)(b) & 0xff))) << 8)) +#endif + +#ifndef LOWORD + #define LOWORD(l) ((WORD)((DWORD_PTR)(l) & 0xffff)) +#endif + +#ifndef HIWORD + #define HIWORD(l) ((WORD)((DWORD_PTR)(l) >> 16)) +#endif +////////////////////////////////////////////////////////////////////////// + + + diff --git a/ref/vt-ex/include/virtools/vtCXPrecomp.h b/ref/vt-ex/include/virtools/vtCXPrecomp.h new file mode 100644 index 0000000..59fb686 --- /dev/null +++ b/ref/vt-ex/include/virtools/vtCXPrecomp.h @@ -0,0 +1,11 @@ +#ifndef __VTCXPRECOMP_H +#define __VTCXPRECOMP_H + +#include "VxMath.h" +#include "CKAll.h" + + +#undef min +#undef max + +#endif diff --git a/ref/vt-ex/include/virtools/vtGUID.h b/ref/vt-ex/include/virtools/vtGUID.h new file mode 100644 index 0000000..6f05965 --- /dev/null +++ b/ref/vt-ex/include/virtools/vtGUID.h @@ -0,0 +1,91 @@ +#pragma once + +#include "CKAll.h" + +class vtGUID +{ +private: + CKGUID guid; + +public: + + CKGUID GetVirtoolsGUID() + { + return guid; + } + vtGUID( DWORD d1=0, DWORD d2=0 ):guid(d1,d2) {} + + XString ToString( void ) + { + XString laid; + + laid << DecimalToHex( guid.d1 ); + laid << DecimalToHex( guid.d2 ); + + return laid; + } + + bool FromString( const XString laid ) + { + + if( laid.Length() != 16 ) + return false; + + XString d1(laid); + XString d2(laid); + + d1.Crop( 0, 8 ); + d2.Crop( 8, 8 ); + + HexToDecimalHI( d1.Str(), guid.d1 ); + HexToDecimalLO( d2.Str(), guid.d2 ); + + return true; + } + + vtGUID & operator =( const CKGUID& ckguid ) + { + guid.d1 = ckguid.d1; + guid.d2 = ckguid.d2; + + return *this; + } + + operator XString() { return ToString(); } + +private: + XString DecimalToHex( int decimal ) + { + XString hexStr; + char hexstring[17]; + itoa( decimal, hexstring, 16); + + int length = strlen(hexstring); + if (length < 8) + { + int add = 8 - length; + for (int i = 0; i < add; i++) + { + hexStr << "0"; + } + } + + hexStr << hexstring; + + return hexStr; + + } + + bool HexToDecimalHI (char* HexNumber, unsigned int& Number) + { + char* pStopString; + Number = strtol (HexNumber, &pStopString, 16); + return (bool)(Number != LONG_MAX); + } + bool HexToDecimalLO(char* HexNumber, unsigned int& Number) + { + char* pStopString; + Number = strtoul(HexNumber, &pStopString, 16); + return (bool)(Number != LONG_MAX); + } +}; diff --git a/ref/vt-ex/include/virtools/vtStructHelper.h b/ref/vt-ex/include/virtools/vtStructHelper.h new file mode 100644 index 0000000..4ff8d10 --- /dev/null +++ b/ref/vt-ex/include/virtools/vtStructHelper.h @@ -0,0 +1,133 @@ +#ifndef __VT_STRUCT_HELPER_H__ +#define __VT_STRUCT_HELPER_H__ + + + +namespace vtTools +{ + + namespace ParameterTools + { + + struct StructurMember + { + CKGUID guid; XString name; XString defaultValue; + CKObject *par; + StructurMember() + { + guid = CKGUID(0,0); name = ""; defaultValue = ""; + } + + StructurMember(CKGUID _guid,XString _name,XString _defaultValue) : + guid(_guid) , name(_name) , defaultValue(_defaultValue) + { + } + + }; + + class CustomStructure + { + + public : + CustomStructure(){} + CustomStructure(XString name,CKGUID guid,StructurMember members[],int size) : mGuid(guid) , mName(name) + { + + for (int i = 0 ; i < size ; i ++) + { + + StructurMember *p=new StructurMember(members[i].guid,members[i].name,members[i].defaultValue); + getArray().push_back(p); + } + + } + std::vectorpars; + std::vector&getArray() + { + return pars; + } + + CKGUID mGuid; + XString mName; + }; + + class StructHelper + { + + public : + + static XArraygetMemberGuids(CustomStructure _inStructure) + { + XArrayresult; + + int size = _inStructure.getArray().size(); + for (int i = 0 ; i < size ; i ++) + { + StructurMember *m=_inStructure.getArray().at(i); + result.PushBack(m->guid); + } + return result; + } + static XString getLabelNames(CustomStructure _inStructure) + { + XString result; + + int size = _inStructure.getArray().size(); + for (int i = 0 ; i < size ; i ++) + { + StructurMember *m=_inStructure.getArray().at(i); + result << m->name.CStr(); + + if (i != size -1) + { + result << ","; + } + } + return result; + } + + static XString getDefaultValue(CustomStructure _inStructure) + { + XString result; + + int size = _inStructure.getArray().size(); + for (int i = 0 ; i < size ; i ++) + { + StructurMember *m=_inStructure.getArray().at(i); + result << m->defaultValue.CStr(); + if (i != size -1) + { + result << ";"; + } + } + return result; + } + }; + + } +} + +#define STRUCT_ATTRIBUTE(G,N,D) vtTools::ParameterTools::StructurMember(G,N,D) +#define DECLARE_STRUCT(T,N,G,A,S) CustomStructure cs##T(N,G,A,S) + +#define STRUCT_SIZE(SOURCE_MAP) (sizeof(SOURCE_MAP) / sizeof(SOURCE_MAP[0])) +#define STRUCT_MEMBER_NAMES(SRC) vtTools::ParameterTools::StructHelper::getLabelNames(cs##SRC) +#define STRUCT_MEMBER_GUIDS(SRC) vtTools::ParameterTools::StructHelper::getMemberGuids(cs##SRC) +#define STRUCT_MEMBER_DEFAULTS(SRC) vtTools::ParameterTools::StructHelper::getDefaultValue(cs##SRC) + + +#define REGISTER_CUSTOM_STRUCT(NAME,ENUM_TYPE,GUID,MEMBER_ARRAY,HIDDEN) DECLARE_STRUCT(ENUM_TYPE,NAME,GUID,MEMBER_ARRAY,STRUCT_SIZE(MEMBER_ARRAY)); \ + XArray ListGuid##ENUM_TYPE = STRUCT_MEMBER_GUIDS(ENUM_TYPE);\ + pm->RegisterNewStructure(GUID,NAME,STRUCT_MEMBER_NAMES(ENUM_TYPE).Str(),ListGuid##ENUM_TYPE);\ + CKParameterTypeDesc* param_type##ENUM_TYPE=pm->GetParameterTypeDescription(GUID);\ + if (param_type##ENUM_TYPE && HIDDEN) param_type##ENUM_TYPE->dwFlags|=CKPARAMETERTYPE_HIDDEN + + +#define REGISTER_STRUCT_AS_ATTRIBUTE(NAME,ENUM_TYPE,CATEGORY,GUID,CLASS,MEMBER_ARRAY,USE_DEFAULTS) int att##ENUM_TYPE = attman->RegisterNewAttributeType(NAME,GUID,CLASS);\ + attman->SetAttributeCategory(att##ENUM_TYPE,CATEGORY);\ + if(USE_DEFAULTS)\ + attman->SetAttributeDefaultValue(att##ENUM_TYPE,STRUCT_MEMBER_DEFAULTS(ENUM_TYPE).Str()); + + + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/virtools/vtTools.h b/ref/vt-ex/include/virtools/vtTools.h new file mode 100644 index 0000000..99f7cac --- /dev/null +++ b/ref/vt-ex/include/virtools/vtTools.h @@ -0,0 +1,836 @@ +#ifndef __VT_TOOLS_H__ + #define __VT_TOOLS_H__ + +#include "CKAll.h" + +#ifndef _INC_STDLIB + #include +#endif + +#ifndef _VECTOR_ + #include +#endif + +//#ifndef __VT_BB_MACROS_H__ +// #include +//#endif + +//#ifndef __VT_BB_HELPER_H__ +//#include +//#endif +namespace vtTools +{ + /*************************************************************************/ + /* common enumerations */ + /* */ + namespace Enums + { + /* + Represents a virtools super type. + See GetVirtoolsSuperType. + */ + enum SuperType + { + vtSTRING = 1, + vtFLOAT = 2, + vtINTEGER = 3, + vtVECTOR = 4, + vtVECTOR2D = 5, + vtCOLOUR = 6, + vtMATRIX = 7, + vtQUATERNION = 8, + vtRECTANGLE = 9, + vtBOX = 10, + vtBOOL = 11, + vtENUMERATION = 12, + vtFLAGS = 13, + vtFile = 14, + vtOBJECT = 16, + vtUNKNOWN = 17 + }; + + /* Author: gunther.baumgart + Represents the c++ equivalent for TGBLWidgetType + pm->RegisterNewEnum(EVTWIDGETTYPE,"EVTWidgetType", + "StaticText=1, + TextEdit=2, + CheckButton=4, + PushButton=8, + ListBox=16, + ComboBox=32, + FileSelector=64, + ColorSelector=128" ); + */ + + enum EVTWidgetType + { + EVT_WIDGET_STATIC_TEXT = 1, + EVT_WIDGET_EDIT_TEXT =2, + EVT_WIDGET_CHECK_BUTTON =3, + EVT_WIDGET_LIST_BOX =5, + EVT_WIDGET_COMBO_BOX =6, + EVT_WIDGET_FILE_SELECTION =7, + EVT_WIDGET_COLOR_SELECTION =8 + }; + + /* + + */ + + }/* end namespace typedefs */ + + /*************************************************************************/ + /* common Structs */ + /* */ + namespace Structs + { + + + ////////////////////////////////////////////////////////////////////////// + /* + ParameterInfo is used to describe a virtools parameter type. + Example : Matrix = horizontalItems = 4, + verticalItems = 4 + memberType =vtFLOAT, + superType= vtMATRIX + */ + struct ParameterInfo + { + int horizontalItems; + int verticalItems; + + Enums::SuperType superType; + Enums::SuperType memberType; + + }; + ////////////////////////////////////////////////////////////////////////// + /* + SGBL_WidgetInfo describes an parameter for using GBLWidgets + GBL-Widgets. + */ + struct WidgetInfo + { + struct WidgetInfoItem + { + Enums::SuperType baseType; + Enums::EVTWidgetType widgetType; //with which widget + XString value; + XString label; + + }; + XArrayitems; + Structs::ParameterInfo parameterInfo; + }; + }/* end namespace Structs */ + + /************************************************************************/ + /* parameter tools */ + /* */ + namespace ParameterTools + { + + + /* + ******************************************************************* + * Function: IsNumeric() + * + * Description : Check each character of the string + If a character at a certain position is not a digit, + then the string is not a valid natural number + + * Parameters : char*Str,r : the string to test + * Returns : int + * + ******************************************************************* + */ + int IsNumeric(const char* Str,Enums::SuperType superType); + + /* + ******************************************************************* + * Function: GetParameterMemberInfo() + * + * Description : GetParameterMemberInfo returns the type super type of the used structure members. + Example : vtVECTOR returns vtFLOAT + * Parameters : CKContext* context, r : the virtools context. + CKParameterType parameterType, r : the type to test. + * Returns : CO_EVT_VirtoolsSuperType + * + ******************************************************************* + */ + Enums::SuperType GetParameterMemberInfo(CKContext* context,CKParameterType parameterType); + + /* + ******************************************************************* + * Function: GetParameterInfo() + * + * Description : GetParameterInfo returns an info about a virtools type. + Example : Vector4D returns : + result.horizontalItems = 4 ; + result.verticalItems = 1 ; + result.memberType = vtFLOAT + result.superType = vtQUATERNION; + * Parameters : CKContext* context, r : the virtools context. + CKParameterType parameterType, r : the type to test. + * Returns : ParameterInfo + * + ******************************************************************* + */ + Structs::ParameterInfo GetParameterInfo(CKContext* context,CKParameterType parameterType); + + /* + ******************************************************************* + * Function: CreateWidgetInfo() + * + * Description : CreateWidgetInfo returns an handy info about an parameter type and a + given string value of this parameter. + + * Parameters : CKContext* context, r : the virtools context. + CKParameterType parameterType, r : the type to test. + XString stringValue,r : the string value of the given type. + + * Returns : WidgetInfo + ******************************************************************* + */ + Structs::WidgetInfo* CreateWidgetInfo(CKContext* context,CKParameterType parameterType,XString stringValue); + /* + ******************************************************************* + * Function: GetWidgetType() + * + * Description : GetWidgetType returns the type of the GBLWidget which should used for a + specific virtools super type. + Example : vtBOOL = CheckBox + vtENUMERATION = ComboBox + * + * Parameters : CO_EVT_VirtoolsSuperType superType, r : the given virtools super type + * Returns : EWidgetType + * + ******************************************************************* + */ + Enums::EVTWidgetType GetWidgetType(Enums::SuperType superType); + /* + ******************************************************************* + * Function: TypeCheckedParameterCopy() + * + * Description : Copies the source parameter to a destination parameter. On a type mismatch + * it tries to copy as string. This also works for nested virtools structures. See + CO_EVT_VirtoolsSuperType for supported types. + * + * Parameters : CKParameter*dest,rw : the destination parameter + CKParameter*src,r : the source parameter + * Returns : bool = true if succesful. + * todo:: return copied diff + * + ******************************************************************* + */ + int TypeCheckedParameterCopy( CKParameter*dest, CKParameter*src); + + /* + ******************************************************************* + * Function: GetParameterAsString() + * + * Description : Returns the string value a CKParameter. + * + * Parameters : CKParameter*src ,r the given parameter + + * Returns : CKSTRING + * + ******************************************************************* + */ + CKSTRING GetParameterAsString( CKParameter*src); + + /* + ******************************************************************* + * Function: CompareStringRep() + * + * Description : This function compares the string representation of the two CKParameters. + * + * Parameters : CKParameter* valueA,r : the first parameter + CKParameter* valueB,r : the second parameter + * Returns : int (like strcmp) + * + ******************************************************************* + */ + int CompareStringRep(CKParameter*valueA, CKParameter*valueB); + /* + ******************************************************************* + * Function:GetVirtoolsSuperType() + * + * Description : GetVirtoolsSuperType returns the base type of a virtools parameter. + This is very useful to determine whether a parameter can be used for + network or a database. + * + * Parameters : CKContext *ctx, r : the virtools context + CKGUID guid, r : the guid of the parameter + * + * Returns : CO_EVT_VirtoolsSuperType, + * + ******************************************************************* + */ + Enums::SuperType GetVirtoolsSuperType(CKContext *ctx,const CKGUID guid); + /* + ******************************************************************* + * Function: TypeIsSerializable() + * Description : Returns true if the given type can be stored as string. + + It also checks custom virtools structures recursive. + + it checks only + * + * Parameters : CKContext *ctx, r : the virtools context + CKParameterType type, r : the type + * Returns : bool + * + ******************************************************************* + */ + bool TypeIsSerializable(CKContext *ctx,CKParameterType type); + /* + ******************************************************************* + * Function: IsValidStruct() + * + * Description : Like TypeIsSerializable, even checks a custom virtools structure, recursive. + * + * Parameters : CKContext *ctx,r : the virtools context + CKGUID type,r : the type to check + + * Returns : bool + * + ******************************************************************* + */ + bool IsValidStruct(CKContext *ctx,CKGUID type); + /* + ******************************************************************* + * Function:SetParameterStructureValue() + * + * Description : Sets a specific value in a custom structure. + * + * Parameters : CKParameter *par, r : the virtools virtools parameter + const unsigned short StructurIndex, r : the index within the custom structure + T value, r : the value. + bool update,r : If this function is part of a virtools parameter operation, this + should set to false, otherwise it is an infinity loop. + * Returns : is a void + * + ******************************************************************* + */ + templatevoid SetParameterStructureValue( + CKParameter *par, + const unsigned short StructurIndex, + T value, + bool update = TRUE + ) + { + assert(par && StructurIndex>=0 ); + CK_ID* paramids = (CK_ID*)par->GetReadDataPtr(update); + CKParameterOut *pout = static_cast(par->GetCKContext()->GetObject(paramids[StructurIndex])); + pout->SetValue(&value); + } + + /* + ******************************************************************* + * Function:SetParameterStructureValue() + * + * Description : This is a template function specialization for CKSTRING. + * Sets a specific value in a custom structure. + * + * Parameters : CKParameter *par, r : the virtools virtools parameter + const unsigned short StructurIndex, r : the index within the custom structure + T value, r : the value. + bool update,r : If this function is part of a virtools parameter operation, this + should set to false, otherwise it is an infinity loop. + * Returns : is a void + * + ******************************************************************* + */ + template<>__inline void SetParameterStructureValue + ( + CKParameter *par, + const unsigned short StructurIndex, + CKSTRING value, + bool update + ) + { + assert(par && StructurIndex>=0 ); + static_cast(par->GetCKContext()->GetObject( static_cast(par->GetReadDataPtr(update))[StructurIndex]))->SetStringValue(value); + } + + /* + ******************************************************************* + * Function:GetValueFromParameterStruct() + * + * Description : returns a object from a custom structure. + * + * Parameters : CKParameter *par, r : the virtools virtools parameter + const unsigned short StructurIndex, r : the index within the custom structures + bool update,r : If this function is part of a virtools parameter operation, this + should set to false, otherwise it is an infinity loop. + * Returns : T. + * + ******************************************************************* + */ + template__inline T GetValueFromParameterStruct( + CKParameter *par, + const unsigned short StructurIndex, + bool update=false) + { + T value; + assert(par); + CK_ID* paramids = static_cast(par->GetReadDataPtr(update)); + CKParameterOut* pout = static_cast(par->GetCKContext()->GetObject(paramids[StructurIndex])); + pout->GetValue(&value); + return value; + } + /* + ******************************************************************* + * Function:GetValueFromParameterStruct() + * + * Description : This is a template function specialization for CKSTRING + * Gets a specific value from custom structure. + * + * Parameters : CKParameter *par, r : the virtools virtools parameter + const unsigned short StructurIndex, r : the index within the custom structures + bool update,r : If this function is part of a virtools parameter operation, this + should set to false, otherwise it is an infinity loop. + + * Returns : CKSTRING. + * + ******************************************************************* + */ + template<>__inline CKSTRING GetValueFromParameterStruct( + CKParameter *par, + const unsigned short StructurIndex, + bool update) + { + assert( par && StructurIndex >=0 ); + CK_ID* paramids = static_cast(par->GetReadDataPtr(update)); + CKParameterOut* pout = static_cast(par->GetCKContext()->GetObject(paramids[StructurIndex])); + CKSTRING stringValue = static_cast(pout->GetReadDataPtr(update)); + return stringValue; + + } + + __inline CKParameterOut* GetParameterFromStruct(CKParameter *par,const int index,bool update=false) + { + CK_ID* paramids = static_cast(par->GetReadDataPtr(update)); + if (paramids) + { + return static_cast(par->GetCKContext()->GetObject(paramids[index])); + } + return NULL; + } + + } /*end namespace virtools parameter tools */ + + + /************************************************************************/ + /* building block tools */ + /* */ + namespace BehaviorTools + { + + + + + + __inline void Error(CKBehavior *beh,CKSTRING errorString,int errorOutputIndex,bool trigger=false,int outTrigger=0,bool outputOnConsole = false) + { + if(!beh) + return; + + if(!strlen(errorString)) + return; + + CKParameterOut *pout = beh->GetOutputParameter(errorOutputIndex); + pout->SetStringValue(errorString); + if (trigger) + { + beh->ActivateOutput(outTrigger); + } + CKContext* ctx = beh->GetCKContext(); + if(outputOnConsole && ctx) + ctx->OutputToConsole(errorString,FALSE); + + } + __inline void Error(CKBehavior *beh,int error,int errorOutputIndex,CKSTRING errorString,bool trigger=false,int outTrigger=0,bool outputOnConsole = false) + { + if(!beh) + return; + + beh->SetOutputParameterValue(errorOutputIndex,&error); + if (trigger) + { + beh->ActivateOutput(outTrigger); + } + + + if(!strlen(errorString)) + return; + + CKContext* ctx = beh->GetCKContext(); + if(outputOnConsole && ctx) + ctx->OutputToConsole(errorString,FALSE); + + } + + + /* + ******************************************************************* + * Function:GetInputParameterValue() + * + * Description : Returns an input parameter value. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : T + * + ******************************************************************* + */ + template__inline void SetOutputParameterValue( + CKBehavior *beh, + const int pos, + T value) + { + #ifdef _DEBUG + assert(beh); + #endif + + T val = value; + beh->SetOutputParameterValue(pos,&val); + } + + template__inline void SetInputParameterValue( + CKBehavior *beh, + const int pos, + T value) + { + T val = value; + CKParameterOut *inPar = (CKParameterOut*)(beh->GetInputParameter(pos)->GetRealSource()); + if (inPar) + { + inPar->SetValue(&val); + } + } + + /* + ******************************************************************* + * Function:GetInputParameterValue() + * + * Description : Returns an input parameter value. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : T + * + ******************************************************************* + * + */ + template<>__inline void SetInputParameterValue( + CKBehavior *beh, + const int pos, + CKSTRING val) + { + CKParameterIn*inPar = beh->GetInputParameter(pos); + if (inPar && val && strlen(val) ) + { + CKParameter*par = inPar->GetRealSource(); + if (par) + par->SetStringValue(val); + } + } + + + /* + ******************************************************************* + * Function:GetInputParameterValue() + * + * Description : Returns an input parameter value. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : T + * + ******************************************************************* + */ + template<>__inline void SetOutputParameterValue( + CKBehavior *beh, + const int pos, + CKSTRING val) + { + #ifdef _DEBUG + assert(beh); + #endif // _DEBUG + + if(strlen(val)) + { + CKParameterOut *pout = beh->GetOutputParameter(pos); + if (pout) + { + pout->SetStringValue(val); + } + } + } + /* + ******************************************************************* + * Function:GetInputParameterValue() + * + * Description : Returns an input parameter value. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : T + * + ******************************************************************* + */ + template<>__inline void SetOutputParameterValue( + CKBehavior *beh, + const int pos, + const char *val) + { + #ifdef _DEBUG + assert(beh); + #endif // _DEBUG + if(strlen(val)) + { + CKParameterOut *pout = beh->GetOutputParameter(pos); + if (pout) + { + pout->SetStringValue(const_cast(val)); + } + } + } + /* + ******************************************************************* + * Function:GetInputParameterValue() + * + * Description : Returns an input parameter value. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : T + * + ******************************************************************* + */ + template__inline T GetInputParameterValue( + CKBehavior *beh, + const int pos) + { + assert(beh); + T value ; + beh->GetInputParameterValue(pos,&value); + return value; + } + + /* + ******************************************************************* + * Function:GetInputParameterValue() + * + * Description : Returns an input parameter value. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : T + * + ******************************************************************* + */ + template__inline T GetOutputParameterValue( + CKBehavior *beh, + const int pos) + { + assert(beh); + T value ; + beh->GetOutputParameterValue(pos,&value); + return value; + } + + /* + ******************************************************************* + * Function:GetInputParameterValue() + * + * Description : This is a template function specialization for CKSTRING. + Returns an input parameter value. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : CKSTRING + * + ******************************************************************* + */ + template<>__inline CKSTRING GetInputParameterValue( + CKBehavior *beh, + const int pos) + { + assert(beh); + return static_cast(beh->GetInputParameterReadDataPtr(pos)); + } + + /* + ******************************************************************* + * Function:GetInputParameterValue() + * + * Description : This is a template function specialization for CKBeObject*. + Returns a input parameter value from a building block. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : CKBeObject. + * + ******************************************************************* + */ + template<>__inline CKObject* GetInputParameterValue( + CKBehavior *beh, + const int pos) + { + assert(beh); + return beh->GetInputParameterObject(pos); + } + + void __inline EnablePOutputBySettings(CKBehavior *beh,int index) + { + int cond; + beh->GetLocalParameterValue(index,&cond); + beh->EnableOutputParameter(index,cond); + } + + void __inline EnablePInputBySettings(CKBehavior *beh,int index) + { + int cond; + beh->GetLocalParameterValue(index,&cond); + beh->EnableInputParameter(index,cond); + } + + //void SetOutputParameterValueBySettings + + + template__inline T SetOutputParameterBySettings( + CKBehavior *beh, + const int pos, + T value) + { + int cond; + beh->GetLocalParameterValue(pos,&cond); + if (cond) + { + SetOutputParameterValue(beh,pos,value); + } + } + + + + + + //todo : parametric log / debug forwarding!!! - > g.baumgart ! + + + + }/* end namespace behavior tools*/ + + + /**************************************************************************/ + /* attribute tools */ + /* */ + /* */ + namespace AttributeTools + { + + /* + ****************************************************************** + * Function:GetObjectFromAttribute() + * + * Description : This is a template function specialization for CKBeObject*. + Returns a input parameter value from a building block. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : CKBeObject. + * + ******************************************************************* + */ + template__inline T* GetObjectFromAttribute(CKContext *ctx,CKObject *_e,const int attributeID,const int StructurIndex) + { + T *value; + CKParameterOut* pout = _e->GetAttributeParameter(attributeID); + CK_ID* paramids = (CK_ID*)pout->GetReadDataPtr(); + pout = (CKParameterOut*)ctx->GetObject(paramids[StructurIndex]); + value = (T*)ctx->GetObject(*(CK_ID*)pout->GetReadDataPtr()); + return value ? value : NULL; + } + /* + ****************************************************************** + * Function:GetObjectFromAttribute() + * + * Description : This is a template function specialization for CKBeObject*. + Returns a input parameter value from a building block. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : CKBeObject. + * + ******************************************************************* + */ + template__inline void SetAttributeValue(CKBeObject *_e,const int attributeID,const int StructurIndex,T* value) + { + CKParameterOut* pout = _e->GetAttributeParameter(attributeID); + if(pout) + { + CK_ID* paramids = (CK_ID*)pout->GetReadDataPtr(); + pout = (CKParameterOut*)_e->GetCKContext()->GetObject(paramids[StructurIndex]); + if (pout) + { + pout->SetValue(value); + } + } + } + /* + ****************************************************************** + * Function:GetObjectFromAttribute() + * + * Description : This is a template function specialization for CKBeObject*. + Returns a input parameter value from a building block. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : CKBeObject. + * + ******************************************************************* + */ + template__inline T GetValueFromAttribute(CKBeObject *_e,int attributeID,int StructurIndex) + { + T value; + CKParameterOut* pout = _e->GetAttributeParameter(attributeID); + if (pout) + { + CK_ID* paramids = static_cast(pout->GetReadDataPtr()); + pout = static_cast(_e->GetCKContext()->GetObject(paramids[StructurIndex])); + if (pout) + { + pout->GetValue(&value); + } + } + return value; + } + + /* + ****************************************************************** + * Function:GetObjectFromAttribute() + * + * Description : This is a template function specialization for CKBeObject*. + Returns a input parameter value from a building block. + * + * Parameters : CKBehavior *beh, r : the behavior context + const unsigned short pos, r : the parameter input index + * Returns : CKBeObject. + * + ******************************************************************* + */ + template__inline T GetValueFromAttribute(CKBeObject *_e,int attributeID) + { + T value; + CKParameterOut* pout = _e->GetAttributeParameter(attributeID); + if (pout) + { + pout->GetValue(&value); + } + return value; + } + + }/* end namespace attribute tools*/ +} + +#endif diff --git a/ref/vt-ex/include/vtxall.h b/ref/vt-ex/include/vtxall.h new file mode 100644 index 0000000..2f2fb8c --- /dev/null +++ b/ref/vt-ex/include/vtxall.h @@ -0,0 +1,49 @@ +#ifndef __VT_X_ALL_H__ +#define __VT_X_ALL_H__ + +/******************************************************************** + created: 2008/12/05 + created: 5:12:2008 0:34 + filename: x:\ProjectRoot\localSVN\usr\include\vtXAll.h + file path: x:\ProjectRoot\localSVN\usr\include + file base: vtXAll + file ext: h + author: mc007 + + purpose: collective header file, includes all generic vt helper classes +*********************************************************************/ + + +#include + +//#include +//#include + +using namespace vtTools; +using namespace BehaviorTools; + +//#include + +#include "vtLogTools.h" +#include "vtStructHelper.h" + +/* +#define VTD_PREFIX +#endif + + + + +void xCONVENTION_CALLBACK updateAssertHandlerData( + E_ASSERTION_FAILURE_SEVERITY _failureSeverity, + char *_assertionExpression, + char *_assertionFileName, + int _assertionSourceLine, + char *_assertionPostMessage, + void* _postAction, + bool _result); + +void xCONVENTION_CALLBACK tickAssertHandlerData(); + + + + +//---------------------------------------------------------------- +// +// Assertion checks customization +// +typedef void (xCONVENTION_CALLBACK *CAssertionFailedProcedure)( + E_ASSERTION_FAILURE_SEVERITY fsFailureSeverity, + const char *szAssertionExpression, + const char *szAssertionFileName, + unsigned int uiAssertionSourceLine + ); + +//typedef void (xCONVENTION_CALLBACK *CPostCallback)(); + +typedef void (xCONVENTION_CALLBACK *xErrorHandlerFn) + ( + E_ASSERTION_FAILURE_SEVERITY m_fsFailureSeverity, + char *m_szAssertionExpression, + char *m_szAssertionFileName, + int m_uiAssertionSourceLine, + char *szAssertionPostMessage, + void* postAction, + bool result + ); + + + + +class xAssertionEx +{ +public: + + static CAssertionFailedProcedure getAssertFailureCustomHandler() + { + xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"invoked"); +// xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"Null"); + return g_fnAssertFailureHandler; + } + static void CustomizeAssertionChecks(CAssertionFailedProcedure fnAssertionFailureProcedure) + { + xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"invoked"); +// xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"Null"); + g_fnAssertFailureHandler = fnAssertionFailureProcedure; + } + + + + //xErrorHandlerFn xCONVENTION_API getErrorHandler(); + + + //---------------------------------------------------------------- + // + // + // + static xErrorHandlerFn getErrorHandler() + { + ///xAssertInfo *testData = getLastAssertInfo(); + //xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"invoked"); + return g_fnAssertHandler; + } + + static void updateErrorHandler(xErrorHandlerFn fnFailureProcedure) + { + g_fnAssertHandler = fnFailureProcedure; + //xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"invoked"); + + } + + //void xCONVENTION_API setErrorHandler(xErrorHandlerFn fnFailureProcedure); + + + static void swapBuffer(xAssertInfo&newData); + static xAssertionEx *Instance(); + xAssertionEx(); + +private: + + static CAssertionFailedProcedure g_fnAssertFailureHandler; + static xErrorHandlerFn g_fnAssertHandler; + + +}; + +#define xAssertRouted(Assertion) if(Assertion){}else assert_notify_failure(#Assertion) + +#define XASSERT_HANDLER(Assertion) (false || (Assertion) \ + || (xAssertionEx::getAssertFailureCustomHandler() \ + && (xAssertionEx::getAssertFailureCustomHandler()( \ + AFS_ASSERT, #Assertion, __FILE__, __LINE__), true))) + +#define xCHECK_HANDLER(Assertion) ((bConditionValue = false || (Assertion)\ + || (xAssertionEx::getAssertFailureCustomHandler() \ + && (xAssertionEx::getAssertFailureCustomHandler()( \ + AFS_CHECK, #Assertion, __FILE__, __LINE__), true))) + + + +#define _xAssertHandler(Assertion) (false || (Assertion) || \ + (xAssertionEx::getErrorHandler() &&\ + (xAssertionEx::getErrorHandler()( AFS_ASSERT, #Assertion, __FILE__, __LINE__,"asdasd",NULL,TRUE), true))) + + +/*#define _xAssert(Assertion) (false || (Assertion) + || (xAssertionEx::getErrorHandler() \ + && (xAssertionEx::getErrorHandler()( \ + AFS_ASSERT, #Assertion, __FILE__, __LINE__,"","",FALSE), true))) +*/ + + +#define xAssert(Assertion) xAssertRouted(XASSERT_HANDLER(Assertion)) + +#define xVerify(Assertion) xAssert(Assertion) + +#define xCheck(Assertion) { \ + bool bConditionValue; \ + assert(xCHECK_HANDLER(Assertion)); \ + (void)(bConditionValue || (*(int *)0 = 0)); \ + + +#define xVerify(Assertion) _xAssertHandler(Assertion) + + +/* +#define xVerify(Assertion) { \ + bool bConditionValue=False; \ + xAssert(xVerifyHandlerEx(Assertion)); \ + (void)(bConditionValue || (*(int *)0 = 0)); \ +} + +*/ + + +/* + +#define xVerify(Assertion) { \ + bool bConditionValue; \ + assert(xVerifyHandlerEx(Assertion)); \ + (void)(bConditionValue || (*(int *)0 = 0)); \ +} + + + + +//#define xAssert(Assertion) assert(XASSERT_HANDLER(Assertion)) + +//#define xVerify(Assertion) assert(xVerifyHandlerEx(Assertion)) + +/* + + + + +/* + +//extern xErrorHandlerFn xAssertionEx::g_fnAssertHandler; + +*/ + +/* + + + +#define xASSERT_HANDLER(Condition) (false || (Condition) \ +|| (xAssertionEx::GetAssertFailureCustomHandler() \ +&& (xAssertionEx::GetAssertFailureCustomHandler()( \ +AFS_ASSERT, #Condition, __FILE__, __LINE__), true))) + +#define xAssert(Condition) XASSERT(xASSERT_HANDLER(Condition)) +*/ +//#define xVerify(Condition) xAssert(Condition) + +//#define XASSERT(Condition) assert(xASSERT_HANDLER(Condition)) + + +/* +#define xVerifyHandlerEx(Condition,Message,Object,PostAction,Result) (false || (Condition,Message,Object,PostAction,Result) \ +|| (xAssertionEx::CVerifyChecks2() \ +&& (xAssertionEx::CVerifyChecks2()( \ +AFS_ASSERT, #Condition, __FILE__, __LINE__,Message,Object,PostAction,Result), true))) +*/ +/* +#define xVerifyAndCorrect(Condition,Message,Object,PostAction,Result) { \ +bool bConditionValue; \ +xAssert(xVerifyHandlerEx(Condition,Message,Object,PostAction,Result)); \ +(void)(bConditionValue || (*(int *)0 = 0)); \ +} +*/ + +/* +#define xCheck(Condition) { \ +bool bConditionValue; \ +XASSERT(xCHECK_HANDLER(Condition)); \ +(void)(bConditionValue || (*(int *)0 = 0)); \ +} +*/ + +/* +#define xVerifyHandlerEx(Conditio1n,Message,Object,PostAction,Result) (false || (Condition,Message,Object,PostAction,Result) \ +|| (xAssertionEx::CVerifyChecks2() \ +&& (xAssertionEx::CVerifyChecks2()( \ +AFS_ASSERT, #Condition, __FILE__, __LINE__,Message,Object,PostAction,Result), true))) +*/ + + +/* +#define xVerifyHandler(Condition) (false || (Condition) \ +|| (xAssertionEx::GetAssertFailureCustomHandler() \ +&& (xAssertionEx::GetAssertFailureCustomHandler()( \ +AFS_ASSERT, #Condition, __FILE__, __LINE__), true))) +*/ +/* +#define xVerifyHandler(Condition,Message,Object,PostAction,Result) (false || (Condition,Message,Object,PostAction,Result) \ +|| (xAssertionEx::CVerifyChecks() \ +&& (xAssertionEx::CVerifyChecks()(\ +AFS_ASSERT, #Condition ,__FILE__, __LINE__,Message,Object,PostAction,Result), true))) +*/ + +/* +#define xVerifyHandler(Condition,Message,Object,PostAction,Result) (false || (Condition +|| (xAssertionEx::CVerifyChecks() \ +&& (xAssertionEx::CVerifyChecks()( AFS_ASSERT, #Condition ,\ +__FILE__, __LINE__,Message,Object,PostAction,Result), true))) +*/ + +/* +#define xCHECK_HANDLER(Condition) ((bConditionValue = false || (Condition)) \ +|| (xAssertionEx::GetAssertFailureCustomHandler() \ +&& (xAssertionEx::GetAssertFailureCustomHandler()( \ +AFS_CHECK, #Condition, __FILE__, __LINE__), true))) +*/ + +/* +#define xCHECK_HANDLER_MO(Condition) ((bConditionValue = false || (Condition)) \ +|| (xAssertionEx::GetAssertFailureCustomHandler() \ +&& (xAssertionEx::GetAssertFailureCustomHandler()( \ +AFS_CHECK, #Condition, __FILE__, __LINE__), true))) +*/ + + + + + +/* + + + +/* + + +#define xCheckMO(Condition) { \ +bool bConditionValue; \ +XASSERT(xCHECK_HANDLER(Condition)); \ +(void)(bConditionValue || (*(int *)0 = 0)); \ +} +*/ + + + + +//---------------------------------------------------------------- +// +// Release Code : +// +//#define xAssert(Condition) ((void)0) + +//#define xVerify(Condition) ((void)(Condition)) + + + + +/* +#define xVerifyAndCorrect(Condition) { \ + bool bConditionValue = true; \ + xAssert(xVerifyHandlerEx(Condition)); \ + (void)(bConditionValue || (*(int *)0 = 0)); } + +*/ +/* +#define xVerifyHandlerEx(Condition) (false||(Condition) \ + || (xAssertionEx::GetVerifyCustomHandler() \ + && (xAssertionEx::GetVerifyCustomHandler()( \ + AFS_ASSERT, #Condition, __FILE__, __LINE__), true))) +*/ + + + + + + +/* +#define xVerifyHandlerEx(Condition) (false || (Condition)) \ + || (xAssertionEx::CVerifyChecks2() \ + && (xAssertionEx::CVerifyChecks2()( \ + AFS_ASSERT, #Condition, __FILE__, __LINE__), true))) +*/ + + + + + +//#define xVerifyAndCorrect(Condition,Message,Object,PostAction,Result) xAssert(XASSERT_HANDLER(Condition,Message,Object,PostAction,Result)) +//#define xVerify(Condition) xAssert(Condition) + +/*#define xVerifyAndCorrect(Condition,Message,Object,PostAction,Result)xAssert(Condition)*/ + + + + + + + + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/xBitSet.h b/ref/vt-ex/include/xBitSet.h new file mode 100644 index 0000000..0fb4c53 --- /dev/null +++ b/ref/vt-ex/include/xBitSet.h @@ -0,0 +1,102 @@ +#ifndef __X_BIT_SET_H__ +#define __X_BIT_SET_H__ + +#ifndef u32 + typedef unsigned int u32; +#endif + +class xBitSet +{ +private: + u32 mBits; + +public: + /// Default constructor initializes this bit set to all zeros. + xBitSet() { mBits = 0; } + + /// Copy constructor. + xBitSet(const xBitSet& in_rCopy) { mBits = in_rCopy.mBits; } + + /// Construct from an input u32. + xBitSet(const u32 in_mask) { mBits = in_mask; } + + /// @name Accessors + /// @{ + + /// Returns the u32 representation of the bit set. + operator u32() const { return mBits; } + + /// Returns the u32 representation of the bit set. + u32 getMask() const { return mBits; } + + /// @} + + /// @name Mutators + /// + /// Most of these methods take a word (ie, a BitSet32) of bits + /// to operate with. + /// @{ + + /// Sets all the bits in the bit set to 1 + void set() { mBits = 0xFFFFFFFFUL; } + + /// Sets all the bits in the bit set that are set in m. + void set(const u32 m) { mBits |= m; } + + /// For each bit set in s, sets or clears that bit in this, depending on whether b is true or false. + void set(xBitSet s, bool b) { mBits = (mBits&~(s.mBits))|(b?s.mBits:0); } + + /// Clears all the bits in the bit set to 0. + void clear() { mBits = 0; } + + /// Clears all the bits in the bit set that are set in m. + void clear(const u32 m) { mBits &= ~m; } + + /// Flips all the bits in the bit set that are set in m. + void toggle(const u32 m) { mBits ^= m; } + + /// Test if the passed bits are set. + bool test(const u32 m) const { return (mBits & m) != 0; } + + /// Test if the passed bits and only the passed bits are set. + bool testStrict(const u32 m) const { return (mBits & m) == m; } + + xBitSet& operator =(const u32 m) { mBits = m; return *this; } + xBitSet& operator|=(const u32 m) { mBits |= m; return *this; } + xBitSet& operator&=(const u32 m) { mBits &= m; return *this; } + xBitSet& operator^=(const u32 m) { mBits ^= m; return *this; } + + xBitSet operator|(const u32 m) const { return xBitSet(mBits | m); } + xBitSet operator&(const u32 m) const { return xBitSet(mBits & m); } + xBitSet operator^(const u32 m) const { return xBitSet(mBits ^ m); } + + /// @} +}; + +#ifndef xBit + #define xBit(f) (1 << f) +#endif + +__inline bool isFlagOn(xBitSet value,int flag) +{ + return value.test(1 << flag ); +} +__inline bool isFlagOff(xBitSet value,int flag) +{ + return value.test(1 << flag ) ? false : true; +} + +__inline void setFlag(xBitSet& value,int flag,bool condition) +{ + value.set(flag,condition); +} +__inline void enableFlag(xBitSet& value,int flag) +{ + value.set(1 << flag,true ); +} +__inline void disableFlag(xBitSet& value,int flag) +{ + value.set(1 << flag,false); +} + +#endif \ No newline at end of file diff --git a/ref/vt-ex/include/xDebugTools.h b/ref/vt-ex/include/xDebugTools.h new file mode 100644 index 0000000..964a8f5 --- /dev/null +++ b/ref/vt-ex/include/xDebugTools.h @@ -0,0 +1,328 @@ +#ifndef __X_DEBUG_TOOLS_H__ + #define __X_DEBUG_TOOLS_H__ + + #include "xPlatform.h" + #include "xAssertion.h" + #include "xLogger.h" +// #include + #include + + #define X_IS_BETWEEN(VALUE,MIN,MAX) (VALUE < MAX && VALUE > MIN) + + #define X_NEGATE(A) !(A) + #define _FLT_ASSIGMENT(A,B) ((A=B)==0) + + + //---------------------------------------------------------------- + // + // base types + // + + + + #define D_MSG_BUFFER_MAX 4096 + + + + #ifdef _DEBUG + + #define D_FILE_INFO 1 + #define D_FILE_LINE_INFO 0 + #else + + #define D_FILE_INFO 1 + #define D_FILE_LINE_INFO 0 + + #endif + + //---------------------------------------------------------------- + // + // constants + // + + + //---------------------------------------------------------------- + // hide filed details + #if D_FILE_INFO==1 + #if !defined(__FILE__) + extern const char *const __FILE__; + #endif + #else + #undef __FILE__ + #define __FILE__ "" + #endif + + + #if D_FILE_LINE_INFO==1 + #if !defined(__LINE__) + extern const unsigned int __LINE__; + #endif + #else + #undef __LINE__ + #define __LINE__ 0 + #endif + + //---------------------------------------------------------------- + // + // surround objects : + // + #if defined(referenceObject) + #define DC_OBJECT referenceObject + #else + #define DC_OBJECT NULL + #endif + + + + //---------------------------------------------------------------- + // + // Constants + // + #define ASSERT_STRING "Assertion" + + #define FATAL_STRING "Assertion" + + #define D_SO_NAME_EX(SourceObjectName) SourceObjectName ? SourceObjectName->GetName() : "none" + +#ifdef referenceObject + #define D_SO_NAME referenceObject ? referenceObject->GetName() : "none" +#else + #define D_SO_NAME "???" +#endif + + + + //---------------------------------------------------------------- + // + // code fragments + // + + + #define D_DO_POST(PostAction) PostAction; + + #define D_ASSERT_P_END(PostAction) xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,buffer);\ + D_DO_POST(PostAction); + + + + #define xSTR_MERGE(A,B) A##B + + + //---------------------------------------------------------------- + // + // Assertions code fragments + // + + #define WCASSERT_PREFIX(Assertion,bufferSize) if(!(Assertion)){char buffer[bufferSize]; + + + #define xASSERT_FORMAT_STRING(Assertion) "%s :\n\t Assertion \"" #Assertion "\" failed \n\t : %s : " + + //#define xASSERT_FORMAT_OPERATION(Assertion,postMsg,PostAction) _snprintf(buffer,D_MSG_BUFFER_MAX,xASSERT_FORMAT_STRING_PA(Assertion,PostAction),D_SO_NAME,xSTR_MERGE(postMsg,PostAction)); + + #define xASSERT_FORMAT_OPERATION_EX(Assertion,SourceObjectName,PostMessage,PostAction) _snprintf(buffer,D_MSG_BUFFER_MAX,xASSERT_FORMAT_STRING(Assertion),SourceObjectName, \ + xSTR_MERGE(PostMessage,xSTR_MERGE(" , excecuting : ",#PostAction))); + //---------------------------------------------------------------- + // + // constants + // + #if D_FILE_INFO==1 + + #define xASSERT_FORMAT_STRING(A) "%s :\n\t Assertion2 \"" #A "\" failed in \n\t : (%s:%d) :\n\t %s " // \"" #B "\" " + + #define xASSERT_FORMAT_OPERATION_EX(Assertion,SourceObjectName,PostMessage,PostAction) _snprintf(buffer,D_MSG_BUFFER_MAX,xASSERT_FORMAT_STRING(Assertion),SourceObjectName,__FILE__,__LINE__, \ + xSTR_MERGE(PostMessage,xSTR_MERGE(" , excecuting : ",#PostAction))); + #endif + + + #define WIDEN2(x) L ## x + #define WIDEN(x) WIDEN2(x) + #define __WFILE__ WIDEN(__FILE__) + #define AMACRO( object_name, var_name ) reinterpret_cast((&(((object_name*)0)->var_name))) + + + + + + #define xAssertWPO(Assertion) xVerify(Assertion) + + #define REFRESH_ASSERT_HANDLER(Type,Assertion,PostMessage,PostAction,Result) updateAssertHandlerData(Type,#Assertion,__FILE__,__LINE__,PostMessage,((void*)(PostAction)),Result); + + //---------------------------------------------------------------- + // + // macros to make an assert, error warning message, and providing a field to correct data + // + // prepare meta data : + + + #define CREATE_ASSERT_INFO_EX(Assertion,Type,FormatString,SourceObjectName,PostMessage,PostAction) WCASSERT_PREFIX(Assertion,D_MSG_BUFFER_MAX) \ + xASSERT_FORMAT_OPERATION_EX(Assertion,SourceObjectName,PostMessage,PostAction); + + #define xwASSERTEx(Assertion,SourceObjectName,PostMessage,PostAction,Result) CREATE_ASSERT_INFO_EX(Assertion,AFS_ASSERT,xASSERT_FORMAT_STRING(Assertion),SourceObjectName,PostMessage,PostAction,Result); + + //REFRESH_ASSERT_HANDLER(AFS_ASSERT,Assertion,buffer,PostAction,Result); + + #define __xwASSERT(Assertion,SourceObjectName,PostMessage,PostAction,Result) xwASSERTEx(Assertion,SourceObjectName,PostMessage,PostAction,Result) + + #define xAssertW(Assertion,PostAction,PostMessage,SourceObjectName,Result) \ + __xwASSERT(Assertion,SourceObjectName,PostMessage,PostAction,Result) \ + _xAssertHandler(Assertion); \ + D_ASSERT_P_END(PostAction) \ + Result = false; \ + } + +/* + #define xAssertW(Assertion,PostAction,PostMessage,SourceObjectName,Result) \ + __xwASSERT(Assertion,SourceObjectName,PostMessage,PostAction,Result) \ + xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"start assert");\ + (false || (Assertion) || (xAssertionEx::getErrorHandler() && (xAssertionEx::getErrorHandler()\ + ( AFS_ASSERT, #Assertion, __FILE__, __LINE__,"asdasd",NULL,TRUE), true)));\ + xAssertInfo *info = assertFailed();\ + if(info ){\ + xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"assert failed");\ + D_ASSERT_P_END(PostAction) \ + Result = false; } \ + }*/ + + + /* +_xAssertHandler(Assertion); \ + xAssertInfo *info = assertFailed();\ + if(info ){\ + xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,"assert failed");\ + D_ASSERT_P_END(PostAction) \ + Result = false; } \ + } +*/ + #define iAssertW(Assertion,PostAction,PostMessage)\ + { bool returnValue = false;\ + xAssertW(Assertion,PostAction,PostMessage,D_SO_NAME,returnValue)\ + } + + #define iAssertWR(Assertion,PostAction,Result){\ + xAssertW(Assertion,PostAction,"",D_SO_NAME,Result)\ + } + + + + #define iAssertW1(Assertion,PostAction)\ + { bool returnValue = false;\ + iAssertW(Assertion,PostAction,"")\ + } + + #define iAssertAndAbortMesg(Assertion,Msg)\ + { bool returnValue = false;\ + iAssertW(Assertion,NULL,Msg);\ + if(!returnValue)return;\ + } + #define iAssertAndAbort1(Assertion,POSTACTION)\ + { bool returnValue = false;\ + iAssertW(Assertion,POSTACTION,"");\ + if(!returnValue)return;\ + } + + #define xError(Message) xLogger::xLog(XL_START,ELOGERROR,E_LI_MANAGER,Message); + #define xWarning(Message) xLogger::xLog(XL_START,ELOGWARNING,E_LI_MANAGER,Message); + #define xTrace(Message) xLogger::xLog(XL_START,ELOGTRACE,E_LI_MANAGER,Message); + #define xInfo(Message) xLogger::xLog(XL_START,ELOGINFO,E_LI_MANAGER,Message); + + void _inline qdbg(const char *fmt,...) + { + char buffer[4096]; + unsigned int bufferStart = 0; + + va_list s; + va_start( s, fmt ); + _vsnprintf(buffer + bufferStart, sizeof(buffer) - bufferStart, fmt, s); + va_end(s); + xLogger::xLog(XL_START,ELOGINFO,E_LI_MANAGER,buffer); + } + + #define xTrace1(Message,Object) { char buffer[D_MSG_BUFFER_MAX];\ + _snprintf(buffer,Message,Object ? Object->GetName() : "");\ + xTrace(buffer)\ + } + + + +//#define iAssertWR(Assertion,PostAction,Result) xVerify(Assertion) +//#define iAssertW1(Assertion,PostAction) xVerify(Assertion) + + + //(xAssertionEx::getErrorHandler() && (xAssertionEx::getErrorHandler()( AFS_ASSERT, #Assertion, __FILE__, __LINE__,"","",FALSE), true))) +//xVerify(Assertion); + + + + //xVerify(Assertion) + + + + + //xASSERT_FORMAT_OPERATION(Condition,postMsg) \ + //D_ASSERT_P_END(postStep) } + + + + + + + + + //#define D_VERIFY_O(Condition,obj,postMsg) WASSERT_VERIFY_PREFIX(Condition,D_MSG_BUFFER_MAX) + //#define D_VERIFY_CORRECT_MOP(Condition) WASSERT_VERIFY_AND_CORRECT_PREFIX(Condition) + //xASSERT_FORMAT_OPERATION(Condition,postMsg); + + + //,postMsg,postStep,Result + //if(!(Condition)){char buffer[bufferSize]; + //char buffer[bufferSize]; + + + + //#define WASSERT_CHECK_PREFIX(Condition,bufferSize) xCheck(Condition); + + + //char buffer[bufferSize]; + //---------------------------------------------------------------- + // + // !assert(a) ? : print warning, do post step + // + // + + #define xWASSERT_O_P(Condition,obj,postMsg,postStep) WCASSERT_PREFIX(Condition,D_MSG_BUFFER_MAX)\ + xASSERT_FORMAT_OPERATION(Condition,postMsg) \ + D_ASSERT_P_END(postStep) } + + //---------------------------------------------------------------- + // + // !assert(condition)? print warning and leave + // + #define D_WASSERTION_O(Condition,obj,postMsg) WASSERT_CHECK_PREFIX(Condition,D_MSG_BUFFER_MAX) \ + xASSERT_FORMAT_OPERATION(Condition,postMsg); + + + + #define D_CHECK_O(Condition,obj,postMsg) WASSERT_CHECK_PREFIX(Condition,D_MSG_BUFFER_MAX) + + + //xASSERT_FORMAT_OPERATION(Condition,postMsg); + + +/*D_ASSERT_P_END(postStep) }*/ + + //---------------------------------------------------------------- + // + // !assert(condition)? print warning and leave + // +/* #define eAssertCheckMO(cond,obj,postMsg) WASSERT_CHECK_PREFIX(cond,D_MSG_BUFFER_MAX)\ + xASSERT_FORMAT_OPERATION(cond,postMsg) \ + D_ASSERT_P_END(postStep) } +*/ +#endif //D_FILE_INFO + +//#endif//file + + + + \ No newline at end of file diff --git a/ref/vt-ex/include/xLogger.h b/ref/vt-ex/include/xLogger.h new file mode 100644 index 0000000..69f11d6 --- /dev/null +++ b/ref/vt-ex/include/xLogger.h @@ -0,0 +1,227 @@ +/// +//////////////////////////////////////////////////////// +// xLogger.h +// Implementation of the Class xLogger +// Created on: 10-Feb-2007 12:40:39 +/////////////////////////////////////////////////////////// + +#if !defined __X_LOGGER_H__ +#define __X_LOGGER_H__ + +#include +//#include +#include +//#include +#include + +#include + +#include +#include +#include + + + + +#ifndef DEBUG_CALLER + #define DEBUG_CALLER +#endif + +#ifndef TNL_COMPILER_VISUALC + #define TNL_COMPILER_VISUALC +#endif + +#ifndef DEBUG_CALLERS_FUNC + #define DEBUG_CALLERS_FUNC +#endif + + + +#ifndef this + #define XL_PREFIX __FUNCTION__ +#else + #define XL_PREFIX typeid(this).name() +#endif + +#ifndef this + #define XL_OBJECT_PREFIX(T) "FN:"##T +#else + #define XL_OBJECT_PREFIX(T) "Call in Class:"##T +#endif + + +#define XL_START XL_OBJECT_PREFIX(XL_PREFIX) + + +#define XLOG_PREFIX0 + + +#ifdef VIRTOOLS_USER_SDK + class CKContext; +#endif + + +namespace xUtils +{ + + + typedef enum xLoggerFlags { + ELOGGER_NONE=0, + ELOGGER_CONSOLE=2, + ELOGGER_MCORE=4, + ELOGGER_CEGUI=8, + ELOGGER_OUT_OBJECTS=16 + }xLoggerFlags; + + enum ELOGTYPE + { + ELOGDEBUG, + ELOGTRACE, + ELOGERROR, + ELOGWARNING, + ELOGINFO, + ELOGALL, + }; + + typedef enum E_PRINT_STYLE_FLAGS + { + + E_PSF_PRINT_LOG_TYPE=1, + E_PSF_PRINT_COMPONENT, + E_PSF_PRINT_NEWLINE, + E_PSF_PRINT_TAB, + + }; + + static char* sLogTypes[]= + { + "DEBUG", + "TRACE", + "ERROR", + "WARNING", + "INFO", + }; + + /// xLogConsumer is the base class for the message logging system in TNL. + /// + /// TNL by default doesn't log messages anywhere, but users of the library + /// can instantiate subclasses that override the logString method. + /// Any instantiated subclass of xLogConsumer will receive all general + /// logprintf's, as well as any log messages that are enabled via + /// the TNLLogEnable macro. + class xLogConsumer + { + xLogConsumer *mNextConsumer; ///< Next xLogConsumer in the global linked list of log consumers. + xLogConsumer *mPrevConsumer; ///< Previous xLogConsumer in the global linked list of log consumers. + + static xLogConsumer *mLinkedList; ///< Head of the global linked list of log consumers. + + public: + /// Constructor adds this xLogConsumer to the global linked list. + xLogConsumer(); + + /// Destructor removes this xLogConsumer from the global linked list, and updates the log flags. + virtual ~xLogConsumer(); + + /// Returns the head of the linked list of all log consumers. + static xLogConsumer *getLinkedList() { return mLinkedList; } + + /// Returns the next xLogConsumer in the linked list. + xLogConsumer *getNext() { return mNextConsumer; } + + /// Writes a string to this instance of xLogConsumer. + /// + /// By default the string is sent to the Platform::outputDebugString function. Subclasses + /// might log to a file, a remote service, or even a message box. + virtual void logString(const char *string); + }; + + class MODULE_API xLogger + { + + public: + + + + + xLogger(); + virtual ~xLogger(); + void Init(); + + + + static xBitSet& getVerbosityFlags(); + void setVerbosityFlags(xBitSet val) { m_VerbosityFlags = val; } + + static xBitSet& getLogFlags(); + void setLogFlags(xBitSet val) { mLogFlags = val; } + static bool isLogging(int logItem); + static void enableLogItem(int logItem,bool enbabled=true); + + static void xLog(int verbosity,const char *header,const char*msg,...); + static void xLog(int type,int component,const char *header, ...); + static void xLog(xBitSet styleFlags,int type,int component,const char *header, ...); + static void xLog(char *cppText,int type,int component,const char *header, ...); + static void xLogExtro(int style,const char *header, ...); + + + static xLogger*GetInstance(); + + void DoProcessing(float eTime/* =0::0f */); + + + typedef std::mapxLogItems; + typedef std::vectoritemDescriptionArray; + + itemDescriptionArray mItemsDescriptions; + itemDescriptionArray& getItemDescriptions(){return xLogger::GetInstance()->mItemsDescriptions;} + + inline void addItemDescription(const char*descr){ mItemsDescriptions.push_back(descr); } + + const char*getItemDescription(); + + + xLogItems mLogItems; + xUtils::xLogger::xLogItems& getLogItems() { return mLogItems; } + void setLogItems(xUtils::xLogger::xLogItems val) { mLogItems = val; } + + void addLogItem(int item); + void setLoggingLevel(int item,xBitSet flags); + xBitSet getLogLevel(int item); + void enableLoggingLevel(int item,int level,int enable); + + void finalPrint(const char*string); + + #ifdef VIRTOOLS_USER_SDK + CKContext * getVirtoolsContext() const { return mContext; } + void setVirtoolsContext(CKContext * val) { mContext = val; } + #endif + + void enableConsoleOutput(bool enable); + + protected : + + #ifdef VIRTOOLS_USER_SDK + CKContext *mContext; + #endif + + xBitSet mLogFlags; + xBitSet m_VerbosityFlags; + int m_Verbosity; + int m_LogOutChannels; + + + public : + int lastTyp; + int lastComponent; + + + }; +} + + +using namespace xUtils; + + +#endif // !defined(EA_3DFA15A6_382B_4624_9E00_4531365CB9AF__INCLUDED_) + diff --git a/ref/vt-ex/include/xPlatform.h b/ref/vt-ex/include/xPlatform.h new file mode 100644 index 0000000..1c520f8 --- /dev/null +++ b/ref/vt-ex/include/xPlatform.h @@ -0,0 +1,220 @@ +#ifndef __X_PLATFORM__ + #define __X_PLATFORM__ + + enum E_ASSERTION_FAILURE_SEVERITY + { + AFS__MIN, + + AFS_ASSERT=AFS__MIN, + AFS_CHECK, + + AFS__MAX, + }; + + //---------------------------------------------------------------- + // + // host identifier + // + + #define xTARGET_OS_GENUNIX 1 + #define xTARGET_OS_WINDOWS 2 + #define xTARGET_OS_QNX 3 + #define xTARGET_OS_MAC 4 + + //---------------------------------------------------------------- + // + // base types + // + #if !defined(__LINE__) + extern const unsigned int __LINE__; + #endif + + + #if !defined(__FILE__) + extern const char *const __FILE__; + #endif + + + //---------------------------------------------------------------- + // + // Determine platform + // + + #if defined(_WINDOWS) || defined(_WIN32) + + #define xTARGET_OS xTARGET_OS_WINDOWS + + #elif defined(__QNX__) + + #define xTARGET_OS xTARGET_OS_QNX + + #elif defined(__APPLE__) + + #define xTARGET_OS xTARGET_OS_MAC + + #endif + + //---------------------------------------------------------------- + // + // determine call convention + // + #if xTARGET_OS == xTARGET_OS_WINDOWS + + #define xCONVENTION_METHOD + #define xCONVENTION_API __stdcall + #define xCONVENTION_CALLBACK __stdcall + + + #else // #if xTARGET_OS != xTARGET_OS_WINDOWS + + #define xCONVENTION_METHOD + #define xCONVENTION_API + #define xCONVENTION_CALLBACK + + #endif + + + //---------------------------------------------------------------- + // + // cpu bandwidth + // + #if !defined(xTARGET_BITS) + + #if defined(_LP64) || defined(_WIN64) + #define xTARGET_BITS xTARGET_BITS_64 + #else + #define xTARGET_BITS xTARGET_BITS_32 + #endif + + #else // #if defined(xTARGET_BITS) + + #if xTARGET_BITS <= 0 || xTARGET_BITS >= xTARGET_BITS__MAX + + #error Please define a valid value for xTARGET_BITS + + #endif + + #endif + + //---------------------------------------------------------------- + // + // determine compiler + // + + #define xCOMPILER__OTHER 1 + #define xCOMPILER_GCC 2 + #define xCOMPILER_MSVC 3 + + #define xCOMPILER__MAX 4 + + + #define xCOMPILER_VERSION__OTHER 1 + #define xCOMPILER_VERSION_MSVC1998 2 + #define xCOMPILER_VERSION_GCCLT4 3 + + #define xCOMPILER_VERSION__MAX 4 + + + ////////////////////////////////////////////////////////////////////////// + + #if !defined(xCOMPILER) + + #if defined(__GNUC__) + + #define xCOMPILER xCOMPILER_GCC + + #if __GNUC__ < 4 + + #define xCOMPILER_VERSION xCOMPILER_VERSION_GCCLT4 + + #endif + + + #elif defined(_MSC_VER) + + #define xCOMPILER xCOMPILER_MSVC + + #if _MSC_VER <= 1200 + + #define xCOMPILER_VERSION xCOMPILER_VERSION_MSVC1998 + + #endif + + #else + + #define xCOMPILER xCOMPILER__OTHER + + #endif + + + #else + + #if xCOMPILER <= 0 || xCOMPILER >= xCOMPILER__MAX + + #error Please define a valid value for xCOMPILER + + #endif + + #endif + + + #if !defined(xCOMPILER_VERSION) + + #define xCOMPILER_VERSION xCOMPILER_VERSION__OTHER + + #endif + + + + #if xCOMPILER_VERSION <= 0 || xCOMPILER_VERSION >= xCOMPILER_VERSION__MAX + + #error Please define a valid value for xCOMPILER_VERSION + + #endif + + + //---------------------------------------------------------------- + // + // inline , always inline + // + #if !defined(_xINLINES_DEFINED) + + #define _xINLINES_DEFINED + + + #if xCOMPILER == xCOMPILER_GCC + + #define xALWAYSINLINE_PRE__DEFINITION inline + #define xALWAYSINLINE_IN__DEFINITION __attribute__((always_inline)) + + #elif xCOMPILER == xCOMPILER_MSVC + + #define xALWAYSINLINE_PRE__DEFINITION __forceinline + #define xALWAYSINLINE_IN__DEFINITION + + #else + + #define xALWAYSINLINE_PRE__DEFINITION inline + #define xALWAYSINLINE_IN__DEFINITION + + #endif + + + + #if defined(_DEBUG) + + #define xALWAYSINLINE_PRE inline + #define xALWAYSINLINE_IN + #define xINLINE inline + + #else + + #define xALWAYSINLINE_PRE xALWAYSINLINE_PRE__DEFINITION + #define xALWAYSINLINE_IN xALWAYSINLINE_IN__DEFINITION + #define xINLINE inline + #endif + + #endif // #if !defined(_xINLINES_DEFINED) + + +#endif \ No newline at end of file diff --git a/ref/vt-ex/src/3D/DXDiagNVUtil.cpp b/ref/vt-ex/src/3D/DXDiagNVUtil.cpp new file mode 100644 index 0000000..ead79b7 --- /dev/null +++ b/ref/vt-ex/src/3D/DXDiagNVUtil.cpp @@ -0,0 +1,770 @@ +/*********************************************************************NVMH4**** +Path: SDK\LIBS\src\NV_D3DCommon +File: DXDiagNVUtil.cpp + +Copyright NVIDIA Corporation 2002 +TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED +*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS +BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES +WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, +BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) +ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS +BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + +Comments: +See the DXDiagNVUtil.h file for additional comments + +******************************************************************************/ + + +#define INITGUID // to define _CLSID_DxDiagProvider, _IID_IDxDiagProvider + +#include "3d\DxDiagNVUtil.h" +#include // for _filelength() +#include // for getcwd() +#include // for L text macro +#include +#include + +//#pragma comment( lib, "dxguid.lib" ) + +// use #if 1 to turn trace messages on +#if 0 + #define TRACE0(v) v +#else + #define TRACE0(v) {} +#endif + + + +// use as an alternative to wcstombs() +string DXDiagNVUtil::WStringToString( const wstring * in_pwstring ) +{ + if( in_pwstring == NULL ) + return( "" ); + + return( lpcwstrToString( in_pwstring->c_str() )); +} + +string DXDiagNVUtil::WStringToString( wstring & in_wstring ) +{ + return( lpcwstrToString( in_wstring.c_str() )); +} + + +string DXDiagNVUtil::lpcwstrToString( const LPCWSTR in_lpcwstr ) +{ + //@ consider using windows.h WideCharToMultiByte(..) + char * mbBuf; + size_t sz; + sz = 2 * wcslen( in_lpcwstr ); + mbBuf = new char[sz]; + wcstombs( mbBuf, in_lpcwstr, sz ); // convert the string + string outstr; + outstr = mbBuf; + SAFE_ARRAY_DELETE( mbBuf ); + return( outstr ); +} + + +HRESULT DXDiagNVUtil::GetChildByIndex( IDxDiagContainer * pParent, + DWORD dwIndex, + IDxDiagContainer ** ppChild ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( pParent ); + FAIL_IF_NULL( ppChild ); + + // We need to look up the child by name, not by index, so first + // get the name of the child at the appropriate index. + + // Get a single child container name, writing the name to wstr + WCHAR wstr[256]; + hr = pParent->EnumChildContainerNames( dwIndex, wstr, 256 ); + RET_VAL_IF_FAILED( hr ); + + // Now get the child container by name + hr = pParent->GetChildContainer( wstr, ppChild ); + return( hr ); +} + + +HRESULT DXDiagNVUtil::GetNumDisplayDevices( DWORD * out_pdwNumAdapters ) +{ + HRESULT hr = S_OK; + MSGVARNAME_AND_FAIL_IF_NULL( m_pDxDiagRoot ); + MSGVARNAME_AND_FAIL_IF_NULL( out_pdwNumAdapters ); + + IDxDiagContainer * pChild; + hr = GetChildContainer( L"DxDiag_DisplayDevices", & pChild ); + MSG_AND_RET_VAL_IF( FAILED(hr), "GetNumDisplayDevices() Couldn't get display devices container!\n", hr ); + + hr = pChild->GetNumberOfChildContainers( out_pdwNumAdapters ); + MSG_AND_BREAK_IF( FAILED(hr), "GetNumDisplayDevices() Couldn't get number of child containers!\n" ); + + SAFE_RELEASE( pChild ); + return( hr ); +} + + +HRESULT DXDiagNVUtil::GetDisplayDeviceNode( DWORD dwDeviceIndex, IDxDiagContainer ** ppNode ) +{ + // fill *ppNode with pointer to the display device at index nDevice of the DXDiag_DisplayDevices container + // you must SAFE_RELEASE( *ppNode ) outside of this function. + HRESULT hr = S_OK; + FAIL_IF_NULL( ppNode ); + + IDxDiagContainer * pDevicesNode; + hr = GetChildContainer( L"DxDiag_DisplayDevices", & pDevicesNode ); + MSG_AND_RET_VAL_IF( FAILED(hr), "GetDisplayDeviceNode() couldn't get devices node!\n", hr ); + + // Get the device at the appropriate index + hr = GetChildByIndex( pDevicesNode, dwDeviceIndex, ppNode ); + + SAFE_RELEASE( pDevicesNode ); + return( hr ); +} + + + +HRESULT DXDiagNVUtil::GetDisplayDeviceDescription( DWORD dwDevice, wstring * pwstrName ) +{ + HRESULT hr = S_OK; + MSGVARNAME_AND_FAIL_IF_NULL( m_pDxDiagRoot ); + MSGVARNAME_AND_FAIL_IF_NULL( pwstrName ); + + IDxDiagContainer * pDisplayDevice; + hr = GetDisplayDeviceNode( dwDevice, &pDisplayDevice ); + RET_VAL_IF_FAILED( hr ); + FAIL_IF_NULL( pDisplayDevice ); + + // Get the device's name: + hr = GetProperty( pDisplayDevice, L"szDescription", pwstrName ); + MSG_IF( FAILED(hr), "GetDisplayDeviceName() Couldn't get device's name property!\n"); + + SAFE_RELEASE( pDisplayDevice ); + return( hr ); +} + +HRESULT DXDiagNVUtil::GetDisplayDeviceNVDriverVersion( DWORD dwDevice, float * fVersion ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( fVersion ); + *fVersion = 0.0f; + wstring wstr; + + hr = GetDisplayDeviceDriverVersionStr( dwDevice, & wstr ); + MSG_IF( FAILED(hr), "GetDisplayDeviceNVDriverVersion() couldn't get driver version string\n"); + RET_VAL_IF_FAILED(hr); + + // nv driver string will be something like: "6.14.0010.5216" + // where the #s we care about are the last digits + size_t pos; + pos = wstr.find_last_of( '.' ); + wstr.erase( 0, pos ); + //FMsgW(L"wstr: %s\n", wstr.c_str() ); + + // decode the string + // multiply by 100 to convert .5216 into 52.16 + *fVersion = (float) _wtof( wstr.c_str() ) * 100.0f; + return( hr ); +} + +HRESULT DXDiagNVUtil::GetDisplayDeviceDriverVersionStr( DWORD dwDevice, wstring * pwstrVers ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( pwstrVers ); + + hr = GetDisplayDeviceProp( dwDevice, L"szDriverVersion", pwstrVers ); + MSG_IF( FAILED(hr), "GetDisplayDeviceName() Couldn't get device's driver version string!\n"); + + return( hr ); +} + + +HRESULT DXDiagNVUtil::GetDisplayDeviceMemoryInMB( DWORD dwDevice, int * pDisplayMemory ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( pDisplayMemory ); + *pDisplayMemory = 0; + wstring wstr; + hr = GetDisplayDeviceProp( dwDevice, L"szDisplayMemoryEnglish", &wstr ); + MSG_IF( FAILED(hr), "GetDisplayDeviceMemoryInMB() Couldn't get the property string!\n"); + + // decode the value to an int + // assume 1st string is the integer number + int nMem; + int num_fields; + num_fields = swscanf( wstr.c_str(), L"%d", &nMem ); + if( num_fields != 1 ) + { + FMsg("GetDisplayDeviceMemoryInMB error scanning memory string description!\n"); + return( E_FAIL ); + } + + *pDisplayMemory = nMem; + return( hr ); +} + +HRESULT DXDiagNVUtil::GetDisplayDeviceProp( DWORD dwDevice, LPCWSTR prop_name, wstring * pwstrProp ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( prop_name ); + FAIL_IF_NULL( pwstrProp ); + *pwstrProp = L""; + + IDxDiagContainer * pDisplayDevice; + hr = GetDisplayDeviceNode( dwDevice, &pDisplayDevice ); + RET_VAL_IF_FAILED( hr ); + FAIL_IF_NULL( pDisplayDevice ); + + hr = GetProperty( pDisplayDevice, prop_name, pwstrProp ); + MSG_IF( FAILED(hr), "GetDisplayDeviceProp() Couldn't get the property string!\n"); + + return( hr ); +} + +HRESULT DXDiagNVUtil::GetPhysicalMemoryInMB( float * out_pfMemory ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( out_pfMemory ); + wstring property; + hr = GetProperty( L"DxDiag_SystemInfo", L"ullPhysicalMemory", &property ); + + float mem = (float) _wtof( property.c_str() ); + // convert bytes to MB + mem = mem / (1024 * 1024); + *out_pfMemory = mem; + return( hr ); +} + +HRESULT DXDiagNVUtil::GetDisplayDeviceAGPMemoryStatus( DWORD dwDeviceIndex, wstring * pwstrAGPEnabled, + wstring * pwstrAGPExists, wstring * pwstrAGPStatus ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( m_pDxDiagRoot ); + FAIL_IF_NULL( pwstrAGPEnabled ); + FAIL_IF_NULL( pwstrAGPExists ); + FAIL_IF_NULL( pwstrAGPStatus ); + *pwstrAGPEnabled = L""; + *pwstrAGPExists = L""; + *pwstrAGPStatus = L""; + hr = GetDisplayDeviceProp( dwDeviceIndex, L"bAGPEnabled", pwstrAGPEnabled ); + hr = GetDisplayDeviceProp( dwDeviceIndex, L"szAGPStatusEnglish", pwstrAGPStatus ); + + wstring property; + hr = GetDisplayDeviceProp( dwDeviceIndex, L"bAGPExistenceValid", &property ); + if( SUCCEEDED(hr) && property == L"true" ) + { + hr = GetDisplayDeviceProp( dwDeviceIndex, L"bAGPExists", pwstrAGPExists ); + } + return( hr ); +} + + +HRESULT DXDiagNVUtil::GetDebugLevels( wstring * pwstrLevels ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( pwstrLevels ); + *pwstrLevels = L""; + wstring propval; + + hr = GetProperty( L"DxDiag_SystemInfo", L"nD3DDebugLevel", &propval ); + pwstrLevels->append( L"D3DDebugLevel = "); pwstrLevels->append( propval ); pwstrLevels->append(L"\n"); + + hr = GetProperty( L"DxDiag_SystemInfo", L"nDDrawDebugLevel", &propval ); + pwstrLevels->append( L"DDrawDebugLevel = "); pwstrLevels->append( propval ); pwstrLevels->append(L"\n"); + + hr = GetProperty( L"DxDiag_SystemInfo", L"nDIDebugLevel", &propval ); + pwstrLevels->append( L"DIDebugLevel = "); pwstrLevels->append( propval ); pwstrLevels->append(L"\n"); + + hr = GetProperty( L"DxDiag_SystemInfo", L"nDMusicDebugLevel", &propval ); + pwstrLevels->append( L"DMusicDebugLevel = "); pwstrLevels->append( propval ); pwstrLevels->append(L"\n"); + + hr = GetProperty( L"DxDiag_SystemInfo", L"nDPlayDebugLevel", &propval ); + pwstrLevels->append( L"DPlayDebugLevel = "); pwstrLevels->append( propval ); pwstrLevels->append(L"\n"); + + hr = GetProperty( L"DxDiag_SystemInfo", L"nDSoundDebugLevel", &propval ); + pwstrLevels->append( L"DSoundDebugLevel = "); pwstrLevels->append( propval ); pwstrLevels->append(L"\n"); + + hr = GetProperty( L"DxDiag_SystemInfo", L"nDShowDebugLevel", &propval ); + pwstrLevels->append( L"DShowDebugLevel = "); pwstrLevels->append( propval ); pwstrLevels->append(L"\n"); + + return( hr ); +} + +HRESULT DXDiagNVUtil::GetDirectXVersion( DWORD * pdwDirectXVersionMajor, + DWORD * pdwDirectXVersionMinor, + TCHAR * pcDirectXVersionLetter ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( m_pDxDiagRoot ); + FAIL_IF_NULL( pdwDirectXVersionMajor ); + FAIL_IF_NULL( pdwDirectXVersionMinor ); + FAIL_IF_NULL( pcDirectXVersionLetter ); + + wstring propval; + GetProperty( L"DxDiag_SystemInfo", L"dwDirectXVersionMajor", &propval ); + *pdwDirectXVersionMajor = _wtoi( propval.c_str() ); + + GetProperty( L"DxDiag_SystemInfo", L"dwDirectXVersionMinor", &propval ); + *pdwDirectXVersionMinor = _wtoi( propval.c_str() ); + + GetProperty( L"DxDiag_SystemInfo", L"szDirectXVersionLetter", &propval ); + string str; + + str = WStringToString( &propval ); + if( str.length() > 0 ) + *pcDirectXVersionLetter = str.at(0); + else + *pcDirectXVersionLetter = ' '; + + return( hr ); +} + + + +//------------------------------------------------------------------------ +// Get the property at pContainer by name +// Decode the VARIANT property to a string and return the string +HRESULT DXDiagNVUtil::GetProperty( IDxDiagContainer * pContainer, LPCWSTR property_name, wstring * out_value ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( pContainer ); + FAIL_IF_NULL( property_name ); + FAIL_IF_NULL( out_value ); + + WCHAR wszPropValue[256]; + VARIANT var; + VariantInit( &var ); + + hr = pContainer->GetProp( property_name, &var ); + if( SUCCEEDED(hr) ) + { + // Switch according to the type. There's 4 different types: + switch( var.vt ) + { + case VT_UI4: + swprintf( wszPropValue, L"%d", var.ulVal ); + break; + case VT_I4: + swprintf( wszPropValue, L"%d", var.lVal ); + break; + case VT_BOOL: + swprintf( wszPropValue, L"%s", (var.boolVal) ? L"true" : L"false" ); + break; + case VT_BSTR: + wcsncpy( wszPropValue, var.bstrVal, 255 ); + wszPropValue[255] = 0; + break; + } + // copy string to the output string + (*out_value) = wszPropValue; + } + else + { + FMsgW(L"GetProperty( cont, prop, val ) Couldn't get prop [%s]\n", property_name ); + //char mbBuf[512]; + //wcstombs( mbBuf, property_name, 512 ); + //FMsg("GetProperty( cont, prop, val ) Couldn't get prop [%s]\n", mbBuf ); + } + + VariantClear( &var ); + return( hr ); +} + + +HRESULT DXDiagNVUtil::GetProperty( LPCWSTR container_name0, + LPCWSTR property_name, + wstring * out_value ) +{ + HRESULT hr = S_OK; + + IDxDiagContainer * pContainer; + hr = GetChildContainer( container_name0, &pContainer ); + TRACE0( MSG_IF( FAILED(hr), "GetProperty(cn,pn,&v) GetChildContainer(<1>) failed!\n" )); + RET_VAL_IF_FAILED( hr ); + FAIL_IF_NULL( pContainer ); + + hr = GetProperty( pContainer, property_name, out_value ); + TRACE0( MSG_IF( FAILED(hr), "GetProperty(<1>) pContainer->GetProperty(c,n,v) failed!\n")); + + SAFE_RELEASE( pContainer ); + return( hr ); +} + +HRESULT DXDiagNVUtil::GetProperty( LPCWSTR container_name0, + LPCWSTR container_name1, + LPCWSTR property_name, + wstring * out_value ) +{ + HRESULT hr = S_OK; + + IDxDiagContainer * pContainer; + hr = GetChildContainer( container_name0, container_name1, &pContainer ); + MSG_AND_RET_VAL_IF( FAILED(hr), "GetProperty(cn,cn,pn,&v) couldn't get child container!\n", hr ); + + hr = GetProperty( pContainer, property_name, out_value ); + MSG_AND_RET_VAL_IF( FAILED(hr), "GetProperty(cn,cn,pn,&v) couldn't get container property!\n", hr ); + + SAFE_RELEASE( pContainer ); + return( hr ); +} + +HRESULT DXDiagNVUtil::GetProperty( LPCWSTR container_name0, + LPCWSTR container_name1, + LPCWSTR container_name2, + LPCWSTR property_name, + wstring * out_value ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( out_value ); + IDxDiagContainer * pContainer; + hr = GetChildContainer( container_name0, container_name1, container_name2, &pContainer ); + MSG_AND_RET_VAL_IF( FAILED(hr), "GetProperty(cn,cn,cn,pn,&v) couldn't get child container!\n", hr ); + + hr = GetProperty( pContainer, property_name, out_value ); + MSG_AND_RET_VAL_IF( FAILED(hr), "GetProperty(cn,cn,cn,pn,&v) couldn't get container property!\n", hr ); + + SAFE_RELEASE( pContainer ); + return( hr ); +} + + + +//------------------------------ + +HRESULT DXDiagNVUtil::GetChildContainer( LPCWSTR name0, IDxDiagContainer ** ppChild ) +{ + // you must release *ppChild on your own when you're done with it + HRESULT hr = S_OK; + MSGVARNAME_AND_FAIL_IF_NULL( m_pDxDiagRoot ); + MSGVARNAME_AND_FAIL_IF_NULL( ppChild ); + + hr = m_pDxDiagRoot->GetChildContainer( name0, ppChild ); + TRACE0( MSG_IF( FAILED(hr), "GetChildContainer(<1>) m_pDxDiagRoot->GetChildContainer() failed\n" )); + RET_VAL_IF_FAILED( hr ); + FAIL_IF_NULL( *ppChild ); + + return( hr ); +} + +HRESULT DXDiagNVUtil::GetChildContainer( LPCWSTR name0, + LPCWSTR name1, + IDxDiagContainer ** ppChild ) +{ + // intermediate children are released before returning + // you only have to release() *ppChild + HRESULT hr = S_OK; + + IDxDiagContainer * pChild; + hr = GetChildContainer( name0, &pChild ); + TRACE0( MSG_IF( FAILED(hr), "GetChildContainer(<2>) GetChildContainer(<1>) failed\n" ) ); + RET_VAL_IF_FAILED( hr ); + FAIL_IF_NULL( pChild ); + + hr = pChild->GetChildContainer( name1, ppChild ); + TRACE0( MSG_IF( FAILED(hr), "GetChildContainer(<2>) IDxDiagContainer->GetChildContainer() failed\n" ) ); + + SAFE_RELEASE( pChild ); // release the intermediate + return( hr ); +} + +HRESULT DXDiagNVUtil::GetChildContainer( LPCWSTR name0, + LPCWSTR name1, + LPCWSTR name2, + IDxDiagContainer ** ppChild ) +{ + // intermediate children are released before returning + // you only have to release() *ppChild + HRESULT hr = S_OK; + + IDxDiagContainer * pChild; + hr = GetChildContainer( name0, name1, &pChild ); + TRACE0( MSG_IF( FAILED(hr), "GetChildContainer(<3>) GetChildContainer(<2>) failed\n" ) ); + RET_VAL_IF_FAILED( hr ); + FAIL_IF_NULL( pChild ); + + hr = pChild->GetChildContainer( name2, ppChild ); + TRACE0( MSG_IF( FAILED(hr), "GetChildContainer(<3>) IDxDiagContainer->GetChildContainer() failed\n" ) ); + + SAFE_RELEASE( pChild ); // release the intermediate + return( hr ); +} + + +// public interface to display all node and subnode names +HRESULT DXDiagNVUtil::ListAllDXDiagPropertyNames() +{ + HRESULT hr = S_OK; + hr = ListAllDXDiagPropertyNames( m_pDxDiagRoot ); + return( hr ); +} + + +HRESULT DXDiagNVUtil::ListAllDXDiagPropertyNames( IDxDiagContainer * pDxDiagContainer, + WCHAR* wszParentName ) +{ + // Recurse through all properties and child properties, + // outputting their names via OutputDebugString(..) + // Start this by calling with the root IDxDiagContainer and a NULL string ptr. + // + // This function can take a while to complete. + // + // Adapted from DXSDK example file DxDiagOutput.cpp + + HRESULT hr = S_OK; + FAIL_IF_NULL( pDxDiagContainer ); + + DWORD dwPropCount; + DWORD dwPropIndex; + WCHAR wszPropName[256]; + DWORD dwChildCount; + DWORD dwChildIndex; + WCHAR wszChildName[256]; + IDxDiagContainer* pChildContainer = NULL; + + const bool bGetPropertyValue = false; + + hr = pDxDiagContainer->GetNumberOfProps( &dwPropCount ); + if( SUCCEEDED(hr) ) + { + // Print each property in this container + for( dwPropIndex = 0; dwPropIndex < dwPropCount; dwPropIndex++ ) + { + hr = pDxDiagContainer->EnumPropNames( dwPropIndex, wszPropName, 256 ); + + if( SUCCEEDED( hr ) ) + { + if( bGetPropertyValue ) + { + wstring propval; + hr = GetProperty( pDxDiagContainer, wszPropName, & propval ); + FMsgW(L"%35s : prop \"%s\" = %s\n", wszParentName, wszPropName, propval.c_str() ); + } + else + { + // otherwise, just list the property name and parent container info + FMsgW(L"%35s : prop \"%s\"\n", wszParentName, wszPropName ); + } + } + } + } + + // Recursivly call this function for each of its child containers + hr = pDxDiagContainer->GetNumberOfChildContainers( &dwChildCount ); + if( SUCCEEDED(hr) ) + { + for( dwChildIndex = 0; dwChildIndex < dwChildCount; dwChildIndex++ ) + { + hr = pDxDiagContainer->EnumChildContainerNames( dwChildIndex, wszChildName, 256 ); + if( SUCCEEDED(hr) ) + { + hr = pDxDiagContainer->GetChildContainer( wszChildName, &pChildContainer ); + if( SUCCEEDED(hr) ) + { + // wszFullChildName isn't needed but is used for text output + WCHAR wszFullChildName[256]; + + // Append child name to parent and pass down in the recursion + // as full parent name. + if( wszParentName ) + swprintf( wszFullChildName, L"%s.%s", wszParentName, wszChildName ); + else + swprintf( wszFullChildName, L"%s", wszChildName ); + + // recurse + ListAllDXDiagPropertyNames( pChildContainer, wszFullChildName ); + SAFE_RELEASE( pChildContainer ); + } + } + } + } + return( hr ); +} + +// Recurse through all properties and child properties, outputting their names +// to the file. +// This function is slow and takes a while to output all the nodes, so it can be +// called with a sub-node initial argument if you only care about a small part of the +// COM data structure tree. +// Adapted from DXSDK example file DxDiagOutput.cpp +// pOpenTextFile Must be a file opened for writing text +// Call this with NULL 2nd and 3rd args to start from the top of the node structure. +HRESULT DXDiagNVUtil::ListAllDXDiagPropertyNamesToTxtFile( FILE * pOpenTextFile, + bool bGetPropertyValues, + IDxDiagContainer * pDxDiagContainer, + WCHAR * wszParentName ) +{ + HRESULT hr = S_OK; + FAIL_IF_NULL( pOpenTextFile ); + if( pDxDiagContainer == NULL ) + pDxDiagContainer = m_pDxDiagRoot; + FAIL_IF_NULL( pDxDiagContainer ); + + DWORD dwPropCount; + DWORD dwPropIndex; + WCHAR wszPropName[256]; + DWORD dwChildCount; + DWORD dwChildIndex; + WCHAR wszChildName[256]; + IDxDiagContainer* pChildContainer = NULL; + string strParentName, strPropName, strPropVal; + wstring wstrParentName, wstrPropName; + + hr = pDxDiagContainer->GetNumberOfProps( &dwPropCount ); + if( SUCCEEDED(hr) ) + { + if( wszParentName != NULL ) + wstrParentName = wszParentName; + else + wstrParentName = L""; + strParentName = WStringToString( wstrParentName ); + + // Print each property in this container + for( dwPropIndex = 0; dwPropIndex < dwPropCount; dwPropIndex++ ) + { + hr = pDxDiagContainer->EnumPropNames( dwPropIndex, wszPropName, 256 ); + if( wszPropName != NULL ) + wstrPropName = wszPropName; + else + wstrPropName = L""; + strPropName = WStringToString( wstrPropName ); + + if( SUCCEEDED( hr ) ) + { + if( bGetPropertyValues ) + { + wstring wstrPropVal; + hr = GetProperty( pDxDiagContainer, wszPropName, & wstrPropVal ); + strPropVal = WStringToString( wstrPropVal ); + + fprintf( pOpenTextFile, "%35s : prop \"%s\" = %s\n", strParentName.c_str(), strPropName.c_str(), strPropVal.c_str() ); + } + else + { + // otherwise, just list the property name and parent container info + fprintf( pOpenTextFile, "%35s : prop \"%s\"\n", strParentName.c_str(), strPropName.c_str() ); + } + } + } + } + + // Recursivly call this function for each of its child containers + hr = pDxDiagContainer->GetNumberOfChildContainers( &dwChildCount ); + if( SUCCEEDED(hr) ) + { + for( dwChildIndex = 0; dwChildIndex < dwChildCount; dwChildIndex++ ) + { + hr = pDxDiagContainer->EnumChildContainerNames( dwChildIndex, wszChildName, 256 ); + if( SUCCEEDED(hr) ) + { + hr = pDxDiagContainer->GetChildContainer( wszChildName, &pChildContainer ); + if( SUCCEEDED(hr) ) + { + // wszFullChildName isn't needed but is used for text output + WCHAR wszFullChildName[256]; + + // Append child name to parent and pass down in the recursion + // as full parent name. + if( wszParentName ) + swprintf( wszFullChildName, L"%s.%s", wszParentName, wszChildName ); + else + swprintf( wszFullChildName, L"%s", wszChildName ); + + // recurse + ListAllDXDiagPropertyNamesToTxtFile( pOpenTextFile, bGetPropertyValues, + pChildContainer, wszFullChildName ); + SAFE_RELEASE( pChildContainer ); + } + } + } + } + return( hr ); +} + + +HRESULT DXDiagNVUtil::InitIDxDiagContainer() +{ + // Call FreeIDxDiagContainer() to clean up things done here + HRESULT hr; + + if( m_pDxDiagRoot != NULL ) + { + FMsg("DXDiagNVUtil::InitIDxDiagContainer already initialized!\n"); + return( S_OK ); + } + + // Init COM. COM may fail if its already been inited with a different + // concurrency model. And if it fails you shouldn't release it. + hr = CoInitialize(NULL); + m_bCleanupCOM = SUCCEEDED(hr); + + // Get an IDxDiagProvider + hr = CoCreateInstance( CLSID_DxDiagProvider, + NULL, + CLSCTX_INPROC_SERVER, + IID_IDxDiagProvider, + (LPVOID*) &m_pDxDiagProvider ); + if( SUCCEEDED(hr) ) + { + // Fill out a DXDIAG_INIT_PARAMS struct + DXDIAG_INIT_PARAMS dxDiagInitParam; + ZeroMemory( &dxDiagInitParam, sizeof(DXDIAG_INIT_PARAMS) ); + dxDiagInitParam.dwSize = sizeof(DXDIAG_INIT_PARAMS); + dxDiagInitParam.dwDxDiagHeaderVersion = DXDIAG_DX9_SDK_VERSION; + dxDiagInitParam.bAllowWHQLChecks = false; + dxDiagInitParam.pReserved = NULL; + + // Init the m_m_pDxDiagProvider + hr = m_pDxDiagProvider->Initialize( &dxDiagInitParam ); + if( SUCCEEDED(hr) ) + { + // Get the DxDiag root container + hr = m_pDxDiagProvider->GetRootContainer( & m_pDxDiagRoot ); + if( FAILED(hr) ) + { + FMsg("Couldn't GetRootContainer from DxDiagProvider!\n"); + assert( false ); + FreeIDxDiagContainer(); + return( hr ); + } + } + else + { + FMsg("Couldn't Initialize DxDiagProvider!\n"); + assert( false ); + FreeIDxDiagContainer(); + return( hr ); + } + } + else + { + FMsg("Couldn't initialize COM!\n"); + assert( false ); + FreeIDxDiagContainer(); + return( hr ); + } + + return( hr ); +} + + +HRESULT DXDiagNVUtil::FreeIDxDiagContainer() +{ + HRESULT hr = S_OK; + SAFE_RELEASE( m_pDxDiagProvider ); + SAFE_RELEASE( m_pDxDiagRoot ); + + if( m_bCleanupCOM ) + { + CoUninitialize(); + m_bCleanupCOM = false; + } + + return( hr ); +} + + diff --git a/ref/vt-ex/src/3D/GetGPUAndSystemInfo.cpp b/ref/vt-ex/src/3D/GetGPUAndSystemInfo.cpp new file mode 100644 index 0000000..a9b5479 --- /dev/null +++ b/ref/vt-ex/src/3D/GetGPUAndSystemInfo.cpp @@ -0,0 +1,287 @@ +/*--------------------------------------------------------------------- NVMH5 -|---------------------- +Path: Sdk\Demos\Direct3D9\src\GetGPUAndSystemInfo\ +File: GetGPUAndSystemInfo.cpp + +Copyright NVIDIA Corporation 2003 +TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS* AND NVIDIA AND +AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA +OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER +INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF +BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS +SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + +Comments: +See GetGPUAndSystemInfo.h for additional comments. + + +-------------------------------------------------------------------------------|--------------------*/ + + +#include +#include + +#include "GetGPUAndSystemInfo.h" + +#include "shared\NV_Common.h" +#include "shared\NV_Error.h" + + +/*------------------------------------------------------------------ +Retrieve various data through the IDxDiagContainer interface. + +The DXDiagNVUtil class provides a few convenient wrapper functions, +and direct querries using the IDxDiagContainer COM object names are +also supported. For a list of all the container and property COM +object names, call ListAllDXDiagPropertyNames(..) +------------------------------------------------------------------*/ +HRESULT GetGPUAndSystemInfo::GetData() +{ + HRESULT hr = S_OK; + //---------------------------------------------------------------------------- + hr = m_DXDiagNVUtil.InitIDxDiagContainer(); + MSG_AND_RET_VAL_IF( FAILED(hr), "Couldn't initialize DXDiagNVUtil!\n", hr ); + wstring wstr; + // Get the computer's machine name: + m_DXDiagNVUtil.GetProperty( L"DxDiag_SystemInfo", L"szMachineNameEnglish", &wstr ); + m_strMachineName = m_DXDiagNVUtil.WStringToString( &wstr ); + + FMsg("\n\n"); + FMsg("------------------------------------------------------------------------\n"); + FMsgW(L"machine name: %s\n", wstr.c_str() ); + + // Get info about physcial memory: + m_DXDiagNVUtil.GetPhysicalMemoryInMB( & m_fSystemPhysicalMemoryMB ); + FMsg("physical memory: %g MB\n", m_fSystemPhysicalMemoryMB ); + + // Get info about logical disks + IDxDiagContainer * pContainer, *pChild; + DWORD dwNumDisks; + hr = m_DXDiagNVUtil.GetChildContainer( L"DxDiag_LogicalDisks", & pContainer ); + if( SUCCEEDED(hr)) + { + pContainer->GetNumberOfChildContainers( & dwNumDisks ); + + wstring drive, space; + FMsgW(L"logical disks: %d\n", dwNumDisks ); + for( DWORD n=0; n < dwNumDisks; n++ ) + { + hr = m_DXDiagNVUtil.GetChildByIndex( pContainer, n, &pChild ); + if( SUCCEEDED(hr) ) + { + m_DXDiagNVUtil.GetProperty( pChild, L"szDriveLetter", &drive ); + m_DXDiagNVUtil.GetProperty( pChild, L"szFreeSpace", &space ); + FMsgW(L" %s Free space = %s\n", drive.c_str(), space.c_str() ); + SAFE_RELEASE( pChild ); + } + } + SAFE_RELEASE( pContainer ); + } + + FMsg("------------------------------------------------------------------------\n"); + + m_DXDiagNVUtil.GetDirectXVersion( &m_dwDXVersionMajor, &m_dwDXVersionMinor, &m_cDXVersionLetter ); + FMsg("DirectX Version: %d.%d%c\n", m_dwDXVersionMajor, m_dwDXVersionMinor, m_cDXVersionLetter ); + + hr = m_DXDiagNVUtil.GetNumDisplayDevices( & m_dwNumDisplayDevices ); + MSG_AND_RET_VAL_IF( FAILED(hr), "Couldn't GetNumDisplayDevices()\n", hr ); + FMsg("Num Display Devices: %d\n", m_dwNumDisplayDevices ); + + string str; + +// for( DWORD dev=0; dev < m_dwNumDisplayDevices; dev ++ ) + if( m_dwNumDisplayDevices > 0 ) + { + DWORD dev = 0; + + // get info from display devices + m_DXDiagNVUtil.GetDisplayDeviceDescription( dev, & m_wstrDeviceDesc ); + m_DXDiagNVUtil.GetDisplayDeviceNVDriverVersion( dev, & m_fDriverVersion ); + m_DXDiagNVUtil.GetDisplayDeviceMemoryInMB( dev, & m_nDeviceMemoryMB ); + + // report the info via OutputDebugString + FMsgW(L"Device %d Description: %s\n", dev, m_wstrDeviceDesc.c_str() ); + FMsg( "Device %d Driver version: %g\n", dev, m_fDriverVersion ); + FMsg( "Device %d Physical mem: %d MB\n", dev, m_nDeviceMemoryMB ); + + // Get info about AGP memory: + wstring wstrAGPEnabled, wstrAGPExists, wstrAGPStatus; + hr = m_DXDiagNVUtil.GetDisplayDeviceAGPMemoryStatus( dev, &wstrAGPEnabled, &wstrAGPExists, &wstrAGPStatus ); + if( SUCCEEDED(hr)) + { + // create a string from the AGP status strings + m_strAGPStatus = ""; + str = m_DXDiagNVUtil.WStringToString( &wstrAGPEnabled ); + m_strAGPStatus += "AGP Enabled = "; m_strAGPStatus += str; m_strAGPStatus += ", "; + str = m_DXDiagNVUtil.WStringToString( &wstrAGPExists ); + m_strAGPStatus += "AGP Exists = "; m_strAGPStatus += str; m_strAGPStatus += ", "; + str = m_DXDiagNVUtil.WStringToString( &wstrAGPStatus ); + m_strAGPStatus += "AGP Status = "; m_strAGPStatus += str; + } + FMsg("%s\n", m_strAGPStatus.c_str() ); + + wstring wstrNotes, wstrTestD3D9; + m_DXDiagNVUtil.GetProperty( L"DxDiag_DisplayDevices", L"0", L"szTestResultD3D9English", &wstrTestD3D9 ); + m_DXDiagNVUtil.GetProperty( L"DxDiag_DisplayDevices", L"0", L"szNotesEnglish", &wstrNotes ); + + str = m_DXDiagNVUtil.WStringToString( &wstrTestD3D9 ); + FMsg("Device 0 szTestResultD3D9English = \"%s\"\n", str.c_str() ); + str = m_DXDiagNVUtil.WStringToString( &wstrNotes ); + FMsg("Device 0 szNotesEnglish = \"%s\"\n", str.c_str() ); + } + + m_DXDiagNVUtil.GetDebugLevels( & m_wstrDxDebugLevels ); + FMsg("DirectX Debug Levels:\n"); + FMsgW(L"%s\n", m_wstrDxDebugLevels.c_str() ); + + + // ListAllDXDiagPropertyNames() is slow + // It prints out all nodes, child nodes, properties and their values +// m_DXDiagNVUtil.ListAllDXDiagPropertyNames(); + + // Use a call like that below to print out a specific node and it's children. + // For example, to list all the display device property names. +/* + m_DXDiagNVUtil.GetChildContainer( L"DxDiag_DisplayDevices", &pContainer ); + m_DXDiagNVUtil.ListAllDXDiagPropertyNames( pContainer, L"DxDiag_DisplayDevices" ); + SAFE_RELEASE( pContainer ); +// */ + + m_DXDiagNVUtil.FreeIDxDiagContainer(); + return( hr ); +} + + +HRESULT GetGPUAndSystemInfo::IsFPBlendingSupported( IDirect3D9 * pD3D9, FloatingPointBlendModes * pOutResult ) +{ + FMsg("There is a bug with this code in that is does not report that blending works for ordinary backbuffer formats\n"); + assert( false ); + + HRESULT hr = S_OK; + FAIL_IF_NULL( pD3D9 ); + FAIL_IF_NULL( pOutResult ); + + bool * pResult; + + hr = pD3D9->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + D3DFMT_A8R8G8B8, + D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, + D3DRTYPE_SURFACE, + D3DFMT_R16F ); + pResult = &pOutResult->m_bR16f; + if( hr == D3D_OK ) + *pResult = true; + else if( hr == D3DERR_NOTAVAILABLE ) + *pResult = false; + else + FMsg("Unknown return result for D3DFMT_R16F : %u\n", hr ); + + + hr = pD3D9->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + D3DFMT_A8R8G8B8, + D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, + D3DRTYPE_SURFACE, + D3DFMT_A16B16G16R16F ); + pResult = &pOutResult->m_bA16B16G16R16f; + if( hr == D3D_OK ) + *pResult = true; + else if( hr == D3DERR_NOTAVAILABLE ) + *pResult = false; + else + FMsg("Unknown return result for D3DFMT_A16B16G16R16F : %u\n", hr ); + + hr = pD3D9->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, + D3DFMT_A8R8G8B8, +// D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, + 0 | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, // per the DX90SDK docs + D3DRTYPE_SURFACE, + D3DFMT_A8R8G8B8 ); + pResult = &pOutResult->m_bA8R8G8B8; + if( hr == D3D_OK ) + *pResult = true; + else if( hr == D3DERR_NOTAVAILABLE ) + *pResult = false; + else + FMsg("Unknown return result for D3DFMT_A8R8G8B8 : %u\n", hr ); + + + if( pOutResult->m_bA16B16G16R16f == true ) + FMsg("D3DFMT_A16B16G16R16F POSTPIXELSHADER_BLENDING is supported\n"); + else + FMsg("D3DFMT_A16B16G16R16F POSTPIXELSHADER_BLENDING is not supported\n"); + + if( pOutResult->m_bR16f == true ) + FMsg("D3DFMT_R16F POSTPIXELSHADER_BLENDING is supported\n"); + else + FMsg("D3DFMT_R16F POSTPIXELSHADER_BLENDING is not supported\n"); + + if( pOutResult->m_bA8R8G8B8 == true ) + FMsg("D3DFMT_A8R8G8B8 POSTPIXELSHADER_BLENDING is supported\n"); + else + FMsg("D3DFMT_A8R8G8B8 POSTPIXELSHADER_BLENDING is not supported\n"); + +/* +Use IDirect3D9::CheckDeviceFormat, with usage (D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADERBLENDING). +HRESULT CheckDeviceFormat( UINT Adapter, + D3DDEVTYPE DeviceType, + D3DFORMAT AdapterFormat, + DWORD Usage, + D3DRESOURCETYPE RType, + D3DFORMAT CheckFormat +); + +D3DFMT_R16F 111 16-bit float format using 16 bits for the red channel. +D3DFMT_G16R16F 112 32-bit float format using 16 bits for the red channel and 16 bits for the green channel. +D3DFMT_A16B16G16R16F + +D3DFMT_R32F 114 32-bit float format using 32 bits for the red channel. +D3DFMT_G32R32F 115 64-bit float format using 32 bits for the red channel and 32 bits for the green channel. +D3DFMT_A32B32G32R32F + +D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING + +D3DUSAGE_QUERY_FILTER (more than just point sampling) + +Query the resource to verify support for post pixel shader blending support. +If IDirect3D9::CheckDeviceFormat fails with D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, +post pixel blending operations are not supported. These include alpha test, pixel fog, +render-target blending, color write enable, and dithering. + +MSFT examples from SDK + if( pCaps->PixelShaderVersion < D3DPS_VERSION(1,1) ) + { + if( FAILED( m_pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, + pCaps->DeviceType, adapterFormat, D3DUSAGE_RENDERTARGET, + D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8 ) ) ) + { + return E_FAIL; + } + } + + // Need to support post-pixel processing (for alpha blending) + if( FAILED( m_pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType, + adapterFormat, D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, + D3DRTYPE_SURFACE, backBufferFormat ) ) ) + { + return E_FAIL; + } + +HRESULT CMyD3DApplication::ConfirmDevice( D3DCAPS9* pCaps, DWORD dwBehavior, + D3DFORMAT adapterFormat, D3DFORMAT backBufferFormat ) +{ + // Need to support post-pixel processing (for alpha blending) + if( FAILED( m_pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType, + adapterFormat, D3DUSAGE_RENDERTARGET | D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, + D3DRTYPE_SURFACE, backBufferFormat ) ) ) + { + return E_FAIL; + } + +*/ + + + + return( hr ); +} + diff --git a/ref/vt-ex/src/3D/NV_StringFuncs.cpp b/ref/vt-ex/src/3D/NV_StringFuncs.cpp new file mode 100644 index 0000000..0dbd6f2 --- /dev/null +++ b/ref/vt-ex/src/3D/NV_StringFuncs.cpp @@ -0,0 +1,386 @@ +/*********************************************************************NVMH4**** +Path: SDK\LIBS\inc\shared +File: NV_StringFuncs.cpp + +Copyright NVIDIA Corporation 2002 +TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED +*AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS +BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES +WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, +BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) +ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS +BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + + +Comments: +See NV_StringFuncs.h for comments. + + +******************************************************************************/ + + + +#include "shared\NV_StringFuncs.h" +#include "shared\NV_Common.h" +#include "shared\NV_Error.h" + +#pragma warning(disable : 4786) +#include +#include +#include +#include +#include +#include + + +namespace NVStringConv +{ + // use as an alternative to wcstombs() + std::string WStringToString( const std::wstring * in_pwstring ) + { + if( in_pwstring == NULL ) + return( "" ); + return( lpcwstrToString( in_pwstring->c_str() )); + } + + std::string WStringToString( std::wstring & in_wstring ) + { + return( lpcwstrToString( in_wstring.c_str() )); + } + + std::string lpcwstrToString( LPCWSTR in_lpcwstr ) + { + //@ consider using windows.h WideCharToMultiByte(..) + char * mbBuf; + size_t sz; + sz = 2 * wcslen( in_lpcwstr ); + mbBuf = new char[sz]; + if( mbBuf == NULL ) + return( "" ); + wcstombs( mbBuf, in_lpcwstr, sz ); // convert the string + std::string outstr; + outstr = mbBuf; + delete [] mbBuf; + return( outstr ); + } + + std::wstring StringToWString( const std::string * in_pString ) + { + std::wstring wstr = L""; + if( in_pString != NULL ) + wstr = lpcstrToWString( in_pString->c_str() ); + return( wstr ); + } + + std::wstring StringToWString( std::string & in_String ) + { + return( lpcstrToWString( in_String.c_str() )); + } + + std::wstring lpcstrToWString( LPCSTR lpstr ) + { + int nLen = MultiByteToWideChar( CP_ACP, 0, lpstr, -1, NULL, NULL); + LPWSTR lpszW = new WCHAR[nLen+1]; + MultiByteToWideChar( CP_ACP, 0, lpstr, -1, lpszW, nLen); + lpszW[nLen] = '\0'; + std::wstring wstr; + wstr.reserve( nLen ); + wstr.insert( 0, lpszW ); +// wstr = lpszW; + delete[] lpszW; + return( wstr ); + } +}; // namespace NVStringConv + + +//--------------------------------------------------------------------------- + + // Create a string using va_args, just like printf, sprintf, etc. +std::string StrPrintf( const char * szFormat, ... ) +{ + std::string out; + + const int bufsz = 2048; + char buffer[ bufsz ]; + + va_list args; + va_start( args, szFormat ); + _vsnprintf( buffer, bufsz, szFormat, args ); + va_end( args ); + + buffer[bufsz-1] = '\0'; // terminate in case of overflow + out = buffer; + + return( out ); +} + +std::string StrToUpper( const std::string & strIn ) +{ + unsigned int i; + std::string out; + out.reserve( strIn.size() ); + for( i=0; i < strIn.size(); i++ ) + { + out += toupper( strIn.at(i) ); + } + return( out ); +} + +std::string StrToLower( const std::string & strIn ) +{ + unsigned int i; + std::string out; + out.reserve( strIn.size() ); + for( i=0; i < strIn.size(); i++ ) + { + out += tolower( strIn.at(i) ); + } + return( out ); +} + + +std::string StrsToString( const std::vector< std::string > & vstrIn ) +{ + return( StrsToString( vstrIn, " " )); +} + + // same as above, but lets you specify the separator +std::string StrsToString( const std::vector< std::string > & vstrIn, const std::string & separator ) +{ + std::string out; + out.reserve( vstrIn.size() * 5 ); // rough estimate, 5 chars per string + unsigned int i; + for( i=0; i < vstrIn.size(); i++ ) + { + out += vstrIn.at(i) + separator; + } + return( out ); +} + +std::string StrsToString( const std::list< std::string > & lstrIn, const std::string & separator ) +{ + std::string out; + out.reserve( lstrIn.size() * 5 ); + std::list< std::string>::const_iterator p; + for( p = lstrIn.begin(); p != lstrIn.end(); p++ ) + { + out += (*p) + separator; + } + return( out ); +} + + + +std::string * StrReplace( const std::string & sequence_to_replace, + const std::string & replacement_string, + const std::string & strIn, + std::string * pOut, + bool bVerbose ) +{ + if( pOut == NULL ) + return( pOut ); + if( & strIn == pOut ) + { + // can't have strIn and pOut point to the same thing + // have to copy the input string + std::string incpy = strIn; + return( StrReplace( sequence_to_replace, replacement_string, incpy, pOut )); + } + + + // Similar functionality to CString::Replace(), but no MFC required. + unsigned int i; + std::vector< size_t > vpos; + std::string::size_type pos; + pos = 0; + + *pOut = ""; + + do + { + pos = strIn.find( sequence_to_replace, pos ); + if( pos != std::string::npos ) + { + vpos.push_back( pos ); + pos++; + } + } while( pos != std::string::npos ); + + if( bVerbose ) + { + FMsg("found at "); + for( i=0; i < vpos.size(); i++ ) + { + FMsg("%d ", vpos.at(i) ); + } + FMsg("\n"); + } + + size_t last_pos = 0; + size_t repl_size = sequence_to_replace.size(); + pOut->reserve( strIn.size() + vpos.size() * replacement_string.size() - vpos.size() * repl_size ); + // last_pos marks character which should be included + // in the output string + for( i=0; i < vpos.size(); i++ ) + { + *pOut += strIn.substr( last_pos, vpos.at(i) - last_pos ); + last_pos = vpos.at(i) + repl_size; + *pOut += replacement_string; + } + // add remainder of orig string to the end + *pOut += strIn.substr( last_pos, strIn.size() - last_pos ); + + return( pOut ); +} + + +std::string StrReplace( const std::string & sequence_to_replace, + const std::string & replacement_string, + const std::string & strIn ) +{ + std::string out; + + StrReplace( sequence_to_replace, replacement_string, strIn, &out ); + + return( out ); +} + + + +std::string StrTokenize( const std::string & strIn, const std::string & delimiters ) +{ + // applies strtok repeatedly & acumulates ouput tokens + // in output string separated by spaces + + return( StrTokenize( strIn, delimiters, " " )); +} + + +std::string StrTokenize( const std::string & strIn, + const std::string & delimiters, + const std::string & output_separator ) +{ + // Same as above, but allows you to specify the separator between + // tokens in the output + // No trailing separator is added + + std::string out; + char * token; + char * copy = new char[strIn.size()+2]; // +2 just to be safe! + strcpy( copy, strIn.c_str() ); + token = strtok( copy, delimiters.c_str() ); + while( token != NULL ) + { + out += token; + token = strtok( NULL, delimiters.c_str() ); + + // If there's another token, add the separator + // This means there is no trailing separator. + if( token != NULL ) + { + out += output_separator; + } + } + delete[] copy; + return( out ); +} + + +sfsizet StrFindCaseless( const std::string & strSearchIn, + sfsizet start_pos, + const std::string & strSearchFor ) +{ + sfsizet outpos = std::string::npos; + std::string sin = StrToUpper( strSearchIn ); + std::string sfor = StrToUpper( strSearchFor ); + + outpos = sin.find( sfor, start_pos ); + + return( outpos ); +} + + +std::vector< sfsizet > StrFindAllCaseless( const std::string & strSearchIn, + sfsizet start_pos, + const std::string & strSearchFor ) +{ + std::vector< sfsizet > out; + sfsizet pos = start_pos; + std::string sin = StrToUpper( strSearchIn ); + std::string sfor = StrToUpper( strSearchFor ); + + while( pos != std::string::npos ) + { + pos = sin.find( sfor, pos ); + if( pos != std::string::npos ) + { + out.push_back( pos ); + pos++; + } + } + + return( out ); +} + +std::vector< sfsizet > StrFindAll( const std::string & strSearchIn, + sfsizet start_pos, + const std::string & strSearchFor ) +{ + std::vector< sfsizet > out; + sfsizet pos = start_pos; + while( pos != std::string::npos ) + { + pos = strSearchIn.find( strSearchFor, pos ); + if( pos != std::string::npos ) + { + out.push_back( pos ); + pos++; + } + } + return( out ); +} + + +std::vector< std::string> StrSort( const std::vector< std::string > & vStrIn ) +{ + std::vector< std::string > vOut; + std::list< std::string > lstr; + + unsigned int i; + for( i=0; i < vStrIn.size(); i++ ) + { + lstr.push_back( vStrIn.at(i) ); + } + lstr.sort(); + + std::list< std::string>::const_iterator p; + for( p = lstr.begin(); p != lstr.end(); p++ ) + { + vOut.push_back( *p ); + } + return( vOut ); +} + +//------------------------------------------------------------------- +// Reduce a full or relative path name to just a lone filename. +// Example: +// name = GetFilenameFromFullPath( "C:\MyFiles\project1\texture.dds" ); +// name is "texture.dds" +// Returns the input string if no path info was found & removed. +//------------------------------------------------------------------- +tstring GetFilenameFromFullPath( const tstring & full_path ) +{ + size_t pos; + pos = full_path.find_last_of( '\\', full_path.length() ); + if( pos == tstring::npos ) + pos = full_path.find_last_of( '/', full_path.length() ); + if( pos == tstring::npos ) + return( full_path ); + tstring name; + name = full_path.substr( pos+1, full_path.length() ); + return( name ); +} + diff --git a/ref/vt-ex/src/3D/nvfile.cpp b/ref/vt-ex/src/3D/nvfile.cpp new file mode 100644 index 0000000..743e560 --- /dev/null +++ b/ref/vt-ex/src/3D/nvfile.cpp @@ -0,0 +1,297 @@ +/****************************************************************************** + + Copyright (C) 1999, 2000 NVIDIA Corporation + This file is provided without support, instruction, or implied warranty of any + kind. NVIDIA makes no guarantee of its fitness for a particular purpose and is + not liable under any circumstances for any damages or loss whatsoever arising + from the use or inability to use this file or items derived from it. + + Comments: + + + +******************************************************************************/ +#include +#include +#include "rmxfguid.h" +#include "rmxftmpl.h" +#include "shared/nvfile.h" + +using namespace std; + +#ifndef SAFE_RELEASE + #define SAFE_RELEASE(x) { if (x) { x->Release(); x = NULL; } } +#endif + +HRESULT NVFile::LoadFrame( IDirect3DDevice9* pDevice, + LPD3DXFILEDATA pFileData, + NVFrame* pParentFrame ) +{ + LPD3DXFILEDATA pChildData = NULL; + GUID guid; + DWORD cbSize; + NVFrame* pCurrentFrame; + HRESULT hr; + + // Get the type of the object + if( FAILED( hr = pFileData->GetType( &guid ) ) ) + return hr; + + if( guid == TID_D3DRMMesh ) + { + hr = LoadMesh( pDevice, pFileData, pParentFrame ); + if( FAILED(hr) ) + return hr; + } + if( guid == TID_D3DRMFrameTransformMatrix ) + { + D3DXMATRIX* pmatMatrix; + hr = pFileData->Lock(&cbSize, (LPCVOID*)&pmatMatrix ); + if( FAILED(hr) ) + return hr; + + // Update the parent's matrix with the new one + pParentFrame->SetMatrix( pmatMatrix ); + } + if( guid == TID_D3DRMFrame ) + { + // Get the frame name + TCHAR strAnsiName[512] = _T(""); + SIZE_T dwNameLength = 512; + SIZE_T cChildren; + +#ifdef UNICODE + + CHAR tmp[512]; + if( FAILED( hr = pFileData->GetName( tmp, &dwNameLength ) ) ) + return hr; + + MultiByteToWideChar(CP_ACP,0,tmp,512,strAnsiName,512); +#else + if( FAILED( hr = pFileData->GetName( strAnsiName, &dwNameLength ) ) ) + return hr; +#endif + + + // Create the frame + pCurrentFrame = new NVFrame( strAnsiName ); + if( pCurrentFrame == NULL ) + return E_OUTOFMEMORY; + + pCurrentFrame->m_pNext = pParentFrame->m_pChild; + pParentFrame->m_pChild = pCurrentFrame; + + // Enumerate child objects + pFileData->GetChildren(&cChildren); + for (UINT iChild = 0; iChild < cChildren; iChild++) + { + // Query the child for its FileData + hr = pFileData->GetChild(iChild, &pChildData ); + if( SUCCEEDED(hr) ) + { + hr = LoadFrame( pDevice, pChildData, pCurrentFrame ); + SAFE_RELEASE( pChildData ); + } + + if( FAILED(hr) ) + return hr; + } + } + + return S_OK; +} + +HRESULT NVFile::LoadMesh( IDirect3DDevice9* pDevice, + LPD3DXFILEDATA pFileData, + NVFrame* pParentFrame ) +{ + // Currently only allowing one mesh per frame + if( pParentFrame->m_pMesh ) + return E_FAIL; + + // Get the mesh name + TCHAR strAnsiName[512] = {0}; + SIZE_T dwNameLength = 512; + + HRESULT hr; +#ifdef UNICODE + + CHAR tmp[512]; + if( FAILED( hr = pFileData->GetName( tmp, &dwNameLength ) ) ) + return hr; + + MultiByteToWideChar(CP_ACP,0,tmp,512,strAnsiName,512); +#else + if( FAILED( hr = pFileData->GetName( strAnsiName, &dwNameLength ) ) ) + return hr; +#endif + + // Create the mesh + pParentFrame->m_pMesh = new NVMesh( strAnsiName ); + if( pParentFrame->m_pMesh == NULL ) + return E_OUTOFMEMORY; + pParentFrame->m_pMesh->Create( pDevice, pFileData ); + + return S_OK; +} + +HRESULT NVFile::Create( IDirect3DDevice9* pDevice, const tstring& strPathname ) +{ + LPD3DXFILE pDXFile = NULL; + LPD3DXFILEENUMOBJECT pEnumObj = NULL; + LPD3DXFILEDATA pFileData = NULL; + HRESULT hr; + SIZE_T cChildren; + + tstring::size_type Pos = strPathname.find_last_of(_T("\\"), strPathname.size()); + if (Pos != strPathname.npos) + { + // Make sure we are on the right path for loading resources associated with this file + m_strFilePath = strPathname.substr(0, Pos); + SetCurrentDirectory(m_strFilePath.c_str()); + } + + // Create a x file object + if( FAILED( hr = D3DXFileCreate( &pDXFile ) ) ) + return E_FAIL; + + // Register templates for d3drm and patch extensions. + if( FAILED( hr = pDXFile->RegisterTemplates( (VOID*)D3DRM_XTEMPLATES, + D3DRM_XTEMPLATE_BYTES ) ) ) + { + SAFE_RELEASE( pDXFile ); + return E_FAIL; + } +#ifdef UNICODE + int len = WideCharToMultiByte(CP_ACP,0,strPathname.c_str(),-1,NULL,NULL,NULL,NULL); + char *tmp = new char[len]; + WideCharToMultiByte(CP_ACP,0,strPathname.c_str(),-1,tmp,len,NULL,NULL); + + + hr = pDXFile->CreateEnumObject( (VOID*)tmp, + D3DXF_FILELOAD_FROMFILE, &pEnumObj ); + +#else + // Create enum object + hr = pDXFile->CreateEnumObject( (VOID*)strPathname.c_str(), + D3DXF_FILELOAD_FROMFILE, &pEnumObj ); +#endif + if (FAILED(hr)) + { + SAFE_RELEASE( pDXFile ); + return hr; + } + + // Enumerate top level objects (which are always frames) + pEnumObj->GetChildren(&cChildren); + for (UINT iChild = 0; iChild < cChildren; iChild++) + { + hr = pEnumObj->GetChild(iChild, &pFileData); + if (FAILED(hr)) + return hr; + + hr = LoadFrame( pDevice, pFileData, this ); + SAFE_RELEASE( pFileData ); + if( FAILED(hr) ) + { + SAFE_RELEASE( pEnumObj ); + SAFE_RELEASE( pDXFile ); + return E_FAIL; + } + } + + SAFE_RELEASE( pFileData ); + SAFE_RELEASE( pEnumObj ); + SAFE_RELEASE( pDXFile ); + + return S_OK; +} + +HRESULT NVFile::Render( IDirect3DDevice9* pDevice ) +{ + // Setup the world transformation + D3DXMATRIX matSavedWorld, matWorld; + pDevice->GetTransform(D3DTS_WORLD, &matSavedWorld); + D3DXMatrixMultiply( &matWorld, &matSavedWorld, &m_mat ); + pDevice->SetTransform(D3DTS_WORLD, &matWorld ); + + // Render opaque subsets in the meshes + if( m_pChild ) + m_pChild->Render( pDevice, TRUE, FALSE ); + + // Enable alpha blending + pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ); + pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); + pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); + + // Render alpha subsets in the meshes + if( m_pChild ) + m_pChild->Render( pDevice, FALSE, TRUE ); + + // Restore state + pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); + pDevice->SetTransform(D3DTS_WORLD, &matSavedWorld ); + + return S_OK; +} + + +bool CalcFileObjectSizeCB( NVFrame* pFrame, D3DXMATRIX* pMat, VOID* pfSize ) +{ + NVBounds* pBounds = (NVBounds*)pfSize; + NVMesh* pMesh = pFrame->m_pMesh; + DWORD dwStride = 0; + + if (!pMesh) + { + return true; + } + + // Get the bounds for the mesh and transform them by the local + // world transform. + NVBounds MeshBounds = *pMesh->GetBounds(); + MeshBounds.Transform(pMat); + + if (pBounds->m_vecMaxExtents.x < MeshBounds.m_vecMaxExtents.x) + pBounds->m_vecMaxExtents.x = MeshBounds.m_vecMaxExtents.x; + + if (pBounds->m_vecMaxExtents.y < MeshBounds.m_vecMaxExtents.y) + pBounds->m_vecMaxExtents.y = MeshBounds.m_vecMaxExtents.y; + + if (pBounds->m_vecMaxExtents.z < MeshBounds.m_vecMaxExtents.z) + pBounds->m_vecMaxExtents.z = MeshBounds.m_vecMaxExtents.z; + + + if (pBounds->m_vecMinExtents.x > MeshBounds.m_vecMinExtents.x) + pBounds->m_vecMinExtents.x = MeshBounds.m_vecMinExtents.x; + + if (pBounds->m_vecMinExtents.y > MeshBounds.m_vecMinExtents.y) + pBounds->m_vecMinExtents.y = MeshBounds.m_vecMinExtents.y; + + if (pBounds->m_vecMinExtents.z > MeshBounds.m_vecMinExtents.z) + pBounds->m_vecMinExtents.z = MeshBounds.m_vecMinExtents.z; + + if (pBounds->m_fRadius < MeshBounds.m_fRadius) + pBounds->m_fRadius = MeshBounds.m_fRadius; + + return true; +} + +//----------------------------------------------------------------------------- +// Name: GetBoundingInfo() +// Desc: +//----------------------------------------------------------------------------- +void NVFile::GetBoundingInfo(NVBounds* pBounds) +{ + pBounds->m_vecCenter = D3DXVECTOR3(0.0f, 0.0f, 0.0f); + pBounds->m_fRadius = 0.0f; + pBounds->m_vecMinExtents = D3DXVECTOR3(FLT_MAX, FLT_MAX, FLT_MAX); + pBounds->m_vecMaxExtents = D3DXVECTOR3(-FLT_MAX, -FLT_MAX, -FLT_MAX); + + D3DXMATRIX Matrix; + D3DXMatrixIdentity(&Matrix); + WalkFrames(CalcFileObjectSizeCB, &Matrix, (VOID*)pBounds); + + pBounds->m_vecCenter = (pBounds->m_vecMaxExtents + pBounds->m_vecMinExtents) / 2.0f; +} + diff --git a/ref/vt-ex/src/profile/GDirectory.cpp b/ref/vt-ex/src/profile/GDirectory.cpp new file mode 100644 index 0000000..915ff21 --- /dev/null +++ b/ref/vt-ex/src/profile/GDirectory.cpp @@ -0,0 +1,296 @@ +// -------------------------------------------------------------------------- +// www.UnitedBusinessTechnologies.com +// Copyright (c) 1998 - 2002 All Rights Reserved. +// +// Source in this file is released to the public under the following license: +// -------------------------------------------------------------------------- +// This toolkit may be used free of charge for any purpose including corporate +// and academic use. For profit, and Non-Profit uses are permitted. +// +// This source code and any work derived from this source code must retain +// this copyright at the top of each source file. +// +// UBT welcomes any suggestions, improvements or new platform ports. +// email to: XMLFoundation@UnitedBusinessTechnologies.com +// -------------------------------------------------------------------------- +#include "pch.h" +#include "DirectoryListing.h" +#include "GString.h" +#include "GException.h" +//#include + +// #include + +// #include "Winbase.h" +#include +#include +#include // for: mkdir + + + + + +const char *CDirectoryListing::LastLeaf(const char *pzFullPath, char chSlash/*= 0*/) +{ + static GString strReturnValue; + strReturnValue = ""; + if (pzFullPath && pzFullPath[0]) + { + strReturnValue = pzFullPath; + int nLen = strlen(pzFullPath); + if (chSlash) + { + if (pzFullPath[nLen - 1] == chSlash) + nLen--; + + } + else if ( pzFullPath[nLen - 1] == '\\' || pzFullPath[nLen - 1] == '/') + { + nLen--; // if the input value is "/etc/bin/" start searching behind the last '/' + // so that the return leaf value is "bin" + } + + for(int i = nLen-1; i > -1; i-- ) + { + if (chSlash) + { + if (pzFullPath[i] == chSlash) + { + strReturnValue = &pzFullPath[i+1]; + break; + } + } + else if (pzFullPath[i] == '\\' || pzFullPath[i] == '/') + { + strReturnValue = &pzFullPath[i+1]; + break; + } + } + } + return strReturnValue; +} + + + + +void CDirectoryListing::CreatePath(const char *pzPathOnlyOrPathAndFileName, int bPathHasFileName) +{ + // cast off the const, we'll modify then restore the string + char *pzFileAndPath = (char *)pzPathOnlyOrPathAndFileName; + + if (!pzFileAndPath) + { + return; + } + int nLen = strlen(pzFileAndPath); + for(int i=0;iAddLast(strFullPath); + } + + // now add the final slash for a string like this "/myPath/SubDir/" + strFullPath += chSlash; + + // go down into that directory now. + RecurseFolder(strFullPath, strDirs, strFiles); + } + } + + if(strFiles) + { + CDirectoryListing files(pzDir, 1); // files only + GStringIterator it2(&files); + while (it2()) + { + // pzDir may be "/myPath" to begin with + GString strFullPath(pzDir); + if ( strFullPath.GetAt(strFullPath.GetLength() - 1) != '\\' && + strFullPath.GetAt(strFullPath.GetLength() - 1) != '/') + { + // strFullPath will now end with a slash like "/myPath/" + strFullPath += chSlash; + } + + + const char *pzFile = it2++; + strFullPath += pzFile; + strFiles->AddLast((const char *)strFullPath); + } + } + } + catch( GenericException & ) + { + // ignore the directory we can't access + // rErr.GetDescription(); + } +} + + +void CDirectoryListing::Init(const char *szDirPath, int nMode) +{ + static GString dotdot(".."); + static GString dot("."); + + bool bIncludeSubDirs = (nMode == 2 || nMode == 3) ? 1 : 0; + bool bIncludeFiles = (nMode == 1 || nMode == 3) ? 1 : 0; + + + GString strPathWithTrailingSlash(szDirPath); + GString strPathWithNoTrailingSlash(szDirPath); + + // if szDirPath ends with a slash + if ( strPathWithNoTrailingSlash.Right(1) == "/" || + strPathWithNoTrailingSlash.Right(1) == "\\" ) + { + // if the path is "/" leave it alone + if (strPathWithNoTrailingSlash.Length() > 1) + strPathWithNoTrailingSlash = strPathWithNoTrailingSlash.Left(strPathWithNoTrailingSlash.Length() - 1); + } + else + { + strPathWithTrailingSlash += "\\"; + + } + + if( _access( (const char *)strPathWithNoTrailingSlash, 0 ) ) + { + throw GenericException("GDirectoryListing",0,(const char *)strPathWithNoTrailingSlash, errno); + } + + // FindFirstFile & FindNextFile + HANDLE hFindFile; + WIN32_FIND_DATA find; + BOOL fRet = TRUE; + GString strSearch( strPathWithTrailingSlash ); + strSearch += "*.*"; + hFindFile = FindFirstFile((const char *)strSearch, &find); + while (hFindFile != (HANDLE)-1 && fRet == TRUE) + { + GString strTemp( strPathWithTrailingSlash ); + strTemp += find.cFileName; + struct stat sstruct; + + int result = stat(strTemp, &sstruct); + if (result == 0) + { + if ( !(sstruct.st_mode & _S_IFDIR) ) + { + // Add the file + if (bIncludeFiles) + { + AddLast((const char *)find.cFileName); + } + } + else if (bIncludeSubDirs) + { + GString strFileName( LastLeaf( (char *)(const char *)strTemp,'\\') ); + if ( ( dotdot.Compare(strFileName) != 0 ) && ( dot.Compare(strFileName) != 0 )) + { + GString strFormattedDir; + strFormattedDir.Format("[dir] %s", LastLeaf( (char *)(const char *)strFileName,'\\') ); + AddLast((const char *)strFormattedDir); + } + } + + } + + fRet = FindNextFile(hFindFile, &find); + } + FindClose(hFindFile); +} + + +CDirectoryListing::CDirectoryListing(const char *szPath) +{ + Init(szPath, 1); +} + +// nMode = 1 files, 2 dirs, 3 both +CDirectoryListing::CDirectoryListing(const char *szPath, int nMode) +{ + Init(szPath, nMode); +} + +CDirectoryListing::~CDirectoryListing() +{ +} + diff --git a/ref/vt-ex/src/profile/GException.cpp b/ref/vt-ex/src/profile/GException.cpp new file mode 100644 index 0000000..d6631d0 --- /dev/null +++ b/ref/vt-ex/src/profile/GException.cpp @@ -0,0 +1,689 @@ + +// -------------------------------------------------------------------------- +// www.UnitedBusinessTechnologies.com +// Copyright (c) 1998 - 2002 All Rights Reserved. +// +// Source in this file is released to the public under the following license: +// -------------------------------------------------------------------------- +// This toolkit may be used free of charge for any purpose including corporate +// and academic use. For profit, and Non-Profit uses are permitted. +// +// This source code and any work derived from this source code must retain +// this copyright at the top of each source file. +// +// UBT welcomes any suggestions, improvements or new platform ports. +// email to: XMLFoundation@UnitedBusinessTechnologies.com +// -------------------------------------------------------------------------- +#include "pch.h" +#include "GException.h" +#include "GString.h" +#include "GProfile.h" +#include //for: va_start(), va_end +#include //for: strlen(), memcpy() + +static char *g_pzStaticErrMap = 0; + +void SetErrorDescriptions(const char *pzErrData) +{ + if (g_pzStaticErrMap) + delete g_pzStaticErrMap; + g_pzStaticErrMap = new char[strlen(pzErrData)+1]; + memcpy(g_pzStaticErrMap,pzErrData,strlen(pzErrData)+1); +} + + +GProfile &GetErrorProfile() +{ + static GString strErrorFile; + GString *pstrErrorFileContents = 0; + + if (strErrorFile.IsEmpty()) + { + if (g_pzStaticErrMap) + { + strErrorFile = "Static Load"; + pstrErrorFileContents = new GString(g_pzStaticErrMap,strlen(g_pzStaticErrMap)); + } + else + { + const char *pzErrFile = GetProfile().GetString("System", "Errors", 0); + if (pzErrFile && pzErrFile[0]) + { + pstrErrorFileContents = new GString(); + if (!pstrErrorFileContents->FromFile(pzErrFile,0)) + { + pzErrFile = 0; + } + strErrorFile = pzErrFile; + } + // if the error file could not be found, default to a minimal error file + if (!pzErrFile) + { + (*pstrErrorFileContents) = "[Exception]\nSubSystem=0\n[Profile]\nSubSystem=1\n0=[%s.%s]Error Description File Not loaded.\n1=[%s]Error Description File Not loaded.\n"; + strErrorFile = "Static"; + } + } + } + static GProfile ErrorProfile(pstrErrorFileContents->StrVal(), pstrErrorFileContents->Length()); + return ErrorProfile; +} + + +#if defined _DEBUGX && _WIN32 + +#include +#include +#include +#pragma comment( lib, "imagehlp" ) + +/////////////////////////////////////////////////////////////////////////// +/////////////////////// Win32 stack tracing /////////////////////////////// + +#define gle (GetLastError()) +#define lenof(a) (sizeof(a) / sizeof((a)[0])) +#define MAXNAMELEN 1024 // max name length for found symbols +#define IMGSYMLEN ( sizeof IMAGEHLP_SYMBOL ) +#define TTBUFLEN 65536 // for a temp buffer + +void _stack_se_translator(unsigned int e, _EXCEPTION_POINTERS* p) +{ + HANDLE hThread; + + DuplicateHandle( GetCurrentProcess(), GetCurrentThread(), + GetCurrentProcess(), &hThread, 0, false, DUPLICATE_SAME_ACCESS ); + + GenericCallStack stk(hThread, *(p->ContextRecord)); + + CloseHandle( hThread ); + + throw stk; +} + + +GenericCallStack::GenericCallStack(const GenericCallStack &src) +{ + _stk = src._stk; +} + +struct ModuleEntry +{ + std::string imageName; + std::string moduleName; + DWORD baseAddress; + DWORD size; +}; +typedef std::vector< ModuleEntry > ModuleList; +typedef ModuleList::iterator ModuleListIter; + +// miscellaneous toolhelp32 declarations; we cannot #include the header +// because not all systems may have it +#define MAX_MODULE_NAME32 255 +#define TH32CS_SNAPMODULE 0x00000008 +#pragma pack( push, 8 ) +typedef struct tagMODULEENTRY32 +{ + DWORD dwSize; + DWORD th32ModuleID; // This module + DWORD th32ProcessID; // owning process + DWORD GlblcntUsage; // Global usage count on the module + DWORD ProccntUsage; // Module usage count in th32ProcessID's context + BYTE * modBaseAddr; // Base address of module in th32ProcessID's context + DWORD modBaseSize; // Size in bytes of module starting at modBaseAddr + HMODULE hModule; // The hModule of this module in th32ProcessID's context + char szModule[MAX_MODULE_NAME32 + 1]; + char szExePath[MAX_PATH]; +} MODULEENTRY32; +typedef MODULEENTRY32 * PMODULEENTRY32; +typedef MODULEENTRY32 * LPMODULEENTRY32; +#pragma pack( pop ) + +bool fillModuleListTH32( ModuleList& modules, DWORD pid ) +{ + // CreateToolhelp32Snapshot() + typedef HANDLE (__stdcall *tCT32S)( DWORD dwFlags, DWORD th32ProcessID ); + // Module32First() + typedef BOOL (__stdcall *tM32F)( HANDLE hSnapshot, LPMODULEENTRY32 lpme ); + // Module32Next() + typedef BOOL (__stdcall *tM32N)( HANDLE hSnapshot, LPMODULEENTRY32 lpme ); + + // I think the DLL is called tlhelp32.dll on Win9X, so we try both + const char *dllname[] = { "kernel32.dll", "tlhelp32.dll" }; + HINSTANCE hToolhelp; + tCT32S pCT32S; + tM32F pM32F; + tM32N pM32N; + + HANDLE hSnap; + MODULEENTRY32 me = { sizeof me }; + bool keepGoing; + ModuleEntry e; + int i; + + for ( i = 0; i < lenof( dllname ); ++ i ) + { + hToolhelp = LoadLibrary( dllname[i] ); + if ( hToolhelp == 0 ) + continue; + pCT32S = (tCT32S) GetProcAddress( hToolhelp, "CreateToolhelp32Snapshot" ); + pM32F = (tM32F) GetProcAddress( hToolhelp, "Module32First" ); + pM32N = (tM32N) GetProcAddress( hToolhelp, "Module32Next" ); + if ( pCT32S != 0 && pM32F != 0 && pM32N != 0 ) + break; // found the functions! + FreeLibrary( hToolhelp ); + hToolhelp = 0; + } + + if ( hToolhelp == 0 ) // nothing found? + return false; + + hSnap = pCT32S( TH32CS_SNAPMODULE, pid ); + if ( hSnap == (HANDLE) -1 ) + return false; + + keepGoing = !!pM32F( hSnap, &me ); + while ( keepGoing ) + { + // here, we have a filled-in MODULEENTRY32 + e.imageName = me.szExePath; + e.moduleName = me.szModule; + e.baseAddress = (DWORD) me.modBaseAddr; + e.size = me.modBaseSize; + modules.push_back( e ); + keepGoing = !!pM32N( hSnap, &me ); + } + + CloseHandle( hSnap ); + + FreeLibrary( hToolhelp ); + + return modules.size() != 0; +} + +// miscellaneous psapi declarations; we cannot #include the header +// because not all systems may have it +typedef struct _MODULEINFO { + LPVOID lpBaseOfDll; + DWORD SizeOfImage; + LPVOID EntryPoint; +} MODULEINFO, *LPMODULEINFO; + +bool fillModuleListPSAPI( ModuleList& modules, DWORD pid, HANDLE hProcess ) +{ + // EnumProcessModules() + typedef BOOL (__stdcall *tEPM)( HANDLE hProcess, HMODULE *lphModule, DWORD cb, LPDWORD lpcbNeeded ); + // GetModuleFileNameEx() + typedef DWORD (__stdcall *tGMFNE)( HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize ); + // GetModuleBaseName() -- redundant, as GMFNE() has the same prototype, but who cares? + typedef DWORD (__stdcall *tGMBN)( HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize ); + // GetModuleInformation() + typedef BOOL (__stdcall *tGMI)( HANDLE hProcess, HMODULE hModule, LPMODULEINFO pmi, DWORD nSize ); + + HINSTANCE hPsapi; + tEPM pEPM; + tGMFNE pGMFNE; + tGMBN pGMBN; + tGMI pGMI; + + int i; + ModuleEntry e; + DWORD cbNeeded; + MODULEINFO mi; + HMODULE *hMods = 0; + char *tt = 0; + + hPsapi = LoadLibrary( "psapi.dll" ); + if ( hPsapi == 0 ) + return false; + + modules.clear(); + + pEPM = (tEPM) GetProcAddress( hPsapi, "EnumProcessModules" ); + pGMFNE = (tGMFNE) GetProcAddress( hPsapi, "GetModuleFileNameExA" ); + pGMBN = (tGMFNE) GetProcAddress( hPsapi, "GetModuleBaseNameA" ); + pGMI = (tGMI) GetProcAddress( hPsapi, "GetModuleInformation" ); + if ( pEPM == 0 || pGMFNE == 0 || pGMBN == 0 || pGMI == 0 ) + { + // yuck. Some API is missing. + FreeLibrary( hPsapi ); + return false; + } + + hMods = new HMODULE[TTBUFLEN / sizeof HMODULE]; + tt = new char[TTBUFLEN]; + // not that this is a sample. Which means I can get away with + // not checking for errors, but you cannot. :) + + if ( ! pEPM( hProcess, hMods, TTBUFLEN, &cbNeeded ) ) + { + goto cleanup; + } + + if ( cbNeeded > TTBUFLEN ) + { + goto cleanup; + } + + for ( i = 0; i < cbNeeded / sizeof hMods[0]; ++ i ) + { + // for each module, get: + // base address, size + pGMI( hProcess, hMods[i], &mi, sizeof mi ); + e.baseAddress = (DWORD) mi.lpBaseOfDll; + e.size = mi.SizeOfImage; + // image file name + tt[0] = '\0'; + pGMFNE( hProcess, hMods[i], tt, TTBUFLEN ); + e.imageName = tt; + // module name + tt[0] = '\0'; + pGMBN( hProcess, hMods[i], tt, TTBUFLEN ); + e.moduleName = tt; + + modules.push_back( e ); + } + +cleanup: + if ( hPsapi ) + FreeLibrary( hPsapi ); + delete [] tt; + delete [] hMods; + + return modules.size() != 0; +} + +bool fillModuleList( ModuleList& modules, DWORD pid, HANDLE hProcess ) +{ + // try toolhelp32 first + if ( fillModuleListTH32( modules, pid ) ) + return true; + // nope? try psapi, then + return fillModuleListPSAPI( modules, pid, hProcess ); +} + +void enumAndLoadModuleSymbols( HANDLE hProcess, DWORD pid ) +{ + ModuleList modules; + ModuleListIter it; + char *img, *mod; + + // fill in module list + fillModuleList( modules, pid, hProcess ); + + for ( it = modules.begin(); it != modules.end(); ++ it ) + { + // unfortunately, SymLoadModule() wants writeable strings + img = new char[(*it).imageName.size() + 1]; + strcpy( img, (*it).imageName.c_str() ); + mod = new char[(*it).moduleName.size() + 1]; + strcpy( mod, (*it).moduleName.c_str() ); + + SymLoadModule( hProcess, 0, img, mod, (*it).baseAddress, (*it).size ); + + delete [] img; + delete [] mod; + } +} + +GenericCallStack::GenericCallStack(HANDLE hThread, CONTEXT& c) +{ + DWORD imageType = IMAGE_FILE_MACHINE_I386; + HANDLE hProcess = GetCurrentProcess(); + + int frameNum; // counts walked frames + DWORD offsetFromSymbol; // tells us how far from the symbol we were + DWORD symOptions; // symbol handler settings + IMAGEHLP_SYMBOL *pSym = (IMAGEHLP_SYMBOL *) malloc( IMGSYMLEN + MAXNAMELEN ); + char undFullName[MAXNAMELEN]; // undecorated name with all shenanigans + + IMAGEHLP_MODULE Module; + IMAGEHLP_LINE Line; + std::string symSearchPath; + char *tt = 0, *p; + + STACKFRAME s; // in/out stackframe + memset( &s, '\0', sizeof s ); + + tt = new char[TTBUFLEN]; + + // build symbol search path from: + symSearchPath = ""; + // current directory + if ( GetCurrentDirectory( TTBUFLEN, tt ) ) + symSearchPath += tt + std::string( ";" ); + // dir with executable + if ( GetModuleFileName( 0, tt, TTBUFLEN ) ) + { + for ( p = tt + strlen( tt ) - 1; p >= tt; -- p ) + { + // locate the rightmost path separator + if ( *p == '\\' || *p == '/' || *p == ':' ) + break; + } + // if we found one, p is pointing at it; if not, tt only contains + // an exe name (no path), and p points before its first byte + if ( p != tt ) // path sep found? + { + if ( *p == ':' ) // we leave colons in place + ++ p; + *p = '\0'; // eliminate the exe name and last path sep + symSearchPath += tt + std::string( ";" ); + } + } + // environment variable _NT_SYMBOL_PATH + if ( GetEnvironmentVariable( "_NT_SYMBOL_PATH", tt, TTBUFLEN ) ) + symSearchPath += tt + std::string( ";" ); + // environment variable _NT_ALTERNATE_SYMBOL_PATH + if ( GetEnvironmentVariable( "_NT_ALTERNATE_SYMBOL_PATH", tt, TTBUFLEN ) ) + symSearchPath += tt + std::string( ";" ); + // environment variable SYSTEMROOT + if ( GetEnvironmentVariable( "SYSTEMROOT", tt, TTBUFLEN ) ) + symSearchPath += tt + std::string( ";" ); + + if ( symSearchPath.size() > 0 ) // if we added anything, we have a trailing semicolon + symSearchPath = symSearchPath.substr( 0, symSearchPath.size() - 1 ); + + // why oh why does SymInitialize() want a writeable string? + strncpy( tt, symSearchPath.c_str(), TTBUFLEN ); + tt[TTBUFLEN - 1] = '\0'; // if strncpy() overruns, it doesn't add the null terminator + + // init symbol handler stuff (SymInitialize()) + if ( ! SymInitialize( hProcess, tt, false ) ) + { + goto tagCleanUp; + } + + symOptions = SymGetOptions(); + symOptions |= SYMOPT_LOAD_LINES; + symOptions &= ~SYMOPT_UNDNAME; + SymSetOptions( symOptions ); // SymSetOptions() + + enumAndLoadModuleSymbols( hProcess, GetCurrentProcessId() ); + + // init STACKFRAME for first call + // Notes: will have to be #ifdef-ed for Alphas; MIPSes are dead anyway, + // and good riddance. + s.AddrPC.Offset = c.Eip; + s.AddrPC.Mode = AddrModeFlat; + s.AddrFrame.Offset = c.Ebp; + s.AddrFrame.Mode = AddrModeFlat; + + memset( pSym, '\0', IMGSYMLEN + MAXNAMELEN ); + pSym->SizeOfStruct = IMGSYMLEN; + pSym->MaxNameLength = MAXNAMELEN; + + memset( &Line, '\0', sizeof Line ); + Line.SizeOfStruct = sizeof Line; + + memset( &Module, '\0', sizeof Module ); + Module.SizeOfStruct = sizeof Module; + + offsetFromSymbol = 0; + + for ( frameNum = 0; ;) + { + // get next stack frame (StackWalk(), SymFunctionTableAccess(), SymGetModuleBase()) + // if this returns ERROR_INVALID_ADDRESS (487) or ERROR_NOACCESS (998), you can + // assume that either you are done, or that the stack is so hosed that the next + // deeper frame could not be found. + if ( ! StackWalk( imageType, hProcess, hThread, &s, &c, NULL, + SymFunctionTableAccess, SymGetModuleBase, NULL ) ) + break; + + if ( s.AddrPC.Offset != 0 ) + { // we seem to have a valid PC + // show procedure info (SymGetSymFromAddr()) + if ( ! SymGetSymFromAddr( hProcess, s.AddrPC.Offset, &offsetFromSymbol, pSym ) ) + { + break; + } + else + { + // UnDecorateSymbolName() + UnDecorateSymbolName( pSym->Name, undFullName, MAXNAMELEN, UNDNAME_COMPLETE ); + if (!frameNum && strstr(undFullName, "Exception")) + continue; + _stk += undFullName; + } + } // we seem to have a valid PC + + // no return address means no deeper stackframe + if ( s.AddrReturn.Offset == 0 ) + { + // avoid misunderstandings in the printf() following the loop + SetLastError( 0 ); + break; + } + ++frameNum; + } + + // de-init symbol handler etc. (SymCleanup()) + SymCleanup( hProcess ); + free( pSym ); +tagCleanUp:; + delete [] tt; +} + +GenericCallStack::~GenericCallStack() +{ +} + +const GStringList *GenericCallStack::GetStack() +{ + return &_stk; +} + +const char *GenericCallStack::GetStackAsString() +{ + _strStk.Empty(); + GStringIterator it(&_stk); + + while (it()) + { + if (!_strStk.IsEmpty()) + _strStk += "\n"; + _strStk += it++; + } + + return (const char *)_strStk; +} + +#endif + +GenericException::GenericException(int nError, int nSubSystem, const char *pzText, GStringList *pStack) +{ + _error = nError; + _subSystem = nSubSystem; + _cause = 0; + this->Format("%s",pzText); + + if (pStack) + { + GStringIterator it(pStack); + while (it()) + _stk.AddLast(it++); + } +} + +void GenericException::AddErrorDetail(int nError, const char *pzErrorText) +{ + GString strTemp; + strTemp.Format("[Error %ld] %s\n",nError,pzErrorText); + _ErrorDetail.AddLast(strTemp); +} + + +void GenericException::AddErrorDetail(const char* szSystem, int error, ...) +{ + int nSubSystem = 0; + int nError = error; + try + { + GProfile &ErrorProfile = GetErrorProfile(); + nSubSystem = atoi(ErrorProfile.GetString(szSystem, "SubSystem")); + + GString strKey; + strKey.Format("%ld", error); + strKey = ErrorProfile.GetString(szSystem, (const char *)strKey); + + GString strTemp; + va_list argList; + va_start(argList, error); + strTemp.FormatV((const char *)strKey, argList); + va_end(argList); + + GString strAddedToUserStack; + strAddedToUserStack.Format("[Error %ld:%ld] %s\n", nSubSystem, nError, (const char *)strTemp); + _ErrorDetail.AddLast(strAddedToUserStack); + + } + catch (GenericException &e) + { + _subSystem = e._subSystem; + _error = e._error; + + Format("%s", (const char *)e); + return; + } +} + + +GenericException::GenericException(const char* szSystem, int error, ...) +{ + _subSystem = 0; + _error = error; + + try + { + GProfile &ErrorProfile = GetErrorProfile(); + _subSystem = atoi(ErrorProfile.GetString(szSystem, "SubSystem")); + GString strKey; + strKey.Format("%ld", error); + strKey = ErrorProfile.GetString(szSystem, (const char *)strKey); + + va_list argList; + va_start(argList, error); + FormatV((const char *)strKey, argList); + va_end(argList); + } + catch (GenericException &e) + { + _subSystem = e._subSystem; + _error = e._error; + + Format("%s", (const char *)e); + return; + } + +} + +GenericException::GenericException(const GenericException &cpy) +{ + _subSystem = cpy._subSystem; + _error = cpy._error; + _ErrorDetail = cpy._ErrorDetail; + Format("%s", (const char *)cpy); +} + +GenericException::GenericException(int error, const char *str) +{ + _subSystem = 0; + _error = error; + Format("%s", str); +} + +GenericException::GenericException() +{ + _subSystem = 0; +} + +GenericException::~GenericException() +{ +} + +const char *GenericException::GetDescription() +{ + // Get the user stack into strUserStack + GString strUserStack; + GStringIterator it(&_ErrorDetail); + while (it()) + { + strUserStack += it++; + if (it()) + strUserStack += "\n"; + } + + _ret.Format("[Error %ld:%ld] %s\n%s", _subSystem, _error, (const char *)*this, (const char *)strUserStack); + return (const char *)_ret; +} + + +const char *GenericException::ToXML(const char *pzExceptionParent/* = "TransactResultSet"*/) +{ + _ret.Empty(); + + // Get the user stack into strUserStack + GString strUserStack; + GStringIterator it(&_ErrorDetail); + while (it()) + { + strUserStack += "\t\t"; + strUserStack.AppendEscapeXMLReserved(it++); + strUserStack += ""; + if (it()) + strUserStack += "\n"; + } + + + GString strDescription = (const char *)*this; + strDescription.EscapeXMLReserved(); + + + _ret.Format("<%s>\n\t\n\t\t%s\n\t\t" + "%ld\n\t\t%d\n%s\t", + pzExceptionParent, + (const char *)strDescription, + _error, + _subSystem, + (const char *)strUserStack, + pzExceptionParent); + + + return (const char *)_ret; +} + +long GenericException::GetCause() +{ + _cause = _subSystem; + _cause <<= 4; + _cause |= _error; + + return _cause; +} + +const GStringList *GenericException::GetStack() +{ + return &_stk; +} + +const char *GenericException::GetStackAsString() +{ + _ret.Empty(); + + if (_stk.isEmpty()) + { + _ret = "Call stack unavailable."; + } + else + { + GStringIterator it(&_stk); + + while (it()) + { + if (!_ret.IsEmpty()) + _ret += "\n"; + _ret += it++; + } + } + + return (const char *)_ret; +} diff --git a/ref/vt-ex/src/profile/GList.cpp b/ref/vt-ex/src/profile/GList.cpp new file mode 100644 index 0000000..7954416 --- /dev/null +++ b/ref/vt-ex/src/profile/GList.cpp @@ -0,0 +1,353 @@ +#include "pch.h" +// -------------------------------------------------------------------------- +// www.UnitedBusinessTechnologies.com +// Copyright (c) 1998 - 2002 All Rights Reserved. +// +// Source in this file is released to the public under the following license: +// -------------------------------------------------------------------------- +// This toolkit may be used free of charge for any purpose including corporate +// and academic use. For profit, and Non-Profit uses are permitted. +// +// This source code and any work derived from this source code must retain +// this copyright at the top of each source file. +// +// UBT welcomes any suggestions, improvements or new platform ports. +// email to: XMLFoundation@UnitedBusinessTechnologies.com +// -------------------------------------------------------------------------- + +#include "GList.h" + +void GList::AppendList(const GList *pListToCopy) +{ + if (pListToCopy) + { + GListIterator it( pListToCopy ); + while (it()) + { + void *p = (void *)it++; + AddLast(p); + } + } +} + +GList::GList(const GList &cpy) +{ + AppendList(&cpy); +} + +void GList::operator=(const GList &cpy) +{ + AppendList(&cpy); +} + +#include +GList::GList() +{ + // constructs an initially empty list + FirstNode = LastNode = CurrentNode = 0; + iSize = 0; +} + +GList::~GList() +{ +// inline RemoveAll(); + while (FirstNode) + { + // inline RemoveFirst() + if (CurrentNode == FirstNode) CurrentNode = FirstNode->NextNode; + if (LastNode == FirstNode) LastNode = 0; + Node *Save = FirstNode->NextNode; + delete FirstNode; + FirstNode = Save; + iSize--; + } + +} + +void * GList::First() const +{ + if (!FirstNode) + { + return 0; + } + GList *pThis = (GList *)this; + pThis->CurrentNode = FirstNode; + return FirstNode->Data; +} + +void * GList::Last() const +{ + if (!LastNode) + { + return 0; + } + GList *pThis = (GList *)this; + pThis->CurrentNode = LastNode; + return LastNode->Data; +} + +void * GList::Current() const +{ + if (!CurrentNode) + { + return 0; + } + return CurrentNode->Data; +} + +void * GList::Next() const +{ + if (!CurrentNode) + { + return 0; + } + GList *pThis = (GList *)this; + pThis->CurrentNode = CurrentNode->NextNode; + return Current(); +} + +void * GList::Previous() const +{ + if (!CurrentNode) + { + return 0; + } + GList *pThis = (GList *)this; + pThis->CurrentNode = CurrentNode->PrevNode; + return Current(); +} + +void * GList::Tail() const +{ + if (!CurrentNode) + { + return 0; + } + return CurrentNode->NextNode->Data; +} + +void GList::AddBeforeCurrent( void * Data ) +{ +// Add maintains list integrity by adding the new node before the current +// node, if the current node is the first node, the new node becomes the +// first node. + Node *pN; + pN = new Node(CurrentNode, 0); + if (FirstNode == 0) + FirstNode = LastNode = CurrentNode = pN; + if (FirstNode->PrevNode) + FirstNode = FirstNode->PrevNode; + iSize++; + pN->Data = Data; +} + +void GList::AddAfterCurrent( void * Data ) +{ +// AddLast maintains list integrity by adding the new node after the current +// node, if the current node is the last node, the new node becomes the last +// node. + Node *pN; + pN = new Node(CurrentNode); + if (FirstNode == 0) + FirstNode = LastNode = CurrentNode = pN; + if (LastNode->NextNode) + LastNode = LastNode->NextNode; + iSize++; + pN->Data = Data; +} + +void GList::AddHead( void * Data) +{ +// AddHead maintains list integrity by making the new node the first node. + Node *pN; + pN = new Node(FirstNode, 0); + if (LastNode == 0) + LastNode = CurrentNode = pN; + iSize++; + pN->Data = Data; + FirstNode = pN; +} + +void GList::AddLast( void * Data) +{ +// AddLast maintains list integrity by making the new node the last node. +// Node *pN = m_nodePool.getNode(LastNode); + Node *pN = new Node(LastNode); + if (FirstNode == 0) + FirstNode = CurrentNode = pN; + iSize++; + pN->Data = Data; + LastNode = pN; +} + +void GList::Remove(void *Data) +{ + void *p = First(); + while(p) + { + if (p == Data) + { + RemoveCurrent(); + break; + } + p = Next(); + } +} + +void GList::RemoveAll() +{ + while (FirstNode) + { + // inline RemoveFirst() + if (CurrentNode == FirstNode) CurrentNode = FirstNode->NextNode; + if (LastNode == FirstNode) LastNode = 0; + Node *Save = FirstNode->NextNode; + delete FirstNode; + FirstNode = Save; + iSize--; + } +} + +void GList::RemoveFirst() +{ +// RemoveFirst maintains list integrity by making the first node the node +// after the first node. If the first node is the only node in the list, +// removing it produces an empty list. + if (FirstNode) + { + if (CurrentNode == FirstNode) CurrentNode = FirstNode->NextNode; + if (LastNode == FirstNode) LastNode = 0; + Node *Save = FirstNode->NextNode; + delete FirstNode; + FirstNode = Save; + iSize--; + } +} + +void * GList::RemoveLast() +{ + void *ret = 0; + + if (LastNode) + { + ret = LastNode->Data; + + if (CurrentNode == LastNode) + CurrentNode = LastNode->PrevNode; + if (FirstNode == LastNode) + FirstNode = 0; + Node *Save = LastNode->PrevNode; + +// m_nodePool.releaseNode(LastNode); + delete LastNode; + + LastNode = Save; + iSize--; + } + + return ret; +} + +void GList::RemoveCurrent() +// RemoveCurrent maintains list integrity by making the current node +// the next node if it exists, if there is not a next node, current node +// becomes the previous node if it exists, otherwise, current = NULL. +// If the current node is also the first node, then the first node becomes +// the next node by default. If the current node is also the last node, +// then the last node becomes the previous node by default. If current == +// last == first, then removing the current node produces an empty list +// and current = first = last = NULL. +{ + if (CurrentNode) + { + Node *Save; + if (!CurrentNode->PrevNode) FirstNode = CurrentNode->NextNode; + if (CurrentNode->NextNode) Save = CurrentNode->NextNode; + else if (CurrentNode->PrevNode) Save = LastNode = CurrentNode->PrevNode; + else Save = FirstNode = LastNode = 0; + delete CurrentNode; + CurrentNode = Save; + iSize--; + } +} + +void GList::RemoveNext() +{ +// RemoveNext maintains list integrity by checking if the next node is the +// last node, if this is the case, then the last node becomes the current +// node. + if (CurrentNode) + { + if (CurrentNode->NextNode) + { + if (!CurrentNode->NextNode->NextNode) LastNode = CurrentNode; + Node * DeleteNode = CurrentNode->NextNode; + delete DeleteNode; + iSize--; + } + } +} + +void GList::RemovePrevious() +{ +// RemovePrevious maintains list integrity by checking if the next node is +// the first node, if this is the case, then the first node becomes the +// current node. + if (CurrentNode) + { + if (CurrentNode->PrevNode) + { + if (!CurrentNode->PrevNode->PrevNode) FirstNode = CurrentNode; + Node * DeleteNode = CurrentNode->PrevNode; + delete DeleteNode; + iSize--; + } + } +} + +void GList::SetCurrent(Node *p) +{ + CurrentNode = p; +} + +GListIterator::GListIterator(const GList *iList, int IterateFirstToLast) +{ + pTList = (GList *)iList; + iDataNode = 0; + if (pTList) + { + if (IterateFirstToLast) + iDataNode = (GList::Node *)((GList *)iList)->FirstNode; + else + iDataNode = ((GList *)iList)->LastNode; + } +} + +void GListIterator::reset(int IterateFirstToLast /* = 1 */) +{ + if (IterateFirstToLast) + iDataNode = (GList::Node *)((GList *)pTList)->FirstNode; + else + iDataNode = ((GList *)pTList)->LastNode; +} + +void * GListIterator::operator ++ (int) +{ + void *pRet = iDataNode->Data; + iCurrentNode = iDataNode; + iDataNode = iDataNode->NextNode; + return pRet; +} + +void * GListIterator::operator -- (int) +{ + void *pRet = iDataNode->Data; + iCurrentNode = iDataNode; + iDataNode = iDataNode->PrevNode; + return pRet; +} + +int GListIterator::operator () (void) const +{ + return iDataNode != 0; +} diff --git a/ref/vt-ex/src/profile/GProfile.cpp b/ref/vt-ex/src/profile/GProfile.cpp new file mode 100644 index 0000000..d2cc5a9 --- /dev/null +++ b/ref/vt-ex/src/profile/GProfile.cpp @@ -0,0 +1,523 @@ +#include "pch.h" +#include "GProfile.h" +#include "GException.h" +#include "DirectoryListing.h" +#include //for: memcpy() + +#ifndef _WIN32 + #include +#endif + + +#ifdef _WIN32 + #include +#endif + +static GProfile *g_AlternateProfile = 0; +GProfile *SetProfile(GProfile *pApplicationProfile) +{ + GProfile *pReturn = g_AlternateProfile; + g_AlternateProfile = pApplicationProfile; + return pReturn; +} + +GProfile &GetProfile() +{ + static GProfile *s_pDefaultProfile = 0; + if (g_AlternateProfile) + return *g_AlternateProfile; + if (!s_pDefaultProfile) + s_pDefaultProfile = new GProfile ("txml.txt","XML_CONFIG_FILE"); + return *s_pDefaultProfile; +} + + +GProfile::GProfile(const char *pzFileName, const char *pzEnvOverride ) + : m_bCached(0) +{ + m_strEnvOverride = pzEnvOverride; + m_strBaseFileName = pzFileName; // no path + + GString strConfigFileDefault; +#ifdef _WIN32 // like "txml.txt" + strConfigFileDefault.Format("c:\\%s",pzFileName); +#else + strConfigFileDefault.Format("/%s",pzFileName); +#endif + // env var like "XML_CONFIG_FILE" + if (getenv(pzEnvOverride)) + // Use the system environment setting + m_strFile = getenv(pzEnvOverride); + else + // Use the default + m_strFile = strConfigFileDefault; +} + + +// +// load the profile configuration file yourself, +// and create this object "with no disk config file" +GProfile::GProfile(const char *szBuffer, long dwSize) +{ + ProfileParse(szBuffer, dwSize); +} + + +// create a profile from the supplied file name +GProfile::GProfile(const char *pzFilePathAndName ) + : m_bCached(0) +{ + m_strEnvOverride = "NONE"; + m_strBaseFileName = CDirectoryListing::LastLeaf(pzFilePathAndName); //"txml.txt"; + + if (pzFilePathAndName && pzFilePathAndName[0]) + // use the supplied pzFilePathAndName + m_strFile = pzFilePathAndName; + +} + + +GProfile::~GProfile() +{ + Destroy(); +} + +void GProfile::Destroy() +{ + GListIterator itSections(&m_lstSections); + while (itSections()) + { + Section *pSection = (Section *)itSections++; + + GListIterator itNVP(&pSection->m_lstNVP); + while (itNVP()) + { + NameValuePair *pNVP = (NameValuePair *)itNVP++; + delete pNVP; + } + + delete pSection; + } + + m_lstSections.RemoveAll(); +} + +#ifdef _WIN32 +void GProfile::ThrowLastError(const char *pzFile) +{ + LPVOID lpMsgBuf; + + DWORD dwExp = GetLastError(); + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + dwExp, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpMsgBuf, + 0, + NULL + ); + + GString strTemp = (char *)lpMsgBuf; + strTemp.TrimRightWS(); + + GString strFile; + strFile.Format("%s - %s", (const char *)strTemp,pzFile); + GenericException exp(dwExp,(const char *)strFile); + LocalFree( lpMsgBuf ); + throw exp; +} +#endif + +void GProfile::GetLine(GString &strLine, + const char *szBuffer, + int *nIdx, + int dwSize) +{ + strLine.Empty(); + + while (*nIdx < dwSize) + { + if (szBuffer[*nIdx] == '\n') + break; + + strLine += szBuffer[*nIdx]; + (*nIdx)++; + } + + (*nIdx)++; +} + +void GProfile::ProfileParse(const char *szBuffer, long dwSize) +{ + Section *pSection = 0; + + // parse the file + int nIdx = 0; + while (nIdx < dwSize) + { + GString strLine; + GetLine(strLine, szBuffer, &nIdx, dwSize); + + + strLine.TrimRightWS(); + strLine.TrimLeftWS(); + if ((strLine.IsEmpty()) || (strLine[0] == ';')) + continue; + + + strLine.Replace("\\n", '\n'); + + if (strLine[0] == '[') + { + int nIdx = strLine.Find(']'); + if (nIdx == -1) + nIdx = strLine.Length(); + + // new section + pSection = new Section; + pSection->m_strName = strLine.Mid(1, nIdx - 1); + pSection->m_strName.TrimLeftWS(); + pSection->m_strName.TrimRightWS(); + + m_lstSections.AddLast(pSection); + } + else if (pSection) + { + int nIdx = strLine.Find('='); + if (nIdx == -1) + continue; + NameValuePair *pNVP = new NameValuePair; + pSection->m_lstNVP.AddLast(pNVP); + pNVP->m_strName = strLine.Left(nIdx); + pNVP->m_strName.TrimLeftWS(); + pNVP->m_strName.TrimRightWS(); + + pNVP->m_strValue = strLine.Mid(nIdx + 1); + pNVP->m_strValue.TrimLeftWS(); + pNVP->m_strValue.TrimRightWS(); + } + } + m_bCached = true; +} + +void GProfile::Load() +{ + if (m_bCached) + return; + + // destroy the cached objects + Destroy(); + + char *szBuffer = 0; + long dwSize = 0; + + + +#ifdef _WIN32 + + // open the file + HANDLE hFile = CreateFile((const char *)m_strFile, + GENERIC_READ, 0, 0, OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, 0); + + dwSize = GetFileSize(hFile, NULL); + + szBuffer = new char[dwSize + 1]; + + // read the file + long dwRead; + if (!ReadFile(hFile, szBuffer, dwSize, (DWORD *)&dwRead, 0)) + { + delete [] szBuffer; + CloseHandle(hFile); + } + + // close the file + CloseHandle(hFile); + + +#else + // open the file + GString strTemp; + int nResult = strTemp.FromFile((const char *)m_strFile, 0); + + szBuffer = new char[strTemp.Length() + 1]; + memcpy(szBuffer,(const char *)strTemp, strTemp.Length()); + dwSize = strTemp.Length(); + +#endif + + + // terminate the buffer + //szBuffer[dwSize] = 0; + + ProfileParse(szBuffer, dwSize); + + delete [] szBuffer; + +} + +GProfile::Section *GProfile::FindSection(const char *szSection) +{ + Load(); + + Section *pRet = 0; + + GListIterator itSections(&m_lstSections); + while ( itSections() && (!pRet)) + { + Section *pSection = (Section *)itSections++; + + if (pSection->m_strName.CompareNoCase(szSection) == 0) + pRet = pSection; + } + + return pRet; +} + +GProfile::NameValuePair *GProfile::FindKey(const char *szKey, GProfile::Section *pSection) +{ + NameValuePair *pRet = 0; + + if (pSection) + { + GListIterator itNVP(&pSection->m_lstNVP); + while ((itNVP()) && (!pRet)) + { + NameValuePair *pNVP = (NameValuePair *)itNVP++; + if (pNVP->m_strName.CompareNoCase(szKey) == 0) + pRet = pNVP; + } + } + + return pRet; +} + +// function retrieves the names of all sections +void GProfile::GetSectionNames(GStringList *lpList) +{ + Load(); + + if (lpList) + { + GListIterator itSections(&m_lstSections); + while (itSections()) + { + Section *pSection = (Section *)itSections++; + lpList->AddLast(pSection->m_strName); + } + } +} + +const GList *GProfile::GetSection(const char *szSectionName) +{ + Section *pSection = FindSection(szSectionName); + + if (pSection) + return &pSection->m_lstNVP; + + return 0; +} + + +// written by sean, not sure what this is about... +static bool IsTrue(char chValue) +{ + bool bRet; + + if (chValue > '1') + bRet = ((chValue & 0x10) != 0); + else + bRet = ((chValue & 0x01) != 0); + + return bRet; +} + +// function retrieves a boolean from the specified section +short GProfile::GetBool(const char *szSectionName, const char *szKey, short bThrowNotFound /* = true */) +{ + Section *pSection = FindSection(szSectionName); + if (pSection) + { + NameValuePair *pNVP = FindKey(szKey, pSection); + if (pNVP) + { + char chTest = '0'; + if (!pNVP->m_strValue.IsEmpty()) + chTest = pNVP->m_strValue[0]; + return IsTrue(chTest); + } + else if (bThrowNotFound) + { + // throw key not found + + } + } + else if (bThrowNotFound) + { + + } + + return 0; +} + +// function retrieves a boolean from the specified section +short GProfile::GetBoolean(const char *szSectionName, const char *szKey, short bThrowNotFound /* = true */) +{ + Section *pSection = FindSection(szSectionName); + if (pSection) + { + NameValuePair *pNVP = FindKey(szKey, pSection); + if (pNVP) + { + if (pNVP->m_strValue.CompareNoCase("true") == 0 || + pNVP->m_strValue.CompareNoCase("on") == 0 || + pNVP->m_strValue.CompareNoCase("yes") == 0 || + pNVP->m_strValue.CompareNoCase("1") == 0) + { + return 1; + } + else + { + return 0; + } + } + else if (bThrowNotFound) + { + + } + } + else if (bThrowNotFound) + { + // throw key not found + + } + + return 0; +} + + +// function retrieves a long from the specified section +long GProfile::GetLong(const char *szSectionName, const char *szKey, short bThrowNotFound /* = true */) +{ + Section *pSection = FindSection(szSectionName); + if (pSection) + { + NameValuePair *pNVP = FindKey(szKey, pSection); + if (pNVP) + { + if (!pNVP->m_strValue.IsEmpty()) + return atol((const char *)pNVP->m_strValue); + } + else if (bThrowNotFound) + { + // throw key not found + + } + } + else if (bThrowNotFound) + { + // throw key not found + + } + + return 0; +} + +const char *GProfile::GetPath(const char *szSectionName, const char *szKey, short bThrowNotFound) +{ + Section *pSection = FindSection(szSectionName); + if (pSection) + { + NameValuePair *pNVP = FindKey(szKey, pSection); + if (pNVP) + { + if ( !( pNVP->m_strValue.Right(1) == "/" || pNVP->m_strValue.Right(1) == "\\") ) + { + #ifdef _WIN32 + pNVP->m_strValue += "\\"; + #else + pNVP->m_strValue += "/"; + #endif + } + return pNVP->m_strValue; + } + else if (bThrowNotFound) + { + // throw key not found + + } + } + else if (bThrowNotFound) + { + // throw key not found + + } + + return 0; +} + +// function retrieves a string from the specified section +const char *GProfile::GetString(const char *szSectionName, const char *szKey, short bThrowNotFound /* = true */) +{ + Section *pSection = FindSection(szSectionName); + if (pSection) + { + NameValuePair *pNVP = FindKey(szKey, pSection); + if (pNVP) + { + return (const char *)pNVP->m_strValue; + } + else if (bThrowNotFound) + { + // throw key not found + + } + } + else if (bThrowNotFound) + { + // throw key not found + + } + + return 0; +} + +void GProfile::SetString(const char *szSectionName, const char *szKey, const char *szValue) +{ + m_bCached = true; + + Section *pSection = FindSection(szSectionName); + if (!pSection) + { + pSection = new Section; + pSection->m_strName = szSectionName; + pSection->m_strName.TrimLeftWS(); + pSection->m_strName.TrimRightWS(); + + m_lstSections.AddLast(pSection); + } + + if (pSection) + { + NameValuePair *pNVP = FindKey(szKey, pSection); + if (!pNVP) + { + pNVP = new NameValuePair; + pSection->m_lstNVP.AddLast(pNVP); + pNVP->m_strName = szKey; + pNVP->m_strName.TrimLeftWS(); + pNVP->m_strName.TrimRightWS(); + } + + if (pNVP) + { + pNVP->m_strValue = szValue; + pNVP->m_strValue.TrimLeftWS(); + pNVP->m_strValue.TrimRightWS(); + } + } +} diff --git a/ref/vt-ex/src/profile/GString.cpp b/ref/vt-ex/src/profile/GString.cpp new file mode 100644 index 0000000..4be95f9 --- /dev/null +++ b/ref/vt-ex/src/profile/GString.cpp @@ -0,0 +1,2621 @@ +// -------------------------------------------------------------------------- +// www.UnitedBusinessTechnologies.com +// Copyright (c) 1998 - 2002 All Rights Reserved. +// +// Source in this file is released to the public under the following license: +// -------------------------------------------------------------------------- +// This toolkit may be used free of charge for any purpose including corporate +// and academic use. For profit, and Non-Profit uses are permitted. +// +// This source code and any work derived from this source code must retain +// this copyright at the top of each source file. +// +// UBT welcomes any suggestions, improvements or new platform ports. +// email to: XMLFoundation@UnitedBusinessTechnologies.com +// -------------------------------------------------------------------------- +#include "pch.h" +#include "GString.h" +#include "GException.h" + +#include // for: memcpy(), strlen(), strcmp(), memmove(), strchr(), + // strstr(), strncmp() +#include // for: isdigit() +#include // for: atof(), atoi(), atol(), abs(), and strtol() +#include // for: sprintf(), vsprintf(), FILE, fopen(), fwrite(), + // fclose(), fseek(), fread() +#include // for: va_start(), va_end */ + + +// Global default format specifiers that affect all GStrings +GString GString::g_FloatFmt("%.6g"); +GString GString::g_DoubleFmt("%.6g"); +GString GString::g_LongDoubleFmt("%.6Lg"); + + + +#ifndef _WIN32 + #ifndef __int64 + #define __int64 long long + #endif +#endif + + + +static void x64toa ( + unsigned __int64 val, + char *buf, + unsigned radix, + int is_neg + ) +{ + char *p; /* pointer to traverse string */ + char *firstdig; /* pointer to first digit */ + char temp; /* temp char */ + unsigned digval; /* value of digit */ + + p = buf; + + if ( is_neg ) + { + *p++ = '-'; /* negative, so output '-' and negate */ + val = (unsigned __int64)(-(__int64)val); + } + + firstdig = p; /* save pointer to first digit */ + + do { + digval = (unsigned) (val % radix); + val /= radix; /* get next digit */ + + /* convert to ascii and store */ + if (digval > 9) + *p++ = (char) (digval - 10 + 'a'); /* a letter */ + else + *p++ = (char) (digval + '0'); /* a digit */ + } while (val > 0); + + /* We now have the digit of the number in the buffer, but in reverse + order. Thus we reverse them now. */ + + *p-- = '\0'; /* terminate string; p points to last digit */ + + do { + temp = *p; + *p = *firstdig; + *firstdig = temp; /* swap *p and *firstdig */ + --p; + ++firstdig; /* advance to next two digits */ + } while (firstdig < p); /* repeat until halfway */ +} + + +// long long to ascii +char * lltoa ( __int64 val,char *buf,int radix) +{ + x64toa((unsigned __int64)val, buf, radix, (radix == 10 && val < 0)); + return buf; +} + + + + + +#define CommonConstruct(nInitialSize) \ + _str = 0; \ + _len = 0; \ + _strIsOnHeap = 0; \ + _max = nInitialSize; \ + if (nInitialSize == 256) \ + _str = _initialbuf; \ + else \ + { \ + _initialbuf[0] = 0; \ + _str = new char[nInitialSize]; \ + _strIsOnHeap = 1; \ + } \ + if (!_str) \ + throw GenericException("String", 0); \ + _str[_len] = 0; + + +void GString::AppendEscapeXMLReserved(const char *Src, int nLen/* = -1*/) +{ + const unsigned char *src = (const unsigned char *)Src; + while (*src && (nLen != 0)) + { + if (nLen != -1) // -1 means to append until a null in src + nLen--; + + switch (*src) + { + case '<' : + case '>' : + case '&' : + case '"' : + case '\'' : + this->write("&#",2); + (*this) += (unsigned int)(unsigned char)*src; + (*this) += ';'; + break; + default : + // IE can't deal with special chars(éâåçêëè....) so escape them too + if ((*src > 127) || (*src < 32)) + { + this->write("&#",2); + (*this) += (unsigned int)(unsigned char)*src; + (*this) += ';'; + break; + + } + else // most cases, append normal char to this GString + { + // inline operator += code + if (_len >= _max) + resize(); + _str[_len] = *src; + _len++; + + if (_len >= _max) + resize(); + _str[_len] = 0; + } + break; + } + src++; + } +} + +void GString::AppendXMLTabs( int nTabs ) +{ + static const char* TABS = + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t" + "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t"; + const int MAX_TABS = 80; + + + if (_len) +#ifdef _WIN32 + (*this) << "\r\n"; +#else + (*this) << "\n"; +#endif + + + write( TABS, (nTabs > MAX_TABS) ? MAX_TABS : nTabs ); +} + + +void GString::EscapeXMLReserved() +{ + GString str_xml( Length() + 1024 ); + const unsigned char *src = (const unsigned char *)(const char *)(*this); + + while (*src) + { + switch (*src) + { + case '<' : + case '>' : + case '&' : + case '"' : + case '\'' : + str_xml << "&#" << (unsigned int)*src << ';'; + break; + default : + if ((*src > 127) || (*src < 32)) + { + str_xml << "&#" << (unsigned int)((unsigned char)*src) << ';'; + } + else + { + str_xml << *src; + } + break; + } + src++; + } + + (*this) = str_xml; +} + + +void GString::resize() +{ + // double the size of the buffer + _max <<= 1; + char *nstr = new char[_max]; + + // not enough memory for resize + if (!nstr) + throw GenericException("String", 0); + + nstr[0] = 0; + + if (_str) + { + memcpy(nstr, _str, _len); + if (_strIsOnHeap) + delete [] _str; + } + + _str = nstr; + _strIsOnHeap = 1; + _initialbuf[0] = 0; +} + +// constructs an empty string +GString::GString(long nInitialSize) +{ + CommonConstruct(nInitialSize); +} + +// constructs a copy of the source string +GString::GString(const GString &src ) +{ + long l = (src._len > 256) ? src._len + 256 : 256; + CommonConstruct( l ); + + _len = ___min(_max, src._len); + memcpy(_str, src._str, _len); + _str[_len] = 0; +} + +GString::GString(const GString &src, int nCnt) +{ + long l = (src._len > 256) ? src._len + 256 : 256; + CommonConstruct(l); + + _len = ___min(_max, ___min(src._len, nCnt)); + memcpy(_str, src._str, _len); + _str[_len] = 0; +} + +// constructs a copy of the character string +GString::GString(const char *src) +{ + long srcLen = (src) ? strlen(src) : 256; + long nInitialSize = (srcLen > 256) ? srcLen + 256 : 256; + + CommonConstruct(nInitialSize); + + while (src && *src) + { + _str[_len] = *src; + _len++; + src++; + if (_len >= _max) + resize(); + } + if (_len >= _max) + resize(); + _str[_len] = 0; +} + + + +GString::GString(const char *src, int nCnt) +{ + long nInitialSize = (nCnt > 256) ? nCnt + 256 : 256; + + CommonConstruct(nInitialSize); + + _len = 0; + if (src) + { + int i; + _len = ___min(_max - 1, nCnt); + for (i = 0; i < _len && src[i]; i++) + _str[i] = src[i]; + _len = i; + } + + _str[_len] = 0; +} + +// constructs a string with ch repeated nCnt times +GString::GString(char ch, short nCnt) +{ + long nInitialSize = (nCnt > 256) ? nCnt + 256 : 256; + + CommonConstruct(nInitialSize); + + _len = ___min(_max - 1, nCnt); + int i; + for (i = 0; i < _len; i++) + _str[i] = ch; + + _len = i; + _str[_len] = 0; +} + +GString::~GString() +{ + if (_strIsOnHeap) + delete [] _str; +} +/* +.h declaration: GString & operator=(const strstreambuf &); + +GString & GString::operator=(const strstreambuf &buf) +{ + _max = ((strstreambuf &)buf).seekoff(0, ios::cur, ios::in | ios::out) + 1; + char *nstr = new char[_max]; + + // not enough memory for resize + if (!nstr) + throw GenericException("String", 0); + + nstr[0] = 0; + + if (_str) + { + if (_strIsOnHeap) + delete [] _str; + } + + _str = nstr; + _strIsOnHeap = 1; + _initialbuf[0] = 0; + + _len = _max - 1; + strncpy(_str, ((strstreambuf &)buf).str(), _len); + _str[_len] = 0; + ((strstreambuf &)buf).freeze(0); + + return *this; +}*/ + +GString & GString::operator=(char _p) +{ + if (!_max) + { + _max = 2; + resize(); + } + + _len = 0; + _str[_len] = _p; + _len++; + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(__int64 _p) +{ + char szBuffer[256]; +// sprintf(szBuffer, "%I64d", _p); + lltoa ( _p,szBuffer,10); + + + int nLen = strlen(szBuffer); + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(const char * _p) +{ + _len = 0; + while (_p && *_p) + { + if (_len >= _max) + resize(); + _str[_len] = *_p; + _p++; + _len++; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(const signed char * _p) +{ + *this = (const char *)_p; + + return *this; +} + +GString & GString::operator=(unsigned char _p) +{ + *this = (char)_p; + + return *this; +} + +GString & GString::operator=(signed char _p) +{ + *this = (char)_p; + + return *this; +} + +GString & GString::operator=(short _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%hi", _p); + + int nLen = strlen(szBuffer); + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(unsigned short _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%hu", _p); + + int nLen = strlen(szBuffer); + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(int _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%li", _p); + + int nLen = strlen(szBuffer); + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(unsigned int _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%lu", _p); + + int nLen = strlen(szBuffer); + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(long _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%li", _p); + + int nLen = strlen(szBuffer); + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(unsigned long _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%lu", _p); + + int nLen = strlen(szBuffer); + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(float _p) +{ + char szBuffer[50]; + sprintf(szBuffer, g_FloatFmt._str, _p); + int nLen = strlen(szBuffer); + + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + + + +GString & GString::operator=(double _p) +{ + char szBuffer[50]; + sprintf(szBuffer, "%.6g", _p); + int nLen = strlen(szBuffer); + + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(long double _p) +{ + char szBuffer[50]; + sprintf(szBuffer, "%.6Lg", _p); + int nLen = strlen(szBuffer); + + for (_len = 0; _len < nLen; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator=(const GString & _p) +{ + for (_len = 0; _len < _p._len; _len++) + { + if (_len >= _max) + resize(); + _str[_len] = _p._str[_len]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + + +GString & GString::operator+=(__int64 _p) +{ + char szBuffer[25]; +// sprintf(szBuffer, "%I64d", _p); + lltoa ( _p,szBuffer,10); + + int nLen = strlen(szBuffer); + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + + + +GString & GString::operator+=(const signed char * _p) +{ + while (_p && *_p) + { + if (_len >= _max) + resize(); + _str[_len] = *_p; + _p++; + _len++; + } + + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator+=(const char * _p) +{ + while (_p && *_p) + { + if (_len >= _max) + resize(); + _str[_len] = *_p; + _p++; + _len++; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + + +void GString::write(const char *p,int nSize) +{ + while (_len + nSize + 1 >= _max) + resize(); + memcpy(&_str[_len],p,nSize); + _len += nSize; + _str[_len] = 0; +} + +GString & GString::operator+=(char _p) +{ + if (_p) + { + if (_len >= _max) + resize(); + _str[_len] = _p; + _len++; + + if (_len >= _max) + resize(); + _str[_len] = 0; + } + + return *this; +} + +GString & GString::operator+=(unsigned char _p) +{ + if (_p) + { + if (_len >= _max) + resize(); + _str[_len] = _p; + _len++; + + if (_len >= _max) + resize(); + _str[_len] = 0; + } + + return *this; +} + +GString & GString::operator+=(signed char _p) +{ + if (_p) + { + if (_len >= _max) + resize(); + _str[_len] = _p; + _len++; + + if (_len >= _max) + resize(); + _str[_len] = 0; + } + + return *this; +} + +GString & GString::operator+=(short _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%hi", _p); + + int nLen = strlen(szBuffer); + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator+=(unsigned short _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%hu", _p); + + int nLen = strlen(szBuffer); + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator+=(int _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%li", _p); + + int nLen = strlen(szBuffer); + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator+=(unsigned int _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%lu", _p); + + int nLen = strlen(szBuffer); + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator+=(long _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%ld", _p); + + int nLen = strlen(szBuffer); + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator+=(unsigned long _p) +{ + char szBuffer[25]; + sprintf(szBuffer, "%lu", _p); + int nLen = strlen(szBuffer); + + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + + + return *this; +} + +GString & GString::operator+=(float _p) +{ + char szBuffer[50]; + sprintf(szBuffer, g_FloatFmt._str, _p); + int nLen = strlen(szBuffer); + + + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + + return *this; +} + +GString & GString::operator+=(double _p) +{ + char szBuffer[50]; + sprintf(szBuffer, "%.6g", _p); + int nLen = strlen(szBuffer); + + + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + + return *this; +} + +GString & GString::operator+=(long double _p) +{ + char szBuffer[50]; + sprintf(szBuffer, "%.6Lg", _p); + int nLen = strlen(szBuffer); + + + for (int i = 0; i < nLen; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = szBuffer[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + + return *this; +} + +GString & GString::operator+=(const GString & _p) +{ + while (_len + _p._len + 1 >= _max) + resize(); + memcpy(&_str[_len],_p._str,_p._len); + _len += _p._len; + _str[_len] = 0; + return *this; +/* + for (int i = 0; i < _p._len; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = _p._str[i]; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +*/ +} + +GString & GString::operator<<(__int64 _p) +{ + return *this += _p; +} + +GString & GString::operator<<(const char * _p) +{ + while (_p && *_p) + { + if (_len >= _max) + resize(); + _str[_len] = *_p; + _p++; + _len++; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; + + return *this; +} + +GString & GString::operator<<(const signed char * _p) +{ + return *this += _p; +} + +GString & GString::operator<<(char _p) +{ + if (_p) + { + if (_len >= _max) + resize(); + _str[_len] = _p; + _len++; + + if (_len >= _max) + resize(); + _str[_len] = 0; + } + return *this; +} + +GString & GString::operator<<(unsigned char _p) +{ + return *this += _p; +} + +GString & GString::operator<<(signed char _p) +{ + return *this += _p; +} + +GString & GString::operator<<(short _p) +{ + return *this += _p; +} + +GString & GString::operator<<(unsigned short _p) +{ + return *this += _p; +} + +GString & GString::operator<<(int _p) +{ + return *this += _p; +} + +GString & GString::operator<<(unsigned int _p) +{ + return *this += _p; +} + +GString & GString::operator<<(long _p) +{ + return *this += _p; +} + +GString & GString::operator<<(unsigned long _p) +{ + return *this += _p; +} + +GString & GString::operator<<(float _p) +{ + return *this += _p; +} + +GString & GString::operator<<(double _p) +{ + return *this += _p; +} + +GString & GString::operator<<(long double _p) +{ + return *this += _p; +} + + +GString & GString::operator<<(const GString & _p) +{ +// return *this += _p; + while (_len + _p._len + 1 >= _max) + resize(); + memcpy(&_str[_len],_p._str,_p._len); + _len += _p._len; + _str[_len] = 0; + return *this; +} + +GString operator+(GString &_p1, GString &_p2) +{ + GString strRet(_p1._len + _p2._len + 1); + int i; + for (i = 0; i < _p1._len; strRet._len++, i++) + strRet._str[strRet._len] = _p1._str[i]; + + for (i = 0; i < _p2._len; strRet._len++, i++) + strRet._str[strRet._len] = _p2._str[i]; + + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(GString &_p1, const char *_p2) +{ + GString strRet; + + for (int i = 0; i < _p1._len; strRet._len++, i++) + { + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = _p1._str[i]; + } + + while (_p2 && *_p2) + { + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = *_p2; + _p2++; + strRet._len++; + } + + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(const char *_p1, GString &_p2) +{ + GString strRet; + + while (_p1 && *_p1) + { + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = *_p1; + _p1++; + strRet._len++; + } + + for (int i = 0; i < _p2._len; strRet._len++, i++) + { + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = _p2._str[i]; + } + + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(GString &_p1, const signed char *_p2) +{ + GString strRet; + + for (int i = 0; i < _p1._len; strRet._len++, i++) + { + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = _p1._str[i]; + } + + while (_p2 && *_p2) + { + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = *_p2; + _p2++; + strRet._len++; + } + + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(const signed char *_p1, GString &_p2) +{ + GString strRet; + + while (_p1 && *_p1) + { + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = *_p1; + _p1++; + strRet._len++; + } + + for (int i = 0; i < _p2._len; strRet._len++, i++) + { + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = _p2._str[i]; + } + + if (strRet._len >= strRet._max) + strRet.resize(); + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(GString &_p1, char _p2) +{ + GString strRet(_p1._len + 2); + + for (int i = 0; i < _p1._len; strRet._len++, i++) + strRet._str[strRet._len] = _p1._str[i]; + + strRet._str[strRet._len] = _p2; + strRet._len++; + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(char _p1, GString &_p2) +{ + GString strRet(_p2._len + 2); + + strRet._str[strRet._len] = _p1; + strRet._len++; + + for (int i = 0; i < _p2._len; strRet._len++, i++) + strRet._str[strRet._len] = _p2._str[i]; + + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(GString &_p1, unsigned char _p2) +{ + GString strRet(_p1._len + 2); + + for (int i = 0; i < _p1._len; strRet._len++, i++) + strRet._str[strRet._len] = _p1._str[i]; + + strRet._str[strRet._len] = _p2; + strRet._len++; + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(unsigned char _p1, GString &_p2) +{ + GString strRet(_p2._len + 2); + + strRet._str[strRet._len] = _p1; + strRet._len++; + + for (int i = 0; i < _p2._len; strRet._len++, i++) + strRet._str[strRet._len] = _p2._str[i]; + + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(GString &_p1, signed char _p2) +{ + GString strRet(_p1._len + 2); + + for (int i = 0; i < _p1._len; strRet._len++, i++) + strRet._str[strRet._len] = _p1._str[i]; + + strRet._str[strRet._len] = _p2; + strRet._len++; + strRet._str[strRet._len] = 0; + + return strRet; +} + +GString operator+(signed char _p1, GString &_p2) +{ + GString strRet(_p2._len + 2); + + strRet._str[strRet._len] = _p1; + strRet._len++; + + for (int i = 0; i < _p2._len; strRet._len++, i++) + strRet._str[strRet._len] = _p2._str[i]; + + strRet._str[strRet._len] = 0; + + return strRet; +} + +//ostream& operator<<(ostream &os, GString &s) +//{ +// os << s._str; +// return os; +//} + +int GString::operator > (const GString &s) const +{ + return strcmp(_str, s._str) > 0; +} + +int GString::operator >= (const GString &s) const +{ + return strcmp(_str, s._str) >= 0; +} + +int GString::operator == (const GString &s) const +{ + return strcmp(_str, s._str) == 0; +} + +int GString::operator < (const GString &s) const +{ + return strcmp(_str, s._str) < 0; +} + +int GString::operator <= (const GString &s) const +{ + return strcmp(_str, s._str) <= 0; +} + +int GString::operator != (const GString &s) const +{ + return strcmp(_str, s._str) != 0; +} + +int GString::operator > (const char *s) const +{ + return strcmp(_str, s) > 0; +} + +int GString::operator >= (const char *s) const +{ + return strcmp(_str, s) >= 0; +} + +int GString::operator == (const char *s) const +{ + return strcmp(_str, s) == 0; +} + +int GString::operator < (const char *s) const +{ + return strcmp(_str, s) < 0; +} + +int GString::operator <= (const char *s) const +{ + return strcmp(_str, s) <= 0; +} + +int GString::operator != (const char *s) const +{ + return strcmp(_str, s) != 0; +} + +int GString::Compare(const char *s) const +{ + return strcmp(_str, s); +} + +int GString::Compare(GString &s) const +{ + return strcmp(_str, s._str); +} + +int GString::CompareNoCase(const char *s) const +{ + int i = 0; // start at the beginning + + // loop through the two strings comparing case insensitively + while ((toupper(_str[i]) == toupper(s[i])) && // the two strings are equal + (_str[i] != '\0')) // the first hasn't ended + i++; + + // the difference between the characters that ended it is + // indicative of the direction of the comparison. if this + // is negative, the first was before the second. if it is + // positive, the first was after the second. if it is zero, + // the two are equal (and the != '\0' condition stopped the + // loop such that the two were of equal length). + return (short)toupper(_str[i]) - (short)toupper(s[i]); +} + +int GString::CompareNoCase(const GString &s) const +{ + int i = 0; // start at the beginning + + // loop through the two strings comparing case insensitively + while ((toupper(_str[i]) == toupper(s._str[i])) && // the two strings are equal + (_str[i] != '\0')) // the first hasn't ended + i++; + + // the difference between the characters that ended it is + // indicative of the direction of the comparison. if this + // is negative, the first was before the second. if it is + // positive, the first was after the second. if it is zero, + // the two are equal (and the != '\0' condition stopped the + // loop such that the two were of equal length). + return (short)toupper(_str[i]) - (short)toupper(s._str[i]); +} + +char& GString::operator[](int nIdx) +{ + // check for subscript out of range + if (nIdx > _len) + throw GenericException("String", 1); + + return _str[nIdx]; +} + +char GString::GetAt(int nIdx) const +{ + // check for subscript out of range + if (nIdx > _len) + throw GenericException("String", 1); + + return _str[nIdx]; +} + +void GString::SetAt(int nIdx, char ch) +{ + // check for subscript out of range + if (nIdx >= _len) + throw GenericException("String", 1); + + _str[nIdx] = ch; +} + +void GString::PadLeft(int nCnt, char ch /* = ' ' */) +{ + if (nCnt > _len) + Prepend(nCnt - _len, ch); +} + +void GString::Prepend(int nCnt, char ch /* = ' ' */) +{ + while (nCnt + _len + 1 >= _max) + resize(); + + memmove(&_str[nCnt], _str, _len); + _len += nCnt; + + for (int i = 0; i < nCnt; i++) + _str[i] = ch; + + _str[_len] = 0; +} + +void GString::TrimLeft(char ch /* = ' ' */, short nCnt /* = -1 */) +{ + int i = 0; + while ((i < _len) && (_str[i] == ch) && (nCnt != 0)) + { + i++; + nCnt--; + } + + if (i != 0) + { + _len -= i; + memmove(_str, &_str[i], _len + 1); + } +} + +#define isWS(ch) ( ch == 0x20 || ch == 0x09 || ch == 0x0D || ch == 0x0A) +void GString::TrimLeftWS() +{ + int i = 0; + while ((i < _len) && (isWS(_str[i]))) + i++; + + if (i != 0) + { + _len -= i; + memmove(_str, &_str[i], _len + 1); + } +} + +void GString::PadRight(int nCnt, char ch /* = ' ' */) +{ + if (nCnt > _len) + Append(nCnt - _len, ch); +} + +void GString::Append(int nCnt, char ch /* = ' ' */) +{ + for (int i = 0; i < nCnt; i++, _len++) + { + if (_len >= _max) + resize(); + _str[_len] = ch; + } + + if (_len >= _max) + resize(); + _str[_len] = 0; +} + +void GString::TrimRightBytes(short nCnt) +{ + if (_len >= nCnt) + _len -= nCnt; + _str[_len] = 0; +} + +void GString::TrimRight(char ch /* = ' ' */, short nCnt /* = -1 */) +{ + while ((_len) && (_str[_len - 1] == ch) && (nCnt != 0)) + { + _len--; + nCnt--; + } + + _str[_len] = 0; +} + +GString GString::Left (int nCnt) const +{ + if (nCnt > _len) + nCnt = _len; + + return GString(_str, nCnt); +} + +GString GString::Mid (int nFirst) const +{ + if (nFirst > _len) + nFirst = _len; + + return GString(&_str[nFirst]); +} + +GString GString::Mid (int nFirst, int nCnt) const +{ + if (nFirst > _len) + nFirst = _len; + + return GString(&_str[nFirst], nCnt); +} + +GString GString::Right(int nCnt) const +{ + if (nCnt > _len) + nCnt = _len + 1; + + int nFirst = _len - nCnt; + return GString(&_str[nFirst]); +} + +void GString::TrimRightWS() +{ + while ((_len) && (isWS(_str[_len - 1]))) + _len--; + + _str[_len] = 0; +} + +void GString::MakeUpper() +{ + for (int i = 0; i < _len; i++) + _str[i] = toupper(_str[i]); +} + +void GString::MakeLower() +{ + for (int i = 0; i < _len; i++) + _str[i] = tolower(_str[i]); +} + +void GString::MakeReverse() +{ + for (int a = 0, b = _len - 1; a < b; a++, b--) + { + char c = _str[b]; + _str[b] = _str[a]; + _str[a] = c; + } +} + +char * stristr(const char * str1, const char * str2) +{ + char *cp = (char *) str1; + char *s1, *s2; + + if ( !*str2 ) + return((char *)str1); + + while (*cp) + { + s1 = cp; + s2 = (char *) str2; + + while ( *s1 && *s2 && !(tolower(*s1)-tolower(*s2)) ) + s1++, s2++; + + if (!*s2) + return(cp); + + cp++; + } + return 0; +} + +int GString::FindSubStringCaseInsensitive( const char * lpszSub, int nStart/* = 0*/ ) const +{ + char *p = stristr(&_str[nStart], lpszSub); + if (p) + return p - _str; + return -1; +} + +int GString::Find( char ch ) const +{ + return Find(ch, 0); +} + +int GString::Find( const char * lpszSub ) const +{ + return Find(lpszSub, 0); +} + +int GString::Find( char ch, int nStart ) const +{ + if (nStart >= _len) + return -1; + + // find first single character + const char *lpsz = strchr(_str + nStart, (int)ch); + + // return -1 if not found and index otherwise + return (lpsz == NULL) ? -1 : (int)(lpsz - _str); +} + +int GString::Find( const char * lpszSub, int nStart ) const +{ + if (nStart > _len) + return -1; + + // find first matching substring + const char *lpsz = strstr(_str + nStart, lpszSub); + + // return -1 for not found, distance from beginning otherwise + return (lpsz == NULL) ? -1 : (int)(lpsz - _str); +} + +void GString::Insert( int nIndex, char ch ) +{ + // subscript out of range + if (nIndex > _len) + throw GenericException("String", 1); + + if (_len + 2 >= _max) + resize(); + + _len++; + memmove(&_str[nIndex + 1], &_str[nIndex], _len - nIndex); + _str[nIndex] = ch; + _str[_len] = 0; +} + +void GString::Insert( int nIndex, const char * pstr ) +{ + if (!pstr) + return; + + // subscript out of range + if (nIndex > _len) + throw GenericException("String", 1); + + int nCnt = strlen(pstr); + while (_len + nCnt + 1 >= _max) + resize(); + + _len += nCnt; + memmove(&_str[nIndex + nCnt], &_str[nIndex], _len - nIndex); + + while (*pstr) + { + _str[nIndex] = *pstr; + pstr++; + nIndex++; + } + + _str[_len] = 0; +} + +void GString::MergeMask(const char *szSrc, const char *szMask) +{ + Empty(); + + if ((szSrc != 0) && (*szSrc != 0)) + { + while ((*szSrc != 0) || (*szMask != 0)) + { + switch (*szMask) + { + // copy a single character from the + case '_' : + if (*szSrc) + { + *this += *szSrc; + szSrc++; + } + szMask++; + break; + // copy the remaining characters from szSrc + case '*' : + *this += szSrc; + while (*szSrc) + szSrc++; + szMask++; + break; + // all other characters are mask chars + // with the exception of '\' which is + // used to escape '_', '*' and '\' + default : + if (*szMask != 0) + { + if (*szMask == '\\') + // skip the escape character + szMask++; + if (*szMask != 0) + { + *this += *szMask; + szMask++; + } + } + break; + } + + // throw away the remaining characters in the source string + if (*szMask == 0) + break; + } + } +} + +bool IsNaN(const char *szN, + char decimal_separator, + char grouping_separator, + char minus_sign) +{ + bool bRet = false; + + bool bDot = false; + bool bNeg = false; + int i = 0; + while ((*szN) && (!bRet)) + { + bRet = !(((*szN >= '0') && (*szN <= '9')) || + *szN == grouping_separator || + *szN == decimal_separator || + *szN == minus_sign); + + if (*szN == decimal_separator) + { + if (bDot) + bRet = true; // NaN + bDot = true; + } + + if (*szN == minus_sign) + { + if (((i) && szN[1]) || bNeg) + bRet = true; // NaN + bNeg = true; + } + + szN++; + i++; + } + + return bRet; +} + +short CountOf(const char *szN, char zero_digit) +{ + int nRet = 0; + + while (*szN) + { + if (*szN == zero_digit) + nRet++; + + szN++; + } + + return nRet; +} + +long round(const char *value) +{ + long dres = (long)atof(value); + double drem = atof(value); + drem -= dres; + short nAdd = 1; + if (drem < 0) drem *= -1, nAdd *= -1; + if (drem >= .5) dres += nAdd; + + return dres; +} + +void GString::FormatNumber(const char *szFormat, + char decimal_separator, + char grouping_separator, + char minus_sign, + const char *NaN, + char zero_digit, + char digit, + char pattern_separator, + char percent, + char permille) +{ + if (szFormat && *szFormat) + { + // make sure that the string is a number {0..9, '.', '-'} + // if the string contains a character not in the number + // subset then set the value of the string to NaN. + const char *szValue = _str; + if (IsNaN(szValue, '.', ',', '-')) + *this = NaN; + else + { + // it's a number, get the whole part and the fraction part + int nIdx = Find('.'); + GString strWhole; + strWhole = (nIdx == -1) ? _str : (const char *)Left(nIdx); + GString strFraction('0', (short)1); + nIdx = Find('.') + 1; + if (nIdx > 0) + strFraction = Mid(nIdx); + bool bIsNeg = (Find(minus_sign) != -1); + + long nWhole = abs(atol((const char *)strWhole)); + long nFract = abs(atol((const char *)strFraction)); + + // check for % and ? + if (percent == szFormat[0]) + { + double d = atof(_str); + d *= 100; + GString strTemp; + strTemp.Format("%f", d); + nIdx = strTemp.Find('.'); + strFraction = (nIdx == -1) ? strTemp._str : (const char *)strTemp.Left(nIdx); + nWhole = atol((const char *)strFraction); + nFract = 0; + } + if (permille == szFormat[0]) + { + double d = atof(_str); + d *= 1000; + GString strTemp; + strTemp.Format("%f", d); + nIdx = strTemp.Find('.'); + strFraction = (nIdx == -1) ? strTemp._str : (const char *)strTemp.Left(nIdx); + nWhole = atol((const char *)strFraction); + nFract = 0; + } + + // if the number is negative, get the negative pattern out of the format. + // if a negative pattern doesn't exist, the minus_sign will be prepended + // to the positive pattern. + GString strFormat(szFormat); + nIdx = strFormat.Find(pattern_separator); + if (bIsNeg) + { + if (nIdx != -1) + strFormat = strFormat.Mid(nIdx + 1); + else + strFormat.Format("%c%s", minus_sign, (const char *)strFormat); + } + else + { + if (nIdx != -1) + strFormat = strFormat.Left(nIdx); + } + + GString strFormatWhole(strFormat); + GString strFormatDecimal('#', (short)1); + + // determine the number of digits per group + int nGroup = 0; + nIdx = strFormat.Find(','); + if (nIdx != -1) + { + nIdx++; + int nNext = strFormat.Find(',', nIdx); + if (nNext == -1) + nNext = strFormat.Find('.', nIdx); + if (nNext == -1) + nNext = strFormat.Length(); + nGroup = (nNext - nIdx); + } + + // determine the number of decimals to display + int nDecimals = 0; + nIdx = strFormat.Find('.'); + if ((nIdx != -1) && + (percent != szFormat[0]) && + (permille != szFormat[0])) + { + if (nGroup) + strFormatWhole = strFormat.Mid(nIdx - nGroup, nGroup); + else + strFormatWhole = strFormat.Left(nIdx); + nIdx++; + strFormatDecimal = strFormat.Mid(nIdx); + nDecimals = (strFormat.Length() - nIdx); + } + + // Format the whole part of the number + int nCount = CountOf((const char *)strFormatWhole, zero_digit); + strWhole.Format("%0ld", nWhole); + if (strWhole.Length() < nCount) + { + GString temp(zero_digit, (short)(nCount - (short)strWhole.Length())); + strWhole.Format("%s%s", (const char *)temp, (const char *)strWhole); + } + + Empty(); + + // add all prefix characters + nIdx = 0; + const char *szP = (const char *)strFormat; + while (*szP) + { + if (*szP == digit || + *szP == zero_digit || + *szP == decimal_separator || + *szP == grouping_separator || + *szP == percent || + *szP == permille) + break; + + szP++; + nIdx++; + } + strFormat = strFormat.Left(nIdx); + + strFormat.MakeReverse(); + + int i, j; + for (i = 0, j = strWhole.Length() - 1; j >= 0; j--, i++) + { + if ((nGroup) && (i == nGroup)) + { + *this += grouping_separator; + i = 0; + } + + *this += strWhole[j]; + } + *this += strFormat; + + MakeReverse(); + + if (nDecimals) + { + *this += decimal_separator; + + strFraction.Format("%ld", nFract); + const char *szF1 = (const char *)strFormatDecimal; + const char *szF2 = (const char *)strFraction; + i = 0; + while (*szF1) + { + if (*szF2) + *this += *szF2; + else if (*szF1 == zero_digit) + *this += zero_digit; + else if (*szF1 != digit) // add all sufix characters + *this += *szF1; + if (*szF2) + szF2++; + if (*szF1) + szF1++; + } + } + + if (percent == szFormat[0]) + *this += percent; + if (permille == szFormat[0]) + *this += permille; + } + } +} + +#define FORCE_ANSI 0x10000 +#define FORCE_UNICODE 0x20000 +#define FORCE_INT64 0x40000 + +void GString::FormatV(const char *lpszFormat, va_list argList) +{ + va_list argListSave = argList; + + // make a guess at the maximum length of the resulting string + int nMaxLen = 0; + for (const char *lpsz = lpszFormat; *lpsz != '\0'; lpsz++) + { + // handle '%' character, but watch out for '%%' + if (*lpsz != '%' || *(lpsz = lpsz + 1) == '%') + { + nMaxLen += strlen(lpsz); + continue; + } + + int nItemLen = 0; + + // handle '%' character with format + int nWidth = 0; + for (; *lpsz != '\0'; lpsz++) + { + // check for valid flags + if (*lpsz == '#') + nMaxLen += 2; // for '0x' + else if (*lpsz == '*') + nWidth = va_arg(argList, int); + else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' || + *lpsz == ' ') + ; + else // hit non-flag character + break; + } + // get width and skip it + if (nWidth == 0) + { + // width indicated by + nWidth = atoi(lpsz); + for (; *lpsz != '\0' && isdigit(*lpsz); lpsz++) + ; + } + (nWidth >= 0); + + int nPrecision = 0; + if (*lpsz == '.') + { + // skip past '.' separator (width.precision) + lpsz++; + + // get precision and skip it + if (*lpsz == '*') + { + nPrecision = va_arg(argList, int); + lpsz++; + } + else + { + nPrecision = atoi(lpsz); + for (; *lpsz != '\0' && isdigit(*lpsz); lpsz++) + ; + } + (nPrecision >= 0); + } + + // should be on type modifier or specifier + int nModifier = 0; + if (strncmp(lpsz, "I64", 3) == 0) + { + lpsz += 3; + nModifier = FORCE_INT64; + } + else + { + switch (*lpsz) + { + // modifiers that affect size + case 'h': + nModifier = FORCE_ANSI; + lpsz++; + break; + case 'l': + nModifier = FORCE_UNICODE; + lpsz++; + break; + + // modifiers that do not affect size + case 'F': + case 'N': + case 'L': + lpsz++; + break; + } + } + + // now should be on specifier + switch (*lpsz | nModifier) + { + // single characters + case 'c': + case 'C': + nItemLen = 2; +#ifdef WIN32 + va_arg(argList, char); +#else + // gcc says: "`char' is promoted to `int' when passed through ... + // so we pass 'int' not 'char' to va_arg" + va_arg(argList, int); +#endif + break; + + // strings + case 's': + { + const char *pstrNextArg = va_arg(argList, const char *); + if (pstrNextArg == NULL) + nItemLen = 6; // "(null)" + else + { + nItemLen = strlen(pstrNextArg); + nItemLen = ___max(1, nItemLen); + } + } + break; + + case 's'|FORCE_ANSI: + case 'S'|FORCE_ANSI: + { + const char * pstrNextArg = va_arg(argList, const char *); + if (pstrNextArg == NULL) + nItemLen = 6; // "(null)" + else + { + nItemLen = strlen(pstrNextArg); + nItemLen = ___max(1, nItemLen); + } + } + break; + } + // adjust nItemLen for strings + if (nItemLen != 0) + { + if (nPrecision != 0) + nItemLen = ___min(nItemLen, nPrecision); + nItemLen = ___max(nItemLen, nWidth); + } + else + { + switch (*lpsz) + { + // integers + case 'd': + case 'i': + case 'u': + case 'x': + case 'X': + case 'o': + if (nModifier & FORCE_INT64) + va_arg(argList, __int64); + else + va_arg(argList, int); + nItemLen = 32; + nItemLen = ___max(nItemLen, nWidth+nPrecision); + break; + + case 'e': + case 'g': + case 'G': + va_arg(argList, double); + nItemLen = 128; + nItemLen = ___max(nItemLen, nWidth+nPrecision); + break; + + case 'f': + { + double f; + // 312 == strlen("-1+(309 zeroes).") + // 309 zeroes == max precision of a double + // 6 == adjustment in case precision is not specified, + // which means that the precision defaults to 6 + char *pszTemp = new char[___max(nWidth, 312+nPrecision+6)]; + + f = va_arg(argList, double); + sprintf( pszTemp, "%*.*f", nWidth, nPrecision+6, f ); + nItemLen = strlen(pszTemp); + + delete [] pszTemp; + } + break; + + case 'p': + va_arg(argList, void*); + nItemLen = 32; + nItemLen = ___max(nItemLen, nWidth+nPrecision); + break; + + // no output + case 'n': + va_arg(argList, int*); + break; + } + } + + // adjust nMaxLen for output nItemLen + nMaxLen += nItemLen; + } + + if (nMaxLen + 1 > _max) + { + if (_strIsOnHeap) + delete _str; + _max = nMaxLen + 1; + _str = new char[_max]; + _strIsOnHeap = 1; + _initialbuf[0] = 0; + } + + _len = vsprintf(_str, lpszFormat, argListSave); + + va_end(argListSave); + + if (_len < 0) + { + _len = 0; + _str[_len] = 0; + } +} + +// Load an error from the active ErrorProfile() owned by GException.cpp +void GString::LoadResource(const char* szSystem, int error, ...) +{ + int nerror = error; + + GProfile &ErrorProfile = GetErrorProfile(); + int nsubSystem = atoi(ErrorProfile.GetString(szSystem, "SubSystem")); + + GString strKey; + strKey.Format("%ld", error); + strKey = ErrorProfile.GetString(szSystem, (const char *)strKey); + + va_list argList; + va_start(argList, error); + FormatV((const char *)strKey, argList); + va_end(argList); + +} + + +void GString::Format(const char *lpszFormat, ...) +{ + va_list argList; + va_start(argList, lpszFormat); + FormatV(lpszFormat, argList); + va_end(argList); +} + +int GString::ToFileAppend(const char* pzFileName, bool bThrowOnFail /*= 1*/) +{ + FILE *fp = fopen(pzFileName,"a"); + if (fp) + { + fwrite(_str,1,_len,fp); + fclose(fp); + } + else + { + // the file could not be opened for writing + if (bThrowOnFail) + throw GenericException("String", 3, pzFileName); + + // fail + return 0; + } + // success + return 1; +} + +int GString::ToFile(const char* pzFileName, bool bThrowOnFail/* = 1*/) +{ + FILE *fp = fopen(pzFileName,"wb"); + if (fp) + { + fwrite(_str,1,_len,fp); + fclose(fp); + } + else + { + // the file could not be opened for writing + if (bThrowOnFail) + throw GenericException("String", 3, pzFileName); + + // fail + return 0; + } + // success + return 1; +} + +int GString::FromFile(const char* pzFileName, bool bThrowOnFail/* = 1*/) +{ + FILE *fp = fopen(pzFileName,"rb"); + if (fp) + { + // get the size of the file + fseek(fp,0,SEEK_END); + long lBytes = ftell(fp); + fseek(fp,0,SEEK_SET); + + if (_strIsOnHeap) + delete [] _str; + + // pre-alloc the GString + _str = new char[lBytes + 1]; + _strIsOnHeap = 1; + _initialbuf[0] = 0; + + int n = fread(_str,sizeof(char),lBytes,fp); + _len = lBytes; + _str[_len] = 0; + fclose(fp); + } + else + { + // the file could not be opened. + if (bThrowOnFail) + throw GenericException("String", 2, pzFileName); + + // fail + return 0; + } + // success + return 1; +} + +/* +int GString::GStringFromFile(GString &strDest, + const char* pzFileName, + int nMode) +{ + fstream fs(pzFileName, nMode); + if (fs.good()) + { + fs.seekg( 0, ios::end ); + long lFileBytes = fs.tellg(); + fs.seekg( 0, ios::beg ); + + if (strDest._strIsOnHeap) + delete [] strDest._str; + strDest._str = new char[lFileBytes + 1]; + strDest._strIsOnHeap = 1; + strDest._initialbuf[0] = 0; + + fs.read(strDest._str, lFileBytes); + strDest._len = lFileBytes; + strDest._str[strDest._len] = 0; + } + else + { + return 0; // Failed to open input file + } + return 1; // success +} + +int GString::GStringFromFile(ostream &strDest, + const char* pzFileName, + int nMode) +{ + fstream fs(pzFileName, nMode); + if (fs.good()) + { + fs.seekg( 0, ios::end ); + long lFileBytes = fs.tellg(); + fs.seekg( 0, ios::beg ); + + char *buf = new char[lFileBytes]; + fs.read(buf,lFileBytes); + + if (strDest.tellp()) + strDest.seekp(strDest.tellp() - 1); + + strDest.write(buf,lFileBytes); + delete buf; + + strDest << ends; + } + else + { + return 0; // Failed to open input file + } + return 1; // success +} +*/ + +void GString::ReplaceCaseInsensitive( const char * szWhat, const char *szRep, int nStart/* = 0*/ ) +{ + if ((!szWhat) || (!szRep)) + return; + + int nPos = FindSubStringCaseInsensitive(szWhat, nStart); + int nLen = strlen(szRep); + + while (nPos != -1) + { + Remove(nPos, strlen(szWhat)); + if (nLen) + Insert(nPos, szRep); + + nPos += nLen; + + nPos = FindSubStringCaseInsensitive(szWhat, nPos); + } +} + + +void GString::Replace( const char * szWhat, const char *szRep ) +{ + if ((!szWhat) || (!szRep)) + return; + + int nPos = Find(szWhat); + int nLen = strlen(szRep); + + while (nPos != -1) + { + Remove(nPos, strlen(szWhat)); + if (nLen) + Insert(nPos, szRep); + + nPos += nLen; + + nPos = Find(szWhat, nPos); + } +} + +void GString::Replace( char chWhat, char chRep ) +{ + char szWhat[2]; + szWhat[0] = chWhat; + szWhat[1] = 0; + + char szRep[2]; + szRep[0] = chRep; + szRep[1] = 0; + + Replace( (const char *)szWhat, (const char *)szRep ); +} + +void GString::Replace( const char * szWhat, char chRep ) +{ + char szRep[2]; + szRep[0] = chRep; + szRep[1] = 0; + + Replace( (const char *)szWhat, (const char *)szRep ); +} + +void GString::Replace( char chWhat, const char *szRep ) +{ + char szWhat[2]; + szWhat[0] = chWhat; + szWhat[1] = 0; + + Replace( (const char *)szWhat, (const char *)szRep ); +} + +void GString::Remove( int nStart, int nLen ) +{ + // subscript out of range + if (nStart + nLen > _len) + throw GenericException("String", 1); + + memmove(&_str[nStart], &_str[nStart + nLen], _len - (nStart + nLen)); + _len -= nLen; + _str[_len] = 0; +} + +void GString::StripQuotes() +{ + if ((_len >= 2) && (_str[0] == _str[_len - 1])) + { + if ((_str[0] == '\'') || (_str[0] == '"')) + { + memmove(&_str[0], &_str[1], _len - 2); + _len -= 2; + _str[_len] = 0; + } + } +} + + +void GString::NormalizeSpace() +{ + int nBegWS = -1; + int nEndWS = -1; + + for (int i = 0; i < _len; i++) + { + if (isWS(_str[i])) + { + nEndWS = i; + if (nBegWS == -1) + nBegWS = i; + } + else if ((nBegWS != -1) && + (nEndWS != -1)) + { + nEndWS++; + Remove(nBegWS, nEndWS - nBegWS); + Insert(nBegWS, ' '); + i = nBegWS; + nBegWS = -1; + nEndWS = -1; + } + else + { + nBegWS = -1; + nEndWS = -1; + } + } + + if ((nBegWS != -1) && + (nEndWS != -1)) + { + nEndWS++; + Remove(nBegWS, nEndWS - nBegWS); + Insert(nBegWS, ' '); + } + + TrimLeftWS(); + TrimRightWS(); +} + +void GString::Translate(const char *szConvert, const char *szTo) +{ + if ((szConvert) && (szTo)) + { + int nTranslate = ___min(strlen(szConvert), strlen(szTo)); + for (int i = 0; i < _len; i++) + { + for (int j = 0; j < nTranslate; j++) + { + if (_str[i] == szConvert[j]) + _str[i] = szTo[j]; + } + } + } +} + + +// replace each char in pzReplaceChars with %nn where +// nn is a two byte hex value of the byte that was replaced. +// example: GString s("ABC"); +// s.EscapeWithHex("XYZB"); +// s == "A%42C" +// 42 is hex for 66 that is the ASCII of a B +// +// example: GString s("A\nC"); +// s.EscapeWithHex("\r\n\t"); +// s == "A%0AC" +// +const char *GString::EscapeWithHex(const char *pzEscapeChars) +{ + GString strDestrination; + GString strEscapeChars(pzEscapeChars); + char *pSrc = (char *)(const char *)(*this); + int nSourceBytes = strlen(pSrc); + + for(int i=0;i < nSourceBytes; i++) + { + // escape special chars + if ( strEscapeChars.Find(pSrc[i]) > -1 ) + { + char buf[20]; + sprintf(buf,"%%%02X",pSrc[i]); + strDestrination += buf; + } + else + { + strDestrination += pSrc[i]; + } + } + *this = strDestrination; + return *this; +} + +// reverse of GString::EscapeWithHex() +void GString::UnEscapeHexed() +{ + const char *pSource = *this; + char *pDest = new char [strlen(pSource) + 1]; + + char *pszQuery = (char *)pSource; + char *t = pDest; + while (*pszQuery) + { + switch (*pszQuery) + { + case '%' : + { + pszQuery++; + char chTemp = pszQuery[2]; + pszQuery[2] = 0; + char *pStart = pszQuery; + char *pEnd; + *t = (char)strtol(pStart, &pEnd, 16); + pszQuery[2] = chTemp; + pszQuery = pEnd; + t++; + continue; + } + break; + default : + *t = *pszQuery; + break; + } + pszQuery++; + t++; + } + *t = 0; + *this = pDest; + delete pDest; +} diff --git a/ref/vt-ex/src/profile/GStringList.cpp b/ref/vt-ex/src/profile/GStringList.cpp new file mode 100644 index 0000000..4c85fbe --- /dev/null +++ b/ref/vt-ex/src/profile/GStringList.cpp @@ -0,0 +1,221 @@ +// -------------------------------------------------------------------------- +// www.UnitedBusinessTechnologies.com +// Copyright (c) 1998 - 2002 All Rights Reserved. +// +// Source in this file is released to the public under the following license: +// -------------------------------------------------------------------------- +// This toolkit may be used free of charge for any purpose including corporate +// and academic use. For profit, and Non-Profit uses are permitted. +// +// This source code and any work derived from this source code must retain +// this copyright at the top of each source file. +// +// UBT welcomes any suggestions, improvements or new platform ports. +// email to: XMLFoundation@UnitedBusinessTechnologies.com +// -------------------------------------------------------------------------- + +#include "pch.h" +#include "GStringList.h" +#include "GString.h" +#include +#include // for: strlen(), strstr() +#include "GProfile.h" +const char *GStringList::PeekLast() +{ + m_strSerializeDest = ""; + GString *pG = (GString *)GList::Last(); + if (pG) + m_strSerializeDest = (const char *)*pG; + return m_strSerializeDest; +} + + +const char *GStringList::PeekFirst() +{ + m_strSerializeDest = ""; + GString *pG = (GString *)GList::First(); + if (pG) + m_strSerializeDest = (const char *)*pG; + return m_strSerializeDest; +} + +const char *GStringList::RemoveFirst() +{ + m_strSerializeDest = ""; + GString *pG = (GString *)GList::First(); + if (pG) + { + GList::RemoveFirst(); + m_strSerializeDest = (const char *)*pG; + delete pG; + } + return m_strSerializeDest; +} + +const char *GStringList::RemoveLast() +{ + m_strSerializeDest = ""; + GString *pG = (GString *)GList::RemoveLast(); + if (pG) + { + m_strSerializeDest = (const char *)*pG; + delete pG; + } + return m_strSerializeDest; +} + +GString *GStringList::AddFirst(const char *szString) +{ + GString *pstrString = new GString(szString); + GList::AddHead(pstrString); + return pstrString; +} + + +GString *GStringList::AddLast(const char *szString) +{ + GString *pstrString = new GString(szString); + GList::AddLast(pstrString); + return pstrString; +} + +GStringList::GStringList(const GStringList &src) +{ + GStringIterator it(&src); + while (it()) + AddLast(it++); +} + +GStringList::GStringList() +{ +} + +void GStringList::operator+=(const GStringList &src) +{ + GStringIterator it(&src); + while (it()) + AddLast(it++); +} + +void GStringList::operator+=(const char *szSrc) +{ + AddLast(szSrc); +} + +void GStringList::RemoveAll() +{ + int n = Size(); + for(int i=0; iNextNode; + if (LastNode == FirstNode) + LastNode = 0; + Node *Save = FirstNode->NextNode; + delete (GString *)FirstNode->Data; + delete FirstNode; + FirstNode = Save; + iSize--; + } +} + +void GStringIterator::reset() +{ + pDataNode = (GStringList::Node *)((GStringList *)pTList)->FirstNode; +} + +GStringIterator::GStringIterator(const GStringList *pList) +{ + pTList = (GStringList *)pList; + pDataNode = (GStringList::Node *)((GStringList *)pList)->FirstNode; +} + +const char *GStringIterator::operator ++ (int) +{ + GString *pRet = (GString *)pDataNode->Data; + pCurrentNode = pDataNode; + pDataNode = pDataNode->NextNode; + return pRet->StrVal(); +} + +int GStringIterator::operator () (void) const +{ + return pDataNode != 0; +} + + +const char *GStringList::Serialize(const char *pzDelimiter) +{ + m_strSerializeDest = ""; + GStringIterator it(this); + int nCount = 0; + + while (it()) + { + if (nCount) + m_strSerializeDest += pzDelimiter; + nCount++; + m_strSerializeDest += it++; + } + return m_strSerializeDest; +} + +GStringList::GStringList(const char *pzDelimiter, const char *pzSource) +{ + DeSerialize(pzDelimiter, pzSource); +} + +void GStringList::DeSerialize(const char *pzDelimiter, const char *pzSource) +{ + if (!pzDelimiter || !pzSource || !pzDelimiter[0] || !pzSource[0]) + return; + + + int nSourceLen = strlen(pzSource); + + int nDelimiterLen = strlen(pzDelimiter); + + if (!nSourceLen) + return; + + char *beg = (char *)pzSource; + char *del = strstr(beg,pzDelimiter); + while(1) + { + if ( !del ) + { + // there is only one entry in the list + AddLast(beg); + break; + } + + // temporarily null on the delimiter + char chOld = *del; + *del = 0; + + // add this (now null terminated) entry + AddLast(beg); + + // advance to the next string + beg = del + nDelimiterLen; + + // unnull the previous + *del = chOld; + + // advance to the next delimiter, break if none + del = strstr(beg,pzDelimiter); + if ( !del ) + { + AddLast(beg); + break; + } + } + +} + diff --git a/ref/vt-ex/src/virtools/Behaviors/generic/BGInstancer.cpp b/ref/vt-ex/src/virtools/Behaviors/generic/BGInstancer.cpp new file mode 100644 index 0000000..542f42d --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/generic/BGInstancer.cpp @@ -0,0 +1,926 @@ +/******************************************************************** + created: 2006/05/07 + created: 05:07:2006 8:14 + filename: x:\junctions\ProjectRoot\current\vt_plugins\vt_toolkit\Behaviors\Generic\BGInstancer.cpp + file path: x:\junctions\ProjectRoot\current\vt_plugins\vt_toolkit\Behaviors\Generic + file base: BGInstancer + file ext: cpp + author: mc007 + + purpose: +*********************************************************************/ +#include //for pch only,can be removed! + +#include "BGInstancer.h" + + + +/* + ******************************************************************* + * Function: CKObjectDeclaration *FillBehaviour( void ) + * + * Description : As its name infers, this function describes each Building Block + * on a functional level : what it can be applied to, its GUID, its + * creation function, etc.. + * + * + * Parameters : + * None + * + * Returns : CKObjectDeclaration *, containing: + * - The type of object declaration ( Must Be CKDLL_BEHAVIORPROTOTYPE ) + * - The function that will create the CKBehaviorPrototype for this behavior. + * - A short description of what the behavior is supposed to do. + * - The category in which this behavior will appear in the Virtools interface. + * - A unique CKGUID + * - Author and Version info + * - The class identifier of objects to which the behavior can be applied to. + * + ******************************************************************* + */ +CKObjectDeclaration * BGWrapper::FillBehaviour( void ) +{ + CKObjectDeclaration *objectDeclaration = CreateCKObjectDeclaration( "BgInstancer" ); + + objectDeclaration->SetType( CKDLL_BEHAVIORPROTOTYPE ); + objectDeclaration->SetCreationFunction( BGWrapper::CreatePrototype ); + objectDeclaration->SetDescription( "Encapsulates the functionality provided by a Behaviour Graph and allows reuse while minimising maintenance overhead." ); + objectDeclaration->SetCategory( "Narratives/Script Management" ); + objectDeclaration->SetGuid( BGWRAPPER_GUID ); + objectDeclaration->SetVersion( 0x00000001 ); + objectDeclaration->SetAuthorGuid( VTCX_AUTHOR_GUID ); + objectDeclaration->SetAuthorName( VTCX_AUTHOR ); + objectDeclaration->SetCompatibleClassId( CKCID_BEOBJECT ); + + return objectDeclaration; +} + +/* + ******************************************************************* + * Function: CKERROR CreatePrototype( CKBehaviorPrototype** behaviorPrototypePtr ) + * + * Description : The prototype creation function will be called the first time + * a behavior must be created to create the CKBehaviorPrototype + * that contains the description of the behavior. + * + * Parameters : + * behaviorPrototypePtr Pointer to a CKBehaviorPrototype object that + * describes the behavior's internal structure + * and relationships with other objects. + * + * Returns : CKERROR + * + ******************************************************************* + */ +CKERROR BGWrapper::CreatePrototype( CKBehaviorPrototype** behaviorPrototypePtr ) + { + +#if RUNTIME + // Not editable from Virtools Dev + CKBehaviorPrototype *behaviorPrototype = CreateCKBehaviorPrototypeRunTime( "BGWrapper" ); +#elif GAMEDEVELOPER + // Edition depend on the BB. + CKBehaviorPrototype *behaviorPrototype = CreateCKBehaviorPrototype( "BGWrapper" ); +#else + // Editable from Virtools Dev + CKBehaviorPrototype *behaviorPrototype = CreateCKBehaviorPrototype( "BGWrapper" ); +#endif + + + if ( !behaviorPrototype ) + return CKERR_OUTOFMEMORY; + + //---- Local Parameters Declaration + behaviorPrototype->DeclareLocalParameter("BG Script", CKPGUID_BEHAVIOR ); + + //---- Settings Declaration + behaviorPrototype->DeclareSetting("BG filename", CKPGUID_STRING ,"path undefined.(BGWrapper Settings)"); + + behaviorPrototype->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); + + behaviorPrototype->SetBehaviorFlags((CK_BEHAVIOR_FLAGS)(CKBEHAVIOR_INTERNALLYCREATEDINPUTS | + CKBEHAVIOR_INTERNALLYCREATEDINPUTPARAMS | + CKBEHAVIOR_INTERNALLYCREATEDOUTPUTS | + CKBEHAVIOR_INTERNALLYCREATEDOUTPUTPARAMS)); + + behaviorPrototype->SetBehaviorCallbackFct(BGWrapperCB, + CKCB_BEHAVIORLOAD | + CKCB_BEHAVIORRESET | + CKCB_BEHAVIORSETTINGSEDITED | + CKCB_BEHAVIORDETACH | + CKCB_BEHAVIORDEACTIVATESCRIPT + , NULL); + + behaviorPrototype->SetFunction( BGWrapper::BehaviourFunction ); + + *behaviorPrototypePtr = behaviorPrototype; + return CK_OK; +} + +/* + ******************************************************************* + * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext ) + * + * Description : The execution function is the function that will be called + * during the process loop of the behavior engine, if the behavior + * is defined as using an execution function. This function is not + * called if the behavior is defined as a graph. This function is the + * heart of the behavior: it should compute the essence of the behavior, + * in an incremental way. The minimum amount of computing should be + * done at each call, to leave time for the other behaviors to run. + * The function receives the delay in milliseconds that has elapsed + * since the last behavioral process, and should rely on this value to + * manage the amount of effect it has on its computation, if the effect + * of this computation relies on time. + * + * Parameters : + * behaviourContext Behavior context reference, which gives access to + * frequently used global objects ( context, level, manager, etc... ) + * + * Returns : int, If it is done, it should return CKBR_OK. If it returns + * CKBR_ACTIVATENEXTFRAME, the behavior will again be called + * during the next process loop. + * + ******************************************************************* + */ + +int BGWrapper::BehaviourFunction( const CKBehaviorContext& behContext ) +{ + CKBehavior *behaviour = behContext.Behavior; + CKContext *context = behContext.Context; + int iPin, nbPin; + + CKBehavior* script = (CKBehavior*)behaviour->GetLocalParameterObject(EBGWRAPPERPARAM_PARAMETER_SCRIPT); + + if (script == NULL) + return CKBR_GENERICERROR; + + // Activate the right inputs + nbPin = behaviour->GetInputCount(); + for (iPin = 0; iPin < nbPin; iPin++) + { + if (behaviour->IsInputActive(iPin)) + { + script->ActivateInput(iPin, TRUE); + behaviour->ActivateInput(iPin, FALSE); + } + } + + // Deactivate all the outputs + nbPin = script->GetOutputCount(); + for (iPin = 0; iPin < nbPin; iPin++) + { + behaviour->ActivateOutput(iPin, FALSE); + } + + // Parameter In: Set Source + int nbPinBB = behaviour->GetInputParameterCount(); + int nbPinBG = script->GetInputParameterCount(); + + if (nbPinBB != nbPinBG) + return CKBR_GENERICERROR; + + for (iPin = 0; iPin < nbPinBB; iPin++) + { + CKParameterIn *pBin = behaviour->GetInputParameter(iPin); + CKParameter* pSource = pBin->GetDirectSource(); + + CKParameterIn *pSin = script->GetInputParameter(iPin); + pSin->SetDirectSource(pSource); + } + + // Execute the contained script + CKERROR result = script->Execute(behContext.DeltaTime); + + // The script loop on itself too much times + if (result == CKBR_INFINITELOOP) + { + context->OutputToConsoleExBeep("Execute Script : Script %s Executed too much times",script->GetName()); + script->Activate(FALSE,FALSE); + return CKBR_OK; + } + + // Activate the right outputs + nbPin = script->GetOutputCount(); + for (iPin = 0; iPin < nbPin; iPin++) + { + if (script->IsOutputActive(iPin)) + { + behaviour->ActivateOutput(iPin); + script->ActivateOutput(iPin, FALSE); + } + } + + // Update Parameters Out + nbPin = behaviour->GetOutputParameterCount(); + for (iPin = 0; iPin < nbPin; iPin++) + { + CKParameterOut *pBout = behaviour->GetOutputParameter(iPin); + CKParameterOut *pSout = script->GetOutputParameter(iPin); + pBout->CopyValue(pSout, TRUE); + } + + + // Test if there are any active sub-behaviors, restart the next frame if any + BOOL bActivateNextFrame = FALSE; + ActivateNextFrameSubBB(script,bActivateNextFrame); + if (bActivateNextFrame) + return CKBR_ACTIVATENEXTFRAME; + + // return the execute value + return result; +} + +/* + ******************************************************************* + * Function: CKERROR BGWrapperCB(const CKBehaviorContext& behContext) + * + * Description : The Behavior Callback function is called by Virtools + * when various events happen in the life of a BuildingBlock. + * + * Parameters : + * behaviourContext Behavior context reference, which gives access to + * frequently used global objects ( context, level, manager, etc... ) + * + * Returns : CKERROR + * + ******************************************************************* + */ +CKERROR BGWrapper::BGWrapperCB(const CKBehaviorContext& behContext) +{ + CKERROR result = CKBR_GENERICERROR; + + // Initialize common pointers. + CKBehavior *behaviour = behContext.Behavior; + CKContext *context = behContext.Context; + CKLevel *level = behContext.CurrentLevel; + CKBeObject *owner = behContext.Behavior->GetOwner(); + + char*name = behaviour->GetName(); + + if ( behaviour == NULL || context == NULL || level == NULL /*|| owner == NULL*/ ) + return CKBR_OK; + + //Get The BG Script Object if exists + CKBehavior* newBG = NULL; + CKBehavior* curBG = (CKBehavior*)behaviour->GetLocalParameterObject(EBGWRAPPERPARAM_PARAMETER_SCRIPT); + + // Get the BG nms file path. GetStringValue doesn't work with setting... + char fileName[_MAX_PATH+1]; + memset(fileName,0,_MAX_PATH+1); + CKParameter* scriptPath = behaviour->GetLocalParameter(EBGWRAPPERPARAM_PARAMETER_NAME); + if ( scriptPath == NULL ) + return CKBR_OK; + + int lenPath = scriptPath->GetDataSize(); + if ( lenPath >= _MAX_PATH ) + return CKBR_OK; + + void*ptrPath = scriptPath->GetReadDataPtr(TRUE); + if ( ptrPath == NULL ) + return CKBR_OK; + + memcpy(fileName,ptrPath,lenPath); + + CKDWORD message = behContext.CallbackMessage; + + switch (message) + { + case CKM_BEHAVIORLOAD : // when the behavior is loaded + case CKM_BEHAVIORRESET: // when the behavior is reseted + case CKM_BEHAVIORSETTINGSEDITED : // when the settings are edited + { + if ( curBG != NULL ) + { + DestroyCurrentBG(level,behaviour,curBG); + curBG = NULL; + } + + newBG = BGLoader( fileName, behContext ); + if ( newBG == NULL ) + return CKBR_OK; + + if ( message == CKM_BEHAVIORLOAD || message == CKM_BEHAVIORRESET ) + { + //context->OutputToConsoleExBeep("%s : LOADED %s",behaviour->GetName(), fileName); + if ( CheckIO(behaviour, newBG) == TRUE ) + result = CKBR_OK; + else + context->OutputToConsoleExBeep("%s : Too many inputs/outputs changes in %s\r\nPlease reconstruct the wrapper.",behaviour->GetName(), fileName); + } + else if ( message == CKM_BEHAVIORSETTINGSEDITED ) + { + if ( CheckIO(behaviour, newBG) == TRUE ) + { + result = CKBR_OK; + } + else if (DeleteIO(behaviour) == TRUE) + { + if ( CreateIO(behaviour, newBG ) == TRUE ) + result = CKBR_OK; + else + context->OutputToConsoleExBeep("%s : Cannot Create Inputs/Outputs %s",behaviour->GetName(), fileName); + } + else + context->OutputToConsoleExBeep("%s : Cannot Delete Inputs/Outputs %s",behaviour->GetName(), fileName); + } + + if ( result == CKBR_OK && newBG != NULL ) + SetNewBG(behaviour,newBG); + } + break; + + case CKM_BEHAVIORDEACTIVATESCRIPT: + { + if ( curBG != NULL ) + DesactivateSubBB(curBG); + result = CKBR_OK; + } + break; + + case CKM_BEHAVIORDETACH : // when the behavior is deleted + { + if (curBG != NULL) + { + DestroyCurrentBG(level,behaviour,curBG); + curBG = NULL; + } + result = CKBR_OK; + } + break; + + default: + { + result = CKBR_OK; + } + break; + + } + + if (result != CKBR_OK) + context->OutputToConsoleExBeep("%s : Problem while manipulating",behaviour->GetName()); + + + + return result; + } + + + /* + ******************************************************************* + * Function: CKBehavior* BGLoader(CKSTRING fileName,const CKBehaviorContext& behContext) + * + * Description : Load a virtools script.and add it to the current level. + * + * Parameters : + * fileName string containing the script filename to be loaded. + * behaviourContext Behavior context reference, which gives access to + * frequently used global objects ( context, level, manager, etc... ) + * + * Returns : CKBehavior* the loaded behaviour, NULL if failed. + * + ******************************************************************* + */ +CKBehavior* BGWrapper::BGLoader(CKSTRING fileName,const CKBehaviorContext& behContext) +{ + CKERROR result = CKBR_GENERICERROR; + + // Initialize common pointers. + CKBehavior *behaviour = behContext.Behavior; + CKContext *context = behContext.Context; + CKLevel *level = behContext.CurrentLevel; + CKBeObject *owner = behContext.Behavior->GetOwner(); + + if ( behaviour == NULL || context == NULL || level == NULL ) + return NULL; + + char fileToLoad[_MAX_PATH],nakedFileName[_MAX_PATH]; + char drive[_MAX_DRIVE], dir[_MAX_DIR], fname[_MAX_FNAME], ext[_MAX_EXT]; + _splitpath(fileName, drive, dir, fname, ext); + + if ( ext[0] == 0 ) + strcpy(ext,".nms"); + + strcpy(fileToLoad,drive); + strcat(fileToLoad,dir); + strcat(fileToLoad,fname); + strcat(fileToLoad,ext); + + if ( strcmp(_strlwr(ext),".nms") != 0 ) + { + context->OutputToConsoleExBeep("BGWrapper : Can only load .nms files %s",fileToLoad); + return NULL; + } + + CKObjectArray* array = CreateCKObjectArray(); + + context->SetAutomaticLoadMode(CKLOAD_OK, CKLOAD_OK, CKLOAD_USECURRENT, CKLOAD_USECURRENT); + + // Virtools Load the BGs nms file.first try the absolute path, then the lastCmoloaded path, and then the PathManager manager data paths + if (context->Load(fileToLoad, array, (CK_LOAD_FLAGS)(CK_LOAD_AUTOMATICMODE | CK_LOAD_AS_DYNAMIC_OBJECT )) != CK_OK) + { + strcpy(nakedFileName,fname); + strcat(nakedFileName,ext); + + CKSTRING lastCmo = context->GetLastCmoLoaded(); + char driveCmo[_MAX_DRIVE], dirCmo[_MAX_DIR], fnameCmo[_MAX_FNAME], extCmo[_MAX_EXT]; + _splitpath(lastCmo, driveCmo, dirCmo, fnameCmo, extCmo); + + strcpy(fileToLoad,driveCmo);strcat(fileToLoad,dirCmo);strcat(fileToLoad,nakedFileName); + + if (context->Load(fileToLoad, array, (CK_LOAD_FLAGS)(CK_LOAD_AUTOMATICMODE | CK_LOAD_AS_DYNAMIC_OBJECT )) != CK_OK) + { + // failed then try to go thru the data path. + CKPathManager* pathmanager = behContext.Context->GetPathManager(); + if (!pathmanager) + { + context->OutputToConsoleExBeep("BGWrapper : Cannot find the Path Manager"); + return NULL; + } + + XString resolved(nakedFileName); + array->Clear(); + pathmanager->ResolveFileName(resolved,DATA_PATH_IDX,-1); + if (context->Load(resolved.Str(), array, (CK_LOAD_FLAGS)(CK_LOAD_AUTOMATICMODE | CK_LOAD_AS_DYNAMIC_OBJECT )) != CK_OK) + { + context->OutputToConsoleExBeep("BGWrapper : Cannot Load %s", nakedFileName); + return NULL; + } + } + + + } + + // Check if only one Object is loaded (we should have only one BG here) + if ( array->GetCount() != 1 ) + { + context->OutputToConsoleExBeep("BGWrapper : To many objects inside the nms %s.It should contain one BG only.",fileToLoad); + + level->BeginRemoveSequence(TRUE); + for (array->Reset(); !array->EndOfList(); array->Next()) + { + CKObject* curObject = array->GetData(context); + level->RemoveObject(curObject); + CKDestroyObject(curObject); + } + level->BeginRemoveSequence(FALSE); + DeleteCKObjectArray(array); + + return NULL; + } + + array->Reset(); + CKObject* curObject = array->GetData(context); + + if ( curObject == NULL ) + { + context->OutputToConsoleExBeep("BGWrapper : Object NULL in loaded array."); + return NULL; + } + + // Make it not to be saved even if it is loaded as dynamic... (not needed ?) + curObject->ModifyObjectFlags( CK_OBJECT_NOTTOBESAVED,0 ); + + // Check if the object we've loaded is derivated from the BEHAVIOR + if ( !CKIsChildClassOf(curObject, CKCID_BEHAVIOR) ) + { + context->OutputToConsoleExBeep("BGWrapper : no behavior in the nms : %s",fileToLoad); + + level->BeginRemoveSequence(TRUE); + level->RemoveObject(curObject); + level->BeginRemoveSequence(FALSE); + CKDestroyObject(curObject); + DeleteCKObjectArray(array); + + return NULL; + } + + CKBehavior*pBG = (CKBehavior*)curObject; + + // Check if the behavior we've loaded is a BG and not a BB. + if ( pBG->IsUsingFunction() ) + { + context->OutputToConsoleExBeep("BGWrapper : BGWrapper accepts only a BG not a BB : %s",fileToLoad); + + level->BeginRemoveSequence(TRUE); + level->RemoveObject(curObject); + level->BeginRemoveSequence(FALSE); + CKDestroyObject(curObject); + DeleteCKObjectArray(array); + + return NULL; + } + + // Check if the BG can be applied to the 's BeObject owner. + char*nameee = pBG->GetName(); + CK_CLASSID cid = pBG->GetCompatibleClassID(); + + + if (owner!=NULL) + if ( !CKIsChildClassOf(owner, pBG->GetCompatibleClassID()) ) + { + context->OutputToConsoleExBeep("BGWrapper : Incompatible Class, cannot add BG to script %s",fileToLoad); + + level->BeginRemoveSequence(TRUE); + level->RemoveObject(curObject); + level->BeginRemoveSequence(FALSE); + CKDestroyObject(curObject); + DeleteCKObjectArray(array); + + return NULL; + } + + // Add the BG to the 's level. + level->BeginAddSequence(TRUE); + level->AddObject(curObject); + level->BeginAddSequence(FALSE); + DeleteCKObjectArray(array); + + if (owner!=NULL) + OwnerSubBB(pBG,owner); + + return pBG; +} + + + /* + ******************************************************************* + * Function: BOOL CheckIO(CKBehavior* behaviour, CKBehavior* script) + * + * Description : Check if all the Inputs,Outputs, pIns and pOuts of both behavior are matching + * + * Parameters : + * behaviour Behavior 1, usually the BG wrapper BB. + * script Behavior 2, usually the wrapped BG. + * + * Returns : BOOL + * + ******************************************************************* + */ +BOOL BGWrapper::CheckIO(CKBehavior* behaviour, CKBehavior* script) + { + int iParam; + int nbPin0, nbPin1; + int flag = 0; + + // Input + nbPin0 = behaviour->GetInputCount(); + nbPin1 = script->GetInputCount(); + if (nbPin0 != nbPin1) + return FALSE; + + // Ouput + nbPin0 = behaviour->GetOutputCount(); + nbPin1 = script->GetOutputCount(); + if (nbPin0 != nbPin1) + return FALSE; + + // Parameter In + nbPin0 = behaviour->GetInputParameterCount(); + nbPin1 = script->GetInputParameterCount(); + if (nbPin0 != nbPin1) + return FALSE; + for (iParam = 0; iParam < nbPin0; iParam++) + { + CKParameterIn* pSin = script->GetInputParameter(iParam); + CKParameterIn* pBin = behaviour->GetInputParameter(iParam); + if (pSin == NULL || pBin == NULL) + return FALSE; + if (pSin->GetType() != pBin->GetType()) + return FALSE; + } + + // Parameter Out + nbPin0 = behaviour->GetOutputParameterCount(); + nbPin1 = script->GetOutputParameterCount(); + if (nbPin0 != nbPin1) + return FALSE; + for (iParam = 0; iParam < nbPin0; iParam++) + { + CKParameterOut* pSout = script->GetOutputParameter(iParam); + CKParameterOut* pBout = behaviour->GetOutputParameter(iParam); + if (pSout == NULL || pBout == NULL) + return FALSE; + if (pSout->GetType() != pBout->GetType()) + return FALSE; + } + + return TRUE; + } + + + /* + ******************************************************************* + * Function: BOOL :CreateIO(CKBehavior* behaviour, CKBehavior* script) + * + * Description : Check if all the Inputs,Outputs, pIns and pOuts of both behavior are matching + * + * Parameters : + * behaviour Behavior 1, usually the BG wrapper BB. + * script Behavior 2, usually the wrapped BG. + * + * Returns : BOOL + * + ******************************************************************* + */ +BOOL BGWrapper::CreateIO(CKBehavior* behaviour, CKBehavior* script) + { + int iIO; + int nbPin; + + // Input + nbPin = script->GetInputCount(); + for (iIO = 0; iIO < nbPin; iIO++) + { + CKBehaviorIO* pPin = script->GetInput(iIO); + if (pPin == NULL) + return FALSE; + + if (behaviour->AddInput(pPin->GetName()) != iIO) + return FALSE; + } + + // Output + nbPin = script->GetOutputCount(); + for (iIO = 0; iIO < nbPin; iIO++) + { + CKBehaviorIO* pPin = script->GetOutput(iIO); + if (pPin == NULL) + return FALSE; + + if (behaviour->AddOutput(pPin->GetName()) != iIO) + return FALSE; + } + + // Parameter In + nbPin = script->GetInputParameterCount(); + for (iIO = 0; iIO < nbPin; iIO++) + { + CKParameterIn* pPin = script->GetInputParameter(iIO); + if (pPin == NULL) + return FALSE; + + CKParameterIn* pPin2; + if ((pPin2 = behaviour->CreateInputParameter(pPin->GetName(), (CKParameterType)pPin->GetType())) == NULL) + return FALSE; + } + + // Parameter Out + nbPin = script->GetOutputParameterCount(); + for (iIO = 0; iIO < nbPin; iIO++) + { + CKParameterOut* pPin = script->GetOutputParameter(iIO); + if (pPin == NULL) + return FALSE; + + if (behaviour->CreateOutputParameter(pPin->GetName(), (CKParameterType)pPin->GetType()) == NULL) + return FALSE; + } + + return TRUE; + } + + /* + ******************************************************************* + * Function: BOOL DeleteIO(CKBehavior* behaviour) + * + * Description : Delete all kind of inputs/outputs on the given behavior + * + * Parameters : + * behaviour The behavior to be naked on. + * + * Returns : BOOL + * + ******************************************************************* + */ +BOOL BGWrapper::DeleteIO(CKBehavior* behaviour) + { + int iIO; + int nbPin0; + + // Input + nbPin0 = behaviour->GetInputCount(); + for (iIO = nbPin0-1; iIO >= 0; iIO--) + { + if (behaviour->DeleteInput(iIO) != CK_OK) + return FALSE; + } + + // Ouput + nbPin0 = behaviour->GetOutputCount(); + for (iIO = nbPin0-1; iIO >= 0; iIO--) + { + if (behaviour->DeleteOutput(iIO) != CK_OK) + return FALSE; + } + + // Parameter In + nbPin0 = behaviour->GetInputParameterCount(); + for (iIO = nbPin0-1; iIO >= 0; iIO--) + { + CKParameterIn* pParam; + + if ((pParam = behaviour->RemoveInputParameter(iIO)) == NULL) + return FALSE; + CKDestroyObject(pParam); + } + + // Parameter Out + nbPin0 = behaviour->GetOutputParameterCount(); + for (iIO = nbPin0-1; iIO >= 0; iIO--) + { + CKParameterOut* pParam; + if ((pParam = behaviour->RemoveOutputParameter(iIO)) == NULL) + return FALSE; + CKDestroyObject(pParam); + } + + return TRUE; + } + + /* + ******************************************************************* + * Function: BOOL HasIO(CKBehavior* behaviour) + * + * Description : return TRUE if the behavior has almost one IN/OU/PIN/POUT + * + * Parameters : + * behaviour The behavior to be checked. + * + * Returns : BOOL + * + ******************************************************************* + */ + +BOOL BGWrapper::HasIO(CKBehavior* behaviour) + { + // Input + if (behaviour->GetInputCount()) + return TRUE; + + // Ouput + if (behaviour->GetOutputCount()) + return TRUE; + + // Parameter In + if (behaviour->GetInputParameterCount()) + return TRUE; + + // Parameter Out + if (behaviour->GetOutputParameterCount()) + return TRUE; + + return FALSE; + } + + /* + ******************************************************************* + * Function: void ActivateNextFrameSubBB(CKBehavior* scriptObject,BOOL &bActivateNextFrame) + * + * Description : set the bActivateNextFrame to TRUE if one sub behavior is still active. + * + * Parameters : + * scriptObject The behavior to be checked. + * + * Returns : void + * + ******************************************************************* + */ +void BGWrapper::ActivateNextFrameSubBB(CKBehavior* scriptObject,BOOL &bActivateNextFrame) +{ + if ( scriptObject == NULL ) + return; + + if ( scriptObject->IsActive() ) + { + bActivateNextFrame = TRUE; + return; + } + + for ( int i = 0; i < scriptObject->GetSubBehaviorCount(); i++) + { + CKBehavior*scriptSub = scriptObject->GetSubBehavior(i); + ActivateNextFrameSubBB(scriptSub,bActivateNextFrame); + } +} + + /* + ******************************************************************* + * Function: void DesactivateSubBB(CKBehavior* scriptObject) + * + * Description : Desactivate all sub-Behavior + * + * Parameters : + * scriptObject The behavior to be totally desactivated. + * + * Returns : void + * + ******************************************************************* + */ +void BGWrapper::DesactivateSubBB(CKBehavior* scriptObject) +{ + if ( scriptObject == NULL ) + return; + + scriptObject->Activate(FALSE,TRUE); + + for ( int i = 0; i < scriptObject->GetSubBehaviorCount(); i++) + { + CKBehavior*scriptSub = scriptObject->GetSubBehavior(i); + DesactivateSubBB(scriptSub); + } +} + + /* + ******************************************************************* + * Function: void OwnerSubBB(CKBehavior* scriptObject,CKBeObject*owner) + * + * Description : Set Owner ptr to all sub-Behavior. + * + * Parameters : + * scriptObject behavior to be parsed. + * owner owner to be assigned. + * + * Returns : void + * + ******************************************************************* + */ +void BGWrapper::OwnerSubBB(CKBehavior* scriptObject,CKBeObject*owner) +{ + if ( scriptObject == NULL ) + return; + + scriptObject->SetSubBehaviorOwner(owner); + scriptObject->SetOwner(owner); + + for ( int i = 0; i < scriptObject->GetSubBehaviorCount(); i++) + { + CKBehavior*scriptSub = scriptObject->GetSubBehavior(i); + OwnerSubBB(scriptSub,owner); + } +} + + /* + ******************************************************************* + * Function: void SetNewBG(CKBehavior *behaviour,CKBehavior *newBehavior) + * + * Description : Set new BB name and store the BG locally. + * + * Parameters : + * behaviour BG wrapper BB + * newBehavior BG assigned to the wrapper + * + * Returns : void + * + ******************************************************************* + */ +void BGWrapper::SetNewBG(CKBehavior *behaviour,CKBehavior *newBehavior) +{ + if ( behaviour == NULL || newBehavior == NULL ) + return; + + CKSTRING nameBG = newBehavior->GetName(); + size_t len = strlen(nameBG); + char*buf = (char*)malloc(len+128); + if ( buf != NULL ) + { + sprintf(buf, "BI(%s)", newBehavior->GetName()); + behaviour->SetName(buf); + free(buf); + } + else + behaviour->SetName("BI(###ERROR###)"); + + behaviour->SetLocalParameterObject(EBGWRAPPERPARAM_PARAMETER_SCRIPT,newBehavior); +} + +/* + ******************************************************************* + * Function: void DestroyCurrentBG(CKLevel* level,CKBehavior *behaviour,CKBehavior *scriptObject) + * + * Description : Destroy the currently wrapped BG + * + * Parameters : + * level level from witch the BG will be removed + * behaviour BG wrapper BB. + * scriptObject BG assigned to the wrapper. + * + * Returns : void + * + ******************************************************************* + */ +void BGWrapper::DestroyCurrentBG(CKLevel* level,CKBehavior *behaviour,CKBehavior *scriptObject) +{ + if ( level == NULL || behaviour == NULL || scriptObject == NULL ) + return; + + behaviour->SetName("BI(###Failed###)"); + + level->BeginRemoveSequence(TRUE); + level->RemoveObject(scriptObject); + level->BeginRemoveSequence(FALSE); + CKDestroyObject(scriptObject); + + behaviour->SetLocalParameterObject(EBGWRAPPERPARAM_PARAMETER_SCRIPT,NULL); + +} diff --git a/ref/vt-ex/src/virtools/Behaviors/generic/BGInstancer.h b/ref/vt-ex/src/virtools/Behaviors/generic/BGInstancer.h new file mode 100644 index 0000000..24dd3f3 --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/generic/BGInstancer.h @@ -0,0 +1,52 @@ +/******************************************************************** + created: 2006/22/06 + created: 22:06:2006 12:26 + filename: x:\junctions\ProjectRoot\current\vt_plugins\vt_toolkit\Behaviors\Generic\BGInstancer.h + file path: x:\junctions\ProjectRoot\current\vt_plugins\vt_toolkit\Behaviors\Generic + file base: BGInstancer + file ext: h + author: mc007 + + purpose: instancing of b-graphs per file +*********************************************************************/ + +#define BGWRAPPER_GUID CKGUID(0x35fb3204,0x6b59721c) + +// Parameters for BGWrapper +enum EBGWRAPPERPARAM + { + // local + EBGWRAPPERPARAM_PARAMETER_SCRIPT = 0, + EBGWRAPPERPARAM_PARAMETER_NAME = 1, + EBGWRAPPERPARAM_LOCAL_PARAMETER_COUNT, + }; + +class BGWrapper +{ + + public: + static CKObjectDeclaration* FillBehaviour( void ); + static CKERROR CreatePrototype( CKBehaviorPrototype** behaviorPrototypePtr ); + static int BehaviourFunction( const CKBehaviorContext& behaviorContext ); + + private: + static CKERROR BGWrapperCB(const CKBehaviorContext& behContext); + + static BOOL HasIO(CKBehavior* pBeh); + static BOOL DeleteIO(CKBehavior* pBeh); + static BOOL CreateIO(CKBehavior* pBeh, CKBehavior* pScript); + static BOOL CheckIO(CKBehavior* pBeh, CKBehavior* pScript); + + static CKBehavior* BGLoader(CKSTRING fileName,const CKBehaviorContext& behContext); + + static void ActivateNextFrameSubBB(CKBehavior* scriptObject,BOOL &bActivateNextFrame); + static void DesactivateSubBB(CKBehavior* scriptObject); + static void OwnerSubBB(CKBehavior* scriptObject,CKBeObject*owner); + static void SetNewBG(CKBehavior *behaviour,CKBehavior *newBehavior); + static void DestroyCurrentBG(CKLevel* level,CKBehavior *behaviour,CKBehavior *scriptObject); + + + +}; + + diff --git a/ref/vt-ex/src/virtools/Behaviors/generic/GBLAsyncBlock.cpp b/ref/vt-ex/src/virtools/Behaviors/generic/GBLAsyncBlock.cpp new file mode 100644 index 0000000..55d10d4 --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/generic/GBLAsyncBlock.cpp @@ -0,0 +1,321 @@ +#include + +#include ".\GBLAsyncBlock.h" + + +/* + ******************************************************************* + * Function: CKObjectDeclaration *FillBehaviour( void ) + * + * Description : As its name infers, this function describes each Building Block + * on a functional level : what it can be applied to, its GUID, its + * creation function, etc.. + * + * + * Paramters : + * None + * + * Returns : CKObjectDeclaration *, containing: + * - The type of object declaration ( Must Be CKDLL_BEHAVIORPROTOTYPE ) + * - The function that will create the CKBehaviorPrototype for this behavior. + * - A short description of what the behavior is supposed to do. + * - The category in which this behavior will appear in the Virtools interface. + * - A unique CKGUID + * - Author and Version info + * - The class identifier of objects to which the behavior can be applied to. + * + ******************************************************************* + */ +CKObjectDeclaration * ExeInThread::FillBehaviour( void ) +{ + CKObjectDeclaration *objectDeclaration = CreateCKObjectDeclaration( "ExecuteBBInThread" ); + + objectDeclaration->SetType( CKDLL_BEHAVIORPROTOTYPE ); + objectDeclaration->SetCreationFunction( ExeInThread::CreatePrototype ); + objectDeclaration->SetDescription( "Executes a BB in a Thread" ); + objectDeclaration->SetCategory( "Narratives/Script Management" ); + objectDeclaration->SetGuid( CKGUID( 0x72387e71,0x89d786d) ); + objectDeclaration->SetVersion( 0x00000001 ); + objectDeclaration->SetAuthorGuid( VTCX_AUTHOR_GUID ); + objectDeclaration->SetAuthorName( VTCX_AUTHOR ); + objectDeclaration->SetCompatibleClassId( CKCID_BEOBJECT ); + + return objectDeclaration; +} + + +/* + ******************************************************************* + * Function: CKERROR CreatePrototype( CKBehaviorPrototype** behaviorPrototypePtr ) + * + * Description : The prototype creation function will be called the first time + * a behavior must be created to create the CKBehaviorPrototype + * that contains the description of the behavior. + * + * Paramters : + * behaviorPrototypePtr w Pointer to a CKBehaviorPrototype object that + * describes the behavior's internal structure + * and relationships with other objects. + * + * Returns : CKERROR + * + ******************************************************************* + */ +CKERROR ExeInThread::CreatePrototype( CKBehaviorPrototype** behaviorPrototypePtr ) +{ + CKBehaviorPrototype *behaviorPrototype = CreateCKBehaviorPrototype( "ExecuteBBInThread" ); + if ( !behaviorPrototype ) + { + return CKERR_OUTOFMEMORY; + } + + //--- Inputs declaration + behaviorPrototype->DeclareInput( "In" ); + + //--- Outputs declaration + behaviorPrototype->DeclareOutput( "Out" ); + + + + //---- Local Parameters Declaration + + behaviorPrototype->DeclareLocalParameter("thethread", CKPGUID_POINTER, "0"); + behaviorPrototype->DeclareLocalParameter("thestatus", CKPGUID_INT, "0"); + + + + //---- Settings Declaration + + behaviorPrototype->SetBehaviorCallbackFct( ExeInThread::CallBack, CKCB_BEHAVIORATTACH|CKCB_BEHAVIORDETACH|CKCB_BEHAVIORDELETE|CKCB_BEHAVIOREDITED|CKCB_BEHAVIORSETTINGSEDITED|CKCB_BEHAVIORLOAD|CKCB_BEHAVIORPRESAVE|CKCB_BEHAVIORPOSTSAVE|CKCB_BEHAVIORRESUME|CKCB_BEHAVIORPAUSE|CKCB_BEHAVIORRESET|CKCB_BEHAVIORRESET|CKCB_BEHAVIORDEACTIVATESCRIPT|CKCB_BEHAVIORACTIVATESCRIPT|CKCB_BEHAVIORREADSTATE, NULL ); + behaviorPrototype->SetFunction( ExeInThread::BehaviourFunction ); + + *behaviorPrototypePtr = behaviorPrototype; + return CK_OK; +} + +/* + ******************************************************************* + * Function: int BehaviourFunction( const CKBehaviorContext& behaviorContext ) + * + * Description : The execution function is the function that will be called + * during the process loop of the behavior engine, if the behavior + * is defined as using an execution function. This function is not + * called if the behavior is defined as a graph. This function is the + * heart of the behavior: it should compute the essence of the behavior, + * in an incremental way. The minimum amount of computing should be + * done at each call, to leave time for the other behaviors to run. + * The function receives the delay in milliseconds that has elapsed + * since the last behavioral process, and should rely on this value to + * manage the amount of effect it has on its computation, if the effect + * of this computation relies on time. + * + * Paramters : + * behaviourContext r Behavior context reference, which gives access to + * frequently used global objects ( context, level, manager, etc... ) + * + * Returns : int, If it is done, it should return CKBR_OK. If it returns + * CKBR_ACTIVATENEXTFRAME, the behavior will again be called + * during the next process loop. + * + ******************************************************************* + */ +int ExeInThread::BehaviourFunction( const CKBehaviorContext& behaviorContext ) +{ + CKBehavior* beh = behaviorContext.Behavior; + CKContext* ctx = beh->GetCKContext(); + + if (beh->IsInputActive(0)) + { + + beh->ActivateInput(0,FALSE); + + VxThread *VXT; + + int status = 0; + beh->GetLocalParameterValue(1,&status); + + if (status == ThreadStatus::Requested) + { + return CKBR_ACTIVATENEXTFRAME; + } + + if (status == ThreadStatus::Active) + { + status = ThreadStatus::Requested; + beh->SetLocalParameterValue(1,&status); + return CKBR_ACTIVATENEXTFRAME; + } + + VXT = new VxThread(); + VXT->SetName("Thread"); + VXT->SetPriority(VXTP_NORMAL); + AsyncThreadInfo * threadInfo; + + threadInfo = new AsyncThreadInfo; + + threadInfo->targetBeh = NULL; + + int count = beh->GetParent()->GetSubBehaviorLinkCount(); + + for (int i=0; iGetParent()->GetSubBehaviorLink(i); + if (link->GetInBehaviorIO() == beh->GetOutput(0)) + { + threadInfo->targetBeh = link->GetOutBehaviorIO()->GetOwner(); + + int targetInputs = threadInfo->targetBeh->GetInputCount(); + if (targetInputs == 1) + { + threadInfo->targetInputToActivate = 0; + } + else + { + for (int j=0; jGetOutBehaviorIO() == threadInfo->targetBeh->GetInput(j)) + { + threadInfo->targetInputToActivate = j; + break; + } + } + } + break; + } + } + + if (threadInfo->targetBeh == NULL) + { + delete threadInfo; + return CKBR_BEHAVIORERROR; + } + + VXT->CreateThread(BlockingThreadFunction,threadInfo); + beh->SetLocalParameterValue(0,&VXT,sizeof(VxThread *)); + + status = ThreadStatus::Active; + beh->SetLocalParameterValue(1,&status); + + return CKBR_ACTIVATENEXTFRAME; + + } + else + { + VxThread *VXT; + beh->GetLocalParameterValue(0,&VXT); + + unsigned int status = -1; + + VXT->GetExitCode(status); + + if (status == VXT_OK) + { + VXT->Close(); + delete VXT; + VXT=NULL; + beh->SetLocalParameterValue(0,&VXT); + + + + int status; + beh->GetLocalParameterValue(1,&status); + + if (status == ThreadStatus::Requested) + { + beh->ActivateInput(0); + status = ThreadStatus::Idle; + beh->SetLocalParameterValue(1,&status); + return CKBR_ACTIVATENEXTFRAME; + + } + + status = ThreadStatus::Idle; + beh->SetLocalParameterValue(1,&status); + return CKBR_OK; + } + + } + + return CKBR_ACTIVATENEXTFRAME; +} + +/* +******************************************************************* +* Function: int Callback( const CKBehaviorContext& behaviorContext ) +* +* Description : The Behavior Callback function is called by Virtools when various events happen +* in the life of a BuildingBlock. Exactly which events trigger a call to the +* Behavior Callback function is defined in the Behavior Prototype, along with the +* declaration of the function pointer +* +* Parameters : +* behaviourContext r Behavior context reference, which gives +* access to frequently used global objects +* ( context, level, manager, etc... ) +* +* Returns : int, The return value of the callback function should be one of the CK_BEHAVIOR_RETURN values. +* +******************************************************************* +*/ +int ExeInThread::CallBack( const CKBehaviorContext& behaviorContext ) +{ + switch ( behaviorContext.CallbackMessage ) + { + case CKM_BEHAVIORATTACH: + break; + case CKM_BEHAVIORDETACH: + break; + case CKM_BEHAVIORDELETE: + break; + case CKM_BEHAVIOREDITED: + break; + case CKM_BEHAVIORSETTINGSEDITED: + break; + case CKM_BEHAVIORLOAD: + break; + case CKM_BEHAVIORPRESAVE: + break; + case CKM_BEHAVIORPOSTSAVE: + break; + case CKM_BEHAVIORRESUME: + { + int status = ThreadStatus::Idle; + behaviorContext.Behavior->SetLocalParameterValue(1,&status); + } + break; + + case CKM_BEHAVIORPAUSE: + break; + case CKM_BEHAVIORRESET: + break; + case CKM_BEHAVIORNEWSCENE: + break; + case CKM_BEHAVIORDEACTIVATESCRIPT: + break; + case CKM_BEHAVIORACTIVATESCRIPT: + break; + case CKM_BEHAVIORREADSTATE: + break; + + } + return CKBR_OK; +} + +unsigned int BlockingThreadFunction(void *arg) +{ + ExeInThread::AsyncThreadInfo* threadInfo = (ExeInThread::AsyncThreadInfo*)arg; + + threadInfo->targetBeh->ActivateInput(threadInfo->targetInputToActivate); + + int res; + + do + { + res = threadInfo->targetBeh->Execute(0); + } + while (res == CKBR_ACTIVATENEXTFRAME); + delete threadInfo; + return VXT_OK; +} + + diff --git a/ref/vt-ex/src/virtools/Behaviors/generic/GBLAsyncBlock.h b/ref/vt-ex/src/virtools/Behaviors/generic/GBLAsyncBlock.h new file mode 100644 index 0000000..5937ab2 --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/generic/GBLAsyncBlock.h @@ -0,0 +1,22 @@ +#pragma once + +class ExeInThread +{ + public: + static CKObjectDeclaration * FillBehaviour( void ); + static int CallBack( const CKBehaviorContext& behaviorContext ); + static int BehaviourFunction( const CKBehaviorContext& behaviorContext ); + static CKERROR CreatePrototype( CKBehaviorPrototype** behaviorPrototypePtr ); + + enum ThreadStatus { + Idle = 0, Requested = 2, Active = 3}; + + + friend unsigned int BlockingThreadFunction(void *arg); + + typedef struct ThreadInfo + { + CKBehavior* targetBeh; + int targetInputToActivate; + } AsyncThreadInfo; +}; diff --git a/ref/vt-ex/src/virtools/Behaviors/generic/GetSubBBId.cpp b/ref/vt-ex/src/virtools/Behaviors/generic/GetSubBBId.cpp new file mode 100644 index 0000000..2d87917 --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/generic/GetSubBBId.cpp @@ -0,0 +1,79 @@ +#include +#include "CKAll.h" +CKObjectDeclaration *FillBehaviorGetNextBBIdDecl(); +CKERROR CreateGetNextBBIdProto(CKBehaviorPrototype **); +int GetNextBBId(const CKBehaviorContext& behcontext); +CKERROR GetNextBBIdCB(const CKBehaviorContext& behcontext); + + +CKObjectDeclaration *FillBehaviorGetNextBBIdDecl() +{ + CKObjectDeclaration *od = CreateCKObjectDeclaration("GetNextBBId"); + od->SetDescription("Returns behavior id of first found and connected building block or behavior graph"); + + od->SetType( CKDLL_BEHAVIORPROTOTYPE); + od->SetGuid(CKGUID(0x572066cc,0x58402b59)); + od->SetAuthorGuid(VIRTOOLS_GUID); + od->SetAuthorName("Günter Baumgart"); + od->SetVersion(0x00010000); + od->SetCreationFunction(CreateGetNextBBIdProto); + od->SetCompatibleClassId(CKCID_BEOBJECT); + od->SetCategory("Narratives"); + return od; +} + + +CKERROR CreateGetNextBBIdProto(CKBehaviorPrototype **pproto) +{ + CKBehaviorPrototype *proto = NULL; + proto = CreateCKBehaviorPrototype("GetNextBBId"); + if(!proto) return CKERR_OUTOFMEMORY; + + proto->DeclareInput("In"); + proto->DeclareOutput("Out"); + + proto->DeclareOutParameter("ID",CKPGUID_INT); + proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); + proto->SetFunction( GetNextBBId ); + + *pproto = proto; + return CK_OK; + +} + + +int GetNextBBId(const CKBehaviorContext& behcontext) +{ + CKBehavior* beh = behcontext.Behavior; + CKContext* ctx = behcontext.Context; + + beh->ActivateInput(0,FALSE); + + int count = beh->GetParent()->GetSubBehaviorLinkCount(); + int result = -1; + + for (int i=0; iGetParent()->GetSubBehaviorLink(i); + if (link->GetInBehaviorIO() == beh->GetOutput(0)) + { + result = link->GetOutBehaviorIO()->GetOwner()->GetID(); + beh->SetOutputParameterValue(0,&result); + break; + } + } + + CKBehavior *script = static_cast(ctx->GetObject(result)); + if (script) + { + int bc = script->GetOutputCount(); + + int bc2 = script->GetInputCount(); + + } + + + beh->ActivateOutput(0); + beh->SetOutputParameterValue(0,&result); + return CKBR_OK; +} diff --git a/ref/vt-ex/src/virtools/Behaviors/joystick/JSetXYForce.cpp b/ref/vt-ex/src/virtools/Behaviors/joystick/JSetXYForce.cpp new file mode 100644 index 0000000..0315528 --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/joystick/JSetXYForce.cpp @@ -0,0 +1,572 @@ +#include +#define STRICT +#define DIRECTINPUT_VERSION 0x0800 + +#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } +#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } } +#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } } + +#include +#include +#include +#include +#include +#include + +#include "CKAll.h" + + +static CKContext *ctx = NULL; + +//---------------------------------------------------------------- +// +// +// +#define HAS_CONFIG + +#ifdef HAS_CONFIG +#include "gConfig.h" +#endif // BB_TOOLS + +#ifdef BB_TOOLS + + #include + #include "vtLogTools.h" + #include "vtCBBErrorHelper.h" + #include + #include + + using namespace vtTools::BehaviorTools; + +#endif + +//----------------------------------------------------------------------------- +// Defines, constants, and global variables +//----------------------------------------------------------------------------- +struct EFFECTS_NODE +{ + LPDIRECTINPUTEFFECT pDIEffect; + DWORD dwPlayRepeatCount; + EFFECTS_NODE* pNext; +}; + +LPDIRECTINPUT8 g_pDI = NULL; +LPDIRECTINPUTDEVICE8 g_pFFDevice = NULL; +EFFECTS_NODE g_EffectsList; + +static bool gInitiated = false; + +//----------------------------------------------------------------------------- +// Function-prototypes +//----------------------------------------------------------------------------- +INT_PTR CALLBACK MainDialogProc( HWND, UINT, WPARAM, LPARAM ); +BOOL CALLBACK EnumFFDevicesCallback2( LPCDIDEVICEINSTANCE pDDI, VOID* pvRef ); +BOOL CALLBACK EnumAndCreateEffectsCallback2( LPCDIFILEEFFECT pDIFileEffect, VOID* pvRef ); + +HRESULT InitDirectInput2( HWND hDlg ); +HRESULT FreeDirectInput2(); +VOID EmptyEffectList2(); +HRESULT OnReadFile2( HWND hDlg,const char*file); +HRESULT OnPlayEffects2( HWND hDlg ); + +LPDIRECTINPUTEFFECT g_pEffect = NULL; +BOOL g_bActive = TRUE; + +DWORD g_dwNumForceFeedbackAxis = 0; +INT g_nXForce; +INT g_nYForce; +DWORD g_dwLastEffectSet; // Time of the previous force feedback effect set + +//----------------------------------------------------------------------------- +// Name: EnumAxesCallback() +// Desc: Callback function for enumerating the axes on a joystick and counting +// each force feedback enabled axis +//----------------------------------------------------------------------------- +BOOL CALLBACK EnumAxesCallback( const DIDEVICEOBJECTINSTANCE* pdidoi, + VOID* pContext ) +{ + DWORD* pdwNumForceFeedbackAxis = ( DWORD* )pContext; + + if( ( pdidoi->dwFlags & DIDOI_FFACTUATOR ) != 0 ) + ( *pdwNumForceFeedbackAxis )++; + + return DIENUM_CONTINUE; +} + +HRESULT InitDirectInput2( HWND hDlg ) +{ + HRESULT hr; + + DIPROPDWORD dipdw; + + // Setup the g_EffectsList circular linked list + ZeroMemory( &g_EffectsList, sizeof( EFFECTS_NODE ) ); + g_EffectsList.pNext = &g_EffectsList; + + // Create a DInput object + if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) ) + { + ctx->OutputToConsole("PlayFFE :: DirectInput8Create"); + return hr; + } + + // Get the first enumerated force feedback device + if( FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumFFDevicesCallback2, 0, + DIEDFL_ATTACHEDONLY | + DIEDFL_FORCEFEEDBACK ) ) ) + { + ctx->OutputToConsole("PlayFFE :: EnumDevices failed"); + return hr; + } + + + if( g_pFFDevice == NULL ) + { + + ctx->OutputToConsole("PlayFFE :: No force feedback device found."); + return -1; + } + + + // Set the data format + if( FAILED( hr = g_pFFDevice->SetDataFormat( &c_dfDIJoystick ) ) ) + return hr; + + + // Set the coop level + //hr = g_pFFDevice->SetCooperativeLevel( hDlg , DISCL_EXCLUSIVE | DISCL_FOREGROUND) ; + hr = g_pFFDevice->SetCooperativeLevel( hDlg , DISCL_EXCLUSIVE | DISCL_BACKGROUND) ; + + + + //DISCL_NONEXCLUSIVE + + // Since we will be playing force feedback effects, we should disable the + // auto-centering spring. + dipdw.diph.dwSize = sizeof( DIPROPDWORD ); + dipdw.diph.dwHeaderSize = sizeof( DIPROPHEADER ); + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + dipdw.dwData = FALSE; + + if( FAILED( hr = g_pFFDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ) ) ) + return hr; + + // Enumerate and count the axes of the joystick + if( FAILED( hr = g_pFFDevice->EnumObjects( EnumAxesCallback, + ( VOID* )&g_dwNumForceFeedbackAxis, DIDFT_AXIS ) ) ) + return hr; + + + // This simple sample only supports one or two axis joysticks + if( g_dwNumForceFeedbackAxis > 2 ) + g_dwNumForceFeedbackAxis = 2; + + // This application needs only one effect: Applying raw forces. + DWORD rgdwAxes[2] = { DIJOFS_X, DIJOFS_Y }; + LONG rglDirection[2] = { 0,0 }; + DICONSTANTFORCE cf = { 0 }; + cf.lMagnitude = 0; + + + DIEFFECT eff; + ZeroMemory( &eff, sizeof( eff ) ); + eff.dwSize = sizeof( DIEFFECT ); + eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; + eff.dwDuration = INFINITE; + eff.dwSamplePeriod = 0; + eff.dwGain = DI_FFNOMINALMAX; + eff.dwTriggerButton = DIEB_NOTRIGGER; + eff.dwTriggerRepeatInterval = 0; + eff.cAxes = g_dwNumForceFeedbackAxis; + eff.rgdwAxes = rgdwAxes; + eff.rglDirection = rglDirection; + eff.lpEnvelope = 0; + eff.cbTypeSpecificParams = sizeof( DICONSTANTFORCE ); + eff.lpvTypeSpecificParams = &cf; + eff.dwStartDelay = 0; + + // Create the prepared effect + if( FAILED( hr = g_pFFDevice->CreateEffect( GUID_ConstantForce, + &eff, &g_pEffect, NULL ) ) ) + { + return hr; + } + + if( NULL == g_pEffect ) + return E_FAIL; + + return S_OK; +} + + + + +//----------------------------------------------------------------------------- +// Name: EnumFFDevicesCallback2() +// Desc: Get the first enumerated force feedback device +//----------------------------------------------------------------------------- +BOOL CALLBACK EnumFFDevicesCallback2( LPCDIDEVICEINSTANCE pDDI, VOID* pvRef ) +{ + if( FAILED( g_pDI->CreateDevice( pDDI->guidInstance, &g_pFFDevice, NULL ) ) ) + return DIENUM_CONTINUE; // If failed, try again + + // Stop when a device was successfully found + return DIENUM_STOP; +} + + + + +//----------------------------------------------------------------------------- +// Name: FreeDirectInput2() +// Desc: Initialize the DirectInput variables. +//----------------------------------------------------------------------------- +HRESULT FreeDirectInput2() +{ + // Release any DirectInputEffect objects. + if( g_pFFDevice ) + { + EmptyEffectList2(); + g_pFFDevice->Unacquire(); + SAFE_RELEASE( g_pFFDevice ); + } + + // Release any DirectInput objects. + SAFE_RELEASE( g_pDI ); + + return S_OK; +} + + + + +//----------------------------------------------------------------------------- +// Name: EmptyEffectList2() +// Desc: Goes through the circular linked list and releases the effects, +// and deletes the nodes +//----------------------------------------------------------------------------- +VOID EmptyEffectList2() +{ + EFFECTS_NODE* pEffectNode = g_EffectsList.pNext; + EFFECTS_NODE* pEffectDelete; + + while ( pEffectNode != &g_EffectsList ) + { + pEffectDelete = pEffectNode; + pEffectNode = pEffectNode->pNext; + + SAFE_RELEASE( pEffectDelete->pDIEffect ); + SAFE_DELETE( pEffectDelete ); + } + + g_EffectsList.pNext = &g_EffectsList; +} + + + + +//----------------------------------------------------------------------------- +// Name: OnReadFile2() +// Desc: Reads a file contain a collection of DirectInput force feedback +// effects. It creates each of effect read in and stores it +// in the linked list, g_EffectsList. +//----------------------------------------------------------------------------- +HRESULT OnReadFile2( HWND hDlg,const char*file) +{ + HRESULT hr; + + EmptyEffectList2(); + + // Enumerate the effects in the file selected, and create them in the callback + if( FAILED( hr = g_pFFDevice->EnumEffectsInFile( file,EnumAndCreateEffectsCallback2, + NULL, DIFEF_MODIFYIFNEEDED ) ) ) + return hr; + + // If list of effects is empty, then we haven't been able to create any effects + if( g_EffectsList.pNext == &g_EffectsList ) + { + ctx->OutputToConsole("Unable to create any effects."); + + } + else + { + // We have effects so enable the 'play effects' button + + } + + return S_OK; +} + + + + +BOOL CALLBACK EnumAndCreateEffectsCallback2(LPCDIFILEEFFECT pDIFileEffect, VOID* pvRef ) +{ + HRESULT hr; + LPDIRECTINPUTEFFECT pDIEffect = NULL; + + // Create the file effect + if( FAILED( hr = g_pFFDevice->CreateEffect( pDIFileEffect->GuidEffect, + pDIFileEffect->lpDiEffect, + &pDIEffect, NULL ) ) ) + { + ctx->OutputToConsole("Could not create force feedback effect on this device"); + return DIENUM_CONTINUE; + } + + // Create a new effect node + EFFECTS_NODE* pEffectNode = new EFFECTS_NODE; + if( NULL == pEffectNode ) + return DIENUM_STOP; + + // Fill the pEffectNode up + ZeroMemory( pEffectNode, sizeof( EFFECTS_NODE ) ); + pEffectNode->pDIEffect = pDIEffect; + pEffectNode->dwPlayRepeatCount = 1; + + // Add pEffectNode to the circular linked list, g_EffectsList + pEffectNode->pNext = g_EffectsList.pNext; + g_EffectsList.pNext = pEffectNode; + + return DIENUM_CONTINUE; +} + + + + +HRESULT OnPlayEffects2( HWND hDlg ) +{ + EFFECTS_NODE* pEffectNode = g_EffectsList.pNext; + LPDIRECTINPUTEFFECT pDIEffect = NULL; + HRESULT hr; + + // Stop all previous forces + if( FAILED( hr = g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ) ) ) + return hr; + + + while ( pEffectNode != &g_EffectsList ) + { + // Play all of the effects enumerated in the file + pDIEffect = pEffectNode->pDIEffect; + + if( NULL != pDIEffect ) + { + if( FAILED( hr = pDIEffect->Start( pEffectNode->dwPlayRepeatCount, 0 ) ) ) + return hr; + } + + pEffectNode = pEffectNode->pNext; + } + + return S_OK; +} + + + + +CKObjectDeclaration *FillBehaviorJSetXYForceDecl(); +CKERROR CreateJSetXYForceProto(CKBehaviorPrototype **); +int JSetXYForce(const CKBehaviorContext& behcontext); +CKERROR PlayFFECallBackObject(const CKBehaviorContext& behcontext); +CKObjectDeclaration *FillBehaviorJSetXYForceDecl() +{ + CKObjectDeclaration *od = CreateCKObjectDeclaration("JSetXYForce"); + od->SetDescription(""); + od->SetType( CKDLL_BEHAVIORPROTOTYPE); + od->SetGuid(CKGUID(0x6890534f,0x31c12074)); + od->SetAuthorGuid(VIRTOOLS_GUID); + od->SetAuthorName("Virtools"); + od->SetVersion(0x00010000); + od->SetCreationFunction(CreateJSetXYForceProto); + od->SetCompatibleClassId(CKCID_BEOBJECT); + od->SetCategory("Controllers/Joystick"); + return od; +} + + + +enum bbIO_Inputs +{ + BB_I_DO, + BB_I_RELEASE, +}; + +enum bbIO_Outputs +{ + BB_O_DONE, + BB_O_RELEASED, + BB_O_ERROR, +}; +CKERROR CreateJSetXYForceProto(CKBehaviorPrototype **pproto) +{ + CKBehaviorPrototype *proto = NULL; + proto = CreateCKBehaviorPrototype("JSetXYForce"); + if(!proto) return CKERR_OUTOFMEMORY; + + proto->DeclareInput("In"); + //proto->DeclareInput("stop"); + proto->DeclareInput("release device"); + + proto->DeclareOutput("Done"); + //proto->DeclareOutput("Stopped"); + proto->DeclareOutput("Released"); + proto->DeclareOutput("Error"); + + + proto->DeclareInParameter("Force Vector",CKPGUID_2DVECTOR); + proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); + proto->SetFunction( JSetXYForce ); + + proto->SetBehaviorCallbackFct(PlayFFECallBackObject); + + *pproto = proto; + return CK_OK; +} + + +HRESULT SetDeviceForcesXY(float x,float y) +{ + // Modifying an effect is basically the same as creating a new one, except + // you need only specify the parameters you are modifying + LONG rglDirection[2] = { 0, 0 }; + + DICONSTANTFORCE cf; + + if( g_dwNumForceFeedbackAxis == 1 ) + { + // If only one force feedback axis, then apply only one direction and + // keep the direction at zero + cf.lMagnitude = x; + rglDirection[0] = 0; + } + else + { + // If two force feedback axis, then apply magnitude from both directions + rglDirection[0] = x; + rglDirection[1] = y; + cf.lMagnitude = ( DWORD )sqrt( x * x + y * y ); + + } + + DIEFFECT eff; + ZeroMemory( &eff, sizeof( eff ) ); + eff.dwSize = sizeof( DIEFFECT ); + eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS; + eff.cAxes = g_dwNumForceFeedbackAxis; + eff.rglDirection = rglDirection; + eff.lpEnvelope = 0; + eff.cbTypeSpecificParams = sizeof( DICONSTANTFORCE ); + eff.lpvTypeSpecificParams = &cf; + eff.dwStartDelay = 0; + + // Now set the new parameters and start the effect immediately. + HRESULT hr = S_OK; + + hr = g_pEffect->SetParameters( &eff, DIEP_DIRECTION |DIEP_TYPESPECIFICPARAMS |DIEP_START ); + HRESULT a1 = DIERR_INVALIDPARAM; + + + + return hr; +} + + +int JSetXYForce(const CKBehaviorContext& behcontext) +{ + CKBehavior* beh = behcontext.Behavior; + CKContext* ctx2 = behcontext.Context; + if (!ctx) + { + ctx = ctx2; + } + + HWND mWin = (HWND )ctx->GetMainWindow(); + HRESULT hr = S_OK; + + + //init and load effect + if( beh->IsInputActive(BB_I_DO) ) + { + beh->ActivateInput(BB_I_DO,FALSE); + if (!gInitiated) + { + if (!InitDirectInput2(mWin) == S_OK) + { + beh->ActivateOutput(BB_O_ERROR); + return CKBR_OK; + }else{ + + hr = g_pFFDevice->Acquire(); + hr =g_pEffect->Start( 1, 0 ); // Start the effect +// E_ACCESSDENIED + + gInitiated = true; + } + } + + Vx2DVector vectorForce; + beh->GetInputParameterValue(0,&vectorForce); + + + + SetDeviceForcesXY(vectorForce.x,vectorForce.y); + beh->ActivateOutput(BB_O_DONE); + } + + + //play + + if( beh->IsInputActive(BB_I_RELEASE)) + { + beh->ActivateInput(BB_I_RELEASE,FALSE); + { + beh->ActivateOutput(BB_I_RELEASE); + FreeDirectInput2(); + return CKBR_OK; + } + } + + + /* + //stop the effect + if( beh->IsInputActive(2) ){ + beh->ActivateInput(2,FALSE); + + //g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); + beh->ActivateOutput(2); + return CKBR_OK; + }*/ + + + return CKBR_OK; +} + + +CKERROR PlayFFECallBackObject(const CKBehaviorContext& behcontext) +{ + CKBehavior* beh = behcontext.Behavior; + + switch(behcontext.CallbackMessage) { + case CKM_BEHAVIORCREATE: + case CKM_BEHAVIORLOAD: + case CKM_BEHAVIORDETACH: + case CKM_BEHAVIORRESET: + { + + + gInitiated = false; + if ( g_pFFDevice) + g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); + FreeDirectInput2(); + + //Sleep(2000); + + + } + break; + } + + return CKBR_OK; +} diff --git a/ref/vt-ex/src/virtools/Behaviors/joystick/PlayEffect.cpp b/ref/vt-ex/src/virtools/Behaviors/joystick/PlayEffect.cpp new file mode 100644 index 0000000..efdc369 --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/joystick/PlayEffect.cpp @@ -0,0 +1,471 @@ +#define STRICT +#define DIRECTINPUT_VERSION 0x0800 + +#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } +#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } } +#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } } + +#include +#include +#include +#include +#include +#include + +#include "CKAll.h" + + +static CKContext *ctx = NULL; + +//---------------------------------------------------------------- +// +// +// +#define HAS_CONFIG + +#ifdef HAS_CONFIG +#include "gConfig.h" +#endif // BB_TOOLS + +#ifdef BB_TOOLS + + #include + #include "vtLogTools.h" + #include "vtCBBErrorHelper.h" + #include + #include + + using namespace vtTools::BehaviorTools; + +#endif + +//----------------------------------------------------------------------------- +// Defines, constants, and global variables +//----------------------------------------------------------------------------- +struct EFFECTS_NODE +{ + LPDIRECTINPUTEFFECT pDIEffect; + DWORD dwPlayRepeatCount; + EFFECTS_NODE* pNext; +}; + +LPDIRECTINPUT8 g_pDI = NULL; +LPDIRECTINPUTDEVICE8 g_pFFDevice = NULL; +EFFECTS_NODE g_EffectsList; + + + + +//----------------------------------------------------------------------------- +// Function-prototypes +//----------------------------------------------------------------------------- +INT_PTR CALLBACK MainDialogProc( HWND, UINT, WPARAM, LPARAM ); +BOOL CALLBACK EnumFFDevicesCallback( LPCDIDEVICEINSTANCE pDDI, VOID* pvRef ); +BOOL CALLBACK EnumAndCreateEffectsCallback( LPCDIFILEEFFECT pDIFileEffect, VOID* pvRef ); + +HRESULT InitDirectInput( HWND hDlg ); +HRESULT FreeDirectInput2(); +VOID EmptyEffectList(); +HRESULT OnReadFile( HWND hDlg,const char*file); +HRESULT OnPlayEffects2( HWND hDlg ); + +HRESULT InitDirectInput( HWND hDlg ) +{ + HRESULT hr; + + // Setup the g_EffectsList circular linked list + ZeroMemory( &g_EffectsList, sizeof( EFFECTS_NODE ) ); + g_EffectsList.pNext = &g_EffectsList; + + // Create a DInput object + if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) ) + { + ctx->OutputToConsole("PlayFFE :: DirectInput8Create"); + return hr; + } + + // Get the first enumerated force feedback device + if( FAILED( hr = g_pDI->EnumDevices( 0, EnumFFDevicesCallback, 0, + DIEDFL_ATTACHEDONLY | + DIEDFL_FORCEFEEDBACK ) ) ) + { + ctx->OutputToConsole("PlayFFE :: EnumDevices failed"); + return hr; + } + + + if( g_pFFDevice == NULL ) + { + + ctx->OutputToConsole("PlayFFE :: No force feedback device found."); + return -1; + } + + + // Set the data format + if( FAILED( hr = g_pFFDevice->SetDataFormat( &c_dfDIJoystick ) ) ) + return hr; + + + // Set the coop level + hr = g_pFFDevice->SetCooperativeLevel( hDlg , DISCL_EXCLUSIVE | DISCL_FOREGROUND) ; + + + + // Disable auto-centering spring + DIPROPDWORD dipdw; + dipdw.diph.dwSize = sizeof(DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + dipdw.dwData = FALSE; + + + + if( FAILED( hr = g_pFFDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ) ) ) + return hr; + + // Acquire the device + if( FAILED( hr = g_pFFDevice->Acquire() ) ) + return hr; + + + int op = 2; + + return S_OK; +} + + + + +//----------------------------------------------------------------------------- +// Name: EnumFFDevicesCallback() +// Desc: Get the first enumerated force feedback device +//----------------------------------------------------------------------------- +BOOL CALLBACK EnumFFDevicesCallback( LPCDIDEVICEINSTANCE pDDI, VOID* pvRef ) +{ + if( FAILED( g_pDI->CreateDevice( pDDI->guidInstance, &g_pFFDevice, NULL ) ) ) + return DIENUM_CONTINUE; // If failed, try again + + // Stop when a device was successfully found + return DIENUM_STOP; +} + + + + +//----------------------------------------------------------------------------- +// Name: FreeDirectInput2() +// Desc: Initialize the DirectInput variables. +//----------------------------------------------------------------------------- +HRESULT FreeDirectInput2() +{ + // Release any DirectInputEffect objects. + if( g_pFFDevice ) + { + EmptyEffectList(); + g_pFFDevice->Unacquire(); + SAFE_RELEASE( g_pFFDevice ); + } + + // Release any DirectInput objects. + SAFE_RELEASE( g_pDI ); + + return S_OK; +} + + + + +//----------------------------------------------------------------------------- +// Name: EmptyEffectList() +// Desc: Goes through the circular linked list and releases the effects, +// and deletes the nodes +//----------------------------------------------------------------------------- +VOID EmptyEffectList() +{ + EFFECTS_NODE* pEffectNode = g_EffectsList.pNext; + EFFECTS_NODE* pEffectDelete; + + while ( pEffectNode != &g_EffectsList ) + { + pEffectDelete = pEffectNode; + pEffectNode = pEffectNode->pNext; + + SAFE_RELEASE( pEffectDelete->pDIEffect ); + SAFE_DELETE( pEffectDelete ); + } + + g_EffectsList.pNext = &g_EffectsList; +} + + + + +//----------------------------------------------------------------------------- +// Name: OnReadFile() +// Desc: Reads a file contain a collection of DirectInput force feedback +// effects. It creates each of effect read in and stores it +// in the linked list, g_EffectsList. +//----------------------------------------------------------------------------- +HRESULT OnReadFile( HWND hDlg,const char*file) +{ + HRESULT hr; + + EmptyEffectList(); + + // Enumerate the effects in the file selected, and create them in the callback + if( FAILED( hr = g_pFFDevice->EnumEffectsInFile( file,EnumAndCreateEffectsCallback, + NULL, DIFEF_MODIFYIFNEEDED ) ) ) + return hr; + + // If list of effects is empty, then we haven't been able to create any effects + if( g_EffectsList.pNext == &g_EffectsList ) + { + ctx->OutputToConsole("Unable to create any effects."); + + } + else + { + // We have effects so enable the 'play effects' button + + } + + return S_OK; +} + + + + +//----------------------------------------------------------------------------- +// Name: EnumAndCreateEffectsCallback() +// Desc: Create the effects as they are enumerated and add them to the +// linked list, g_EffectsList +//----------------------------------------------------------------------------- +BOOL CALLBACK EnumAndCreateEffectsCallback(LPCDIFILEEFFECT pDIFileEffect, VOID* pvRef ) +{ + HRESULT hr; + LPDIRECTINPUTEFFECT pDIEffect = NULL; + + // Create the file effect + if( FAILED( hr = g_pFFDevice->CreateEffect( pDIFileEffect->GuidEffect, + pDIFileEffect->lpDiEffect, + &pDIEffect, NULL ) ) ) + { + ctx->OutputToConsole("Could not create force feedback effect on this device"); + return DIENUM_CONTINUE; + } + + // Create a new effect node + EFFECTS_NODE* pEffectNode = new EFFECTS_NODE; + if( NULL == pEffectNode ) + return DIENUM_STOP; + + // Fill the pEffectNode up + ZeroMemory( pEffectNode, sizeof( EFFECTS_NODE ) ); + pEffectNode->pDIEffect = pDIEffect; + pEffectNode->dwPlayRepeatCount = 1; + + // Add pEffectNode to the circular linked list, g_EffectsList + pEffectNode->pNext = g_EffectsList.pNext; + g_EffectsList.pNext = pEffectNode; + + return DIENUM_CONTINUE; +} + + + + +//----------------------------------------------------------------------------- +// Name: OnPlayEffects2() +// Desc: Plays all of the effects enumerated in the file +//----------------------------------------------------------------------------- +HRESULT OnPlayEffects2( HWND hDlg ) +{ + EFFECTS_NODE* pEffectNode = g_EffectsList.pNext; + LPDIRECTINPUTEFFECT pDIEffect = NULL; + HRESULT hr; + + // Stop all previous forces + if( FAILED( hr = g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ) ) ) + return hr; + + + while ( pEffectNode != &g_EffectsList ) + { + // Play all of the effects enumerated in the file + pDIEffect = pEffectNode->pDIEffect; + + if( NULL != pDIEffect ) + { + if( FAILED( hr = pDIEffect->Start( pEffectNode->dwPlayRepeatCount, 0 ) ) ) + return hr; + } + + pEffectNode = pEffectNode->pNext; + } + + return S_OK; +} + + + + +CKObjectDeclaration *FillBehaviorPlayFFEffectDecl(); +CKERROR CreatePlayFFEffectProto(CKBehaviorPrototype **); +int PlayFFEffect(const CKBehaviorContext& behcontext); +CKERROR PlayFFECallBackObject(const CKBehaviorContext& behcontext); + + +CKObjectDeclaration *FillBehaviorPlayFFEffectDecl() +{ + CKObjectDeclaration *od = CreateCKObjectDeclaration("PlayFFEffect"); + od->SetDescription(""); + od->SetType( CKDLL_BEHAVIORPROTOTYPE); + od->SetGuid(CKGUID(0x54397475,0x4ca43e26)); + od->SetAuthorGuid(VIRTOOLS_GUID); + od->SetAuthorName("Virtools"); + od->SetVersion(0x00010000); + od->SetCreationFunction(CreatePlayFFEffectProto); + od->SetCompatibleClassId(CKCID_BEOBJECT); + od->SetCategory("Controllers/Joystick"); + return od; +} + + +CKERROR CreatePlayFFEffectProto(CKBehaviorPrototype **pproto) +{ + CKBehaviorPrototype *proto = NULL; + proto = CreateCKBehaviorPrototype("PlayFFEffect"); + if(!proto) return CKERR_OUTOFMEMORY; + + proto->DeclareInput("Init"); + proto->DeclareInput("play"); + proto->DeclareInput("stop"); + proto->DeclareInput("release device"); + + + proto->DeclareOutput("initiated"); + proto->DeclareOutput("play exit"); + proto->DeclareOutput("stopped"); + proto->DeclareOutput("released"); + + proto->DeclareOutput("error"); + + + proto->DeclareInParameter("effect file",CKPGUID_STRING); + proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); + proto->SetFunction( PlayFFEffect ); + + proto->SetBehaviorCallbackFct(PlayFFECallBackObject); + + *pproto = proto; + return CK_OK; + +} + + +int PlayFFEffect(const CKBehaviorContext& behcontext) +{ + CKBehavior* beh = behcontext.Behavior; + CKContext* ctx2 = behcontext.Context; + ctx = ctx2; + + + + HWND mWin = (HWND )ctx->GetMainWindow(); + + //init and load effect + if( beh->IsInputActive(0) ){ + beh->ActivateInput(0,FALSE); + + + HRESULT result = InitDirectInput(mWin); + HRESULT sa = S_OK; + if (InitDirectInput(mWin) == S_OK) + { + + XString filename((CKSTRING) beh->GetInputParameterReadDataPtr(0)); + OnReadFile(mWin,filename.Str()); + beh->ActivateOutput(0); + return CKBR_OK; + }else{ + beh->ActivateOutput(4); + return CKBR_OK; + } + + } + + + //play + + if( beh->IsInputActive(1) ){ + beh->ActivateInput(1,FALSE); + + + if (OnPlayEffects2(NULL) != S_OK ){ + beh->ActivateOutput(4); + return CKBR_OK; + } + beh->ActivateOutput(1); + return CKBR_OK; + } + + + //stop the effect + if( beh->IsInputActive(2) ){ + beh->ActivateInput(2,FALSE); + + // Stop all previous forces + g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); + beh->ActivateOutput(2); + return CKBR_OK; + } + + + // [11/7/2004] + //save device release + + if( beh->IsInputActive(3) ){ + beh->ActivateInput(3,FALSE); + + + + if ( g_pFFDevice) + g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); + + FreeDirectInput2(); + beh->ActivateOutput(3); + return CKBR_OK; + + + } + + return CKBR_OK; +} + + +CKERROR PlayFFECallBackObject(const CKBehaviorContext& behcontext) +{ + CKBehavior* beh = behcontext.Behavior; + + switch(behcontext.CallbackMessage) { + case CKM_BEHAVIORCREATE: + case CKM_BEHAVIORLOAD: + case CKM_BEHAVIORDETACH: + case CKM_BEHAVIORRESET: + { + + + if ( g_pFFDevice) + g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ); + FreeDirectInput2(); + //Sleep(2000); + + + } + break; + } + + return CKBR_OK; +} diff --git a/ref/vt-ex/src/virtools/Behaviors/joystick/hasFFe.cpp b/ref/vt-ex/src/virtools/Behaviors/joystick/hasFFe.cpp new file mode 100644 index 0000000..f6149f8 --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/joystick/hasFFe.cpp @@ -0,0 +1,169 @@ +#include +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +// +// HasFFEffects +// +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// + +#define STRICT +//#define DIRECTINPUT_VERSION 0x0800 + + +#define SAFE_DELETE(p) { if(p) { delete (p); (p)=NULL; } } +#define SAFE_DELETE_ARRAY(p) { if(p) { delete[] (p); (p)=NULL; } } +#define SAFE_RELEASE(p) { if(p) { (p)->Release(); (p)=NULL; } } + +#include +#include +#include +#include +#include + +#include "dinput.h" + +#include "CKAll.h" + +//---------------------------------------------------------------- +// +// +// + +#define HAS_CONFIG + +#ifdef HAS_CONFIG + #include "gConfig.h" +#endif // BB_TOOLS + +#ifdef BB_TOOLS + + + #include + #include "vtLogTools.h" + #include "vtCBBErrorHelper.h" + #include + #include + + using namespace vtTools::BehaviorTools; + +#endif + + + +CKObjectDeclaration *FillBehaviorHasFFEffectsDecl(); +CKERROR CreateHasFFEffectsProto(CKBehaviorPrototype **); +int HasFFEffects(const CKBehaviorContext& behcontext); +CKERROR PlayFFECallBackObject2(const CKBehaviorContext& behcontext); + + +CKObjectDeclaration *FillBehaviorHasFFEffectsDecl() +{ + CKObjectDeclaration *od = CreateCKObjectDeclaration("JHasForceFeedback"); + od->SetDescription(""); + od->SetType( CKDLL_BEHAVIORPROTOTYPE); + od->SetGuid(CKGUID(0x12641a78,0x7ca70c45)); + od->SetAuthorGuid(VIRTOOLS_GUID); + od->SetAuthorName("Virtools"); + od->SetVersion(0x00010000); + od->SetCreationFunction(CreateHasFFEffectsProto); + od->SetCompatibleClassId(CKCID_BEOBJECT); + od->SetCategory("Controllers/Joystick"); + return od; +} + + +CKERROR CreateHasFFEffectsProto(CKBehaviorPrototype **pproto) +{ + CKBehaviorPrototype *proto = NULL; + proto = CreateCKBehaviorPrototype("JHasForceFeedback"); + if(!proto) return CKERR_OUTOFMEMORY; + + proto->DeclareInput("In"); + proto->DeclareOutput("yes"); + proto->DeclareOutput("no"); + + proto->SetFlags(CK_BEHAVIORPROTOTYPE_NORMAL); + proto->SetFunction( HasFFEffects ); + proto->SetBehaviorCallbackFct(PlayFFECallBackObject2); + + *pproto = proto; + return CK_OK; + +} + + +LPDIRECTINPUT8 g_pDI2 = NULL; +LPDIRECTINPUTDEVICE8 g_pFFDevice2 = NULL; + +BOOL CALLBACK EnumFFDevicesCallback0( LPCDIDEVICEINSTANCE pDDI, VOID* pvRef ) +{ + if( FAILED( g_pDI2->CreateDevice( pDDI->guidInstance, &g_pFFDevice2, NULL ) ) ) + return DIENUM_CONTINUE; // If failed, try again + return DIENUM_STOP; +} + + + +HRESULT FreeDirectInput0() +{ + // Release any DirectInputEffect objects. + if( g_pFFDevice2 ) + { + + g_pFFDevice2->Unacquire(); + SAFE_RELEASE( g_pFFDevice2 ); + } + + // Release any DirectInput objects. + SAFE_RELEASE( g_pDI2 ); + + return S_OK; +} + +int HasFFEffects(const CKBehaviorContext& behcontext) +{ + CKBehavior* beh = behcontext.Behavior; + CKContext* ctx = behcontext.Context; + + HWND mWin = (HWND )ctx->GetMainWindow(); + + DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI2, NULL ) ; + + // Get the first enumerated force feedback device + g_pDI2->EnumDevices( 0, EnumFFDevicesCallback0, 0, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK ); + + if( g_pFFDevice2 == NULL ) + beh->ActivateOutput(1); + else + beh->ActivateOutput(0); + + FreeDirectInput0(); + return CKBR_OK; +} + + +CKERROR PlayFFECallBackObject2(const CKBehaviorContext& behcontext) +{ + CKBehavior* beh = behcontext.Behavior; + + switch(behcontext.CallbackMessage) { + case CKM_BEHAVIORCREATE: + case CKM_BEHAVIORLOAD: + case CKM_BEHAVIORDETACH: + + { + + + if ( g_pFFDevice2) + g_pFFDevice2->SendForceFeedbackCommand( DISFFC_STOPALL ); + + FreeDirectInput0(); + + } + break; + } + + return CKBR_OK; +} + diff --git a/ref/vt-ex/src/virtools/Behaviors/joystick/jTest.cmo b/ref/vt-ex/src/virtools/Behaviors/joystick/jTest.cmo new file mode 100644 index 0000000000000000000000000000000000000000..59b8284727793e6d881cd5b396ae90d434b9067c GIT binary patch literal 3189 zcmb7GcRbr|*Z&c-Mr_(fVph$drJ~$Ah$0oMX6?PTc8w@qc9l}2s8zJ6Qa5*viip{y zEke!7xcvZ{M`GN;TKwU~cXM6=wc& z+RiaV{p>2N389n0=%jQ~5U_KmhF!CE?^CsJ>&ZKM{FK22Es%$V8z}af1Ld7=-k^cD zYXj0<{pC6xxE=(x%;78kmft5cPN9`_7U^VeVp(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EDMEw~H)y6DSD z^A{I&frqiuWx_iJn`u9y`#O<^vzEZSDk$`B)jr#>C2P@;u<`$Go;d1d$T;JrzcG;Ob!N*}hu8JqFM230)h=t3(@;0}A(6+P8kdt#nwYG+Gz z+!%v6n9)|>`NzokBbP_*bQM;T?gc%#cSfL1#)GXIzth%jmYb)TwXsv4UA3{P!MOO6 zBMbCk#j<5!NosBEDrkPX{y}iw)OJ*=Kc%b?yA_QKJvRY&-*qfcXMnGNSk$zR@zCF* zWn23e$(VfhM+Xjl|1RS+BH|-8)hq5LH6ePMayqmzN~%&7Hnsh@=c=Msh!VApeIB_(kI1-UVDhCRm#^(547I#gQ@Qb@#QJM-tZrT z-AkMzB$mqx8L(@MFN2rD)eJvP`T}u$`$o|Ec{h_z+q&2r@Ns^cNUdw&6ML1GyVNgf z+L{mlx{gM!BsbdzK0!46EP!^EZhG?0oso)c;tEWX?n4+8_JK3ju_d!*c6+@{RjlXbkJ;}D z{(Fsj%Q}hV;&+=HW3mRn7B`o?{#X>*7`R8VS$VJ7mr(k>bnq2iyr@3^ekR&=fbh~V zl~|M&2#JWTUi#bDh`Y=r*47oS1Rd0ZQaJGY(8Rs6Ky`(EwT9@uZZ zv9%Yf{_aSvhGb0Jm5bxkEeVdk%gUQ0U~_37g%!IJ1kM#wHgwS7n>Qm`~&c{hUnamRu_i?0d5=^faxcNO2Z2 z_U;L-Fi+M|@;2_G$nyH?IO69a$?*3M#E{p0uKF>J33#30)&d{@Sfe5${33%rLfrj> z)B?hM<5>WJImMg@1Wb`8NPy)yWjQ_oa|XByaB*;OaJ|*1%pbSf V8XgNt$L@DLv5G&*S~X$Z`(LP-$zlKi literal 0 HcmV?d00001 diff --git a/ref/vt-ex/src/virtools/Behaviors/joystick/readffe.cpp b/ref/vt-ex/src/virtools/Behaviors/joystick/readffe.cpp new file mode 100644 index 0000000..fce18d2 --- /dev/null +++ b/ref/vt-ex/src/virtools/Behaviors/joystick/readffe.cpp @@ -0,0 +1,405 @@ +//----------------------------------------------------------------------------- +// File: ReadFFE.cpp +// +// Desc: DirectInput support to enumerate and play all effects in stored in a +// DirectInput effects file. +// +// Copyright (c) 1998-2001 Microsoft Corporation. All rights reserved. +//----------------------------------------------------------------------------- +#define STRICT +#define DIRECTINPUT_VERSION 0x0900 + +#include +#include +#include +#include +#include +#include +#include "DXUtil.h" +#include "resource.h" + + + + +//----------------------------------------------------------------------------- +// Defines, constants, and global variables +//----------------------------------------------------------------------------- +struct EFFECTS_NODE +{ + LPDIRECTINPUTEFFECT pDIEffect; + DWORD dwPlayRepeatCount; + EFFECTS_NODE* pNext; +}; + +LPDIRECTINPUT8 g_pDI = NULL; +LPDIRECTINPUTDEVICE8 g_pFFDevice = NULL; +EFFECTS_NODE g_EffectsList; + + + + +//----------------------------------------------------------------------------- +// Function-prototypes +//----------------------------------------------------------------------------- +INT_PTR CALLBACK MainDialogProc( HWND, UINT, WPARAM, LPARAM ); +BOOL CALLBACK EnumFFDevicesCallback( LPCDIDEVICEINSTANCE pDDI, VOID* pvRef ); +BOOL CALLBACK EnumAndCreateEffectsCallback( LPCDIFILEEFFECT pDIFileEffect, VOID* pvRef ); + +HRESULT InitDirectInput( HWND hDlg ); +HRESULT FreeDirectInput(); +VOID EmptyEffectList(); +HRESULT OnReadFile( HWND hDlg ); +HRESULT OnPlayEffects( HWND hDlg ); + + + + +//----------------------------------------------------------------------------- +// Name: WinMain() +// Desc: Entry point for the application. +//----------------------------------------------------------------------------- +int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, int ) +{ + InitCommonControls(); + + // Display the main dialog box. + DialogBox( hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDialogProc ); + + return TRUE; +} + + + + +//----------------------------------------------------------------------------- +// Name: MainDialogProc +// Desc: Handles dialog messages +//----------------------------------------------------------------------------- +INT_PTR CALLBACK MainDialogProc( HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam ) +{ + HRESULT hr; + + switch( msg ) + { + case WM_INITDIALOG: + { + // Set the icon for this dialog. + HICON hIcon = LoadIcon( (HINSTANCE)GetModuleHandle(NULL), + MAKEINTRESOURCE( IDI_ICON ) ); + PostMessage( hDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon ); // Set big icon + PostMessage( hDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon ); // Set small icon + + EnableWindow( GetDlgItem( hDlg, IDC_PLAY_EFFECTS ), FALSE ); + + hr = InitDirectInput( hDlg ); + if( FAILED(hr) ) + { + MessageBox( NULL, _T("Error Initializing DirectInput. ") + _T("The sample will now exit."), + _T("ReadFFE"), MB_ICONERROR | MB_OK ); + EndDialog( hDlg, TRUE ); + } + return TRUE; + } + + case WM_COMMAND: + switch( LOWORD(wParam) ) + { + case IDCANCEL: + EndDialog( hDlg, FALSE ); + return TRUE; + + case IDC_READ_FILE: + if( FAILED( hr = OnReadFile( hDlg ) ) ) + { + MessageBox( NULL, _T("Error reading effects file."), + _T("ReadFFE"), MB_ICONERROR | MB_OK ); + EnableWindow( GetDlgItem( hDlg, IDC_PLAY_EFFECTS ), FALSE ); + } + return TRUE; + + case IDC_PLAY_EFFECTS: + if( FAILED( hr = OnPlayEffects( hDlg ) ) ) + { + MessageBox( NULL, _T("Error playing DirectInput effects. ") + _T("The sample will now exit."), + _T("ReadFFE"), MB_ICONERROR | MB_OK ); + EndDialog( hDlg, 1 ); + } + return TRUE; + } + break; + + case WM_DESTROY: + FreeDirectInput(); + return TRUE; + } + + return FALSE; +} + + + + +//----------------------------------------------------------------------------- +// Name: InitDirectInput() +// Desc: Initialize the DirectInput variables. +//----------------------------------------------------------------------------- +HRESULT InitDirectInput( HWND hDlg ) +{ + HRESULT hr; + + // Setup the g_EffectsList circular linked list + ZeroMemory( &g_EffectsList, sizeof( EFFECTS_NODE ) ); + g_EffectsList.pNext = &g_EffectsList; + + // Create a DInput object + if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, + IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) ) + return hr; + + // Get the first enumerated force feedback device + if( FAILED( hr = g_pDI->EnumDevices( 0, EnumFFDevicesCallback, 0, + DIEDFL_ATTACHEDONLY | + DIEDFL_FORCEFEEDBACK ) ) ) + return hr; + + if( g_pFFDevice == NULL ) + { + MessageBox( hDlg, _T("No force feedback device found. ") + _T("The sample will now exit."), + _T("ReadFFE"), MB_ICONERROR | MB_OK ); + EndDialog( hDlg, 0 ); + return S_OK; + } + + // Set the data format + if( FAILED( hr = g_pFFDevice->SetDataFormat( &c_dfDIJoystick ) ) ) + return hr; + + // Set the coop level + if( FAILED( hr = g_pFFDevice->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE | + DISCL_BACKGROUND ) ) ) + return hr; + + // Disable auto-centering spring + DIPROPDWORD dipdw; + dipdw.diph.dwSize = sizeof(DIPROPDWORD); + dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); + dipdw.diph.dwObj = 0; + dipdw.diph.dwHow = DIPH_DEVICE; + dipdw.dwData = FALSE; + + if( FAILED( hr = g_pFFDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ) ) ) + return hr; + + // Acquire the device + if( FAILED( hr = g_pFFDevice->Acquire() ) ) + return hr; + + return S_OK; +} + + + + +//----------------------------------------------------------------------------- +// Name: EnumFFDevicesCallback() +// Desc: Get the first enumerated force feedback device +//----------------------------------------------------------------------------- +BOOL CALLBACK EnumFFDevicesCallback( LPCDIDEVICEINSTANCE pDDI, VOID* pvRef ) +{ + if( FAILED( g_pDI->CreateDevice( pDDI->guidInstance, &g_pFFDevice, NULL ) ) ) + return DIENUM_CONTINUE; // If failed, try again + + // Stop when a device was successfully found + return DIENUM_STOP; +} + + + + +//----------------------------------------------------------------------------- +// Name: FreeDirectInput() +// Desc: Initialize the DirectInput variables. +//----------------------------------------------------------------------------- +HRESULT FreeDirectInput() +{ + // Release any DirectInputEffect objects. + if( g_pFFDevice ) + { + EmptyEffectList(); + g_pFFDevice->Unacquire(); + SAFE_RELEASE( g_pFFDevice ); + } + + // Release any DirectInput objects. + SAFE_RELEASE( g_pDI ); + + return S_OK; +} + + + + +//----------------------------------------------------------------------------- +// Name: EmptyEffectList() +// Desc: Goes through the circular linked list and releases the effects, +// and deletes the nodes +//----------------------------------------------------------------------------- +VOID EmptyEffectList() +{ + EFFECTS_NODE* pEffectNode = g_EffectsList.pNext; + EFFECTS_NODE* pEffectDelete; + + while ( pEffectNode != &g_EffectsList ) + { + pEffectDelete = pEffectNode; + pEffectNode = pEffectNode->pNext; + + SAFE_RELEASE( pEffectDelete->pDIEffect ); + SAFE_DELETE( pEffectDelete ); + } + + g_EffectsList.pNext = &g_EffectsList; +} + + + + +//----------------------------------------------------------------------------- +// Name: OnReadFile() +// Desc: Reads a file contain a collection of DirectInput force feedback +// effects. It creates each of effect read in and stores it +// in the linked list, g_EffectsList. +//----------------------------------------------------------------------------- +HRESULT OnReadFile( HWND hDlg ) +{ + HRESULT hr; + + static TCHAR strFileName[MAX_PATH] = TEXT(""); + static TCHAR strPath[MAX_PATH] = TEXT(""); + + // Setup the OPENFILENAME structure + OPENFILENAME ofn = { sizeof(OPENFILENAME), hDlg, NULL, + TEXT("FEdit Files\0*.ffe\0All Files\0*.*\0\0"), NULL, + 0, 1, strFileName, MAX_PATH, NULL, 0, strPath, + TEXT("Open FEdit File"), + OFN_FILEMUSTEXIST|OFN_HIDEREADONLY, 0, 0, + TEXT(".ffe"), 0, NULL, NULL }; + + // Get the default media path (something like C:\DXSDK\SAMPLES\MULTIMEDIA\DINPUT\MEDIA) + if( '\0' == strPath[0] ) + DXUtil_GetDXSDKMediaPathCch( strPath, MAX_PATH ); + + // Display the OpenFileName dialog. Then, try to load the specified file + if( FALSE == GetOpenFileName( &ofn ) ) + return S_OK; + + EmptyEffectList(); + + // Enumerate the effects in the file selected, and create them in the callback + if( FAILED( hr = g_pFFDevice->EnumEffectsInFile( strFileName, + EnumAndCreateEffectsCallback, + NULL, DIFEF_MODIFYIFNEEDED ) ) ) + return hr; + + // Remember the path for next time + _tcscpy( strPath, strFileName ); + TCHAR* strLastSlash = _tcsrchr( strPath, '\\' ); + if( strLastSlash ) + strLastSlash[0] = '\0'; + + // If list of effects is empty, then we haven't been able to create any effects + if( g_EffectsList.pNext == &g_EffectsList ) + { + // Pop up a box informing the user + MessageBox( hDlg, _T("Unable to create any effects."), + _T("ReadFFE"), MB_ICONEXCLAMATION | MB_OK ); + EnableWindow( GetDlgItem( hDlg, IDC_PLAY_EFFECTS ), FALSE ); + } + else + { + // We have effects so enable the 'play effects' button + EnableWindow( GetDlgItem( hDlg, IDC_PLAY_EFFECTS ), TRUE ); + } + + return S_OK; +} + + + + +//----------------------------------------------------------------------------- +// Name: EnumAndCreateEffectsCallback() +// Desc: Create the effects as they are enumerated and add them to the +// linked list, g_EffectsList +//----------------------------------------------------------------------------- +BOOL CALLBACK EnumAndCreateEffectsCallback( LPCDIFILEEFFECT pDIFileEffect, VOID* pvRef ) +{ + HRESULT hr; + LPDIRECTINPUTEFFECT pDIEffect = NULL; + + // Create the file effect + if( FAILED( hr = g_pFFDevice->CreateEffect( pDIFileEffect->GuidEffect, + pDIFileEffect->lpDiEffect, + &pDIEffect, NULL ) ) ) + { + OutputDebugString( TEXT("Could not create force feedback effect on this device.\n") ); + return DIENUM_CONTINUE; + } + + // Create a new effect node + EFFECTS_NODE* pEffectNode = new EFFECTS_NODE; + if( NULL == pEffectNode ) + return DIENUM_STOP; + + // Fill the pEffectNode up + ZeroMemory( pEffectNode, sizeof( EFFECTS_NODE ) ); + pEffectNode->pDIEffect = pDIEffect; + pEffectNode->dwPlayRepeatCount = 1; + + // Add pEffectNode to the circular linked list, g_EffectsList + pEffectNode->pNext = g_EffectsList.pNext; + g_EffectsList.pNext = pEffectNode; + + return DIENUM_CONTINUE; +} + + + + +//----------------------------------------------------------------------------- +// Name: OnPlayEffects() +// Desc: Plays all of the effects enumerated in the file +//----------------------------------------------------------------------------- +HRESULT OnPlayEffects( HWND hDlg ) +{ + EFFECTS_NODE* pEffectNode = g_EffectsList.pNext; + LPDIRECTINPUTEFFECT pDIEffect = NULL; + HRESULT hr; + + // Stop all previous forces + if( FAILED( hr = g_pFFDevice->SendForceFeedbackCommand( DISFFC_STOPALL ) ) ) + return hr; + + while ( pEffectNode != &g_EffectsList ) + { + // Play all of the effects enumerated in the file + pDIEffect = pEffectNode->pDIEffect; + + if( NULL != pDIEffect ) + { + if( FAILED( hr = pDIEffect->Start( pEffectNode->dwPlayRepeatCount, 0 ) ) ) + return hr; + } + + pEffectNode = pEffectNode->pNext; + } + + return S_OK; +} + + + + diff --git a/ref/vt-ex/src/virtools/vtTools.cpp b/ref/vt-ex/src/virtools/vtTools.cpp new file mode 100644 index 0000000..88a2e22 --- /dev/null +++ b/ref/vt-ex/src/virtools/vtTools.cpp @@ -0,0 +1,844 @@ +#include "StdAfx.h" + +#include +#include +#include + +/* +******************************************************************* +* Function: IsNumeric() +* +* Description : Check each character of the string +If a character at a certain position is not a digit, +then the string is not a valid natural number + +* Parameters : char*Str,r : the string to test +* Returns : int +* +******************************************************************* +*/ + +int vtTools::ParameterTools::IsNumeric(const char* Str,vtTools::Enums::SuperType superType) +{ + bool dotAlreadyFound = false; + + + //allow empty strings : + if(strlen(Str) == 0 ) + { + return true; + } + + using namespace vtTools::Enums; + + for(unsigned int i = 0; i < strlen(Str); i++) + { + if( Str[i] < '0' || Str[i] > '9' ) + { + + if ( ( Str[i] == '.' || Str[i] == ',') ) + { + if (superType == vtINTEGER ) + { + return false; + } + + if (dotAlreadyFound) + { + return false; + } + + dotAlreadyFound = true; + continue; + } + + if (!(i == 0 && Str[i]== '-')) + { + return false; + } + } + } + return true; +} + +/* +******************************************************************* +* Function: CreateWidgetInfo() +* +* Description : CreateWidgetInfo returns an handy info about an parameter type an a + given string value of this parameter. + +* Parameters : CKContext* context, r : the virtools context. + CKParameterType parameterType, r : the type to test. + uxString stringValue,r : the string value of the given type. + +* Returns : WidgetInfo +******************************************************************* +*/ +vtTools::Structs::WidgetInfo* +vtTools::ParameterTools:: +CreateWidgetInfo(CKContext* context, + CKParameterType parameterType, + XString stringValue) +{ + using namespace vtTools::Structs; + using namespace vtTools::Enums; + using namespace vtTools::ParameterTools; + + + CKParameterManager *pm = static_cast(context->GetParameterManager()); + + CKGUID guid =pm->ParameterTypeToGuid(parameterType); + + WidgetInfo* result = new WidgetInfo(); + + + result->parameterInfo = GetParameterInfo(context,parameterType); + + CKParameterLocal *localCopy = context->CreateCKParameterLocal("buffer",guid,TRUE); + + localCopy->SetStringValue(stringValue.Str()); + + + switch(result->parameterInfo.superType) { + + ////////////////////////////////////////////////////////////////////////// color ////////////////////////////////////////////////////////////////////////// + case vtCOLOUR: + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + VxColor realValue; + localCopy->GetValue(&realValue); + + int dColor = realValue.GetRGBA(); + + int r = ColorGetRed(dColor); + int g = ColorGetGreen(dColor); + int b = ColorGetBlue(dColor); + int a = ColorGetAlpha(dColor); + + item->value << r << "," << g << "," << b << "," << a; + + item->widgetType = EVT_WIDGET_COLOR_SELECTION; + result->items.PushBack(item); + break; + } + ////////////////////////////////////////////////////////////////////////// integer ////////////////////////////////////////////////////////////////////////// + case vtFLOAT: + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + float realValue; + localCopy->GetValue(&realValue); + item->value << realValue; + item->widgetType = EVT_WIDGET_EDIT_TEXT; + result->items.PushBack(item); + break; + } + ////////////////////////////////////////////////////////////////////////// integer ////////////////////////////////////////////////////////////////////////// + case vtINTEGER: + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + int realValue; + localCopy->GetValue(&realValue); + item->value << realValue; + item->widgetType = EVT_WIDGET_EDIT_TEXT; + result->items.PushBack(item); + break; + } + ////////////////////////////////////////////////////////////////////////// bool ////////////////////////////////////////////////////////////////////////// + case vtBOOL: + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + CKBOOL realValue; + localCopy->GetValue(&realValue); + item->value << realValue; + item->widgetType = EVT_WIDGET_CHECK_BUTTON; + result->items.PushBack(item); + break; + } + + ////////////////////////////////////////////////////////////////////////// string or file ////////////////////////////////////////////////////////////////////////// + case vtFile : + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + item->value = stringValue; + item->widgetType = EVT_WIDGET_FILE_SELECTION; + result->items.PushBack(item); + break; + } + case vtSTRING: + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + item->value = stringValue; + item->widgetType = EVT_WIDGET_EDIT_TEXT; + result->items.PushBack(item); + break; + } + ////////////////////////////////////////////////////////////////////////// box ////////////////////////////////////////////////////////////////////////// + case vtBOX: + { + for (int i = 0 ; i < 6 ; i ++ ) + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + + VxBbox realValue; + localCopy->GetValue(&realValue); + item->widgetType = EVT_WIDGET_EDIT_TEXT; + switch(i) + { + case 0: + item->value << realValue.v[i]; + item->label = "min x: "; + break; + case 1: + item->value << realValue.v[i]; + item->label = "min y: "; + break; + case 2: + item->value << realValue.v[i]; + item->label = "min z: "; + break; + case 3: + item->value << realValue.v[i]; + item->label = "max x: "; + break; + case 4: + item->value << realValue.v[i]; + item->label = "max y: "; + break; + case 5: + item->value << realValue.v[i]; + item->label = "max z: "; + break; + } + result->items.PushBack(item); + } + break; + } + ////////////////////////////////////////////////////////////////////////// rectangle ////////////////////////////////////////////////////////////////////////// + case vtRECTANGLE: + { + for (int i = 0 ; i < 4 ; i ++ ) + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + + VxRect realValue; + localCopy->GetValue(&realValue); + item->widgetType = EVT_WIDGET_EDIT_TEXT; + switch(i) + { + case 0: + item->value << realValue.left; + item->label = "Left: "; + break; + case 1: + item->value << realValue.top; + item->label = "Top: "; + break; + case 2: + item->value << realValue.right; + item->label = "Right: "; + break; + case 3: + item->value << realValue.bottom; + item->label = "Bottom: "; + break; + } + result->items.PushBack(item); + } + break; + } + ////////////////////////////////////////////////////////////////////////// vector 2 ////////////////////////////////////////////////////////////////////////// + case vtVECTOR2D: + { + for (int i = 0 ; i < 2 ; i ++ ) + { + + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + Vx2DVector VectorValue; + localCopy->GetValue(&VectorValue); + item->value << VectorValue[i]; + item->widgetType = EVT_WIDGET_EDIT_TEXT; + switch(i) + { + case 0: + item->label = "x: "; + break; + case 1: + item->label = "y: "; + } + result->items.PushBack(item); + } + break; + } + ////////////////////////////////////////////////////////////////////////// vector 3 ////////////////////////////////////////////////////////////////////////// + case vtVECTOR: + { + for (int i = 0 ; i < 3 ; i ++ ) + { + + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + VxVector VectorValue; + localCopy->GetValue(&VectorValue); + item->value << VectorValue[i]; + item->widgetType = EVT_WIDGET_EDIT_TEXT; + + switch(i) + { + case 0: + item->label = "x"; + break; + case 1: + item->label = "y"; + break; + case 2: + item->label = "z"; + break; + } + result->items.PushBack(item); + } + break; + } + ////////////////////////////////////////////////////////////////////////// vector4 ////////////////////////////////////////////////////////////////////////// + case vtQUATERNION: + { + + for (int i = 0 ; i < 4 ; i ++ ) + { + + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + VxQuaternion realValue; + localCopy->GetValue(&realValue); + item->value << realValue[i]; + item->widgetType = EVT_WIDGET_EDIT_TEXT; + switch(i) + { + case 0: + item->label = "x: "; + break; + case 1: + item->label = "y: "; + break; + case 2: + item->label = "z: "; + break; + case 3: + item->label = "w: "; + break; + } + result->items.PushBack(item); + } + break; + } + ////////////////////////////////////////////////////////////////////////// enumeration ////////////////////////////////////////////////////////////////////////// + case vtENUMERATION: + { + + + CKEnumStruct *enumStruct = pm->GetEnumDescByType(parameterType); + if ( enumStruct ) + { + for (int i = 0 ; i < enumStruct->GetNumEnums() ; i ++ ) + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + item->value = enumStruct->GetEnumDescription(i); + item->widgetType = EVT_WIDGET_COMBO_BOX; + result->items.PushBack(item); + item->value=""; + + item->value <GetEnumValue(i); + + item->label =enumStruct->GetEnumDescription(i); + } + } + break; + } + ////////////////////////////////////////////////////////////////////////// flags ////////////////////////////////////////////////////////////////////////// + case vtFLAGS: + { + CKFlagsStruct*flagStruct = pm->GetFlagsDescByType(parameterType); + if ( flagStruct ) + { + for (int i = 0 ; i < flagStruct->GetNumFlags() ; i ++ ) + { + WidgetInfo::WidgetInfoItem *item = new WidgetInfo::WidgetInfoItem(); + item->value = flagStruct->GetFlagDescription(i); + item->widgetType = EVT_WIDGET_CHECK_BUTTON; + result->items.PushBack(item); + } + } + break; + } + } + return result; +} +/* +******************************************************************* +* Function: GetParameterMemberInfo() +* +* Description : GetParameterMemberInfo returns the type super type of the used structure members. + Example : vtVECTOR returns vtFLOAT +* +* Parameters : CKContext* context, r : the virtools context. + CKParameterType parameterType, r : the type to test. +* Returns : SuperType +* +******************************************************************* +*/ +vtTools::Enums::SuperType +vtTools::ParameterTools::GetParameterMemberInfo(CKContext* context,CKParameterType parameterType) +{ + assert ( context ); + using namespace vtTools::Enums; + using namespace vtTools::ParameterTools; + + SuperType superType = GetVirtoolsSuperType(context,context->GetParameterManager()->ParameterTypeToGuid(parameterType)); + + switch(superType) + { + case vtENUMERATION: + return vtSTRING; + + case vtBOOL: + case vtFLAGS: + return vtBOOL; + case vtCOLOUR: + return vtCOLOUR; + case vtFile: + return vtFile; + case vtINTEGER: + return vtINTEGER; + case vtFLOAT: + return vtFLOAT; + case vtSTRING: + return vtSTRING; + case vtVECTOR2D: + case vtRECTANGLE: + case vtVECTOR: + case vtBOX: + case vtQUATERNION: + case vtMATRIX: + return vtFLOAT; + default: + return vtSTRING; + } +} + +/* +******************************************************************* +* Function: GetParameterInfo() +* +* Description : GetParameterInfo returns an info about a virtools type. + Example : Vector4D returns : + result.horizontalItems = 4 ; + result.verticalItems = 1 ; + result.memberType = vtFLOAT + result.superType = vtQUATERNION; + +* Parameters : CKContext* context, r : the virtools context. + CKParameterType parameterType, r : the type to test. +* Returns : ParameterInfo +* +******************************************************************* +*/ +vtTools::Structs::ParameterInfo +vtTools::ParameterTools::GetParameterInfo(CKContext* context,CKParameterType parameterType) +{ + + assert(context); + + using namespace vtTools::Structs; + using namespace vtTools::Enums; + using namespace vtTools::ParameterTools; + + CKParameterManager *pm = static_cast(context->GetParameterManager()); + + ParameterInfo result; + + result.memberType = vtTools::ParameterTools::GetParameterMemberInfo(context,parameterType); + result.superType = vtTools::ParameterTools::GetVirtoolsSuperType(context,pm->ParameterTypeToGuid(parameterType)); + + + switch(result.superType) + { + + case vtFLAGS: + { + CKFlagsStruct *flagStruct = pm->GetFlagsDescByType(parameterType); + if (flagStruct) + { + result.horizontalItems = 1 ; + result.verticalItems = flagStruct->GetNumFlags() ; + + } + break; + } + case vtENUMERATION: + { + CKEnumStruct* enumStruct = pm->GetEnumDescByType(parameterType); + if (enumStruct) + { + result.horizontalItems = 1 ; + result.verticalItems = enumStruct->GetNumEnums(); + break; + } + } + case vtBOOL: + case vtINTEGER: + case vtFLOAT: + case vtFile: + case vtSTRING: + result.horizontalItems = 1; + result.verticalItems = 1; + break; + case vtVECTOR2D: + result.horizontalItems = 2; + result.verticalItems = 1; + break; + case vtRECTANGLE: + result.horizontalItems = 2; + result.verticalItems = 2; + break; + case vtVECTOR: + result.horizontalItems = 3; + result.verticalItems = 1; + break; + case vtBOX: + result.horizontalItems = 3; + result.verticalItems = 2; + break; + case vtQUATERNION: + case vtCOLOUR: + result.horizontalItems = 4; + result.verticalItems = 1; + break; + case vtMATRIX: + result.horizontalItems = 4; + result.verticalItems = 4; + break; + default: + { + result.horizontalItems = 0; + result.verticalItems = 0; + break; + } + } + return result; +} + +/* +******************************************************************* +* Function: GetWidgetType() +* +* Description : GetWidgetType returns the type of the GBLWidget which should used for a + specific virtools super type. + Example : vtBOOL = CheckBox + vtENUMERATION = ComboBox + +* Parameters : SuperType superType, r : the given virtools super type +* Returns : EWidgetType +* +******************************************************************* +*/ + + +vtTools::Enums::EVTWidgetType +vtTools::ParameterTools::GetWidgetType(vtTools::Enums::SuperType superType) +{ + using namespace vtTools::Enums; + + switch(superType) + { + case vtENUMERATION: + return EVT_WIDGET_COMBO_BOX; + + case vtFLAGS: + case vtBOOL: + return EVT_WIDGET_CHECK_BUTTON; + + case vtINTEGER: + case vtFLOAT: + case vtSTRING: + case vtVECTOR2D: + case vtRECTANGLE: + case vtVECTOR: + case vtBOX: + case vtQUATERNION: + case vtMATRIX: + return EVT_WIDGET_EDIT_TEXT; + + case vtCOLOUR: + return EVT_WIDGET_COLOR_SELECTION; + case vtFile: + return EVT_WIDGET_FILE_SELECTION; + + + default: + return EVT_WIDGET_EDIT_TEXT; + } +} + +/* +******************************************************************* +* Function:GetVirtoolsSuperType() +* +* Description : GetVirtoolsSuperType returns the base type of virtools parameter. + This is very useful if want to determine whether a parameter can be used for + network of database. +* +* Parameters : CKContext *ctx, r : the virtools context + CKGUID guid, r : the guid of the parameter +* +* Returns : SuperType, +* +******************************************************************* +*/ + + + +vtTools::Enums::SuperType +vtTools::ParameterTools:: + GetVirtoolsSuperType(CKContext *ctx, + const CKGUID guid) +{ + assert(ctx); + + using namespace vtTools::Enums; + + CKParameterTypeDesc *tdescr = ctx->GetParameterManager()->GetParameterTypeDescription(guid); + + CKParameterManager *pm = static_cast(ctx->GetParameterManager()); + + if ( (pm->GetEnumDescByType(pm->ParameterGuidToType(guid))) ) + { + return vtENUMERATION; + } + + // parameter is a flag + if ( (pm->GetFlagsDescByType(pm->ParameterGuidToType(guid))) ) + { + return vtFLAGS; + } + + // is a bool : + if( (ctx->GetParameterManager()->ParameterGuidToType(guid)) == ctx->GetParameterManager()->ParameterGuidToType(CKPGUID_BOOL)) + return vtBOOL; + + /*// is a file : + if( (ctx->GetParameterManager()->ParameterGuidToType(guid)) == ctx->GetParameterManager()->ParameterGuidToType(GBLCO_FILE_TYPE)) + return vtFile;*/ + + // is a string : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_STRING)) + return vtSTRING; + + // is a float : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_FLOAT)) + return vtFLOAT; + + // is a integer : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_INT)) + return vtINTEGER; + + // is a VxVector : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_VECTOR)) + return vtVECTOR; + + // is a Vx2DVector : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_2DVECTOR)) + return vtVECTOR2D; + + // is a VxColor : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_COLOR)) + return vtCOLOUR; + + // is a VxMatrix : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_MATRIX)) + return vtMATRIX; + + // is a VxQuaternion : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_QUATERNION)) + return vtQUATERNION; + + // is a Rectangle : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_RECT)) + return vtRECTANGLE; + + // is a Box : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_BOX)) + return vtBOX; + + + // is a CKObject : + if(ctx->GetParameterManager()->IsDerivedFrom(guid,CKPGUID_OBJECT)) + return vtOBJECT; + + return vtUNKNOWN; +} + +/* +******************************************************************* +* Function: TypeIsSerializable() +* Description : Returns true if the given type can be stored as string. + + It also checks custom virtools structures recursive. + + hidden Structs or parameter types are skipped ! +* +* Parameters : CKContext *ctx, r : the virtools context + CKParameterType type, r : the type +* Returns : bool +* +******************************************************************* +*/ +bool +vtTools::ParameterTools:: +TypeIsSerializable( + CKContext *ctx, + CKParameterType type) +{ + + assert(ctx); + + CKParameterTypeDesc *tdescr = ctx->GetParameterManager()->GetParameterTypeDescription(type); + + bool result = false; + if(tdescr) + { + using namespace vtTools::Enums; + using namespace vtTools::ParameterTools; + + // return isNotHidden AND isNotCKBeObject AND isNotUnknown OR isValidStruct : // + return + ( + ! (tdescr->dwFlags & CKPARAMETERTYPE_HIDDEN) && // internally type + (GetVirtoolsSuperType(ctx,tdescr->Guid) != vtOBJECT ) && // objects not allowed ! + (GetVirtoolsSuperType(ctx,tdescr->Guid) != vtUNKNOWN ) // also possible !! + ) + || + ( + ( + ( (tdescr->dwFlags & CKPARAMETERTYPE_STRUCT) == 0x00000010 ) ? // parameter is a custom struct + IsValidStruct(ctx,tdescr->Guid) : false //check the struct + ) + + ); + } + return result; +} +/* + ******************************************************************* + * Function: IsValidStruct() + * + * Description : Like TypeIsSerializable, even checks a custom virtools structure, recursive. + * + * Parameters : CKContext *ctx,r : the virtools context + CKGUID type,r : the type to check + + * Returns : bool + * + ******************************************************************* +*/ +bool +vtTools::ParameterTools:: +IsValidStruct(CKContext *ctx,CKGUID type) +{ + + assert(ctx); + + CKParameterManager* pm = ctx->GetParameterManager(); + CKStructStruct *data = pm->GetStructDescByType(pm->ParameterGuidToType(type)); + + bool result = true; + + if (data) + for (int i=0;iNbData;++i) + if(vtTools::ParameterTools::TypeIsSerializable(ctx,pm->ParameterGuidToType(data->GetSubParamGuid(i)))) + continue; + else + result = false; + return result; +} +/* +******************************************************************* +* Function: TypeCheckedParameterCopy() +* +* Description : Copies the source parameter to a destination parameter. On a type mismatch +* it tries to copy as string. This also works for nested virtools structures. See +SuperType for supported types. +* +* Parameters : CKParameter*dest,rw : the destination parameter +CKParameter*src,r : the source parameter +* Returns : bool = true if succesful. +* todo:: return checked diff +* +******************************************************************* +*/ +int +vtTools::ParameterTools:: +TypeCheckedParameterCopy( CKParameter*dest, CKParameter*src) +{ + using vtTools::ParameterTools::TypeIsSerializable; + + /* return ( (TypeIsOk AND CopyIsOk == CK_OK ) OR (TypeIsSerializable && CopyByStringIsOk== CK_OK ) ) */ + return + ( + src && // useful + //ok, compare the type : + dest->GetGUID() == src->GetGUID() && + //type match, store new value : + ( dest->CopyValue(src) == CK_OK ) + ) + || /* canceled ? try a string : */ + ( + TypeIsSerializable(src->GetCKContext(),src->GetType()) && + ( dest->SetStringValue( static_cast(src->GetReadDataPtr())) ==CK_OK ) + );; +} +/* +******************************************************************* +* Function: CompareStringRep() +* +* Description : This function compares the string representation of the CKParameters +* +* Parameters : CKParameter* valueA,r : the first parameter + CKParameter* valueB,r : the second parameter +* Returns : int (like strcmp) +* +******************************************************************* +*/ +int +vtTools::ParameterTools:: +CompareStringRep(CKParameter*valueA, CKParameter*valueB) +{ + + assert(valueA && valueB); + + VxScratch sbufferA(valueA->GetDataSize()); + CKSTRING bufferA = (CKSTRING)sbufferA.Mem(); + valueA->GetStringValue(bufferA); + + VxScratch sbufferB(valueB->GetDataSize()); + CKSTRING bufferB = (CKSTRING)sbufferB.Mem(); + valueB->GetStringValue(bufferB); + return strcmp( bufferA,bufferB ); +} +/* +******************************************************************* +* Function: GetParameterAsString() +* +* Description : Returns the string value of a CKParameter. +* +* Parameters : CKParameter*src ,r the given parameter + +* Returns : CKSTRING +* +******************************************************************* +*/ +CKSTRING +vtTools::ParameterTools::GetParameterAsString( CKParameter*src) +{ + assert(src); + VxScratch scratch(src->GetDataSize()); + CKSTRING out2 = (CKSTRING)scratch.Mem(); + src->GetStringValue(out2); + return out2; + +} \ No newline at end of file diff --git a/run-console.sh b/run-console.sh index fa829b2..f1da2b0 100644 --- a/run-console.sh +++ b/run-console.sh @@ -1,5 +1,5 @@ #sh scripts/build.sh Debug console sh scripts/build.sh cd build/bin -./blueprints-example_d.exe --graph=./BlueprintsGraph.json --run --headless --log-level=info --max-steps=1000 +./nodehub_d.exe --graph=./BlueprintsGraph.json --run --headless --log-level=debug --max-steps=1000 --log=./last-run.log diff --git a/run-with-console.bat b/run-with-console.bat deleted file mode 100644 index 155a7f2..0000000 --- a/run-with-console.bat +++ /dev/null @@ -1,24 +0,0 @@ -@echo off -REM Run blueprints example with console output visible -REM This keeps the console window attached so you can see log output - -cd build\bin - -echo ======================================== -echo ImGui Node Editor - Console Mode -echo ======================================== -echo. -echo Guided Links Logging Enabled -echo Press Ctrl+C to stop -echo ======================================== -echo. - -REM Run without Start-Process to keep console attached -blueprints-example_d.exe - -echo. -echo ======================================== -echo Application Exited -echo ======================================== -pause - diff --git a/run.sh b/run.sh index a23d33b..557a2ed 100644 --- a/run.sh +++ b/run.sh @@ -1,4 +1,4 @@ sh scripts/build.sh cd build/bin # rm Blueprints.json -./blueprints-example_d.exe +./nodehub_d.exe diff --git a/scripts/build.bat b/scripts/build.bat deleted file mode 100644 index d7fcaf9..0000000 --- a/scripts/build.bat +++ /dev/null @@ -1,43 +0,0 @@ -@echo off -REM Build script for simple-example project only -REM Usage: scripts\build.bat [Release|Debug] - -setlocal - -REM Default to Debug build if not specified -set BUILD_TYPE=%1 -if "%BUILD_TYPE%"=="" set BUILD_TYPE=Debug - -echo ========================================== -echo Building simple-example (%BUILD_TYPE%) -echo ========================================== -echo. - -REM Build only the simple-example target -cmake --build build --config %BUILD_TYPE% --target simple-example - -if %ERRORLEVEL% EQU 0 ( - echo. - echo Build successful! - echo. - echo Executable location: - if "%BUILD_TYPE%"=="Release" ( - echo build\bin\simple-example.exe - ) else ( - echo build\bin\simple-example_d.exe - ) - echo. - echo Run with: - if "%BUILD_TYPE%"=="Release" ( - echo .\build\bin\simple-example.exe - ) else ( - echo .\build\bin\simple-example_d.exe - ) -) else ( - echo. - echo Build failed! - exit /b 1 -) - -endlocal - diff --git a/scripts/build.ps1 b/scripts/build.ps1 deleted file mode 100644 index 478635d..0000000 --- a/scripts/build.ps1 +++ /dev/null @@ -1,40 +0,0 @@ -# Build script for simple-example project only -# Usage: .\scripts\build.ps1 [-BuildType Release|Debug] - -param( - [Parameter(Position=0)] - [ValidateSet('Debug', 'Release')] - [string]$BuildType = 'Debug' -) - -Write-Host "==========================================" -ForegroundColor Cyan -Write-Host "Building simple-example ($BuildType)" -ForegroundColor Cyan -Write-Host "==========================================" -ForegroundColor Cyan -Write-Host "" - -# Build only the simple-example target -cmake --build build --config $BuildType --target simple-example - -if ($LASTEXITCODE -eq 0) { - Write-Host "" - Write-Host "[OK] Build successful!" -ForegroundColor Green - Write-Host "" - Write-Host "Executable location:" -ForegroundColor Yellow - if ($BuildType -eq "Release") { - Write-Host " build\bin\simple-example.exe" -ForegroundColor White - } else { - Write-Host " build\bin\simple-example_d.exe" -ForegroundColor White - } - Write-Host "" - Write-Host "Run with:" -ForegroundColor Yellow - if ($BuildType -eq "Release") { - Write-Host " .\build\bin\simple-example.exe" -ForegroundColor White - } else { - Write-Host " .\build\bin\simple-example_d.exe" -ForegroundColor White - } -} else { - Write-Host "" - Write-Host "[ERROR] Build failed!" -ForegroundColor Red - exit 1 -} - diff --git a/scripts/build.sh b/scripts/build.sh index 915c33b..aa6facf 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -4,6 +4,8 @@ # - First argument: Build type (Release or Debug, default: Debug) # - Second argument: 'console' to build console variant instead +export CMAKE_EXPORT_COMPILE_COMMANDS=1 + taskkill /F /IM blueprints-example_d.exe 2>/dev/null taskkill /F /IM blueprints-example-console_d.exe 2>/dev/null @@ -16,10 +18,10 @@ BUILD_TYPE="${1:-Debug}" # Check if console variant requested if [ "$2" == "console" ]; then - TARGET="blueprints-example-console" + TARGET="nodehub-console" VARIANT="Console" else - TARGET="blueprints-example" + TARGET="nodehub" VARIANT="GUI" fi diff --git a/scripts/generate_protos.sh b/scripts/generate_protos.sh new file mode 100644 index 0000000..ded137d --- /dev/null +++ b/scripts/generate_protos.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -e + +# This script generates C++ source and header files from .proto definitions +# using the protoc compiler. + +# Get the project root directory +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" + +# Define the output directory for the generated files +OUTPUT_DIR="$PROJECT_ROOT/applications/tests/protos" + +# Create the output directory if it doesn't exist +mkdir -p "$OUTPUT_DIR" + +echo "Generating protobuf files..." + +# Generate files for parameter.proto +protoc --proto_path="$PROJECT_ROOT/applications/protos" --cpp_out="$OUTPUT_DIR" "$PROJECT_ROOT/applications/protos/parameter.proto" + +# Generate files for test_primitives.proto +protoc --proto_path="$PROJECT_ROOT/applications/tests" --cpp_out="$OUTPUT_DIR" "$PROJECT_ROOT/applications/tests/test_primitives.proto" + +echo "Protobuf files generated successfully in $OUTPUT_DIR" diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/sslast.png b/sslast.png deleted file mode 100644 index e69de29..0000000 diff --git a/tests/commons.ts b/tests/commons.ts new file mode 100644 index 0000000..955adc7 --- /dev/null +++ b/tests/commons.ts @@ -0,0 +1,44 @@ +import { execFile } from "child_process"; +import { promisify } from "util"; +import * as path from "path"; + +const execFileAsync = promisify(execFile); + +// Define the path to the binary directory, which will be our working directory. +const binDirectory = path.resolve(__dirname, "../build/bin"); + +// Define the path to the executable. +const executablePath = path.resolve(binDirectory, "nodehub_d.exe"); + +// Define the common arguments for running the CLI in a headless test environment +const commonArgs = [ + "--headless", + "--run", + "--log-level=info", + "--max-steps=1000" +]; + +/** + * Runs the CLI application with a given set of arguments. + * + * @param testArgs - An array of strings representing the arguments specific to the test. + * @returns A promise that resolves with the stdout, stderr, and exit code of the process. + */ +export async function runCli(testArgs: string[]) { + const allArgs = [...commonArgs, ...testArgs]; + + try { + const { stdout, stderr } = await execFileAsync(executablePath, allArgs, { + cwd: binDirectory // Run from the binary's directory + }); + return { stdout, stderr, code: 0 }; + } catch (error: any) { + // If execFileAsync throws, it's because the process exited with a non-zero code. + // We still want to capture the output and the code. + return { + stdout: error.stdout, + stderr: error.stderr, + code: error.code || 1, + }; + } +} diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts new file mode 100644 index 0000000..6eb6eaf --- /dev/null +++ b/tests/e2e.test.ts @@ -0,0 +1,16 @@ +import { describe, it, expect } from "vitest"; +import { runCli } from "./commons"; + +describe("E2E Core Tests", () => { + it("should run the CLI without errors using the default graph", async () => { + // As per run-console.sh, the default graph file is in the same directory as the executable + const args = ["--graph=./BlueprintsGraph.json"]; + + const { stdout, stderr, code } = await runCli(args); + + // For now, we just expect the process to exit cleanly. + // We can add assertions about stdout/stderr content later. + expect(code).toBe(0); + expect(stderr).toBe(""); + }); +}); diff --git a/tests/fixtures/graph-log.json b/tests/fixtures/graph-log.json new file mode 100644 index 0000000..ce09e1c --- /dev/null +++ b/tests/fixtures/graph-log.json @@ -0,0 +1,108 @@ +{ + "app_links": null, + "app_nodes": + [ + { + "block_display_mode": 1, + "block_type": "Math.Add", + "inputs": + [ + { + "pin_id": 3, + "type": 2, + "value": "" + }, + { + "pin_id": 4, + "type": 2, + "value": "2" + } + ], + "name": "Add", + "node_type": "block", + "outputs": + [ + { + "pin_id": 6, + "type": 2, + "value": "" + } + ], + "position": + { + "x": 208, + "y": 96 + }, + "size": + { + "x": 96, + "y": 62 + }, + "uuid_high": 16777216, + "uuid_low": 2 + }, + { + "block_display_mode": 1, + "block_type": "Log", + "inputs": + [ + { + "pin_id": 11, + "type": 4, + "value": "" + }, + { + "pin_id": 13, + "type": 2, + "value": "" + } + ], + "log_append_to_file": true, + "log_level": 2, + "log_output_to_console": true, + "log_variable_params": + [ + { + "name": "Param1", + "pin_id": 13, + "type": 2 + } + ], + "name": "Log", + "node_type": "block", + "outputs": null, + "position": + { + "x": 352, + "y": 99 + }, + "size": + { + "x": 96, + "y": 58 + }, + "uuid_high": 16777216, + "uuid_low": 8 + }, + { + "block_display_mode": 1, + "block_type": "Start", + "inputs": null, + "name": "Start", + "node_type": "block", + "outputs": null, + "position": + { + "x": 64, + "y": 105 + }, + "size": + { + "x": 96, + "y": 46 + }, + "uuid_high": 16777216, + "uuid_low": 16 + } + ] +} \ No newline at end of file