Common.h

00001 /*
00002  * Common.h - type declarations, (debug) macro's, assertion classes.
00003  *
00004  * This file is part of the Rulbus Device Class Library (RDCL).
00005  *
00006  * Copyright (C) 2003-2004, Leiden University.
00007  *
00008  * This library is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * The library is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with mngdriver; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  *
00022  * $Id: Common.h 2 2004-10-12 11:54:15Z moene $
00023  */
00024 
00025 #ifndef __COMMON_H
00026 #define __COMMON_H
00027 #define __IN_COMMON_H
00028 
00029 #include <math>         // for std::fabs
00030 #include <limits>       // for std::numeric_limits<>
00031 #include <string>       // for std::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    // compiler types:
00319    //
00320 
00321    DECLARE_TYPE(        signed char, int8   );  // signed 8-bit integral type
00322    DECLARE_TYPE(      unsigned char, uInt8  );  // signed 8-bit integral type
00323    DECLARE_TYPE(   signed short int, int16  );  // signed 16-bit integral type
00324    DECLARE_TYPE( unsigned short int, uInt16 );  // unsigned 16-bit integral type
00325    DECLARE_TYPE(         signed int, int32  );  // signed 32-bit integral type
00326    DECLARE_TYPE(       unsigned int, uInt32 );  // unsigned 32-bit integral type
00327    DECLARE_TYPE(              float, float32 ); // 32-bit real type (Real32)
00328    DECLARE_TYPE(             double, float64 ); // 64-bit real type (Real64)
00329 
00330    //
00331    // library types:
00332    //
00333 
00334    DECLARE_TYPE(              uInt8, Byte   );  // Byte type
00335    DECLARE_TYPE(             uInt16, Word   );  // Word type
00336    DECLARE_TYPE(             uInt32, Quad   );  // Double word type
00337    DECLARE_TYPE(               char, Char   );  // character type
00338    DECLARE_TYPE(                int, Int    );  // integral type
00339    DECLARE_TYPE(              int16, Int16  );  // 16-bit signed integral type
00340    DECLARE_TYPE(              int32, Int32  );  // 32-bit signed integral type
00341    DECLARE_TYPE(             double, Real   );  // real type
00342    DECLARE_TYPE(            float32, Real32 );  // 32-bit real type
00343    DECLARE_TYPE(            float64, Real64 );  // 64-bit real type
00344 
00345    DECLARE_TYPE(        std::string, String       );    // String type
00346    DECLARE_TYPE(     std::exception, StdException );    // StdException type
00347 
00348    DECLARE_TYPE(             String, Name   );  // Name type
00349    DECLARE_TYPE(                Int, Addr   );  // Addr type
00350    DECLARE_TYPE(                Int, Rack   );  // Rack type
00351 
00352    DECLARE_TYPE(               Real, Volt   );  // Voltage type [V]
00353    DECLARE_TYPE(             Real32, Volt32 );  // 32-bit Voltage type [V]
00354    DECLARE_TYPE(               Real, Time   );  // Time type [s]
00355    DECLARE_TYPE(               Real, Freq   );  // Frequency type [Hz]
00356    DECLARE_TYPE(               Real, Length );  // Length type [m]
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 } // namespace Rulbus
00397 
00398 #include "Shims.h"              // for to_cstr(), used in Exception.h
00399 #include "Assertion.h"          // for design-by-contract exceptions, assertions
00400 #include "Exception.h"          // for our exceptions
00401 
00402 #undef __IN_COMMON_H
00403 #endif  // __COMMON_H
00404 
00405 /*
00406  * end of file
00407  */

Generated on Tue Oct 12 14:11:57 2004 for Rulbus Device Class Library for Microsoft Windows by doxygen 1.3.4