SAGA API  v9.5
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  if( SG_UI_Get_Application_Name().Cmp("saga_cmd") == 0 && pTool->is_Interactive() )
124  {
125  delete(pTool);
126  }
127  else
128  {
129  pTool->m_ID.Printf("%d", ID);
130  pTool->m_Library = m_Info[TLB_INFO_Library ];
131  pTool->m_Library_Menu = m_Info[TLB_INFO_Menu_Path];
132  pTool->m_File_Name = m_Info[TLB_INFO_File ];
133 
134  m_Tools.Add(pTool);
135  }
136  }
137  }
138 
139  return( Get_Count() > 0 );
140 }
141 
142 //---------------------------------------------------------
144 {
145  Delete_Tools();
146 
147  for(size_t i=0; i<m_Tools.Get_uSize(); i++)
148  {
149  delete((CSG_Tool *)m_Tools[i]);
150  }
151 
152  m_Tools.Destroy();
153 
154  return( true );
155 }
156 
157 
159 // //
161 
162 //---------------------------------------------------------
164 {
165  return( m_Info[ID] );
166 }
167 
168 
170 // //
172 
173 //---------------------------------------------------------
175 {
176  return( (int)m_Tools.Get_Size() );
177 }
178 
179 //---------------------------------------------------------
181 {
182  if( i >= 0 && i < Get_Count() )
183  {
184  return( (CSG_Tool *)m_Tools[i] );
185  }
186 
187  return( NULL );
188 }
189 
190 
192 // //
194 
195 //---------------------------------------------------------
197 {
198  CSG_Tool *pTool = m_Fnc_Create_Tool ? m_Fnc_Create_Tool(ID) : NULL;
199 
200  if( pTool && pTool != TLB_INTERFACE_SKIP_TOOL )
201  {
202  pTool->m_ID.Printf("%d", ID);
203  pTool->m_Library = m_Info[TLB_INFO_Library ];
204  pTool->m_Library_Menu = m_Info[TLB_INFO_Menu_Path];
205  pTool->m_File_Name = m_Info[TLB_INFO_File ];
206  pTool->m_bGUI = bWithGUI && pTool->m_bGUI;
207 
208  m_xTools.Add(pTool);
209 
210  return( pTool );
211  }
212 
213  return( NULL );
214 }
215 
216 //---------------------------------------------------------
218 {
219  for(size_t i=0; i<m_xTools.Get_uSize(); i++)
220  {
221  if( pTool == m_xTools.Get(i) && m_xTools.Del(i) )
222  {
223  delete(pTool);
224 
225  return( true );
226  }
227  }
228 
229  return( false );
230 }
231 
232 //---------------------------------------------------------
234 {
235  for(size_t i=0; i<m_xTools.Get_uSize(); i++)
236  {
237  delete((CSG_Tool *)m_xTools[i]);
238  }
239 
240  m_xTools.Destroy();
241 
242  return( true );
243 }
244 
245 
247 // //
248 // //
249 // //
251 
252 //---------------------------------------------------------
CSG_Tool_Library_Interface::Get_Tool
CSG_Tool * Get_Tool(int i)
Definition: tool_library_interface.cpp:180
CSG_String::Printf
int Printf(const char *Format,...)
Definition: api_string.cpp:308
_TL
#define _TL(s)
Definition: api_core.h:1489
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:629
SG_UI_Get_Application_Name
CSG_String SG_UI_Get_Application_Name(void)
Definition: api_callback.cpp:812
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:630
saga_api.h
CSG_Tool
Definition: tool.h:151
TLB_INFO_User
@ TLB_INFO_User
Definition: tool.h:627
CSG_String::Cmp
int Cmp(const CSG_String &String) const
Definition: api_string.cpp:515
TLB_INFO_Count
@ TLB_INFO_Count
Definition: tool.h:631
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:878
TSG_PFNC_TLB_Get_Info
CSG_String(* TSG_PFNC_TLB_Get_Info)(int i)
Definition: tool.h:637
CSG_Tool_Library_Interface::Delete_Tool
bool Delete_Tool(CSG_Tool *pTool)
Definition: tool_library_interface.cpp:217
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:680
TLB_INFO_File
@ TLB_INFO_File
Definition: tool.h:628
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:174
CSG_Strings::Set_Count
bool Set_Count(int Count)
Definition: api_core.h:710
CSG_Tool_Library_Interface::Delete_Tools
bool Delete_Tools(void)
Definition: tool_library_interface.cpp:233
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:899
CSG_Array_Pointer::Destroy
void Destroy(void)
Definition: api_core.h:376
CSG_String
Definition: api_core.h:563
CSG_Tool_Library_Interface::Get_Info
const CSG_String & Get_Info(int ID)
Definition: tool_library_interface.cpp:163
CSG_Tool_Library_Interface::~CSG_Tool_Library_Interface
virtual ~CSG_Tool_Library_Interface(void)
Definition: tool_library_interface.cpp:69
CSG_Tool::is_Interactive
virtual bool is_Interactive(void) const
Definition: tool.h:238
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:636
CSG_Array_Pointer::Get
void *& Get(sLong Index)
Definition: api_core.h:395
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:557
CSG_Tool_Library_Interface::Create_Tool
CSG_Tool * Create_Tool(int i, bool bWithGUI=false)
Definition: tool_library_interface.cpp:196
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:143
TLB_INFO_Menu_Path
@ TLB_INFO_Menu_Path
Definition: tool.h:625
CSG_Tool_Library_Interface::CSG_Tool_Library_Interface
CSG_Tool_Library_Interface(void)
Definition: tool_library_interface.cpp:63