Horizon
attributes.hpp
1 #pragma once
2 #include <string>
3 
4 namespace horizon::ODB::attribute {
5 
6 namespace detail {
7 std::string make_legal_string_attribute(const std::string &n);
8 }
9 
10 template <typename T> struct attribute_name {
11 };
12 
13 enum class Type { FLOAT, BOOLEAN, TEXT };
14 
15 template <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 
21 template <typename T> struct boolean_attribute {
22  bool value = true;
23  static constexpr Type type = Type::BOOLEAN;
24 };
25 
26 template <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 
51 template <typename T> struct is_feature : std::false_type {
52 };
53 template <typename T> struct is_net : std::false_type {
54 };
55 template <typename T> struct is_pkg : std::false_type {
56 };
57 
58 template <class T> inline constexpr bool is_feature_v = is_feature<T>::value;
59 template <class T> inline constexpr bool is_net_v = is_net<T>::value;
60 template <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 
74 enum class drill { PLATED, NON_PLATED, VIA };
75 ATTR_NAME(drill)
76 ATTR_IS_FEATURE(drill)
77 
78 enum class primary_side { TOP, BOTTOM };
79 ATTR_NAME(primary_side)
80 
81 enum class pad_usage { TOEPRINT, VIA, G_FIDUCIAL, L_FIDUCIAL, TOOLING_HOLE };
82 ATTR_NAME(pad_usage)
83 ATTR_IS_FEATURE(pad_usage)
84 
85 MAKE_FLOAT_ATTR(drc_max_height, 3)
86 ATTR_IS_FEATURE(drc_max_height)
87 
88 MAKE_BOOLEAN_ATTR(smd)
89 ATTR_IS_FEATURE(smd)
90 
91 MAKE_TEXT_ATTR(electrical_class)
92 ATTR_IS_NET(electrical_class)
93 
94 MAKE_TEXT_ATTR(net_type)
95 ATTR_IS_NET(net_type)
96 
97 MAKE_TEXT_ATTR(diff_pair)
98 ATTR_IS_NET(diff_pair)
99 
100 MAKE_TEXT_ATTR(string)
101 ATTR_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