TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Sortie.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 Sortie_included
17#define Sortie_included
18
19#include <AbstractIO.h>
20#include <iostream>
21#include <assert.h>
22#include <arch.h>
23#include <string>
24#include <memory>
25
26using std::ostream;
27using std::flush;
28using std::endl;
29using std::cerr;
30using std::ends;
31using std::cout;
32using std::ios;
33using std::cin;
34
35template <typename T> class TRUST_Ref;
37class Separateur;
38class Objet_U;
39
40/*! @brief Classe de base des flux de sortie.
41 *
42 * Elle sait ecrire des types simples (entiers, flottants) et des Objet_U (via printOn de l'objet_U)
43 * Attention, certains classes derivees sont paralleles: dans ce cas, il faut appeler
44 * syncfile() periodiquement sur tous les processeurs. Voir class EcrFicPartage
45 * Attention: pour ecrire correctement un flux a la fois en ASCII et BINAIRE,
46 * il faut utiliser un Separateur (finl ou space) pour separer les objets ecrits.
47 *
48 * @sa Entree
49 */
50
51class Sortie: public AbstractIO
52{
53public:
54 Sortie();
55 Sortie(ostream& os);
56 Sortie(const Sortie& os);
57 virtual ~Sortie() {}
58
59 Sortie& operator=(ostream& os);
61
62 void set_bin(bool bin) override;
63
64 inline ostream& get_ostream() { return *ostream_; }
65 inline const ostream& get_ostream() const { return *ostream_; }
66 inline void set_col_width(int w) { col_width_ = w; }
67
68 Sortie& operator <<(ostream& (*f)(ostream&));
70 Sortie& operator <<(ios& (*f)(ios&));
71
72 virtual Sortie& flush();
73 virtual Sortie& lockfile();
74 virtual Sortie& unlockfile();
75 virtual Sortie& syncfile();
76 virtual void setf(IOS_FORMAT);
77 virtual void precision(int);
78
79 template <typename T>
80 Sortie& operator<<(const TRUST_Ref<T>& ) { std::cerr << __func__ << " :: SHOULD NOT BE CALLED ! Use -> !! " << std::endl ; throw; }
81
82 Sortie& operator<<(const TRUST_Ref_Objet_U& ) { std::cerr << __func__ << " :: SHOULD NOT BE CALLED ! Use -> !! " << std::endl ; throw; }
83
84 virtual Sortie& operator<<(const Separateur& );
85 virtual Sortie& operator<<(const Objet_U& ob);
86 virtual Sortie& operator<<(const int ob);
87 virtual Sortie& operator<<(const unsigned ob);
88 virtual Sortie& operator<<(const long ob);
89 virtual Sortie& operator<<(const long long ob);
90 virtual Sortie& operator<<(const unsigned long ob);
91 virtual Sortie& operator<<(const float ob);
92 virtual Sortie& operator<<(const double ob);
93 virtual Sortie& operator<<(const char * ob);
94 virtual Sortie& operator<<(const std::string& str);
95
96 virtual int add_col(const double ob);
97 virtual int add_col(const char * ob);
98
99 // The put methods can potentially write long stream of data (std::streamsize == ptrdiff_t == long)
100 // but in many derived classes only used after the Scatter (e.g. LecFicDiffuse) we downcast to int inside impl.
101 virtual int put(const unsigned* ob, std::streamsize n, std::streamsize nb_colonnes=1);
102 virtual int put(const int* ob, std::streamsize n, std::streamsize nb_colonnes=1);
103 virtual int put(const float * ob, std::streamsize n, std::streamsize nb_colonnes=1);
104 virtual int put(const double* ob, std::streamsize n, std::streamsize nb_colonnes=1);
105 virtual int put(const long * ob, std::streamsize n, std::streamsize nb_colonnes=1);
106 virtual int put(const long long * ob, std::streamsize n, std::streamsize nb_colonnes=1);
107
108 inline bool has_ostream() const { return ostream_ != nullptr; }
109
110protected:
112
113 /*! A smart pointer to a std::ostream object, or any of its derived class.
114 * Explicit construction might be done in derived classes of Sortie.
115 */
116 std::unique_ptr<ostream> ostream_;
117
118private:
119 template <typename _TYPE_>
120 int put_template(const _TYPE_* ob, std::streamsize n, std::streamsize nb_col);
121
122 template <typename _TYPE_>
123 Sortie& operator_template(const _TYPE_& );
124};
125
126#endif /* Sortie_included */
classe Objet_U Cette classe est la classe de base des Objets de TRUST
Definition Objet_U.h:73
Separateur pour les fichiers.
Definition Separateur.h:30
Classe de base des flux de sortie.
Definition Sortie.h:52
bool has_ostream() const
Definition Sortie.h:108
virtual Sortie & flush()
Definition Sortie.cpp:138
ostream & get_ostream()
Definition Sortie.h:64
Sortie()
Definition Sortie.cpp:26
virtual ~Sortie()
Definition Sortie.h:57
virtual int put(const unsigned *ob, std::streamsize n, std::streamsize nb_colonnes=1)
Definition Sortie.cpp:101
Sortie & operator<<(const TRUST_Ref_Objet_U &)
Definition Sortie.h:82
void set_bin(bool bin) override
Change le mode d'ecriture du fichier.
Definition Sortie.cpp:255
virtual Sortie & unlockfile()
Definition Sortie.cpp:180
Sortie & operator<<(ostream &(*f)(ostream &))
Definition Sortie.cpp:116
virtual Sortie & lockfile()
Definition Sortie.cpp:173
virtual void precision(int)
Definition Sortie.cpp:40
void set_col_width(int w)
Definition Sortie.h:66
const ostream & get_ostream() const
Definition Sortie.h:65
Sortie & operator<<(const TRUST_Ref< T > &)
Definition Sortie.h:80
int col_width_
Definition Sortie.h:111
Sortie & operator=(ostream &os)
Definition Sortie.cpp:64
virtual int add_col(const double ob)
Definition Sortie.cpp:83
virtual void setf(IOS_FORMAT)
Definition Sortie.cpp:34
virtual Sortie & syncfile()
Definition Sortie.cpp:187
std::unique_ptr< ostream > ostream_
Definition Sortie.h:116
classe TRUST_Ref_Objet_U
Definition TRUST_Ref.h:117