Remove templates on iterator and element

This commit is contained in:
Thomas Krijnen
2021-07-11 15:00:59 +02:00
parent ff73f82798
commit eeaf04c6ea
25 changed files with 203 additions and 293 deletions
@@ -70,7 +70,6 @@
namespace IfcGeom {
template <typename P = double, typename PP = P>
class Iterator {
private:
Iterator(const Iterator&); // N/I
@@ -80,7 +79,7 @@ namespace IfcGeom {
IfcGeom::IteratorSettings settings_;
std::vector<IfcGeom::filter_t> filters_;
IteratorImplementation<P, PP>* implementation_;
IteratorImplementation* implementation_;
public:
Iterator(const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file, int num_threads = 1)
@@ -88,20 +87,20 @@ namespace IfcGeom {
, settings_(settings)
{
try {
implementation_ = iterator_implementations<P, PP>().construct(file_->schema()->name(), settings, file, filters_, num_threads);
implementation_ = iterator_implementations().construct(file_->schema()->name(), settings, file, filters_, num_threads);
} catch (const std::exception& e) {
Logger::Error(e);
implementation_ = nullptr;
}
}
Iterator(const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file, const std::vector<IfcGeom::filter_t>& filters, size_t num_threads = 1)
Iterator(const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file, const std::vector<IfcGeom::filter_t>& filters, int num_threads = 1)
: file_(file)
, settings_(settings)
, filters_(filters)
{
try {
implementation_ = iterator_implementations<P, PP>().construct(file_->schema()->name(), settings, file, filters_, num_threads);
implementation_ = iterator_implementations().construct(file_->schema()->name(), settings, file, filters_, num_threads);
} catch (const std::exception& e) {
Logger::Error(e);
implementation_ = nullptr;
@@ -131,11 +130,11 @@ namespace IfcGeom {
IfcUtil::IfcBaseClass* next() const { return implementation_->next(); }
Element<P, PP>* get() { return implementation_->get(); }
Element* get() { return implementation_->get(); }
BRepElement<P, PP>* get_native() { return implementation_->get_native(); }
BRepElement* get_native() { return implementation_->get_native(); }
const Element<P, PP>* get_object(int id) { return implementation_->get_object(id); }
const Element* get_object(int id) { return implementation_->get_object(id); }
IfcUtil::IfcBaseClass* create() { return implementation_->create(); }
};
@@ -2,48 +2,36 @@
#include <boost/algorithm/string/case_conv.hpp>
template <typename P, typename PP>
IteratorFactoryImplementation<P, PP>& iterator_implementations() {
static IteratorFactoryImplementation<P, PP> impl;
IteratorFactoryImplementation& iterator_implementations() {
static IteratorFactoryImplementation impl;
return impl;
}
template IteratorFactoryImplementation<float, float>& iterator_implementations<float, float>();
template IteratorFactoryImplementation<float, double>& iterator_implementations<float, double>();
template IteratorFactoryImplementation<double, double>& iterator_implementations<double, double>();
#ifdef HAS_SCHEMA_2x3
template <typename P, typename PP>
extern void init_IteratorImplementation_Ifc2x3(IteratorFactoryImplementation<P, PP>*);
extern void init_IteratorImplementation_Ifc2x3(IteratorFactoryImplementation*);
#endif
#ifdef HAS_SCHEMA_4
template <typename P, typename PP>
extern void init_IteratorImplementation_Ifc4(IteratorFactoryImplementation<P, PP>*);
extern void init_IteratorImplementation_Ifc4(IteratorFactoryImplementation*);
#endif
#ifdef HAS_SCHEMA_4x1
template <typename P, typename PP>
extern void init_IteratorImplementation_Ifc4x1(IteratorFactoryImplementation<P, PP>*);
extern void init_IteratorImplementation_Ifc4x1(IteratorFactoryImplementation*);
#endif
#ifdef HAS_SCHEMA_4x2
template <typename P, typename PP>
extern void init_IteratorImplementation_Ifc4x2(IteratorFactoryImplementation<P, PP>*);
extern void init_IteratorImplementation_Ifc4x2(IteratorFactoryImplementation*);
#endif
#ifdef HAS_SCHEMA_4x3_rc1
template <typename P, typename PP>
extern void init_IteratorImplementation_Ifc4x3_rc1(IteratorFactoryImplementation<P, PP>*);
extern void init_IteratorImplementation_Ifc4x3_rc1(IteratorFactoryImplementation*);
#endif
#ifdef HAS_SCHEMA_4x3_rc2
template <typename P, typename PP>
extern void init_IteratorImplementation_Ifc4x3_rc2(IteratorFactoryImplementation<P, PP>*);
extern void init_IteratorImplementation_Ifc4x3_rc2(IteratorFactoryImplementation*);
#endif
template <typename P, typename PP>
IteratorFactoryImplementation<P, PP>::IteratorFactoryImplementation() {
IteratorFactoryImplementation::IteratorFactoryImplementation() {
#ifdef HAS_SCHEMA_2x3
init_IteratorImplementation_Ifc2x3(this);
#endif
@@ -64,24 +52,17 @@ IteratorFactoryImplementation<P, PP>::IteratorFactoryImplementation() {
#endif
}
template <typename P, typename PP>
void IteratorFactoryImplementation<P, PP>::bind(const std::string& schema_name, typename get_factory_type<P, PP>::type fn) {
void IteratorFactoryImplementation::bind(const std::string& schema_name, iterator_fn fn) {
const std::string schema_name_lower = boost::to_lower_copy(schema_name);
this->insert(std::make_pair(schema_name_lower, fn));
}
template <typename P, typename PP>
IfcGeom::IteratorImplementation<P, PP>* IteratorFactoryImplementation<P, PP>::construct(const std::string& schema_name, const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file, const std::vector<IfcGeom::filter_t>& filters, int num_threads) {
IfcGeom::IteratorImplementation* IteratorFactoryImplementation::construct(const std::string& schema_name, const IfcGeom::IteratorSettings& settings, IfcParse::IfcFile* file, const std::vector<IfcGeom::filter_t>& filters, int num_threads) {
const std::string schema_name_lower = boost::to_lower_copy(schema_name);
typename std::map<std::string, typename get_factory_type<P, PP>::type>::const_iterator it;
typename std::map<std::string, iterator_fn>::const_iterator it;
it = this->find(schema_name_lower);
if (it == this->end()) {
throw IfcParse::IfcException("No geometry iterator registered for " + schema_name);
}
return it->second(settings, file, filters, num_threads);
}
template class IteratorFactoryImplementation<float, float>;
template class IteratorFactoryImplementation<float, double>;
template class IteratorFactoryImplementation<double, double>;
@@ -13,52 +13,26 @@
#include <string>
namespace IfcGeom {
template <typename P, typename PP>
class IteratorImplementation;
template <typename P, typename PP>
class Element;
template <typename P, typename PP>
class BRepElement;
}
typedef boost::function4<IfcGeom::IteratorImplementation<float, float>*, const IfcGeom::IteratorSettings&, IfcParse::IfcFile*, const std::vector<IfcGeom::filter_t>&, int> iterator_float_float_fn;
typedef boost::function4<IfcGeom::IteratorImplementation<float, double>*, const IfcGeom::IteratorSettings&, IfcParse::IfcFile*, const std::vector<IfcGeom::filter_t>&, int> iterator_float_double_fn;
typedef boost::function4<IfcGeom::IteratorImplementation<double, double>*, const IfcGeom::IteratorSettings&, IfcParse::IfcFile*, const std::vector<IfcGeom::filter_t>&, int> iterator_double_double_fn;
typedef boost::function4<IfcGeom::IteratorImplementation*, const IfcGeom::IteratorSettings&, IfcParse::IfcFile*, const std::vector<IfcGeom::filter_t>&, int> iterator_fn;
template <typename P, typename PP>
struct get_factory_type {};
template <>
struct get_factory_type<float, float> {
typedef iterator_float_float_fn type;
};
template <>
struct get_factory_type<float, double> {
typedef iterator_float_double_fn type;
};
template <>
struct get_factory_type<double, double> {
typedef iterator_double_double_fn type;
};
template <typename P, typename PP>
class IteratorFactoryImplementation : public std::map<std::string, typename get_factory_type<P, PP>::type> {
class IteratorFactoryImplementation : public std::map<std::string, iterator_fn> {
public:
IteratorFactoryImplementation();
void bind(const std::string& schema_name, typename get_factory_type<P, PP>::type fn);
IfcGeom::IteratorImplementation<P, PP>* construct(const std::string& schema_name, const IfcGeom::IteratorSettings&, IfcParse::IfcFile*, const std::vector<IfcGeom::filter_t>&, int);
void bind(const std::string& schema_name, iterator_fn fn);
IfcGeom::IteratorImplementation* construct(const std::string& schema_name, const IfcGeom::IteratorSettings&, IfcParse::IfcFile*, const std::vector<IfcGeom::filter_t>&, int);
};
template <typename P, typename PP>
IteratorFactoryImplementation<P, PP>& iterator_implementations();
IteratorFactoryImplementation& iterator_implementations();
namespace IfcGeom {
template <typename P, typename PP>
class IteratorImplementation {
public:
virtual bool initialize() = 0;
@@ -70,9 +44,9 @@ namespace IfcGeom {
virtual double getUnitMagnitude() const = 0;
virtual IfcParse::IfcFile* file() const = 0;
virtual IfcUtil::IfcBaseClass* next() = 0;
virtual Element<P, PP>* get() = 0;
virtual BRepElement<P, PP>* get_native() = 0;
virtual const Element<P, PP>* get_object(int id) = 0;
virtual Element* get() = 0;
virtual BRepElement* get_native() = 0;
virtual const Element* get_object(int id) = 0;
virtual IfcUtil::IfcBaseClass* create() = 0;
};
+1 -2
View File
@@ -36,7 +36,6 @@
namespace IfcGeom {
template <typename P, typename PP>
class BRepElement;
class Kernel {
@@ -91,7 +90,7 @@ namespace IfcGeom {
return implementation_->getValue(var);
}
virtual BRepElement<double, double>* convert(
virtual BRepElement* convert(
const IteratorSettings& settings, IfcUtil::IfcBaseClass* representation,
IfcUtil::IfcBaseClass* product)
{