TYPED_TEST(DocumentMove, MoveAssignment) { typedef TypeParam Allocator; typedef GenericDocument<UTF8<>, Allocator> Document; Allocator allocator; Document a(&allocator); a.Parse("[\"one\", \"two\", \"three\"]"); EXPECT_FALSE(a.HasParseError()); EXPECT_TRUE(a.IsArray()); EXPECT_EQ(3u, a.Size()); EXPECT_EQ(&a.GetAllocator(), &allocator); // Document b; b = a; // does not compile (!is_copy_assignable) Document b; b = std::move(a); EXPECT_TRUE(a.IsNull()); EXPECT_TRUE(b.IsArray()); EXPECT_EQ(3u, b.Size()); EXPECT_EQ(&a.GetAllocator(), (void*)0); EXPECT_EQ(&b.GetAllocator(), &allocator); b.Parse("{\"Foo\": \"Bar\", \"Baz\": 42}"); EXPECT_FALSE(b.HasParseError()); EXPECT_TRUE(b.IsObject()); EXPECT_EQ(2u, b.MemberCount()); // Document c; c = a; // does not compile (see static_assert) Document c; c = std::move(b); EXPECT_TRUE(b.IsNull()); EXPECT_TRUE(c.IsObject()); EXPECT_EQ(2u, c.MemberCount()); EXPECT_EQ(&b.GetAllocator(), (void*)0); EXPECT_EQ(&c.GetAllocator(), &allocator); }
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParse_MemoryPoolAllocator)) { for (size_t i = 0; i < kTrialCount; i++) { Document doc; doc.Parse(json_); ASSERT_TRUE(doc.IsObject()); } }
LRESULT Cdispatcher_uiDlg::OnReadStats(WPARAM wparam, LPARAM lParam) { char *buf = (char*)wparam; Document d; if (d.Parse(buf).HasParseError()) { int unicodeLen = MultiByteToWideChar(CP_ACP, 0, buf, -1, 0, 0); wchar_t *wc = new wchar_t[unicodeLen+1]; memset(wc, 0, (unicodeLen + 1)*sizeof(wchar_t)); MultiByteToWideChar(CP_ACP, 0, buf, -1, wc, unicodeLen); m_static_msg.SetWindowText(wc); delete[]wc; } else { //read/stats uint64_t count_service = 0; uint64_t count_dispatch = 0; for (Value::ConstMemberIterator iter = d.MemberBegin(); iter != d.MemberEnd(); ++iter) { const char * app = iter->name.GetString(); count_service += iter->value["service"].GetUint64(); count_dispatch += iter->value["dispatch"].GetUint64(); } wchar_t tmp[1024]; swprintf_s(tmp, L"%lld", count_dispatch); m_dispatch_count.SetWindowTextW(tmp); swprintf_s(tmp, L"%lld", count_service); m_service_count.SetWindowTextW(tmp); } return 0; }
int parseJSON(char *json) { Document d; d.Parse(json); Value &uniq = d["uniq"]; Value &faces = d["faces"]; int T = faces.Size(); vec FI = zeros<vec>(3*T); vec FN = zeros<vec>(3*T); for (SizeType i=0; i<T; i++) { FI(i*3 + 0) = faces[i]["a"].GetInt(); FI(i*3 + 1) = faces[i]["b"].GetInt(); FI(i*3 + 2) = faces[i]["c"].GetInt(); FN(i*3 + 0) = faces[i]["normal"]["x"].GetDouble(); FN(i*3 + 1) = faces[i]["normal"]["y"].GetDouble(); FN(i*3 + 2) = faces[i]["normal"]["z"].GetDouble(); } int V = uniq.Size(); vec VI = zeros<vec>(3*V); mat A = zeros<mat>(V, V); for (SizeType i=0; i<V; i++) { VI(i*3 + 0) = uniq[i]["vertex"]["x"].GetDouble(); VI(i*3 + 1) = uniq[i]["vertex"]["y"].GetDouble(); VI(i*3 + 2) = uniq[i]["vertex"]["z"].GetDouble(); Value &edges = uniq[i]["edges"]; int n = edges.Size(); for (SizeType j=0; j<n; j++) { if (i == j) { A(i, j) = 1; } else { double d = (double) 1/n; A(i, j) = -d; } } } mat L, U, P; lu(L, U, P, A); cout << L.t() << endl; vec b = zeros<vec>(V); mat G = zeros<mat>(V, V); int p = 0; int q = V-1; int w = 1000; b(p) = w; G(p, p) = w*w; G(q, q) = w*w; return 0; }
int *createMatrix(int uniq[], int faces[], int edges[][20]) { int n = sizeof(*uniq); int w = 1000; const char* json = "{\"project\":\"rapidjson\",\"stars\":10}"; Document d; d.Parse(json); Value& s = d["stars"]; StringBuffer buffer; Writer<StringBuffer> writer(buffer); d.Accept(writer); cout << buffer.GetString() << endl; sp_mat L = zeros<sp_mat>(n, n); int p = 0; int q = n-1; sp_mat b = zeros<sp_mat>(1, n); b(0, p) = w; sp_mat G = zeros<sp_mat>(n, n); G(p, p) = w*w; G(q, q) = w*w; cout << G.t() << endl; cout << edges[0] << endl; return edges[0]; }
void Bec3::initFromFile(string path){ ifstream conf(path); if (!conf.is_open()) { cout << "\033[31m[ERROR]\033[00m Could'nt load configuration file." << endl; exit(EXIT_FAILURE); } stringstream buffer; buffer << conf.rdbuf(); Document document; document.Parse(buffer.str().c_str()); const Value &user = document["user"]; const Value &objects = document["objects"]; //LOG TO BEC3 WITH USER CONFIGURATION const Value &user_login = user["login"]; const Value &user_password = user["password"]; connect(user_login.GetString(), user_password.GetString() ); //ADD ALL OBJECTS for (SizeType i = 0; i < objects.Size(); ++i) { const Value &id = objects[i]["id"]; const Value &type = objects[i]["type"]; addObject( id.GetString() , type.GetString() ); } timer = std::clock(); }
SerializableSprite* SpriteManager::createSprite(const unordered_map<string, string>& map) { const int x = atoi(map.at("x").c_str()), y = atoi(map.at("y").c_str()); const string className = map.at("className"), properties = map.at("properties"); int64_t rowid = strTo<int64_t>(map.at("rowid")); //CC_ASSERT(rowid != 0); Document json; json.Parse(properties.c_str()); auto it = _createFuncsWithJson.find(className); if (it == _createFuncsWithJson.end()) { log("unable to instantiate sprite. class name: %s, properties: %s", className.c_str(), properties.c_str()); return nullptr; } auto sprite = (*it).second(json); sprite->setPosition(x, y); sprite->setRowid(rowid); sprite->setLocalZOrder(SPRITE_ZORDER); log("SpriteManager::createSprite: x: %d, y: %d, class: %s, properties: %s", x, y, className.c_str(), properties.c_str()); return sprite; }
TYPED_TEST(DocumentMove, MoveAssignmentParseError) { typedef TypeParam Allocator; typedef GenericDocument<UTF8<>, Allocator> Document; ParseResult noError; Document a; a.Parse("{ 4 = 4]"); ParseResult error(a.GetParseError(), a.GetErrorOffset()); EXPECT_TRUE(a.HasParseError()); EXPECT_NE(error.Code(), noError.Code()); EXPECT_NE(error.Offset(), noError.Offset()); Document b; b = std::move(a); EXPECT_FALSE(a.HasParseError()); EXPECT_TRUE(b.HasParseError()); EXPECT_EQ(a.GetParseError(), noError.Code()); EXPECT_EQ(b.GetParseError(), error.Code()); EXPECT_EQ(a.GetErrorOffset(), noError.Offset()); EXPECT_EQ(b.GetErrorOffset(), error.Offset()); Document c; c = std::move(b); EXPECT_FALSE(b.HasParseError()); EXPECT_TRUE(c.HasParseError()); EXPECT_EQ(b.GetParseError(), noError.Code()); EXPECT_EQ(c.GetParseError(), error.Code()); EXPECT_EQ(b.GetErrorOffset(), noError.Offset()); EXPECT_EQ(c.GetErrorOffset(), error.Offset()); }
void test1(... ) { using namespace rapidjson; string json = "{\"project\":\"rapidjson\",\"stars\":10}"; Document doc; doc.Parse( json.data() ); doc.SetString("project"); }
Tactic::Param TDefend::paramFromJSON(string json) { using namespace rapidjson; Tactic::Param tParam; Document d; d.Parse(json.c_str()); tParam.DefendP.x = d["x"].GetDouble(); return tParam; }
TEST(SchemaValidator, Issue608) { Document sd; sd.Parse("{\"required\": [\"a\", \"b\"] }"); SchemaDocument s(sd); VALIDATE(s, "{\"a\" : null, \"b\": null}", true); INVALIDATE(s, "{\"a\" : null, \"a\" : null}", "", "required", ""); }
TEST(SchemaValidator, Enum_Typed) { Document sd; sd.Parse("{ \"type\": \"string\", \"enum\" : [\"red\", \"amber\", \"green\"] }"); SchemaDocument s(sd); VALIDATE(s, "\"red\"", true); INVALIDATE(s, "\"blue\"", "", "enum", ""); }
TEST(SchemaValidator, String) { Document sd; sd.Parse("{\"type\":\"string\"}"); SchemaDocument s(sd); VALIDATE(s, "\"I'm a string\"", true); INVALIDATE(s, "42", "", "type", ""); }
TEST(SchemaValidator, Enum_InvalidType) { Document sd; sd.Parse("{ \"type\": \"string\", \"enum\": [\"red\", \"amber\", \"green\", null] }"); SchemaDocument s(sd); VALIDATE(s, "\"red\"", true); INVALIDATE(s, "null", "", "type", ""); }
TEST_F(RapidJson, SIMD_SUFFIX(DocumentParseStdString_MemoryPoolAllocator)) { const std::string s(json_, length_); for (size_t i = 0; i < kTrialCount; i++) { Document doc; doc.Parse(s); ASSERT_TRUE(doc.IsObject()); } }
int main(int argc, const char* argv[]) { luaL_openlibs(L); luabridge::getGlobalNamespace(L) .beginClass<Entity>("Entity") .addConstructor<void(*)(void)>() .addFunction("say", &Entity::say) .addFunction("getComponent", &Entity::getComponent) .addFunction("addComponent", &Entity::addComponent) .endClass() .beginClass<Component>("Component") .addCFunction("getVariable", &Component::getVariable) .addCFunction("setVariable", &Component::setVariable) .addFunction("getParent", &Component::getParent) .addFunction("addMember", &Component::addMember) .endClass(); // -- LuaScript enemyLuaScript(L, "Enemy.lua"); LuaScript entityLuaScript(L, "Player.lua"); ComponentScript entityScript(&entityLuaScript); ComponentScript enemyScript(&enemyLuaScript); // -- Entity myEntity; myEntity.addComponent(&entityScript); myEntity.addComponent(&enemyScript); Entity myEntity2; myEntity2.addComponent(&enemyScript); // myEntity.onLoop(); // myEntity2.onLoop(); myEntity.getComponent("Player.lua")->getScript()->getReference("doPlayerStuff")->call(myEntity.getComponent("Player.lua"), myEntity2); // -- Document d; d.Parse("{}"); rapidjson::Value entityValue(rapidjson::kObjectType); myEntity.onSerialize(&entityValue, &d.GetAllocator()); myEntity2.onSerialize(&entityValue, &d.GetAllocator()); d.AddMember("entities", entityValue, d.GetAllocator()); rapidjson::StringBuffer sb; rapidjson::Writer<rapidjson::StringBuffer> writer(sb); d.Accept(writer); std::cout << sb.GetString() << "\n"; }
TEST(SchemaValidator, Number_MultipleOfOne) { Document sd; sd.Parse("{\"type\":\"number\",\"multipleOf\":1}"); SchemaDocument s(sd); VALIDATE(s, "42", true); VALIDATE(s, "42.0", true); INVALIDATE(s, "3.1415926", "", "multipleOf", ""); }
TEST(SchemaValidator, Integer_MultipleOf64Boundary) { Document sd; sd.Parse("{\"type\":\"integer\",\"multipleOf\":18446744073709551615}"); SchemaDocument s(sd); VALIDATE(s, "0", true); VALIDATE(s, "18446744073709551615", true); INVALIDATE(s, "18446744073709551614", "", "multipleOf", ""); }
TEST(SchemaValidator, Not) { Document sd; sd.Parse("{\"not\":{ \"type\": \"string\"}}"); SchemaDocument s(sd); VALIDATE(s, "42", true); VALIDATE(s, "{ \"key\": \"value\" }", true); INVALIDATE(s, "\"I am a string\"", "", "not", ""); }
TEST(SchemaValidator, AnyOf) { Document sd; sd.Parse("{\"anyOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" } ] }"); SchemaDocument s(sd); VALIDATE(s, "\"Yes\"", true); VALIDATE(s, "42", true); INVALIDATE(s, "{ \"Not a\": \"string or number\" }", "", "anyOf", ""); }
TEST(SchemaValidator, AllOf) { { Document sd; sd.Parse("{\"allOf\": [{ \"type\": \"string\" }, { \"type\": \"string\", \"maxLength\": 5 }]}"); SchemaDocument s(sd); VALIDATE(s, "\"ok\"", true); INVALIDATE(s, "\"too long\"", "", "allOf", ""); } { Document sd; sd.Parse("{\"allOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" } ] }"); SchemaDocument s(sd); VALIDATE(s, "\"No way\"", false); INVALIDATE(s, "-1", "", "allOf", ""); } }
TEST(SchemaValidator, ObjectInArray) { Document sd; sd.Parse("{\"type\":\"array\", \"items\": { \"type\":\"string\" }}"); SchemaDocument s(sd); VALIDATE(s, "[\"a\"]", true); INVALIDATE(s, "[1]", "/items", "type", "/0"); INVALIDATE(s, "[{}]", "/items", "type", "/0"); }
TEST(SchemaValidator, Array) { Document sd; sd.Parse("{\"type\":\"array\"}"); SchemaDocument s(sd); VALIDATE(s, "[1, 2, 3, 4, 5]", true); VALIDATE(s, "[3, \"different\", { \"types\" : \"of values\" }]", true); INVALIDATE(s, "{\"Not\": \"an array\"}", "", "type", ""); }
void query(string &word) { auto response = cpr::Get(cpr::Url{string(YD_API_URL) + word}); Document doc; doc.Parse(response.text.c_str()); print_explanation(doc); }
TEST(SchemaValidator, Array_UniqueItems) { Document sd; sd.Parse("{\"type\": \"array\", \"uniqueItems\": true}"); SchemaDocument s(sd); VALIDATE(s, "[1, 2, 3, 4, 5]", true); INVALIDATE(s, "[1, 2, 3, 3, 4]", "", "uniqueItems", "/3"); VALIDATE(s, "[]", true); }
TEST(SchemaValidator, String_Pattern_Invalid) { Document sd; sd.Parse("{\"type\":\"string\",\"pattern\":\"a{0}\"}"); // TODO: report regex is invalid somehow SchemaDocument s(sd); VALIDATE(s, "\"\"", true); VALIDATE(s, "\"a\"", true); VALIDATE(s, "\"aa\"", true); }
bool loadJson(const std::string_view json, Document& doc) { if (json.empty() == true) { return false; } // Default template parameter uses UTF8 and MemoryPoolAllocator. return (doc.Parse(json.data(), json.size()).HasParseError() == false); }
TEST(SchemaValidator, Typeless) { Document sd; sd.Parse("{}"); SchemaDocument s(sd); VALIDATE(s, "42", true); VALIDATE(s, "\"I'm a string\"", true); VALIDATE(s, "{ \"an\": [ \"arbitrarily\", \"nested\" ], \"data\": \"structure\" }", true); }
void GBlurProcessor::init(const char* json) { // Read json string to set properties using namespace rapidjson; Document document; document.Parse(json); assert(document.IsObject()); assert(document.HasMember("level")); level = document["level"].GetInt(); }
TEST(SchemaValidator, MultiType) { Document sd; sd.Parse("{ \"type\": [\"number\", \"string\"] }"); SchemaDocument s(sd); VALIDATE(s, "42", true); VALIDATE(s, "\"Life, the universe, and everything\"", true); INVALIDATE(s, "[\"Life\", \"the universe\", \"and everything\"]", "", "type", ""); }