Skip to content
Snippets Groups Projects
Commit ca0f8cf6 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

SampleToPython: Doxy com, rename fct and var and auxiliary class

parent 6fcc1375
No related branches found
No related tags found
No related merge requests found
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// //
// BornAgain: simulate and fit scattering at grazing incidence // BornAgain: simulate and fit scattering at grazing incidence
// //
//! @file Core/Export/SampleLabelHandler.cpp //! @file Core/Export/ModelKeyHandler.cpp
//! @brief Implement class SampleLabelHandler. //! @brief Implement class ModelKeyHandler.
//! //!
//! @homepage http://www.bornagainproject.org //! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING) //! @license GNU General Public License v3 or higher (see COPYING)
...@@ -12,25 +12,25 @@ ...@@ -12,25 +12,25 @@
// //
// ************************************************************************************************ // ************************************************************************************************
#include "Core/Export/SampleLabelHandler.h" #include "Core/Export/ModelKeyHandler.h"
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <stdexcept> #include <stdexcept>
void SampleLabelHandler::insertKeyedObject(const std::string& key, const IModel* s) { void ModelKeyHandler::insertModel(const std::string& tag, const IModel* s) {
m_objects[key].emplace_back(s); m_objects[tag].emplace_back(s);
} }
std::string SampleLabelHandler::obj2key(const IModel* s) const { std::string ModelKeyHandler::obj2key(const IModel* s) const {
for (auto it: m_objects) { for (auto it: m_objects) {
const std::vector<const IModel*>& v = it.second; const std::vector<const IModel*>& v = it.second;
const auto vpos = std::find(v.begin(), v.end(), s); const auto vpos = std::find(v.begin(), v.end(), s);
if (vpos == std::end(v)) if (vpos == std::end(v))
continue; continue;
const std::string& key = it.first; const std::string& tag = it.first;
if (v.size() == 1) if (v.size() == 1)
return key; return tag;
return key + "_" + std::to_string(vpos - v.begin() + 1); return tag + "_" + std::to_string(vpos - v.begin() + 1);
} }
throw std::runtime_error("BUG: object not found in SampleLabelHandler"); throw std::runtime_error("BUG: object not found in ModelKeyHandler");
} }
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// //
// BornAgain: simulate and fit scattering at grazing incidence // BornAgain: simulate and fit scattering at grazing incidence
// //
//! @file Core/Export/SampleLabelHandler.h //! @file Core/Export/ModelKeyHandler.h
//! @brief Defines classes LabelMap and SampleLabelHandler. //! @brief Defines classes LabelMap and ModelKeyHandler.
//! //!
//! @homepage http://www.bornagainproject.org //! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING) //! @license GNU General Public License v3 or higher (see COPYING)
...@@ -21,14 +21,12 @@ ...@@ -21,14 +21,12 @@
class IModel; class IModel;
//! The handler which construct labels for sample variables during python script generation. //! Stores IModel instances, associates them with given tag, and provides unique keys.
//! @ingroup tools_internal //! @ingroup tools_internal
class SampleLabelHandler { class ModelKeyHandler {
public: public:
SampleLabelHandler() {} void insertModel(const std::string& tag, const IModel* s);
void insertKeyedObject(const std::string& key, const IModel* s);
template <class T> std::vector<const T*> objectsOfType() const; template <class T> std::vector<const T*> objectsOfType() const;
std::string obj2key(const IModel* s) const; std::string obj2key(const IModel* s) const;
...@@ -38,7 +36,7 @@ private: ...@@ -38,7 +36,7 @@ private:
}; };
template <class T> std::vector<const T*> SampleLabelHandler::objectsOfType() const { template <class T> std::vector<const T*> ModelKeyHandler::objectsOfType() const {
std::vector<const T*> ret; std::vector<const T*> ret;
for (auto it: m_objects) for (auto it: m_objects)
for (const IModel* s : it.second) for (const IModel* s : it.second)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "Core/Export/INodeUtils.h" #include "Core/Export/INodeUtils.h"
#include "Core/Export/PyFmt.h" #include "Core/Export/PyFmt.h"
#include "Core/Export/PyFmt2.h" #include "Core/Export/PyFmt2.h"
#include "Core/Export/SampleLabelHandler.h" #include "Core/Export/ModelKeyHandler.h"
#include "Param/Varia/ParameterUtils.h" #include "Param/Varia/ParameterUtils.h"
#include "Sample/Aggregate/InterferenceFunctions.h" #include "Sample/Aggregate/InterferenceFunctions.h"
#include "Sample/Aggregate/ParticleLayout.h" #include "Sample/Aggregate/ParticleLayout.h"
...@@ -101,39 +101,39 @@ std::string SampleToPython::generateSampleCode(const MultiLayer& multilayer) { ...@@ -101,39 +101,39 @@ std::string SampleToPython::generateSampleCode(const MultiLayer& multilayer) {
} }
void SampleToPython::initLabels(const MultiLayer& multilayer) { void SampleToPython::initLabels(const MultiLayer& multilayer) {
m_objs.reset(new SampleLabelHandler()); m_objs.reset(new ModelKeyHandler());
m_objs->insertKeyedObject("sample", &multilayer); m_objs->insertModel("sample", &multilayer);
for (const auto* x : multilayer.containedMaterials()) for (const auto* x : multilayer.containedMaterials())
m_objs->insertKeyedObject("mat_"+x->getName(), x); m_objs->insertModel("mat_"+x->getName(), x);
for (const auto* x : INodeUtils::AllDescendantsOfType<Layer>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<Layer>(multilayer))
m_objs->insertKeyedObject("layer", x); m_objs->insertModel("layer", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<LayerRoughness>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<LayerRoughness>(multilayer))
m_objs->insertKeyedObject("roughness", x); m_objs->insertModel("roughness", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<ParticleLayout>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<ParticleLayout>(multilayer))
m_objs->insertKeyedObject("layout", x); m_objs->insertModel("layout", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<IFormFactor>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<IFormFactor>(multilayer))
m_objs->insertKeyedObject("ff", x); m_objs->insertModel("ff", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<IInterferenceFunction>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<IInterferenceFunction>(multilayer))
m_objs->insertKeyedObject("iff", x); m_objs->insertModel("iff", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<Particle>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<Particle>(multilayer))
m_objs->insertKeyedObject("particle", x); m_objs->insertModel("particle", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<ParticleComposition>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<ParticleComposition>(multilayer))
m_objs->insertKeyedObject("particle", x); m_objs->insertModel("particle", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<ParticleCoreShell>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<ParticleCoreShell>(multilayer))
m_objs->insertKeyedObject("particle", x); m_objs->insertModel("particle", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<MesoCrystal>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<MesoCrystal>(multilayer))
m_objs->insertKeyedObject("particle", x); m_objs->insertModel("particle", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<ParticleDistribution>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<ParticleDistribution>(multilayer))
m_objs->insertKeyedObject("particle_distrib", x); m_objs->insertModel("particle_distrib", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<Lattice2D>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<Lattice2D>(multilayer))
m_objs->insertKeyedObject("lattice", x); m_objs->insertModel("lattice", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<Lattice3D>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<Lattice3D>(multilayer))
m_objs->insertKeyedObject("lattice", x); m_objs->insertModel("lattice", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<Crystal>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<Crystal>(multilayer))
m_objs->insertKeyedObject("crystal", x); m_objs->insertModel("crystal", x);
for (const auto* x : INodeUtils::AllDescendantsOfType<IRotation>(multilayer)) for (const auto* x : INodeUtils::AllDescendantsOfType<IRotation>(multilayer))
m_objs->insertKeyedObject("rotation", x); m_objs->insertModel("rotation", x);
} }
SampleToPython::SampleToPython() = default; SampleToPython::SampleToPython() = default;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
class IParticle; class IParticle;
class MultiLayer; class MultiLayer;
class SampleLabelHandler; class ModelKeyHandler;
//! Generates Python code snippet from domain (C++) objects representing sample construction. //! Generates Python code snippet from domain (C++) objects representing sample construction.
...@@ -51,7 +51,7 @@ private: ...@@ -51,7 +51,7 @@ private:
std::string defineRoughnesses() const; std::string defineRoughnesses() const;
std::string defineMultiLayers() const; std::string defineMultiLayers() const;
std::unique_ptr<SampleLabelHandler> m_objs; std::unique_ptr<ModelKeyHandler> m_objs;
}; };
#endif // BORNAGAIN_CORE_EXPORT_SAMPLETOPYTHON_H #endif // BORNAGAIN_CORE_EXPORT_SAMPLETOPYTHON_H
...@@ -1200,6 +1200,24 @@ user-defined weighting factors. Used linearly, no matter which norm is chosen. ...@@ -1200,6 +1200,24 @@ user-defined weighting factors. Used linearly, no matter which norm is chosen.
"; ";
// File: classModelKeyHandler.xml
%feature("docstring") ModelKeyHandler "
Stores IModel instances, associates them with given tag, and provides unique keys.
C++ includes: ModelKeyHandler.h
";
%feature("docstring") ModelKeyHandler::insertModel "void ModelKeyHandler::insertModel(const std::string &tag, const IModel *s)
";
%feature("docstring") ModelKeyHandler::objectsOfType "std::vector< const T * > ModelKeyHandler::objectsOfType() const
";
%feature("docstring") ModelKeyHandler::obj2key "std::string ModelKeyHandler::obj2key(const IModel *s) const
";
// File: classMPISimulation.xml // File: classMPISimulation.xml
%feature("docstring") MPISimulation ""; %feature("docstring") MPISimulation "";
...@@ -1343,57 +1361,6 @@ Returns the total number of the intensity values in the simulation result. ...@@ -1343,57 +1361,6 @@ Returns the total number of the intensity values in the simulation result.
"; ";
// File: classOrderedMap.xml
%feature("docstring") OrderedMap "
Ordered map which saves the order of insertion.
C++ includes: OrderedMap.h
";
%feature("docstring") OrderedMap::OrderedMap "OrderedMap< Key, Object >::OrderedMap()
";
%feature("docstring") OrderedMap::~OrderedMap "virtual OrderedMap< Key, Object >::~OrderedMap()
";
%feature("docstring") OrderedMap::clear "void OrderedMap< Key, Object >::clear()
";
%feature("docstring") OrderedMap::begin "const_iterator OrderedMap< Key, Object >::begin() const
";
%feature("docstring") OrderedMap::end "const_iterator OrderedMap< Key, Object >::end() const
";
%feature("docstring") OrderedMap::begin "iterator OrderedMap< Key, Object >::begin()
";
%feature("docstring") OrderedMap::end "iterator OrderedMap< Key, Object >::end()
";
%feature("docstring") OrderedMap::size "size_t OrderedMap< Key, Object >::size() const
";
%feature("docstring") OrderedMap::empty "bool OrderedMap< Key, Object >::empty() const
";
%feature("docstring") OrderedMap::insert "void OrderedMap< Key, Object >::insert(const Key &key, const Object &object)
";
%feature("docstring") OrderedMap::find "iterator OrderedMap< Key, Object >::find(const Key &key)
";
%feature("docstring") OrderedMap::find "const_iterator OrderedMap< Key, Object >::find(const Key &key) const
";
%feature("docstring") OrderedMap::erase "size_t OrderedMap< Key, Object >::erase(const Key &key)
";
%feature("docstring") OrderedMap::value "const Object& OrderedMap< Key, Object >::value(const Key &key) const
";
// File: classOutputData.xml // File: classOutputData.xml
%feature("docstring") OutputData ""; %feature("docstring") OutputData "";
...@@ -1742,27 +1709,6 @@ boolean, defines if data uncertainties should be taken into account ...@@ -1742,27 +1709,6 @@ boolean, defines if data uncertainties should be taken into account
"; ";
// File: classSampleLabelHandler.xml
%feature("docstring") SampleLabelHandler "
The handler which construct labels for sample variables during python script generation.
C++ includes: SampleLabelHandler.h
";
%feature("docstring") SampleLabelHandler::SampleLabelHandler "SampleLabelHandler::SampleLabelHandler()
";
%feature("docstring") SampleLabelHandler::insertKeyedObject "void SampleLabelHandler::insertKeyedObject(const std::string &key, const IModel *s)
";
%feature("docstring") SampleLabelHandler::objectsOfType "std::vector< const T * > SampleLabelHandler::objectsOfType() const
";
%feature("docstring") SampleLabelHandler::obj2key "std::string SampleLabelHandler::obj2key(const IModel *s) const
";
// File: classSampleToPython.xml // File: classSampleToPython.xml
%feature("docstring") SampleToPython " %feature("docstring") SampleToPython "
...@@ -2176,43 +2122,43 @@ Returns default units to convert to. ...@@ -2176,43 +2122,43 @@ Returns default units to convert to.
// File: namespace_0d19.xml // File: namespace_0d19.xml
// File: namespace_0d39.xml // File: namespace_0d38.xml
// File: namespace_0d41.xml // File: namespace_0d40.xml
// File: namespace_0d46.xml // File: namespace_0d45.xml
// File: namespace_0d55.xml // File: namespace_0d54.xml
// File: namespace_0d57.xml // File: namespace_0d56.xml
// File: namespace_0d61.xml // File: namespace_0d60.xml
// File: namespace_0d63.xml // File: namespace_0d62.xml
// File: namespace_0d68.xml // File: namespace_0d67.xml
// File: namespace_0d70.xml // File: namespace_0d69.xml
// File: namespace_0d74.xml // File: namespace_0d73.xml
// File: namespace_0d84.xml // File: namespace_0d83.xml
// File: namespace_0d86.xml // File: namespace_0d85.xml
// File: namespace_0d92.xml // File: namespace_0d91.xml
// File: namespaceExportToPython.xml // File: namespaceExportToPython.xml
...@@ -2659,7 +2605,10 @@ Helper factory function to use in GISASSimulation. Depending on the type of det ...@@ -2659,7 +2605,10 @@ Helper factory function to use in GISASSimulation. Depending on the type of det
// File: INodeUtils_8h.xml // File: INodeUtils_8h.xml
// File: OrderedMap_8h.xml // File: ModelKeyHandler_8cpp.xml
// File: ModelKeyHandler_8h.xml
// File: PyFmt_8cpp.xml // File: PyFmt_8cpp.xml
...@@ -2680,12 +2629,6 @@ Helper factory function to use in GISASSimulation. Depending on the type of det ...@@ -2680,12 +2629,6 @@ Helper factory function to use in GISASSimulation. Depending on the type of det
// File: PyFmtLimits_8h.xml // File: PyFmtLimits_8h.xml
// File: SampleLabelHandler_8cpp.xml
// File: SampleLabelHandler_8h.xml
// File: SampleToPython_8cpp.xml // File: SampleToPython_8cpp.xml
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment