Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

util.h

00001 //==========================================================================
00002 //   UTIL.H - header for
00003 //                             OMNeT++
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Utility functions
00008 //
00009 //==========================================================================
00010 
00011 /*--------------------------------------------------------------*
00012   Copyright (C) 1992-2001 Andras Varga
00013   Technical University of Budapest, Dept. of Telecommunications,
00014   Stoczek u.2, H-1111 Budapest, Hungary.
00015 
00016   This file is distributed WITHOUT ANY WARRANTY. See the file
00017   `license' for details on this and other legal matters.
00018 *--------------------------------------------------------------*/
00019 
00020 #ifndef __UTIL_H
00021 #define __UTIL_H
00022 
00023 #include <stdarg.h>  // for va_list
00024 #include "defs.h"
00025 
00026 
00030 #define NUM_RANDOM_GENERATORS    32
00031 
00032 #define INTRAND_MAX  0x7ffffffeL  /* = 2**31-2 FIXME */
00033 
00034 
00035 //
00036 // #defines provided for backwards compatibility.
00037 // They may be removed in a future release!
00038 //
00039 #define myrandomize      opp_randomize
00040 #define genk_myrandomize genk_opp_randomize
00041 #define mystrdup         opp_strdup
00042 #define mystrcpy         opp_strcpy
00043 #define mystrcmp         opp_strcmp
00044 #define mystrmatch       opp_strmatch
00045 #define fastconcat       opp_concat
00046 #define indexedname      opp_mkindexedname
00047 
00053 
00062 SIM_API simtime_t strToSimtime(const char *str);
00063 
00074 SIM_API simtime_t strToSimtime0(const char *&str);
00075 
00081 SIM_API char *simtimeToStr(simtime_t t, char *dest=NULL);
00083 
00084 
00107 
00113 SIM_API int testrand();
00114 
00120 SIM_API long opp_nextrand(long& seed);
00121 
00125 SIM_API void opp_randomize();
00126 
00130 SIM_API long randseed();
00131 
00135 SIM_API long randseed(long seed);
00136 
00140 SIM_API long intrand();
00141 
00145 SIM_API long intrand(long r);
00146 
00150 inline  double dblrand();
00151 
00155 SIM_API void genk_opp_randomize(int gen_nr);
00156 
00160 SIM_API long genk_randseed(int gen_nr);
00161 
00165 SIM_API long genk_randseed(int gen_nr, long seed);
00166 
00170 SIM_API long genk_intrand(int gen_nr);
00171 
00175 SIM_API long genk_intrand(int gen_nr,long r);
00176 
00180 inline  double genk_dblrand(int gen_nr);
00182 
00183 
00193 
00198 SIM_API double uniform(double a, double b);
00199 
00205 SIM_API double intuniform(double a, double b);
00206 
00212 SIM_API double exponential(double mean);
00213 
00218 SIM_API double normal(double mean, double variance);
00219 
00228 SIM_API double truncnormal(double mean, double varianced);
00229 
00230 
00235 SIM_API double genk_uniform(double gen_nr, double a, double b);
00236 
00241 SIM_API double genk_intuniform(double gen_nr, double a, double b);
00242 
00247 SIM_API double genk_exponential(double gen_nr, double p);
00248 
00253 SIM_API double genk_normal(double gen_nr, double mean, double variance);
00254 
00259 SIM_API double genk_truncnormal(double gen_nr, double mean, double variance);
00261 
00262 
00268 
00272 SIM_API double min(double a, double b);
00273 
00277 SIM_API double max(double a, double b);
00278 
00283 SIM_API double bool_and(double a, double b);
00284 
00289 SIM_API double bool_or(double a, double b);
00290 
00295 SIM_API double bool_xor(double a, double b);
00296 
00301 SIM_API double bool_not(double a);
00302 
00307 SIM_API double bin_and(double a, double b);
00308 
00313 SIM_API double bin_or(double a, double b);
00314 
00319 SIM_API double bin_xor(double a, double b);
00320 
00325 SIM_API double bin_compl(double a);
00326 
00331 SIM_API double shift_left(double a, double b);
00332 
00337 SIM_API double shift_right(double a, double b);
00339 
00340 
00352 
00357 SIM_API char *opp_strdup(const char *);
00358 
00363 SIM_API char *opp_strcpy(char *,const char *);
00364 
00369 SIM_API int  opp_strcmp(const char *, const char *);
00370 
00375 SIM_API bool opp_strmatch(const char *, const char *);
00376 
00381 SIM_API int opp_strlen(const char *);
00382 
00386 SIM_API char *opp_mkindexedname(char *dest, const char *name, int index);
00387 
00392 SIM_API char *opp_concat(const char *s1, const char *s2, const char *s3=NULL, const char *s4=NULL);
00393 
00399 SIM_API char *opp_strprettytrunc(char *dest, const char *src, unsigned maxlen);
00400 
00405 inline const char *correct(const char *);
00406 
00408 
00414 
00418 inline bool equal(double a, double b, double epsilon);
00420 
00421 //
00422 // INTERNAL: a restricted vsscanf implementation used by cStatistic::freadvarsf()
00423 //
00424 SIM_API int opp_vsscanf(const char *s, const char *fmt, va_list va);
00425 
00433 
00437 SIM_API void opp_error(int errcode,...);
00438 
00443 SIM_API void opp_error(const char *msg,...);
00444 
00450 SIM_API void opp_warning(int errcode,...);
00451 
00456 SIM_API void opp_warning(const char *msg,...);
00457 
00461 SIM_API void opp_terminate(int errcode,...);
00462 
00467 SIM_API void opp_terminate(const char *msg,...);
00469 
00480 class SIM_API opp_string
00481 {
00482   private:
00483     char *str;
00484 
00485   public:
00489     opp_string()               {str = 0;}
00490 
00494     opp_string(const char *s)  {str = opp_strdup(s);}
00495 
00499     opp_string(opp_string& s)  {str = opp_strdup(s.str);}
00500 
00504     ~opp_string()              {delete[] str;}
00505 
00509     operator const char *() const    {return str;}
00510 
00516     char *buffer() const        {return str;}
00517 
00521     char *allocate(unsigned size)
00522                                {delete[] str;str=new char[size];return str;}
00523 
00528     const char *operator=(const char *s)
00529                                {delete[] str;str=opp_strdup(s);return str;}
00530 
00534     opp_string& operator=(const opp_string& s)
00535                                {delete[] str;str=opp_strdup(s.str);return *this;}
00536 };
00537 
00538 //==========================================================================
00539 //=== Implementation of utility functions:
00540 
00541 inline bool equal(double a, double b, double epsilon)
00542 {
00543    double d = a-b;
00544    return (d>=0.0 ? d : -d) < epsilon;
00545 }
00546 
00547 inline const char *correct(const char *s)
00548 {
00549    return s ? s : "";
00550 }
00551 
00552 inline double dblrand()
00553 {
00554    return (double)intrand() / (double)((unsigned long)INTRAND_MAX+1UL);
00555 }
00556 
00557 inline double genk_dblrand(int gen_nr)
00558 {
00559    return (double)genk_intrand(gen_nr) / (double)((unsigned long)INTRAND_MAX+1UL);
00560 }
00561 
00562 #endif
00563 
00564 

Generated at Sat May 4 15:45:49 2002 for OMNeT++ by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001