INETDefs.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004 Andras Varga
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU Lesser General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU Lesser General Public License
00015 // along with this program; if not, see <http://www.gnu.org/licenses/>.
00016 //
00017 
00018 #ifndef __INET_INETDEFS_H
00019 #define __INET_INETDEFS_H
00020 
00021 //
00022 // General definitions.
00023 // Andras Varga
00024 //
00025 
00026 #include <omnetpp.h>
00027 
00028 #if OMNETPP_VERSION < 0x0400
00029 #  error At least OMNeT++/OMNEST version 4.0 required
00030 #endif
00031 
00032 #if defined(INET_EXPORT)
00033 #  define INET_API OPP_DLLEXPORT
00034 #elif defined(INET_IMPORT)
00035 #  define INET_API OPP_DLLIMPORT
00036 #else
00037 #  define INET_API
00038 #endif
00039 
00040 typedef unsigned short ushort;
00041 typedef unsigned int uint;
00042 typedef unsigned long ulong;
00043 
00044 
00045 //
00046 // Macro to prevent executing ev<< statements in Express mode.
00047 // Compare ev/sec values with code compiled with #define EV ev.
00048 //
00049 #define EV ev.isDisabled()?ev:ev
00050 
00051 
00052 //
00053 // Macro to protect expressions like gate("out")->getToGate()->getToGate()
00054 // from crashing if something in between returns NULL.
00055 // The above expression should be changed to
00056 //    CHK(CHK(gate("out"))->getToGate())->getToGate()
00057 // which is uglier but doesn't crash, just stops with a nice
00058 // error message if something goes wrong.
00059 //
00060 template <class T>
00061 T *__checknull(T *p, const char *expr, const char *file, int line)
00062 {
00063     if (!p)
00064         opp_error("Expression %s returned NULL at %s:%d",expr,file,line);
00065     return p;
00066 }
00067 #define CHK(x) __checknull((x), #x, __FILE__, __LINE__)
00068 
00069 
00070 #define PK(msg)  check_and_cast<cPacket *>(msg)    /*XXX temp def*/
00071 
00072 
00073 #ifdef _MSC_VER
00074 //
00075 // Implementation of the error function, from the Mobility Framework
00076 //
00077 // Unfortunately the windows math library does not provide an
00078 // implementation of the error function, so we use an own
00079 // implementation (Thanks to Jirka Klaue)
00080 // Author Jirka Klaue
00081 //
00082 static double erfc(double x)
00083 {
00084     double t, u, y;
00085 
00086     if (x <= -6)
00087         return 2;
00088     if (x >= 6)
00089         return 0;
00090 
00091     t = 3.97886080735226 / (fabs(x) + 3.97886080735226);
00092     u = t - 0.5;
00093     y = (((((((((0.00127109764952614092 * u + 1.19314022838340944e-4) * u -
00094         0.003963850973605135) * u - 8.70779635317295828e-4) * u +
00095         0.00773672528313526668) * u + 0.00383335126264887303) * u -
00096         0.0127223813782122755) * u - 0.0133823644533460069) * u +
00097         0.0161315329733252248) * u + 0.0390976845588484035) * u +
00098         0.00249367200053503304;
00099     y = ((((((((((((y * u - 0.0838864557023001992) * u -
00100         0.119463959964325415) * u + 0.0166207924969367356) * u +
00101         0.357524274449531043) * u + 0.805276408752910567) * u +
00102         1.18902982909273333) * u + 1.37040217682338167) * u +
00103         1.31314653831023098) * u + 1.07925515155856677) * u +
00104         0.774368199119538609) * u + 0.490165080585318424) * u +
00105         0.275374741597376782) * t * exp(-x * x);
00106 
00107     return x < 0 ? 2 - y : y;
00108 }
00109 #endif
00110 
00111 #endif