GranOO  3.0
A robust and versatile workbench to build 3D dynamic simulations based on the Discrete Element Method
Out.hpp
Go to the documentation of this file.
1 // This file is part of GranOO, a workbench for DEM simulation.
2 //
3 // Author(s) : - Damien Andre IRCER/UNILIM, Limoges France
4 // <damien.andre@unilim.fr>
5 // - Jean-luc Charles Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
6 // <jean-luc.charles@ensam.eu>
7 // - Jeremie Girardot Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
8 // <jeremie.girardot@ensam.eu>
9 // - Cedric Hubert LAMIH/UPHF, Valenciennes France
10 // <cedric.hubert@uphf.fr>
11 // - Ivan Iordanoff Arts et Metiers ParisTech, CNRS, I2M, Bordeaux France
12 // <ivan.iordanoff@ensam.eu>
13 //
14 // Copyright (C) 2008-2019 D. Andre, JL. Charles, J. Girardot, C. Hubert, I. Iordanoff
15 //
16 // This program is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 // This program is distributed in the hope that it will be useful,
22 // but WITHOUT ANY WARRANTY; without even the implied warranty of
23 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 // GNU General Public License for more details.
25 //
26 // You should have received a copy of the GNU General Public License
27 // along with this program. If not, see <http://www.gnu.org/licenses/>.
28 
29 
30 
31 #ifndef _LibCore_Out_HPP
32 #define _LibCore_Out_HPP
33 
34 #include <iosfwd>
35 
36 namespace GranOO3
37 {
38  namespace Core
39  {
40 
41  class Out
42  {
43  public:
44  enum Mode {GRANOO_NORMAL, GRANOO_WARNING, GRANOO_ERROR, GRANOO_DEBUG};
45 
46  public:
47  Out(Mode mode);
48  ~Out();
49 
50  std::ostream& newline();
51  std::ostream& ostream();
52  void flush();
54  void display_state();
55 
56  void set_ostream(std::ostream*);
57 
58  template<typename T> std::ostream & operator<<(const T& t); // standard msg
59 
60  private:
61  Out() = delete;
62  Out & operator=(const Out &) = delete;
63 
64  static std::string _warni_label;
65  static std::string _error_label;
66  static std::string _debug_label;
67 
68  private:
70  std::ostream* _os;
71  unsigned int _last_status;
72  };
73 
74 
75 
76  template<typename T>
77  std::ostream & Out::operator<<(const T& t) {
79 
80  switch (_mode) {
81  case GRANOO_NORMAL: (*_os) << t; break;
82  case GRANOO_WARNING: (*_os) << _warni_label << t; break;
83  case GRANOO_ERROR: (*_os) << _error_label << t; break;
84  case GRANOO_DEBUG: (*_os) << _debug_label << t; break;
85  }
86  return (*_os);
87  }
88 
89  }
90 }
91 
92 // Here it's a hack to use granoo::cout as granoo::cout
93 // You can use also granoo::cerr as error output
94 // and granoo::cwarn to display warning message
95 // Another hack allow to use granoo::endl instead of std::endl
96 class granoo
97 {
98 
99 public:
104 
105  struct granoo_endl {};
107 };
108 
109 std::ostream & operator<<(std::ostream& os, const granoo::granoo_endl& b);
110 std::ostream & operator<<(GranOO3::Core::Out& os, const granoo::granoo_endl& b);
111 
112 
113 #endif
114 
115 
116 
117 
118 
119 
120 
std::ostream & operator<<(std::ostream &os, const granoo::granoo_endl &b)
Definition: Out.cpp:105
Definition: Out.hpp:42
std::ostream * _os
Definition: Out.hpp:70
Mode
Definition: Out.hpp:44
static std::string _warni_label
Definition: Out.hpp:64
void display_state_if_needed()
Definition: Out.cpp:90
unsigned int _last_status
Definition: Out.hpp:71
Out & operator=(const Out &)=delete
~Out()
Definition: Out.cpp:59
std::ostream & operator<<(const T &t)
Definition: Out.hpp:77
void display_state()
Definition: Out.cpp:85
std::ostream & ostream()
Definition: Out.cpp:75
void flush()
Definition: Out.cpp:80
static std::string _debug_label
Definition: Out.hpp:66
void set_ostream(std::ostream *)
Definition: Out.cpp:63
std::ostream & newline()
Definition: Out.cpp:68
static std::string _error_label
Definition: Out.hpp:65
Mode _mode
Definition: Out.hpp:69
Definition: Out.hpp:97
static GranOO3::Core::Out cwarn
Definition: Out.hpp:102
static GranOO3::Core::Out cerr
Definition: Out.hpp:101
static GranOO3::Core::Out debug
Definition: Out.hpp:103
static granoo_endl endl
Definition: Out.hpp:106
static GranOO3::Core::Out cout
Definition: Out.hpp:100
Definition: Common.hpp:198
x y t t *t x y t t t x y t t t x *y t *t t x *y t *t t x y t t t x y t t t t(t+t)") define_sfop3(16
Definition: Out.hpp:105