SbBasic.h Source File

| http://www.sim.no/ http://www.coin3d.org/

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

SbBasic.h
1 #ifndef COIN_SBBASIC_H
2 #define COIN_SBBASIC_H
3
4 /**************************************************************************\
5 *
6 * This file is part of the Coin 3D visualization library.
7 * Copyright (C) by Kongsberg Oil & Gas Technologies.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * ("GPL") version 2 as published by the Free Software Foundation.
12 * See the file LICENSE.GPL at the root directory of this source
13 * distribution for additional information about the GNU GPL.
14 *
15 * For using Coin with software that can not be combined with the GNU
16 * GPL, and for taking advantage of the additional benefits of our
17 * support services, please contact Kongsberg Oil & Gas Technologies
18 * about acquiring a Coin Professional Edition License.
19 *
20 * See http://www.coin3d.org/ for more information.
21 *
22 * Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
23 * http://www.sim.no/ sales@sim.no coin-support@coin3d.org
24 *
25 \**************************************************************************/
26
27 #include <Inventor/C/errors/debugerror.h>
28 #include <Inventor/C/basic.h>
29
30 /* ********************************************************************** */
31 /* Trap people trying to use Inventor headers while compiling C source code.
32 * (we get support mail about this from time to time)
33 */
34 #ifndef __cplusplus
35 #error You are not compiling C++ - maybe your source file is named <file>.c
36 #endif
37
38 /* ********************************************************************** */
39 /* Include these for Open Inventor compatibility reasons (they are not
40 * actually used in Coin.)
41 */
42 #define SoEXTENDER
43 #define SoINTERNAL
44
45 /* ********************************************************************** */
46
47 /* Some useful inline template functions:
48 * SbAbs(Val) - returns absolute value
49 * SbMin(Val1, Val2) - returns minimum value
50 * SbMax(Val1, Val2) - returns maximum value
51 * SbClamp(Val, Min, Max) - returns clamped value
52 * SbSwap(Val1, Val2) - swaps the two values (no return value)
53 * SbSqr(val) - returns (val)²
54 */
55
56 template <class Type>
57 inline Type SbAbs( Type Val ) {
58 return (Val < 0) ? 0 - Val : Val;
59 }
60
61 template <class Type>
62 inline Type SbMax( const Type A, const Type B ) {
63 return (A < B) ? B : A;
64 }
65
66 template <class Type>
67 inline Type SbMin( const Type A, const Type B ) {
68 return (A < B) ? A : B;
69 }
70
71 template <class Type>
72 inline Type SbClamp( const Type Val, const Type Min, const Type Max ) {
73 return (Val < Min) ? Min : (Val > Max) ? Max : Val;
74 }
75
76 template <class Type>
77 inline void SbSwap( Type & A, Type & B ) {
78 Type T; T = A; A = B; B = T;
79 }
80
81 template <class Type>
82 inline Type SbSqr(const Type val) {
83 return val * val;
84 }
85
86 /* *********************************************************************** */
87
88 // SbDividerChk() - checks if divide-by-zero is attempted, and emits a
89 // warning if so for debug builds. inlined like this to not take much
90 // screenspace in inline functions.
91
92 // cc_debugerror_post() is not attempted resolved before the template is
93 // used, hence the missing Inventor/errors/SoDebugError.h #include. This
94 // "trick" does only work *portably* for functions in the global namespace.
95
96 template <typename Type>
97 inline void SbDividerChk(const char * funcname, Type divider) {
98 #ifndef NDEBUG
99 if (!(divider != static_cast<Type>(0)))
100 cc_debugerror_post(funcname, "divide by zero error.", divider);
101 #endif // !NDEBUG
102 }
103
104 /* ********************************************************************** */
105
106 /* COMPILER BUG WORKAROUND:
107
108 We've had reports that Sun CC v4.0 is (likely) buggy, and doesn't
109 allow a statement like
110
111 SoType SoNode::classTypeId = SoType::badType();
112
113 As a hack we can however get around this by instead writing it as
114
115 SoType SoNode::classTypeId;
116
117 ..as the SoType variable will then be initialized to bitpattern
118 0x0000, which equals SoType::badType(). We can *however* not do
119 this for the Intel C/C++ compiler, as that does *not* init to the
120 0x0000 bitpattern (which may be a separate bug -- I haven't read
121 the C++ spec closely enough to decide whether that relied on
122 unspecified behavior or not).
123
124 The latest version of the Intel compiler has been tested to still
125 have this problem, so I've decided to re-install the old code, but
126 in this form:
127
128 SoType SoNode::classTypeId STATIC_SOTYPE_INIT;
129
130 ..so it is easy to revert if somebody complains that the code
131 reversal breaks their old Sun CC 4.0 compiler -- see the #define of
132 STATIC_SOTYPE_INIT below.
133
134 If that happens, we should work with the reporter, having access to
135 the buggy compiler, to make a configure check which sets the
136 SUN_CC_4_0_SOTYPE_INIT_BUG #define in include/Inventor/C/basic.h.in.
137
138 (Note that the Sun CC compiler has moved on, and a later version
139 we've tested, 5.4, does not have the bug.)
140
141 20050105 mortene.
142 */
143
144 #define SUN_CC_4_0_SOTYPE_INIT_BUG 0 /* assume compiler is ok for now */
145
146 #if SUN_CC_4_0_SOTYPE_INIT_BUG
147 #define STATIC_SOTYPE_INIT
148 #else
149 #define STATIC_SOTYPE_INIT = SoType::badType()
150 #endif
151
152 /* ********************************************************************** */
153
154 #endif /* !COIN_SBBASIC_H */

Copyright © 1998-2010 by Kongsberg Oil & Gas Technologies. All rights reserved.