SAGA API Version 9.13
Loading...
Searching...
No Matches
metadata.h
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// metadata.h //
15// //
16// Copyright (C) 2009 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 Hamburg //
44// Germany //
45// //
46// e-mail: oconrad@saga-gis.org //
47// //
49
50//---------------------------------------------------------
51#ifndef HEADER_INCLUDED__SAGA_API__metadata_H
52#define HEADER_INCLUDED__SAGA_API__metadata_H
53
54
56// //
57// //
58// //
60
61//---------------------------------------------------------
68
69
71// //
72// //
73// //
75
76//---------------------------------------------------------
77#include "api_core.h"
78
79#ifndef SWIG
80#include "picojson/picojson.h"
81#endif // #ifdef SWIG
82
84// //
85// //
86// //
88
89//---------------------------------------------------------
91{
92 friend class CSG_HTTP;
93
94public:
95 CSG_MetaData (void);
96 bool Create (void);
97
98 CSG_MetaData (const CSG_MetaData &MetaData);
99 bool Create (const CSG_MetaData &MetaData);
100
101 CSG_MetaData (const CSG_String &File, const SG_Char *Extension = NULL);
102 bool Create (const CSG_String &File, const SG_Char *Extension = NULL);
103
104 CSG_MetaData (CSG_File &File);
105 bool Create (CSG_File &File);
106
107 virtual ~CSG_MetaData (void);
108 void Destroy (void);
109
110 bool Load (const CSG_String &File, const SG_Char *Extension = NULL);
111 bool Save (const CSG_String &File, const SG_Char *Extension = NULL) const;
112
113 bool Load (CSG_File &Stream);
114 bool Save (CSG_File &Stream) const;
115
116 bool Load (class wxXmlNode *pNode);
117 bool Save (class wxXmlNode *pNode) const;
118
119 bool Load_HTTP (const CSG_String &Server, const CSG_String &Path, const SG_Char *Username = NULL, const SG_Char *Password = NULL);
120
121 bool from_XML (const char *XML, size_t Length, const char *Encoding = "UTF-8");
122 bool from_XML (const CSG_String &XML);
123 bool to_XML ( CSG_String &XML) const;
124
125 bool Load_JSON (const CSG_String &File);
126 bool Save_JSON (const CSG_String &File) const;
127
128 bool from_JSON (const CSG_String &JSON);
129 bool to_JSON ( CSG_String &JSON) const;
130
131 bool Assign (const CSG_MetaData &MetaData, bool bAddChildren = true);
132
133 CSG_MetaData & operator = (const CSG_MetaData &MetaData) { Assign (MetaData, true); return( *this ); }
134 CSG_MetaData & operator += (const CSG_MetaData &MetaData) { Add_Child(MetaData, true); return( *this ); }
135
136 void Set_Name (const CSG_String &Name) { m_Name = Name; }
137 bool Cmp_Name (const CSG_String &String, bool bNoCase = true) const;
138 const CSG_String & Get_Name (void) const { return( m_Name ); }
139 const CSG_String & Get_Content (void) const { return( m_Content ); }
140 const SG_Char * Get_Content (int Index) const { return( Get_Child(Index) ? Get_Child(Index)->Get_Content().c_str() : NULL ); }
141 const SG_Char * Get_Content (const CSG_String &Name) const;
142 bool Get_Content (const CSG_String &Name, CSG_String &Value) const;
143 bool Get_Content (const CSG_String &Name, double &Value) const;
144 bool Get_Content (const CSG_String &Name, int &Value) const;
145 bool Get_Content (const CSG_String &Name, sLong &Value) const;
146 void Set_Content (const CSG_String &Content) { m_Content = Content; }
147 void Fmt_Content (const char *Format, ...);
148 void Fmt_Content (const wchar_t *Format, ...);
149 bool Cmp_Content (const CSG_String &String, bool bNoCase = false) const;
150
151 CSG_MetaData * Get_Parent (void) const { return( m_pParent ); }
152
153 int Get_Count (void) const { return( (int)m_Children.Get_Size() ); }
154 int Get_Children_Count (void) const { return( (int)m_Children.Get_Size() ); }
155 CSG_MetaData * Get_Child (int Index) const { return( Index >= 0 && Index < (int)m_Children.Get_Size() ? *((CSG_MetaData **)m_Children.Get_Entry((size_t)Index)) : NULL ); }
156 CSG_MetaData * Get_Child (const CSG_String &Name) const;
157 CSG_MetaData * Get_Child_by_JSON_Pointer(const CSG_String &JSON_Pointer) const;
158 CSG_MetaData * Add_Child (void);
159 CSG_MetaData * Add_Child (const CSG_String &Name);
160 CSG_MetaData * Add_Child (const CSG_String &Name, const CSG_String &Content);
161 CSG_MetaData * Add_Child (const CSG_String &Name, double Content);
162 CSG_MetaData * Add_Child (const CSG_String &Name, int Content);
163 CSG_MetaData * Add_Child (const CSG_String &Name, sLong Content);
164 CSG_MetaData * Add_Child (const CSG_MetaData &MetaData, bool bAddChildren = true);
165 CSG_MetaData * Ins_Child ( int Position);
166 CSG_MetaData * Ins_Child (const CSG_String &Name , int Position);
167 CSG_MetaData * Ins_Child (const CSG_String &Name, const CSG_String &Content, int Position);
168 CSG_MetaData * Ins_Child (const CSG_String &Name, double Content, int Position);
169 CSG_MetaData * Ins_Child (const CSG_String &Name, int Content, int Position);
170 CSG_MetaData * Ins_Child (const CSG_String &Name, sLong Content, int Position);
171 CSG_MetaData * Ins_Child (const CSG_MetaData &MetaData , int Position, bool bAddChildren = true);
172 bool Mov_Child (int from_Index, int to_Index);
173 bool Del_Child (int Index);
174 bool Del_Child (const CSG_String &Name);
175
176 bool Add_Children (const CSG_MetaData &MetaData);
177 bool Del_Children (int Depth = 0, const SG_Char *Name = NULL);
178
179 CSG_MetaData * operator () (int Index ) const { return( Get_Child(Index) ); }
180 CSG_MetaData * operator () (const CSG_String &Name) const { return( Get_Child(Name ) ); }
181 CSG_MetaData & operator [] (int Index ) { return( *Get_Child(Index) ); }
182 CSG_MetaData & operator [] (const CSG_String &Name) { return( *Get_Child(Name ) ); }
183 const CSG_MetaData & operator [] (int Index ) const { return( *Get_Child(Index) ); }
184 const CSG_MetaData & operator [] (const CSG_String &Name) const { return( *Get_Child(Name ) ); }
185
186 int Get_Property_Count (void) const { return( m_Prop_Names.Get_Count() ); }
187 const CSG_String & Get_Property_Name (int Index) const { return( m_Prop_Names[Index] ); }
188 const SG_Char * Get_Property (int Index) const { return( Index >= 0 && Index < m_Prop_Values.Get_Count() ? m_Prop_Values[Index].c_str() : NULL ); }
189 const SG_Char * Get_Property (const CSG_String &Name) const { return( Get_Property(_Get_Property(Name)) ); }
190 bool Get_Property (const CSG_String &Name, CSG_String &Value) const;
191 bool Get_Property (const CSG_String &Name, double &Value) const;
192 bool Get_Property (const CSG_String &Name, int &Value) const;
193 bool Get_Property (const CSG_String &Name, sLong &Value) const;
194 bool Add_Property (const CSG_String &Name, const CSG_String &Value);
195 bool Add_Property (const CSG_String &Name, double Value);
196 bool Add_Property (const CSG_String &Name, int Value);
197 bool Add_Property (const CSG_String &Name, sLong Value);
198 bool Set_Property (const CSG_String &Name, const CSG_String &Value, bool bAddIfNotExists = true);
199 bool Set_Property (const CSG_String &Name, double Value, bool bAddIfNotExists = true);
200 bool Set_Property (const CSG_String &Name, int Value, bool bAddIfNotExists = true);
201 bool Set_Property (const CSG_String &Name, sLong Value, bool bAddIfNotExists = true);
202 bool Cmp_Property (const CSG_String &Name, const CSG_String &String, bool bNoCase = false) const;
203 bool Del_Property (const CSG_String &Name);
204 bool Del_Property (int i);
205
206 CSG_String asText (int Flags = 0) const;
207 class CSG_Table Get_Table (int Flags = 0) const;
208
209
210private:
211
212 CSG_MetaData(CSG_MetaData *pParent);
213
214
215 CSG_Array m_Children;
216
217 CSG_MetaData *m_pParent, *m_pDummy;
218
219 CSG_String m_Name, m_Content;
220
221 CSG_Strings m_Prop_Names, m_Prop_Values;
222
223
224 void _On_Construction (void);
225
226 int _Get_Child (const CSG_String &Name) const;
227 int _Get_Property (const CSG_String &Name) const;
228
229 void _JSON_To_MetaData (const picojson::value &j, CSG_MetaData *pNode);
230 CSG_String _JSON_Escape_String (const CSG_String &s) const;
231
232};
233
234
236// //
237// //
238// //
240
241//---------------------------------------------------------
243{
244public:
245 CSG_HTTP (void);
246 bool Create (void);
247
248 CSG_HTTP (const CSG_String &Server, const CSG_String &User = "", const CSG_String &Password = "");
249 bool Create (const CSG_String &Server, const CSG_String &User = "", const CSG_String &Password = "");
250
251 virtual ~CSG_HTTP (void);
252 bool Destroy (void);
253
254 bool is_Connected (void) const { return( m_pHTTP != NULL ); }
255
256 bool Request (const CSG_String &Request, CSG_Bytes &Answer);
257 bool Request (const CSG_String &Request, CSG_MetaData &Answer);
258 bool Request (const CSG_String &Request, CSG_String &Answer);
259 bool Request (const CSG_String &Request, const SG_Char *File);
260
261
262private:
263
264 class wxHTTP *m_pHTTP = NULL;
265
266
267 class wxInputStream * _Request (const CSG_String &Request);
268
269};
270
271//---------------------------------------------------------
272SAGA_API_DLL_EXPORT bool SG_FTP_Download (const CSG_String &Target_Directory, const CSG_String &Source, const CSG_String &User = "", const CSG_String &Password = "", unsigned short Port = 21, bool bBinary = true, bool bVerbose = false);
273
274
276// //
278
279//---------------------------------------------------------
281{
282public:
283 CSG_WebRequest (void);
284 bool Create (void);
285
286 CSG_WebRequest (const CSG_String &Server, const CSG_String &User = "", const CSG_String &Password = "");
287 bool Create (const CSG_String &Server, const CSG_String &User = "", const CSG_String &Password = "");
288
289 bool Destroy (void);
290
291 bool Request (const CSG_String &Request, CSG_Bytes &Answer);
292 bool Request (const CSG_String &Request, CSG_MetaData &Answer);
293 bool Request (const CSG_String &Request, CSG_String &Answer);
294 bool Request (const CSG_String &Request, const SG_Char *File );
295
296 bool Post (const CSG_String &Request, const CSG_String &Body, CSG_Bytes &Answer, const CSG_String &ContentType = "application/json");
297 bool Post (const CSG_String &Request, const CSG_String &Body, CSG_MetaData &Answer, const CSG_String &ContentType = "application/json");
298 bool Post (const CSG_String &Request, const CSG_String &Body, CSG_String &Answer, const CSG_String &ContentType = "application/json");
299 bool Post (const CSG_String &Request, const CSG_String &Body, const SG_Char *File, const CSG_String &ContentType = "application/json");
300
301 static bool Request (const CSG_String &Server, const CSG_String &Request, CSG_Bytes &Answer);
302 static bool Request (const CSG_String &Server, const CSG_String &Request, CSG_MetaData &Answer);
303 static bool Request (const CSG_String &Server, const CSG_String &Request, CSG_String &Answer);
304 static bool Request (const CSG_String &Server, const CSG_String &Request, const SG_Char *File );
305
306 static bool Post (const CSG_String &Server, const CSG_String &Request, const CSG_String &Body, CSG_Bytes &Answer, const CSG_String &ContentType = "application/json");
307 static bool Post (const CSG_String &Server, const CSG_String &Request, const CSG_String &Body, CSG_MetaData &Answer, const CSG_String &ContentType = "application/json");
308 static bool Post (const CSG_String &Server, const CSG_String &Request, const CSG_String &Body, CSG_String &Answer, const CSG_String &ContentType = "application/json");
309 static bool Post (const CSG_String &Server, const CSG_String &Request, const CSG_String &Body, const SG_Char *File, const CSG_String &ContentType = "application/json");
310
311
312private:
313
314 CSG_String m_Server, m_User, m_Password;
315
316};
317
318
320// //
321// //
322// //
324
325//---------------------------------------------------------
326#endif // #ifndef HEADER_INCLUDED__SAGA_API__metadata_H
signed long long sLong
Definition api_core.h:158
#define SAGA_API_DLL_EXPORT
Definition api_core.h:94
#define SG_Char
Definition api_core.h:536
bool is_Connected(void) const
Definition metadata.h:254
bool Destroy(void)
CSG_HTTP(void)
bool Create(void)
bool to_XML(CSG_String &XML) const
bool Save(const CSG_String &File, const SG_Char *Extension=NULL) const
Definition metadata.cpp:904
const CSG_String & Get_Name(void) const
Definition metadata.h:138
bool Create(void)
Definition metadata.cpp:73
bool Assign(const CSG_MetaData &MetaData, bool bAddChildren=true)
Definition metadata.cpp:780
int Get_Children_Count(void) const
Definition metadata.h:154
friend class CSG_HTTP
Definition metadata.h:92
CSG_MetaData * Get_Child(int Index) const
Definition metadata.h:155
bool Load_JSON(const CSG_String &File)
bool Save_JSON(const CSG_String &File) const
const SG_Char * Get_Content(int Index) const
Definition metadata.h:140
CSG_MetaData * Get_Parent(void) const
Definition metadata.h:151
CSG_MetaData(void)
Definition metadata.cpp:68
const CSG_String & Get_Property_Name(int Index) const
Definition metadata.h:187
const CSG_String & Get_Content(void) const
Definition metadata.h:139
bool Load_HTTP(const CSG_String &Server, const CSG_String &Path, const SG_Char *Username=NULL, const SG_Char *Password=NULL)
const SG_Char * Get_Property(int Index) const
Definition metadata.h:188
void Set_Name(const CSG_String &Name)
Definition metadata.h:136
void Set_Content(const CSG_String &Content)
Definition metadata.h:146
bool from_JSON(const CSG_String &JSON)
CSG_MetaData * Add_Child(void)
Definition metadata.cpp:166
bool Load(const CSG_String &File, const SG_Char *Extension=NULL)
Definition metadata.cpp:809
int Get_Count(void) const
Definition metadata.h:153
void Destroy(void)
Definition metadata.cpp:140
const SG_Char * Get_Property(const CSG_String &Name) const
Definition metadata.h:189
bool from_XML(const char *XML, size_t Length, const char *Encoding="UTF-8")
Definition metadata.cpp:974
bool to_JSON(CSG_String &JSON) const
int Get_Property_Count(void) const
Definition metadata.h:186
bool Post(const CSG_String &Request, const CSG_String &Body, CSG_Bytes &Answer, const CSG_String &ContentType="application/json")
bool Destroy(void)
bool Create(void)
bool Request(const CSG_String &Request, CSG_Bytes &Answer)
SAGA_API_DLL_EXPORT bool SG_FTP_Download(const CSG_String &Target_Directory, const CSG_String &Source, const CSG_String &User="", const CSG_String &Password="", unsigned short Port=21, bool bBinary=true, bool bVerbose=false)