summaryrefslogtreecommitdiffhomepage
path: root/StarsEx/ParseUtil.inl.h
diff options
context:
space:
mode:
Diffstat (limited to 'StarsEx/ParseUtil.inl.h')
-rw-r--r--StarsEx/ParseUtil.inl.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/StarsEx/ParseUtil.inl.h b/StarsEx/ParseUtil.inl.h
new file mode 100644
index 0000000..f59489b
--- /dev/null
+++ b/StarsEx/ParseUtil.inl.h
@@ -0,0 +1,30 @@
+/* Starshatter: The Open Source Project
+ Copyright (c) 2021-2024, Starshatter: The Open Source Project Contributors
+ Copyright (c) 2011-2012, Starshatter OpenSource Distribution Contributors
+ Copyright (c) 1997-2006, Destroyer Studios LLC.
+*/
+
+#include <type_traits>
+
+#include <starshatter/definition.h>
+#include <Utils.h>
+
+
+template <typename Number>
+bool
+GetDefNumber(Number& dst, TermDef* def, const char* file)
+{
+ static_assert(std::is_convertible<long double, Number>::value);
+ if (!def || !def->term()) {
+ Print("WARNING: missing NUMBER TermDef in '%s'\n", file);
+ return false;
+ }
+ TermNumber* tr = def->term()->isNumber();
+ if (tr) {
+ dst = static_cast<Number>(tr->value());
+ return true;
+ }
+ else
+ Print("WARNING: invalid NUMBER %s in '%s'\n", def->name()->value().data(), file);
+ return false;
+}