Skip to content
Snippets Groups Projects
Log.h 1.78 KiB
Newer Older
Stephen Smith's avatar
Stephen Smith committed
/*  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

}