Skip to content

Commit

Permalink
State namespace jsonxx more distinctly
Browse files Browse the repository at this point in the history
  • Loading branch information
teusbenschop committed Apr 14, 2024
1 parent 02a861a commit 7bddd2f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
39 changes: 19 additions & 20 deletions database/notes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <database/logic.h>
#include <time.h>
using namespace std;
using namespace jsonxx;


// Database resilience.
Expand Down Expand Up @@ -568,7 +567,7 @@ int Database_Notes::store_new_note (const string& bible, int book, int chapter,
string path = note_file (identifier);
string folder = filter_url_dirname (path);
filter_url_mkdir (folder);
Object note;
jsonxx::Object note;
note << bible_key () << bible;
note << passage_key () << passage;
note << status_key () << status;
Expand Down Expand Up @@ -1833,11 +1832,11 @@ string Database_Notes::notes_order_by_relevance_statement ()
string Database_Notes::get_bulk (vector <int> identifiers)
{
// JSON container for the bulk notes.
Array bulk;
jsonxx::Array bulk;
// Go through all the notes.
for (auto identifier : identifiers) {
// JSON object for the note.
Object note;
jsonxx::Object note;
// Add all the fields of the note.
string assigned = get_field (identifier, assigned_key ());
note << "a" << assigned;
Expand Down Expand Up @@ -1875,24 +1874,24 @@ vector <string> Database_Notes::set_bulk (string json)
vector <string> summaries;

// Parse the incoming JSON.
Array bulk;
jsonxx::Array bulk;
bulk.parse (json);

// Go through the notes the JSON contains.
for (size_t i = 0; i < bulk.size (); i++) {

// Get all the different fields for this note.
Object note = bulk.get<Object>(static_cast<unsigned>(i));
string assigned = note.get<String> ("a");
string bible = note.get<String> ("b");
string contents = note.get<String> ("c");
int identifier = static_cast<int>(note.get<Number> ("i"));
int modified = static_cast<int>(note.get<Number> ("m"));
string passage = note.get<String> ("p");
string subscriptions = note.get<String> ("sb");
string summary = note.get<String> ("sm");
string status = note.get<String> ("st");
int severity = static_cast<int>(note.get<Number> ("sv"));
jsonxx::Object note = bulk.get<jsonxx::Object>(static_cast<unsigned>(i));
string assigned = note.get<jsonxx::String> ("a");
string bible = note.get<jsonxx::String> ("b");
string contents = note.get<jsonxx::String> ("c");
int identifier = static_cast<int>(note.get<jsonxx::Number> ("i"));
int modified = static_cast<int>(note.get<jsonxx::Number> ("m"));
string passage = note.get<jsonxx::String> ("p");
string subscriptions = note.get<jsonxx::String> ("sb");
string summary = note.get<jsonxx::String> ("sm");
string status = note.get<jsonxx::String> ("st");
int severity = static_cast<int>(note.get<jsonxx::Number> ("sv"));

// Feedback about which note it received in bulk.
summaries.push_back (summary);
Expand All @@ -1901,7 +1900,7 @@ vector <string> Database_Notes::set_bulk (string json)
string path = note_file (identifier);
string folder = filter_url_dirname (path);
filter_url_mkdir (folder);
Object note2;
jsonxx::Object note2;
note2 << assigned_key () << assigned;
note2 << bible_key () << bible;
note2 << contents_key () << contents;
Expand Down Expand Up @@ -1930,10 +1929,10 @@ string Database_Notes::get_field (int identifier, string key)
{
string file = note_file (identifier);
string json = filter_url_file_get_contents (file);
Object note;
jsonxx::Object note;
note.parse (json);
string value;
if (note.has<String> (key)) value = note.get<String> (key);
if (note.has<jsonxx::String> (key)) value = note.get<jsonxx::String> (key);
return value;
}

Expand All @@ -1943,7 +1942,7 @@ void Database_Notes::set_field (int identifier, string key, string value)
{
string file = note_file (identifier);
string json = filter_url_file_get_contents (file);
Object note;
jsonxx::Object note;
note.parse (json);
note << key << value;
json = note.json ();
Expand Down
27 changes: 13 additions & 14 deletions filter/google.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#include <jsonxx/jsonxx.h>
#pragma GCC diagnostic pop
using namespace std;
using namespace jsonxx;


namespace filter::google {
Expand Down Expand Up @@ -121,7 +120,7 @@ tuple <bool, string, string> translate (const string text, const char * source,
const string url { "https://translation.googleapis.com/language/translate/v2" };

// Create the JSON data to post.
Object translation_data;
jsonxx::Object translation_data;
translation_data << "q" << text;
translation_data << "source" << string (source);
translation_data << "target" << string (target);
Expand Down Expand Up @@ -151,12 +150,12 @@ tuple <bool, string, string> translate (const string text, const char * source,
// }
if (error.empty()) {
try {
Object json_object;
jsonxx::Object json_object;
json_object.parse (translation);
Object data = json_object.get<Object> ("data");
Array translations = data.get<Array> ("translations");
Object translated = translations.get<Object>(0);
translation = translated.get<String> ("translatedText");
jsonxx::Object data = json_object.get<jsonxx::Object> ("data");
jsonxx::Array translations = data.get<jsonxx::Array> ("translations");
jsonxx::Object translated = translations.get<jsonxx::Object>(0);
translation = translated.get<jsonxx::String> ("translatedText");
} catch (const exception & exception) {
error = exception.what();
error.append (" - ");
Expand Down Expand Up @@ -189,7 +188,7 @@ vector <pair <string, string> > get_languages (const string & target)
const string url { "https://translation.googleapis.com/language/translate/v2/languages" };

// Create the JSON data to post.
Object request_data;
jsonxx::Object request_data;
request_data << "target" << target;
string postdata = request_data.json ();

Expand Down Expand Up @@ -225,14 +224,14 @@ vector <pair <string, string> > get_languages (const string & target)
vector <pair <string, string> > language_codes_names;
if (error.empty()) {
try {
Object json_object;
jsonxx::Object json_object;
json_object.parse (result_json);
Object data = json_object.get<Object> ("data");
Array languages = data.get<Array> ("languages");
jsonxx::Object data = json_object.get<jsonxx::Object> ("data");
jsonxx::Array languages = data.get<jsonxx::Array> ("languages");
for (size_t i = 0; i < languages.size(); i++) {
Object language_name = languages.get<Object>(static_cast<unsigned>(i));
string language = language_name.get<String>("language");
string name = language_name.get<String>("name");
jsonxx::Object language_name = languages.get<jsonxx::Object>(static_cast<unsigned>(i));
string language = language_name.get<jsonxx::String>("language");
string name = language_name.get<jsonxx::String>("name");
language_codes_names.push_back({language, name});
}
} catch (const exception & exception) {
Expand Down
1 change: 0 additions & 1 deletion resource/external.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#endif
#pragma GCC diagnostic pop
using namespace std;
using namespace jsonxx; // Tpdo


// Local forward declarations:
Expand Down

0 comments on commit 7bddd2f

Please sign in to comment.