SAGA API v9.10
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
81// //
82// //
83// //
85
86//---------------------------------------------------------
88{
89 friend class CSG_HTTP;
90
91public:
92 CSG_MetaData (void);
93 bool Create (void);
94
95 CSG_MetaData (const CSG_MetaData &MetaData);
96 bool Create (const CSG_MetaData &MetaData);
97
98 CSG_MetaData (const CSG_String &File, const SG_Char *Extension = NULL);
99 bool Create (const CSG_String &File, const SG_Char *Extension = NULL);
100
101 CSG_MetaData (CSG_File &File);
102 bool Create (CSG_File &File);
103
104 virtual ~CSG_MetaData (void);
105 void Destroy (void);
106
107 bool Load (const CSG_String &File, const SG_Char *Extension = NULL);
108 bool Save (const CSG_String &File, const SG_Char *Extension = NULL) const;
109
110 bool Load (CSG_File &Stream);
111 bool Save (CSG_File &Stream) const;
112
113 bool Load_HTTP (const CSG_String &Server, const CSG_String &Path, const SG_Char *Username = NULL, const SG_Char *Password = NULL);
114
115 bool from_XML (const char *XML, size_t Length, const char *Encoding = "UTF-8");
116 bool from_XML (const CSG_String &XML);
117 bool to_XML ( CSG_String &XML) const;
118
119 bool Load_JSON (const CSG_String &File);
120 bool Save_JSON (const CSG_String &File) const;
121
122 bool from_JSON (const CSG_String &JSON);
123 bool to_JSON ( CSG_String &JSON) const;
124
125 bool Assign (const CSG_MetaData &MetaData, bool bAddChildren = true);
126
127 CSG_MetaData & operator = (const CSG_MetaData &MetaData) { Assign (MetaData, true); return( *this ); }
128 CSG_MetaData & operator += (const CSG_MetaData &MetaData) { Add_Child(MetaData, true); return( *this ); }
129
130 void Set_Name (const CSG_String &Name) { m_Name = Name; }
131 bool Cmp_Name (const CSG_String &String, bool bNoCase = true) const;
132 const CSG_String & Get_Name (void) const { return( m_Name ); }
133 const CSG_String & Get_Content (void) const { return( m_Content ); }
134 const SG_Char * Get_Content (int Index) const { return( Get_Child(Index) ? Get_Child(Index)->Get_Content().c_str() : NULL ); }
135 const SG_Char * Get_Content (const CSG_String &Name) const;
136 bool Get_Content (const CSG_String &Name, CSG_String &Value) const;
137 bool Get_Content (const CSG_String &Name, double &Value) const;
138 bool Get_Content (const CSG_String &Name, int &Value) const;
139 bool Get_Content (const CSG_String &Name, sLong &Value) const;
140 void Set_Content (const CSG_String &Content) { m_Content = Content; }
141 void Fmt_Content (const char *Format, ...);
142 void Fmt_Content (const wchar_t *Format, ...);
143 bool Cmp_Content (const CSG_String &String, bool bNoCase = false) const;
144
145 CSG_MetaData * Get_Parent (void) const { return( m_pParent ); }
146
147 int Get_Count (void) const { return( (int)m_Children.Get_Size() ); }
148 int Get_Children_Count (void) const { return( (int)m_Children.Get_Size() ); }
149 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 ); }
150 CSG_MetaData * Get_Child (const CSG_String &Name) const;
151 CSG_MetaData * Add_Child (void);
152 CSG_MetaData * Add_Child (const CSG_String &Name);
153 CSG_MetaData * Add_Child (const CSG_String &Name, const CSG_String &Content);
154 CSG_MetaData * Add_Child (const CSG_String &Name, double Content);
155 CSG_MetaData * Add_Child (const CSG_String &Name, int Content);
156 CSG_MetaData * Add_Child (const CSG_String &Name, sLong Content);
157 CSG_MetaData * Add_Child (const CSG_MetaData &MetaData, bool bAddChildren = true);
158 CSG_MetaData * Ins_Child ( int Position);
159 CSG_MetaData * Ins_Child (const CSG_String &Name , int Position);
160 CSG_MetaData * Ins_Child (const CSG_String &Name, const CSG_String &Content, int Position);
161 CSG_MetaData * Ins_Child (const CSG_String &Name, double Content, int Position);
162 CSG_MetaData * Ins_Child (const CSG_String &Name, int Content, int Position);
163 CSG_MetaData * Ins_Child (const CSG_String &Name, sLong Content, int Position);
164 CSG_MetaData * Ins_Child (const CSG_MetaData &MetaData , int Position, bool bAddChildren = true);
165 bool Mov_Child (int from_Index, int to_Index);
166 bool Del_Child (int Index);
167 bool Del_Child (const CSG_String &Name);
168
169 bool Add_Children (const CSG_MetaData &MetaData);
170 bool Del_Children (int Depth = 0, const SG_Char *Name = NULL);
171
172 CSG_MetaData * operator () (int Index ) const { return( Get_Child(Index) ); }
173 CSG_MetaData * operator () (const CSG_String &Name) const { return( Get_Child(Name ) ); }
174 CSG_MetaData & operator [] (int Index ) { return( *Get_Child(Index) ); }
175 CSG_MetaData & operator [] (const CSG_String &Name) { return( *Get_Child(Name ) ); }
176 const CSG_MetaData & operator [] (int Index ) const { return( *Get_Child(Index) ); }
177 const CSG_MetaData & operator [] (const CSG_String &Name) const { return( *Get_Child(Name ) ); }
178
179 int Get_Property_Count (void) const { return( m_Prop_Names.Get_Count() ); }
180 const CSG_String & Get_Property_Name (int Index) const { return( m_Prop_Names[Index] ); }
181 const SG_Char * Get_Property (int Index) const { return( Index >= 0 && Index < m_Prop_Values.Get_Count() ? m_Prop_Values[Index].c_str() : NULL ); }
182 const SG_Char * Get_Property (const CSG_String &Name) const { return( Get_Property(_Get_Property(Name)) ); }
183 bool Get_Property (const CSG_String &Name, CSG_String &Value) const;
184 bool Get_Property (const CSG_String &Name, double &Value) const;
185 bool Get_Property (const CSG_String &Name, int &Value) const;
186 bool Get_Property (const CSG_String &Name, sLong &Value) const;
187 bool Add_Property (const CSG_String &Name, const CSG_String &Value);
188 bool Add_Property (const CSG_String &Name, double Value);
189 bool Add_Property (const CSG_String &Name, int Value);
190 bool Add_Property (const CSG_String &Name, sLong Value);
191 bool Set_Property (const CSG_String &Name, const CSG_String &Value, bool bAddIfNotExists = true);
192 bool Set_Property (const CSG_String &Name, double Value, bool bAddIfNotExists = true);
193 bool Set_Property (const CSG_String &Name, int Value, bool bAddIfNotExists = true);
194 bool Set_Property (const CSG_String &Name, sLong Value, bool bAddIfNotExists = true);
195 bool Cmp_Property (const CSG_String &Name, const CSG_String &String, bool bNoCase = false) const;
196 bool Del_Property (const CSG_String &Name);
197 bool Del_Property (int i);
198
199 CSG_String asText (int Flags = 0) const;
200 class CSG_Table Get_Table (int Flags = 0) const;
201
202
203private:
204
205 CSG_MetaData(CSG_MetaData *pParent);
206
207
208 CSG_Array m_Children;
209
210 CSG_MetaData *m_pParent, *m_pDummy;
211
212 CSG_String m_Name, m_Content;
213
214 CSG_Strings m_Prop_Names, m_Prop_Values;
215
216
217 void _On_Construction (void);
218
219 int _Get_Child (const CSG_String &Name) const;
220 int _Get_Property (const CSG_String &Name) const;
221
222 void _Load (class wxXmlNode *pNode);
223 void _Save (class wxXmlNode *pNode) const;
224
225};
226
227
229// //
230// //
231// //
233
234//---------------------------------------------------------
236{
237public:
238 CSG_HTTP (void);
239 bool Create (void);
240
241 CSG_HTTP (const CSG_String &Server, const SG_Char *Username = NULL, const SG_Char *Password = NULL);
242 bool Create (const CSG_String &Server, const SG_Char *Username = NULL, const SG_Char *Password = NULL);
243
244 virtual ~CSG_HTTP (void);
245 bool Destroy (void);
246
247 bool is_Connected (void) const;
248
249 bool Request (const CSG_String &Request, CSG_Bytes &Answer);
250 bool Request (const CSG_String &Request, CSG_MetaData &Answer);
251 bool Request (const CSG_String &Request, CSG_String &Answer);
252 bool Request (const CSG_String &Request, const SG_Char *File);
253
254
255protected:
256
257 class wxHTTP *m_pHTTP;
258
259
260private:
261
262 class wxInputStream * _Request (const CSG_String &Request);
263
264};
265
266//---------------------------------------------------------
267SAGA_API_DLL_EXPORT bool SG_FTP_Download (const CSG_String &Target_Directory, const CSG_String &Source, const SG_Char *Username = NULL, const SG_Char *Password = NULL, unsigned short Port = 21, bool bBinary = true, bool bVerbose = false);
268
269
271// //
272// //
273// //
275
276//---------------------------------------------------------
277#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
class wxHTTP * m_pHTTP
Definition metadata.h:257
bool Request(const CSG_String &Request, CSG_Bytes &Answer)
bool Destroy(void)
CSG_HTTP(void)
bool Create(void)
bool to_XML(CSG_String &XML) const
Definition metadata.cpp:985
bool Save(const CSG_String &File, const SG_Char *Extension=NULL) const
Definition metadata.cpp:879
const CSG_String & Get_Name(void) const
Definition metadata.h:132
bool Create(void)
Definition metadata.cpp:73
bool Assign(const CSG_MetaData &MetaData, bool bAddChildren=true)
Definition metadata.cpp:757
int Get_Children_Count(void) const
Definition metadata.h:148
friend class CSG_HTTP
Definition metadata.h:89
CSG_MetaData * Get_Child(int Index) const
Definition metadata.h:149
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:134
CSG_MetaData * Get_Parent(void) const
Definition metadata.h:145
CSG_MetaData(void)
Definition metadata.cpp:68
const CSG_String & Get_Property_Name(int Index) const
Definition metadata.h:180
const CSG_String & Get_Content(void) const
Definition metadata.h:133
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:181
void Set_Name(const CSG_String &Name)
Definition metadata.h:130
void Set_Content(const CSG_String &Content)
Definition metadata.h:140
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:786
int Get_Count(void) const
Definition metadata.h:147
void Destroy(void)
Definition metadata.cpp:140
const SG_Char * Get_Property(const CSG_String &Name) const
Definition metadata.h:182
bool from_XML(const char *XML, size_t Length, const char *Encoding="UTF-8")
Definition metadata.cpp:947
bool to_JSON(CSG_String &JSON) const
int Get_Property_Count(void) const
Definition metadata.h:179
SAGA_API_DLL_EXPORT bool SG_FTP_Download(const CSG_String &Target_Directory, const CSG_String &Source, const SG_Char *Username=NULL, const SG_Char *Password=NULL, unsigned short Port=21, bool bBinary=true, bool bVerbose=false)