nv-sgl 0.6.0__cp313-cp313-win_amd64.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. include/tevclient.h +393 -0
  2. nv_sgl-0.6.0.dist-info/LICENSE +29 -0
  3. nv_sgl-0.6.0.dist-info/METADATA +21 -0
  4. nv_sgl-0.6.0.dist-info/RECORD +142 -0
  5. nv_sgl-0.6.0.dist-info/WHEEL +5 -0
  6. nv_sgl-0.6.0.dist-info/top_level.txt +1 -0
  7. sgl/__init__.py +15 -0
  8. sgl/__init__.pyi +6738 -0
  9. sgl/d3d12/D3D12Core.dll +0 -0
  10. sgl/d3d12/d3d12SDKLayers.dll +0 -0
  11. sgl/dxcompiler.dll +0 -0
  12. sgl/dxil.dll +0 -0
  13. sgl/gfx.dll +0 -0
  14. sgl/include/sgl/app/app.h +113 -0
  15. sgl/include/sgl/core/bitmap.h +302 -0
  16. sgl/include/sgl/core/crypto.h +89 -0
  17. sgl/include/sgl/core/data_type.h +46 -0
  18. sgl/include/sgl/core/dds_file.h +103 -0
  19. sgl/include/sgl/core/enum.h +201 -0
  20. sgl/include/sgl/core/error.h +161 -0
  21. sgl/include/sgl/core/file_stream.h +77 -0
  22. sgl/include/sgl/core/file_system_watcher.h +141 -0
  23. sgl/include/sgl/core/format.h +36 -0
  24. sgl/include/sgl/core/fwd.h +90 -0
  25. sgl/include/sgl/core/hash.h +45 -0
  26. sgl/include/sgl/core/input.h +522 -0
  27. sgl/include/sgl/core/logger.h +214 -0
  28. sgl/include/sgl/core/macros.h +184 -0
  29. sgl/include/sgl/core/maths.h +45 -0
  30. sgl/include/sgl/core/memory_mapped_file.h +112 -0
  31. sgl/include/sgl/core/memory_mapped_file_stream.h +32 -0
  32. sgl/include/sgl/core/memory_stream.h +74 -0
  33. sgl/include/sgl/core/object.h +683 -0
  34. sgl/include/sgl/core/platform.h +239 -0
  35. sgl/include/sgl/core/plugin.h +331 -0
  36. sgl/include/sgl/core/resolver.h +39 -0
  37. sgl/include/sgl/core/short_vector.h +141 -0
  38. sgl/include/sgl/core/static_vector.h +111 -0
  39. sgl/include/sgl/core/stream.h +54 -0
  40. sgl/include/sgl/core/string.h +276 -0
  41. sgl/include/sgl/core/struct.h +360 -0
  42. sgl/include/sgl/core/thread.h +28 -0
  43. sgl/include/sgl/core/timer.h +52 -0
  44. sgl/include/sgl/core/traits.h +15 -0
  45. sgl/include/sgl/core/type_utils.h +19 -0
  46. sgl/include/sgl/core/window.h +177 -0
  47. sgl/include/sgl/device/agility_sdk.h +24 -0
  48. sgl/include/sgl/device/blit.h +88 -0
  49. sgl/include/sgl/device/buffer_cursor.h +162 -0
  50. sgl/include/sgl/device/command.h +539 -0
  51. sgl/include/sgl/device/cuda_api.h +766 -0
  52. sgl/include/sgl/device/cuda_interop.h +39 -0
  53. sgl/include/sgl/device/cuda_utils.h +107 -0
  54. sgl/include/sgl/device/cursor_utils.h +129 -0
  55. sgl/include/sgl/device/device.h +668 -0
  56. sgl/include/sgl/device/device_resource.h +37 -0
  57. sgl/include/sgl/device/fence.h +91 -0
  58. sgl/include/sgl/device/formats.h +330 -0
  59. sgl/include/sgl/device/framebuffer.h +85 -0
  60. sgl/include/sgl/device/fwd.h +164 -0
  61. sgl/include/sgl/device/helpers.h +20 -0
  62. sgl/include/sgl/device/hot_reload.h +75 -0
  63. sgl/include/sgl/device/input_layout.h +74 -0
  64. sgl/include/sgl/device/kernel.h +69 -0
  65. sgl/include/sgl/device/memory_heap.h +155 -0
  66. sgl/include/sgl/device/native_formats.h +342 -0
  67. sgl/include/sgl/device/native_handle.h +73 -0
  68. sgl/include/sgl/device/native_handle_traits.h +65 -0
  69. sgl/include/sgl/device/pipeline.h +138 -0
  70. sgl/include/sgl/device/print.h +45 -0
  71. sgl/include/sgl/device/python/cursor_utils.h +853 -0
  72. sgl/include/sgl/device/query.h +52 -0
  73. sgl/include/sgl/device/raytracing.h +84 -0
  74. sgl/include/sgl/device/reflection.h +1254 -0
  75. sgl/include/sgl/device/resource.h +705 -0
  76. sgl/include/sgl/device/sampler.h +57 -0
  77. sgl/include/sgl/device/shader.h +516 -0
  78. sgl/include/sgl/device/shader_cursor.h +85 -0
  79. sgl/include/sgl/device/shader_object.h +94 -0
  80. sgl/include/sgl/device/shader_offset.h +67 -0
  81. sgl/include/sgl/device/shared_handle.h +12 -0
  82. sgl/include/sgl/device/slang_utils.h +54 -0
  83. sgl/include/sgl/device/swapchain.h +74 -0
  84. sgl/include/sgl/device/types.h +782 -0
  85. sgl/include/sgl/math/colorspace.h +56 -0
  86. sgl/include/sgl/math/constants.h +7 -0
  87. sgl/include/sgl/math/float16.h +146 -0
  88. sgl/include/sgl/math/matrix.h +6 -0
  89. sgl/include/sgl/math/matrix_math.h +746 -0
  90. sgl/include/sgl/math/matrix_types.h +207 -0
  91. sgl/include/sgl/math/python/primitivetype.h +33 -0
  92. sgl/include/sgl/math/quaternion.h +6 -0
  93. sgl/include/sgl/math/quaternion_math.h +484 -0
  94. sgl/include/sgl/math/quaternion_types.h +83 -0
  95. sgl/include/sgl/math/ray.h +47 -0
  96. sgl/include/sgl/math/scalar_math.h +249 -0
  97. sgl/include/sgl/math/scalar_types.h +107 -0
  98. sgl/include/sgl/math/vector.h +6 -0
  99. sgl/include/sgl/math/vector_math.h +1796 -0
  100. sgl/include/sgl/math/vector_types.h +336 -0
  101. sgl/include/sgl/python/nanobind.h +489 -0
  102. sgl/include/sgl/python/py_doc.h +11600 -0
  103. sgl/include/sgl/python/sgl_ext_pch.h +8 -0
  104. sgl/include/sgl/sgl.h +21 -0
  105. sgl/include/sgl/sgl_pch.h +6 -0
  106. sgl/include/sgl/stl/bit.h +377 -0
  107. sgl/include/sgl/tests/testing.h +54 -0
  108. sgl/include/sgl/ui/fwd.h +34 -0
  109. sgl/include/sgl/ui/imgui_config.h +43 -0
  110. sgl/include/sgl/ui/ui.h +71 -0
  111. sgl/include/sgl/ui/widgets.h +918 -0
  112. sgl/include/sgl/utils/python/slangpy.h +366 -0
  113. sgl/include/sgl/utils/renderdoc.h +50 -0
  114. sgl/include/sgl/utils/slangpy.h +153 -0
  115. sgl/include/sgl/utils/tev.h +93 -0
  116. sgl/include/sgl/utils/texture_loader.h +106 -0
  117. sgl/math/__init__.pyi +5083 -0
  118. sgl/platform/__init__.pyi +102 -0
  119. sgl/renderdoc/__init__.pyi +51 -0
  120. sgl/sgl.dll +0 -0
  121. sgl/sgl_ext.cp313-win_amd64.pyd +0 -0
  122. sgl/shaders/nvapi/nvHLSLExtns.h +2315 -0
  123. sgl/shaders/nvapi/nvHLSLExtnsInternal.h +758 -0
  124. sgl/shaders/nvapi/nvShaderExtnEnums.h +142 -0
  125. sgl/shaders/sgl/device/blit.slang +93 -0
  126. sgl/shaders/sgl/device/nvapi.slang +5 -0
  127. sgl/shaders/sgl/device/nvapi.slangh +7 -0
  128. sgl/shaders/sgl/device/print.slang +445 -0
  129. sgl/shaders/sgl/math/constants.slang +4 -0
  130. sgl/shaders/sgl/math/ray.slang +29 -0
  131. sgl/shaders/sgl/ui/imgui.slang +49 -0
  132. sgl/slang-glslang.dll +0 -0
  133. sgl/slang-llvm.dll +0 -0
  134. sgl/slang-rt.dll +0 -0
  135. sgl/slang.dll +0 -0
  136. sgl/slangpy/__init__.pyi +268 -0
  137. sgl/tev/__init__.pyi +108 -0
  138. sgl/tevclient.lib +0 -0
  139. sgl/thread/__init__.pyi +4 -0
  140. sgl/ui/__init__.pyi +1118 -0
  141. share/cmake/tevclient/tevclient-config-release.cmake +19 -0
  142. share/cmake/tevclient/tevclient-config.cmake +108 -0
@@ -0,0 +1,201 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include "sgl/core/error.h"
6
+ #include "sgl/core/format.h"
7
+
8
+ #include <span>
9
+ #include <string>
10
+ #include <string_view>
11
+ #include <type_traits>
12
+ #include <algorithm>
13
+ #include <vector>
14
+ #include <concepts>
15
+
16
+ namespace sgl {
17
+
18
+ // Helper using ADL to find EnumInfo in other namespaces.
19
+ template<typename T>
20
+ using EnumInfo = decltype(find_enum_info_adl(std::declval<T>()));
21
+
22
+ template<typename T>
23
+ concept has_enum_info = requires(T v) {
24
+ {
25
+ EnumInfo<T>::name()
26
+ } -> std::same_as<const std::string&>;
27
+ {
28
+ EnumInfo<T>::items()
29
+ } -> std::same_as<std::span<std::pair<T, std::string>>>;
30
+ };
31
+
32
+ /**
33
+ * Convert an enum value to a string.
34
+ * Throws if the enum value is not found in the registered enum information.
35
+ */
36
+ template<has_enum_info T>
37
+ inline const std::string& enum_to_string(T value)
38
+ {
39
+ const auto& items = EnumInfo<T>::items();
40
+ auto it = std::find_if(items.begin(), items.end(), [value](const auto& item) { return item.first == value; });
41
+ if (it == items.end())
42
+ SGL_THROW("Invalid enum value {}", int(value));
43
+ return it->second;
44
+ }
45
+
46
+ /**
47
+ * Convert a string to an enum value.
48
+ * Throws if the string is not found in the registered enum information.
49
+ */
50
+ template<has_enum_info T>
51
+ inline T string_to_enum(std::string_view name)
52
+ {
53
+ const auto& items = EnumInfo<T>::items();
54
+ auto it = std::find_if(items.begin(), items.end(), [name](const auto& item) { return item.second == name; });
55
+ if (it == items.end())
56
+ SGL_THROW("Invalid enum name \"{}\"", name);
57
+ return it->first;
58
+ }
59
+
60
+ /**
61
+ * Check if an enum has a value with the given name.
62
+ */
63
+ template<has_enum_info T>
64
+ inline bool enum_has_value(std::string_view name)
65
+ {
66
+ const auto& items = EnumInfo<T>::items();
67
+ auto it = std::find_if(items.begin(), items.end(), [name](const auto& item) { return item.second == name; });
68
+ return it != items.end();
69
+ }
70
+
71
+ /**
72
+ * Convert an flags enum value to a list of strings.
73
+ * Throws if any of the flags are not found in the registered enum information.
74
+ */
75
+ template<has_enum_info T>
76
+ inline std::vector<std::string> flags_to_string_list(T flags)
77
+ {
78
+ std::vector<std::string> list;
79
+ const auto& items = EnumInfo<T>::items();
80
+ for (const auto& item : items) {
81
+ if (is_set(flags, item.first)) {
82
+ list.push_back(item.second);
83
+ flip_bit(flags, item.first);
84
+ }
85
+ }
86
+ if (flags != T(0))
87
+ SGL_THROW("Invalid enum flags value {}", int(flags));
88
+ return list;
89
+ }
90
+
91
+ /**
92
+ * Convert a list of strings to a flags enum value.
93
+ * Throws if any of the strings are not found in the registered enum information.
94
+ */
95
+ template<has_enum_info T>
96
+ inline T string_list_to_flags(const std::vector<std::string>& list)
97
+ {
98
+ T flags = T(0);
99
+ for (const auto& name : list)
100
+ flags |= string_to_enum<T>(name);
101
+ return flags;
102
+ }
103
+
104
+ namespace detail {
105
+
106
+ /// Format an enum value.
107
+ /// First, we check for a single value and return "name::value" if it succeeds.
108
+ /// Otherwise, we check for flags and return "name::(value1 | value2 | ...)".
109
+ /// Any bits that are not found in the enum information are formatted as hex.
110
+ template<has_enum_info T>
111
+ inline std::string format_enum(T value)
112
+ {
113
+ const auto& items = EnumInfo<T>::items();
114
+ // Check for single value.
115
+ for (const auto& item : items)
116
+ if (item.first == value)
117
+ return item.second;
118
+ // Check for flags.
119
+ std::string str = "(";
120
+ uint64_t bits = uint64_t(value);
121
+ bool first = true;
122
+ for (const auto& item : items) {
123
+ if (bits & uint64_t(item.first)) {
124
+ if (!first)
125
+ str += " | ";
126
+ str += item.second;
127
+ bits &= ~uint64_t(item.first);
128
+ first = false;
129
+ }
130
+ }
131
+ if (bits != 0) {
132
+ if (!first)
133
+ str += " | ";
134
+ str += fmt::format("0x{:x}", bits);
135
+ }
136
+ str += ")";
137
+ return str;
138
+ }
139
+
140
+ } // namespace detail
141
+ } // namespace sgl
142
+
143
+ /**
144
+ * Define enum information. This is expected to be used as follows:
145
+ *
146
+ * enum class Foo { A, B, C };
147
+ * SGL_ENUM_INFO(Foo, {
148
+ * { Foo::A, "A" },
149
+ * { Foo::B, "B" },
150
+ * { Foo::C, "C" },
151
+ * })
152
+ */
153
+ #define SGL_ENUM_INFO(T, ...) \
154
+ struct T##_info { \
155
+ static const std::string& name() \
156
+ { \
157
+ static const std::string name = #T; \
158
+ return name; \
159
+ } \
160
+ static std::span<std::pair<T, std::string>> items() \
161
+ { \
162
+ static std::pair<T, std::string> items[] = __VA_ARGS__; \
163
+ return {std::begin(items), std::end(items)}; \
164
+ } \
165
+ };
166
+
167
+ /**
168
+ * Register enum information to be used with helper functions.
169
+ * This needs to be placed outside of any structs but within the
170
+ * namespace of the enum:
171
+ *
172
+ * namespace ns
173
+ * {
174
+ * struct Bar
175
+ * {
176
+ * enum class Foo { A, B, C };
177
+ * SGL_ENUM_INFO(Foo, ...)
178
+ * };
179
+ *
180
+ * SGL_ENUM_REGISTER(Bar::Foo)
181
+ * } // namespace ns
182
+ *
183
+ * Registered enums can be converted to/from strings using:
184
+ * - enum_to_string<Enum>(Enum value)
185
+ * - string_to_enum<Enum>(std::string_view name)
186
+ */
187
+ #define SGL_ENUM_REGISTER(T) \
188
+ constexpr T##_info find_enum_info_adl [[maybe_unused]] (T) noexcept \
189
+ { \
190
+ return T##_info{}; \
191
+ }
192
+
193
+ /// Enum formatter.
194
+ template<sgl::has_enum_info T>
195
+ struct fmt::formatter<T> : formatter<std::string> {
196
+ template<typename FormatContext>
197
+ auto format(const T& e, FormatContext& ctx) const
198
+ {
199
+ return formatter<std::string>::format(sgl::detail::format_enum(e), ctx);
200
+ }
201
+ };
@@ -0,0 +1,161 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include "sgl/core/macros.h"
6
+ #include "sgl/core/logger.h"
7
+ #include "sgl/core/format.h"
8
+
9
+ #include <stdexcept>
10
+ #include <string>
11
+ #include <string_view>
12
+
13
+ /**
14
+ * \file error.h
15
+ * \brief Error handling utilities.
16
+ *
17
+ * Exceptions:
18
+ * - SGL_THROW(msg, ...)
19
+ * - SGL_CHECK(cond, msg, ...)
20
+ * - SGL_UNIMPLEMENTED()
21
+ * - SGL_UNREACHABLE()
22
+ *
23
+ * Assertions:
24
+ * - SGL_ASSERT(cond)
25
+ * - SGL_ASSERT_OP(a, b, op)
26
+ *
27
+ */
28
+
29
+ /// Source location information.
30
+ /// This is similar to std::source_location which unfortunately is still not
31
+ /// well supported on all major C++ library implementations.
32
+ struct SourceLocation {
33
+ const char* file_name{nullptr};
34
+ const char* function_name{nullptr};
35
+ uint32_t line{0};
36
+ uint32_t column{0};
37
+
38
+ [[nodiscard]] static consteval SourceLocation current(
39
+ const char* file_name = __builtin_FILE(),
40
+ const char* function_name = __builtin_FUNCTION(),
41
+ uint32_t line = __builtin_LINE(),
42
+ #if !SGL_GCC
43
+ uint32_t column = __builtin_COLUMN()
44
+ #else
45
+ uint32_t column = 0
46
+ #endif
47
+ )
48
+ {
49
+ return SourceLocation{file_name, function_name, line, column};
50
+ }
51
+ };
52
+
53
+ // -------------------------------------------------------------------------------------------------
54
+ // Exceptions
55
+ // -------------------------------------------------------------------------------------------------
56
+
57
+ namespace sgl {
58
+
59
+ enum class ExceptionDiagnosticFlags {
60
+ none = 0,
61
+ /// Break into debugger when throwing an exception.
62
+ break_debugger = 1,
63
+ /// Log exception message.
64
+ log = 2,
65
+ };
66
+
67
+ SGL_ENUM_CLASS_OPERATORS(ExceptionDiagnosticFlags);
68
+
69
+ /// Set exception diagnostic options.
70
+ void SGL_API set_exception_diagnostics(ExceptionDiagnosticFlags flags);
71
+
72
+
73
+ /// Throw an exception.
74
+ [[noreturn]] SGL_API void throw_exception(const SourceLocation& loc, std::string_view msg);
75
+
76
+ namespace detail {
77
+ [[noreturn]] inline void throw_exception(const SourceLocation& loc, std::string_view msg)
78
+ {
79
+ ::sgl::throw_exception(loc, msg);
80
+ }
81
+
82
+ template<typename... Args>
83
+ [[noreturn]] inline void throw_exception(const SourceLocation& loc, fmt::format_string<Args...> fmt, Args&&... args)
84
+ {
85
+ ::sgl::throw_exception(loc, fmt::format(fmt, std::forward<Args>(args)...));
86
+ }
87
+
88
+ } // namespace detail
89
+ } // namespace sgl
90
+
91
+ /// Helper for throwing exceptions.
92
+ /// Logs the exception and a stack trace before throwing.
93
+ #define SGL_THROW(...) ::sgl::detail::throw_exception(SourceLocation::current(), __VA_ARGS__)
94
+
95
+ /// Helper for checking conditions and throwing exceptions.
96
+ /// Logs the exception and a stack trace before throwing.
97
+ #define SGL_CHECK(cond, ...) \
98
+ do { \
99
+ if (!(cond)) \
100
+ SGL_THROW(__VA_ARGS__); \
101
+ } while (0)
102
+
103
+ /// Helper for throwing an exception if a pointer is null.
104
+ #define SGL_CHECK_NOT_NULL(arg) SGL_CHECK(arg != nullptr, "\"{}\" must not be null", #arg)
105
+
106
+ #define SGL_CHECK_LT(arg, value) SGL_CHECK(arg < value, "\"{}\" must be less than {}", #arg, value)
107
+ #define SGL_CHECK_LE(arg, value) SGL_CHECK(arg <= value, "\"{}\" must be less than or equal {}", #arg, value)
108
+ #define SGL_CHECK_GT(arg, value) SGL_CHECK(arg > value, "\"{}\" must be greater than {}", #arg, value)
109
+ #define SGL_CHECK_GE(arg, value) SGL_CHECK(arg >= value, "\"{}\" must be greater than or equal {}", #arg, value)
110
+ #define SGL_CHECK_BOUNDS(arg, min, max) \
111
+ SGL_CHECK(arg >= min && arg < max, "\"{}\" must be in range [{}, {}]", #arg, min, max)
112
+
113
+ /// Helper for marking unimplemented functions.
114
+ #define SGL_UNIMPLEMENTED() SGL_THROW("Unimplemented")
115
+
116
+ /// Helper for marking unreachable code.
117
+ #define SGL_UNREACHABLE() SGL_THROW("Unreachable")
118
+
119
+ // -------------------------------------------------------------------------------------------------
120
+ // Assertions
121
+ // -------------------------------------------------------------------------------------------------
122
+
123
+ namespace sgl {
124
+
125
+ /// Report a failed assertion.
126
+ [[noreturn]] SGL_API void report_assertion(const SourceLocation& loc, std::string_view cond);
127
+
128
+ } // namespace sgl
129
+
130
+ #if SGL_ENABLE_ASSERTS
131
+
132
+ #define SGL_ASSERT(cond) \
133
+ if (!(cond)) { \
134
+ ::sgl::report_assertion(SourceLocation::current(), #cond); \
135
+ }
136
+
137
+ #define SGL_ASSERT_OP(a, b, op) \
138
+ if (!((a)op(b))) { \
139
+ ::sgl::report_assertion( \
140
+ SourceLocation::current(), \
141
+ fmt::format("{} {} {} ({} {} {})", #a, #op, #b, a, #op, b) \
142
+ ); \
143
+ }
144
+
145
+ #else // SGL_ENABLE_ASSERTS
146
+
147
+ #define SGL_ASSERT(a) \
148
+ { \
149
+ }
150
+ #define SGL_ASSERT_OP(a, b, op) \
151
+ { \
152
+ }
153
+
154
+ #endif // SGL_ENABLE_ASSERTS
155
+
156
+ #define SGL_ASSERT_EQ(a, b) SGL_ASSERT_OP(a, b, ==)
157
+ #define SGL_ASSERT_NE(a, b) SGL_ASSERT_OP(a, b, !=)
158
+ #define SGL_ASSERT_GE(a, b) SGL_ASSERT_OP(a, b, >=)
159
+ #define SGL_ASSERT_GT(a, b) SGL_ASSERT_OP(a, b, >)
160
+ #define SGL_ASSERT_LE(a, b) SGL_ASSERT_OP(a, b, <=)
161
+ #define SGL_ASSERT_LT(a, b) SGL_ASSERT_OP(a, b, <)
@@ -0,0 +1,77 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include "sgl/core/stream.h"
6
+ #include "sgl/core/enum.h"
7
+
8
+ #include <exception>
9
+ #include <filesystem>
10
+ #include <iosfwd>
11
+ #include <memory>
12
+
13
+ namespace sgl {
14
+
15
+ class SGL_API EOFException : public std::runtime_error {
16
+ public:
17
+ EOFException(const std::string& what, size_t gcount)
18
+ : std::runtime_error(what)
19
+ , m_gcount(gcount)
20
+ {
21
+ }
22
+
23
+ size_t gcount() const { return m_gcount; }
24
+
25
+ private:
26
+ size_t m_gcount;
27
+ };
28
+
29
+ class SGL_API FileStream : public Stream {
30
+ SGL_OBJECT(FileStream)
31
+ public:
32
+ enum class Mode {
33
+ read,
34
+ write,
35
+ read_write,
36
+ };
37
+
38
+ SGL_ENUM_INFO(
39
+ Mode,
40
+ {
41
+ {Mode::read, "read"},
42
+ {Mode::write, "write"},
43
+ {Mode::read_write, "read_write"},
44
+ }
45
+ );
46
+
47
+ FileStream(const std::filesystem::path& path, Mode mode);
48
+ virtual ~FileStream();
49
+
50
+ const std::filesystem::path& path() const { return m_path; }
51
+ Mode mode() const { return m_mode; }
52
+
53
+ bool is_open() const override;
54
+ bool is_readable() const override { return m_mode == Mode::read || m_mode == Mode::read_write; }
55
+ bool is_writable() const override { return m_mode == Mode::write || m_mode == Mode::read_write; }
56
+
57
+ void close() override;
58
+
59
+ void read(void* p, size_t size) override;
60
+ void write(const void* p, size_t size) override;
61
+ void seek(size_t pos) override;
62
+ void truncate(size_t size) override;
63
+ size_t tell() const override;
64
+ size_t size() const override;
65
+ void flush() override;
66
+
67
+ std::string to_string() const override;
68
+
69
+ private:
70
+ std::filesystem::path m_path;
71
+ Mode m_mode;
72
+ std::unique_ptr<std::fstream> m_stream;
73
+ };
74
+
75
+ SGL_ENUM_REGISTER(FileStream::Mode);
76
+
77
+ } // namespace sgl
@@ -0,0 +1,141 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include "sgl/core/fwd.h"
6
+ #include "sgl/core/stream.h"
7
+ #include "sgl/core/enum.h"
8
+ #include "sgl/core/platform.h"
9
+
10
+ #include <atomic>
11
+ #include <chrono>
12
+ #include <filesystem>
13
+ #include <functional>
14
+ #include <map>
15
+ #include <mutex>
16
+ #include <thread>
17
+
18
+ namespace sgl {
19
+
20
+ /// Types of file system event that can be reported.
21
+ enum class FileSystemWatcherChange {
22
+ invalid,
23
+ added,
24
+ removed,
25
+ modified,
26
+ };
27
+
28
+ /// Init options for FileSystemWatcher.
29
+ struct FileSystemWatchDesc {
30
+
31
+ /// Directory to monitor.
32
+ std::filesystem::path directory;
33
+ };
34
+
35
+ /// Data reported on a given file system event to a file monitored
36
+ /// by FileSystemWatcher.
37
+ struct FileSystemWatchEvent {
38
+
39
+ /// Path of file that has changed relative to watcher.
40
+ std::filesystem::path path;
41
+
42
+ /// Absolute path of file in file system
43
+ std::filesystem::path absolute_path;
44
+
45
+ /// Change type.
46
+ FileSystemWatcherChange change{FileSystemWatcherChange::invalid};
47
+
48
+ /// System time change was recorded.
49
+ std::chrono::system_clock::time_point time;
50
+ };
51
+
52
+ // Declare watch state (only used internally).
53
+ struct FileSystemWatchState;
54
+
55
+ /// Monitors directories for changes and calls a callback when they're detected.
56
+ /// The watcher automatically queues up changes until disk has been idle for
57
+ /// a period. Relies on regular polling of update().
58
+ class SGL_API FileSystemWatcher : public Object {
59
+ SGL_OBJECT(FileSystemWatcher)
60
+ public:
61
+ using ChangeCallback = std::function<void(std::span<FileSystemWatchEvent>)>;
62
+
63
+ FileSystemWatcher();
64
+ ~FileSystemWatcher();
65
+
66
+ /// FileSystemWatch move constructor is deleted to allow for map of unique ptrs.
67
+ FileSystemWatcher(FileSystemWatcher&& other) = delete;
68
+
69
+ /// Add watch of a new directory.
70
+ uint32_t add_watch(const FileSystemWatchDesc& desc);
71
+
72
+ /// Remove existing watch.
73
+ void remove_watch(uint32_t id);
74
+
75
+ /// Remove existing watch.
76
+ void remove_watch(const std::filesystem::path& directory);
77
+
78
+ /// Get number of active watches
79
+ size_t watch_count() const { return m_watches.size(); }
80
+
81
+ /// Get callback for file system events.
82
+ ChangeCallback on_change() const { return m_on_change; }
83
+
84
+ /// Set callback for file system events.
85
+ void set_on_change(ChangeCallback on_change);
86
+
87
+ /// Update function to poll the watcher + report events.
88
+ void update();
89
+
90
+ /// Delay period before queued events are output.
91
+ uint32_t delay() { return m_output_delay_ms; }
92
+
93
+ /// Set delay period before queued events are output.
94
+ void set_delay(uint32_t milliseconds) { m_output_delay_ms = milliseconds; }
95
+
96
+ /// Internal function called when OS reports an event.
97
+ void _notify_change(FileSystemWatchState* state, const std::filesystem::path& path, FileSystemWatcherChange change);
98
+
99
+ private:
100
+ /// Releases OS monitoring for a given watch.
101
+ void stop_watch(const std::unique_ptr<FileSystemWatchState>&);
102
+
103
+ /// Next unique id to be assigned to a given watch.
104
+ uint32_t m_next_id{1};
105
+
106
+ /// Delay before outputting events in milliseconds.
107
+ uint32_t m_output_delay_ms{1000};
108
+
109
+ /// Map of id->watch.
110
+ std::map<int, std::unique_ptr<FileSystemWatchState>> m_watches;
111
+
112
+ /// Watch event callback.
113
+ ChangeCallback m_on_change;
114
+
115
+ /// Events reported since last call to watch event callback.
116
+ std::vector<FileSystemWatchEvent> m_queued_events;
117
+
118
+ /// Time last event was recorded.
119
+ std::chrono::system_clock::time_point m_last_event;
120
+
121
+ #if SGL_LINUX
122
+ /// File descriptor for linux inotify watcher.
123
+ int m_inotify_file_descriptor;
124
+ #endif
125
+
126
+ #if !SGL_LINUX
127
+ /// Mutex to protect the watch map.
128
+ std::mutex m_watches_mutex;
129
+
130
+ /// Mutex to protect the queued events.
131
+ std::mutex m_queued_events_mutex;
132
+
133
+ /// Thread to poll for file system changes.
134
+ std::thread m_thread;
135
+ std::atomic<bool> m_stop_thread{false};
136
+ void thread_func();
137
+ #endif
138
+ };
139
+
140
+
141
+ } // namespace sgl
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include "sgl/core/macros.h"
6
+
7
+ SGL_DIAGNOSTIC_PUSH
8
+ SGL_DISABLE_MSVC_WARNING(4061 4459)
9
+ #include <fmt/format.h>
10
+ #include <fmt/ranges.h>
11
+ SGL_DIAGNOSTIC_POP
12
+
13
+ #include <filesystem>
14
+ #include <optional>
15
+
16
+ template<>
17
+ struct fmt::formatter<std::filesystem::path> : formatter<std::string> {
18
+ template<typename FormatContext>
19
+ auto format(const std::filesystem::path& p, FormatContext& ctx) const
20
+ {
21
+ return formatter<std::string>::format(p.string(), ctx);
22
+ }
23
+ };
24
+
25
+ template<typename T>
26
+ struct fmt::formatter<std::optional<T>> : formatter<T> {
27
+ template<typename FormatContext>
28
+ auto format(const std::optional<T>& opt, FormatContext& ctx) const
29
+ {
30
+ if (opt) {
31
+ formatter<T>::format(*opt, ctx);
32
+ return ctx.out();
33
+ }
34
+ return fmt::format_to(ctx.out(), "nullopt");
35
+ }
36
+ };
@@ -0,0 +1,90 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+
3
+ #pragma once
4
+
5
+ #include <cstdlib>
6
+
7
+ namespace sgl {
8
+
9
+ // bitmap.h
10
+
11
+ class Bitmap;
12
+
13
+ // blob.h
14
+
15
+ class Blob;
16
+
17
+ // file_stream.h
18
+
19
+ class EOFException;
20
+ class FileStream;
21
+
22
+ // file_system_watcher.h
23
+
24
+ struct FileSystemWatchDesc;
25
+ struct FileSystemWatchEvent;
26
+ class FileSystemWatcher;
27
+
28
+ // input.h
29
+
30
+ struct KeyboardEvent;
31
+ struct MouseEvent;
32
+ struct GamepadEvent;
33
+ struct GamepadState;
34
+
35
+ // logger.h
36
+
37
+ class LoggerOutput;
38
+ class ConsoleLoggerOutput;
39
+ class FileLoggerOutput;
40
+ class DebugConsoleLoggerOutput;
41
+ class Logger;
42
+
43
+ // memory_mapped_file_stream.h
44
+
45
+ class MemoryMappedFileStream;
46
+
47
+ // memory_mapped_file.h
48
+
49
+ class MemoryMappedFile;
50
+
51
+ // memory_stream.h
52
+
53
+ class MemoryStream;
54
+
55
+ // object.h
56
+
57
+ class Object;
58
+ template<typename>
59
+ class ref;
60
+ template<typename>
61
+ class breakable_ref;
62
+
63
+ // short_vector.h
64
+
65
+ template<typename T, size_t N>
66
+ class short_vector;
67
+
68
+ // static_vector.h
69
+
70
+ template<typename T, size_t N>
71
+ class static_vector;
72
+
73
+ // stream.h
74
+
75
+ class Stream;
76
+
77
+ // struct.h
78
+
79
+ class Struct;
80
+ class StructConverter;
81
+
82
+ // timer.h
83
+
84
+ class Timer;
85
+
86
+ // window.h
87
+
88
+ class Window;
89
+
90
+ } // namespace sgl