Ejemplo n.º 1
0
    explicit ContigPair(LineBuffer &source)
    : count(0)
    {
        auto const line = source.get();
        if (line.first == nullptr) return;

        auto n = 0;
        for (auto i = line.first, end = i; ; ++end) {
            if (end == line.second || *end == '\t') {
                switch (n) {
                    case 0:
                        first.ref = unsigned(references[std::string(i, end)]);
                        break;
                    case 1:
                        if (!string_to_i(first.start, i, end)) goto CONVERSION_ERROR;
                        break;
                    case 2:
                        if (!string_to_i(first.end, i, end)) goto CONVERSION_ERROR;
                        break;
                    case 3:
                        second.ref = unsigned(references[std::string(i, end)]);
                        break;
                    case 4:
                        if (!string_to_i(second.start, i, end)) goto CONVERSION_ERROR;
                        break;
                    case 5:
                        if (!string_to_i(second.end, i, end)) goto CONVERSION_ERROR;
                        break;
                    case 6:
                        group = unsigned(groups[std::string(i, end)]);
                        break;
                    case 7:
                        std::cerr << "extra data in record: " << std::string(line.first, line.second) << std::endl;
                        return;
                }
                ++n;
                if (end == line.second)
                    break;
                i = end + 1;
            }
        }
        if (n < 6) {
            std::cerr << "truncated record: " << std::string(line.first, line.second) << std::endl;
            return;
        }
        if (n < 7)
            group = groups[""];

        count = 1;
        return;
        
    CONVERSION_ERROR:
        std::cerr << "error parsing record: " << std::string(line.first, line.second) << std::endl;
        return;
    }