INET Framework for OMNeT++/OMNEST
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 //
00024 
00025 #include <omnetpp.h>
00026 
00027 #if OMNETPP_VERSION < 0x0402
00028 #  error At least OMNeT++/OMNEST version 4.2 required
00029 #endif
00030 
00031 #if defined(INET_EXPORT)
00032 #  define INET_API OPP_DLLEXPORT
00033 #elif defined(INET_IMPORT)
00034 #  define INET_API OPP_DLLIMPORT
00035 #else
00036 #  define INET_API
00037 #endif
00038 
00039 typedef unsigned short ushort;
00040 typedef unsigned int uint;
00041 typedef unsigned long ulong;
00042 
00043 
00044 //
00045 // Macro to prevent executing ev<< statements in Express mode.
00046 // Compare ev/sec values with code compiled with #define EV ev.
00047 //
00048 #define EV ev.isDisabled()?ev:ev
00049 
00050 
00051 //
00052 // Macro to protect expressions like gate("out")->getToGate()->getToGate()
00053 // from crashing if something in between returns NULL.
00054 // The above expression should be changed to
00055 //    CHK(CHK(gate("out"))->getToGate())->getToGate()
00056 // which is uglier but doesn't crash, just stops with a nice
00057 // error message if something goes wrong.
00058 //
00059 template <class T>
00060 T *__checknull(T *p, const char *expr, const char *file, int line)
00061 {
00062     if (!p)
00063         opp_error("Expression %s returned NULL at %s:%d",expr,file,line);
00064     return p;
00065 }
00066 #define CHK(x) __checknull((x), #x, __FILE__, __LINE__)
00067 
00068 
00069 #define PK(msg)  check_and_cast<cPacket *>(msg)    /*XXX temp def*/
00070 
00071 
00072 #ifdef _MSC_VER
00073 //
00074 // Implementation of the error function, from the Mobility Framework
00075 //
00076 // Unfortunately the windows math library does not provide an
00077 // implementation of the error function, so we use an own
00078 // implementation (Thanks to Jirka Klaue)
00079 // Author Jirka Klaue
00080 //
00081 static double erfc(double x)
00082 {
00083     double t, u, y;
00084 
00085     if (x <= -6)
00086         return 2;
00087     if (x >= 6)
00088         return 0;
00089 
00090     t = 3.97886080735226 / (fabs(x) + 3.97886080735226);
00091     u = t - 0.5;
00092     y = (((((((((0.00127109764952614092 * u + 1.19314022838340944e-4) * u -
00093         0.003963850973605135) * u - 8.70779635317295828e-4) * u +
00094         0.00773672528313526668) * u + 0.00383335126264887303) * u -
00095         0.0127223813782122755) * u - 0.0133823644533460069) * u +
00096         0.0161315329733252248) * u + 0.0390976845588484035) * u +
00097         0.00249367200053503304;
00098     y = ((((((((((((y * u - 0.0838864557023001992) * u -
00099         0.119463959964325415) * u + 0.0166207924969367356) * u +
00100         0.357524274449531043) * u + 0.805276408752910567) * u +
00101         1.18902982909273333) * u + 1.37040217682338167) * u +
00102         1.31314653831023098) * u + 1.07925515155856677) * u +
00103         0.774368199119538609) * u + 0.490165080585318424) * u +
00104         0.275374741597376782) * t * exp(-x * x);
00105 
00106     return x < 0 ? 2 - y : y;
00107 }
00108 #endif
00109 
00110 #endif