当前位置: 首页>>代码示例>>C++>>正文


C++ Shape类代码示例

本文整理汇总了C++中Shape的典型用法代码示例。如果您正苦于以下问题:C++ Shape类的具体用法?C++ Shape怎么用?C++ Shape使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Shape类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

/* ********************************************************************************************* */
int main(int argc, char* argv[]) {

    // Create Left Leg skeleton
    Skeleton LeftLegSkel;

    // Pointers to be used during the Skeleton building
    Matrix3d inertiaMatrix;
    inertiaMatrix << 0, 0, 0, 0, 0, 0, 0, 0, 0;
    double mass = 1.0;

    // ***** BodyNode 1: Left Hip Yaw (LHY) ***** *
    BodyNode* node = new BodyNode("LHY");
    Joint* joint = create1DOFJoint(NULL, node, 0.0, 0.0, DART_PI, DOF_YAW);
    joint->setName("LHY");
    Shape* shape = new BoxShape(Vector3d(0.3, 0.3, 1.0));
    node->addVisualizationShape(shape);
    node->addCollisionShape(shape);
    node->setMass(mass);
    LeftLegSkel.addBodyNode(node);

    // ***** BodyNode 2: Left Hip Roll (LHR) whose parent is: LHY *****\

    BodyNode* parent_node = LeftLegSkel.getBodyNode("LHY");
    node = new BodyNode("LHR");
    joint = create1DOFJoint(parent_node, node, 0.0, 0.0, DART_PI, DOF_ROLL);
    joint->setName("LHR");
    Eigen::Isometry3d T(Eigen::Translation3d(0.0, 0.0, 0.5));
    joint->setTransformFromParentBodyNode(T);
    shape = new BoxShape(Vector3d(0.3, 0.3, 1.0));
    shape->setOffset(Vector3d(0.0, 0.0, 0.5));
    node->setLocalCOM(shape->getOffset());
    node->setMass(mass);
    node->addVisualizationShape(shape);
    node->addCollisionShape(shape);
    LeftLegSkel.addBodyNode(node);

    // ***** BodyNode 3: Left Hip Pitch (LHP) whose parent is: LHR *****
    parent_node = LeftLegSkel.getBodyNode("LHR");
    node = new BodyNode("LHP");
    joint = create1DOFJoint(parent_node, node, 0.0, 0.0, DART_PI, DOF_ROLL);
    joint->setName("LHP");
    T = Eigen::Translation3d(0.0, 0.0, 1.0);
    joint->setTransformFromParentBodyNode(T);
    shape = new BoxShape(Vector3d(0.3, 0.3, 1.0));
    shape->setOffset(Vector3d(0.0, 0.0, 0.5));
    node->setLocalCOM(shape->getOffset());
    node->setMass(mass);
    Shape* shape1 = new EllipsoidShape(Vector3d(0.3, 0.3, 1.0));
    shape1->setOffset(Vector3d(0.0, 0.0, 0.5));
    node->addVisualizationShape(shape1);
    node->addCollisionShape(shape);
    LeftLegSkel.addBodyNode(node);

    // Initialize the skeleton
    LeftLegSkel.initDynamics();

    // Window stuff
    MyWindow window(&LeftLegSkel);
    glutInit(&argc, argv);
    window.initWindow(640, 480, "Skeleton example");
    glutMainLoop();

    return 0;
}
开发者ID:sonyomega,项目名称:dart,代码行数:65,代码来源:Main.cpp

示例2:

void __fastcall ViewUnitEditor::LoadDxfPattern				(Blocks*	pBlocks, 	NumberSortType	eType)
{
	if (pBlocks == NULL)
	{
		return;
	}

	// declare necessary variables
	Block*		pBlock;
	Shape*		pShape;

	int			nBlockSize			= pBlocks->size();
	int			nBlockShapeCount	= 0;

	RECTFLOAT	shapeRect;

	double		dShapePointX;
	double		dShapePointY;
	double		dRadius;

	SHAPE_TYPE	etype;
	int			idx = 0;

	_pUnitdesigninfo->ResetAll();

	// convert common shapes to ball data
	for (int idxBlock = 0 ; idxBlock < nBlockSize ; idxBlock++)
	{
		pBlock = pBlocks->at(idxBlock);

		if (pBlock == NULL)
		{
			continue;
		}

		if (pBlock->getShapes() == NULL)
		{
			continue;
		}

		nBlockShapeCount = pBlock->getShapes()->size();

		for (int idxShape = 0 ; idxShape < nBlockShapeCount ; idxShape++)
		{
			pShape = pBlock->getShapes()->at(idxShape);

			if (pShape == NULL)
			{
				continue;
			}

			if (pShape->getType() == SHAPE_BLOCK_INSERT)
			{
				((Block_Insert*)pShape)->setBlocks(pBlocks);
			}

			etype = pShape->getType();

			if (!(etype == SHAPE_CIRCLE || etype == SHAPE_LINECIRCLE || etype == SHAPE_FILLCIRCLE))
			{
				continue;
			}

			if (!pShape->getRegion(shapeRect))
			{
				continue;
			}

			dRadius = ((shapeRect.right - shapeRect.left) / 2);

			if (dRadius <= 0)
			{
				continue;
			}

			dShapePointX = shapeRect.left	+ ((shapeRect.right	- shapeRect.left)	/ 2) ;
			dShapePointY = shapeRect.bottom	+ ((shapeRect.top	- shapeRect.bottom)	/ 2) ;

			_pUnitdesigninfo->SetBallCountX(1);
			_pUnitdesigninfo->SetBallCountY(_pUnitdesigninfo->GetBallCountY() + 1);

			_pUnitdesigninfo->SetBallPointManually	(0, idx, dShapePointX, dShapePointY);
			_pUnitdesigninfo->SetBallRadius			(0, idx, dRadius);

			idx++;
		}
	}
	// convert common shapes to ball data

	// sort ball data
    _pUnitdesigninfo->Sort(eType);

	// regen all view datas
	onRegen();
}
开发者ID:japgo,项目名称:mygithub,代码行数:95,代码来源:viewuniteditor.cpp

示例3: atoi

void
js::ObjectImpl::checkShapeConsistency()
{
    static int throttle = -1;
    if (throttle < 0) {
        if (const char *var = getenv("JS_CHECK_SHAPE_THROTTLE"))
            throttle = atoi(var);
        if (throttle < 0)
            throttle = 0;
    }
    if (throttle == 0)
        return;

    MOZ_ASSERT(isNative());

    Shape *shape = lastProperty();
    Shape *prev = NULL;

    if (inDictionaryMode()) {
        MOZ_ASSERT(shape->hasTable());

        ShapeTable &table = shape->table();
        for (uint32_t fslot = table.freelist; fslot != SHAPE_INVALID_SLOT;
             fslot = getSlot(fslot).toPrivateUint32()) {
            MOZ_ASSERT(fslot < slotSpan());
        }

        for (int n = throttle; --n >= 0 && shape->parent; shape = shape->parent) {
            MOZ_ASSERT_IF(shape != lastProperty(), !shape->hasTable());

            Shape **spp = table.search(shape->propid(), false);
            MOZ_ASSERT(SHAPE_FETCH(spp) == shape);
        }

        shape = lastProperty();
        for (int n = throttle; --n >= 0 && shape; shape = shape->parent) {
            MOZ_ASSERT_IF(shape->slot() != SHAPE_INVALID_SLOT, shape->slot() < slotSpan());
            if (!prev) {
                MOZ_ASSERT(shape == lastProperty());
                MOZ_ASSERT(shape->listp == &shape_);
            } else {
                MOZ_ASSERT(shape->listp == &prev->parent);
            }
            prev = shape;
        }
    } else {
        for (int n = throttle; --n >= 0 && shape->parent; shape = shape->parent) {
            if (shape->hasTable()) {
                ShapeTable &table = shape->table();
                MOZ_ASSERT(shape->parent);
                for (Shape::Range r(shape); !r.empty(); r.popFront()) {
                    Shape **spp = table.search(r.front().propid(), false);
                    MOZ_ASSERT(SHAPE_FETCH(spp) == &r.front());
                }
            }
            if (prev) {
                MOZ_ASSERT(prev->maybeSlot() >= shape->maybeSlot());
                shape->kids.checkConsistency(prev);
            }
            prev = shape;
        }
    }
}
开发者ID:,项目名称:,代码行数:63,代码来源:

示例4: parent

Shape *
PropertyTree::getChild(ExclusiveContext *cx, Shape *parentArg, StackShape &unrootedChild)
{
    RootedShape parent(cx, parentArg);
    MOZ_ASSERT(parent);

    Shape *existingShape = nullptr;

    /*
     * The property tree has extremely low fan-out below its root in
     * popular embeddings with real-world workloads. Patterns such as
     * defining closures that capture a constructor's environment as
     * getters or setters on the new object that is passed in as
     * |this| can significantly increase fan-out below the property
     * tree root -- see bug 335700 for details.
     */
    KidsPointer *kidp = &parent->kids;
    if (kidp->isShape()) {
        Shape *kid = kidp->toShape();
        if (kid->matches(unrootedChild))
            existingShape = kid;
    } else if (kidp->isHash()) {
        if (KidsHash::Ptr p = kidp->toHash()->lookup(unrootedChild))
            existingShape = *p;
    } else {
        /* If kidp->isNull(), we always insert. */
    }

#ifdef JSGC_INCREMENTAL
    if (existingShape) {
        JS::Zone *zone = existingShape->zone();
        if (zone->needsIncrementalBarrier()) {
            /*
             * We need a read barrier for the shape tree, since these are weak
             * pointers.
             */
            Shape *tmp = existingShape;
            MarkShapeUnbarriered(zone->barrierTracer(), &tmp, "read barrier");
            MOZ_ASSERT(tmp == existingShape);
        } else if (zone->isGCSweeping() && !existingShape->isMarked() &&
                   !existingShape->arenaHeader()->allocatedDuringIncremental)
        {
            /*
             * The shape we've found is unreachable and due to be finalized, so
             * remove our weak reference to it and don't use it.
             */
            MOZ_ASSERT(parent->isMarked());
            parent->removeChild(existingShape);
            existingShape = nullptr;
        } else if (existingShape->isMarked(gc::GRAY)) {
            JS::UnmarkGrayGCThingRecursively(existingShape, JSTRACE_SHAPE);
        }
    }
#endif

    if (existingShape)
        return existingShape;

    Shape *shape = Shape::new_(cx, unrootedChild, parent->numFixedSlots());
    if (!shape)
        return nullptr;

    if (!insertChild(cx, parent, shape))
        return nullptr;

    return shape;
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:67,代码来源:jspropertytree.cpp

示例5: appendSpan

void Region::Shape::appendSpans(const Shape& shape, SpanIterator begin, SpanIterator end)
{
    for (SpanIterator it = begin; it != end; ++it)
        appendSpan(it->y, shape.segmentsBegin(it), shape.segmentsEnd(it));
}
开发者ID:335969568,项目名称:Blink-1,代码行数:5,代码来源:Region.cpp

示例6: RenderObjectAt

void RenderManager::RenderObjectAt(Shape& shape, const a2de::Vector2D& screen_position, bool filled) {
    a2de::Vector2D old_pos(shape.GetPosition());
    shape.SetPosition(screen_position);
    RenderObject(shape, filled);
    shape.SetPosition(old_pos);
}
开发者ID:cugone,项目名称:Abrams2015,代码行数:6,代码来源:CRenderManager.cpp

示例7: loadShader

void MyGlWindow::init(){
	loadShader( program, "shader.vert", "shader.frag" );
	if(!program){
		cerr<<"Error setting up shaders!"<<endl;
		exit(1);
	}

	glGenVertexArrays(1, &vao);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glClearColor(0.0, 0.0, 0.33, 1.0);
	glCullFace(GL_BACK);

	float aspectRatio = (float)w()/(float)h();
	cam = new camera(l, r, t, b, n, f, aspectRatio);

	shared_ptr<ObjParser> parser = make_shared<ObjParser>();
	Shape s = parser->parse("Neutral.obj");
	s.setVao(vao);
	if(SMOOTH)
		s.smoothNormals();
	s.initBuffers(program, "vNeutral", "nNeutral");
	s.setRotate(0, 1, 0, 0);
	shapes.push_back(s);

	Shape s2 = parser->parse("28_MouthSmile_L.obj");
	s2.setVao(vao);
	if(SMOOTH)
		s2.smoothNormals();
	s2.initBuffers(program, "vSmile_L", "nSmile_L");
	s2.setRotate(0, 1, 0, 0);
	shapes.push_back(s2);

	Shape s3 = parser->parse("29_MouthSmile_R.obj");
	s3.setVao(vao);
	if(SMOOTH)
		s3.smoothNormals();
	s3.initBuffers(program, "vSmile_R", "nSmile_R");
	s3.setRotate(0, 1, 0, 0);
	shapes.push_back(s3);

	Shape s4 = parser->parse("16_BrowsU_C.obj");
	s4.setVao(vao);
	if(SMOOTH)
		s4.smoothNormals();
	s4.initBuffers(program, "vBrowsup", "nBrowsup");
	s4.setRotate(0, 1, 0, 0);
	shapes.push_back(s4);

	Shape s5 = parser->parse("21_JawOpen.obj");
	s5.setVao(vao);
	if(SMOOTH)
		s5.smoothNormals();
	s5.initBuffers(program, "vMouthopen", "nMouthopen");
	s5.setRotate(0, 1, 0, 0);
	shapes.push_back(s5);

	Shape s6 = parser->parse("45_Puff.obj");
	s6.setVao(vao);
	if(SMOOTH)
		s6.smoothNormals();
	s6.initBuffers(program, "vPuff", "nPuff");
	s6.setRotate(0, 1, 0, 0);
	shapes.push_back(s6);

	Shape s7 = parser->parse("44_Sneer.obj");
	s7.setVao(vao);
	if(SMOOTH)
		s7.smoothNormals();
	s7.initBuffers(program, "vSneer", "nSneer");
	s7.setRotate(0, 1, 0, 0);
	shapes.push_back(s7);

	Shape s8 = parser->parse("41_LipsPucker.obj");
	s8.setVao(vao);
	if(SMOOTH)
		s8.smoothNormals();
	s8.initBuffers(program, "vKiss", "nKiss");
	s8.setRotate(0, 1, 0, 0);
	shapes.push_back(s8);

}
开发者ID:chagge,项目名称:Cry_Project,代码行数:82,代码来源:MyGlWindow.cpp

示例8: JS_ASSERT

Shape *
PropertyTree::getChild(ExclusiveContext *cx, Shape *parent_, uint32_t nfixed, const StackShape &child)
{
    {
        Shape *shape = NULL;

        JS_ASSERT(parent_);

        /*
         * The property tree has extremely low fan-out below its root in
         * popular embeddings with real-world workloads. Patterns such as
         * defining closures that capture a constructor's environment as
         * getters or setters on the new object that is passed in as
         * |this| can significantly increase fan-out below the property
         * tree root -- see bug 335700 for details.
         */
        KidsPointer *kidp = &parent_->kids;
        if (kidp->isShape()) {
            Shape *kid = kidp->toShape();
            if (kid->matches(child))
                shape = kid;
        } else if (kidp->isHash()) {
            if (KidsHash::Ptr p = kidp->toHash()->lookup(child))
                shape = *p;
        } else {
            /* If kidp->isNull(), we always insert. */
        }

#ifdef JSGC_INCREMENTAL
        if (shape) {
            JS::Zone *zone = shape->zone();
            if (zone->needsBarrier()) {
                /*
                 * We need a read barrier for the shape tree, since these are weak
                 * pointers.
                 */
                Shape *tmp = shape;
                MarkShapeUnbarriered(zone->barrierTracer(), &tmp, "read barrier");
                JS_ASSERT(tmp == shape);
            } else if (zone->isGCSweeping() && !shape->isMarked() &&
                       !shape->arenaHeader()->allocatedDuringIncremental)
            {
                /*
                 * The shape we've found is unreachable and due to be finalized, so
                 * remove our weak reference to it and don't use it.
                 */
                JS_ASSERT(parent_->isMarked());
                parent_->removeChild(shape);
                shape = NULL;
            }
        }
#endif

        if (shape)
            return shape;
    }

    StackShape::AutoRooter childRoot(cx, &child);
    RootedShape parent(cx, parent_);

    Shape *shape = newShape(cx);
    if (!shape)
        return NULL;

    new (shape) Shape(child, nfixed);

    if (!insertChild(cx, parent, shape))
        return NULL;

    return shape;
}
开发者ID:birtles,项目名称:mozilla-central,代码行数:71,代码来源:jspropertytree.cpp

示例9: w_Shape_rayCast

	int w_Shape_rayCast(lua_State * L)
	{
		Shape * t = luax_checkshape(L, 1);
		lua_remove(L, 1);
		ASSERT_GUARD(return t->rayCast(L);)
	}
开发者ID:PaulForey,项目名称:lovepd,代码行数:6,代码来源:wrap_Shape.cpp

示例10: max_pool

            void max_pool(const T* arg,
                          T* out,
                          const Shape& arg_shape,
                          const Shape& out_shape,
                          const Shape& window_shape,
                          const Strides& window_movement_strides,
                          const Shape& padding_below,
                          const Shape& padding_above)
            {
                // At the outermost level we will walk over every output coordinate O.
                CoordinateTransform output_transform(out_shape);

                for (const Coordinate& out_coord : output_transform)
                {
                    // Our output coordinate O will have the form:
                    //
                    //   (N,chan,i_1,...,i_n)

                    size_t batch_index = out_coord[0];
                    size_t channel = out_coord[1];

                    // For the input data we need to iterate the coordinate:
                    //
                    //   I:
                    //
                    // over the range (noninclusive on the right):
                    //
                    //   (N,chan,s_1*i_1,s_2*i_2,...,s_n*i_n) ->
                    //
                    //     (N+1,chan+1,s_1*i_1 + window_shape_1,...,s_n*i_n + window_shape_n)
                    //
                    // with unit stride.
                    //
                    // We iterate this over the *padded* data, so below we will need to check for coordinates that fall in the padding area.

                    size_t n_spatial_dimensions = arg_shape.size() - 2;

                    Coordinate input_batch_transform_start(2 + n_spatial_dimensions);
                    Coordinate input_batch_transform_end(2 + n_spatial_dimensions);
                    Strides input_batch_transform_source_strides(2 + n_spatial_dimensions, 1);
                    AxisVector input_batch_transform_source_axis_order(2 + n_spatial_dimensions);
                    CoordinateDiff input_batch_transform_padding_below(2 + n_spatial_dimensions);
                    CoordinateDiff input_batch_transform_padding_above(2 + n_spatial_dimensions);

                    input_batch_transform_start[0] = batch_index;
                    input_batch_transform_end[0] = batch_index + 1;
                    input_batch_transform_start[1] = channel;
                    input_batch_transform_end[1] = channel + 1;
                    input_batch_transform_padding_below[0] = 0;
                    input_batch_transform_padding_below[1] = 0;
                    input_batch_transform_padding_above[0] = 0;
                    input_batch_transform_padding_above[1] = 0;

                    for (size_t i = 2; i < n_spatial_dimensions + 2; i++)
                    {
                        size_t window_shape_this_dim = window_shape[i - 2];
                        size_t movement_stride = window_movement_strides[i - 2];

                        input_batch_transform_start[i] = movement_stride * out_coord[i];
                        input_batch_transform_end[i] =
                            input_batch_transform_start[i] + window_shape_this_dim;
                        input_batch_transform_padding_below[i] = padding_below[i - 2];
                        input_batch_transform_padding_above[i] = padding_above[i - 2];
                    }

                    for (size_t i = 0; i < arg_shape.size(); i++)
                    {
                        input_batch_transform_source_axis_order[i] = i;
                    }

                    CoordinateTransform input_batch_transform(
                        arg_shape,
                        input_batch_transform_start,
                        input_batch_transform_end,
                        input_batch_transform_source_strides,
                        input_batch_transform_source_axis_order,
                        input_batch_transform_padding_below,
                        input_batch_transform_padding_above);

                    // As we go, we compute the maximum value:
                    //
                    //   output[O] = max(output[O],arg[I])

                    T result = std::numeric_limits<T>::lowest();

                    for (const Coordinate& input_batch_coord : input_batch_transform)
                    {
                        if (input_batch_transform.has_source_coordinate(input_batch_coord))
                        {
                            T x = arg[input_batch_transform.index(input_batch_coord)];
                            result = x > result ? x : result;
                        }
                    }

                    out[output_transform.index(out_coord)] = result;
                }
            }
开发者ID:okhat,项目名称:ngraph,代码行数:97,代码来源:max_pool.hpp

示例11: max_pool_backprop

            void max_pool_backprop(const T* arg_forward,
                                   const T* delta,
                                   T* out,
                                   const Shape& delta_shape,
                                   const Shape& out_shape, // same as arg_forward_shape
                                   const Shape& window_shape,
                                   const Strides& window_movement_strides,
                                   const Shape& padding_below,
                                   const Shape& padding_above)
            {
                CoordinateTransform out_transform(out_shape);

                for (const Coordinate& out_coord : out_transform)
                {
                    out[out_transform.index(out_coord)] = 0;
                }

                CoordinateTransform delta_transform(delta_shape);

                for (const Coordinate& delta_coord : delta_transform)
                {
                    size_t img_index = delta_coord[0];
                    size_t channel = delta_coord[1];

                    size_t n_image_dimensions = out_shape.size() - 2;
                    Coordinate source_window_transform_start(2 + n_image_dimensions);
                    Coordinate source_window_transform_end(2 + n_image_dimensions);
                    Strides source_window_transform_source_strides(2 + n_image_dimensions, 1);
                    AxisVector source_window_transform_source_axis_order(2 + n_image_dimensions);
                    CoordinateDiff source_window_transform_padding_below(2 + n_image_dimensions);
                    CoordinateDiff source_window_transform_padding_above(2 + n_image_dimensions);

                    source_window_transform_start[0] = img_index;
                    source_window_transform_end[0] = img_index + 1;
                    source_window_transform_start[1] = channel;
                    source_window_transform_end[1] = channel + 1;
                    source_window_transform_padding_below[0] = 0;
                    source_window_transform_padding_below[1] = 0;
                    source_window_transform_padding_above[0] = 0;
                    source_window_transform_padding_above[1] = 0;

                    for (size_t i = 2; i < n_image_dimensions + 2; i++)
                    {
                        size_t window_shape_this_dim = window_shape[i - 2];
                        size_t movement_stride = window_movement_strides[i - 2];

                        source_window_transform_start[i] = movement_stride * delta_coord[i];
                        source_window_transform_end[i] =
                            source_window_transform_start[i] + window_shape_this_dim;
                        source_window_transform_padding_below[i] = padding_below[i - 2];
                        source_window_transform_padding_above[i] = padding_above[i - 2];
                    }
                    std::iota(begin(source_window_transform_source_axis_order),
                              end(source_window_transform_source_axis_order),
                              0);

                    CoordinateTransform source_window_transform(
                        out_shape,
                        source_window_transform_start,
                        source_window_transform_end,
                        source_window_transform_source_strides,
                        source_window_transform_source_axis_order,
                        source_window_transform_padding_below,
                        source_window_transform_padding_above);

                    Coordinate argmax_coord;
                    bool argmax_coord_valid = false;
                    T max_val = 0; // just initializing to keep compiler happy, this 0 is ignored

                    for (const Coordinate& source_window_coord : source_window_transform)
                    {
                        if (source_window_transform.has_source_coordinate(source_window_coord))
                        {
                            T candidate =
                                arg_forward[source_window_transform.index(source_window_coord)];

                            if (!argmax_coord_valid || candidate > max_val)
                            {
                                max_val = candidate;
                                argmax_coord = source_window_coord;
                                argmax_coord_valid = true;
                            }
                        }
                    }

                    if (argmax_coord_valid)
                    {
                        out[source_window_transform.index(argmax_coord)] +=
                            delta[delta_transform.index(delta_coord)];
                    }
                }
            }
开发者ID:okhat,项目名称:ngraph,代码行数:92,代码来源:max_pool.hpp

示例12: loadFromShape

bool Mesh::loadFromShape(Shape& shape) {
    shape.loadIntoMesh(*this);
    return true;
}
开发者ID:jhuang2github,项目名称:JHRenderEngine,代码行数:4,代码来源:Mesh.cpp

示例13: main

int main (){

	Shape *cir = Shape::Create("circle");
	if ( cir != NULL ) cir->draw();
	return 0;
}
开发者ID:selvagit,项目名称:experiments,代码行数:6,代码来源:factory_method.cpp

示例14: StatsCellCallback

static void
StatsCellCallback(JSRuntime *rt, void *data, void *thing, JSGCTraceKind traceKind,
                  size_t thingSize)
{
    RuntimeStats *rtStats = static_cast<RuntimeStats *>(data);
    CompartmentStats *cStats = rtStats->currCompartmentStats;
    switch (traceKind) {
    case JSTRACE_OBJECT:
    {
        JSObject *obj = static_cast<JSObject *>(thing);
        if (obj->isFunction()) {
            cStats->gcHeapObjectsFunction += thingSize;
        } else {
            cStats->gcHeapObjectsNonFunction += thingSize;
        }
        size_t slotsSize, elementsSize, miscSize;
        obj->sizeOfExcludingThis(rtStats->mallocSizeOf, &slotsSize,
                                 &elementsSize, &miscSize);
        cStats->objectSlots += slotsSize;
        cStats->objectElements += elementsSize;
        cStats->objectMisc += miscSize;
        break;
    }
    case JSTRACE_STRING:
    {
        JSString *str = static_cast<JSString *>(thing);
        cStats->gcHeapStrings += thingSize;
        cStats->stringChars += str->sizeOfExcludingThis(rtStats->mallocSizeOf);
        break;
    }
    case JSTRACE_SHAPE:
    {
        Shape *shape = static_cast<Shape*>(thing);
        size_t propTableSize, kidsSize;
        shape->sizeOfExcludingThis(rtStats->mallocSizeOf, &propTableSize, &kidsSize);
        if (shape->inDictionary()) {
            cStats->gcHeapShapesDict += thingSize;
            cStats->shapesExtraDictTables += propTableSize;
            JS_ASSERT(kidsSize == 0);
        } else {
            cStats->gcHeapShapesTree += thingSize;
            cStats->shapesExtraTreeTables += propTableSize;
            cStats->shapesExtraTreeShapeKids += kidsSize;
        }
        break;
    }
    case JSTRACE_BASE_SHAPE:
    {
        cStats->gcHeapShapesBase += thingSize;
        break;
    }
    case JSTRACE_SCRIPT:
    {
        JSScript *script = static_cast<JSScript *>(thing);
        cStats->gcHeapScripts += thingSize;
        cStats->scriptData += script->sizeOfData(rtStats->mallocSizeOf);
#ifdef JS_METHODJIT
        cStats->mjitData += script->sizeOfJitScripts(rtStats->mallocSizeOf);
#endif
        break;
    }
    case JSTRACE_TYPE_OBJECT:
    {
        types::TypeObject *obj = static_cast<types::TypeObject *>(thing);
        cStats->gcHeapTypeObjects += thingSize;
        obj->sizeOfExcludingThis(&cStats->typeInferenceSizes, rtStats->mallocSizeOf);
        break;
    }
#if JS_HAS_XML_SUPPORT
    case JSTRACE_XML:
    {
        cStats->gcHeapXML += thingSize;
        break;
    }
#endif
    }
    // Yes, this is a subtraction:  see StatsArenaCallback() for details.
    cStats->gcHeapArenaUnused -= thingSize;
}
开发者ID:,项目名称:,代码行数:79,代码来源:

示例15: MOZ_ASSERT

bool
js::ForOfPIC::Chain::initialize(JSContext* cx)
{
    MOZ_ASSERT(!initialized_);

    // Get the canonical Array.prototype
    RootedNativeObject arrayProto(cx, GlobalObject::getOrCreateArrayPrototype(cx, cx->global()));
    if (!arrayProto)
        return false;

    // Get the canonical ArrayIterator.prototype
    RootedNativeObject arrayIteratorProto(cx,
        GlobalObject::getOrCreateArrayIteratorPrototype(cx, cx->global()));
    if (!arrayIteratorProto)
        return false;

    // From this point on, we can't fail.  Set initialized and fill the fields
    // for the canonical Array.prototype and ArrayIterator.prototype objects.
    initialized_ = true;
    arrayProto_ = arrayProto;
    arrayIteratorProto_ = arrayIteratorProto;

    // Shortcut returns below means Array for-of will never be optimizable,
    // do set disabled_ now, and clear it later when we succeed.
    disabled_ = true;

    // Look up Array.prototype[@@iterator], ensure it's a slotful shape.
    Shape* iterShape = arrayProto->lookup(cx, SYMBOL_TO_JSID(cx->wellKnownSymbols().iterator));
    if (!iterShape || !iterShape->hasSlot() || !iterShape->hasDefaultGetter())
        return true;

    // Get the referred value, and ensure it holds the canonical ArrayValues function.
    Value iterator = arrayProto->getSlot(iterShape->slot());
    JSFunction* iterFun;
    if (!IsFunctionObject(iterator, &iterFun))
        return true;
    if (!IsSelfHostedFunctionWithName(iterFun, cx->names().ArrayValues))
        return true;

    // Look up the 'next' value on ArrayIterator.prototype
    Shape* nextShape = arrayIteratorProto->lookup(cx, cx->names().next);
    if (!nextShape || !nextShape->hasSlot())
        return true;

    // Get the referred value, ensure it holds the canonical ArrayIteratorNext function.
    Value next = arrayIteratorProto->getSlot(nextShape->slot());
    JSFunction* nextFun;
    if (!IsFunctionObject(next, &nextFun))
        return true;
    if (!IsSelfHostedFunctionWithName(nextFun, cx->names().ArrayIteratorNext))
        return true;

    disabled_ = false;
    arrayProtoShape_ = arrayProto->lastProperty();
    arrayProtoIteratorSlot_ = iterShape->slot();
    canonicalIteratorFunc_ = iterator;
    arrayIteratorProtoShape_ = arrayIteratorProto->lastProperty();
    arrayIteratorProtoNextSlot_ = nextShape->slot();
    canonicalNextFunc_ = next;
    return true;
}
开发者ID:MekliCZ,项目名称:positron,代码行数:61,代码来源:PIC.cpp


注:本文中的Shape类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。