21#ifndef _ATTRIBUTE_PROVIDER_H_
22#define _ATTRIBUTE_PROVIDER_H_
44template <
typename T, TYPE AttrType>
54template <
typename T,
unsigned int N>
101template <
typename Tag,
template <
typename,
unsigned int>
class Attr,
TYPE AttrType,
unsigned int N>
107template <
typename Tag,
template <
typename>
class Attr,
TYPE AttrType>
148#define DEFINE_ATTR( Tag, Attr, AttrType, AttrName, ... ) \
152 constexpr const char Tag##_name[] = AttrName; \
153 using Tag = Attribute<Tag##_t, Attr, AttrType, __VA_ARGS__>::TYPE; \
155 struct AttributeName<Tag> \
157 static constexpr const char* name = Tag##_name; \
160#define DEFINE_ATTR_SIMPLE( Tag, Attr, AttrType, AttrName ) \
164 constexpr const char Tag##_name[] = AttrName; \
165 using Tag = AttributeSimple<Tag##_t, Attr, AttrType>::TYPE; \
167 struct AttributeName<Tag> \
169 static constexpr const char* name = Tag##_name; \
173#define DEFINE_FLOAT_ATTR( NAME, N ) DEFINE_ATTR( NAME, FloatAttribute, TYPE::FLOAT, #NAME, N )
175#define DEFINE_BOOLEAN_ATTR( NAME ) \
176 DEFINE_ATTR_SIMPLE( NAME, BooleanAttribute, TYPE::BOOLEAN, #NAME )
178#define DEFINE_TEXT_ATTR( NAME ) DEFINE_ATTR_SIMPLE( NAME, TextAttribute, TYPE::TEXT, #NAME )
180#define DEFINE_LIST_TEXT_ATTR( NAME ) DEFINE_ATTR_SIMPLE( NAME, ListTextAttribute, TYPE::TEXT, #NAME )
182#define DEFINE_INTEGER_ATTR( NAME ) DEFINE_ATTR_SIMPLE( NAME, IntegerAttribute, TYPE::INTEGER, #NAME )
184#define DEFINE_OPTION_ATTR( NAME ) \
189 struct AttributeSimple<NAME##_t, OPTION_Attribute, TYPE::OPTION>; \
191 struct AttributeName<NAME> \
193 static constexpr const char* name = #NAME; \
198#define USED_BY_FEATURE_ENTITY( NAME ) \
200 struct IsFeature<NAME> : std::true_type \
204#define USED_BY_NET_ENTITY( NAME ) \
206 struct IsNet<NAME> : std::true_type \
210#define USED_BY_PKG_ENTITY( NAME ) \
212 struct IsPkg<NAME> : std::true_type \
216#define USED_BY_CMP_ENTITY( NAME ) \
218 struct IsComp<NAME> : std::true_type \
276DEFINE_ATTR( post_machining_top_diameter, FloatAttribute,
TYPE::
FLOAT,
"post_machining_top_diameter", 3 )
278DEFINE_ATTR( post_machining_top_depth, FloatAttribute,
TYPE::
FLOAT,
"post_machining_top_depth", 3 )
280DEFINE_ATTR( post_machining_top_angle, FloatAttribute,
TYPE::
FLOAT,
"post_machining_top_angle", 1 )
282DEFINE_ATTR( post_machining_bottom_diameter, FloatAttribute,
TYPE::
FLOAT,
"post_machining_bottom_diameter", 3 )
284DEFINE_ATTR( post_machining_bottom_depth, FloatAttribute,
TYPE::
FLOAT,
"post_machining_bottom_depth", 3 )
286DEFINE_ATTR( post_machining_bottom_angle, FloatAttribute,
TYPE::
FLOAT,
"post_machining_bottom_angle", 1 )
369 template <
typename Tr,
typename Ta>
378 if constexpr( std::is_enum_v<Ta> )
379 r.m_ODBattributes.emplace(
id, std::to_string(
static_cast<int>( v ) ) );
384 template <
typename Tr,
typename Ta>
392 if constexpr( std::is_enum_v<Ta> )
393 r.m_ODBattributes.emplace(
id, std::to_string(
static_cast<int>( v ) ) );
401 void WriteAttributes( std::ostream& ost,
const std::string& prefix =
"" )
const;
408 template <
typename Ta>
411 if constexpr(
requires { v.value.empty(); } )
412 return v.value.empty();
418 size_t GetTextIndex( std::unordered_map<std::string, size_t>& aMap,
419 std::vector<std::pair<size_t, std::string>>& aVec,
420 const std::string& aText );
422 template <
typename T,
unsigned int n>
428 template <
typename T>
434 template <
typename T>
440 template <
typename T>
446 template <
typename T>
449 return std::to_string( a.
value );
void WriteAttributesText(std::ostream &ost, const std::string &prefix="") const
std::vector< std::pair< size_t, std::string > > m_attrTextVec
std::vector< std::pair< size_t, std::string > > m_attrNameVec
std::string AttrValue2String(ODB_ATTR::IntegerAttribute< T > a)
virtual ~ATTR_MANAGER()=default
std::string AttrValue2String(ODB_ATTR::ListTextAttribute< T > a)
size_t GetTextIndex(std::unordered_map< std::string, size_t > &aMap, std::vector< std::pair< size_t, std::string > > &aVec, const std::string &aText)
std::string AttrValue2String(ODB_ATTR::FloatAttribute< T, n > a)
void WriteAttributes(std::ostream &ost, const std::string &prefix="") const
size_t GetAttrTextNumber(const wxString &aName)
void AddUserDefAttribute(Tr &r, Ta v)
std::unordered_map< std::string, size_t > m_attrNames
static bool isEmptyText(const Ta &v)
An empty TEXT value is the attribute's default and has no legal text table entry.
size_t GetAttrNameNumber(const wxString &name)
std::string AttrValue2String(ODB_ATTR::BooleanAttribute< T > a)
std::string AttrValue2String(ODB_ATTR::TextAttribute< T > a)
void AddSystemAttribute(Tr &r, Ta v)
void WriteAttributesName(std::ostream &ost, const std::string &prefix="") const
std::unordered_map< std::string, size_t > m_attrTexts
void WriteAttributes(std::ostream &ost) const
virtual ~ATTR_RECORD_WRITER()=default
std::map< unsigned int, std::string > m_ODBattributes
ATTR_RECORD_WRITER()=default
static std::string ToStdString(const wxString &aStr)
wxString Double2String(const ODB_FORMAT &aFormat, double aVal)
#define DEFINE_OPTION_ATTR(NAME)
#define USED_BY_CMP_ENTITY(NAME)
#define DEFINE_FLOAT_ATTR(NAME, N)
#define DEFINE_BOOLEAN_ATTR(NAME)
#define DEFINE_INTEGER_ATTR(NAME)
#define DEFINE_ATTR(Tag, Attr, AttrType, AttrName,...)
#define DEFINE_LIST_TEXT_ATTR(NAME)
#define DEFINE_TEXT_ATTR(NAME)
#define USED_BY_FEATURE_ENTITY(NAME)
constexpr AttributeBase(T v)
static constexpr TYPE type
static constexpr unsigned int digits
constexpr TextAttribute(const std::string &t)