Blame view

src/expressionParser/TemplateParamsInfo.hh 2.93 KB
93f280a8   Benjamin Renard   Implements templa...
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * 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_ */