TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Entree.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Entree_included
17#define Entree_included
18
19#include <Process.h>
20#include <AbstractIO.h>
21#include <iostream>
22#include <assert.h>
23#include <stdio.h>
24#include <cstdio> // Pour EOF sur GNU >= 4.4
25#include <arch.h> // pour LIBLATAFILTER int64
26#include <cstdint>// Pour INT32_MAX sur GNU >= 13
27
28using std::istream;
29using std::ios;
30
31template <typename T> class TRUST_Ref;
33class Objet_U;
34class Nom;
35
36/*! @brief Class defining operators and methods for all reading operation in an input flow (file, keyboard
37 * communication buffer, etc.)
38 *
39 * @sa Sortie
40 */
41class Entree: public AbstractIO
42{
43public:
44 // Constructeurs
45 Entree();
46 Entree(istream& is);
47 Entree(const Entree& is);
48 virtual ~Entree();
49
50 void set_bin(bool bin) override;
51
52 // Operateurs d'affectation
53 Entree& operator=(istream& is);
55
56 virtual istream& get_istream();
57 virtual const istream& get_istream() const;
58 void set_istream(istream *is);
59
61 Entree& operator >>(istream& (*f)(istream&));
62 Entree& operator >>(ios& (*f)(ios&));
63
64 template <typename T>
65 Entree& operator>>(const TRUST_Ref<T>& ) { std::cerr << __func__ << " :: SHOULD NOT BE CALLED ! Use -> !! " << std::endl ; throw; }
66
67 Entree& operator>>(const TRUST_Ref_Objet_U& ) { std::cerr << __func__ << " :: SHOULD NOT BE CALLED ! Use -> !! " << std::endl ; throw; }
68
69 virtual Entree& operator>>(int& ob);
70 virtual Entree& operator>>(long& ob);
71 virtual Entree& operator>>(long long& ob);
72 virtual Entree& operator>>(float& ob);
73 virtual Entree& operator>>(double& ob);
74 virtual Entree& operator>>(std::string& ob);
75
76 // final
77 virtual Entree& operator>>(Objet_U& ob) final;
78
79 virtual int get(int *ob, std::streamsize n);
80 virtual int get(long *ob, std::streamsize n);
81 virtual int get(long long *ob, std::streamsize n);
82 virtual int get(float *ob, std::streamsize n);
83 virtual int get(double *ob, std::streamsize n);
84
85 virtual int get(char *buf, std::streamsize bufsize);
86
87 virtual int eof();
88 virtual int jumpOfLines();
89 virtual int fail();
90 virtual int good();
91 virtual void set_check_types(bool flag);
92 bool check_types() const { return check_types_; }
94 virtual void set_error_action(Error_Action);
96
97 inline operator istream& () { return get_istream(); }
98 inline istream& putback(char ch) { return get_istream().putback(ch); }
99 inline bool get_diffuse() { return diffuse_; }
100
101 virtual void set_diffuse(bool diffuse);
102
103protected:
104 // methode inline pour traiter rapidement le cas trivial. Sinon, appel a la methode virtuelle error_handle_()
105 inline int error_handle(int fail_flag)
106 {
107 if (!fail_flag) return 1;
108 else return error_handle_(fail_flag);
109 }
110
111 virtual int error_handle_(int fail_flag);
112 bool check_types_ = false;
114 bool diffuse_; // By default true, but some child classes (eg: LecFicDiffuse) could set temporary to false to not diffuse to other processes
115
116private:
117 istream *istream_;
118
119 template <typename _TYPE_>
120 int get_template(_TYPE_ *ob, std::streamsize n);
121
122 template <typename _TYPE_>
123 Entree& operator_template(_TYPE_& ob);
124};
125
126int is_a_binary_file(Nom&);
127
128void convert_to(const char *s, int& ob);
129void convert_to(const char *s, long& ob);
130void convert_to(const char *s, long long& ob);
131void convert_to(const char *s, float& ob);
132void convert_to(const char *s, double& ob);
133
134// Classe renvoyee par Entree si une exception est levee lors d'une erreur
136{
137};
138
139#endif
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
virtual int good()
Definition Entree.cpp:270
virtual int error_handle_(int fail_flag)
Cette fonction est appellee par operateur>>, get, get_nom ouvrir, fermer, lire, etc.
Definition Entree.cpp:342
bool get_diffuse()
Definition Entree.h:99
int error_handle(int fail_flag)
Definition Entree.h:105
Entree()
Definition Entree.cpp:24
Entree & operator>>(const TRUST_Ref_Objet_U &)
Definition Entree.h:67
virtual int fail()
Definition Entree.cpp:263
bool check_types_
Definition Entree.h:112
Entree & operator=(istream &is)
Definition Entree.cpp:72
virtual int get(int *ob, std::streamsize n)
Definition Entree.cpp:222
istream & putback(char ch)
Definition Entree.h:98
virtual void set_diffuse(bool diffuse)
ToDo TMA : commenter.
Definition Entree.cpp:410
Entree & operator>>(const TRUST_Ref< T > &)
Definition Entree.h:65
virtual ~Entree()
Definition Entree.cpp:277
virtual int jumpOfLines()
Definition Entree.cpp:238
bool diffuse_
Definition Entree.h:114
Error_Action
Definition Entree.h:93
@ ERROR_EXCEPTION
Definition Entree.h:93
@ ERROR_EXIT
Definition Entree.h:93
@ ERROR_CONTINUE
Definition Entree.h:93
virtual void set_error_action(Error_Action)
Change le comportement en cas d'erreur de l'entree, voir error_handle_() et get_error_action().
Definition Entree.cpp:382
Error_Action error_action_
Definition Entree.h:113
Entree & operator>>(Entree &(*f)(Entree &))
Definition Entree.cpp:55
virtual int eof()
Definition Entree.cpp:256
virtual istream & get_istream()
Definition Entree.cpp:41
void set_bin(bool bin) override
Change le mode d'ecriture du fichier.
Definition Entree.cpp:291
void set_istream(istream *is)
Definition Entree.cpp:50
bool check_types() const
Definition Entree.h:92
Error_Action get_error_action()
renvoie error_action_ pour cette entree (permet de la modifier et de restaurer ensuite la valeur ante...
Definition Entree.cpp:374
virtual void set_check_types(bool flag)
indique si le stream doit verifier les types des objets lus (ints et nombres flottants).
Definition Entree.cpp:313
class Nom Une chaine de caractere pour nommer les objets de TRUST
Definition Nom.h:31
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
classe TRUST_Ref_Objet_U
Definition TRUST_Ref.h:117