diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-15 22:24:31 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-15 22:24:31 +0200 |
commit | 246fd1369dce903dad48730478bebbe9733ac88e (patch) | |
tree | 50a6dc779453ef430a13fd13c9ca21a4d2c3f2a1 /c/data.h | |
parent | 8877627ee3fcd5a8f0ce2fcccec7688973e9cb2d (diff) | |
download | EpisodeBrowser-246fd1369dce903dad48730478bebbe9733ac88e.tar.gz |
Start moving data into C++.
This is the first step in the process of getting rid of the SWI Prolog
dependency. We'll see how it goes.
Diffstat (limited to 'c/data.h')
-rw-r--r-- | c/data.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/c/data.h b/c/data.h new file mode 100644 index 0000000..a2b6cac --- /dev/null +++ b/c/data.h @@ -0,0 +1,74 @@ +#ifndef DATA_H +#define DATA_H + +#include "pl.h" +#include "util.h" +#include "wcharptr.h" + +struct ElvData +{ + int rating = 0; + bool bWatched = false; + bool bTVOriginal = false; + wchar_t sRating[3] = {0}; + wchar_t siEp[5] = {0}; + wchar_t title[128] = {0}; +}; + +struct DlvData +{ + wchar_t date[64] = {0}; + wchar_t source[64] = {0}; + wchar_t screenwriter[64] = {0}; + wchar_t hint[128] = {0}; + wchar_t wiki[128] = {0}; +}; + +inline int FromWeb(const int iEp, ElvData& e, DlvData& d) noexcept +{ + WcharPtr title, wiki, date, source, hint; + const int r = Pl("episode_data","fetch_episode_data",iEp,&title,&wiki,&date,&source,&hint); + if (title) Wcscpy(e.title, title); + if (wiki) Wcscpy(d.wiki, wiki); + if (date) Wcscpy(d.date, date); + if (source) Wcscpy(d.source, source); + if (hint) Wcscpy(d.hint, hint); + return r; +} + +inline bool FromProlog(const int iEp, ElvData& e) noexcept +{ + if (WcharPtr title; Pl("episode_data","episode_title",iEp,&title)) + Wcscpy(e.title, title); + else + return false; + + if (Pl("episode_data","episode_rating",iEp,&e.rating)) + Swprintf(e.sRating, L"%d", e.rating); + + if (Pl("episode_data","tv_original",iEp)) + e.bTVOriginal = true; + + if (Pl("track_episodes","watched",iEp)) + e.bWatched = true; + + Swprintf(e.siEp, L"%d", iEp); + + return true; +} + +inline void FromProlog(const int iEp, DlvData& d) noexcept +{ + if (WcharPtr wiki; Pl("episode_data","episode_wiki",iEp,&wiki)) + Wcscpy(d.wiki, wiki); + if (WcharPtr screenwriter; Pl("episode_data","episode_datum",iEp,"Screenwriter",&screenwriter)) + Wcscpy(d.screenwriter, screenwriter); + if (WcharPtr date; Pl("episode_data","episode_datum",iEp,"Date",&date)) + Wcscpy(d.date, date); + if (WcharPtr source; Pl("episode_data","episode_datum",iEp,"Source",&source)) + Wcscpy(d.source, source); + if (WcharPtr hint; Pl("episode_data","episode_datum",iEp,"Hint",&hint)) + Wcscpy(d.hint, hint); +} + +#endif |