Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

Utils.h

Go to the documentation of this file.
00001 /* WARANTY NOTICE AND COPYRIGHT
00002 This program is free software; you can redistribute it and/or
00003 modify it under the terms of the GNU General Public License
00004 as published by the Free Software Foundation; either version 2
00005 of the License, or (at your option) any later version.
00006 
00007 This program is distributed in the hope that it will be useful,
00008 but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010 GNU General Public License for more details.
00011 
00012 You should have received a copy of the GNU General Public License
00013 along with this program; if not, write to the Free Software
00014 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00015 
00016 Copyright (C) Michael J. Meyer
00017 
00018 matmjm@mindspring.com
00019 spyqqqdia@yahoo.com
00020 
00021 */
00022 
00023 #ifndef martingale_utils_h
00024 #define martingale_utils_h
00025 
00026 
00027 #include <string>
00028 #include <sstream>
00029 #include "TypedefsMacros.h"
00030 
00031 
00032 MTGL_BEGIN_NAMESPACE(Martingale)
00033 
00034 
00035 
00036 
00037 /***************************************************************************************
00038 
00039                                   TIMING
00040 
00041 ***************************************************************************************/
00042 
00043 
00044 class Timer {
00045         
00046         double before, 
00047                after;   // system time in seconds
00048         
00049 public:
00050         Timer(){ before=0; after=0; }
00051     void start(){ before=clock()/CLOCKS_PER_SEC; }
00052         void stop(){  after=clock()/CLOCKS_PER_SEC;  }
00053         
00055         void report(string message);    
00056         
00057 }; // end Timer
00058 
00059 
00060 /***************************************************************************************
00061 
00062                 STRING REPRESENTATION OF VARIOUS OBJECTS
00063 
00064 ***************************************************************************************/
00065  
00066 
00070 template<class T>
00071 class Type_t {
00072 
00073     T t;
00074 
00075 public:
00076         
00077     Type_t(T t0): t(t0) { }
00078   
00079     string toString()
00080     {
00081          ostringstream os;
00082          os<<t;
00083          return os.str();
00084     }
00085         
00086 }; // end Type_t
00087 
00088 
00089 
00090 typedef Type_t<int> Int_t;
00091 typedef Type_t<long> Long_t;
00092 typedef Type_t<double> Double_t;
00093 typedef Type_t<long double> LongDouble_t;
00094 typedef Type_t<Real> Real_t;
00095 
00096 
00099 template<class C>
00100 std::ostream& operator << (std::ostream& os, const C& c)
00101 {
00102         return c.printSelf(os);
00103 }
00104 
00105 
00106 
00107 
00108 /***************************************************************************************
00109 
00110                  Loop Status
00111 
00112 ***************************************************************************************/
00113 
00114 
00120 class LoopStatus {
00121         
00122     long  clocks_at_start,                 // clocks at beginning of loop
00123               clocks_for_one_percent,          // clocks to complete 1% of the loop
00124               seconds_left;
00125         
00126     string  title,                         // description of what's going on in the loop
00127                 message;                       // message printed
00128         
00129 public:
00130 
00131         
00136 LoopStatus(string loopTitle) :
00137 //initialization list
00138 clocks_at_start(clock()), clocks_for_one_percent(0),
00139 seconds_left(1000000000), title(loopTitle),
00140 message("timing the first 1% of the loop.")
00141 { std::cerr << "\n\n"+title+":\n"+message; }    
00142 
00143 
00146 void clear();
00147         
00148 
00157 void consoleReport(int n, int N);
00158 
00159 
00160 }; //end LoopStatus
00161 
00162 
00163 
00164 
00165            
00166 MTGL_END_NAMESPACE(Martingale)
00167 
00168 #endif

Generated on Mon Sep 22 02:16:32 2003 for Libor-Library by doxygen1.3-rc3