diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-15 18:50:15 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-15 18:50:15 +0200 |
commit | e2dfdd7d07f54b464a4419dcf102662f1694d4b8 (patch) | |
tree | 7c8ef515847be96cdb12ddc21b8a3104fcce9428 /c/defs.h | |
parent | 450770c00ae724fa8a3dc05fc86bf414cfa34e2f (diff) | |
download | EpisodeBrowser-e2dfdd7d07f54b464a4419dcf102662f1694d4b8.tar.gz |
Split defs.h into separate header files.
This is feasible now that the makedeps script exists to automatically
manage build dependencies (see 6034fe2, d00f8b3).
Diffstat (limited to 'c/defs.h')
-rw-r--r-- | c/defs.h | 200 |
1 files changed, 0 insertions, 200 deletions
diff --git a/c/defs.h b/c/defs.h deleted file mode 100644 index 102dce2..0000000 --- a/c/defs.h +++ /dev/null @@ -1,200 +0,0 @@ -#ifndef DEFS_H -#define DEFS_H - -#include <memory> -#include <optional> -#include <stdexcept> -#include <windows.h> -#include <commctrl.h> -#include <SWI-Prolog.h> - -/* common.cpp */ -TCHAR *TszFromSz(const char *, int); -struct Win32Error : public std::exception -{ - Win32Error(DWORD); - ~Win32Error(void); - virtual const char *what(void) const noexcept override; -private: - DWORD m_dwErr; - char *m_szMsg = NULL; -}; -struct Library -{ - Library(const TCHAR *); - ~Library(void); - FARPROC GetProcAddress(const char *); -private: - HMODULE m_hModule; -}; - -/* main.cpp */ -void UpdateLayout(); - -/* listview.cpp */ -struct ListView -{ - ListView(HMENU, DWORD); - int Height(int = -1); - HWND HWnd(void) const; - virtual void UpdateTheme(BOOL); - virtual LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -protected: - int m_bHeader = 1; - WNDPROC m_prevProc; - HWND m_hWnd; -}; - -/* episodelistview.cpp */ -struct EpisodeListView : public ListView -{ - EpisodeListView(void); - void DoSort(void); - void EnsureFocusVisible(void); - LRESULT HandleNotify(LPARAM); - int ISort(void) const; - void Redraw(void); - void SaveFocus(void); - void SetTop(int); - void RestoreFocus(void); - void SelectUnwatched(int); - void ShowFocus(void); - void Update(void); - void UpdateItem(LPLVITEM); - LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM) override; -private: - int m_iSort; - LVITEM m_lviFocus; - friend int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM); -}; - -/* datalistview.cpp */ -struct DataListView : public ListView -{ - DataListView(void); - void ShowEpisode(int); -}; - -/* pl.cpp */ -int Plx(const char *, const char *); -struct Query -{ - Query(module_t ctx, predicate_t p, term_t t0); - ~Query(void); - int Cut(); - int Close(); - int NextSolution(); -private: - qid_t m_q; -}; - -/* Polymorphic aliases for PL_put_*, PL_get_*. */ -inline int PlPut(term_t t, int x) { return PL_put_integer(t, x); } -inline int PlPut(term_t t, long x) { return PL_put_integer(t, x); } -inline int PlPut(term_t t, long long x) { return PL_put_integer(t, x); } -inline int PlPut(term_t t, atom_t x) { return PL_put_atom(t, x); } -inline int PlPut(term_t t, char *x) { return PL_put_atom(t, PL_new_atom(x)); } -inline int PlPut(term_t t, const char *x) { return PL_put_atom(t, PL_new_atom(x)); } -inline int PlPut(term_t t, int *x) { return -1; } -inline int PlPut(term_t t, long *x) { return -1; } -inline int PlPut(term_t t, long long *x) { return -1; } -inline int PlPut(term_t t, atom_t *x) { return -1; } -inline int PlPut(term_t t, char **x) { return -1; } - -inline int PlGet(term_t t, int x) { return -1; } -inline int PlGet(term_t t, long x) { return -1; } -inline int PlGet(term_t t, long long x) { return -1; } -inline int PlGet(term_t t, atom_t x) { return -1; } -inline int PlGet(term_t t, char *x) { return -1; } -inline int PlGet(term_t t, const char *x) { return -1; } -inline int PlGet(term_t t, int *x) { return PL_get_integer(t, x); } -inline int PlGet(term_t t, long *x) { return PL_get_long(t, x); } -inline int PlGet(term_t t, long long *x) { return PL_get_int64(t, x); } -inline int PlGet(term_t t, atom_t *x) { return PL_get_atom(t, x); } -inline int PlGet(term_t t, char **x) { return PL_get_atom_chars(t, x); } - -/* Helper templates for Plx, Pl. */ -template <typename T> -int PlPutv(term_t t, T arg) { return PlPut(t, arg); } -template <typename T, typename ...R> -int PlPutv(term_t t, T arg, R... rest) { return PlPut(t, arg)? PlPutv(t+1, rest...): 0; } -template <typename T> -int PlGetv(term_t t, T arg) { return PlGet(t, arg); } -template <typename T, typename ...R> -int PlGetv(term_t t, T arg, R... rest) { return PlGet(t, arg)? PlGetv(t+1, rest...): 0; } -template <typename T> -int Countv(int i, T arg) { return i+1; } -template <typename T, typename ...R> -int Countv(int i, T arg, R... rest) { return Countv(i+1, rest...); } - -/* Call Prolog predicate, propagating Prolog exceptions. */ -template <typename ...T> -int Plx(const char *szMod, const char *szPred, T... args) -{ - int iArity = Countv(0, args...); - term_t t = PL_new_term_refs(iArity); - if (!PlPutv(t, args...)) return 0; - Query q(NULL, PL_predicate(szPred, iArity, szMod), t); - if (!q.NextSolution()) return 0; - if (!PlGetv(t, args...)) return 0; - return 1; -} - -/* Call Prolog predicate, ignoring Prolog exceptions. */ -inline int Pl(const char *szMod, const char *szPred) -{ - try { - return Plx(szMod, szPred); - } catch (term_t &t) { - return 0; - } -} -template <typename ...T> -int Pl(const char *szMod, const char *szPred, T... args) -{ - try { - return Plx(szMod, szPred, args...); - } catch (term_t &t) { - return 0; - } -} - -/* defs.h */ -#ifdef UNICODE -#define WA "W" -#else -#define WA "A" -#endif - -#define DLVSIKEY 0 -#define DLVSIVALUE 1 -#define ELVSIEPISODE 0 -#define ELVSITITLE 1 -#define ELVSIRATING 2 - -inline int Cmp(int a, int b) -{ - if (a == b) - return 0; - if (a > b) - return 1; - return -1; -} - -inline int Dpi(int i) -{ - extern int g_iDPI; - return MulDiv(i, g_iDPI, 96); -} - -template <class T, typename ...A> -std::optional<T> try_make(A ...args) -{ - try { - return T(args...); - } catch (...) { - return {}; - } -} - -#endif |