Skip to content

Commit

Permalink
Clearer types in code rather than void pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Jan 6, 2024
1 parent b6af6cf commit 8b6e2b5
Show file tree
Hide file tree
Showing 42 changed files with 200 additions and 182 deletions.
2 changes: 1 addition & 1 deletion changes/change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ bool changes_change_acl (Webserver_Request& webserver_request)
string changes_change (Webserver_Request& webserver_request)
{
Database_Modifications database_modifications {};
Database_Notes database_notes = Database_Notes (std::addressof(webserver_request));
Database_Notes database_notes = Database_Notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));


Expand Down
2 changes: 1 addition & 1 deletion database/maintenance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void database_maintenance ()
database_ipc.trim ();


Database_Notes database_notes = Database_Notes (&webserver_request);
Database_Notes database_notes = Database_Notes (webserver_request);
database_notes.trim ();
if (!client_mode) database_notes.trim_server ();
database_notes.optimize ();
Expand Down
22 changes: 9 additions & 13 deletions database/notes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ using namespace jsonxx;
*/


Database_Notes::Database_Notes (void * webserver_request_in)
Database_Notes::Database_Notes (Webserver_Request& webserver_request):
m_webserver_request (webserver_request)
{
webserver_request = webserver_request_in;
}


Expand Down Expand Up @@ -228,7 +228,7 @@ void Database_Notes::trim_server ()
// Deal with new notes storage in JSON.
identifiers = get_due_for_deletion ();
for (auto & identifier : identifiers) {
trash_consultation_note (webserver_request, identifier);
trash_consultation_note (std::addressof(m_webserver_request), identifier);
erase (identifier);
}
}
Expand Down Expand Up @@ -292,7 +292,7 @@ void Database_Notes::sync ()
// Any note identifiers in the main index, and not in the filesystem, remove them.
for (auto id : database_identifiers) {
if (find (identifiers.begin(), identifiers.end(), id) == identifiers.end()) {
trash_consultation_note (webserver_request, id);
trash_consultation_note (std::addressof(m_webserver_request), id);
erase (id);
}
}
Expand Down Expand Up @@ -507,9 +507,8 @@ vector <int> Database_Notes::get_identifiers ()
string Database_Notes::assemble_contents (int identifier, string contents)
{
string new_contents = get_contents (identifier);
string datetime = filter::date::localized_date_format (webserver_request);
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string user = request->session_logic ()->currentUser ();
string datetime = filter::date::localized_date_format (std::addressof(m_webserver_request));
string user = m_webserver_request.session_logic ()->currentUser ();
// To make the notes more readable, add whitespace between the comments.
bool is_initial_comment = new_contents.empty ();
if (!is_initial_comment) {
Expand Down Expand Up @@ -624,8 +623,7 @@ int Database_Notes::store_new_note (const string& bible, int book, int chapter,
// limit: If >= 0, it indicates the starting limit for the selection.
vector <int> Database_Notes::select_notes (vector <string> bibles, int book, int chapter, int verse, int passage_selector, int edit_selector, int non_edit_selector, const string& status_selector, string bible_selector, string assignment_selector, bool subscription_selector, int severity_selector, int text_selector, const string& search_text, int limit)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string username = request->session_logic ()->currentUser ();
string username = m_webserver_request.session_logic ()->currentUser ();
vector <int> identifiers;
// SQL SELECT statement.
string query = notes_select_identifier ();
Expand Down Expand Up @@ -906,8 +904,7 @@ void Database_Notes::add_comment (int identifier, const string& comment)
// Subscribe the current user to the note identified by identifier.
void Database_Notes::subscribe (int identifier)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string user = request->session_logic ()->currentUser ();
string user = m_webserver_request.session_logic ()->currentUser ();
subscribe_user (identifier, user);
}

Expand Down Expand Up @@ -989,8 +986,7 @@ bool Database_Notes::is_subscribed (int identifier, const string& user)
// Unsubscribes the currently logged in user from the note identified by identifier.
void Database_Notes::unsubscribe (int identifier)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
string user = request->session_logic ()->currentUser ();
string user = m_webserver_request.session_logic ()->currentUser ();
unsubscribe_user (identifier, user);
}

Expand Down
5 changes: 3 additions & 2 deletions database/notes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <config/libraries.h>
#include <filter/passage.h>

class Webserver_Request;

struct Database_Notes_Text
{
Expand All @@ -35,9 +36,9 @@ class Database_Notes
{

public:
Database_Notes (void * webserver_request_in);
Database_Notes (Webserver_Request& webserver_request);
private:
void * webserver_request {nullptr};
Webserver_Request& m_webserver_request;

public:
void create ();
Expand Down
3 changes: 2 additions & 1 deletion demo/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,8 @@ void demo_prepare_sample_bible ()
// Create sample notes.
void demo_create_sample_notes (void * webserver_request)
{
Database_Notes database_notes (webserver_request);
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
Database_Notes database_notes (*request);
vector <int> identifiers = database_notes.get_identifiers ();
if (identifiers.size () < 10) {
for (int i = 1; i <= 10; i++) {
Expand Down
2 changes: 1 addition & 1 deletion notes/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool notes_actions_acl (Webserver_Request& webserver_request)

string notes_actions (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));


Expand Down
2 changes: 1 addition & 1 deletion notes/assign-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool notes_assign_1_acl (Webserver_Request& webserver_request)

string notes_assign_1 (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));
Database_NoteAssignment database_noteassignment;

Expand Down
2 changes: 1 addition & 1 deletion notes/assign-n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool notes_assign_n_acl (Webserver_Request& webserver_request)

std::string notes_assign_n (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Database_NoteAssignment database_noteassignment;


Expand Down
2 changes: 1 addition & 1 deletion notes/bb-1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool notes_bible_1_acl (Webserver_Request& webserver_request)

string notes_bible_1 (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));


Expand Down
2 changes: 1 addition & 1 deletion notes/bb-n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ bool notes_bible_n_acl (Webserver_Request& webserver_request)

string notes_bible_n (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));


Expand Down
2 changes: 1 addition & 1 deletion notes/bulk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool notes_bulk_acl (Webserver_Request& webserver_request)

string notes_bulk (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));
Database_NoteAssignment database_noteassignment;

Expand Down
2 changes: 1 addition & 1 deletion notes/click.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool notes_click_acl (Webserver_Request& webserver_request)
// This function is called from click.js.
string notes_click (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));


Expand Down
2 changes: 1 addition & 1 deletion notes/comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool notes_comment_acl (Webserver_Request& webserver_request)

string notes_comment (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));


Expand Down
2 changes: 1 addition & 1 deletion notes/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool notes_create_acl (Webserver_Request& webserver_request)

string notes_create (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));

string page;
Expand Down
2 changes: 1 addition & 1 deletion notes/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool notes_edit_acl (Webserver_Request& webserver_request)

string notes_edit (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);
Notes_Logic notes_logic = Notes_Logic (std::addressof(webserver_request));


Expand Down
2 changes: 1 addition & 1 deletion notes/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool notes_index_acl (Webserver_Request& webserver_request)

string notes_index (Webserver_Request& webserver_request)
{
Database_Notes database_notes (std::addressof(webserver_request));
Database_Notes database_notes (webserver_request);

string page;

Expand Down
Loading

0 comments on commit 8b6e2b5

Please sign in to comment.