Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
IosFile.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/* IosFile.cc (C) 2000-2021 */
9/* */
10/* Routines des Lecture/Ecriture d'un fichier. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/std/internal/IosFile.h"
15
16#include "arcane/utils/Iostream.h"
17#include "arcane/utils/IOException.h"
18#include "arcane/utils/ITraceMng.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29bool IosFile::
30isEnd()
31{
32 (*m_stream) >> ws;
33 return m_stream->eof();
34}
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39const char* IosFile::
40getNextLine(const char* comment_char)
41{
42 while (m_stream->good()) {
43 m_stream->getline(m_buf, sizeof(m_buf) - 1);
44 if (m_stream->eof())
45 break;
46 if (m_buf[0] == '\n' || m_buf[0] == '\r')
47 continue;
48 bool is_comment = true; // Comments are searched for by default
49 if (!comment_char)
50 is_comment = false; // If none has been set, just skip their track of it
51 // Regarde si un caractère de commentaire est présent
52 for (int i = 0; is_comment && i < IOS_BFR_SZE && m_buf[i] != '\0'; ++i) {
53 if (!isspace(m_buf[i])) {
54 is_comment = (m_buf[i] == *comment_char);
55 break;
56 }
57 }
58
59 if (!is_comment) {
60 // Supprime le '\n' ou '\r' final
61 for (int i = 0; i < IOS_BFR_SZE && m_buf[i] != '\0'; ++i) {
62 //cout << " V=" << m_buf[i] << " I=" << (int)m_buf[i] << "\n";
63 if (m_buf[i] == '\n' || m_buf[i] == '\r') {
64 m_buf[i] = '\0';
65 break;
66 }
67 }
68 return m_buf;
69 }
70 }
71 throw IOException("IosFile::getNexLine()", "Unexpected EndOfFile");
72}
73
74/*---------------------------------------------------------------------------*/
75/*---------------------------------------------------------------------------*/
76
77const char* IosFile::
78getNextLine()
79{
80 return getNextLine(nullptr);
81}
82
83/*---------------------------------------------------------------------------*/
84/*---------------------------------------------------------------------------*/
85
86Real IosFile::
87getReal()
88{
89 Real v = 0.;
90 (*m_stream) >> ws >> v;
91 if (m_stream->good())
92 return v;
93 throw IOException("IosFile::getReal()", "Bad Real");
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99Integer IosFile::
100getInteger()
101{
102 Integer v = 0;
103 (*m_stream) >> ws >> v;
104 if (m_stream->good())
105 return v;
106 throw IOException("IosFile::getInteger()", "Bad Integer");
107}
108
109/*---------------------------------------------------------------------------*/
110/*---------------------------------------------------------------------------*/
111
112Int64 IosFile::
113getInt64()
114{
115 Int64 v = 0;
116 (*m_stream) >> ws >> v;
117 if (m_stream->good())
118 return v;
119 throw IOException("IosFile::getInteger()", "Bad Int64");
120}
121
122/*---------------------------------------------------------------------------*/
123/*---------------------------------------------------------------------------*/
124
125bool IosFile::
126lookForString(const String& str)
127{
128 const char* bfr = getNextLine();
129 // ITraceMng::info() << "[IosFile::getString] Looking for " << str;
130 std::istringstream iline(bfr);
131 std::string got;
132 iline >> got;
133 // info() << "[IosFile::getString] got=" << got;
134 return isEqualString(got, str);
135}
136
137/*---------------------------------------------------------------------------*/
138/*---------------------------------------------------------------------------*/
139
140void IosFile::
141checkString(const String& current_value, const String& expected_value)
142{
143 String current_value_low = current_value.lower();
144 String expected_value_low = expected_value.lower();
145
146 if (current_value_low != expected_value_low) {
147 String s = "Expecting chain '" + expected_value + "', found '" + current_value + "'";
148 throw IOException("IosFile::checkString()", s);
149 }
150}
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
155void IosFile::
156checkString(const String& current_value, const String& expected_value1, const String& expected_value2)
157{
158 String current_value_low = current_value.lower();
159 String expected_value1_low = expected_value1.lower();
160 String expected_value2_low = expected_value2.lower();
161
162 if (current_value_low != expected_value1_low && current_value_low != expected_value2_low) {
163 String s = "Expecting chain '" + expected_value1 + "' or '" + expected_value2 + "', found '" + current_value + "'";
164 throw IOException("IosFile::checkString()", s);
165 }
166}
167
168/*---------------------------------------------------------------------------*/
169/*---------------------------------------------------------------------------*/
170
171bool IosFile::
172isEqualString(const String& current_value, const String& expected_value)
173{
174 String current_value_low = current_value.lower();
175 String expected_value_low = expected_value.lower();
176 return (current_value_low == expected_value_low);
177}
178
179/*---------------------------------------------------------------------------*/
180/*---------------------------------------------------------------------------*/
181
182} // End namespace Arcane
183
184/*---------------------------------------------------------------------------*/
185/*---------------------------------------------------------------------------*/
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.