mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-14 02:07:54 -06:00

Type handling is mainly done using templates. Template Slic3r::ClassTraits is used to store info about exported types (perl class name). Currently only perl class name and refference name is used. Template values are initialized by REGISTER_CLASS macro. This macro is used in .cpp file of class ( it needs to be used exactly for each type). Ref<type> class is used to return value as perl reference. Operator overloading is used to make c++ and XSpp happy, only pointer value should be possible to return. Clone<type> class is used to return copy of value ( using new and copy constructor). Copy is created on assigment, this should be probably improved (memory leak on multiple assignments). It is overloaded to be able to return type, type* and type&. Typechecking in ExtrusionEntityCollection updated to check all passed types.
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#ifndef slic3r_perlglue_hpp_
|
|
#define slic3r_perlglue_hpp_
|
|
|
|
namespace Slic3r {
|
|
|
|
template<class T>
|
|
struct ClassTraits {
|
|
static const char* name;
|
|
static const char* name_ref;
|
|
};
|
|
|
|
#define REGISTER_CLASS(cname,perlname) \
|
|
class cname; \
|
|
template <>const char* ClassTraits<cname>::name = "Slic3r::" perlname; \
|
|
template <>const char* ClassTraits<cname>::name_ref = "Slic3r::" perlname "::Ref";
|
|
|
|
template<class T>
|
|
const char* perl_class_name(const T*) { return ClassTraits<T>::name; }
|
|
template<class T>
|
|
const char* perl_class_name_ref(const T*) { return ClassTraits<T>::name_ref; }
|
|
|
|
template <class T>
|
|
class Ref {
|
|
T* val;
|
|
public:
|
|
Ref() {}
|
|
Ref(T* t) : val(t) {}
|
|
operator T*() const {return val; }
|
|
static const char* CLASS() { return ClassTraits<T>::name_ref; }
|
|
};
|
|
|
|
template <class T>
|
|
class Clone {
|
|
T* val;
|
|
public:
|
|
Clone() {}
|
|
Clone(T* t) : val(new T(*t)) {}
|
|
Clone(const T& t) : val(new T(t)) {}
|
|
operator T*() const {return val; }
|
|
static const char* CLASS() { return ClassTraits<T>::name; }
|
|
};
|
|
};
|
|
|
|
#endif
|