Borderbasix

mdebug.hpp
Go to the documentation of this file.
1 #ifndef MDEBUG_HPP
2 #define MDEBUG_HPP
3 #include <iostream>
4 #include <fstream>
5 #include <string>
6 
7 #ifndef MDEBUG_PREFIX
8 #define MDEBUG_PREFIX ""
9 #endif
10 
11 struct mdebug {
12 
13  enum mode {init, app};
14  mdebug(int l) {
15 #ifdef MDEBUG_COUT
16  m_level=l;
17 #endif
18  }
19 
20  mdebug( mode md = app) {
21 #ifdef MDEBUG_COUT
22  m_level=0;
23 #endif
24 #ifdef MDEBUG_FILE
25  m_file = std::string(MDEBUG_PREFIX)+"debug.txt";
26 
27  if (md == init) {
28  m_f.open (m_file.c_str(), std::fstream::out);
29  } else {
30  m_f.open (m_file.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
31  }
32 #endif
33  }
34 
35  mdebug(const char* file, mode md = app) {
36 #ifdef MDEBUG_COUT
37  m_level=0;
38 #endif
39 #ifdef MDEBUG_FILE
40  m_file = std::string(MDEBUG_PREFIX)+file;
41 
42  if (md == init) {
43  m_f.open (m_file.c_str(), std::fstream::out);
44  } else {
45  m_f.open (m_file.c_str(), std::fstream::in | std::fstream::out | std::fstream::app);
46  }
47 #endif
48  }
49 
50  ~mdebug() {
51 #ifdef MDEBUG_FILE
52  if(m_level<=verbose) m_f<<"\n";
53  m_f.close();
54 #endif
55 #ifdef MDEBUG_COUT
56  if(m_level <= verbose)
57  std::cout<<std::endl;
58 #endif
59  }
60 
61  void clear() {
62 #ifdef MDEBUG_FILE
63  m_f.close();
64  m_f.open (m_file.c_str(), std::fstream::out);
65 #endif
66  }
67 
68  template<class X>
69  mdebug& operator << (const X& x) {
70 #ifdef MDEBUG_FILE
71  if(m_level<=verbose) m_f<<x<<" ";
72 #endif
73 #ifdef MDEBUG_COUT
74  if(m_level<=verbose) std::cout<<x<<" ";
75 #endif
76  return *this;
77  }
78 #ifdef MDEBUG_FILE
79  std::fstream m_f;
80  std::string m_file;
81 #endif
82 #ifdef MDEBUG_COUT
83  int m_level;
84  static int verbose;
85 #endif
86 };
87 #ifdef MDEBUG_COUT
88 int mdebug::verbose=0;
89 #endif
90 void mdebug_verbose(int l){
91 #ifdef MDEBUG_COUT
92  mdebug::verbose=l;
93 #endif
94 }
95 
96 #endif // MDEBUG_HPP
#define MDEBUG_PREFIX
Definition: mdebug.hpp:8
Definition: mdebug.hpp:13
MSKCONST char * file
Definition: mosek.h:2254
mdebug(int l)
Definition: mdebug.hpp:14
void mdebug_verbose(int l)
Definition: mdebug.hpp:90
MSKaccmodee MSKint32t MSKsoltypee MSKstakeye MSKrealt * x
Definition: mosek.h:3209
Definition: mdebug.hpp:13
Definition: mdebug.hpp:11
mdebug(const char *file, mode md=app)
Definition: mdebug.hpp:35
mdebug(mode md=app)
Definition: mdebug.hpp:20
void clear()
Definition: mdebug.hpp:61
mode
Definition: mdebug.hpp:13
mdebug & operator<<(const X &x)
Definition: mdebug.hpp:69
~mdebug()
Definition: mdebug.hpp:50
Home  |  Download & InstallContributions