log_option_parser.hpp 1.31 KB
Newer Older
Swann Perarnau's avatar
Swann Perarnau committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#ifndef __LOG_OPTION_PARSER_HPP__
#define __LOG_OPTION_PARSER_HPP__

#include "common.hpp"
#include <utility>
#include <vector>
#include <string>

using std::vector;
using std::pair;
using std::string;


struct Log_option_group
{
	Log_dest dest;
	pair<Log_type, Activation> activation_levels[4];
	int nb_activation_levels;
	int current_activation_level;
	string filename; //if applicable
};

class Log_option_parser
{
	private:
		string _option;
		string _delim0;
		string _delim1;
		vector<Log_option_group> _log_option_groups;
		int _log_option_group_index;

		string _error_message;
		bool _has_error;

		bool parse_single_option_group(string& option_chunk);
		void parse_all_option_groups();

	public:
		Log_option_parser(const string& option, 
				const string& delim0=",", const string& delim1=":");
		~Log_option_parser();

		void reset(const string& option,
				const string& delim0=",", const string& delim1=":");

		/*Return LOG_DEST_DEV_NULL if no more Log_dest to return*/
		Log_dest get_next_log_dest();

		/*Returns (LOG_TYPE_INVALID, ACTIVATION_UNDEFINED) if no more
		 * to return*/
		pair<Log_type, Activation> get_next_level_activation();

		const string& get_filename();

		const string& get_error_message() const {return _error_message;}
		bool has_error() const {return _has_error;}
};

#endif //__LOG_OPTION_PARSER_HPP__