Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
SimpleCsvReaderWriter.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/* SimpleCsvReaderWriter.h (C) 2000-2022 */
9/* */
10/* Class allowing reading and writing a file in CSV format. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_STD_SIMPLECSVREADERWRITER_H
13#define ARCANE_STD_SIMPLECSVREADERWRITER_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ISimpleTableReaderWriter.h"
18
19#include "arcane/utils/FatalErrorException.h"
20
21#include "arcane/core/Directory.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
32class SimpleCsvReaderWriter
34{
35 public:
36
37 SimpleCsvReaderWriter(const Ref<SimpleTableInternal>& simple_table_internal)
38 : m_simple_table_internal(simple_table_internal)
39 , m_separator(';')
40 , m_precision_print(6)
41 , m_is_fixed_print(false)
42 , m_scientific_notation(false)
43 {
44 if (simple_table_internal.isNull())
45 ARCANE_FATAL("The reference passed as a parameter is Null.");
46 }
47
48 SimpleCsvReaderWriter()
49 : m_simple_table_internal()
50 , m_separator(';')
51 , m_precision_print(6)
52 , m_is_fixed_print(false)
53 , m_scientific_notation(false)
54 {
55 }
56
57 ~SimpleCsvReaderWriter() = default;
58
59 public:
60
61 bool writeTable(const Directory& dst, const String& file_name) override;
62 bool readTable(const Directory& src, const String& file_name) override;
63 void clearInternal() override;
64 void print() override;
65
66 Integer precision() override;
67 void setPrecision(Integer precision) override;
68
69 bool isFixed() override;
70 void setFixed(bool fixed) override;
71
72 bool isForcedToUseScientificNotation() override;
73 void setForcedToUseScientificNotation(bool use_scientific) override;
74
75 String fileType() override { return m_output_file_type; };
76
78 void setInternal(const Ref<SimpleTableInternal>& simple_table_internal) override;
79
80 protected:
81
82 bool _openFile(std::ifstream& stream, Directory directory, const String& file);
83 void _closeFile(std::ifstream& stream);
84 void _print(std::ostream& stream);
85
86 protected:
87
88 Ref<SimpleTableInternal> m_simple_table_internal;
89
90 char m_separator;
91
92 Integer m_precision_print;
93 bool m_is_fixed_print;
94 bool m_scientific_notation;
95
96 const String m_output_file_type = "csv";
97};
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102} // End namespace Arcane
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
106
107#endif
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
Class managing a directory.
Definition Directory.h:36
Class interface allowing reading a file and writing a file with or from a SimpleTableInternal.
bool isNull() const
Indicates if the counter references a non-null instance.
Reference to an instance.
void setFixed(bool fixed) override
Method allowing setting or unsetting the 'std::fixed' flag.
void setInternal(const Ref< SimpleTableInternal > &simple_table_internal) override
Method allowing setting a reference to a SimpleTableInternal.
bool isForcedToUseScientificNotation() override
Method allowing checking if the 'std::scientific' flag is active or not for writing values.
void clearInternal() override
Method allowing clearing the content of the SimpleTableInternal object.
void setForcedToUseScientificNotation(bool use_scientific) override
Method allowing setting or unsetting the 'std::scientific' flag.
bool readTable(const Directory &src, const String &file_name) override
Method allowing reading a file containing a simple table.
String fileType() override
Method allowing retrieval of the file type that will be written by the implementation....
void print() override
Method allowing writing the table to the standard output.
bool isFixed() override
Method allowing checking if the 'std::fixed' flag is active or not for writing values.
Ref< SimpleTableInternal > internal() override
Method allowing retrieval of a reference to the SimpleTableInternal object used.
bool writeTable(const Directory &dst, const String &file_name) override
Method allowing writing a simple table to a file.
void setPrecision(Integer precision) override
Method allowing modification of the print precision.
Integer precision() override
Method allowing retrieval of the precision currently used for writing values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.