1
1
// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2
2
// -----------------------------------------------------------------------------
3
- // Copyright 2000-2023 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
3
+ // Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4
4
// See the top-level COPYRIGHT file for details.
5
5
// SPDX-License-Identifier: Apache-2.0
6
6
// -----------------------------------------------------------------------------
7
7
/* ---------------------------------------------------------------------------*/
8
- /* BasicReader.cc (C) 2000-2023 */
8
+ /* BasicReader.cc (C) 2000-2024 */
9
9
/* */
10
10
/* Lecture simple pour les protections/reprises. */
11
11
/* ---------------------------------------------------------------------------*/
19
19
#include " arcane/utils/JSONReader.h"
20
20
#include " arcane/utils/IDataCompressor.h"
21
21
#include " arcane/utils/IHashAlgorithm.h"
22
+ #include " arcane/utils/Ref.h"
22
23
23
24
#include " arcane/core/IApplication.h"
24
25
#include " arcane/core/IXmlDocumentHolder.h"
@@ -50,24 +51,13 @@ BasicGenericReader(IApplication* app, Int32 version, Ref<KeyValueTextReader> tex
50
51
: TraceAccessor(app->traceMng ())
51
52
, m_application(app)
52
53
, m_text_reader(text_reader)
53
- , m_rank(A_NULL_RANK)
54
54
, m_version(version)
55
55
{
56
56
}
57
57
58
58
/* ---------------------------------------------------------------------------*/
59
59
/* ---------------------------------------------------------------------------*/
60
60
61
- BasicGenericReader::
62
- ~BasicGenericReader ()
63
- {
64
- for (const auto & x : m_variables_data_info)
65
- delete x.second ;
66
- }
67
-
68
- /* ---------------------------------------------------------------------------*/
69
- /* ---------------------------------------------------------------------------*/
70
-
71
61
void BasicGenericReader::
72
62
initialize (const String& path, Int32 rank)
73
63
{
@@ -143,7 +133,7 @@ initialize(const String& path, Int32 rank)
143
133
for (Integer i = 0 , is = variables_elem.size (); i < is; ++i) {
144
134
XmlNode n = variables_elem[i];
145
135
String var_full_name = n.attrValue (" full-name" );
146
- auto vdi = new VariableDataInfo (var_full_name, n);
136
+ Ref<VariableDataInfo> vdi = makeRef ( new VariableDataInfo (var_full_name, n) );
147
137
m_variables_data_info.insert (std::make_pair (var_full_name, vdi));
148
138
}
149
139
@@ -164,14 +154,14 @@ initialize(const String& path, Int32 rank)
164
154
/* ---------------------------------------------------------------------------*/
165
155
/* ---------------------------------------------------------------------------*/
166
156
167
- VariableDataInfo* BasicGenericReader::
157
+ Ref< VariableDataInfo> BasicGenericReader::
168
158
_getVarInfo (const String& full_name)
169
159
{
170
160
VariableDataInfoMap::const_iterator ivar = m_variables_data_info.find (full_name);
171
161
if (ivar == m_variables_data_info.end ())
172
162
ARCANE_THROW (ReaderWriterException,
173
163
" Can not find own metadata infos for data var={0} rank={1}" , full_name, m_rank);
174
- VariableDataInfo* vdi = ivar->second ;
164
+ Ref< VariableDataInfo> vdi = ivar->second ;
175
165
return vdi;
176
166
}
177
167
@@ -183,7 +173,7 @@ readData(const String& var_full_name, IData* data)
183
173
{
184
174
KeyValueTextReader* reader = m_text_reader.get ();
185
175
String vname = var_full_name;
186
- VariableDataInfo* vdi = _getVarInfo (vname);
176
+ Ref< VariableDataInfo> vdi = _getVarInfo (vname);
187
177
if (m_version < 3 )
188
178
reader->setFileOffset (vdi->fileOffset ());
189
179
@@ -354,18 +344,6 @@ initialize()
354
344
/* ---------------------------------------------------------------------------*/
355
345
/* ---------------------------------------------------------------------------*/
356
346
357
- BasicReader::
358
- ~BasicReader ()
359
- {
360
- for (const auto & i : m_parallel_data_readers)
361
- delete i.second ;
362
- for (const auto & r : m_global_readers)
363
- delete r;
364
- }
365
-
366
- /* ---------------------------------------------------------------------------*/
367
- /* ---------------------------------------------------------------------------*/
368
-
369
347
void BasicReader::
370
348
_directReadVal (VariableMetaData* varmd, IData* data)
371
349
{
@@ -396,7 +374,7 @@ _directReadVal(VariableMetaData* varmd, IData* data)
396
374
}
397
375
398
376
if (is_item_variable) {
399
- ParallelDataReader* parallel_data_reader = _getReader (varmd);
377
+ Ref< ParallelDataReader> parallel_data_reader = _getReader (varmd);
400
378
401
379
Int64UniqueArray full_written_unique_ids;
402
380
IData* full_written_data = nullptr ;
@@ -439,7 +417,7 @@ _directReadVal(VariableMetaData* varmd, IData* data)
439
417
/* ---------------------------------------------------------------------------*/
440
418
/* ---------------------------------------------------------------------------*/
441
419
442
- ParallelDataReader* BasicReader::
420
+ Ref< ParallelDataReader> BasicReader::
443
421
_getReader (VariableMetaData* varmd)
444
422
{
445
423
Int32 nb_to_read = m_nb_rank_to_read;
@@ -454,7 +432,7 @@ _getReader(VariableMetaData* varmd)
454
432
return ix->second ;
455
433
456
434
IParallelMng* pm = m_parallel_mng;
457
- auto reader = new ParallelDataReader (pm);
435
+ Ref<ParallelDataReader> reader = makeRef ( new ParallelDataReader (pm) );
458
436
{
459
437
UniqueArray<SharedArray<Int64>> written_unique_ids (nb_to_read);
460
438
Int64Array& wanted_unique_ids = reader->wantedUniqueIds ();
@@ -609,7 +587,7 @@ _setRanksToRead()
609
587
/* ---------------------------------------------------------------------------*/
610
588
/* ---------------------------------------------------------------------------*/
611
589
612
- IGenericReader* BasicReader::
590
+ Ref< IGenericReader> BasicReader::
613
591
_readOwnMetaDataAndCreateReader (Int32 rank)
614
592
{
615
593
String main_filename = _getBasicVariableFile (m_version, m_path, rank);
@@ -628,7 +606,7 @@ _readOwnMetaDataAndCreateReader(Int32 rank)
628
606
}
629
607
}
630
608
631
- auto r = new BasicGenericReader (m_application, m_version, text_reader);
609
+ auto r = makeRef<IGenericReader>( new BasicGenericReader (m_application, m_version, text_reader) );
632
610
r->initialize (m_path, rank);
633
611
return r;
634
612
}
0 commit comments