------------------------------------------------------------------------------
--                                                                          --
--                 An Ada2005 binding to the Qt C++ library                 --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2007-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.                                      --
--                                                                          --
------------------------------------------------------------------------------
--  This generic package allows application to store values of the user
--  defined types in the instance of the QVariant type.
private with Interfaces.C;
with Qt4.Meta_Types;
with Qt4.Variants;

generic
   type Value_Type is private;
   Type_Name : String;

package Qt_Ada.Generic_Variants is

   Type_Id : constant Qt4.Meta_Types.Meta_Type_Type;

   function Create (Item : Value_Type) return Qt4.Variants.Q_Variant;

   function To_Value (Variant : Qt4.Variants.Q_Variant'Class)
     return Value_Type;

private

   type Value_Type_Access is access all Value_Type;
   pragma Convention (C, Value_Type_Access);

   type Constructor_Access is
     not null access function (Item : Value_Type_Access)
       return not null Value_Type_Access;
   pragma Convention (C, Constructor_Access);

   type Destructor_Access is
     not null access procedure (Item : Value_Type_Access);
   pragma Convention (C, Destructor_Access);

   function registerType_wrapper (Type_Name   : Interfaces.C.char_array;
                                  Destructor  : Destructor_Access;
                                  Constructor : Constructor_Access)
     return Qt4.Meta_Types.Meta_Type_Type;
   pragma Import (C, registerType_wrapper, "__QtAda_QMetaType_registerType");

   function Constructor (Item : Value_Type_Access)
     return not null Value_Type_Access;
   pragma Convention (C, Constructor);
   --  Allocates new object of the type Value_Type and returns its reference.
   --  Initialize an object to the value of the specified object is its
   --  reference is not null and initialize by the default value otherwise.

   procedure Destructor (Item : Value_Type_Access);
   pragma Convention (C, Destructor);

   Type_Id : constant Qt4.Meta_Types.Meta_Type_Type
     := registerType_wrapper (Interfaces.C.To_C (Type_Name),
                              Destructor'Access,
                              Constructor'Access);

end Qt_Ada.Generic_Variants;
