UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
u3d_defines.hpp
1 /* u3d_defines.hpp */
2 /* $Id: u3d_defines.hpp,v 1.30 2009/06/11 09:10:44 sasha Exp $ */
3 #ifndef __u3d_defines_hpp
4 #define __u3d_defines_hpp
5 
6 #include <set>
7 #include <vector>
8 #include <u3d_message.hpp>
9 #include <stdexcept> /* for std::out_of_range */
10 #include <limits>
11 
12 using namespace std;
13 
14 #include <math.h>
15 
16 #define MIN_(a,b) ( ((a)<(b))?(a):(b) )
17 #define MAX_(a,b) ( ((a)>(b))?(a):(b) )
18 
19 //#define MIN(a,b) ((a)<(b))?(a):(b)
20 //#define MAX(a,b) ((a)>(b))?(a):(b)
21 
22 #define U3D_FILE_NAME_BUFFER_SIZE 1024
23 #define U3D_EPSILON 1.e-6
24 #define U3D_EPSILON_TRIGONOM 1.e-13 // Ilya magic
25 #define U3D_EPS_LENGTH 1
26 
27 #define U3D_MIGR_PROG_NAME "rtmigr3d"
28 
29 
30 #define EQUAL_REALS(a,b) ( (fabs((a)-(b)) < U3D_EPSILON ? true : false) )
31 
32 typedef set<int> int_set;
33 
34 
35 
36 enum U3D_COLOR {WHITE, BLACK};
37 
39 void fiazr2xyz(double f, double az, double r, double &px, double &py, double &pz);
40 
42 void xyz2fiazr(double px, double py, double pz, double &f, double &az, double &r);
43 
44 
45 
46 
47 //______________________________________________________________________________________________________
48 //
49 // ****************************** SAFE WORKING WITH MEMORY PART ****************************************
50 //______________________________________________________________________________________________________
51 
52 
53 
54 
55 #include <malloc.h>
56 #include <stdlib.h>
57 
58 
59 #define DMU_FILL_CHAR 0xbe
60 #define DMU_SZONE_SIZE 512
61 
62 
63 //#define __use_standard_malloc__
64 //#define __use_standard_vector__
65 
66 
67 void* dmu_malloc(size_t size, const char* file, int line);
68 
69 void dmu_free(void* ptr, const char* file, int line);
70 
71 
72 
73 // return -1 if left side corrupted; 1, if right side corrupted
74 // and 0 on success .
75 int dmu_check (void* ptr, const char* file, int line);
76 
77 
78 
79 #ifndef __use_standard_malloc__
80 
81 
82 
83 # ifndef __FILE__
84 # define __FILE__ "0"
85 # endif
86 
87 
88 # ifndef __LINE__
89 # define __LINE__ -1
90 # endif
91 
92 
93 # define malloc(size) dmu_malloc((size), __FILE__, __LINE__)
94 # define free(ptr) dmu_free((ptr), __FILE__, __LINE__)
95 
96 
97 #endif // __use_standard_malloc__
98 
99 
100 
101 
102 
103 #ifndef __use_standard_vector__
104 
105 template<class T>
106 struct MyAllocator {
107 
108  // Typedefs
109  typedef std::size_t size_type;
110  typedef std::ptrdiff_t difference_type;
111  typedef T* pointer;
112  typedef const T* const_pointer;
113  typedef T& reference;
114  typedef const T& const_reference;
115  typedef T value_type;
116 
117 
118  template<class U> struct rebind {
119  typedef MyAllocator<U> other;
120  };
121 
122  MyAllocator() throw() { };
123 
124  template<class U>
125  MyAllocator(const MyAllocator<U>&) throw () { };
126 
127  ~MyAllocator() throw() {};
128 
129  pointer address(reference x) const { return &x; };
130 
131  const_pointer address(const_reference x) const { return &x; };
132 
133  pointer allocate(size_type n, void* hint=0) {
134  return static_cast<T*>(::operator new(n*sizeof(T)));
135  };
136 
137  void deallocate(void* p, size_type n) {
138  ::operator delete(p);
139  };
140 
141  size_type max_size() const throw() {
142  return std::numeric_limits<size_type>::max() / sizeof(T);
143  };
144 
145  void construct(pointer p, const T& val) {
146  new (static_cast<void*>(p)) T(val);
147  };
148 
149  void destroy(pointer p) {
150  p->~T();
151  };
152 };
153 
154 
155 
156 
157 
158 template<>
159 struct MyAllocator<void> {
160  typedef void* pointer;
161  typedef const void* const_pointer;
162  typedef void value_type;
163 
164  template<class U> struct rebind {
165  typedef MyAllocator<U> other;
166  };
167 };
168 
169 
170 
171 template<class T>
172 bool operator==(const MyAllocator<T>&, const MyAllocator<T>&) {
173  return true;
174 };
175 
176 
177 template<class T>
178 bool operator!=(const MyAllocator<T>&, const MyAllocator<T>&) {
179  return false;
180 };
181 
182 
183 
184 
185 
186 
187 template<typename T>
188 struct safe_vector : public std::vector<T, MyAllocator<T> >
189 {
190  safe_vector() :
191  std::vector<T, MyAllocator<T> >()
192  {}
193 
194  safe_vector(std::size_t ndx) :
195  std::vector<T, MyAllocator<T> >(ndx)
196  {}
197 
198  safe_vector(const safe_vector<T>& other ) :
199  std::vector<T, MyAllocator<T> > (other)
200  {}
201 
202  const safe_vector<T>& operator=(const safe_vector<T>& other) {
203  //assert(!"Must be not used!!!");
204  this->resize(other.size());
205  std::copy(other.begin(), other.end(), this->begin());
206 
207  return *this;
208  }
209 
210  const T& operator[] (std::size_t ndx) const
211  {
212  const T* ret = 0;
213  try {
214  ret = &(this->at(ndx));
215  }
216  catch (std::out_of_range& e) {
217  U3dMessage::error("safe_vector: ndx=%d const operator[] : %s", ndx, e.what());
218  abort();
219  }
220 
221  return *ret;
222  }
223 
224  T& operator[] (std::size_t ndx) {
225  T* ret = 0;
226  try {
227  ret = &(this->at(ndx));
228  }
229  catch (std::out_of_range& e) {
230  U3dMessage::error("safe_vector: ndx=%d operator[] : %s", ndx, e.what());
231  abort();
232  }
233 
234  return *ret;
235  };
236 };
237 
238 #else // __use_standard_vector__
239 
240 #define safe_vector vector
241 
242 #endif // __use_standard_vector__
243 
244 
245 //typedef safe_vector<int> std::vector<int>;
246 //typedef safe_vector<double> std::vector<double>;
247 
248 
249 
250 
251 //============================================================================
252 
253 
254 
255 #endif /* u3d_defines.hpp */
static void error(const char *format,...)
Definition: u3d_defines.hpp:118
Definition: u3d_defines.hpp:188
Definition: u3d_defines.hpp:106