diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/fud_csv.hpp | 2 | ||||
-rw-r--r-- | include/fud_file.hpp | 10 | ||||
-rw-r--r-- | include/fud_span.hpp | 1 | ||||
-rw-r--r-- | include/fud_string_view.hpp | 34 | ||||
-rw-r--r-- | include/fud_vector.hpp | 35 |
5 files changed, 67 insertions, 15 deletions
diff --git a/include/fud_csv.hpp b/include/fud_csv.hpp index 237c56f..2e0b6dd 100644 --- a/include/fud_csv.hpp +++ b/include/fud_csv.hpp @@ -88,6 +88,8 @@ struct Csv { // assumes file is at start static FudStatus parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t maxExtraAttempts); + + [[nodiscard]] Result<Option<StringView>, FudStatus> entry(size_t line, size_t column) const; }; } // namespace fud diff --git a/include/fud_file.hpp b/include/fud_file.hpp index 6f1acbf..66719e4 100644 --- a/include/fud_file.hpp +++ b/include/fud_file.hpp @@ -38,7 +38,7 @@ enum class FileAccessMode : uint8_t ReadWrite = Read | Write }; -enum class OpenFlagEnum : uint16_t +enum class OpenFlagEnum : uint8_t { Append = 0x01, Truncate = Append << 1, @@ -91,7 +91,7 @@ class OpenFlags { return mode; } - constexpr uint32_t flags() const noexcept + [[nodiscard]] constexpr uint32_t flags() const noexcept { uint32_t openFlags = 0; openFlags |= static_cast<uint32_t>(hasFlag(OpenFlagEnum::Append)) * O_APPEND; @@ -105,7 +105,7 @@ class OpenFlags { return openFlags; } - constexpr bool hasFlag(OpenFlagEnum flag) const noexcept + [[nodiscard]] constexpr bool hasFlag(OpenFlagEnum flag) const noexcept { return (m_mask & static_cast<FlagType>(flag)) != 0; } @@ -142,7 +142,7 @@ class RegularFile { Result<size_t, FudStatus> size() const; - constexpr int fileDescriptor() const + [[nodiscard]] constexpr int fileDescriptor() const { return m_fd; } @@ -225,7 +225,7 @@ class BufferedRegularFile { Result<size_t, FudStatus> searchSubstring(StringView subString); - constexpr const RegularFile& file() const + [[nodiscard]] constexpr const RegularFile& file() const { return m_file; } diff --git a/include/fud_span.hpp b/include/fud_span.hpp index ed4bcc7..b274d6f 100644 --- a/include/fud_span.hpp +++ b/include/fud_span.hpp @@ -35,6 +35,7 @@ struct Span { using ValueType = T; T* m_data; + // NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members) const size_t m_size; static Span make(Array<T, Size>& array) diff --git a/include/fud_string_view.hpp b/include/fud_string_view.hpp index 327bf20..c3bc0a1 100644 --- a/include/fud_string_view.hpp +++ b/include/fud_string_view.hpp @@ -18,10 +18,10 @@ #ifndef FUD_STRING_VIEW_HPP #define FUD_STRING_VIEW_HPP +#include "fud_assert.hpp" +#include "fud_config.hpp" #include "fud_status.hpp" #include "fud_utf8.hpp" -#include "fud_config.hpp" -#include "fud_assert.hpp" #include <string_view> @@ -31,6 +31,7 @@ class String; struct StringView { template <size_t N> + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) consteval StringView(const utf8 (&input)[N]) : m_length{N - 1}, m_data{input} { static_assert(N > 0); @@ -52,28 +53,42 @@ struct StringView { } template <size_t N> - StringView(const char (&input)[N]) : m_length{N - 1}, m_data{reinterpret_cast<const utf8*>(input)} + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) + StringView(const char (&input)[N]) : + m_length{N - 1}, + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + m_data{reinterpret_cast<const utf8*>(input)} { static_assert(N > 0); } StringView(size_t strLen, const char* strData) : - m_length(strLen), // line break - m_data{reinterpret_cast<const utf8*>(strData)} // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) + m_length(strLen), + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) + m_data{reinterpret_cast<const utf8*>(strData)} { } - StringView(std::string_view rhs) noexcept : StringView(rhs.length(), rhs.data()) {} + StringView(std::string_view rhs) noexcept : StringView(rhs.length(), rhs.data()) + { + } explicit StringView(const String& fudString) noexcept; template <size_t N> + // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays) constexpr static StringView makeFromCString(const char (&input)[N]) { static_assert(N > 0); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) return StringView{N - 1, reinterpret_cast<const utf8*>(input)}; } + [[nodiscard]] constexpr Span<const utf8> asSpan() const + { + return Span<const utf8>{m_data, m_length}; + } + [[nodiscard]] constexpr size_t length() const { return m_length; @@ -84,8 +99,9 @@ struct StringView { return m_data; } - [[nodiscard]] inline const char* c_str() const + [[nodiscard]] const char* c_str() const { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) return reinterpret_cast<const char*>(m_data); } @@ -98,12 +114,12 @@ struct StringView { return m_data[index]; } - constexpr const utf8* begin() const noexcept + [[nodiscard]] constexpr const utf8* begin() const noexcept { return m_data; } - constexpr const utf8* end() const noexcept + [[nodiscard]] constexpr const utf8* end() const noexcept { return m_data + m_length; } diff --git a/include/fud_vector.hpp b/include/fud_vector.hpp index 2942e71..760587b 100644 --- a/include/fud_vector.hpp +++ b/include/fud_vector.hpp @@ -116,6 +116,7 @@ class Vector { } output.m_allocator = allocator; + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) output.m_data = reinterpret_cast<T*>(dataPtrResult.getOkay()); output.m_length = 0; output.m_capacity = capacity; @@ -354,6 +355,7 @@ class Vector { return dataPtrResult.takeError(); } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) auto* dataPtr = reinterpret_cast<T*>(dataPtrResult.takeOkay()); for (size_t index = 0; index < m_length; ++index) { const auto* ptr = new (dataPtr + index) T(std::move(m_data[index])); @@ -363,6 +365,7 @@ class Vector { auto status = FudStatus::Success; if (m_capacity > 0) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) m_allocator->deallocate(reinterpret_cast<std::byte*>(m_data), m_capacity); } @@ -645,7 +648,9 @@ class Vector { } if (m_length + Size > m_capacity) { - auto status = grow(); + size_t currentLength = m_length; + auto status = resize(m_length + Size); + m_length = currentLength; if (status != FudStatus::Success) { return status; } @@ -660,6 +665,33 @@ class Vector { return FudStatus::Success; } + FudStatus extend(Span<const T> span) + { + if (span.data() == nullptr) { + return FudStatus::NullPointer; + } + if (std::numeric_limits<size_t>::max() - span.size() < m_length) { + return FudStatus::Failure; + } + if (m_length + span.size() > m_capacity) + { + size_t currentLength = m_length; + auto status = resize(m_length + span.size()); + m_length = currentLength; + if (status != FudStatus::Success) { + return status; + } + } + + for (size_t spanIndex = 0; spanIndex < span.size(); ++spanIndex) { + const auto* ptr = new (m_data + m_length) T(span[spanIndex]); + fudAssert(ptr != nullptr); + m_length++; + } + + return FudStatus::Success; + } + FudStatus erase(size_t index) { if (index >= m_length) { @@ -709,6 +741,7 @@ class Vector { auto status = clear(); if (m_data != nullptr && m_allocator != nullptr) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) m_allocator->deallocate(reinterpret_cast<std::byte*>(m_data), m_capacity); } |