Kitlist
A list manager for maintaining kit lists
Loading...
Searching...
No Matches
kitparser.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of Kitlist, a program to maintain a simple list
4 of items and assign items to one or more categories.
5
6 Copyright (C) 2008-2025 Frank Dean
7
8 Kitlist is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 Kitlist is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Kitlist. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22#ifndef KITPARSER_HPP
23#define KITPARSER_HPP
24
25#include "model.hpp"
26#include "pugixml.hpp"
27#include <memory>
28#include <stdexcept>
29#include <string>
30
43class KitParser {
44
46 std::string filename;
47
49 std::unique_ptr<Model> model;
50
56 void parse_items(const pugi::xml_node& node);
57
63 void parse_categories(const pugi::xml_node& node);
64
65public:
66
68 KitParser(const std::string filename) :
69 filename(filename), model(new Model()) {}
70
78 std::unique_ptr<Model> parse();
79
86 class parse_exception : public std::exception {
87 std::string message;
88 public:
89 parse_exception(std::string message) : std::exception(), message(message) {}
90 virtual const char* what() const throw() override {
91 return message.c_str();
92 }
93 };
94
95};
96
97#endif // KITPARSER_HPP
virtual const char * what() const override
Definition kitparser.hpp:90
parse_exception(std::string message)
Definition kitparser.hpp:89
void parse_categories(const pugi::xml_node &node)
Parses the categories XML node.
Definition kitparser.cpp:46
std::unique_ptr< Model > model
The Model representing the parsed file.
Definition kitparser.hpp:49
void parse_items(const pugi::xml_node &node)
Parses the items XML node.
Definition kitparser.cpp:30
std::unique_ptr< Model > parse()
Parses the XML, building the data Model.
Definition kitparser.cpp:75
std::string filename
The filename to be parsed.
Definition kitparser.hpp:46
KitParser(const std::string filename)
Defautl constructor.
Definition kitparser.hpp:68
Maintains the data model.
Definition model.hpp:40
Copyright 2008-2025 Frank Dean