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