//----------------------------------------------------------------------------- bool joint_c::fetch( Reveal::Core::joint_ptr joint, mongo::BSONObj bson ) { assert( joint ); joint->id = bson.getField( FIELD_ID ).String(); mongo::BSONObj bson_q = bson.getObjectField( FIELD_STATE_POSITION ); std::vector<mongo::BSONElement> v_q; bson_q.elems( v_q ); for( unsigned i = 0; i < v_q.size(); i++ ) joint->state.q( i, v_q[i].Double() ); mongo::BSONObj bson_dq = bson.getObjectField( FIELD_STATE_VELOCITY ); std::vector<mongo::BSONElement> v_dq; bson_dq.elems( v_dq ); for( unsigned i = 0; i < v_dq.size(); i++ ) joint->state.dq( i, v_dq[i].Double() ); mongo::BSONObj bson_u = bson.getObjectField( FIELD_CONTROL ); std::vector<mongo::BSONElement> v_u; bson_u.elems( v_u ); for( unsigned i = 0; i < v_u.size(); i++ ) joint->control.u( i, v_u[i].Double() ); return true; }
RepoBSON::RepoBSON( const mongo::BSONObj &obj, const std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> &binMapping) : mongo::BSONObj(obj), bigFiles(binMapping) { std::vector<std::pair<std::string, std::string>> existingFiles; if (bigFiles.size() > 0) { mongo::BSONObjBuilder builder, arrbuilder; for (const auto & pair : bigFiles) { //append field name :file name arrbuilder << pair.first << pair.second.first; } if (obj.hasField(REPO_LABEL_OVERSIZED_FILES)) { arrbuilder.appendElementsUnique(obj.getObjectField(REPO_LABEL_OVERSIZED_FILES)); } builder.append(REPO_LABEL_OVERSIZED_FILES, arrbuilder.obj()); builder.appendElementsUnique(obj); *this = builder.obj(); bigFiles = binMapping; } }
std::string CjsonExporter::toCjson(const mongo::BSONObj &mongoChemObj) { // Follow the database link and convert to CJSON. MongoDatabase *db = MongoDatabase::instance(); if (!db) return ""; mongo::BSONObj structure = mongoChemObj.getObjectField("3dStructure"); if (!structure.hasField("$ref") || !structure.hasField("$id") || !structure.getField("$id").isSimpleType()) { return ""; } std::auto_ptr<mongo::DBClientCursor> cursor = db->query(db->databaseName() + "." + structure.getStringField("$ref"), QUERY("_id" << structure.getField("$id").OID()), 1); mongo::BSONObj object; if (cursor->more()) object = cursor->next(); else return ""; std::vector<std::string> toCopy; toCopy.push_back("name"); toCopy.push_back("inchi"); toCopy.push_back("formula"); toCopy.push_back("properties"); mongo::BSONObjBuilder builder; for (size_t i = 0; i < toCopy.size(); i++) { mongo::BSONElement field = mongoChemObj.getField(toCopy[i]); if (!field.eoo()) builder.append(field); } toCopy.clear(); toCopy.push_back("atoms"); toCopy.push_back("bonds"); for (size_t i = 0; i < toCopy.size(); i++) { mongo::BSONElement field = object.getField(toCopy[i]); if (!field.eoo()) builder.append(field); } // Add the chemical JSON version field. builder.append("chemical json", 0); mongo::BSONObj obj = builder.obj(); return obj.jsonString(mongo::Strict); }
//----------------------------------------------------------------------------- bool joint_c::fetch( Reveal::Core::model_ptr model, mongo::BSONObj bson_model ) { Reveal::Core::joint_ptr joint; mongo::BSONObj bson_joints; std::vector<mongo::BSONElement> v_joints; bson_joints = bson_model.getObjectField( DOCUMENT ); bson_joints.elems( v_joints ); for( unsigned i = 0; i < v_joints.size(); i++ ) { joint = Reveal::Core::joint_ptr( new Reveal::Core::joint_c() ); fetch( joint, v_joints[i].Obj() ); model->joints.push_back( joint ); } return true; }