diff --git a/Core/Material/BaseMaterialImpl.h b/Core/Material/BaseMaterialImpl.h index e967546716b4014b76627986751fa1d98b993f66..959165cbb3ef12b00b5d1b1cf87f565ffa8d8097 100644 --- a/Core/Material/BaseMaterialImpl.h +++ b/Core/Material/BaseMaterialImpl.h @@ -24,6 +24,12 @@ class Transform3D; class WavevectorInfo; +enum class MATERIAL_TYPES { + VacuumMaterial = 0, + RefractiveCoefMaterial, + WavelengthIndependentMaterial +}; + //! @ingroup materials class BA_CORE_API_ BaseMaterialImpl : public INamed @@ -59,7 +65,7 @@ public: virtual complex_t materialData() const = 0; //! Returns type of material implementation - virtual size_t typeID() const = 0; + virtual MATERIAL_TYPES typeID() const = 0; //! Returns (\f$ \pi/\lambda^2 \f$ - sld), sld being the scattering length density virtual complex_t scalarSubtrSLD(const WavevectorInfo& wavevectors) const = 0; @@ -71,20 +77,6 @@ public: //! Prints object data virtual void print(std::ostream &ostr) const = 0; - - template <class T> static size_t g_typeID(); - -protected: - enum MATERIAL_TYPES : size_t { - VacuumMaterial = 0, - RefractiveCoefMaterial, - WavelengthIndependentMaterial - }; }; -template<class T> -size_t BaseMaterialImpl::g_typeID() { - return T::g_typeID(); -} - #endif /* IMATERIALIMPL_H_ */ diff --git a/Core/Material/Material.cpp b/Core/Material/Material.cpp index 8da8ababe139d376e52a69afb6c18807d13f753a..848f2a08104e1663713cfa6bbf05fd82d34cc5b7 100644 --- a/Core/Material/Material.cpp +++ b/Core/Material/Material.cpp @@ -54,7 +54,7 @@ std::string Material::getName() const return m_material_impl->getName(); } -size_t Material::typeID() const +MATERIAL_TYPES Material::typeID() const { return m_material_impl->typeID(); } diff --git a/Core/Material/Material.h b/Core/Material/Material.h index f38b46ebbda7e39083bf9ddd965a509d305280e9..9c0a021d3ccaef04522654e321769c469dbf183b 100644 --- a/Core/Material/Material.h +++ b/Core/Material/Material.h @@ -67,8 +67,10 @@ public: //! Returns the name of material std::string getName() const; +#ifndef SWIG //! Returns the type of underlying material implementation - size_t typeID() const; + MATERIAL_TYPES typeID() const; +#endif //SWIG //! Get the magnetization (in A/m) kvector_t magnetization() const; @@ -92,17 +94,10 @@ public: friend BA_CORE_API_ std::ostream& operator<<( std::ostream& ostr, const Material& mat); - template <class T> static size_t g_typeID(); - private: std::unique_ptr<BaseMaterialImpl> m_material_impl; }; -template <class T> size_t Material::g_typeID() -{ - return BaseMaterialImpl::g_typeID<T>(); -} - //! Comparison operator for material wrapper (equality check) BA_CORE_API_ bool operator==(const Material& left, const Material& right); diff --git a/Core/Material/RefractiveCoefMaterial.h b/Core/Material/RefractiveCoefMaterial.h index f7ee055396567efcbe2d4ddebb9532ef0ec593b1..3611d948b1b166669213ba80f9c13d84a9abd9d8 100644 --- a/Core/Material/RefractiveCoefMaterial.h +++ b/Core/Material/RefractiveCoefMaterial.h @@ -47,9 +47,9 @@ public: virtual complex_t materialData() const override; //! Returns type of material implementation - virtual size_t typeID() const override + virtual MATERIAL_TYPES typeID() const override { - return g_typeID(); + return MATERIAL_TYPES::RefractiveCoefMaterial; } //! Returns (\f$ \pi/\lambda^2 \f$ - sld), sld (in \f$nm^{-2}\f$) being the scattering length density. @@ -61,11 +61,6 @@ public: //! Prints object data virtual void print(std::ostream &ostr) const override; - static size_t g_typeID() - { - return MATERIAL_TYPES::RefractiveCoefMaterial; - } - private: RefractiveCoefMaterial(const std::string& name, double delta, double beta, kvector_t magnetization); diff --git a/Core/Material/WavelengthIndependentMaterial.h b/Core/Material/WavelengthIndependentMaterial.h index b364bb1d8f37e493dbe4ee549f3496de558990bc..2192718a17bd9050852df97bb6e09ba6af316456 100644 --- a/Core/Material/WavelengthIndependentMaterial.h +++ b/Core/Material/WavelengthIndependentMaterial.h @@ -44,9 +44,9 @@ public: virtual complex_t materialData() const override; //! Returns type of material implementation - virtual size_t typeID() const override + virtual MATERIAL_TYPES typeID() const override { - return g_typeID(); + return MATERIAL_TYPES::WavelengthIndependentMaterial; } //! Returns (\f$ \pi/\lambda^2 \f$ - sld), sld (in \f$nm^{-2}\f$) being the scattering length density @@ -55,11 +55,6 @@ public: //! Prints object data virtual void print(std::ostream &ostr) const override; - static size_t g_typeID() - { - return MATERIAL_TYPES::WavelengthIndependentMaterial; - } - private: WavelengthIndependentMaterial(const std::string& name, double sld, double abs_term, kvector_t magnetization); diff --git a/Tests/UnitTests/Core/Other/MaterialTest.h b/Tests/UnitTests/Core/Other/MaterialTest.h index f47605fdc54c51ea27c5d5ad75b45e120e0c7e89..d7fc1fd16f3eca0ee8fade5f62b1225f2ac6bf57 100644 --- a/Tests/UnitTests/Core/Other/MaterialTest.h +++ b/Tests/UnitTests/Core/Other/MaterialTest.h @@ -144,8 +144,8 @@ TEST_F(MaterialTest, TypeIdsTest) { Material material = MaterialBySLD("Material", 1.0, 1.0); Material material2 = HomogeneousMaterial("Material", 1.0, 1.0); - EXPECT_TRUE(material.typeID() == Material::g_typeID<WavelengthIndependentMaterial>()); - EXPECT_TRUE(material2.typeID() == Material::g_typeID<RefractiveCoefMaterial>()); + EXPECT_TRUE(material.typeID() == MATERIAL_TYPES::WavelengthIndependentMaterial); + EXPECT_TRUE(material2.typeID() == MATERIAL_TYPES::RefractiveCoefMaterial); EXPECT_TRUE(material.typeID() != material2.typeID()); Material material3 = MaterialBySLD("Material", 1.0, 1.0); EXPECT_TRUE(material.typeID() == material3.typeID());