diff options
-rw-r--r-- | c/common.cpp | 2 | ||||
-rw-r--r-- | c/common.h | 4 | ||||
-rw-r--r-- | c/datalistview.cpp | 8 | ||||
-rw-r--r-- | c/episodelistview.cpp | 35 | ||||
-rw-r--r-- | c/listview.cpp | 14 | ||||
-rw-r--r-- | c/main.cpp | 42 | ||||
-rw-r--r-- | c/pl.cpp | 12 | ||||
-rw-r--r-- | c/pl.h | 72 |
8 files changed, 87 insertions, 102 deletions
diff --git a/c/common.cpp b/c/common.cpp index 02feecf..7a1438d 100644 --- a/c/common.cpp +++ b/c/common.cpp @@ -2,7 +2,7 @@ #include "common.h" -Win32Error::Win32Error(DWORD dwErr) +Win32Error::Win32Error(const DWORD dwErr) { m_dwErr = dwErr; FormatMessageA( @@ -30,7 +30,7 @@ private: HMODULE m_hModule; }; -inline int Cmp(int a, int b) +inline int Cmp(const int a, const int b) { if (a == b) return 0; if (a > b) return 1; @@ -38,7 +38,7 @@ inline int Cmp(int a, int b) } /* Return integer scaled for current DPI. */ -inline int Dpi(int i) +inline int Dpi(const int i) { extern int g_iDPI; return MulDiv(i, g_iDPI, 96); diff --git a/c/datalistview.cpp b/c/datalistview.cpp index 532e3a6..a25cc83 100644 --- a/c/datalistview.cpp +++ b/c/datalistview.cpp @@ -13,7 +13,7 @@ extern EpisodeListView *g_lpElv; -DataListView::DataListView(HWND hWndParent) +DataListView::DataListView(const HWND hWndParent) : ListView(hWndParent, (HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER) { LVCOLUMN lvc; @@ -31,7 +31,7 @@ DataListView::DataListView(HWND hWndParent) ListView_InsertColumn(m_hWnd, DLVSIVALUE, &lvc); } -void DataListView::ShowEpisode(int iEpisode) +void DataListView::ShowEpisode(const int iEpisode) { ListView_DeleteAllItems(m_hWnd); @@ -39,9 +39,9 @@ void DataListView::ShowEpisode(int iEpisode) lviKey.mask = LVIF_TEXT; lviValue.mask = LVIF_TEXT; - term_t t = PL_new_term_refs(3); + const term_t t = PL_new_term_refs(3); if (!PL_put_integer(t,iEpisode)) return; - qid_t q = PL_open_query(NULL, PL_Q_NORMAL, + const qid_t q = PL_open_query(NULL, PL_Q_NORMAL, PL_predicate("episode_datum", 3, "episode_data"), t); for (int i = 0; PL_next_solution(q); i++) { diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 01b4c1a..4196062 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -13,7 +13,7 @@ extern DataListView *g_lpDlv; int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM); -EpisodeListView::EpisodeListView(HWND hWndParent) +EpisodeListView::EpisodeListView(const HWND hWndParent) : ListView(hWndParent, (HMENU)IDC_EPISODELISTVIEW, 0) { LVCOLUMN lvc; @@ -45,14 +45,14 @@ void EpisodeListView::DoSort() void EpisodeListView::EnsureFocusVisible() { - int iEpFocus = ListView_GetNextItem(m_hWnd, -1, LVNI_FOCUSED); + const int iEpFocus = ListView_GetNextItem(m_hWnd, -1, LVNI_FOCUSED); if (iEpFocus == -1) return; ListView_EnsureVisible(m_hWnd, iEpFocus, TRUE); } -LRESULT EpisodeListView::HandleNotify(LPARAM lParam) +LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) { - LPNMLISTVIEW lpNmLv = (LPNMLISTVIEW)lParam; + const LPNMLISTVIEW lpNmLv = (LPNMLISTVIEW)lParam; switch (lpNmLv->hdr.code) { case LVN_ITEMCHANGED: /* Select/focus episode. */ @@ -66,7 +66,7 @@ LRESULT EpisodeListView::HandleNotify(LPARAM lParam) break; case LVN_COLUMNCLICK: /* Sort by column. */ { - int iColumn = lpNmLv->iSubItem+1; + const int iColumn = lpNmLv->iSubItem+1; m_iSort = abs(m_iSort) == iColumn? -m_iSort: iColumn; Pl("cfg","set_sort",m_iSort); DoSort(); @@ -75,7 +75,7 @@ LRESULT EpisodeListView::HandleNotify(LPARAM lParam) } case LVN_KEYDOWN: /* Navigate episodes by keyboard. */ { - LPNMLVKEYDOWN lpNmLvKd = (LPNMLVKEYDOWN)lParam; + const LPNMLVKEYDOWN lpNmLvKd = (LPNMLVKEYDOWN)lParam; switch (lpNmLvKd->wVKey) { case VK_LEFT: SelectUnwatched(-1); @@ -88,7 +88,7 @@ LRESULT EpisodeListView::HandleNotify(LPARAM lParam) } case NM_CUSTOMDRAW: /* Make unwatched episodes bold. */ { - LPNMLVCUSTOMDRAW lpLvCd = (LPNMLVCUSTOMDRAW)lParam; + const LPNMLVCUSTOMDRAW lpLvCd = (LPNMLVCUSTOMDRAW)lParam; switch (lpLvCd->nmcd.dwDrawStage) { case CDDS_PREPAINT: return CDRF_NOTIFYITEMDRAW; @@ -131,7 +131,7 @@ LRESULT EpisodeListView::HandleNotify(LPARAM lParam) case NM_RCLICK: { extern HMENU g_hPopupMenu; - DWORD dwPos = GetMessagePos(); + const DWORD dwPos = GetMessagePos(); TrackPopupMenu(g_hPopupMenu, TPM_RIGHTBUTTON, LOWORD(dwPos), HIWORD(dwPos), 0, m_hWndParent, NULL); @@ -157,9 +157,9 @@ void EpisodeListView::SaveFocus() Pl("cfg","set_focus",lvi.lParam); } -void EpisodeListView::SetTop(int iItem) +void EpisodeListView::SetTop(const int iItem) { - int iLast = ListView_GetItemCount(m_hWnd)-1; + const int iLast = ListView_GetItemCount(m_hWnd)-1; ListView_EnsureVisible(m_hWnd, iLast, TRUE); ListView_EnsureVisible(m_hWnd, iItem, TRUE); } @@ -237,7 +237,7 @@ void EpisodeListView::SelectUnwatched(int iDir) void EpisodeListView::ShowFocus() { - int iEpFocus = ListView_GetNextItem(m_hWnd, -1, LVNI_FOCUSED); + const int iEpFocus = ListView_GetNextItem(m_hWnd, -1, LVNI_FOCUSED); if (iEpFocus == -1) return; ListView_EnsureVisible(m_hWnd, iEpFocus, TRUE); } @@ -353,7 +353,7 @@ void EpisodeListView::Update() } /* Update episode name and rating. */ -void EpisodeListView::UpdateItem(LPLVITEM lpLvi) +void EpisodeListView::UpdateItem(const LPLVITEM lpLvi) { TCHAR *tszName; int iRating; @@ -375,19 +375,18 @@ r: if (!Pl("episode_data","episode_rating",lpLvi->lParam,&iRating)) { ListView_SetItemText(m_hWnd, lpLvi->iItem, ELVSIRATING, tszRating); } -LRESULT CALLBACK EpisodeListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK EpisodeListView::WndProc(const HWND hWnd, const UINT uMsg, + const WPARAM wParam, const LPARAM lParam) { switch (uMsg) { case WM_GETDLGCODE: { - LRESULT lResult; - /* For the episode list view, the Enter key should not * be handled by the dialog manager, but instead be sent * along to the main window procedure, so that it may be * handled by the NM_RETURN case in ElvHandleNotify. */ - lResult = CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam); + const LRESULT lResult = CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam); if (lParam && ((MSG *)lParam)->message == WM_KEYDOWN && ((MSG *)lParam)->wParam == VK_RETURN) return DLGC_WANTMESSAGE; @@ -398,7 +397,7 @@ LRESULT CALLBACK EpisodeListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, L return ListView::WndProc(hWnd, uMsg, wParam, lParam); } -int CALLBACK ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM lExtra) +int CALLBACK ElvSort(const LPARAM iItem1, const LPARAM iItem2, const LPARAM lExtra) { EpisodeListView *lpElv = (EpisodeListView *)lExtra; @@ -410,7 +409,7 @@ int CALLBACK ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM lExtra) /* abs(m_iSort) is the 1-based index of the column to sort by. * If m_iSort is negative, the order is descending. */ - int iOrder = Cmp(lpElv->m_iSort, 0); + const int iOrder = Cmp(lpElv->m_iSort, 0); switch (abs(lpElv->m_iSort)-1) { case ELVSIEPISODE: diff --git a/c/listview.cpp b/c/listview.cpp index 27529e0..5791226 100644 --- a/c/listview.cpp +++ b/c/listview.cpp @@ -9,7 +9,7 @@ extern HFONT g_hfNormal; static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -ListView::ListView(HWND hWndParent, HMENU hMenu, DWORD dwStyle) +ListView::ListView(const HWND hWndParent, const HMENU hMenu, const DWORD dwStyle) { m_hWndParent = hWndParent; m_bHeader = !(dwStyle & LVS_NOCOLUMNHEADER); @@ -21,13 +21,11 @@ ListView::ListView(HWND hWndParent, HMENU hMenu, DWORD dwStyle) 0, 0, 0, 0, m_hWndParent, hMenu, GetModuleHandle(NULL), this ); - if (SetProp(m_hWnd, TEXT("this"), (HANDLE)this)) m_prevProc = (WNDPROC)SetWindowLongPtr(m_hWnd, GWLP_WNDPROC, (LONG_PTR)::WndProc); ListView_SetExtendedListViewStyle(m_hWnd, LVS_EX_FULLROWSELECT); - SendMessage(m_hWnd, WM_SETFONT, (WPARAM)g_hfNormal, MAKELPARAM(FALSE, 0)); } @@ -36,7 +34,7 @@ int ListView::Height(int bHeader) { if (bHeader == -1) bHeader = m_bHeader; - int iCount = ListView_GetItemCount(m_hWnd); + const int iCount = ListView_GetItemCount(m_hWnd); return iCount? Dpi(bHeader? 27: 4)+iCount*Dpi(19): 0; } @@ -45,7 +43,7 @@ HWND ListView::Handle() const return m_hWnd; } -void ListView::UpdateTheme(BOOL bThemeActive) +void ListView::UpdateTheme(const BOOL bThemeActive) { DWORD dwStyle; LPTSTR tszTheme; @@ -73,7 +71,8 @@ void ListView::UpdateTheme(BOOL bThemeActive) SendMessage(m_hWnd, WM_UPDATEUISTATE, MAKEWPARAM(wAction, UISF_HIDEFOCUS), 0); } -LRESULT CALLBACK ListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK ListView::WndProc(const HWND hWnd, const UINT uMsg, + const WPARAM wParam, const LPARAM lParam) { switch (uMsg) { case WM_NOTIFY: @@ -88,7 +87,8 @@ LRESULT CALLBACK ListView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l return CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam); } -LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, + const LPARAM lParam) { ListView *lpLv = (ListView *)GetProp(hWnd, TEXT("this")); @@ -28,15 +28,14 @@ int g_bViewWatched = 1; int g_bThread = 0; int g_iDPI = 96; static int g_cxVScroll; -void OnTerminate(void); +static void OnTerminate(void); static LRESULT CALLBACK CBTProc(int, WPARAM, LPARAM); static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM); static HWND CreateStatusBar(HWND, HINSTANCE); static void UpdateTheme(void); -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPSTR lpCmdLine, INT nCmdShow) +int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, const LPSTR lpCmdLine, const INT nCmdShow) { /* Exit gracefully on uncaught exception. */ std::set_terminate(OnTerminate); @@ -80,8 +79,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, g_hPopupMenu = LoadMenu(NULL, MAKEINTRESOURCE(IDR_POPUPMENU)); g_hPopupMenu = GetSubMenu(g_hPopupMenu, 0); - WNDCLASSEX wc; - memset(&wc, 0, sizeof(WNDCLASSEX)); + WNDCLASSEX wc = {0}; wc.cbSize = sizeof(WNDCLASSEX); wc.lpfnWndProc = WndProc; wc.hInstance = hInstance; @@ -97,10 +95,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* Create window. Note that a CBT hook is used to initialize * important global variables before any messages are sent to * the new window. */ - HHOOK hHook; - HWND hWnd; - hHook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); - hWnd = CreateWindowEx( + const HHOOK hHook = SetWindowsHookEx(WH_CBT, CBTProc, 0, GetCurrentThreadId()); + const HWND hWnd = CreateWindowEx( 0, TEXT("Episode Browser"), TEXT("Episode Browser"), @@ -133,7 +129,7 @@ void OnTerminate() { try { std::rethrow_exception(std::current_exception()); - } catch (term_t &t) { + } catch (const term_t &t) { TCHAR *tsz; if (PL_get_tchars(t, &tsz, CVT_WRITE)) { MessageBox(NULL, tsz, TEXT("Fatal Error"), MB_ICONERROR); @@ -178,7 +174,7 @@ static LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) return 0; } -LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: @@ -200,11 +196,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) DestroyWindow(hWnd); break; case WM_DESTROY: - { g_lpElv->SaveFocus(); PostQuitMessage(0); break; - } case WM_SIZE: SendMessage(g_hWndStatus, WM_SIZE, wParam, lParam); UpdateLayout(); @@ -221,7 +215,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) break; case 0x02E0: /* WM_DPICHANGED */ { - LPRECT lpr = (LPRECT)lParam; + const LPRECT lpr = (LPRECT)lParam; g_iDPI = HIWORD(wParam); SetWindowPos(hWnd, NULL, lpr->left, lpr->top, @@ -302,7 +296,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ); break; case IDM_VIEW_WATCHED: - { CheckMenuItem(GetMenu(hWnd), IDM_VIEW_WATCHED, g_bViewWatched? MF_UNCHECKED: MF_CHECKED); g_bViewWatched = !g_bViewWatched; @@ -310,9 +303,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) g_lpElv->Update(); g_lpElv->EnsureFocusVisible(); break; - } case IDM_VIEW_TV_ORIGINAL: - { CheckMenuItem(GetMenu(hWnd), IDM_VIEW_TV_ORIGINAL, g_bViewTVOriginal? MF_UNCHECKED: MF_CHECKED); g_bViewTVOriginal = !g_bViewTVOriginal; @@ -320,16 +311,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) g_lpElv->Update(); g_lpElv->EnsureFocusVisible(); break; - } case IDM_VIEW_OTHERS: /* Show/hide other screenwriters. */ - { - int iEpFocus; if (g_szLimitScreenwriter[0]) { CheckMenuItem(GetMenu(hWnd), IDM_VIEW_OTHERS, MF_CHECKED); g_szLimitScreenwriter[0] = 0; } else { - iEpFocus = ListView_GetNextItem(g_lpElv->Handle(), -1, LVNI_FOCUSED); + const int iEpFocus = ListView_GetNextItem(g_lpElv->Handle(), -1, LVNI_FOCUSED); if (iEpFocus == -1) break; LVITEM lvi; @@ -349,7 +337,6 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) g_lpElv->Update(); g_lpElv->EnsureFocusVisible(); break; - } case IDM_WATCH_LOCALLY: case IDM_WATCH_ONLINE: case IDM_TOGGLE: @@ -469,7 +456,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) return 0; } -INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK AboutDlgProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, const LPARAM lParam) { switch (uMsg) { case WM_CLOSE: @@ -489,9 +476,9 @@ INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam return TRUE; } -HWND CreateStatusBar(HWND hWndParent, HINSTANCE hInstance) +HWND CreateStatusBar(const HWND hWndParent, const HINSTANCE hInstance) { - HWND hWnd = CreateWindowEx( + return CreateWindowEx( 0, STATUSCLASSNAME, (LPCTSTR) NULL, @@ -502,7 +489,6 @@ HWND CreateStatusBar(HWND hWndParent, HINSTANCE hInstance) hInstance, NULL ); - return hWnd; } /***/ @@ -537,7 +523,7 @@ void UpdateLayout() SendMessage(g_lpDlv->Handle(), WM_SETREDRAW, TRUE, 0); /* Resize status bar parts. */ - int aParts[] = {rc.right-Dpi(55), rc.right}; + const int aParts[] = {rc.right-Dpi(55), rc.right}; SendMessage(g_hWndStatus, SB_SETPARTS, (WPARAM)sizeof(aParts), (LPARAM)aParts); } @@ -545,7 +531,7 @@ void UpdateLayout() void UpdateTheme() { if (!g_bThemes) return; - BOOL bThemeActive = IsThemeActive(); + const int bThemeActive = IsThemeActive(); g_lpDlv->UpdateTheme(bThemeActive); g_lpElv->UpdateTheme(bThemeActive); } @@ -3,7 +3,7 @@ #include "pl.h" -Query::Query(module_t ctx, predicate_t p, term_t t0) +Query::Query(const module_t ctx, const predicate_t p, const term_t t0) { m_q = PL_open_query(ctx, PL_Q_CATCH_EXCEPTION, p, t0); } @@ -16,25 +16,25 @@ Query::~Query() int Query::Cut() { if (PL_cut_query(m_q)) return 1; - if (term_t t = PL_exception(m_q)) throw t; + if (const term_t t = PL_exception(m_q)) throw t; return 0; } int Query::Close() { if (PL_close_query(m_q)) return 1; - if (term_t t = PL_exception(m_q)) throw t; + if (const term_t t = PL_exception(m_q)) throw t; return 0; } int Query::NextSolution() { if (PL_next_solution(m_q)) return 1; - if (term_t t = PL_exception(m_q)) throw t; + if (const term_t t = PL_exception(m_q)) throw t; return 0; } -int PL_get_tchars(term_t t, TCHAR **lpTsz, int iFlags) +int PL_get_tchars(const term_t t, TCHAR **lpTsz, const int iFlags) { #ifdef UNICODE size_t len; @@ -50,7 +50,7 @@ int PL_get_tchars(term_t t, TCHAR **lpTsz, int iFlags) int Plx(const char *szMod, const char *szPred) { - term_t t = PL_new_term_refs(0); + const term_t t = PL_new_term_refs(0); Query q(NULL, PL_predicate(szPred, 0, szMod), t); return q.NextSolution(); } @@ -19,61 +19,61 @@ private: }; /* 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, wchar_t *x) { return PL_put_atom(t, PL_new_atom_wchars(-1, x)); } -inline int PlPut(term_t t, const wchar_t *x) { return PL_put_atom(t, PL_new_atom_wchars(-1, x)); } -inline int PlPut(term_t, int *) { return -1; } -inline int PlPut(term_t, long *) { return -1; } -inline int PlPut(term_t, long long *) { return -1; } -inline int PlPut(term_t, atom_t *) { return -1; } -inline int PlPut(term_t, char **) { return -1; } -inline int PlPut(term_t, wchar_t **) { return -1; } +inline int PlPut(const term_t t, const int x) { return PL_put_integer(t, x); } +inline int PlPut(const term_t t, const long x) { return PL_put_integer(t, x); } +inline int PlPut(const term_t t, const long long x) { return PL_put_integer(t, x); } +inline int PlPut(const term_t t, const atom_t x) { return PL_put_atom(t, x); } +inline int PlPut(const term_t t, char *x) { return PL_put_atom(t, PL_new_atom(x)); } +inline int PlPut(const term_t t, const char *x) { return PL_put_atom(t, PL_new_atom(x)); } +inline int PlPut(const term_t t, wchar_t *x) { return PL_put_atom(t, PL_new_atom_wchars(-1, x)); } +inline int PlPut(const term_t t, const wchar_t *x) { return PL_put_atom(t, PL_new_atom_wchars(-1, x)); } +inline int PlPut(const term_t, int *) { return -1; } +inline int PlPut(const term_t, long *) { return -1; } +inline int PlPut(const term_t, long long *) { return -1; } +inline int PlPut(const term_t, atom_t *) { return -1; } +inline int PlPut(const term_t, char **) { return -1; } +inline int PlPut(const term_t, wchar_t **) { return -1; } -inline int PlGet(term_t, int) { return -1; } -inline int PlGet(term_t, long) { return -1; } -inline int PlGet(term_t, long long) { return -1; } -inline int PlGet(term_t, atom_t) { return -1; } -inline int PlGet(term_t, char*) { return -1; } -inline int PlGet(term_t, const char *) { 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); } -inline int PlGet(term_t t, wchar_t **x) +inline int PlGet(const term_t, const int) { return -1; } +inline int PlGet(const term_t, const long) { return -1; } +inline int PlGet(const term_t, const long long) { return -1; } +inline int PlGet(const term_t, const atom_t) { return -1; } +inline int PlGet(const term_t, char*) { return -1; } +inline int PlGet(const term_t, const char *) { return -1; } +inline int PlGet(const term_t t, int *x) { return PL_get_integer(t, x); } +inline int PlGet(const term_t t, long *x) { return PL_get_long(t, x); } +inline int PlGet(const term_t t, long long *x) { return PL_get_int64(t, x); } +inline int PlGet(const term_t t, atom_t *x) { return PL_get_atom(t, x); } +inline int PlGet(const term_t t, char **x) { return PL_get_atom_chars(t, x); } +inline int PlGet(const term_t t, wchar_t **x) { atom_t a; - size_t siz; + size_t len; if (!PL_get_atom(t, &a)) return 0; - *x = (wchar_t *)PL_atom_wchars(a, &siz); + *x = (wchar_t *)PL_atom_wchars(a, &len); return *x != NULL; } /* Helper templates for Plx, Pl. */ template <typename T> -int PlPutv(term_t t, T arg) { return PlPut(t, arg); } +int PlPutv(const 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; } +int PlPutv(const 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); } +int PlGetv(const 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; } +int PlGetv(const 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; } +int Countv(const 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...); } +int Countv(const 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); + const int iArity = Countv(0, args...); + const 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; |