Skip to content

Commit c0c5dbc

Browse files
committed
add some example
1 parent 86a3f3f commit c0c5dbc

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/main.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ bool get_bool(prism::ContextTypes* value) {
115115
return false;
116116
}
117117

118-
prism::ContextTypes* append_formula(prism::ContextItems* _, prism::ContextTypes* a_arg, prism::ContextTypes* a_single,
118+
prism::ContextTypes* append_formula(prism::ContextItems* items, prism::ContextTypes* a_arg, prism::ContextTypes* a_single,
119119
prism::ContextTypes* a_mult, prism::ContextTypes* a_mix,
120120
prism::ContextTypes* a_with_alpha, prism::ContextTypes* a_only_alpha,
121121
prism::ContextTypes* a_alpha, prism::ContextTypes* a_first_cycle) {
122+
if (!items->contains("local_var")) {
123+
items->insert({"local_var", prism::ContextTypes{0}});
124+
}
125+
// increase local_var by 1
126+
auto& local_var = std::get<int>(items->at("local_var"));
127+
local_var++;
122128
// uint8_t c[2][4] =
123129
auto c = std::get<prism::MTDArray<int>>(*a_arg);
124130
bool do_single = get_bool(a_single);
@@ -169,6 +175,23 @@ std::optional<std::string> include_fs(const std::string& path){
169175
return std::string(data.begin(), data.end());
170176
}
171177

178+
std::string to_string(const prism::ContextTypes& value) {
179+
if (std::holds_alternative<int>(value)) {
180+
return std::to_string(std::get<int>(value));
181+
} else if (std::holds_alternative<float>(value)) {
182+
return std::to_string(std::get<float>(value));
183+
} else if (std::holds_alternative<std::string>(value)) {
184+
return std::get<std::string>(value);
185+
} else if (std::holds_alternative<prism::MTDArray<bool>>(value)) {
186+
return "MTDArray<bool>";
187+
} else if (std::holds_alternative<prism::MTDArray<int>>(value)) {
188+
return "MTDArray<int>";
189+
} else if (std::holds_alternative<prism::MTDArray<float>>(value)) {
190+
return "MTDArray<float>";
191+
}
192+
return "Unknown type";
193+
}
194+
172195
int main(int argc, char** argv) {
173196
if (argc < 2) {
174197
SPDLOG_ERROR("Usage: {} <file>", argv[0]);
@@ -287,6 +310,9 @@ int main(int argc, char** argv) {
287310
processor.populate(vars);
288311
processor.load(std::string(data.begin(), data.end()));
289312
SPDLOG_INFO("Processed data: \n{}", processor.process());
313+
for (const auto& item : processor.getTypes()) {
314+
SPDLOG_INFO("{}: {}", item.first, to_string(item.second));
315+
}
290316
return 0;
291317
}
292318
#endif

0 commit comments

Comments
 (0)