TemplateParamsInfo.hh 2.93 KB
/*
 * TemplateParamsInfo.hh
 *
 *  Created on: May 10, 2019
 *      Author: AKKA
 */

#ifndef TEMPLATEPARAMSINFO_HH_
#define TEMPLATEPARAMSINFO_HH_

#include <string>
#include <vector>

namespace AMDA {
namespace parser {

class ArgumentItem {
public:

	ArgumentItem() : _key(""), _name("") {}

	void setKey(const std::string& key) {
		_key = key;
	}

	const std::string& getKey() const {
		return _key;
	}

	void setName(const std::string& name) {
		_name = name;
	}

	const std::string getName() const {
		return _name;
	}

private:

	std::string _key;

	std::string _name;
};

class TemplateAgrument {
public:

	typedef enum {
		AT_STRING,
		AT_INT,
		AT_FLOAT,
		AT_BOOL,
		AT_LIST,
		AT_GENERATED_LIST
	} ArgumentType;

	TemplateAgrument() : _key(""), _name(""), _type(ArgumentType::AT_STRING), _default("") {}

	void setKey(const std::string& key) {
		_key = key;
	}

	const std::string& getKey() const {
		return _key;
	}

	void setName(const std::string& name) {
		_name = name;
	}

	const std::string& getName() const {
		return _name;
	}

	void setType(ArgumentType type) {
		_type = type;
	}

	ArgumentType getType() {
		return _type;
	}

	void setDefault(const std::string& def)  {
		_default = def;
	}

	const std::string& getDefault() const {
		return _default;
	}

	void generateAutoItems(const std::string& nametpl, int minKey, int maxKey) {
		if (_type == AT_GENERATED_LIST) {
			_items.clear();
			for (int i = minKey; i <= maxKey; ++i) {
				ArgumentItem item;
				item.setKey(std::to_string(i));
				std::string name = "";
				if (nametpl.empty()) {
					name += _name;
					name += " #";
					name += std::to_string(i);
				}
				else {
					name = nametpl;
					std::string from = "##key##";
					size_t start_pos = name.find(from);
					if (start_pos != std::string::npos) {
						name.replace(start_pos, from.length(), std::to_string(i));
					}
				}
				item.setName(name);
				_items.push_back(item);
			}
		}
	}

	void addItem(const ArgumentItem& item) {
		_items.push_back(item);
	}

	const std::vector<ArgumentItem>& getItems() const {
		return _items;
	}

private:

	std::string _key;

	std::string _name;

	ArgumentType _type;

	std::string _default;

	std::vector<ArgumentItem> _items;
};

class TemplateParam {
public:

	TemplateParam() : _paramId(""), _fileName("") {}

	void setParamId(const std::string& paramId) {
		_paramId = paramId;
	}

	const std::string& getParamId() const {
		return _paramId;
	}

	void setFileName(const std::string& fileName) {
		_fileName = fileName;
	}

	const std::string& getFileName() const {
		return _fileName;
	}

	void addArgument(const TemplateAgrument& arg) {
		_arguments.push_back(arg);
	}

	const std::vector<TemplateAgrument>& getArguments() const {
		return _arguments;
	}

private:

	std::string _paramId;

	std::string _fileName;

	std::vector<TemplateAgrument> _arguments;

};

typedef std::vector<TemplateParam> TemplateParamsList;

} /* namespace parser */
} /* namespace AMDA */

#endif /* TEMPLATEPARAMSINFO_HH_ */