SAGA API  v9.2
tool_library_interface.cpp
Go to the documentation of this file.
1 
3 // //
4 // SAGA //
5 // //
6 // System for Automated Geoscientific Analyses //
7 // //
8 // Application Programming Interface //
9 // //
10 // Library: SAGA_API //
11 // //
12 //-------------------------------------------------------//
13 // //
14 // tool_library_interface.cpp //
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 // //
51 
52 //---------------------------------------------------------
53 #include "saga_api.h"
54 
55 
57 // //
58 // //
59 // //
61 
62 //---------------------------------------------------------
64 {
65  m_Fnc_Create_Tool = NULL;
66 }
67 
68 //---------------------------------------------------------
70 {
71  Destroy();
72 }
73 
74 
76 // //
78 
79 //---------------------------------------------------------
80 bool CSG_Tool_Library_Interface::Create(const CSG_String &Version, const CSG_String &TLB_Path, TSG_PFNC_TLB_Get_Info Fnc_Info, TSG_PFNC_TLB_Create_Tool Fnc_Create_Tool)
81 {
82  Destroy();
83 
84  //-----------------------------------------------------
85  m_Info.Set_Count(TLB_INFO_Count);
86 
87  for(int i=0; i<TLB_INFO_User; i++)
88  {
89  m_Info[i] = Fnc_Info(i);
90  }
91 
92  CSG_String Library = SG_File_Get_Name(TLB_Path, false);
93 
94  #if !defined(_SAGA_MSW)
95  if( Library.Find("lib") == 0 )
96  {
97  Library = Library.Right(Library.Length() - 3);
98  }
99  #endif
100 
101  m_Info[TLB_INFO_Library ] = Library;
102  m_Info[TLB_INFO_SAGA_Version] = Version;
103  m_Info[TLB_INFO_File ] = SG_File_Get_Path_Absolute(TLB_Path);
104 
105  if( Version.Cmp(SAGA_VERSION) )
106  {
107  SG_UI_Msg_Add_Error(CSG_String::Format("SAGA API %s: %s=%s, %s=%s", _TL("version mismatch"), _TL("current version"), SAGA_VERSION,
108  Library.c_str(), Version.c_str()
109  ));
110 
111  return( false );
112  }
113 
114  //-----------------------------------------------------
115  m_Fnc_Create_Tool = Fnc_Create_Tool;
116 
117  CSG_Tool *pTool;
118 
119  for(int ID=0; (pTool = m_Fnc_Create_Tool(ID)) != NULL; ID++)
120  {
121  if( pTool != TLB_INTERFACE_SKIP_TOOL )
122  {
123  pTool->m_ID.Printf("%d", ID);
124  pTool->m_Library = m_Info[TLB_INFO_Library ];
125  pTool->m_Library_Menu = m_Info[TLB_INFO_Menu_Path];
126  pTool->m_File_Name = m_Info[TLB_INFO_File ];
127 
128  m_Tools.Add(pTool);
129  }
130  }
131 
132  return( Get_Count() > 0 );
133 }
134 
135 //---------------------------------------------------------
137 {
138  Delete_Tools();
139 
140  for(size_t i=0; i<m_Tools.Get_uSize(); i++)
141  {
142  delete((CSG_Tool *)m_Tools[i]);
143  }
144 
145  m_Tools.Destroy();
146 
147  return( true );
148 }
149 
150 
152 // //
154 
155 //---------------------------------------------------------
157 {
158  return( m_Info[ID] );
159 }
160 
161 
163 // //
165 
166 //---------------------------------------------------------
168 {
169  return( (int)m_Tools.Get_Size() );
170 }
171 
172 //---------------------------------------------------------
174 {
175  if( i >= 0 && i < Get_Count() )
176  {
177  return( (CSG_Tool *)m_Tools[i] );
178  }
179 
180  return( NULL );
181 }
182 
183 
185 // //
187 
188 //---------------------------------------------------------
190 {
191  CSG_Tool *pTool = m_Fnc_Create_Tool ? m_Fnc_Create_Tool(ID) : NULL;
192 
193  if( pTool && pTool != TLB_INTERFACE_SKIP_TOOL )
194  {
195  pTool->m_ID.Printf("%d", ID);
196  pTool->m_Library = m_Info[TLB_INFO_Library ];
197  pTool->m_Library_Menu = m_Info[TLB_INFO_Menu_Path];
198  pTool->m_File_Name = m_Info[TLB_INFO_File ];
199  pTool->m_bWithGUI = bWithGUI;
200 
201  m_xTools.Add(pTool);
202 
203  return( pTool );
204  }
205 
206  return( NULL );
207 }
208 
209 //---------------------------------------------------------
211 {
212  for(size_t i=0; i<m_xTools.Get_uSize(); i++)
213  {
214  if( pTool == m_xTools.Get(i) && m_xTools.Del(i) )
215  {
216  delete(pTool);
217 
218  return( true );
219  }
220  }
221 
222  return( false );
223 }
224 
225 //---------------------------------------------------------
227 {
228  for(size_t i=0; i<m_xTools.Get_uSize(); i++)
229  {
230  delete((CSG_Tool *)m_xTools[i]);
231  }
232 
233  m_xTools.Destroy();
234 
235  return( true );
236 }
237 
238 
240 // //
241 // //
242 // //
244 
245 //---------------------------------------------------------
CSG_Tool_Library_Interface::Get_Tool
CSG_Tool * Get_Tool(int i)
Definition: tool_library_interface.cpp:173
CSG_String::Printf
int Printf(const char *Format,...)
Definition: api_string.cpp:308
_TL
#define _TL(s)
Definition: api_core.h:1480
SAGA_VERSION
#define SAGA_VERSION
Definition: saga_api.h:90
CSG_String::Length
size_t Length(void) const
Definition: api_string.cpp:172
TLB_INFO_Library
@ TLB_INFO_Library
Definition: tool.h:623
CSG_Array_Pointer::Get_Size
sLong Get_Size(void) const
Definition: api_core.h:381
TLB_INFO_SAGA_Version
@ TLB_INFO_SAGA_Version
Definition: tool.h:624
saga_api.h
CSG_Tool
Definition: tool.h:149
TLB_INFO_User
@ TLB_INFO_User
Definition: tool.h:621
CSG_String::Cmp
int Cmp(const CSG_String &String) const
Definition: api_string.cpp:515
TLB_INFO_Count
@ TLB_INFO_Count
Definition: tool.h:625
SG_File_Get_Name
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Name(const CSG_String &full_Path, bool bExtension)
Definition: api_file.cpp:862
TSG_PFNC_TLB_Get_Info
CSG_String(* TSG_PFNC_TLB_Get_Info)(int i)
Definition: tool.h:631
CSG_Tool_Library_Interface::Delete_Tool
bool Delete_Tool(CSG_Tool *pTool)
Definition: tool_library_interface.cpp:210
CSG_Tool_Library_Interface::Create
bool Create(const CSG_String &Version, const CSG_String &TLB_Path, TSG_PFNC_TLB_Get_Info Fnc_Info, TSG_PFNC_TLB_Create_Tool Fnc_Create_Tool)
Definition: tool_library_interface.cpp:80
CSG_Array_Pointer::Del
bool Del(sLong Index)
Definition: api_memory.cpp:512
TLB_INTERFACE_SKIP_TOOL
#define TLB_INTERFACE_SKIP_TOOL
Definition: tool.h:674
TLB_INFO_File
@ TLB_INFO_File
Definition: tool.h:622
CSG_Array_Pointer::Get_uSize
size_t Get_uSize(void) const
Definition: api_core.h:382
CSG_Tool_Library_Interface::Get_Count
int Get_Count(void)
Definition: tool_library_interface.cpp:167
CSG_Strings::Set_Count
bool Set_Count(int Count)
Definition: api_core.h:704
CSG_Tool_Library_Interface::Delete_Tools
bool Delete_Tools(void)
Definition: tool_library_interface.cpp:226
CSG_String::Format
static CSG_String Format(const char *Format,...)
Definition: api_string.cpp:270
CSG_String::Find
int Find(char Character, bool fromEnd=false) const
Definition: api_string.cpp:616
SG_File_Get_Path_Absolute
SAGA_API_DLL_EXPORT CSG_String SG_File_Get_Path_Absolute(const CSG_String &full_Path)
Definition: api_file.cpp:883
CSG_Array_Pointer::Destroy
void Destroy(void)
Definition: api_core.h:376
CSG_String
Definition: api_core.h:557
CSG_Tool_Library_Interface::Get_Info
const CSG_String & Get_Info(int ID)
Definition: tool_library_interface.cpp:156
CSG_Tool_Library_Interface::~CSG_Tool_Library_Interface
virtual ~CSG_Tool_Library_Interface(void)
Definition: tool_library_interface.cpp:69
CSG_Array_Pointer::Add
bool Add(void *Value)
Definition: api_memory.cpp:485
TSG_PFNC_TLB_Create_Tool
CSG_Tool *(* TSG_PFNC_TLB_Create_Tool)(int i)
Definition: tool.h:630
CSG_Array_Pointer::Get
void *& Get(sLong Index)
Definition: api_core.h:394
CSG_String::c_str
const SG_Char * c_str(void) const
Definition: api_string.cpp:236
SG_UI_Msg_Add_Error
void SG_UI_Msg_Add_Error(const char *Message)
Definition: api_callback.cpp:544
CSG_Tool_Library_Interface::Create_Tool
CSG_Tool * Create_Tool(int i, bool bWithGUI=false)
Definition: tool_library_interface.cpp:189
CSG_String::Right
CSG_String Right(size_t count) const
Definition: api_string.cpp:693
CSG_Tool_Library_Interface::Destroy
bool Destroy(void)
Definition: tool_library_interface.cpp:136
TLB_INFO_Menu_Path
@ TLB_INFO_Menu_Path
Definition: tool.h:619
CSG_Tool_Library_Interface::CSG_Tool_Library_Interface
CSG_Tool_Library_Interface(void)
Definition: tool_library_interface.cpp:63