LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
xmlParser.hpp
Go to the documentation of this file.
1#ifndef PARSER_XMLPARSER_HPP
2#define PARSER_XMLPARSER_HPP
3
4#include <cstddef>
5#include <cstdint>
6#include <expat.h>
7
8#include <filesystem>
9#include <istream>
10
11#include "IDataParser.hpp"
12
13namespace parser
14{
15
16class XmlParser : public IDataParser
17{
18 public:
19 XmlParser();
20 virtual ~XmlParser() override = default;
21 // Loads and parses XML file using Expat
22 void ParseData(const std::filesystem::path& filepath) override;
23 void ParseData(std::istream& input) override;
24 uint32_t GetCurrentProgress() const override;
25 uint32_t GetTotalProgress() const override;
26
27 public:
28 uint32_t m_currentProgress = 0; // Initialize to 0
29};
30
32{
33 std::string currentElement;
34 std::string currentText;
35 size_t totalBytes = 0;
36 size_t bytesProcessed = 0;
39 int eventId = 0;
40 int depth = 0;
41 bool insideRoot = false;
42 bool insideEvent = false;
45 XmlParser* parser = nullptr;
46 XML_Parser parserHandle = nullptr;
47
48 // Add event batching
49 std::vector<std::pair<int, db::LogEvent::EventItems>> eventBatch;
50
51 // Reserve strings to avoid reallocations
53 {
54 currentElement.reserve(64);
55 currentText.reserve(1024);
56 eventBatch.reserve(5000);
57 eventItems.reserve(10);
58 }
59};
60
61} // namespace parser
62#endif // PARSER_XMLPARSER_HPP
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
Abstract base class for all data parsing implementations.
Definition IDataParser.hpp:110
Definition xmlParser.hpp:17
uint32_t m_currentProgress
Definition xmlParser.hpp:28
void ParseData(const std::filesystem::path &filepath) override
Loads and parses XML data from a file path.
Definition xmlParser.cpp:170
XmlParser()
Definition xmlParser.cpp:161
uint32_t GetTotalProgress() const override
Gets the total expected progress value.
Definition xmlParser.cpp:345
virtual ~XmlParser() override=default
uint32_t GetCurrentProgress() const override
Gets the current parsing progress.
Definition xmlParser.cpp:340
Data parsing components and interfaces.
Definition IControler.hpp:22
Definition xmlParser.hpp:32
ParserState()
Definition xmlParser.hpp:52
int eventId
Definition xmlParser.hpp:39
size_t lastProgressBytes
Definition xmlParser.hpp:38
std::vector< std::pair< int, db::LogEvent::EventItems > > eventBatch
Definition xmlParser.hpp:49
bool insideEvent
Definition xmlParser.hpp:42
XML_Parser parserHandle
Definition xmlParser.hpp:46
size_t eventsSinceLastNotify
Definition xmlParser.hpp:37
std::string discoveredEventElement
Definition xmlParser.hpp:43
size_t totalBytes
Definition xmlParser.hpp:35
std::string currentText
Definition xmlParser.hpp:34
size_t bytesProcessed
Definition xmlParser.hpp:36
std::string currentElement
Definition xmlParser.hpp:33
db::LogEvent::EventItems eventItems
Definition xmlParser.hpp:44
int depth
Definition xmlParser.hpp:40
bool insideRoot
Definition xmlParser.hpp:41