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