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 7, 2024
1 parent ef67781 commit 0abd702
Show file tree
Hide file tree
Showing 34 changed files with 152 additions and 162 deletions.
2 changes: 1 addition & 1 deletion bb/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ void bible_logic::import_resource (string bible, string resource)
string html;
do {
// Fetch this resource from the server.
html = resource_logic_get_verse (&webserver_request, resource, book, chapter, verse);
html = resource_logic_get_verse (webserver_request, resource, book, chapter, verse);
server_is_installing_module = (html == sword_logic_installing_module_text ());
if (server_is_installing_module) {
Database_Logs::log (translate ("Waiting while Bibledit Cloud installs the requested SWORD module"));
Expand Down
2 changes: 1 addition & 1 deletion consistency/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ string Consistency_Logic::response ()

string Consistency_Logic::verseText (string resource, int book, int chapter, int verse)
{
return resource_logic_get_html (std::addressof(m_webserver_request), resource, book, chapter, verse, false);
return resource_logic_get_html (m_webserver_request, resource, book, chapter, verse, false);
}


Expand Down
2 changes: 1 addition & 1 deletion public/index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ string public_index (Webserver_Request& webserver_request)
view.set_variable ("custom_css", Filter_Css::get_css (clss, fonts::logic::get_font_path (font),
direction, lineheight, letterspacing));

Styles_Css styles_css = Styles_Css (std::addressof(webserver_request), stylesheet);
Styles_Css styles_css (webserver_request, stylesheet);
styles_css.exports ();
styles_css.generate ();
string css = styles_css.css ();
Expand Down
4 changes: 2 additions & 2 deletions resource/comparative1edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ string resource_comparative1edit (Webserver_Request& webserver_request)
if (value.empty()) {
Dialog_List dialog_list = Dialog_List ("comparative1edit", translate("Select a resource to be used as a base resource"), translate ("The base resource is used as a starting point for the comparison."), "");
dialog_list.add_query ("name", name);
vector <string> resources = resource_logic_get_names (std::addressof(webserver_request), true);
vector <string> resources = resource_logic_get_names (webserver_request, true);
for (auto & resource : resources) {
dialog_list.add_row (resource, "base", resource);
}
Expand All @@ -112,7 +112,7 @@ string resource_comparative1edit (Webserver_Request& webserver_request)
if (value.empty()) {
Dialog_List dialog_list = Dialog_List ("comparative1edit", translate("Select a resource to be used as the updated resource."), translate ("The updated resource will be compared with the base resource."), "");
dialog_list.add_query ("name", name);
vector <string> resources = resource_logic_get_names (std::addressof(webserver_request), true);
vector <string> resources = resource_logic_get_names (webserver_request, true);
for (auto & resource : resources) {
dialog_list.add_row (resource, "update", resource);
}
Expand Down
6 changes: 3 additions & 3 deletions resource/get.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ string resource_get (Webserver_Request& webserver_request)
}
}
for (unsigned int i = 0; i < chapters_before.size (); i++) {
bits.push_back (resource_logic_get_html (std::addressof(webserver_request), s_resource, book, chapters_before[i], verses_before[i], add_verse_numbers));
bits.push_back (resource_logic_get_html (webserver_request, s_resource, book, chapters_before[i], verses_before[i], add_verse_numbers));
}


// Focused verse.
bits.push_back (resource_logic_get_html (std::addressof(webserver_request), s_resource, book, chapter, verse, add_verse_numbers));
bits.push_back (resource_logic_get_html (webserver_request, s_resource, book, chapter, verse, add_verse_numbers));


// Context after the focused verse.
Expand All @@ -145,7 +145,7 @@ string resource_get (Webserver_Request& webserver_request)
}
}
for (unsigned int i = 0; i < chapters_after.size (); i++) {
bits.push_back (resource_logic_get_html (std::addressof(webserver_request), s_resource, book, chapters_after[i], verses_after[i], add_verse_numbers));
bits.push_back (resource_logic_get_html (webserver_request, s_resource, book, chapters_after[i], verses_after[i], add_verse_numbers));
}
}
}
Expand Down
42 changes: 18 additions & 24 deletions resource/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,12 @@ Stages to retrieve resource content and serve it.
*/


std::vector <std::string> resource_logic_get_names (void * webserver_request, bool bibles_only)
std::vector <std::string> resource_logic_get_names (Webserver_Request& webserver_request, bool bibles_only)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

std::vector <std::string> names {};

// Bibles the user has read access to.
std::vector <std::string> bibles = access_bible::bibles (*request);
std::vector <std::string> bibles = access_bible::bibles (webserver_request);
names.insert (names.end(), bibles.begin (), bibles.end());

// USFM resources.
Expand Down Expand Up @@ -139,12 +137,10 @@ std::vector <std::string> resource_logic_get_names (void * webserver_request, bo
}


std::string resource_logic_get_html (void * webserver_request,
std::string resource_logic_get_html (Webserver_Request& webserver_request,
std::string resource, int book, int chapter, int verse,
bool add_verse_numbers)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

// Determine the type of the resource.
bool is_bible = resource_logic_is_bible (resource);
bool is_usfm = resource_logic_is_usfm (resource);
Expand Down Expand Up @@ -186,7 +182,7 @@ std::string resource_logic_get_html (void * webserver_request,
Database_Mappings database_mappings;

// Retrieve versification system of the active Bible.
std::string bible = request->database_config_user ()->getBible ();
std::string bible = webserver_request.database_config_user ()->getBible ();
std::string bible_versification = Database_Config_Bible::getVersificationSystem (bible);

// Determine the versification system of the current resource.
Expand Down Expand Up @@ -230,7 +226,7 @@ std::string resource_logic_get_html (void * webserver_request,
bool add_passages_in_full = false;

// Deal with user's preference whether to include related passages.
if (request->database_config_user ()->getIncludeRelatedPassages ()) {
if (webserver_request.database_config_user ()->getIncludeRelatedPassages ()) {

// Take the Bible's active passage and mapping, and translate that to the original mapping.
std::vector <Passage> related_passages = database_mappings.translate (bible_versification, database_mappings.original (), book, chapter, verse);
Expand Down Expand Up @@ -272,10 +268,8 @@ std::string resource_logic_get_html (void * webserver_request,
// This is the most basic version that fetches the text of a $resource.
// It works on server and on client.
// It uses the cache.
std::string resource_logic_get_verse (void * webserver_request, std::string resource, int book, int chapter, int verse)
std::string resource_logic_get_verse (Webserver_Request& webserver_request, std::string resource, int book, int chapter, int verse)
{
Webserver_Request * request = static_cast<Webserver_Request *>(webserver_request);

std::string data {};

// Determine the type of the current resource.
Expand All @@ -297,7 +291,8 @@ std::string resource_logic_get_verse (void * webserver_request, std::string reso

if (isBible || isLocalUsfm) {
std::string chapter_usfm {};
if (isBible) chapter_usfm = request->database_bibles()->get_chapter (resource, book, chapter);
if (isBible)
chapter_usfm = webserver_request.database_bibles()->get_chapter (resource, book, chapter);
if (isLocalUsfm) chapter_usfm = database_usfmresources.getUsfm (resource, book, chapter);
std::string verse_usfm = filter::usfm::get_verse_text (chapter_usfm, verse);
std::string stylesheet = styles_logic_standard_sheet ();
Expand All @@ -323,7 +318,7 @@ std::string resource_logic_get_verse (void * webserver_request, std::string reso
data.append ("<div><img src=\"/resource/imagefetch?name=" + resource + "&image=" + image + "\" alt=\"Image resource\" style=\"width:100%\"></div>");
}
} else if (isLexicon) {
data = lexicon_logic_get_html (*request, resource, book, chapter, verse);
data = lexicon_logic_get_html (webserver_request, resource, book, chapter, verse);
} else if (isSword) {
const std::string sword_module = sword_logic_get_remote_module (resource);
const std::string sword_source = sword_logic_get_source (resource);
Expand Down Expand Up @@ -356,7 +351,7 @@ std::string resource_logic_get_verse (void * webserver_request, std::string reso
}


std::string resource_logic_cloud_get_comparison (void * webserver_request,
std::string resource_logic_cloud_get_comparison (Webserver_Request& webserver_request,
std::string resource, int book, int chapter, int verse,
bool add_verse_numbers)
{
Expand Down Expand Up @@ -429,7 +424,7 @@ std::string resource_logic_cloud_get_comparison (void * webserver_request,
}


std::string resource_logic_cloud_get_translation (void * webserver_request,
std::string resource_logic_cloud_get_translation (Webserver_Request& webserver_request,
const std::string& resource,
int book, int chapter, int verse,
bool add_verse_numbers)
Expand Down Expand Up @@ -515,15 +510,15 @@ std::string resource_logic_get_contents_for_client (std::string resource, int bo
// This type of resource is special.
// It is not one resource, but made out of two resources.
// It fetches data from two resources and combines that into one.
Webserver_Request request {};
return resource_logic_cloud_get_comparison (&request, resource, book, chapter, verse, false);
Webserver_Request webserver_request {};
return resource_logic_cloud_get_comparison (webserver_request, resource, book, chapter, verse, false);
}

if (is_translated) {
// Handle a translated resource.
// This passes the resource title only
Webserver_Request request;
return resource_logic_cloud_get_translation (&request, resource, book, chapter, verse, false);
Webserver_Request webserver_request;
return resource_logic_cloud_get_translation (webserver_request, resource, book, chapter, verse, false);
}

// Nothing found.
Expand Down Expand Up @@ -774,16 +769,15 @@ std::string resource_logic_web_or_cache_get (std::string url, std::string& error


// Returns the page type for the resource selector.
std::string resource_logic_selector_page (void * webserver_request)
std::string resource_logic_selector_page (Webserver_Request& webserver_request)
{
Webserver_Request * request {static_cast<Webserver_Request *>(webserver_request)};
std::string page {request->query["page"]};
std::string page {webserver_request.query["page"]};
return page;
}


// Returns the page which called the resource selector.
std::string resource_logic_selector_caller (void * webserver_request)
std::string resource_logic_selector_caller (Webserver_Request& webserver_request)
{
std::string caller = resource_logic_selector_page (webserver_request);
if (caller == "view") caller = "organize";
Expand Down
16 changes: 9 additions & 7 deletions resource/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@

#include <config/libraries.h>

std::string resource_logic_get_html (void * webserver_request,
class Webserver_Request;

std::string resource_logic_get_html (Webserver_Request& webserver_request,
std::string resource, int book, int chapter, int verse,
bool add_verse_numbers);
std::string resource_logic_get_verse (void * webserver_request, std::string resource, int book, int chapter, int verse);
std::string resource_logic_cloud_get_comparison (void * webserver_request,
std::string resource_logic_get_verse (Webserver_Request& webserver_request, std::string resource, int book, int chapter, int verse);
std::string resource_logic_cloud_get_comparison (Webserver_Request& webserver_request,
std::string resource, int book, int chapter, int verse,
bool add_verse_numbers);
std::string resource_logic_cloud_get_translation (void * webserver_request,
std::string resource_logic_cloud_get_translation (Webserver_Request& webserver_request,
const std::string & resource, int book, int chapter, int verse,
bool add_verse_numbers);
std::string resource_logic_get_contents_for_client (std::string resource, int book, int chapter, int verse);
std::string resource_logic_client_fetch_cache_from_cloud (std::string resource, int book, int chapter, int verse);

std::vector <std::string> resource_logic_get_names (void * webserver_request, bool bibles_only);
std::vector <std::string> resource_logic_get_names (Webserver_Request& webserver_request, bool bibles_only);

void resource_logic_import_images (std::string resource, std::string path);

Expand All @@ -52,8 +54,8 @@ std::string resource_logic_assemble_rich_divider (std::string title, std::string

std::string resource_logic_web_or_cache_get (std::string url, std::string & error);

std::string resource_logic_selector_page (void * webserver_request);
std::string resource_logic_selector_caller (void * webserver_request);
std::string resource_logic_selector_page (Webserver_Request& webserver_request);
std::string resource_logic_selector_caller (Webserver_Request& webserver_request);

std::string resource_logic_default_user_url ();

Expand Down
18 changes: 9 additions & 9 deletions resource/print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,33 +322,33 @@ string resource_print (Webserver_Request& webserver_request)

void resource_print_job (string jobId, string user, string bible)
{
Webserver_Request request;
request.session_logic ()->set_username (user);
Webserver_Request webserver_request;
webserver_request.session_logic ()->set_username (user);


Database_Jobs database_jobs = Database_Jobs ();
database_jobs.set_progress (filter::strings::convert_to_int (jobId), translate("The document is being created..."));


vector <string> resources = request.database_config_user()->getPrintResourcesForUser (user);
vector <string> resources = webserver_request.database_config_user()->getPrintResourcesForUser (user);


Passage from = request.database_config_user()->getPrintPassageFromForUser (user);
Passage from = webserver_request.database_config_user()->getPrintPassageFromForUser (user);
int ifrom = filter_passage_to_integer (from);


Passage to = request.database_config_user()->getPrintPassageToForUser (user);
Passage to = webserver_request.database_config_user()->getPrintPassageToForUser (user);
int ito = filter_passage_to_integer (to);


vector <string> result;


vector <int> books = request.database_bibles()->get_books (bible);
vector <int> books = webserver_request.database_bibles()->get_books (bible);
for (auto & book : books) {
vector <int> chapters = request.database_bibles()->get_chapters (bible, book);
vector <int> chapters = webserver_request.database_bibles()->get_chapters (bible, book);
for (auto & chapter : chapters) {
string usfm = request.database_bibles()->get_chapter (bible, book, chapter);
string usfm = webserver_request.database_bibles()->get_chapter (bible, book, chapter);
vector <int> verses = filter::usfm::get_verse_numbers (usfm);
for (auto & verse : verses) {
int passage = filter_passage_to_integer (Passage ("", book, chapter, filter::strings::convert_to_string (verse)));
Expand All @@ -360,7 +360,7 @@ void resource_print_job (string jobId, string user, string bible)
for (auto & resource : resources) {
result.push_back ("<p>");
result.push_back (resource);
string html = resource_logic_get_html (&request, resource, book, chapter, verse, false);
string html = resource_logic_get_html (webserver_request, resource, book, chapter, verse, false);
result.push_back (html);
result.push_back ("</p>");
}
Expand Down
4 changes: 2 additions & 2 deletions resource/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ string resource_select (Webserver_Request& webserver_request)
Assets_View view {};


view.set_variable ("page", resource_logic_selector_page (std::addressof(webserver_request)));
view.set_variable ("page", resource_logic_selector_page (webserver_request));
bool is_def = false;
if (webserver_request.query["type"] == "def") is_def = true;
if (is_def) view.set_variable ("type", "def");
string caller = resource_logic_selector_caller (std::addressof(webserver_request));
string caller = resource_logic_selector_caller (webserver_request);
view.set_variable ("caller", caller);


Expand Down
2 changes: 1 addition & 1 deletion resource/translated1edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ string resource_translated1edit (Webserver_Request& webserver_request)
if (value.empty()) {
Dialog_List dialog_list = Dialog_List ("translated1edit", translate("Select a resource to be used as the original resource"), translate ("The original resource will be translated from the source language to the target language."), string());
dialog_list.add_query ("name", name);
vector <string> resources = resource_logic_get_names (std::addressof(webserver_request), true);
vector <string> resources = resource_logic_get_names (webserver_request, true);
for (const auto & resource : resources) {
dialog_list.add_row (resource, "original", resource);
}
Expand Down
2 changes: 1 addition & 1 deletion sendreceive/bibles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void sendreceive_bibles ()


Webserver_Request webserver_request;
Sync_Logic sync_logic = Sync_Logic (&webserver_request);
Sync_Logic sync_logic = Sync_Logic (webserver_request);


string response = client_logic_connection_setup ("", "");
Expand Down
Loading

0 comments on commit 0abd702

Please sign in to comment.