39 Commits

Author SHA1 Message Date
d5bf60447b Cleanup 2023-12-08 16:22:09 +01:00
2440e5baca Cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-07 18:41:55 +01:00
8fc9a7e56b stream: allow invalid handle detection in cached_file
Otherwise one cannot distinguish between file open but in failed state
and file not open.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-06 15:25:48 +01:00
9967b41eae stream: make memory_file properly copyable and movable
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-06 11:02:12 +01:00
976662415b stream: unify size method and make it const
diag_file::size() was setting the m_state and returning 0 on error,
which violated original size() convention not to change stream state and
to return fsize_max on error.

Changing m_state prevented declaring size() method as const before.

cache::seek() was missing size() return value check.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-12-01 14:11:02 +01:00
3dfd62ec2f socket: add own cross-platform declaration
Like with stdex::locale_t, this frees us from using Windowsizms on other
platforms. Sockets came from Unix to Windows and not the other way
around in the first place.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-09 09:25:42 +01:00
2c45749f78 string, locale: make stdex::locale(_t) independent .hpp file
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-09 08:12:31 +01:00
ee8f54ee5f Fix to compile for Linux
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-11-08 13:48:41 +01: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
a469860382 stream: revise cache init and cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
00b05092af stream: reuse converter R/W methods
Where we need to read from/write to m_source and immediately apply its
state to our converter, we already have methods for this.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
47e63b1f32 Use lambda as trampoline to simplify thread functions
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:08 +02:00
7cd4d099ff stream: cleanup
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
36012a107b stream: cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
b791621a2a stream: make std:thread member rather than derive from it
When deriving, C++ might believe the derived class is still movable. But
it's not and rather than deleting move constructor and operator, this
approach made simpler code.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
9365f0252c stream: add socket
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
e61720598f stream: revise string reading and writing
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:07 +02:00
86e7ed3690 stream: add support for collection reading and writing
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-10-10 16:43:06 +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
b724ce1333 stream: fix wchar_t/UTF-16 confusion and revise readln and write_array
On non-Windows, wchar_t is UTF-32.  This adds preliminary support for UTF-32
and changes readln and write_array members to use charset_encoder for better
performance on non-Windows platforms.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-22 13:04:41 +02:00
6689aa5210 stream: add file::exists and file::readonly
We are targeting C++14, while C++17 already has std::filesystem::exists. 😢

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-20 13:00:20 +02:00
dcfc4752b5 stream: add stdex::sstring method variants 2023-09-20 12:09:58 +02:00
475e6734a7 stream: extend open/create disposition flags
User could not create file only if it did not exist.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-20 11:13:16 +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
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
b8cb07f456 stream: cleanup
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-09-07 14:35:03 +02:00
670cbb8d36 Catch by reference
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-29 16:19:53 +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
2c2680dfb3 Resolve _WINSOCKAPI_ and WIN32_LEAN_AND_MEAN hell. Hopefully!
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-25 03:56:27 +02:00
be83f36082 stream: add write_array variants for zero-terminated strings
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-24 13:57:57 +02:00
73d03d81af stream: fix buffered_sys and cached_file destruction
We had to introduce out-of-order construction for those classes, but we
forgot to implement out-of-order destruction. File gets closed first
by cached_file::m_source destructor, then inherited destructor
cache::~cache() which flushes the cache is called.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-24 13:56:41 +02:00
1c622c3091 stream: fix ISequentialStream
MSVC 2019 didn't handle stdex::stream::ISequentialStream and
ISequentialStream disambiguation very well.

Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-22 17:05:49 +02:00
55d39b1566 stream: fix cache handling in open and close
Reusing same class instance for different files reused cache content
as well.

Reported-by: Peter Holozan <peter.holozan@amebis.si>
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-21 10:27:43 +02:00
42a38802d3 stream: fix Win32
Signed-off-by: Simon Rozman <simon@rozman.si>
2023-08-19 08:31:08 +02:00
8457226168 ios, stream: replace <iostream> with leaner and faster own streaming
Our test program runs 15 minutes using our streams vs. 25 minutes using
std::iostream derived streams.

Streams were ported from Amebis AOsn project.

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