LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
CsvParser.hpp
Go to the documentation of this file.
1
8#ifndef PARSER_CSVPARSER_HPP
9#define PARSER_CSVPARSER_HPP
10
11#include <cstddef>
12#include <cstdint>
13#include <filesystem>
14#include <istream>
15#include <string>
16#include <string_view>
17#include <vector>
18
19#include "Error.hpp"
20#include "IDataParser.hpp"
21#include "Result.hpp"
22
23namespace parser
24{
25
47class CsvParser : public IDataParser
48{
49 public:
53 CsvParser();
54
58 virtual ~CsvParser() override = default;
59
66 void ParseData(const std::filesystem::path& filepath) override;
67
74 void ParseData(std::istream& input) override;
75
81 uint32_t GetCurrentProgress() const override;
82
88 uint32_t GetTotalProgress() const override;
89
95 void SetDelimiter(char delimiter) { m_delimiter = delimiter; }
96
102 void SetHasHeaders(bool hasHeaders) { m_hasHeaders = hasHeaders; }
103
104 private:
111 std::vector<std::string> ParseLine(const std::string& line);
112
122 const std::vector<std::string>& fields,
123 const std::vector<std::string>& headers,
124 int eventId);
125
134 const std::vector<std::string>& headers, const std::string& name);
135
142 std::string Trim(std::string_view str);
143
144 char m_delimiter = ',';
145 bool m_hasHeaders = true;
146 uint32_t m_currentProgress = 0;
147 uint32_t m_totalProgress = 0;
148};
149
150} // namespace parser
151
152#endif // PARSER_CSVPARSER_HPP
Error handling utilities.
Interface definitions for data parsing components.
std::vector< std::pair< std::string, std::string > > EventItems
A collection of key-value pairs representing event data (eventFieldName, data).
Definition LogEvent.hpp:101
Parses CSV formatted log files.
Definition CsvParser.hpp:48
uint32_t m_currentProgress
Current bytes processed.
Definition CsvParser.hpp:146
bool m_hasHeaders
Whether first line contains headers.
Definition CsvParser.hpp:145
std::string Trim(std::string_view str)
Trims whitespace from both ends of a string.
Definition CsvParser.cpp:397
CsvParser()
Constructs a new CSV parser with default settings.
Definition CsvParser.cpp:21
void SetDelimiter(char delimiter)
Sets the field delimiter character.
Definition CsvParser.hpp:95
uint32_t GetCurrentProgress() const override
Gets the current parsing progress.
Definition CsvParser.cpp:414
util::Result< size_t, error::Error > FindHeaderIndex(const std::vector< std::string > &headers, const std::string &name)
Finds the index of a header by name.
Definition CsvParser.cpp:383
virtual ~CsvParser() override=default
Virtual destructor for proper cleanup.
uint32_t m_totalProgress
Total bytes to process.
Definition CsvParser.hpp:147
void ParseData(const std::filesystem::path &filepath) override
Parses CSV data from a file.
Definition CsvParser.cpp:29
std::vector< std::string > ParseLine(const std::string &line)
Parses a single CSV line into fields.
Definition CsvParser.cpp:215
db::LogEvent::EventItems CreateEventFromFields(const std::vector< std::string > &fields, const std::vector< std::string > &headers, int eventId)
Creates EventItems from parsed CSV fields.
Definition CsvParser.cpp:316
char m_delimiter
Field delimiter character.
Definition CsvParser.hpp:144
uint32_t GetTotalProgress() const override
Gets the total expected progress.
Definition CsvParser.cpp:419
void SetHasHeaders(bool hasHeaders)
Sets whether the first line contains headers.
Definition CsvParser.hpp:102
Abstract base class for all data parsing implementations.
Definition IDataParser.hpp:110
Definition Result.hpp:15
Data parsing components and interfaces.
Definition IControler.hpp:22