nv-sgl 0.6.0__cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Sign up to get free protection for your applications and to get access to all the features.
- include/tevclient.h +393 -0
- nv_sgl-0.6.0.dist-info/LICENSE +29 -0
- nv_sgl-0.6.0.dist-info/METADATA +21 -0
- nv_sgl-0.6.0.dist-info/RECORD +133 -0
- nv_sgl-0.6.0.dist-info/WHEEL +6 -0
- nv_sgl-0.6.0.dist-info/top_level.txt +1 -0
- sgl/__init__.py +15 -0
- sgl/__init__.pyi +6738 -0
- sgl/include/sgl/app/app.h +113 -0
- sgl/include/sgl/core/bitmap.h +302 -0
- sgl/include/sgl/core/crypto.h +89 -0
- sgl/include/sgl/core/data_type.h +46 -0
- sgl/include/sgl/core/dds_file.h +103 -0
- sgl/include/sgl/core/enum.h +201 -0
- sgl/include/sgl/core/error.h +161 -0
- sgl/include/sgl/core/file_stream.h +77 -0
- sgl/include/sgl/core/file_system_watcher.h +141 -0
- sgl/include/sgl/core/format.h +36 -0
- sgl/include/sgl/core/fwd.h +90 -0
- sgl/include/sgl/core/hash.h +45 -0
- sgl/include/sgl/core/input.h +522 -0
- sgl/include/sgl/core/logger.h +214 -0
- sgl/include/sgl/core/macros.h +184 -0
- sgl/include/sgl/core/maths.h +45 -0
- sgl/include/sgl/core/memory_mapped_file.h +112 -0
- sgl/include/sgl/core/memory_mapped_file_stream.h +32 -0
- sgl/include/sgl/core/memory_stream.h +74 -0
- sgl/include/sgl/core/object.h +683 -0
- sgl/include/sgl/core/platform.h +239 -0
- sgl/include/sgl/core/plugin.h +331 -0
- sgl/include/sgl/core/resolver.h +39 -0
- sgl/include/sgl/core/short_vector.h +141 -0
- sgl/include/sgl/core/static_vector.h +111 -0
- sgl/include/sgl/core/stream.h +54 -0
- sgl/include/sgl/core/string.h +276 -0
- sgl/include/sgl/core/struct.h +360 -0
- sgl/include/sgl/core/thread.h +28 -0
- sgl/include/sgl/core/timer.h +52 -0
- sgl/include/sgl/core/traits.h +15 -0
- sgl/include/sgl/core/type_utils.h +19 -0
- sgl/include/sgl/core/window.h +177 -0
- sgl/include/sgl/device/agility_sdk.h +24 -0
- sgl/include/sgl/device/blit.h +88 -0
- sgl/include/sgl/device/buffer_cursor.h +162 -0
- sgl/include/sgl/device/command.h +539 -0
- sgl/include/sgl/device/cuda_api.h +766 -0
- sgl/include/sgl/device/cuda_interop.h +39 -0
- sgl/include/sgl/device/cuda_utils.h +107 -0
- sgl/include/sgl/device/cursor_utils.h +129 -0
- sgl/include/sgl/device/device.h +668 -0
- sgl/include/sgl/device/device_resource.h +37 -0
- sgl/include/sgl/device/fence.h +91 -0
- sgl/include/sgl/device/formats.h +330 -0
- sgl/include/sgl/device/framebuffer.h +85 -0
- sgl/include/sgl/device/fwd.h +164 -0
- sgl/include/sgl/device/helpers.h +20 -0
- sgl/include/sgl/device/hot_reload.h +75 -0
- sgl/include/sgl/device/input_layout.h +74 -0
- sgl/include/sgl/device/kernel.h +69 -0
- sgl/include/sgl/device/memory_heap.h +155 -0
- sgl/include/sgl/device/native_formats.h +342 -0
- sgl/include/sgl/device/native_handle.h +73 -0
- sgl/include/sgl/device/native_handle_traits.h +65 -0
- sgl/include/sgl/device/pipeline.h +138 -0
- sgl/include/sgl/device/print.h +45 -0
- sgl/include/sgl/device/python/cursor_utils.h +853 -0
- sgl/include/sgl/device/query.h +52 -0
- sgl/include/sgl/device/raytracing.h +84 -0
- sgl/include/sgl/device/reflection.h +1254 -0
- sgl/include/sgl/device/resource.h +705 -0
- sgl/include/sgl/device/sampler.h +57 -0
- sgl/include/sgl/device/shader.h +516 -0
- sgl/include/sgl/device/shader_cursor.h +85 -0
- sgl/include/sgl/device/shader_object.h +94 -0
- sgl/include/sgl/device/shader_offset.h +67 -0
- sgl/include/sgl/device/shared_handle.h +12 -0
- sgl/include/sgl/device/slang_utils.h +54 -0
- sgl/include/sgl/device/swapchain.h +74 -0
- sgl/include/sgl/device/types.h +782 -0
- sgl/include/sgl/math/colorspace.h +56 -0
- sgl/include/sgl/math/constants.h +7 -0
- sgl/include/sgl/math/float16.h +146 -0
- sgl/include/sgl/math/matrix.h +6 -0
- sgl/include/sgl/math/matrix_math.h +746 -0
- sgl/include/sgl/math/matrix_types.h +207 -0
- sgl/include/sgl/math/python/primitivetype.h +33 -0
- sgl/include/sgl/math/quaternion.h +6 -0
- sgl/include/sgl/math/quaternion_math.h +484 -0
- sgl/include/sgl/math/quaternion_types.h +83 -0
- sgl/include/sgl/math/ray.h +47 -0
- sgl/include/sgl/math/scalar_math.h +249 -0
- sgl/include/sgl/math/scalar_types.h +107 -0
- sgl/include/sgl/math/vector.h +6 -0
- sgl/include/sgl/math/vector_math.h +1796 -0
- sgl/include/sgl/math/vector_types.h +336 -0
- sgl/include/sgl/python/nanobind.h +489 -0
- sgl/include/sgl/python/py_doc.h +11600 -0
- sgl/include/sgl/python/sgl_ext_pch.h +8 -0
- sgl/include/sgl/sgl.h +21 -0
- sgl/include/sgl/sgl_pch.h +6 -0
- sgl/include/sgl/stl/bit.h +377 -0
- sgl/include/sgl/tests/testing.h +54 -0
- sgl/include/sgl/ui/fwd.h +34 -0
- sgl/include/sgl/ui/imgui_config.h +43 -0
- sgl/include/sgl/ui/ui.h +71 -0
- sgl/include/sgl/ui/widgets.h +918 -0
- sgl/include/sgl/utils/python/slangpy.h +366 -0
- sgl/include/sgl/utils/renderdoc.h +50 -0
- sgl/include/sgl/utils/slangpy.h +153 -0
- sgl/include/sgl/utils/tev.h +93 -0
- sgl/include/sgl/utils/texture_loader.h +106 -0
- sgl/libgfx.so +0 -0
- sgl/libsgl.so +0 -0
- sgl/libslang-glslang.so +0 -0
- sgl/libslang.so +0 -0
- sgl/libtevclient.a +0 -0
- sgl/math/__init__.pyi +5083 -0
- sgl/platform/__init__.pyi +102 -0
- sgl/renderdoc/__init__.pyi +51 -0
- sgl/sgl_ext.cpython-313-x86_64-linux-gnu.so +0 -0
- sgl/shaders/sgl/device/blit.slang +93 -0
- sgl/shaders/sgl/device/nvapi.slang +5 -0
- sgl/shaders/sgl/device/nvapi.slangh +7 -0
- sgl/shaders/sgl/device/print.slang +445 -0
- sgl/shaders/sgl/math/constants.slang +4 -0
- sgl/shaders/sgl/math/ray.slang +29 -0
- sgl/shaders/sgl/ui/imgui.slang +49 -0
- sgl/slangpy/__init__.pyi +268 -0
- sgl/tev/__init__.pyi +108 -0
- sgl/thread/__init__.pyi +4 -0
- sgl/ui/__init__.pyi +1118 -0
- share/cmake/tevclient/tevclient-config-release.cmake +19 -0
- share/cmake/tevclient/tevclient-config.cmake +103 -0
@@ -0,0 +1,141 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include <utility>
|
6
|
+
#include <algorithm>
|
7
|
+
|
8
|
+
namespace sgl {
|
9
|
+
|
10
|
+
/**
|
11
|
+
* \brief A vector that stores a small number of elements on the stack.
|
12
|
+
*
|
13
|
+
* \tparam T Element type
|
14
|
+
* \tparam N Size of the short vector
|
15
|
+
*/
|
16
|
+
template<typename T, std::size_t N>
|
17
|
+
class short_vector {
|
18
|
+
public:
|
19
|
+
static_assert(N > 0, "short_vector must have a size greater than zero.");
|
20
|
+
|
21
|
+
using value_type = T;
|
22
|
+
using size_type = std::size_t;
|
23
|
+
using difference_type = std::ptrdiff_t;
|
24
|
+
using reference = value_type&;
|
25
|
+
using const_reference = const value_type&;
|
26
|
+
using iterator = value_type*;
|
27
|
+
using const_iterator = const value_type*;
|
28
|
+
|
29
|
+
/// Default constructor.
|
30
|
+
short_vector() noexcept
|
31
|
+
: m_data(m_short_data)
|
32
|
+
, m_size(0)
|
33
|
+
, m_capacity(N)
|
34
|
+
{
|
35
|
+
}
|
36
|
+
|
37
|
+
/// Size constructor.
|
38
|
+
short_vector(size_type size, const value_type& value)
|
39
|
+
: m_data(m_short_data)
|
40
|
+
, m_size(size)
|
41
|
+
, m_capacity(N)
|
42
|
+
{
|
43
|
+
if (size > m_capacity)
|
44
|
+
grow(size);
|
45
|
+
for (size_type i = 0; i < size; ++i)
|
46
|
+
m_data[i] = value;
|
47
|
+
}
|
48
|
+
|
49
|
+
/// Initializer list constructor.
|
50
|
+
short_vector(std::initializer_list<value_type> list)
|
51
|
+
: m_data(m_short_data)
|
52
|
+
, m_size(0)
|
53
|
+
, m_capacity(N)
|
54
|
+
{
|
55
|
+
for (const auto& value : list)
|
56
|
+
push_back(value);
|
57
|
+
}
|
58
|
+
|
59
|
+
~short_vector()
|
60
|
+
{
|
61
|
+
if (m_data != m_short_data)
|
62
|
+
delete[] m_data;
|
63
|
+
}
|
64
|
+
|
65
|
+
short_vector(const short_vector& other) = delete;
|
66
|
+
short_vector(short_vector&& other) = delete;
|
67
|
+
|
68
|
+
short_vector& operator=(const short_vector& other) = delete;
|
69
|
+
short_vector& operator=(short_vector&& other) = delete;
|
70
|
+
|
71
|
+
reference operator[](size_type index) noexcept { return m_data[index]; }
|
72
|
+
const_reference operator[](size_type index) const noexcept { return m_data[index]; }
|
73
|
+
|
74
|
+
reference front() noexcept { return m_data[0]; }
|
75
|
+
const_reference front() const noexcept { return m_data[0]; }
|
76
|
+
|
77
|
+
reference back() noexcept { return m_data[m_size - 1]; }
|
78
|
+
const_reference back() const noexcept { return m_data[m_size - 1]; }
|
79
|
+
|
80
|
+
iterator begin() noexcept { return m_data; }
|
81
|
+
const_iterator begin() const noexcept { return m_data; }
|
82
|
+
|
83
|
+
iterator end() noexcept { return m_data + m_size; }
|
84
|
+
const_iterator end() const noexcept { return m_data + m_size; }
|
85
|
+
|
86
|
+
bool empty() const noexcept { return m_size == 0; }
|
87
|
+
|
88
|
+
value_type* data() noexcept { return m_data; }
|
89
|
+
const value_type* data() const noexcept { return m_data; }
|
90
|
+
|
91
|
+
size_type size() const noexcept { return m_size; }
|
92
|
+
size_type capacity() const noexcept { return m_capacity; }
|
93
|
+
|
94
|
+
void clear() noexcept { m_size = 0; }
|
95
|
+
|
96
|
+
void reserve(size_type new_capacity) { grow(new_capacity); }
|
97
|
+
|
98
|
+
void push_back(const value_type& value)
|
99
|
+
{
|
100
|
+
if (m_size == m_capacity)
|
101
|
+
grow(m_capacity * 2);
|
102
|
+
m_data[m_size++] = value;
|
103
|
+
}
|
104
|
+
|
105
|
+
void push_back(value_type&& value)
|
106
|
+
{
|
107
|
+
if (m_size == m_capacity)
|
108
|
+
grow(m_capacity * 2);
|
109
|
+
m_data[m_size++] = std::move(value);
|
110
|
+
}
|
111
|
+
|
112
|
+
template<typename... Args>
|
113
|
+
void emplace_back(Args&&... args)
|
114
|
+
{
|
115
|
+
if (m_size == m_capacity)
|
116
|
+
grow(m_capacity * 2);
|
117
|
+
m_data[m_size++] = value_type(std::forward<Args>(args)...);
|
118
|
+
}
|
119
|
+
|
120
|
+
void pop_back() { --m_size; }
|
121
|
+
|
122
|
+
private:
|
123
|
+
void grow(size_type new_capacity)
|
124
|
+
{
|
125
|
+
if (new_capacity <= m_capacity)
|
126
|
+
return;
|
127
|
+
m_capacity = new_capacity;
|
128
|
+
value_type* new_data = new value_type[m_capacity];
|
129
|
+
std::move(m_data, m_data + m_size, new_data);
|
130
|
+
if (m_data != m_short_data)
|
131
|
+
delete[] m_data;
|
132
|
+
m_data = new_data;
|
133
|
+
}
|
134
|
+
|
135
|
+
value_type m_short_data[N];
|
136
|
+
value_type* m_data;
|
137
|
+
size_type m_size;
|
138
|
+
size_type m_capacity;
|
139
|
+
};
|
140
|
+
|
141
|
+
} // namespace sgl
|
@@ -0,0 +1,111 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/error.h"
|
6
|
+
|
7
|
+
#include <utility>
|
8
|
+
#include <array>
|
9
|
+
|
10
|
+
namespace sgl {
|
11
|
+
|
12
|
+
/**
|
13
|
+
* \brief A vector that stores up to a fixed number of elements.
|
14
|
+
*
|
15
|
+
* \tparam T Element type
|
16
|
+
* \tparam N Maximum size of the static vector
|
17
|
+
*/
|
18
|
+
template<typename T, std::size_t N>
|
19
|
+
class static_vector {
|
20
|
+
public:
|
21
|
+
static_assert(N > 0, "static_vector must have a size greater than zero.");
|
22
|
+
|
23
|
+
using value_type = T;
|
24
|
+
using size_type = std::size_t;
|
25
|
+
using difference_type = std::ptrdiff_t;
|
26
|
+
using reference = value_type&;
|
27
|
+
using const_reference = const value_type&;
|
28
|
+
using iterator = value_type*;
|
29
|
+
using const_iterator = const value_type*;
|
30
|
+
|
31
|
+
/// Default constructor.
|
32
|
+
static_vector() noexcept = default;
|
33
|
+
|
34
|
+
/// Size constructor.
|
35
|
+
static_vector(size_type size, const value_type& value)
|
36
|
+
{
|
37
|
+
for (size_type i = 0; i < size; ++i)
|
38
|
+
push_back(value);
|
39
|
+
}
|
40
|
+
|
41
|
+
/// Initializer list constructor.
|
42
|
+
static_vector(std::initializer_list<value_type> list)
|
43
|
+
{
|
44
|
+
for (const auto& value : list)
|
45
|
+
push_back(value);
|
46
|
+
}
|
47
|
+
|
48
|
+
~static_vector() = default;
|
49
|
+
|
50
|
+
static_vector(const static_vector& other) = default;
|
51
|
+
static_vector(static_vector&& other) = default;
|
52
|
+
|
53
|
+
static_vector& operator=(const static_vector& other) = default;
|
54
|
+
static_vector& operator=(static_vector&& other) = default;
|
55
|
+
|
56
|
+
reference operator[](size_type index) noexcept { return m_data[index]; }
|
57
|
+
const_reference operator[](size_type index) const noexcept { return m_data[index]; }
|
58
|
+
|
59
|
+
reference front() noexcept { return m_data[0]; }
|
60
|
+
const_reference front() const noexcept { return m_data[0]; }
|
61
|
+
|
62
|
+
reference back() noexcept { return m_data[m_size - 1]; }
|
63
|
+
const_reference back() const noexcept { return m_data[m_size - 1]; }
|
64
|
+
|
65
|
+
iterator begin() noexcept { return m_data.data(); }
|
66
|
+
const_iterator begin() const noexcept { return m_data.data(); }
|
67
|
+
|
68
|
+
iterator end() noexcept { return m_data.data() + m_size; }
|
69
|
+
const_iterator end() const noexcept { return m_data.data() + m_size; }
|
70
|
+
|
71
|
+
bool empty() const noexcept { return m_size == 0; }
|
72
|
+
|
73
|
+
value_type* data() noexcept { return m_data.data(); }
|
74
|
+
const value_type* data() const noexcept { return m_data.data(); }
|
75
|
+
|
76
|
+
size_type size() const noexcept { return m_size; }
|
77
|
+
size_type capacity() const noexcept { return N; }
|
78
|
+
|
79
|
+
void clear() noexcept { m_size = 0; }
|
80
|
+
|
81
|
+
void push_back(const value_type& value)
|
82
|
+
{
|
83
|
+
SGL_ASSERT(m_size < capacity());
|
84
|
+
m_data[m_size++] = value;
|
85
|
+
}
|
86
|
+
|
87
|
+
void push_back(value_type&& value)
|
88
|
+
{
|
89
|
+
SGL_ASSERT(m_size < capacity());
|
90
|
+
m_data[m_size++] = std::move(value);
|
91
|
+
}
|
92
|
+
|
93
|
+
template<typename... Args>
|
94
|
+
void emplace_back(Args&&... args)
|
95
|
+
{
|
96
|
+
SGL_ASSERT(m_size < capacity());
|
97
|
+
m_data[m_size++] = value_type(std::forward<Args>(args)...);
|
98
|
+
}
|
99
|
+
|
100
|
+
void pop_back()
|
101
|
+
{
|
102
|
+
SGL_ASSERT(m_size > 0);
|
103
|
+
--m_size;
|
104
|
+
}
|
105
|
+
|
106
|
+
private:
|
107
|
+
std::array<T, N> m_data;
|
108
|
+
size_type m_size{0};
|
109
|
+
};
|
110
|
+
|
111
|
+
} // namespace sgl
|
@@ -0,0 +1,54 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
#include "sgl/core/object.h"
|
7
|
+
|
8
|
+
namespace sgl {
|
9
|
+
|
10
|
+
/**
|
11
|
+
* \brief Base class for all stream objects.
|
12
|
+
*/
|
13
|
+
class SGL_API Stream : public Object {
|
14
|
+
SGL_OBJECT(Stream)
|
15
|
+
public:
|
16
|
+
/// Returns true if the stream is open.
|
17
|
+
virtual bool is_open() const = 0;
|
18
|
+
|
19
|
+
/// Returns true if the stream is readable.
|
20
|
+
virtual bool is_readable() const = 0;
|
21
|
+
|
22
|
+
/// Returns true if the stream is writable.
|
23
|
+
virtual bool is_writable() const = 0;
|
24
|
+
|
25
|
+
/// Close the stream. No further read/writes are allowed.
|
26
|
+
/// \note This is a no-op if the stream is already closed.
|
27
|
+
virtual void close() = 0;
|
28
|
+
|
29
|
+
/// Read data from the stream.
|
30
|
+
/// Throws an exception if not all data could be read.
|
31
|
+
virtual void read(void* p, size_t size) = 0;
|
32
|
+
|
33
|
+
/// Write data to the stream.
|
34
|
+
/// Throws an exception if not all data could be written.
|
35
|
+
virtual void write(const void* p, size_t size) = 0;
|
36
|
+
|
37
|
+
/// Seeks a position within the stream.
|
38
|
+
virtual void seek(size_t pos) = 0;
|
39
|
+
|
40
|
+
/// Truncate the stream to the given size.
|
41
|
+
/// Throws an exception if stream is in read-only mode or does not support truncation.
|
42
|
+
virtual void truncate(size_t size) = 0;
|
43
|
+
|
44
|
+
/// Get the current position in the stream.
|
45
|
+
virtual size_t tell() const = 0;
|
46
|
+
|
47
|
+
/// Get the size of the stream.
|
48
|
+
virtual size_t size() const = 0;
|
49
|
+
|
50
|
+
/// Flush the internal buffers.
|
51
|
+
virtual void flush() = 0;
|
52
|
+
};
|
53
|
+
|
54
|
+
} // namespace sgl
|
@@ -0,0 +1,276 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
|
3
|
+
#pragma once
|
4
|
+
|
5
|
+
#include "sgl/core/macros.h"
|
6
|
+
#include "sgl/core/object.h"
|
7
|
+
|
8
|
+
#include <span>
|
9
|
+
#include <string_view>
|
10
|
+
#include <string>
|
11
|
+
#include <vector>
|
12
|
+
|
13
|
+
namespace sgl::string {
|
14
|
+
|
15
|
+
/**
|
16
|
+
* Copy a string to a C-style string buffer.
|
17
|
+
* Truncates the input string if it doesn't fit the buffer and always null-terminates the buffer.
|
18
|
+
* \param dst C-style string buffer.
|
19
|
+
* \param dst_len Length of the buffer.
|
20
|
+
* \param src Input string.
|
21
|
+
*/
|
22
|
+
SGL_API void copy_to_cstr(char* dst, size_t dst_len, std::string_view src);
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Convert a string to lower case.
|
26
|
+
* \param str Input string.
|
27
|
+
* \return Lower case string.
|
28
|
+
*/
|
29
|
+
[[nodiscard]] SGL_API std::string to_lower(std::string_view str);
|
30
|
+
|
31
|
+
/**
|
32
|
+
* Convert a string to upper case.
|
33
|
+
* \param str Input string.
|
34
|
+
* \return Upper case string.
|
35
|
+
*/
|
36
|
+
[[nodiscard]] SGL_API std::string to_upper(std::string_view str);
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Convert a string to wide string.
|
40
|
+
* \param str Input string.
|
41
|
+
* \return Wide string.
|
42
|
+
*/
|
43
|
+
[[nodiscard]] inline std::wstring to_wstring(std::string_view str)
|
44
|
+
{
|
45
|
+
return std::wstring(str.begin(), str.end());
|
46
|
+
}
|
47
|
+
|
48
|
+
// inline std::string to_string(std::wstring str)
|
49
|
+
// {
|
50
|
+
// return std::string(str.begin(), str.end());
|
51
|
+
// }
|
52
|
+
|
53
|
+
/**
|
54
|
+
* Check is a string has the specified prefix.
|
55
|
+
* \param str Input string.
|
56
|
+
* \param prefix Prefix to check for.
|
57
|
+
* \param case_sensitive Whether comparison should be case-sensitive.
|
58
|
+
* \return True if the input string has the specified prefix.
|
59
|
+
*/
|
60
|
+
[[nodiscard]] SGL_API bool has_prefix(std::string_view str, std::string_view prefix, bool case_sensitive = true);
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Check is a string has the specified suffix.
|
64
|
+
* \param str Input string.
|
65
|
+
* \param suffix Suffix to check for.
|
66
|
+
* \param case_sensitive Whether comparison should be case-sensitive.
|
67
|
+
* \return True if the input string has the specified suffix.
|
68
|
+
*/
|
69
|
+
[[nodiscard]] SGL_API bool has_suffix(std::string_view str, std::string_view suffix, bool case_sensitive = true);
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Split a string into a list of strings based on a list of delimiter characters.
|
73
|
+
* \param str Input string.
|
74
|
+
* \param delimiters Delimiter characters.
|
75
|
+
* \return List of split strings excluding the delimiter characters.
|
76
|
+
*/
|
77
|
+
[[nodiscard]] SGL_API std::vector<std::string> split(std::string_view str, std::string_view delimiters);
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Join an list of strings separated by a specified seperator.
|
81
|
+
* \param strings Input strings.
|
82
|
+
* \param separator String placed between each string to be joined.
|
83
|
+
* \return Joined string.
|
84
|
+
*/
|
85
|
+
[[nodiscard]] SGL_API std::string join(std::span<const std::string> strings, std::string_view separator);
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Replace every newline with the specified indentation.
|
89
|
+
* \param str Input string.
|
90
|
+
* \param indentation Indentation string.
|
91
|
+
* \return The indented string.
|
92
|
+
*/
|
93
|
+
[[nodiscard]] SGL_API std::string indent(std::string_view str, std::string_view indentation = " ");
|
94
|
+
|
95
|
+
template<typename T>
|
96
|
+
concept object_to_string = requires(typename std::remove_pointer<typename remove_ref<T>::type>::type t) {
|
97
|
+
{
|
98
|
+
t.to_string()
|
99
|
+
} -> std::convertible_to<std::string>;
|
100
|
+
};
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Convert a list of objects that have a to_string() method to a string.
|
104
|
+
* \tparam T Type of objects.
|
105
|
+
* \param list List of objects.
|
106
|
+
* \return The list of objects as a string.
|
107
|
+
*/
|
108
|
+
template<object_to_string T>
|
109
|
+
inline std::string list_to_string(std::span<T> list, std::string_view indentation = " ")
|
110
|
+
{
|
111
|
+
if (list.empty())
|
112
|
+
return "[]";
|
113
|
+
std::string result = "[\n";
|
114
|
+
for (const auto& item : list) {
|
115
|
+
result += indentation;
|
116
|
+
if constexpr (std::is_pointer_v<T> || is_ref_v<T>)
|
117
|
+
result += string::indent(item->to_string());
|
118
|
+
else
|
119
|
+
result += string::indent(item.to_string());
|
120
|
+
result += ",\n";
|
121
|
+
}
|
122
|
+
result += "]";
|
123
|
+
return result;
|
124
|
+
}
|
125
|
+
|
126
|
+
template<typename T>
|
127
|
+
concept free_standing_to_string = requires(T t) {
|
128
|
+
{
|
129
|
+
to_string(t)
|
130
|
+
} -> std::convertible_to<std::string>;
|
131
|
+
};
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Convert a list of objects that have a free-standing to_string() method to a string.
|
135
|
+
* \tparam T Type of objects.
|
136
|
+
* \param list List of objects.
|
137
|
+
* \return The list of objects as a string.
|
138
|
+
*/
|
139
|
+
template<free_standing_to_string T>
|
140
|
+
inline std::string list_to_string(std::span<T> list, std::string_view indentation = " ")
|
141
|
+
{
|
142
|
+
if (list.empty())
|
143
|
+
return "[]";
|
144
|
+
std::string result = "[\n";
|
145
|
+
for (const auto& item : list) {
|
146
|
+
result += indentation;
|
147
|
+
result += string::indent(to_string(item));
|
148
|
+
result += ",\n";
|
149
|
+
}
|
150
|
+
result += "]";
|
151
|
+
return result;
|
152
|
+
}
|
153
|
+
|
154
|
+
template<typename T>
|
155
|
+
inline std::string list_to_string(const std::vector<T>& list, std::string_view indentation = " ")
|
156
|
+
{
|
157
|
+
return list_to_string(std::span{list}, indentation);
|
158
|
+
}
|
159
|
+
|
160
|
+
template<typename T>
|
161
|
+
concept iterable_has_to_string = requires(typename T::iterator t) {
|
162
|
+
{
|
163
|
+
(*t)->to_string()
|
164
|
+
} -> std::convertible_to<std::string>;
|
165
|
+
};
|
166
|
+
|
167
|
+
template<iterable_has_to_string T>
|
168
|
+
inline std::string iterable_to_string(const T& iterable)
|
169
|
+
{
|
170
|
+
std::string result = "[\n";
|
171
|
+
for (const auto& item : iterable) {
|
172
|
+
result += " ";
|
173
|
+
result += string::indent(item->to_string());
|
174
|
+
result += ",\n";
|
175
|
+
}
|
176
|
+
result += "]";
|
177
|
+
return result;
|
178
|
+
}
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Remove leading whitespace.
|
182
|
+
* \param str Input string.
|
183
|
+
* \param whitespace Whitespace characters.
|
184
|
+
* \return String with leading whitespace removed.
|
185
|
+
*/
|
186
|
+
[[nodiscard]] SGL_API std::string
|
187
|
+
remove_leading_whitespace(std::string_view str, std::string_view whitespace = " \n\r\t");
|
188
|
+
|
189
|
+
/**
|
190
|
+
* Remove trailing whitespace.
|
191
|
+
* \param str Input string.
|
192
|
+
* \param whitespace Whitespace characters.
|
193
|
+
* \return String with trailing whitespace removed.
|
194
|
+
*/
|
195
|
+
[[nodiscard]] SGL_API std::string
|
196
|
+
remove_trailing_whitespace(std::string_view str, std::string_view whitespace = " \n\r\t");
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Remove leading and trailing whitespace.
|
200
|
+
* \param str Input string.
|
201
|
+
* \param whitespace Whitespace characters.
|
202
|
+
* \return String with leading and trailing whitespace removed.
|
203
|
+
*/
|
204
|
+
[[nodiscard]] SGL_API std::string
|
205
|
+
remove_leading_trailing_whitespace(std::string_view str, std::string_view whitespace = " \n\r\t");
|
206
|
+
|
207
|
+
/**
|
208
|
+
* Convert a size in bytes to a human readable string:
|
209
|
+
* - prints bytes (B) if size < 1000 bytes
|
210
|
+
* - prints kilobytes (KB) if size < 1000 kilobytes
|
211
|
+
* - prints megabytes (MB) if size < 1000 megabytes
|
212
|
+
* - prints gigabytes (GB) if size < 1000 gigabytes
|
213
|
+
* - otherwise prints terabytes (TB)
|
214
|
+
* \param size Size in bytes.
|
215
|
+
* \return Size as a human readable string.
|
216
|
+
*/
|
217
|
+
[[nodiscard]] SGL_API std::string format_byte_size(size_t size);
|
218
|
+
|
219
|
+
/**
|
220
|
+
* Convert a duration in seconds to a human readable string:
|
221
|
+
* - prints nanoseconds (ns) if duration < 1 microsecond
|
222
|
+
* - prints microseconds (us) if duration < 1 millisecond
|
223
|
+
* - prints milliseconds (ms) if duration < 1 second
|
224
|
+
* - prints seconds (s) if duration < 60 seconds
|
225
|
+
* - prints minutes (m) if duration < 60 minutes
|
226
|
+
* - prints hours (h) if duration < 24 hours
|
227
|
+
* - otherwise prints days (d)
|
228
|
+
* \param seconds Duration in seconds.
|
229
|
+
* \return Duration as a human readable string.
|
230
|
+
*/
|
231
|
+
[[nodiscard]] SGL_API std::string format_duration(double seconds);
|
232
|
+
|
233
|
+
/**
|
234
|
+
* Convert data to a hexadecimal string.
|
235
|
+
* \param data Input data.
|
236
|
+
* \param len Length of input data.
|
237
|
+
* \return Hexadecimal string.
|
238
|
+
*/
|
239
|
+
[[nodiscard]] SGL_API std::string hexlify(const void* data, size_t len);
|
240
|
+
|
241
|
+
/**
|
242
|
+
* Convert data to a hexadecimal string.
|
243
|
+
* \param data Input data.
|
244
|
+
* \return Hexadecimal string.
|
245
|
+
*/
|
246
|
+
[[nodiscard]] inline std::string hexlify(std::span<const uint8_t> data)
|
247
|
+
{
|
248
|
+
return hexlify(data.data(), data.size());
|
249
|
+
}
|
250
|
+
|
251
|
+
/**
|
252
|
+
* Encode data into base 64 encoding.
|
253
|
+
* \param data Input data.
|
254
|
+
* \param len Length of input data.
|
255
|
+
* \return Base 64 encoded string.
|
256
|
+
*/
|
257
|
+
[[nodiscard]] SGL_API std::string encode_base64(const void* data, size_t len);
|
258
|
+
|
259
|
+
/**
|
260
|
+
* Encode data into base 64 encoding.
|
261
|
+
* \param data Input data.
|
262
|
+
* \return Base 64 encoded string.
|
263
|
+
*/
|
264
|
+
[[nodiscard]] inline std::string encode_base64(std::span<const uint8_t> data)
|
265
|
+
{
|
266
|
+
return encode_base64(data.data(), data.size());
|
267
|
+
}
|
268
|
+
|
269
|
+
/**
|
270
|
+
* Decode data from base 64 encoding.
|
271
|
+
* \param str Base 64 encoded string.
|
272
|
+
* \return Decoded data.
|
273
|
+
*/
|
274
|
+
[[nodiscard]] SGL_API std::vector<uint8_t> decode_base64(std::string_view str);
|
275
|
+
|
276
|
+
} // namespace sgl::string
|