/*
 * StringLineReader.h
 *
 *  Created on: 20. 3. 2017
 *	  Author: Jan Travnicek
 */

#ifndef _STRING_LINE_READER_H_
#define _STRING_LINE_READER_H_

#include <string>

#include <readline/LineReader.h>

namespace cli {

class StringLineReader final : public cli::LineReader {
	std::string m_string;

	bool readline ( std::string & line ) override {
		if ( m_string == "" )
			return false;

		line = std::exchange ( m_string, "" );
		return true;
	}

public:
	StringLineReader ( std::string string ) : m_string ( std::move ( string ) ) {
	}
};

} // namespace cli

#endif /* _STRING_LINE_READER_H_ */
