------------------------------------------------------------------------------
--                                                                          --
--                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.Dates is

   procedure Q_Date_Image (Item : Q_Date);
   pragma Export (Ada, Q_Date_Image, "q_date_image");

   function initialize_QDate
    (Storage : in System.Address)
      return Internals.QDate_Access;
   pragma Import (C, initialize_QDate, "__QtAda_inititialize_QDate");

   function initialize_QDate_int_int_int
    (Storage : in System.Address;
     Y : in Qt4.Q_Integer;
     M : in Qt4.Q_Integer;
     D : in Qt4.Q_Integer)
      return Internals.QDate_Access;
   pragma Import (C, initialize_QDate_int_int_int, "__QtAda_inititialize_QDate_int_int_int");

   function adjust_QDate
    (Storage : in System.Address;
     From    : in Internals.QDate_Access)
       return Internals.QDate_Access;
   pragma Import (C, adjust_QDate, "__QtAda_adjust_QDate");

   procedure finalize_QDate (Object : in Internals.QDate_Access);
   pragma Import (C, finalize_QDate, "__QtAda_finalize_QDate");

   procedure QDate_addDays_int
    (Returns : in Internals.QDate_Access;
     Self : in Internals.QDate_Access;
     Days : in Qt4.Q_Integer);
   pragma Import (C, QDate_addDays_int, "__QtAda_QDate_addDays_int_Q");

   procedure QDate_addMonths_int
    (Returns : in Internals.QDate_Access;
     Self : in Internals.QDate_Access;
     Months : in Qt4.Q_Integer);
   pragma Import (C, QDate_addMonths_int, "__QtAda_QDate_addMonths_int_Q");

   procedure QDate_addYears_int
    (Returns : in Internals.QDate_Access;
     Self : in Internals.QDate_Access;
     Years : in Qt4.Q_Integer);
   pragma Import (C, QDate_addYears_int, "__QtAda_QDate_addYears_int_Q");

   function QDate_day
    (Self : in Internals.QDate_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDate_day, "__QtAda_QDate_day_Q");

   function QDate_dayOfWeek
    (Self : in Internals.QDate_Access)
       return Qt4.Day_Of_Week;
   pragma Import (C, QDate_dayOfWeek, "__QtAda_QDate_dayOfWeek_Q");

   function QDate_dayOfYear
    (Self : in Internals.QDate_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDate_dayOfYear, "__QtAda_QDate_dayOfYear_Q");

   function QDate_daysInMonth
    (Self : in Internals.QDate_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDate_daysInMonth, "__QtAda_QDate_daysInMonth_Q");

   function QDate_daysInYear
    (Self : in Internals.QDate_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDate_daysInYear, "__QtAda_QDate_daysInYear_Q");

   function QDate_daysTo_QDateCR
    (Self : in Internals.QDate_Access;
     D : in Internals.QDate_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDate_daysTo_QDateCR, "__QtAda_QDate_daysTo_QDateCR_Q");

   function QDate_isNull
    (Self : in Internals.QDate_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QDate_isNull, "__QtAda_QDate_isNull_Q");

   function QDate_isValid
    (Self : in Internals.QDate_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QDate_isValid, "__QtAda_QDate_isValid_Q");

   function QDate_month
    (Self : in Internals.QDate_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDate_month, "__QtAda_QDate_month_Q");

   function QDate_toJulianDay
    (Self : in Internals.QDate_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDate_toJulianDay, "__QtAda_QDate_toJulianDay_Q");

   procedure QDate_toString_QStringCR
    (Returns : in Qt4.Strings.Internals.QString_Access;
     Self : in Internals.QDate_Access;
     Format : in Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QDate_toString_QStringCR, "__QtAda_QDate_toString_QStringCR_Q");

   procedure QDate_toString_DateFormat
    (Returns : in Qt4.Strings.Internals.QString_Access;
     Self : in Internals.QDate_Access;
     F : in Qt4.Date_Format);
   pragma Import (C, QDate_toString_DateFormat, "__QtAda_QDate_toString_DateFormat_Q");

   function QDate_year
    (Self : in Internals.QDate_Access)
       return Qt4.Q_Integer;
   pragma Import (C, QDate_year, "__QtAda_QDate_year_Q");

   procedure QDate_currentDate
    (Returns : in Internals.QDate_Access);
   pragma Import (C, QDate_currentDate, "__QtAda_QDate_currentDate_S");

   procedure QDate_fromJulianDay_int
    (Returns : in Internals.QDate_Access;
     Jd : in Qt4.Q_Integer);
   pragma Import (C, QDate_fromJulianDay_int, "__QtAda_QDate_fromJulianDay_int_S");

   procedure QDate_fromString_QStringCR_DateFormat
    (Returns : in Internals.QDate_Access;
     S : in Qt4.Strings.Internals.QString_Access;
     F : in Qt4.Date_Format);
   pragma Import (C, QDate_fromString_QStringCR_DateFormat, "__QtAda_QDate_fromString_QStringCR_DateFormat_S");

   procedure QDate_fromString_QStringCR_QStringCR
    (Returns : in Internals.QDate_Access;
     S : in Qt4.Strings.Internals.QString_Access;
     Format : in Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QDate_fromString_QStringCR_QStringCR, "__QtAda_QDate_fromString_QStringCR_QStringCR_S");

   function QDate_isLeapYear_int
    (Year : in Qt4.Q_Integer)
       return Interfaces.C.unsigned;
   pragma Import (C, QDate_isLeapYear_int, "__QtAda_QDate_isLeapYear_int_S");

   function QDate_isValid_int_int_int
    (Y : in Qt4.Q_Integer;
     M : in Qt4.Q_Integer;
     D : in Qt4.Q_Integer)
       return Interfaces.C.unsigned;
   pragma Import (C, QDate_isValid_int_int_int, "__QtAda_QDate_isValid_int_int_int_S");

   procedure QDate_longDayName_DayOfWeek
    (Returns : in Qt4.Strings.Internals.QString_Access;
     Weekday : in Qt4.Day_Of_Week);
   pragma Import (C, QDate_longDayName_DayOfWeek, "__QtAda_QDate_longDayName_DayOfWeek_S");

   procedure QDate_longMonthName_int
    (Returns : in Qt4.Strings.Internals.QString_Access;
     Month : in Qt4.Q_Integer);
   pragma Import (C, QDate_longMonthName_int, "__QtAda_QDate_longMonthName_int_S");

   procedure QDate_shortDayName_DayOfWeek
    (Returns : in Qt4.Strings.Internals.QString_Access;
     Weekday : in Qt4.Day_Of_Week);
   pragma Import (C, QDate_shortDayName_DayOfWeek, "__QtAda_QDate_shortDayName_DayOfWeek_S");

   procedure QDate_shortMonthName_int
    (Returns : in Qt4.Strings.Internals.QString_Access;
     Month : in Qt4.Q_Integer);
   pragma Import (C, QDate_shortMonthName_int, "__QtAda_QDate_shortMonthName_int_S");

   function eq_QDateCR
    (Self : in Internals.QDate_Access;
     Other : in Internals.QDate_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, eq_QDateCR, "__QtAda_QDate_eq_QDateCR_Q");

   function lt_QDateCR
    (Self : in Internals.QDate_Access;
     Other : in Internals.QDate_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, lt_QDateCR, "__QtAda_QDate_lt_QDateCR_Q");

   function le_QDateCR
    (Self : in Internals.QDate_Access;
     Other : in Internals.QDate_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, le_QDateCR, "__QtAda_QDate_le_QDateCR_Q");

   function gt_QDateCR
    (Self : in Internals.QDate_Access;
     Other : in Internals.QDate_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, gt_QDateCR, "__QtAda_QDate_gt_QDateCR_Q");

   function ge_QDateCR
    (Self : in Internals.QDate_Access;
     Other : in Internals.QDate_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, ge_QDateCR, "__QtAda_QDate_ge_QDateCR_Q");

   ------------------
   -- Q_Date_Image --
   ------------------

   procedure Q_Date_Image (Item : Q_Date) is
   begin
      Qt4_Debug.Output (Item.To_String.To_Local_8_Bit);
   end Q_Date_Image;

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

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

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

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

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

   overriding
   procedure Initialize (Self : in out Q_Date) is
      use type Internals.QDate_Access;

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

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

   function Create
    (Y : in Qt4.Q_Year_Number;
     M : in Qt4.Q_Month_Number;
     D : in Qt4.Q_Day_Number)
       return Q_Date
   is
   begin
      return Self : Q_Date
        := (Ada.Finalization.Controlled with others => <>)
      do
         Self.Object := initialize_QDate_int_int_int (Self.Storage'Address, Y, M, D);
      end return;
   end Create;

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

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

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

   function Add_Months
    (Self : in Q_Date'Class;
     Months : in Qt4.Q_Integer)
       return Q_Date
   is
   begin
      return Returns : Q_Date do
         QDate_addMonths_int (Returns.Object, Self.Object, Months);
      end return;
   end Add_Months;

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

   function Add_Years
    (Self : in Q_Date'Class;
     Years : in Qt4.Q_Integer)
       return Q_Date
   is
   begin
      return Returns : Q_Date do
         QDate_addYears_int (Returns.Object, Self.Object, Years);
      end return;
   end Add_Years;

   ---------
   -- Day --
   ---------

   function Day
    (Self : in Q_Date'Class)
       return Qt4.Q_Day_Number
   is
   begin
      return QDate_day (Self.Object);
   end Day;

   -----------------
   -- Day_Of_Week --
   -----------------

   function Day_Of_Week
    (Self : in Q_Date'Class)
       return Qt4.Day_Of_Week
   is
   begin
      return QDate_dayOfWeek (Self.Object);
   end Day_Of_Week;

   -----------------
   -- Day_Of_Year --
   -----------------

   function Day_Of_Year
    (Self : in Q_Date'Class)
       return Qt4.Q_Years_Day_Number
   is
   begin
      return QDate_dayOfYear (Self.Object);
   end Day_Of_Year;

   -------------------
   -- Days_In_Month --
   -------------------

   function Days_In_Month
    (Self : in Q_Date'Class)
       return Qt4.Q_Day_Number
   is
   begin
      return QDate_daysInMonth (Self.Object);
   end Days_In_Month;

   ------------------
   -- Days_In_Year --
   ------------------

   function Days_In_Year
    (Self : in Q_Date'Class)
       return Qt4.Q_Years_Day_Number
   is
   begin
      return QDate_daysInYear (Self.Object);
   end Days_In_Year;

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

   function Days_To
    (Self : in Q_Date'Class;
     D : in Q_Date'Class)
       return Qt4.Q_Integer
   is
   begin
      return QDate_daysTo_QDateCR (Self.Object, D.Object);
   end Days_To;

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

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

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

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

   -----------
   -- Month --
   -----------

   function Month
    (Self : in Q_Date'Class)
       return Qt4.Q_Month_Number
   is
   begin
      return QDate_month (Self.Object);
   end Month;

   -------------------
   -- To_Julian_Day --
   -------------------

   function To_Julian_Day
    (Self : in Q_Date'Class)
       return Qt4.Q_Integer
   is
   begin
      return QDate_toJulianDay (Self.Object);
   end To_Julian_Day;

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

   function To_String
    (Self : in Q_Date'Class;
     Format : in Qt4.Strings.Q_String'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QDate_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'Class;
     F : in Qt4.Date_Format
       := Text_Date)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QDate_toString_DateFormat (Qt4.Strings.Internals.QString_View (Returns), Self.Object, F);
      end return;
   end To_String;

   ----------
   -- Year --
   ----------

   function Year
    (Self : in Q_Date'Class)
       return Qt4.Q_Year_Number
   is
   begin
      return QDate_year (Self.Object);
   end Year;

   ------------------
   -- Current_Date --
   ------------------

   function Current_Date
     return Q_Date
   is
   begin
      return Returns : Q_Date do
         QDate_currentDate (Returns.Object);
      end return;
   end Current_Date;

   ---------------------
   -- From_Julian_Day --
   ---------------------

   function From_Julian_Day
    (Jd : in Qt4.Q_Integer)
       return Q_Date
   is
   begin
      return Returns : Q_Date do
         QDate_fromJulianDay_int (Returns.Object, Jd);
      end return;
   end From_Julian_Day;

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

   function From_String
    (S : in Qt4.Strings.Q_String'Class;
     F : in Qt4.Date_Format
       := Text_Date)
       return Q_Date
   is
   begin
      return Returns : Q_Date do
         QDate_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
   is
   begin
      return Returns : Q_Date do
         QDate_fromString_QStringCR_QStringCR (Returns.Object, Qt4.Strings.Internals.QString_View (S), Qt4.Strings.Internals.QString_View (Format));
      end return;
   end From_String;

   ------------------
   -- Is_Leap_Year --
   ------------------

   function Is_Leap_Year
    (Year : in Qt4.Q_Year_Number)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QDate_isLeapYear_int (Year), 0);
   end Is_Leap_Year;

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

   function Is_Valid
    (Y : in Qt4.Q_Year_Number;
     M : in Qt4.Q_Month_Number;
     D : in Qt4.Q_Day_Number)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QDate_isValid_int_int_int (Y, M, D), 0);
   end Is_Valid;

   -------------------
   -- Long_Day_Name --
   -------------------

   function Long_Day_Name
    (Weekday : in Qt4.Day_Of_Week)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QDate_longDayName_DayOfWeek (Qt4.Strings.Internals.QString_View (Returns), Weekday);
      end return;
   end Long_Day_Name;

   ---------------------
   -- Long_Month_Name --
   ---------------------

   function Long_Month_Name
    (Month : in Qt4.Q_Month_Number)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QDate_longMonthName_int (Qt4.Strings.Internals.QString_View (Returns), Month);
      end return;
   end Long_Month_Name;

   --------------------
   -- Short_Day_Name --
   --------------------

   function Short_Day_Name
    (Weekday : in Qt4.Day_Of_Week)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QDate_shortDayName_DayOfWeek (Qt4.Strings.Internals.QString_View (Returns), Weekday);
      end return;
   end Short_Day_Name;

   ----------------------
   -- Short_Month_Name --
   ----------------------

   function Short_Month_Name
    (Month : in Qt4.Q_Month_Number)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QDate_shortMonthName_int (Qt4.Strings.Internals.QString_View (Returns), Month);
      end return;
   end Short_Month_Name;

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

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

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

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

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

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

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

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

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

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

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

   package body Internals is

   ----------------
   -- QDate_View --
   ----------------

      function QDate_View
       (Item : in Q_Date'Class)
          return QDate_Access
      is
      begin
         return Item.Object;
      end QDate_View;

      package QDate_Conversions is
        new System.Address_To_Access_Conversions
             (QDate);

   ---------------------
   -- QDateTo_Pointer --
   ---------------------

      function To_Pointer
       (Address : in System.Address)
          return QDate_Access
      is
      begin
         return
           QDate_Access
            (QDate_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   ---------------------
   -- QDateTo_Address --
   ---------------------

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

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

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

   end Internals;

end Qt4.Dates;
