|
- #include <map>
- #include <string>
- #include <vector>
- #include "ctx.h"
-
- #ifndef memory_Context_HEADER
- #define memory_Context_HEADER
-
- struct memory_Context {
- bool didLaunch = false;
- bool exit = false;
- std::string input = "";
- std::vector<int> hiddenItems;
- std::vector<int> mismatchedItems;
- std::string recentField = "none";
- std::string outputGoOn = "";
- std::string outputGreeting = "";
- std::string outputHelp = "";
- std::string outputMatchedItems = "";
- std::string outputMismatchedItems = "";
- std::string outputPromptSelection = "";
- std::string outputVictory = "";
- std::map<int, int> playfieldItems;
- int playfieldSize = 0;
- int selectedId = -1;
- std::vector<int> selectedItems;
- bool victory = false;
-
- template <typename T> T field(const std::string &fieldName) {
- if (fieldName == "didLaunch") {
- return *reinterpret_cast<T*>(&didLaunch);
- } else if (fieldName == "exit") {
- return *reinterpret_cast<T*>(&exit);
- } else if (fieldName == "input") {
- return *reinterpret_cast<T*>(&input);
- } else if (fieldName == "hiddenItems") {
- return *reinterpret_cast<T*>(&hiddenItems);
- } else if (fieldName == "mismatchedItems") {
- return *reinterpret_cast<T*>(&mismatchedItems);
- } else if (fieldName == "outputGoOn") {
- return *reinterpret_cast<T*>(&outputGoOn);
- } else if (fieldName == "outputGreeting") {
- return *reinterpret_cast<T*>(&outputGreeting);
- } else if (fieldName == "outputHelp") {
- return *reinterpret_cast<T*>(&outputHelp);
- } else if (fieldName == "outputMatchedItems") {
- return *reinterpret_cast<T*>(&outputMatchedItems);
- } else if (fieldName == "outputMismatchedItems") {
- return *reinterpret_cast<T*>(&outputMismatchedItems);
- } else if (fieldName == "outputPromptSelection") {
- return *reinterpret_cast<T*>(&outputPromptSelection);
- } else if (fieldName == "outputVictory") {
- return *reinterpret_cast<T*>(&outputVictory);
- } else if (fieldName == "playfieldItems") {
- return *reinterpret_cast<T*>(&playfieldItems);
- } else if (fieldName == "playfieldSize") {
- return *reinterpret_cast<T*>(&playfieldSize);
- } else if (fieldName == "selectedId") {
- return *reinterpret_cast<T*>(&selectedId);
- } else if (fieldName == "selectedItems") {
- return *reinterpret_cast<T*>(&selectedItems);
- }
- // victory
- return *reinterpret_cast<T*>(&victory);
- }
-
- void setField(const std::string &fieldName, bool value) {
- if (fieldName == "didLaunch") {
- didLaunch = value;
- } else if (fieldName == "exit") {
- exit = value;
- } else if (fieldName == "victory") {
- victory = value;
- }
- }
-
- void setField(const std::string &fieldName, const std::string &value) {
- if (fieldName == "input") {
- input = value;
- } else if (fieldName == "outputGoOn") {
- outputGoOn = value;
- } else if (fieldName == "outputGreeting") {
- outputGreeting = value;
- } else if (fieldName == "outputHelp") {
- outputHelp = value;
- } else if (fieldName == "outputMatchedItems") {
- outputMatchedItems = value;
- } else if (fieldName == "outputMismatchedItems") {
- outputMismatchedItems = value;
- } else if (fieldName == "outputPromptSelection") {
- outputPromptSelection = value;
- } else if (fieldName == "outputVictory") {
- outputVictory = value;
- }
- }
-
- void setField(const std::string &fieldName, const std::vector<int> &value) {
- if (fieldName == "hiddenItems") {
- hiddenItems = value;
- } else if (fieldName == "mismatchedItems") {
- mismatchedItems = value;
- } else if (fieldName == "selectedItems") {
- selectedItems = value;
- }
- }
-
- void setField(const std::string &fieldName, const std::map<int, int> &value) {
- if (fieldName == "playfieldItems") {
- playfieldItems = value;
- }
- }
-
- void setField(const std::string &fieldName, int value) {
- if (fieldName == "playfieldSize") {
- playfieldSize = value;
- } else if (fieldName == "selectedId") {
- selectedId = value;
- }
- }
- };
-
- memory_Context memory_createContext();
-
- #endif // memory_Context_HEADER
|