------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2007-2009 Vadim Godunko <vgodunko@gmail.com>                 --
--                                                                          --
-- QtAda is free software;  you can  redistribute it and/or modify it under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 2,  or (at your option) any later ver- --
-- sion. QtAda is distributed in the hope that it will be useful, but WITH- --
-- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
-- for  more details.  You should have  received  a copy of the GNU General --
-- Public License distributed with QtAda;  see file COPYING.  If not, write --
-- to  the  Free Software Foundation,  51  Franklin  Street,  Fifth  Floor, --
-- Boston, MA 02110-1301, USA.                                              --
--                                                                          --
-- As a special exception,  if other files  instantiate  generics from this --
-- unit, or you link  this unit with other files  to produce an executable, --
-- this  unit  does not  by itself cause  the resulting  executable  to  be --
-- covered  by the  GNU  General  Public  License.  This exception does not --
-- however invalidate  any other reasons why  the executable file  might be --
-- covered by the  GNU Public License.                                      --
--                                                                          --
------------------------------------------------------------------------------
--    This file has been generated automatically. Please don't edit it.     --
------------------------------------------------------------------------------
pragma Style_Checks ("NM32766");
with System.Address_To_Access_Conversions;

with Qt4_Debug;

package body Qt4.Date_Times is

   procedure Q_Date_Time_Image (Item : in Q_Date_Time);
   pragma Export (Ada, Q_Date_Time_Image, "q_date_time_image");

   function initialize_QDateTime
    (Storage : in System.Address)
      return Internals.QDateTime_Access;
   pragma Import (C, initialize_QDateTime, "__QtAda_inititialize_QDateTime");

   function initialize_QDateTime_QDateCR
    (Storage : in System.Address;
     Date : in Qt4.Dates.Internals.QDate_Access)
      return Internals.QDateTime_Access;
   pragma Import (C, initialize_QDateTime_QDateCR, "__QtAda_inititialize_QDateTime_QDateCR");

   function initialize_QDateTime_QDateCR_QTimeCR_TimeSpec
    (Storage : in System.Address;
     Date : in Qt4.Dates.Internals.QDate_Access;
     Time : in Qt4.Times.Internals.QTime_Access;
     Spec : in Qt4.Time_Spec)
      return Internals.QDateTime_Access;
   pragma Import (C, initialize_QDateTime_QDateCR_QTimeCR_TimeSpec, "__QtAda_inititialize_QDateTime_QDateCR_QTimeCR_TimeSpec");

   function adjust_QDateTime
    (Storage : in System.Address;
     From    : in Internals.QDateTime_Access)
       return Internals.QDateTime_Access;
   pragma Import (C, adjust_QDateTime, "__QtAda_adjust_QDateTime");

   procedure finalize_QDateTime (Object : in Internals.QDateTime_Access);
   pragma Import (C, finalize_QDateTime, "__QtAda_finalize_QDateTime");

   procedure QDateTime_addDays_int
    (Returns : in Internals.QDateTime_Access;
     Self : in Internals.QDateTime_Access;
     Days : in Qt4.Q_Integer);
   pragma Import (C, QDateTime_addDays_int, "__QtAda_QDateTime_addDays_int_Q");

   procedure QDateTime_addMSecs_qint64
    (Returns : in Internals.QDateTime_Access;
     Self : in Internals.QDateTime_Access;
     Msecs : in Qt4.Q_Integer_64);
   pragma Import (C, QDateTime_addMSecs_qint64, "__QtAda_QDateTime_addMSecs_qint64_Q");

   procedure QDateTime_addMonths_int
    (Returns : in Internals.QDateTime_Access;
     Self : in Internals.QDateTime_Access;
     Days : in Qt4.Q_Integer);
   pragma Import (C, QDateTime_addMonths_int, "__QtAda_QDateTime_addMonths_int_Q");

   procedure QDateTime_addSecs_int
    (Returns : in Internals.QDateTime_Access;
     Self : in Internals.QDateTime_Access;
     Days : in Qt4.Q_Integer);
   pragma Import (C, QDateTime_addSecs_int, "__QtAda_QDateTime_addSecs_int_Q");

   procedure QDateTime_addYears_int
    (Returns : in Internals.QDateTime_Access;
     Self : in Internals.QDateTime_Access;
     Days : in Qt4.Q_Integer);
   pragma Import (C, QDateTime_addYears_int, "__QtAda_QDateTime_addYears_int_Q");

   procedure QDateTime_date
    (Returns : in Qt4.Dates.Internals.QDate_Access;
     Self : in Internals.QDateTime_Access);
   pragma Import (C, QDateTime_date, "__QtAda_QDateTime_date_Q");

   function QDateTime_daysTo_QDateTimeCR
    (Self : in Internals.QDateTime_Access;
     Other : in Internals.QDateTime_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDateTime_daysTo_QDateTimeCR, "__QtAda_QDateTime_daysTo_QDateTimeCR_Q");

   function QDateTime_isNull
    (Self : in Internals.QDateTime_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QDateTime_isNull, "__QtAda_QDateTime_isNull_Q");

   function QDateTime_isValid
    (Self : in Internals.QDateTime_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QDateTime_isValid, "__QtAda_QDateTime_isValid_Q");

   function QDateTime_secsTo_QDateTimeCR
    (Self : in Internals.QDateTime_Access;
     Other : in Internals.QDateTime_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDateTime_secsTo_QDateTimeCR, "__QtAda_QDateTime_secsTo_QDateTimeCR_Q");

   procedure QDateTime_setDate_QDateCR
    (Self : in Internals.QDateTime_Access;
     Date : in Qt4.Dates.Internals.QDate_Access);
   pragma Import (C, QDateTime_setDate_QDateCR, "__QtAda_QDateTime_setDate_QDateCR");

   procedure QDateTime_setTime_QTimeCR
    (Self : in Internals.QDateTime_Access;
     Time : in Qt4.Times.Internals.QTime_Access);
   pragma Import (C, QDateTime_setTime_QTimeCR, "__QtAda_QDateTime_setTime_QTimeCR");

   procedure QDateTime_setTimeSpec_TimeSpec
    (Self : in Internals.QDateTime_Access;
     Spec : in Qt4.Time_Spec);
   pragma Import (C, QDateTime_setTimeSpec_TimeSpec, "__QtAda_QDateTime_setTimeSpec_TimeSpec");

   procedure QDateTime_time
    (Returns : in Qt4.Times.Internals.QTime_Access;
     Self : in Internals.QDateTime_Access);
   pragma Import (C, QDateTime_time, "__QtAda_QDateTime_time_Q");

   function QDateTime_timeSpec
    (Self : in Internals.QDateTime_Access)
       return Qt4.Time_Spec;
   pragma Import (C, QDateTime_timeSpec, "__QtAda_QDateTime_timeSpec_Q");

   procedure QDateTime_toLocalTime
    (Returns : in Internals.QDateTime_Access;
     Self : in Internals.QDateTime_Access);
   pragma Import (C, QDateTime_toLocalTime, "__QtAda_QDateTime_toLocalTime_Q");

   procedure QDateTime_toString_QStringCR
    (Returns : in Qt4.Strings.Internals.QString_Access;
     Self : in Internals.QDateTime_Access;
     Format : in Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QDateTime_toString_QStringCR, "__QtAda_QDateTime_toString_QStringCR_Q");

   procedure QDateTime_toString_DateFormat
    (Returns : in Qt4.Strings.Internals.QString_Access;
     Self : in Internals.QDateTime_Access;
     F : in Qt4.Date_Format);
   pragma Import (C, QDateTime_toString_DateFormat, "__QtAda_QDateTime_toString_DateFormat_Q");

   procedure QDateTime_toTimeSpec_TimeSpec
    (Returns : in Internals.QDateTime_Access;
     Self : in Internals.QDateTime_Access;
     Spec : in Qt4.Time_Spec);
   pragma Import (C, QDateTime_toTimeSpec_TimeSpec, "__QtAda_QDateTime_toTimeSpec_TimeSpec_Q");

   procedure QDateTime_toUTC
    (Returns : in Internals.QDateTime_Access;
     Self : in Internals.QDateTime_Access);
   pragma Import (C, QDateTime_toUTC, "__QtAda_QDateTime_toUTC_Q");

   procedure QDateTime_currentDateTime
    (Returns : in Internals.QDateTime_Access);
   pragma Import (C, QDateTime_currentDateTime, "__QtAda_QDateTime_currentDateTime_S");

   procedure QDateTime_fromString_QStringCR_DateFormat
    (Returns : in Internals.QDateTime_Access;
     S : in Qt4.Strings.Internals.QString_Access;
     F : in Qt4.Date_Format);
   pragma Import (C, QDateTime_fromString_QStringCR_DateFormat, "__QtAda_QDateTime_fromString_QStringCR_DateFormat_S");

   procedure QDateTime_fromString_QStringCR_QStringCR
    (Returns : in Internals.QDateTime_Access;
     S : in Qt4.Strings.Internals.QString_Access;
     Format : in Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QDateTime_fromString_QStringCR_QStringCR, "__QtAda_QDateTime_fromString_QStringCR_QStringCR_S");

   function eq_QDateTimeCR
    (Self : in Internals.QDateTime_Access;
     Other : in Internals.QDateTime_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, eq_QDateTimeCR, "__QtAda_QDateTime_eq_QDateTimeCR_Q");

   function lt_QDateTimeCR
    (Self : in Internals.QDateTime_Access;
     Other : in Internals.QDateTime_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, lt_QDateTimeCR, "__QtAda_QDateTime_lt_QDateTimeCR_Q");

   function le_QDateTimeCR
    (Self : in Internals.QDateTime_Access;
     Other : in Internals.QDateTime_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, le_QDateTimeCR, "__QtAda_QDateTime_le_QDateTimeCR_Q");

   function gt_QDateTimeCR
    (Self : in Internals.QDateTime_Access;
     Other : in Internals.QDateTime_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, gt_QDateTimeCR, "__QtAda_QDateTime_gt_QDateTimeCR_Q");

   function ge_QDateTimeCR
    (Self : in Internals.QDateTime_Access;
     Other : in Internals.QDateTime_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, ge_QDateTimeCR, "__QtAda_QDateTime_ge_QDateTimeCR_Q");

   -----------------------
   -- Q_Date_Time_Image --
   -----------------------

   procedure Q_Date_Time_Image (Item : in Q_Date_Time) is
   begin
      Qt4_Debug.Output (Item.To_String.To_Local_8_Bit);
   end Q_Date_Time_Image;

   ------------
   -- Adjust --
   ------------

   overriding
   procedure Adjust (Self : in out Q_Date_Time) is
   begin
      Self.Object := adjust_QDateTime (Self.Storage'Address, Self.Object);
      Self.Wrapper := False;
   end Adjust;

   --------------
   -- Finalize --
   --------------

   overriding
   procedure Finalize (Self : in out Q_Date_Time) is
   begin
      if not Self.Wrapper then
         finalize_QDateTime (Self.Object);
      end if;
   end Finalize;

   ----------------
   -- Initialize --
   ----------------

   overriding
   procedure Initialize (Self : in out Q_Date_Time) is
      use type Internals.QDateTime_Access;

   begin
      if Self.Object = null then
         Self.Object := initialize_QDateTime (Self.Storage'Address);
      end if;
   end Initialize;

   ------------
   -- Create --
   ------------

   function Create
    (Date : in Qt4.Dates.Q_Date'Class)
       return Q_Date_Time
   is
   begin
      return Self : Q_Date_Time
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QDateTime_QDateCR (Self.Storage'Address, Qt4.Dates.Internals.QDate_View (Date));
      end return;
   end Create;

   ------------
   -- Create --
   ------------

   function Create
    (Date : in Qt4.Dates.Q_Date'Class;
     Time : in Qt4.Times.Q_Time'Class;
     Spec : in Qt4.Time_Spec
       := Local_Time)
       return Q_Date_Time
   is
   begin
      return Self : Q_Date_Time
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QDateTime_QDateCR_QTimeCR_TimeSpec (Self.Storage'Address, Qt4.Dates.Internals.QDate_View (Date), Qt4.Times.Internals.QTime_View (Time), Spec);
      end return;
   end Create;

   --------------
   -- Add_Days --
   --------------

   function Add_Days
    (Self : in Q_Date_Time'Class;
     Days : in Qt4.Q_Integer)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_addDays_int (Returns.Object, Self.Object, Days);
      end return;
   end Add_Days;

   ----------------
   -- Add_M_Secs --
   ----------------

   function Add_M_Secs
    (Self : in Q_Date_Time'Class;
     Msecs : in Duration)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_addMSecs_qint64 (Returns.Object, Self.Object, Qt4.Q_Integer_64 (Msecs * 1000.0));
      end return;
   end Add_M_Secs;

   ----------------
   -- Add_Months --
   ----------------

   function Add_Months
    (Self : in Q_Date_Time'Class;
     Days : in Qt4.Q_Integer)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_addMonths_int (Returns.Object, Self.Object, Days);
      end return;
   end Add_Months;

   --------------
   -- Add_Secs --
   --------------

   function Add_Secs
    (Self : in Q_Date_Time'Class;
     Days : in Qt4.Q_Integer)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_addSecs_int (Returns.Object, Self.Object, Days);
      end return;
   end Add_Secs;

   ---------------
   -- Add_Years --
   ---------------

   function Add_Years
    (Self : in Q_Date_Time'Class;
     Days : in Qt4.Q_Integer)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_addYears_int (Returns.Object, Self.Object, Days);
      end return;
   end Add_Years;

   ----------
   -- Date --
   ----------

   function Date
    (Self : in Q_Date_Time'Class)
       return Qt4.Dates.Q_Date
   is
   begin
      return Returns : Qt4.Dates.Q_Date do
         QDateTime_date (Qt4.Dates.Internals.QDate_View (Returns), Self.Object);
      end return;
   end Date;

   -------------
   -- Days_To --
   -------------

   function Days_To
    (Self : in Q_Date_Time'Class;
     Other : in Q_Date_Time'Class)
       return Qt4.Q_Integer
   is
   begin
      return QDateTime_daysTo_QDateTimeCR (Self.Object, Other.Object);
   end Days_To;

   -------------
   -- Is_Null --
   -------------

   function Is_Null
    (Self : in Q_Date_Time'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QDateTime_isNull (Self.Object), 0);
   end Is_Null;

   --------------
   -- Is_Valid --
   --------------

   function Is_Valid
    (Self : in Q_Date_Time'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QDateTime_isValid (Self.Object), 0);
   end Is_Valid;

   -------------
   -- Secs_To --
   -------------

   function Secs_To
    (Self : in Q_Date_Time'Class;
     Other : in Q_Date_Time'Class)
       return Qt4.Q_Integer
   is
   begin
      return QDateTime_secsTo_QDateTimeCR (Self.Object, Other.Object);
   end Secs_To;

   --------------
   -- Set_Date --
   --------------

   procedure Set_Date
    (Self : in out Q_Date_Time'Class;
     Date : in Qt4.Dates.Q_Date'Class)
   is
   begin
      QDateTime_setDate_QDateCR (Self.Object, Qt4.Dates.Internals.QDate_View (Date));
   end Set_Date;

   --------------
   -- Set_Time --
   --------------

   procedure Set_Time
    (Self : in out Q_Date_Time'Class;
     Time : in Qt4.Times.Q_Time'Class)
   is
   begin
      QDateTime_setTime_QTimeCR (Self.Object, Qt4.Times.Internals.QTime_View (Time));
   end Set_Time;

   -------------------
   -- Set_Time_Spec --
   -------------------

   procedure Set_Time_Spec
    (Self : in out Q_Date_Time'Class;
     Spec : in Qt4.Time_Spec)
   is
   begin
      QDateTime_setTimeSpec_TimeSpec (Self.Object, Spec);
   end Set_Time_Spec;

   ----------
   -- Time --
   ----------

   function Time
    (Self : in Q_Date_Time'Class)
       return Qt4.Times.Q_Time
   is
   begin
      return Returns : Qt4.Times.Q_Time do
         QDateTime_time (Qt4.Times.Internals.QTime_View (Returns), Self.Object);
      end return;
   end Time;

   ---------------
   -- Time_Spec --
   ---------------

   function Time_Spec
    (Self : in Q_Date_Time'Class)
       return Qt4.Time_Spec
   is
   begin
      return QDateTime_timeSpec (Self.Object);
   end Time_Spec;

   -------------------
   -- To_Local_Time --
   -------------------

   function To_Local_Time
    (Self : in Q_Date_Time'Class)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_toLocalTime (Returns.Object, Self.Object);
      end return;
   end To_Local_Time;

   ---------------
   -- To_String --
   ---------------

   function To_String
    (Self : in Q_Date_Time'Class;
     Format : in Qt4.Strings.Q_String'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QDateTime_toString_QStringCR (Qt4.Strings.Internals.QString_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Format));
      end return;
   end To_String;

   ---------------
   -- To_String --
   ---------------

   function To_String
    (Self : in Q_Date_Time'Class;
     F : in Qt4.Date_Format
       := Text_Date)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QDateTime_toString_DateFormat (Qt4.Strings.Internals.QString_View (Returns), Self.Object, F);
      end return;
   end To_String;

   ------------------
   -- To_Time_Spec --
   ------------------

   function To_Time_Spec
    (Self : in Q_Date_Time'Class;
     Spec : in Qt4.Time_Spec)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_toTimeSpec_TimeSpec (Returns.Object, Self.Object, Spec);
      end return;
   end To_Time_Spec;

   ------------
   -- To_UTC --
   ------------

   function To_UTC
    (Self : in Q_Date_Time'Class)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_toUTC (Returns.Object, Self.Object);
      end return;
   end To_UTC;

   -----------------------
   -- Current_Date_Time --
   -----------------------

   function Current_Date_Time
     return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_currentDateTime (Returns.Object);
      end return;
   end Current_Date_Time;

   -----------------
   -- From_String --
   -----------------

   function From_String
    (S : in Qt4.Strings.Q_String'Class;
     F : in Qt4.Date_Format
       := Text_Date)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_fromString_QStringCR_DateFormat (Returns.Object, Qt4.Strings.Internals.QString_View (S), F);
      end return;
   end From_String;

   -----------------
   -- From_String --
   -----------------

   function From_String
    (S : in Qt4.Strings.Q_String'Class;
     Format : in Qt4.Strings.Q_String'Class)
       return Q_Date_Time
   is
   begin
      return Returns : Q_Date_Time do
         QDateTime_fromString_QStringCR_QStringCR (Returns.Object, Qt4.Strings.Internals.QString_View (S), Qt4.Strings.Internals.QString_View (Format));
      end return;
   end From_String;

   ---------
   -- "=" --
   ---------

   function "="
    (Self : in Q_Date_Time;
     Other : in Q_Date_Time)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (eq_QDateTimeCR (Self.Object, Other.Object), 0);
   end "=";

   ---------
   -- "<" --
   ---------

   function "<"
    (Self : in Q_Date_Time;
     Other : in Q_Date_Time)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (lt_QDateTimeCR (Self.Object, Other.Object), 0);
   end "<";

   ----------
   -- "<=" --
   ----------

   function "<="
    (Self : in Q_Date_Time;
     Other : in Q_Date_Time)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (le_QDateTimeCR (Self.Object, Other.Object), 0);
   end "<=";

   ---------
   -- ">" --
   ---------

   function ">"
    (Self : in Q_Date_Time;
     Other : in Q_Date_Time)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (gt_QDateTimeCR (Self.Object, Other.Object), 0);
   end ">";

   ----------
   -- ">=" --
   ----------

   function ">="
    (Self : in Q_Date_Time;
     Other : in Q_Date_Time)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (ge_QDateTimeCR (Self.Object, Other.Object), 0);
   end ">=";

   ---------------
   -- Internals --
   ---------------

   package body Internals is

   --------------------
   -- QDateTime_View --
   --------------------

      function QDateTime_View
       (Item : in Q_Date_Time'Class)
          return QDateTime_Access
      is
      begin
         return Item.Object;
      end QDateTime_View;

      package QDateTime_Conversions is
        new System.Address_To_Access_Conversions
             (QDateTime);

   -------------------------
   -- QDateTimeTo_Pointer --
   -------------------------

      function To_Pointer
       (Address : in System.Address)
          return QDateTime_Access
      is
      begin
         return
           QDateTime_Access
            (QDateTime_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   -------------------------
   -- QDateTimeTo_Address --
   -------------------------

      function To_Address
       (Pointer : in QDateTime_Access)
          return System.Address
      is
      begin
         return
           QDateTime_Conversions.To_Address
            (QDateTime_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

   --------------------
   -- Create_Wrapper --
   --------------------

      function Create_Wrapper
       (Item : in Internals.QDateTime_Access)
          return Q_Date_Time
      is
      begin
         return Q_Date_Time'
          (Ada.Finalization.Controlled with
             Object  => Item,
             Wrapper => True,
             others  => <>);
      end Create_Wrapper;

   end Internals;

end Qt4.Date_Times;
