Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | Related Pages

util.h

00001 //==========================================================================
00002 //  UTIL.H - part of
00003 //                     OMNeT++/OMNEST
00004 //            Discrete System Simulation in C++
00005 //
00006 //
00007 //  Utility functions
00008 //
00009 //==========================================================================
00010 
00011 /*--------------------------------------------------------------*
00012   Copyright (C) 1992-2005 Andras Varga
00013 
00014   This file is distributed WITHOUT ANY WARRANTY. See the file
00015   `license' for details on this and other legal matters.
00016 *--------------------------------------------------------------*/
00017 
00018 #ifndef __UTIL_H
00019 #define __UTIL_H
00020 
00021 #include <stdarg.h>  // for va_list
00022 #include <stdio.h>   // for sprintf
00023 #include <typeinfo>  // for type_info
00024 #include "defs.h"
00025 
00026 // forward declarations
00027 class cModule;
00028 
00029 // logically belongs to csimul.h but must be here because of declaration order
00030 enum {CTX_BUILDINSIDE, CTX_INITIALIZE, CTX_EVENT, CTX_FINISH};
00031 
00032 //
00033 // #defines provided for backwards compatibility.
00034 // They may be removed in a future release!
00035 //
00036 #define myrandomize      opp_randomize
00037 #define genk_myrandomize genk_opp_randomize
00038 #define mystrdup         opp_strdup
00039 #define mystrcpy         opp_strcpy
00040 #define mystrcmp         opp_strcmp
00041 #define mystrmatch       opp_strmatch
00042 #define fastconcat       opp_concat
00043 #define indexedname      opp_mkindexedname
00044 
00045 
00051 
00060 SIM_API simtime_t strToSimtime(const char *str);
00061 
00072 SIM_API simtime_t strToSimtime0(const char *&str);
00073 
00079 SIM_API char *simtimeToStr(simtime_t t, char *dest=NULL);
00081 
00082 
00088 
00092 SIM_API double min(double a, double b);
00093 
00097 SIM_API double max(double a, double b);
00098 
00103 SIM_API double bool_and(double a, double b);
00104 
00109 SIM_API double bool_or(double a, double b);
00110 
00115 SIM_API double bool_xor(double a, double b);
00116 
00121 SIM_API double bool_not(double a);
00122 
00127 SIM_API double bin_and(double a, double b);
00128 
00133 SIM_API double bin_or(double a, double b);
00134 
00139 SIM_API double bin_xor(double a, double b);
00140 
00145 SIM_API double bin_compl(double a);
00146 
00151 SIM_API double shift_left(double a, double b);
00152 
00157 SIM_API double shift_right(double a, double b);
00159 
00160 
00172 
00177 SIM_API char *opp_strdup(const char *);
00178 
00183 SIM_API char *opp_strcpy(char *,const char *);
00184 
00189 SIM_API int  opp_strcmp(const char *, const char *);
00190 
00195 SIM_API bool opp_strmatch(const char *, const char *);
00196 
00201 SIM_API int opp_strlen(const char *);
00202 
00206 SIM_API char *opp_mkindexedname(char *dest, const char *name, int index);
00207 
00212 SIM_API char *opp_concat(const char *s1, const char *s2, const char *s3=NULL, const char *s4=NULL);
00213 
00219 SIM_API char *opp_strprettytrunc(char *dest, const char *src, unsigned maxlen);
00220 
00225 inline const char *correct(const char *);
00227 
00233 
00237 inline bool equal(double a, double b, double epsilon);
00239 
00240 //
00241 // INTERNAL: a restricted vsscanf implementation used by cStatistic::freadvarsf()
00242 //
00243 SIM_API int opp_vsscanf(const char *s, const char *fmt, va_list va);
00244 
00249 
00255 SIM_API void opp_error(int errcode,...);
00256 
00263 SIM_API void opp_error(const char *msg,...);
00264 
00275 SIM_API void opp_warning(int errcode,...);
00276 
00287 SIM_API void opp_warning(const char *msg,...);
00288 
00294 SIM_API void opp_terminate(int errcode,...);
00295 
00302 SIM_API void opp_terminate(const char *msg,...);
00304 
00305 //
00306 // INTERNAL: return name of a C++ type -- correcting quirks of various compilers...
00307 //
00308 const char *opp_typename(const std::type_info& t);
00309 
00310 //==========================================================================
00311 
00312 #define MAX_METHODCALL 1024
00313 
00331 #define Enter_Method cContextSwitcher __ctx(this); __ctx.methodCall
00332 
00343 #define Enter_Method_Silent() cContextSwitcher __ctx(this)
00344 
00355 class SIM_API cContextSwitcher
00356 {
00357   private:
00358     cModule *callerContext;
00359     int contexttype;
00360   public:
00364     cContextSwitcher(cModule *thisptr, int ctxtype=CTX_EVENT);
00365 
00369     ~cContextSwitcher();
00370 
00375     void methodCall(const char *fmt,...);
00376 };
00377 
00378 
00379 //==========================================================================
00380 //=== Implementation of utility functions:
00381 
00382 inline bool equal(double a, double b, double epsilon)
00383 {
00384    double d = a-b;
00385    return (d>=0.0 ? d : -d) < epsilon;
00386 }
00387 
00388 inline const char *correct(const char *s)
00389 {
00390    return s ? s : "";
00391 }
00392 
00393 // internally used: appends [num] to the given string
00394 inline void opp_appendindex(char *s, unsigned int i)
00395 {
00396    while (*s) s++;
00397    *s++ = '[';
00398    if (i<10)
00399        {*s++ = '0'+i; *s++=']'; *s=0; return;}
00400    if (i<100)
00401        {*s++ = '0'+i/10; *s++='0'+i%10; *s++=']'; *s=0; return;}
00402    sprintf(s,"%d]",i);
00403 }
00404 
00405 #endif
00406 
00407 

Generated on Fri Apr 1 12:25:33 2005 for OMNeT++/OMNEST Simulation Library by  doxygen 1.3.9.1