# compatibility.h

    00001 /* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003   -----------------------------------------------------------------------------
    00004   compatibility.h
    00005       File to store some compiler specific stuff in. Currently handles, or
    00006       least tries to handle the min() max() problems when using MSVC
    00007
    00008
    00009  (c) Maarten Keijzer (mak@dhi.dk) and GeNeura Team, 1999, 2000
    00010
    00011     This library is free software; you can redistribute it and/or
    00012     modify it under the terms of the GNU Lesser General Public
    00013     License as published by the Free Software Foundation; either
    00014     version 2 of the License, or (at your option) any later version.
    00015
    00016     This library is distributed in the hope that it will be useful,
    00017     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00018     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00019     Lesser General Public License for more details.
    00020
    00021     You should have received a copy of the GNU Lesser General Public
    00022     License along with this library; if not, write to the Free Software
    00023     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00024
    00025     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
    00026  */
    00027
    00028 #ifndef COMPAT_H
    00029 #define COMPAT_H
    00030
    00031 #include <string>
    00032 #include <iostream>
    00033
    00034 #ifdef __GNUC__
    00035 #if __GNUC__ < 3
    00036         // check for stdlibc++v3 which does have ios_base
    00037         #ifndef _CPP_BITS_IOSBASE_H
    00038         typedef ios ios_base; // not currently defined in GCC
    00039         #endif
    00040 #endif
    00041 #endif
    00042
    00043 #if defined(_MSC_VER) && (_MSC_VER < 1300)
    00044 /*
    00045 Maarten: added this code here because Mirkosoft has the
    00046 nasty habit of #define min and max in stdlib.h (and windows.h)
    00047 I'm trying to undo this horrible macro magic (microsoft yet macrohard)
    00048 here. Sure hope it works
    00049 Olivier: this has been removed in .NET :) One step more standard...
    00050 */
    00051 #pragma warning(disable:4786)
    00052
    00053 #include <stdlib.h>
    00054
    00055 #ifdef min
    00056 #undef min
    00057 #undef max // as they come in std::pairs
    00058 #endif
    00059
    00060 // add min and max to std...
    00061 namespace std
    00062 {
    00063     template <class T> const T& min(const T& a, const T& b)
    00064     {
    00065         if(a < b)
    00066             return a;
    00067         // else
    00068         return b;
    00069     }
    00070
    00071     template <class T> const T& max(const T& a, const T& b)
    00072     {
    00073         if(a > b)
    00074             return a;
    00075         // else
    00076         return b;
    00077     }
    00078 }
    00079
    00080 #endif
    00081         // _MSC_VER
    00082 #endif