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


C++ BSONElement::binDataType方法代码示例

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


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

示例1: getUUIDField

repoUUID RepoBSON::getUUIDField(const std::string &label) const{
	repoUUID uuid;
	if (hasField(label))
	{

		const mongo::BSONElement bse = getField(label);
		if (bse.type() == mongo::BSONType::BinData && (bse.binDataType() == mongo::bdtUUID ||
			bse.binDataType() == mongo::newUUID))
		{
			int len = static_cast<int>(bse.size() * sizeof(boost::uint8_t));
			const char *binData = bse.binData(len);
			memcpy(uuid.data, binData, len);
		}
		else
		{
			repoError << "Field  " << label << " is not of type UUID!";
			uuid = generateUUID();  // failsafe
		}
	}
	else
	{
		repoError << "Field  " << label << " does not exist!";
		uuid = generateUUID();  // failsafe
	}

	return uuid;
}
开发者ID:wsdflink,项目名称:3drepobouncer,代码行数:27,代码来源:repo_bson.cpp

示例2: formatUuid

        std::string formatUuid(mongo::BSONElement &element, Robomongo::UUIDEncoding encoding)
        {
            mongo::BinDataType binType = element.binDataType();

            if (binType != mongo::newUUID && binType != mongo::bdtUUID)
                throw new std::invalid_argument("Binary subtype should be 3 (bdtUUID) or 4 (newUUID)");

            int len;
            const char *data = element.binData(len);
            std::string hex = HexUtils::toStdHexLower(data, len);

            if (binType == mongo::bdtUUID) {
                std::string uuid = HexUtils::hexToUuid(hex, encoding);

                switch(encoding) {
                case DefaultEncoding: return "LUUID(\"" + uuid + "\")";
                case JavaLegacy:      return "JUUID(\"" + uuid + "\")";
                case CSharpLegacy:    return "NUUID(\"" + uuid + "\")";
                case PythonLegacy:    return "PYUUID(\"" + uuid + "\")";
                default:              return "LUUID(\"" + uuid + "\")";
                }
            } else {
                std::string uuid = HexUtils::hexToUuid(hex, DefaultEncoding);
                return "UUID(\"" + uuid + "\")";
            }
        }
开发者ID:foyan,项目名称:robomongo,代码行数:26,代码来源:HexUtils.cpp

示例3: isUuidType

        bool isUuidType(const mongo::BSONElement &elem) 
        {
            if (elem.type() != mongo::BinData)
                return false;

            mongo::BinDataType binType = elem.binDataType();
            return (binType == mongo::newUUID || binType == mongo::bdtUUID);
        }
开发者ID:melinite,项目名称:robomongo,代码行数:8,代码来源:BsonUtils.cpp

示例4: if

void repo::core::RepoNodeMesh::retrieveFacesArray(
    const mongo::BSONElement &bse,
    const unsigned int api,
    const unsigned int facesByteCount,
    const unsigned int facesCount,
    std::vector<aiFace> *faces)
{
    //--------------------------------------------------------------------------
    // TODO make use of RepoTranscoderBSON to retrieve vector of unsigned int
    if (REPO_NODE_API_LEVEL_1 == api)
    {
        faces->resize(facesCount);
        unsigned int * serializedFaces = new unsigned int[facesByteCount/sizeof(unsigned int)];
        if (NULL != faces &&
                NULL != serializedFaces &&
                facesCount > 0 &&
                bse.binDataType() == mongo::BinDataGeneral)
        {
            // Copy over all the integers
            int len = (int) facesByteCount;
            const char *binData = bse.binData(len);
            memcpy(serializedFaces, binData, facesByteCount);

            // Retrieve numbers of vertices for each face and subsequent
            // indices into the vertex array.
            // In API level 1, mesh is represented as
            // [n1, v1, v2, ..., n2, v1, v2...]
            unsigned int counter = 0;
            int mNumIndicesIndex = 0;
            while (counter < facesCount)
            {
                int mNumIndices = serializedFaces[mNumIndicesIndex];
                aiFace face;
                face.mNumIndices = mNumIndices;
                unsigned int *indices = new unsigned int[mNumIndices];
                for (int i = 0; i < mNumIndices; ++i)
                    indices[i] = serializedFaces[mNumIndicesIndex + 1 + i];
                face.mIndices = indices;
                (*faces)[counter] = face;
                mNumIndicesIndex = mNumIndicesIndex + mNumIndices + 1;
                ++counter;
            }
        }

        // Memory cleanup
        if (NULL != serializedFaces)
            delete [] serializedFaces;

    }
    else if (REPO_NODE_API_LEVEL_2 == api)
    {
        // TODO: triangles only
    }
    else if (REPO_NODE_API_LEVEL_3 == api)
    {
        // TODO: compression
    }
}
开发者ID:DoumbiaAmadou,项目名称:3drepocore,代码行数:58,代码来源:repo_node_mesh.cpp

示例5: buildJsonString

        void buildJsonString(const mongo::BSONElement &elem,std::string &con, UUIDEncoding uuid, SupportedTimes tz)
        {
            switch (elem.type())
            {
            case NumberDouble:
                {
                    char dob[32] = {0};
                    sprintf(dob, "%f", elem.Double());
                    con.append(dob);
                }
                break;
            case String:
                {
                    con.append(elem.valuestr(), elem.valuestrsize() - 1);
                }
                break;
            case Object:
                {
                    buildJsonString(elem.Obj(), con, uuid, tz);
                }
                break;
            case Array:
                {
                    buildJsonString(elem.Obj(), con, uuid, tz);
                }
                break;
            case BinData:
                {
                    mongo::BinDataType binType = elem.binDataType();
                    if (binType == mongo::newUUID || binType == mongo::bdtUUID) {
                        std::string uu = HexUtils::formatUuid(elem, uuid);
                        con.append(uu);
                        break;
                    }
                    con.append("<binary>");
                }
                break;
            case Undefined:
                con.append("<undefined>");
                break;
            case jstOID:
                {
                    std::string idValue = elem.OID().toString();
                    char buff[256] = {0};
                    sprintf(buff, "ObjectId(\"%s\")", idValue.c_str());
                    con.append(buff);
                }
                break;
            case Bool:
                con.append(elem.Bool() ? "true" : "false");
                break;
            case Date:
                {
                    long long ms = (long long) elem.Date().millis;

                    boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
                    boost::posix_time::time_duration diff = boost::posix_time::millisec(ms);
                    boost::posix_time::ptime time = epoch + diff;

                    std::string date = miutil::isotimeString(time,false,tz==LocalTime);

                    con.append(date);
                    break;
                }
            case jstNULL:
                con.append("<null>");
                break;

            case RegEx:
                {
                    con.append("/" + std::string(elem.regex()) + "/");

                    for ( const char *f = elem.regexFlags(); *f; ++f ) {
                        switch ( *f ) {
                        case 'g':
                        case 'i':
                        case 'm':
                            con+=*f;
                        default:
                            break;
                        }
                    }
                }
                break;
            case DBRef:
                break;
            case Code:
                con.append(elem._asCode());
                break;
            case Symbol:
                con.append(elem.valuestr(), elem.valuestrsize() - 1);
                break;
            case CodeWScope:
                {
                    mongo::BSONObj scope = elem.codeWScopeObject();
                    if (!scope.isEmpty() ) {
                        con.append(elem._asCode());
                        break;
                    }
                }
//.........这里部分代码省略.........
开发者ID:melinite,项目名称:robomongo,代码行数:101,代码来源:BsonUtils.cpp


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