Biorithm  1.1
 All Classes Functions Variables Typedefs Friends
global.h
00001 /**************************************************************************
00002  * Copyright (c) 2002-2011 T. M. Murali                                   *
00003  *                                                                        *
00004  * This file is part of Biorithm.                                         *
00005  *                                                                        *
00006  * Biorithm is free software: you can redistribute it and/or modify       *
00007  * it under the terms of the GNU General Public License as published by   *
00008  * the Free Software Foundation, either version 3 of the License, or      *
00009  * (at your option) any later version.                                    *
00010  *                                                                        *
00011  * Biorithm is distributed in the hope that it will be useful,            *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00014  * GNU General Public License for more details.                           *
00015  *                                                                        *
00016  * You should have received a copy of the GNU General Public License      *
00017  * along with Biorithm.  If not, see <http://www.gnu.org/licenses/>.      *
00018  *                                                                        *
00019  **************************************************************************/
00020 
00021 // Purpose: projective clustering of gene expression data
00022 
00023 #ifndef _GLOBAL_H
00024 #define _GLOBAL_H
00025 
00026 #include <iostream>
00027 #include <fstream>
00028 // include map since many other headers need it.
00029 #include <map>
00030 using namespace std;
00031 
00032 #include "mystring.h"
00033 #include "info.h"
00034 
00035 typedef double MyNT;
00036 
00037 //
00038 // miscellaneous heplful functions and definitions.
00039 //
00040 
00041 // modelled on LEDA's forall in LEDA/iteration.h but adapted for STL
00042 // containers.
00043 #define MY_LOOP_VAR(y)  loop_var
00044 
00045 #define MY_LOOP_ITERATOR_TYPE(p) (typename T::iterator)p
00046 
00047 template<class T, class var_type>
00048 inline void MY_LoopInf(const T& S, var_type& x, void* p) 
00049 {
00050   if (MY_LOOP_ITERATOR_TYPE(p) != S.end())
00051     x = *(MY_LOOP_ITERATOR_TYPE(p));
00052 }
00053 
00054 template<class T>
00055 inline bool MY_LoopSucc(const T& S, void*& p) 
00056 {
00057   if (MY_LOOP_ITERATOR_TYPE(p) != S.end())
00058     {
00059       // you moron! increment p *before* assignment.
00060       p = ++(MY_LOOP_ITERATOR_TYPE(p));
00061       return true;
00062     }
00063   else return false;
00064 }
00065 
00066 #define MY_forall(x,S)\
00067 for(void* MY_LOOP_VAR(__LINE__) = S.begin();\
00068 MY_LoopInf(S,x,MY_LOOP_VAR(__LINE__)), MY_LoopSucc(S,MY_LOOP_VAR(__LINE__)); )
00069 
00070 
00071 // print vectors. use the definition in graph-global.h. commenting
00072 // this out may screw up compilation of xMotif.
00073 
00074 // template < class item >
00075 // ostream& operator<<(ostream& ostr, const vector< item >& v)
00076 // {
00077 //   for (unsigned int i = 0; i < v.size(); i++)
00078 //     ostr << v[i] << " ";
00079 // //  ostr << endl;
00080 //   return(ostr);
00081 // }
00082 
00083 // print pair
00084 template < class T1, class T2 > ostream& operator<<(ostream& ostr, const pair< T1, T2 >& p)
00085 {
00086   ostr << "(" << p.first << ", " << p.second << ")";
00087   return(ostr);
00088 }
00089 
00090 // check if a file has been opened properly
00091 inline bool fileCheck(ifstream& istr, const string& name)
00092 {
00093   if (!istr)
00094     {
00095       cerr << "ERROR! Cannot open file \"" << name << "\".\n";
00096       return(false);
00097     }
00098   return(true);
00099 }
00100 
00101 inline bool fileCheck(ofstream& ostr, const string& name)
00102 {
00103   if (!ostr)
00104     {
00105       cerr << "ERROR! Cannot open file \"" << name << "\".\n";
00106       return(false);
00107     }
00108   return(true);
00109 }
00110 
00111 
00112 #endif // _GLOBAL_H 
 All Classes Functions Variables Typedefs Friends