IOSS 2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Ioss_DynamicTopologyNotifier.h
Go to the documentation of this file.
1// Copyright(C) 2024, 2025 National Technology & Engineering Solutions
2// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3// NTESS, the U.S. Government retains certain rights in this software.
4//
5// See packages/seacas/LICENSE for details
6
7#pragma once
8
11
12#include "Ioss_CodeTypes.h"
13#include "Ioss_DBUsage.h"
14#include "Ioss_DatabaseIO.h" // for DatabaseIO
15#include "Ioss_ParallelUtils.h" // for ParallelUtils
16#include "Ioss_PropertyManager.h" // for PropertyManager
17#include "Ioss_Utils.h"
18#include "ioss_export.h"
19
20#include <cstddef> // for size_t, nullptr
21#include <cstdint> // for int64_t
22#include <iomanip>
23#include <sstream>
24#include <string> // for string, operator<
25
26namespace Ioss {
27
28 class IOSS_EXPORT DynamicTopologyNotifier
29 {
30 public:
31 explicit DynamicTopologyNotifier(const std::string &model_name) : m_modelName(model_name) {}
32
33 virtual ~DynamicTopologyNotifier() = default;
34
35 IOSS_NODISCARD std::string name() const { return m_modelName; }
36
37 IOSS_NODISCARD const std::vector<std::shared_ptr<DynamicTopologyObserver>> &
39 {
40 return m_observers;
41 }
42
43 IOSS_NODISCARD std::vector<std::shared_ptr<DynamicTopologyObserver>> &get_observers()
44 {
45 return m_observers;
46 }
47
48 void register_observer(std::shared_ptr<DynamicTopologyObserver> observer);
49
50 void unregister_observer(std::shared_ptr<DynamicTopologyObserver> observer);
51
52 void reset_topology_modification();
53
54 void set_topology_modification(unsigned int type);
55
56 template <typename ObserverType> bool has_observer_type() const
57 {
58 bool found = false;
59
60 for (const std::shared_ptr<DynamicTopologyObserver> &observer : m_observers) {
61 if (dynamic_cast<const ObserverType *>(observer.get()) != nullptr) {
62 found = true;
63 break;
64 }
65 }
66 return found;
67 }
68
69 template <typename ObserverType>
70 std::vector<std::shared_ptr<ObserverType>> get_observer_type() const
71 {
72 std::vector<std::shared_ptr<ObserverType>> typed_observers;
73
74 for (const std::shared_ptr<DynamicTopologyObserver> &observer : m_observers) {
75 ObserverType *typed_observer = dynamic_cast<ObserverType *>(observer.get());
76 if (typed_observer != nullptr) {
77 typed_observers.push_back(std::dynamic_pointer_cast<ObserverType>(observer));
78 }
79 }
80
81 return typed_observers;
82 }
83
84 private:
85 const std::string m_modelName;
86 std::vector<std::shared_ptr<DynamicTopologyObserver>> m_observers;
87 };
88
89} // namespace Ioss
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:56
std::vector< std::shared_ptr< DynamicTopologyObserver > > m_observers
Definition Ioss_DynamicTopologyNotifier.h:86
IOSS_NODISCARD std::vector< std::shared_ptr< DynamicTopologyObserver > > & get_observers()
Definition Ioss_DynamicTopologyNotifier.h:43
const std::string m_modelName
Definition Ioss_DynamicTopologyNotifier.h:85
IOSS_NODISCARD std::string name() const
Definition Ioss_DynamicTopologyNotifier.h:35
std::vector< std::shared_ptr< ObserverType > > get_observer_type() const
Definition Ioss_DynamicTopologyNotifier.h:70
DynamicTopologyNotifier(const std::string &model_name)
Definition Ioss_DynamicTopologyNotifier.h:31
IOSS_NODISCARD const std::vector< std::shared_ptr< DynamicTopologyObserver > > & get_observers() const
Definition Ioss_DynamicTopologyNotifier.h:38
bool has_observer_type() const
Definition Ioss_DynamicTopologyNotifier.h:56
virtual ~DynamicTopologyNotifier()=default
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40