Enhanced interface of JSON_ARRAY and JSON_OBJECT

Added JSON_ITERATOR
This commit is contained in:
2013-08-05 12:07:07 +02:00
parent 3e976768ac
commit 8e743f3253
3 changed files with 118 additions and 10 deletions

View File

@@ -18,7 +18,7 @@ class
inherit
JSON_VALUE
DEBUG_OUTPUT
ITERABLE [JSON_VALUE]
create
make_array
@@ -69,6 +69,14 @@ feature -- Visitor pattern
a_visitor.visit_json_array (Current)
end
feature -- Access
new_cursor: ITERATION_CURSOR [JSON_VALUE]
-- Fresh cursor associated with current structure
do
Result := values.new_cursor
end
feature -- Mesurement
count: INTEGER
@@ -87,16 +95,42 @@ feature -- Status report
feature -- Change Element
add (value: JSON_VALUE)
put_front (v: JSON_VALUE)
require
value_not_null: value /= void
v_not_void: v /= Void
do
values.extend (value)
values.put_front (v)
ensure
has_new_value: old values.count + 1 = values.count and
values.has (value)
values.first = v
end
add, extend (v: JSON_VALUE)
require
v_not_void: v /= Void
do
values.extend (v)
ensure
has_new_value: old values.count + 1 = values.count and
values.has (v)
end
prune_all (v: JSON_VALUE)
-- Remove all occurrences of `v'.
require
v_not_void: v /= Void
do
values.prune_all (v)
ensure
not_has_new_value: not values.has (v)
end
wipe_out
-- Remove all items.
do
values.wipe_out
end
feature -- Report
hash_code: INTEGER
@@ -118,6 +152,7 @@ feature -- Conversion
array_representation: ARRAYED_LIST [JSON_VALUE]
-- Representation as a sequences of values
-- be careful, modifying the return object may have impact on the original JSON_ARRAY object
do
Result := values
end
@@ -127,7 +162,7 @@ feature -- Status report
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := count.out
Result := count.out + " item(s)"
end
feature {NONE} -- Implementation