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 5, 2024
1 parent 4b256ca commit 8831aa4
Show file tree
Hide file tree
Showing 34 changed files with 158 additions and 154 deletions.
4 changes: 2 additions & 2 deletions bb/import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ std::string bible_import (Webserver_Request& webserver_request)
const std::string bible = access_bible::clamp (webserver_request, webserver_request.query["bible"]);
view.set_variable ("bible", filter::strings::escape_special_xml_characters (bible));

const int book = Ipc_Focus::getBook (std::addressof(webserver_request));
const int chapter = Ipc_Focus::getChapter (std::addressof(webserver_request));
const int book = Ipc_Focus::getBook (webserver_request);
const int chapter = Ipc_Focus::getChapter (webserver_request);

// Whether the user has write access to this Bible.
if (bool write_access = access_bible::write (webserver_request, bible); write_access) {
Expand Down
2 changes: 1 addition & 1 deletion changes/changes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ string changes_changes (Webserver_Request& webserver_request)
const int id = filter::strings::convert_to_int (navigate);
const Passage passage = database_modifications.getNotificationPassage (id);
if (passage.m_book) {
Ipc_Focus::set (std::addressof(webserver_request), passage.m_book, passage.m_chapter, filter::strings::convert_to_int (passage.m_verse));
Ipc_Focus::set (webserver_request, passage.m_book, passage.m_chapter, filter::strings::convert_to_int (passage.m_verse));
Navigation_Passage::record_history (std::addressof(webserver_request), passage.m_book, passage.m_chapter, filter::strings::convert_to_int (passage.m_verse));
}
// Set the correct default Bible for the user.
Expand Down
28 changes: 14 additions & 14 deletions demo/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ void demo_clean_data ()
Database_Logs::log ("Cleaning up the demo data");


Webserver_Request request {};
Webserver_Request webserver_request {};


// Set user to the demo credentials (admin).
// This is the user who is always logged-in in a demo installation.
request.session_logic ()->set_username (session_admin_credentials ());
webserver_request.session_logic ()->set_username (session_admin_credentials ());


// Delete empty stylesheet that may have been there.
request.database_styles()->revokeWriteAccess ("", styles_logic_standard_sheet ());
request.database_styles()->deleteSheet ("");
webserver_request.database_styles()->revokeWriteAccess ("", styles_logic_standard_sheet ());
webserver_request.database_styles()->deleteSheet ("");
styles_sheets_create_all ();


// Set both stylesheets to "Standard" for all Bibles.
vector <string> bibles = request.database_bibles()->get_bibles ();
vector <string> bibles = webserver_request.database_bibles()->get_bibles ();
for (const auto & bible : bibles) {
Database_Config_Bible::setExportStylesheet (bible, styles_logic_standard_sheet ());
Database_Config_Bible::setEditorStylesheet (bible, styles_logic_standard_sheet ());
Expand All @@ -152,10 +152,10 @@ void demo_clean_data ()
pair (session_admin_credentials (), Filter_Roles::admin ())
};
for (const auto & element : users) {
if (!request.database_users ()->usernameExists (element.first)) {
request.database_users ()->add_user(element.first, element.first, element.second, "");
if (!webserver_request.database_users ()->usernameExists (element.first)) {
webserver_request.database_users ()->add_user(element.first, element.first, element.second, "");
}
request.database_users ()->set_level (element.first, element.second);
webserver_request.database_users ()->set_level (element.first, element.second);
}


Expand All @@ -167,25 +167,25 @@ void demo_clean_data ()

// Create sample notes.
if (config::logic::default_bibledit_configuration ()) {
demo_create_sample_notes (&request);
demo_create_sample_notes (&webserver_request);
}


// Create samples for the workspaces.
if (config::logic::default_bibledit_configuration ()) {
demo_create_sample_workspaces (&request);
demo_create_sample_workspaces (&webserver_request);
}


// Set navigator to John 3:16.
if (config::logic::default_bibledit_configuration ()) {
Ipc_Focus::set (&request, 43, 3, 16);
Ipc_Focus::set (webserver_request, 43, 3, 16);
}


// Set and/or trim resources to display.
// Too many resources crash the demo: Limit the amount.
vector <string> resources = request.database_config_user()->getActiveResources ();
vector <string> resources = webserver_request.database_config_user()->getActiveResources ();
bool reset_resources {false};
size_t max_resource {25};
if (resources.size () > max_resource) reset_resources = true;
Expand All @@ -196,12 +196,12 @@ void demo_clean_data ()
}
if (reset_resources) {
resources = demo_logic_default_resources ();
request.database_config_user()->setActiveResources (resources);
webserver_request.database_config_user()->setActiveResources (resources);
}


// No flipped basic <> advanded mode.
request.database_config_user ()->setBasicInterfaceMode (false);
webserver_request.database_config_user ()->setBasicInterfaceMode (false);
}


Expand Down
2 changes: 1 addition & 1 deletion edit/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ string edit_edit (Webserver_Request& webserver_request)
{
string passage_query = webserver_request.query ["passage"];
Passage passage = filter_integer_to_passage (filter::strings::convert_to_int (passage_query));
Ipc_Focus::set (std::addressof(webserver_request), passage.m_book, passage.m_chapter, filter::strings::convert_to_int (passage.m_verse));
Ipc_Focus::set (webserver_request, passage.m_book, passage.m_chapter, filter::strings::convert_to_int (passage.m_verse));
Navigation_Passage::record_history (std::addressof(webserver_request), passage.m_book, passage.m_chapter, filter::strings::convert_to_int (passage.m_verse));

// Check whether a Bible editor is alive.
Expand Down
6 changes: 3 additions & 3 deletions edit/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ std::string edit_index (Webserver_Request& webserver_request)
int switchverse = 1;
if (webserver_request.query.count ("switchverse"))
switchverse = filter::strings::convert_to_int (webserver_request.query ["switchverse"]);
Ipc_Focus::set (std::addressof(webserver_request), switchbook, switchchapter, switchverse);
Ipc_Focus::set (webserver_request, switchbook, switchchapter, switchverse);
Navigation_Passage::record_history (std::addressof(webserver_request), switchbook, switchchapter, switchverse);
}

Expand All @@ -78,12 +78,12 @@ std::string edit_index (Webserver_Request& webserver_request)
const std::string bibleselect = webserver_request.post ["bibleselect"];
webserver_request.database_config_user ()->setBible (bibleselect);
// Going to another Bible, ensure that the focused book exists there.
int book = Ipc_Focus::getBook (std::addressof(webserver_request));
int book = Ipc_Focus::getBook (webserver_request);
const std::vector <int> books = webserver_request.database_bibles()->get_books (bibleselect);
if (find (books.begin(), books.end(), book) == books.end()) {
if (!books.empty ()) book = books [0];
else book = 0;
Ipc_Focus::set (std::addressof(webserver_request), book, 1, 1);
Ipc_Focus::set (webserver_request, book, 1, 1);
}
return std::string();
}
Expand Down
6 changes: 3 additions & 3 deletions edit/navigate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ std::string edit_navigate (Webserver_Request& webserver_request)


// If the offset is between the focused verse's min and max values, then do nothing.
int verse = Ipc_Focus::getVerse (std::addressof(webserver_request));
int verse = Ipc_Focus::getVerse (webserver_request);
for (size_t i = 0; i < verses.size (); i++) {
if (verse == verses[i]) {
if (offset >= starting_offsets [i]) {
Expand Down Expand Up @@ -137,8 +137,8 @@ std::string edit_navigate (Webserver_Request& webserver_request)
if (verse >= 0) {
// Only update navigation in case the verse changed.
// This avoids unnecessary focus operations in the clients.
if (verse != Ipc_Focus::getVerse (std::addressof(webserver_request))) {
Ipc_Focus::set (std::addressof(webserver_request), book, chapter, verse);
if (verse != Ipc_Focus::getVerse (webserver_request)) {
Ipc_Focus::set (webserver_request, book, chapter, verse);
}
// The editor should scroll the verse into view,
// because the caret is in the Bible text.
Expand Down
2 changes: 1 addition & 1 deletion edit/position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ std::string edit_position (Webserver_Request& webserver_request)

const std::string stylesheet = Database_Config_Bible::getEditorStylesheet (bible);
const std::string usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter);
const int verse = Ipc_Focus::getVerse (std::addressof(webserver_request));
const int verse = Ipc_Focus::getVerse (webserver_request);


Editor_Usfm2Html editor_usfm2html;
Expand Down
4 changes: 2 additions & 2 deletions edit/preview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ string edit_preview (Webserver_Request& webserver_request)
lineheight,
letterspacing));

int book = Ipc_Focus::getBook (std::addressof(webserver_request));
int chapter = Ipc_Focus::getChapter (std::addressof(webserver_request));
int book = Ipc_Focus::getBook (webserver_request);
int chapter = Ipc_Focus::getChapter (webserver_request);

string stylesheet = Database_Config_Bible::getEditorStylesheet (bible);

Expand Down
2 changes: 1 addition & 1 deletion editone2/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ string editone2_index (Webserver_Request& webserver_request)
if (webserver_request.query.count ("switchbook") && webserver_request.query.count ("switchchapter")) {
int switchbook = filter::strings::convert_to_int (webserver_request.query ["switchbook"]);
int switchchapter = filter::strings::convert_to_int (webserver_request.query ["switchchapter"]);
Ipc_Focus::set (std::addressof(webserver_request), switchbook, switchchapter, 1);
Ipc_Focus::set (webserver_request, switchbook, switchchapter, 1);
Navigation_Passage::record_history (std::addressof(webserver_request), switchbook, switchchapter, 1);
}

Expand Down
8 changes: 4 additions & 4 deletions editone2/verse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ string editone2_verse (Webserver_Request& webserver_request)
// Only update navigation in case the verse changed.
// This avoids unnecessary focus operations in the clients.
int iverse = filter::strings::convert_to_int (sverse);
if (iverse != Ipc_Focus::getVerse (std::addressof(webserver_request))) {
int book = Ipc_Focus::getBook (std::addressof(webserver_request));
int chapter = Ipc_Focus::getChapter (std::addressof(webserver_request));
Ipc_Focus::set (std::addressof(webserver_request), book, chapter, iverse);
if (iverse != Ipc_Focus::getVerse (webserver_request)) {
int book = Ipc_Focus::getBook (webserver_request);
int chapter = Ipc_Focus::getChapter (webserver_request);
Ipc_Focus::set (webserver_request, book, chapter, iverse);
}
}

Expand Down
2 changes: 1 addition & 1 deletion editusfm/focus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ string editusfm_focus (Webserver_Request& webserver_request)
int book = filter::strings::convert_to_int (webserver_request.query ["book"]);
int chapter = filter::strings::convert_to_int (webserver_request.query ["chapter"]);
string usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter);
int verse = Ipc_Focus::getVerse (std::addressof(webserver_request));
int verse = Ipc_Focus::getVerse (webserver_request);
int startingOffset = filter::usfm::versenumber_to_offset (usfm, verse);
int endingOffset = startingOffset;
// The following deals with a combined verse.
Expand Down
2 changes: 1 addition & 1 deletion editusfm/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ std::string editusfm_index (Webserver_Request& webserver_request)
const std::string switchchapter = webserver_request.query ["switchchapter"];
const int book = filter::strings::convert_to_int (switchbook);
const int chapter = filter::strings::convert_to_int (switchchapter);
Ipc_Focus::set (std::addressof(webserver_request), book, chapter, 1);
Ipc_Focus::set (webserver_request, book, chapter, 1);
Navigation_Passage::record_history (std::addressof(webserver_request), book, chapter, 1);
}

Expand Down
4 changes: 2 additions & 2 deletions editusfm/offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ string editusfm_offset (Webserver_Request& webserver_request)
vector <int> verses = filter::usfm::offset_to_versenumber (usfm, offset);
// Only update navigation in case the verse differs.
// This avoids unnecessary focus operations in the clients.
if (!in_array (Ipc_Focus::getVerse (std::addressof(webserver_request)), verses)) {
if (!in_array (Ipc_Focus::getVerse (webserver_request), verses)) {
if (!verses.empty ()) {
Ipc_Focus::set (std::addressof(webserver_request), book, chapter, verses[0]);
Ipc_Focus::set (webserver_request, book, chapter, verses[0]);
}
}
return "";
Expand Down
26 changes: 10 additions & 16 deletions ipc/focus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,39 @@ using namespace std;


// Sets the focus.
void Ipc_Focus::set (void * webserver_request, int book, int chapter, int verse)
void Ipc_Focus::set (Webserver_Request& webserver_request, int book, int chapter, int verse)
{
bool set = false;
if (book != getBook (webserver_request)) set = true;
if (chapter != getChapter (webserver_request)) set = true;
if (verse != getVerse (webserver_request)) set = true;
if (set) {
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);


request->database_config_user()->setFocusedBook (book);
request->database_config_user()->setFocusedChapter (chapter);
request->database_config_user()->setFocusedVerse (verse);
webserver_request.database_config_user()->setFocusedBook (book);
webserver_request.database_config_user()->setFocusedChapter (chapter);
webserver_request.database_config_user()->setFocusedVerse (verse);
}
}


// Gets the focused book.
int Ipc_Focus::getBook (void * webserver_request)
int Ipc_Focus::getBook (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
int book = request->database_config_user()->getFocusedBook ();
int book = webserver_request.database_config_user()->getFocusedBook ();
return book;
}


// Gets the focused chapter.
int Ipc_Focus::getChapter (void * webserver_request)
int Ipc_Focus::getChapter (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
int chapter = request->database_config_user()->getFocusedChapter ();
int chapter = webserver_request.database_config_user()->getFocusedChapter ();
return chapter;
}


// Gets the focused verse.
int Ipc_Focus::getVerse (void * webserver_request)
int Ipc_Focus::getVerse (Webserver_Request& webserver_request)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);
int verse = request->database_config_user()->getFocusedVerse ();
int verse = webserver_request.database_config_user()->getFocusedVerse ();
return verse;
}
10 changes: 6 additions & 4 deletions ipc/focus.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

#include <config/libraries.h>

class Webserver_Request;

class Ipc_Focus
{
public:
static void set (void * webserver_request, int book, int chapter, int verse);
static int getBook (void * webserver_request);
static int getChapter (void * webserver_request);
static int getVerse (void * webserver_request);
static void set (Webserver_Request& webserver_request, int book, int chapter, int verse);
static int getBook (Webserver_Request& webserver_request);
static int getChapter (Webserver_Request& webserver_request);
static int getVerse (Webserver_Request& webserver_request);
private:
};
26 changes: 13 additions & 13 deletions library/bibledit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,15 +416,15 @@ const char * bibledit_get_reference_for_accordance ()
string user = client_logic_get_username ();

// Get the active Bible and its versification system.
Webserver_Request request;
request.session_logic()->set_username(user);
Database_Config_User database_config_user (&request);
string bible = request.database_config_user ()->getBible ();
Webserver_Request webserver_request;
webserver_request.session_logic()->set_username(user);
Database_Config_User database_config_user (&webserver_request);
string bible = webserver_request.database_config_user ()->getBible ();
string versification = Database_Config_Bible::getVersificationSystem (bible);

int book = Ipc_Focus::getBook (&request);
int chapter = Ipc_Focus::getChapter (&request);
int verse = Ipc_Focus::getVerse (&request);
int book = Ipc_Focus::getBook (webserver_request);
int chapter = Ipc_Focus::getChapter (webserver_request);
int verse = Ipc_Focus::getVerse (webserver_request);

// Accordance expects a verse reference in the English versification system.
vector <Passage> passages;
Expand Down Expand Up @@ -456,11 +456,11 @@ void bibledit_put_reference_from_accordance (const char * reference)
{
// Get and set the user name on this client device.
string user = client_logic_get_username ();
Webserver_Request request;
request.session_logic()->set_username(user);
Webserver_Request webserver_request;
webserver_request.session_logic()->set_username(user);

// Setting whether to enable receiving verse references from Accordance.
bool enabled = request.database_config_user ()->getReceiveFocusedReferenceFromAccordance ();
bool enabled = webserver_request.database_config_user ()->getReceiveFocusedReferenceFromAccordance ();
if (!enabled) return;

// Interpret the passage from Accordance, e.g. MAT 1:1.
Expand All @@ -474,8 +474,8 @@ void bibledit_put_reference_from_accordance (const char * reference)
int verse = filter::strings::convert_to_int(chapter_verse[1]);

// Get the active Bible and its versification system.
Database_Config_User database_config_user (&request);
string bible = request.database_config_user ()->getBible ();
Database_Config_User database_config_user (&webserver_request);
string bible = webserver_request.database_config_user ()->getBible ();
string versification = Database_Config_Bible::getVersificationSystem (bible);

// Accordance expects a verse reference in the English versification system.
Expand All @@ -492,5 +492,5 @@ void bibledit_put_reference_from_accordance (const char * reference)
book = passages[0].m_book;
chapter = passages[0].m_chapter;
string verse_s = passages[0].m_verse;
Ipc_Focus::set (&request, book, chapter, verse);
Ipc_Focus::set (webserver_request, book, chapter, verse);
}
2 changes: 1 addition & 1 deletion navigation/paratext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ string navigation_paratext (Webserver_Request& webserver_request)
chapter = passages[0].m_chapter;
verse = filter::strings::convert_to_int (passages[0].m_verse);
// Set the focused passage for Bibledit.
Ipc_Focus::set (std::addressof(webserver_request), book, chapter, verse);
Ipc_Focus::set (webserver_request, book, chapter, verse);
}
}
}
Expand Down
Loading

0 comments on commit 8831aa4

Please sign in to comment.