#ifndef BUFFERLINEWALKER_H
#define BUFFERLINEWALKER_H

#include "Buffer.h"
#include "CharacterWidthDeterminer.h"
#include <functional>

/**
 * Provides functionality to walk a line of a buffer taking into account the
 * view width and multi-column characters.
 */
class BufferLineWalker
{
public:
    BufferLineWalker(
            std::shared_ptr<Buffer> buffer,
            std::shared_ptr<Buffer::Iterator> start_of_line,
            int view_width,
            CharacterWidthDeterminer & character_width_determiner);
    void operator++() { return (*this)++; }
    void operator++(int unused);
    bool is_eol() const
    {
        if (is_valid())
        {
            return (m_code_point == '\n');
        }
        return false;
    }
    bool is_valid() const
    {
        return (bool)m_iterator;
    }
    int row_offset() const { return m_row_offset; }
    int screen_column() const { return m_screen_column; }
    int virtual_column() const { return m_virtual_column; }
    int character_width() const { return m_character_width; }
    uint32_t code_point() const { return m_code_point; }
    std::shared_ptr<Buffer::Iterator> iterator() const { return m_iterator; }

protected:
    std::shared_ptr<Buffer> m_buffer;
    std::shared_ptr<Buffer::Iterator> m_iterator;
    CharacterWidthDeterminer & m_character_width_determiner;
    int m_view_width;
    int m_row_offset;
    int m_screen_column;
    int m_virtual_column;
    int m_character_width;
    uint32_t m_code_point;

    void process_new_character();
};

#endif
