do not crash on malformed schedule files
[sispare-qt.git] / card.hh
blob6f51e3723fd54c1a396e25be23a805b364cbd85a
1 /*
2 * Copyright (c) 2021, S. Gilles <sgilles@sgilles.net>
4 * Permission to use, copy, modify, and/or distribute this software
5 * for any purpose with or without fee is hereby granted, provided
6 * that the above copyright notice and this permission notice appear
7 * in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
13 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
14 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #ifndef CARD_H
19 #define CARD_H
21 #include <filesystem>
22 #include <variant>
24 /* What's gone on for a particular card */
25 enum class Review_status { Unreviewed, Pass_easy, Pass_hard, Fail };
28 * This is an individual flash card. It has a front side (A), a reverse
29 * side (B), and some information about what level of review it's
30 * currently at.
32 * The hash thing is just so that we can trivially shuffle these cards
33 * for review by sticking them into an ordered map. We salt with a
34 * per-run value Session::salt.
36 class Card {
37 public:
38 Card() = delete;
40 bool operator==(const Card& that) const;
41 std::weak_ordering operator<=>(const Card& that) const;
43 static Card mk(const std::filesystem::path&dir);
45 /* For debugging */
46 friend std::ostream& operator<< (std::ostream &out, const Card &us);
48 /* The directory defining this card */
49 const std::filesystem::path path;
51 /* The contents of this card's A-side */
52 const std::string a;
54 /* The contents of this card's B-side */
55 const std::string b;
57 /* The hash used for (shuffled) comparison */
58 const std::size_t hash;
60 /* The mastery level of this card */
61 const int level;
63 private:
64 explicit Card(const std::filesystem::path& path, const std::string& a, const std::string& b, int level);
68 #endif