📄 api_core.h
字号:
///////////////////////////////////////////////////////////
// //
// SAGA //
// //
// System for Automated Geoscientific Analyses //
// //
// Application Programming Interface //
// //
// Library: SAGA_API //
// //
//-------------------------------------------------------//
// //
// api_core.h //
// //
// Copyright (C) 2005 by Olaf Conrad //
// //
//-------------------------------------------------------//
// //
// This file is part of 'SAGA - System for Automated //
// Geoscientific Analyses'. //
// //
// This library is free software; you can redistribute //
// it and/or modify it under the terms of the GNU Lesser //
// General Public License as published by the Free //
// Software Foundation, version 2.1 of the License. //
// //
// This library is distributed in the hope that it will //
// be useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A //
// PARTICULAR PURPOSE. See the GNU Lesser General Public //
// License for more details. //
// //
// You should have received a copy of the GNU Lesser //
// General Public License along with this program; if //
// not, write to the Free Software Foundation, Inc., //
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, //
// USA. //
// //
//-------------------------------------------------------//
// //
// contact: Olaf Conrad //
// Institute of Geography //
// University of Goettingen //
// Goldschmidtstr. 5 //
// 37077 Goettingen //
// Germany //
// //
// e-mail: oconrad@saga-gis.org //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#ifndef HEADER_INCLUDED__SAGA_API__api_core_H
#define HEADER_INCLUDED__SAGA_API__api_core_H
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#ifdef _SAGA_MSW
#define _SAGA_DLL_EXPORT __declspec( dllexport )
#define _SAGA_DLL_IMPORT __declspec( dllimport )
#else
#define _SAGA_DLL_EXPORT
#define _SAGA_DLL_IMPORT
#endif
//---------------------------------------------------------
#ifdef _SAGA_API_EXPORTS
#define SAGA_API_DLL_EXPORT _SAGA_DLL_EXPORT
#else
#define SAGA_API_DLL_EXPORT _SAGA_DLL_IMPORT
#endif
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#ifndef SWIG
#include <stdlib.h>
#include <stdio.h>
#include <wchar.h>
#endif // #ifdef SWIG
///////////////////////////////////////////////////////////
// //
// //
// //
///////////////////////////////////////////////////////////
/*
* this is defined by configure, but will not be on a normal application build
*/
#ifndef SIZEOF_LONG
# if defined(__alpha) || defined(__sparcv9) || defined(__LP64__) || (defined(__HOS_AIX__) && defined(_LP64))
# define SIZEOF_LONG 8
#else
# define SIZEOF_LONG 4
#endif
#endif
//---------------------------------------------------------
#ifdef _TYPEDEF_BOOL
typedef unsigned int bool;
#define true ((bool)1)
#define false ((bool)0)
#endif // _TYPEDEF_BOOL
//---------------------------------------------------------
#ifdef _TYPEDEF_BYTE
typedef unsigned char BYTE;
#endif // _TYPEDEF_BYTE
//---------------------------------------------------------
#ifdef _TYPEDEF_WORD
typedef unsigned short WORD;
#if (SIZEOF_LONG == 4)
typedef unsigned long DWORD;
#else
typedef unsigned int DWORD;
#endif
#endif // _TYPEDEF_WORD
///////////////////////////////////////////////////////////
// //
// Memory //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#define SG_GET_LONG(b0, b1, b2, b3) ((long) (((BYTE)(b0) | ((WORD)(b1) << 8)) | (((DWORD)(BYTE)(b2)) << 16) | (((DWORD)(BYTE)(b3)) << 24)))
#define SG_GET_BYTE_0(vLong) ((BYTE) ((vLong) ))
#define SG_GET_BYTE_1(vLong) ((BYTE) ((vLong) >> 8))
#define SG_GET_BYTE_2(vLong) ((BYTE) ((vLong) >> 16))
#define SG_GET_BYTE_3(vLong) ((BYTE) ((vLong) >> 24))
//---------------------------------------------------------
SAGA_API_DLL_EXPORT void * SG_Malloc (size_t size);
SAGA_API_DLL_EXPORT void * SG_Calloc (size_t num, size_t size);
SAGA_API_DLL_EXPORT void * SG_Realloc (void *memblock, size_t size);
SAGA_API_DLL_EXPORT void SG_Free (void *memblock);
SAGA_API_DLL_EXPORT void SG_Swap_Bytes (void *Buffer, int nBytes);
SAGA_API_DLL_EXPORT int SG_Mem_Get_Int (const char *Buffer , bool bSwapBytes);
SAGA_API_DLL_EXPORT void SG_Mem_Set_Int (char *Buffer, int Value , bool bSwapBytes);
SAGA_API_DLL_EXPORT double SG_Mem_Get_Double (const char *Buffer , bool bSwapBytes);
SAGA_API_DLL_EXPORT void SG_Mem_Set_Double (char *Buffer, double Value , bool bSwapBytes);
///////////////////////////////////////////////////////////
// //
// String //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#ifndef _SAGA_UNICODE
#define SG_Char char
#define SG_T(s) s
#define SG_PRINTF printf
#define SG_SSCANF sscanf
#define SG_STR_CMP strcmp
#define SG_STR_CPY strcpy
#define SG_STR_LEN strlen
#define SG_STR_TOD strtod
#define SG_STR_SGTOMB(s) s
#define SG_STR_MBTOSG(s) s
#else
#define SG_Char wchar_t
#define SG_T(s) L ## s
#define SG_PRINTF wprintf
#define SG_SSCANF swscanf
#define SG_STR_CMP wcscmp
#define SG_STR_CPY wcscpy
#define SG_STR_LEN wcslen
#define SG_STR_TOD wcstod
#define SG_STR_SGTOMB(s) CSG_String(s).b_str()
#define SG_STR_MBTOSG(s) CSG_String(s).c_str()
#endif
//---------------------------------------------------------
class SAGA_API_DLL_EXPORT CSG_String
{
public:
CSG_String(void);
CSG_String(const CSG_String &String);
CSG_String(const SG_Char *String);
#ifdef _SAGA_UNICODE
CSG_String(const char *String);
#endif
CSG_String(SG_Char Character);
virtual ~CSG_String(void);
const SG_Char * c_str (void) const;
operator const SG_Char * (void) const { return( c_str() ); }
#ifndef _SAGA_UNICODE
const char * b_str (void) { return( c_str() ); }
#else
const char * b_str (void);
#endif
size_t Length (void) const;
void Clear (void);
int Printf (const SG_Char *Format, ...);
static CSG_String Format (const SG_Char *Format, ...);
CSG_String & Append (const SG_Char *String);
CSG_String & Append (SG_Char Character);
CSG_String & operator = (const CSG_String &String);
CSG_String & operator = (const SG_Char *String);
CSG_String & operator = (SG_Char Character);
CSG_String operator + (const CSG_String &String) const;
CSG_String operator + (const SG_Char *String) const;
CSG_String operator + (SG_Char Character) const;
void operator += (const CSG_String &String);
void operator += (const SG_Char *String);
void operator += (SG_Char Character);
SG_Char & operator [] (int i);
int Cmp (const SG_Char *String) const;
int CmpNoCase (const SG_Char *String) const;
CSG_String & Make_Lower (void);
CSG_String & Make_Upper (void);
size_t Replace (const SG_Char *sOld, const SG_Char *sNew, bool replaceAll = true);
CSG_String & Remove (size_t pos);
CSG_String & Remove (size_t pos, size_t len);
int Remove_WhiteChars (bool fromEnd = false);
int Find (SG_Char Character, bool fromEnd = false);
int Find (const SG_Char *String);
bool Contains (const SG_Char *String);
CSG_String AfterFirst (SG_Char Character) const;
CSG_String AfterLast (SG_Char Character) const;
CSG_String BeforeFirst (SG_Char Character) const;
CSG_String BeforeLast (SG_Char Character) const;
CSG_String Right (size_t count) const;
CSG_String Mid (size_t first, size_t count) const;
CSG_String Left (size_t count) const;
int asInt (void) const;
bool asInt (int &Value) const;
double asDouble (void) const;
bool asDouble (double &Value) const;
protected:
class wxString *m_pString;
#ifdef _SAGA_UNICODE
char *m_bString;
#endif
};
//---------------------------------------------------------
SAGA_API_DLL_EXPORT CSG_String operator + (const SG_Char *A, const CSG_String &B);
SAGA_API_DLL_EXPORT CSG_String operator + (SG_Char A, const CSG_String &B);
//---------------------------------------------------------
class SAGA_API_DLL_EXPORT CSG_Strings
{
public:
CSG_Strings(void);
CSG_Strings(const CSG_Strings &Strings);
CSG_Strings(int nStrings, const SG_Char **Strings);
virtual ~CSG_Strings(void);
void Clear (void);
CSG_Strings & operator = (const CSG_Strings &Strings);
bool Assign (const CSG_Strings &Strings);
bool Add (const CSG_String &String);
bool Set_Count (int nStrings);
int Get_Count (void) { return( m_nStrings ); }
CSG_String & operator [] (int Index) const { return( *m_Strings[Index] ); }
CSG_String & Get_String (int Index) const { return( *m_Strings[Index] ); }
protected:
int m_nStrings;
CSG_String **m_Strings;
};
//---------------------------------------------------------
SAGA_API_DLL_EXPORT CSG_String SG_Get_CurrentTimeStr (bool bWithDate = true);
SAGA_API_DLL_EXPORT double SG_Degree_To_Double (const SG_Char *String);
SAGA_API_DLL_EXPORT CSG_String SG_Double_To_Degree (double Value);
SAGA_API_DLL_EXPORT double SG_Date_To_Double (const SG_Char *String);
SAGA_API_DLL_EXPORT CSG_String SG_Double_To_Date (double Value);
SAGA_API_DLL_EXPORT int SG_Get_Significant_Decimals (double Value, int maxDecimals = 6);
SAGA_API_DLL_EXPORT CSG_String SG_Get_String (double Value, int Precision = 2, bool bScientific = false);
///////////////////////////////////////////////////////////
// //
// File //
// //
///////////////////////////////////////////////////////////
//---------------------------------------------------------
#ifndef _SAGA_UNICODE
#define SG_FILE_OPEN fopen
#define SG_FILE_PRINTF fprintf
#define SG_FILE_SCANF fscanf
#define SG_FILE_GETC fgetc
#else
#ifndef _SAGA_LINUX
#define SG_FILE_OPEN _wfopen
#else
#define SG_FILE_OPEN fopen
#endif
#define SG_FILE_PRINTF fwprintf
#define SG_FILE_SCANF fwscanf
#define SG_FILE_GETC fgetwc
#endif
//---------------------------------------------------------
enum
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -