------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2010 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.                                      --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 3769 $ $Date: 2010-10-24 03:16:28 +0400 (Sun, 24 Oct 2010) $
------------------------------------------------------------------------------
with Qt4.String_Lists;
with Qt4.Strings;
with System;
with System.Address_To_Access_Conversions;

package body Qt4.Process_Environments is

   function initialize_QProcessEnvironment
    (Storage : System.Address)
      return Internals.QProcessEnvironment_Access;
   pragma Import (C, initialize_QProcessEnvironment, "__QtAda_inititialize_QProcessEnvironment");

   function adjust_QProcessEnvironment
    (Storage : System.Address;
     From    : Internals.QProcessEnvironment_Access)
       return Internals.QProcessEnvironment_Access;
   pragma Import (C, adjust_QProcessEnvironment, "__QtAda_adjust_QProcessEnvironment");

   procedure finalize_QProcessEnvironment (Object : Internals.QProcessEnvironment_Access);
   pragma Import (C, finalize_QProcessEnvironment, "__QtAda_finalize_QProcessEnvironment");

   procedure QProcessEnvironment_clear
    (Self : Internals.QProcessEnvironment_Access);
   pragma Import (C, QProcessEnvironment_clear, "__QtAda_QProcessEnvironment_clear");

   function QProcessEnvironment_contains_QStringCR
    (Self : Internals.QProcessEnvironment_Access;
     Name : Qt4.Strings.Internals.QString_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QProcessEnvironment_contains_QStringCR, "__QtAda_QProcessEnvironment_contains_QStringCR_Q");

   procedure QProcessEnvironment_insert_QStringCR_QStringCR
    (Self : Internals.QProcessEnvironment_Access;
     Name : Qt4.Strings.Internals.QString_Access;
     Value : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QProcessEnvironment_insert_QStringCR_QStringCR, "__QtAda_QProcessEnvironment_insert_QStringCR_QStringCR");

   function QProcessEnvironment_isEmpty
    (Self : Internals.QProcessEnvironment_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, QProcessEnvironment_isEmpty, "__QtAda_QProcessEnvironment_isEmpty_Q");

   procedure QProcessEnvironment_remove_QStringCR
    (Self : Internals.QProcessEnvironment_Access;
     Name : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QProcessEnvironment_remove_QStringCR, "__QtAda_QProcessEnvironment_remove_QStringCR");

   procedure QProcessEnvironment_toStringList
    (Returns : Qt4.String_Lists.Internals.QStringList_Access;
     Self : Internals.QProcessEnvironment_Access);
   pragma Import (C, QProcessEnvironment_toStringList, "__QtAda_QProcessEnvironment_toStringList_Q");

   procedure QProcessEnvironment_value_QStringCR_QStringCR
    (Returns : Qt4.Strings.Internals.QString_Access;
     Self : Internals.QProcessEnvironment_Access;
     Name : Qt4.Strings.Internals.QString_Access;
     Default_Value : Qt4.Strings.Internals.QString_Access);
   pragma Import (C, QProcessEnvironment_value_QStringCR_QStringCR, "__QtAda_QProcessEnvironment_value_QStringCR_QStringCR_Q");

   function eq_QProcessEnvironmentCR
    (Self : Internals.QProcessEnvironment_Access;
     S : Internals.QProcessEnvironment_Access)
       return Interfaces.C.unsigned;
   pragma Import (C, eq_QProcessEnvironmentCR, "__QtAda_QProcessEnvironment_eq_QProcessEnvironmentCR_Q");

   procedure QProcessEnvironment_systemEnvironment
    (Returns : Internals.QProcessEnvironment_Access);
   pragma Import (C, QProcessEnvironment_systemEnvironment, "__QtAda_QProcessEnvironment_systemEnvironment_S");

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

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

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

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

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

   overriding
   procedure Initialize (Self : in out Q_Process_Environment) is
      use type Internals.QProcessEnvironment_Access;

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

   -----------
   -- Clear --
   -----------

   procedure Clear
    (Self : in out Q_Process_Environment'Class)
   is
   begin
      QProcessEnvironment_clear (Self.Object);
   end Clear;

   --------------
   -- Contains --
   --------------

   function Contains
    (Self : Q_Process_Environment'Class;
     Name : Qt4.Strings.Q_String'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QProcessEnvironment_contains_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Name)), 0);
   end Contains;

   ------------
   -- Insert --
   ------------

   procedure Insert
    (Self : in out Q_Process_Environment'Class;
     Name : Qt4.Strings.Q_String'Class;
     Value : Qt4.Strings.Q_String'Class)
   is
   begin
      QProcessEnvironment_insert_QStringCR_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Name), Qt4.Strings.Internals.QString_View (Value));
   end Insert;

   --------------
   -- Is_Empty --
   --------------

   function Is_Empty
    (Self : Q_Process_Environment'Class)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (QProcessEnvironment_isEmpty (Self.Object), 0);
   end Is_Empty;

   ------------
   -- Remove --
   ------------

   procedure Remove
    (Self : in out Q_Process_Environment'Class;
     Name : Qt4.Strings.Q_String'Class)
   is
   begin
      QProcessEnvironment_remove_QStringCR (Self.Object, Qt4.Strings.Internals.QString_View (Name));
   end Remove;

   --------------------
   -- To_String_List --
   --------------------

   function To_String_List
    (Self : Q_Process_Environment'Class)
       return Qt4.String_Lists.Q_String_List
   is
   begin
      return Returns : Qt4.String_Lists.Q_String_List do
         QProcessEnvironment_toStringList (Qt4.String_Lists.Internals.QStringList_View (Returns), Self.Object);
      end return;
   end To_String_List;

   -----------
   -- Value --
   -----------

   function Value
    (Self : Q_Process_Environment'Class;
     Name : Qt4.Strings.Q_String'Class;
     Default_Value : Qt4.Strings.Q_String'Class)
       return Qt4.Strings.Q_String
   is
   begin
      return Returns : Qt4.Strings.Q_String do
         QProcessEnvironment_value_QStringCR_QStringCR (Qt4.Strings.Internals.QString_View (Returns), Self.Object, Qt4.Strings.Internals.QString_View (Name), Qt4.Strings.Internals.QString_View (Default_Value));
      end return;
   end Value;

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

   overriding function "="
    (Self : Q_Process_Environment;
     S : Q_Process_Environment)
       return Boolean
   is
   begin
      return Interfaces.C."/=" (eq_QProcessEnvironmentCR (Self.Object, S.Object), 0);
   end "=";

   ------------------------
   -- System_Environment --
   ------------------------

   function System_Environment
     return Q_Process_Environment
   is
   begin
      return Returns : Q_Process_Environment do
         QProcessEnvironment_systemEnvironment (Returns.Object);
      end return;
   end System_Environment;

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

   package body Internals is

   ------------------------------
   -- QProcessEnvironment_View --
   ------------------------------

      function QProcessEnvironment_View
       (Item : Q_Process_Environment'Class)
          return QProcessEnvironment_Access
      is
      begin
         return Item.Object;
      end QProcessEnvironment_View;

      package QProcessEnvironment_Conversions is
        new System.Address_To_Access_Conversions
             (QProcessEnvironment);

   -----------------------------------
   -- QProcessEnvironmentTo_Pointer --
   -----------------------------------

      function To_Pointer
       (Address : System.Address)
          return QProcessEnvironment_Access
      is
      begin
         return
           QProcessEnvironment_Access
            (QProcessEnvironment_Conversions.To_Pointer
            (Address));
      end To_Pointer;

   -----------------------------------
   -- QProcessEnvironmentTo_Address --
   -----------------------------------

      function To_Address
       (Pointer : QProcessEnvironment_Access)
          return System.Address
      is
      begin
         return
           QProcessEnvironment_Conversions.To_Address
            (QProcessEnvironment_Conversions.Object_Pointer
              (Pointer));
      end To_Address;

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

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

   end Internals;

end Qt4.Process_Environments;
