/*
 * Copyright (c) 2012, 2013, 2014 Jonas 'Sortie' Termansen.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 * linebuffer.h
 * Provides a simple queue-like line buffering for terminals.
 */

#ifndef SORTIX_LINEBUFFER_H
#define SORTIX_LINEBUFFER_H

#include <stddef.h>
#include <stdint.h>

namespace Sortix {

class LineBuffer
{
public:
	LineBuffer();
	~LineBuffer();

public:
	bool Push(uint32_t unicode);
	uint32_t Pop();
	uint32_t Peek() const;
	uint32_t Backspace();
	uint32_t WouldBackspace() const;
	void Commit();
	void Freeze();
	bool CanPop() const;
	bool CanBackspace() const;
	void Flush();

private:
	uint32_t* buffer;
	size_t bufferlength;
	size_t bufferoffset;
	size_t buffercommitted;
	size_t bufferfrozen;
	size_t bufferused;

};

} // namespace Sortix

#endif
