Skip to content

Commit

Permalink
state namespace explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Apr 19, 2024
1 parent 0c4ac9f commit a37a5c3
Show file tree
Hide file tree
Showing 90 changed files with 488 additions and 512 deletions.
3 changes: 1 addition & 2 deletions database/bibleactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,4 @@ void Database_BibleActions::erase (std::string bible, int book, int chapter)
sql.add (";");
sql.execute ();
}



9 changes: 4 additions & 5 deletions database/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <database/sqlite.h>
#include <webserver/request.h>
#include <database/logic.h>
using namespace std;


// Database resilience: Stored in plain file system.
Expand Down Expand Up @@ -141,7 +140,7 @@ void Database_Ipc::deleteMessage (int id)
}


string Database_Ipc::getFocus ()
std::string Database_Ipc::getFocus ()
{
std::string user = m_webserver_request.session_logic ()->currentUser ();

Expand Down Expand Up @@ -226,13 +225,13 @@ bool Database_Ipc::getNotesAlive ()
}


string Database_Ipc::folder ()
std::string Database_Ipc::folder ()
{
return filter_url_create_root_path ({database_logic_databases (), "ipc"});
}


string Database_Ipc::file (std::string file)
std::string Database_Ipc::file (std::string file)
{
return filter_url_create_path ({folder (), file});
}
Expand All @@ -243,7 +242,7 @@ string Database_Ipc::file (std::string file)
// The fields are those that can be obtained from the name of the files.
// One file is one entry in the database.
// The filename looks like this: rowid__user__channel__command
vector <Database_Ipc_Item> Database_Ipc::readData ()
std::vector <Database_Ipc_Item> Database_Ipc::readData ()
{
std::vector <Database_Ipc_Item> data;
std::vector <std::string> files = filter_url_scandir (folder ());
Expand Down
11 changes: 4 additions & 7 deletions database/jobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <filter/date.h>
#include <config/globals.h>
#include <database/sqlite.h>
using namespace std;


// Database resilience:
Expand Down Expand Up @@ -158,7 +157,7 @@ void Database_Jobs::set_start (int id, std::string start)
}


string Database_Jobs::get_start (int id)
std::string Database_Jobs::get_start (int id)
{
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT start FROM jobs WHERE id =");
Expand Down Expand Up @@ -189,7 +188,7 @@ void Database_Jobs::set_percentage (int id, int percentage)
}


string Database_Jobs::get_percentage (int id)
std::string Database_Jobs::get_percentage (int id)
{
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT percentage FROM jobs WHERE id =");
Expand Down Expand Up @@ -219,7 +218,7 @@ void Database_Jobs::set_progress (int id, std::string progress)
}


string Database_Jobs::get_progress (int id)
std::string Database_Jobs::get_progress (int id)
{
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT progress FROM jobs WHERE id =");
Expand Down Expand Up @@ -249,7 +248,7 @@ void Database_Jobs::set_result (int id, std::string result)
}


string Database_Jobs::get_result (int id)
std::string Database_Jobs::get_result (int id)
{
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT result FROM jobs WHERE id =");
Expand All @@ -263,5 +262,3 @@ string Database_Jobs::get_result (int id)
}
return std::string();
}


15 changes: 7 additions & 8 deletions database/kjv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <filter/string.h>
#include <config/globals.h>
#include <database/sqlite.h>
using namespace std;


// This is the database for the Strong's numbers and English glosses.
Expand Down Expand Up @@ -77,7 +76,7 @@ const char * Database_Kjv::filename ()


// Get Strong's numbers and English snippets for book / chapter / verse.
vector <Database_Kjv_Item> Database_Kjv::getVerse (int book, int chapter, int verse)
std::vector <Database_Kjv_Item> Database_Kjv::getVerse (int book, int chapter, int verse)
{
std::vector <Database_Kjv_Item> hits;
std::vector <int> rows = rowids (book, chapter, verse);
Expand All @@ -92,15 +91,15 @@ vector <Database_Kjv_Item> Database_Kjv::getVerse (int book, int chapter, int ve


// Get all passages that contain a strong's number.
vector <Passage> Database_Kjv::searchStrong (std::string strong)
std::vector <Passage> Database_Kjv::searchStrong (std::string strong)
{
int strongid = get_id ("strong", strong);
SqliteDatabase sql = SqliteDatabase (filename ());
sql.add ("SELECT DISTINCT book, chapter, verse FROM kjv2 WHERE strong =");
sql.add (strongid);
sql.add ("ORDER BY rowid;");
std::vector <Passage> hits;
std::map <string, std::vector <std::string> > result = sql.query ();
std::map <std::string, std::vector <std::string> > result = sql.query ();
std::vector <std::string> books = result ["book"];
std::vector <std::string> chapters = result ["chapter"];
std::vector <std::string> verses = result ["verse"];
Expand Down Expand Up @@ -144,7 +143,7 @@ void Database_Kjv::store (int book, int chapter, int verse, std::string strong,
}


vector <int> Database_Kjv::rowids (int book, int chapter, int verse)
std::vector <int> Database_Kjv::rowids (int book, int chapter, int verse)
{
SqliteDatabase sql = SqliteDatabase (filename ());
sql.add ("SELECT rowid FROM kjv2 WHERE book =");
Expand All @@ -161,13 +160,13 @@ vector <int> Database_Kjv::rowids (int book, int chapter, int verse)
}


string Database_Kjv::strong (int rowid)
std::string Database_Kjv::strong (int rowid)
{
return get_item ("strong", rowid);
}


string Database_Kjv::english (int rowid)
std::string Database_Kjv::english (int rowid)
{
return get_item ("english", rowid);
}
Expand Down Expand Up @@ -203,7 +202,7 @@ int Database_Kjv::get_id (const char * table_row, std::string item)
}


string Database_Kjv::get_item (const char * item, int rowid)
std::string Database_Kjv::get_item (const char * item, int rowid)
{
// The $rowid refers to the main table.
// Update it so it refers to the sub table.
Expand Down
7 changes: 3 additions & 4 deletions database/localization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <config/globals.h>
#include <database/sqlite.h>
#include <locale/logic.h>
using namespace std;


// Database resilience.
Expand Down Expand Up @@ -53,7 +52,7 @@ void Database_Localization::create (std::string po)
database_sqlite_exec (db, "DROP TABLE IF EXISTS localization;");
database_sqlite_exec (db, "VACUUM;");
database_sqlite_exec (db, "CREATE TABLE IF NOT EXISTS localization (msgid text, msgstr text);");
unordered_map <string, std::string> translations = locale_logic_read_msgid_msgstr (po);
std::unordered_map <std::string, std::string> translations = locale_logic_read_msgid_msgstr (po);
for (auto & element : translations) {
SqliteSQL sql = SqliteSQL ();
sql.add ("INSERT INTO localization VALUES (");
Expand All @@ -67,7 +66,7 @@ void Database_Localization::create (std::string po)
}


string Database_Localization::translate (const std::string& english)
std::string Database_Localization::translate (const std::string& english)
{
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT msgstr FROM localization WHERE msgid =");
Expand All @@ -81,7 +80,7 @@ string Database_Localization::translate (const std::string& english)
}


string Database_Localization::backtranslate (const std::string& localization)
std::string Database_Localization::backtranslate (const std::string& localization)
{
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT msgid FROM localization WHERE msgstr =");
Expand Down
5 changes: 2 additions & 3 deletions database/login.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <filter/md5.h>
#include <filter/roles.h>
#include <filter/date.h>
using namespace std;


// This database is resilient.
Expand Down Expand Up @@ -164,13 +163,13 @@ void Database_Login::renameTokens (std::string username_existing, std::string us

// Returns the username that matches the cookie sent by the browser.
// Once a day, $daily will be set true.
string Database_Login::getUsername (std::string cookie, bool & daily)
std::string Database_Login::getUsername (std::string cookie, bool & daily)
{
SqliteDatabase sql (database ());
sql.add ("SELECT rowid, timestamp, username FROM logins WHERE cookie =");
sql.add (cookie);
sql.add (";");
std::map <string, std::vector <std::string> > result = sql.query ();
std::map <std::string, std::vector <std::string> > result = sql.query ();
if (result.empty()) return std::string();
std::string username = result ["username"][0];
int stamp = filter::strings::convert_to_int (result ["timestamp"] [0]);
Expand Down
7 changes: 3 additions & 4 deletions database/logs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <database/sqlite.h>
#include <filter/date.h>
#include <journal/logic.h>
using namespace std;


// Bibledit no longer uses a database for storing the journal.
Expand Down Expand Up @@ -141,7 +140,7 @@ void Database_Logs::rotate ()


// Get the logbook entries.
vector <std::string> Database_Logs::get (std::string & lastfilename)
std::vector <std::string> Database_Logs::get (std::string & lastfilename)
{
lastfilename = "0";

Expand All @@ -159,7 +158,7 @@ vector <std::string> Database_Logs::get (std::string & lastfilename)

// Gets journal entry more recent than "filename".
// Updates "filename" to the item it got.
string Database_Logs::next (std::string &filename)
std::string Database_Logs::next (std::string &filename)
{
std::vector <std::string> files = filter_url_scandir (folder ());
for (unsigned int i = 0; i < files.size (); i++) {
Expand All @@ -186,7 +185,7 @@ void Database_Logs::clear ()


// The folder where to store the records.
string Database_Logs::folder ()
std::string Database_Logs::folder ()
{
return filter_url_create_root_path ({"logbook"});
}
13 changes: 6 additions & 7 deletions database/mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <webserver/request.h>
#include <database/logs.h>
#include <filter/date.h>
using namespace std;


// Handles mail sent from Bibledit to the users.
Expand Down Expand Up @@ -130,7 +129,7 @@ int Database_Mail::getMailCount ()


// Get the mails of the current user.
vector <Database_Mail_User> Database_Mail::getMails ()
std::vector <Database_Mail_User> Database_Mail::getMails ()
{
std::vector <Database_Mail_User> mails;
std::string user = m_webserver_request.session_logic ()->currentUser();
Expand All @@ -139,7 +138,7 @@ vector <Database_Mail_User> Database_Mail::getMails ()
sql.add (user);
sql.add ("ORDER BY timestamp DESC;");
sqlite3 * db = connect ();
std::map <string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
std::map <std::string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
database_sqlite_disconnect (db);
std::vector <std::string> rowids = result ["rowid"];
std::vector <std::string> timestamps = result ["timestamp"];
Expand Down Expand Up @@ -176,7 +175,7 @@ Database_Mail_Item Database_Mail::get (int id)
sql.add (id);
sql.add (";");
sqlite3 * db = connect ();
std::map <string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
std::map <std::string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
database_sqlite_disconnect (db);
Database_Mail_Item item = Database_Mail_Item ();
if (!result.empty ()) {
Expand All @@ -189,7 +188,7 @@ Database_Mail_Item Database_Mail::get (int id)


// Get ids of all mails ready for sending.
vector <int> Database_Mail::getMailsToSend ()
std::vector <int> Database_Mail::getMailsToSend ()
{
std::vector <int> ids;
int timestamp = filter::date::seconds_since_epoch ();
Expand Down Expand Up @@ -228,9 +227,9 @@ void Database_Mail::postpone (int id)


// Get the row IDs of all mails in the database.
vector <int> Database_Mail::getAllMails ()
std::vector <int> Database_Mail::getAllMails ()
{
std::vector <int> rowids;
std::vector <int> rowids {};
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT rowid FROM mail;");
sqlite3 * db = connect ();
Expand Down
17 changes: 8 additions & 9 deletions database/mappings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <filter/string.h>
#include <database/sqlite.h>
#include <database/books.h>
using namespace std;


// This is a database for the verse mapping systems.
Expand Down Expand Up @@ -189,15 +188,15 @@ void Database_Mappings::import (const std::string& name, const std::string& data


// Exports a mapping.
string Database_Mappings::output (const std::string& name)
std::string Database_Mappings::output (const std::string& name)
{
std::vector <std::string> data;
SqliteSQL sql = SqliteSQL ();
sql.add ("SELECT * FROM maps WHERE name =");
sql.add (name);
sql.add ("ORDER BY book ASC, chapter ASC, verse ASC;");
sqlite3 * db = connect ();
std::map <string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
std::map <std::string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
database_sqlite_disconnect (db);
std::vector <std::string> books = result ["book"];
std::vector <std::string> chapters = result ["chapter"];
Expand Down Expand Up @@ -248,7 +247,7 @@ void Database_Mappings::erase (const std::string& name)


// Returns the mapping names in the database.
vector <std::string> Database_Mappings::names ()
std::vector <std::string> Database_Mappings::names ()
{
// Get the names from the database.
sqlite3 * db = connect ();
Expand All @@ -265,7 +264,7 @@ vector <std::string> Database_Mappings::names ()
}


string Database_Mappings::original ()
std::string Database_Mappings::original ()
{
return "Hebrew Greek";
}
Expand All @@ -277,7 +276,7 @@ string Database_Mappings::original ()
// It returns an array with one passage in most cases.
// When the verses in the $input and $output versifications overlap,
// it may return an array with two passages.
vector <Passage> Database_Mappings::translate (const std::string& input, const std::string& output, int book, int chapter, int verse)
std::vector <Passage> Database_Mappings::translate (const std::string& input, const std::string& output, int book, int chapter, int verse)
{
// Care for situation that the input and output are the same.
if (input == output) {
Expand All @@ -301,7 +300,7 @@ vector <Passage> Database_Mappings::translate (const std::string& input, const s
sql.add (verse);
sql.add (";");
sqlite3 * db = connect ();
std::map <string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
std::map <std::string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
database_sqlite_disconnect (db);
std::vector <std::string> origbooks = result ["origbook"];
std::vector <std::string> origchapters = result ["origchapter"];
Expand Down Expand Up @@ -342,13 +341,13 @@ vector <Passage> Database_Mappings::translate (const std::string& input, const s
sql.add (origverse);
sql.add (";");
sqlite3 * db = connect ();
std::map <string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
std::map <std::string, std::vector <std::string> > result = database_sqlite_query (db, sql.sql);
database_sqlite_disconnect (db);
std::vector <std::string> books = result ["book"];
std::vector <std::string> chapters = result ["chapter"];
std::vector <std::string> verses = result ["verse"];
for (unsigned int i = 0; i < books.size (); i++) {
Passage passage2 = Passage (string(), filter::strings::convert_to_int (books [i]), filter::strings::convert_to_int (chapters [i]), verses [i]);
Passage passage2 = Passage (std::string(), filter::strings::convert_to_int (books [i]), filter::strings::convert_to_int (chapters [i]), verses [i]);
bool passageExists = false;
for (auto & existingpassage : targetpassage) {
if (existingpassage.equal (passage2)) passageExists = true;
Expand Down
Loading

0 comments on commit a37a5c3

Please sign in to comment.