Horizon
Loading...
Searching...
No Matches
attributes.hpp
1#pragma once
2#include <string>
3
4namespace horizon::ODB::attribute {
5
6namespace detail {
7std::string make_legal_string_attribute(const std::string &n);
8}
9
10template <typename T> struct attribute_name {};
11
12enum class Type { FLOAT, BOOLEAN, TEXT };
13
14template <typename T, unsigned int n> struct float_attribute {
15 double value;
16 static constexpr unsigned int ndigits = n;
17 static constexpr Type type = Type::FLOAT;
18};
19
20template <typename T> struct boolean_attribute {
21 bool value = true;
22 static constexpr Type type = Type::BOOLEAN;
23};
24
25template <typename T> struct text_attribute {
26 text_attribute(const std::string &t) : value(detail::make_legal_string_attribute(t))
27 {
28 }
29 std::string value;
30 static constexpr Type type = Type::TEXT;
31};
32
33#define ATTR_NAME(n) \
34 template <> struct attribute_name<n> { \
35 static constexpr const char *name = "." #n; \
36 };
37
38#define MAKE_FLOAT_ATTR(n, nd) \
39 using n = float_attribute<struct n##_t, nd>; \
40 ATTR_NAME(n)
41
42#define MAKE_TEXT_ATTR(n) \
43 using n = text_attribute<struct n##_t>; \
44 ATTR_NAME(n)
45
46#define MAKE_BOOLEAN_ATTR(n) \
47 using n = boolean_attribute<struct n##_t>; \
48 ATTR_NAME(n)
49
50template <typename T> struct is_feature : std::false_type {};
51template <typename T> struct is_net : std::false_type {};
52template <typename T> struct is_pkg : std::false_type {};
53
54template <class T> inline constexpr bool is_feature_v = is_feature<T>::value;
55template <class T> inline constexpr bool is_net_v = is_net<T>::value;
56template <class T> inline constexpr bool is_pkg_v = is_pkg<T>::value;
57
58#define ATTR_IS_FEATURE(a) \
59 template <> struct is_feature<a> : std::true_type {};
60
61#define ATTR_IS_NET(a) \
62 template <> struct is_net<a> : std::true_type {};
63
64#define ATTR_IS_PKG(a) \
65 template <> struct is_pkg<a> : std::true_type {};
66
67enum class drill { PLATED, NON_PLATED, VIA };
68ATTR_NAME(drill)
69ATTR_IS_FEATURE(drill)
70
71enum class primary_side { TOP, BOTTOM };
72ATTR_NAME(primary_side)
73
74enum class pad_usage { TOEPRINT, VIA, G_FIDUCIAL, L_FIDUCIAL, TOOLING_HOLE };
75ATTR_NAME(pad_usage)
76ATTR_IS_FEATURE(pad_usage)
77
78MAKE_FLOAT_ATTR(drc_max_height, 3)
79ATTR_IS_FEATURE(drc_max_height)
80
81MAKE_BOOLEAN_ATTR(smd)
82ATTR_IS_FEATURE(smd)
83
84MAKE_TEXT_ATTR(electrical_class)
85ATTR_IS_NET(electrical_class)
86
87MAKE_TEXT_ATTR(net_type)
88ATTR_IS_NET(net_type)
89
90MAKE_TEXT_ATTR(diff_pair)
91ATTR_IS_NET(diff_pair)
92
93MAKE_TEXT_ATTR(string)
94ATTR_IS_FEATURE(string)
95
96} // namespace horizon::ODB::attribute
Definition attributes.hpp:10
Definition attributes.hpp:20
Definition attributes.hpp:14
Definition attributes.hpp:50
Definition attributes.hpp:51
Definition attributes.hpp:52
Definition attributes.hpp:25