aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-17 02:05:15 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-17 02:05:15 +0200
commite96b4db3fb46384f286e9297186b87648c7219c4 (patch)
tree16766c9d41426ee110f374e5915ab5d6b9bcdb2a
parent26bc41099c10b3a63fd744690df5c25cb713718b (diff)
downloadEpisodeBrowser-e96b4db3fb46384f286e9297186b87648c7219c4.tar.gz
Add const to pointers, update spacing.
It seems that "right-spaced" pointers are more widely used among C++ programmers.
-rw-r--r--c/common.cpp6
-rw-r--r--c/common.h8
-rw-r--r--c/datalistview.cpp6
-rw-r--r--c/episodelistview.cpp12
-rw-r--r--c/listview.cpp2
-rw-r--r--c/main.cpp16
-rw-r--r--c/pl.cpp4
-rw-r--r--c/pl.h52
8 files changed, 53 insertions, 53 deletions
diff --git a/c/common.cpp b/c/common.cpp
index 7a1438d..d109081 100644
--- a/c/common.cpp
+++ b/c/common.cpp
@@ -21,12 +21,12 @@ Win32Error::~Win32Error()
HeapFree(GetProcessHeap(), 0, m_szMsg);
}
-const char *Win32Error::what(void) const noexcept
+const char* Win32Error::what(void) const noexcept
{
return m_szMsg;
}
-Library::Library(const TCHAR *tszLibrary)
+Library::Library(const TCHAR* const tszLibrary)
{
m_hModule = LoadLibrary(tszLibrary);
if (!m_hModule)
@@ -38,7 +38,7 @@ Library::~Library()
FreeLibrary(m_hModule);
}
-FARPROC Library::GetProcAddress(const char *szProc)
+FARPROC Library::GetProcAddress(const char* const szProc)
{
return ::GetProcAddress(m_hModule, szProc);
}
diff --git a/c/common.h b/c/common.h
index d6e5848..5528ff6 100644
--- a/c/common.h
+++ b/c/common.h
@@ -15,17 +15,17 @@ struct Win32Error : public std::exception
{
Win32Error(DWORD);
~Win32Error(void);
- virtual const char *what(void) const noexcept override;
+ virtual const char* what(void) const noexcept override;
private:
DWORD m_dwErr;
- char *m_szMsg = NULL;
+ char* const m_szMsg = NULL;
};
struct Library
{
- Library(const TCHAR *);
+ Library(const TCHAR*);
~Library(void);
- FARPROC GetProcAddress(const char *);
+ FARPROC GetProcAddress(const char*);
private:
HMODULE m_hModule;
};
diff --git a/c/datalistview.cpp b/c/datalistview.cpp
index a25cc83..855fd03 100644
--- a/c/datalistview.cpp
+++ b/c/datalistview.cpp
@@ -11,7 +11,7 @@
#include "main.h"
#include "pl.h"
-extern EpisodeListView *g_lpElv;
+extern EpisodeListView* const g_lpElv;
DataListView::DataListView(const HWND hWndParent)
: ListView(hWndParent, (HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER)
@@ -45,8 +45,8 @@ void DataListView::ShowEpisode(const int iEpisode)
PL_predicate("episode_datum", 3, "episode_data"), t);
for (int i = 0; PL_next_solution(q); i++) {
- TCHAR *tszKey;
- TCHAR *tszValue;
+ TCHAR* tszKey;
+ TCHAR* tszValue;
if (!(PlGet(t+1, &tszKey) && PlGet(t+2, &tszValue)))
continue;
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index 4196062..e1119b4 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -10,7 +10,7 @@
#include "listview.h"
#include "pl.h"
-extern DataListView *g_lpDlv;
+extern DataListView* const g_lpDlv;
int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM);
EpisodeListView::EpisodeListView(const HWND hWndParent)
@@ -355,7 +355,7 @@ void EpisodeListView::Update()
/* Update episode name and rating. */
void EpisodeListView::UpdateItem(const LPLVITEM lpLvi)
{
- TCHAR *tszName;
+ TCHAR* tszName;
int iRating;
static TCHAR tszRating[3];
@@ -387,8 +387,8 @@ LRESULT CALLBACK EpisodeListView::WndProc(const HWND hWnd, const UINT uMsg,
* handled by the NM_RETURN case in ElvHandleNotify. */
const LRESULT lResult = CallWindowProc(m_prevProc, hWnd, uMsg, wParam, lParam);
- if (lParam && ((MSG *)lParam)->message == WM_KEYDOWN
- && ((MSG *)lParam)->wParam == VK_RETURN)
+ if (lParam && ((MSG*)lParam)->message == WM_KEYDOWN
+ && ((MSG*)lParam)->wParam == VK_RETURN)
return DLGC_WANTMESSAGE;
return lResult;
}
@@ -399,7 +399,7 @@ LRESULT CALLBACK EpisodeListView::WndProc(const HWND hWnd, const UINT uMsg,
int CALLBACK ElvSort(const LPARAM iItem1, const LPARAM iItem2, const LPARAM lExtra)
{
- EpisodeListView *lpElv = (EpisodeListView *)lExtra;
+ EpisodeListView* const lpElv = (EpisodeListView*)lExtra;
LVITEM lvi1, lvi2;
lvi1.mask = lvi2.mask = LVIF_PARAM;
@@ -427,7 +427,7 @@ int CALLBACK ElvSort(const LPARAM iItem1, const LPARAM iItem2, const LPARAM lExt
}
case ELVSITITLE:
{
- char *sz1, *sz2;
+ char* sz1,* sz2;
int cch, cch1, cch2;
if (!Pl("episode_data","episode_title",lvi1.lParam,&sz1))
return 0;
diff --git a/c/listview.cpp b/c/listview.cpp
index 5791226..4a64398 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -90,7 +90,7 @@ LRESULT CALLBACK ListView::WndProc(const HWND hWnd, const UINT uMsg,
LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
const LPARAM lParam)
{
- ListView *lpLv = (ListView *)GetProp(hWnd, TEXT("this"));
+ ListView* const lpLv = (ListView*)GetProp(hWnd, TEXT("this"));
if (uMsg == WM_DESTROY)
RemoveProp(hWnd, TEXT("this"));
diff --git a/c/main.cpp b/c/main.cpp
index 73d1e3b..36738c5 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -11,8 +11,8 @@
#include "main.h"
#include "pl.h"
-DataListView *g_lpDlv = nullptr;
-EpisodeListView *g_lpElv = nullptr;
+DataListView* g_lpDlv = nullptr;
+EpisodeListView* g_lpElv = nullptr;
atom_t g_aThread;
char g_szLimitScreenwriter[64] = {0};
@@ -63,7 +63,7 @@ int WINAPI WinMain(const HINSTANCE hInstance, const HINSTANCE, const LPSTR lpCmd
g_fBold = CreateFontIndirect(&lf);
/* Initialize Prolog. */
- char *argv[] = { (char *)"EpisodeBrowser", NULL };
+ char* argv[] = { (char*)"EpisodeBrowser", NULL };
if (!PL_initialise(1, argv))
throw std::runtime_error("Could not initialize Prolog.");
if (!Pl("track_episodes","attach") || !Pl("episode_data","attach"))
@@ -129,14 +129,14 @@ void OnTerminate()
{
try {
std::rethrow_exception(std::current_exception());
- } catch (const term_t &t) {
- TCHAR *tsz;
+ } catch (const term_t& t) {
+ TCHAR* tsz;
if (PL_get_tchars(t, &tsz, CVT_WRITE)) {
MessageBox(NULL, tsz, TEXT("Fatal Error"), MB_ICONERROR);
} else
MessageBoxA(NULL, "The program was terminated due to a Prolog exception.",
"Fatal Error", MB_ICONERROR);
- } catch (std::exception &e) {
+ } catch (std::exception& e) {
MessageBoxA(NULL, e.what(), "Fatal Error", MB_ICONERROR);
} catch (...) {
MessageBoxA(NULL, "The program was terminated due to an exception.",
@@ -166,7 +166,7 @@ static LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
g_lpElv = new EpisodeListView(g_hWnd);
/* Get saved view settings. */
- char *sz;
+ char* sz;
Pl("cfg","get_view_watched",&g_bViewWatched);
Pl("cfg","get_view_tv_original",&g_bViewTVOriginal);
if (Pl("cfg","get_limit_screenwriter",&sz))
@@ -325,7 +325,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
lvi.mask = LVIF_PARAM;
if (!ListView_GetItem(g_lpElv->Handle(), &lvi)) break;
- char *sz;
+ char* sz;
if (!Pl("episode_data","episode_datum",lvi.lParam,"Screenwriter",&sz))
break;
strcpy_s(g_szLimitScreenwriter,
diff --git a/c/pl.cpp b/c/pl.cpp
index 307fc1e..dcabd78 100644
--- a/c/pl.cpp
+++ b/c/pl.cpp
@@ -34,7 +34,7 @@ int Query::NextSolution()
return 0;
}
-int PL_get_tchars(const term_t t, TCHAR **lpTsz, const int iFlags)
+int PL_get_tchars(const term_t t, TCHAR** const lpTsz, const int iFlags)
{
#ifdef UNICODE
size_t len;
@@ -48,7 +48,7 @@ int PL_get_tchars(const term_t t, TCHAR **lpTsz, const int iFlags)
#endif
}
-int Plx(const char *szMod, const char *szPred)
+int Plx(const char* const szMod, const char* const szPred)
{
const term_t t = PL_new_term_refs(0);
Query q(NULL, PL_predicate(szPred, 0, szMod), t);
diff --git a/c/pl.h b/c/pl.h
index 9f40676..38fa94f 100644
--- a/c/pl.h
+++ b/c/pl.h
@@ -4,8 +4,8 @@
#include <windows.h>
#include <SWI-Prolog.h>
-int PL_get_tchars(term_t, TCHAR **, int);
-int Plx(const char *, const char *);
+int PL_get_tchars(term_t, TCHAR**, int);
+int Plx(const char*, const char*);
struct Query
{
@@ -23,34 +23,34 @@ 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 PlPut(const term_t t, char* const x) { return PL_put_atom(t, PL_new_atom(x)); }
+inline int PlPut(const term_t t, const char* const x) { return PL_put_atom(t, PL_new_atom(x)); }
+inline int PlPut(const term_t t, wchar_t* const x) { return PL_put_atom(t, PL_new_atom_wchars(-1, x)); }
+inline int PlPut(const term_t t, const wchar_t* const x) { return PL_put_atom(t, PL_new_atom_wchars(-1, x)); }
+inline int PlPut(const term_t, int* const) { return -1; }
+inline int PlPut(const term_t, long* const) { return -1; }
+inline int PlPut(const term_t, long long* const) { return -1; }
+inline int PlPut(const term_t, atom_t* const) { return -1; }
+inline int PlPut(const term_t, char** const) { return -1; }
+inline int PlPut(const term_t, wchar_t** const) { return -1; }
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)
+inline int PlGet(const term_t, char* const) { return -1; }
+inline int PlGet(const term_t, const char* const) { return -1; }
+inline int PlGet(const term_t t, int* const x) { return PL_get_integer(t, x); }
+inline int PlGet(const term_t t, long* const x) { return PL_get_long(t, x); }
+inline int PlGet(const term_t t, long long* const x) { return PL_get_int64(t, x); }
+inline int PlGet(const term_t t, atom_t* const x) { return PL_get_atom(t, x); }
+inline int PlGet(const term_t t, char** const x) { return PL_get_atom_chars(t, x); }
+inline int PlGet(const term_t t, wchar_t** const x)
{
atom_t a;
size_t len;
if (!PL_get_atom(t, &a)) return 0;
- *x = (wchar_t *)PL_atom_wchars(a, &len);
+ *x = (wchar_t*)PL_atom_wchars(a, &len);
return *x != NULL;
}
@@ -70,7 +70,7 @@ 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 Plx(const char* const szMod, const char* const szPred, T... args)
{
const int iArity = Countv(0, args...);
const term_t t = PL_new_term_refs(iArity);
@@ -82,20 +82,20 @@ int Plx(const char *szMod, const char *szPred, T... args)
}
/* Call Prolog predicate, ignoring Prolog exceptions. */
-inline int Pl(const char *szMod, const char *szPred)
+inline int Pl(const char* const szMod, const char* const szPred)
{
try {
return Plx(szMod, szPred);
- } catch (term_t &t) {
+ } catch (term_t& t) {
return 0;
}
}
template <typename ...T>
-int Pl(const char *szMod, const char *szPred, T... args)
+int Pl(const char* const szMod, const char* const szPred, T... args)
{
try {
return Plx(szMod, szPred, args...);
- } catch (term_t &t) {
+ } catch (term_t& t) {
return 0;
}
}