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


C++ DataObjectRef::setStored方法代码示例

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


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

示例1: encodeDataObject


//.........这里部分代码省略.........
        HAGGLE_ERR("Unable to open file %s\n", filePathOriginalDataObject);
        return NULL;
    }

    FILE* fragmentFilePointer = fopen(fragmentFile.c_str(), "wb");
    if (NULL == fragmentFilePointer) {
        HAGGLE_ERR("Error opening fragment file %s\n", fragmentFile.c_str());
	fclose(originaldataObjectFilePointer);
        return NULL;
    }

    this->fragmentationEncoderStorage->addDataObject(originalDataObject->getIdStr(), originalDataObject);

    fseek(originaldataObjectFilePointer, 0, SEEK_END);
    size_t fileSize = ftell(originaldataObjectFilePointer);

    size_t dataLen = fragmentationDataObjectUtility->getFileLength(originalDataObject);
    size_t totalNumberOfFragments = this->fragmentationDataObjectUtility->calculateTotalNumberOfFragments(dataLen,
            fragmentSize);
    int* fragmentSequenceNumberList = this->getIndexesOfFragmentsToCreate(totalNumberOfFragments);

    string sequenceNumberListCsv = "";

    size_t numberOfFragmentsToWrite = this->fragmentationConfiguration->getNumberFragmentsPerDataObject();
    if (numberOfFragmentsToWrite > totalNumberOfFragments) {
        HAGGLE_DBG2( "numberOfFragmentsToWrite=%d > totalNumberOfFragments=%d\n",
                numberOfFragmentsToWrite, totalNumberOfFragments);
        numberOfFragmentsToWrite = totalNumberOfFragments;
    }
    for (int count = 0; count < numberOfFragmentsToWrite && startIndex < totalNumberOfFragments;
            count++, startIndex++) {
        size_t sequenceNumberToWrite = fragmentSequenceNumberList[startIndex];
        HAGGLE_DBG2( "sequenceNumberToWrite=%d startIndex=%d totalNumberOfFragments=%d\n",
                sequenceNumberToWrite, startIndex, totalNumberOfFragments);
        FragmentationPositionInfo fragmentationPositionInfo =
                this->fragmentationDataObjectUtility->calculateFragmentationPositionInfo(sequenceNumberToWrite,
                        fragmentSize, fileSize);
        char intbuffer[33];
        memset(intbuffer, 0, sizeof(intbuffer));
        sprintf(intbuffer, "%d", sequenceNumberToWrite);
        sequenceNumberListCsv = sequenceNumberListCsv + intbuffer + ",";

        fseek(originaldataObjectFilePointer, fragmentationPositionInfo.startPosition, SEEK_SET);
        char* buffer = new char[fragmentationPositionInfo.actualFragmentSize + 1];
        memset(buffer, 0, fragmentationPositionInfo.actualFragmentSize + 1);
        size_t bytesRead = fread(buffer, 1, fragmentationPositionInfo.actualFragmentSize,
                originaldataObjectFilePointer);
        if (ferror(originaldataObjectFilePointer)) {
            HAGGLE_ERR("Error reading file %s\n", filePathOriginalDataObject);
	    delete[] buffer;
	    delete[] fragmentSequenceNumberList;
	    fclose(fragmentFilePointer);
	    fclose(originaldataObjectFilePointer);
            return NULL;
        }
        HAGGLE_DBG2( "bytesRead=%d read for sequenceNumber=%d actualFragmentSize=%d startPosition=%d\n",
                bytesRead, sequenceNumberToWrite, fragmentationPositionInfo.actualFragmentSize, fragmentationPositionInfo.startPosition);

        /*write to fragment*/
        fwrite(buffer, fragmentationPositionInfo.actualFragmentSize, 1, fragmentFilePointer);
        if (ferror(fragmentFilePointer)) {
            HAGGLE_ERR("Error writing file %s\n", fragmentFile.c_str());
	    delete[] buffer;
	    delete[] fragmentSequenceNumberList;
	    fclose(fragmentFilePointer);
	    fclose(originaldataObjectFilePointer);
            return NULL;
        }
        HAGGLE_DBG2("wrote fragment file %s - sequenceNumber=%d\n", fragmentFile.c_str(), sequenceNumberToWrite);

        delete[] buffer;
    }
    delete[] fragmentSequenceNumberList;
    fclose(fragmentFilePointer);
    fclose(originaldataObjectFilePointer);

    sequenceNumberListCsv = sequenceNumberListCsv.substr(0, sequenceNumberListCsv.size() - 1);
    HAGGLE_DBG2("sequenceNumberListCsv=%s\n", sequenceNumberListCsv.c_str());

    DataObjectRef fragmentDataObjectRef = DataObject::create(fragmentFile, fragmentationDataObjectUtility->getFileName(originalDataObject));

    if(!fragmentDataObjectRef) {
      HAGGLE_ERR("Unable to create data object for file %s (%s)\n", fragmentFile.c_str(), originalDataObject->getFileName().c_str());
      return NULL;
    }

    bool addedAttributes = this->addAttributes(originalDataObject, fragmentDataObjectRef, sequenceNumberListCsv);

    if (!addedAttributes) {
        HAGGLE_ERR("Unable to add fragment attributes\n");
        return NULL;
    }

    fragmentDataObjectRef->setStored(true);

    HAGGLE_DBG2("Created fragment file %s for parent data object %s\n",
            fragmentDataObjectRef->getFilePath().c_str(), originalDataObject->getIdStr());

    return fragmentDataObjectRef;
}
开发者ID:SRI-CSL,项目名称:ENCODERS,代码行数:101,代码来源:FragmentationEncoderService.cpp


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