mexLog.h

Go to the documentation of this file.
00001 
00004 // This file is part of the SaliencyToolbox - Copyright (C) 2006-2007
00005 // by Dirk B. Walther and the California Institute of Technology.
00006 // See the enclosed LICENSE.TXT document for the license agreement. 
00007 // More information about this project is available at: 
00008 // http://www.saliencytoolbox.net
00009 
00010 #ifndef MEXLOG_H_DEFINED
00011 #define MEXLOG_H_DEFINED
00012 
00013 #include <streambuf>
00014 #include <iostream>
00015 #include <mex.h>
00016 
00017 #define ASSERT(exp) if (!(exp)) mexFatal("ASSERT failed in %s at line %d: " \
00018                                          #exp,__FILE__,__LINE__);
00019 
00021 void mexInfo(const char *fmt,...);
00022 
00024 void mexError(const char *fmt,...);
00025 
00027 void mexFatal(const char *fmt,...);
00028 
00030 void mexDebug(const char *fmt,...);
00031 
00032 // ######################################################################
00034 class MexBuf : public std::streambuf
00035 {
00036  public:
00037   MexBuf()  : std::streambuf() 
00038   { setbuf((char*)0,0); }
00039   
00040   virtual int overflow(int c)
00041   {
00042     if (c != EOF)
00043       mexPrintf("%c", c);
00044     return c;
00045   }
00046 
00047   virtual std::streamsize xsputn(const char* s, const std::streamsize n)
00048   {
00049     std::streamsize c = n;
00050     while (*s && c--)
00051       mexPrintf("%c", *s++);
00052     return n;
00053   }
00054 
00055 };
00056 
00057 // ######################################################################
00059 class MexBufInit
00060 {
00061  public:
00062   MexBufInit(MexBuf& buf)  
00063   {
00064     std::cout.rdbuf(&buf);
00065     std::cerr.rdbuf(&buf);
00066   }
00067 
00068   ~MexBufInit() {}
00069 
00070  private:
00071   MexBufInit(const MexBufInit&);
00072   MexBufInit& operator=(const MexBufInit&);
00073 };
00074 
00075 // ######################################################################
00076 namespace
00077 {
00078   static MexBuf mexbuf__;
00079   static MexBufInit mexbufInit__(mexbuf__);
00080 }
00081 
00082 #endif

Generated on Fri Sep 7 13:09:49 2007 for SaliencyToolbox by  doxygen 1.5.2