28 Commits

Author SHA1 Message Date
7e4dd3e49d socket: add sys_object alike wrapper for sockets
Unlike Posix, Windows handles HANDLE (file, pipe) and SOCKET descriptors
differently. It uses different close(), different errno... So sys_object
was not usable for socket without templating operations to a traits
class.

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-04-22 08:43:00 +02:00
1f242823d0 system: make sys_object::duplicate public
It's useful to clone std handles when creating streams to write/read to
standard streams. As the stream we give handle to assumes the handle
ownership, it'd close the std handles in stream destructor.

Signed-off-by: Simon Rozman <simon@rozman.si>
2024-04-17 13:58:59 +02:00
08a18d1519 macOS support
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-02-08 12:09:33 +01:00
38c6b40b21 Bump Copyright year
Signed-off-by: Simon Rozman <simon@rozman.si>
2024-01-06 10:55:09 +01:00
f5bce32d06 Use std::string_view where possible
Unfortunately, MSVC cannot deduce template parameters properly where
`const std::basic_string_view<...>` is the parameter. It requires
explicit type cast or explicit template type specification. Which kind
of voids the whole purpose of using std::basic_string_view to make the
client code simpler.

Example: https://gist.github.com/rozmansi/493911be70bdac08dc6826c976c5bbe4
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-22 14:17:08 +01:00
2e65d0351c Trim excessive inline
Methods and templates are implicitly marked as inline already.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-11 11:33:27 +01:00
8fbbf58a1b system: update documentation
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-01 14:05:54 +01:00
ee8f54ee5f Fix to compile for Linux
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-08 13:48:41 +01:00
89a5c6e5e6 sys_info: move to a separate .hpp
The stdex::sys_info is instantiated for each compilation unit. To reduce
amount of copies, move it to a separate .hpp as system.hpp is almost
always #included.

Breaking-change: Add #include <stdex/sys_info.hpp>
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-19 10:16:53 +02:00
16a86cf350 Add #include wrapper to fix min/max <Windows.h> mess
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-18 12:51:49 +02:00
856be3a0d8 Revise #include to make each .hpp individually compilable
Mind that min/max Windows.h mess is Microsoft's problem, not ours.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-18 09:12:06 +02:00
8732b1df5b system: add admin and elevated bools to sys_info
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
ab8d37ee75 Turn assert() into _Analysis_assume_ on Release builds
While runtime asserts also served as MSVC Code Analysis hints, the lack
of asserts in Release builds provides no hints to Code Analysis which
rises a lot of warnings then.

Maybe I should learn how to use SAL to annotate <ptr, len> parameter
pairs to allow ptr==nullptr when and only when len==0? 😇

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
9ba4b21cef Un-static global data
Otherwise, compiler generates instances for each compilation unit.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
c16579984d system: add sys_info
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:42:04 +02:00
9f21015209 system: add sregex
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:42:03 +02:00
49b741c94f Replace errno_error with std::system_error
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-01 23:09:50 +02:00
c4e94150d1 hash: add
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-25 14:57:14 +02:00
b5984ea8f2 Port to macOS
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-19 18:02:18 +02:00
66f8a6c3b7 Re-add UTF-8 BOM XCode is removing
Visual Studio IDE really needs it on non-UTF-8 PCs.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-14 09:13:04 +02:00
f05bf56a61 Don't #define NOMINMAX when compiled with -DNOMINMAX
MSVC issues compile-time warning about redefining.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-13 14:27:14 +02:00
657eac0c69 system: add PATH_SEPARATOR
I am aware of the std::filesystem::path::preferred_separator, but we
are targeting C++14 and we need this as a precompiler macro to allow
concatenation of the path strings in precompile stage.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-13 11:29:20 +02:00
83d7fd844d Port to macOS
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-12 16:55:16 +02:00
b326f819ab Fix to compile using XCode
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-11 16:44:30 +02:00
b76db46076 system: simplify and streamline system char and string type names
"sys_char" sticks out of "wchar_t", "char32_t", "uint32_t"...
Likewise, "sys_string" out of "string", "wstring", "u16string",
"u32string"...

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-29 10:09:35 +02:00
4ca3ed0718 system: add missing include
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-22 17:06:17 +02:00
34449d124d system: add sys_string
"std::basic_string<sys_char>" is too cumbersome and error-prone for
daily use.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-21 10:20:44 +02:00
72ce0a03e5 system: add
Windows is very peculiar with #include <windows.h>. Besides we need some
OS primitive wrappers that are OS-specific.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-18 15:05:18 +02:00