Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ISimpleTableReaderWriter.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* ISimpleTableReaderWriter.h (C) 2000-2025 */
9/* */
10/* Interface representing a simple table reader/writer. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ISIMPLETABLEREADERWRITER_H
13#define ARCANE_CORE_ISIMPLETABLEREADERWRITER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ISimpleTableInternalMng.h"
18
19#include "arcane/core/Directory.h"
20#include "arcane/core/IParallelMng.h"
22#include "arcane/utils/Iostream.h"
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
38class ARCANE_CORE_EXPORT SimpleTableReaderWriterUtils
39{
40 public:
41
52 static bool createDirectoryOnlyProcess0(IParallelMng* parallel_mng, const Directory& directory)
53 {
54 int sf = 0;
55 if (parallel_mng->commRank() == 0) {
56 sf = directory.createDirectory();
57 }
58 if (parallel_mng->commSize() > 1) {
59 sf = parallel_mng->reduce(Parallel::ReduceMax, sf);
60 }
61 return sf == 0;
62 };
63
72 static bool isFileExist(const Directory& directory, const String& file)
73 {
74 std::ifstream stream;
75 stream.open(directory.file(file).localstr(), std::ifstream::in);
76 bool fin = stream.good();
77 stream.close();
78 return fin;
79 };
80};
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
98class ARCANE_CORE_EXPORT ISimpleTableReaderWriter
99{
100 public:
101
102 virtual ~ISimpleTableReaderWriter() = default;
103
104 public:
105
127 virtual bool writeTable(const Directory& dst, const String& file_name) = 0;
128
160 virtual bool readTable(const Directory& src, const String& file_name) = 0;
161
166 virtual void clearInternal() = 0;
167
175 virtual void print() = 0;
176
183 virtual Integer precision() = 0;
184
201 virtual void setPrecision(Integer precision) = 0;
202
210 virtual bool isFixed() = 0;
231 virtual void setFixed(bool fixed) = 0;
232
251 virtual void setForcedToUseScientificNotation(bool use_scientific) = 0;
252
260 virtual String fileType() = 0;
261
269
276 virtual void setInternal(const Ref<SimpleTableInternal>& simple_table_internal) = 0;
277};
278
279/*---------------------------------------------------------------------------*/
280/*---------------------------------------------------------------------------*/
281
282} // End namespace Arcane
283
284/*---------------------------------------------------------------------------*/
285/*---------------------------------------------------------------------------*/
286
287#endif
Declarations of types on entities.
Class managing a directory.
Definition Directory.h:36
String file(const String &file_name) const override
Returns the full path of the file file_name in the directory.
Definition Directory.cc:120
bool createDirectory() const override
Creates the directory.
Definition Directory.cc:102
Interface of the parallelism manager for a subdomain.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual Int32 commSize() const =0
Number of instances in the communicator.
virtual char reduce(eReduceType rt, char v)=0
Performs a reduction of type rt on the real v and returns the value.
Class interface allowing reading a file and writing a file with or from a SimpleTableInternal.
virtual bool isForcedToUseScientificNotation()=0
Method allowing checking if the 'std::scientific' flag is active or not for writing values.
virtual bool writeTable(const Directory &dst, const String &file_name)=0
Method allowing writing a simple table to a file.
virtual void setPrecision(Integer precision)=0
Method allowing modification of the print precision.
virtual void setInternal(const Ref< SimpleTableInternal > &simple_table_internal)=0
Method allowing setting a reference to a SimpleTableInternal.
virtual Integer precision()=0
Method allowing retrieval of the precision currently used for writing values.
virtual bool isFixed()=0
Method allowing checking if the 'std::fixed' flag is active or not for writing values.
virtual bool readTable(const Directory &src, const String &file_name)=0
Method allowing reading a file containing a simple table.
virtual void setFixed(bool fixed)=0
Method allowing setting or unsetting the 'std::fixed' flag.
virtual Ref< SimpleTableInternal > internal()=0
Method allowing retrieval of a reference to the SimpleTableInternal object used.
virtual void setForcedToUseScientificNotation(bool use_scientific)=0
Method allowing setting or unsetting the 'std::scientific' flag.
virtual String fileType()=0
Method allowing retrieval of the file type that will be written by the implementation....
virtual void clearInternal()=0
Method allowing clearing the content of the SimpleTableInternal object.
virtual void print()=0
Method allowing writing the table to the standard output.
Reference to an instance.
Class containing two static methods useful for implementations.
static bool createDirectoryOnlyProcess0(IParallelMng *parallel_mng, const Directory &directory)
Static method allowing the creation of a directory with multiple processes.
static bool isFileExist(const Directory &directory, const String &file)
Static method allowing verification of file existence.
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
Definition String.cc:229
@ ReduceMax
Maximum of values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.