/** @file parser.h
 *
 *	Declaration of parsing module interface.
 *
 *	Parsing module parses input file and stores the results as Word(s) instances
 *	in passed container.
 *
 *	(C) Ceslav Przywara 2008, MFF UK Prague
 *
 */

#ifndef _PARSER_H
#define	_PARSER_H

#include <fstream>
#include <vector>

// Word(s) container type.
#include "word.h"

namespace ace {

/** Parser object binds itself to open ifstream object, which corresponds to
 *	certain input datafile. Then parses the file by steps, which are determined
 *	by calls to next(size_t, ContextWindow::Mode, words_store_t&) method.
 */
class Parser {
public:
	/** Container holds numbers of words in each sentence (recently) parsed.
	 */
	typedef std::vector<size_t> parsed_counter_t;

private:
	/** Reference to file to be parsed.
	 */
	std::ifstream& _input_file;
	/** Line numbers counter.
	 */
	size_t _line_no;
	/** Parsed words and sentences counter (its value changes by every call to
	 *	next(size_t, ContextWindow::Mode, words_store_t&).
	 */
	parsed_counter_t _parsed_counter;

public:

	/** Constructor attach Parser to given input file ifstream object.
	 *	@param input_file Reference to (already open!) file to be parsed.
	 */
	Parser(std::ifstream& input_file): _input_file(input_file), _line_no(0) {}

	/** @return True, if internal parser pointer reached the end of file.
	 */
	inline bool eof(void) const { return _input_file.eof(); }

	/** @return Reference to const instance of recently parsed sentences counter.
	 */
	inline const parsed_counter_t& parsed(void) const { return _parsed_counter; }

	/** Parse and push next sentence(s). The number of sentences parsed depends
	 *	on count and mode params and on the current position of filestream pointer
	 *	(no parsing may be performed behind the end of file:).
	 *	@param count Number of units to parse (unit type is determined by `mode`).
	 *	@param mode One of ContextWindow::Mode values.
	 *	@param store Reference to container to push parsed words in.
	 *	@return True, if any sentence has been parsed.
	 */
	bool next(size_t count, ContextWindow::Mode mode, words_store_t& store);
	
};

} // namespace ace

#endif
