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