diff --git a/Base/Math/IntegratorMCMiser.h b/Base/Math/IntegratorMCMiser.h index f6eb912dbc4a5be44a661a49ae77db2e8ee1dced..e2f7fa3b1e75ad39fb5d7abce3720b6b1021433d 100644 --- a/Base/Math/IntegratorMCMiser.h +++ b/Base/Math/IntegratorMCMiser.h @@ -22,7 +22,8 @@ #include <memory> //! Alias template for member function with signature double f(double) -template <class T> using miser_integrand = double (T::*)(const double*, size_t, const void*) const; +template <typename T> +using miser_integrand = double (T::*)(const double*, size_t, const void*) const; //! Template class to use Monte Carlo MISER integration of class member functions. //! @@ -33,7 +34,7 @@ template <class T> using miser_integrand = double (T::*)(const double*, size_t, //! 'auto integrator = make_integrator_miser(this, mem_function, dimension)' //! - Call: 'integrator.integrate(lmin, lmax, data, n_points)' -template <class T> class IntegratorMCMiser { +template <typename T> class IntegratorMCMiser { public: //! structure holding the object and possible extra parameters struct CallBackHolder { @@ -67,11 +68,11 @@ private: }; //! Alias template for handle to a miser integrator -template <class T> using P_integrator_miser = std::unique_ptr<IntegratorMCMiser<T>>; +template <typename T> using P_integrator_miser = std::unique_ptr<IntegratorMCMiser<T>>; //! Template function to create an integrator object -template <class T> +template <typename T> P_integrator_miser<T> make_integrator_miser(const T* object, miser_integrand<T> mem_function, size_t dim) { @@ -83,7 +84,7 @@ P_integrator_miser<T> make_integrator_miser(const T* object, miser_integrand<T> // Implementation // ************************************************************************************************ -template <class T> +template <typename T> IntegratorMCMiser<T>::IntegratorMCMiser(const T* p_object, miser_integrand<T> p_member_function, size_t dim) : m_object(p_object) @@ -99,13 +100,13 @@ IntegratorMCMiser<T>::IntegratorMCMiser(const T* p_object, miser_integrand<T> p_ m_random_gen = gsl_rng_alloc(random_type); } -template <class T> IntegratorMCMiser<T>::~IntegratorMCMiser() +template <typename T> IntegratorMCMiser<T>::~IntegratorMCMiser() { gsl_monte_miser_free(m_gsl_workspace); gsl_rng_free(m_random_gen); } -template <class T> +template <typename T> double IntegratorMCMiser<T>::integrate(double* min_array, double* max_array, const void* params, size_t n_points) const { diff --git a/Base/Type/CloneableVector.h b/Base/Type/CloneableVector.h index 07716a65a37d90790f690ba754606c2a4ae69009..19ae1f0a896ef44ca9bc789b8def165d2b81f391 100644 --- a/Base/Type/CloneableVector.h +++ b/Base/Type/CloneableVector.h @@ -28,7 +28,7 @@ //! If the copy constructor or the copy assignment operator is used, //! then there must be a function T::clone(). -template <class T> class CloneableVector : public OwningVector<T> { +template <typename T> class CloneableVector : public OwningVector<T> { public: CloneableVector() = default; //! Constructor that takes over ownership of elements in given vector diff --git a/Base/Type/OwningVector.h b/Base/Type/OwningVector.h index 4d5590d1cd480097c8ceffa46d3257c4e05c515d..24d7f5ec72c59121c30d688b568bc247cd4efe8b 100644 --- a/Base/Type/OwningVector.h +++ b/Base/Type/OwningVector.h @@ -27,7 +27,7 @@ //! //! Cannot be copied. For a copyable vector of cloneable objects, use CloneableVector. -template <class T> class OwningVector { +template <typename T> class OwningVector { public: OwningVector() = default; //! Constructor that takes over ownership of elements in given vector diff --git a/Base/Type/VectorWC.h b/Base/Type/VectorWC.h index acb1b7bd2be6e5b8cd5af318f05ac3262523fe24..492f46fcf0b98529be57ccbae99880d62e79e13a 100644 --- a/Base/Type/VectorWC.h +++ b/Base/Type/VectorWC.h @@ -23,7 +23,7 @@ //! An OwningVector with a current index. -template <class T> class VectorWC : public OwningVector<T> { +template <typename T> class VectorWC : public OwningVector<T> { using super = OwningVector<T>; public: diff --git a/Base/Util/Vec.h b/Base/Util/Vec.h index 4e408dacbcfd924c7c3a3d86ed49819f34b38d3b..3c29800467588145da5d490f535a098952e91a7b 100644 --- a/Base/Util/Vec.h +++ b/Base/Util/Vec.h @@ -19,7 +19,7 @@ namespace Vec { -template <class T, class S> int indexOfPtr(const T* t, const std::vector<S*>& v) +template <typename T, class S> int indexOfPtr(const T* t, const std::vector<S*>& v) { for (size_t i = 0; i < v.size(); i++) if (v[i] == t) @@ -27,7 +27,7 @@ template <class T, class S> int indexOfPtr(const T* t, const std::vector<S*>& v) return -1; } -template <class T, class S> bool containsPtr(const T* t, const std::vector<S*>& v) +template <typename T, class S> bool containsPtr(const T* t, const std::vector<S*>& v) { for (size_t i = 0; i < v.size(); i++) if (v[i] == t) @@ -35,12 +35,12 @@ template <class T, class S> bool containsPtr(const T* t, const std::vector<S*>& return false; } -template <class C> void concat(std::vector<C>& v, const std::vector<C>& w) +template <typename C> void concat(std::vector<C>& v, const std::vector<C>& w) { v.insert(v.end(), w.begin(), w.end()); } -template <class C> std::vector<C> flatten(const std::vector<std::vector<C>>& src) +template <typename C> std::vector<C> flatten(const std::vector<std::vector<C>>& src) { std::vector<C> result; for (const auto& row : src) @@ -48,7 +48,8 @@ template <class C> std::vector<C> flatten(const std::vector<std::vector<C>>& src return result; } -template <class C> std::vector<std::vector<C>> reshapeTo2D(const std::vector<C>& src, size_t n_rows) +template <typename C> +std::vector<std::vector<C>> reshapeTo2D(const std::vector<C>& src, size_t n_rows) { size_t n_cols = src.size() / n_rows; std::vector<std::vector<C>> result(n_rows); diff --git a/Fit/Adapter/MinimizerAdapter.h b/Fit/Adapter/MinimizerAdapter.h index caac59b431eeeea04fe756742851ab56d9ae2560..de8cfcae584129a86c9effc68fb4ae0da112297b 100644 --- a/Fit/Adapter/MinimizerAdapter.h +++ b/Fit/Adapter/MinimizerAdapter.h @@ -89,13 +89,13 @@ protected: virtual const root_minimizer_t* rootMinimizer() const = 0; root_minimizer_t* rootMinimizer(); - template <class T> + template <typename T> OptionContainer::option_t addOption(const std::string& optionName, T value, const std::string& description = ""); - template <class T> void setOptionValue(const std::string& optionName, T value); + template <typename T> void setOptionValue(const std::string& optionName, T value); - template <class T> T optionValue(const std::string& optionName) const; + template <typename T> T optionValue(const std::string& optionName) const; private: MinimizerOptions m_options; @@ -104,19 +104,19 @@ private: bool m_status; }; -template <class T> +template <typename T> OptionContainer::option_t MinimizerAdapter::addOption(const std::string& optionName, T value, const std::string& description) { return m_options.addOption(optionName, value, description); } -template <class T> void MinimizerAdapter::setOptionValue(const std::string& optionName, T value) +template <typename T> void MinimizerAdapter::setOptionValue(const std::string& optionName, T value) { m_options.setOptionValue(optionName, value); } -template <class T> T MinimizerAdapter::optionValue(const std::string& optionName) const +template <typename T> T MinimizerAdapter::optionValue(const std::string& optionName) const { return m_options.optionValue<T>(optionName); } diff --git a/Fit/Option/OptionContainer.h b/Fit/Option/OptionContainer.h index 9f773d6d57aa22f30d2815b3089250264e69dc6f..a54428459af65d874fb65255a29454a65c5f4eee 100644 --- a/Fit/Option/OptionContainer.h +++ b/Fit/Option/OptionContainer.h @@ -37,16 +37,16 @@ public: OptionContainer(const OptionContainer& other); OptionContainer& operator=(const OptionContainer& other); - template <class T> + template <typename T> option_t addOption(const std::string& optionName, T value, const std::string& description = ""); option_t option(const std::string& optionName); option_t option(const std::string& optionName) const; - template <class T> T optionValue(const std::string& optionName) const; + template <typename T> T optionValue(const std::string& optionName) const; //! Sets the value of option. Option should hold same value type already. - template <class T> void setOptionValue(const std::string& optionName, T value); + template <typename T> void setOptionValue(const std::string& optionName, T value); iterator begin() { return m_options.begin(); } const_iterator begin() const { return m_options.begin(); } @@ -63,7 +63,7 @@ protected: container_t m_options; }; -template <class T> +template <typename T> OptionContainer::option_t OptionContainer::addOption(const std::string& optionName, T value, const std::string& description) { @@ -76,12 +76,12 @@ OptionContainer::option_t OptionContainer::addOption(const std::string& optionNa return result; } -template <class T> T OptionContainer::optionValue(const std::string& optionName) const +template <typename T> T OptionContainer::optionValue(const std::string& optionName) const { return option(optionName)->get<T>(); } -template <class T> void OptionContainer::setOptionValue(const std::string& optionName, T value) +template <typename T> void OptionContainer::setOptionValue(const std::string& optionName, T value) { option(optionName)->value() = value; if (option(optionName)->value().index() != option(optionName)->defaultValue().index()) diff --git a/GUI/Model/Beam/DistributionCatalog.h b/GUI/Model/Beam/DistributionCatalog.h index e9ff125eab1e18ed4ec919e44710b839c2bc15f2..ff3f426703f689a8996be53aa5b40c484961d1d3 100644 --- a/GUI/Model/Beam/DistributionCatalog.h +++ b/GUI/Model/Beam/DistributionCatalog.h @@ -22,7 +22,7 @@ class DistributionItem; class DistributionCatalog { public: - using BaseItem = DistributionItem; // used in PolyItem<Catalog> + using BaseItem = DistributionItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { diff --git a/GUI/Model/Beam/FootprintCatalog.h b/GUI/Model/Beam/FootprintCatalog.h index 2afd280824ac386e75a00f174a15738839fba9e2..2ec424abb3594662bb4986e74f67637bb83189dd 100644 --- a/GUI/Model/Beam/FootprintCatalog.h +++ b/GUI/Model/Beam/FootprintCatalog.h @@ -22,7 +22,7 @@ class FootprintItem; class FootprintCatalog { public: - using BaseItem = FootprintItem; // used in PolyItem<Catalog> + using BaseItem = FootprintItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { None = 0, Gaussian = 1, Square = 2 }; diff --git a/GUI/Model/Beam/SourceItems.cpp b/GUI/Model/Beam/SourceItems.cpp index 68871604d46a554d0a82a355d052697592aaee3c..0682bd726e94ceea630f0f6bb4c340ce4930bd00 100644 --- a/GUI/Model/Beam/SourceItems.cpp +++ b/GUI/Model/Beam/SourceItems.cpp @@ -72,7 +72,10 @@ SourceItem::SourceItem() RealLimits::limited(0.0, 1e32), "intensity"); m_azimuthal_angle_item = std::make_unique<BeamDistributionItem>(Units::deg); - m_footprint.simpleInit("Type", "Footprint type", FootprintCatalog::Type::Gaussian); + m_footprint.simpleInit( + "Footprint type", + "Model for surface area where scattering takes place (\"beam footprint\")", + FootprintCatalog::Type::Gaussian); } void SourceItem::writeTo(QXmlStreamWriter* w) const diff --git a/GUI/Model/Descriptor/PolyItem.h b/GUI/Model/Descriptor/PolyItem.h index 5ce1d6d034055357179b0260c4b56eb9012652de..b1e56356c6ed5670e5b5d03c607fb7403229ad0b 100644 --- a/GUI/Model/Descriptor/PolyItem.h +++ b/GUI/Model/Descriptor/PolyItem.h @@ -26,7 +26,6 @@ public: void simpleInit(const QString& label, const QString& tooltip, typename Catalog::Type currentType); - BaseItem* operator->() const { return m_item.get(); } BaseItem* certainItem() const { return m_item.get(); } void setCertainItem(BaseItem* t) { m_item.reset(t); } @@ -44,24 +43,19 @@ public: m_item.reset(XML::readItemFrom<Catalog>(r, args...)); } - QString label() const { return m_label; } - QString tooltip() const { return m_tooltip; } - QStringList options() const { return m_options; } + QString piLabel() const { return m_label; } + QString piTooltip() const { return m_tooltip; } + QStringList menuEntries() const { return m_menu_entries; } - void setCurrentIndex(int newIndex) { currentIndexSetter(newIndex); } + void setCurrentIndex(int index) { m_item.reset(Catalog::create(m_types[index])); } int currentIndex() const { return m_types.indexOf(Catalog::type(m_item.get())); } private: - void initFieldsAndSetter(const QString& label, const QString& tooltip); - - //! Reimplementable function to set currently selected option. - std::function<void(int)> currentIndexSetter = nullptr; - std::unique_ptr<BaseItem> m_item; //!< Current selection - QString m_label; //!< A label text (short, no trailing colon) - QString m_tooltip; //!< Tooltip text - QStringList m_options; //!< List of options, usually presented as combo entries + QString m_label; //!< A label text (short, no trailing colon) + QString m_tooltip; //!< Tooltip text + QStringList m_menu_entries; //!< List of options, usually presented as combo entries QVector<typename Catalog::Type> m_types = Catalog::types(); }; @@ -74,7 +68,13 @@ template <typename C> void PolyItem<C>::simpleInit(const QString& label, const QString& tooltip, typename C::Type currentType) { - initFieldsAndSetter(label, tooltip); + m_label = label; + m_tooltip = tooltip; + + m_menu_entries.clear(); + for (const auto type : m_types) + m_menu_entries << C::uiInfo(type).menuEntry; + int index = C::types().indexOf(currentType); setCurrentIndex(index); } @@ -87,19 +87,4 @@ template <typename C> template <typename S> S* PolyItem<C>::createCertainItem() return t; } -template <typename C> -void PolyItem<C>::initFieldsAndSetter(const QString& label, const QString& tooltip) -{ - m_label = label; - m_tooltip = tooltip; - m_options.clear(); - for (const auto type : m_types) - m_options << C::uiInfo(type).menuEntry; - - currentIndexSetter = [this](int current) { - BaseItem* t = C::create(m_types[current]); - m_item.reset(t); - }; -} - #endif // BORNAGAIN_GUI_MODEL_DESCRIPTOR_POLYITEM_H diff --git a/GUI/Model/Detector/DetectorItem.cpp b/GUI/Model/Detector/DetectorItem.cpp index dce47cc318ca229cf6cee2cf7683e7c9614ec3f1..4bf62db56c117f915570aee2672d8c22f5d17d50 100644 --- a/GUI/Model/Detector/DetectorItem.cpp +++ b/GUI/Model/Detector/DetectorItem.cpp @@ -83,7 +83,7 @@ void DetectorItem::setMasks(MasksSet* item) std::unique_ptr<IResolutionFunction2D> DetectorItem::createResolutionFunction() const { - return m_resolution_function->createResolutionFunction(); + return m_resolution_function.certainItem()->createResolutionFunction(); } void DetectorItem::writeTo(QXmlStreamWriter* w) const diff --git a/GUI/Model/Detector/ResolutionFunctionCatalog.h b/GUI/Model/Detector/ResolutionFunctionCatalog.h index b8dade0c9df0ff89bfa6fb7337bc1dd1ed607cfa..77a37eea84fc6675c8c2a6ca23589c47aafbbaf9 100644 --- a/GUI/Model/Detector/ResolutionFunctionCatalog.h +++ b/GUI/Model/Detector/ResolutionFunctionCatalog.h @@ -22,7 +22,7 @@ class ResolutionFunctionItem; class ResolutionFunctionCatalog { public: - using BaseItem = ResolutionFunctionItem; // used in PolyItem<Catalog> + using BaseItem = ResolutionFunctionItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { None = 0, Gaussian = 1 }; diff --git a/GUI/Model/FromCore/ItemizeSample.cpp b/GUI/Model/FromCore/ItemizeSample.cpp index 23a06deeb6ecf08ab889486827c4b5ba45f1f94a..ae5d1ce37be6a91368062b4e618d9558fcc04fa0 100644 --- a/GUI/Model/FromCore/ItemizeSample.cpp +++ b/GUI/Model/FromCore/ItemizeSample.cpp @@ -74,7 +74,7 @@ void set_PDF1D(InterferenceRadialParacrystalItem* parent, const IProfile1D* ipdf // note: SetterPDF(1|2)Type are needed because template template parameter must be classes -template <class T> struct SetterPDF1Type { +template <typename T> struct SetterPDF1Type { T* operator()(Interference2DParacrystalItem* parent) { auto* p = new T; @@ -83,7 +83,7 @@ template <class T> struct SetterPDF1Type { } }; -template <class T> struct SetterPDF2Type { +template <typename T> struct SetterPDF2Type { T* operator()(Interference2DParacrystalItem* parent) { auto* p = new T; @@ -92,7 +92,7 @@ template <class T> struct SetterPDF2Type { } }; -template <template <class T> class U> +template <template <typename T> class U> void set_PDF2D(Interference2DParacrystalItem* parent, const IProfile2D* pdf) { if (const auto* pdf_cauchy = dynamic_cast<const Profile2DCauchy*>(pdf)) { diff --git a/GUI/Model/Mask/MaskCatalog.h b/GUI/Model/Mask/MaskCatalog.h index f2b51d6e715ee450ce6a2310857797d65fb55175..05eb73bef71c201a95bfa067b1739fd46648754c 100644 --- a/GUI/Model/Mask/MaskCatalog.h +++ b/GUI/Model/Mask/MaskCatalog.h @@ -22,7 +22,7 @@ class MaskItem; class MaskCatalog { public: - using BaseItem = MaskItem; // used in PolyItem<Catalog> + using BaseItem = MaskItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { diff --git a/GUI/Model/Sample/FormfactorCatalog.h b/GUI/Model/Sample/FormfactorCatalog.h index f13299de5410ed2273e264f184310e334f11b674..5b90758fd9ba09d557e1439e78d9e45f34964f5b 100644 --- a/GUI/Model/Sample/FormfactorCatalog.h +++ b/GUI/Model/Sample/FormfactorCatalog.h @@ -22,7 +22,7 @@ class FormfactorItem; class FormfactorCatalog { public: - using BaseItem = FormfactorItem; // used in PolyItem<Catalog> + using BaseItem = FormfactorItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { diff --git a/GUI/Model/Sample/InterferenceCatalog.h b/GUI/Model/Sample/InterferenceCatalog.h index 4acd7a7ac832103cf3889a730f1a0036d3e64360..cda030d479503fa16c37dce15a6162735c2802f6 100644 --- a/GUI/Model/Sample/InterferenceCatalog.h +++ b/GUI/Model/Sample/InterferenceCatalog.h @@ -22,7 +22,7 @@ class InterferenceItem; class InterferenceCatalog { public: - using BaseItem = InterferenceItem; // used in PolyItem<Catalog> + using BaseItem = InterferenceItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { diff --git a/GUI/Model/Sample/InterferenceItems.cpp b/GUI/Model/Sample/InterferenceItems.cpp index 10a7b7431e02c9770303538781ab87d325093b6d..c618bfa86e3b73faf6f913635caab7275800d624 100644 --- a/GUI/Model/Sample/InterferenceItems.cpp +++ b/GUI/Model/Sample/InterferenceItems.cpp @@ -83,7 +83,7 @@ std::unique_ptr<IInterference> Interference1DLatticeItem::createInterference() c { auto result = std::make_unique<Interference1DLattice>(m_length.dVal(), Units::deg2rad(m_rotation_angle.dVal())); - result->setDecayFunction(*m_decay_function->createProfile()); + result->setDecayFunction(*m_decay_function.certainItem()->createProfile()); result->setPositionVariance(m_position_variance.dVal()); return std::unique_ptr<IInterference>(result.release()); } @@ -164,7 +164,7 @@ std::unique_ptr<IInterference> Interference2DLatticeItem::createInterference() c std::unique_ptr<Interference2DLattice> result( new Interference2DLattice(*latticeItem->createLattice())); - result->setDecayFunction(*m_decay_function->createProfile()); + result->setDecayFunction(*m_decay_function.certainItem()->createProfile()); result->setIntegrationOverXi(xiIntegration()); result->setPositionVariance(m_position_variance.dVal()); @@ -219,7 +219,8 @@ std::unique_ptr<IInterference> Interference2DParacrystalItem::createInterference result->setDampingLength(m_damping_length.dVal()); result->setDomainSizes(m_domain_size1.dVal(), m_domain_size2.dVal()); result->setIntegrationOverXi(xiIntegration()); - result->setProbabilityDistributions(*m_pdf1->createProfile(), *m_pdf2->createProfile()); + result->setProbabilityDistributions(*m_pdf1.certainItem()->createProfile(), + *m_pdf2.certainItem()->createProfile()); result->setPositionVariance(m_position_variance.dVal()); return std::unique_ptr<IInterference>(result.release()); } @@ -369,7 +370,7 @@ std::unique_ptr<IInterference> InterferenceRadialParacrystalItem::createInterfer m_damping_length.dVal()); result->setDomainSize(m_domain_size.dVal()); result->setKappa(m_kappa.dVal()); - auto pdf = m_pdf->createProfile(); + auto pdf = m_pdf.certainItem()->createProfile(); result->setProbabilityDistribution(*pdf); result->setPositionVariance(m_position_variance.dVal()); return std::unique_ptr<IInterference>(result.release()); diff --git a/GUI/Model/Sample/ItemWithParticles.cpp b/GUI/Model/Sample/ItemWithParticles.cpp index 0ef665e3f02d6a4b2698cf7593e0959aa3441d06..e97abcb6b0a622a4943acf1285949841dfa710a5 100644 --- a/GUI/Model/Sample/ItemWithParticles.cpp +++ b/GUI/Model/Sample/ItemWithParticles.cpp @@ -39,7 +39,7 @@ std::unique_ptr<IRotation> ItemWithParticles::createRotation() const { if (!m_rotation.certainItem()) return {}; - return m_rotation->createRotation(); + return m_rotation.certainItem()->createRotation(); } void ItemWithParticles::writeTo(QXmlStreamWriter* w) const diff --git a/GUI/Model/Sample/Lattice2DCatalog.h b/GUI/Model/Sample/Lattice2DCatalog.h index ce744beffab895c65dabd60149a23c4b5f5f2a5b..a2ab1493a7824e22194120f59b77d510bceba636 100644 --- a/GUI/Model/Sample/Lattice2DCatalog.h +++ b/GUI/Model/Sample/Lattice2DCatalog.h @@ -22,7 +22,7 @@ class Lattice2DItem; class Lattice2DCatalog { public: - using BaseItem = Lattice2DItem; // used in PolyItem<Catalog> + using BaseItem = Lattice2DItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { Basic = 1, Square = 2, Hexagonal }; diff --git a/GUI/Model/Sample/MesocrystalItem.cpp b/GUI/Model/Sample/MesocrystalItem.cpp index 609c7c329d90b1ccc8fb597abc9ec77aca53f079..c03a0cf47a379e2adb2e4fa63e31b980c25cf777 100644 --- a/GUI/Model/Sample/MesocrystalItem.cpp +++ b/GUI/Model/Sample/MesocrystalItem.cpp @@ -146,7 +146,7 @@ std::unique_ptr<IParticle> MesocrystalItem::getBasis() const std::unique_ptr<IFormfactor> MesocrystalItem::getOuterShape() const { - return m_outer_shape->createFormfactor(); + return m_outer_shape.certainItem()->createFormfactor(); } std::vector<ItemWithParticles*> MesocrystalItem::containedItemsWithParticles() const diff --git a/GUI/Model/Sample/ParticleCatalog.h b/GUI/Model/Sample/ParticleCatalog.h index 6a5d61b4c080ac4812768c241fd573a9c30b0e93..ce75f98406e57cf10275e8e4795bba0a89106aa3 100644 --- a/GUI/Model/Sample/ParticleCatalog.h +++ b/GUI/Model/Sample/ParticleCatalog.h @@ -23,7 +23,7 @@ class MaterialsSet; class ParticleCatalog { public: - using BaseItem = ItemWithParticles; // used in PolyItem<Catalog> + using BaseItem = ItemWithParticles; // Do not change the numbering! It is serialized! enum class Type : uint8_t { Particle = 1, Composition = 2, CoreShell = 3, Mesocrystal = 4 }; diff --git a/GUI/Model/Sample/ParticleItem.cpp b/GUI/Model/Sample/ParticleItem.cpp index 5ac02f6a477e089b91f60120324488210d48dadb..3a286813b5add5e60360642323e884e1068206a4 100644 --- a/GUI/Model/Sample/ParticleItem.cpp +++ b/GUI/Model/Sample/ParticleItem.cpp @@ -75,7 +75,8 @@ std::unique_ptr<Particle> ParticleItem::createParticle() const { auto domainMaterial = materialItem()->createMaterial(); - auto particle = std::make_unique<Particle>(*domainMaterial, *m_form_factor->createFormfactor()); + auto particle = std::make_unique<Particle>(*domainMaterial, + *m_form_factor.certainItem()->createFormfactor()); particle->setAbundance(abundance().dVal()); if (auto r = createRotation(); r && !r->isIdentity()) particle->rotate(*r); diff --git a/GUI/Model/Sample/ProfileCatalogs.h b/GUI/Model/Sample/ProfileCatalogs.h index f9d8cf0129c08e739879f995cc6c6ba14d8a63a2..fe762f4af43cdc1aaf25937900e31172917023ef 100644 --- a/GUI/Model/Sample/ProfileCatalogs.h +++ b/GUI/Model/Sample/ProfileCatalogs.h @@ -23,7 +23,7 @@ class Profile2DItem; class Profile1DCatalog { public: - using BaseItem = Profile1DItem; // used in PolyItem<Catalog> + using BaseItem = Profile1DItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { diff --git a/GUI/Model/Sample/RotationCatalog.h b/GUI/Model/Sample/RotationCatalog.h index b43105f62d19c14be5b1bf57000e2f785cc9bb38..d165f722366ce9098b888c0dfe745c4dd42b578f 100644 --- a/GUI/Model/Sample/RotationCatalog.h +++ b/GUI/Model/Sample/RotationCatalog.h @@ -22,7 +22,7 @@ class RotationItem; class RotationCatalog { public: - using BaseItem = RotationItem; // used in PolyItem<Catalog> + using BaseItem = RotationItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { diff --git a/GUI/Model/Sample/RoughnessCatalog.h b/GUI/Model/Sample/RoughnessCatalog.h index 891d35dd7073db6ab431298da0bd800968cb8bb7..0319aef78ad7a7ea64497fa3151ca465773794ab 100644 --- a/GUI/Model/Sample/RoughnessCatalog.h +++ b/GUI/Model/Sample/RoughnessCatalog.h @@ -22,7 +22,7 @@ class RoughnessItem; class RoughnessCatalog { public: - using BaseItem = RoughnessItem; // used in PolyItem<Catalog> + using BaseItem = RoughnessItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { None = 0, Basic = 1 }; diff --git a/GUI/Model/Sample/SampleItem.cpp b/GUI/Model/Sample/SampleItem.cpp index c59f39e8f2cf2390b10a2594688a4e51545859f2..a234ebb3ba1f0acca9b23d571b83eaa5ae93ab0f 100644 --- a/GUI/Model/Sample/SampleItem.cpp +++ b/GUI/Model/Sample/SampleItem.cpp @@ -151,7 +151,7 @@ void SampleItem::readFrom(QXmlStreamReader* r) m_cross_correlation_length.readFrom2(r, tag); else if (tag == Tag::ExternalField) XML::readTaggedElement(r, tag, m_external_field); - else if (tag == Tag::MaterialsSet || tag == "MaterialModel" /*v<=21*/) + else if (tag == Tag::MaterialsSet) XML::readTaggedElement(r, tag, m_materials); else if (tag == Tag::Layer) XML::readTaggedElement(r, tag, *createLayerItemAt()); diff --git a/GUI/Model/Sim/BackgroundCatalog.h b/GUI/Model/Sim/BackgroundCatalog.h index 42ab48cac8ecac797a231587b90b0520e93ef035..3cb296b1a417f7e1ddc12b5e6cda74bf7808c6e7 100644 --- a/GUI/Model/Sim/BackgroundCatalog.h +++ b/GUI/Model/Sim/BackgroundCatalog.h @@ -22,7 +22,7 @@ class BackgroundItem; class BackgroundCatalog { public: - using BaseItem = BackgroundItem; // used in PolyItem<Catalog> + using BaseItem = BackgroundItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { None = 0, Constant = 1, Poisson = 2 }; diff --git a/GUI/Model/Sim/InstrumentCatalog.h b/GUI/Model/Sim/InstrumentCatalog.h index af304fe5f41d085878d1c79ccee469dba2f28783..f82ef88e0ee3b3e832b62c06f6f4ff3167657e47 100644 --- a/GUI/Model/Sim/InstrumentCatalog.h +++ b/GUI/Model/Sim/InstrumentCatalog.h @@ -22,7 +22,7 @@ class InstrumentItem; class InstrumentCatalog { public: - using BaseItem = InstrumentItem; // used in PolyItem<Catalog> + using BaseItem = InstrumentItem; // Do not change the numbering! It is serialized! enum class Type : uint8_t { Scatter2D = 0, Offspec = 1, Specular = 2, Depthprobe = 3 }; diff --git a/GUI/Model/Type/ModelForSet.h b/GUI/Model/Type/ModelForSet.h index 77faf442a4e652f1be7ca59279812d054ddcda8b..d6fb18318de37520f230ede468ae7ec9fd7c6490 100644 --- a/GUI/Model/Type/ModelForSet.h +++ b/GUI/Model/Type/ModelForSet.h @@ -18,11 +18,11 @@ #include "GUI/Model/Type/PredefinedColors.h" #include <QAbstractListModel> -template <class T> class SetWithModel; +template <typename T> class SetWithModel; //! Data model for a set of NamedItem%s. -template <class T> class ModelForSet : public QAbstractListModel { +template <typename T> class ModelForSet : public QAbstractListModel { public: explicit ModelForSet(SetWithModel<T>* set) : m_set(set) diff --git a/GUI/Model/Type/SetWithModel.h b/GUI/Model/Type/SetWithModel.h index 7d1748e0ef646635a741faaaa1165c944cd35919..404793c458c3ca58c8add1486818ebe7b85475a3 100644 --- a/GUI/Model/Type/SetWithModel.h +++ b/GUI/Model/Type/SetWithModel.h @@ -47,7 +47,7 @@ signals: //! A set of NamedItem%s that has a current item and a QListModel. -template <class T> class SetWithModel : public AbstractSetModel { +template <typename T> class SetWithModel : public AbstractSetModel { public: SetWithModel() : m_qmodel(std::make_unique<ModelForSet<T>>(this)) diff --git a/GUI/View/IO/ComponentRW.cpp b/GUI/View/IO/ComponentRW.cpp index b3134d7938e0ed04bc56621bbd25a463886854ff..eaf286055e6b1877df5ad78d5f7bd55e83806bde 100644 --- a/GUI/View/IO/ComponentRW.cpp +++ b/GUI/View/IO/ComponentRW.cpp @@ -22,8 +22,8 @@ namespace { -template <class T> void saveToXML(const QString& fname, const T* t); -template <class T> T* loadFromXML(const QString& fname); +template <typename T> void saveToXML(const QString& fname, const T* t); +template <typename T> T* loadFromXML(const QString& fname); template <> void saveToXML<InstrumentItem>(const QString& fname, const InstrumentItem* t) { @@ -41,7 +41,7 @@ auto dummy_saveXML_InstrumentItem = &IO::saveComponentToXML<class InstrumentItem auto dummy_loadXML_InstrumentItem = &IO::loadComponentFromXML<class InstrumentItem>; -template <class T> void IO::saveComponentToXML(const QString& type, const T* t) +template <typename T> void IO::saveComponentToXML(const QString& type, const T* t) { if (!t) return; @@ -60,7 +60,7 @@ template <class T> void IO::saveComponentToXML(const QString& type, const T* t) } } -template <class T> T* IO::loadComponentFromXML(const QString& type) +template <typename T> T* IO::loadComponentFromXML(const QString& type) { QString fname = QFileDialog::getOpenFileName(gApp->mainWindow, "Load " + type, gApp->xml_dir, "XML files (*.xml)", nullptr); diff --git a/GUI/View/IO/ComponentRW.h b/GUI/View/IO/ComponentRW.h index 377bdce9737fc3af14bcd66dd3b3cde91779cbc1..95fc690cf90cdbc7b08b831c076e37848d64acf7 100644 --- a/GUI/View/IO/ComponentRW.h +++ b/GUI/View/IO/ComponentRW.h @@ -19,8 +19,8 @@ namespace IO { -template <class T> void saveComponentToXML(const QString& type, const T* t); -template <class T> T* loadComponentFromXML(const QString& type); +template <typename T> void saveComponentToXML(const QString& type, const T* t); +template <typename T> T* loadComponentFromXML(const QString& type); } // namespace IO diff --git a/GUI/View/IO/DataLoader.cpp b/GUI/View/IO/DataLoader.cpp index 63d49a90a132b226f5f630ff5192b71fc410fd49..3ecda7f785049dc00a05d3d215dfc97a1a10e84d 100644 --- a/GUI/View/IO/DataLoader.cpp +++ b/GUI/View/IO/DataLoader.cpp @@ -30,7 +30,7 @@ namespace { // The following two functions are templated on T in {IO::Filetype1D, IO::Filetype2D}. -template <class T> +template <typename T> QString join_filterkeys(std::vector<std::pair<const QString, T>> _nomap, const QString& _separator) { QString result; @@ -42,7 +42,7 @@ QString join_filterkeys(std::vector<std::pair<const QString, T>> _nomap, const Q return result; } -template <class T> +template <typename T> T filterkey2type(std::vector<std::pair<const QString, T>> _nomap, const QString& _key) { for (const auto& it : _nomap) diff --git a/GUI/View/Numeric/ComboUtil.h b/GUI/View/Numeric/ComboUtil.h index e6dafb091fa77845b4ef16068fd9c8efb2b9f73c..5fd0e833c74ef2c0ff084df9c3c3acb05e71469f 100644 --- a/GUI/View/Numeric/ComboUtil.h +++ b/GUI/View/Numeric/ComboUtil.h @@ -51,9 +51,9 @@ QComboBox* createComboBoxFromPolyitem(PolyItem<T>& d, std::function<void(int)> s bool inScrollArea) { auto* combo = new QComboBox; - combo->addItems(d.options()); - combo->setMaxCount(d.options().size()); - combo->setToolTip(d.tooltip()); + combo->addItems(d.menuEntries()); + combo->setMaxCount(d.menuEntries().size()); + combo->setToolTip(d.piTooltip()); combo->setCurrentIndex(d.currentIndex()); if (inScrollArea) diff --git a/GUI/View/Sample/HeinzFormLayout.h b/GUI/View/Sample/HeinzFormLayout.h index c84700a2b0aeaef8eccd3ccb7db9b5a3eaa6cdcc..890e500d43bd1939379a5cbef92267c53d0458e3 100644 --- a/GUI/View/Sample/HeinzFormLayout.h +++ b/GUI/View/Sample/HeinzFormLayout.h @@ -58,7 +58,7 @@ public: //! Returns the newly added row. template <typename T> void addSelection(PolyItem<T>& d) { - addBoldRow(d.label(), new PolyForm(QFormLayout::parentWidget(), d, m_ec)); + addBoldRow(d.piLabel(), new PolyForm(QFormLayout::parentWidget(), d, m_ec)); } //! Adds a row with a bold printed label and a DSpinBox. diff --git a/GUI/View/Sample/ISelectionForm.h b/GUI/View/Sample/ISelectionForm.h index fc2c7bf61cb0c032765fe6cbbc709283b5238c77..2d6b992e11c5a2da986239e86518a027a99e3432 100644 --- a/GUI/View/Sample/ISelectionForm.h +++ b/GUI/View/Sample/ISelectionForm.h @@ -41,7 +41,7 @@ protected: m_combo = new QComboBox; WheelEventEater::install(m_combo); - m_combo->addItems(d.options()); + m_combo->addItems(d.menuEntries()); m_combo->setCurrentIndex(d.currentIndex()); m_combo->setMaxVisibleItems(m_combo->count()); diff --git a/GUI/View/Sample/InterferenceForm.cpp b/GUI/View/Sample/InterferenceForm.cpp index 301de9e0194e923dcda49a4f7d10748915f888d4..dacd186257883e370920c8eb37b6f9a49cce3ebe 100644 --- a/GUI/View/Sample/InterferenceForm.cpp +++ b/GUI/View/Sample/InterferenceForm.cpp @@ -34,7 +34,7 @@ InterferenceForm::InterferenceForm(QWidget* parent, ParticleLayoutItem* layoutIt WheelEventEater::install(m_interference_type_combo); const auto& d = layoutItem->interferenceSelection(); - m_interference_type_combo->addItems(d.options()); + m_interference_type_combo->addItems(d.menuEntries()); m_interference_type_combo->setCurrentIndex(d.currentIndex()); m_interference_type_combo->setMaxVisibleItems(m_interference_type_combo->count()); m_interference_type_combo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); @@ -88,7 +88,7 @@ void InterferenceForm::createInterferenceWidgets() } else if (auto* itf = dynamic_cast<Interference2DLatticeItem*>(interference)) { m_layout->addValue(itf->positionVariance()); auto* w = new LatticeTypeSelectionForm(this, itf, m_ec); - m_layout->addBoldRow(itf->latticeTypeSelection().label(), w); + m_layout->addBoldRow(itf->latticeTypeSelection().piLabel(), w); m_layout->addSelection(itf->decayFunctionSelection()); } else if (auto* itf = dynamic_cast<InterferenceFinite2DLatticeItem*>(interference)) { m_layout->addValue(itf->positionVariance()); @@ -110,14 +110,14 @@ void InterferenceForm::createInterferenceWidgets() "Domain size 2 in number of unit cells")); auto* w = new LatticeTypeSelectionForm(this, itf, m_ec); - m_layout->addBoldRow(itf->latticeTypeSelection().label(), w); + m_layout->addBoldRow(itf->latticeTypeSelection().piLabel(), w); } else if (auto* itf = dynamic_cast<Interference2DParacrystalItem*>(interference)) { m_layout->addValue(itf->positionVariance()); m_layout->addValue(itf->dampingLength()); m_layout->addValue(itf->domainSize1()); m_layout->addValue(itf->domainSize2()); auto* w = new LatticeTypeSelectionForm(this, itf, m_ec); - m_layout->addBoldRow(itf->latticeTypeSelection().label(), w); + m_layout->addBoldRow(itf->latticeTypeSelection().piLabel(), w); m_layout->addSelection(itf->probabilityDistributionSelection1()); m_layout->addSelection(itf->probabilityDistributionSelection2()); } diff --git a/GUI/View/Scene/MaskGraphicsScene.cpp b/GUI/View/Scene/MaskGraphicsScene.cpp index 57cd10cbca3ec3776392589e41edf33ef11f2334..779a099ad949b06c98666f6e45772ee9879a41c5 100644 --- a/GUI/View/Scene/MaskGraphicsScene.cpp +++ b/GUI/View/Scene/MaskGraphicsScene.cpp @@ -36,7 +36,7 @@ namespace { const qreal min_distance_to_create_rect = 10; //! Return true if area beneath the mouse contains views of given type. -template <class T> bool areaContains(QVector<QGraphicsItem*> items) +template <typename T> bool areaContains(QVector<QGraphicsItem*> items) { for (QGraphicsItem* item : items) if (dynamic_cast<T*>(item)) diff --git a/Param/Node/INode.h b/Param/Node/INode.h index 845a84427c06c1597ccee22fe4d239ed1d31dab2..3860ead303d9fa2836f526a92399af9fb7abb119 100644 --- a/Param/Node/INode.h +++ b/Param/Node/INode.h @@ -83,7 +83,7 @@ protected: #ifndef SWIG -template <class T> +template <typename T> std::vector<const INode*>& operator<<(std::vector<const INode*>& v_node, const std::unique_ptr<T>& node) { @@ -92,7 +92,7 @@ std::vector<const INode*>& operator<<(std::vector<const INode*>& v_node, return v_node; } -template <class T> +template <typename T> std::vector<const INode*>& operator<<(std::vector<const INode*>&& v_node, const std::unique_ptr<T>& node) { diff --git a/Resample/Interparticle/IInterparticleStrategy.h b/Resample/Interparticle/IInterparticleStrategy.h index 8ce6fc5f2bdffd7ac797207730f4c83fdff2c392..046d68cc9f4be62de773feaa5c59fefe0d29aa32 100644 --- a/Resample/Interparticle/IInterparticleStrategy.h +++ b/Resample/Interparticle/IInterparticleStrategy.h @@ -24,7 +24,7 @@ #include <memory> #include <vector> -template <class T> class IntegratorMCMiser; +template <typename T> class IntegratorMCMiser; class CoheringSubparticles; class DiffuseElement; diff --git a/Sample/ComponentBuilder/IRegistry.h b/Sample/ComponentBuilder/IRegistry.h index 4e0b40a46c1d27394216a710b5aafb92f1f51464..2993a64e72d42c13709063b5077e52a6dc7cd987 100644 --- a/Sample/ComponentBuilder/IRegistry.h +++ b/Sample/ComponentBuilder/IRegistry.h @@ -26,7 +26,7 @@ //! Templated object registry. -template <class T> class IRegistry { +template <typename T> class IRegistry { public: const T* getItem(const std::string& key) const { diff --git a/Sim/Export/ComponentKeyHandler.h b/Sim/Export/ComponentKeyHandler.h index 77d0e4947d50db906cec825696bb15972ff416ca..69015cd3bcb25063a03f0c89f932879a9c3cfaca 100644 --- a/Sim/Export/ComponentKeyHandler.h +++ b/Sim/Export/ComponentKeyHandler.h @@ -30,14 +30,14 @@ class ComponentKeyHandler { public: void insertModel(const std::string& tag, const INode* s); - template <class T> std::vector<const T*> objectsOfType() const; + template <typename T> std::vector<const T*> objectsOfType() const; std::string obj2key(const INode* s) const; private: std::map<std::string, std::vector<const INode*>> m_objects; }; -template <class T> std::vector<const T*> ComponentKeyHandler::objectsOfType() const +template <typename T> std::vector<const T*> ComponentKeyHandler::objectsOfType() const { std::vector<const T*> result; for (const auto& it : m_objects) diff --git a/Sim/Fitting/FitObserver.h b/Sim/Fitting/FitObserver.h index 807aeb789178bed1c6ff523d3637d566b4f0d657..411086ee5c247088c6ee3725357bcd458a833bbc 100644 --- a/Sim/Fitting/FitObserver.h +++ b/Sim/Fitting/FitObserver.h @@ -25,7 +25,7 @@ //! Contains collection of observers and call them at specified intervals. //! Each observer will be called at first iteration and every-nth iterations. -template <class T> class FitObserver { +template <typename T> class FitObserver { public: using observer_t = std::function<void(const T&)>; FitObserver(); @@ -63,19 +63,19 @@ private: int m_notify_count; //! Total number of notify calls }; -template <class T> +template <typename T> FitObserver<T>::FitObserver() : m_notify_count(0) { } -template <class T> +template <typename T> void FitObserver<T>::addObserver(int every_nth, FitObserver<T>::observer_t&& observer) { m_observers.emplace_back(ObserverData(every_nth, observer)); } -template <class T> void FitObserver<T>::notify(const T& data) +template <typename T> void FitObserver<T>::notify(const T& data) { for (const auto& observer : m_observers) { if (need_notify(observer.m_every_nth)) @@ -85,7 +85,7 @@ template <class T> void FitObserver<T>::notify(const T& data) m_notify_count++; } -template <class T> void FitObserver<T>::notify_all(const T& data) +template <typename T> void FitObserver<T>::notify_all(const T& data) { for (const auto& observer : m_observers) observer.m_observer(data); @@ -93,7 +93,7 @@ template <class T> void FitObserver<T>::notify_all(const T& data) m_notify_count++; } -template <class T> bool FitObserver<T>::need_notify(int every_nth) +template <typename T> bool FitObserver<T>::need_notify(int every_nth) { return every_nth && m_notify_count % every_nth == 0; } diff --git a/Sim/Fitting/ObjectiveMetric.cpp b/Sim/Fitting/ObjectiveMetric.cpp index 652cccfc31c1121ed9d85f91ea3e4146d78cda0c..6ffa3bb4bbd32feced1dd6a3ff974fd635a28f81 100644 --- a/Sim/Fitting/ObjectiveMetric.cpp +++ b/Sim/Fitting/ObjectiveMetric.cpp @@ -27,7 +27,7 @@ const double double_max = std::numeric_limits<double>::max(); const double double_min = std::numeric_limits<double>::min(); const double ln10 = std::log(10.0); -template <class T> T* copyMetric(const T& metric) +template <typename T> T* copyMetric(const T& metric) { auto* result = new T; result->setNorm(metric.norm()); diff --git a/Sim/Fitting/ObjectiveMetricUtil.cpp b/Sim/Fitting/ObjectiveMetricUtil.cpp index d92ce4f78532710b06c5193583693d26a9e95c82..484c97a0c5e68a2a3a207c76fd74338a0647cdf5 100644 --- a/Sim/Fitting/ObjectiveMetricUtil.cpp +++ b/Sim/Fitting/ObjectiveMetricUtil.cpp @@ -36,7 +36,7 @@ const std::map<std::string, std::function<double(double)>> norm_factory = {{"l1" {"l2", l2_norm}}; const std::string default_norm_name = "l2"; -template <class U> std::vector<std::string> keys(const std::map<std::string, U>& map) +template <typename U> std::vector<std::string> keys(const std::map<std::string, U>& map) { std::vector<std::string> result; result.reserve(map.size()); diff --git a/devtools/checks/check-scg-cpp-style.py b/devtools/checks/check-scg-cpp-style.py index 3f9795aed3e6afeb38298214418699b00028dd62..e4983a2775a5ec613118c14b9a67c3c17f8c8b58 100755 --- a/devtools/checks/check-scg-cpp-style.py +++ b/devtools/checks/check-scg-cpp-style.py @@ -72,7 +72,7 @@ def check_block(fn, t, name, errs): elif name == "fwd decl": rex = r'(class|struct) \w+;' t = rm_namespace(t) - matches = [m for m in re.finditer(r'(\n*)\n('+ rex + r'([ ]*//.*)?\n)+(\n*)', t)] + matches = [m for m in re.finditer(r'(\n*|template.*)\n('+ rex + r'([ ]*//.*)?\n)+(\n*)', t)] if len(matches) > 1: @@ -89,6 +89,8 @@ def check_block(fn, t, name, errs): m = matches[0] + if re.match(r'^template', m.group(1)): + return if m.group(1) == '': if not re.match(rex, t): errs.append(f"missing blank line above {name} block in file {fn}")