--------------------------------------------- ----------------------------------- -- -- -- OCARINA COMPONENTS -- -- -- -- O C A R I N A . D I A . P A R S E R . C O R E -- -- -- -- B o d y -- -- -- -- Copyright (C) 2005-2006, GET-Telecom Paris. -- -- -- -- Ocarina is free software; you can redistribute it and/or modify -- -- it under terms of the GNU General Public License as published by the -- -- Free Software Foundation; either version 2, or (at your option) any -- -- later version. Ocarina is distributed in the hope that it will be -- -- useful, but WITHOUT 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 Ocarina; see file COPYING. -- -- If not, write to the Free Software Foundation, 51 Franklin Street, Fifth -- -- Floor, Boston, MA 02111-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. -- -- -- -- Ocarina is maintained by the Ocarina team -- -- (ocarina-users@listes.enst.fr) -- -- -- ------------------------------------------------------------------------------ with Ada.Text_IO; use Ada.Text_IO; with DOM.Core.Nodes; package body Ocarina.Dia.Parser.Core is -- List : Append procedure Append (List : in out Node_List; N : Node) is Old : Node_Array_Access := List.Items; begin if Old = null or else Old'Last = List.Last then List.Items := new Node_Array (0 .. List.Last + 5); if Old /= null then List.Items (0 .. List.Last) := Old.all; Free (Old); end if; end if; List.Last := List.Last + 1; List.Items (List.Last) := N; end Append; -- List : Remove procedure Remove (List : in out Node_List; N : Node) is begin if List.Items = null or else List.Last = 0 then Free (List.Items); List.Last := -1; else for J in 0 .. List.Last loop if List.Items (J) = N then List.Items (J .. List.Last - 1) := List.Items (J + 1 .. List.Last); List.Last := List.Last - 1; return; end if; end loop; end if; end Remove; -- Returns the number of objects in a list function Count_Objects (NL : Node_List) return Integer is N : Node; Compteur : Integer := 0; begin if NL.Items = null or else NL.Last = 0 then null; else for J in 0 .. NL.Last loop N := NL.Items (J); case N.Node_Type_Arg is when AADLObject_Type => Compteur := Compteur + 1; when others => null; end case; end loop; end if; return Compteur; end Count_Objects; -- Looks for a specific attribute and returns its value, or raises -- Missing_Attribute function Get_Required_Attribute (Attrs : DOM.Core.Named_Node_Map; N : String) return String is use DOM.Core; A : constant DOM.Core.Node := DOM.Core.Nodes.Get_Named_Item (Attrs, N); begin if A /= null then return DOM.Core.Nodes.Node_Value (A); else Put_Line (N); raise Missing_Attribute; end if; end Get_Required_Attribute; -- Looks for a specific child node and returns the first element -- with that name procedure Get_Required_Child (Children : DOM.Core.Node_List; S : String; Index : in out Natural; E : out DOM.Core.Node) is use DOM.Core; Found : Integer := -1; begin for I in Index .. (DOM.Core.Nodes.Length (Children) - 1) loop declare Item : constant DOM.Core.Node := DOM.Core.Nodes.Item (Children, I); begin if DOM.Core.Nodes.Node_Name (Item) = S then E := Item; Index := I; Found := 0; exit; end if; end; end loop; if Found /= 0 then Put_Line (S); raise Missing_Child; end if; end Get_Required_Child; end Ocarina.Dia.Parser.Core;