diff --git a/Src/IACore/imp/cpp/AsyncOps.cpp b/Src/IACore/imp/cpp/AsyncOps.cpp index 8f73ad1..04ebea7 100644 --- a/Src/IACore/imp/cpp/AsyncOps.cpp +++ b/Src/IACore/imp/cpp/AsyncOps.cpp @@ -28,7 +28,7 @@ auto AsyncOps::run_task(Mut> task) -> void { auto AsyncOps::initialize_scheduler(Mut worker_count) -> Result { if (worker_count == 0) { - Const hw_concurrency = std::thread::hardware_concurrency(); + const u32 hw_concurrency = std::thread::hardware_concurrency(); Mut threads = 2; if (hw_concurrency > 2) { threads = hw_concurrency - 2; @@ -65,14 +65,14 @@ auto AsyncOps::terminate_scheduler() -> void { } auto AsyncOps::schedule_task(Mut> task, - Const tag, Const schedule, - Const priority) -> void { + const TaskTag tag, Schedule *schedule, + const Priority priority) -> void { ensure(!s_schedule_workers.empty(), "Scheduler must be initialized before calling schedule_task"); schedule->counter.fetch_add(1); { - Const> lock(s_queue_mutex); + const std::lock_guard lock(s_queue_mutex); if (priority == Priority::High) { s_high_priority_queue.emplace_back( ScheduledTask{tag, schedule, std::move(task)}); @@ -84,8 +84,8 @@ auto AsyncOps::schedule_task(Mut> task, s_wake_condition.notify_one(); } -auto AsyncOps::cancel_tasks_of_tag(Const tag) -> void { - Const> lock(s_queue_mutex); +auto AsyncOps::cancel_tasks_of_tag(const TaskTag tag) -> void { + const std::lock_guard lock(s_queue_mutex); { MutRef> queue = s_high_priority_queue; @@ -120,8 +120,7 @@ auto AsyncOps::cancel_tasks_of_tag(Const tag) -> void { } } -auto AsyncOps::wait_for_schedule_completion(Const schedule) - -> void { +auto AsyncOps::wait_for_schedule_completion(Schedule *schedule) -> void { ensure(!s_schedule_workers.empty(), "Scheduler must be initialized before " "calling wait_for_schedule_completion"); @@ -147,7 +146,7 @@ auto AsyncOps::wait_for_schedule_completion(Const schedule) task.schedule_handle->counter.notify_all(); } } else { - Const current_val = schedule->counter.load(); + const u32 current_val = schedule->counter.load(); if (current_val > 0) { schedule->counter.wait(current_val); } @@ -159,8 +158,8 @@ auto AsyncOps::get_worker_count() -> WorkerId { return static_cast(s_schedule_workers.size()); } -auto AsyncOps::schedule_worker_loop(Const stop_token, - Const worker_id) -> void { +auto AsyncOps::schedule_worker_loop(const std::stop_token stop_token, + const WorkerId worker_id) -> void { while (!stop_token.stop_requested()) { Mut task; Mut found_task = false; diff --git a/Src/IACore/imp/cpp/CLI.cpp b/Src/IACore/imp/cpp/CLI.cpp index 4616c3b..37f3a32 100644 --- a/Src/IACore/imp/cpp/CLI.cpp +++ b/Src/IACore/imp/cpp/CLI.cpp @@ -16,7 +16,7 @@ #include namespace IACore { -CLIParser::CLIParser(Const>> args) : m_arg_list(args) { +CLIParser::CLIParser(const Span args) : m_arg_list(args) { m_current_arg = m_arg_list.begin(); // Skip executable path diff --git a/Src/IACore/imp/cpp/DataOps.cpp b/Src/IACore/imp/cpp/DataOps.cpp index 9810196..eab4d1c 100644 --- a/Src/IACore/imp/cpp/DataOps.cpp +++ b/Src/IACore/imp/cpp/DataOps.cpp @@ -31,7 +31,7 @@ namespace IACore { template -[[nodiscard]] inline auto read_unaligned(Const *> ptr) -> T { +[[nodiscard]] inline auto read_unaligned(const u8 *ptr) -> T { Mut v; std::memcpy(&v, ptr, sizeof(T)); return v; @@ -41,7 +41,7 @@ struct Crc32Tables { Mut table[8][256] = {}; consteval Crc32Tables() { - constexpr Const T = 0x82F63B78; + constexpr const u32 T = 0x82F63B78; for (Mut i = 0; i < 256; i++) { Mut crc = i; @@ -53,24 +53,24 @@ struct Crc32Tables { for (Mut i = 0; i < 256; i++) { for (Mut slice = 1; slice < 8; slice++) { - Const prev = table[slice - 1][i]; + const u32 prev = table[slice - 1][i]; table[slice][i] = (prev >> 8) ^ table[0][prev & 0xFF]; } } } }; -static constexpr Const CRC32_TABLES{}; +static constexpr const Crc32Tables CRC32_TABLES{}; #if IA_ARCH_X64 -inline auto crc32_x64_hw(Ref>> data) -> u32 { +inline auto crc32_x64_hw(Ref> data) -> u32 { Mut p = data.data(); Mut crc = 0xFFFFFFFF; Mut len = data.size(); while (len >= 8) { - Const chunk = read_unaligned(p); + const u64 chunk = read_unaligned(p); crc = static_cast(_mm_crc32_u64(static_cast(crc), chunk)); p += 8; len -= 8; @@ -86,14 +86,14 @@ inline auto crc32_x64_hw(Ref>> data) -> u32 { #if IA_ARCH_ARM64 __attribute__((target("+crc"))) inline auto -crc32_arm64_hw(Ref>> data) -> u32 { +crc32_arm64_hw(Ref> data) -> u32 { Mut p = data.data(); Mut crc = 0xFFFFFFFF; Mut len = data.size(); while (len >= 8) { - Const chunk = read_unaligned(p); + const u64 chunk = read_unaligned(p); crc = __crc32cd(crc, chunk); p += 8; len -= 8; @@ -107,14 +107,14 @@ crc32_arm64_hw(Ref>> data) -> u32 { } #endif -inline auto crc32_software_slice8(Ref>> data) -> u32 { +inline auto crc32_software_slice8(Ref> data) -> u32 { Mut p = data.data(); Mut crc = 0xFFFFFFFF; Mut len = data.size(); while (len >= 8) { - Const term1 = crc ^ read_unaligned(p); - Const term2 = read_unaligned(p + 4); + const u32 term1 = crc ^ read_unaligned(p); + const u32 term2 = read_unaligned(p + 4); crc = CRC32_TABLES.table[7][term1 & 0xFF] ^ CRC32_TABLES.table[6][(term1 >> 8) & 0xFF] ^ @@ -136,7 +136,7 @@ inline auto crc32_software_slice8(Ref>> data) -> u32 { return ~crc; } -auto DataOps::crc32(Ref>> data) -> u32 { +auto DataOps::crc32(Ref> data) -> u32 { #if IA_ARCH_X64 // IACore mandates AVX2 so no need to check return crc32_x64_hw(data); @@ -148,33 +148,32 @@ auto DataOps::crc32(Ref>> data) -> u32 { return crc32_software_slice8(data); } -constexpr Const XXH_PRIME32_1 = 0x9E3779B1U; -constexpr Const XXH_PRIME32_2 = 0x85EBCA77U; -constexpr Const XXH_PRIME32_3 = 0xC2B2AE3DU; -constexpr Const XXH_PRIME32_4 = 0x27D4EB2FU; -constexpr Const XXH_PRIME32_5 = 0x165667B1U; +constexpr const u32 XXH_PRIME32_1 = 0x9E3779B1U; +constexpr const u32 XXH_PRIME32_2 = 0x85EBCA77U; +constexpr const u32 XXH_PRIME32_3 = 0xC2B2AE3DU; +constexpr const u32 XXH_PRIME32_4 = 0x27D4EB2FU; +constexpr const u32 XXH_PRIME32_5 = 0x165667B1U; -inline auto xxh32_round(Mut seed, Const input) -> u32 { +inline auto xxh32_round(Mut seed, const u32 input) -> u32 { seed += input * XXH_PRIME32_2; seed = std::rotl(seed, 13); seed *= XXH_PRIME32_1; return seed; } -auto DataOps::hash_xxhash(Ref string, Const seed) -> u32 { - return hash_xxhash( - Span>(reinterpret_cast(string.data()), - string.length()), - seed); +auto DataOps::hash_xxhash(Ref string, const u32 seed) -> u32 { + return hash_xxhash(Span(reinterpret_cast(string.data()), + string.length()), + seed); } -auto DataOps::hash_xxhash(Ref>> data, Const seed) -> u32 { +auto DataOps::hash_xxhash(Ref> data, const u32 seed) -> u32 { Mut p = data.data(); - Const b_end = p + data.size(); + const u8 *b_end = p + data.size(); Mut h32{}; if (data.size() >= 16) { - Const limit = b_end - 16; + const u8 *limit = b_end - 16; Mut v1 = seed + XXH_PRIME32_1 + XXH_PRIME32_2; Mut v2 = seed + XXH_PRIME32_2; @@ -201,7 +200,7 @@ auto DataOps::hash_xxhash(Ref>> data, Const seed) -> u32 { h32 += static_cast(data.size()); while (p + 4 <= b_end) { - Const t = read_unaligned(p) * XXH_PRIME32_3; + const u32 t = read_unaligned(p) * XXH_PRIME32_3; h32 += t; h32 = std::rotl(h32, 17) * XXH_PRIME32_4; p += 4; @@ -221,21 +220,21 @@ auto DataOps::hash_xxhash(Ref>> data, Const seed) -> u32 { return h32; } -constexpr Const FNV1A_32_PRIME = 0x01000193; -constexpr Const FNV1A_32_OFFSET = 0x811c9dc5; +constexpr const u32 FNV1A_32_PRIME = 0x01000193; +constexpr const u32 FNV1A_32_OFFSET = 0x811c9dc5; auto DataOps::hash_fnv1a(Ref string) -> u32 { Mut hash = FNV1A_32_OFFSET; - for (Const c : string) { + for (const char c : string) { hash ^= static_cast(c); hash *= FNV1A_32_PRIME; } return hash; } -auto DataOps::hash_fnv1a(Ref>> data) -> u32 { +auto DataOps::hash_fnv1a(Ref> data) -> u32 { Mut hash = FNV1A_32_OFFSET; - Const ptr = data.data(); + const u8 *ptr = data.data(); for (Mut i = 0; i < data.size(); ++i) { hash ^= ptr[i]; @@ -244,8 +243,7 @@ auto DataOps::hash_fnv1a(Ref>> data) -> u32 { return hash; } -auto DataOps::detect_compression(Const>> data) - -> CompressionType { +auto DataOps::detect_compression(const Span data) -> CompressionType { if (data.size() < 2) { return CompressionType::None; } @@ -262,7 +260,7 @@ auto DataOps::detect_compression(Const>> data) return CompressionType::None; } -auto DataOps::zlib_inflate(Ref>> data) -> Result> { +auto DataOps::zlib_inflate(Ref> data) -> Result> { Mut zs{}; zs.zalloc = Z_NULL; zs.zfree = Z_NULL; @@ -276,7 +274,7 @@ auto DataOps::zlib_inflate(Ref>> data) -> Result> { zs.avail_in = static_cast(data.size()); Mut> out_buffer; - Const guess_size = + const usize guess_size = data.size() < 1024 ? data.size() * 4 : data.size() * 2; out_buffer.resize(guess_size); @@ -286,8 +284,8 @@ auto DataOps::zlib_inflate(Ref>> data) -> Result> { Mut ret; do { if (zs.avail_out == 0) { - Const current_pos = zs.total_out; - Const new_size = out_buffer.size() * 2; + const usize current_pos = zs.total_out; + const usize new_size = out_buffer.size() * 2; out_buffer.resize(new_size); zs.next_out = reinterpret_cast(out_buffer.data() + current_pos); @@ -309,7 +307,7 @@ auto DataOps::zlib_inflate(Ref>> data) -> Result> { return out_buffer; } -auto DataOps::zlib_deflate(Ref>> data) -> Result> { +auto DataOps::zlib_deflate(Ref> data) -> Result> { Mut zs{}; zs.zalloc = Z_NULL; zs.zfree = Z_NULL; @@ -328,7 +326,7 @@ auto DataOps::zlib_deflate(Ref>> data) -> Result> { zs.next_out = reinterpret_cast(out_buffer.data()); zs.avail_out = static_cast(out_buffer.size()); - Const ret = deflate(&zs, Z_FINISH); + const int ret = deflate(&zs, Z_FINISH); if (ret != Z_STREAM_END) { deflateEnd(&zs); @@ -341,8 +339,8 @@ auto DataOps::zlib_deflate(Ref>> data) -> Result> { return out_buffer; } -auto DataOps::zstd_inflate(Ref>> data) -> Result> { - Const content_size = +auto DataOps::zstd_inflate(Ref> data) -> Result> { + const unsigned long long content_size = ZSTD_getFrameContentSize(data.data(), data.size()); if (content_size == ZSTD_CONTENTSIZE_ERROR) { @@ -353,8 +351,8 @@ auto DataOps::zstd_inflate(Ref>> data) -> Result> { Mut> out_buffer; out_buffer.resize(static_cast(content_size)); - Const d_size = ZSTD_decompress(out_buffer.data(), out_buffer.size(), - data.data(), data.size()); + const usize d_size = ZSTD_decompress(out_buffer.data(), out_buffer.size(), + data.data(), data.size()); if (ZSTD_isError(d_size)) { return fail("Failed to inflate: {}", ZSTD_getErrorName(d_size)); @@ -380,7 +378,7 @@ auto DataOps::zstd_inflate(Ref>> data) -> Result> { } if (output.pos == output.size) { - Const new_size = out_buffer.size() * 2; + const usize new_size = out_buffer.size() * 2; out_buffer.resize(new_size); output.dst = out_buffer.data(); output.size = new_size; @@ -394,14 +392,14 @@ auto DataOps::zstd_inflate(Ref>> data) -> Result> { return out_buffer; } -auto DataOps::zstd_deflate(Ref>> data) -> Result> { - Const max_dst_size = ZSTD_compressBound(data.size()); +auto DataOps::zstd_deflate(Ref> data) -> Result> { + const usize max_dst_size = ZSTD_compressBound(data.size()); Mut> out_buffer; out_buffer.resize(max_dst_size); - Const compressed_size = ZSTD_compress(out_buffer.data(), max_dst_size, - data.data(), data.size(), 3); + const usize compressed_size = ZSTD_compress(out_buffer.data(), max_dst_size, + data.data(), data.size(), 3); if (ZSTD_isError(compressed_size)) { return fail("Failed to deflate: {}", ZSTD_getErrorName(compressed_size)); @@ -411,7 +409,7 @@ auto DataOps::zstd_deflate(Ref>> data) -> Result> { return out_buffer; } -auto DataOps::gzip_deflate(Ref>> data) -> Result> { +auto DataOps::gzip_deflate(Ref> data) -> Result> { Mut zs{}; zs.zalloc = Z_NULL; zs.zfree = Z_NULL; @@ -432,7 +430,7 @@ auto DataOps::gzip_deflate(Ref>> data) -> Result> { zs.next_out = reinterpret_cast(out_buffer.data()); zs.avail_out = static_cast(out_buffer.size()); - Const ret = deflate(&zs, Z_FINISH); + const int ret = deflate(&zs, Z_FINISH); if (ret != Z_STREAM_END) { deflateEnd(&zs); @@ -445,7 +443,7 @@ auto DataOps::gzip_deflate(Ref>> data) -> Result> { return out_buffer; } -auto DataOps::gzip_inflate(Ref>> data) -> Result> { +auto DataOps::gzip_inflate(Ref> data) -> Result> { return zlib_inflate(data); } diff --git a/Src/IACore/imp/cpp/FileOps.cpp b/Src/IACore/imp/cpp/FileOps.cpp index 2f587ef..19e2ffb 100644 --- a/Src/IACore/imp/cpp/FileOps.cpp +++ b/Src/IACore/imp/cpp/FileOps.cpp @@ -29,36 +29,36 @@ namespace IACore { Mut>> FileOps::s_mapped_files; -auto FileOps::unmap_file(Const *> mapped_ptr) -> void { +auto FileOps::unmap_file(const u8 *mapped_ptr) -> void { if (!s_mapped_files.contains(mapped_ptr)) { return; } Mut it = s_mapped_files.find(mapped_ptr); - Const> handles = it->second; + const std::tuple handles = it->second; s_mapped_files.erase(it); #if IA_PLATFORM_WINDOWS ::UnmapViewOfFile(std::get<1>(handles)); ::CloseHandle(static_cast(std::get<2>(handles))); - Const handle = static_cast(std::get<0>(handles)); + const HANDLE handle = static_cast(std::get<0>(handles)); if (handle != INVALID_HANDLE_VALUE) { ::CloseHandle(handle); } #elif IA_PLATFORM_UNIX ::munmap(std::get<1>(handles), (usize)std::get<2>(handles)); - Const fd = (i32)((u64)std::get<0>(handles)); + const i32 fd = (i32)((u64)std::get<0>(handles)); if (fd != -1) { ::close(fd); } #endif } -auto FileOps::map_shared_memory(Ref name, Const size, - Const is_owner) -> Result { +auto FileOps::map_shared_memory(Ref name, const usize size, + const bool is_owner) -> Result { #if IA_PLATFORM_WINDOWS - Const wchars_num = + const int wchars_num = MultiByteToWideChar(CP_UTF8, 0, name.c_str(), -1, NULL, 0); Mut w_name(wchars_num, 0); MultiByteToWideChar(CP_UTF8, 0, name.c_str(), -1, &w_name[0], wchars_num); @@ -135,7 +135,7 @@ auto FileOps::unlink_shared_memory(Ref name) -> void { auto FileOps::map_file(Ref path, MutRef size) -> Result { #if IA_PLATFORM_WINDOWS - Const handle = CreateFileA( + const HANDLE handle = CreateFileA( path.string().c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); @@ -161,7 +161,7 @@ auto FileOps::map_file(Ref path, MutRef size) return fail("Failed to memory map {}", path.string()); } - Const *result = + const u8 *result = static_cast(MapViewOfFile(h_map, FILE_MAP_READ, 0, 0, 0)); if (result == NULL) { CloseHandle(handle); @@ -173,7 +173,7 @@ auto FileOps::map_file(Ref path, MutRef size) return result; #elif IA_PLATFORM_UNIX - Const handle = open(path.string().c_str(), O_RDONLY); + const int handle = open(path.string().c_str(), O_RDONLY); if (handle == -1) { return fail("Failed to open {} for memory mapping", path.string()); } @@ -192,7 +192,7 @@ auto FileOps::map_file(Ref path, MutRef size) close(handle); return fail("Failed to memory map {}", path.string()); } - Const *> result = static_cast(addr); + const u8 *result = static_cast(addr); madvise(addr, size, MADV_SEQUENTIAL); s_mapped_files[result] = std::make_tuple((void *)((u64)handle), (void *)addr, (void *)size); @@ -200,7 +200,7 @@ auto FileOps::map_file(Ref path, MutRef size) #endif } -auto FileOps::stream_to_file(Ref path, Const overwrite) +auto FileOps::stream_to_file(Ref path, const bool overwrite) -> Result { if (!overwrite && std::filesystem::exists(path)) { return fail("File already exists: {}", path.string()); @@ -222,7 +222,7 @@ auto FileOps::read_text_file(Ref path) -> Result { } Mut result; fseek(f, 0, SEEK_END); - Const len = ftell(f); + const long len = ftell(f); if (len > 0) { result.resize(static_cast(len)); fseek(f, 0, SEEK_SET); @@ -239,7 +239,7 @@ auto FileOps::read_binary_file(Ref path) -> Result> { } Mut> result; fseek(f, 0, SEEK_END); - Const len = ftell(f); + const long len = ftell(f); if (len > 0) { result.resize(static_cast(len)); fseek(f, 0, SEEK_SET); @@ -250,8 +250,8 @@ auto FileOps::read_binary_file(Ref path) -> Result> { } auto FileOps::write_text_file(Ref path, Ref contents, - Const overwrite) -> Result { - Const *> mode = overwrite ? "w" : "wx"; + const bool overwrite) -> Result { + const char *mode = overwrite ? "w" : "wx"; Mut f = fopen(path.string().c_str(), mode); if (!f) { if (!overwrite && errno == EEXIST) { @@ -259,14 +259,14 @@ auto FileOps::write_text_file(Ref path, Ref contents, } return fail("Failed to write to file: {}", path.string()); } - Const result = fwrite(contents.data(), 1, contents.size(), f); + const usize result = fwrite(contents.data(), 1, contents.size(), f); fclose(f); return result; } -auto FileOps::write_binary_file(Ref path, Const>> contents, - Const overwrite) -> Result { - Const *> mode = overwrite ? "w" : "wx"; +auto FileOps::write_binary_file(Ref path, const Span contents, + const bool overwrite) -> Result { + const char *mode = overwrite ? "w" : "wx"; Mut f = fopen(path.string().c_str(), mode); if (!f) { if (!overwrite && errno == EEXIST) { @@ -274,7 +274,7 @@ auto FileOps::write_binary_file(Ref path, Const>> contents, } return fail("Failed to write to file: {}", path.string()); } - Const result = fwrite(contents.data(), 1, contents.size(), f); + const usize result = fwrite(contents.data(), 1, contents.size(), f); fclose(f); return result; } @@ -301,8 +301,8 @@ auto FileOps::normalize_executable_path(Ref path) -> Path { return result; } -auto FileOps::native_open_file(Ref path, Const access, - Const mode, Const permissions) +auto FileOps::native_open_file(Ref path, const FileAccess access, + const FileMode mode, const u32 permissions) -> Result { #if IA_PLATFORM_WINDOWS Mut dw_access = 0; @@ -392,7 +392,7 @@ auto FileOps::native_open_file(Ref path, Const access, #endif } -auto FileOps::native_close_file(Const handle) -> void { +auto FileOps::native_close_file(const NativeFileHandle handle) -> void { if (handle == INVALID_FILE_HANDLE) { return; } @@ -428,8 +428,8 @@ auto FileOps::MemoryMappedRegion::operator=( return *this; } -auto FileOps::MemoryMappedRegion::map(Const handle, - Const offset, Const size) +auto FileOps::MemoryMappedRegion::map(const NativeFileHandle handle, + const u64 offset, const usize size) -> Result { unmap(); @@ -447,7 +447,7 @@ auto FileOps::MemoryMappedRegion::map(Const handle, return fail("Failed to get file size"); } - Const end_offset = offset + size; + const u64 end_offset = offset + size; if (static_cast(file_size.QuadPart) < end_offset) { Mut new_size; new_size.QuadPart = static_cast(end_offset); @@ -465,8 +465,8 @@ auto FileOps::MemoryMappedRegion::map(Const handle, return fail("CreateFileMapping failed: {}", GetLastError()); } - Const offset_high = static_cast(offset >> 32); - Const offset_low = static_cast(offset & 0xFFFFFFFF); + const DWORD offset_high = static_cast(offset >> 32); + const DWORD offset_low = static_cast(offset & 0xFFFFFFFF); m_ptr = static_cast(MapViewOfFile(m_map_handle, FILE_MAP_WRITE, offset_high, offset_low, size)); @@ -484,7 +484,7 @@ auto FileOps::MemoryMappedRegion::map(Const handle, return fail("Failed to fstat file"); } - Const end_offset = offset + size; + const u64 end_offset = offset + size; if (static_cast(sb.st_size) < end_offset) { if (ftruncate(handle, static_cast(end_offset)) == -1) { return fail("Failed to ftruncate (extend) file"); diff --git a/Src/IACore/imp/cpp/Http/Client.cpp b/Src/IACore/imp/cpp/Http/Client.cpp index 32e802a..2c228cc 100644 --- a/Src/IACore/imp/cpp/Http/Client.cpp +++ b/Src/IACore/imp/cpp/Http/Client.cpp @@ -21,8 +21,8 @@ auto HttpClient::create(Ref host) -> Result> { return make_box_protected(httplib::Client(host)); } -static auto build_headers(Span> headers, - Const *> default_content_type) +static auto build_headers(Span headers, + const char *default_content_type) -> httplib::Headers { Mut out; Mut has_content_type = false; @@ -59,26 +59,26 @@ auto HttpClient::disable_certificate_verification() -> void { } auto HttpClient::preprocess_response(Ref response) -> String { - Const>> response_bytes = { - reinterpret_cast *>(response.data()), response.size()}; - Const compression = + const Span response_bytes = { + reinterpret_cast(response.data()), response.size()}; + const DataOps::CompressionType compression = DataOps::detect_compression(response_bytes); switch (compression) { case DataOps::CompressionType::Gzip: { - Const>> data = DataOps::gzip_inflate(response_bytes); + const Result> data = DataOps::gzip_inflate(response_bytes); if (!data) { return response; } - return String(reinterpret_cast *>(data->data()), data->size()); + return String(reinterpret_cast(data->data()), data->size()); } case DataOps::CompressionType::Zlib: { - Const>> data = DataOps::zlib_inflate(response_bytes); + const Result> data = DataOps::zlib_inflate(response_bytes); if (!data) { return response; } - return String(reinterpret_cast *>(data->data()), data->size()); + return String(reinterpret_cast(data->data()), data->size()); } case DataOps::CompressionType::None: @@ -88,10 +88,9 @@ auto HttpClient::preprocess_response(Ref response) -> String { return response; } -auto HttpClient::raw_get(Ref path, Span> headers, - Const *> default_content_type) - -> Result { - Const http_headers = +auto HttpClient::raw_get(Ref path, Span headers, + const char *default_content_type) -> Result { + const httplib::Headers http_headers = build_headers(headers, default_content_type); Mut adjusted_path = path; @@ -99,8 +98,7 @@ auto HttpClient::raw_get(Ref path, Span> headers, adjusted_path = "/" + path; } - Const res = - m_client.Get(adjusted_path.c_str(), http_headers); + const httplib::Result res = m_client.Get(adjusted_path.c_str(), http_headers); if (res) { m_last_response_code = static_cast(res->status); @@ -113,16 +111,15 @@ auto HttpClient::raw_get(Ref path, Span> headers, return fail("Network Error: {}", httplib::to_string(res.error())); } -auto HttpClient::raw_post(Ref path, Span> headers, - Ref body, - Const *> default_content_type) +auto HttpClient::raw_post(Ref path, Span headers, + Ref body, const char *default_content_type) -> Result { Mut http_headers = build_headers(headers, default_content_type); Mut content_type = default_content_type; if (http_headers.count("Content-Type")) { - Const t = http_headers.find("Content-Type"); + const httplib::Headers::iterator t = http_headers.find("Content-Type"); content_type = t->second; http_headers.erase(t); } @@ -134,8 +131,8 @@ auto HttpClient::raw_post(Ref path, Span> headers, adjusted_path = "/" + path; } - Const res = m_client.Post( - adjusted_path.c_str(), http_headers, body, content_type.c_str()); + const httplib::Result res = m_client.Post(adjusted_path.c_str(), http_headers, + body, content_type.c_str()); if (res) { m_last_response_code = static_cast(res->status); diff --git a/Src/IACore/imp/cpp/Http/Common.cpp b/Src/IACore/imp/cpp/Http/Common.cpp index b0f1716..082be41 100644 --- a/Src/IACore/imp/cpp/Http/Common.cpp +++ b/Src/IACore/imp/cpp/Http/Common.cpp @@ -21,7 +21,7 @@ auto HttpCommon::url_encode(Ref value) -> String { escaped.fill('0'); escaped << std::hex << std::uppercase; - for (Const c : value) { + for (const char c : value) { if (std::isalnum(static_cast(c)) || c == '-' || c == '_' || c == '.' || c == '~') escaped << c; @@ -39,8 +39,8 @@ auto HttpCommon::url_decode(Ref value) -> String { for (Mut i = 0; i < value.length(); ++i) { if (value[i] == '%' && i + 2 < value.length()) { - Const hex_str = value.substr(i + 1, 2); - Const decoded_char = + const std::string hex_str = value.substr(i + 1, 2); + const char decoded_char = static_cast(std::strtol(hex_str.c_str(), nullptr, 16)); result += decoded_char; i += 2; @@ -53,7 +53,7 @@ auto HttpCommon::url_decode(Ref value) -> String { return result; } -auto HttpCommon::header_type_to_string(Const type) -> String { +auto HttpCommon::header_type_to_string(const EHeaderType type) -> String { switch (type) { case EHeaderType::ACCEPT: return "Accept"; @@ -111,7 +111,7 @@ auto HttpCommon::header_type_to_string(Const type) -> String { return ""; } -auto HttpCommon::is_success_response_code(Const code) -> bool { +auto HttpCommon::is_success_response_code(const EResponseCode code) -> bool { return (i32)code >= 200 && (i32)code < 300; } } // namespace IACore \ No newline at end of file diff --git a/Src/IACore/imp/cpp/Http/Server.cpp b/Src/IACore/imp/cpp/Http/Server.cpp index e1ccf3d..2a39d49 100644 --- a/Src/IACore/imp/cpp/Http/Server.cpp +++ b/Src/IACore/imp/cpp/Http/Server.cpp @@ -18,24 +18,21 @@ namespace IACore { auto HttpServer::Request::get_header(Ref key) const -> String { - if (Const::const_iterator> it = headers.find(key); - it != headers.end()) { + if (auto it = headers.find(key); it != headers.end()) { return it->second; } return ""; } auto HttpServer::Request::get_param(Ref key) const -> String { - if (Const::const_iterator> it = params.find(key); - it != params.end()) { + if (auto it = params.find(key); it != params.end()) { return it->second; } return ""; } auto HttpServer::Request::get_path_param(Ref key) const -> String { - if (Const::const_iterator> it = path_params.find(key); - it != path_params.end()) { + if (auto it = path_params.find(key); it != path_params.end()) { return it->second; } return ""; @@ -58,7 +55,7 @@ void HttpServer::Response::set_content(Ref content, Ref type) { content_type = type; } -void HttpServer::Response::set_status(Const status_code) { +void HttpServer::Response::set_status(const EResponseCode status_code) { code = status_code; } @@ -78,7 +75,7 @@ auto HttpServer::create() -> Result> { return make_box(); } -auto HttpServer::listen(Ref host, Const port) -> Result { +auto HttpServer::listen(Ref host, const u32 port) -> Result { if (!m_server.listen(host.c_str(), static_cast(port))) { return fail("Failed to start HTTP server on {}:{}", host, port); } @@ -94,8 +91,8 @@ void HttpServer::stop() { auto HttpServer::is_running() const -> bool { return m_server.is_running(); } void HttpServer::register_handler(Ref method, Ref pattern, - Const handler) { - Const wrapper = + const Handler handler) { + const httplib::Server::Handler wrapper = [handler](Ref req, MutRef res) { Mut ia_req; ia_req.path = req.path; @@ -138,23 +135,23 @@ void HttpServer::register_handler(Ref method, Ref pattern, } } -void HttpServer::get(Ref pattern, Const handler) { +void HttpServer::get(Ref pattern, const Handler handler) { register_handler("GET", pattern, handler); } -void HttpServer::post(Ref pattern, Const handler) { +void HttpServer::post(Ref pattern, const Handler handler) { register_handler("POST", pattern, handler); } -void HttpServer::put(Ref pattern, Const handler) { +void HttpServer::put(Ref pattern, const Handler handler) { register_handler("PUT", pattern, handler); } -void HttpServer::del(Ref pattern, Const handler) { +void HttpServer::del(Ref pattern, const Handler handler) { register_handler("DELETE", pattern, handler); } -void HttpServer::options(Ref pattern, Const handler) { +void HttpServer::options(Ref pattern, const Handler handler) { register_handler("OPTIONS", pattern, handler); } diff --git a/Src/IACore/imp/cpp/IPC.cpp b/Src/IACore/imp/cpp/IPC.cpp index 89696c0..41a4d4a 100644 --- a/Src/IACore/imp/cpp/IPC.cpp +++ b/Src/IACore/imp/cpp/IPC.cpp @@ -31,7 +31,7 @@ struct IpcConnectionDescriptor { shared_mem_size); } - static auto deserialize(Const data) + static auto deserialize(const StringView data) -> Option { enum class ParseState { SocketPath, SharedMemPath, SharedMemSize }; @@ -56,8 +56,8 @@ struct IpcConnectionDescriptor { break; case ParseState::SharedMemSize: { - Const start = data.data() + t; - Const end = data.data() + i; + const char *start = data.data() + t; + const char *end = data.data() + i; if (std::from_chars(start, end, result.shared_mem_size).ec != std::errc{}) { return std::nullopt; @@ -77,8 +77,8 @@ IpcNode::~IpcNode() { } } -auto IpcNode::connect(Const connection_string) -> Result { - Const> desc_opt = +auto IpcNode::connect(const char *connection_string) -> Result { + const Option desc_opt = IpcConnectionDescriptor::deserialize(connection_string); if (!desc_opt) { return fail("Failed to parse connection string"); @@ -141,7 +141,7 @@ void IpcNode::update() { } Mut signal = 0; - Const res = recv(m_socket, reinterpret_cast(&signal), 1, 0); + const isize res = recv(m_socket, reinterpret_cast(&signal), 1, 0); if (res == 1) { on_signal(signal); } else if (res == 0 || (res < 0 && !SocketOps::is_would_block())) { @@ -152,30 +152,30 @@ void IpcNode::update() { } } -void IpcNode::send_signal(Const signal) { +void IpcNode::send_signal(const u8 signal) { if (m_socket != INVALID_SOCKET) { send(m_socket, reinterpret_cast(&signal), sizeof(signal), 0); } } -auto IpcNode::send_packet(Const packet_id, Const>> payload) +auto IpcNode::send_packet(const u16 packet_id, const Span payload) -> Result { if (!m_mino.is_valid()) return fail("invalid MINO"); return m_mino.push(packet_id, payload); } -void IpcManager::NodeSession::send_signal(Const signal) { +void IpcManager::NodeSession::send_signal(const u8 signal) { if (data_socket != INVALID_SOCKET) { send(data_socket, reinterpret_cast(&signal), sizeof(signal), 0); } } -auto IpcManager::NodeSession::send_packet(Const packet_id, - Const>> payload) +auto IpcManager::NodeSession::send_packet(const u16 packet_id, + const Span payload) -> Result { - Const> lock(send_mutex); + const std::scoped_lock lock(send_mutex); if (!moni.is_valid()) return fail("invalid MONI"); return moni.push(packet_id, payload); @@ -207,7 +207,7 @@ IpcManager::~IpcManager() { } void IpcManager::update() { - Const now = + const std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); for (Mut i = static_cast(m_pending_sessions.size()) - 1; i >= 0; @@ -246,7 +246,7 @@ void IpcManager::update() { SocketOps::close(session->listener_socket); session->listener_socket = INVALID_SOCKET; - Const session_id = session->node_process->id.load(); + const NativeProcessID session_id = session->node_process->id.load(); Mut session_ptr = session.get(); m_active_sessions.push_back(std::move(session)); m_pending_sessions.erase(m_pending_sessions.begin() + i); @@ -269,7 +269,7 @@ void IpcManager::update() { } Mut signal = 0; - Const res = + const isize res = recv(node->data_socket, reinterpret_cast(&signal), 1, 0); if (res == 1) { @@ -288,12 +288,12 @@ void IpcManager::update() { } auto IpcManager::spawn_node(Ref executable_path, - Const shared_memory_size) + const u32 shared_memory_size) -> Result { Mut> session = make_box(); static Mut> s_id_gen{0}; - Const sid = ++s_id_gen; + const u32 sid = ++s_id_gen; Mut sock_path; #if IA_PLATFORM_WINDOWS @@ -316,7 +316,7 @@ auto IpcManager::spawn_node(Ref executable_path, fcntl(session->listener_socket, F_SETFL, O_NONBLOCK); #endif - Const shm_name = std::format("ia_shm_{}", sid); + const String shm_name = std::format("ia_shm_{}", sid); session->mapped_ptr = AU_TRY(FileOps::map_shared_memory(shm_name, shared_memory_size, true)); @@ -327,8 +327,8 @@ auto IpcManager::spawn_node(Ref executable_path, layout->meta.version = 1; layout->meta.total_size = shared_memory_size; - Const header_size = IpcSharedMemoryLayout::get_header_size(); - Const usable_bytes = shared_memory_size - header_size; + const u64 header_size = IpcSharedMemoryLayout::get_header_size(); + const u64 usable_bytes = shared_memory_size - header_size; Mut half_size = (usable_bytes / 2); half_size -= (half_size % 64); @@ -356,17 +356,17 @@ auto IpcManager::spawn_node(Ref executable_path, desc.shared_mem_path = shm_name; desc.shared_mem_size = shared_memory_size; - Const args = std::format("\"{}\"", desc.serialize()); + const String args = std::format("\"{}\"", desc.serialize()); session->node_process = AU_TRY(ProcessOps::spawn_process_async( FileOps::normalize_executable_path(executable_path).string(), args, - [sid](Const line) { + [sid](StringView line) { if (Env::IS_DEBUG) { std::cout << std::format("{}[Node:{}:STDOUT|STDERR]: {}{}\n", console::MAGENTA, sid, line, console::RESET); } }, - [sid](Const> result) { + [sid](Result result) { if (Env::IS_DEBUG) { if (!result) { std::cout << std::format( @@ -386,7 +386,7 @@ auto IpcManager::spawn_node(Ref executable_path, executable_path.string()); } - Const process_id = session->node_process->id.load(); + const NativeProcessID process_id = session->node_process->id.load(); session->shared_mem_name = shm_name; session->creation_time = std::chrono::system_clock::now(); @@ -395,12 +395,12 @@ auto IpcManager::spawn_node(Ref executable_path, return process_id; } -auto IpcManager::wait_till_node_is_online(Const node_id) +auto IpcManager::wait_till_node_is_online(const NativeProcessID node_id) -> bool { Mut is_pending = true; while (is_pending) { is_pending = false; - for (Const> &session : m_pending_sessions) { + for (const Box &session : m_pending_sessions) { if (session->node_process->id.load() == node_id) { is_pending = true; break; @@ -412,8 +412,8 @@ auto IpcManager::wait_till_node_is_online(Const node_id) return m_active_session_map.contains(node_id); } -void IpcManager::shutdown_node(Const node_id) { - Const::iterator> it_node = +void IpcManager::shutdown_node(const NativeProcessID node_id) { + const HashMap::iterator it_node = m_active_session_map.find(node_id); if (it_node == m_active_session_map.end()) { return; @@ -431,8 +431,8 @@ void IpcManager::shutdown_node(Const node_id) { m_active_session_map.erase(it_node); } -void IpcManager::send_signal(Const node, Const signal) { - Const::iterator> it_node = +void IpcManager::send_signal(const NativeProcessID node, const u8 signal) { + const HashMap::iterator it_node = m_active_session_map.find(node); if (it_node == m_active_session_map.end()) { return; @@ -440,9 +440,9 @@ void IpcManager::send_signal(Const node, Const signal) { it_node->second->send_signal(signal); } -auto IpcManager::send_packet(Const node, Const packet_id, - Const>> payload) -> Result { - Const::iterator> it_node = +auto IpcManager::send_packet(const NativeProcessID node, const u16 packet_id, + const Span payload) -> Result { + const HashMap::iterator it_node = m_active_session_map.find(node); if (it_node == m_active_session_map.end()) return fail("no such node"); diff --git a/Src/IACore/imp/cpp/Logger.cpp b/Src/IACore/imp/cpp/Logger.cpp index f80dbc3..2597a19 100644 --- a/Src/IACore/imp/cpp/Logger.cpp +++ b/Src/IACore/imp/cpp/Logger.cpp @@ -24,11 +24,11 @@ Mut Logger::m_log_level = Logger::LogLevel::Info; Mut Logger::m_log_file; static auto get_seconds_count() -> f64 { - static Const> start_time = + static const std::chrono::time_point start_time = std::chrono::steady_clock::now(); - Const> now = + const std::chrono::time_point now = std::chrono::steady_clock::now(); - Const> duration = now - start_time; + const std::chrono::duration duration = now - start_time; return duration.count(); } @@ -41,8 +41,7 @@ auto Logger::terminate() -> void { } } -auto Logger::enable_logging_to_disk(Const *> file_path) - -> Result { +auto Logger::enable_logging_to_disk(const char *file_path) -> Result { if (m_log_file.is_open()) { m_log_file.flush(); m_log_file.close(); @@ -57,7 +56,7 @@ auto Logger::enable_logging_to_disk(Const *> file_path) return {}; } -auto Logger::set_log_level(Const log_level) -> void { +auto Logger::set_log_level(const LogLevel log_level) -> void { m_log_level = log_level; } @@ -68,10 +67,10 @@ auto Logger::flush_logs() -> void { } } -auto Logger::log_internal(Const *> prefix, Const *> tag, +auto Logger::log_internal(const char *prefix, const char *tag, ForwardRef msg) -> void { - Const seconds = get_seconds_count(); - Const out_line = + const f64 seconds = get_seconds_count(); + const String out_line = std::format("[{:>8.3f}]: [{}]: {}", seconds, tag, msg); std::cout << prefix << out_line << console::RESET << '\n'; diff --git a/Src/IACore/imp/cpp/Platform.cpp b/Src/IACore/imp/cpp/Platform.cpp index 112221f..718b282 100644 --- a/Src/IACore/imp/cpp/Platform.cpp +++ b/Src/IACore/imp/cpp/Platform.cpp @@ -30,7 +30,7 @@ namespace IACore { Mut Platform::s_capabilities{}; #if defined(IA_ARCH_X64) -auto Platform::cpuid(Const function, Const sub_function, +auto Platform::cpuid(const i32 function, const i32 sub_function, Mut out[4]) -> void { #ifdef _MSC_VER __cpuidex(reinterpret_cast(out), static_cast(function), @@ -59,21 +59,21 @@ auto Platform::check_cpu() -> bool { } cpuid(1, 0, cpu_info); - Const osxsave = (cpu_info[2] & (1 << 27)) != 0; - Const avx = (cpu_info[2] & (1 << 28)) != 0; - Const fma = (cpu_info[2] & (1 << 12)) != 0; + const bool osxsave = (cpu_info[2] & (1 << 27)) != 0; + const bool avx = (cpu_info[2] & (1 << 28)) != 0; + const bool fma = (cpu_info[2] & (1 << 12)) != 0; if (!osxsave || !avx || !fma) { return false; } - Const xcr_feature_mask = _xgetbv(0); + const u64 xcr_feature_mask = _xgetbv(0); if ((xcr_feature_mask & 0x6) != 0x6) { return false; } cpuid(7, 0, cpu_info); - Const avx2 = (cpu_info[1] & (1 << 5)) != 0; + const bool avx2 = (cpu_info[1] & (1 << 5)) != 0; if (!avx2) { return false; } @@ -82,7 +82,7 @@ auto Platform::check_cpu() -> bool { #elif defined(IA_ARCH_ARM64) #if defined(__linux__) || defined(__ANDROID__) - Const hw_caps = getauxval(AT_HWCAP); + const usize hw_caps = getauxval(AT_HWCAP); #ifndef HWCAP_CRC32 #define HWCAP_CRC32 (1 << 7) diff --git a/Src/IACore/imp/cpp/ProcessOps.cpp b/Src/IACore/imp/cpp/ProcessOps.cpp index db309e7..16bc739 100644 --- a/Src/IACore/imp/cpp/ProcessOps.cpp +++ b/Src/IACore/imp/cpp/ProcessOps.cpp @@ -18,13 +18,13 @@ namespace IACore { struct LineBuffer { Mut m_accumulator; - Const)>> m_callback; + const std::function m_callback; - auto append(Const data, Const size) -> void; + auto append(const char *data, const usize size) -> void; auto flush() -> void; }; -auto LineBuffer::append(Const data, Const size) -> void { +auto LineBuffer::append(const char *data, const usize size) -> void { Mut start = 0; for (Mut i = 0; i < size; ++i) { if (data[i] == '\n' || data[i] == '\r') { @@ -68,7 +68,7 @@ auto ProcessOps::get_current_process_id() -> NativeProcessID { auto ProcessOps::spawn_process_sync( Ref command, Ref args, - Const)>> on_output_line_callback) + const std::function on_output_line_callback) -> Result { Mut> id = 0; if constexpr (Env::IS_WINDOWS) { @@ -80,8 +80,8 @@ auto ProcessOps::spawn_process_sync( auto ProcessOps::spawn_process_async( Ref command, Ref args, - Const)>> on_output_line_callback, - Const>)>> on_finish_callback) + const std::function on_output_line_callback, + const std::function)> on_finish_callback) -> Result> { Mut> handle = make_box(); handle->is_running = true; @@ -118,7 +118,7 @@ auto ProcessOps::terminate_process(Ref> handle) -> void { return; } - Const pid = handle->id.load(); + const NativeProcessID pid = handle->id.load(); if (pid == 0) { return; } @@ -137,7 +137,7 @@ auto ProcessOps::terminate_process(Ref> handle) -> void { auto ProcessOps::spawn_process_windows( Ref command, Ref args, - Const)>> on_output_line_callback, + const std::function on_output_line_callback, MutRef> id) -> Result { #if IA_PLATFORM_WINDOWS Mut sa_attr = {sizeof(SECURITY_ATTRIBUTES), NULL, true}; @@ -162,8 +162,8 @@ auto ProcessOps::spawn_process_windows( Mut command_line = std::format("\"{}\" {}", command, args); - Const success = CreateProcessA(NULL, command_line.data(), NULL, NULL, - true, 0, NULL, NULL, &si, &pi); + const BOOL success = CreateProcessA(NULL, command_line.data(), NULL, NULL, + true, 0, NULL, NULL, &si, &pi); CloseHandle(h_write); @@ -206,7 +206,7 @@ auto ProcessOps::spawn_process_windows( auto ProcessOps::spawn_process_posix( Ref command, Ref args, - Const)>> on_output_line_callback, + const std::function on_output_line_callback, MutRef> id) -> Result { #if IA_PLATFORM_UNIX Mut> pipefd; @@ -214,7 +214,7 @@ auto ProcessOps::spawn_process_posix( return fail("Failed to create pipe"); } - Const pid = fork(); + const pid_t pid = fork(); if (pid == -1) { return fail("Failed to fork process"); @@ -235,7 +235,7 @@ auto ProcessOps::spawn_process_posix( Mut in_quotes = false; Mut is_escaped = false; - for (Const c : args) { + for (const char c : args) { if (is_escaped) { current_token += c; is_escaped = false; diff --git a/Src/IACore/imp/cpp/SocketOps.cpp b/Src/IACore/imp/cpp/SocketOps.cpp index 9d1a421..ec8e3b4 100644 --- a/Src/IACore/imp/cpp/SocketOps.cpp +++ b/Src/IACore/imp/cpp/SocketOps.cpp @@ -19,7 +19,7 @@ namespace IACore { Mut SocketOps::s_init_count = 0; -auto SocketOps::close(Const sock) -> void { +auto SocketOps::close(const SocketHandle sock) -> void { if (sock == INVALID_SOCKET) { return; } @@ -30,7 +30,7 @@ auto SocketOps::close(Const sock) -> void { #endif } -auto SocketOps::listen(Const sock, Const queue_size) +auto SocketOps::listen(const SocketHandle sock, const i32 queue_size) -> Result { if (::listen(sock, queue_size) == 0) { return {}; @@ -44,7 +44,7 @@ auto SocketOps::listen(Const sock, Const queue_size) } auto SocketOps::create_unix_socket() -> Result { - Const sock = socket(AF_UNIX, SOCK_STREAM, 0); + const SocketHandle sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock == INVALID_SOCKET) { #if IA_PLATFORM_WINDOWS return fail("socket(AF_UNIX) failed: {}", WSAGetLastError()); @@ -55,8 +55,8 @@ auto SocketOps::create_unix_socket() -> Result { return sock; } -auto SocketOps::bind_unix_socket(Const sock, - Const path) -> Result { +auto SocketOps::bind_unix_socket(const SocketHandle sock, const char *path) + -> Result { if (sock == INVALID_SOCKET) { return fail("Invalid socket handle"); } @@ -66,7 +66,7 @@ auto SocketOps::bind_unix_socket(Const sock, Mut addr{}; addr.sun_family = AF_UNIX; - Const max_len = sizeof(addr.sun_path) - 1; + const usize max_len = sizeof(addr.sun_path) - 1; #if IA_PLATFORM_WINDOWS strncpy_s(addr.sun_path, sizeof(addr.sun_path), path, max_len); #else @@ -85,8 +85,8 @@ auto SocketOps::bind_unix_socket(Const sock, return {}; } -auto SocketOps::connect_unix_socket(Const sock, - Const path) -> Result { +auto SocketOps::connect_unix_socket(const SocketHandle sock, const char *path) + -> Result { if (sock == INVALID_SOCKET) { return fail("Invalid socket handle"); } @@ -94,7 +94,7 @@ auto SocketOps::connect_unix_socket(Const sock, Mut addr{}; addr.sun_family = AF_UNIX; - Const max_len = sizeof(addr.sun_path) - 1; + const usize max_len = sizeof(addr.sun_path) - 1; #if IA_PLATFORM_WINDOWS strncpy_s(addr.sun_path, sizeof(addr.sun_path), path, max_len); #else @@ -113,8 +113,8 @@ auto SocketOps::connect_unix_socket(Const sock, return {}; } -auto SocketOps::is_port_available(Const port, Const type) -> bool { - Const sock = socket(AF_INET, type, 0); +auto SocketOps::is_port_available(const u16 port, const i32 type) -> bool { + const SocketHandle sock = socket(AF_INET, type, 0); if (sock == INVALID_SOCKET) { return false; } diff --git a/Src/IACore/imp/cpp/StreamReader.cpp b/Src/IACore/imp/cpp/StreamReader.cpp index 424a7f1..cdce378 100644 --- a/Src/IACore/imp/cpp/StreamReader.cpp +++ b/Src/IACore/imp/cpp/StreamReader.cpp @@ -20,7 +20,7 @@ namespace IACore { auto StreamReader::create_from_file(Ref path) -> Result { Mut size = 0; - Const ptr = AU_TRY(FileOps::map_file(path, size)); + const u8 *ptr = AU_TRY(FileOps::map_file(path, size)); Mut reader(Span(ptr, size)); reader.m_storage_type = StorageType::OwningMmap; @@ -35,7 +35,7 @@ StreamReader::StreamReader(ForwardRef> data) m_data_size = m_owning_vector.size(); } -StreamReader::StreamReader(Const> data) +StreamReader::StreamReader(const Span data) : m_data(data.data()), m_data_size(data.size()), m_storage_type(StorageType::NonOwning) {} diff --git a/Src/IACore/imp/cpp/StreamWriter.cpp b/Src/IACore/imp/cpp/StreamWriter.cpp index 7008f5d..9095a99 100644 --- a/Src/IACore/imp/cpp/StreamWriter.cpp +++ b/Src/IACore/imp/cpp/StreamWriter.cpp @@ -37,7 +37,7 @@ StreamWriter::StreamWriter() : m_storage_type(StorageType::OwningVector) { m_buffer = m_owning_vector.data(); } -StreamWriter::StreamWriter(Const> data) +StreamWriter::StreamWriter(const Span data) : m_buffer(data.data()), m_cursor(0), m_capacity(data.size()), m_storage_type(StorageType::NonOwning) {} @@ -58,7 +58,7 @@ auto StreamWriter::operator=(ForwardRef other) -> MutRef { if (this != &other) { if (m_storage_type == StorageType::OwningFile) { - if (Const> res = flush_to_disk(); !res) { + if (const Result res = flush_to_disk(); !res) { std::fprintf(stderr, "[IACore] Data loss in StreamWriter move: %s\n", res.error().c_str()); } @@ -84,7 +84,7 @@ auto StreamWriter::operator=(ForwardRef other) StreamWriter::~StreamWriter() { if (m_storage_type == StorageType::OwningFile) { - if (Const> res = flush_to_disk(); !res) { + if (const Result res = flush_to_disk(); !res) { std::fprintf(stderr, "[IACore] LOST DATA in ~StreamWriter: %s\n", res.error().c_str()); } @@ -109,7 +109,7 @@ auto StreamWriter::flush_to_disk() -> Result { return fail("Failed to open file for writing: {}", m_file_path.string()); } - Const written = std::fwrite(m_buffer, 1, m_cursor, f); + const usize written = std::fwrite(m_buffer, 1, m_cursor, f); std::fclose(f); if (written != m_cursor) { @@ -118,15 +118,15 @@ auto StreamWriter::flush_to_disk() -> Result { return {}; } -auto StreamWriter::write(Const byte, Const count) -> Result { +auto StreamWriter::write(const u8 byte, const usize count) -> Result { if (m_cursor + count > m_capacity) { if (m_storage_type == StorageType::NonOwning) { return fail("StreamWriter buffer overflow (NonOwning)"); } - Const required = m_cursor + count; - Const double_cap = m_capacity * 2; - Const new_capacity = (double_cap > required) ? double_cap : required; + const usize required = m_cursor + count; + const usize double_cap = m_capacity * 2; + const usize new_capacity = (double_cap > required) ? double_cap : required; m_owning_vector.resize(new_capacity); m_capacity = m_owning_vector.size(); @@ -138,16 +138,15 @@ auto StreamWriter::write(Const byte, Const count) -> Result { return {}; } -auto StreamWriter::write(Const buffer, Const size) - -> Result { +auto StreamWriter::write(const void *buffer, const usize size) -> Result { if (m_cursor + size > m_capacity) { if (m_storage_type == StorageType::NonOwning) { return fail("StreamWriter buffer overflow (NonOwning)"); } - Const required = m_cursor + size; - Const double_cap = m_capacity * 2; - Const new_capacity = (double_cap > required) ? double_cap : required; + const usize required = m_cursor + size; + const usize double_cap = m_capacity * 2; + const usize new_capacity = (double_cap > required) ? double_cap : required; m_owning_vector.resize(new_capacity); m_capacity = m_owning_vector.size(); diff --git a/Src/IACore/imp/cpp/StringOps.cpp b/Src/IACore/imp/cpp/StringOps.cpp index 5e42375..a1bfe0a 100644 --- a/Src/IACore/imp/cpp/StringOps.cpp +++ b/Src/IACore/imp/cpp/StringOps.cpp @@ -17,15 +17,15 @@ namespace IACore { -static Const BASE64_CHAR_TABLE = +static const String BASE64_CHAR_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -static auto is_base64(Const c) -> bool { +static auto is_base64(const u8 c) -> bool { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c == '+') || (c == '/'); } -static auto get_base64_index(Const c) -> u8 { +static auto get_base64_index(const u8 c) -> u8 { if (c >= 'A' && c <= 'Z') return c - 'A'; if (c >= 'a' && c <= 'z') @@ -39,16 +39,16 @@ static auto get_base64_index(Const c) -> u8 { return 0; } -auto StringOps::encode_base64(Const>> data) -> String { +auto StringOps::encode_base64(const Span data) -> String { Mut result; result.reserve(((data.size() + 2) / 3) * 4); for (Mut i = 0; i < data.size(); i += 3) { - Const b0 = data[i]; - Const b1 = (i + 1 < data.size()) ? data[i + 1] : 0; - Const b2 = (i + 2 < data.size()) ? data[i + 2] : 0; + const u32 b0 = data[i]; + const u32 b1 = (i + 1 < data.size()) ? data[i + 1] : 0; + const u32 b2 = (i + 2 < data.size()) ? data[i + 2] : 0; - Const triple = (b0 << 16) | (b1 << 8) | b2; + const u32 triple = (b0 << 16) | (b1 << 8) | b2; result += BASE64_CHAR_TABLE[(triple >> 18) & 0x3F]; result += BASE64_CHAR_TABLE[(triple >> 12) & 0x3F]; @@ -75,8 +75,8 @@ auto StringOps::decode_base64(Ref data) -> Vec { Mut i = 0; Mut> tmp_buf = {}; - for (Const c_char : data) { - Const c = static_cast(c_char); + for (const char c_char : data) { + const u8 c = static_cast(c_char); if (c == '=') { break; } @@ -86,10 +86,10 @@ auto StringOps::decode_base64(Ref data) -> Vec { tmp_buf[i++] = c; if (i == 4) { - Const n0 = get_base64_index(tmp_buf[0]); - Const n1 = get_base64_index(tmp_buf[1]); - Const n2 = get_base64_index(tmp_buf[2]); - Const n3 = get_base64_index(tmp_buf[3]); + const u8 n0 = get_base64_index(tmp_buf[0]); + const u8 n1 = get_base64_index(tmp_buf[1]); + const u8 n2 = get_base64_index(tmp_buf[2]); + const u8 n3 = get_base64_index(tmp_buf[3]); result.push_back((n0 << 2) | ((n1 & 0x30) >> 4)); result.push_back(((n1 & 0x0F) << 4) | ((n2 & 0x3C) >> 2)); @@ -104,9 +104,9 @@ auto StringOps::decode_base64(Ref data) -> Vec { tmp_buf[j] = 'A'; } - Const n0 = get_base64_index(tmp_buf[0]); - Const n1 = get_base64_index(tmp_buf[1]); - Const n2 = get_base64_index(tmp_buf[2]); + const u8 n0 = get_base64_index(tmp_buf[0]); + const u8 n1 = get_base64_index(tmp_buf[1]); + const u8 n2 = get_base64_index(tmp_buf[2]); if (i > 1) { result.push_back((n0 << 2) | ((n1 & 0x30) >> 4)); diff --git a/Src/IACore/imp/cpp/Utils.cpp b/Src/IACore/imp/cpp/Utils.cpp index 9e24cdf..401f2b7 100644 --- a/Src/IACore/imp/cpp/Utils.cpp +++ b/Src/IACore/imp/cpp/Utils.cpp @@ -19,7 +19,7 @@ namespace IACore { namespace { -auto from_hex_char(Const c) -> i32 { +auto from_hex_char(const char c) -> i32 { if (c >= '0' && c <= '9') { return c - '0'; } @@ -36,7 +36,7 @@ auto from_hex_char(Const c) -> i32 { extern Mut g_start_time; auto Utils::get_unix_time() -> u64 { - Const now = + const std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); return std::chrono::duration_cast( now.time_since_epoch()) @@ -44,14 +44,14 @@ auto Utils::get_unix_time() -> u64 { } auto Utils::get_ticks_count() -> u64 { - Const duration = + const std::chrono::high_resolution_clock::duration duration = std::chrono::high_resolution_clock::now() - g_start_time; return std::chrono::duration_cast(duration) .count(); } auto Utils::get_seconds_count() -> f64 { - Const duration = + const std::chrono::high_resolution_clock::duration duration = std::chrono::high_resolution_clock::now() - g_start_time; return static_cast( std::chrono::duration_cast(duration).count()); @@ -61,31 +61,31 @@ auto Utils::get_random() -> f32 { return static_cast(std::rand()) / static_cast(RAND_MAX); } -auto Utils::get_random(Const max) -> u64 { +auto Utils::get_random(const u64 max) -> u64 { return static_cast(static_cast(max) * get_random()); } -auto Utils::get_random(Const min, Const max) -> i64 { +auto Utils::get_random(const i64 min, const i64 max) -> i64 { return min + static_cast(static_cast(max - min) * get_random()); } -auto Utils::sleep(Const milliseconds) -> void { +auto Utils::sleep(const u64 milliseconds) -> void { std::this_thread::sleep_for(std::chrono::milliseconds(milliseconds)); } -auto Utils::binary_to_hex_string(Const>> data) -> String { - static constexpr Const lut = "0123456789ABCDEF"; +auto Utils::binary_to_hex_string(const Span data) -> String { + static constexpr const char LUT[17] = "0123456789ABCDEF"; Mut res = String(); res.reserve(data.size() * 2); - for (Const b : data) { - res.push_back(lut[(b >> 4) & 0x0F]); - res.push_back(lut[b & 0x0F]); + for (u8 b : data) { + res.push_back(LUT[(b >> 4) & 0x0F]); + res.push_back(LUT[b & 0x0F]); } return res; } -auto Utils::hex_string_to_binary(Const hex) -> Result> { +auto Utils::hex_string_to_binary(const StringView hex) -> Result> { if (hex.size() % 2 != 0) { return fail("Hex string must have even length"); } @@ -94,11 +94,11 @@ auto Utils::hex_string_to_binary(Const hex) -> Result> { out.reserve(hex.size() / 2); for (Mut i = 0; i < hex.size(); i += 2) { - Const high = hex[i]; - Const low = hex[i + 1]; + const char high = hex[i]; + const char low = hex[i + 1]; - Const h = from_hex_char(high); - Const l = from_hex_char(low); + const i32 h = from_hex_char(high); + const i32 l = from_hex_char(low); if (h == -1 || l == -1) { return fail("Invalid hex character found"); diff --git a/Src/IACore/imp/cpp/XML.cpp b/Src/IACore/imp/cpp/XML.cpp index 0831d68..6a1e1c9 100644 --- a/Src/IACore/imp/cpp/XML.cpp +++ b/Src/IACore/imp/cpp/XML.cpp @@ -20,7 +20,7 @@ namespace IACore { auto XML::parse_from_string(Ref data) -> Result { Mut doc; - Const parse_result = doc.load_string(data.c_str()); + const pugi::xml_parse_result parse_result = doc.load_string(data.c_str()); if (!parse_result) { return fail("Failed to parse XML {}", parse_result.description()); } @@ -29,7 +29,7 @@ auto XML::parse_from_string(Ref data) -> Result { auto XML::parse_from_file(Ref path) -> Result { Mut doc; - Const parse_result = + const pugi::xml_parse_result parse_result = doc.load_file(path.string().c_str()); if (!parse_result) { return fail("Failed to parse XML {}", parse_result.description()); @@ -37,13 +37,13 @@ auto XML::parse_from_file(Ref path) -> Result { return std::move(doc); } -auto XML::serialize_to_string(Ref node, Const escape) -> String { +auto XML::serialize_to_string(Ref node, const bool escape) -> String { Mut oss; node.print(oss); return escape ? escape_xml_string(oss.str()) : oss.str(); } -auto XML::serialize_to_string(Ref doc, Const escape) -> String { +auto XML::serialize_to_string(Ref doc, const bool escape) -> String { Mut oss; doc.save(oss); return escape ? escape_xml_string(oss.str()) : oss.str(); @@ -53,7 +53,7 @@ auto XML::escape_xml_string(Ref xml) -> String { Mut buffer; buffer.reserve(xml.size() + (xml.size() / 10)); - for (Const c : xml) { + for (const char c : xml) { switch (c) { case '&': buffer.append("&"); diff --git a/Src/IACore/inc/IACore/ADT/RingBuffer.hpp b/Src/IACore/inc/IACore/ADT/RingBuffer.hpp index 2839c73..e624d84 100644 --- a/Src/IACore/inc/IACore/ADT/RingBuffer.hpp +++ b/Src/IACore/inc/IACore/ADT/RingBuffer.hpp @@ -20,7 +20,7 @@ namespace IACore { class RingBufferView { public: - static constexpr Const PACKET_ID_SKIP = 0; + static constexpr const u16 PACKET_ID_SKIP = 0; struct ControlBlock { struct alignas(64) { @@ -39,9 +39,9 @@ public: struct PacketHeader { PacketHeader() : id(0), payload_size(0) {} - PacketHeader(Const id) : id(id), payload_size(0) {} + PacketHeader(const u16 id) : id(id), payload_size(0) {} - PacketHeader(Const id, Const payload_size) + PacketHeader(const u16 id, const u16 payload_size) : id(id), payload_size(payload_size) {} Mut id{}; @@ -51,10 +51,10 @@ public: public: static auto default_instance() -> RingBufferView; - static auto create(Ref> buffer, Const is_owner) + static auto create(Ref> buffer, const bool is_owner) -> Result; - static auto create(Const control_block, Ref> buffer, - Const is_owner) -> Result; + static auto create(ControlBlock *control_block, Ref> buffer, + const bool is_owner) -> Result; // Returns: // - nullopt if empty @@ -63,16 +63,16 @@ public: auto pop(MutRef out_header, Ref> out_buffer) -> Result>; - auto push(Const packet_id, Ref> data) -> Result; + auto push(const u16 packet_id, Ref> data) -> Result; auto get_control_block() -> ControlBlock *; [[nodiscard]] auto is_valid() const -> bool; protected: - RingBufferView(Ref> buffer, Const is_owner); - RingBufferView(Const control_block, Ref> buffer, - Const is_owner); + RingBufferView(Ref> buffer, const bool is_owner); + RingBufferView(ControlBlock *control_block, Ref> buffer, + const bool is_owner); private: Mut m_data_ptr{}; @@ -80,26 +80,24 @@ private: Mut m_control_block{}; private: - auto write_wrapped(Const offset, Const data, - Const size) -> void; - auto read_wrapped(Const offset, Const out_data, Const size) + auto write_wrapped(const u32 offset, const void *data, const u32 size) -> void; + auto read_wrapped(const u32 offset, void *out_data, const u32 size) -> void; }; inline auto RingBufferView::default_instance() -> RingBufferView { return RingBufferView(nullptr, {}, false); } -inline auto RingBufferView::create(Ref> buffer, Const is_owner) +inline auto RingBufferView::create(Ref> buffer, const bool is_owner) -> Result { if (buffer.size() <= sizeof(ControlBlock)) { return fail("Buffer too small for ControlBlock"); } if (!is_owner) { - Const cb = reinterpret_cast(buffer.data()); - Const capacity = - static_cast(buffer.size()) - sizeof(ControlBlock); + const ControlBlock *cb = reinterpret_cast(buffer.data()); + const u32 capacity = static_cast(buffer.size()) - sizeof(ControlBlock); if (cb->consumer.capacity != capacity) { return fail("Capacity mismatch"); } @@ -108,8 +106,8 @@ inline auto RingBufferView::create(Ref> buffer, Const is_owner) return RingBufferView(buffer, is_owner); } -inline auto RingBufferView::create(Const control_block, - Ref> buffer, Const is_owner) +inline auto RingBufferView::create(ControlBlock *control_block, + Ref> buffer, const bool is_owner) -> Result { if (control_block == nullptr) { return fail("ControlBlock is null"); @@ -122,7 +120,7 @@ inline auto RingBufferView::create(Const control_block, } inline RingBufferView::RingBufferView(Ref> buffer, - Const is_owner) { + const bool is_owner) { m_control_block = reinterpret_cast(buffer.data()); m_data_ptr = buffer.data() + sizeof(ControlBlock); @@ -135,9 +133,9 @@ inline RingBufferView::RingBufferView(Ref> buffer, } } -inline RingBufferView::RingBufferView(Const control_block, +inline RingBufferView::RingBufferView(ControlBlock *control_block, Ref> buffer, - Const is_owner) { + const bool is_owner) { m_control_block = control_block; m_data_ptr = buffer.data(); m_capacity = static_cast(buffer.size()); @@ -152,11 +150,11 @@ inline RingBufferView::RingBufferView(Const control_block, inline auto RingBufferView::pop(MutRef out_header, Ref> out_buffer) -> Result> { - Const write = + const u32 write = m_control_block->producer.write_offset.load(std::memory_order_acquire); - Const read = + const u32 read = m_control_block->consumer.read_offset.load(std::memory_order_relaxed); - Const cap = m_capacity; + const u32 cap = m_capacity; if (read == write) { return std::nullopt; @@ -170,11 +168,11 @@ inline auto RingBufferView::pop(MutRef out_header, } if (out_header.payload_size > 0) { - Const data_read_offset = (read + sizeof(PacketHeader)) % cap; + const u32 data_read_offset = (read + sizeof(PacketHeader)) % cap; read_wrapped(data_read_offset, out_buffer.data(), out_header.payload_size); } - Const new_read_offset = + const u32 new_read_offset = (read + sizeof(PacketHeader) + out_header.payload_size) % cap; m_control_block->consumer.read_offset.store(new_read_offset, std::memory_order_release); @@ -182,21 +180,21 @@ inline auto RingBufferView::pop(MutRef out_header, return std::make_optional(static_cast(out_header.payload_size)); } -inline auto RingBufferView::push(Const packet_id, Ref> data) +inline auto RingBufferView::push(const u16 packet_id, Ref> data) -> Result { if (data.size() > std::numeric_limits::max()) { return fail("Data size exceeds u16 limit"); } - Const total_size = sizeof(PacketHeader) + static_cast(data.size()); + const u32 total_size = sizeof(PacketHeader) + static_cast(data.size()); - Const read = + const u32 read = m_control_block->consumer.read_offset.load(std::memory_order_acquire); - Const write = + const u32 write = m_control_block->producer.write_offset.load(std::memory_order_relaxed); - Const cap = m_capacity; + const u32 cap = m_capacity; - Const free_space = + const u32 free_space = (read <= write) ? (m_capacity - write) + read : (read - write); // Leave 1 byte empty (prevent ambiguities) @@ -204,17 +202,17 @@ inline auto RingBufferView::push(Const packet_id, Ref> data) return fail("RingBuffer full"); } - Const header{packet_id, static_cast(data.size())}; + const PacketHeader header{packet_id, static_cast(data.size())}; write_wrapped(write, &header, sizeof(PacketHeader)); - Const data_write_offset = (write + sizeof(PacketHeader)) % cap; + const u32 data_write_offset = (write + sizeof(PacketHeader)) % cap; if (!data.empty()) { write_wrapped(data_write_offset, data.data(), static_cast(data.size())); } - Const new_write_offset = (data_write_offset + data.size()) % cap; + const u32 new_write_offset = (data_write_offset + data.size()) % cap; m_control_block->producer.write_offset.store(new_write_offset, std::memory_order_release); @@ -225,32 +223,30 @@ inline auto RingBufferView::get_control_block() -> ControlBlock * { return m_control_block; } -inline auto RingBufferView::write_wrapped(Const offset, - Const data, - Const size) -> void { +inline auto RingBufferView::write_wrapped(const u32 offset, const void *data, + const u32 size) -> void { if (offset + size <= m_capacity) { std::memcpy(m_data_ptr + offset, data, size); } else { - Const first_chunk = m_capacity - offset; - Const second_chunk = size - first_chunk; + const u32 first_chunk = m_capacity - offset; + const u32 second_chunk = size - first_chunk; - Const src = static_cast(data); + const u8 *src = static_cast(data); std::memcpy(m_data_ptr + offset, src, first_chunk); std::memcpy(m_data_ptr, src + first_chunk, second_chunk); } } -inline auto RingBufferView::read_wrapped(Const offset, - Const out_data, - Const size) -> void { +inline auto RingBufferView::read_wrapped(const u32 offset, void *out_data, + const u32 size) -> void { if (offset + size <= m_capacity) { std::memcpy(out_data, m_data_ptr + offset, size); } else { - Const first_chunk = m_capacity - offset; - Const second_chunk = size - first_chunk; + const u32 first_chunk = m_capacity - offset; + const u32 second_chunk = size - first_chunk; - Const dst = static_cast(out_data); + u8 *dst = static_cast(out_data); std::memcpy(dst, m_data_ptr + offset, first_chunk); std::memcpy(dst + first_chunk, m_data_ptr, second_chunk); diff --git a/Src/IACore/inc/IACore/AsyncOps.hpp b/Src/IACore/inc/IACore/AsyncOps.hpp index 1f15203..3006c0d 100644 --- a/Src/IACore/inc/IACore/AsyncOps.hpp +++ b/Src/IACore/inc/IACore/AsyncOps.hpp @@ -26,7 +26,7 @@ public: using TaskTag = u64; using WorkerId = u16; - static constexpr Const MAIN_THREAD_WORKER_ID = 0; + static constexpr const WorkerId MAIN_THREAD_WORKER_ID = 0; enum class Priority : u8 { High, Normal }; @@ -35,15 +35,14 @@ public: }; public: - static auto initialize_scheduler(Const worker_count = 0) -> Result; + static auto initialize_scheduler(const u8 worker_count = 0) -> Result; static auto terminate_scheduler() -> void; - static auto schedule_task(Mut)>> task, - Const tag, Mut schedule, - Const priority = Priority::Normal) - -> void; + static auto schedule_task(Mut> task, + const TaskTag tag, Mut schedule, + const Priority priority = Priority::Normal) -> void; - static auto cancel_tasks_of_tag(Const tag) -> void; + static auto cancel_tasks_of_tag(const TaskTag tag) -> void; static auto wait_for_schedule_completion(Mut schedule) -> void; @@ -55,11 +54,11 @@ private: struct ScheduledTask { Mut tag{}; Mut schedule_handle{}; - Mut)>> task{}; + Mut> task{}; }; static auto schedule_worker_loop(Mut stop_token, - Const worker_id) -> void; + const WorkerId worker_id) -> void; private: static Mut s_queue_mutex; diff --git a/Src/IACore/inc/IACore/CLI.hpp b/Src/IACore/inc/IACore/CLI.hpp index 1a95192..0c158f4 100644 --- a/Src/IACore/inc/IACore/CLI.hpp +++ b/Src/IACore/inc/IACore/CLI.hpp @@ -28,7 +28,7 @@ class CLIParser { */ public: - CLIParser(Const>> args); + CLIParser(const Span args); ~CLIParser() = default; public: @@ -57,7 +57,7 @@ public: } private: - Const>> m_arg_list; - Mut>::const_iterator> m_current_arg; + const Span m_arg_list; + Mut::const_iterator> m_current_arg; }; } // namespace IACore \ No newline at end of file diff --git a/Src/IACore/inc/IACore/DataOps.hpp b/Src/IACore/inc/IACore/DataOps.hpp index 135540f..d025499 100644 --- a/Src/IACore/inc/IACore/DataOps.hpp +++ b/Src/IACore/inc/IACore/DataOps.hpp @@ -24,24 +24,22 @@ public: public: static auto hash_fnv1a(Ref string) -> u32; - static auto hash_fnv1a(Ref>> data) -> u32; + static auto hash_fnv1a(Ref> data) -> u32; - static auto hash_xxhash(Ref string, Const seed = 0) -> u32; - static auto hash_xxhash(Ref>> data, Const seed = 0) - -> u32; + static auto hash_xxhash(Ref string, const u32 seed = 0) -> u32; + static auto hash_xxhash(Ref> data, const u32 seed = 0) -> u32; - static auto crc32(Ref>> data) -> u32; + static auto crc32(Ref> data) -> u32; - static auto detect_compression(Const>> data) - -> CompressionType; + static auto detect_compression(const Span data) -> CompressionType; - static auto gzip_inflate(Ref>> data) -> Result>; - static auto gzip_deflate(Ref>> data) -> Result>; + static auto gzip_inflate(Ref> data) -> Result>; + static auto gzip_deflate(Ref> data) -> Result>; - static auto zlib_inflate(Ref>> data) -> Result>; - static auto zlib_deflate(Ref>> data) -> Result>; + static auto zlib_inflate(Ref> data) -> Result>; + static auto zlib_deflate(Ref> data) -> Result>; - static auto zstd_inflate(Ref>> data) -> Result>; - static auto zstd_deflate(Ref>> data) -> Result>; + static auto zstd_inflate(Ref> data) -> Result>; + static auto zstd_deflate(Ref> data) -> Result>; }; } // namespace IACore \ No newline at end of file diff --git a/Src/IACore/inc/IACore/DynamicLib.hpp b/Src/IACore/inc/IACore/DynamicLib.hpp index 68b4e4a..9942e23 100644 --- a/Src/IACore/inc/IACore/DynamicLib.hpp +++ b/Src/IACore/inc/IACore/DynamicLib.hpp @@ -43,7 +43,7 @@ public: Mut lib; #if IA_PLATFORM_WINDOWS - Const h = LoadLibraryA(full_path.string().c_str()); + const HMODULE h = LoadLibraryA(full_path.string().c_str()); if (!h) { return fail(get_windows_error()); } @@ -51,7 +51,7 @@ public: #else Mut h = dlopen(full_path.c_str(), RTLD_LAZY | RTLD_LOCAL); if (!h) { - Const err = dlerror(); + const char *err = dlerror(); return fail(err ? err : "Unknown dlopen error"); } lib.m_handle = h; @@ -96,7 +96,7 @@ public: #else dlerror(); // Clear prev errors sym = dlsym(m_handle, name.c_str()); - if (Const err = dlerror()) { + if (const char *err = dlerror()) { return fail(err); } #endif @@ -129,19 +129,19 @@ private: #if IA_PLATFORM_WINDOWS static auto get_windows_error() -> String { - Const error_id = ::GetLastError(); + const DWORD error_id = ::GetLastError(); if (error_id == 0) { return String(); } Mut message_buffer = nullptr; - Const size = FormatMessageA( + const usize size = FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, error_id, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast(&message_buffer), 0, nullptr); - Const message(message_buffer, size); + const String message(message_buffer, size); LocalFree(message_buffer); return "Win32 Error: " + message; } diff --git a/Src/IACore/inc/IACore/Environment.hpp b/Src/IACore/inc/IACore/Environment.hpp index 8b44ea9..c004120 100644 --- a/Src/IACore/inc/IACore/Environment.hpp +++ b/Src/IACore/inc/IACore/Environment.hpp @@ -24,7 +24,7 @@ class Environment { public: static auto find(Ref name) -> Option { #if IA_PLATFORM_WINDOWS - Const buffer_size = + const u32 buffer_size = static_cast(GetEnvironmentVariableA(name.c_str(), nullptr, 0)); if (buffer_size == 0) { @@ -34,7 +34,7 @@ public: Mut result; result.resize(buffer_size); - Const actual_size = static_cast( + const u32 actual_size = static_cast( GetEnvironmentVariableA(name.c_str(), result.data(), buffer_size)); if (actual_size == 0 || actual_size > buffer_size) { @@ -45,7 +45,7 @@ public: return result; #else - Const val = std::getenv(name.c_str()); + const char *val = std::getenv(name.c_str()); if (val == nullptr) { return std::nullopt; } diff --git a/Src/IACore/inc/IACore/FileOps.hpp b/Src/IACore/inc/IACore/FileOps.hpp index 63cad80..bcf0a3b 100644 --- a/Src/IACore/inc/IACore/FileOps.hpp +++ b/Src/IACore/inc/IACore/FileOps.hpp @@ -22,11 +22,10 @@ #if IA_PLATFORM_WINDOWS using NativeFileHandle = HANDLE; -static constexpr au::Const INVALID_FILE_HANDLE = - INVALID_HANDLE_VALUE; +static constexpr NativeFileHandle INVALID_FILE_HANDLE = INVALID_HANDLE_VALUE; #else using NativeFileHandle = int; -static constexpr au::Const INVALID_FILE_HANDLE = -1; +static constexpr NativeFileHandle INVALID_FILE_HANDLE = -1; #endif namespace IACore { @@ -49,31 +48,31 @@ public: TruncateExisting // Opens existing and clears it }; - static auto native_open_file(Ref path, Const access, - Const mode, - Const permissions = 0644) + static auto native_open_file(Ref path, const FileAccess access, + const FileMode mode, + const u32 permissions = 0644) -> Result; - static auto native_close_file(Const handle) -> void; + static auto native_close_file(const NativeFileHandle handle) -> void; public: static auto normalize_executable_path(Ref path) -> Path; public: - static auto unmap_file(Const mapped_ptr) -> void; + static auto unmap_file(const u8 *mapped_ptr) -> void; static auto map_file(Ref path, MutRef size) -> Result; // @param `is_owner` true to allocate/truncate. false to just open. - static auto map_shared_memory(Ref name, Const size, - Const is_owner) -> Result; + static auto map_shared_memory(Ref name, const usize size, + const bool is_owner) -> Result; static auto unlink_shared_memory(Ref name) -> void; static auto stream_from_file(Ref path) -> Result; - static auto stream_to_file(Ref path, Const overwrite = false) + static auto stream_to_file(Ref path, const bool overwrite = false) -> Result; static auto read_text_file(Ref path) -> Result; @@ -81,10 +80,10 @@ public: static auto read_binary_file(Ref path) -> Result>; static auto write_text_file(Ref path, Ref contents, - Const overwrite = false) -> Result; + const bool overwrite = false) -> Result; - static auto write_binary_file(Ref path, Const> contents, - Const overwrite = false) -> Result; + static auto write_binary_file(Ref path, const Span contents, + const bool overwrite = false) -> Result; private: static Mut>> @@ -103,7 +102,7 @@ public: auto operator=(ForwardRef other) noexcept -> MemoryMappedRegion &; - auto map(Const handle, Const offset, Const size) + auto map(const NativeFileHandle handle, const u64 offset, const usize size) -> Result; auto unmap() -> void; diff --git a/Src/IACore/inc/IACore/Http/Client.hpp b/Src/IACore/inc/IACore/Http/Client.hpp index 8ff3785..a5c4d54 100644 --- a/Src/IACore/inc/IACore/Http/Client.hpp +++ b/Src/IACore/inc/IACore/Http/Client.hpp @@ -31,20 +31,20 @@ public: auto operator=(Ref) -> MutRef = delete; public: - auto raw_get(Ref path, Span> headers, - Const *default_content_type = + auto raw_get(Ref path, Span headers, + const char *default_content_type = "application/x-www-form-urlencoded") -> Result; - auto raw_post(Ref path, Span> headers, Ref body, - Const *default_content_type = + auto raw_post(Ref path, Span headers, Ref body, + const char *default_content_type = "application/x-www-form-urlencoded") -> Result; template - auto json_get(Ref path, Span> headers) + auto json_get(Ref path, Span headers) -> Result; template - auto json_post(Ref path, Span> headers, + auto json_post(Ref path, Span headers, Ref body) -> Result; // Certificate verification is enabled by default @@ -66,9 +66,9 @@ protected: }; template -auto HttpClient::json_get(Ref path, Span> headers) +auto HttpClient::json_get(Ref path, Span headers) -> Result { - Const raw_response = + const String raw_response = AU_TRY(raw_get(path, headers, "application/json")); if (last_response_code() != EResponseCode::OK) { @@ -79,11 +79,11 @@ auto HttpClient::json_get(Ref path, Span> headers) } template -auto HttpClient::json_post(Ref path, Span> headers, +auto HttpClient::json_post(Ref path, Span headers, Ref body) -> Result { - Const encoded_body = AU_TRY(Json::encode_struct(body)); + const String encoded_body = AU_TRY(Json::encode_struct(body)); - Const raw_response = + const String raw_response = AU_TRY(raw_post(path, headers, encoded_body, "application/json")); if (last_response_code() != EResponseCode::OK) { diff --git a/Src/IACore/inc/IACore/Http/Common.hpp b/Src/IACore/inc/IACore/Http/Common.hpp index 96216e9..12d12c9 100644 --- a/Src/IACore/inc/IACore/Http/Common.hpp +++ b/Src/IACore/inc/IACore/Http/Common.hpp @@ -130,20 +130,20 @@ public: static auto url_encode(Ref value) -> String; static auto url_decode(Ref value) -> String; - static auto header_type_to_string(Const type) -> String; + static auto header_type_to_string(const EHeaderType type) -> String; - static inline auto create_header(Const key, Ref value) + static inline auto create_header(const EHeaderType key, Ref value) -> Header; static inline auto create_header(Ref key, Ref value) -> Header; - static auto is_success_response_code(Const code) -> bool; + static auto is_success_response_code(const EResponseCode code) -> bool; protected: HttpCommon() = default; }; -auto HttpCommon::create_header(Const key, Ref value) +auto HttpCommon::create_header(const EHeaderType key, Ref value) -> HttpCommon::Header { return Header{header_type_to_string(key), value}; } diff --git a/Src/IACore/inc/IACore/Http/Server.hpp b/Src/IACore/inc/IACore/Http/Server.hpp index 80ed89f..024de1b 100644 --- a/Src/IACore/inc/IACore/Http/Server.hpp +++ b/Src/IACore/inc/IACore/Http/Server.hpp @@ -46,7 +46,7 @@ public: Mut content_type = "text/plain"; void set_content(Ref content, Ref type); - void set_status(Const status_code); + void set_status(const EResponseCode status_code); void add_header(Ref key, Ref value); }; @@ -62,25 +62,25 @@ public: auto operator=(HttpServer &&) -> HttpServer & = delete; auto operator=(const HttpServer &) -> HttpServer & = delete; - auto listen(Ref host, Const port) -> Result; + auto listen(Ref host, const u32 port) -> Result; void stop(); auto is_running() const -> bool; - void get(Ref pattern, Const handler); - void post(Ref pattern, Const handler); - void put(Ref pattern, Const handler); - void del(Ref pattern, Const handler); - void options(Ref pattern, Const handler); + void get(Ref pattern, const Handler handler); + void post(Ref pattern, const Handler handler); + void put(Ref pattern, const Handler handler); + void del(Ref pattern, const Handler handler); + void options(Ref pattern, const Handler handler); template void json_get(Ref pattern, - Const(Ref)>> handler); + const std::function)>> handler); template void json_post( Ref pattern, - Const(Ref)>> handler); + const std::function)>> handler); protected: HttpServer(); @@ -89,22 +89,22 @@ private: Mut m_server; void register_handler(Ref method, Ref pattern, - Const handler); + const Handler handler); }; template void HttpServer::json_get( Ref pattern, - Const(Ref)>> handler) { + const std::function)>> handler) { get(pattern, [handler](Ref req, MutRef res) { - Const> result = handler(req); + const Result result = handler(req); if (!result) { res.set_status(EResponseCode::INTERNAL_SERVER_ERROR); res.set_content(result.error(), "text/plain"); return; } - Const> json_res = Json::encode_struct(*result); + const Result json_res = Json::encode_struct(*result); if (!json_res) { res.set_status(EResponseCode::INTERNAL_SERVER_ERROR); res.set_content("Failed to encode JSON response", "text/plain"); @@ -119,9 +119,9 @@ void HttpServer::json_get( template void HttpServer::json_post( Ref pattern, - Const(Ref)>> handler) { + const std::function)>> handler) { post(pattern, [handler](Ref req, MutRef res) { - Const> payload = + const Result payload = Json::parse_to_struct(req.body); if (!payload) { res.set_status(EResponseCode::BAD_REQUEST); @@ -129,14 +129,14 @@ void HttpServer::json_post( return; } - Const> result = handler(*payload); + const Result result = handler(*payload); if (!result) { res.set_status(EResponseCode::INTERNAL_SERVER_ERROR); res.set_content(result.error(), "text/plain"); return; } - Const> json_res = Json::encode_struct(*result); + const Result json_res = Json::encode_struct(*result); if (!json_res) { res.set_status(EResponseCode::INTERNAL_SERVER_ERROR); res.set_content("Failed to encode JSON response", "text/plain"); diff --git a/Src/IACore/inc/IACore/IACore.hpp b/Src/IACore/inc/IACore/IACore.hpp index 5a1a44f..4bcf3d2 100644 --- a/Src/IACore/inc/IACore/IACore.hpp +++ b/Src/IACore/inc/IACore/IACore.hpp @@ -21,7 +21,7 @@ #define IACORE_MAIN() \ auto _app_entry(IACore::Ref> args) \ -> IACore::Result; \ - auto main(Const argc, Mut argv[]) -> int { \ + auto main(int argc, Mut argv[]) -> int { \ IACore::Mut exit_code = 0; \ IACore::initialize(); \ IACore::Mut> args; \ @@ -29,7 +29,7 @@ for (IACore::Mut i = 0; i < argc; ++i) { \ args.push_back(argv[i]); \ } \ - IACore::Const> result = _app_entry(args); \ + IACore::Result result = _app_entry(args); \ if (!result) { \ IACore::Logger::error("Application exited with an error: '{}'.", \ result.error()); \ diff --git a/Src/IACore/inc/IACore/IATest.hpp b/Src/IACore/inc/IACore/IATest.hpp index a6173ff..2769ff4 100644 --- a/Src/IACore/inc/IACore/IATest.hpp +++ b/Src/IACore/inc/IACore/IATest.hpp @@ -105,8 +105,7 @@ public: protected: template - auto _test_eq(Ref lhs, Ref rhs, Const description) - -> bool { + auto _test_eq(Ref lhs, Ref rhs, const char *description) -> bool { if (lhs != rhs) { print_fail(description, to_string(lhs), to_string(rhs)); return false; @@ -115,8 +114,7 @@ protected: } template - auto _test_neq(Ref lhs, Ref rhs, Const description) - -> bool { + auto _test_neq(Ref lhs, Ref rhs, const char *description) -> bool { if (lhs == rhs) { print_fail(description, to_string(lhs), "NOT " + to_string(rhs)); return false; @@ -125,11 +123,10 @@ protected: } template - auto _test_approx(Const lhs, Const rhs, Const description) - -> bool { + auto _test_approx(const T lhs, const T rhs, const char *description) -> bool { static_assert(std::is_floating_point_v, "Approx only works for floats/doubles"); - Const diff = std::abs(lhs - rhs); + const T diff = std::abs(lhs - rhs); if (diff > static_cast(0.0001)) { print_fail(description, to_string(lhs), to_string(rhs)); return false; @@ -137,7 +134,7 @@ protected: return true; } - auto _test(Const value, Const description) -> bool { + auto _test(const bool value, const char *description) -> bool { if (!value) { std::cout << console::BLUE << " " << description << "... " << console::RED << "FAILED" << console::RESET << "\n"; @@ -146,7 +143,7 @@ protected: return true; } - auto _test_not(Const value, Const description) -> bool { + auto _test_not(const bool value, const char *description) -> bool { if (value) { std::cout << console::BLUE << " " << description << "... " << console::RED << "FAILED" << console::RESET << "\n"; @@ -155,13 +152,12 @@ protected: return true; } - auto _test_unit(Mut functor, Const name) -> void { + auto _test_unit(Mut functor, const char *name) -> void { m_units.push_back({name, std::move(functor)}); } private: - auto print_fail(Const desc, Ref v1, Ref v2) - -> void { + auto print_fail(const char *desc, Ref v1, Ref v2) -> void { std::cout << console::BLUE << " " << desc << "... " << console::RED << "FAILED" << console::RESET << "\n"; std::cout << console::RED << " Expected: " << v2 << console::RESET @@ -215,7 +211,7 @@ auto Runner::test_block() -> void { << console::RESET; } - Const result = v.functor(); + const bool result = v.functor(); if (!result) { m_fail_count++; @@ -237,7 +233,7 @@ auto Runner::summarize() -> void { if (m_fail_count == 0) { std::cout << "\n\tALL TESTS PASSED!\n\n"; } else { - Const success_rate = + const f64 success_rate = (100.0 * static_cast(m_test_count - m_fail_count) / static_cast(m_test_count)); std::cout << console::RED << m_fail_count << " OF " << m_test_count diff --git a/Src/IACore/inc/IACore/IPC.hpp b/Src/IACore/inc/IACore/IPC.hpp index a0cc4b8..2743cd2 100644 --- a/Src/IACore/inc/IACore/IPC.hpp +++ b/Src/IACore/inc/IACore/IPC.hpp @@ -35,7 +35,7 @@ struct alignas(64) IpcSharedMemoryLayout { Mut
meta; // Pad to ensure MONI starts on a fresh cache line (64 bytes) - Const> _pad0; + const Array _pad0; // ========================================================= // RING BUFFER CONTROL BLOCKS @@ -56,7 +56,7 @@ struct alignas(64) IpcSharedMemoryLayout { Mut mino_data_size; // Pad to ensure the actual Data Buffer starts on a fresh cache line - Const> _pad1; + const Array _pad1; static constexpr auto get_header_size() -> usize { return sizeof(IpcSharedMemoryLayout); @@ -73,17 +73,17 @@ public: // When Manager spawns a node, `connection_string` is passed // as the first command line argument - auto connect(Const connection_string) -> Result; + auto connect(const char *connection_string) -> Result; auto update() -> void; - auto send_signal(Const signal) -> void; - auto send_packet(Const packet_id, Const>> payload) + auto send_signal(const u8 signal) -> void; + auto send_packet(const u16 packet_id, const Span payload) -> Result; protected: - virtual auto on_signal(Const signal) -> void = 0; - virtual auto on_packet(Const packet_id, Const>> payload) + virtual auto on_signal(const u8 signal) -> void = 0; + virtual auto on_packet(const u16 packet_id, const Span payload) -> void = 0; private: @@ -116,13 +116,13 @@ class IpcManager { Mut is_ready{false}; - auto send_signal(Const signal) -> void; - auto send_packet(Const packet_id, Const>> payload) + auto send_signal(const u8 signal) -> void; + auto send_packet(const u16 packet_id, const Span payload) -> Result; }; public: - static constexpr Const DEFAULT_NODE_SHARED_MEMORY_SIZE = 4 * 1024 * 1024; + static constexpr const u32 DEFAULT_NODE_SHARED_MEMORY_SIZE = 4 * 1024 * 1024; public: virtual ~IpcManager(); @@ -131,22 +131,22 @@ public: auto spawn_node(Ref executable_path, - Const shared_memory_size = DEFAULT_NODE_SHARED_MEMORY_SIZE) + const u32 shared_memory_size = DEFAULT_NODE_SHARED_MEMORY_SIZE) -> Result; - auto wait_till_node_is_online(Const node) -> bool; + auto wait_till_node_is_online(const NativeProcessID node) -> bool; - auto shutdown_node(Const node) -> void; + auto shutdown_node(const NativeProcessID node) -> void; - auto send_signal(Const node, Const signal) -> void; - auto send_packet(Const node, Const packet_id, - Const>> payload) -> Result; + auto send_signal(const NativeProcessID node, const u8 signal) -> void; + auto send_packet(const NativeProcessID node, const u16 packet_id, + const Span payload) -> Result; protected: - virtual auto on_signal(Const node, Const signal) + virtual auto on_signal(const NativeProcessID node, const u8 signal) -> void = 0; - virtual auto on_packet(Const node, Const packet_id, - Const>> payload) -> void = 0; + virtual auto on_packet(const NativeProcessID node, const u16 packet_id, + const Span payload) -> void = 0; private: Mut> m_receive_buffer; diff --git a/Src/IACore/inc/IACore/JSON.hpp b/Src/IACore/inc/IACore/JSON.hpp index 16f12ce..00cc593 100644 --- a/Src/IACore/inc/IACore/JSON.hpp +++ b/Src/IACore/inc/IACore/JSON.hpp @@ -48,7 +48,7 @@ private: class Json { private: - static constexpr Const GLAZE_OPTS = + static constexpr const glz::opts GLAZE_OPTS = glz::opts{.error_on_unknown_keys = false}; public: @@ -65,7 +65,7 @@ public: }; inline auto Json::parse(Ref json_str) -> Result { - Const res = + const nlohmann::json res = nlohmann::json::parse(json_str, nullptr, false, true); if (res.is_discarded()) { @@ -80,7 +80,7 @@ inline auto Json::parse_read_only(Ref json_str) Mut root; - Const error = parser->parse(json_str).get(root); + const simdjson::error_code error = parser->parse(json_str).get(root); if (error) { return fail("JSON Error: {}", simdjson::error_message(error)); @@ -97,7 +97,7 @@ template inline auto Json::parse_to_struct(Ref json_str) -> Result { Mut result{}; - Const err = glz::read(result, json_str); + const glz::error_ctx err = glz::read(result, json_str); if (err) { return fail("JSON Struct Parse Error: {}", @@ -109,7 +109,7 @@ inline auto Json::parse_to_struct(Ref json_str) -> Result { template inline auto Json::encode_struct(Ref data) -> Result { Mut result; - Const err = glz::write_json(data, result); + const glz::error_ctx err = glz::write_json(data, result); if (err) { return fail("JSON Struct Encode Error"); diff --git a/Src/IACore/inc/IACore/Logger.hpp b/Src/IACore/inc/IACore/Logger.hpp index e801e81..b22346d 100644 --- a/Src/IACore/inc/IACore/Logger.hpp +++ b/Src/IACore/inc/IACore/Logger.hpp @@ -33,36 +33,35 @@ public: enum class LogLevel { Trace, Debug, Info, Warn, Error }; public: - static auto enable_logging_to_disk(Const file_path) - -> Result; - static auto set_log_level(Const log_level) -> void; + static auto enable_logging_to_disk(const char *file_path) -> Result; + static auto set_log_level(const LogLevel log_level) -> void; template - static auto trace(Const> fmt, + static auto trace(const std::format_string fmt, ForwardRef... args) -> void { log_trace(std::vformat(fmt.get(), std::make_format_args(args...))); } template - static auto debug(Const> fmt, + static auto debug(const std::format_string fmt, ForwardRef... args) -> void { log_debug(std::vformat(fmt.get(), std::make_format_args(args...))); } template - static auto info(Const> fmt, + static auto info(const std::format_string fmt, ForwardRef... args) -> void { log_info(std::vformat(fmt.get(), std::make_format_args(args...))); } template - static auto warn(Const> fmt, + static auto warn(const std::format_string fmt, ForwardRef... args) -> void { log_warn(std::vformat(fmt.get(), std::make_format_args(args...))); } template - static auto error(Const> fmt, + static auto error(const std::format_string fmt, ForwardRef... args) -> void { log_error(std::vformat(fmt.get(), std::make_format_args(args...))); } @@ -107,7 +106,7 @@ private: } #endif - static auto log_internal(Const prefix, Const tag, + static auto log_internal(const char *prefix, const char *tag, ForwardRef msg) -> void; private: diff --git a/Src/IACore/inc/IACore/PCH.hpp b/Src/IACore/inc/IACore/PCH.hpp index 59500f6..a58aab8 100644 --- a/Src/IACore/inc/IACore/PCH.hpp +++ b/Src/IACore/inc/IACore/PCH.hpp @@ -82,14 +82,14 @@ namespace Env { using namespace Auxid::Env; #if IA_PLATFORM_WINDOWS -constexpr Const IS_WINDOWS = true; -constexpr Const IS_UNIX = false; +constexpr const bool IS_WINDOWS = true; +constexpr const bool IS_UNIX = false; #else -constexpr Const IS_WINDOWS = false; -constexpr Const IS_UNIX = true; +constexpr const bool IS_WINDOWS = false; +constexpr const bool IS_UNIX = true; #endif -constexpr Const MAX_PATH_LEN = 4096; +constexpr const usize MAX_PATH_LEN = 4096; } // namespace Env @@ -120,13 +120,13 @@ struct Version { // Console Colors // ============================================================================= namespace console { -constexpr Const RESET = "\033[0m"; -constexpr Const RED = "\033[31m"; -constexpr Const GREEN = "\033[32m"; -constexpr Const YELLOW = "\033[33m"; -constexpr Const BLUE = "\033[34m"; -constexpr Const MAGENTA = "\033[35m"; -constexpr Const CYAN = "\033[36m"; +constexpr const char *RESET = "\033[0m"; +constexpr const char *RED = "\033[31m"; +constexpr const char *GREEN = "\033[32m"; +constexpr const char *YELLOW = "\033[33m"; +constexpr const char *BLUE = "\033[34m"; +constexpr const char *MAGENTA = "\033[35m"; +constexpr const char *CYAN = "\033[36m"; } // namespace console } // namespace IACore diff --git a/Src/IACore/inc/IACore/Platform.hpp b/Src/IACore/inc/IACore/Platform.hpp index b7e452c..49bf133 100644 --- a/Src/IACore/inc/IACore/Platform.hpp +++ b/Src/IACore/inc/IACore/Platform.hpp @@ -37,8 +37,8 @@ public: static auto check_cpu() -> bool; #if IA_ARCH_X64 - static auto cpuid(Const function, Const sub_function, - Mut out) -> void; + static auto cpuid(const i32 function, const i32 sub_function, Mut out) + -> void; #endif static auto get_architecture_name() -> const char *; diff --git a/Src/IACore/inc/IACore/ProcessOps.hpp b/Src/IACore/inc/IACore/ProcessOps.hpp index b21d9e6..7f7ba04 100644 --- a/Src/IACore/inc/IACore/ProcessOps.hpp +++ b/Src/IACore/inc/IACore/ProcessOps.hpp @@ -44,13 +44,13 @@ public: static auto spawn_process_sync( Ref command, Ref args, - Const)>> on_output_line_callback) + const std::function on_output_line_callback) -> Result; static auto spawn_process_async( Ref command, Ref args, - Const)>> on_output_line_callback, - Const>)>> on_finish_callback) + const std::function on_output_line_callback, + const std::function)> on_finish_callback) -> Result>; static auto terminate_process(Ref> handle) -> void; @@ -58,12 +58,12 @@ public: private: static auto spawn_process_windows( Ref command, Ref args, - Const)>> on_output_line_callback, + const std::function on_output_line_callback, MutRef> id) -> Result; static auto spawn_process_posix( Ref command, Ref args, - Const)>> on_output_line_callback, + const std::function on_output_line_callback, MutRef> id) -> Result; }; } // namespace IACore \ No newline at end of file diff --git a/Src/IACore/inc/IACore/SIMD.hpp b/Src/IACore/inc/IACore/SIMD.hpp index c944c55..872bf32 100644 --- a/Src/IACore/inc/IACore/SIMD.hpp +++ b/Src/IACore/inc/IACore/SIMD.hpp @@ -41,10 +41,9 @@ class alignas(16) IntVec4 { public: IntVec4() = default; - inline explicit IntVec4(Const s); - inline explicit IntVec4(Const values); - inline explicit IntVec4(Const a, Const b, Const c, - Const d); + inline explicit IntVec4(const u32 s); + inline explicit IntVec4(const u32 *values); + inline explicit IntVec4(const u32 a, const u32 b, const u32 c, const u32 d); inline auto operator+(Ref other) const -> IntVec4; inline auto operator-(Ref other) const -> IntVec4; @@ -55,44 +54,43 @@ public: inline auto operator^(Ref other) const -> IntVec4; inline auto operator~() const -> IntVec4; - inline auto operator<<(Const amount) const -> IntVec4; - inline auto operator>>(Const amount) const -> IntVec4; + inline auto operator<<(const u32 amount) const -> IntVec4; + inline auto operator>>(const u32 amount) const -> IntVec4; [[nodiscard]] inline auto sat_add(Ref other) const -> IntVec4; [[nodiscard]] inline auto sat_sub(Ref other) const -> IntVec4; - [[nodiscard]] inline auto clamp(Const min, Const max) const + [[nodiscard]] inline auto clamp(const u32 min, const u32 max) const -> IntVec4; [[nodiscard]] inline auto mult_add(Ref multiplier, Ref addend) const -> IntVec4; inline auto store(Mut values) -> void; - static inline auto load(Const values) -> IntVec4; + static inline auto load(const u32 *values) -> IntVec4; private: using Tag = hn::FixedTag; Mut> m_data; - inline explicit IntVec4(Const> v) : m_data(v) {} + inline explicit IntVec4(const hn::Vec v) : m_data(v) {} }; class alignas(16) FloatVec4 { public: FloatVec4() = default; - inline explicit FloatVec4(Const s); - inline explicit FloatVec4(Const values); - inline explicit FloatVec4(Const a, Const b, Const c, - Const d); + inline explicit FloatVec4(const f32 s); + inline explicit FloatVec4(const f32 *values); + inline explicit FloatVec4(const f32 a, const f32 b, const f32 c, const f32 d); inline auto operator+(Ref other) const -> FloatVec4; inline auto operator-(Ref other) const -> FloatVec4; inline auto operator*(Ref other) const -> FloatVec4; inline auto operator/(Ref other) const -> FloatVec4; - [[nodiscard]] inline auto clamp(Const min, Const max) const + [[nodiscard]] inline auto clamp(const f32 min, const f32 max) const -> FloatVec4; [[nodiscard]] inline auto abs() const -> FloatVec4; @@ -106,30 +104,30 @@ public: Ref addend) const -> FloatVec4; inline auto store(Mut values) -> void; - static inline auto load(Const values) -> FloatVec4; + static inline auto load(const f32 *values) -> FloatVec4; private: using Tag = hn::FixedTag; Mut> m_data; - inline explicit FloatVec4(Const> v) : m_data(v) {} + inline explicit FloatVec4(const hn::Vec v) : m_data(v) {} }; } // namespace IACore namespace IACore { -IntVec4::IntVec4(Const s) { - Const d; +IntVec4::IntVec4(const u32 s) { + const Tag d; m_data = hn::Set(d, s); } -IntVec4::IntVec4(Const values) { - Const data; +IntVec4::IntVec4(const u32 *values) { + const Tag data; m_data = hn::Load(data, values); } -IntVec4::IntVec4(Const a, Const b, Const c, Const d) { - Const data; +IntVec4::IntVec4(const u32 a, const u32 b, const u32 c, const u32 d) { + const Tag data; alignas(16) Mut> values = {a, b, c, d}; m_data = hn::Load(data, values.data()); } @@ -160,11 +158,11 @@ auto IntVec4::operator^(Ref other) const -> IntVec4 { auto IntVec4::operator~() const -> IntVec4 { return IntVec4(hn::Not(m_data)); } -auto IntVec4::operator<<(Const amount) const -> IntVec4 { +auto IntVec4::operator<<(const u32 amount) const -> IntVec4 { return IntVec4(hn::ShiftLeftSame(m_data, amount)); } -auto IntVec4::operator>>(Const amount) const -> IntVec4 { +auto IntVec4::operator>>(const u32 amount) const -> IntVec4 { return IntVec4(hn::ShiftRightSame(m_data, amount)); } @@ -181,37 +179,37 @@ auto IntVec4::sat_sub(Ref other) const -> IntVec4 { return IntVec4(hn::SaturatedSub(m_data, other.m_data)); } -auto IntVec4::clamp(Const min, Const max) const -> IntVec4 { - Const d; - Const> v_min = hn::Set(d, min); - Const> v_max = hn::Set(d, max); +auto IntVec4::clamp(const u32 min, const u32 max) const -> IntVec4 { + const Tag d; + const hn::Vec v_min = hn::Set(d, min); + const hn::Vec v_max = hn::Set(d, max); return IntVec4(hn::Min(hn::Max(m_data, v_min), v_max)); } auto IntVec4::store(Mut values) -> void { - Const d; + const Tag d; hn::Store(m_data, d, values); } -auto IntVec4::load(Const values) -> IntVec4 { - Const d; +auto IntVec4::load(const u32 *values) -> IntVec4 { + const Tag d; return IntVec4(hn::Load(d, values)); } } // namespace IACore namespace IACore { -FloatVec4::FloatVec4(Const s) { - Const d; +FloatVec4::FloatVec4(const f32 s) { + const Tag d; m_data = hn::Set(d, s); } -FloatVec4::FloatVec4(Const values) { - Const d; +FloatVec4::FloatVec4(const f32 *values) { + const Tag d; m_data = hn::Load(d, values); } -FloatVec4::FloatVec4(Const a, Const b, Const c, Const d) { - Const data; +FloatVec4::FloatVec4(const f32 a, const f32 b, const f32 c, const f32 d) { + const Tag data; alignas(16) Mut> temp = {a, b, c, d}; m_data = hn::Load(data, temp.data()); } @@ -237,10 +235,10 @@ auto FloatVec4::mult_add(Ref multiplier, Ref addend) const return FloatVec4(hn::MulAdd(m_data, multiplier.m_data, addend.m_data)); } -auto FloatVec4::clamp(Const min, Const max) const -> FloatVec4 { - Const d; - Const> v_min = hn::Set(d, min); - Const> v_max = hn::Set(d, max); +auto FloatVec4::clamp(const f32 min, const f32 max) const -> FloatVec4 { + const Tag d; + const hn::Vec v_min = hn::Set(d, min); + const hn::Vec v_max = hn::Set(d, max); return FloatVec4(hn::Min(hn::Max(m_data, v_min), v_max)); } @@ -255,26 +253,26 @@ auto FloatVec4::rsqrt() const -> FloatVec4 { auto FloatVec4::abs() const -> FloatVec4 { return FloatVec4(hn::Abs(m_data)); } auto FloatVec4::dot(Ref other) const -> f32 { - Const d; - Const> v_mul = hn::Mul(m_data, other.m_data); + const Tag d; + const hn::Vec v_mul = hn::Mul(m_data, other.m_data); return hn::ReduceSum(d, v_mul); } auto FloatVec4::normalize() const -> FloatVec4 { - Const d; - Const> v_mul = hn::Mul(m_data, m_data); - Const> v_len_sq = hn::SumOfLanes(d, v_mul); - Const> v_inv_len = hn::ApproximateReciprocalSqrt(v_len_sq); + const Tag d; + const hn::Vec v_mul = hn::Mul(m_data, m_data); + const hn::Vec v_len_sq = hn::SumOfLanes(d, v_mul); + const hn::Vec v_inv_len = hn::ApproximateReciprocalSqrt(v_len_sq); return FloatVec4(hn::Mul(m_data, v_inv_len)); } auto FloatVec4::store(Mut values) -> void { - Const d; + const Tag d; hn::Store(m_data, d, values); } -auto FloatVec4::load(Const values) -> FloatVec4 { - Const d; +auto FloatVec4::load(const f32 *values) -> FloatVec4 { + const Tag d; return FloatVec4(hn::Load(d, values)); } } // namespace IACore \ No newline at end of file diff --git a/Src/IACore/inc/IACore/SocketOps.hpp b/Src/IACore/inc/IACore/SocketOps.hpp index 440570f..b636a54 100644 --- a/Src/IACore/inc/IACore/SocketOps.hpp +++ b/Src/IACore/inc/IACore/SocketOps.hpp @@ -53,7 +53,7 @@ public: } #if IA_PLATFORM_WINDOWS Mut wsa_data; - Const res = WSAStartup(MAKEWORD(2, 2), &wsa_data); + const i32 res = WSAStartup(MAKEWORD(2, 2), &wsa_data); if (res != 0) { s_init_count--; return fail("WSAStartup failed with error: {}", res); @@ -77,29 +77,29 @@ public: static auto is_initialized() -> bool { return s_init_count > 0; } - static auto is_port_available_tcp(Const port) -> bool { + static auto is_port_available_tcp(const u16 port) -> bool { return is_port_available(port, SOCK_STREAM); } - static auto is_port_available_udp(Const port) -> bool { + static auto is_port_available_udp(const u16 port) -> bool { return is_port_available(port, SOCK_DGRAM); } static auto is_would_block() -> bool; - static auto close(Const sock) -> void; + static auto close(const SocketHandle sock) -> void; - static auto listen(Const sock, Const queue_size = 5) + static auto listen(const SocketHandle sock, const i32 queue_size = 5) -> Result; static auto create_unix_socket() -> Result; - static auto bind_unix_socket(Const sock, - Const path) -> Result; - static auto connect_unix_socket(Const sock, - Const path) -> Result; + static auto bind_unix_socket(const SocketHandle sock, const char *path) + -> Result; + static auto connect_unix_socket(const SocketHandle sock, const char *path) + -> Result; - static auto unlink_file(Const path) -> void { + static auto unlink_file(const char *path) -> void { #if IA_PLATFORM_WINDOWS DeleteFileA(path); #elif IA_PLATFORM_UNIX @@ -108,7 +108,7 @@ public: } private: - static auto is_port_available(Const port, Const type) -> bool; + static auto is_port_available(const u16 port, const i32 type) -> bool; private: static Mut s_init_count; diff --git a/Src/IACore/inc/IACore/StreamReader.hpp b/Src/IACore/inc/IACore/StreamReader.hpp index 83543d6..b57bfea 100644 --- a/Src/IACore/inc/IACore/StreamReader.hpp +++ b/Src/IACore/inc/IACore/StreamReader.hpp @@ -31,7 +31,7 @@ public: static auto create_from_file(Ref path) -> Result; explicit StreamReader(ForwardRef> data); - explicit StreamReader(Const> data); + explicit StreamReader(const Span data); ~StreamReader(); StreamReader(ForwardRef other); @@ -40,17 +40,17 @@ public: StreamReader(Ref) = delete; auto operator=(Ref) -> MutRef = delete; - auto read(Mut buffer, Const size) -> Result; + auto read(Mut buffer, const usize size) -> Result; template [[nodiscard("Check for EOF")]] auto read() -> Result; - auto skip(Const amount) -> void { + auto skip(const usize amount) -> void { m_cursor = std::min(m_cursor + amount, m_data_size); } - auto seek(Const pos) -> void { + auto seek(const usize pos) -> void { m_cursor = (pos > m_data_size) ? m_data_size : pos; } @@ -72,7 +72,7 @@ private: Mut m_storage_type = StorageType::NonOwning; }; -inline auto StreamReader::read(Mut buffer, Const size) +inline auto StreamReader::read(Mut buffer, const usize size) -> Result { if (m_cursor + size > m_data_size) [[unlikely]] { return fail("Unexpected EOF while reading"); @@ -90,7 +90,7 @@ inline auto StreamReader::read() -> Result { static_assert(std::is_trivially_copyable_v, "T must be trivially copyable to read via memcpy"); - constexpr Const SIZE = sizeof(T); + constexpr const usize SIZE = sizeof(T); if (m_cursor + SIZE > m_data_size) [[unlikely]] { return fail("Unexpected EOF while reading"); diff --git a/Src/IACore/inc/IACore/StreamWriter.hpp b/Src/IACore/inc/IACore/StreamWriter.hpp index 1c71d43..6c3d3d2 100644 --- a/Src/IACore/inc/IACore/StreamWriter.hpp +++ b/Src/IACore/inc/IACore/StreamWriter.hpp @@ -30,7 +30,7 @@ public: static auto create_from_file(Ref path) -> Result; StreamWriter(); - explicit StreamWriter(Const> data); + explicit StreamWriter(const Span data); StreamWriter(ForwardRef other); auto operator=(ForwardRef other) -> MutRef; @@ -40,8 +40,8 @@ public: ~StreamWriter(); - auto write(Const byte, Const count) -> Result; - auto write(Const buffer, Const size) -> Result; + auto write(const u8 byte, const usize count) -> Result; + auto write(const void *buffer, const usize size) -> Result; template auto write(Ref value) -> Result; diff --git a/Src/IACore/inc/IACore/StringOps.hpp b/Src/IACore/inc/IACore/StringOps.hpp index be6094c..cdd3593 100644 --- a/Src/IACore/inc/IACore/StringOps.hpp +++ b/Src/IACore/inc/IACore/StringOps.hpp @@ -20,7 +20,7 @@ namespace IACore { class StringOps { public: - static auto encode_base64(Const>> data) -> String; + static auto encode_base64(const Span data) -> String; static auto decode_base64(Ref data) -> Vec; }; } // namespace IACore \ No newline at end of file diff --git a/Src/IACore/inc/IACore/Utils.hpp b/Src/IACore/inc/IACore/Utils.hpp index 36e1431..ba551b6 100644 --- a/Src/IACore/inc/IACore/Utils.hpp +++ b/Src/IACore/inc/IACore/Utils.hpp @@ -29,14 +29,14 @@ public: static auto get_seconds_count() -> f64; static auto get_random() -> f32; - static auto get_random(Const max) -> u64; - static auto get_random(Const min, Const max) -> i64; + static auto get_random(const u64 max) -> u64; + static auto get_random(const i64 min, const i64 max) -> i64; - static auto sleep(Const milliseconds) -> void; + static auto sleep(const u64 milliseconds) -> void; - static auto binary_to_hex_string(Const>> data) -> String; + static auto binary_to_hex_string(const Span data) -> String; - static auto hex_string_to_binary(Const hex) -> Result>; + static auto hex_string_to_binary(const StringView hex) -> Result>; template inline static auto sort(ForwardRef range) -> void { @@ -60,11 +60,11 @@ public: Mut h = 0; if constexpr (std::is_constructible_v) { - Const sv(v); - Const> hasher; + const StringView sv(v); + const ankerl::unordered_dense::hash hasher; h = hasher(sv); } else { - Const> hasher; + const ankerl::unordered_dense::hash hasher; h = hasher(v); } @@ -79,7 +79,7 @@ public: } template - inline static auto compute_hash_flat(Ref obj, Const... members) + inline static auto compute_hash_flat(Ref obj, const MemberPtrs... members) -> u64 { Mut seed = 0; (hash_combine(seed, obj.*members), ...); diff --git a/Src/IACore/inc/IACore/XML.hpp b/Src/IACore/inc/IACore/XML.hpp index 09602f6..0226430 100644 --- a/Src/IACore/inc/IACore/XML.hpp +++ b/Src/IACore/inc/IACore/XML.hpp @@ -29,9 +29,9 @@ public: static auto parse_from_string(Ref data) -> Result; static auto parse_from_file(Ref path) -> Result; - static auto serialize_to_string(Ref node, Const escape = false) + static auto serialize_to_string(Ref node, const bool escape = false) -> String; - static auto serialize_to_string(Ref doc, Const escape = false) + static auto serialize_to_string(Ref doc, const bool escape = false) -> String; static auto escape_xml_string(Ref xml) -> String; diff --git a/Tests/Unit/Main.cpp b/Tests/Unit/Main.cpp index e08f918..0ba2084 100644 --- a/Tests/Unit/Main.cpp +++ b/Tests/Unit/Main.cpp @@ -33,7 +33,7 @@ IACORE_MAIN() { << "===============================================================\n" << console::RESET << "\n"; - Const result = Test::TestRegistry::run_all(); + const i32 result = Test::TestRegistry::run_all(); SocketOps::terminate();