-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalias_gen.py
executable file
·49 lines (34 loc) · 950 Bytes
/
alias_gen.py
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
#! /usr/bin/python3
header = """
#ifndef UNITS_ALIASES_HPP
#define UNITS_ALIASES_HPP
// WARNING: this file is auto-generated, all changes will be lost!!
#include "core.hpp"
namespace units {
"""
template = """
template<typename T>
using {0}_t = physical_unit<T, std::ratio<{3}>, {2}>;
using {0} = {0}_t<double>;
inline namespace literals {{
auto operator""{1}(long double val) {{
\treturn {0}{{static_cast<double>(val)}};
}}
}} //namespace literals
"""
footer = """
} //namespace units
#endif
"""
def main():
input = open("src/data/aliases.txt", "r")
output = open("src/include/aliases.hpp", "w")
output.write(header)
for line in input:
(name, short, dimension, factor) = line.split(";")
output.write(template.format(name.strip(), short.strip(),
dimension.strip(), factor.strip()))
output.write(footer)
output.close()
if __name__ == "__main__":
main()