~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/temporal.h

  • Committer: Olaf van der Spek
  • Date: 2011-10-24 21:23:54 UTC
  • mto: This revision was merged to the branch mainline in revision 2449.
  • Revision ID: olafvdspek@gmail.com-20111024212354-j32gbc2sbsw0985q
Use str_ref

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 * @see drizzled/calendar.cc
40
40
 */
41
41
 
42
 
#ifndef DRIZZLED_TEMPORAL_H
43
 
#define DRIZZLED_TEMPORAL_H
 
42
#pragma once
44
43
 
45
44
#define DRIZZLE_MAX_SECONDS 59
 
45
#define DRIZZLE_MAX_SECONDS_WITH_LEAP 61
46
46
#define DRIZZLE_MAX_MINUTES 59
47
47
#define DRIZZLE_MAX_HOURS 23
48
48
#define DRIZZLE_MAX_DAYS 31
66
66
 
67
67
#define DRIZZLE_YY_PART_YEAR  70
68
68
 
69
 
#include "drizzled/calendar.h"
70
 
 
 
69
#include <drizzled/calendar.h>
 
70
#include <drizzled/common_fwd.h>
71
71
#include <cassert>
72
72
#include <ostream>
73
73
 
74
 
/* Outside forward declarations */
75
 
class my_decimal;
76
 
 
77
 
namespace drizzled
78
 
{
79
 
 
80
 
/* Forward declaration needed */
81
 
class TemporalInterval;
82
 
class TemporalIntervalYear;
83
 
class TemporalIntervalDayOrLess;
84
 
class TemporalIntervalDayOrWeek;
85
 
class TemporalIntervalYearMonth;
 
74
namespace drizzled {
86
75
 
87
76
/**
88
77
 * Base class for all temporal data classes.
89
78
 */
90
 
class Temporal
 
79
class DRIZZLED_API Temporal
91
80
{
92
81
protected:
93
82
  enum calendar _calendar;
195
184
  friend class TemporalFormat;
196
185
};
197
186
 
198
 
/* Forward declaration needed */
199
 
class DateTime;
200
 
class Timestamp;
201
 
class Time;
202
 
 
203
187
/**
204
188
 * Class representing temporal components in a valid
205
189
 * SQL date range, with no time component
206
190
 */
207
 
class Date: public Temporal
 
191
class DRIZZLED_API Date: public Temporal
208
192
{
209
193
public:
210
194
  Date() :Temporal() {}
419
403
   *
420
404
   * @param Pointer to a time_t to convert to
421
405
   */
422
 
  virtual void to_time_t(time_t *to) const;
 
406
  virtual void to_time_t(time_t &to) const;
423
407
 
424
408
  /**
425
409
   * Attempts to populate the Date instance based
433
417
  virtual bool from_time_t(const time_t from);
434
418
 
435
419
  /**
436
 
   * Fills a supplied my_decimal with a representation of
 
420
   * Fills a supplied type::Decimal with a representation of
437
421
   * the Date value.
438
422
   *
439
 
   * @param Pointer to the my_decimal to fill
 
423
   * @param Pointer to the type::Decimal to fill
440
424
   */
441
 
  virtual void to_decimal(my_decimal *to) const;
 
425
  virtual void to_decimal(type::Decimal *to) const;
442
426
 
443
427
  friend class TemporalInterval;
444
428
  friend class Timestamp;
451
435
 * Class representing temporal components having only
452
436
 * a time component, with no date structure
453
437
 */
454
 
class Time: public Temporal
 
438
class DRIZZLED_API Time: public Temporal
455
439
{
456
440
public:
457
441
  Time() :Temporal() {}
485
469
  bool is_valid_datetime() const {return false;}
486
470
  bool is_valid_time() const {return is_valid();}
487
471
  bool is_valid_timestamp() const {return false;}
 
472
 
488
473
  /** Returns whether the temporal value is valid date. */
489
474
  bool is_valid() const;
 
475
  bool is_fuzzy_valid() const;
490
476
 
491
477
  /**
492
478
   * Fills a supplied char string with a
530
516
  void to_int32_t(int32_t *to) const;
531
517
 
532
518
  /**
 
519
   * Fills a supplied 8-byte integer pointer with an
 
520
   * integer representation of the Time
 
521
   * value. It is assume seconds past unix epoch
 
522
   *
 
523
   * @param Integer to fill.
 
524
   */
 
525
  void to_uint64_t(uint64_t &to) const;
 
526
 
 
527
  /**
533
528
   * Attempts to populate the Time instance based
534
529
   * on the contents of a supplied 4-byte integer.
535
530
   *
557
552
  bool from_time_t(const time_t from);
558
553
 
559
554
  /**
560
 
   * Fills a supplied my_decimal with a representation of
 
555
   * Fills a supplied type::Decimal with a representation of
561
556
   * the Time value.
562
557
   *
563
 
   * @param Pointer to the my_decimal to fill
 
558
   * @param Pointer to the type::Decimal to fill
564
559
   */
565
 
  void to_decimal(my_decimal *to) const;
 
560
  void to_decimal(type::Decimal *to) const;
566
561
 
567
562
  friend class Date;
568
563
  friend class DateTime;
572
567
 * Class representing temporal components in a valid
573
568
 * SQL datetime range, including a time component
574
569
 */
575
 
class DateTime: public Date
 
570
class DRIZZLED_API DateTime: public Date
576
571
{
577
572
public:
578
573
  DateTime() :Date() {}
643
638
   * @param time_t to convert from
644
639
   */
645
640
  bool from_time_t(const time_t from);
 
641
  bool from_timeval(struct timeval &_timeval);
646
642
 
647
643
  /**
648
644
   * Attempts to populate the DateTime instance based
671
667
  void to_tm(struct tm *to) const;
672
668
 
673
669
  /**
674
 
   * Fills a supplied my_decimal with a representation of
 
670
   * Fills a supplied type::Decimal with a representation of
675
671
   * the DateTime value.
676
672
   *
677
 
   * @param Pointer to the my_decimal to fill
 
673
   * @param Pointer to the type::Decimal to fill
678
674
   */
679
 
  void to_decimal(my_decimal *to) const;
 
675
  void to_decimal(type::Decimal *to) const;
680
676
 
681
677
  friend class Timestamp;
682
678
};
684
680
/**
685
681
 * Class representing temporal components in the UNIX epoch
686
682
 */
687
 
class Timestamp: public DateTime
 
683
class DRIZZLED_API Timestamp: public DateTime
688
684
{
689
685
public:
690
686
  Timestamp() :DateTime() {}
738
734
   *
739
735
   * @param Pointer to a time_t to convert to
740
736
   */
741
 
  void to_time_t(time_t *to) const;
 
737
  void to_time_t(time_t &to) const;
742
738
};
743
739
 
744
740
/**
750
746
 * Class representing temporal components in the UNIX epoch
751
747
 * with an additional microsecond component.
752
748
 */
753
 
class MicroTimestamp: public Timestamp
 
749
class DRIZZLED_API MicroTimestamp: public Timestamp
754
750
{
755
751
public:
756
752
  MicroTimestamp() :Timestamp() {}
786
782
   *
787
783
   * @param timeval to fill.
788
784
   */
789
 
  void to_timeval(struct timeval *to) const;
 
785
  void to_timeval(struct timeval &to) const;
790
786
};
791
787
 
792
788
/**
793
789
 * Class representing temporal components in the UNIX epoch
794
790
 * with an additional nanosecond component.
795
791
 */
796
 
class NanoTimestamp: public Timestamp
 
792
class DRIZZLED_API NanoTimestamp: public Timestamp
797
793
{
798
794
public:
799
795
  NanoTimestamp() :Timestamp() {}
815
811
 
816
812
} /* end namespace drizzled */
817
813
 
818
 
#endif /* DRIZZLED_TEMPORAL_H */