Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
CardDatabase Class Reference

Core in-memory container for card and set data. More...

#include <card_database.h>

Inheritance diagram for CardDatabase:
[legend]
Collaboration diagram for CardDatabase:
[legend]

Public Slots

void addCard (const CardInfoPtr &card)
 Adds a card to the database.
void addSet (const CardSetPtr &set)
 Adds a set to the database.
void addFormat (const FormatRulesPtr &format)
void loadCardDatabases ()
 Loads card databases from configured paths.
void reloadCardDatabasesAndNotify ()
bool saveCustomTokensToFile ()
 Saves custom tokens to file.
void swapInDatabaseData (CardDatabaseData data)
 Replaces the entire contents of the database with the provided snapshot in a single operation. Intended to be called once a background load has finished building a CardDatabaseData, so that observers never see a partially-populated database.

Signals

void cardDatabaseLoadingFinished ()
 Emitted when the card database has finished loading successfully.
void cardDatabaseReset ()
 Emitted once after the live database contents have been replaced by a freshly loaded snapshot. Models should rebuild from the database in a single batch rather than reacting to per-card adds.
void cardDatabaseLoadingFailed ()
 Emitted when the card database fails to load.
void cardDatabaseNewSetsFound (int numUnknownSets, QStringList unknownSetsNames)
 Emitted when new sets are found.
void cardDatabaseAllNewSetsEnabled ()
 Emitted when all new sets have been enabled.
void cardDatabaseEnabledSetsChanged ()
 Emitted when enabled sets have changed.
void cardAdded (CardInfoPtr card)
 Emitted when a new card is added.
void cardRemoved (CardInfoPtr card)
 Emitted when a card is removed.

Public Member Functions

 CardDatabase (QObject *parent=nullptr, ICardPreferenceProvider *prefs=nullptr, ICardDatabasePathProvider *pathProvider=nullptr, ICardSetPriorityController *setPriorityController=nullptr)
 Constructs a new CardDatabase instance.
 ~CardDatabase () override
 Destructor clears all internal data.
void removeCard (const CardInfoPtr &card)
 Removes a card from the database.
void clear ()
 Clears all cards, sets, and internal state.
const CardNameMapgetCardList () const
 Returns the map of cards by name.
CardSetPtr getSet (const QString &setName)
 Retrieves a set by short name, creating a new one if missing.
CardSetList getSetList () const
 Returns a list of all sets in the database.
LoadStatus getLoadStatus () const
 Returns the current load status.
CardDatabaseQuerierquery () const
 Returns the querier for performing card lookups.
void enableAllUnknownSets ()
 Enables all unknown sets in the database.
void markAllSetsAsKnown ()
 Marks all sets as known.
void notifyEnabledSetsChanged (bool recomputeCachedSets=true)
 Notifies listeners that enabled sets changed.
void checkUnknownSets ()
 Check for sets that are unknown and emit signals if needed.
ICardSetPriorityControllergetPriorityController ()

Protected Attributes

ICardSetPriorityControllersetPriorityController
 Controller to determine set priority when choosing preferred printings.
CardNameMap cards
 Cards indexed by exact name.
CardNameMap simpleNameCards
 Cards indexed by simplified name (normalized).
SetNameMap sets
 Sets indexed by short name.
FormatRulesNameMap formats
CardDatabaseLoaderloader
 Loader responsible for file discovery and parsing.
LoadStatus loadStatus
 Current load status of the database.
CardDatabaseQuerierquerier
 Querier for higher-level card lookups.

Private Member Functions

void refreshCachedReverseRelatedCards ()
 Refreshes the cached reverse-related cards for all cards.
void refreshCachedReverseRelatedCards (CardNameMap &cardMap)
 Refreshes the cached reverse-related cards for the given card map.

Private Attributes

QBasicMutex * clearDatabaseMutex = new QBasicMutex()
 Mutexes for thread safety.
QBasicMutex * addCardMutex = new QBasicMutex()
QBasicMutex * removeCardMutex = new QBasicMutex()

Friends

class CardDatabaseLoader
class CardDatabaseQuerier

Detailed Description

Core in-memory container for card and set data.

Responsible for maintaining CardInfo objects, CardSet objects, and providing access to CardDatabaseQuerier for query operations. Handles addition, removal, and clearing of cards and sets.

Constructor & Destructor Documentation

◆ CardDatabase()

CardDatabase::CardDatabase ( QObject * parent = nullptr,
ICardPreferenceProvider * prefs = nullptr,
ICardDatabasePathProvider * pathProvider = nullptr,
ICardSetPriorityController * setPriorityController = nullptr )
explicit

Constructs a new CardDatabase instance.

Parameters
parentQObject parent.
prefsOptional card preference provider.
pathProviderOptional database path provider.
setPriorityControllerOptional controller for set priority.
Here is the call graph for this function:

◆ ~CardDatabase()

CardDatabase::~CardDatabase ( )
override

Destructor clears all internal data.

Here is the call graph for this function:

Member Function Documentation

◆ addCard

void CardDatabase::addCard ( const CardInfoPtr & card)
slot

Adds a card to the database.

Parameters
cardCardInfoPtr to add.
Here is the call graph for this function:

◆ addFormat

void CardDatabase::addFormat ( const FormatRulesPtr & format)
slot

◆ addSet

void CardDatabase::addSet ( const CardSetPtr & set)
slot

Adds a set to the database.

Parameters
setPointer to CardSet to add.

◆ cardAdded

void CardDatabase::cardAdded ( CardInfoPtr card)
signal

Emitted when a new card is added.

Here is the caller graph for this function:

◆ cardDatabaseAllNewSetsEnabled

void CardDatabase::cardDatabaseAllNewSetsEnabled ( )
signal

Emitted when all new sets have been enabled.

Here is the caller graph for this function:

◆ cardDatabaseEnabledSetsChanged

void CardDatabase::cardDatabaseEnabledSetsChanged ( )
signal

Emitted when enabled sets have changed.

Here is the caller graph for this function:

◆ cardDatabaseLoadingFailed

void CardDatabase::cardDatabaseLoadingFailed ( )
signal

Emitted when the card database fails to load.

Here is the caller graph for this function:

◆ cardDatabaseLoadingFinished

void CardDatabase::cardDatabaseLoadingFinished ( )
signal

Emitted when the card database has finished loading successfully.

Here is the caller graph for this function:

◆ cardDatabaseNewSetsFound

void CardDatabase::cardDatabaseNewSetsFound ( int numUnknownSets,
QStringList unknownSetsNames )
signal

Emitted when new sets are found.

Parameters
numUnknownSetsNumber of unknown sets.
unknownSetsNamesNames of unknown sets.
Here is the caller graph for this function:

◆ cardDatabaseReset

void CardDatabase::cardDatabaseReset ( )
signal

Emitted once after the live database contents have been replaced by a freshly loaded snapshot. Models should rebuild from the database in a single batch rather than reacting to per-card adds.

Here is the caller graph for this function:

◆ cardRemoved

void CardDatabase::cardRemoved ( CardInfoPtr card)
signal

Emitted when a card is removed.

Here is the caller graph for this function:

◆ checkUnknownSets()

void CardDatabase::checkUnknownSets ( )

Check for sets that are unknown and emit signals if needed.

Called from MainWindow::startupConfigCheck() after signal connections are live (the front-loaded parse in main() runs before MainWindow exists, so signals emitted there would have no receivers). May also be called by the loader via the friend declaration. Has side effects: enables all sets when none are enabled (first-run), marks all sets as known.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void CardDatabase::clear ( )

Clears all cards, sets, and internal state.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enableAllUnknownSets()

void CardDatabase::enableAllUnknownSets ( )

Enables all unknown sets in the database.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCardList()

const CardNameMap & CardDatabase::getCardList ( ) const
inlinenodiscard

Returns the map of cards by name.

Here is the caller graph for this function:

◆ getLoadStatus()

LoadStatus CardDatabase::getLoadStatus ( ) const
inlinenodiscard

Returns the current load status.

Here is the caller graph for this function:

◆ getPriorityController()

ICardSetPriorityController * CardDatabase::getPriorityController ( )
inline

◆ getSet()

CardSetPtr CardDatabase::getSet ( const QString & setName)

Retrieves a set by short name, creating a new one if missing.

Parameters
setNameShort name of the set.
Returns
Pointer to the CardSet.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getSetList()

CardSetList CardDatabase::getSetList ( ) const
nodiscard

Returns a list of all sets in the database.

Here is the caller graph for this function:

◆ loadCardDatabases

void CardDatabase::loadCardDatabases ( )
slot

Loads card databases from configured paths.

Here is the caller graph for this function:

◆ markAllSetsAsKnown()

void CardDatabase::markAllSetsAsKnown ( )

Marks all sets as known.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ notifyEnabledSetsChanged()

void CardDatabase::notifyEnabledSetsChanged ( bool recomputeCachedSets = true)

Notifies listeners that enabled sets changed.

Parameters
recomputeCachedSetsWhen true, every card's cached set-name / alt-name data is recomputed (needed only when enabled-set state actually changed). Pass false after a plain reload, where enabled-set state is unchanged and the cached data is still valid.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ query()

CardDatabaseQuerier * CardDatabase::query ( ) const
inlinenodiscard

Returns the querier for performing card lookups.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refreshCachedReverseRelatedCards() [1/2]

void CardDatabase::refreshCachedReverseRelatedCards ( )
private

Refreshes the cached reverse-related cards for all cards.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ refreshCachedReverseRelatedCards() [2/2]

void CardDatabase::refreshCachedReverseRelatedCards ( CardNameMap & cardMap)
private

Refreshes the cached reverse-related cards for the given card map.

Parameters
cardMapMap of cards to process.

◆ reloadCardDatabasesAndNotify

void CardDatabase::reloadCardDatabasesAndNotify ( )
slot
Here is the call graph for this function:
Here is the caller graph for this function:

◆ removeCard()

void CardDatabase::removeCard ( const CardInfoPtr & card)

Removes a card from the database.

Parameters
cardPointer to the card to remove.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ saveCustomTokensToFile

bool CardDatabase::saveCustomTokensToFile ( )
slot

Saves custom tokens to file.

Returns
True if successful.
Here is the caller graph for this function:

◆ swapInDatabaseData

void CardDatabase::swapInDatabaseData ( CardDatabaseData data)
slot

Replaces the entire contents of the database with the provided snapshot in a single operation. Intended to be called once a background load has finished building a CardDatabaseData, so that observers never see a partially-populated database.

Parameters
dataThe fully-built snapshot to adopt.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CardDatabaseLoader

friend class CardDatabaseLoader
friend

◆ CardDatabaseQuerier

friend class CardDatabaseQuerier
friend

Member Data Documentation

◆ addCardMutex

QBasicMutex * CardDatabase::addCardMutex = new QBasicMutex()
private

◆ cards

CardNameMap CardDatabase::cards
protected

Cards indexed by exact name.

◆ clearDatabaseMutex

QBasicMutex* CardDatabase::clearDatabaseMutex = new QBasicMutex()
private

Mutexes for thread safety.

◆ formats

FormatRulesNameMap CardDatabase::formats
protected

◆ loader

CardDatabaseLoader* CardDatabase::loader
protected

Loader responsible for file discovery and parsing.

◆ loadStatus

LoadStatus CardDatabase::loadStatus
protected

Current load status of the database.

◆ querier

CardDatabaseQuerier* CardDatabase::querier
protected

Querier for higher-level card lookups.

◆ removeCardMutex

QBasicMutex * CardDatabase::removeCardMutex = new QBasicMutex()
private

◆ setPriorityController

ICardSetPriorityController* CardDatabase::setPriorityController
protected

Controller to determine set priority when choosing preferred printings.

◆ sets

SetNameMap CardDatabase::sets
protected

Sets indexed by short name.

◆ simpleNameCards

CardNameMap CardDatabase::simpleNameCards
protected

Cards indexed by simplified name (normalized).


The documentation for this class was generated from the following files: