コード例 #1
0
    MongoCollectionInfo::MongoCollectionInfo(mongo::BSONObj stats):_ns(QString::fromStdString(stats.getStringField("ns")))
    {
        // if "size" and "storageSize" are of type Int32 or Int64, they
        // will be converted to double by "numberDouble()" function.
        _sizeBytes = stats.getField("size").numberDouble();
        _storageSizeBytes = stats.getField("storageSize").numberDouble();

        _count = stats.getIntField("count");
    }
コード例 #2
0
ファイル: trial.cpp プロジェクト: jacquelinekay/reveal
//-----------------------------------------------------------------------------
bool trial_c::map( Reveal::Core::trial_ptr& trial, mongo::BSONObj obj ) { 

  trial = Reveal::Core::trial_ptr( new Reveal::Core::trial_c() );

  trial->scenario_id = obj.getField( "scenario_id" ).String();
  trial->t = obj.getField( "t" ).Double();

  model_c::fetch( trial, obj );

  return true;
}
コード例 #3
0
/** Good if one primary and rest secondaries and arbiters */
static bool goodReplStatus (mongo::BSONObj &info) {
	if (!info.getField("ok").trueValue()) return false;
	vector<mongo::BSONElement> ms = info.getField("members").Array();
	bool primary = false;
	for (unsigned i = 0; i < ms.size(); i++) {
		int state = ms[i].Obj().getIntField("state");
		if (state == 1) {primary = true; continue;}
		if (state != 2 && state != 7) return false;
	}
	return primary;
}
コード例 #4
0
ファイル: solution.cpp プロジェクト: jacquelinekay/reveal
//-----------------------------------------------------------------------------
bool solution_c::map( Reveal::Core::solution_ptr& solution, mongo::BSONObj obj, Reveal::Core::solution_c::type_e type ) { 
  solution = Reveal::Core::solution_ptr( new Reveal::Core::solution_c( type ) );

  if( type == Reveal::Core::solution_c::CLIENT )
    solution->experiment_id = obj.getField( "experiment_id" ).String();
  solution->scenario_id = obj.getField( "scenario_id" ).String();
  solution->t = obj.getField( "t" ).Double();
  if( type == Reveal::Core::solution_c::CLIENT )
    solution->real_time = obj.getField( "real_time" ).Double();

  model_c::fetch( solution, obj );

  return true;
}
コード例 #5
0
ファイル: joint.cpp プロジェクト: jacquelinekay/reveal
//-----------------------------------------------------------------------------
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;
}
コード例 #6
0
repo::core::RepoNodeTexture::RepoNodeTexture(const mongo::BSONObj &obj)
    : RepoNodeAbstract(obj)
    , data(NULL)
{
	//
	// Width
	//
    if (obj.hasField(REPO_LABEL_WIDTH))
        width = obj.getField(REPO_LABEL_WIDTH).numberInt();

	//
	// Height
	//
    if (obj.hasField(REPO_LABEL_HEIGHT))
        height = obj.getField(REPO_LABEL_HEIGHT).numberInt();

	//
	// Format
	//
	if (obj.hasField(REPO_NODE_LABEL_EXTENSION)) {
		extension = obj.getField(REPO_NODE_LABEL_EXTENSION).str();
		name += "." + extension; // assimp needs full names with extension
	}

	//
	// Bit depth
	//
	//if (obj.hasField(REPO_NODE_LABEL_BIT_DEPTH))
	//	bitDepth = obj.getField(REPO_NODE_LABEL_BIT_DEPTH).numberInt();

	//
	// Data
	//
    if (obj.hasField(REPO_LABEL_DATA) &&
		obj.hasField(REPO_NODE_LABEL_DATA_BYTE_COUNT))
	{

        std::cerr << "Texture" << std::endl;
		data = new std::vector<char>();
		RepoTranscoderBSON::retrieve(
            obj.getField(REPO_LABEL_DATA),
			obj.getField(REPO_NODE_LABEL_DATA_BYTE_COUNT).numberInt(),
			data);
	}	
}
コード例 #7
0
ファイル: MongoClient.cpp プロジェクト: gsimsek/robomongo
    void MongoClient::saveDocument(const mongo::BSONObj &obj, const MongoNamespace &ns)
    {
        mongo::BSONElement id = obj.getField("_id");
        mongo::BSONObjBuilder builder;
        builder.append(id);
        mongo::BSONObj bsonQuery = builder.obj();
        mongo::Query query(bsonQuery);

        _dbclient->update(ns.toString(), query, obj, true, false);
        checkLastErrorAndThrow(ns.databaseName());
    }
コード例 #8
0
ファイル: MongoClient.cpp プロジェクト: 2812140729/robomongo
    void MongoClient::saveDocument(const mongo::BSONObj &obj, const MongoNamespace &ns)
    {

        mongo::BSONElement id = obj.getField("_id");
        mongo::BSONObjBuilder builder;
        builder.append(id);
        mongo::BSONObj bsonQuery = builder.obj();
        mongo::Query query(bsonQuery);

        _dbclient->update(ns.toString(), query, obj, true, false);
        //_dbclient->save(ns.toString().toStdString(), obj);
    }
コード例 #9
0
ファイル: transform_computable.cpp プロジェクト: timn/fawkes
std::list<mongo::BSONObj> TransformComputable::compute_transform(mongo::BSONObj query, std::string collection)
{
  //get positions in other frames
  BSONObjBuilder query_other_frames;
  query_other_frames.appendElements(query.removeField("frame").removeField("allow_tf"));
  query_other_frames.append("frame", fromjson("{$exists:true}"));
  QResCursor cur = robot_memory_->query(query_other_frames.obj(), collection);

  //transform them is possible
  std::list<mongo::BSONObj> res;
  std::string target_frame = query.getField("frame").String();
  while(cur->more())
  {
    BSONObj pos = cur->next();
    if(pos.hasField("frame") && pos.hasField("translation") && pos.hasField("rotation"))
    {
      std::string src_frame = pos.getField("frame").String();
      Time now(0, 0);
      if(tf_->can_transform(target_frame.c_str(), src_frame.c_str(), now))
      {
        BSONObjBuilder res_pos;
        std::vector<BSONElement> src_trans = pos.getField("translation").Array();
        std::vector<BSONElement> src_rot = pos.getField("rotation").Array();
        fawkes::tf::Transform pose_tf(fawkes::tf::Quaternion(src_rot[0].Double(), src_rot[1].Double(), src_rot[2].Double(), src_rot[3].Double()),
          fawkes::tf::Vector3(src_trans[0].Double(), src_trans[1].Double(), src_trans[2].Double()));
        fawkes::tf::Stamped<fawkes::tf::Pose> src_stamped_pose(pose_tf, Time(0, 0), src_frame.c_str());
        fawkes::tf::Stamped<fawkes::tf::Pose> res_stamped_pose;
        tf_->transform_pose(target_frame.c_str(), src_stamped_pose, res_stamped_pose);

        res_pos.appendElements(pos.removeField("frame").removeField("translation").removeField("rotation").removeField("_id"));
        res_pos.append("frame", target_frame);
        res_pos.append("allow_tf", true);
        BSONArrayBuilder arrb_trans;
        arrb_trans.append(res_stamped_pose.getOrigin().x());
        arrb_trans.append(res_stamped_pose.getOrigin().y());
        arrb_trans.append(res_stamped_pose.getOrigin().z());
        res_pos.append("translation", arrb_trans.arr());
        BSONArrayBuilder arrb_rot;
        arrb_rot.append(res_stamped_pose.getRotation().x());
        arrb_rot.append(res_stamped_pose.getRotation().y());
        arrb_rot.append(res_stamped_pose.getRotation().z());
        arrb_rot.append(res_stamped_pose.getRotation().w());
        res_pos.append("rotation", arrb_rot.arr());
        res.push_back(res_pos.obj());
      }
//      else
//      {
//        logger_->log_info(name_, "Cant transform %s to %s", src_frame.c_str(), target_frame.c_str());
//      }
    }
  }
  return res;
}
コード例 #10
0
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);
}
コード例 #11
0
ファイル: MongoUser.cpp プロジェクト: Aahanbhatt/robomongo
 MongoUser::MongoUser(const float version, const mongo::BSONObj &obj) :
     _version(version), _readOnly(false)
 {
     _id = obj.getField("_id").OID();
     _name = BsonUtils::getField<mongo::String>(obj, "user");
     _passwordHash = BsonUtils::getField<mongo::String>(obj, "pwd");
     if (_version<minimumSupportedVersion) {
         _readOnly = BsonUtils::getField<mongo::Bool>(obj, "readOnly");
     }     
     else {
         _userSource = BsonUtils::getField<mongo::String>(obj, "userSource");
         std::vector<mongo::BSONElement> roles = BsonUtils::getField<mongo::Array>(obj, "roles");
         for (std::vector<mongo::BSONElement>::const_iterator it = roles.begin(); it != roles.end(); ++it)
         {
             _role.push_back(BsonUtils::bsonelement_cast<std::string>(*it));
         }
     }
 }
コード例 #12
0
repo::core::RepoNodeCamera::RepoNodeCamera(const mongo::BSONObj &obj) 
	: RepoNodeAbstract(obj)
{
    //--------------------------------------------------------------------------
	// Aspect ratio
	if (obj.hasField(REPO_NODE_LABEL_ASPECT_RATIO))
        aspectRatio = (float)
                obj.getField(REPO_NODE_LABEL_ASPECT_RATIO).numberDouble();
	
    //--------------------------------------------------------------------------
	// Far clipping plane
	if (obj.hasField(REPO_NODE_LABEL_FAR))
        farClippingPlane = (float)
                obj.getField(REPO_NODE_LABEL_FAR).numberDouble();

    //--------------------------------------------------------------------------
	// Near clipping plane
	if (obj.hasField(REPO_NODE_LABEL_NEAR))
        nearClippingPlane = (float)
                obj.getField(REPO_NODE_LABEL_NEAR).numberDouble();

    //--------------------------------------------------------------------------
	// Field of view
	if (obj.hasField(REPO_NODE_LABEL_FOV))
        fieldOfView = (float)
                obj.getField(REPO_NODE_LABEL_FOV).numberDouble();

    //--------------------------------------------------------------------------
	// Look at vector
	if (obj.hasField(REPO_NODE_LABEL_LOOK_AT))
		lookAt = RepoTranscoderBSON::retrieveVector3D(
			obj.getField(REPO_NODE_LABEL_LOOK_AT));

    //--------------------------------------------------------------------------
	// Position vector 
	if (obj.hasField(REPO_NODE_LABEL_POSITION))
		position = RepoTranscoderBSON::retrieveVector3D(
			obj.getField(REPO_NODE_LABEL_POSITION));

    //--------------------------------------------------------------------------
	// Up vector
	if (obj.hasField(REPO_NODE_LABEL_UP))
		up = RepoTranscoderBSON::retrieveVector3D(
			obj.getField(REPO_NODE_LABEL_UP));
}
コード例 #13
0
repo::core::RepoNodeMesh::RepoNodeMesh(
    const mongo::BSONObj &obj) : RepoNodeAbstract(obj),
    vertices(NULL),
    faces(NULL),
    normals(NULL),
    outline(NULL),
    uvChannels(NULL),
    colors(NULL)
{
    //--------------------------------------------------------------------------
    // Vertices
    if (obj.hasField(REPO_NODE_LABEL_VERTICES) &&
            obj.hasField(REPO_NODE_LABEL_VERTICES_COUNT))
    {
        vertices = new std::vector<aiVector3t<float>>();
        RepoTranscoderBSON::retrieve(
            obj.getField(REPO_NODE_LABEL_VERTICES),
            obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt(),
            vertices);
    }

    //--------------------------------------------------------------------------
    // Faces
    if (obj.hasField(REPO_NODE_LABEL_FACES) &&
            obj.hasField(REPO_NODE_LABEL_FACES_COUNT) &&
            obj.hasField(REPO_NODE_LABEL_FACES_BYTE_COUNT))
    {
        faces = new std::vector<aiFace>();
        retrieveFacesArray(
            obj.getField(REPO_NODE_LABEL_FACES),
            api,
            obj.getField(REPO_NODE_LABEL_FACES_BYTE_COUNT).numberInt(),
            obj.getField(REPO_NODE_LABEL_FACES_COUNT).numberInt(),
            faces);
    }

    //--------------------------------------------------------------------------
    // Normals
    if (obj.hasField(REPO_NODE_LABEL_NORMALS) &&
            obj.hasField(REPO_NODE_LABEL_VERTICES_COUNT))
    {
        normals = new std::vector<aiVector3t<float> >();
        RepoTranscoderBSON::retrieve(
            obj.getField(REPO_NODE_LABEL_NORMALS),
            obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt(),
            normals);
    }

    //--------------------------------------------------------------------------
    // Polygon mesh outline (2D bounding rectangle in XY for the moment)
    //
    if (obj.hasField(REPO_NODE_LABEL_OUTLINE))
    {
        //outline = new std::vector<aiVector2D>();
        // TODO: fill in
    }

    //--------------------------------------------------------------------------
    // Bounding box
    if (obj.hasField(REPO_NODE_LABEL_BOUNDING_BOX))
    {
        std::pair<aiVector3D, aiVector3D> min_max = RepoTranscoderBSON::retrieveBBox(
                    obj.getField(REPO_NODE_LABEL_BOUNDING_BOX));

        this->boundingBox.setMin(min_max.first);
        this->boundingBox.setMax(min_max.second);
    }



    //--------------------------------------------------------------------------
    // SHA-256 hash
    if (obj.hasField(REPO_NODE_LABEL_SHA256))
    {
        vertexHash = obj.getField(REPO_NODE_LABEL_SHA256).numberInt();
    }

    //--------------------------------------------------------------------------
    // UV channels
    if (obj.hasField(REPO_NODE_LABEL_UV_CHANNELS) &&
            obj.hasField(REPO_NODE_LABEL_UV_CHANNELS_BYTE_COUNT) &&
            obj.hasField(REPO_NODE_LABEL_UV_CHANNELS_COUNT))
    {
        unsigned int numberOfConcatenatedEntries =
            obj.getField(REPO_NODE_LABEL_UV_CHANNELS_COUNT).numberInt() *
            obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt();

        std::vector<aiVector2t<float>> concatenated;
        RepoTranscoderBSON::retrieve(
            obj.getField(REPO_NODE_LABEL_UV_CHANNELS),
            numberOfConcatenatedEntries,
            &concatenated);

        unsigned int channelsCount =
            obj.getField(REPO_NODE_LABEL_UV_CHANNELS_COUNT).numberInt();

        unsigned int channelSize = (unsigned int) concatenated.size()/channelsCount;
        uvChannels =
            new std::vector<std::vector<aiVector3t<float>> *>(channelsCount);

        // For every uv channel present (usually only one)
        for (unsigned int i = 0; i < channelsCount; ++i)
        {
            uvChannels->at(i) = new std::vector<aiVector3t<float>>();
            uvChannels->at(i)->reserve(channelSize);

            // Copy over all per vertex UV values
            for (unsigned int j = 0; j < channelSize; ++j)
            {
                aiVector2t<float> uv = concatenated[(i * channelSize) + j];
                uvChannels->at(i)->push_back(aiVector3t<float>(uv.x, uv.y, 0));
            }
        }
    }
}