Skip to content

IterRead

Description

Propagating read. Writes the current element to *out and advances the iterator. out must point at storage compatible with the iterator’s element type.

Success

*out is set, pos advances by dir, returns true.

Failure

Iterator is exhausted. *out is not written, pos is unchanged, returns false.

Usage example (Cross-references)

Usage examples (Cross-references)
        BufIter  it     = BufIterFromMemory(buf, 1);
        u8       v;
        IterRead(&it, &v);
        IterMustRead(&it, &v);
        return true;
        BufIter  it     = BufIterFromMemory(buf, 1);
        u8       v;
        IterRead(&it, &v);
        IterMustNext(&it);
        return true;
        }
        u8 v;
        IterRead(&it, &v);
        if (IterRemainingLength(&it) != 2) {
            return false;
            return false;
        }
        IterRead(&it, &v);
        IterRead(&it, &v);
        return IterRemainingLength(&it) == 0;
        }
        IterRead(&it, &v);
        IterRead(&it, &v);
        return IterRemainingLength(&it) == 0;
    }
        }
        u8 v;
        IterRead(&it, &v);
        if (IterRemainingLength(&it) != 2) {
            return false;
            return false;
        }
        IterRead(&it, &v);
        IterRead(&it, &v);
        return IterRemainingLength(&it) == 0;
        }
        IterRead(&it, &v);
        IterRead(&it, &v);
        return IterRemainingLength(&it) == 0;
    }
        BufIter  it     = BufIterFromMemory(buf, 3);
        u8       v      = 0;
        if (!IterRead(&it, &v) || v != 10) {
            return false;
        }
            return false;
        }
        if (!IterRead(&it, &v) || v != 20) {
            return false;
        }
            return false;
        }
        if (!IterRead(&it, &v) || v != 30) {
            return false;
        }
        }
        // Fourth read must fail: cursor sits at EOF after the three above.
        return !IterRead(&it, &v);
    }
        BufIter  it     = from_rev(buf, 3);
        u8       v      = 0;
        if (!IterRead(&it, &v) || v != 30) {
            return false;
        }
            return false;
        }
        if (!IterRead(&it, &v) || v != 20) {
            return false;
        }
            return false;
        }
        if (!IterRead(&it, &v) || v != 10) {
            return false;
        }
        }
        // Fourth read must fail: cursor has stepped past the start sentinel.
        return !IterRead(&it, &v);
    }
        BufIter  it     = BufIterFromMemory(buf, 1);
        u8       v      = 0;
        IterRead(&it, &v);
        size pos_before = IterIndex(&it);
        u8   sentinel   = 0xAA;
        u8   sentinel   = 0xAA;
        v               = sentinel;
        if (IterRead(&it, &v)) {
            return false;
        }
    /// TAGS: StrIter, Read, Advance, Alias
    ///
    #define StrIterRead(mi, out) IterRead((mi), (out))
    
    ///
    #define IterMustRead(mi, out)                                                                                          \
        do {                                                                                                               \
            if (!IterRead((mi), (out))) {                                                                                  \
                LOG_FATAL("IterMustRead: iterator exhausted");                                                             \
            }                                                                                                              \
Last updated on