------------------------------------------------------------------------------
--                                                                          --
--                An Ada2005 binding to the Qt C++ framework                --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2009, 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: 3764 $ $Date: 2010-10-23 23:13:39 +0400 (Sat, 23 Oct 2010) $
------------------------------------------------------------------------------
private with Ada.Finalization;
with System.Storage_Elements;

private with Qt_Ada.Internals.Value_Class_Sizes;

package Qt4.Byte_Arrays is

   type Q_Byte_Array is tagged private;

   function Create
     return Q_Byte_Array;

   procedure Append
    (Self : in out Q_Byte_Array'Class;
     Ba : Q_Byte_Array'Class);

   function Element_At
    (Self : Q_Byte_Array'Class;
     I : Qt4.Q_Integer)
       return System.Storage_Elements.Storage_Element;

   function Capacity
    (Self : Q_Byte_Array'Class)
       return Qt4.Q_Integer;

   procedure Chop
    (Self : in out Q_Byte_Array'Class;
     N : Qt4.Q_Integer);

   procedure Clear
    (Self : in out Q_Byte_Array'Class);

   function Contains
    (Self : Q_Byte_Array'Class;
     Ba : Q_Byte_Array'Class)
       return Boolean;

   function Count
    (Self : Q_Byte_Array'Class;
     Ba : Q_Byte_Array'Class)
       return Qt4.Q_Integer;

   function Count
    (Self : Q_Byte_Array'Class)
       return Qt4.Q_Integer;

   function Ends_With
    (Self : Q_Byte_Array'Class;
     Ba : Q_Byte_Array'Class)
       return Boolean;

   function Index_Of
    (Self : Q_Byte_Array'Class;
     Ba : Q_Byte_Array'Class;
     From : Qt4.Q_Integer
       := 0)
       return Qt4.Q_Integer;

   procedure Insert
    (Self : in out Q_Byte_Array'Class;
     Index : Qt4.Q_Integer;
     Ba : Q_Byte_Array'Class);

   function Is_Empty
    (Self : Q_Byte_Array'Class)
       return Boolean;

   function Is_Null
    (Self : Q_Byte_Array'Class)
       return Boolean;

   function Last_Index_Of
    (Self : Q_Byte_Array'Class;
     Ba : Q_Byte_Array'Class;
     From : Qt4.Q_Integer
       := -1)
       return Qt4.Q_Integer;

   function Left
    (Self : Q_Byte_Array'Class;
     Length : Qt4.Q_Integer)
       return Q_Byte_Array;

   function Length
    (Self : Q_Byte_Array'Class)
       return Qt4.Q_Integer;

   function Mid
    (Self : Q_Byte_Array'Class;
     Pos : Qt4.Q_Integer;
     Length : Qt4.Q_Integer
       := -1)
       return Q_Byte_Array;

   procedure Prepend
    (Self : in out Q_Byte_Array'Class;
     Ba : Q_Byte_Array'Class);

   procedure Remove
    (Self : in out Q_Byte_Array'Class;
     Pos : Qt4.Q_Integer;
     Len : Qt4.Q_Integer);

   function Repeated
    (Self : Q_Byte_Array'Class;
     Times : Qt4.Q_Integer)
       return Q_Byte_Array;

   procedure Replace
    (Self : in out Q_Byte_Array'Class;
     Pos : Qt4.Q_Integer;
     Len : Qt4.Q_Integer;
     After : Q_Byte_Array'Class);

   procedure Replace
    (Self : in out Q_Byte_Array'Class;
     Before : Q_Byte_Array'Class;
     After : Q_Byte_Array'Class);

   procedure Reserve
    (Self : in out Q_Byte_Array'Class;
     Size : Qt4.Q_Integer);

   procedure Resize
    (Self : in out Q_Byte_Array'Class;
     Size : Qt4.Q_Integer);

   function Right
    (Self : Q_Byte_Array'Class;
     Length : Qt4.Q_Integer)
       return Q_Byte_Array;

   function Simplified
    (Self : Q_Byte_Array'Class)
       return Q_Byte_Array;

   function Size
    (Self : Q_Byte_Array'Class)
       return Qt4.Q_Integer;

   procedure Squeeze
    (Self : in out Q_Byte_Array'Class);

   function Starts_With
    (Self : Q_Byte_Array'Class;
     Ba : Q_Byte_Array'Class)
       return Boolean;

   function To_Base_64
    (Self : Q_Byte_Array'Class)
       return Q_Byte_Array;

   function To_Hex
    (Self : Q_Byte_Array'Class)
       return Q_Byte_Array;

   procedure Trimmed
    (Self : in out Q_Byte_Array'Class);

   procedure Truncate
    (Self : in out Q_Byte_Array'Class;
     Pos : Qt4.Q_Integer);

   function From_Base_64
    (Base_64 : Q_Byte_Array'Class)
       return Q_Byte_Array;

   function From_Hex
    (Hex_Encoded : Q_Byte_Array'Class)
       return Q_Byte_Array;

   overriding
   function "="
    (Self : Q_Byte_Array;
     S : Q_Byte_Array)
       return Boolean;

   function "<"
    (Self : Q_Byte_Array;
     S : Q_Byte_Array)
       return Boolean;

   function ">"
    (Self : Q_Byte_Array;
     S : Q_Byte_Array)
       return Boolean;

   function "<="
    (Self : Q_Byte_Array;
     S : Q_Byte_Array)
       return Boolean;

   function ">="
    (Self : Q_Byte_Array;
     S : Q_Byte_Array)
       return Boolean;

   package Internals is

      type QByteArray is private;

      type QByteArray_Access is access all QByteArray;
      pragma Convention (C, QByteArray_Access);

      function QByteArray_View
       (Item : Q_Byte_Array'Class)
          return QByteArray_Access;
      pragma Inline (QByteArray_View);

      function To_Pointer
       (Address : System.Address)
          return QByteArray_Access;
      pragma Inline (To_Pointer);

      function To_Address
       (Pointer : QByteArray_Access)
          return System.Address;
      pragma Inline (To_Address);

      function Create_Wrapper
       (Item : Internals.QByteArray_Access)
          return Q_Byte_Array;

   private

      type QByteArray is record
         Placeholder : Interfaces.C.char_array (1 .. Qt_Ada.Internals.Value_Class_Sizes.QByteArray_C_Size_Of);
      end record;
      pragma Convention (C, QByteArray);

   end Internals;

private

   type Q_Byte_Array is new Ada.Finalization.Controlled with record
      Storage : aliased Internals.QByteArray;
      Object  : Internals.QByteArray_Access := null;
      Wrapper : Boolean := False;
   end record;

   overriding
   procedure Adjust (Self : in out Q_Byte_Array);

   overriding
   procedure Finalize (Self : in out Q_Byte_Array);

   overriding
   procedure Initialize (Self : in out Q_Byte_Array);

end Qt4.Byte_Arrays;
