diff --git a/octa/atomic.hh b/octa/atomic.hh index f62fa3b..e81051d 100644 --- a/octa/atomic.hh +++ b/octa/atomic.hh @@ -922,8 +922,8 @@ using AtomicChar = Atomic; using AtomicShort = Atomic; using AtomicInt = Atomic; using AtomicLong = Atomic; -using AtomicSchar = Atomic; -using AtomicUchar = Atomic; +using AtomicSbyte = Atomic; +using AtomicByte = Atomic; using AtomicUshort = Atomic; using AtomicUint = Atomic; using AtomicUlong = Atomic; diff --git a/octa/functional.hh b/octa/functional.hh index f0bfabc..7428607 100644 --- a/octa/functional.hh +++ b/octa/functional.hh @@ -203,8 +203,8 @@ OCTA_HASH_BASIC(short) OCTA_HASH_BASIC(int) OCTA_HASH_BASIC(long) -OCTA_HASH_BASIC(octa::schar) -OCTA_HASH_BASIC(octa::uchar) +OCTA_HASH_BASIC(octa::sbyte) +OCTA_HASH_BASIC(octa::byte) OCTA_HASH_BASIC(octa::ushort) OCTA_HASH_BASIC(octa::uint) OCTA_HASH_BASIC(octa::ulong) @@ -217,7 +217,7 @@ OCTA_HASH_BASIC(octa::Wchar) namespace detail { static inline Size mem_hash(const void *p, octa::Size l) { - const octa::uchar *d = (const octa::uchar *)p; + const octa::byte *d = (const octa::byte *)p; octa::Size h = 5381; for (Size i = 0; i < l; ++i) h = ((h << 5) + h) ^ d[i]; return h; diff --git a/octa/io.hh b/octa/io.hh index 0ab61a1..94dee77 100644 --- a/octa/io.hh +++ b/octa/io.hh @@ -84,14 +84,11 @@ struct FileStream: Stream { bool flush() { return !fflush(p_f); } - using Stream::read; - using Stream::write; - - octa::Size read(void *buf, octa::Size count) { + octa::Size read_bytes(void *buf, octa::Size count) { return fread(buf, 1, count, p_f); } - octa::Size write(const void *buf, octa::Size count) { + octa::Size write_bytes(const void *buf, octa::Size count) { return fwrite(buf, 1, count, p_f); } @@ -144,8 +141,7 @@ static inline void writeln(const octa::String &s) { template static inline void writeln(const T &v) { - octa::write(v); - putc('\n', ::stdout); + octa::writeln(octa::to_string(v)); } template diff --git a/octa/memory.hh b/octa/memory.hh index 1f5c4ba..b6a66df 100644 --- a/octa/memory.hh +++ b/octa/memory.hh @@ -554,10 +554,10 @@ template struct Allocator { Size max_size() const { return Size(~0) / sizeof(T); } Pointer allocate(Size n, Allocator::ConstPointer = nullptr) { - return (Pointer) ::new octa::uchar[n * sizeof(T)]; + return (Pointer) ::new octa::byte[n * sizeof(T)]; } - void deallocate(Pointer p, Size) { ::delete[] (octa::uchar *) p; } + void deallocate(Pointer p, Size) { ::delete[] (octa::byte *) p; } template void construct(U *p, A &&...args) { @@ -588,10 +588,10 @@ template struct Allocator { Size max_size() const { return Size(~0) / sizeof(T); } Pointer allocate(Size n, Allocator::ConstPointer = nullptr) { - return (Pointer) ::new octa::uchar[n * sizeof(T)]; + return (Pointer) ::new octa::byte[n * sizeof(T)]; } - void deallocate(Pointer p, Size) { ::delete[] (octa::uchar *) p; } + void deallocate(Pointer p, Size) { ::delete[] (octa::byte *) p; } template void construct(U *p, A &&...args) { diff --git a/octa/stream.hh b/octa/stream.hh index 5601197..3d9ede5 100644 --- a/octa/stream.hh +++ b/octa/stream.hh @@ -52,26 +52,35 @@ struct Stream { virtual bool flush() { return true; } - virtual octa::Size read(void *, octa::Size) { return 0; } - virtual octa::Size write(const void *, octa::Size) { return 0; } + virtual octa::Size read_bytes(void *, octa::Size) { return 0; } + virtual octa::Size write_bytes(const void *, octa::Size) { return 0; } - virtual int read() { - octa::uchar c; - return (read(&c, 1) == 1) ? c : -1; + virtual int getchar() { + octa::byte c; + return (read_bytes(&c, 1) == 1) ? c : -1; } - virtual bool write(int c) { - octa::uchar wc = octa::uchar(c); - return write(&wc, 1) == 1; + virtual bool putchar(int c) { + octa::byte wc = octa::byte(c); + return write_bytes(&wc, 1) == 1; } virtual bool write(const char *s) { octa::Size len = strlen(s); - return write(s, len) == len; + return write_bytes(s, len) == len; } virtual bool write(const octa::String &s) { - return write(s.data(), s.size()) == s.size(); + return write_bytes(s.data(), s.size()) == s.size(); + } + + template bool write(const T &v) { + return write(octa::to_string(v)); + } + + template + bool write(const T &v, const A &...args) { + return write(v) && write(args...); } virtual bool writeln(const octa::String &s) { @@ -82,23 +91,32 @@ struct Stream { return write(s) && write('\n'); } + template bool writeln(const T &v) { + return writeln(octa::to_string(v)); + } + + template + bool writeln(const T &v, const A &...args) { + return write(v) && write(args...) && write('\n'); + } + template StreamRange iter(); template octa::Size put(const T *v, octa::Size count) { - return write(v, count * sizeof(T)) / sizeof(T); + return write_bytes(v, count * sizeof(T)) / sizeof(T); } template bool put(T v) { - return write(&v, sizeof(T)) == sizeof(T); + return write_bytes(&v, sizeof(T)) == sizeof(T); } template octa::Size get(T *v, octa::Size count) { - return read(v, count * sizeof(T)) / sizeof(T); + return read_bytes(v, count * sizeof(T)) / sizeof(T); } template bool get(T &v) { - return read(&v, sizeof(T)) == sizeof(T); + return read_bytes(&v, sizeof(T)) == sizeof(T); } template T get() { @@ -122,12 +140,12 @@ struct StreamRange: InputRange< bool pop_front() { if (empty()) return false; T val; - return !!p_stream->read(&val, sizeof(T)); + return !!p_stream->read_bytes(&val, sizeof(T)); } T front() const { T val; - p_stream->seek(-p_stream->read(&val, sizeof(T)), StreamSeek::cur); + p_stream->seek(-p_stream->read_bytes(&val, sizeof(T)), StreamSeek::cur); return val; } @@ -136,7 +154,7 @@ struct StreamRange: InputRange< } void put(T val) { - p_size += p_stream->write(&val, sizeof(T)); + p_size += p_stream->write_bytes(&val, sizeof(T)); } private: diff --git a/octa/string.hh b/octa/string.hh index cca8968..8a8dd34 100644 --- a/octa/string.hh +++ b/octa/string.hh @@ -486,12 +486,14 @@ template<> struct ToString { \ } \ }; +OCTA_TOSTR_NUM(octa::sbyte, "%d") OCTA_TOSTR_NUM(int, "%d") OCTA_TOSTR_NUM(int &, "%d") OCTA_TOSTR_NUM(long, "%ld") OCTA_TOSTR_NUM(float, "%f") OCTA_TOSTR_NUM(double, "%f") +OCTA_TOSTR_NUM(octa::byte, "%u") OCTA_TOSTR_NUM(octa::uint, "%u") OCTA_TOSTR_NUM(octa::ulong, "%lu") OCTA_TOSTR_NUM(octa::llong, "%lld") diff --git a/octa/type_traits.hh b/octa/type_traits.hh index 9ae17c5..4180803 100644 --- a/octa/type_traits.hh +++ b/octa/type_traits.hh @@ -98,8 +98,8 @@ namespace detail { template<> struct IsIntegralBase: True {}; template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; - template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; + template<> struct IsIntegralBase: True {}; template<> struct IsIntegralBase: True {}; template<> struct IsIntegralBase: True {}; template<> struct IsIntegralBase: True {}; @@ -868,13 +868,13 @@ namespace detail { ~TlNat() = delete; }; - using Stypes = TypeList>>>>; - using Utypes = TypeList struct MakeSigned { using Type = int; }; template<> struct MakeSigned { using Type = long; }; - template<> struct MakeSigned { using Type = octa::schar; }; - template<> struct MakeSigned { using Type = octa::schar; }; + template<> struct MakeSigned { using Type = octa::sbyte; }; + template<> struct MakeSigned { using Type = octa::sbyte; }; template<> struct MakeSigned { using Type = short; }; template<> struct MakeSigned { using Type = int; }; template<> struct MakeSigned { using Type = long; }; @@ -966,8 +966,8 @@ namespace detail { template<> struct MakeUnsigned { using Type = octa::uint; }; template<> struct MakeUnsigned { using Type = octa::ulong; }; - template<> struct MakeUnsigned { using Type = octa::uchar; }; - template<> struct MakeUnsigned { using Type = octa::uchar; }; + template<> struct MakeUnsigned { using Type = octa::byte; }; + template<> struct MakeUnsigned { using Type = octa::byte; }; template<> struct MakeUnsigned { using Type = octa::ushort; }; template<> struct MakeUnsigned { using Type = octa::uint; }; template<> struct MakeUnsigned { using Type = octa::ulong; }; @@ -1117,14 +1117,14 @@ using CommonType = typename octa::detail::CommonTypeBase::Type; namespace detail { template struct AlignedTest { union Type { - octa::uchar data[N]; + octa::byte data[N]; octa::MaxAlign align; }; }; template struct AlignedStorageBase { struct Type { - alignas(A) octa::uchar data[N]; + alignas(A) octa::byte data[N]; }; }; } @@ -1157,7 +1157,7 @@ namespace detail { = AlignMax::value; struct type { - alignas(alignment_value) octa::uchar data[AlignMax::value]; }; }; diff --git a/octa/types.hh b/octa/types.hh index 9ae90c4..cfce8a9 100644 --- a/octa/types.hh +++ b/octa/types.hh @@ -13,8 +13,8 @@ namespace octa { /* "builtin" types */ -using schar = signed char; -using uchar = unsigned char; +using sbyte = signed char; +using byte = unsigned char; using ushort = unsigned short; using uint = unsigned int; using ulong = unsigned long;