Basic.h
1 /**************************************************************************\
2  *
3  * FILE: Basic.h
4  *
5  * This source file is part of DIME.
6  * Copyright (C) 1998-1999 by Systems In Motion. All rights reserved.
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License, version 2, as
10  * published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License (the accompanying file named COPYING) for more
16  * details.
17  *
18  **************************************************************************
19  *
20  * If you need DIME for a non-GPL project, contact Systems In Motion
21  * to acquire a Professional Edition License:
22  *
23  * Systems In Motion http://www.sim.no/
24  * Prof. Brochs gate 6 sales@sim.no
25  * N-7030 Trondheim Voice: +47 22114160
26  * NORWAY Fax: +47 67172912
27  *
28 \**************************************************************************/
29 
30 #ifndef DIME_BASIC_H
31 #define DIME_BASIC_H
32 
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <stdarg.h>
36 #include <string.h>
37 #include <assert.h>
38 #include <math.h>
39 
40 // we prefer to use floats to save mem. Applications needing
41 // scientific calculations should typedef this to double
42 typedef float dxfdouble;
43 
44 #ifdef _WIN32
45 #include "float.h"
46 #define M_PI 3.14159265357989
47 #endif
48 
49 #define DXFABS(x) ((x)<0?-(x):(x))
50 #define DXFMAX(x,y) ((x)>(y)?(x):(y))
51 #define DXFMIN(x,y) ((x)<(y)?(x):(y))
52 #define DXFDEG2RAD(x) (M_PI*(x)/180.0)
53 #define DXFRAD2DEG(x) (180.0*(x)/M_PI)
54 
55 
56 #ifdef __sgi
57 #define bool int
58 #define true 1
59 #define false 0
60 #endif // __sgi
61 
62 
63 template <class T> inline
64 T DXFSQR(const T x)
65 {
66  return x*x;
67 }
68 
69 #if defined(__BEOS__)
70 #include <support/SupportDefs.h>
71 #else // ! defined(__BEOS__)
72 typedef signed char int8;
73 typedef unsigned char uint8;
74 typedef signed short int16;
75 typedef unsigned short uint16;
76 #ifdef _WIN32
77 typedef long int32;
78 #else // ! defined(_WIN32)
79 typedef signed int int32;
80 #endif // ! defined(_WIN32)
81 typedef unsigned int uint32;
82 #endif // ! defined(__BEOS__)
83 
84 #ifdef macintosh
85  char* strdup( const char* );
86 #endif
87 
88 #define ARRAY_NEW(memh, type, num) \
89 memh ? (type*) memh->allocMem((num)*sizeof(type)) : new type[num]
90 
91 #define DXF_STRCPY(mh, d, s) \
92 mh ? d = mh->stringAlloc(s) : d = new char[strlen(s)+1]; if (d) strcpy(d,s)
93 
94 typedef bool dimeCallbackFunc(const class dimeState * const, class dimeEntity *, void *);
95 typedef dimeCallbackFunc * dimeCallback;
96 
97 typedef union {
98  int8 int8_data;
99  int16 int16_data;
100  int32 int32_data;
101  float float_data;
102  dxfdouble double_data;
103  const char *string_data;
104  const char *hex_data;
105 } dimeParam;
106 
107 /* ********************************************************************** */
108 /* Precaution to avoid an some errors easily made by the application
109  programmer. */
110 
111 #ifdef DIME_DLL_API
112 # error Leave the internal DIME_DLL_API define alone.
113 #endif /* DIME_DLL_API */
114 #ifdef DIME_INTERNAL
115 # ifdef DIME_NOT_DLL
116 # error The DIME_NOT_DLL define is not supposed to be used when building the library, only when building Win32 applications.
117 # endif /* DIME_INTERNAL && DIME_NOT_DLL */
118 # ifdef DIME_DLL
119 # error The DIME_DLL define is not supposed to be used when building the library, only when building Win32 applications.
120 # endif /* DIME_INTERNAL && DIME_DLL */
121 #endif /* DIME_INTERNAL */
122 
123 /*
124  On MSWindows platforms, one of these defines must always be set when
125  building application programs:
126 
127  - "DIME_DLL", when the application programmer is using the library
128  in the form of a dynamic link library (DLL)
129 
130  - "DIME_NOT_DLL", when the application programmer is using the
131  library in the form of a static object library (LIB)
132 
133  Note that either DIME_DLL or DIME_NOT_DLL _must_ be defined by the
134  application programmer on MSWindows platforms, or else the #error
135  statement will hit. Set up one or the other of these two defines in
136  your compiler environment according to how the library was built --
137  as a DLL (use "DIME_DLL") or as a LIB (use "DIME_NOT_DLL").
138 
139  (Setting up defines for the compiler is typically done by either
140  adding something like "/DDIME_DLL" to the compiler's argument line
141  (for command-line build processes), or by adding the define to the
142  list of preprocessor symbols in your IDE GUI (in the MSVC IDE, this
143  is done from the "Project"->"Settings" menu, choose the "C/C++" tab,
144  then "Preprocessor" from the dropdown box and add the appropriate
145  define)).
146 
147  It is extremely important that the application programmer uses the
148  correct define, as using "DIME_NOT_DLL" when "DIME_DLL" is correct
149  will cause mysterious crashes.
150  */
151 /* FIXME: use a feature check to see if this is a platform which can
152  recognize the __declspec keyword instead of the crap #if below.
153  20011201 mortene. */
154 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
155 # ifdef DIME_INTERNAL
156 # ifdef DIME_MAKE_DLL
157 # define DIME_DLL_API __declspec(dllexport)
158 # endif /* DIME_MAKE_DLL */
159 # else /* !DIME_INTERNAL */
160 # ifdef DIME_DLL
161 # ifdef DIME_NOT_DLL
162 # error Do not define both DIME_DLL and DIME_NOT_DLL at the same time
163 # endif
164 # define DIME_DLL_API __declspec(dllimport)
165 # else /* !DIME_DLL */
166 # ifndef DIME_NOT_DLL
167 # error Define either DIME_DLL or DIME_NOT_DLL as appropriate for your linkage! See dime/Basic.h for further instructions.
168 # endif /* DIME_NOT_DLL */
169 # endif /* !DIME_DLL */
170 # endif /* !DIME_INTERNAL */
171 #endif /* Microsoft Windows */
172 
173 /* Empty define to avoid errors when _not_ compiling an MSWindows DLL. */
174 #ifndef DIME_DLL_API
175 # define DIME_DLL_API
176 #endif /* !DIME_DLL_API */
177 
178 /* ********************************************************************** */
179 
180 #endif // !DIME_BASIC_H

Copyright © 1998-1999, Systems In Motion <sales@sim.no>. All rights reserved.
System documentation was generated using doxygen.