diff options
author | Dominick Allen <djallen@librehumanitas.org> | 2025-01-04 12:02:45 -0600 |
---|---|---|
committer | Dominick Allen <djallen@librehumanitas.org> | 2025-01-04 12:02:45 -0600 |
commit | 1d357adfa19725ee69fb267a363f1fd217b1272f (patch) | |
tree | 8d8710ba8ba7dff0b3da6b073fbb94f1a7b03ec5 /source | |
parent | 0b400af9519444deef4cc6ad2c43c30e2092ab4f (diff) |
Diffstat (limited to 'source')
-rw-r--r-- | source/fud_allocator.cpp | 2 | ||||
-rw-r--r-- | source/fud_csv.cpp | 1 | ||||
-rw-r--r-- | source/fud_sqlite.cpp | 24 | ||||
-rw-r--r-- | source/fud_string.cpp | 13 |
4 files changed, 32 insertions, 8 deletions
diff --git a/source/fud_allocator.cpp b/source/fud_allocator.cpp index 3f58fb0..08a64fa 100644 --- a/source/fud_allocator.cpp +++ b/source/fud_allocator.cpp @@ -43,6 +43,7 @@ bool FudAllocator::isEqual(const Allocator& rhs) const return &rhs == static_cast<const Allocator*>(this); } +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) FudAllocator globalFudAllocator{}; Result<std::byte*, FudStatus> NullAllocator::allocate(size_t bytes, size_t alignment) @@ -63,6 +64,7 @@ bool NullAllocator::isEqual(const Allocator& rhs) const return &rhs == static_cast<const Allocator*>(this); } +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) NullAllocator globalNullAllocator{}; } // namespace fud diff --git a/source/fud_csv.cpp b/source/fud_csv.cpp index 260a4ff..82935e4 100644 --- a/source/fud_csv.cpp +++ b/source/fud_csv.cpp @@ -141,7 +141,6 @@ FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, size_t maxExtraAttempts) { - static_cast<void>(csv); constexpr size_t BufferSize = 256; SimpleStackAllocator<BufferSize> stackAllocator{}; TextBuffer textBuffer{stackAllocator}; diff --git a/source/fud_sqlite.cpp b/source/fud_sqlite.cpp index 735389f..4a7187f 100644 --- a/source/fud_sqlite.cpp +++ b/source/fud_sqlite.cpp @@ -26,23 +26,33 @@ SqliteDbResult SqliteDb::make(const String& name, SqliteOpenMode mode, int extra if (copyResult != FudStatus::Success) { return SqliteDbResult::error(copyResult); } - sqlDb.m_mode = mode; - sqlDb.m_extraFlags = extraFlags; - auto status = sqlDb.initialize(); - if (status != FudStatus::Success) { - return SqliteDbResult::error(status); + return finishMake(mode, extraFlags, std::move(sqlDb)); +} + +SqliteDbResult SqliteDb::make(StringView name, SqliteOpenMode mode, int extraFlags) +{ + SqliteDb sqlDb{}; + auto nameResult{String::from(name)}; + if (nameResult.isError()) { + return SqliteDbResult::error(nameResult.takeError()); } - return SqliteDbResult::okay(std::move(sqlDb)); + sqlDb.m_name = nameResult.takeOkay(); + return finishMake(mode, extraFlags, std::move(sqlDb)); } SqliteDbResult SqliteDb::make(const char* cStrName, SqliteOpenMode mode, int extraFlags) { + SqliteDb sqlDb{}; auto nameResult = String::makeFromCString(cStrName); if (nameResult.isError()) { return SqliteDbResult::error(nameResult); } - SqliteDb sqlDb{}; sqlDb.m_name = nameResult.takeOkay(); + return finishMake(mode, extraFlags, std::move(sqlDb)); +} + +SqliteDbResult SqliteDb::finishMake(SqliteOpenMode& mode, int& extraFlags, SqliteDb&& sqlDb) +{ sqlDb.m_mode = mode; sqlDb.m_extraFlags = extraFlags; auto status = sqlDb.initialize(); diff --git a/source/fud_string.cpp b/source/fud_string.cpp index 37a2a4b..a2a62f4 100644 --- a/source/fud_string.cpp +++ b/source/fud_string.cpp @@ -21,6 +21,19 @@ namespace fud { +StringResult String::withAllocator(Allocator& allocator) +{ + if (!String::allocatorValid(&allocator)) + { + return Error{FudStatus::ArgumentInvalid}; + } + + String output{}; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + output.m_allocator = reinterpret_cast<uintptr_t>(&allocator); + return Okay{std::move(output)}; +} + StringResult String::makeFromCString(const char8_t* cString) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) |