Add submodules, namespace json to prepare for the addition of rapidjson (sigh)

This commit is contained in:
Henrik Rydgård 2018-08-13 00:05:00 +02:00
parent 42f4d7b40f
commit eddaf97938
12 changed files with 42 additions and 7 deletions

6
.gitmodules vendored
View File

@ -19,3 +19,9 @@
[submodule "ext/SPIRV-Cross"]
path = ext/SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross.git
[submodule "ext/discord-rpc"]
path = ext/discord-rpc
url = https://github.com/discordapp/discord-rpc.git
[submodule "ext/rapidjson"]
path = ext/rapidjson
url = https://github.com/Tencent/rapidjson.git

View File

@ -1162,8 +1162,8 @@ void Config::DownloadCompletedCallback(http::Download &download) {
return;
}
JsonReader reader(data.c_str(), data.size());
const JsonGet root = reader.root();
json::JsonReader reader(data.c_str(), data.size());
const json::JsonGet root = reader.root();
if (!root) {
ERROR_LOG(LOADER, "Failed to parse json");
return;

View File

@ -24,6 +24,8 @@
#include "net/websocket_server.h"
#include "Common/Log.h"
using namespace json;
static inline void DebuggerJsonAddTicket(JsonWriter &writer, const JsonGet &data) {
const JsonNode *value = data.get("ticket");
if (value)

View File

@ -82,6 +82,8 @@ static bool FindServer(std::string &resultHost, int &resultPort) {
std::string json;
result.TakeAll(&json);
using namespace json;
JsonReader reader(json.c_str(), json.size());
if (!reader.ok()) {
return false;

View File

@ -391,6 +391,7 @@ void StoreScreen::update() {
}
void StoreScreen::ParseListing(std::string json) {
using namespace json;
JsonReader reader(json.c_str(), json.size());
if (!reader.ok() || !reader.root()) {
ELOG("Error parsing JSON from store");
@ -540,8 +541,8 @@ std::string StoreScreen::GetStoreJsonURL(std::string storePath) const {
return path;
}
std::string StoreScreen::GetTranslatedString(const JsonGet json, std::string key, const char *fallback) const {
JsonGet dict = json.getDict("en_US");
std::string StoreScreen::GetTranslatedString(const json::JsonGet json, std::string key, const char *fallback) const {
json::JsonGet dict = json.getDict("en_US");
if (dict && json.hasChild(lang_.c_str(), JSON_OBJECT)) {
if (json.getDict(lang_.c_str()).hasChild(key.c_str(), JSON_STRING)) {
dict = json.getDict(lang_.c_str());

View File

@ -29,7 +29,10 @@
// set game specific settings, etc.
// Uses GameInfoCache heavily to implement the functionality.
struct JsonGet;
namespace json {
struct JsonGet;
}
class ProductItemView;
enum EntryType {
@ -79,7 +82,7 @@ private:
std::vector<StoreEntry> FilterEntries();
std::string GetStoreJsonURL(std::string storePath) const;
std::string GetTranslatedString(const JsonGet json, std::string key, const char *fallback = nullptr) const;
std::string GetTranslatedString(const json::JsonGet json, std::string key, const char *fallback = nullptr) const;
std::shared_ptr<http::Download> listing_;
std::shared_ptr<http::Download> image_;

1
ext/discord-rpc Submodule

@ -0,0 +1 @@
Subproject commit 3d3ae7129d17643bc706da0a2eea85aafd10ab3a

View File

@ -2,6 +2,8 @@
#include "file/vfs.h"
#include "json/json_reader.h"
namespace json {
JsonReader::JsonReader(const std::string &filename) {
size_t buf_size;
buffer_ = (char *)VFSReadFile(filename.c_str(), &buf_size);
@ -117,3 +119,5 @@ bool JsonGet::getBool(const char *child_name, bool default_value) const {
}
return default_value;
}
} // namespace json

View File

@ -1,9 +1,12 @@
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/logging.h"
#include "ext/gason/gason.h"
namespace json {
struct JsonGet {
JsonGet(const JsonValue &value) : value_(value) {
}
@ -83,3 +86,5 @@ private:
DISALLOW_COPY_AND_ASSIGN(JsonReader);
};
} // namespace json

View File

@ -1,9 +1,12 @@
#include <iomanip>
#include <cmath>
#include <cstring>
#include "json/json_reader.h"
#include "json/json_writer.h"
namespace json {
JsonWriter::JsonWriter(int flags) {
pretty_ = (flags & PRETTY) != 0;
str_.imbue(std::locale::classic());
@ -383,3 +386,5 @@ static void json_stringify_array(JsonWriter &writer, const JsonNode *node) {
break;
}
}
} // namespace json

View File

@ -13,6 +13,10 @@
#include <vector>
#include <sstream>
struct JsonNode;
namespace json {
class JsonWriter {
public:
JsonWriter(int flags = NORMAL);
@ -79,5 +83,6 @@ private:
bool pretty_;
};
struct JsonNode;
std::string json_stringify(const JsonNode *json);
} // namespace json

1
ext/rapidjson Submodule

@ -0,0 +1 @@
Subproject commit 73063f5002612c6bf64fe24f851cd5cc0d83eef9