Study Dungeon  1.0.0
A group project for COSC345
deck.h
Go to the documentation of this file.
1 
15 #pragma once
16 #ifndef DECK_H
17 #define DECK_H
18 
19 #include "util.h"
20 #include <algorithm>
21 #include <filesystem>
22 #include <fstream>
23 #include <iostream>
24 #include <string>
25 #include <windows.h>
26 
27 
35 {
36  UNKNOWN = 0,
37  EASY = 1,
38  MEDIUM = 2,
39  HARD = 3
40 };
41 
42 namespace fs = std::filesystem;
43 
54 CardDifficulty strToCardDifficulty(const std::string &difficultyStr);
55 
62 std::string cardDifficultyToStr(const CardDifficulty &difficulty);
63 
71 class FlashCard
72 {
73 public:
74  FlashCard();
75  FlashCard(std::string question, std::string answer, CardDifficulty difficulty, int n_times_answered);
77  std::string question{};
78 
80  std::string answer{};
81 
84 
87 
91  void printCard();
92 
96  void printCardAsTemplate();
97 
103  std::string stringCardAsTemplate();
104 };
105 
106 
113 {
114 public:
116  std::string name{};
118  std::filesystem::path filename{};
120  std::vector<FlashCard> cards{};
121 
125  void printDeck();
126 
127 
131  void printDeckAsTemplate();
132 };
133 
134 
144 std::vector<FlashCardDeck> loadFlashCardDecks(std::filesystem::path deck_dir_path);
145 
146 
153 FlashCardDeck readFlashCardDeck(std::filesystem::path deck_file);
154 
164 bool writeFlashCardDeck(const FlashCardDeck &deck, std::filesystem::path filename);
165 
166 
177 bool writeFlashCardDeckWithChecks(const FlashCardDeck &deck, std::filesystem::path filename, bool force_overwrite);
178 
179 
186 std::vector<FlashCardDeck> createExampleDecks();
187 
194 std::filesystem::path createDeckFilename(std::filesystem::path deck_dir);
195 
196 
204 bool updateDeckFile(FlashCardDeck &deck_to_update);
205 
206 #endif
Class that defines a "deck" of flashcards.
Definition: deck.h:113
void printDeck()
Prints flashcard deck information and then each card.
Definition: deck.cpp:85
void printDeckAsTemplate()
Prints flashcard deck name and then each card as template for a deck file.
Definition: deck.cpp:97
std::string name
Definition: deck.h:116
std::vector< FlashCard > cards
Definition: deck.h:120
std::filesystem::path filename
Definition: deck.h:118
This structure holds the information for each flashcard.
Definition: deck.h:72
void printCardAsTemplate()
Used to.
Definition: deck.cpp:68
std::string answer
Definition: deck.h:80
std::string stringCardAsTemplate()
Returns the card in template form as a string.
Definition: deck.cpp:75
CardDifficulty difficulty
Definition: deck.h:83
void printCard()
Prints the card question and answer.
Definition: deck.cpp:61
int n_times_answered
Definition: deck.h:86
std::string question
Definition: deck.h:77
bool writeFlashCardDeck(const FlashCardDeck &deck, std::filesystem::path filename)
Write a deck of flashcards to disk.
FlashCardDeck readFlashCardDeck(std::filesystem::path deck_file)
For a given deck file, read the contents in to create all the cards.
CardDifficulty strToCardDifficulty(const std::string &difficultyStr)
Converts a string into the CardDifficulty enum.
Definition: deck.cpp:15
std::vector< FlashCardDeck > loadFlashCardDecks(std::filesystem::path deck_dir_path)
Load the decks from files stored with the ".deck" extension inside decks/.
std::string cardDifficultyToStr(const CardDifficulty &difficulty)
Converts the card difficulty from enum to a string.
Definition: deck.cpp:35
std::filesystem::path createDeckFilename(std::filesystem::path deck_dir)
Prompt the user for name of the file to save the deckfile to.
Definition: deck.cpp:306
bool updateDeckFile(FlashCardDeck &deck_to_update)
Updates an existing FlashCardDeck on file.
Definition: deck.cpp:331
CardDifficulty
The possible difficulties for a flashcard.
Definition: deck.h:35
std::vector< FlashCardDeck > createExampleDecks()
Create example deck files.
Definition: deck.cpp:292
bool writeFlashCardDeckWithChecks(const FlashCardDeck &deck, std::filesystem::path filename, bool force_overwrite)
Write a deck of flashcards to disk.
Contains useful helper functions.