with GNATCOM.IInterface;

with GNATCOM.Errors;

package body MSHTML.IHTMLStorage_Interface is

   procedure Initialize (This : in out IHTMLStorage_Type) is
   begin
      Set_IID (This, IID_IHTMLStorage);
   end Initialize;

   function Pointer (This : IHTMLStorage_Type)
     return Pointer_To_IHTMLStorage
   is
   begin
      return To_Pointer_To_IHTMLStorage (Address (This));
   end Pointer;

   procedure Attach (This    : in out IHTMLStorage_Type;
                     Pointer : in     Pointer_To_IHTMLStorage)
   is
   begin
      Attach (This, GNATCOM.IInterface.To_Pointer_To_IUnknown
              (Pointer.all'Address));
   end Attach;

   function Get_length
     (This : IHTMLStorage_Type)
     return Interfaces.C.long
   is
       RetVal : aliased Interfaces.C.long;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_length
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_length;

   function Get_remainingSpace
     (This : IHTMLStorage_Type)
     return Interfaces.C.long
   is
       RetVal : aliased Interfaces.C.long;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.Get_remainingSpace
         (Pointer (This),
          RetVal'Unchecked_Access));

      return RetVal;
   end Get_remainingSpace;

   function key
     (This                     : IHTMLStorage_Type;
      lIndex                   : Interfaces.C.long)
     return GNATCOM.Types.BSTR
   is
       RetVal : aliased GNATCOM.Types.BSTR;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.key
         (Pointer (This),
          lIndex,
          RetVal'Unchecked_Access));

      return RetVal;
   end key;

   function getItem
     (This                     : IHTMLStorage_Type;
      bstrKey                  : GNATCOM.Types.BSTR;
      Free                     : Boolean := True)
     return GNATCOM.Types.VARIANT
   is
       RetVal : aliased GNATCOM.Types.VARIANT;
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.getItem
         (Pointer (This),
          bstrKey,
          RetVal'Unchecked_Access));

      if Free then
               GNATCOM.IInterface.Free (bstrKey);
      
      end if;

      return RetVal;
   end getItem;

   procedure setItem
     (This      : IHTMLStorage_Type;
      bstrKey   : GNATCOM.Types.BSTR;
      bstrValue : GNATCOM.Types.BSTR;
      Free      : Boolean := True)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.setItem
         (Pointer (This),
          bstrKey,
          bstrValue));

      if Free then
               GNATCOM.IInterface.Free (bstrKey);
               GNATCOM.IInterface.Free (bstrValue);
      
      end if;

   end setItem;

   procedure removeItem
     (This    : IHTMLStorage_Type;
      bstrKey : GNATCOM.Types.BSTR;
      Free    : Boolean := True)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.removeItem
         (Pointer (This),
          bstrKey));

      if Free then
               GNATCOM.IInterface.Free (bstrKey);
      
      end if;

   end removeItem;

   procedure clear
     (This : IHTMLStorage_Type)
   is
   begin
      GNATCOM.Errors.Error_Check
        (Pointer (This).Vtbl.clear
         (Pointer (This)));

   end clear;

end MSHTML.IHTMLStorage_Interface;

