mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 09:33:25 -08:00
* [CardDB] Stream card properties from blobs Parsed and cached cards used to keep a materialized QHash<QString, QString> for their properties: LazyPropertiesHash only deferred building that hash until the first query, and the cache writer re-serialized it on save. - LazyPropertiesHash answers value(), contains(), size(), isEmpty() and keys() straight out of the serialized blob, so a property query no longer builds a hash. - serialize() is public, and the cache writer passes the stored blob through instead of serializing a hash it just rebuilt. - CardInfo and PrintingInfo expose getPropertiesBlob() and getPropertyCount(); PrintingInfo::operator== compares key by key without materializing either side. - The XML parsers build cards via newInstanceFromPropertiesBlob(), which derives the simple name and the alternate names that the parser used to keep next to the hash. The reload cycle fix stays out of this change; it depends on changing the CardInfo self pointer and is reviewed separately. * [CardDB] Address review comments on streaming properties * [CardDB] Address final review nits on property streaming Move BlobReader and the blob accessors into LazyPropertiesHash as private members so the parsing helper is declared with the class instead of hiding in the translation unit. Add LazyPropertiesHash::serializedFrom() and use it where a PrintingInfo is built from a fresh property hash, replacing the nested LazyPropertiesHash(LazyPropertiesHash::serialize(props)) construction. The pre-materialized QHash constructor stays: CardInfo's non-blob factory still uses it for the oracle import path, and the tests cover it directly. --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
160 lines
4.4 KiB
C++
160 lines
4.4 KiB
C++
#ifndef COCKATRICE_PRINTING_INFO_H
|
|
#define COCKATRICE_PRINTING_INFO_H
|
|
|
|
#include "../set/card_set.h"
|
|
#include "libcockatrice/card/lazy_properties_hash.h"
|
|
|
|
#include <QHash>
|
|
#include <QList>
|
|
#include <QMap>
|
|
#include <QSharedPointer>
|
|
#include <QString>
|
|
#include <QStringList>
|
|
|
|
class PrintingInfo;
|
|
|
|
using SetToPrintingsMap = QMap<QString, QList<PrintingInfo>>;
|
|
|
|
/**
|
|
* @class PrintingInfo
|
|
* @ingroup CardPrintings
|
|
*
|
|
* @brief Represents metadata for a specific variation of a card within a set.
|
|
*
|
|
* A card can have multiple variations across sets. PrintingInfo associates
|
|
* a card with one such variation, and provides per-printing attributes
|
|
* such as identifiers or additional properties.
|
|
*
|
|
* Equality is defined as both the set and the property values being equal.
|
|
*/
|
|
class PrintingInfo
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructs a PrintingInfo associated with a specific set.
|
|
*
|
|
* @param _set The set this printing belongs to (defaults to null).
|
|
* @param _properties The printing properties (defaults to empty)
|
|
*/
|
|
explicit PrintingInfo(const CardSetPtr &_set = nullptr, const LazyPropertiesHash &_properties = {});
|
|
|
|
/**
|
|
* @brief Destroys the PrintingInfo.
|
|
*
|
|
* Defaulted since no special cleanup is required.
|
|
*/
|
|
~PrintingInfo() = default;
|
|
|
|
/**
|
|
* @brief Equality operator.
|
|
*
|
|
* Two PrintingInfo objects are equal if they refer to the same set
|
|
* and contain the exact same property key/value pairs.
|
|
*
|
|
* @param other Another PrintingInfo to compare against.
|
|
* @return True if both set and properties are equal, otherwise false.
|
|
*/
|
|
bool operator==(const PrintingInfo &other) const;
|
|
|
|
/**
|
|
* @brief check if the info is empty, as if default constructed.
|
|
*
|
|
* @return True if both set and properties are empty, otherwise false.
|
|
*/
|
|
bool isEmpty() const
|
|
{
|
|
return set == nullptr && properties.isEmpty();
|
|
}
|
|
|
|
private:
|
|
CardSetPtr set; ///< The set this variation belongs to.
|
|
LazyPropertiesHash properties; ///< Key-value store for variation-specific attributes.
|
|
|
|
public:
|
|
/**
|
|
* @brief Returns the set this printing belongs to.
|
|
*
|
|
* @return Pointer to the associated CardSet.
|
|
*/
|
|
[[nodiscard]] CardSetPtr getSet() const
|
|
{
|
|
return set;
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the list of property names defined for this printing.
|
|
*
|
|
* @return List of keys stored in the properties map.
|
|
*/
|
|
[[nodiscard]] QStringList getProperties() const
|
|
{
|
|
return properties.keys();
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the printing properties in their serialized blob form.
|
|
*/
|
|
[[nodiscard]] QByteArray getPropertiesBlob() const
|
|
{
|
|
return properties.serialized();
|
|
}
|
|
|
|
/**
|
|
* @brief Returns the materialized property hash, forcing deserialization of the blob.
|
|
*
|
|
* Prefer getProperty() or getPropertiesBlob(), which avoid building the hash.
|
|
*/
|
|
[[nodiscard]] const QHash<QString, QString> &getPropertiesHash() const
|
|
{
|
|
return properties.getProperties();
|
|
}
|
|
|
|
/**
|
|
* @brief Retrieves the value of a specific property.
|
|
*
|
|
* @param propertyName The key name of the property to query.
|
|
* @return The property value as a string, or an empty string if not set.
|
|
*/
|
|
[[nodiscard]] QString getProperty(const QString &propertyName) const
|
|
{
|
|
return properties.value(propertyName);
|
|
}
|
|
|
|
/**
|
|
* @brief Sets or updates the value of a specific property.
|
|
*
|
|
* If the property already exists, its value is replaced.
|
|
*
|
|
* @param _name The name of the property.
|
|
* @param _value The string value to assign.
|
|
*/
|
|
void setProperty(const QString &_name, const QString &_value);
|
|
|
|
/**
|
|
* @brief Returns the providerID for this printing.
|
|
*
|
|
* @return A string representing the providerID.
|
|
*/
|
|
[[nodiscard]] QString getUuid() const;
|
|
|
|
/**
|
|
* @brief Returns the flavorName for this printing.
|
|
*
|
|
* @return The flavorName, or empty if it isn't present.
|
|
*/
|
|
[[nodiscard]] QString getFlavorName() const;
|
|
|
|
/**
|
|
* @brief Returns the artist name credited for this printing's artwork.
|
|
*
|
|
* Requires a card database generated with artist data.
|
|
*
|
|
* @return The artist name, or empty if it isn't present.
|
|
*/
|
|
[[nodiscard]] QString getArtist() const
|
|
{
|
|
return getProperty("artist");
|
|
}
|
|
};
|
|
|
|
#endif // COCKATRICE_PRINTING_INFO_H
|