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"] [submodule "ext/SPIRV-Cross"]
path = ext/SPIRV-Cross path = ext/SPIRV-Cross
url = https://github.com/KhronosGroup/SPIRV-Cross.git 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; return;
} }
JsonReader reader(data.c_str(), data.size()); json::JsonReader reader(data.c_str(), data.size());
const JsonGet root = reader.root(); const json::JsonGet root = reader.root();
if (!root) { if (!root) {
ERROR_LOG(LOADER, "Failed to parse json"); ERROR_LOG(LOADER, "Failed to parse json");
return; return;

View File

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

View File

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

View File

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

View File

@ -29,7 +29,10 @@
// set game specific settings, etc. // set game specific settings, etc.
// Uses GameInfoCache heavily to implement the functionality. // Uses GameInfoCache heavily to implement the functionality.
namespace json {
struct JsonGet; struct JsonGet;
}
class ProductItemView; class ProductItemView;
enum EntryType { enum EntryType {
@ -79,7 +82,7 @@ private:
std::vector<StoreEntry> FilterEntries(); std::vector<StoreEntry> FilterEntries();
std::string GetStoreJsonURL(std::string storePath) const; 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> listing_;
std::shared_ptr<http::Download> image_; 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 "file/vfs.h"
#include "json/json_reader.h" #include "json/json_reader.h"
namespace json {
JsonReader::JsonReader(const std::string &filename) { JsonReader::JsonReader(const std::string &filename) {
size_t buf_size; size_t buf_size;
buffer_ = (char *)VFSReadFile(filename.c_str(), &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; return default_value;
} }
} // namespace json

View File

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

View File

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

View File

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

1
ext/rapidjson Submodule

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