PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/xml/dtd/xml_dtd_node.e

http://github.com/tybor/Liberty
Specman e | 197 lines | 147 code | 25 blank | 25 comment | 3 complexity | 7eec7c540059376e1f7c1c88aa464891 MD5 | raw file
  1-- See the Copyright notice at the end of this file.
  2--
  3class XML_DTD_NODE
  4   --
  5   -- A real node read from the XML stream.
  6   --
  7
  8insert
  9   RECYCLABLE
 10      redefine
 11         fill_tagged_out_memory
 12      end
 13
 14create {XML_DTD_VALIDATOR}
 15   make
 16
 17feature {ANY}
 18   fill_tagged_out_memory
 19      local
 20         i: INTEGER
 21      do
 22         name.utf8_encode_in(tagged_out_memory)
 23         if not children.is_empty then
 24            tagged_out_memory.extend('(')
 25            from
 26               i := children.lower
 27            until
 28               i > children.upper
 29            loop
 30               if i /= children.lower then
 31                  tagged_out_memory.append(once ", ")
 32               end
 33               children.item(i).fill_tagged_out_memory
 34               i := i + 1
 35            end
 36            tagged_out_memory.extend(')')
 37         end
 38      end
 39
 40feature {XML_DTD_VALIDATOR, XML_DTD_ELEMENT}
 41   name: UNICODE_STRING
 42      require
 43         element /= Void
 44      do
 45         Result := element.name
 46      end
 47
 48   element: XML_DTD_ELEMENT
 49
 50   parent: XML_DTD_NODE
 51
 52   children: FAST_ARRAY[XML_DTD_NODE]
 53
 54   set_element (a_element: like element) assign element
 55      do
 56         element := a_element
 57      ensure
 58         element = a_element
 59      end
 60
 61   set_parent (a_parent: like parent) assign parent
 62      require
 63         not a_parent.fast_has(Current)
 64      do
 65         a_parent.add_last(Current)
 66         parent := a_parent
 67      end
 68
 69feature {XML_DTD_NODE, XML_DTD_VALIDATOR}
 70   valid_index (index: INTEGER): BOOLEAN
 71      do
 72         Result := children.valid_index(index)
 73      end
 74
 75   remove (index: INTEGER)
 76      require
 77         valid_index(index)
 78      do
 79         children.remove(index)
 80      end
 81
 82   add_last (a_node: XML_DTD_NODE)
 83      do
 84         children.add_last(a_node)
 85      ensure
 86         not is_empty
 87      end
 88
 89   is_empty: BOOLEAN
 90      do
 91         Result := children.is_empty
 92      end
 93
 94   count: INTEGER
 95      do
 96         Result := children.count
 97      end
 98
 99   fast_has (a_node: XML_DTD_NODE): BOOLEAN
100      do
101         Result := children.fast_has(a_node)
102      end
103
104   first: XML_DTD_NODE
105      require
106         not is_empty
107      do
108         Result := children.first
109      end
110
111   last: XML_DTD_NODE
112      require
113         not is_empty
114      do
115         Result := children.last
116      end
117
118   item (index: INTEGER): XML_DTD_NODE
119      require
120         valid_index(index)
121      do
122         Result := children.item(index)
123      end
124
125   fast_first_index_of (a_node: XML_DTD_NODE): INTEGER
126      do
127         Result := children.fast_first_index_of(a_node)
128      end
129
130feature {XML_DTD_VALIDATOR} -- Tree validation
131   is_valid_child (explorer: XML_DTD_VALIDATOR; node_name: UNICODE_STRING): BOOLEAN
132      require
133         explorer /= Void
134         element.is_built
135      do
136         Result := element.is_valid_child(explorer, node_name, children)
137      end
138
139   is_valid_data (explorer: XML_DTD_VALIDATOR; data: UNICODE_STRING): BOOLEAN
140      require
141         explorer /= Void
142         element.is_built
143      do
144         Result := element.is_valid_data(explorer, data, children)
145      end
146
147feature {RECYCLING_POOL}
148   recycle
149      local
150         i: INTEGER
151      do
152         if parent /= Void then
153            i := parent.fast_first_index_of(Current)
154            check
155               parent.valid_index(i)
156            end
157            parent.remove(i)
158            check
159               not parent.fast_has(Current)
160            end
161         end
162         parent := Void
163      ensure
164         (old parent /= Void) implies (not (old parent).fast_has(Current))
165         parent = Void
166      end
167
168feature {}
169   make
170      do
171         create children.make(0)
172      end
173
174invariant
175   children /= Void
176
177end -- class XML_DTD_NODE
178--
179-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
180--
181-- Permission is hereby granted, free of charge, to any person obtaining a copy
182-- of this software and associated documentation files (the "Software"), to deal
183-- in the Software without restriction, including without limitation the rights
184-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
185-- copies of the Software, and to permit persons to whom the Software is
186-- furnished to do so, subject to the following conditions:
187--
188-- The above copyright notice and this permission notice shall be included in
189-- all copies or substantial portions of the Software.
190--
191-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
192-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
193-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
194-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
195-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
196-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
197-- THE SOFTWARE.