SAGA API  v9.6
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 //---------------------------------------------------------
70 // //
72 // //
73 // //
75 
76 //---------------------------------------------------------
77 #include "api_core.h"
78 
79 
81 // //
82 // //
83 // //
85 
86 //---------------------------------------------------------
88 {
89  friend class CSG_HTTP;
90 
91 public:
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 CSG_String &XML);
116  bool to_XML ( CSG_String &XML) const;
117 
118  bool Load_JSON (const CSG_String &File);
119  bool Save_JSON (const CSG_String &File) const;
120 
121  bool from_JSON (const CSG_String &JSON);
122  bool to_JSON ( CSG_String &JSON) const;
123 
124  bool Assign (const CSG_MetaData &MetaData, bool bAddChildren = true);
125 
126  CSG_MetaData & operator = (const CSG_MetaData &MetaData) { Assign (MetaData, true); return( *this ); }
127  CSG_MetaData & operator += (const CSG_MetaData &MetaData) { Add_Child(MetaData, true); return( *this ); }
128 
129  void Set_Name (const CSG_String &Name) { m_Name = Name; }
130  bool Cmp_Name (const CSG_String &String, bool bNoCase = true) const;
131  const CSG_String & Get_Name (void) const { return( m_Name ); }
132  const CSG_String & Get_Content (void) const { return( m_Content ); }
133  const SG_Char * Get_Content (int Index) const { return( Get_Child(Index) ? Get_Child(Index)->Get_Content().c_str() : NULL ); }
134  const SG_Char * Get_Content (const CSG_String &Name) const;
135  bool Get_Content (const CSG_String &Name, CSG_String &Value) const;
136  bool Get_Content (const CSG_String &Name, double &Value) const;
137  bool Get_Content (const CSG_String &Name, int &Value) const;
138  bool Get_Content (const CSG_String &Name, sLong &Value) const;
139  void Set_Content (const CSG_String &Content) { m_Content = Content; }
140  void Fmt_Content (const char *Format, ...);
141  void Fmt_Content (const wchar_t *Format, ...);
142  bool Cmp_Content (const CSG_String &String, bool bNoCase = false) const;
143 
144  CSG_MetaData * Get_Parent (void) const { return( m_pParent ); }
145 
146  int Get_Count (void) const { return( (int)m_Children.Get_Size() ); }
147  int Get_Children_Count (void) const { return( (int)m_Children.Get_Size() ); }
148  CSG_MetaData * Get_Child (int Index) const { return( Index >= 0 ? *((CSG_MetaData **)m_Children.Get_Entry((size_t)Index)) : NULL ); }
149  CSG_MetaData * Get_Child (const CSG_String &Name) const;
150  CSG_MetaData * Add_Child (void);
151  CSG_MetaData * Add_Child (const CSG_String &Name);
152  CSG_MetaData * Add_Child (const CSG_String &Name, const CSG_String &Content);
153  CSG_MetaData * Add_Child (const CSG_String &Name, double Content);
154  CSG_MetaData * Add_Child (const CSG_String &Name, int Content);
155  CSG_MetaData * Add_Child (const CSG_String &Name, sLong Content);
156  CSG_MetaData * Add_Child (const CSG_MetaData &MetaData, bool bAddChildren = true);
157  CSG_MetaData * Ins_Child ( int Position);
158  CSG_MetaData * Ins_Child (const CSG_String &Name , int Position);
159  CSG_MetaData * Ins_Child (const CSG_String &Name, const CSG_String &Content, int Position);
160  CSG_MetaData * Ins_Child (const CSG_String &Name, double Content, int Position);
161  CSG_MetaData * Ins_Child (const CSG_String &Name, int Content, int Position);
162  CSG_MetaData * Ins_Child (const CSG_String &Name, sLong Content, int Position);
163  CSG_MetaData * Ins_Child (const CSG_MetaData &MetaData , int Position, bool bAddChildren = true);
164  bool Mov_Child (int from_Index, int to_Index);
165  bool Del_Child (int Index);
166  bool Del_Child (const CSG_String &Name);
167 
168  bool Add_Children (const CSG_MetaData &MetaData);
169  bool Del_Children (int Depth = 0, const SG_Char *Name = NULL);
170 
171  CSG_MetaData * operator () (int Index ) const { return( Get_Child(Index) ); }
172  CSG_MetaData * operator () (const CSG_String &Name) const { return( Get_Child(Name ) ); }
173  CSG_MetaData & operator [] (int Index ) { return( *Get_Child(Index) ); }
174  CSG_MetaData & operator [] (const CSG_String &Name) { return( *Get_Child(Name ) ); }
175  const CSG_MetaData & operator [] (int Index ) const { return( *Get_Child(Index) ); }
176  const CSG_MetaData & operator [] (const CSG_String &Name) const { return( *Get_Child(Name ) ); }
177 
178  int Get_Property_Count (void) const { return( m_Prop_Names.Get_Count() ); }
179  const CSG_String & Get_Property_Name (int Index) const { return( m_Prop_Names[Index] ); }
180  const SG_Char * Get_Property (int Index) const { return( Index >= 0 && Index < m_Prop_Values.Get_Count() ? m_Prop_Values[Index].c_str() : NULL ); }
181  const SG_Char * Get_Property (const CSG_String &Name) const { return( Get_Property(_Get_Property(Name)) ); }
182  bool Get_Property (const CSG_String &Name, CSG_String &Value) const;
183  bool Get_Property (const CSG_String &Name, double &Value) const;
184  bool Get_Property (const CSG_String &Name, int &Value) const;
185  bool Get_Property (const CSG_String &Name, sLong &Value) const;
186  bool Add_Property (const CSG_String &Name, const CSG_String &Value);
187  bool Add_Property (const CSG_String &Name, double Value);
188  bool Add_Property (const CSG_String &Name, int Value);
189  bool Add_Property (const CSG_String &Name, sLong Value);
190  bool Set_Property (const CSG_String &Name, const CSG_String &Value, bool bAddIfNotExists = true);
191  bool Set_Property (const CSG_String &Name, double Value, bool bAddIfNotExists = true);
192  bool Set_Property (const CSG_String &Name, int Value, bool bAddIfNotExists = true);
193  bool Set_Property (const CSG_String &Name, sLong Value, bool bAddIfNotExists = true);
194  bool Cmp_Property (const CSG_String &Name, const CSG_String &String, bool bNoCase = false) const;
195  bool Del_Property (const CSG_String &Name);
196  bool Del_Property (int i);
197 
198  CSG_String asText (int Flags = 0) const;
199  class CSG_Table Get_Table (int Flags = 0) const;
200 
201 
202 private:
203 
204  CSG_MetaData(CSG_MetaData *pParent);
205 
206 
207  CSG_Array m_Children;
208 
209  CSG_MetaData *m_pParent, *m_pDummy;
210 
211  CSG_String m_Name, m_Content;
212 
213  CSG_Strings m_Prop_Names, m_Prop_Values;
214 
215 
216  void _On_Construction (void);
217 
218  int _Get_Child (const CSG_String &Name) const;
219  int _Get_Property (const CSG_String &Name) const;
220 
221  void _Load (class wxXmlNode *pNode);
222  void _Save (class wxXmlNode *pNode) const;
223 
224 };
225 
226 
228 // //
229 // //
230 // //
232 
233 //---------------------------------------------------------
235 {
236 public:
237  CSG_HTTP (void);
238  bool Create (void);
239 
240  CSG_HTTP (const CSG_String &Server, const SG_Char *Username = NULL, const SG_Char *Password = NULL);
241  bool Create (const CSG_String &Server, const SG_Char *Username = NULL, const SG_Char *Password = NULL);
242 
243  virtual ~CSG_HTTP (void);
244  bool Destroy (void);
245 
246  bool is_Connected (void) const;
247 
248  bool Request (const CSG_String &Request, CSG_Bytes &Answer);
249  bool Request (const CSG_String &Request, CSG_MetaData &Answer);
250  bool Request (const CSG_String &Request, CSG_String &Answer);
251  bool Request (const CSG_String &Request, const SG_Char *File);
252 
253 
254 protected:
255 
256  class wxHTTP *m_pHTTP;
257 
258 
259 private:
260 
261  class wxInputStream * _Request (const CSG_String &Request);
262 
263 };
264 
265 //---------------------------------------------------------
266 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);
267 
268 
270 // //
271 // //
272 // //
274 
275 //---------------------------------------------------------
276 #endif // #ifndef HEADER_INCLUDED__SAGA_API__metadata_H
CSG_MetaData::Get_Children_Count
int Get_Children_Count(void) const
Definition: metadata.h:147
CSG_MetaData::Get_Content
const CSG_String & Get_Content(void) const
Definition: metadata.h:132
CSG_MetaData::Set_Content
void Set_Content(const CSG_String &Content)
Definition: metadata.h:139
CSG_HTTP
Definition: metadata.h:235
api_core.h
CSG_MetaData::Get_Property_Name
const CSG_String & Get_Property_Name(int Index) const
Definition: metadata.h:179
CSG_MetaData::Get_Child
CSG_MetaData * Get_Child(int Index) const
Definition: metadata.h:148
CSG_MetaData::Get_Property_Count
int Get_Property_Count(void) const
Definition: metadata.h:178
CSG_MetaData::Get_Name
const CSG_String & Get_Name(void) const
Definition: metadata.h:131
CSG_File
Definition: api_core.h:1124
CSG_HTTP::Destroy
bool Destroy(void)
Definition: metadata.cpp:1236
CSG_HTTP::m_pHTTP
class wxHTTP * m_pHTTP
Definition: metadata.h:256
CSG_MetaData::Get_Property
const SG_Char * Get_Property(const CSG_String &Name) const
Definition: metadata.h:181
CSG_HTTP::Create
bool Create(void)
Definition: metadata.cpp:1175
sLong
signed long long sLong
Definition: api_core.h:158
SAGA_API_DLL_EXPORT
#define SAGA_API_DLL_EXPORT
Definition: api_core.h:94
CSG_Strings
Definition: api_core.h:699
CSG_Bytes
Definition: api_core.h:812
CSG_MetaData::Get_Content
const SG_Char * Get_Content(int Index) const
Definition: metadata.h:133
CSG_Table
Definition: table.h:283
CSG_MetaData::Get_Parent
CSG_MetaData * Get_Parent(void) const
Definition: metadata.h:144
SG_Char
#define SG_Char
Definition: api_core.h:536
CSG_Array
Definition: api_core.h:308
CSG_String
Definition: api_core.h:563
CSG_MetaData
Definition: metadata.h:88
CSG_MetaData::Set_Name
void Set_Name(const CSG_String &Name)
Definition: metadata.h:129
SG_FTP_Download
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)
Definition: metadata.cpp:1392
CSG_MetaData::Get_Count
int Get_Count(void) const
Definition: metadata.h:146
CSG_MetaData::Get_Property
const SG_Char * Get_Property(int Index) const
Definition: metadata.h:180
CSG_Table::_On_Construction
virtual void _On_Construction(void)
Definition: table.cpp:302