00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __COMMON_H
00026 #define __COMMON_H
00027 #define __IN_COMMON_H
00028
00029 #include <math>
00030 #include <limits>
00031 #include <string>
00032
00098 #ifdef DOXYGEN
00099 #define DEBUG DFLAG_ALL
00100 #endif
00101
00102 #define DFLAG_NONE 0x0000
00103 #define DFLAG_ALL 0xFFFF
00104 #define DFLAG_PRODUCTION (DFLAG_ALL & ~DFLAG_ENSURE)
00105
00106 #define DFLAG_GENERAL 0x0001
00107 #define DFLAG_INTERFACE 0x0002
00108 #define DFLAG_BUSVIOLATION 0x0004
00109 #define DFLAG_REQUIRE 0x0010
00110 #define DFLAG_ENSURE 0x0020
00111 #define DFLAG_NEVER_GET_HERE 0x0040
00112
00113 #if !defined( DEBUG )
00114 #define DEBUG DFLAG_NONE
00115 #endif
00116
00121 #define dim(a) (sizeof(a)/sizeof((a)[0]))
00122
00127 #define DECLARE_TYPE( mydecl, mytype ) \
00128 typedef mydecl mytype; \
00129 typedef mytype * mytype ## Ptr; \
00130 typedef const mytype * mytype ## Cptr; \
00131 typedef mytype & mytype ## Ref; \
00132 typedef const mytype & mytype ## Cref;
00133
00138 #define DECLARE_CLASS( tag ) \
00139 class tag; \
00140 typedef tag * tag ## Ptr; \
00141 typedef const tag * tag ## Cptr; \
00142 typedef tag & tag ## Ref; \
00143 typedef const tag & tag ## Cref;
00144
00145 #if 0
00146
00150 #define PROXY_CAST static_cast
00151 #else
00152
00156 #define PROXY_CAST dynamic_cast
00157 #endif
00158
00159
00161
00166 namespace Rulbus
00167 {
00315
00316
00317
00318
00319
00320
00321 DECLARE_TYPE( signed char, int8 );
00322 DECLARE_TYPE( unsigned char, uInt8 );
00323 DECLARE_TYPE( signed short int, int16 );
00324 DECLARE_TYPE( unsigned short int, uInt16 );
00325 DECLARE_TYPE( signed int, int32 );
00326 DECLARE_TYPE( unsigned int, uInt32 );
00327 DECLARE_TYPE( float, float32 );
00328 DECLARE_TYPE( double, float64 );
00329
00330
00331
00332
00333
00334 DECLARE_TYPE( uInt8, Byte );
00335 DECLARE_TYPE( uInt16, Word );
00336 DECLARE_TYPE( uInt32, Quad );
00337 DECLARE_TYPE( char, Char );
00338 DECLARE_TYPE( int, Int );
00339 DECLARE_TYPE( int16, Int16 );
00340 DECLARE_TYPE( int32, Int32 );
00341 DECLARE_TYPE( double, Real );
00342 DECLARE_TYPE( float32, Real32 );
00343 DECLARE_TYPE( float64, Real64 );
00344
00345 DECLARE_TYPE( std::string, String );
00346 DECLARE_TYPE( std::exception, StdException );
00347
00348 DECLARE_TYPE( String, Name );
00349 DECLARE_TYPE( Int, Addr );
00350 DECLARE_TYPE( Int, Rack );
00351
00352 DECLARE_TYPE( Real, Volt );
00353 DECLARE_TYPE( Real32, Volt32 );
00354 DECLARE_TYPE( Real, Time );
00355 DECLARE_TYPE( Real, Freq );
00356 DECLARE_TYPE( Real, Length );
00357
00369 template <typename aType>
00370 struct isEqual
00371 {
00376 isEqual( aType a ): m_a(a) { }
00377
00382 bool operator()( aType b )
00383 {
00384 return std::fabs( b - m_a ) < std::numeric_limits<aType>::epsilon();
00385 }
00386
00387 aType m_a;
00388 };
00389
00390 typedef isEqual<Volt> isEqualVolt;
00391 typedef isEqual<Time> isEqualTime;
00392 typedef isEqual<Freq> isEqualFreq;
00393
00395
00396 }
00397
00398 #include "Shims.h"
00399 #include "Assertion.h"
00400 #include "Exception.h"
00401
00402 #undef __IN_COMMON_H
00403 #endif // __COMMON_H
00404
00405
00406
00407