Study Dungeon  1.0.0
A group project for COSC345
Data Structures | Macros | Enumerations | Functions
deck.h File Reference

Functions and classes relating to flashcards. More...

#include "util.h"
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <string>
#include <windows.h>

Go to the source code of this file.

Data Structures

class  FlashCard
 This structure holds the information for each flashcard. More...
 
class  FlashCardDeck
 Class that defines a "deck" of flashcards. More...
 

Enumerations

enum  CardDifficulty { UNKNOWN = 0 , EASY = 1 , MEDIUM = 2 , HARD = 3 }
 The possible difficulties for a flashcard. More...
 

Functions

CardDifficulty strToCardDifficulty (const std::string &difficultyStr)
 Converts a string into the CardDifficulty enum. More...
 
std::string cardDifficultyToStr (const CardDifficulty &difficulty)
 Converts the card difficulty from enum to a string. More...
 
std::vector< FlashCardDeckloadFlashCardDecks (std::filesystem::path deck_dir_path)
 Load the decks from files stored with the ".deck" extension inside decks/. More...
 
FlashCardDeck readFlashCardDeck (std::filesystem::path deck_file)
 For a given deck file, read the contents in to create all the cards. More...
 
bool writeFlashCardDeck (const FlashCardDeck &deck, std::filesystem::path filename)
 Write a deck of flashcards to disk. More...
 
bool writeFlashCardDeckWithChecks (const FlashCardDeck &deck, std::filesystem::path filename, bool force_overwrite)
 Write a deck of flashcards to disk. More...
 
std::vector< FlashCardDeckcreateExampleDecks ()
 Create example deck files. More...
 
std::filesystem::path createDeckFilename (std::filesystem::path deck_dir)
 Prompt the user for name of the file to save the deckfile to. More...
 
bool updateDeckFile (FlashCardDeck &deck_to_update)
 Updates an existing FlashCardDeck on file. More...
 

Detailed Description

Functions and classes relating to flashcards.

Author
Green Alligators

These functions are involved with the parsing of files to create flashcards which are then converted into a deck. Cards are also parsed to text and written to file to save them.

Version
1.0.0
Date
2024-08-07

Enumeration Type Documentation

◆ CardDifficulty

The possible difficulties for a flashcard.

possible values: EASY (1), MEDIUM (2), and HARD (3) \showenumvalues

Function Documentation

◆ cardDifficultyToStr()

std::string cardDifficultyToStr ( const CardDifficulty difficulty)

Converts the card difficulty from enum to a string.

Parameters
difficultyThe CardDifficulty
Returns
std::string

◆ createDeckFilename()

std::filesystem::path createDeckFilename ( std::filesystem::path  deck_dir)

Prompt the user for name of the file to save the deckfile to.

Parameters
deck_dirDirectory to append the filename to
Returns
std::filesystem::path

◆ createExampleDecks()

std::vector<FlashCardDeck> createExampleDecks ( )

Create example deck files.

A helper function that will create some example deck files if no decks exist.

Returns
A vector of the example FlashCardDecks

◆ loadFlashCardDecks()

std::vector<FlashCardDeck> loadFlashCardDecks ( std::filesystem::path  deck_dir_path)

Load the decks from files stored with the ".deck" extension inside decks/.

Will iterate through all files within the path directory that have a .deck suffix. each deck file will be parsed and turned into a FlashCardDeck. All FlashCardDecks are added into a vector and returned.

Parameters
deck_pathPath on the file system to a directory where the deck files are located.
Returns
std::vector<FlashCardDeck>

◆ readFlashCardDeck()

FlashCardDeck readFlashCardDeck ( std::filesystem::path  deck_file)

For a given deck file, read the contents in to create all the cards.

Parameters
deck_fileThe path to the file containing the deck information
Returns
A FlashCardDeck after parsing the file.

◆ strToCardDifficulty()

CardDifficulty strToCardDifficulty ( const std::string &  difficultyStr)

Converts a string into the CardDifficulty enum.

"EASY" -> EASY "MEDIUM" -> MEDIUM "HARD" -> HARD Anything else is converted to UNKNOWN

Parameters
difficultyStrThe card difficulty as a string
Returns
CardDifficulty

◆ updateDeckFile()

bool updateDeckFile ( FlashCardDeck deck_to_update)

Updates an existing FlashCardDeck on file.

Parameters
deck_to_updateFlashCardDeck to write to file
Returns
true update was successful
false update was unsuccesssful

◆ writeFlashCardDeck()

bool writeFlashCardDeck ( const FlashCardDeck deck,
std::filesystem::path  filename 
)

Write a deck of flashcards to disk.

This will check the parent directory exists and write to a file. It does perform the additional checks on the filename that writeFlashCardWithChecks does

Parameters
deckThe FlashCard deck to be written to file
filenameThe file path for the deck file
Returns
true if successfully writes deck to file.

◆ writeFlashCardDeckWithChecks()

bool writeFlashCardDeckWithChecks ( const FlashCardDeck deck,
std::filesystem::path  filename,
bool  force_overwrite 
)

Write a deck of flashcards to disk.

The standard location will be in Decks/ located with the executable and use a suffix of ".deck". This method checks

Parameters
deckThe FlashCard deck to be written to file
filenameThe file path for the deck file
force_overwrite(default false) skip the overwrite confimration prompt
Returns
true if successfully writes deck to file.