pragma Style_Checks ("NM32766");

---------------------------------------------------
--  This file has been generated automatically from
--  /wrkdirs/usr/ports/net/polyorb/work/polyorb-2.9.0/idls/cos/time/TimeBase.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 Ada.Unchecked_Conversion;
with Ada.Unchecked_Deallocation;
with PolyORB.Utils.Strings;
with PolyORB.Utils.Strings.Lists;
with PolyORB.Initialization;

package body TimeBase.Helper is

   
   package body Internals is

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

      function Wrap
        (X : access TimeBase.TimeT)
        return PolyORB.Any.Content'Class
      is
      begin
         return CORBA.Wrap
           (CORBA.Unsigned_Long_Long
              (X.all)'Unrestricted_Access);
      end Wrap;

      TimeT_Initialized : PolyORB.Std.Boolean :=
        False;

      ----------------------
      -- Initialize_TimeT --
      ----------------------

      procedure Initialize_TimeT is
         Name_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("TimeT");
         Id_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("IDL:omg.org/TimeBase/TimeT:1.0");
      begin
         if not TimeT_Initialized
         then
            TimeT_Initialized :=
              True;
            TimeBase.Helper.TC_TimeT :=
              CORBA.TypeCode.Internals.Build_Alias_TC
                 (Name => Name_Ü,
                  Id => Id_Ü,
                  Parent => CORBA.TC_Unsigned_Long_Long);
            CORBA.TypeCode.Internals.Disable_Reference_Counting
              (TimeBase.Helper.TC_TimeT);
         end if;
      end Initialize_TimeT;

      InaccuracyT_Initialized : PolyORB.Std.Boolean :=
        False;

      ----------------------------
      -- Initialize_InaccuracyT --
      ----------------------------

      procedure Initialize_InaccuracyT is
         Name_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("InaccuracyT");
         Id_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("IDL:omg.org/TimeBase/InaccuracyT:1.0");
      begin
         if not InaccuracyT_Initialized
         then
            InaccuracyT_Initialized :=
              True;
            TimeBase.Helper.Internals.Initialize_TimeT;
            TimeBase.Helper.TC_InaccuracyT :=
              CORBA.TypeCode.Internals.Build_Alias_TC
                 (Name => Name_Ü,
                  Id => Id_Ü,
                  Parent => TimeBase.Helper.TC_TimeT);
            CORBA.TypeCode.Internals.Disable_Reference_Counting
              (TimeBase.Helper.TC_InaccuracyT);
         end if;
      end Initialize_InaccuracyT;

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

      function Wrap
        (X : access TimeBase.TdfT)
        return PolyORB.Any.Content'Class
      is
      begin
         return CORBA.Wrap
           (CORBA.Short
              (X.all)'Unrestricted_Access);
      end Wrap;

      TdfT_Initialized : PolyORB.Std.Boolean :=
        False;

      ---------------------
      -- Initialize_TdfT --
      ---------------------

      procedure Initialize_TdfT is
         Name_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("TdfT");
         Id_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("IDL:omg.org/TimeBase/TdfT:1.0");
      begin
         if not TdfT_Initialized
         then
            TdfT_Initialized :=
              True;
            TimeBase.Helper.TC_TdfT :=
              CORBA.TypeCode.Internals.Build_Alias_TC
                 (Name => Name_Ü,
                  Id => Id_Ü,
                  Parent => CORBA.TC_Short);
            CORBA.TypeCode.Internals.Disable_Reference_Counting
              (TimeBase.Helper.TC_TdfT);
         end if;
      end Initialize_TdfT;

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

      function Get_Aggregate_Element
        (Acc : not null access Content_Ü_UtcT;
         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.Wrap
                 (CORBA.Unsigned_Long_Long
                    (Acc.V.time)'Unrestricted_Access);
            when 1 =>
               return CORBA.Wrap
                 (Acc.V.inacclo'Unrestricted_Access);
            when 2 =>
               return CORBA.Wrap
                 (Acc.V.inacchi'Unrestricted_Access);
            when 3 =>
               return CORBA.Wrap
                 (CORBA.Short
                    (Acc.V.tdf)'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_Ü_UtcT)
        return PolyORB.Types.Unsigned_Long
      is
         pragma Unreferenced (Acc);
      begin
         return 4;
      end Get_Aggregate_Count;

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

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

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

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

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

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

      function Clone
        (Acc : Content_Ü_UtcT;
         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_Ü_UtcT)
            then
               return null;
            end if;
            Target :=
              Into;
            Content_Ü_UtcT
              (Target.all).V.all :=
              Acc.V.all;
         else
            Target :=
              new Content_Ü_UtcT;
            Content_Ü_UtcT
              (Target.all).V :=
              new TimeBase.UtcT'
                 (Acc.V.all);
         end if;
         return Target;
      end Clone;

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

      procedure Finalize_Value
        (Acc : in out Content_Ü_UtcT)
      is
         procedure Free
           is new Ada.Unchecked_Deallocation
              (TimeBase.UtcT,
               Ptr_Ü_UtcT);

      begin
         Free
           (Acc.V);
      end Finalize_Value;

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

      function Wrap
        (X : access TimeBase.UtcT)
        return PolyORB.Any.Content'Class
      is
      begin
         return Content_Ü_UtcT'
           (PolyORB.Any.Aggregate_Content with
            V => Ptr_Ü_UtcT
              (X));
      end Wrap;

      UtcT_Initialized : PolyORB.Std.Boolean :=
        False;

      ---------------------
      -- Initialize_UtcT --
      ---------------------

      procedure Initialize_UtcT is
         Name_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("UtcT");
         Id_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("IDL:omg.org/TimeBase/UtcT:1.0");
         Argument_Name_Ü_time : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("time");
         Argument_Name_Ü_inacclo : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("inacclo");
         Argument_Name_Ü_inacchi : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("inacchi");
         Argument_Name_Ü_tdf : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("tdf");
      begin
         if not UtcT_Initialized
         then
            UtcT_Initialized :=
              True;
            TimeBase.Helper.TC_UtcT :=
              CORBA.TypeCode.Internals.To_CORBA_Object
                 (PolyORB.Any.TypeCode.Tcf_Struct);
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (Name_Ü));
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (Id_Ü));
            TimeBase.Helper.Internals.Initialize_TimeT;
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (TimeBase.Helper.TC_TimeT));
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (Argument_Name_Ü_time));
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (CORBA.TC_Unsigned_Long));
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (Argument_Name_Ü_inacclo));
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (CORBA.TC_Unsigned_Short));
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (Argument_Name_Ü_inacchi));
            TimeBase.Helper.Internals.Initialize_TdfT;
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (TimeBase.Helper.TC_TdfT));
            CORBA.Internals.Add_Parameter
              (TC_UtcT,
               CORBA.To_Any
                 (Argument_Name_Ü_tdf));
            CORBA.TypeCode.Internals.Disable_Reference_Counting
              (TimeBase.Helper.TC_UtcT);
         end if;
      end Initialize_UtcT;

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

      function Get_Aggregate_Element
        (Acc : not null access Content_Ü_IntervalT;
         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.Wrap
                 (CORBA.Unsigned_Long_Long
                    (Acc.V.lower_bound)'Unrestricted_Access);
            when 1 =>
               return CORBA.Wrap
                 (CORBA.Unsigned_Long_Long
                    (Acc.V.upper_bound)'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_Ü_IntervalT)
        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_Ü_IntervalT;
         Count : PolyORB.Types.Unsigned_Long)
      is
      begin
         null;
      end Set_Aggregate_Count;

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

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

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

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

      function Clone
        (Acc : Content_Ü_IntervalT;
         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_Ü_IntervalT)
            then
               return null;
            end if;
            Target :=
              Into;
            Content_Ü_IntervalT
              (Target.all).V.all :=
              Acc.V.all;
         else
            Target :=
              new Content_Ü_IntervalT;
            Content_Ü_IntervalT
              (Target.all).V :=
              new TimeBase.IntervalT'
                 (Acc.V.all);
         end if;
         return Target;
      end Clone;

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

      procedure Finalize_Value
        (Acc : in out Content_Ü_IntervalT)
      is
         procedure Free
           is new Ada.Unchecked_Deallocation
              (TimeBase.IntervalT,
               Ptr_Ü_IntervalT);

      begin
         Free
           (Acc.V);
      end Finalize_Value;

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

      function Wrap
        (X : access TimeBase.IntervalT)
        return PolyORB.Any.Content'Class
      is
      begin
         return Content_Ü_IntervalT'
           (PolyORB.Any.Aggregate_Content with
            V => Ptr_Ü_IntervalT
              (X));
      end Wrap;

      IntervalT_Initialized : PolyORB.Std.Boolean :=
        False;

      --------------------------
      -- Initialize_IntervalT --
      --------------------------

      procedure Initialize_IntervalT is
         Name_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("IntervalT");
         Id_Ü : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("IDL:omg.org/TimeBase/IntervalT:1.0");
         Argument_Name_Ü_lower_bound : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("lower_bound");
         Argument_Name_Ü_upper_bound : constant CORBA.String :=
           CORBA.To_CORBA_String
              ("upper_bound");
      begin
         if not IntervalT_Initialized
         then
            IntervalT_Initialized :=
              True;
            TimeBase.Helper.TC_IntervalT :=
              CORBA.TypeCode.Internals.To_CORBA_Object
                 (PolyORB.Any.TypeCode.Tcf_Struct);
            CORBA.Internals.Add_Parameter
              (TC_IntervalT,
               CORBA.To_Any
                 (Name_Ü));
            CORBA.Internals.Add_Parameter
              (TC_IntervalT,
               CORBA.To_Any
                 (Id_Ü));
            TimeBase.Helper.Internals.Initialize_TimeT;
            CORBA.Internals.Add_Parameter
              (TC_IntervalT,
               CORBA.To_Any
                 (TimeBase.Helper.TC_TimeT));
            CORBA.Internals.Add_Parameter
              (TC_IntervalT,
               CORBA.To_Any
                 (Argument_Name_Ü_lower_bound));
            TimeBase.Helper.Internals.Initialize_TimeT;
            CORBA.Internals.Add_Parameter
              (TC_IntervalT,
               CORBA.To_Any
                 (TimeBase.Helper.TC_TimeT));
            CORBA.Internals.Add_Parameter
              (TC_IntervalT,
               CORBA.To_Any
                 (Argument_Name_Ü_upper_bound));
            CORBA.TypeCode.Internals.Disable_Reference_Counting
              (TimeBase.Helper.TC_IntervalT);
         end if;
      end Initialize_IntervalT;

   end Internals;

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

   function From_Any
     (Item : CORBA.Any)
     return TimeBase.TimeT
   is
      Result : constant CORBA.Unsigned_Long_Long :=
        CORBA.From_Any
           (Item);
   begin
      return TimeBase.TimeT
        (Result);
   end From_Any;

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

   function To_Any
     (Item : TimeBase.TimeT)
     return CORBA.Any
   is
      Result : CORBA.Any :=
        CORBA.To_Any
           (CORBA.Unsigned_Long_Long
              (Item));
   begin
      CORBA.Internals.Set_Type
        (Result,
         TC_TimeT);
      return Result;
   end To_Any;

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

   function From_Any
     (Item : CORBA.Any)
     return TimeBase.InaccuracyT
   is
      Result : constant TimeBase.TimeT :=
        TimeBase.Helper.From_Any
           (Item);
   begin
      return TimeBase.InaccuracyT
        (Result);
   end From_Any;

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

   function To_Any
     (Item : TimeBase.InaccuracyT)
     return CORBA.Any
   is
      Result : CORBA.Any :=
        TimeBase.Helper.To_Any
           (TimeBase.TimeT
              (Item));
   begin
      CORBA.Internals.Set_Type
        (Result,
         TC_InaccuracyT);
      return Result;
   end To_Any;

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

   function From_Any
     (Item : CORBA.Any)
     return TimeBase.TdfT
   is
      Result : constant CORBA.Short :=
        CORBA.From_Any
           (Item);
   begin
      return TimeBase.TdfT
        (Result);
   end From_Any;

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

   function To_Any
     (Item : TimeBase.TdfT)
     return CORBA.Any
   is
      Result : CORBA.Any :=
        CORBA.To_Any
           (CORBA.Short
              (Item));
   begin
      CORBA.Internals.Set_Type
        (Result,
         TC_TdfT);
      return Result;
   end To_Any;

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

   function From_Any
     (Item : CORBA.Any)
     return TimeBase.UtcT
   is
   begin
      return (time => TimeBase.Helper.From_Any
        (CORBA.Internals.Get_Aggregate_Element
           (Item,
            TimeBase.Helper.TC_TimeT,
            0)),
      inacclo => CORBA.From_Any
        (CORBA.Internals.Get_Aggregate_Element
           (Item,
            CORBA.TC_Unsigned_Long,
            1)),
      inacchi => CORBA.From_Any
        (CORBA.Internals.Get_Aggregate_Element
           (Item,
            CORBA.TC_Unsigned_Short,
            2)),
      tdf => TimeBase.Helper.From_Any
        (CORBA.Internals.Get_Aggregate_Element
           (Item,
            TimeBase.Helper.TC_TdfT,
            3)));
   end From_Any;

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

   function To_Any
     (Item : TimeBase.UtcT)
     return CORBA.Any
   is
      Result : CORBA.Any :=
        CORBA.Internals.Get_Empty_Any_Aggregate
           (TC_UtcT);
   begin
      CORBA.Internals.Add_Aggregate_Element
        (Result,
         TimeBase.Helper.To_Any
           (Item.time));
      CORBA.Internals.Add_Aggregate_Element
        (Result,
         CORBA.To_Any
           (Item.inacclo));
      CORBA.Internals.Add_Aggregate_Element
        (Result,
         CORBA.To_Any
           (Item.inacchi));
      CORBA.Internals.Add_Aggregate_Element
        (Result,
         TimeBase.Helper.To_Any
           (Item.tdf));
      return Result;
   end To_Any;

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

   function From_Any
     (Item : CORBA.Any)
     return TimeBase.IntervalT
   is
   begin
      return (lower_bound => TimeBase.Helper.From_Any
        (CORBA.Internals.Get_Aggregate_Element
           (Item,
            TimeBase.Helper.TC_TimeT,
            0)),
      upper_bound => TimeBase.Helper.From_Any
        (CORBA.Internals.Get_Aggregate_Element
           (Item,
            TimeBase.Helper.TC_TimeT,
            1)));
   end From_Any;

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

   function To_Any
     (Item : TimeBase.IntervalT)
     return CORBA.Any
   is
      Result : CORBA.Any :=
        CORBA.Internals.Get_Empty_Any_Aggregate
           (TC_IntervalT);
   begin
      CORBA.Internals.Add_Aggregate_Element
        (Result,
         TimeBase.Helper.To_Any
           (Item.lower_bound));
      CORBA.Internals.Add_Aggregate_Element
        (Result,
         TimeBase.Helper.To_Any
           (Item.upper_bound));
      return Result;
   end To_Any;

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

   procedure Deferred_Initialization is
   begin
      TimeBase.Helper.Internals.Initialize_TimeT;
      TimeBase.Helper.Internals.Initialize_InaccuracyT;
      TimeBase.Helper.Internals.Initialize_TdfT;
      TimeBase.Helper.Internals.Initialize_UtcT;
      TimeBase.Helper.Internals.Initialize_IntervalT;
   end Deferred_Initialization;

begin
   declare
      use PolyORB.Utils.Strings;
      use PolyORB.Utils.Strings.Lists;
   begin
      PolyORB.Initialization.Register_Module
        (PolyORB.Initialization.Module_Info'
           (Name => +"TimeBase.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 TimeBase.Helper;
