Debug.H

Go to the documentation of this file.
00001 /*===========================================================================*/
00002 /*
00003  * This file is part of libogg++ - a c++ library for the Ogg transport format
00004  *
00005  * Copyright (C) 2006, 2007, 2008 Elaine Tsiang YueLien
00006  *
00007  * libogg++ is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  * 
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the
00019  * Free Software Foundation, Inc.
00020  * 51 Franklin Street, Fifth Floor
00021  * Boston, MA  02110-1301, USA
00022  *
00023  *===========================================================================*/
00028 /*===========================================================================*/
00029 #ifndef OggDebug
00030 #define OggDebug
00031 
00032 #ifdef __GNUG__
00033 #pragma interface
00034 #endif
00035 
00036 #include        <iostream>
00037 
00038 extern  "C"
00039 {
00040 #include        <pthread.h>
00041 }
00042 
00043 
00044 namespace       Ogg
00045 {
00046   using std::ostream;
00047     
00048   class Debug
00049   {
00050   private:
00051     pthread_mutex_t     lock;
00052 
00053   public:
00054     Debug() throw()
00055     {
00056       pthread_mutex_init(&lock, 0);
00057     }
00058 
00059     virtual
00060     ~Debug() throw ()
00061     {}
00062 
00063     void
00064     begin()
00065     {
00066       pthread_mutex_lock(&lock);
00067       std::cerr << std::endl << "[";
00068     }
00069 
00070     void
00071     end()
00072     {
00073       std::cerr << "]" << std::endl;
00074       pthread_mutex_unlock(&lock);
00075     }
00076   }
00077   ;
00078 
00079   extern Debug  Dbg;
00080 
00081   inline
00082   Debug& operator<<(ostream & os, Debug & dbg)
00083   {
00084     dbg.end();
00085     return(dbg);
00086   }
00087 
00088   inline
00089   ostream& operator<<(Debug & dbg, ostream & os)
00090   {
00091     dbg.begin();
00092     return(os);
00093   }
00094 
00095   inline void debug(bool test)
00096   {
00097     if ( _GEN_DEBUG_CODE && test )
00098       ;
00099   }
00100 
00101   template<class X>
00102   inline void debug(bool test
00103                     ,X x
00104                     )
00105   {
00106     if ( _GEN_DEBUG_CODE && test )
00107       {
00108         Dbg << std::cerr
00109             << x
00110             << Dbg;
00111       }
00112   }
00113 
00114   template<class X1
00115            , class X2
00116            >
00117   inline void debug(bool test
00118                     ,X1 x1
00119                     ,X2 x2
00120                     )
00121   {
00122     if ( _GEN_DEBUG_CODE && test )
00123       {
00124         Dbg << std::cerr
00125           << x1
00126           << x2
00127           << Dbg;
00128       }
00129   }
00130 
00131   template<class X1
00132            , class X2
00133            , class X3
00134            >
00135   inline void debug(bool test
00136                     ,X1 x1
00137                     ,X2 x2
00138                     ,X3 x3
00139                     )
00140   {
00141     if ( _GEN_DEBUG_CODE && test )
00142       {
00143         Dbg << std::cerr
00144           << x1
00145           << x2
00146           << x3
00147           << Dbg;
00148       }
00149   }
00150 
00151   template<class X1
00152            , class X2
00153            , class X3
00154            , class X4
00155            >
00156   inline void debug(bool test
00157                     ,X1 x1
00158                     ,X2 x2
00159                     ,X3 x3
00160                     ,X4 x4
00161                     )
00162   {
00163     if ( _GEN_DEBUG_CODE && test )
00164       {
00165         Dbg << std::cerr
00166             << x1
00167             << x2
00168             << x3
00169             << x4
00170             << Dbg;
00171       }
00172   }
00173 
00174   template<class X1
00175            , class X2
00176            , class X3
00177            , class X4
00178            , class X5
00179            >
00180   inline void debug(bool test
00181                     ,X1 x1
00182                     ,X2 x2
00183                     ,X3 x3
00184                     ,X4 x4
00185                     ,X5 x5
00186                     )
00187   {
00188     if ( _GEN_DEBUG_CODE && test )
00189       {
00190         Dbg << std::cerr
00191             << x1
00192             << x2
00193             << x3
00194             << x4
00195             << x5
00196             << Dbg;
00197       }
00198   }
00199 
00200   template<class X1
00201            , class X2
00202            , class X3
00203            , class X4
00204            , class X5
00205            , class X6
00206            >
00207   inline void debug(bool test
00208                     ,X1 x1
00209                     ,X2 x2
00210                     ,X3 x3
00211                     ,X4 x4
00212                     ,X5 x5
00213                     ,X6 x6
00214                     )
00215   {
00216     if ( _GEN_DEBUG_CODE && test )
00217       {
00218         Dbg << std::cerr
00219             << x1
00220             << x2
00221             << x3
00222             << x4
00223             << x5
00224             << x6
00225             << Dbg;
00226       }
00227   }
00228 
00229   template<class X1
00230            , class X2
00231            , class X3
00232            , class X4
00233            , class X5
00234            , class X6
00235            , class X7
00236            >
00237   inline void debug(bool test
00238                     ,X1 x1
00239                     ,X2 x2
00240                     ,X3 x3
00241                     ,X4 x4
00242                     ,X5 x5
00243                     ,X6 x6
00244                     ,X7 x7
00245                     )
00246   {
00247     if ( _GEN_DEBUG_CODE && test )
00248       {
00249         Dbg
00250           <<std::cerr
00251           << x1
00252           << x2
00253           << x3
00254           << x4
00255           << x5
00256           << x6
00257           << x7
00258           << Dbg;
00259       }
00260   }
00261 
00262   template<class X1
00263            , class X2
00264            , class X3
00265            , class X4
00266            , class X5
00267            , class X6
00268            , class X7
00269            , class X8
00270            >
00271   inline void debug(bool test
00272                     ,X1 x1
00273                     ,X2 x2
00274                     ,X3 x3
00275                     ,X4 x4
00276                     ,X5 x5
00277                     ,X6 x6
00278                     ,X7 x7
00279                     ,X8 x8
00280                     )
00281   {
00282     if ( _GEN_DEBUG_CODE && test )
00283       {
00284         Dbg
00285           <<std::cerr
00286           << x1
00287           << x2
00288           << x3
00289           << x4
00290           << x5
00291           << x6
00292           << x7
00293           << x8
00294           << Dbg;
00295       }
00296   }
00297 
00298   template<class X1
00299            , class X2
00300            , class X3
00301            , class X4
00302            , class X5
00303            , class X6
00304            , class X7
00305            , class X8
00306            , class X9
00307            >
00308   inline void debug(bool test
00309                     ,X1 x1
00310                     ,X2 x2
00311                     ,X3 x3
00312                     ,X4 x4
00313                     ,X5 x5
00314                     ,X6 x6
00315                     ,X7 x7
00316                     ,X8 x8
00317                     ,X9 x9
00318                     )
00319   {
00320     if ( _GEN_DEBUG_CODE && test )
00321       {
00322         Dbg
00323           <<std::cerr
00324           << x1
00325           << x2
00326           << x3
00327           << x4
00328           << x5
00329           << x6
00330           << x7
00331           << x8
00332           << x9
00333           << Dbg;
00334       }
00335   }
00336 
00337   template<class X1
00338            , class X2
00339            , class X3
00340            , class X4
00341            , class X5
00342            , class X6
00343            , class X7
00344            , class X8
00345            , class X9
00346            , class X10
00347            >
00348   inline void debug(bool test
00349                     ,X1 x1
00350                     ,X2 x2
00351                     ,X3 x3
00352                     ,X4 x4
00353                     ,X5 x5
00354                     ,X6 x6
00355                     ,X7 x7
00356                     ,X8 x8
00357                     ,X9 x9
00358                     ,X10 x10
00359                     )
00360   {
00361     if ( _GEN_DEBUG_CODE && test )
00362       {
00363         Dbg
00364           <<std::cerr
00365           << x1
00366           << x2
00367           << x3
00368           << x4
00369           << x5
00370           << x6
00371           << x7
00372           << x8
00373           << x9
00374           << x10
00375           << Dbg;
00376       }
00377   }
00378 
00379   template<class X1
00380            , class X2
00381            , class X3
00382            , class X4
00383            , class X5
00384            , class X6
00385            , class X7
00386            , class X8
00387            , class X9
00388            , class X10
00389            , class X11
00390            >
00391   inline void debug(bool test
00392                     ,X1 x1
00393                     ,X2 x2
00394                     ,X3 x3
00395                     ,X4 x4
00396                     ,X5 x5
00397                     ,X6 x6
00398                     ,X7 x7
00399                     ,X8 x8
00400                     ,X9 x9
00401                     ,X10 x10
00402                     ,X11 x11
00403                     )
00404   {
00405     if ( _GEN_DEBUG_CODE && test )
00406       {
00407         Dbg
00408           <<std::cerr
00409           << x1
00410           << x2
00411           << x3
00412           << x4
00413           << x5
00414           << x6
00415           << x7
00416           << x8
00417           << x9
00418           << x10
00419           << x11
00420           << Dbg;
00421       }
00422   }
00423 
00424 }
00425 
00426 #endif

Generated on Tue Aug 12 19:18:37 2008 for libogg++ by  doxygen 1.5.4