pragma Style_Checks ("NM32766");

---------------------------------------------------
--  This file has been generated automatically from
--  /wrkdirs/usr/ports/net/polyorb/work/polyorb-2.9.0/idls/CORBA_IDL/orb.idl
--  by IAC (IDL to Ada Compiler) 2.9.0 (rev. unknown).
---------------------------------------------------
--  NOTE: If you modify this file by hand, your
--  changes will be lost when you re-run the
--  IDL to Ada compiler.
---------------------------------------------------

with PolyORB.Std;
with CORBA.Repository_Root.Helper;
with Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with CORBA.Object.Helper;
with PolyORB.Utils.Strings;
with PolyORB.Utils.Strings.Lists;
with PolyORB.Initialization;

package body CORBA.Repository_Root.Contained.Helper is

   
   package body Internals is

      Contained_Initialized : PolyORB.Std.Boolean :=
        False;

      --------------------------
      -- Initialize_Contained --
      --------------------------

      procedure Initialize_Contained is
         Name_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("Contained");
         Id_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("IDL:omg.org/CORBA/Contained:1.0");
      begin
         if not Contained_Initialized
         then
            Contained_Initialized :=
              True;
            CORBA.Repository_Root.Contained.Helper.TC_Contained :=
              CORBA.TypeCode.Internals.To_CORBA_Object
                 (PolyORB.Any.TypeCode.Tcf_Object);
            CORBA.Internals.Add_Parameter
              (TC_Contained,
               CORBA.To_Any
                 (Name_Ü));
            CORBA.Internals.Add_Parameter
              (TC_Contained,
               CORBA.To_Any
                 (Id_Ü));
            CORBA.TypeCode.Internals.Disable_Reference_Counting
              (CORBA.Repository_Root.Contained.Helper.TC_Contained);
         end if;
      end Initialize_Contained;

      ---------------------------
      -- Get_Aggregate_Element --
      ---------------------------

      function Get_Aggregate_Element
        (Acc : not null access Content_Ü_Description;
         Tc : PolyORB.Any.TypeCode.Object_Ptr;
         Index : PolyORB.Types.Unsigned_Long;
         Mech : not null access PolyORB.Any.Mechanism)
        return PolyORB.Any.Content'Class
      is
         use type PolyORB.Types.Unsigned_Long;
         use type PolyORB.Any.Mechanism;
         pragma Suppress (Validity_Check);
         pragma Unreferenced (Tc);
      begin
         Mech.all :=
           PolyORB.Any.By_Reference;
         case Index is
            when 0 =>
               return CORBA.Repository_Root.Helper.Internals.Wrap
                 (Acc.V.kind'Unrestricted_Access);
            when 1 =>
               return CORBA.Wrap
                 (Acc.V.value'Unrestricted_Access);
            pragma Warnings (Off);
            when others =>
               raise Constraint_Error;
            pragma Warnings (On);

         end case;
      end Get_Aggregate_Element;

      -------------------------
      -- Get_Aggregate_Count --
      -------------------------

      function Get_Aggregate_Count
        (Acc : Content_Ü_Description)
        return PolyORB.Types.Unsigned_Long
      is
         pragma Unreferenced (Acc);
      begin
         return 2;
      end Get_Aggregate_Count;

      -------------------------
      -- Set_Aggregate_Count --
      -------------------------

      procedure Set_Aggregate_Count
        (Acc : in out Content_Ü_Description;
         Count : PolyORB.Types.Unsigned_Long)
      is
      begin
         null;
      end Set_Aggregate_Count;

      ---------------------
      -- Unchecked_Get_V --
      ---------------------

      function Unchecked_Get_V
        (Acc : not null access Content_Ü_Description)
        return PolyORB.Types.Address
      is
         function To_Address
           is new Ada.Unchecked_Conversion
              (Ptr_Ü_Description,
               PolyORB.Types.Address);

      begin
         return To_Address
           (Acc.V);
      end Unchecked_Get_V;

      -----------
      -- Clone --
      -----------

      function Clone
        (Acc : Content_Ü_Description;
         Into : PolyORB.Any.Content_Ptr := null)
        return PolyORB.Any.Content_Ptr
      is
         use type PolyORB.Any.Content_Ptr;
         Target : PolyORB.Any.Content_Ptr;
      begin
         if (Into
            /= null)
         then
            if (Into.all
               not in Content_Ü_Description)
            then
               return null;
            end if;
            Target :=
              Into;
            Content_Ü_Description
              (Target.all).V.all :=
              Acc.V.all;
         else
            Target :=
              new Content_Ü_Description;
            Content_Ü_Description
              (Target.all).V :=
              new CORBA.Repository_Root.Contained.Description'
                 (Acc.V.all);
         end if;
         return Target;
      end Clone;

      --------------------
      -- Finalize_Value --
      --------------------

      procedure Finalize_Value
        (Acc : in out Content_Ü_Description)
      is
         procedure Free
           is new Ada.Unchecked_Deallocation
              (CORBA.Repository_Root.Contained.Description,
               Ptr_Ü_Description);

      begin
         Free
           (Acc.V);
      end Finalize_Value;

      ----------
      -- Wrap --
      ----------

      function Wrap
        (X : access CORBA.Repository_Root.Contained.Description)
        return PolyORB.Any.Content'Class
      is
      begin
         return Content_Ü_Description'
           (PolyORB.Any.Aggregate_Content with
            V => Ptr_Ü_Description
              (X));
      end Wrap;

      Description_Initialized : PolyORB.Std.Boolean :=
        False;

      ----------------------------
      -- Initialize_Description --
      ----------------------------

      procedure Initialize_Description is
         Name_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("Description");
         Id_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("IDL:omg.org/CORBA/Contained/Description:1.0");
         Argument_Name_Ü_kind : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("kind");
         Argument_Name_Ü_value : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("value");
      begin
         if not Description_Initialized
         then
            Description_Initialized :=
              True;
            CORBA.Repository_Root.Contained.Helper.TC_Description :=
              CORBA.TypeCode.Internals.To_CORBA_Object
                 (PolyORB.Any.TypeCode.Tcf_Struct);
            CORBA.Internals.Add_Parameter
              (TC_Description,
               CORBA.To_Any
                 (Name_Ü));
            CORBA.Internals.Add_Parameter
              (TC_Description,
               CORBA.To_Any
                 (Id_Ü));
            CORBA.Repository_Root.Helper.Internals.Initialize_DefinitionKind;
            CORBA.Internals.Add_Parameter
              (TC_Description,
               CORBA.To_Any
                 (CORBA.Repository_Root.Helper.TC_DefinitionKind));
            CORBA.Internals.Add_Parameter
              (TC_Description,
               CORBA.To_Any
                 (Argument_Name_Ü_kind));
            CORBA.Internals.Add_Parameter
              (TC_Description,
               CORBA.To_Any
                 (CORBA.TC_Any));
            CORBA.Internals.Add_Parameter
              (TC_Description,
               CORBA.To_Any
                 (Argument_Name_Ü_value));
            CORBA.TypeCode.Internals.Disable_Reference_Counting
              (CORBA.Repository_Root.Contained.Helper.TC_Description);
         end if;
      end Initialize_Description;

   end Internals;

   --------------
   -- From_Any --
   --------------

   function From_Any
     (Item : CORBA.Any)
     return CORBA.Repository_Root.Contained.Ref
   is
   begin
      return To_Ref
        (CORBA.Object.Helper.From_Any
           (Item));
   end From_Any;

   ------------
   -- To_Any --
   ------------

   function To_Any
     (Item : CORBA.Repository_Root.Contained.Ref)
     return CORBA.Any
   is
      A : CORBA.Any :=
        CORBA.Object.Helper.To_Any
           (CORBA.Object.Ref
              (Item));
   begin
      CORBA.Internals.Set_Type
        (A,
         TC_Contained);
      return A;
   end To_Any;

   ----------------------
   -- Unchecked_To_Ref --
   ----------------------

   function Unchecked_To_Ref
     (The_Ref : CORBA.Object.Ref'Class)
     return CORBA.Repository_Root.Contained.Ref
   is
      Result : CORBA.Repository_Root.Contained.Ref;
   begin
      Set
        (Result,
         CORBA.Object.Object_Of
           (The_Ref));
      return Result;
   end Unchecked_To_Ref;

   ------------
   -- To_Ref --
   ------------

   function To_Ref
     (The_Ref : CORBA.Object.Ref'Class)
     return CORBA.Repository_Root.Contained.Ref
   is
   begin
      if (CORBA.Object.Is_Nil
        (The_Ref)
         or else CORBA.Object.Is_A
           (The_Ref,
            Repository_Id))
      then
         return Unchecked_To_Ref
           (The_Ref);
      end if;
      CORBA.Raise_Bad_Param
        (CORBA.Default_Sys_Member);
   end To_Ref;

   --------------
   -- From_Any --
   --------------

   function From_Any
     (Item : CORBA.Any)
     return CORBA.Repository_Root.Contained.Description
   is
   begin
      return (kind => CORBA.Repository_Root.Helper.From_Any
        (CORBA.Internals.Get_Aggregate_Element
           (Item,
            CORBA.Repository_Root.Helper.TC_DefinitionKind,
            0)),
      value => CORBA.From_Any
        (CORBA.Internals.Get_Aggregate_Element
           (Item,
            CORBA.TC_Any,
            1)));
   end From_Any;

   ------------
   -- To_Any --
   ------------

   function To_Any
     (Item : CORBA.Repository_Root.Contained.Description)
     return CORBA.Any
   is
      Result : CORBA.Any :=
        CORBA.Internals.Get_Empty_Any_Aggregate
           (TC_Description);
   begin
      CORBA.Internals.Add_Aggregate_Element
        (Result,
         CORBA.Repository_Root.Helper.To_Any
           (Item.kind));
      CORBA.Internals.Add_Aggregate_Element
        (Result,
         CORBA.To_Any
           (Item.value));
      return Result;
   end To_Any;

   -----------------------------
   -- Deferred_Initialization --
   -----------------------------

   procedure Deferred_Initialization is
   begin
      CORBA.Repository_Root.Contained.Helper.Internals.Initialize_Contained;
      CORBA.Repository_Root.Contained.Helper.Internals.Initialize_Description;
   end Deferred_Initialization;

begin
   declare
      use PolyORB.Utils.Strings;
      use PolyORB.Utils.Strings.Lists;
   begin
      PolyORB.Initialization.Register_Module
        (PolyORB.Initialization.Module_Info'
           (Name => +"CORBA.Repository_Root.Contained.Helper",
            Conflicts => PolyORB.Utils.Strings.Lists.Empty,
            Depends => +"any"
               & "corba",
            Provides => PolyORB.Utils.Strings.Lists.Empty,
            Implicit => False,
            Init => Deferred_Initialization'Access,
            Shutdown => null));
   end;
end CORBA.Repository_Root.Contained.Helper;
