Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
MemoryDataReaderWriter.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* MemoryDataReaderWriter.cc (C) 2000-2009 */
9/* */
10/* Lecture/ecriture des données en mémoire. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/Collection.h"
15#include "arcane/utils/Enumerator.h"
16#include "arcane/utils/NotImplementedException.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/TraceInfo.h"
19#include "arcane/utils/Ref.h"
20
21#include "arcane/IData.h"
22#include "arcane/IVariable.h"
23#include "arcane/VariableCollection.h"
24
25#include "arcane/impl/MemoryDataReaderWriter.h"
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30ARCANE_BEGIN_NAMESPACE
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35MemoryDataReaderWriter::
36~MemoryDataReaderWriter()
37{
38 free();
39}
40
41/*---------------------------------------------------------------------------*/
42/*---------------------------------------------------------------------------*/
43
44void MemoryDataReaderWriter::
45free()
46{
47 m_vars_to_data.clear();
48}
49
50/*---------------------------------------------------------------------------*/
51/*---------------------------------------------------------------------------*/
52
53void MemoryDataReaderWriter::
54beginWrite(const VariableCollection& vars)
55{
56 // Copie la table courante et enlève toutes les références aux variables
57 // que l'on va sauver. Une fois ceci terminé, il ne reste que des
58 // références à des variables plus utilisées. On libère donc
59 // le IData correspondant.
60 VarToDataMap vars_to_data = m_vars_to_data;
61 for( VariableCollection::Enumerator ivar(vars); ++ivar; ){
62 IVariable* var = *ivar;
63 VarToDataMap::iterator i = vars_to_data.find(var->fullName());
64 if (i!=vars_to_data.end())
65 vars_to_data.erase(i);
66 }
67
68 for( VarToDataMap::iterator i=vars_to_data.begin(); i!=vars_to_data.end(); ++i ){
69 // Supprime la référence à la table courante et détruit la donnée
70 m_vars_to_data.erase(i->first);
71 }
72}
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77void MemoryDataReaderWriter::
78write(IVariable* var,IData* data)
79{
80 Ref<IData> cdata = _findData(var);
81 if (!cdata.get()){
82 cdata = data->cloneRef();
83 m_vars_to_data.insert(std::make_pair(var->fullName(),cdata));
84 }
85 else{
86 cdata->copy(data);
87 }
88}
89
90/*---------------------------------------------------------------------------*/
91/*---------------------------------------------------------------------------*/
92
93void MemoryDataReaderWriter::
94read(IVariable* var,IData* data)
95{
96 Ref<IData> cdata = _findData(var);
97 if (!cdata.get()){
98 warning() << A_FUNCNAME << ": "
99 << String::format("can not find data for variable '{0}': variable will not be restored",
100 var->fullName());
101 return;
102 }
103 data->copy(cdata.get());
104}
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108
109Ref<IData> MemoryDataReaderWriter::
110_findData(IVariable* var)
111{
112 auto i = m_vars_to_data.find(var->fullName());
113 if (i==m_vars_to_data.end())
114 return {};
115 return i->second;
116}
117
118/*---------------------------------------------------------------------------*/
119/*---------------------------------------------------------------------------*/
120
121ARCANE_END_NAMESPACE
122
123/*---------------------------------------------------------------------------*/
124/*---------------------------------------------------------------------------*/
125
Interface d'une donnée.
Definition IData.h:33
virtual void copy(const IData *data)=0
Copie la donnée data dans l'instance courante.
virtual Ref< IData > cloneRef()=0
Clone la donnée.
Interface d'une variable.
Definition IVariable.h:54
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120