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

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

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

Generated on Wed Jul 20 2022 for Coin by Doxygen. 1.9.4