Skip to content

Commit e920379

Browse files
committed
SFINAE for BaseClass*
1 parent 4011666 commit e920379

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/ifcparse/IfcBaseClass.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,19 @@ class IFC_PARSE_API IfcBaseClass : public virtual IfcBaseInterface {
105105
virtual const IfcParse::declaration& declaration() const = 0;
106106

107107
template <typename T>
108-
void set_attribute_value(size_t i, const T& t);
108+
typename std::enable_if<
109+
(!(std::is_pointer<T>::value && std::is_base_of<IfcUtil::IfcBaseClass, typename std::remove_pointer<T>::type>::value) || std::is_same_v<IfcUtil::IfcBaseClass, std::remove_pointer_t<T>>),
110+
void>::type
111+
set_attribute_value(size_t i, const T& t);
109112

110113
template <typename T>
111-
void set_attribute_value(const std::string& name, const T& t);
114+
typename std::enable_if<
115+
(!(std::is_pointer<T>::value&& std::is_base_of<IfcUtil::IfcBaseClass, typename std::remove_pointer<T>::type>::value) || std::is_same_v<IfcUtil::IfcBaseClass, std::remove_pointer_t<T>>),
116+
void>::type
117+
set_attribute_value(const std::string& name, const T& t);
118+
119+
void set_attribute_value(size_t i, IfcUtil::IfcBaseClass* p);
120+
void set_attribute_value(const std::string& name, IfcUtil::IfcBaseClass* p);
112121

113122
void unset_attribute_value(size_t i);
114123

src/ifcparse/IfcParse.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,10 @@ class apply_individual_instance_visitor {
12331233
};
12341234

12351235
template <typename T>
1236-
void IfcUtil::IfcBaseClass::set_attribute_value(size_t i, const T& t) {
1236+
typename std::enable_if<
1237+
(!(std::is_pointer<T>::value&& std::is_base_of<IfcUtil::IfcBaseClass, typename std::remove_pointer<T>::type>::value) || std::is_same_v<IfcUtil::IfcBaseClass, std::remove_pointer_t<T>>),
1238+
void>::type
1239+
IfcUtil::IfcBaseClass::set_attribute_value(size_t i, const T& t) {
12371240
if constexpr (std::is_same_v<std::decay_t<T>, double>) {
12381241
if (!std::isfinite(t)) {
12391242
throw IfcParse::IfcException("Only finite values are allowed");
@@ -1314,7 +1317,10 @@ void IfcUtil::IfcBaseClass::set_attribute_value(size_t i, const T& t) {
13141317
}
13151318

13161319
template <typename T>
1317-
void IfcUtil::IfcBaseClass::set_attribute_value(const std::string& s, const T& t) {
1320+
typename std::enable_if<
1321+
(!(std::is_pointer<T>::value&& std::is_base_of<IfcUtil::IfcBaseClass, typename std::remove_pointer<T>::type>::value) || std::is_same_v<IfcUtil::IfcBaseClass, std::remove_pointer_t<T>>),
1322+
void>::type
1323+
IfcUtil::IfcBaseClass::set_attribute_value(const std::string& s, const T& t) {
13181324
set_attribute_value(declaration().as_entity()->attribute_index(s), t);
13191325
}
13201326

@@ -2738,6 +2744,12 @@ IfcUtil::IfcBaseClass::IfcBaseClass(IfcEntityInstanceData&& data)
27382744
*/
27392745
}
27402746

2747+
void IfcUtil::IfcBaseClass::set_attribute_value(size_t i, IfcUtil::IfcBaseClass* p) {
2748+
set_attribute_value<IfcUtil::IfcBaseClass*>(i, p);
2749+
}
2750+
void IfcUtil::IfcBaseClass::set_attribute_value(const std::string& name, IfcUtil::IfcBaseClass* p) {
2751+
set_attribute_value<IfcUtil::IfcBaseClass*>(name, p);
2752+
}
27412753

27422754
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<Blank>(size_t index, const Blank& value);
27432755
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<Derived>(size_t index, const Derived& value);
@@ -2748,7 +2760,7 @@ template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<double>(s
27482760
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<std::string>(size_t index, const std::string& value);
27492761
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<boost::dynamic_bitset<>>(size_t index, const boost::dynamic_bitset<>& value);
27502762
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<EnumerationReference>(size_t index, const EnumerationReference& value);
2751-
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<IfcUtil::IfcBaseClass*>(size_t index, IfcUtil::IfcBaseClass* const& value);
2763+
// template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<IfcUtil::IfcBaseClass*>(size_t index, IfcUtil::IfcBaseClass* const& value);
27522764
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<std::vector<int>>(size_t index, const std::vector<int>& value);
27532765
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<std::vector<double>>(size_t index, const std::vector<double>& value);
27542766
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<std::vector<std::string>>(size_t index, const std::vector<std::string>& value);
@@ -2767,7 +2779,7 @@ template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<double>(c
27672779
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<std::string>(const std::string& name, const std::string& value);
27682780
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<boost::dynamic_bitset<>>(const std::string& name, const boost::dynamic_bitset<>& value);
27692781
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<EnumerationReference>(const std::string& name, const EnumerationReference& value);
2770-
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<IfcUtil::IfcBaseClass*>(const std::string& name, IfcUtil::IfcBaseClass* const& value);
2782+
// template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<IfcUtil::IfcBaseClass*>(const std::string& name, IfcUtil::IfcBaseClass* const& value);
27712783
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<std::vector<int>>(const std::string& name, const std::vector<int>& value);
27722784
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<std::vector<double>>(const std::string& name, const std::vector<double>& value);
27732785
template void IFC_PARSE_API IfcUtil::IfcBaseClass::set_attribute_value<std::vector<std::string>>(const std::string& name, const std::vector<std::string>& value);

0 commit comments

Comments
 (0)