Coin Logo http://www.sim.no
http://www.coin3d.org

SbBasic.h

00001 /**************************************************************************\
00002  *
00003  *  This file is part of the Coin 3D visualization library.
00004  *  Copyright (C) 1998-2007 by Systems in Motion.  All rights reserved.
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  ("GPL") version 2 as published by the Free Software Foundation.
00009  *  See the file LICENSE.GPL at the root directory of this source
00010  *  distribution for additional information about the GNU GPL.
00011  *
00012  *  For using Coin with software that can not be combined with the GNU
00013  *  GPL, and for taking advantage of the additional benefits of our
00014  *  support services, please contact Systems in Motion about acquiring
00015  *  a Coin Professional Edition License.
00016  *
00017  *  See http://www.coin3d.org/ for more information.
00018  *
00019  *  Systems in Motion, Postboks 1283, Pirsenteret, 7462 Trondheim, NORWAY.
00020  *  http://www.sim.no/  sales@sim.no  coin-support@coin3d.org
00021  *
00022 \**************************************************************************/
00023 
00024 #ifndef COIN_SBBASIC_H
00025 #define COIN_SBBASIC_H
00026 
00027 /* *********************************************************************** */
00028 
00029 #include <Inventor/C/basic.h>
00030 
00031 /* *********************************************************************** */
00032 /* Trap people trying to use Inventor headers while compiling C source code.
00033  * (we get support mail about this from time to time)
00034  */
00035 #ifndef __cplusplus
00036 #error You are not compiling C++ - maybe your source file is named <file>.c
00037 #endif
00038 
00039 /* *********************************************************************** */
00040 /* Include these for Open Inventor compatibility reasons (they are not
00041  * actually used in Coin.)
00042  */
00043 #define SoEXTENDER
00044 #define SoINTERNAL
00045 
00046 /* *********************************************************************** */
00047 
00048 /* Some useful inline template functions:
00049  *   SbAbs(Val)              - returns absolute value
00050  *   SbMin(Val1, Val2)       - returns minimum value
00051  *   SbMax(Val1, Val2)       - returns maximum value
00052  *   SbClamp(Val, Min, Max)  - returns clamped value
00053  *   SbSwap(Val1, Val2)      - swaps the two values (no return value)
00054  *   SbSqr(val)              - returns (val)²
00055  */
00056 
00057 template <class Type>
00058 inline Type SbAbs( Type Val ) {
00059   return (Val < 0) ? 0 - Val : Val;
00060 }
00061 
00062 template <class Type>
00063 inline Type SbMax( const Type A, const Type B ) {
00064   return (A < B) ? B : A;
00065 }
00066 
00067 template <class Type>
00068 inline Type SbMin( const Type A, const Type B ) {
00069   return (A < B) ? A : B;
00070 }
00071 
00072 template <class Type>
00073 inline Type SbClamp( const Type Val, const Type Min, const Type Max ) {
00074   return (Val < Min) ? Min : (Val > Max) ? Max : Val;
00075 }
00076 
00077 template <class Type>
00078 inline void SbSwap( Type & A, Type & B ) {
00079   Type T; T = A; A = B; B = T;
00080 }
00081 
00082 template <class Type>
00083 inline Type SbSqr(const Type val) {
00084   return val * val;
00085 }
00086 
00087 /* *********************************************************************** */
00088 
00089 template <typename Type>
00090 inline void SbDividerChk(const char * funcname, Type divider) {
00091 #ifndef NDEBUG
00092   if (!(divider != static_cast<Type>(0)))
00093     cc_debugerror_post(funcname, "divide by zero error.", divider);
00094 #endif // !NDEBUG
00095 }
00096 
00097 /* *********************************************************************** */
00098 
00099 /* COMPILER BUG WORKAROUND:
00100 
00101    We've had reports that Sun CC v4.0 is (likely) buggy, and doesn't
00102    allow a statement like
00103 
00104      SoType SoNode::classTypeId = SoType::badType();
00105 
00106    As a hack we can however get around this by instead writing it as
00107 
00108      SoType SoNode::classTypeId;
00109 
00110    ..as the SoType variable will then be initialized to bitpattern
00111    0x0000, which equals SoType::badType(). We can *however* not do
00112    this for the Intel C/C++ compiler, as that does *not* init to the
00113    0x0000 bitpattern (which may be a separate bug -- I haven't read
00114    the C++ spec closely enough to decide whether that relied on
00115    unspecified behavior or not).
00116 
00117    The latest version of the Intel compiler has been tested to still
00118    have this problem, so I've decided to re-install the old code, but
00119    in this form:
00120 
00121      SoType SoNode::classTypeId STATIC_SOTYPE_INIT;
00122 
00123    ..so it is easy to revert if somebody complains that the code
00124    reversal breaks their old Sun CC 4.0 compiler -- see the #define of
00125    STATIC_SOTYPE_INIT below.
00126 
00127    If that happens, we should work with the reporter, having access to
00128    the buggy compiler, to make a configure check which sets the
00129    SUN_CC_4_0_SOTYPE_INIT_BUG #define in include/Inventor/C/basic.h.in.
00130 
00131    (Note that the Sun CC compiler has moved on, and a later version
00132    we've tested, 5.4, does not have the bug.)
00133 
00134    20050105 mortene.
00135 */
00136 
00137 #define SUN_CC_4_0_SOTYPE_INIT_BUG 0 /* assume compiler is ok for now */
00138 
00139 #if SUN_CC_4_0_SOTYPE_INIT_BUG
00140 #define STATIC_SOTYPE_INIT
00141 #else
00142 #define STATIC_SOTYPE_INIT = SoType::badType()
00143 #endif
00144 
00145 /* *********************************************************************** */
00146 
00147 #endif /* !COIN_SBBASIC_H */

Copyright © 1998-2007 by Systems in Motion AS. All rights reserved.

Generated on Mon Feb 23 16:33:07 2009 for Coin by Doxygen. 1.5.8