Parser.hh 4.11 KB
/**
 * Parser.hh
 *
 *  Created on: Dec 11, 2012
 *      Author: AKKA IS
 */

#ifndef PARSER_HH_
#define PARSER_HH_
#include <string>
#include <set>
#include <vector>
#include <map>

namespace AMDA {
namespace Parameters {
/**
 * @brief parser ofclassic  process  expression
 */
class Parser {
	/**
	 * @brief List of attributes
	 */
	typedef  std::vector<std::string> AttributList;

	/**
	 * @brief Information of a process
	 */
	struct ProcessInfo {
		/**
		 * default constructor
		 */
		ProcessInfo() {}
		/**
		 * constructor by parameter
		 */
		ProcessInfo(std::string pName, std::string pExpression, AttributList pAttribut) : name(pName), expression(pExpression), attribut(pAttribut) {}

		/**
		 * @brief Process name
		 */
		std::string name;

		/**
		 * @brief Process expression
		 */
		std::string expression;

		/**
		 * @brief Process attributes list
		 */
		AttributList attribut;
	};

public:
	/**
	 * @brief List of parameter name
	 */
	typedef std::set<std::string>  ListParameterName ;

	/**
	 * @brief List of parameter name
	 */
	typedef std::set<std::string>  ListFctName ;

	/**
	 * @brief List of for key name a ProcessInfo
	 */
	typedef std::map<std::string, ProcessInfo>  ListProcessName ;

	/**
	 * @brief Default constructor
	 */
	Parser();

	/**
	 * destructor
	 */
	virtual ~Parser();

	/**
	 * @brief _formulaCC getter
	 */
	const std::string& getFormulaCc() const {
		return _formulaCC;
	}

	/**
	 * @brief _constructorCC getter
	 */
	const std::string& getContructorCc() const {
		return _constructorCC;
	}

	const ListParameterName& getListParameterName() const {
		return _listParameterName;
	}

	/**
	 * @brief _listProcessName getter
	 */
	const ListProcessName& getListProcessName() const {
		return _listProcessName;
	}

	/**
	 * @brief _listFctName getter
	 */
	const ListFctName& getListFctName() const {
		return _listFctName;
	}

	/**
	 * @brief Parse process start
	 * @param expression expression to parse
	 * @details state algorithm used
	 *  read expression by one character after character.
	 */
	void process(std::string expression);

	/**
	 * @brief  Search SemiColon with parenthesis counter.
	 */
	static size_t searchSemiColon(const char* expression);

private:

	/**
	 * @brief Parse a parameter name
	 * @detail Search the first non alphanum character and store the paramName in _listParameterName
	 *  @param it iterator on current character
	 */
	void processParameterName(std::string::iterator &it);

	/**
	 * @brief Parse a process name
	 * @detail Search the first non alphanum character
	 *  and launch processProcessExpression()
	 *  then store the processName with attributes  in _listProcessName
	 *  @param it iterator on current character
	 */
	void processProcessName(std::string::iterator &it);

	/**
	 * @brief Parse a parameter expression
	 * @detail Search the last parenthesis   with interne parenthesis counter
	 *  and return attribut list and sub process expression string
	 *  @param it iterator on current character
	 *  @param attribut output attributes ist
	 *  @return intern process expression string
	 */
	std::string processProcessExpression(std::string::iterator &it, AttributList &attribut);

	/**
		 * @brief Parse a function name
		 * @detail Search the first open parenthesis character and store the function in _listFctName
	 *  @param it iterator on current character
		 */
	void processFctName(std::string::iterator &it);

	/**
	 * @brief  Search the first non alphanum character and return the string between it and non alphanum character
	 *  @param it iterator on current character
	 */
	std::string findAlphaNum_(std::string::iterator &it);

	/**
	 * @brief List of parameter name
	 */
	ListParameterName _listParameterName;

	/**
	 * @brief List of for key name a ProcessInfo
	 */
	ListProcessName _listProcessName;

	/**
	 * @brief List of parameter name
	 */
	ListFctName _listFctName;

	/**
	 * @brief expression to parse;
	 */
	std::string _expression;

	/**
	 *@brief  _formula string to put in CC file
	 */
	std::string _formulaCC;

	/**
	 * @brief _constructor string to put in CC file
	 */
	std::string _constructorCC;


};

} /* namespace Parameters */
} /* namespace AMDA */
#endif /* PARSER_HH_ */