Skip to content

Commit

Permalink
Update RapidJSON to fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kb-1000 committed Jun 2, 2024
1 parent 7a769f0 commit 7fb313c
Show file tree
Hide file tree
Showing 47 changed files with 18,495 additions and 3,380 deletions.
38 changes: 20 additions & 18 deletions source/game/scripts/bind_json.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define RAPIDJSON_HAS_STDSTRING 1
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/prettywriter.h"
Expand All @@ -15,20 +16,21 @@ namespace scripts {

class StrOutputStream {
public:
using Ch = char;
std::string value;

StrOutputStream() {}
void Put(char c) { value += c; }
void Flush() {}
};

static Threaded(rapidjson::MemoryPoolAllocator<>*) allocator = 0;
static Threaded(rapidjson::MemoryPoolAllocator<>*) allocator = nullptr;
rapidjson::MemoryPoolAllocator<>& getAllocator() {
if(!allocator) {
allocator = new rapidjson::MemoryPoolAllocator<>();
addThreadCleanup([]() {
delete allocator;
allocator = 0;
allocator = nullptr;
});
}
return *allocator;
Expand All @@ -39,15 +41,15 @@ class JSONTree : public AtomicRefCounted {
rapidjson::Document doc;

void parse(const std::string& str) {
doc.Parse<0>(str.c_str());
doc.Parse<0>(str);
}

void readFile(const std::string& fname) {
if(!isAccessible(fname)) {
scripts::throwException("Cannot access file outside game or profile directories.");
return;
}
doc.Parse<0>(getFileContents(fname).c_str());
doc.Parse<0>(getFileContents(fname));
}

void writeFile(const std::string& fname, bool pretty) {
Expand Down Expand Up @@ -90,7 +92,7 @@ static std::string nodeString(rapidjson::Value* node) {
scripts::throwException("Node is not a string value.");
return "";
}
return std::string(node->GetString());
return node->GetString();
}

static int nodeBool(rapidjson::Value* node) {
Expand Down Expand Up @@ -159,11 +161,11 @@ static double nodeNumber(rapidjson::Value* node) {
static rapidjson::Value* findMember(rapidjson::Value* node, const std::string& name) {
if(!node->IsObject()) {
scripts::throwException("Node is not an object.");
return 0;
return nullptr;
}
rapidjson::Value::Member* mem = node->FindMember(name.c_str());
if(!mem)
return 0;
auto mem = node->FindMember(name.c_str());
if(mem == node->MemberEnd())
return nullptr;
return &mem->value;
}

Expand All @@ -173,19 +175,19 @@ static void removeMember(rapidjson::Value* node, const std::string& name) {
return;
}

node->RemoveMember(name.c_str());
node->RemoveMember(name);
}

static rapidjson::Value* getMember(rapidjson::Value* node, const std::string& name) {
if(!node->IsObject()) {
scripts::throwException("Node is not an object.");
return 0;
return nullptr;
}
rapidjson::Value::Member* mem = node->FindMember(name.c_str());
if(mem)
auto mem = node->FindMember(name);
if(mem != node->MemberEnd())
return &mem->value;
rapidjson::Value nullValue;
node->AddMember(name.c_str(), getAllocator(), nullValue, getAllocator());
node->AddMember(rapidjson::StringRef(name), nullValue, getAllocator());
return findMember(node, name);
}

Expand All @@ -200,11 +202,11 @@ static void clearItems(rapidjson::Value* node) {
static rapidjson::Value* getItem(rapidjson::Value* node, unsigned index) {
if(!node->IsArray()) {
scripts::throwException("Node is not an array.");
return 0;
return nullptr;
}
if(index >= node->Size()) {
scripts::throwException("Index out of bounds.");
return 0;
return nullptr;
}
return &(*node)[index];
}
Expand All @@ -228,7 +230,7 @@ static void arrReserve(rapidjson::Value* node, unsigned amount) {
static rapidjson::Value* arrPush(rapidjson::Value* node) {
if(!node->IsArray()) {
scripts::throwException("Node is not an array.");
return 0;
return nullptr;
}
rapidjson::Value nullValue;
node->PushBack(nullValue, getAllocator());
Expand All @@ -244,7 +246,7 @@ static void arrPop(rapidjson::Value* node) {
}

static rapidjson::Value* setString(rapidjson::Value* node, const std::string& value) {
node->SetString(value.c_str(), value.size(), getAllocator());
node->SetString(value, getAllocator());
return node;
}

Expand Down
11 changes: 6 additions & 5 deletions source/game/scripts/bind_web.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define RAPIDJSON_HAS_STDSTRING 1
#include "rapidjson/document.h"
#include "scripts/binds.h"
#include "threads.h"
Expand All @@ -19,7 +20,7 @@ static const std::string WikiURI("http://wiki.starruler2.com/api.php?format=json
static const std::string APIURI("http://api.starruler2.com/$1");

static threads::threadreturn threadcall CurlThread(void*);
static const std::string EMPTY_STRING("");
static const std::string EMPTY_STRING{};
struct WebData : AtomicRefCounted {
CURL* curl;
std::string uri;
Expand Down Expand Up @@ -47,7 +48,7 @@ struct WebData : AtomicRefCounted {
}

completed = false;
onPerform = perf;
onPerform = std::move(perf);
uri = URI;
threads::createThread(CurlThread, this);
}
Expand Down Expand Up @@ -524,8 +525,8 @@ bool intoMember(WebData& dat, rapidjson::Value*& node, const char* name) {
dat.errorStr = "Invalid json output. Not an object. "+toString(node->GetType());
return false;
}
rapidjson::Value::Member* mem = node->FindMember(name);
if(!mem) {
auto mem = node->FindMember(name);
if(mem == node->MemberEnd()) {
dat.errorStr = "Invalid json output. No member "+std::string(name);
return false;
}
Expand Down Expand Up @@ -569,7 +570,7 @@ void WikiJSON(WebData& dat) {
return;

rapidjson::Document doc;
doc.Parse<0>(dat.result.c_str());
doc.Parse<0>(dat.result);

rapidjson::Value* cursor = &doc;
if(!intoMember(dat, cursor, "query"))
Expand Down
31 changes: 0 additions & 31 deletions source/rapidjson/example/condense/condense.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions source/rapidjson/example/pretty/pretty.cpp

This file was deleted.

55 changes: 0 additions & 55 deletions source/rapidjson/example/prettyauto/prettyauto.cpp

This file was deleted.

Loading

0 comments on commit 7fb313c

Please sign in to comment.