Ejemplo n.º 1
0
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;
}
Ejemplo n.º 2
0
        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 + "\")";
            }
        }
Ejemplo n.º 3
0
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
    }
}
Ejemplo n.º 4
0
 int decode(T *t, const mongo::BSONElement &elm){
     int len = 0;            
     const char *p = elm.binData(len);
     memcpy((t->*ptr).id, p, len);                
     return 0;                                       
 }