SAGA API v9.10
Loading...
Searching...
No Matches
table_value.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// table_value.h //
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#ifndef HEADER_INCLUDED__SAGA_API__table_value_H
54#define HEADER_INCLUDED__SAGA_API__table_value_H
55
56
58// //
59// //
60// //
62
63//---------------------------------------------------------
72
73
75// //
76// //
77// //
79
80//---------------------------------------------------------
81#include "datetime.h"
82
83
85// //
86// //
87// //
89
90//---------------------------------------------------------
101
102
104// //
105// //
106// //
108
109//---------------------------------------------------------
111{
112public:
114 virtual ~CSG_Table_Value(void) {}
115
116 virtual TSG_Table_Value_Type Get_Type (void) const = 0;
117
118 //-----------------------------------------------------
119 virtual bool Set_Value (const CSG_Bytes &Value) = 0;
120 virtual bool Set_Value (const SG_Char *Value) = 0;
121 virtual bool Set_Value (int Value) = 0;
122 virtual bool Set_Value (sLong Value) = 0;
123 virtual bool Set_Value (double Value) = 0;
124
125 //-----------------------------------------------------
126 virtual CSG_Bytes asBinary (void) const
127 {
128 const SG_Char *s = asString();
129
130 return( CSG_Bytes((BYTE *)s, (int)(s && *s ? SG_STR_LEN(s) : 0) * sizeof(SG_Char)) );
131 }
132
133 virtual const SG_Char * asString (int Decimals =-99) const = 0;
134 virtual int asInt (void) const = 0;
135 virtual sLong asLong (void) const = 0;
136 virtual double asDouble (void) const = 0;
137
138 //-----------------------------------------------------
139 virtual bool is_Equal (const CSG_Table_Value &Value) const = 0;
140 bool operator == (const CSG_Table_Value &Value) const { return( is_Equal(Value) ); }
141
142 //-----------------------------------------------------
143 operator const SG_Char * (void) const { return( asString() ); }
144 operator double (void) const { return( asDouble() ); }
145
146 //-----------------------------------------------------
147 virtual CSG_Table_Value & operator = (const SG_Char *Value) { Set_Value(Value); return( *this ); }
148 virtual CSG_Table_Value & operator = (double Value) { Set_Value(Value); return( *this ); }
149 virtual CSG_Table_Value & operator = (const CSG_Table_Value &Value) = 0;
150
151};
152
153
155// //
157
158//---------------------------------------------------------
160{
161public:
163 virtual ~CSG_Table_Value_Binary(void) {}
164
165 virtual TSG_Table_Value_Type Get_Type (void) const { return( SG_TABLE_VALUE_TYPE_Binary ); }
166
167 //-----------------------------------------------------
168 virtual bool Set_Value (const CSG_Bytes &Value)
169 {
170 return( m_Value.Create(Value) );
171 }
172
173 virtual bool Set_Value (const SG_Char *Value)
174 {
175 return( m_Value.Create((BYTE *)Value, (int)((Value && *Value ? SG_STR_LEN(Value) : 0 * sizeof(SG_Char)))) );
176 }
177
178 virtual bool Set_Value (int Value)
179 {
180 return( m_Value.Create((BYTE *)&Value, sizeof(Value)) );
181 }
182
183 virtual bool Set_Value (sLong Value)
184 {
185 return( m_Value.Create((BYTE *)&Value, sizeof(Value)) );
186 }
187
188 virtual bool Set_Value (double Value)
189 {
190 return( m_Value.Create((BYTE *)&Value, sizeof(Value)) );
191 }
192
193 //-----------------------------------------------------
194 virtual bool Set_NoData (void) { return( m_Value.Destroy() ); }
195 virtual bool is_NoData (void) const { return( m_Value.Get_Count() <= 0 ); }
196
197 //-----------------------------------------------------
198 virtual CSG_Bytes asBinary (void) const { return( m_Value ); }
199 virtual const SG_Char * asString (int Decimals =-99) const { return( (const SG_Char *)m_Value.Get_Bytes() ); }
200 virtual int asInt (void) const { return( m_Value.Get_Count() ); }
201 virtual sLong asLong (void) const { return( m_Value.Get_Count() ); }
202 virtual double asDouble (void) const { return( 0.0 ); }
203
204 //-----------------------------------------------------
205 virtual bool is_Equal (const CSG_Table_Value &Value) const
206 {
207 return( !SG_STR_CMP(asString(), Value.asString()) );
208 }
209
210 //-----------------------------------------------------
211 virtual CSG_Table_Value & operator = (const SG_Char *Value) { Set_Value(Value ); return( *this ); }
212 virtual CSG_Table_Value & operator = (double Value) { Set_Value(Value ); return( *this ); }
213 virtual CSG_Table_Value & operator = (const CSG_Table_Value &Value) { Set_Value(Value.asBinary()); return( *this ); }
214
215 //-----------------------------------------------------
216 CSG_Bytes & Get_Binary (void) { return( m_Value ); }
217
218
219private:
220
221 CSG_Bytes m_Value;
222
223};
224
225
227// //
229
230//---------------------------------------------------------
232{
233public:
235 virtual ~CSG_Table_Value_String(void) {}
236
237 virtual TSG_Table_Value_Type Get_Type (void) const { return( SG_TABLE_VALUE_TYPE_String ); }
238
239 //-----------------------------------------------------
240 virtual bool Set_Value (const CSG_Bytes &Value)
241 {
242 return( Set_Value((SG_Char *)Value.Get_Bytes()) );
243 }
244
245 virtual bool Set_Value (const SG_Char *Value)
246 {
247 if( Value && m_Value.Cmp(Value) )
248 {
249 m_Value = Value;
250
251 return( true );
252 }
253
254 return( false );
255 }
256
257 virtual bool Set_Value (int Value)
258 {
259 return( Set_Value(CSG_String::Format("%d" , Value).c_str()) );
260 }
261
262 virtual bool Set_Value (sLong Value)
263 {
264 return( Set_Value(CSG_String::Format("%lld", Value).c_str()) );
265 }
266
267 virtual bool Set_Value (double Value)
268 {
269 return( Set_Value(CSG_String::Format("%f" , Value).c_str()) );
270 }
271
272 //-----------------------------------------------------
273 virtual const SG_Char * asString (int Decimals =-99) const { return( m_Value ); }
274 virtual int asInt (void) const { return( m_Value.asInt () ); }
275 virtual sLong asLong (void) const { return( m_Value.asInt () ); }
276 virtual double asDouble (void) const { return( m_Value.asDouble() ); }
277
278 //-----------------------------------------------------
279 virtual bool is_Equal (const CSG_Table_Value &Value) const
280 {
281 return( !m_Value.Cmp(Value.asString()) );
282 }
283
284 //-----------------------------------------------------
285 virtual CSG_Table_Value & operator = (const SG_Char *Value) { Set_Value(Value ); return( *this ); }
286 virtual CSG_Table_Value & operator = (double Value) { Set_Value(Value ); return( *this ); }
287 virtual CSG_Table_Value & operator = (const CSG_Table_Value &Value) { Set_Value(Value.asString()); return( *this ); }
288
289
290private:
291
292 CSG_String m_Value;
293
294};
295
296
298// //
300
301//---------------------------------------------------------
303{
304public:
305 CSG_Table_Value_Date(void) { m_Value = 0.0; }
306 virtual ~CSG_Table_Value_Date(void) {}
307
308 virtual TSG_Table_Value_Type Get_Type (void) const { return( SG_TABLE_VALUE_TYPE_Date ); }
309
310 //-----------------------------------------------------
311 virtual bool Set_Value (const CSG_Bytes &Value)
312 {
313 return( Set_Value((SG_Char *)Value.Get_Bytes()) );
314 }
315
316 virtual bool Set_Value (const SG_Char *Value)
317 {
318 return( Set_Value(SG_Date_To_JulianDayNumber(Value)) );
319 }
320
321 virtual bool Set_Value (int Value)
322 {
323 return( Set_Value((double)Value) );
324 }
325
326 virtual bool Set_Value (sLong Value)
327 {
328 return( Set_Value((double)Value) );
329 }
330
331 virtual bool Set_Value (double Value)
332 {
333 if( m_Value != Value )
334 {
335 m_Value = Value;
336 m_Date = SG_JulianDayNumber_To_Date(m_Value);
337
338 return( true );
339 }
340
341 return( false );
342 }
343
344 //-----------------------------------------------------
345 virtual const SG_Char * asString (int Decimals =-99) const { return( m_Date ); }
346 virtual int asInt (void) const { return( (int)m_Value ); }
347 virtual sLong asLong (void) const { return( (sLong)m_Value ); }
348 virtual double asDouble (void) const { return( m_Value ); }
349
350 //-----------------------------------------------------
351 virtual bool is_Equal (const CSG_Table_Value &Value) const
352 {
353 return( m_Value == Value.asDouble() );
354 }
355
356 //-----------------------------------------------------
357 virtual CSG_Table_Value & operator = (const SG_Char *Value) { Set_Value(Value); return( *this ); }
358 virtual CSG_Table_Value & operator = (double Value) { Set_Value(Value); return( *this ); }
360 {
361 switch( Value.Get_Type() )
362 {
365 Set_Value(Value.asString());
366 return( *this );
367
368 default:
369 Set_Value(Value.asDouble());
370 return( *this );
371 }
372 }
373
374
375private:
376
377 double m_Value; // Julian Day Number
378
379 CSG_String m_Date ; // yyyy-mm-dd (ISO 8601)
380
381};
382
383
385// //
387
388//---------------------------------------------------------
390{
391public:
392 CSG_Table_Value_Int(void) { m_Value = 0; }
393 virtual ~CSG_Table_Value_Int(void) {}
394
395 virtual TSG_Table_Value_Type Get_Type (void) const { return( SG_TABLE_VALUE_TYPE_Int ); }
396
397 //-----------------------------------------------------
398 virtual bool Set_Value (const CSG_Bytes &Value)
399 {
400 return( Set_Value((SG_Char *)Value.Get_Bytes()) );
401 }
402
403 virtual bool Set_Value (const SG_Char *Value)
404 {
405 int i;
406 CSG_String s(Value);
407
408 return( s.asInt(i) ? Set_Value(i) : false );
409 }
410
411 virtual bool Set_Value (int Value)
412 {
413 if( m_Value != Value )
414 {
415 m_Value = Value;
416
417 return( true );
418 }
419
420 return( false );
421 }
422
423 virtual bool Set_Value (sLong Value)
424 {
425 return( Set_Value((int)Value) );
426 }
427
428 virtual bool Set_Value (double Value)
429 {
430 return( Set_Value((int)Value) );
431 }
432
433 //-----------------------------------------------------
434 virtual const SG_Char * asString (int Decimals =-99) const
435 {
436 static CSG_String s;
437
438 s.Printf("%d", m_Value);
439
440 return( s.c_str() );
441 }
442
443 virtual int asInt (void) const { return( m_Value ); }
444 virtual sLong asLong (void) const { return( m_Value ); }
445 virtual double asDouble (void) const { return( m_Value ); }
446
447 //-----------------------------------------------------
448 virtual bool is_Equal (const CSG_Table_Value &Value) const
449 {
450 return( m_Value == Value.asInt() );
451 }
452
453 //-----------------------------------------------------
454 virtual CSG_Table_Value & operator = (const SG_Char *Value) { Set_Value(Value ); return( *this ); }
455 virtual CSG_Table_Value & operator = (double Value) { Set_Value(Value ); return( *this ); }
456 virtual CSG_Table_Value & operator = (const CSG_Table_Value &Value) { Set_Value(Value.asInt()); return( *this ); }
457
458
459private:
460
461 int m_Value;
462
463};
464
465
467// //
469
470//---------------------------------------------------------
472{
473public:
474 CSG_Table_Value_Long(void) { m_Value = 0; }
475 virtual ~CSG_Table_Value_Long(void) {}
476
477 virtual TSG_Table_Value_Type Get_Type (void) const { return( SG_TABLE_VALUE_TYPE_Long ); }
478
479 //-----------------------------------------------------
480 virtual bool Set_Value (const CSG_Bytes &Value)
481 {
482 return( Set_Value((SG_Char *)Value.Get_Bytes()) );
483 }
484
485 virtual bool Set_Value (const SG_Char *Value)
486 {
487 int i;
488 CSG_String s(Value);
489
490 return( s.asInt(i) ? Set_Value(i) : false );
491 }
492
493 virtual bool Set_Value (int Value)
494 {
495 return( Set_Value((sLong)Value) );
496 }
497
498 virtual bool Set_Value (sLong Value)
499 {
500 if( m_Value != Value )
501 {
502 m_Value = Value;
503
504 return( true );
505 }
506
507 return( false );
508 }
509
510 virtual bool Set_Value (double Value)
511 {
512 return( Set_Value((sLong)Value) );
513 }
514
515 //-----------------------------------------------------
516 virtual const SG_Char * asString (int Decimals =-99) const
517 {
518 static CSG_String s;
519
520 s.Printf("%lld", m_Value);
521
522 return( s.c_str() );
523 }
524
525 virtual int asInt (void) const { return( (int)m_Value ); }
526 virtual sLong asLong (void) const { return( m_Value ); }
527 virtual double asDouble (void) const { return( (double)m_Value ); }
528
529 //-----------------------------------------------------
530 virtual bool is_Equal (const CSG_Table_Value &Value) const
531 {
532 return( m_Value == Value.asLong() );
533 }
534
535 //-----------------------------------------------------
536 virtual CSG_Table_Value & operator = (const SG_Char *Value) { Set_Value(Value ); return( *this ); }
537 virtual CSG_Table_Value & operator = (double Value) { Set_Value(Value ); return( *this ); }
538 virtual CSG_Table_Value & operator = (const CSG_Table_Value &Value) { Set_Value(Value.asLong()); return( *this ); }
539
540
541private:
542
543 sLong m_Value;
544
545};
546
547
549// //
551
552//---------------------------------------------------------
554{
555public:
556 CSG_Table_Value_Double(void) { m_Value = 0.0; }
557 virtual ~CSG_Table_Value_Double(void) {}
558
559 virtual TSG_Table_Value_Type Get_Type (void) const { return( SG_TABLE_VALUE_TYPE_Double ); }
560
561 //-----------------------------------------------------
562 virtual bool Set_Value (const CSG_Bytes &Value)
563 {
564 return( Set_Value((SG_Char *)Value.Get_Bytes()) );
565 }
566
567 virtual bool Set_Value (const SG_Char *Value)
568 {
569 double d;
570 CSG_String s(Value);
571
572 return( s.asDouble(d) ? Set_Value(d) : false );
573 }
574
575 virtual bool Set_Value (int Value)
576 {
577 return( Set_Value((double)Value) );
578 }
579
580 virtual bool Set_Value (sLong Value)
581 {
582 return( Set_Value((double)Value) );
583 }
584
585 virtual bool Set_Value (double Value)
586 {
587 if( m_Value != Value )
588 {
589 m_Value = Value;
590
591 return( true );
592 }
593
594 return( false );
595 }
596
597 //-----------------------------------------------------
598 virtual const SG_Char * asString (int Decimals =-99) const
599 {
600 static CSG_String s;
601
602 s = SG_Get_String(m_Value, Decimals);
603
604 return( s.c_str() );
605 }
606
607 virtual int asInt (void) const { return( (int )m_Value ); }
608 virtual sLong asLong (void) const { return( (sLong)m_Value ); }
609 virtual double asDouble (void) const { return( m_Value ); }
610
611 //-----------------------------------------------------
612 virtual bool is_Equal (const CSG_Table_Value &Value) const
613 {
614 return( m_Value == Value.asDouble() );
615 }
616
617 //-----------------------------------------------------
618 virtual CSG_Table_Value & operator = (const SG_Char *Value) { Set_Value(Value ); return( *this ); }
619 virtual CSG_Table_Value & operator = (double Value) { Set_Value(Value ); return( *this ); }
620 virtual CSG_Table_Value & operator = (const CSG_Table_Value &Value) { Set_Value(Value.asDouble()); return( *this ); }
621
622
623private:
624
625 double m_Value;
626
627};
628
629
631// //
632// //
633// //
635
636//---------------------------------------------------------
637#endif // #ifndef HEADER_INCLUDED__SAGA_API__table_value_H
signed long long sLong
Definition api_core.h:158
#define SG_STR_LEN
Definition api_core.h:542
#define SG_STR_CMP(s1, s2)
Definition api_core.h:544
#define SG_Char
Definition api_core.h:536
SAGA_API_DLL_EXPORT CSG_String SG_Get_String(double Value, int Precision=-99)
BYTE * Get_Bytes(void) const
Definition api_core.h:834
static CSG_String Format(const char *Format,...)
int asInt(void) const
const SG_Char * c_str(void) const
int Printf(const char *Format,...)
double asDouble(void) const
virtual bool Set_Value(const CSG_Bytes &Value)
virtual bool Set_Value(sLong Value)
virtual ~CSG_Table_Value_Binary(void)
virtual CSG_Bytes asBinary(void) const
virtual bool Set_NoData(void)
virtual bool is_NoData(void) const
CSG_Bytes & Get_Binary(void)
virtual double asDouble(void) const
virtual bool is_Equal(const CSG_Table_Value &Value) const
virtual bool Set_Value(const SG_Char *Value)
virtual int asInt(void) const
virtual bool Set_Value(double Value)
virtual CSG_Table_Value & operator=(const SG_Char *Value)
virtual const SG_Char * asString(int Decimals=-99) const
virtual sLong asLong(void) const
virtual bool Set_Value(int Value)
virtual TSG_Table_Value_Type Get_Type(void) const
virtual const SG_Char * asString(int Decimals=-99) const
virtual bool Set_Value(double Value)
virtual CSG_Table_Value & operator=(const SG_Char *Value)
virtual bool Set_Value(sLong Value)
virtual bool Set_Value(const CSG_Bytes &Value)
virtual ~CSG_Table_Value_Date(void)
virtual bool is_Equal(const CSG_Table_Value &Value) const
virtual double asDouble(void) const
virtual bool Set_Value(int Value)
virtual int asInt(void) const
virtual bool Set_Value(const SG_Char *Value)
virtual TSG_Table_Value_Type Get_Type(void) const
virtual sLong asLong(void) const
virtual bool Set_Value(const CSG_Bytes &Value)
virtual int asInt(void) const
virtual bool Set_Value(sLong Value)
virtual CSG_Table_Value & operator=(const SG_Char *Value)
virtual double asDouble(void) const
virtual sLong asLong(void) const
virtual ~CSG_Table_Value_Double(void)
virtual const SG_Char * asString(int Decimals=-99) const
virtual bool Set_Value(const SG_Char *Value)
virtual bool Set_Value(double Value)
virtual bool is_Equal(const CSG_Table_Value &Value) const
virtual bool Set_Value(int Value)
virtual TSG_Table_Value_Type Get_Type(void) const
virtual int asInt(void) const
virtual bool Set_Value(sLong Value)
virtual double asDouble(void) const
virtual CSG_Table_Value & operator=(const SG_Char *Value)
virtual bool Set_Value(const SG_Char *Value)
virtual bool Set_Value(const CSG_Bytes &Value)
virtual ~CSG_Table_Value_Int(void)
virtual bool is_Equal(const CSG_Table_Value &Value) const
virtual TSG_Table_Value_Type Get_Type(void) const
virtual sLong asLong(void) const
virtual bool Set_Value(int Value)
virtual const SG_Char * asString(int Decimals=-99) const
virtual bool Set_Value(double Value)
virtual bool Set_Value(int Value)
virtual bool Set_Value(const SG_Char *Value)
virtual bool is_Equal(const CSG_Table_Value &Value) const
virtual ~CSG_Table_Value_Long(void)
virtual bool Set_Value(double Value)
virtual sLong asLong(void) const
virtual double asDouble(void) const
virtual TSG_Table_Value_Type Get_Type(void) const
virtual const SG_Char * asString(int Decimals=-99) const
virtual int asInt(void) const
virtual CSG_Table_Value & operator=(const SG_Char *Value)
virtual bool Set_Value(sLong Value)
virtual bool Set_Value(const CSG_Bytes &Value)
virtual ~CSG_Table_Value_String(void)
virtual sLong asLong(void) const
virtual bool Set_Value(double Value)
virtual const SG_Char * asString(int Decimals=-99) const
virtual bool Set_Value(const SG_Char *Value)
virtual bool Set_Value(sLong Value)
virtual double asDouble(void) const
virtual int asInt(void) const
virtual bool is_Equal(const CSG_Table_Value &Value) const
virtual bool Set_Value(const CSG_Bytes &Value)
virtual CSG_Table_Value & operator=(const SG_Char *Value)
virtual bool Set_Value(int Value)
virtual TSG_Table_Value_Type Get_Type(void) const
virtual ~CSG_Table_Value(void)
virtual const SG_Char * asString(int Decimals=-99) const =0
virtual bool Set_Value(int Value)=0
bool operator==(const CSG_Table_Value &Value) const
virtual int asInt(void) const =0
virtual CSG_Bytes asBinary(void) const
virtual CSG_Table_Value & operator=(const SG_Char *Value)
virtual bool is_Equal(const CSG_Table_Value &Value) const =0
virtual bool Set_Value(sLong Value)=0
virtual bool Set_Value(const SG_Char *Value)=0
virtual bool Set_Value(const CSG_Bytes &Value)=0
virtual double asDouble(void) const =0
virtual sLong asLong(void) const =0
virtual bool Set_Value(double Value)=0
virtual TSG_Table_Value_Type Get_Type(void) const =0
bool SG_JulianDayNumber_To_Date(double JDN, int &y, int &m, int &d)
Definition datetime.cpp:682
double SG_Date_To_JulianDayNumber(int Year, int Month, int Day)
Definition datetime.cpp:742
TSG_Table_Value_Type
Definition table_value.h:92
@ SG_TABLE_VALUE_TYPE_String
Definition table_value.h:94
@ SG_TABLE_VALUE_TYPE_Long
Definition table_value.h:97
@ SG_TABLE_VALUE_TYPE_Date
Definition table_value.h:95
@ SG_TABLE_VALUE_TYPE_Int
Definition table_value.h:96
@ SG_TABLE_VALUE_TYPE_Double
Definition table_value.h:98
@ SG_TABLE_VALUE_TYPE_Binary
Definition table_value.h:93