Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bridgeIO.h
Go to the documentation of this file.
1 
14 #ifndef BRIDGEIO_INCLUDED
15 #define BRIDGEIO_INCLUDED
16 
17 #include <iostream>
18 #include <fstream>
19 #include <cstdarg>
20 
21 //#include "commonParameters.h"
22 #include "communicator.h"
23 
24 namespace Bridge {
26  {
31  };
32 
33  class BridgeIO {
34  public:
35  static const std::string class_name;
36 
37  public:
38  // Constructor
39  BridgeIO() : os_(0), ildg_os_(0), is_open_(false) {}
40  ~BridgeIO() {}
41 
42  // Constructor from a stream
43  void init(std::ostream& os)
44  {
45  os_ = &os;
46  is_open_ = true;
47  }
48 
49  void ildg_init(std::ostream& os)
50  {
51  ildg_os_ = &os;
52  }
53 
54  // verbose output for c style
55  // default verbose level, node 0
56  void crucial(const char *format, ...);
57  void general(const char *format, ...);
58  void detailed(const char *format, ...);
59  void paranoiac(const char *format, ...);
60 
61  // input verbose level, node 0
62  void crucial(VerboseLevel vl, const char *format, ...);
63  void general(VerboseLevel vl, const char *format, ...);
64  void detailed(VerboseLevel vl, const char *format, ...);
65  void paranoiac(VerboseLevel vl, const char *format, ...);
66 
67  // input verbose level, input node
68  void crucial(VerboseLevel vl, int node, const char *format, ...);
69  void general(VerboseLevel vl, int node, const char *format, ...);
70  void detailed(VerboseLevel vl, int node, const char *format, ...);
71  void paranoiac(VerboseLevel vl, int node, const char *format, ...);
72 
73  void ildg(const char *format, ...);
74 
75  std::ostream& getStream() { return *os_; }
76  std::ostream& getILDGStream() { return *ildg_os_; }
77 
78  // Is the stream open?
79  bool isOpen() { return is_open_; }
80 
81  static VerboseLevel set_verbose_level(const std::string& str);
82 
83  private:
84  // main method for verbose output for c style
85  inline void print(VerboseLevel level, VerboseLevel write_level,
86  int node, const char *format, va_list& arg)
87  {
88  if ((write_level <= level) && (Communicator::nodeid() == node)) {
89  //*os_ << Communicator::nodeid() << " " << node << " ";
90  vsprintf(buff_, format, arg);
91  *os_ << buff_;
92  }
93  }
94 
95  // Hide copy constructor and =
96  BridgeIO(const BridgeIO&) {}
97  void operator=(const BridgeIO&) {}
98 
99  private:
100  std::ostream *os_;
101  std::ostream *ildg_os_;
102  char buff_[1024];
103  bool is_open_;
104  };
105 
106  extern BridgeIO vout;
107 }
108 #endif //BRIDGE_IO_INCLUDED
BridgeIO vout
Definition: bridgeIO.cpp:207
void detailed(const char *format,...)
Definition: bridgeIO.cpp:50
void ildg_init(std::ostream &os)
Definition: bridgeIO.h:49
void general(const char *format,...)
Definition: bridgeIO.cpp:38
std::ostream * ildg_os_
Definition: bridgeIO.h:101
void operator=(const BridgeIO &)
Definition: bridgeIO.h:97
void ildg(const char *format,...)
Definition: bridgeIO.cpp:172
void init(std::ostream &os)
Definition: bridgeIO.h:43
BridgeIO(const BridgeIO &)
Definition: bridgeIO.h:96
void paranoiac(const char *format,...)
Definition: bridgeIO.cpp:62
bool isOpen()
Definition: bridgeIO.h:79
void crucial(const char *format,...)
Definition: bridgeIO.cpp:26
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:25
void print(VerboseLevel level, VerboseLevel write_level, int node, const char *format, va_list &arg)
Definition: bridgeIO.h:85
static const std::string class_name
Definition: bridgeIO.h:35
char buff_[1024]
Definition: bridgeIO.h:102
static int nodeid()
alternative name for self().
Definition: communicator.h:88
std::ostream * os_
Definition: bridgeIO.h:100
std::ostream & getILDGStream()
Definition: bridgeIO.h:76
std::ostream & getStream()
Definition: bridgeIO.h:75
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:191