dime  0.9.1
Portable DXF file library
Loading...
Searching...
No Matches
Basic.h
1/**************************************************************************\
2 * Copyright (c) Kongsberg Oil & Gas Technologies AS
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31\**************************************************************************/
32
33#ifndef DIME_BASIC_H
34#define DIME_BASIC_H
35
36#include <stdlib.h>
37#include <stdio.h>
38#include <stdarg.h>
39#include <string.h>
40#include <assert.h>
41#include <math.h>
42
43// we prefer to use floats to save mem. Applications needing
44// scientific calculations should typedef this to double
45typedef float dxfdouble;
46// typedef double dxfdouble;
47
48#include <float.h>
49
50#ifndef M_PI
51#define M_PI 3.14159265358979323846
52#endif // !M_PI
53
54#define DXFABS(x) ((x)<0?-(x):(x))
55#define DXFMAX(x,y) ((x)>(y)?(x):(y))
56#define DXFMIN(x,y) ((x)<(y)?(x):(y))
57#define DXFDEG2RAD(x) (M_PI*(x)/180.0)
58#define DXFRAD2DEG(x) (180.0*(x)/M_PI)
59
60
61#ifdef __sgi
62#define bool int
63#define true 1
64#define false 0
65#endif // __sgi
66
67
68template <class T> inline
69T DXFSQR(const T x)
70{
71 return x*x;
72}
73
74#if defined(__BEOS__)
75#include <support/SupportDefs.h>
76#else // ! defined(__BEOS__)
77typedef signed char int8;
78typedef unsigned char uint8;
79typedef signed short int16;
80typedef unsigned short uint16;
81#ifdef _WIN32
82typedef long int32;
83#else // ! defined(_WIN32)
84typedef signed int int32;
85#endif // ! defined(_WIN32)
86typedef unsigned int uint32;
87#endif // ! defined(__BEOS__)
88
89#ifdef macintosh
90 char* strdup( const char* );
91#endif
92
93#define ARRAY_NEW(memh, type, num) \
94memh ? (type*) memh->allocMem((num)*sizeof(type)) : new type[num]
95
96#define DXF_STRCPY(mh, d, s) \
97mh ? d = mh->stringAlloc(s) : d = new char[strlen(s)+1]; if (d) strcpy(d,s)
98
99typedef bool dimeCallbackFunc(const class dimeState * const, class dimeEntity *, void *);
100typedef dimeCallbackFunc * dimeCallback;
101
102typedef union {
103 int8 int8_data;
104 int16 int16_data;
105 int32 int32_data;
106 float float_data;
107 dxfdouble double_data;
108 const char *string_data;
109 const char *hex_data;
110} dimeParam;
111
112/* ********************************************************************** */
113/* Precaution to avoid an some errors easily made by the application
114 programmer. */
115
116#ifdef DIME_DLL_API
117# error Leave the internal DIME_DLL_API define alone.
118#endif /* DIME_DLL_API */
119#ifdef DIME_INTERNAL
120# ifdef DIME_NOT_DLL
121# error The DIME_NOT_DLL define is not supposed to be used when building the library, only when building Win32 applications.
122# endif /* DIME_INTERNAL && DIME_NOT_DLL */
123# ifdef DIME_DLL
124# error The DIME_DLL define is not supposed to be used when building the library, only when building Win32 applications.
125# endif /* DIME_INTERNAL && DIME_DLL */
126#endif /* DIME_INTERNAL */
127
128/*
129 On MSWindows platforms, one of these defines must always be set when
130 building application programs:
131
132 - "DIME_DLL", when the application programmer is using the library
133 in the form of a dynamic link library (DLL)
134
135 - "DIME_NOT_DLL", when the application programmer is using the
136 library in the form of a static object library (LIB)
137
138 Note that either DIME_DLL or DIME_NOT_DLL _must_ be defined by the
139 application programmer on MSWindows platforms, or else the #error
140 statement will hit. Set up one or the other of these two defines in
141 your compiler environment according to how the library was built --
142 as a DLL (use "DIME_DLL") or as a LIB (use "DIME_NOT_DLL").
143
144 (Setting up defines for the compiler is typically done by either
145 adding something like "/DDIME_DLL" to the compiler's argument line
146 (for command-line build processes), or by adding the define to the
147 list of preprocessor symbols in your IDE GUI (in the MSVC IDE, this
148 is done from the "Project"->"Settings" menu, choose the "C/C++" tab,
149 then "Preprocessor" from the dropdown box and add the appropriate
150 define)).
151
152 It is extremely important that the application programmer uses the
153 correct define, as using "DIME_NOT_DLL" when "DIME_DLL" is correct
154 will cause mysterious crashes.
155 */
156/* FIXME: use a feature check to see if this is a platform which can
157 recognize the __declspec keyword instead of the crap #if below.
158 20011201 mortene. */
159#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
160# ifdef DIME_INTERNAL
161# ifdef DIME_MAKE_DLL
162# define DIME_DLL_API __declspec(dllexport)
163# endif /* DIME_MAKE_DLL */
164# else /* !DIME_INTERNAL */
165# ifdef DIME_DLL
166# ifdef DIME_NOT_DLL
167# error Do not define both DIME_DLL and DIME_NOT_DLL at the same time
168# endif
169# define DIME_DLL_API __declspec(dllimport)
170# else /* !DIME_DLL */
171# ifndef DIME_NOT_DLL
172# error Define either DIME_DLL or DIME_NOT_DLL as appropriate for your linkage! See dime/Basic.h for further instructions.
173# endif /* DIME_NOT_DLL */
174# endif /* !DIME_DLL */
175# endif /* !DIME_INTERNAL */
176#endif /* Microsoft Windows */
177
178/* Empty define to avoid errors when _not_ compiling an MSWindows DLL. */
179#ifndef DIME_DLL_API
180# define DIME_DLL_API
181#endif /* !DIME_DLL_API */
182
183int DIME_DLL_API dime_isnan(double value);
184int DIME_DLL_API dime_isinf(double value);
185int DIME_DLL_API dime_finite(double value);
186
187/* ********************************************************************** */
188
189#endif // !DIME_BASIC_H
The dimeEntity class is the superclass of all entity classes.
Definition Entity.h:61
The dimeState class manages various state variables while the model is traversed.
Definition State.h:41
The dimeParam class is a union of the different parameter types.
Definition Basic.h:102