Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Log.h
Mark Woolrich, FMRIB Image Analysis Group
Copyright (C) 1999-2000 University of Oxford */
/* CCOPYRIGHT */
#include <iostream>
#include <fstream>
#include <string>
#include "newmatap.h"
#include "newmatio.h"
using namespace NEWMAT;
namespace UTILS{
#if !defined(__Log_h)
#define __Log_h
class Log
{
public:
static Log& getInstance();
~Log() { delete logger; }
void establishDir(const string& name);
void setDir(const string& name);
void setLogFile(const string& name) {logfilename = name;}
const string& getDir() const { return dir; }
void out(const string& p_fname, const Matrix& p_mat);
void out(const string& p_fname, const RowVector& p_mat);
void out(const string& p_fname, const ColumnVector& p_mat);
ofstream& str() { return logfileout; }
private:
Log() {}
const Log& operator=(Log&);
Log(Log&);
static Log* logger;
string dir;
ofstream logfileout;
string logfilename;
};
inline void Log::out(const string& p_fname, const Matrix& p_mat)
{
ofstream out;
out.open((dir + "/" + p_fname).c_str(), ios::out);
out << "/Matrix" << endl;
out << p_mat;
out.close();
}
inline void Log::out(const string& p_fname, const ColumnVector& p_mat)
{
ofstream out;
out.open((dir + "/" + p_fname).c_str(), ios::out);
out << p_mat;
out.close();
}
inline void Log::out(const string& p_fname, const RowVector& p_mat)
{
ofstream out;
out.open((dir + "/" + p_fname).c_str(), ios::out);
out << p_mat;
out.close();
}
inline Log& Log::getInstance(){
if(logger == NULL)
logger = new Log();
return *logger;
}
#endif
}