summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clang-tidy2
-rw-r--r--cmake/warnings.cmake19
-rw-r--r--include/fud_csv.hpp19
-rw-r--r--include/fud_option.hpp2
-rw-r--r--include/fud_vector.hpp2
-rw-r--r--source/fud_csv.cpp48
-rw-r--r--test/test_csv.cpp2
7 files changed, 58 insertions, 36 deletions
diff --git a/.clang-tidy b/.clang-tidy
index 2a7bc1b..abd3f89 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,5 +1,5 @@
---
-Checks: 'clang-diagnostic-*,clang-analyzer-*,readability*,-readability-use-anyofallof,bugprone*,-bugprone-easily-swappable-parameters,deadcode,cppcoreguidelines*,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory,-cppcoreguidelines-non-private-member-variables-in-classes,modernize-*,-modernize-pass-by-value,-modernize-use-trailing-return-type,-modernize-avoid-c-arrays,performance*,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-type-union-access,-clang-diagnostic-unknown-warning-option,-clang-analyzer-valist*'
+Checks: 'clang-diagnostic-*,clang-analyzer-*,readability*,-readability-use-anyofallof,bugprone*,-bugprone-easily-swappable-parameters,deadcode,cppcoreguidelines*,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-avoid-do-while,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-owning-memory,-cppcoreguidelines-non-private-member-variables-in-classes,modernize-*,-modernize-pass-by-value,-modernize-use-trailing-return-type,-modernize-avoid-c-arrays,performance*,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-pro-type-union-access,-clang-diagnostic-unknown-warning-option,-clang-analyzer-valist*,-modernize-use-designated-initializers'
WarningsAsErrors: ''
HeaderFileExtensions:
- ''
diff --git a/cmake/warnings.cmake b/cmake/warnings.cmake
index 07c39b5..1787263 100644
--- a/cmake/warnings.cmake
+++ b/cmake/warnings.cmake
@@ -3,10 +3,20 @@ set(FUD_WARNINGS
-Werror
-Wall
-Wextra
+
+ # gcc specific
+ # -Wstrict-null-sentinel
+ # -Wsuggest-final-types
+ # -Wsuggest-final-methods
+ # -Wimplicit-fallthrough=5
+ # -Wduplicated-branches
+ # -Wstack-usage=2048 # GCC specific
+ # -Wduplicated-cond
+ # -Wlogical-op
+
# -pedantic
-Wno-error=pedantic
# -pedantic-errors
- -Wstack-usage=2048 # GCC specific
-Wvla # variable modified types don't play nice in C++
# memory / data / array / string
-Wsizeof-pointer-memaccess
@@ -21,7 +31,6 @@ set(FUD_WARNINGS
-Wpointer-arith
-Wstrict-aliasing
-Wstrict-aliasing=2
- -Wstrict-null-sentinel
# classes / initialization
-Weffc++
-Wmismatched-tags
@@ -29,8 +38,6 @@ set(FUD_WARNINGS
-Winit-self
-Wctor-dtor-privacy
-Wnon-virtual-dtor
- -Wsuggest-final-types
- -Wsuggest-final-methods
-Wsuggest-override
# format
-Wformat
@@ -50,9 +57,6 @@ set(FUD_WARNINGS
# semantics / style
-Wshadow
-Wnull-dereference
- -Wimplicit-fallthrough=5
- -Wduplicated-branches
- -Wduplicated-cond
-Wcast-qual
-Wcomment
-Wconversion
@@ -76,7 +80,6 @@ set(FUD_WARNINGS
-Wswitch-enum
# this plays badly with clangd
# -Wzero-as-null-pointer-constant
- -Wlogical-op
# disabled because of dragonbox
# -Wuseless-cast
-Wextra-semi
diff --git a/include/fud_csv.hpp b/include/fud_csv.hpp
index 38b1b81..237c56f 100644
--- a/include/fud_csv.hpp
+++ b/include/fud_csv.hpp
@@ -25,8 +25,6 @@
#include "fud_utf8.hpp"
#include "fud_vector.hpp"
-#include <functional> // reference_wrapper
-
namespace fud {
using TextBuffer = Vector<std::byte>;
@@ -70,19 +68,26 @@ struct Csv {
static Csv make(Allocator& entryAllocator, Allocator& bufferAllocator);
/** Consume and return the CSV. */
- static FudStatus parseFromFilename(
+ static FudStatus parseFromFilenameUnbuffered(
+ Csv& csv,
+ StringView filename,
+ OpenFlags flags = OpenFlags{},
+ Option<int> dirFdOption = NullOpt,
+ size_t maxExtraAttempts = 0);
+
+ static FudStatus parseFromFilenameBuffered(
Csv& csv,
- Option<TextBuffer&&> bufferOption,
+ TextBuffer&& buffer,
StringView filename,
OpenFlags flags = OpenFlags{},
Option<int> dirFdOption = NullOpt,
- Option<size_t> maxExtraAttempts = NullOpt);
+ size_t maxExtraAttempts = 0);
// assumes file is at start
- static FudStatus parseFromUnbufferedFile(Csv& csv, RegularFile&& file, Option<size_t> maxExtraAttempts);
+ static FudStatus parseFromUnbufferedFile(Csv& csv, RegularFile&& file, size_t maxExtraAttempts);
// assumes file is at start
- static FudStatus parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, Option<size_t> maxExtraAttempts);
+ static FudStatus parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t maxExtraAttempts);
};
} // namespace fud
diff --git a/include/fud_option.hpp b/include/fud_option.hpp
index af2fcd3..3c94eaa 100644
--- a/include/fud_option.hpp
+++ b/include/fud_option.hpp
@@ -229,7 +229,7 @@ class Option {
m_data.clear();
}
- static constexpr auto Align = std::max(alignof(T), alignof(std::reference_wrapper<T>));
+ static constexpr auto Align = std::max(alignof(ValueType), alignof(std::reference_wrapper<ValueType>));
alignas(Align) option_detail::DataArray<Size> m_data{};
bool m_engaged;
diff --git a/include/fud_vector.hpp b/include/fud_vector.hpp
index 1730c50..2942e71 100644
--- a/include/fud_vector.hpp
+++ b/include/fud_vector.hpp
@@ -205,7 +205,7 @@ class Vector {
return FudStatus::NullPointer;
}
} else {
- allocator = rhs.allocator;
+ allocator = rhs.m_allocator;
if (allocator == nullptr) {
return FudStatus::ArgumentInvalid;
}
diff --git a/source/fud_csv.cpp b/source/fud_csv.cpp
index 198aeca..e1ecf72 100644
--- a/source/fud_csv.cpp
+++ b/source/fud_csv.cpp
@@ -43,41 +43,55 @@ Csv Csv::make(Allocator& entryAllocator, Allocator& bufferAllocator)
return csv;
}
-FudStatus Csv::parseFromFilename(
+FudStatus Csv::parseFromFilenameUnbuffered(
Csv& csv,
- Option<TextBuffer&&> bufferOption,
StringView filename,
OpenFlags flags,
Option<int> dirFdOption,
- Option<size_t> maxExtraAttempts)
+ size_t maxExtraAttempts)
{
debugPrint(u8"Enter parse from filename\n");
- auto fileResult{RegularFile::open(filename, FileAccessMode::Read, flags, dirFdOption)};
+ auto fileResult{RegularFile::open(filename, FileAccessMode::Read, flags, std::move(dirFdOption))};
if (fileResult.isError()) {
debugPrint(u8"Error opening file: {}\n", FudStatusToString(fileResult.getError()));
return fileResult.takeError();
}
- if (bufferOption.hasValue()) {
- auto bufferedFile{BufferedRegularFile::make(fileResult.takeOkay(), std::move(bufferOption.value()))};
- return parseFromBufferedFile(csv, bufferedFile, maxExtraAttempts);
- }
-
auto unbufferedFile{fileResult.takeOkay()};
return parseFromUnbufferedFile(csv, std::move(unbufferedFile), maxExtraAttempts);
}
+FudStatus Csv::parseFromFilenameBuffered(
+ Csv& csv,
+ TextBuffer&& bufferOption,
+ StringView filename,
+ OpenFlags flags,
+ Option<int> dirFdOption,
+ size_t maxExtraAttempts)
+{
+ debugPrint(u8"Enter parse from filename\n");
+ auto fileResult{RegularFile::open(filename, FileAccessMode::Read, flags, std::move(dirFdOption))};
+
+ if (fileResult.isError()) {
+ debugPrint(u8"Error opening file: {}\n", FudStatusToString(fileResult.getError()));
+ return fileResult.takeError();
+ }
+
+ auto bufferedFile{BufferedRegularFile::make(fileResult.takeOkay(), std::move(bufferOption))};
+ return parseFromBufferedFile(csv, bufferedFile, maxExtraAttempts);
+}
+
template <typename File>
-DrainResult readHeader(Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t& rawSize);
+DrainResult readHeader(Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize);
template <typename File>
-DrainResult scanLine(const Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t& rawSize);
+DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize);
template <typename File>
-FudStatus fillBuffer(Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t rawSize);
+FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSize);
-FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, Option<size_t> maxExtraAttempts)
+FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, size_t maxExtraAttempts)
{
size_t rawSize = 0;
DrainResult readResult{readHeader(csv, file, maxExtraAttempts, rawSize)};
@@ -139,7 +153,7 @@ FudStatus Csv::parseFromBufferedFile(Csv& csv, BufferedRegularFile& file, Option
return FudStatus::Success;
}
-FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, Option<size_t> maxExtraAttempts)
+FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, size_t maxExtraAttempts)
{
static_cast<void>(csv);
constexpr size_t BufferSize = 256;
@@ -150,7 +164,7 @@ FudStatus Csv::parseFromUnbufferedFile(Csv& csv, RegularFile&& file, Option<size
// NOLINTBEGIN(readability-function-cognitive-complexity)
template <typename File>
-DrainResult readHeader(Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t& rawSize)
+DrainResult readHeader(Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize)
{
debugPrint(u8"Entered read header\n");
@@ -215,7 +229,7 @@ DrainResult readHeader(Csv& csv, File& file, Option<size_t> maxExtraAttempts, si
}
template <typename File>
-DrainResult scanLine(const Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t& rawSize)
+DrainResult scanLine(const Csv& csv, File& file, size_t maxExtraAttempts, size_t& rawSize)
{
debugPrint(u8"Entered scanLine\n");
DrainResult readResult{};
@@ -305,7 +319,7 @@ DrainResult scanLine(const Csv& csv, File& file, Option<size_t> maxExtraAttempts
}
template <typename File>
-FudStatus fillBuffer(Csv& csv, File& file, Option<size_t> maxExtraAttempts, size_t rawSize)
+FudStatus fillBuffer(Csv& csv, File& file, size_t maxExtraAttempts, size_t rawSize)
{
static_cast<void>(rawSize);
diff --git a/test/test_csv.cpp b/test/test_csv.cpp
index 6923f6f..90e7ef0 100644
--- a/test/test_csv.cpp
+++ b/test/test_csv.cpp
@@ -64,7 +64,7 @@ TEST(FudCsv, ParseCsvFromFilename)
debugPrint(u8"Wrote happy data:\n-----\n{}\n-----\n", happyData);
- auto parseStatus = Csv::parseFromFilename(csv, NullOpt, happyCsvFilename);
+ auto parseStatus = Csv::parseFromFilenameUnbuffered(csv, happyCsvFilename);
if (parseStatus != FudStatus::Success) {
debugPrint(u8"Error parsing file: {}\n", FudStatusToString(parseStatus));
}