PageRenderTime 25ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/xml/xml_composite_node.e

http://github.com/tybor/Liberty
Specman e | 132 lines | 83 code | 17 blank | 32 comment | 0 complexity | 9b720d31db5a3fbfdd9aaa9a1541114d MD5 | raw file
  1-- See the Copyright notice at the end of this file.
  2--
  3class XML_COMPOSITE_NODE
  4   --
  5   -- A named node containing children
  6   --
  7
  8inherit
  9   XML_NODE
 10
 11create {ANY}
 12   make
 13
 14feature {ANY}
 15   name: UNICODE_STRING
 16         -- The name of the node
 17
 18   attribute_name (index: INTEGER): UNICODE_STRING
 19         -- The name of the i'th attribute
 20      require
 21         index.in_range(1, attributes_count)
 22      do
 23         Result := attributes.key(index)
 24      end
 25
 26   attribute_value (index: INTEGER): UNICODE_STRING
 27         -- The value of the i'th attribute
 28      require
 29         index.in_range(1, attributes_count)
 30      do
 31         Result := attributes.item(index)
 32      end
 33
 34   attribute_at (a_attribute_name: UNICODE_STRING): UNICODE_STRING
 35         -- The value of the attribute given by its name; Void if not set
 36      do
 37         Result := attributes.reference_at(a_attribute_name)
 38      end
 39
 40   attributes_count: INTEGER
 41         -- The number of attributes
 42      do
 43         Result := attributes.count
 44      end
 45
 46   child (index: INTEGER): XML_NODE
 47         -- The i'th child
 48      require
 49         index.in_range(1, children_count)
 50      do
 51         Result := children.item(index - 1)
 52      end
 53
 54   children_count: INTEGER
 55         -- The number of children
 56      do
 57         Result := children.count
 58      end
 59
 60feature {ANY}
 61   accept (visitor: VISITOR)
 62      local
 63         v: XML_NODE_VISITOR
 64      do
 65         v ::= visitor
 66         v.visit_composite_node(Current)
 67      end
 68
 69feature {XML_TREE}
 70   set_attribute (a_attribute_name, a_attribute_value: UNICODE_STRING)
 71      require
 72         a_attribute_name /= Void
 73         a_attribute_value /= Void
 74      do
 75         attributes.put(a_attribute_value, a_attribute_name)
 76      ensure
 77         attribute_at(a_attribute_name) = a_attribute_value
 78      end
 79
 80   add_child (node: XML_NODE)
 81      require
 82         node /= Void
 83         node.parent = Void
 84      do
 85         children.add_last(node)
 86         node.set_parent(Current)
 87      ensure
 88         node.parent = Current
 89         child(children_count) = node
 90      end
 91
 92feature {}
 93   children: FAST_ARRAY[XML_NODE]
 94
 95   attributes: HASHED_DICTIONARY[UNICODE_STRING, UNICODE_STRING]
 96
 97   make (a_name: like name; a_line: like line; a_column: like column)
 98      require
 99         a_line > 0
100         a_column > 0
101      do
102         name := a_name
103         line := a_line
104         column := a_column
105         create attributes.make
106         create children.make(0)
107      end
108
109invariant
110   name /= Void
111
112end -- class XML_COMPOSITE_NODE
113--
114-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
115--
116-- Permission is hereby granted, free of charge, to any person obtaining a copy
117-- of this software and associated documentation files (the "Software"), to deal
118-- in the Software without restriction, including without limitation the rights
119-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
120-- copies of the Software, and to permit persons to whom the Software is
121-- furnished to do so, subject to the following conditions:
122--
123-- The above copyright notice and this permission notice shall be included in
124-- all copies or substantial portions of the Software.
125--
126-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
127-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
128-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
129-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
130-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
131-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
132-- THE SOFTWARE.