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


C++ BitArray::iterAt方法代码示例

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


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

示例1: if

static RSS::DataCharacter
DecodeDataCharacter(const BitArray& row, const RSS::FinderPattern& pattern, bool outsideChar)
{
    std::array<int, 8> counters = {};

    if (outsideChar) {
        if (!RowReader::RecordPatternInReverse(row.begin(), row.iterAt(pattern.startPos()), counters))
            return {};
    }
    else {
        if (!RowReader::RecordPattern(row.iterAt(pattern.endPos() + 1), row.end(), counters))
            return {};
        std::reverse(counters.begin(), counters.end());
    }

    int numModules = outsideChar ? 16 : 15;
    float elementWidth = static_cast<float>(std::accumulate(counters.begin(), counters.end(), 0)) / static_cast<float>(numModules);

    std::array<int, 4> oddCounts;
    std::array<int, 4> evenCounts;
    std::array<float, 4> oddRoundingErrors;
    std::array<float, 4> evenRoundingErrors;

    for (int i = 0; i < 8; i++) {
        float value = (float)counters[i] / elementWidth;
        int count = (int)(value + 0.5f); // Round
        if (count < 1) {
            count = 1;
        }
        else if (count > 8) {
            count = 8;
        }
        int offset = i / 2;
        if ((i & 0x01) == 0) {
            oddCounts[offset] = count;
            oddRoundingErrors[offset] = value - count;
        }
        else {
            evenCounts[offset] = count;
            evenRoundingErrors[offset] = value - count;
        }
    }

    if (!AdjustOddEvenCounts(outsideChar, numModules, oddCounts, evenCounts, oddRoundingErrors, evenRoundingErrors)) {
        return {};
    }

    int oddSum = 0;
    int oddChecksumPortion = 0;
    for (auto it = oddCounts.rbegin(); it != oddCounts.rend(); ++it) {
        oddChecksumPortion *= 9;
        oddChecksumPortion += *it;
        oddSum += *it;
    }
    int evenChecksumPortion = 0;
    int evenSum = 0;
    for (auto it = evenCounts.rbegin(); it != evenCounts.rend(); ++it) {
        evenChecksumPortion *= 9;
        evenChecksumPortion += *it;
        evenSum += *it;
    }
    int checksumPortion = oddChecksumPortion + 3 * evenChecksumPortion;

    if (outsideChar) {
        if ((oddSum & 0x01) != 0 || oddSum > 12 || oddSum < 4) {
            return {};
        }
        int group = (12 - oddSum) / 2;
        int oddWidest = OUTSIDE_ODD_WIDEST[group];
        int evenWidest = 9 - oddWidest;
        int vOdd = RSS::ReaderHelper::GetRSSvalue(oddCounts, oddWidest, false);
        int vEven = RSS::ReaderHelper::GetRSSvalue(evenCounts, evenWidest, true);
        int tEven = OUTSIDE_EVEN_TOTAL_SUBSET[group];
        int gSum = OUTSIDE_GSUM[group];
        return {vOdd * tEven + vEven + gSum, checksumPortion};
    }
    else {
        if ((evenSum & 0x01) != 0 || evenSum > 10 || evenSum < 4) {
            return {};
        }
        int group = (10 - evenSum) / 2;
        int oddWidest = INSIDE_ODD_WIDEST[group];
        int evenWidest = 9 - oddWidest;
        int vOdd = RSS::ReaderHelper::GetRSSvalue(oddCounts, oddWidest, true);
        int vEven = RSS::ReaderHelper::GetRSSvalue(evenCounts, evenWidest, false);
        int tOdd = INSIDE_ODD_TOTAL_SUBSET[group];
        int gSum = INSIDE_GSUM[group];
        return {vEven * tOdd + vOdd + gSum, checksumPortion};
    }

}
开发者ID:huycn,项目名称:zxing-cpp,代码行数:91,代码来源:ODRSS14Reader.cpp


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