Bridge++  Ver. 2.0.2
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 <string>
20 #include <stack>
21 #include <cstdarg>
23 
25 
38 #define ENABLE_ILDG_TAG
39 
40 
41 namespace Bridge {
43  {
48  };
49 
50  class BridgeIO {
51  public:
52  static const std::string class_name;
53 
54  public:
55  // Constructor
56  BridgeIO(const std::string& filename = "stdout");
57  virtual ~BridgeIO();
58 
59  // set output to file or stream
60  void init(const std::string& filename);
61  void init(const std::ostream& os);
62 
63  // pop out current output stream
64  void unset();
65 
66  // verbose output for c style
67  // default verbose level, node 0
68  void crucial(const char *format, ...);
69  void general(const char *format, ...);
70  void detailed(const char *format, ...);
71  void paranoiac(const char *format, ...);
72 
73  // input verbose level, node 0
74  void crucial(VerboseLevel vl, const char *format, ...);
75  void general(VerboseLevel vl, const char *format, ...);
76  void detailed(VerboseLevel vl, const char *format, ...);
77  void paranoiac(VerboseLevel vl, const char *format, ...);
78 
79  // input verbose level, input node
80  void crucial(VerboseLevel vl, int node, const char *format, ...);
81  void general(VerboseLevel vl, int node, const char *format, ...);
82  void detailed(VerboseLevel vl, int node, const char *format, ...);
83  void paranoiac(VerboseLevel vl, int node, const char *format, ...);
84 
87  int indent_level() { return m_indent_level; }
88  void set_indent(const int level) { m_indent_level = level; }
89 
90  bool isOpen();
91 
92  std::ostream& getStream();
93 
94 #ifdef ENABLE_ILDG_TAG
95  void ildg_init(const std::ostream& os);
96  void ildg_init(const std::string& filename);
97 
98  void ildg(const char *format, ...);
99 
100  std::ostream& getILDGStream();
101 #endif
102 
103  // convert between VerboseLevel and string expression
104  static VerboseLevel set_verbose_level(const std::string& str);
105  static std::string get_verbose_level(const VerboseLevel vl);
106 
107  private:
108 
109  // Hide copy constructor and assignment.
110  BridgeIO(const BridgeIO&);
111  BridgeIO& operator=(const BridgeIO&);
112 
113  // main method for verbose output for c style
114  inline void print(VerboseLevel level, VerboseLevel write_level,
115  int node, const char *format, va_list& arg);
116 
117  // internal methods
118  void rewind_();
119  void tidyup_();
120 
121  private:
122 
123  // current output target
124  std::ostream *os_;
125 
126  // previous output targets
127  std::stack<std::ostream *> stack_;
128 
129  // workarea
130  char buff_[1024];
131 
132  static int m_indent_level;
133 
134 #ifdef ENABLE_ILDG_TAG
135  std::ostream *ildg_os_;
136 #endif
137  };
138 
139  extern BridgeIO vout;
140 }
141 #endif //BRIDGE_IO_INCLUDED
Bridge::PARANOIAC
@ PARANOIAC
Definition: bridgeIO.h:47
Bridge::BridgeIO::rewind_
void rewind_()
Definition: bridgeIO.cpp:102
Bridge::BridgeIO::ildg_os_
std::ostream * ildg_os_
Definition: bridgeIO.h:135
Bridge::BridgeIO::init
void init(const std::string &filename)
Definition: bridgeIO.cpp:53
Bridge::BridgeIO::os_
std::ostream * os_
Definition: bridgeIO.h:124
Bridge::BridgeIO::set_indent
void set_indent(const int level)
Definition: bridgeIO.h:88
Bridge::BridgeIO::decrease_indent
void decrease_indent()
Definition: bridgeIO.h:86
Bridge::BridgeIO::getILDGStream
std::ostream & getILDGStream()
Definition: bridgeIO.cpp:503
Bridge
Definition: bridgeIO.cpp:24
Bridge::BridgeIO::increase_indent
void increase_indent()
Definition: bridgeIO.h:85
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
Bridge::GENERAL
@ GENERAL
Definition: bridgeIO.h:45
Bridge::BridgeIO::unset
void unset()
Definition: bridgeIO.cpp:93
Bridge::BridgeIO::stack_
std::stack< std::ostream * > stack_
Definition: bridgeIO.h:127
Bridge::BridgeIO::~BridgeIO
virtual ~BridgeIO()
Definition: bridgeIO.cpp:46
Bridge::BridgeIO::paranoiac
void paranoiac(const char *format,...)
Definition: bridgeIO.cpp:238
Bridge::BridgeIO::tidyup_
void tidyup_()
Definition: bridgeIO.cpp:114
Bridge::BridgeIO::ildg_init
void ildg_init(const std::ostream &os)
Definition: bridgeIO.cpp:443
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
Bridge::BridgeIO
Definition: bridgeIO.h:50
Bridge::BridgeIO::operator=
BridgeIO & operator=(const BridgeIO &)
Bridge::BridgeIO::class_name
static const std::string class_name
Definition: bridgeIO.h:52
Bridge::BridgeIO::buff_
char buff_[1024]
Definition: bridgeIO.h:130
Bridge::BridgeIO::ildg
void ildg(const char *format,...)
Definition: bridgeIO.cpp:476
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Bridge::BridgeIO::BridgeIO
BridgeIO(const std::string &filename="stdout")
Definition: bridgeIO.cpp:29
Bridge::DETAILED
@ DETAILED
Definition: bridgeIO.h:46
Bridge::BridgeIO::m_indent_level
static int m_indent_level
Definition: bridgeIO.h:132
Bridge::BridgeIO::isOpen
bool isOpen()
Definition: bridgeIO.cpp:403
Bridge::BridgeIO::indent_level
int indent_level()
Definition: bridgeIO.h:87
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
communicator.h
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Bridge::BridgeIO::getStream
std::ostream & getStream()
Definition: bridgeIO.cpp:396
Bridge::CRUCIAL
@ CRUCIAL
Definition: bridgeIO.h:44
Bridge::BridgeIO::print
void print(VerboseLevel level, VerboseLevel write_level, int node, const char *format, va_list &arg)
Definition: bridgeIO.cpp:412
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
Bridge::BridgeIO::get_verbose_level
static std::string get_verbose_level(const VerboseLevel vl)
Definition: bridgeIO.cpp:154