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


C++ vector::swap方法代码示例

本文整理汇总了C++中std::vector::swap方法的典型用法代码示例。如果您正苦于以下问题:C++ vector::swap方法的具体用法?C++ vector::swap怎么用?C++ vector::swap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::vector的用法示例。


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

示例1: aggr

        pointwise_aggregates(const Matrix &A, const params &prm, unsigned min_aggregate)
            : count(0)
        {
            if (prm.block_size == 1) {
                plain_aggregates aggr(A, prm);

                remove_small_aggregates(A.nrows, 1, min_aggregate, aggr);

                count = aggr.count;
                strong_connection.swap(aggr.strong_connection);
                id.swap(aggr.id);
            } else {
                strong_connection.resize( nonzeros(A) );
                id.resize( rows(A) );

                Matrix Ap = pointwise_matrix(A, prm.block_size);

                plain_aggregates pw_aggr(Ap, prm);

                remove_small_aggregates(
                        Ap.nrows, prm.block_size, min_aggregate, pw_aggr);

                count = pw_aggr.count * prm.block_size;

#pragma omp parallel
                {
                    std::vector<ptrdiff_t> marker(Ap.nrows, -1);

#ifdef _OPENMP
                    int nt  = omp_get_num_threads();
                    int tid = omp_get_thread_num();

                    size_t chunk_size  = (Ap.nrows + nt - 1) / nt;
                    size_t chunk_start = tid * chunk_size;
                    size_t chunk_end   = std::min(Ap.nrows, chunk_start + chunk_size);
#else
                    size_t chunk_start = 0;
                    size_t chunk_end   = Ap.nrows;
#endif

                    for(size_t ip = chunk_start, ia = ip * prm.block_size; ip < chunk_end; ++ip) {
                        ptrdiff_t row_beg = Ap.ptr[ip];
                        ptrdiff_t row_end = row_beg;

                        for(unsigned k = 0; k < prm.block_size; ++k, ++ia) {
                            id[ia] = prm.block_size * pw_aggr.id[ip] + k;

                            for(ptrdiff_t ja = A.ptr[ia], ea = A.ptr[ia+1]; ja < ea; ++ja) {
                                ptrdiff_t cp = A.col[ja] / prm.block_size;

                                if (marker[cp] < row_beg) {
                                    marker[cp] = row_end;
                                    strong_connection[ja] = pw_aggr.strong_connection[row_end];
                                    ++row_end;
                                } else {
                                    strong_connection[ja] = pw_aggr.strong_connection[ marker[cp] ];
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:huahbo,项目名称:amgcl,代码行数:63,代码来源:pointwise_aggregates.hpp

示例2: ResolveVertexDataArray

void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source, 
	const std::string& MappingInformationType,
	const std::string& ReferenceInformationType,
	const char* dataElementName,
	const char* indexDataElementName,
	size_t vertex_count,
	const std::vector<unsigned int>& mapping_counts,
	const std::vector<unsigned int>& mapping_offsets,
	const std::vector<unsigned int>& mappings)
{
	std::vector<T> tempUV;
	ParseVectorDataArray(tempUV,GetRequiredElement(source,dataElementName));

	// handle permutations of Mapping and Reference type - it would be nice to
	// deal with this more elegantly and with less redundancy, but right
	// now it seems unavoidable.
	if (MappingInformationType == "ByVertice" && ReferenceInformationType == "Direct") {	
		data_out.resize(vertex_count);
		for (size_t i = 0, e = tempUV.size(); i < e; ++i) {

			const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i];
			for (unsigned int j = istart; j < iend; ++j) {
				data_out[mappings[j]] = tempUV[i];
			}
		}
	}
	else if (MappingInformationType == "ByVertice" && ReferenceInformationType == "IndexToDirect") {	
		data_out.resize(vertex_count);

		std::vector<int> uvIndices;
		ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));

		for (size_t i = 0, e = uvIndices.size(); i < e; ++i) {

			const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i];
			for (unsigned int j = istart; j < iend; ++j) {
				if(static_cast<size_t>(uvIndices[i]) >= tempUV.size()) {
					DOMError("index out of range",&GetRequiredElement(source,indexDataElementName));
				}
				data_out[mappings[j]] = tempUV[uvIndices[i]];
			}
		}
	}
	else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "Direct") {	
		if (tempUV.size() != vertex_count) {
			FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygon mapping: ") 
				<< tempUV.size() << ", expected " << vertex_count
			);
			return;
		}

		data_out.swap(tempUV);
	}
	else if (MappingInformationType == "ByPolygonVertex" && ReferenceInformationType == "IndexToDirect") {	
		data_out.resize(vertex_count);

		std::vector<int> uvIndices;
		ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));

		if (uvIndices.size() != vertex_count) {
			FBXImporter::LogError("length of input data unexpected for ByPolygonVertex mapping");
			return;
		}

		unsigned int next = 0;
		BOOST_FOREACH(int i, uvIndices) {
			if(static_cast<size_t>(i) >= tempUV.size()) {
				DOMError("index out of range",&GetRequiredElement(source,indexDataElementName));
			}

			data_out[next++] = tempUV[i];
		}
	}
开发者ID:AldoMarzullo,项目名称:OpenGL_core_project,代码行数:73,代码来源:FBXMeshGeometry.cpp

示例3: InterpolatePointsRNS

void SimRender::InterpolatePointsRNS(std::vector<CVector2D>& points, bool closed, float offset, int segmentSamples /* = 4 */)
{
	PROFILE("InterpolatePointsRNS");
	ENSURE(segmentSamples > 0);

	std::vector<CVector2D> newPoints;

	// (This does some redundant computations for adjacent vertices,
	// but it's fairly fast (<1ms typically) so we don't worry about it yet)

	// TODO: Instead of doing a fixed number of line segments between each
	// control point, it should probably be somewhat adaptive to get a nicer
	// curve with fewer points

	size_t n = points.size();

	if (closed)
	{
		if (n < 1)
			return; // we need at least a single point to not crash
	}
	else
	{
		if (n < 2)
			return; // in non-closed mode, we need at least n=2 to not crash
	}

	size_t imax = closed ? n : n-1;
	newPoints.reserve(imax*segmentSamples);

	// these are primarily used inside the loop, but for open paths we need them outside the loop once to compute the last point
	CVector2D a0;
	CVector2D a1;
	CVector2D a2;
	CVector2D a3;

	for (size_t i = 0; i < imax; ++i)
	{
		// Get the relevant points for this spline segment; each step interpolates the segment between p1 and p2; p0 and p3 are the points
		// before p1 and after p2, respectively; they're needed to compute tangents and whatnot.
		CVector2D p0; // normally points[(i-1+n)%n], but it's a bit more complicated due to open/closed paths -- see below
		CVector2D p1 = points[i];
		CVector2D p2 = points[(i+1)%n];
		CVector2D p3; // normally points[(i+2)%n], but it's a bit more complicated due to open/closed paths -- see below

		if (!closed && (i == 0))
			// p0's point index is out of bounds, and we can't wrap around because we're in non-closed mode -- create an artificial point
			// that extends p1 -> p0 (i.e. the first segment's direction)
			p0 = points[0] + (points[0] - points[1]);
		else
			// standard wrap-around case
			p0 = points[(i-1+n)%n]; // careful; don't use (i-1)%n here, as the result is machine-dependent for negative operands (e.g. if i==0, the result could be either -1 or n-1)


		if (!closed && (i == n-2))
			// p3's point index is out of bounds; create an artificial point that extends p_(n-2) -> p_(n-1) (i.e. the last segment's direction)
			// (note that p2's index should not be out of bounds, because in non-closed mode imax is reduced by 1)
			p3 = points[n-1] + (points[n-1] - points[n-2]);
		else
			// standard wrap-around case
			p3 = points[(i+2)%n];


		// Do the RNS computation (based on GPG4 "Nonuniform Splines")
		float l1 = (p2 - p1).Length(); // length of spline segment (i)..(i+1)
		CVector2D s0 = (p1 - p0).Normalized(); // unit vector of spline segment (i-1)..(i)
		CVector2D s1 = (p2 - p1).Normalized(); // unit vector of spline segment (i)..(i+1)
		CVector2D s2 = (p3 - p2).Normalized(); // unit vector of spline segment (i+1)..(i+2)
		CVector2D v1 = (s0 + s1).Normalized() * l1; // spline velocity at i
		CVector2D v2 = (s1 + s2).Normalized() * l1; // spline velocity at i+1

		// Compute standard cubic spline parameters
		a0 = p1*2 + p2*-2 + v1 + v2;
		a1 = p1*-3 + p2*3 + v1*-2 + v2*-1;
		a2 = v1;
		a3 = p1;

		// Interpolate at regular points across the interval
		for (int sample = 0; sample < segmentSamples; sample++)
			newPoints.push_back(EvaluateSpline(sample/((float) segmentSamples), a0, a1, a2, a3, offset));

	}

	if (!closed)
		// if the path is open, we should take care to include the last control point
		// NOTE: we can't just do push_back(points[n-1]) here because that ignores the offset
		newPoints.push_back(EvaluateSpline(1.f, a0, a1, a2, a3, offset));

	points.swap(newPoints);
}
开发者ID:2asoft,项目名称:0ad,代码行数:90,代码来源:Render.cpp

示例4: CheckContext

// ////////////////////////////////////////////////////////////////////////////
bool InsContext::CheckContext(std::vector<std::string> &error_list) const
{
	typedef std::map<unsigned int, unsigned int>  DVMap;
	typedef DVMap::iterator                       DVMapIter;
	typedef DVMap::const_iterator                 DVMapIterC;
	typedef std::pair<unsigned int, unsigned int> DVMapPair;

	unsigned int ins_item_count   =
		static_cast<unsigned int>(ins_item_list_.size());
	unsigned int dict_value_count =
		static_cast<unsigned int>(dict_value_list_.size());

	unsigned int             count_1;
	DVMap                    dv_map;
	std::vector<std::string> tmp_error_list;

	for (count_1 = 0; count_1 < ins_item_count; ++count_1) {
		const InsItem     &this_item(ins_item_list_[count_1]);
		std::stringstream  item_text;
		item_text << "Error in instruction item index " << count_1 << ", fid " <<
			this_item.auxiliary_id_ << " ('" <<
			this_item.field_name_ << "') with parent index " <<
			this_item.parent_index_ << ": ";
		try {
			if (this_item.parent_index_ >= ins_item_count) {
				std::ostringstream o_str;
				o_str << "The parent index (" << this_item.parent_index_ <<
					") is not less than the number of instruction items (" <<
					ins_item_count << ").";
				tmp_error_list.push_back(item_text.str() + o_str.str());
			}
			if ((count_1 + this_item.element_count_) > ins_item_count) {
				std::ostringstream o_str;
				o_str << "The item index plus the element count (" << count_1 <<
					" + " << this_item.element_count_ << " = " <<
					(count_1 + this_item.element_count_) << ") is greater "
					"than number of instruction items (" << ins_item_count << ").";
				tmp_error_list.push_back(item_text.str() + o_str.str());
			}
			if (this_item.field_operator_ == FieldOperator_None) {
				if ((this_item.dict_value_index_) &&
					(this_item.data_type_ != DataType_Template)) {
					std::ostringstream o_str;
					o_str << "The field has an operator of 'None', but the "
						"dictionary value index is " <<
						this_item.dict_value_index_ << " (should be 0).";
					tmp_error_list.push_back(item_text.str() + o_str.str());
				}
				if ((this_item.dict_value_count_) &&
					(this_item.data_type_ != DataType_Template)) {
					std::ostringstream o_str;
					o_str << "The field has an operator of 'None', but the "
						"dictionary value count is " <<
						this_item.dict_value_count_ << " (should be 0).";
					tmp_error_list.push_back(item_text.str() + o_str.str());
				}
			}
			else {
				if (!this_item.dict_value_count_) {
					std::ostringstream o_str;
					o_str << "The field has an operator of '" <<
						this_item.field_operator_ << "', but the dictionary value "
						"count is 0.";
					tmp_error_list.push_back(item_text.str() + o_str.str());
				}
				else if ((this_item.dict_value_index_ +
					this_item.dict_value_count_) > dict_value_count) {
					std::ostringstream o_str;
					o_str << "The dictionary value index plus the dictionary value "
						"count (" << this_item.dict_value_index_ << " + " <<
						this_item.dict_value_count_ << " = " <<
						(this_item.dict_value_index_ + this_item.dict_value_count_) <<
						") is greater than number of dictionary values (" <<
						dict_value_count << ").";
					tmp_error_list.push_back(item_text.str() + o_str.str());
				}
			}
		}
		catch (const std::exception &except) {
			tmp_error_list.push_back(item_text.str() + except.what());
		}
	}

	error_list.swap(tmp_error_list);

	return(error_list.empty());
}
开发者ID:neilgroves,项目名称:MlbDev,代码行数:88,代码来源:InsContext.cpp

示例5: smooth_curve

bool smooth_curve(const BVH *bvh, const VectorXu &E2E, std::vector<CurvePoint> &curve, bool watertight) {
    const MatrixXu &F = *bvh->F();
    const MatrixXf &V = *bvh->V(), &N = *bvh->N();
    cout << endl;

    std::vector<CurvePoint> curve_new;
    std::vector<Float> weight;
    std::vector<uint32_t> path;

    cout << "Input: " << curve.size() << " vertices" << endl;

    for (int it=0;; ++it) {
        if (curve.size() < 2)
            return false;

        for (uint32_t it2=0; it2<curve.size(); ++it2) {
            curve_new.clear();
            curve_new.push_back(curve[0]);
            for (uint32_t i=1; i<curve.size()-1; ++i) {
                Vector3f p_new = 0.5f * (curve[i-1].p + curve[i+1].p);
                Vector3f n_new = (curve[i-1].n + curve[i+1].n).normalized();
                Float maxlength = (curve[i-1].p - curve[i+1].p).norm()*2;

                Ray ray1(p_new,  n_new, 0, maxlength);
                Ray ray2(p_new, -n_new, 0, maxlength);
                uint32_t idx1 = 0, idx2 = 0;
                Float t1 = 0, t2 = 0;
                Vector2f uv1, uv2;
                bool hit1 = bvh->rayIntersect(ray1, idx1, t1, &uv1);
                bool hit2 = bvh->rayIntersect(ray2, idx2, t2, &uv2);

                if (!hit1 && !hit2)
                    continue;

                CurvePoint pt;
                if (t1 < t2) {
                    pt.p = ray1(t1);
                    pt.f = idx1;
                    pt.n = ((1 - uv1.sum()) * N.col(F(0, idx1)) + uv1.x() * N.col(F(1, idx1)) + uv1.y() * N.col(F(2, idx1))).normalized();
                } else {
                    pt.p = ray2(t2);
                    pt.f = idx2;
                    pt.n = ((1 - uv2.sum()) * N.col(F(0, idx2)) + uv2.x() * N.col(F(1, idx2)) + uv2.y() * N.col(F(2, idx2))).normalized();
                }
                curve_new.push_back(pt);
            }
            curve_new.push_back(curve[curve.size()-1]);
            curve.swap(curve_new);
        }

        if (!watertight && it == 1)
            break;

        curve_new.clear();
        curve_new.push_back(curve[0]);
        for (uint32_t i=1; i<curve.size(); ++i) {
            if (!astar(F, E2E, V, curve[i-1].f, curve[i].f, path))
                return false;

            auto closest = [](const Vector3f &p0, const Vector3f &p1, const Vector3f &target) -> Vector3f {
                Vector3f d = (p1-p0).normalized();
                return p0 + d * std::min(std::max((target-p0).dot(d), 0.0f), (p0-p1).norm());
            };

            if (path.size() > 2) {
                uint32_t base = curve_new.size() - 1;
                for (uint32_t j=1; j<path.size()-1; ++j) {
                    uint32_t f = path[j];
                    Vector3f p0 = V.col(F(0, f)), p1 = V.col(F(1, f)), p2 = V.col(F(2, f));
                    CurvePoint pt2;
                    pt2.f = f;
                    pt2.n = (p1-p0).cross(p2-p0).normalized();
                    pt2.p = (p0+p1+p2) * (1.0f / 3.0f);
                    curve_new.push_back(pt2);
                }
                curve_new.push_back(curve[i]);

                for (uint32_t q=1; q<path.size()-1; ++q) {
                    for (uint32_t j=1; j<path.size()-1; ++j) {
                        Float bestDist1 = std::numeric_limits<Float>::infinity();
                        Float bestDist2 = std::numeric_limits<Float>::infinity();
                        Vector3f bestPt1 = Vector3f::Zero(), bestPt2 = Vector3f::Zero();
                        uint32_t f = path[j];
                        for (uint32_t k=0; k<3; ++k) {
                            Vector3f closest1 = closest(V.col(F(k, f)), V.col(F((k + 1) % 3, f)), curve_new[base+j-1].p);
                            Vector3f closest2 = closest(V.col(F(k, f)), V.col(F((k + 1) % 3, f)), curve_new[base+j+1].p);
                            Float dist1 = (closest1 - curve_new[base+j-1].p).norm();
                            Float dist2 = (closest2 - curve_new[base+j+1].p).norm();
                            if (dist1 < bestDist1) { bestDist1 = dist1; bestPt1 = closest1; }
                            if (dist2 < bestDist2) { bestDist2 = dist2; bestPt2 = closest2; }
                        }
                        curve_new[base+j].p = (bestPt1 + bestPt2) * 0.5f;
                    }
                }
            } else {
                curve_new.push_back(curve[i]);
            }
        }
        curve.swap(curve_new);

//.........这里部分代码省略.........
开发者ID:DrangPo,项目名称:instant-meshes,代码行数:101,代码来源:smoothcurve.cpp

示例6: assert

/*static*/
void
AbstractTexture::resizeData(unsigned int width,
                            unsigned int height,
                            std::vector<unsigned char>&    data,
                            unsigned int newWidth,
                            unsigned int newHeight,
                            bool resizeSmoothly,
                            std::vector<unsigned char>&    newData)
{
#ifdef DEBUG_TEXTURE
    assert(data.size() == width * height * sizeof(int));
#endif // DEBUG_TEXTURE

    newData.clear();

    if (data.empty() || newWidth == 0 || newHeight == 0)
        return;

    if (newWidth == width && newHeight == height)
    {
        newData.swap(data);
        return;
    }

    const auto    size    = newWidth * newHeight * sizeof(int);
    const float    xFactor = ((float)width - 1.0f)/((float)newWidth - 1.0f);
    const float    yFactor = ((float)height - 1.0f)/((float)newHeight - 1.0f);

    newData.resize(size);

    uint    idx    = 0;
    float    y    = 0.0f;
    for (uint q = 0; q < newHeight; ++q)
    {
        uint        j    = (uint) floorf(y);
        const float dy    = y - (float)j;
        if (j >= height)
            j = height - 1;

        float        x    = 0.0f;
        for (uint p = 0; p < newWidth; ++p)
        {
            uint        i    = (uint)floorf(x);
            if (i >= width)
                i = width - 1;

            const uint ijTL    = (i + width * j) << 2;

            if (resizeSmoothly)
            {
                // bilinear interpolation

                const float dx    = x - (float)i;
                const float dxy = dx * dy;

                const uint ijTR    = i < width - 1                        ? ijTL + 4                        : ijTL;
                const uint ijBL = j < height - 1                        ? ijTL + (width << 2)            : ijTL;
                const uint ijBR = (i < width - 1) && (j < height - 1)    ? ijTL + ((width + 1) << 2)    : ijTL;

                const float    wTL    = 1.0f - dx - dy + dxy;
                const float wTR = dx - dxy;
                const float wBL = dy - dxy;
                const float wBR = dxy;

                for (uint k = 0; k < 4; ++k)
                {
                    const float color = wTL * data[ijTL + k] +
                        wTR * data[ijTR + k] +
                        wBL * data[ijBL + k] +
                        wBR * data[ijBR + k];

                    newData[idx + k] = (unsigned char)floorf(color);
                }
            }
            else
            {
                // nearest pixel color

                for (uint k = 0; k < 4; ++k)
                    newData[idx + k] = data[ijTL + k];
            }

            idx    += 4;
            x    += xFactor;
        }
        y += yFactor;
    }

#ifdef DEBUG_TEXTURE
    assert(newData.size() == newWidth * newHeight * sizeof(int));
#endif // DEBUG_TEXTURE
}
开发者ID:RinWorld,项目名称:minko,代码行数:93,代码来源:AbstractTexture.cpp

示例7: aggr

        pointwise_aggregates(const Matrix &A, const params &prm, unsigned min_aggregate)
            : count(0)
        {
            typedef typename backend::value_type<Matrix>::type value_type;
            typedef typename math::scalar_of<value_type>::type scalar_type;
            if (prm.block_size == 1) {
                plain_aggregates aggr(A, prm);

                remove_small_aggregates(A.nrows, 1, min_aggregate, aggr);

                count = aggr.count;
                strong_connection.swap(aggr.strong_connection);
                id.swap(aggr.id);
            } else {
                strong_connection.resize( nonzeros(A) );
                id.resize( rows(A) );

                auto ap = backend::pointwise_matrix(A, prm.block_size);
                backend::crs<scalar_type> &Ap = *ap;

                plain_aggregates pw_aggr(Ap, prm);

                remove_small_aggregates(
                        Ap.nrows, prm.block_size, min_aggregate, pw_aggr);

                count = pw_aggr.count * prm.block_size;

#pragma omp parallel
                {
                    std::vector<ptrdiff_t> j(prm.block_size);
                    std::vector<ptrdiff_t> e(prm.block_size);

#pragma omp for
                    for(ptrdiff_t ip = 0; ip < static_cast<ptrdiff_t>(Ap.nrows); ++ip) {
                        ptrdiff_t ia = ip * prm.block_size;

                        for(unsigned k = 0; k < prm.block_size; ++k, ++ia) {
                            id[ia] = prm.block_size * pw_aggr.id[ip] + k;

                            j[k] = A.ptr[ia];
                            e[k] = A.ptr[ia+1];
                        }

                        for(ptrdiff_t jp = Ap.ptr[ip], ep = Ap.ptr[ip+1]; jp < ep; ++jp) {
                            ptrdiff_t cp = Ap.col[jp];
                            bool      sp = (cp == ip) || pw_aggr.strong_connection[jp];

                            ptrdiff_t col_end = (cp + 1) * prm.block_size;

                            for(unsigned k = 0; k < prm.block_size; ++k) {
                                ptrdiff_t beg = j[k];
                                ptrdiff_t end = e[k];

                                while(beg < end && A.col[beg] < col_end) {
                                    strong_connection[beg] = sp && A.col[beg] != (ia + k);
                                    ++beg;
                                }

                                j[k] = beg;
                            }
                        }
                    }
                }
            }
        }
开发者ID:ddemidov,项目名称:amgcl,代码行数:65,代码来源:pointwise_aggregates.hpp

示例8: SearchWorkThreadMgrProc


//.........这里部分代码省略.........
			TCHAR szAllDriverLetters[100] = { 0 };
			DWORD len = GetLogicalDriveStrings(sizeof(szAllDriverLetters) / sizeof(TCHAR), szAllDriverLetters);
			for (TCHAR * lpszCurrentDriverLetter = szAllDriverLetters; *lpszCurrentDriverLetter; lpszCurrentDriverLetter += _tcslen(lpszCurrentDriverLetter) + 1)
			{
				// 创建搜索线程
				Sleep(nSearchThreadIndex * 1000);
				StringCchPrintf(spi[nSearchThreadIndex].m_szStartLocation, MAX_PATH - 1, _T("%C:"), lpszCurrentDriverLetter[0]);
				spi[nSearchThreadIndex].m_bFastMode = lpDlg->GetFastMode();
				hSearchThread[nSearchThreadIndex] = CreateThread(
					NULL,         // 使用默认的安全描述符
					0,            // 使用默认的栈大小
					(LPTHREAD_START_ROUTINE)SearchThreadProc,
					(LPVOID)(spi + nSearchThreadIndex),
					CREATE_SUSPENDED,						// 先挂起
					dwSeachThreadId + nSearchThreadIndex);	// 取得线程ID
				if (hSearchThread[nSearchThreadIndex])
				{
					if (spi[nSearchThreadIndex].m_bFastMode)
						if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_TIME_CRITICAL))
							if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_HIGHEST))
								if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_ABOVE_NORMAL))
									if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_HIGHEST))
										SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_NORMAL);
					ResumeThread(hSearchThread[nSearchThreadIndex]);
					SetThreadPriorityBoost(hSearchThread[nSearchThreadIndex], !spi[nSearchThreadIndex].m_bFastMode);	// 系统动态调整线程优先级选项
					nSearchThreadIndex++;
				}
			}
			WaitForMultipleObjects(nSearchThreadIndex, hSearchThread, TRUE, INFINITE);
			for (short i = 0; i < nSearchThreadIndex; i++)
			{
				if (hSearchThread[i])
					CloseHandle(hSearchThread[i]);
			}
		}
		else
		{
			// 创建搜索线程
			DWORD ThreadID = 0;
			StringCchPrintf(spi[0].m_szStartLocation, MAX_PATH - 1, _T("%s"), strSearchStartPath);
			spi[0].m_bFastMode = lpDlg->GetFastMode();
			hSearchThread[0] = CreateThread(
				NULL,         // 使用默认的安全描述符
				0,            // 使用默认的栈大小
				(LPTHREAD_START_ROUTINE)SearchThreadProc,
				(LPVOID)&spi[0],
				CREATE_SUSPENDED,						// 先挂起
				&ThreadID);	// 取得线程ID
			if (hSearchThread)
			{
				if (spi[0].m_bFastMode)
					if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_TIME_CRITICAL))
						if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_HIGHEST))
							if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_ABOVE_NORMAL))
								if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_HIGHEST))
									SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_NORMAL);
				ResumeThread(hSearchThread[nSearchThreadIndex]);
				SetThreadPriorityBoost(hSearchThread[nSearchThreadIndex], !spi[nSearchThreadIndex].m_bFastMode);	// 系统动态调整线程优先级选项

				WaitForSingleObject(hSearchThread[nSearchThreadIndex], INFINITE);
				CloseHandle(hSearchThread[nSearchThreadIndex]);
				nSearchThreadIndex++;
			}
		}
		if (g_vecCurrentFindData.size())
		{
			lpDlg->InitList();
			lpDlg->NotifyStatusMsg(_T("正在更新搜索结果列表,请稍候..."));
			lpDlg->UpdateList(g_vecCurrentFindData);
			ULONG nViewCount = 0, nFoundCount = 0;
			for (short i = 0; i < nSearchThreadIndex; i++)
			{
				nViewCount += spi[i].m_nViewCount;
				nFoundCount += spi[i].m_nFoundCount;
			}
			StringCchPrintf(szMsg, nMSG_SIZE - 1, _T("搜索完成,在%d个项目中共找到了%d个对象。"), nViewCount, nFoundCount);
			lpDlg->NotifyStatusMsg(szMsg);
		}
		else
		{
			lpDlg->NotifyStatusMsg(_T("未找到!"));
		}

		// 搜索完了,重置状态
		g_vecCurrentFindData.clear();
		std::vector<FIND_DATA> vecCurrentFindDataTemp;
		g_vecCurrentFindData.swap(vecCurrentFindDataTemp);
		g_hBrokenEvent ? ResetEvent(g_hBrokenEvent) : 0;
		g_hSearchEvent ? ResetEvent(g_hSearchEvent) : 0;

		if (WaitForSingleObject(g_hQuitEvent, 50) == WAIT_OBJECT_0)
		{
			// 搜索任务完成之后检测有无退出信号
			OutputDebugString(_T("Quiting..."));
			break;
		}
	}

	return 0;
}
开发者ID:ccpwcn,项目名称:QuickSearch,代码行数:101,代码来源:SearchModule.cpp

示例9: buildMeshLod


//.........这里部分代码省略.........
	{
		int maxErrorBuffer = -1;
		float maxError = -1.0f;
		for (size_t i = 0; i < lastLevel.size(); ++i)
		{
			if (lastLevel[i] < 0)
			{
				continue;
			}
			//这里有点费解,但又懒得解释
			if (lastLevel[i] == buffers[i].size() - 1)
			{
				maxErrorBuffer = i;
				maxError = FLT_MAX;
			}
			else if (buffers[i][lastLevel[i] + 1].maxError > maxError)
			{
				maxErrorBuffer = i;
				maxError = buffers[i][lastLevel[i] + 1].maxError;
			}
		}
		if (maxErrorBuffer < 0)
		{
			break;
		}
		//填充顶点
		grp::LodIndices& lodIndices = buffers[maxErrorBuffer][lastLevel[maxErrorBuffer]];
		for (size_t i = 0; i < lodIndices.indices.size(); ++i)
		{
			int index = lodIndices.indices[i];
			if (vertexMap.find(index) == vertexMap.end())
			{
				vertexMap.insert(std::make_pair(index, newIndex));
				++newIndex;
			}
		}
		--lastLevel[maxErrorBuffer];
	}
	//顶点重新排序
	std::vector<ExportVertex> sorted(vertexMap.size());
	for (std::map<int, int>::iterator iterMap = vertexMap.begin();
		iterMap != vertexMap.end();
		++iterMap)
	{
		assert(iterMap->second < sorted.size());
		sorted[iterMap->second] = exportVertices[iterMap->first];
	}
	//整理index buffer
	for (size_t bufferIndex = 0; bufferIndex < buffers.size(); ++bufferIndex)
	{
		std::vector<grp::LodIndices>& buffer = buffers[bufferIndex];
		for (size_t levelIndex = 0; levelIndex < buffer.size(); ++levelIndex)
		{
			grp::LodIndices& lodIndice = buffer[levelIndex];
			lodIndice.maxIndex = 0;
			for (size_t indexIndex = 0; indexIndex < lodIndice.indices.size(); ++indexIndex)
			{
				grp::Index32& index = lodIndice.indices[indexIndex];
				assert(vertexMap.find(index) != vertexMap.end());
				index = vertexMap[index];
				if (index > lodIndice.maxIndex)
				{
					lodIndice.maxIndex = index;
				}
			}

		}
	}
	//整理冗余关系
	for (size_t vertexIndex = 0; vertexIndex < sorted.size(); ++vertexIndex)
	{
		ExportVertex& vertex = sorted[vertexIndex];
		std::map<int, int>::iterator found = vertexMap.find(vertex.copyPos);
		if (found != vertexMap.end())
		{
			vertex.copyPos = found->second;
		}
		found = vertexMap.find(vertex.copyNormal);
		if (found != vertexMap.end())
		{
			vertex.copyNormal = found->second;
		}
	}
	//纠正冗余关系,保证copyPos和copyNormal总是小于顶点下标
	for (size_t vertexIndex = 0; vertexIndex < sorted.size(); ++vertexIndex)
	{
		ExportVertex& vertex = sorted[vertexIndex];
		if (vertex.copyPos >= 0)
		{
			changeCopyPos(sorted, vertexIndex, vertex.copyPos);
		}
		if (vertex.copyNormal >= 0)
		{
			changeCopyNormal(sorted, vertexIndex, vertex.copyNormal);
		}
	}
	exportVertices.swap(sorted);

	return true;
}
开发者ID:ColinGilbert,项目名称:grandpa-animation,代码行数:101,代码来源:Exporter_Mesh.cpp

示例10: GetClsidsFromExt


//.........这里部分代码省略.........
	cs.Format(L".%s", ext);
	HRESULT hr = AssocQueryString(ASSOCF_VERIFY, ASSOCSTR_SHELLEXTENSION, cs, extra, buff, &size);
	if (hr == S_OK)
	{
		CLSID cls;
		CLSIDFromString(buff, &cls);
		res.push_back(cls);
	}
	extra = L"{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}";
	hr = AssocQueryString(ASSOCF_VERIFY, ASSOCSTR_SHELLEXTENSION, cs, extra, buff, &size);
	if (hr == S_OK)
	{
		CLSID cls;
		CLSIDFromString(buff, &cls);
		std::vector<CLSID>::iterator it = find(res.begin(), res.end(), cls);
		if (it == res.end())
			res.push_back(cls);
	}
	extra = L"{e357fccd-a995-4576-b01f-234630154e96}";
	hr = AssocQueryString(ASSOCF_VERIFY, ASSOCSTR_SHELLEXTENSION, cs, extra, buff, &size);
	if (hr == S_OK)
	{
		CLSID cls;
		CLSIDFromString(buff, &cls);
		std::vector<CLSID>::iterator it = find(res.begin(), res.end(), cls);
		if (it == res.end())
			res.push_back(cls);
	}
	//extra = L"{534A1E02-D58F-44f0-B58B-36CBED287C7C}";
	//CLSID cls;
	//CLSIDFromString(extra, &cls);
	//res.push_back(cls);
	//hr = AssocQueryString(ASSOCF_VERIFY, ASSOCSTR_SHELLEXTENSION, cs, extra, buff, &size);
	//if (hr == S_OK)
	//{
	//	std::vector<CString>::iterator it = find(res.begin(), res.end(), buff);
	//	if (it == res.end())
	//		res.push_back(buff);
	//}
	
	PERCEIVED     ptype;
	PERCEIVEDFLAG pflag;
	PWSTR         ppszType;
	cs = L"";
	WCHAR wcData[MAX_PATH];
	LONG cData = sizeof(wcData);
	cs.Format(L".%s", ext);
	hr = RegQueryValue(HKEY_CLASSES_ROOT, cs, wcData, &cData);
	if (hr == S_OK)
	{
		cs.Format(L"%s\\shellex\\{8895b1c6-b41f-4c1c-a562-0d564250836f}", wcData);
		cData = sizeof(wcData);
		hr = RegQueryValue(HKEY_CLASSES_ROOT, cs, wcData, &cData);
		if (hr == S_OK)
		{
			CLSID cls;
			CLSIDFromString(wcData, &cls);
			res.push_back(cls);
		}
	}

	cs.Format(L".%s", ext);
	hr = AssocGetPerceivedType(cs, &ptype, &pflag, &ppszType);
	if (hr == S_OK)
	{
		cs.Format(L"SystemFileAssociations\\%s\\ShellEx\\{e357fccd-a995-4576-b01f-234630154e96}", ppszType);
		hr = RegQueryValue(HKEY_CLASSES_ROOT, cs, wcData, &cData);
		if (hr == S_OK)
		{
			CLSID cls;
			CLSIDFromString(buff, &cls);
			std::vector<CLSID>::iterator it = find(res.begin(), res.end(), cls);
			if (it == res.end())
				res.push_back(cls);
		}

		cs.Format(L"SystemFileAssociations\\%s\\ShellEx\\{BB2E617C-0920-11d1-9A0B-00C04FC2D6C1}", ppszType);
		hr = RegQueryValue(HKEY_CLASSES_ROOT, cs, wcData, &cData);
		if (hr == S_OK)
		{
			CLSID cls;
			CLSIDFromString(buff, &cls);
			std::vector<CLSID>::iterator it = find(res.begin(), res.end(), cls);
			if (it == res.end())
				res.push_back(cls);
		}
		cs.Format(L"SystemFileAssociations\\%s\\ShellEx\\ContextMenuHandlers\\ShellVideoSlideshow", ppszType);
		hr = RegQueryValue(HKEY_CLASSES_ROOT, cs, wcData, &cData);
		if (hr == S_OK)
		{
			CLSID cls;
			CLSIDFromString(buff, &cls);
			std::vector<CLSID>::iterator it = find(res.begin(), res.end(), cls);
			if (it == res.end())
				res.push_back(cls);
		}
	}

	retVal.swap(res);
}
开发者ID:sergkap,项目名称:PreViewer,代码行数:101,代码来源:PreviewGenerator.cpp

示例11: set_killmask

 void set_killmask(std::vector<int> killmask_in)
 {
   killmask.swap(killmask_in);
   dedisp_error error = dedisp_set_killmask(plan,&killmask[0]);
   ErrorChecker::check_dedisp_error(error,"set_killmask");
 }
开发者ID:astrooman,项目名称:Bifrost,代码行数:6,代码来源:dedisperser.hpp

示例12: iter_swap

	void iter_swap(std::vector<aItem>::iterator a, std::vector<aItem>::iterator b) {
		a->swap(*b);
	};
开发者ID:BBkBlade,项目名称:e,代码行数:3,代码来源:GotoFileDlg.cpp

示例13: swap

template <class T> void swap(std::vector<T>& x, std::vector<T>& y)
{
    x.swap(y);
}
开发者ID:ddolzhenko,项目名称:traning_algos_2016_06,代码行数:4,代码来源:merge_sort.cpp

示例14: LoadFileStateData

static void LoadFileStateData(const std::string& filename, std::vector<u8>& ret_data)
{
	Flush();
	File::IOFile f(filename, "rb");
	if (!f)
	{
		Core::DisplayMessage("State not found", 2000);
		return;
	}

	StateHeader header;
	f.ReadArray(&header, 1);

	if (memcmp(SConfig::GetInstance().m_LocalCoreStartupParameter.GetUniqueID().c_str(), header.gameID, 6))
	{
		Core::DisplayMessage(StringFromFormat("State belongs to a different game (ID %.*s)",
			6, header.gameID), 2000);
		return;
	}

	std::vector<u8> buffer;

	if (header.size != 0) // non-zero size means the state is compressed
	{
		Core::DisplayMessage("Decompressing State...", 500);

		buffer.resize(header.size);

		lzo_uint i = 0;
		while (true)
		{
			lzo_uint32 cur_len = 0;  // number of bytes to read
			lzo_uint new_len = 0;  // number of bytes to write

			if (!f.ReadArray(&cur_len, 1))
				break;

			f.ReadBytes(out, cur_len);
			const int res = lzo1x_decompress(out, cur_len, &buffer[i], &new_len, nullptr);
			if (res != LZO_E_OK)
			{
				// This doesn't seem to happen anymore.
				PanicAlertT("Internal LZO Error - decompression failed (%d) (%li, %li) \n"
					"Try loading the state again", res, i, new_len);
				return;
			}

			i += new_len;
		}
	}
	else // uncompressed
	{
		const size_t size = (size_t)(f.GetSize() - sizeof(StateHeader));
		buffer.resize(size);

		if (!f.ReadBytes(&buffer[0], size))
		{
			PanicAlert("wtf? reading bytes: %i", (int)size);
			return;
		}
	}

	// all good
	ret_data.swap(buffer);
}
开发者ID:BlackBeetleKing,项目名称:dolphin,代码行数:65,代码来源:State.cpp

示例15: sort

  void sort() {
    sort_arg_t *thread_data;

    //          struct timeval t1, t2;
    //          gettimeofday(&t1, nullptr);

    if (thread_count == 1) {
      std::sort(data->begin(), data->end());
    }
    // divide input data on threads for sorting
    else {
      pthread_t *threads = new pthread_t[thread_count];
      thread_data = new sort_arg_t[thread_count];

      size_t begin = 0;
      size_t per_thread = data->size() / thread_count;
      size_t remainder = data->size() - per_thread * thread_count;

      for (int i = 0; i < thread_count; i++) {
        size_t size = per_thread + (i < remainder ? 1 : 0);
        thread_data[i].data = data;
        thread_data[i].begin = begin;
        thread_data[i].end = begin + size;
        begin += size;
      }

      for (int i = 0; i < thread_count; i++) {
        pthread_create(&threads[i], nullptr, thunk<ParallelSort, &ParallelSort::sort_thread>, new std::pair<void *, void *>(this, &thread_data[i]));
      }

      for (int i = 0; i < thread_count; i++) {
        pthread_join(threads[i], nullptr);
      }

      delete threads;
    }

    //          gettimeofday(&t2, nullptr);
    //          printf("%f,", t2.tv_sec + (double)t2.tv_usec / 1000000 - t1.tv_sec - (double)t1.tv_usec / 1000000);
    //          gettimeofday(&t1, nullptr);

    if (thread_count == 1) {

    }
    // uses a single 2-way merge to merge the two sorted parts
    else if (thread_count == 2) {
      merge_arg_t a, b;
      a.data = thread_data[0].data;
      a.begin = thread_data[0].begin;
      a.end = thread_data[0].end;
      a.delete_data_when_done = false;

      b.data = thread_data[1].data;
      b.begin = thread_data[1].begin;
      b.end = thread_data[1].end;
      b.delete_data_when_done = false;

      std::vector<T> *out = ParallelSort::merge_sorted(a, b);
      data->swap(*out);
      delete out;
    }

    // uses a single n-way merge to merge the sorted parts.
    // this is about 2x slower than the solution below
    //          else {
    //                  std::vector<T> *out = new std::vector<T>();
    //                  merge_data_t d;
    //
    //                  std::priority_queue<merge_data_t> heap;
    //
    //                  for (int i = 0; i < thread_count; i++) {
    //                          d.pos = thread_data[i].begin;
    //                          d.value = (*(thread_data[i].data))[d.pos];
    //                          d.slice = i;
    //                          heap.push(d);
    //                  }
    //
    //                  while (heap.size() > 0) {
    //                          d = heap.top();
    //                          heap.pop();
    //
    //                          out->push_back(d.value);
    //
    //                          d.pos++;
    //                          if (d.pos < thread_data[d.slice].end) {
    //                                  d.value = (*(thread_data[d.slice].data))[d.pos];
    //                                  heap.push(d);
    //                          }
    //                  }
    //                  data->swap(*out);
    //                  delete out;
    //          }

    // uses threaded 2-way merges to merge pairs of sorted parts until
    // only one big sorted part is left
    else {
      pthread_mutex_init(&parts_mutex, nullptr);
      pthread_mutex_init(&parts_exist_mutex, nullptr);

      size_t merge_thread_count = thread_count / 2;
//.........这里部分代码省略.........
开发者ID:InsZVA,项目名称:HyriseVisualizer,代码行数:101,代码来源:parallel_sort.hpp


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