void Identity::initialise(const rapidjson::Value& a) { if (poses && posesJointNames) { std::string postureName; getJSON(a["postureName"], postureName); std::vector<std::string> joints; getJSON(a["joints"], joints); initialise(postureName, joints); } else { throw_named("Poses have not been set!"); } }
bool xmrig::CommonConfig::save() { if (m_fileName.isNull()) { return false; } uv_fs_t req; const int fd = uv_fs_open(uv_default_loop(), &req, m_fileName.data(), O_WRONLY | O_CREAT | O_TRUNC, 0644, nullptr); if (fd < 0) { return false; } uv_fs_req_cleanup(&req); rapidjson::Document doc; getJSON(doc); FILE *fp = fdopen(fd, "w"); char buf[4096]; rapidjson::FileWriteStream os(fp, buf, sizeof(buf)); rapidjson::PrettyWriter<rapidjson::FileWriteStream> writer(os); doc.Accept(writer); fflush(fp); uv_fs_close(uv_default_loop(), &req, fd, nullptr); uv_fs_req_cleanup(&req); LOG_NOTICE("configuration saved to: \"%s\"", m_fileName.data()); return true; }
//-------------------------------------------------------------- void ofApp::loadJSON(){ //if json isn't there ofFile json; string json_file_path = ofToDataPath("innovid_videos.json"); if ( !json.doesFileExist(json_file_path, false) ) { //download, save and load json //this is done on the ui now by hitting the update json button. //could do automatically, but maybe not good if you're not online cout << "json file doesn't exist, lets try to download it" << endl; getJSON(); }else if( json.doesFileExist(json_file_path, false) ){ //else, load saved json cout << "json file exists, lets load it!!!" << endl; std::string file = json_file_path; // Now parse the JSON bool parsingSuccessful = response.open(file); if (parsingSuccessful) { updateJSONDebug(); updateDDL(); } else { cout << "Failed to parse JSON" << endl; } } }
SWIGEXPORT jstring JNICALL Java_com_dsp_1faust_dsp_1faustJNI_getJSON(JNIEnv *jenv, jclass jcls) { jstring jresult = 0 ; char *result = 0 ; (void)jenv; (void)jcls; result = (char *)getJSON(); if (result) jresult = jenv->NewStringUTF((const char *)result); return jresult; }
void TaskMap::initialise(const rapidjson::Value& a, Server_ptr & server, const Scene_ptr & scene_ptr, PlanningProblem_ptr prob) { getJSON(a["class"], object_name_); if (!server) { throw_named("Invalid server!"); } std::vector<std::pair<std::string, std::string> > tmp; initialiseManual(object_name_, server, scene_ptr, prob, tmp); initialise(a); }
void FabricDFGView::saveJsonData() { m_op->setString(UT_String(getJSON().c_str()), CH_STRING_LITERAL, "jsonData", 0, 0); }
//-------------------------------------------------------------- void testApp::guiEvent(ofxUIEventArgs &e) { string name = e.widget->getName(); int kind = e.widget->getKind(); cout << "got event from: " << name << endl; if(name == "iPhone IP") { ofxUITextInput *textinput = (ofxUITextInput *) e.widget; if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_ENTER) { iPhoneIP = textinput->getTextString(); cout << "ON ENTER: "; // ofUnregisterKeyEvents((testApp*)this); } else if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS) { cout << "ON FOCUS: "; } else if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_UNFOCUS) { cout << "ON BLUR: "; // ofRegisterKeyEvents(this); } string output = textinput->getTextString(); cout << output << endl; } if(name == "OS X IP") { ofxUITextInput *textinput = (ofxUITextInput *) e.widget; if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_ENTER) { osxIP = textinput->getTextString(); cout << "ON ENTER: "; // ofUnregisterKeyEvents((testApp*)this); } else if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS) { cout << "ON FOCUS: "; } else if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_UNFOCUS) { cout << "ON BLUR: "; // ofRegisterKeyEvents(this); } string output = textinput->getTextString(); cout << output << endl; } if(name == "iPad IP") { ofxUITextInput *textinput = (ofxUITextInput *) e.widget; if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_ENTER) { iPadIP = textinput->getTextString(); cout << "ON ENTER: "; // ofUnregisterKeyEvents((testApp*)this); } else if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS) { cout << "ON FOCUS: "; } else if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_UNFOCUS) { cout << "ON BLUR: "; // ofRegisterKeyEvents(this); } string output = textinput->getTextString(); cout << output << endl; } else if(name == "Sync Video") { ofxUIToggle *toggle = (ofxUIToggle *) e.widget; setupOSC(); sendOSC = toggle->getValue(); } else if(name == "Download videos") { ofxUIButton *button = (ofxUIButton *) e.widget; //setupOSC(); //sendOSC = toggle->getValue(); if(button->getValue() == 1){ downloadVideos(); } //cout << name << "\t value: " << button->getValue() << endl; } else if(name == "Update JSON") { ofxUIButton *button = (ofxUIButton *) e.widget; //setupOSC(); //sendOSC = toggle->getValue(); if(button->getValue() == 1){ getJSON(); } //cout << name << "\t value: " << button->getValue() << endl; } else if(name == "SELECT A VIDEO") { ofxUIDropDownList *ddlist = (ofxUIDropDownList *) e.widget; vector<ofxUIWidget *> &selected = ddlist->getSelected(); for(int i = 0; i < selected.size(); i++) { cout << "SELECTED: " << selected[i]->getName() << endl; changeVideo(selected[i]->getName()); } } }
EReturn AICOProblem::reinitialise(rapidjson::Document& document, boost::shared_ptr<PlanningProblem> problem) { clear(); if (document.IsArray()) { for (rapidjson::SizeType i = 0; i < document.Size(); i++) { rapidjson::Value& obj = document[i]; if (obj.IsObject()) { std::string constraintClass; if (ok(getJSON(obj["class"], constraintClass))) { if (knownMaps_.find(constraintClass) != knownMaps_.end()) { TaskMap_ptr taskmap; if (ok( TaskMap_fac::Instance().createObject( knownMaps_[constraintClass], taskmap))) { EReturn ret = taskmap->initialise(obj, server_, scenes_, problem); if (ok(ret)) { if (ret != CANCELLED) { std::string name = taskmap->getObjectName(); task_maps_[name] = taskmap; TaskDefinition_ptr task; if (ok( TaskDefinition_fac::Instance().createObject( "TaskSqrError", task))) { TaskSqrError_ptr sqr = boost::static_pointer_cast< TaskSqrError>(task); sqr->setTaskMap(taskmap); int dim; taskmap->taskSpaceDim(dim); sqr->y_star0_.resize(dim); sqr->rho0_(0) = 0.0; sqr->rho1_(0) = 1e4; sqr->object_name_ = name + std::to_string((unsigned long) sqr.get()); // TODO: Better implementation of stting goals from JSON sqr->y_star0_.setZero(); sqr->setTimeSteps(T + 2); Eigen::VectorXd tspan(2); Eigen::VectorXi tspani(2); if (obj["tspan"]["__ndarray__"].IsArray()) { getJSON(obj["tspan"]["__ndarray__"], tspan); } else { getJSON(obj["tspan"], tspan); } if (tspan(0) <= 0.0) tspan(0) = 0.0; if (tspan(1) >= 1.0) tspan(1) = 1.0; tspani(0) = (int) (T * tspan(0)); tspani(1) = (int) (T * tspan(1)); for (int t = tspani(0); t <= tspani(1); t++) { sqr->registerRho( Eigen::VectorXdRef_ptr(sqr->rho1_.segment(0, 1)), t); } sqr->wasFullyInitialised_ = true; task_defs_[name] = task; } else { INDICATE_FAILURE ; return FAILURE; } } else { ROS_WARN_STREAM( "Creation of '"<<constraintClass<<"' cancelled!"); } } else { INDICATE_FAILURE ; return FAILURE; } } else { INDICATE_FAILURE ; return FAILURE; } } else { WARNING("Ignoring unknown constraint '"<<constraintClass<<"'"); } } else { INDICATE_FAILURE ; return FAILURE; } } else { INDICATE_FAILURE ; return FAILURE; } } } else { INDICATE_FAILURE ; return FAILURE; } return SUCCESS; }
void IKProblem::reinitialise(rapidjson::Document& document, boost::shared_ptr<PlanningProblem> problem) { clear(); if (document.IsArray()) { for (rapidjson::SizeType i = 0; i < document.Size(); i++) { rapidjson::Value& obj = document[i]; if (obj.IsObject()) { std::string constraintClass; getJSON(obj["class"], constraintClass); if (knownMaps_.find(constraintClass) != knownMaps_.end()) { TaskMap_ptr taskmap = Initialiser::createMap(knownMaps_[constraintClass]); taskmap->initialise(obj, server_, scene_,problem); std::string name = taskmap->getObjectName(); task_maps_[name] = taskmap; TaskDefinition_ptr task = Initialiser::createDefinition("TaskSqrError"); TaskSqrError_ptr sqr = boost::static_pointer_cast<TaskSqrError>(task); sqr->setTaskMap(taskmap); int dim; taskmap->taskSpaceDim(dim); sqr->y_star0_.resize(dim); sqr->rho0_(0) = 0.0; sqr->rho1_(0) = 1.0; sqr->object_name_ = name+ std::to_string((unsigned long) sqr.get()); // TODO: Better implementation of stting goals from JSON sqr->y_star0_.setZero(); sqr->setTimeSteps(T_); Eigen::VectorXd tspan(2); Eigen::VectorXi tspani(2); // TODO fix ndarray problem getJSON(obj["tspan"], tspan); if (tspan(0) <= 0.0) tspan(0) = 0.0; if (tspan(1) >= 1.0) tspan(1) = 1.0; tspani(0) = (int) ((T_ - 1) * tspan(0)); tspani(1) = (int) ((T_ - 1) * tspan(1)); for (int t = tspani(0); t <= tspani(1); t++) { sqr->registerRho(Eigen::VectorXdRef_ptr(sqr->rho1_.segment(0, 1)),t); } sqr->wasFullyInitialised_ = true; task_defs_[name] = task; } else { // WARNING("Ignoring unknown constraint '"<<constraintClass<<"'"); } } { throw_named("Invalid JSON document object!"); } } } else { throw_named("Invalid JSON array!"); } }
json::Object ReadiumJSApi::getPackageJSON(PackagePtr pckg) { json::Object obj; // Level 0 { obj["rootUrl"] = std::string("/"); //[dict setObject : @"/" forKey:@"rootUrl"]; obj["rendition_layout"] = std::string(""); //[dict setObject : _rendition_layout forKey : @"rendition_layout"]; obj["rendition_flow"] = std::string(""); //[dict setObject : _rendition_flow forKey : @"rendition_flow"]; json::Object spine; json::Array spineItems; size_t idx = 0; shared_ptr<SpineItem> pSpineItem = pckg->SpineItemAt(idx++); while (pSpineItem != 0) { json::Object curItem; shared_ptr<ManifestItem> manifestItem = pSpineItem->ManifestItem(); if (manifestItem) { curItem["href"] = std::string(manifestItem->BaseHref().c_str()); //[dict setObject : _href forKey : @"href"]; } else curItem["href"] = std::string(""); curItem["idref"] = std::string(pSpineItem->Idref().c_str()); //[dict setObject : _idref forKey : @"idref"]; curItem["media_type"] = std::string(pSpineItem->ManifestItem()->MediaType().c_str()); //[dict setObject : _idref forKey : @"idref"]; //pSpineItem->Spread() //enum class PageSpread //{ // Automatic, ///< No value specified by the author. // Left, ///< This is the left page of a spread. // Right, ///< This is the right page of a spread. // Center, ///< This is a double-width page, spread across both left & right. //}; curItem["page_spread"] = std::string(""); //[dict setObject : _page_spread forKey : @"page_spread"]; curItem["rendition_layout"] = std::string(""); //[dict setObject : _rendition_layout forKey : @"rendition_layout"]; curItem["rendition_spread"] = std::string(""); //[dict setObject : _rendition_spread forKey : @"rendition_spread"]; curItem["rendition_flow"] = std::string(""); //[dict setObject : _rendition_flow forKey : @"rendition_flow"]; curItem["media_overlay_id"] = std::string(""); //[dict setObject : _media_overlay_id forKey : @"media_overlay_id"]; spineItems.push_back(curItem); pSpineItem = pckg->SpineItemAt(idx++); } spine["items"] = spineItems; spine["direction"] = std::string("default"); //[dict setObject : _direction forKey : @"direction"]; obj["spine"] = spine; //[dict setObject : [_spine toDictionary] forKey : @"spine"]; json::Object media_overlay; { std::shared_ptr<MediaOverlaysSmilModel> smilModel = pckg->MediaOverlaysSmilModel(); std::vector<std::shared_ptr<SMILData>>::size_type n = smilModel->GetSmilCount(); json::Array smil_models; std::vector<std::shared_ptr<SMILData>>::size_type i = 0; for (i = 0; i < n; ++i) { std::shared_ptr<SMILData> curSmil = smilModel->GetSmil(i); json::Object smilModel; if (curSmil->XhtmlSpineItem()) smilModel["spineItemId"] = std::string(curSmil->XhtmlSpineItem()->Idref().c_str()); else smilModel["spineItemId"] = std::string(""); //smilModel["id"] std::ostringstream stringStream; stringStream << curSmil->DurationMilliseconds_Calculated() / 1000.; std::string copyOfStr = stringStream.str(); smilModel["duration"] = copyOfStr; if (curSmil->SmilManifestItem()) { smilModel["id"] = std::string(curSmil->SmilManifestItem()->Identifier().c_str()); smilModel["href"] = std::string(curSmil->SmilManifestItem()->Href().c_str()); } else { smilModel["id"] = std::string(""); smilModel["href"] = std::string("fake.smil"); } smilModel["smilVersion"] = std::string("3.0"); //[dict setObject : self.children forKey : @"children"]; shared_ptr<const ePub3::SMILData::Sequence> seqBody = curSmil->Body(); json::Array arrChildren = getJSON(seqBody); smilModel["children"] = arrChildren; smil_models.push_back(smilModel); } /* [dict setObject : smilDictionaries forKey : @"smil_models"]; { for (DNSmilModel *mo in _smilModels) { [smilDictionaries addObject : [mo toDictionary]]; } [ [dict setObject : self.id forKey : @"id"]; [dict setObject : self.spineItemId forKey : @"spineItemId"]; [dict setObject : self.href forKey : @"href"]; [dict setObject : self.smilVersion forKey : @"smilVersion"]; [dict setObject : self.duration forKey : @"duration"]; [dict setObject : self.children forKey : @"children"]; ] }*/ media_overlay["smil_models"] = smil_models; json::Array skippables; json::Array escapables; smilModel = pckg->MediaOverlaysSmilModel(); if (smilModel) { std::vector<string>::size_type nCount = smilModel->GetSkippablesCount(); for (std::vector<string>::size_type i = 0; i < nCount; ++i) { string sSkippable = smilModel->GetSkippable(i); skippables.push_back(sSkippable.c_str()); } nCount = smilModel->GetEscapablesCount(); for (std::vector<string>::size_type i = 0; i < nCount; ++i) { string sEsc = smilModel->GetEscapable(i); escapables.push_back(sEsc.c_str()); } } media_overlay["skippables"] = skippables;//[dict setObject : self.skippables forKey : @"skippables"]; media_overlay["escapables"] = escapables;//[dict setObject : self.escapables forKey : @"escapables"]; media_overlay["duration"] = std::string(pckg->MediaOverlays_DurationTotal().c_str()); //[dict setObject : self.duration forKey : @"duration"]; = 1403.5 media_overlay["narrator"] = std::string(pckg->MediaOverlays_Narrator().c_str());//[dict setObject : self.narrator forKey : @"narrator"]; media_overlay["activeClass"] = std::string(pckg->MediaOverlays_ActiveClass().c_str());//[dict setObject : self.activeClass forKey : @"activeClass"];, "activeClass" : "-epub-media-overlay-active", media_overlay["playbackActiveClass"] = std::string(pckg->MediaOverlays_PlaybackActiveClass().c_str());//[dict setObject : self.playbackActiveClass forKey : @"playbackActiveClass"]; } obj["media_overlay"] = media_overlay; //[dict setObject : [_mediaOverlay toDictionary] forKey : @"media_overlay"]; return obj; } return obj; }
json::Array ReadiumJSApi::getJSON(shared_ptr<const ePub3::SMILData::Sequence> seqBody) { json::Array ret; //TODO: populateChildren const shared_vector<const ePub3::SMILData::TimeContainer>::size_type k = seqBody->GetChildrenCount(); shared_vector<const SMILData::TimeContainer>::size_type i = 0; for (; i < k; ++i) { shared_ptr<const SMILData::TimeContainer> timeContainer = seqBody->GetChild(i); json::Object obj; if (timeContainer->IsParallel()) { auto para = std::dynamic_pointer_cast<const ePub3::SMILData::Parallel>(timeContainer); auto audio = para->Audio(); auto text = para->Text(); json::Array ret1; if (audio) { json::Object obj1; { std::ostringstream stringStream; stringStream << audio->ClipEndMilliseconds() / 1000.; std::string copyOfStr = stringStream.str(); obj1["clipEnd"] = copyOfStr; } obj1["nodeType"] = std::string("audio"); obj1["src"] = std::string(audio->SrcFile().c_str()); //"audio\/mobydick_001_002_melville.mp4", { std::ostringstream stringStream; stringStream << audio->ClipBeginMilliseconds() / 1000.; std::string copyOfStr = stringStream.str(); obj1["clipBegin"] = copyOfStr; } ret1.push_back(obj1); } if (text) { json::Object obj2; obj2["srcFile"] = std::string(text->SrcFile().c_str()); //"chapter_002.xhtml", obj2["srcFragmentId"] = std::string(text->SrcFragmentId().c_str()); //"c02h01", obj2["nodeType"] = std::string("text"); obj2["src"] = std::string(text->SrcFile().c_str()) + "#" + std::string(text->SrcFragmentId().c_str()); // "chapter_002.xhtml#c02h01" ret1.push_back(obj2); } obj["children"] = ret1; obj["nodeType"] = std::string("par"); } else if (timeContainer->IsSequence()) { auto sequence = std::dynamic_pointer_cast<const ePub3::SMILData::Sequence>(timeContainer); obj["textref"] = std::string(sequence->TextRefFile().c_str()); //obj["textref"] = json::Array children = getJSON(sequence); obj["children"] = children; obj["nodeType"] = std::string("seq"); } //obj["nodeType"] = std::string(timeContainer->Type().c_str()); obj["epubtype"] = std::string(""); //"textref" : "", //Sequence //timeContainer->Name().c_str(); //"textref" : "", //"epubtype" : "" //"children" : [] //qDebug() << obj; ret.push_back(obj); } return ret; }