File tree Expand file tree Collapse file tree 14 files changed +117
-53
lines changed
Expand file tree Collapse file tree 14 files changed +117
-53
lines changed Original file line number Diff line number Diff line change @@ -244,14 +244,23 @@ class Iteration : public Attributable
244244private:
245245 Iteration ();
246246
247- inline internal::IterationData const &get () const
247+ using Data_t = internal::IterationData;
248+ std::shared_ptr<Data_t> m_iterationData;
249+
250+ inline Data_t const &get () const
251+ {
252+ return *m_iterationData;
253+ }
254+
255+ inline Data_t &get ()
248256 {
249- return dynamic_cast <internal::IterationData const &>(*m_attri) ;
257+ return *m_iterationData ;
250258 }
251259
252- inline internal::IterationData & get ( )
260+ inline void setData (std::shared_ptr<Data_t> data )
253261 {
254- return dynamic_cast <internal::IterationData &>(*m_attri);
262+ m_iterationData = std::move (data);
263+ Attributable::setData (m_iterationData);
255264 }
256265
257266 void flushFileBased (
Original file line number Diff line number Diff line change @@ -434,18 +434,24 @@ OPENPMD_protected
434434 // clang-format on
435435
436436 using Data_t = internal::RecordComponentData;
437+ std::shared_ptr<Data_t> m_recordComponentData;
437438
438439 RecordComponent ();
439440
440441 inline Data_t const &get () const
441442 {
442- return dynamic_cast <Data_t const &>(*m_attri) ;
443+ return *m_recordComponentData ;
443444 }
444445
445446 inline Data_t &get ()
446447 {
447- auto &res = dynamic_cast <Data_t &>(*m_attri);
448- return res;
448+ return *m_recordComponentData;
449+ }
450+
451+ inline void setData (std::shared_ptr<internal::RecordComponentData> data)
452+ {
453+ m_recordComponentData = std::move (data);
454+ BaseRecordComponent::setData (m_recordComponentData);
449455 }
450456
451457 void readBase ();
Original file line number Diff line number Diff line change @@ -534,11 +534,14 @@ OPENPMD_private
534534 using iterations_t = decltype (internal::SeriesData::iterations);
535535 using iterations_iterator = iterations_t ::iterator;
536536
537- inline internal::SeriesData &get ()
537+ using Data_t = internal::SeriesData;
538+ std::shared_ptr<Data_t> m_series = nullptr ;
539+
540+ inline Data_t &get ()
538541 {
539- if (m_attri )
542+ if (m_series )
540543 {
541- return dynamic_cast <internal::SeriesData &>(*m_attri) ;
544+ return *m_series ;
542545 }
543546 else
544547 {
@@ -547,11 +550,11 @@ OPENPMD_private
547550 }
548551 }
549552
550- inline internal::SeriesData const &get () const
553+ inline Data_t const &get () const
551554 {
552- if (m_attri )
555+ if (m_series )
553556 {
554- return dynamic_cast <internal::SeriesData const &>(*m_attri) ;
557+ return *m_series ;
555558 }
556559 else
557560 {
@@ -562,8 +565,9 @@ OPENPMD_private
562565
563566 inline void setData (std::shared_ptr<internal::SeriesData> series)
564567 {
565- iterations = series->iterations ;
566- Attributable::setData (std::move (series));
568+ m_series = std::move (series);
569+ iterations = m_series->iterations ;
570+ Attributable::setData (m_series);
567571 }
568572
569573 std::unique_ptr<ParsedInput> parseInput (std::string);
Original file line number Diff line number Diff line change @@ -111,11 +111,16 @@ class Attributable
111111 friend class WriteIterations ;
112112
113113protected:
114- std::shared_ptr<internal::AttributableData> m_attri{
115- new internal::AttributableData ()};
114+ // tag for internal constructor
115+ struct NoInit
116+ {};
117+
118+ using Data_t = internal::AttributableData;
119+ std::shared_ptr<Data_t> m_attri;
116120
117121public:
118122 Attributable ();
123+ Attributable (NoInit);
119124
120125 virtual ~Attributable () = default ;
121126
@@ -353,11 +358,9 @@ OPENPMD_protected
353358 return m_attri->m_writable ;
354359 }
355360
356- template <typename T = internal::AttributableData>
357- inline void setData (std::shared_ptr<T> attri)
361+ inline void setData (std::shared_ptr<internal::AttributableData> attri)
358362 {
359- m_attri = std::static_pointer_cast<internal::AttributableData>(
360- std::move (attri));
363+ m_attri = std::move (attri);
361364 }
362365
363366 inline internal::AttributableData &get ()
Original file line number Diff line number Diff line change @@ -64,20 +64,27 @@ class BaseRecord : public Container<T_elem>
6464 friend class Mesh ;
6565
6666 using Data_t = internal::BaseRecordData<T_elem>;
67- std::shared_ptr<Data_t> m_baseRecordData{ new Data_t ()} ;
67+ std::shared_ptr<Data_t> m_baseRecordData;
6868
6969 inline Data_t const &get () const
7070 {
71- return dynamic_cast <Data_t const &>(* this -> m_attri ) ;
71+ return *m_baseRecordData ;
7272 }
7373
7474 inline Data_t &get ()
7575 {
76- return dynamic_cast <Data_t &>(* this -> m_attri ) ;
76+ return *m_baseRecordData ;
7777 }
7878
7979 BaseRecord ();
8080
81+ protected:
82+ inline void setData (std::shared_ptr<Data_t> data)
83+ {
84+ m_baseRecordData = std::move (data);
85+ Container<T_elem>::setData (m_baseRecordData);
86+ }
87+
8188public:
8289 using key_type = typename Container<T_elem>::key_type;
8390 using mapped_type = typename Container<T_elem>::mapped_type;
@@ -163,9 +170,9 @@ namespace internal
163170} // namespace internal
164171
165172template <typename T_elem>
166- BaseRecord<T_elem>::BaseRecord()
173+ BaseRecord<T_elem>::BaseRecord() : Container<T_elem>(Attributable::NoInit())
167174{
168- Attributable:: setData (std::make_shared<Data_t>());
175+ setData (std::make_shared<Data_t>());
169176}
170177
171178template <typename T_elem>
Original file line number Diff line number Diff line change @@ -103,18 +103,26 @@ class BaseRecordComponent : virtual public Attributable
103103
104104protected:
105105 using Data_t = internal::BaseRecordComponentData;
106+ std::shared_ptr<Data_t> m_baseRecordComponentData;
106107
107108 inline Data_t const &get () const
108109 {
109- return dynamic_cast <Data_t const &>(*m_attri) ;
110+ return *m_baseRecordComponentData ;
110111 }
111112
112113 inline Data_t &get ()
113114 {
114- return dynamic_cast <Data_t &>(*m_attri);
115+ return *m_baseRecordComponentData;
116+ }
117+
118+ inline void setData (std::shared_ptr<Data_t> data)
119+ {
120+ m_baseRecordComponentData = std::move (data);
121+ Attributable::setData (m_baseRecordComponentData);
115122 }
116123
117124 BaseRecordComponent ();
125+ BaseRecordComponent (NoInit);
118126}; // BaseRecordComponent
119127
120128namespace detail
Original file line number Diff line number Diff line change @@ -147,14 +147,22 @@ class Container : virtual public Attributable
147147 using ContainerData = internal::ContainerData<T, T_key, T_container>;
148148 using InternalContainer = T_container;
149149
150+ std::shared_ptr<ContainerData> m_containerData;
151+
152+ inline void setData (std::shared_ptr<ContainerData> containerData)
153+ {
154+ m_containerData = std::move (containerData);
155+ Attributable::setData (m_containerData);
156+ }
157+
150158 inline InternalContainer const &container () const
151159 {
152- return dynamic_cast <ContainerData const &>(*m_attri). m_container ;
160+ return m_containerData-> m_container ;
153161 }
154162
155163 inline InternalContainer &container ()
156164 {
157- return dynamic_cast <ContainerData &>(*m_attri). m_container ;
165+ return m_containerData-> m_container ;
158166 }
159167
160168public:
@@ -442,10 +450,13 @@ OPENPMD_protected
442450 flushAttributes (flushParams);
443451 }
444452
445- Container ()
453+ Container () : Attributable(NoInit())
446454 {
447- Attributable:: setData (std::make_shared<ContainerData>());
455+ setData (std::make_shared<ContainerData>());
448456 }
457+
458+ Container (NoInit) : Attributable(NoInit())
459+ {}
449460};
450461
451462namespace internal
Original file line number Diff line number Diff line change @@ -118,17 +118,24 @@ OPENPMD_protected
118118
119119 using Data_t = internal::PatchRecordComponentData;
120120
121+ std::shared_ptr<Data_t> m_patchRecordComponentData;
122+
121123 PatchRecordComponent ();
122124
123125 inline Data_t const &get () const
124126 {
125- return dynamic_cast <Data_t const &>(*m_attri) ;
127+ return *m_patchRecordComponentData ;
126128 }
127129
128130 inline Data_t &get ()
129131 {
130- auto &res = dynamic_cast <Data_t &>(*m_attri);
131- return res;
132+ return *m_patchRecordComponentData;
133+ }
134+
135+ inline void setData (std::shared_ptr<Data_t> data)
136+ {
137+ m_patchRecordComponentData = std::move (data);
138+ BaseRecordComponent::setData (m_patchRecordComponentData);
132139 }
133140}; // PatchRecordComponent
134141
Original file line number Diff line number Diff line change @@ -36,9 +36,9 @@ namespace openPMD
3636using internal::CloseStatus;
3737using internal::DeferredParseAccess;
3838
39- Iteration::Iteration ()
39+ Iteration::Iteration () : Attributable(NoInit())
4040{
41- Attributable:: setData (std::make_shared<internal::IterationData >());
41+ setData (std::make_shared<Data_t >());
4242 setTime (static_cast <double >(0 ));
4343 setDt (static_cast <double >(1 ));
4444 setTimeUnitSI (1 );
Original file line number Diff line number Diff line change @@ -40,9 +40,9 @@ namespace internal
4040 RecordComponentData::RecordComponentData () = default ;
4141} // namespace internal
4242
43- RecordComponent::RecordComponent ()
43+ RecordComponent::RecordComponent () : BaseRecordComponent(NoInit())
4444{
45- Attributable:: setData (std::make_shared<internal::RecordComponentData >());
45+ setData (std::make_shared<Data_t >());
4646 setUnitSI (1 );
4747}
4848
You can’t perform that action at this time.
0 commit comments