/* static */ DictionaryStructureWithBufferPolicy::StructurePolicyPtr
        DictionaryStructureWithBufferPolicyFactory::newPolicyForOnMemoryV4Dict(
                const FormatUtils::FORMAT_VERSION formatVersion,
                const std::vector<int> &locale,
                const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap) {
    HeaderPolicy headerPolicy(formatVersion, locale, attributeMap);
    DictBuffersPtr dictBuffers = DictBuffers::createVer4DictBuffers(&headerPolicy,
            DictConstants::MAX_DICT_EXTENDED_REGION_SIZE);
    if (!DynamicPtWritingUtils::writeEmptyDictionary(
            dictBuffers->getWritableTrieBuffer(), 0 /* rootPos */)) {
        AKLOGE("Empty ver4 dictionary structure cannot be created on memory.");
        return nullptr;
    }
    return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(
            new StructurePolicy(std::move(dictBuffers)));
}
コード例 #2
0
/* static */ bool DictFileWritingUtils::createEmptyV4DictFile(const char *const dirPath,
        const std::vector<int> localeAsCodePointVector,
        const DictionaryHeaderStructurePolicy::AttributeMap *const attributeMap,
        const FormatUtils::FORMAT_VERSION formatVersion) {
    HeaderPolicy headerPolicy(formatVersion, localeAsCodePointVector, attributeMap);
    DictBuffersPtr dictBuffers = DictBuffers::createVer4DictBuffers(&headerPolicy,
            DictConstants::MAX_DICT_EXTENDED_REGION_SIZE);
    headerPolicy.fillInAndWriteHeaderToBuffer(true /* updatesLastDecayedTime */,
            EntryCounts(), 0 /* extendedRegionSize */, dictBuffers->getWritableHeaderBuffer());
    if (!DynamicPtWritingUtils::writeEmptyDictionary(
            dictBuffers->getWritableTrieBuffer(), 0 /* rootPos */)) {
        AKLOGE("Empty ver4 dictionary structure cannot be created on memory.");
        return false;
    }
    return dictBuffers->flush(dirPath);
}
/* static */ DictionaryStructureWithBufferPolicy::StructurePolicyPtr
        DictionaryStructureWithBufferPolicyFactory::newPolicyForV4Dict(
                const char *const headerFilePath, const FormatUtils::FORMAT_VERSION formatVersion,
                MmappedBuffer::MmappedBufferPtr &&mmappedBuffer) {
    const int dictDirPathBufSize = strlen(headerFilePath) + 1 /* terminator */;
    char dictPath[dictDirPathBufSize];
    if (!FileUtils::getFilePathWithoutSuffix(headerFilePath,
            DictConstants::HEADER_FILE_EXTENSION, dictDirPathBufSize, dictPath)) {
        AKLOGE("Dictionary file name is not valid as a ver4 dictionary. header path: %s",
                headerFilePath);
        ASSERT(false);
        return nullptr;
    }
    DictBuffersPtr dictBuffers =
            DictBuffers::openVer4DictBuffers(dictPath, std::move(mmappedBuffer), formatVersion);
    if (!dictBuffers || !dictBuffers->isValid()) {
        AKLOGE("DICT: The dictionary doesn't satisfy ver4 format requirements. path: %s",
                dictPath);
        ASSERT(false);
        return nullptr;
    }
    return DictionaryStructureWithBufferPolicy::StructurePolicyPtr(
            new StructurePolicy(std::move(dictBuffers)));
}