TrioCFD 1.9.9_beta
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> // For EOF on GNU >= 4.4
25#include <arch.h> // for LIBLATAFILTER int64
26#include <cstdint>// For INT32_MAX on 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 // Constructors
45 Entree();
46 Entree(istream& is);
47 Entree(const Entree& is);
48 virtual ~Entree();
49
50 void set_bin(bool bin) override;
51
52 // Assignment operators
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 // Inline method to handle the trivial case quickly. Otherwise, calls the virtual method 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 (e.g. LecFicDiffuse) can set it temporarily 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// Class returned by Entree when an exception is raised on error
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)
This function is called by operator>>, get, get_nom, ouvrir, fermer, lire, etc.
Definition Entree.cpp:339
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)
Sets the diffuse flag for this input stream.
Definition Entree.cpp:409
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)
Changes the error behaviour of the input; see error_handle_() and get_error_action().
Definition Entree.cpp:379
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
Changes the file write mode.
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()
Returns error_action_ for this input (allows modifying it and restoring the previous value afterwards...
Definition Entree.cpp:371
virtual void set_check_types(bool flag)
Indicates whether the stream should verify the types of read objects (ints and floating-point numbers...
Definition Entree.cpp:313
class Nom: a character string for naming TRUST objects.
Definition Nom.h:31
Base class for TRUST objects (Objet_U).
Definition Objet_U.h:68
Class TRUST_Ref_Objet_U.
Definition TRUST_Ref.h:117