1------------------------------------------------------------------------------
2--                                                                          --
3--                            Matreshka Project                             --
4--                                                                          --
5--                               XML Processor                              --
6--                                                                          --
7--                        Runtime Library Component                         --
8--                                                                          --
9------------------------------------------------------------------------------
10--                                                                          --
11-- Copyright © 2010-2012, Vadim Godunko <vgodunko@gmail.com>                --
12-- All rights reserved.                                                     --
13--                                                                          --
14-- Redistribution and use in source and binary forms, with or without       --
15-- modification, are permitted provided that the following conditions       --
16-- are met:                                                                 --
17--                                                                          --
18--  * Redistributions of source code must retain the above copyright        --
19--    notice, this list of conditions and the following disclaimer.         --
20--                                                                          --
21--  * Redistributions in binary form must reproduce the above copyright     --
22--    notice, this list of conditions and the following disclaimer in the   --
23--    documentation and/or other materials provided with the distribution.  --
24--                                                                          --
25--  * Neither the name of the Vadim Godunko, IE nor the names of its        --
26--    contributors may be used to endorse or promote products derived from  --
27--    this software without specific prior written permission.              --
28--                                                                          --
29-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS      --
30-- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT        --
31-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    --
32-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT     --
33-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   --
34-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED --
35-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR   --
36-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF   --
37-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING     --
38-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS       --
39-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.             --
40--                                                                          --
41------------------------------------------------------------------------------
42--  $Revision: 3086 $ $Date: 2012-08-18 17:30:25 +0400 (Sat, 18 Aug 2012) $
43------------------------------------------------------------------------------
44pragma Ada_2012;
45
46package Matreshka.Internals.XML.Element_Tables is
47
48   pragma Preelaborate;
49
50   type Element_Table is limited private;
51
52   procedure New_Element
53    (Self    : in out Element_Table;
54     Element : out Element_Identifier);
55   --  Allocates new element and returns its identifier.
56
57   function Is_Declared
58    (Self    : Element_Table;
59     Element : Element_Identifier) return Boolean;
60   --  Returns True when element was declared.
61
62   procedure Set_Is_Declared
63    (Self     : in out Element_Table;
64     Element  : Element_Identifier;
65     Declared : Boolean);
66   --  Sets flag to specified value.
67
68   function Is_Attributes_Declared
69    (Self    : Element_Table;
70     Element : Element_Identifier) return Boolean;
71   --  Returns True when attribute list of element type was declared.
72
73   procedure Set_Is_Attributes_Declared
74    (Self     : in out Element_Table;
75     Element  : Element_Identifier;
76     Declared : Boolean);
77   --  Sets flag to specified value.
78
79   function Attributes
80    (Self    : Element_Table;
81     Element : Element_Identifier) return Attribute_Identifier;
82   --  Returns first attribute in the list of declared attributes.
83
84   procedure Set_Attributes
85    (Self      : in out Element_Table;
86     Element   : Element_Identifier;
87     Attribute : Attribute_Identifier);
88   --  Sets first attribute in the list of declared attributes.
89
90   function Is_Mixed_Content
91    (Self    : Element_Table;
92     Element : Element_Identifier) return Boolean;
93
94   procedure Set_Is_Mixed_Content
95    (Self    : in out Element_Table;
96     Element : Element_Identifier;
97     Value   : Boolean);
98
99   function Is_Empty
100    (Self    : Element_Table;
101     Element : Element_Identifier) return Boolean;
102
103   procedure Set_Is_Empty
104    (Self    : in out Element_Table;
105     Element : Element_Identifier;
106     Value   : Boolean);
107
108   function Is_Any
109    (Self    : Element_Table;
110     Element : Element_Identifier) return Boolean;
111
112   procedure Set_Is_Any
113    (Self    : in out Element_Table;
114     Element : Element_Identifier;
115     Value   : Boolean);
116
117   function Has_Children
118    (Self    : Element_Table;
119     Element : Element_Identifier) return Boolean;
120   --  XXX This subprogram is used to check syntax of the mixed content
121   --  declaration temporary. It probably should be removed after
122   --  implementation of DTD validation.
123
124   procedure Set_Has_Children
125    (Self    : in out Element_Table;
126     Element : Element_Identifier;
127     Value   : Boolean);
128   --  XXX This subprogram is used to check syntax of the mixed content
129   --  declaration temporary. It probably should be removed after
130   --  implementation of DTD validation.
131
132   procedure Reset (Self : in out Element_Table);
133   --  Resets internal structures to initial state.
134
135   procedure Finalize (Self : in out Element_Table);
136   --  Releases all ocupied resources.
137
138   function First_Element (Self : Element_Table) return Element_Identifier
139     with Inline => True;
140   --  Returns first element of the element table if any; returns No_Element
141   --  when table is empty.
142
143   procedure Next_Element
144    (Self    : Element_Table;
145     Element : in out Element_Identifier)
146       with Inline => True;
147   --  Sets Element to the next element in the element table if present or to
148   --  No_Element if where is no more element.
149
150private
151
152   type Element_Record is record
153      Attributes             : Attribute_Identifier;
154      Is_Declared            : Boolean;
155      Is_Attributes_Declared : Boolean;
156      Is_Empty               : Boolean;
157      Is_Any                 : Boolean;
158      Is_Mixed_Content       : Boolean;
159      Has_Children           : Boolean;
160   end record;
161
162   type Element_Array is array (Element_Identifier range <>) of Element_Record;
163
164   type Element_Array_Access is access all Element_Array;
165
166   type Element_Table is limited record
167      Table : Element_Array_Access := new Element_Array (1 .. 16);
168      Last  : Element_Identifier   := No_Element;
169   end record;
170
171   pragma Inline (Attributes);
172   pragma Inline (Is_Attributes_Declared);
173   pragma Inline (Is_Declared);
174   pragma Inline (Set_Attributes);
175   pragma Inline (Set_Is_Attributes_Declared);
176   pragma Inline (Set_Is_Declared);
177
178end Matreshka.Internals.XML.Element_Tables;
179