Cockatrice/libcockatrice_card/libcockatrice/card/database/parser/cockatrice_xml_3.h
BruebachL 749223c2dc
[Card Database] Improve loading times through binary cache (#7051)
* [Card Database] Improve loading times through binary cache

Took 10 minutes


Took 9 minutes

Took 16 seconds

* [Card Database] Remove lib qt include

Took 18 minutes


Took 14 seconds

* Downgrade to 6.3 datastream

Took 5 minutes

* go up to 6.4 datastream

Took 1 minute

* Address comments

* Small bug fixes

Took 20 minutes


Took 10 seconds

* More fixes.

Took 4 minutes


Took 4 seconds

* Even more fixes.

Took 11 minutes


Took 4 seconds

* More fixes.

Took 6 minutes

Took 26 seconds

Took 8 minutes

* Namespace instead of class

Took 6 minutes

---------

Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
2026-07-27 23:12:53 +02:00

86 lines
No EOL
2.9 KiB
C++

#ifndef COCKATRICE_XML3_H
#define COCKATRICE_XML3_H
#include "card_database_parser.h"
#include <QLoggingCategory>
#include <QXmlStreamReader>
inline Q_LOGGING_CATEGORY(CockatriceXml3Log, "cockatrice_xml.xml_3_parser");
/**
* @class CockatriceXml3Parser
* @ingroup CardDatabase
* @brief Parses version 3 of the Cockatrice XML Schema.
*
* This parser reads a Cockatrice XML3 database and emits CardInfoPtr
* and CardSetPtr objects. All card properties are read individually.
*
* @note Differences from v4:
* - No <prop> block; properties are hardcoded (manacost, cmc, type, pt, loyalty, etc.).
* - No set priority field.
* - No support for rebalanced cards or preferences.
* - Related cards support only attach, exclude, variable, and count attributes.
*/
class CockatriceXml3Parser : public ICardDatabaseParser
{
Q_OBJECT
public:
CockatriceXml3Parser(ICardSetPriorityController *cardSetPriorityController);
~CockatriceXml3Parser() override = default;
/**
* @brief Determines if the parser can handle this file.
* @param name File name.
* @param device Open QIODevice containing the XML.
* @return True if the file is a Cockatrice XML3 database.
*/
bool getCanParseFile(const QString &name, QIODevice &device) override;
/**
* @brief Parse the XML database.
* @param device Open QIODevice positioned at start of file.
*/
void parseFile(QIODevice &device) override;
/**
* @brief Parse the XML database into the given snapshot.
* @param device Open QIODevice positioned at start of file.
* @param data Target snapshot to populate.
*/
void parseFileInto(QIODevice &device, CardDatabaseData &data) override;
/**
* @brief Save sets and cards back to an XML3 file.
*/
bool saveToFile(FormatRulesNameMap _formats,
SetNameMap _sets,
CardNameMap cards,
const QString &fileName,
const QString &sourceUrl = "unknown",
const QString &sourceVersion = "unknown") override;
private:
/**
* @brief Load all <card> elements from the XML stream.
* @param xml The open QXmlStreamReader positioned at the <cards> element.
* Parses each <card> node and emits addCard signals for each CardInfoPtr created.
*/
void loadCardsFromXml(QXmlStreamReader &xml);
/**
* @brief Load all <set> elements from the XML stream.
* @param xml The open QXmlStreamReader positioned at the <sets> element.
* Parses each <set> node and adds them to the shared set cache.
*/
void loadSetsFromXml(QXmlStreamReader &xml);
/**
* @brief Extracts the main card type from a full type string.
* @param type The full type string (e.g., "Legendary Artifact Creature - Golem")
* @return The primary type (e.g., "Creature").
*/
QString getMainCardType(QString &type);
};
#endif