|
| 1 | +/*! |
| 2 | + * \file MGIS/Behaviour/BehaviourIntegrationFailureAnalyser.hxx |
| 3 | + * \brief The header define some useful features for debugging purposes |
| 4 | + * \author Thomas Helfer |
| 5 | + * \date 21/08/2025 |
| 6 | + */ |
| 7 | + |
| 8 | +#ifndef LIB_MGIS_BEHAVIOUR_BEHAVIOURINTEGRATIONFAILUREANALYSER_HXX |
| 9 | +#define LIB_MGIS_BEHAVIOUR_BEHAVIOURINTEGRATIONFAILUREANALYSER_HXX |
| 10 | + |
| 11 | +#include <string> |
| 12 | +#include <functional> |
| 13 | +#include <string_view> |
| 14 | +#include "MGIS/Config.hxx" |
| 15 | +#include "MGIS/Behaviour/BehaviourData.hxx" |
| 16 | +#include "MGIS/Behaviour/BehaviourDataView.hxx" |
| 17 | + |
| 18 | +namespace mgis::behaviour { |
| 19 | + |
| 20 | + // forward declarations |
| 21 | + struct Behaviour; |
| 22 | + |
| 23 | +} // end of namespace mgis::behaviour |
| 24 | + |
| 25 | +namespace mgis::behaviour::debug { |
| 26 | + |
| 27 | + /*! |
| 28 | + * \brief object in charge of analysing and integration failure. This object |
| 29 | + * is used by the `integrate_debug` function |
| 30 | + * |
| 31 | + * \note most analysers generate a file. See the |
| 32 | + * `getBehaviourIntegrationFailureAnalysisFileName` below for a way to |
| 33 | + * generate a unique file name. By default, this file name is unique for the |
| 34 | + * given process. In an MPI context, one shall provide a file name generator |
| 35 | + * which takes the MPI process id into account to avoid conflicts, see the |
| 36 | + * function `setBehaviourIntegrationFailureAnalysisFileNameGenerator` for |
| 37 | + * details. |
| 38 | + */ |
| 39 | + struct MGIS_EXPORT BehaviourIntegrationFailureAnalyser { |
| 40 | + /*! |
| 41 | + * \brief handle an integration failure |
| 42 | + * \param[in] b: behaviour being integrated |
| 43 | + * \param[in] d: behaviour data leading to the integration failure |
| 44 | + */ |
| 45 | + virtual void analyse(const Behaviour&, |
| 46 | + const BehaviourData&) const noexcept = 0; |
| 47 | + /*! |
| 48 | + * \brief handle an integration failure |
| 49 | + * \param[in] b: behaviour being integrated |
| 50 | + * \param[in] d: behaviour data view leading to the integration failure |
| 51 | + */ |
| 52 | + virtual void analyse(const Behaviour&, |
| 53 | + const BehaviourDataView&) const noexcept = 0; |
| 54 | + /*! |
| 55 | + * \brief use a copy of the inputs |
| 56 | + * |
| 57 | + * If true, the behaviour data view passed to the `integrate_debug` |
| 58 | + * function is copied before integrating the behaviour. Copying has |
| 59 | + * a significant overhead and is normally not required for correctly written |
| 60 | + * behaviours but data corruption may occur, so copying is safer. |
| 61 | + */ |
| 62 | + virtual bool shallCopyBehaviourDataBeforeIntegration() const noexcept = 0; |
| 63 | + //! \brief destructor |
| 64 | + virtual ~BehaviourIntegrationFailureAnalyser() noexcept; |
| 65 | + }; |
| 66 | + |
| 67 | + /*! |
| 68 | + * \return a file name used to output |
| 69 | + * debugging information in case of integration |
| 70 | + * failure |
| 71 | + * |
| 72 | + * \param[in] n: behaviour name |
| 73 | + * \param[in] ext: file name |
| 74 | + */ |
| 75 | + MGIS_EXPORT std::string getBehaviourIntegrationFailureAnalysisFileName( |
| 76 | + std::string_view, std::string_view); |
| 77 | + |
| 78 | + /*! |
| 79 | + * \brief a function hook used to generate a file name |
| 80 | + * for debugging behaviour integration failures |
| 81 | + * \param[in] g: generator |
| 82 | + * |
| 83 | + * \note the generator takes the behaviour name as first argument and a unique |
| 84 | + * identifier (for the given process) as second argument |
| 85 | + */ |
| 86 | + MGIS_EXPORT void setBehaviourIntegrationFailureAnalysisFileNameGenerator( |
| 87 | + std::function<std::string(std::string_view, // behaviour name |
| 88 | + std::string_view, // unique identifier |
| 89 | + std::string_view) // file extension |
| 90 | + >); |
| 91 | + |
| 92 | +#ifndef LIB_MGIS_BEHAVIOUR_INTEGRATE_HXX |
| 93 | + /*! |
| 94 | + * \return the default debugging options |
| 95 | + */ |
| 96 | + MGIS_EXPORT const debug::BehaviourIntegrationFailureAnalyser& |
| 97 | + getDefaultBehaviourIntegrationFailureAnalyser(); |
| 98 | +#endif |
| 99 | + |
| 100 | +} // end of namespace mgis::behaviour::debug |
| 101 | + |
| 102 | +#endif /* LIB_MGIS_BEHAVIOUR_BEHAVIOURINTEGRATIONFAILUREANALYSER_HXX */ |
0 commit comments