#pragma once
#include <stdint.h>
#include <string>
#include <fstream>

using namespace std;

class Log
{
	public:
		Log(string _datadir, uint32_t _maxfilesize, bool _do_default_comment = true) throw (string);
		void 		next_run() throw (string);
		uint32_t 	next_file() throw (string);
		void 		flush() throw (string);
		int 		save_data(const char *dp, size_t n) throw (string);
		void 		close();
		void 		comment(const string& s);
		void 		comment(const char *s);
		~Log();

		uint32_t 	cur_run() const;
		uint32_t 	cur_file() const;
		uint32_t	bytes_cur_file() const;
		uint32_t 	total_bytes() const;
		string 		cur_file_str() const;
		string 		cur_run_str() const;
		string 		cur_file_path() const;

	private:
		string		active_file;		// name of "active" file
		string		cur_run_name_file;
		string		datadir;			// root directory of all the runs
		bool 		do_default_comment;
		uint32_t 	file;				// current file number
		ofstream 	filestream;			// current output file stream
		uint32_t 	filesize;			// size (bytes) of current file
		uint32_t 	maxfilesize;		// max size (bytes) of each data file
		uint32_t 	run;				// current run number
		string 		rundir;				// root dir of current run
		bool 		switch_data_files;	// 0 to put all data in one file
		uint32_t 	totbytes;			// total bytes writ by this Log

		// Disallow copying by having private copy constructor and
		// assignment operator.
		Log(const Log&);
		Log& operator=(const Log&);
};
