Update JSON_VALUE and JSON_OBJECT interface

This commit is contained in:
jvelilla
2008-05-25 18:23:25 +00:00
parent 8f3c7beba8
commit 8357bf5d72
7 changed files with 132 additions and 7 deletions

View File

@@ -28,6 +28,25 @@ feature -- Initialization
end
feature -- Access
i_th alias "[]", infix "@" (i: INTEGER):JSON_VALUE is
-- Item at `i'-th position
do
Result := values.i_th (i)
end
feature -- Mesurement
count:INTEGER is
--
do
Result:=values.count
end
feature -- Status report
valid_index (i: INTEGER): BOOLEAN is
-- Is `i' a valid index?
do
Result := (1 <= i) and (i <= count)
end
feature -- Change Element
add(value:JSON_VALUE) is
@@ -41,7 +60,7 @@ feature -- Change Element
has_new_value:old values.count + 1 = values.count
end
feature -- Report
to_json:STRING is
--Printable json representation
-- [] or [elements]
@@ -65,7 +84,7 @@ feature -- Change Element
Result.append("]")
end
hash_code:INTEGER is
hash_code:INTEGER is
--
do
from
@@ -78,7 +97,7 @@ feature -- Change Element
values.forth
end
Result := Result \\ values.count
end
feature {NONE} --Implementation
values:ARRAYED_LIST[JSON_VALUE]

View File

@@ -36,4 +36,5 @@ feature -- Access
value:BOOLEAN
end

View File

@@ -22,6 +22,6 @@ feature --Access
Result:= null_value.hash_code
end
feature -- Implementation
feature {NONE}-- Implementation
null_value:STRING is "null"
end

View File

@@ -52,6 +52,7 @@ feature -- Access
Result:=value.is_equal(other.to_json)
end
feature -- Implementation
value:STRING
internal_hash_code:INTEGER

View File

@@ -66,14 +66,12 @@ feature -- Access
end
get_keys:ARRAY[JSON_STRING] is
--
-- array containing actually used keys
do
Result:=object.current_keys
end
feature -- Report
to_json:STRING is
-- Printable json representation

View File

@@ -30,6 +30,7 @@ feature -- Initialization
feature -- Access
feature -- Comparison
is_equal (other: like Current): BOOLEAN is
-- Is JSON_STRING made of same character sequence as `other'

View File

@@ -29,4 +29,109 @@ feature -- Access
deferred
end
feature -- Status Report
is_json_array:BOOLEAN is
-- Does `Current' represent a JSON_ARRAY?
do
if generating_type.is_equal ("JSON_ARRAY") then
Result := true
end
end
is_json_string:BOOLEAN is
-- Does `Current' represent a JSON_STRING?
do
if generating_type.is_equal ("JSON_STRING") then
Result := true
end
end
is_json_object:BOOLEAN is
-- Does `Current' represent a JSON_OBJECT?
do
if generating_type.is_equal ("JSON_OBJECT") then
Result := true
end
end
is_json_number:BOOLEAN is
-- Does 'Current' represent a JSON_NUMBER?
do
if generating_type.is_equal ("JSON_NUMBER") then
Result := true
end
end
is_json_boolean:BOOLEAN is
-- Does 'Current' represent a JSON_BOOLEAN?
do
if generating_type.is_equal ("JSON_BOOLEAN") then
Result := true
end
end
is_json_null:BOOLEAN is
-- Does 'Current' represent a JSON_NULL?
do
if generating_type.is_equal ("JSON_NULL") then
Result := true
end
end
feature -- Conversion
to_json_array:JSON_ARRAY is
-- Convert `Current' as a JSON_ARRAY.
require
is_a_json_array:is_json_array
do
Result ?= Current
end
to_json_string:JSON_STRING is
-- Convert `Current' as a JSON_STRING.
require
is_a_json_string: is_json_string
do
Result ?= Current
end
to_json_object:JSON_OBJECT is
-- Convert 'Current' as a JSON_OBJECT
require
is_a_json_object: is_json_object
do
Result?=Current
end
to_json_number:JSON_NUMBER is
-- Convert 'Current' as a JSON_NUMBER
require
is_a_json_number:is_json_number
do
Result ?= Current
end
to_json_boolean:JSON_BOOLEAN is
-- Convert 'Current' as a JSON_BOOLEAN
require
is_a_json_boolean:is_json_boolean
do
Result ?= Current
end
to_json_null:JSON_NULL is
-- Convert 'Current' as a JSON_NULL
require
is_a_json_null:is_json_null
do
Result ?= Current
end
end