1 
2 ///////////////////////////////////////////////////////////
3 //                                                       //
4 //                         SAGA                          //
5 //                                                       //
6 //      System for Automated Geoscientific Analyses      //
7 //                                                       //
8 //           Application Programming Interface           //
9 //                                                       //
10 //                  Library: SAGA_API                    //
11 //                                                       //
12 //-------------------------------------------------------//
13 //                                                       //
14 //                      api_core.h                       //
15 //                                                       //
16 //          Copyright (C) 2005 by Olaf Conrad            //
17 //                                                       //
18 //-------------------------------------------------------//
19 //                                                       //
20 // This file is part of 'SAGA - System for Automated     //
21 // Geoscientific Analyses'.                              //
22 //                                                       //
23 // This library is free software; you can redistribute   //
24 // it and/or modify it under the terms of the GNU Lesser //
25 // General Public License as published by the Free       //
26 // Software Foundation, either version 2.1 of the        //
27 // License, or (at your option) any later version.       //
28 //                                                       //
29 // This library is distributed in the hope that it will  //
30 // be useful, but WITHOUT ANY WARRANTY; without even the //
31 // implied warranty of MERCHANTABILITY or FITNESS FOR A  //
32 // PARTICULAR PURPOSE. See the GNU Lesser General Public //
33 // License for more details.                             //
34 //                                                       //
35 // You should have received a copy of the GNU Lesser     //
36 // General Public License along with this program; if    //
37 // not, see <http://www.gnu.org/licenses/>.              //
38 //                                                       //
39 //-------------------------------------------------------//
40 //                                                       //
41 //    contact:    Olaf Conrad                            //
42 //                Institute of Geography                 //
43 //                University of Goettingen               //
44 //                Goldschmidtstr. 5                      //
45 //                37077 Goettingen                       //
46 //                Germany                                //
47 //                                                       //
48 //    e-mail:     oconrad@saga-gis.org                   //
49 //                                                       //
50 ///////////////////////////////////////////////////////////
51 
52 //---------------------------------------------------------
53 #ifndef HEADER_INCLUDED__SAGA_API__api_core_H
54 #define HEADER_INCLUDED__SAGA_API__api_core_H
55 
56 
57 ///////////////////////////////////////////////////////////
58 //														 //
59 //														 //
60 //														 //
61 ///////////////////////////////////////////////////////////
62 
63 //---------------------------------------------------------
64 /** \file api_core.h
65 * Classes, functions, type definitions for basic helpers
66 * like data types, memory allocation, string handling, file
67 * access, translations, colors and user interface communication.
68 * @see CSG_String
69 * @see CSG_File
70 * @see CSG_Array
71 * @see CSG_Bytes
72 */
73 
74 
75 ///////////////////////////////////////////////////////////
76 //														 //
77 //														 //
78 //														 //
79 ///////////////////////////////////////////////////////////
80 
81 //---------------------------------------------------------
82 #ifdef _SAGA_MSW
83 	#define	_SAGA_DLL_EXPORT		__declspec( dllexport )
84 	#define	_SAGA_DLL_IMPORT		__declspec( dllimport )
85 #else
86 	#define	_SAGA_DLL_EXPORT
87 	#define	_SAGA_DLL_IMPORT
88 #endif
89 
90 //---------------------------------------------------------
91 #ifdef _SAGA_API_EXPORTS
92 	#define	SAGA_API_DLL_EXPORT		_SAGA_DLL_EXPORT
93 #else
94 	#define	SAGA_API_DLL_EXPORT		_SAGA_DLL_IMPORT
95 #endif
96 
97 
98 ///////////////////////////////////////////////////////////
99 //														 //
100 //														 //
101 //														 //
102 ///////////////////////////////////////////////////////////
103 
104 //---------------------------------------------------------
105 #ifndef SWIG
106 
107 #include <math.h>
108 #include <memory.h>
109 #include <stdlib.h>
110 #include <stdio.h>
111 #include <string.h>
112 #include <wchar.h>
113 #include <string>
114 
115 #endif	// #ifdef SWIG
116 
117 
118 ///////////////////////////////////////////////////////////
119 //														 //
120 //														 //
121 //														 //
122 ///////////////////////////////////////////////////////////
123 
124 //---------------------------------------------------------
125 // this is defined by configure, but will not be on a normal application build
126 
127 #ifndef SIZEOF_LONG
128 	#if defined(__alpha) || defined(__sparcv9) || defined(__LP64__) || (defined(__HOS_AIX__) && defined(_LP64))
129 		#define SIZEOF_LONG		8
130 	#else
131 		#define SIZEOF_LONG		4
132 	#endif
133 #endif
134 
135 //---------------------------------------------------------
136 #ifdef _TYPEDEF_BOOL
137 	typedef unsigned int		bool;
138 	#define true				((bool)1)
139 	#define false				((bool)0)
140 #endif	// _TYPEDEF_BOOL
141 
142 //---------------------------------------------------------
143 #ifdef _TYPEDEF_BYTE
144 	typedef unsigned char		BYTE;
145 #endif	// _TYPEDEF_BYTE
146 
147 //---------------------------------------------------------
148 #ifdef _TYPEDEF_WORD
149 	typedef unsigned short		WORD;
150 	#if SIZEOF_LONG == 4
151 		typedef unsigned long	DWORD;
152 	#else
153 		typedef unsigned int	DWORD;
154 	#endif
155 #endif	// _TYPEDEF_WORD
156 
157 //---------------------------------------------------------
158 	typedef   signed long long	sLong;
159 	typedef unsigned long long	uLong;
160 
161 //---------------------------------------------------------
162 #if defined(_SAGA_MSW)
163 	#include <float.h>
164 	#define SG_is_NaN			_isnan
165 #elif defined(isnan)
166 	#define SG_is_NaN			isnan
167 #else
168 	#define SG_is_NaN(x)		(x != x)
169 #endif
170 
171 
172 ///////////////////////////////////////////////////////////
173 //														 //
174 //                   Parallelization                     //
175 //														 //
176 ///////////////////////////////////////////////////////////
177 
178 //---------------------------------------------------------
179 SAGA_API_DLL_EXPORT void			SG_OMP_Set_Max_Num_Threads	(int iCores);
180 SAGA_API_DLL_EXPORT int				SG_OMP_Get_Max_Num_Threads	(void);
181 SAGA_API_DLL_EXPORT int				SG_OMP_Get_Max_Num_Procs	(void);
182 SAGA_API_DLL_EXPORT int				SG_OMP_Get_Thread_Num		(void);
183 
184 
185 ///////////////////////////////////////////////////////////
186 //														 //
187 //						Memory							 //
188 //														 //
189 ///////////////////////////////////////////////////////////
190 
191 //---------------------------------------------------------
192 #define SG_GET_LONG(b0, b1, b2, b3)	((long) (((BYTE)(b0) | ((WORD)(b1) << 8)) | (((DWORD)(BYTE)(b2)) << 16) | (((DWORD)(BYTE)(b3)) << 24)))
193 
194 #define SG_GET_BYTE_0(vLong)		((BYTE) ((vLong)      ))
195 #define SG_GET_BYTE_1(vLong)		((BYTE) ((vLong) >>  8))
196 #define SG_GET_BYTE_2(vLong)		((BYTE) ((vLong) >> 16))
197 #define SG_GET_BYTE_3(vLong)		((BYTE) ((vLong) >> 24))
198 
199 //---------------------------------------------------------
200 SAGA_API_DLL_EXPORT void *			SG_Malloc			(size_t size);
201 SAGA_API_DLL_EXPORT void *			SG_Calloc			(size_t num, size_t size);
202 SAGA_API_DLL_EXPORT void *			SG_Realloc			(void *memblock, size_t size);
203 SAGA_API_DLL_EXPORT void			SG_Free				(void *memblock);
204 
205 #define SG_FREE_SAFE(PTR)			{ if( PTR ) { SG_Free (PTR); PTR = NULL; } }
206 #define SG_DELETE_SAFE(PTR)			{ if( PTR ) { delete  (PTR); PTR = NULL; } }
207 #define SG_DELETE_ARRAY(PTR)		{ if( PTR ) { delete[](PTR); PTR = NULL; } }
208 
209 //---------------------------------------------------------
210 SAGA_API_DLL_EXPORT void			SG_Swap_Bytes		(void *Buffer, int nBytes);
211 
212 SAGA_API_DLL_EXPORT int				SG_Mem_Get_Int		(const char *Buffer        , bool bSwapBytes);
213 SAGA_API_DLL_EXPORT void			SG_Mem_Set_Int		(char *Buffer, int Value   , bool bSwapBytes);
214 SAGA_API_DLL_EXPORT double			SG_Mem_Get_Double	(const char *Buffer        , bool bSwapBytes);
215 SAGA_API_DLL_EXPORT void			SG_Mem_Set_Double	(char *Buffer, double Value, bool bSwapBytes);
216 
217 
218 ///////////////////////////////////////////////////////////
219 //														 //
220 ///////////////////////////////////////////////////////////
221 
222 //---------------------------------------------------------
223 class SAGA_API_DLL_EXPORT CSG_Buffer
224 {
225 public:
226 
227 						CSG_Buffer		(void);
228 	bool				Create			(void);
229 
230 						CSG_Buffer		(const CSG_Buffer &Buffer);
231 	bool				Create			(const CSG_Buffer &Buffer);
232 
233 						CSG_Buffer		(size_t Size);
234 	bool				Create			(size_t Size);
235 
236 	virtual				~CSG_Buffer		(void);
237 	void				Destroy			(void);
238 
239 	bool				Set_Size		(size_t Size, bool bShrink = true);
Inc_Size(size_t Size)240 	bool				Inc_Size		(size_t Size)				{	return( Set_Size(m_Size + Size) );	}
Get_Size(void)241 	size_t				Get_Size		(void)				const	{	return( m_Size );	}
242 
243 	bool				Set_Data		(const char *Data, size_t Size, bool bShrink = true);
244 	char *				Get_Data		(int Offset = 0)	const	{	return( m_Data + Offset );		}
245 
246 	CSG_Buffer &		operator =		(const CSG_Buffer &Buffer)	{	Create(Buffer);	return( *this );	}
247 	char &				operator []		(int Position)				{	return( m_Data[Position] );	}
248 	char				operator []		(int Position)		const	{	return( m_Data[Position] );	}
249 
250 	void				Add_Value		(char   Value, bool bBigEndian = false)	{	if( Inc_Size(sizeof(Value)) ) Set_Value((int)m_Size - sizeof(Value), Value, bBigEndian);	}
251 	void				Add_Value		(short  Value, bool bBigEndian = false)	{	if( Inc_Size(sizeof(Value)) ) Set_Value((int)m_Size - sizeof(Value), Value, bBigEndian);	}
252 	void				Add_Value		(int    Value, bool bBigEndian = false)	{	if( Inc_Size(sizeof(Value)) ) Set_Value((int)m_Size - sizeof(Value), Value, bBigEndian);	}
253 	void				Add_Value		(float  Value, bool bBigEndian = false)	{	if( Inc_Size(sizeof(Value)) ) Set_Value((int)m_Size - sizeof(Value), Value, bBigEndian);	}
254 	void				Add_Value		(double Value, bool bBigEndian = false)	{	if( Inc_Size(sizeof(Value)) ) Set_Value((int)m_Size - sizeof(Value), Value, bBigEndian);	}
255 
256 	CSG_Buffer &		operator +=		(char   Value)				{	Add_Value(Value);	return( *this );	}
257 	CSG_Buffer &		operator +=		(short  Value)				{	Add_Value(Value);	return( *this );	}
258 	CSG_Buffer &		operator +=		(int    Value)				{	Add_Value(Value);	return( *this );	}
259 	CSG_Buffer &		operator +=		(float  Value)				{	Add_Value(Value);	return( *this );	}
260 	CSG_Buffer &		operator +=		(double Value)				{	Add_Value(Value);	return( *this );	}
261 
262 	void				Set_Value		(int Offset, char   Value, bool bBigEndian = false)	{	m_Data[Offset]	= Value;	}
263 	void				Set_Value		(int Offset, short  Value, bool bBigEndian = false)	{	if( bBigEndian ) SG_Swap_Bytes(&Value, sizeof(Value)); *(short  *)(m_Data + Offset) = Value;	}
264 	void				Set_Value		(int Offset, int    Value, bool bBigEndian = false)	{	if( bBigEndian ) SG_Swap_Bytes(&Value, sizeof(Value)); *(int    *)(m_Data + Offset) = Value;	}
265 	void				Set_Value		(int Offset, float  Value, bool bBigEndian = false)	{	if( bBigEndian ) SG_Swap_Bytes(&Value, sizeof(Value)); *(float  *)(m_Data + Offset) = Value;	}
266 	void				Set_Value		(int Offset, double Value, bool bBigEndian = false)	{	if( bBigEndian ) SG_Swap_Bytes(&Value, sizeof(Value)); *(double *)(m_Data + Offset) = Value;	}
267 
268 	short				asShort			(int Offset, bool bBigEndian = false) const	{	short  Value = *(short  *)(m_Data + Offset); if( bBigEndian ) SG_Swap_Bytes(&Value, sizeof(Value)); return( Value );	}
269 	int					asInt			(int Offset, bool bBigEndian = false) const	{	int    Value = *(int    *)(m_Data + Offset); if( bBigEndian ) SG_Swap_Bytes(&Value, sizeof(Value)); return( Value );	}
270 	float				asFloat			(int Offset, bool bBigEndian = false) const	{	float  Value = *(float  *)(m_Data + Offset); if( bBigEndian ) SG_Swap_Bytes(&Value, sizeof(Value)); return( Value );	}
271 	double				asDouble		(int Offset, bool bBigEndian = false) const	{	double Value = *(double *)(m_Data + Offset); if( bBigEndian ) SG_Swap_Bytes(&Value, sizeof(Value)); return( Value );	}
272 
273 
274 private:
275 
276 	char				*m_Data;
277 
278 	size_t				m_Size;
279 
280 };
281 
282 
283 ///////////////////////////////////////////////////////////
284 //														 //
285 //														 //
286 //														 //
287 ///////////////////////////////////////////////////////////
288 
289 //---------------------------------------------------------
290 typedef enum ESG_Array_Growth
291 {
292 	SG_ARRAY_GROWTH_0	= 0,
293 	SG_ARRAY_GROWTH_1,
294 	SG_ARRAY_GROWTH_2,
295 	SG_ARRAY_GROWTH_3
296 }
297 TSG_Array_Growth;
298 
299 //---------------------------------------------------------
300 class SAGA_API_DLL_EXPORT CSG_Array
301 {
302 public:
303 	CSG_Array(void);
304 	~CSG_Array(void);
305 
306 	CSG_Array							(const CSG_Array &Array);
307 	void *				Create			(const CSG_Array &Array);
308 
309 	CSG_Array							(size_t Value_Size, size_t nValues = 0, TSG_Array_Growth Growth = SG_ARRAY_GROWTH_0);
310 	void *				Create			(size_t Value_Size, size_t nValues = 0, TSG_Array_Growth Growth = SG_ARRAY_GROWTH_0);
311 
312 	void				Destroy			(void);
313 
314 	CSG_Array &			operator =		(const CSG_Array &Array)	{	Create(Array);	return( *this );	}
315 
316 	bool				Set_Growth		(TSG_Array_Growth Growth);
Get_Growth(void)317 	int					Get_Growth		(void)	const			{	return( m_Growth );		}
318 
Get_Value_Size(void)319 	size_t				Get_Value_Size	(void)	const			{	return( m_Value_Size );	}
Get_Size(void)320 	size_t				Get_Size		(void)	const			{	return( m_nValues );	}
321 
322 	/// Returns a pointer to the memory address of the requested variable. You have to type cast and dereference the pointer to get access to the variable itself.
Get_Entry(size_t Index)323 	void *				Get_Entry		(size_t Index)	const	{	return( Index < m_nValues ? (char *)m_Values + Index * m_Value_Size : NULL );	}
324 	void *				operator []		(size_t Index)	const	{	return( Get_Entry(Index) );	}
325 
326 	/// Returns a pointer to the memory address of the requested variable. You have to type cast and dereference the pointer to get access to the variable itself.
Get_Entry(int Index)327 	void *				Get_Entry		(int    Index)	const	{	return( Index >= 0 ? Get_Entry((size_t)Index) : NULL );	}
328 	void *				operator []		(int    Index)	const	{	return( Get_Entry(Index) );	}
329 
Get_Array(void)330 	void *				Get_Array		(void)	const			{	return( m_Values );		}
Get_Array(size_t nValues)331 	void *				Get_Array		(size_t nValues)		{	Set_Array(nValues);	return( m_Values );	}
332 
333 	bool				Set_Array		(size_t nValues, bool bShrink = true);
334 	bool				Set_Array		(size_t nValues, void **pArray, bool bShrink = true);
335 
336 	bool				Inc_Array		(size_t nValues = 1);
337 	bool				Inc_Array		(void **pArray);
338 
339 	bool				Dec_Array		(bool bShrink = true);
340 	bool				Dec_Array		(void **pArray, bool bShrink = true);
341 
342 
343 private:
344 
345 	TSG_Array_Growth	m_Growth;
346 
347 	size_t				m_nValues, m_nBuffer, m_Value_Size;
348 
349 	void				*m_Values;
350 
351 };
352 
353 
354 ///////////////////////////////////////////////////////////
355 //														 //
356 ///////////////////////////////////////////////////////////
357 
358 //---------------------------------------------------------
359 class SAGA_API_DLL_EXPORT CSG_Array_Pointer
360 {
361 public:
CSG_Array_Pointer(const CSG_Array_Pointer & Array)362 	CSG_Array_Pointer					(const CSG_Array_Pointer &Array)			{	Create(Array);	}
363 	void **				Create			(const CSG_Array_Pointer &Array);
364 
365 	CSG_Array_Pointer					(size_t nValues = 0, TSG_Array_Growth Growth = SG_ARRAY_GROWTH_0)	{	Create(nValues, Growth);	}
366 	void **				Create			(size_t nValues = 0, TSG_Array_Growth Growth = SG_ARRAY_GROWTH_0);
367 
Destroy(void)368 	void				Destroy			(void)									{	m_Array.Destroy();	}
369 
Set_Growth(TSG_Array_Growth Growth)370 	bool				Set_Growth		(TSG_Array_Growth Growth)				{	return( m_Array.Set_Growth(Growth) );	}
Get_Growth(void)371 	int					Get_Growth		(void)	const							{	return( m_Array.Get_Growth()       );	}
372 
Get_Size(void)373 	size_t				Get_Size		(void)	const							{	return( m_Array.Get_Size() );	}
374 
Get_Array(void)375 	void **				Get_Array		(void)	const							{	return( (void **)m_Array.Get_Array()        );	}
Get_Array(size_t nValues)376 	void **				Get_Array		(size_t nValues)						{	return( (void **)m_Array.Get_Array(nValues) );	}
377 
378 	bool				Set_Array		(size_t nValues, bool bShrink = true)	{	return( m_Array.Set_Array(nValues, bShrink) );	}
379 	bool				Inc_Array		(size_t nValues = 1)					{	return( m_Array.Inc_Array(nValues) );	}
380 	bool				Dec_Array		(                bool bShrink = true)	{	return( m_Array.Dec_Array(bShrink) );	}
381 
382 	bool				Add				(void *Value);
383 	bool				Add				(const CSG_Array_Pointer &Array);
384 
385 	bool				Del				(int    Index);
386 	bool				Del				(size_t Index);
387 	size_t				Del				(void  *Value);
388 
Set(size_t Index,void * Value)389 	bool				Set				(size_t Index, void *Value)				{	if( Index >= Get_Size() ) return( false ); *((void **)m_Array.Get_Entry(Index)) = Value; return( true );	}
Set(int Index,void * Value)390 	bool				Set				(int    Index, void *Value)				{	return( Set((size_t)Index, Value) );	}
391 
Get(size_t Index)392 	void *&				Get				(size_t Index)							{	return( *((void **)m_Array.Get_Entry(Index)) );	}
Get(size_t Index)393 	void *				Get				(size_t Index)	const					{	return( *((void **)m_Array.Get_Entry(Index)) );	}
Get(int Index)394 	void *&				Get				(int    Index)							{	return( *((void **)m_Array.Get_Entry(Index)) );	}
Get(int Index)395 	void *				Get				(int    Index)	const					{	return( *((void **)m_Array.Get_Entry(Index)) );	}
396 
397 	CSG_Array_Pointer &	operator =		(const CSG_Array_Pointer &Array)		{	Create(Array);	return( *this );	}
398 
399 	void *&				operator []		(size_t Index)							{	return( Get(Index) );	}
400 	void *				operator []		(size_t Index)	const					{	return( Get(Index) );	}
401 	void *&				operator []		(int    Index)							{	return( Get(Index) );	}
402 	void *				operator []		(int    Index)	const					{	return( Get(Index) );	}
403 
404 	CSG_Array_Pointer &	operator +=		(void *Value)							{	Add(Value);	return( *this );	}
405 	CSG_Array_Pointer &	operator +=		(const CSG_Array_Pointer &Array)		{	Add(Array);	return( *this );	}
406 
407 
408 private:
409 
410 	CSG_Array			m_Array;
411 
412 };
413 
414 
415 ///////////////////////////////////////////////////////////
416 //														 //
417 ///////////////////////////////////////////////////////////
418 
419 //---------------------------------------------------------
420 class SAGA_API_DLL_EXPORT CSG_Array_Int
421 {
422 public:
CSG_Array_Int(const CSG_Array_Int & Array)423 	CSG_Array_Int						(const CSG_Array_Int &Array)			{	Create(Array);	}
424 	int *				Create			(const CSG_Array_Int &Array);
425 
426 	CSG_Array_Int						(size_t nValues = 0, TSG_Array_Growth Growth = SG_ARRAY_GROWTH_0)	{	Create(nValues, Growth);	}
427 	int *				Create			(size_t nValues = 0, TSG_Array_Growth Growth = SG_ARRAY_GROWTH_0);
428 
Destroy(void)429 	void				Destroy			(void)									{	m_Array.Destroy();	}
430 
Set_Growth(TSG_Array_Growth Growth)431 	bool				Set_Growth		(TSG_Array_Growth Growth)				{	return( m_Array.Set_Growth(Growth) );	}
Get_Growth(void)432 	int					Get_Growth		(void)	const							{	return( m_Array.Get_Growth()       );	}
433 
Get_Size(void)434 	size_t				Get_Size		(void)	const							{	return( m_Array.Get_Size() );	}
435 
Get_Array(void)436 	int *				Get_Array		(void)	const							{	return( (int *)m_Array.Get_Array()        );	}
Get_Array(size_t nValues)437 	int *				Get_Array		(size_t nValues)						{	return( (int *)m_Array.Get_Array(nValues) );	}
438 
439 	bool				Set_Array		(size_t nValues, bool bShrink = true)	{	return( m_Array.Set_Array(nValues, bShrink) );	}
440 	bool				Inc_Array		(size_t nValues = 1)					{	return( m_Array.Inc_Array(nValues) );	}
441 	bool				Dec_Array		(                bool bShrink = true)	{	return( m_Array.Dec_Array(bShrink) );	}
442 
443 	bool				Add				(int Value);
444 	bool				Add				(const CSG_Array_Int &Array);
445 
Set(size_t Index,int Value)446 	bool				Set				(size_t Index, int Value)				{	if( Index >= Get_Size() ) return( false ); *((int *)m_Array.Get_Entry(Index)) = Value; return( true );	}
Set(int Index,int Value)447 	bool				Set				(int    Index, int Value)				{	return( Set((size_t)Index, Value) );	}
448 
Get(size_t Index)449 	int &				Get				(size_t Index)							{	return( *((int *)m_Array.Get_Entry(Index)) );	}
Get(size_t Index)450 	int	 				Get				(size_t Index)	const					{	return( *((int *)m_Array.Get_Entry(Index)) );	}
Get(int Index)451 	int &				Get				(int    Index)							{	return( *((int *)m_Array.Get_Entry(Index)) );	}
Get(int Index)452 	int	 				Get				(int    Index)	const					{	return( *((int *)m_Array.Get_Entry(Index)) );	}
453 
454 	bool				Assign			(int Value);
455 
456 	CSG_Array_Int &		operator =		(const CSG_Array_Int &Array)			{	Create(Array);	return( *this );	}
457 	CSG_Array_Int &		operator =		(int Value)								{	Assign(Value);	return( *this );	}
458 
459 	int &				operator []		(size_t Index)							{	return( Get(Index) );	}
460 	int  				operator []		(size_t Index)	const					{	return( Get(Index) );	}
461 	int &				operator []		(int    Index)							{	return( Get(Index) );	}
462 	int  				operator []		(int    Index)	const					{	return( Get(Index) );	}
463 
464 	CSG_Array_Int &		operator +=		(int Value)								{	Add(Value);	return( *this );	}
465 	CSG_Array_Int &		operator +=		(const CSG_Array_Int &Array)			{	Add(Array);	return( *this );	}
466 
467 
468 private:
469 
470 	CSG_Array			m_Array;
471 
472 };
473 
474 
475 ///////////////////////////////////////////////////////////
476 //														 //
477 //						String							 //
478 //														 //
479 ///////////////////////////////////////////////////////////
480 
481 //---------------------------------------------------------
482 #define SG_Char				wchar_t
483 #define SG_T(s)				L ## s
484 #define SG_PRINTF			SG_Printf
485 #define SG_FPRINTF			SG_FPrintf
486 #define SG_SSCANF			swscanf
487 #define SG_STR_CPY			wcscpy
488 #define SG_STR_LEN			wcslen
489 #define SG_STR_TOD			wcstod
490 #define SG_STR_CMP(s1, s2)	CSG_String(s1).Cmp(s2)
491 #define SG_STR_MBTOSG(s)	CSG_String(s).w_str()
492 
493 //---------------------------------------------------------
494 enum ESG_File_Flags_Encoding
495 {
496 	SG_FILE_ENCODING_ANSI,
497 	SG_FILE_ENCODING_UTF7,
498 	SG_FILE_ENCODING_UTF8,
499 	SG_FILE_ENCODING_UTF16LE,
500 	SG_FILE_ENCODING_UTF16BE,
501 	SG_FILE_ENCODING_UTF32LE,
502 	SG_FILE_ENCODING_UTF32BE,
503 	SG_FILE_ENCODING_UNDEFINED
504 };
505 
506 //---------------------------------------------------------
507 class SAGA_API_DLL_EXPORT CSG_String
508 {
509 public:
510 	CSG_String(void);
511 	CSG_String(const CSG_String &String);
512 	CSG_String(const char       *String);
513 	CSG_String(const wchar_t    *String);
514 	CSG_String(char    Character, size_t nRepeat = 1);
515 	CSG_String(wchar_t Character, size_t nRepeat = 1);
516 
517 									CSG_String			(const class wxString *pString);
518 	bool							Create				(const class wxString *pString);
519 
520 	virtual ~CSG_String(void);
521 
522 	CSG_String &					operator =			(const CSG_String &String);
523 	CSG_String &					operator =			(const char       *String);
524 	CSG_String &					operator =			(const wchar_t    *String);
525 	CSG_String &					operator =			(char    Character);
526 	CSG_String &					operator =			(wchar_t Character);
527 
528 	size_t							Length				(void)	const;
529 
530 	bool							is_Empty			(void)	const;
531 
532 	SG_Char							operator []			(int    i)	const;
533 	SG_Char							operator []			(size_t i)	const;
534 	SG_Char							Get_Char			(size_t i)	const;
535 
536 	void							Set_Char			(size_t i, char    Character);
537 	void							Set_Char			(size_t i, wchar_t Character);
538 
539 	const char *					b_str				(void)	const;
540 	const wchar_t *					w_str				(void)	const;
541 	const SG_Char *					c_str				(void)	const;
542 
543 	operator const char *								(void)	const	{	return( b_str() );	}
544 	operator const wchar_t *							(void)	const	{	return( w_str() );	}
545 
546 	CSG_String &					Prepend				(const CSG_String &String);
547 
548 	CSG_String &					Append				(const CSG_String &String);
549 	CSG_String &					Append				(const char       *String);
550 	CSG_String &					Append				(const wchar_t    *String);
551 	CSG_String &					Append				(char    Character, size_t nRepeat = 1);
552 	CSG_String &					Append				(wchar_t Character, size_t nRepeat = 1);
553 
554 	void							operator +=			(const CSG_String &String);
555 	void							operator +=			(const char       *String);
556 	void							operator +=			(const wchar_t    *String);
557 	void							operator +=			(char    Character);
558 	void							operator +=			(wchar_t Character);
559 
560 	CSG_String						operator +			(const CSG_String &String)	const;
561 	CSG_String						operator +			(const char       *String)	const;
562 	CSG_String						operator +			(const wchar_t    *String)	const;
563 	CSG_String						operator +			(char    Character)			const;
564 	CSG_String						operator +			(wchar_t Character)			const;
565 
566 	int								Cmp					(const CSG_String &String)	const;
567 	int								CmpNoCase			(const CSG_String &String)	const;
568 
569 	bool							is_Same_As			(const CSG_String &String, bool bCase = true)	const;
570 	bool							is_Same_As			(const char     Character, bool bCase = true)	const;
571 	bool							is_Same_As			(const wchar_t  Character, bool bCase = true)	const;
572 
573 	CSG_String &					Make_Lower			(void);
574 	CSG_String &					Make_Upper			(void);
575 
576 	void							Clear				(void);
577 
578 	static CSG_String				Format				(const char    *Format, ...);
579 	static CSG_String				Format				(const wchar_t *Format, ...);
580 	int								Printf				(const char    *Format, ...);
581 	int								Printf				(const wchar_t *Format, ...);
582 
583 	size_t							Replace				(const CSG_String &sOld, const CSG_String &sNew, bool bReplaceAll = true);
584 
585 	CSG_String &					Remove				(size_t pos);
586 	CSG_String &					Remove				(size_t pos, size_t len);
587 
588 	int								Trim				(bool fromRight = false);
589 	int								Trim_Both			(void);
590 
591 	int								Find				(char    Character, bool fromEnd = false)	const;
592 	int								Find				(wchar_t Character, bool fromEnd = false)	const;
593 	int								Find				(const CSG_String &String)				const;
594 	bool							Contains			(const CSG_String &String)				const;
595 
596 	CSG_String						AfterFirst			(char    Character)						const;
597 	CSG_String						AfterFirst			(wchar_t Character)						const;
598 	CSG_String						AfterLast			(char    Character)						const;
599 	CSG_String						AfterLast			(wchar_t Character)						const;
600 	CSG_String						BeforeFirst			(char    Character)						const;
601 	CSG_String						BeforeFirst			(wchar_t Character)						const;
602 	CSG_String						BeforeLast			(char    Character)						const;
603 	CSG_String						BeforeLast			(wchar_t Character)						const;
604 
605 	CSG_String						Right				(size_t count)							const;
606 	CSG_String						Mid					(size_t first, size_t count = 0)		const;
607 	CSG_String						Left				(size_t count)							const;
608 
609 	bool							is_Number			(void)	const;
610 
611 	int								asInt				(void)									const;
612 	bool							asInt				(int    &Value)							const;
613 
614 	double							asDouble			(void)									const;
615 	bool							asDouble			(double &Value)							const;
616 
617 	static CSG_String				from_UTF8			(const char *String, size_t Length = 0);
618 
619 	size_t							to_UTF8				(char **pString)						const;
620 	CSG_Buffer						to_UTF8				(void)									const;
621 	size_t							to_MBChar			(char **pString, int Encoding)			const;
622 	CSG_Buffer						to_MBChar			(                int Encoding)			const;
623 	bool							to_ASCII			(char **pString, char Replace = '_')	const;
624 	CSG_Buffer						to_ASCII			(                char Replace = '_')	const;
625     std::string						to_StdString		(void)                                  const;
626     std::wstring					to_StdWstring		(void)                                  const;
627 
628 protected:
629 
630 	class wxString					*m_pString;
631 
632 };
633 
634 //---------------------------------------------------------
635 SAGA_API_DLL_EXPORT CSG_String		operator +			(const char    *A, const CSG_String &B);
636 SAGA_API_DLL_EXPORT CSG_String		operator +			(const wchar_t *A, const CSG_String &B);
637 SAGA_API_DLL_EXPORT CSG_String		operator +			(char           A, const CSG_String &B);
638 SAGA_API_DLL_EXPORT CSG_String		operator +			(wchar_t        A, const CSG_String &B);
639 
640 //---------------------------------------------------------
641 class SAGA_API_DLL_EXPORT CSG_Strings
642 {
643 public:
644 	CSG_Strings(void);
645 	CSG_Strings(const CSG_Strings &Strings);
646 	CSG_Strings(int nStrings, const SG_Char **Strings);
647 
648 	virtual ~CSG_Strings(void);
649 
650 	bool							Create				(const CSG_Strings &Strings);
651 	bool							Destroy				(void);
652 
Set_Count(int Count)653 	bool							Set_Count			(int    Count)	{	return( Set_Count((size_t)Count) );	}
654 	bool							Set_Count			(size_t Count);
Get_Count(void)655 	int								Get_Count			(void)	const	{	return( (int)m_Strings.Get_Size() );	}
Get_Size(void)656 	size_t							Get_Size			(void)	const	{	return(      m_Strings.Get_Size() );	}
657 
658 	bool							Add					(const CSG_Strings &Strings);
659 	bool							Add					(const CSG_String  &String );
Ins(const CSG_String & String,int Index)660 	bool							Ins					(const CSG_String  &String , int    Index)	{	return( Ins(String, (size_t)Index) );	}
661 	bool							Ins					(const CSG_String  &String , size_t Index);
Del(int Index)662 	bool							Del					(int    Index)	{	return( Del((size_t)Index) );	}
663 	bool							Del					(size_t Index);
664 
Get_String(int Index)665 	CSG_String &					Get_String			(int    Index) const	{	return( *((CSG_String *)m_Strings[Index]) );	}
Get_String(size_t Index)666 	CSG_String &					Get_String			(size_t Index) const	{	return( *((CSG_String *)m_Strings[Index]) );	}
667 
668 	CSG_String &					operator []			(int    Index) const	{	return( Get_String(Index) );	}
669 	CSG_String &					operator []			(size_t Index) const	{	return( Get_String(Index) );	}
670 
671 	CSG_Strings &					operator  =			(const CSG_Strings &Strings)	{	Create(Strings); return( *this );	}
672 	CSG_Strings &					operator +=			(const CSG_Strings &Strings)	{	Add   (Strings); return( *this );	}
673 	CSG_Strings &					operator +=			(const CSG_String  &String )	{	Add   (String ); return( *this );	}
674 
675 	bool							Sort				(bool Ascending = true);
676 
Clear(void)677 	void							Clear				(void)	{	Destroy();	}
Assign(const CSG_Strings & Strings)678 	bool							Assign				(const CSG_Strings &Strings)	{	return( Create(Strings) );	}
679 
680 
681 protected:
682 
683 	CSG_Array_Pointer				m_Strings;
684 
685 };
686 
687 //---------------------------------------------------------
688 #define SG_DEFAULT_DELIMITERS		" \t\r\n"
689 
690 typedef enum
691 {
692 	SG_TOKEN_INVALID,
693 	SG_TOKEN_DEFAULT,
694 	SG_TOKEN_RET_EMPTY,
695 	SG_TOKEN_RET_EMPTY_ALL,
696 	SG_TOKEN_RET_DELIMS,
697 	SG_TOKEN_STRTOK
698 }
699 TSG_String_Tokenizer_Mode;
700 
701 //---------------------------------------------------------
702 class SAGA_API_DLL_EXPORT CSG_String_Tokenizer
703 {
704 public:
705 	CSG_String_Tokenizer(void);
706 	CSG_String_Tokenizer(const CSG_String &String, const CSG_String &Delimiters = SG_DEFAULT_DELIMITERS, TSG_String_Tokenizer_Mode Mode = SG_TOKEN_DEFAULT);
707 
708 	~CSG_String_Tokenizer(void);
709 
710 
711 	size_t							Get_Tokens_Count	(void)	const;
712 	SG_Char							Get_Last_Delimiter	(void)	const;
713 	CSG_String						Get_Next_Token		(void);
714 	size_t							Get_Position		(void)	const;
715 	CSG_String						Get_String			(void)	const;
716 	bool							Has_More_Tokens		(void)	const;
717 	void							Set_String			(const CSG_String &String, const CSG_String &Delimiters = SG_DEFAULT_DELIMITERS, TSG_String_Tokenizer_Mode Mode = SG_TOKEN_DEFAULT);
718 
719 
720 private:
721 
722 	class wxStringTokenizer			*m_pTokenizer;
723 
724 };
725 
726 //---------------------------------------------------------
727 SAGA_API_DLL_EXPORT CSG_Strings		SG_String_Tokenize				(const CSG_String &String, const CSG_String &Delimiters = SG_DEFAULT_DELIMITERS, TSG_String_Tokenizer_Mode Mode = SG_TOKEN_DEFAULT);
728 
729 //---------------------------------------------------------
730 SAGA_API_DLL_EXPORT bool			SG_is_Character_Numeric			(int Character);
731 
732 SAGA_API_DLL_EXPORT int				SG_Printf						(const CSG_String &String);
733 SAGA_API_DLL_EXPORT int				SG_Printf						(const  char   *Format, ...);
734 SAGA_API_DLL_EXPORT int				SG_Printf						(const wchar_t *Format, ...);
735 
736 SAGA_API_DLL_EXPORT int				SG_FPrintf						(FILE *Stream, const CSG_String &String);
737 SAGA_API_DLL_EXPORT int				SG_FPrintf						(FILE *Stream, const  char   *Format, ...);
738 SAGA_API_DLL_EXPORT int				SG_FPrintf						(FILE *Stream, const wchar_t *Format, ...);
739 
740 SAGA_API_DLL_EXPORT CSG_String		SG_Get_CurrentTimeStr			(bool bWithDate = true);
741 
742 SAGA_API_DLL_EXPORT double			SG_Degree_To_Double				(const CSG_String &String);
743 SAGA_API_DLL_EXPORT CSG_String		SG_Double_To_Degree				(double Value);
744 
745 SAGA_API_DLL_EXPORT int				SG_Get_Significant_Decimals		(double Value, int maxDecimals = 6);
746 
747 SAGA_API_DLL_EXPORT void			SG_Flip_Decimal_Separators		(CSG_String &String);
748 
749 SAGA_API_DLL_EXPORT CSG_String		SG_Get_String					(double Value, int Precision = -99);
750 SAGA_API_DLL_EXPORT CSG_String		SG_Get_String					(int    Value, int Precision = 0);
751 
752 
753 ///////////////////////////////////////////////////////////
754 //														 //
755 //														 //
756 //														 //
757 ///////////////////////////////////////////////////////////
758 
759 //---------------------------------------------------------
760 class SAGA_API_DLL_EXPORT CSG_Bytes
761 {
762 public:
763 							CSG_Bytes		(void);
764 	bool					Create			(void);
765 
766 							CSG_Bytes		(const CSG_Bytes &Bytes);
767 	bool					Create			(const CSG_Bytes &Bytes);
768 
769 							CSG_Bytes		(const BYTE *Bytes, int nBytes);
770 	bool					Create			(const BYTE *Bytes, int nBytes);
771 
772 	virtual ~CSG_Bytes(void);
773 
774 	bool					Destroy			(void);
775 	bool					Clear			(void);
776 
Rewind(void)777 	void					Rewind			(void)				{	m_Cursor	= 0;	}
is_EOF(void)778 	bool					is_EOF			(void)				{	return( m_Cursor >= m_nBytes );	}
779 
Get_Count(void)780 	int						Get_Count		(void)		const	{	return( m_nBytes );	}
Get_Bytes(void)781 	BYTE *					Get_Bytes		(void)		const	{	return( m_Bytes );	}
782 
Get_Bytes(int i)783 	CSG_Bytes				Get_Bytes		(int i)		const	{	if( i < 0 || i >= m_nBytes ) i = 0; return( CSG_Bytes(m_Bytes + i, m_nBytes - i) );	}
784 	CSG_Bytes				operator +		(int i)		const	{	return( Get_Bytes(i) );	}
785 
Get_Byte(int i)786 	BYTE					Get_Byte		(int i)		const	{	return( i >= 0 && i < m_nBytes ? m_Bytes[i]  : 0 );		}
787 	BYTE					operator []		(int i)		const	{	return( Get_Byte(i) );	}
788 
789 	bool					Assign			(const CSG_Bytes &Bytes);
790 	CSG_Bytes &				operator =		(const CSG_Bytes &Bytes)	{	Assign(Bytes);	return( *this );	}
791 
792 	bool					Add				(const CSG_Bytes &Bytes);
793 	CSG_Bytes &				operator +=		(const CSG_Bytes &Bytes)	{	Add(Bytes);		return( *this );	}
794 
795 	bool					Add				(void *Bytes, int nBytes, bool bSwapBytes);
796 
Add(BYTE Value)797 	bool					Add				(BYTE   Value)							{	return( Add(&Value, sizeof(Value), false) );	}
798 	CSG_Bytes &				operator +=		(BYTE   Value)							{	Add(Value);		return( *this );	}
Add(char Value)799 	bool					Add				(char   Value)							{	return( Add(&Value, sizeof(Value), false) );	}
800 	CSG_Bytes &				operator +=		(char   Value)							{	Add(Value);		return( *this );	}
801 	bool					Add				(short  Value, bool bSwapBytes = false)	{	return( Add(&Value, sizeof(Value), bSwapBytes) );	}
802 	CSG_Bytes &				operator +=		(short  Value)							{	Add(Value);		return( *this );	}
803 	bool					Add				(WORD   Value, bool bSwapBytes = false)	{	return( Add(&Value, sizeof(Value), bSwapBytes) );	}
804 	CSG_Bytes &				operator +=		(WORD   Value)							{	Add(Value);		return( *this );	}
805 	bool					Add				(int    Value, bool bSwapBytes = false)	{	return( Add(&Value, sizeof(Value), bSwapBytes) );	}
806 	CSG_Bytes &				operator +=		(int    Value)							{	Add(Value);		return( *this );	}
807 	bool					Add				(DWORD  Value, bool bSwapBytes = false)	{	return( Add(&Value, sizeof(Value), bSwapBytes) );	}
808 	CSG_Bytes &				operator +=		(DWORD  Value)							{	Add(Value);		return( *this );	}
809 	bool					Add				(float  Value, bool bSwapBytes = false)	{	return( Add(&Value, sizeof(Value), bSwapBytes) );	}
810 	CSG_Bytes &				operator +=		(float  Value)							{	Add(Value);		return( *this );	}
811 	bool					Add				(double Value, bool bSwapBytes = false)	{	return( Add(&Value, sizeof(Value), bSwapBytes) );	}
812 	CSG_Bytes &				operator +=		(double Value)							{	Add(Value);		return( *this );	}
813 
asByte(int i)814 	BYTE					asByte			(int i)								const	{	return(       Get_Byte (i) );	}
asChar(int i)815 	char					asChar			(int i)								const	{	return( (char)Get_Byte (i) );	}
816 	short					asShort			(int i, bool bSwapBytes = false)	const	{	short	v = *((short  *)(m_Bytes + i)); if( bSwapBytes ) SG_Swap_Bytes(&v, sizeof(v)); return( v );	}
817 	WORD					asWord			(int i, bool bSwapBytes = false)	const	{	WORD	v = *((WORD   *)(m_Bytes + i)); if( bSwapBytes ) SG_Swap_Bytes(&v, sizeof(v)); return( v );	}
818 	int						asInt			(int i, bool bSwapBytes = false)	const	{	int		v = *((int    *)(m_Bytes + i)); if( bSwapBytes ) SG_Swap_Bytes(&v, sizeof(v)); return( v );	}
819 	DWORD					asDWord			(int i, bool bSwapBytes = false)	const	{	DWORD	v = *((DWORD  *)(m_Bytes + i)); if( bSwapBytes ) SG_Swap_Bytes(&v, sizeof(v)); return( v );	}
820 	float					asFloat			(int i, bool bSwapBytes = false)	const	{	float	v = *((float  *)(m_Bytes + i)); if( bSwapBytes ) SG_Swap_Bytes(&v, sizeof(v)); return( v );	}
821 	double					asDouble		(int i, bool bSwapBytes = false)	const	{	double	v = *((double *)(m_Bytes + i)); if( bSwapBytes ) SG_Swap_Bytes(&v, sizeof(v)); return( v );	}
822 
Read_Byte(void)823 	BYTE					Read_Byte		(void)						{	BYTE	v = asByte  (m_Cursor);             m_Cursor += sizeof(v); return( v ); }
Read_Char(void)824 	char					Read_Char		(void)						{	char	v = asByte  (m_Cursor);             m_Cursor += sizeof(v); return( v ); }
825 	short					Read_Short		(bool bSwapBytes = false)	{	short	v = asShort (m_Cursor, bSwapBytes); m_Cursor += sizeof(v); return( v ); }
826 	WORD					Read_Word		(bool bSwapBytes = false)	{	WORD	v = asWord  (m_Cursor, bSwapBytes); m_Cursor += sizeof(v); return( v ); }
827 	int						Read_Int		(bool bSwapBytes = false)	{	int		v = asInt   (m_Cursor, bSwapBytes); m_Cursor += sizeof(v); return( v ); }
828 	DWORD					Read_DWord		(bool bSwapBytes = false)	{	DWORD	v = asDWord (m_Cursor, bSwapBytes); m_Cursor += sizeof(v); return( v ); }
829 	float					Read_Float		(bool bSwapBytes = false)	{	float	v = asFloat (m_Cursor, bSwapBytes); m_Cursor += sizeof(v); return( v ); }
830 	double					Read_Double		(bool bSwapBytes = false)	{	double	v = asDouble(m_Cursor, bSwapBytes); m_Cursor += sizeof(v); return( v ); }
831 
832 	CSG_String				toHexString		(void)	const;
833 	bool					fromHexString	(const CSG_String &HexString);
834 
835 
836 private:
837 
838 	int						m_nBytes, m_nBuffer, m_Cursor;
839 
840 	BYTE					*m_Bytes;
841 
842 
843 	bool					_Inc_Array		(int nBytes);
844 
845 };
846 
847 //---------------------------------------------------------
848 class SAGA_API_DLL_EXPORT CSG_Bytes_Array
849 {
850 public:
851 	CSG_Bytes_Array(void);
852 	virtual ~CSG_Bytes_Array(void);
853 
854 	bool					Destroy			(void);
855 
Get_Count(void)856 	int						Get_Count		(void)	const	{	return( m_nBytes );		}
Get_Bytes(int i)857 	CSG_Bytes *				Get_Bytes		(int i)			{	return( i >= 0 && i < m_nBytes ? m_pBytes[i] : NULL );	}
858 	CSG_Bytes &				operator []		(int i)			{	return( *Get_Bytes(i) );	}
859 
860 	CSG_Bytes *				Add				(void);
861 
862 
863 private:
864 
865 	int						m_nBytes, m_nBuffer;
866 
867 	CSG_Bytes				**m_pBytes;
868 
869 };
870 
871 
872 ///////////////////////////////////////////////////////////
873 //														 //
874 //														 //
875 //														 //
876 ///////////////////////////////////////////////////////////
877 
878 //---------------------------------------------------------
879 class CSG_Stack
880 {
881 public:
CSG_Stack(size_t RecordSize)882 	CSG_Stack(size_t RecordSize) : m_Size(0), m_Buffer(0), m_RecordSize(RecordSize), m_Stack(NULL)	{}
~CSG_Stack(void)883 	virtual ~CSG_Stack(void)						{	Destroy();				}
884 
Get_RecordSize(void)885 	size_t					Get_RecordSize	(void)	{	return( m_RecordSize );	}
Get_Size(void)886 	size_t					Get_Size		(void)	{	return( m_Size );		}
Clear(void)887 	void					Clear			(void)	{	m_Size	= 0;			}
888 
Destroy(void)889 	void					Destroy			(void)
890 	{
891 		if( m_Stack )
892 		{
893 			SG_Free(m_Stack);
894 		}
895 
896 		m_Size		= 0;
897 		m_Buffer	= 0;
898 		m_Stack		= NULL;
899 	}
900 
901 
902 protected:
903 
Get_Record_Push(void)904 	void *					Get_Record_Push	(void)
905 	{
906 		if( m_Size < m_Buffer || _Grow() )
907 		{
908 			m_Size++;
909 
910 			return( (void *)(((char *)m_Stack) + m_RecordSize * (m_Size - 1)) );
911 		}
912 
913 		return( NULL );
914 	}
915 
Get_Record_Pop(void)916 	void *					Get_Record_Pop	(void)
917 	{
918 		if( m_Size > 0 )
919 		{
920 			m_Size--;
921 
922 			return( (void *)(((char *)m_Stack) + m_RecordSize * (m_Size)) );
923 		}
924 
925 		return( NULL );
926 	}
927 
928 
929 private:
930 
931 	size_t					m_Size, m_Buffer, m_RecordSize;
932 
933 	void					*m_Stack;
934 
935 
_Grow(void)936 	virtual bool			_Grow			(void)
937 	{
938 		void	*Stack	= SG_Realloc(m_Stack, (m_Buffer + 256) * m_RecordSize);
939 
940 		if( Stack )
941 		{
942 			m_Stack		= Stack;
943 			m_Buffer	+= 256;
944 
945 			return( true );
946 		}
947 
948 		return( false );
949 	}
950 
951 };
952 
953 
954 ///////////////////////////////////////////////////////////
955 //														 //
956 //						Data Types						 //
957 //														 //
958 ///////////////////////////////////////////////////////////
959 
960 //---------------------------------------------------------
961 typedef enum ESG_Data_Type
962 {
963 	SG_DATATYPE_Bit			= 0,
964 	SG_DATATYPE_Byte,
965 	SG_DATATYPE_Char,
966 	SG_DATATYPE_Word,
967 	SG_DATATYPE_Short,
968 	SG_DATATYPE_DWord,
969 	SG_DATATYPE_Int,
970 	SG_DATATYPE_ULong,
971 	SG_DATATYPE_Long,
972 	SG_DATATYPE_Float,
973 	SG_DATATYPE_Double,
974 	SG_DATATYPE_String,
975 	SG_DATATYPE_Date,
976 	SG_DATATYPE_Color,
977 	SG_DATATYPE_Binary,
978 	SG_DATATYPE_Undefined
979 }
980 TSG_Data_Type;
981 
982 //---------------------------------------------------------
983 const char	gSG_Data_Type_Identifier[][32]	=
984 {
985 	"BIT",
986 	"BYTE_UNSIGNED",
987 	"BYTE",
988 	"SHORTINT_UNSIGNED",
989 	"SHORTINT",
990 	"INTEGER_UNSIGNED",
991 	"INTEGER",
992 	"LONGINT_UNSIGNED",
993 	"LONGINT",
994 	"FLOAT",
995 	"DOUBLE",
996 	"STRING",
997 	"DATE",
998 	"COLOR",
999 	"BINARY",
1000 	"UNDEFINED"
1001 };
1002 
1003 //---------------------------------------------------------
SG_Data_Type_Get_Size(TSG_Data_Type Type)1004 inline size_t	SG_Data_Type_Get_Size	(TSG_Data_Type Type)
1005 {
1006 	switch( Type )
1007 	{
1008 	case SG_DATATYPE_Bit   : return( 0 );
1009 	case SG_DATATYPE_Byte  : return( sizeof(unsigned char) );
1010 	case SG_DATATYPE_Char  : return( sizeof(char) );
1011 	case SG_DATATYPE_Word  : return( sizeof(unsigned short int) );
1012 	case SG_DATATYPE_Short : return( sizeof(short int) );
1013 	case SG_DATATYPE_DWord : return( sizeof(unsigned int) );
1014 	case SG_DATATYPE_Int   : return( sizeof(int) );
1015 	case SG_DATATYPE_ULong : return( sizeof(uLong) );
1016 	case SG_DATATYPE_Long  : return( sizeof(sLong) );
1017 	case SG_DATATYPE_Float : return( sizeof(float) );
1018 	case SG_DATATYPE_Double: return( sizeof(double) );
1019 	case SG_DATATYPE_String: return( 0 );
1020 	case SG_DATATYPE_Date  : return( 0 );
1021 	case SG_DATATYPE_Color : return( sizeof(unsigned int) );
1022 	case SG_DATATYPE_Binary: return( 0 );
1023 	default                : return( 0 );
1024 	}
1025 }
1026 
1027 //---------------------------------------------------------
1028 SAGA_API_DLL_EXPORT CSG_String		SG_Data_Type_Get_Name		(TSG_Data_Type Type);
1029 SAGA_API_DLL_EXPORT CSG_String		SG_Data_Type_Get_Identifier	(TSG_Data_Type Type);
1030 SAGA_API_DLL_EXPORT TSG_Data_Type	SG_Data_Type_Get_Type		(const CSG_String &Identifier);
1031 SAGA_API_DLL_EXPORT bool			SG_Data_Type_is_Numeric		(TSG_Data_Type Type);
1032 SAGA_API_DLL_EXPORT bool			SG_Data_Type_Range_Check	(TSG_Data_Type Type, double &Value);
1033 
1034 
1035 ///////////////////////////////////////////////////////////
1036 //														 //
1037 //						File							 //
1038 //														 //
1039 ///////////////////////////////////////////////////////////
1040 
1041 //---------------------------------------------------------
1042 typedef enum ESG_File_Type
1043 {
1044 	SG_FILE_TYPE_NORMAL,
1045 	SG_FILE_TYPE_ZIP
1046 }
1047 TSG_File_Type;
1048 
1049 //---------------------------------------------------------
1050 enum ESG_File_Flags_Open
1051 {
1052 	SG_FILE_R,
1053 	SG_FILE_W,
1054 	SG_FILE_RW
1055 };
1056 
1057 //---------------------------------------------------------
1058 enum ESG_File_Flags_Seek
1059 {
1060 	SG_FILE_START,
1061 	SG_FILE_CURRENT,
1062 	SG_FILE_END
1063 };
1064 
1065 //---------------------------------------------------------
1066 class SAGA_API_DLL_EXPORT CSG_File
1067 {
1068 public:
1069 
1070 	CSG_File(void);
1071 	virtual ~CSG_File(void);
1072 
1073 									CSG_File			(const CSG_String &FileName, int Mode = SG_FILE_R, bool bBinary = true, int Encoding = SG_FILE_ENCODING_ANSI);
1074 	virtual bool					Open				(const CSG_String &FileName, int Mode = SG_FILE_R, bool bBinary = true, int Encoding = SG_FILE_ENCODING_ANSI);
1075 
1076 	virtual bool					Close				(void);
1077 
Get_File_Name(void)1078 	virtual const CSG_String &		Get_File_Name		(void)	const	{	return( m_FileName );	}
Get_File_Type(void)1079 	virtual TSG_File_Type			Get_File_Type		(void)	const	{	return( SG_FILE_TYPE_NORMAL );	}
1080 
Get_Stream(void)1081 	class wxStreamBase *			Get_Stream			(void)	const	{	return( (class wxStreamBase *)m_pStream );	}
1082 
1083 	bool							Set_Encoding		(int Encoding);
Get_Encoding(void)1084 	int								Get_Encoding		(void)	const	{	return( m_Encoding );	}
1085 
is_Open(void)1086 	bool							is_Open				(void)	const	{	return( m_pStream != NULL );	}
is_Reading(void)1087 	bool							is_Reading			(void)	const	{	return( m_pStream != NULL && m_Mode != SG_FILE_W );	}
is_Writing(void)1088 	bool							is_Writing			(void)	const	{	return( m_pStream != NULL && m_Mode != SG_FILE_R );	}
1089 	bool							is_EOF				(void)	const;
1090 
1091 	sLong							Length				(void)	const;
1092 
1093 	bool							Seek				(sLong Offset, int Origin = SG_FILE_START)	const;
1094 	bool							Seek_Start			(void)	const;
1095 	bool							Seek_End			(void)	const;
1096 
1097 	sLong							Tell				(void)	const;
1098 
1099 	int								Printf				(const char    *Format, ...);
1100 	int								Printf				(const wchar_t *Format, ...);
1101 
1102 	size_t							Read				(void             *Buffer, size_t Size, size_t Count = 1)	const;
1103 	size_t							Write				(void             *Buffer, size_t Size, size_t Count = 1)	const;
1104 	size_t							Read				(      CSG_String &Buffer, size_t Size)	const;
1105 	size_t							Write				(const CSG_String &Buffer)				const;
1106 
1107 	bool							Read_Line			(CSG_String &sLine)	const;
1108 
1109 	int								Read_Char			(void)	const;
1110 	int								Read_Int			(				bool bBigEndian = false)	const;
1111 	bool							Write_Int			(int    Value,	bool bBigEndian = false);
1112 	double							Read_Double			(				bool bBigEndian = false)	const;
1113 	bool							Write_Double		(double Value,	bool bBigEndian = false);
1114 
1115 	bool							Scan				(int        &Value)	const;
1116 	bool							Scan				(double     &Value)	const;
1117 	bool							Scan				(CSG_String &Value, SG_Char Separator)	const;
1118 
1119 	int								Scan_Int			(void)				const;
1120 	double							Scan_Double			(void)				const;
1121 	CSG_String						Scan_String			(SG_Char Separator)	const;
1122 
1123 
1124 protected:
1125 
1126 	int								m_Mode, m_Encoding;
1127 
1128 	CSG_String						m_FileName;
1129 
1130 	void							*m_pStream, *m_pConvert;
1131 
1132 
1133 	void							On_Construction		(void);
1134 
1135 };
1136 
1137 //---------------------------------------------------------
1138 class SAGA_API_DLL_EXPORT CSG_File_Zip : public CSG_File
1139 {
1140 public:
1141 
1142 	CSG_File_Zip(void);
1143 	virtual ~CSG_File_Zip(void);
1144 
1145 									CSG_File_Zip		(const CSG_String &FileName, int Mode = SG_FILE_R, int Encoding = SG_FILE_ENCODING_ANSI);
1146 	virtual bool					Open				(const CSG_String &FileName, int Mode = SG_FILE_R, int Encoding = SG_FILE_ENCODING_ANSI);
1147 
1148 	virtual bool					Close				(void);
1149 
Get_File_Type(void)1150 	virtual TSG_File_Type			Get_File_Type		(void)	const	{	return( SG_FILE_TYPE_ZIP );	}
1151 
1152 	bool							Add_Directory		(const CSG_String &Name);
1153 	bool							Add_File			(const CSG_String &Name, bool bBinary = true);
1154 
Get_File_Count(void)1155 	size_t							Get_File_Count		(void)	{	return( m_Files.Get_Size() );	}
1156 	bool							Get_File			(const CSG_String &Name);
1157 	bool							Get_File			(size_t Index);
1158 	virtual CSG_String				Get_File_Name		(size_t Index);
1159 	bool							is_Directory		(size_t Index);
1160 
1161 
1162 protected:
1163 
1164 	CSG_Array_Pointer				m_Files;
1165 
1166 };
1167 
1168 //---------------------------------------------------------
1169 SAGA_API_DLL_EXPORT bool			SG_Dir_Exists				(const CSG_String &Directory);
1170 SAGA_API_DLL_EXPORT bool			SG_Dir_Create				(const CSG_String &Directory);
1171 SAGA_API_DLL_EXPORT bool			SG_Dir_Delete				(const CSG_String &Directory, bool bRecursive = false);
1172 SAGA_API_DLL_EXPORT CSG_String		SG_Dir_Get_Current			(void);
1173 SAGA_API_DLL_EXPORT CSG_String		SG_Dir_Get_Temp				(void);
1174 SAGA_API_DLL_EXPORT bool			SG_Dir_List_Subdirectories	(CSG_Strings &List, const CSG_String &Directory);
1175 SAGA_API_DLL_EXPORT bool			SG_Dir_List_Files			(CSG_Strings &List, const CSG_String &Directory);
1176 SAGA_API_DLL_EXPORT bool			SG_Dir_List_Files			(CSG_Strings &List, const CSG_String &Directory, const CSG_String &Extension);
1177 
1178 SAGA_API_DLL_EXPORT bool			SG_File_Exists				(const CSG_String &FileName);
1179 SAGA_API_DLL_EXPORT bool			SG_File_Delete				(const CSG_String &FileName);
1180 SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Name_Temp		(const CSG_String &Prefix);
1181 SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Name_Temp		(const CSG_String &Prefix, const CSG_String &Directory);
1182 SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Name			(const CSG_String &full_Path, bool bExtension);
1183 SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Path			(const CSG_String &full_Path);
1184 SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Path_Absolute	(const CSG_String &full_Path);
1185 SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Path_Relative	(const CSG_String &Directory, const CSG_String &full_Path);
1186 SAGA_API_DLL_EXPORT CSG_String		SG_File_Make_Path			(const CSG_String &Directory, const CSG_String &Name);
1187 SAGA_API_DLL_EXPORT CSG_String		SG_File_Make_Path			(const CSG_String &Directory, const CSG_String &Name, const CSG_String &Extension);
1188 SAGA_API_DLL_EXPORT bool			SG_File_Cmp_Extension		(const CSG_String &FileName, const CSG_String &Extension);
1189 SAGA_API_DLL_EXPORT CSG_String		SG_File_Get_Extension		(const CSG_String &FileName);
1190 SAGA_API_DLL_EXPORT bool			SG_File_Set_Extension		(      CSG_String &FileName, const CSG_String &Extension);
1191 
1192 //---------------------------------------------------------
1193 SAGA_API_DLL_EXPORT bool			SG_Get_Environment			(const CSG_String &Variable,       CSG_String *Value = NULL);
1194 SAGA_API_DLL_EXPORT bool			SG_Set_Environment			(const CSG_String &Variable, const CSG_String &Value);
1195 
1196 
1197 ///////////////////////////////////////////////////////////
1198 //														 //
1199 //						Colors							 //
1200 //														 //
1201 ///////////////////////////////////////////////////////////
1202 
1203 //---------------------------------------------------------
1204 #define SG_GET_RGB( r, g, b   )	((DWORD) (((BYTE)(r) | ((WORD)(g) << 8)) | (((DWORD)(BYTE)(b)) << 16)))
1205 #define SG_GET_RGBA(r, g, b, a)	((DWORD) (((BYTE)(r) | ((WORD)(g) << 8)) | (((DWORD)(BYTE)(b)) << 16) | (((DWORD)(BYTE)(a)) << 24)))
1206 
1207 #define SG_GET_R(rgb)			((BYTE) ((rgb)      ))
1208 #define SG_GET_G(rgb)			((BYTE) ((rgb) >>  8))
1209 #define SG_GET_B(rgb)			((BYTE) ((rgb) >> 16))
1210 #define SG_GET_A(rgb)			((BYTE) ((rgb) >> 24))
1211 
1212 //---------------------------------------------------------
1213 #define SG_COLOR_BLACK			SG_GET_RGB(  0,   0,   0)
1214 #define SG_COLOR_GREY			SG_GET_RGB(128, 128, 128)
1215 #define SG_COLOR_GREY_LIGHT		SG_GET_RGB(192, 192, 192)
1216 #define SG_COLOR_WHITE			SG_GET_RGB(255, 255, 255)
1217 #define SG_COLOR_RED			SG_GET_RGB(255,   0,   0)
1218 #define SG_COLOR_RED_DARK		SG_GET_RGB(128,   0,   0)
1219 #define SG_COLOR_YELLOW			SG_GET_RGB(255, 255,   0)
1220 #define SG_COLOR_YELLOW_DARK	SG_GET_RGB(128, 128,   0)
1221 #define SG_COLOR_GREEN			SG_GET_RGB(  0, 255,   0)
1222 #define SG_COLOR_GREEN_DARK		SG_GET_RGB(  0, 128,   0)
1223 #define SG_COLOR_GREEN_LIGHT	SG_GET_RGB(  0, 255,   0)
1224 #define SG_COLOR_BLUE			SG_GET_RGB(  0,   0, 255)
1225 #define SG_COLOR_BLUE_DARK		SG_GET_RGB(  0,   0, 128)
1226 #define SG_COLOR_BLUE_LIGHT		SG_GET_RGB(  0, 255, 255)
1227 #define SG_COLOR_BLUE_GREEN		SG_GET_RGB(  0, 128, 128)
1228 #define SG_COLOR_PURPLE			SG_GET_RGB(128,   0, 128)
1229 #define SG_COLOR_PINK			SG_GET_RGB(255,   0, 255)
1230 #define SG_COLOR_NONE			-1
1231 #define SG_COLOR_RANDOM			-2
1232 
1233 //---------------------------------------------------------
1234 enum ESG_Colors
1235 {
1236 	SG_COLORS_DEFAULT			= 0,
1237 	SG_COLORS_DEFAULT_BRIGHT,
1238 	SG_COLORS_BLACK_WHITE,
1239 	SG_COLORS_BLACK_RED,
1240 	SG_COLORS_BLACK_GREEN,
1241 	SG_COLORS_BLACK_BLUE,
1242 	SG_COLORS_WHITE_RED,
1243 	SG_COLORS_WHITE_GREEN,
1244 	SG_COLORS_WHITE_BLUE,
1245 	SG_COLORS_YELLOW_RED,
1246 	SG_COLORS_YELLOW_GREEN,
1247 	SG_COLORS_YELLOW_BLUE,
1248 	SG_COLORS_RED_GREEN,
1249 	SG_COLORS_RED_BLUE,
1250 	SG_COLORS_GREEN_BLUE,
1251 	SG_COLORS_RED_GREY_BLUE,
1252 	SG_COLORS_RED_GREY_GREEN,
1253 	SG_COLORS_GREEN_GREY_BLUE,
1254 	SG_COLORS_RED_GREEN_BLUE,
1255 	SG_COLORS_RED_BLUE_GREEN,
1256 	SG_COLORS_GREEN_RED_BLUE,
1257 	SG_COLORS_RAINBOW,
1258 	SG_COLORS_NEON,
1259 	SG_COLORS_TOPOGRAPHY,
1260 	SG_COLORS_TOPOGRAPHY_2,
1261 	SG_COLORS_TOPOGRAPHY_3,
1262 	SG_COLORS_PRECIPITATION,
1263 	SG_COLORS_ASPECT_1,
1264 	SG_COLORS_ASPECT_2,
1265 	SG_COLORS_ASPECT_3,
1266 	SG_COLORS_COUNT
1267 };
1268 
1269 //---------------------------------------------------------
1270 SAGA_API_DLL_EXPORT CSG_String		SG_Colors_Get_Name	(int Index);
1271 
1272 SAGA_API_DLL_EXPORT long			SG_Color_Get_Random	(void);
1273 
1274 SAGA_API_DLL_EXPORT bool			SG_Color_From_Text	(const CSG_String &Text, long &Color);
1275 SAGA_API_DLL_EXPORT CSG_String		SG_Color_To_Text	(long Color, bool bHexadecimal = true);
1276 
1277 //---------------------------------------------------------
1278 class SAGA_API_DLL_EXPORT CSG_Colors
1279 {
1280 public:
1281 									CSG_Colors			(void);
1282 	bool							Create				(void);
1283 
1284 									CSG_Colors			(const CSG_Colors &Colors);
1285 	bool							Create				(const CSG_Colors &Colors);
1286 
1287 									CSG_Colors			(int nColors, int Palette = SG_COLORS_DEFAULT, bool bRevert = false);
1288 	bool							Create				(int nColors, int Palette = SG_COLORS_DEFAULT, bool bRevert = false);
1289 
1290 	virtual ~CSG_Colors(void);
1291 
1292 	void							Destroy				(void);
1293 
1294 	bool							Set_Count			(int nColors);
Get_Count(void)1295 	int								Get_Count			(void) const		{	return( m_nColors );	}
1296 
1297 	CSG_Colors &					operator  =			(const CSG_Colors &Colors);
1298 	long &							operator []			(int Index)			{	return( m_Colors[Index] );	}
1299 
1300 	bool							Set_Color			(int Index, long Color);
1301 	bool							Set_Color			(int Index, int Red, int Green, int Blue);
1302 	bool							Set_Red				(int Index, int Value);
1303 	bool							Set_Green			(int Index, int Value);
1304 	bool							Set_Blue			(int Index, int Value);
1305 	bool							Set_Brightness		(int Index, int Value);
1306 
Get_Color(int Index)1307 	long							Get_Color			(int Index)	const	{	return( m_nColors > 0 ? m_Colors[Index < 0 ? 0 : Index >= m_nColors ? m_nColors - 1 : Index] : 0 );	}
Get_Red(int Index)1308 	long							Get_Red				(int Index)	const	{	return( SG_GET_R(Get_Color(Index)) );	}
Get_Green(int Index)1309 	long							Get_Green			(int Index)	const	{	return( SG_GET_G(Get_Color(Index)) );	}
Get_Blue(int Index)1310 	long							Get_Blue			(int Index)	const	{	return( SG_GET_B(Get_Color(Index)) );	}
Get_Brightness(int Index)1311 	long							Get_Brightness		(int Index)	const	{	return( (Get_Red(Index) + Get_Green(Index) + Get_Blue(Index)) / 3 );	}
1312 
Get_Interpolated(double Index)1313 	long							Get_Interpolated	(double Index)	const
1314 	{
1315 		if( m_nColors <= 0             )	return( 0 );
1316 		if( Index     <= 0             )	return( m_Colors[0] );
1317 		if( Index     >= m_nColors - 1 )	return( m_Colors[m_nColors - 1] );
1318 
1319 		int	i	= (int)Index;	Index	-= i;
1320 
1321 		return( SG_GET_RGB(
1322 			SG_GET_R(m_Colors[i]) + Index * (SG_GET_R(m_Colors[i + 1]) - SG_GET_R(m_Colors[i])),
1323 			SG_GET_G(m_Colors[i]) + Index * (SG_GET_G(m_Colors[i + 1]) - SG_GET_G(m_Colors[i])),
1324 			SG_GET_B(m_Colors[i]) + Index * (SG_GET_B(m_Colors[i + 1]) - SG_GET_B(m_Colors[i])))
1325 		);
1326 	}
1327 
1328 	static int						Get_Predefined_Count(void);
1329 	static const SG_Char *			Get_Predefined_Name	(int Identifier);
1330 	bool							Set_Predefined		(int Index, bool bRevert = false, int nColors = 11);
1331 	bool							Set_Palette			(int Index, bool bRevert = false, int nColors = 11)	{	return( Set_Predefined(Index, bRevert, nColors) );	}
1332 	bool							Set_Default			(int nColors = 11);
1333 	bool							Set_Ramp			(long Color_A, long Color_B);
1334 	bool							Set_Ramp			(long Color_A, long Color_B, int iColor_A, int iColor_B);
1335 	bool							Set_Ramp_Brighness	(int Brightness_A, int Brightness_B);
1336 	bool							Set_Ramp_Brighness	(int Brightness_A, int Brightness_B, int iColor_A, int iColor_B);
1337 
1338 	bool							Random				(void);
1339 	bool							Invert				(void);
1340 	bool							Revert				(void);
1341 	bool							Greyscale			(void);
1342 
1343 	bool							Assign				(const CSG_Colors &Colors);
1344 	bool							Assign				(CSG_Colors *pSource);
1345 
1346 	bool							Load				(const CSG_String &File_Name);
1347 	bool							Save				(const CSG_String &File_Name, bool bBinary);
1348 
1349 	bool							Serialize			(CSG_File &Stream, bool bSave, bool bBinary);
1350 
1351 	bool							to_Text				(      CSG_String &String);
1352 	bool							from_Text			(const CSG_String &String);
1353 
1354 
1355 private:
1356 
1357 	int								m_nColors;
1358 
1359 	long							*m_Colors;
1360 
1361 
1362 	void							_Set_Brightness		(double &a, double &b, double &c, int Pass = 0);
1363 
1364 };
1365 
1366 
1367 ///////////////////////////////////////////////////////////
1368 //														 //
1369 //						Translator						 //
1370 //														 //
1371 ///////////////////////////////////////////////////////////
1372 
1373 //---------------------------------------------------------
1374 class SAGA_API_DLL_EXPORT CSG_Translator
1375 {
1376 public:
1377 	CSG_Translator(void);
1378 	virtual ~CSG_Translator(void);
1379 
1380 									CSG_Translator			(const CSG_String &File_Name, bool bSetExtension = true, int iText = 0, int iTranslation = 1, bool bCmpNoCase = false);
1381 	bool							Create					(const CSG_String &File_Name, bool bSetExtension = true, int iText = 0, int iTranslation = 1, bool bCmpNoCase = false);
1382 
1383 									CSG_Translator			(class CSG_Table *pTranslations, int iText = 0, int iTranslation = 1, bool bCmpNoCase = false);
1384 	bool							Create					(class CSG_Table *pTranslations, int iText = 0, int iTranslation = 1, bool bCmpNoCase = false);
1385 
1386 	void							Destroy					(void);
1387 
is_CaseSensitive(void)1388 	bool							is_CaseSensitive		(void)		const	{	return( !m_bCmpNoCase );	}
1389 
Get_Count(void)1390 	int								Get_Count				(void)		const	{	return( m_nTranslations );	}
Get_Text(int i)1391 	const SG_Char *					Get_Text				(int i)		const	{	return( i >= 0 && i < m_nTranslations ? m_Translations[i]->m_Text        : SG_T("") );	}
Get_Translation(int i)1392 	const SG_Char *					Get_Translation			(int i)		const	{	return( i >= 0 && i < m_nTranslations ? m_Translations[i]->m_Translation : SG_T("") );	}
1393 
1394 	const SG_Char *					Get_Translation			(const SG_Char *Text, bool bReturnNullOnNotFound = false)	const;
1395 	bool							Get_Translation			(const SG_Char *Text, CSG_String &Translation)				const;
1396 
1397 
1398 private:
1399 
1400 	class CSG_Translation
1401 	{
1402 	public:
CSG_Translation(const CSG_String & Text,const CSG_String & Translation)1403 		CSG_Translation(const CSG_String &Text, const CSG_String &Translation)
1404 		{
1405 			m_Text					= Text;
1406 			m_Translation			= Translation;
1407 		}
1408 
1409 		CSG_String					m_Text, m_Translation;
1410 	};
1411 
1412 
1413 private:
1414 
1415 	bool							m_bCmpNoCase;
1416 
1417 	int								m_nTranslations;
1418 
1419 	CSG_Translation					**m_Translations;
1420 
1421 
1422 	int								_Get_Index				(const CSG_String &Text)	const;
1423 
1424 };
1425 
1426 //---------------------------------------------------------
1427 SAGA_API_DLL_EXPORT CSG_Translator &	SG_Get_Translator	(void);
1428 
1429 SAGA_API_DLL_EXPORT const SG_Char *		SG_Translate		(const CSG_String &Text);
1430 
1431 #define _TL(s)	SG_Translate(L ## s)
1432 #define _TW(s)	SG_Translate(CSG_String(s))
1433 
1434 
1435 ///////////////////////////////////////////////////////////
1436 //														 //
1437 //						UI Callback						 //
1438 //														 //
1439 ///////////////////////////////////////////////////////////
1440 
1441 //---------------------------------------------------------
1442 typedef enum ESG_UI_MSG_STYLE
1443 {
1444 	SG_UI_MSG_STYLE_NORMAL	= 0,
1445 	SG_UI_MSG_STYLE_BOLD,
1446 	SG_UI_MSG_STYLE_ITALIC,
1447 	SG_UI_MSG_STYLE_SUCCESS,
1448 	SG_UI_MSG_STYLE_FAILURE,
1449 	SG_UI_MSG_STYLE_BIG,
1450 	SG_UI_MSG_STYLE_SMALL,
1451 	SG_UI_MSG_STYLE_01,
1452 	SG_UI_MSG_STYLE_02,
1453 	SG_UI_MSG_STYLE_03
1454 }
1455 TSG_UI_MSG_STYLE;
1456 
1457 //---------------------------------------------------------
1458 typedef enum ESG_UI_DataObject_Update
1459 {
1460 	SG_UI_DATAOBJECT_UPDATE_ONLY	= 0,
1461 	SG_UI_DATAOBJECT_SHOW,
1462 	SG_UI_DATAOBJECT_SHOW_NEW_MAP,
1463 	SG_UI_DATAOBJECT_SHOW_LAST_MAP
1464 }
1465 TSG_UI_DataObject_Update;
1466 
1467 //---------------------------------------------------------
1468 typedef enum ESG_UI_Callback_ID
1469 {
1470 	CALLBACK_PROCESS_GET_OKAY,
1471 	CALLBACK_PROCESS_SET_OKAY,
1472 	CALLBACK_PROCESS_SET_PROGRESS,
1473 	CALLBACK_PROCESS_SET_READY,
1474 	CALLBACK_PROCESS_SET_TEXT,
1475 
1476 	CALLBACK_STOP_EXECUTION,
1477 
1478 	CALLBACK_DLG_MESSAGE,
1479 	CALLBACK_DLG_CONTINUE,
1480 	CALLBACK_DLG_ERROR,
1481 
1482 	CALLBACK_DLG_PARAMETERS,
1483 
1484 	CALLBACK_MESSAGE_ADD,
1485 	CALLBACK_MESSAGE_ADD_ERROR,
1486 	CALLBACK_MESSAGE_ADD_EXECUTION,
1487 
1488 	CALLBACK_DATAOBJECT_ADD,
1489 	CALLBACK_DATAOBJECT_UPDATE,
1490 	CALLBACK_DATAOBJECT_SHOW,
1491 	CALLBACK_DATAOBJECT_ASIMAGE,
1492 
1493 	CALLBACK_DATAOBJECT_COLORS_GET,
1494 	CALLBACK_DATAOBJECT_COLORS_SET,
1495 	CALLBACK_DATAOBJECT_PARAMS_GET,
1496 	CALLBACK_DATAOBJECT_PARAMS_SET,
1497 
1498 	CALLBACK_DATABASE_UPDATE,
1499 
1500 	CALLBACK_GUI_GET_WINDOW,
1501 	CALLBACK_GET_APP_PATH
1502 }
1503 TSG_UI_Callback_ID;
1504 
1505 //---------------------------------------------------------
1506 class SAGA_API_DLL_EXPORT CSG_UI_Parameter
1507 {
1508 public:
CSG_UI_Parameter(void)1509 	CSG_UI_Parameter(void)                    : Boolean(false), Number( 0.  ), Pointer(NULL)	{}
CSG_UI_Parameter(bool Value)1510 	CSG_UI_Parameter(bool              Value) : Boolean(Value), Number( 0.  ), Pointer(NULL)	{}
CSG_UI_Parameter(int Value)1511 	CSG_UI_Parameter(int               Value) : Boolean(false), Number(Value), Pointer(NULL)	{}
CSG_UI_Parameter(double Value)1512 	CSG_UI_Parameter(double            Value) : Boolean(false), Number(Value), Pointer(NULL)	{}
CSG_UI_Parameter(const CSG_String & Value)1513 	CSG_UI_Parameter(const CSG_String &Value) : Boolean(false), Number( 0.  ), Pointer(NULL), String(Value)	{}
CSG_UI_Parameter(void * Value)1514 	CSG_UI_Parameter(void             *Value) : Boolean(false), Number( 0.  ), Pointer(Value)	{}
1515 	CSG_UI_Parameter(const CSG_UI_Parameter &Copy);
1516 
1517 	bool		Boolean;
1518 
1519 	double		Number;
1520 
1521 	void		*Pointer;
1522 
1523 	CSG_String	String;
1524 
1525 };
1526 
1527 //---------------------------------------------------------
1528 typedef int (* TSG_PFNC_UI_Callback) (TSG_UI_Callback_ID ID, CSG_UI_Parameter &Param_1, CSG_UI_Parameter &Param_2);
1529 
1530 //---------------------------------------------------------
1531 SAGA_API_DLL_EXPORT bool					SG_Set_UI_Callback			(TSG_PFNC_UI_Callback Function);
1532 SAGA_API_DLL_EXPORT TSG_PFNC_UI_Callback	SG_Get_UI_Callback			(void);
1533 
1534 //---------------------------------------------------------
1535 SAGA_API_DLL_EXPORT int						SG_UI_Progress_Lock			(bool bOn);
1536 SAGA_API_DLL_EXPORT int						SG_UI_Progress_Reset		(void);
1537 SAGA_API_DLL_EXPORT bool					SG_UI_Process_Get_Okay		(bool bBlink = false);
1538 SAGA_API_DLL_EXPORT bool					SG_UI_Process_Set_Okay		(bool bOkay = true);
1539 SAGA_API_DLL_EXPORT bool					SG_UI_Process_Set_Progress	(double Position, double Range);
1540 SAGA_API_DLL_EXPORT bool					SG_UI_Process_Set_Ready		(void);
1541 SAGA_API_DLL_EXPORT void					SG_UI_Process_Set_Text		(const CSG_String &Text);
1542 
1543 SAGA_API_DLL_EXPORT bool					SG_UI_Stop_Execution		(bool bDialog);
1544 
1545 SAGA_API_DLL_EXPORT void					SG_UI_Dlg_Message			(const CSG_String &Message, const CSG_String &Caption);
1546 SAGA_API_DLL_EXPORT bool					SG_UI_Dlg_Continue			(const CSG_String &Message, const CSG_String &Caption);
1547 SAGA_API_DLL_EXPORT int						SG_UI_Dlg_Error				(const CSG_String &Message, const CSG_String &Caption);
1548 SAGA_API_DLL_EXPORT bool					SG_UI_Dlg_Parameters		(class CSG_Parameters *pParameters, const CSG_String &Caption);
1549 
1550 SAGA_API_DLL_EXPORT int						SG_UI_Msg_Lock				(bool bOn);
1551 SAGA_API_DLL_EXPORT int						SG_UI_Msg_Reset				(void);
1552 SAGA_API_DLL_EXPORT void					SG_UI_Msg_Add				(const CSG_String &Message, bool bNewLine, TSG_UI_MSG_STYLE Style = SG_UI_MSG_STYLE_NORMAL);
1553 SAGA_API_DLL_EXPORT void					SG_UI_Msg_Add_Error			(const CSG_String &Message);
1554 SAGA_API_DLL_EXPORT void					SG_UI_Msg_Add_Execution		(const CSG_String &Message, bool bNewLine, TSG_UI_MSG_STYLE Style = SG_UI_MSG_STYLE_NORMAL);
1555 
1556 SAGA_API_DLL_EXPORT void					SG_UI_ProgressAndMsg_Lock	(bool bOn);
1557 SAGA_API_DLL_EXPORT void					SG_UI_ProgressAndMsg_Reset	(void);
1558 
1559 SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Add		(class CSG_Data_Object *pDataObject, int Show);
1560 SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Update		(class CSG_Data_Object *pDataObject, int Show, class CSG_Parameters *pParameters);
1561 SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Show		(class CSG_Data_Object *pDataObject, int Show);
1562 SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_asImage	(class CSG_Data_Object *pDataObject, class CSG_Grid *pGrid);
1563 
1564 SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Colors_Get	(class CSG_Data_Object *pDataObject, class CSG_Colors *pColors);
1565 SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Colors_Set	(class CSG_Data_Object *pDataObject, class CSG_Colors *pColors);
1566 SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Params_Get	(class CSG_Data_Object *pDataObject, class CSG_Parameters *pParameters);
1567 SAGA_API_DLL_EXPORT bool					SG_UI_DataObject_Params_Set	(class CSG_Data_Object *pDataObject, class CSG_Parameters *pParameters);
1568 
1569 SAGA_API_DLL_EXPORT bool					SG_UI_ODBC_Update			(const CSG_String &Server);
1570 
1571 SAGA_API_DLL_EXPORT void *					SG_UI_Get_Window_Main		(void);
1572 SAGA_API_DLL_EXPORT CSG_String				SG_UI_Get_Application_Path	(bool bPathOnly = false);
1573 
1574 
1575 ///////////////////////////////////////////////////////////
1576 //														 //
1577 //                     Environment                       //
1578 //														 //
1579 ///////////////////////////////////////////////////////////
1580 
1581 //---------------------------------------------------------
1582 SAGA_API_DLL_EXPORT bool					SG_Initialize_Environment	(bool bLibraries = true, bool bProjections = true, const SG_Char *Directory = NULL, bool bInitializeWX = true);
1583 SAGA_API_DLL_EXPORT bool					SG_Uninitialize_Environment	(void);
1584 
1585 
1586 ///////////////////////////////////////////////////////////
1587 //														 //
1588 //														 //
1589 //														 //
1590 ///////////////////////////////////////////////////////////
1591 
1592 //---------------------------------------------------------
1593 #endif // #ifndef HEADER_INCLUDED__SAGA_API__api_core_H
1594