Drizzled Public API Documentation

temporal_interval.h
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems, Inc.
00005  *
00006  *  Authors: 
00007  *
00008  *  Clint Byrum <clint@fewbar.com>
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; version 2 of the License.
00013  *
00014  *  This program is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with this program; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022  */
00023 
00024 #pragma once
00025 
00026 /* @TODO Replace this include with some forward decls */
00027 #include <drizzled/item.h>
00028 #include <drizzled/type/time.h>
00029 
00030 namespace drizzled {
00031 
00036 class TemporalInterval
00037 {
00038 public:
00039 
00040   TemporalInterval(uint32_t in_year,
00041                    uint32_t in_month,
00042                    uint32_t in_day,
00043                    uint32_t in_hour,
00044                    uint64_t in_minute,
00045                    uint64_t in_second,
00046                    uint64_t in_second_part,
00047                    bool in_neg) :
00048     year(in_year),
00049     month(in_month),
00050     day(in_day),
00051     hour(in_hour),
00052     minute(in_minute),
00053     second(in_second),
00054     second_part(in_second_part),
00055     neg(in_neg)
00056   {}
00057 
00058   TemporalInterval() :
00059     year(0),
00060     month(0),
00061     day(0),
00062     hour(0),
00063     minute(0),
00064     second(0),
00065     second_part(0),
00066     neg(false)
00067   {}
00068 
00073   inline void setNegative(bool in_neg= true)
00074   {
00075     neg= in_neg;
00076   }
00077 
00081   inline void toggleNegative()
00082   {
00083     neg= !neg;
00084   }
00085 
00090   inline bool getNegative() const
00091   {
00092     return neg;
00093   }
00094 
00095   inline uint32_t  get_year() const { return year; }
00096   inline void set_year(uint32_t new_year) { year = new_year; }
00097 
00098   inline uint32_t  get_month() const { return month; }
00099   inline void set_month(uint32_t new_month) { month = new_month; }
00100 
00101   inline uint32_t  get_day() const { return day; }
00102   inline void set_day(uint32_t new_day) { day = new_day; }
00103 
00104   inline uint32_t  get_hour() const { return hour; }
00105   inline void set_hour(uint32_t new_hour) { hour = new_hour; }
00106 
00107   inline uint64_t  get_minute() const { return minute; }
00108   inline void set_minute(uint32_t new_minute) { minute = new_minute; }
00109 
00110   inline uint64_t  get_second() const { return second; }
00111   inline void set_second(uint32_t new_second) { second = new_second; }
00112 
00113   inline uint64_t  get_second_part() const { return second_part; }
00114   inline void set_second_part(uint32_t new_second_part) { second_part = new_second_part; }
00115 
00127   bool initFromItem(Item *args, interval_type int_type, String *str_value);
00128 
00137   bool addDate(type::Time *ltime, interval_type int_type);
00138 
00139 private:
00140 
00144   static const uint32_t MAX_STRING_ELEMENTS = 5;
00145 
00149   static const uint32_t NUM_YEAR_MONTH_STRING_ELEMENTS         = 2;
00150   static const uint32_t NUM_DAY_HOUR_STRING_ELEMENTS           = 2; 
00151   static const uint32_t NUM_DAY_MICROSECOND_STRING_ELEMENTS    = 5;
00152   static const uint32_t NUM_DAY_MINUTE_STRING_ELEMENTS         = 3;
00153   static const uint32_t NUM_DAY_SECOND_STRING_ELEMENTS         = 4;
00154   static const uint32_t NUM_HOUR_MICROSECOND_STRING_ELEMENTS   = 4;
00155   static const uint32_t NUM_HOUR_MINUTE_STRING_ELEMENTS        = 2;
00156   static const uint32_t NUM_HOUR_SECOND_STRING_ELEMENTS        = 3;
00157   static const uint32_t NUM_MINUTE_MICROSECOND_STRING_ELEMENTS = 3;
00158   static const uint32_t NUM_MINUTE_SECOND_STRING_ELEMENTS      = 2;
00159   static const uint32_t NUM_SECOND_MICROSECOND_STRING_ELEMENTS = 2;
00160 
00179   bool getIntervalFromString(const char *str,
00180                              uint32_t length, 
00181                              const charset_info_st * const cs,
00182                              uint32_t count, 
00183                              uint64_t *values,
00184                              bool transform_msec);
00185 
00186   uint32_t  year;
00187   uint32_t  month;
00188   uint32_t  day;
00189   uint32_t  hour;
00190   uint64_t  minute;
00191   uint64_t  second;
00192   uint64_t  second_part;
00193   bool      neg;
00194 
00195 };
00196 
00197 } /* namespace drizzled */
00198