Add accept method (JSON_VISITOR), remove is_xxx queries, remove to_json feature.
Improve comments
This commit is contained in:
@@ -9,8 +9,8 @@ indexing
|
|||||||
]"
|
]"
|
||||||
|
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "$Date$"
|
date: "2008/08/24"
|
||||||
revision: "$Revision$"
|
revision: "Revision 0.1"
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_ARRAY
|
JSON_ARRAY
|
||||||
@@ -36,9 +36,18 @@ feature -- Access
|
|||||||
Result := values.i_th (i)
|
Result := values.i_th (i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Visitor pattern
|
||||||
|
|
||||||
|
accept (a_visitor: JSON_VISITOR) is
|
||||||
|
-- Accept `a_visitor'.
|
||||||
|
-- (Call `visit_json_array' procedure on `a_visitor'.)
|
||||||
|
do
|
||||||
|
a_visitor.visit_json_array (Current)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Mesurement
|
feature -- Mesurement
|
||||||
count:INTEGER is
|
count:INTEGER is
|
||||||
--
|
-- Number of items.
|
||||||
do
|
do
|
||||||
Result:=values.count
|
Result:=values.count
|
||||||
end
|
end
|
||||||
@@ -62,28 +71,6 @@ feature -- Change Element
|
|||||||
end
|
end
|
||||||
|
|
||||||
feature -- Report
|
feature -- Report
|
||||||
to_json:STRING is
|
|
||||||
--Printable json representation
|
|
||||||
-- [] or [elements]
|
|
||||||
local
|
|
||||||
value:JSON_VALUE
|
|
||||||
do
|
|
||||||
create Result.make_empty
|
|
||||||
Result.append("[")
|
|
||||||
from
|
|
||||||
values.start
|
|
||||||
until
|
|
||||||
values.off
|
|
||||||
loop
|
|
||||||
value:=values.item
|
|
||||||
Result.append(value.to_json)
|
|
||||||
values.forth
|
|
||||||
if not values.after then
|
|
||||||
Result.append(",")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Result.append("]")
|
|
||||||
end
|
|
||||||
|
|
||||||
hash_code:INTEGER is
|
hash_code:INTEGER is
|
||||||
--
|
--
|
||||||
@@ -100,6 +87,14 @@ feature -- Report
|
|||||||
Result := Result \\ values.count
|
Result := Result \\ values.count
|
||||||
|
|
||||||
end
|
end
|
||||||
|
feature -- Conversion
|
||||||
|
|
||||||
|
array_representation:ARRAYED_LIST[JSON_VALUE] is
|
||||||
|
-- Representation as a sequences of values
|
||||||
|
do
|
||||||
|
Result:=values
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE} --Implementation
|
feature {NONE} --Implementation
|
||||||
values:ARRAYED_LIST[JSON_VALUE]
|
values:ARRAYED_LIST[JSON_VALUE]
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
indexing
|
indexing
|
||||||
description: "JSON Truth values"
|
description: "JSON Truth values"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "$Date$"
|
date: "2008/08/24"
|
||||||
revision: "$Revision$"
|
revision: "Revision 0.1"
|
||||||
|
|
||||||
class
|
class
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ create
|
|||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
|
|
||||||
make_boolean (an_item: BOOLEAN) is
|
make_boolean (an_item: BOOLEAN) is
|
||||||
--
|
--Initialize.
|
||||||
do
|
do
|
||||||
item := an_item
|
item := an_item
|
||||||
end
|
end
|
||||||
@@ -26,19 +26,24 @@ feature -- Initialization
|
|||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
item: BOOLEAN
|
item: BOOLEAN
|
||||||
|
-- Content
|
||||||
|
|
||||||
to_json: STRING is
|
|
||||||
--
|
|
||||||
do
|
|
||||||
Result := item.out
|
|
||||||
end
|
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER is
|
||||||
--
|
--Hash code value
|
||||||
do
|
do
|
||||||
Result := item.hash_code
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Visitor pattern
|
||||||
|
|
||||||
|
accept (a_visitor: JSON_VISITOR) is
|
||||||
|
-- Accept `a_visitor'.
|
||||||
|
-- (Call `visit_json_boolean' procedure on `a_visitor'.)
|
||||||
|
do
|
||||||
|
a_visitor.visit_json_boolean (Current)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
indexing
|
indexing
|
||||||
description: "JSON Null Values"
|
description: "JSON Null Values"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "$Date$"
|
date: "2008/08/24"
|
||||||
revision: "$Revision$"
|
revision: "Revision 0.1"
|
||||||
|
|
||||||
class
|
class
|
||||||
JSON_NULL
|
JSON_NULL
|
||||||
@@ -10,17 +10,20 @@ class
|
|||||||
JSON_VALUE
|
JSON_VALUE
|
||||||
|
|
||||||
feature --Access
|
feature --Access
|
||||||
to_json:STRING is
|
|
||||||
--
|
|
||||||
do
|
|
||||||
Result:=null_value
|
|
||||||
end
|
|
||||||
|
|
||||||
hash_code:INTEGER is
|
hash_code:INTEGER is
|
||||||
--
|
-- Hash code value
|
||||||
do
|
do
|
||||||
Result:= null_value.hash_code
|
Result:= null_value.hash_code
|
||||||
end
|
end
|
||||||
|
feature -- Visitor pattern
|
||||||
|
|
||||||
|
accept (a_visitor: JSON_VISITOR) is
|
||||||
|
-- Accept `a_visitor'.
|
||||||
|
-- (Call `visit_element_a' procedure on `a_visitor'.)
|
||||||
|
do
|
||||||
|
a_visitor.visit_json_null (Current)
|
||||||
|
end
|
||||||
|
|
||||||
feature {NONE}-- Implementation
|
feature {NONE}-- Implementation
|
||||||
null_value:STRING is "null"
|
null_value:STRING is "null"
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ indexing
|
|||||||
|
|
||||||
description: "JSON Numbers, octal and hexadecimal formats are not used."
|
description: "JSON Numbers, octal and hexadecimal formats are not used."
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "$Date$"
|
date: "2008/08/24"
|
||||||
revision: "$Revision$"
|
revision: "Revision 0.1"
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
|
|
||||||
class
|
class
|
||||||
@@ -15,6 +15,8 @@ inherit
|
|||||||
redefine
|
redefine
|
||||||
is_equal
|
is_equal
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
create
|
create
|
||||||
|
|
||||||
make_integer,
|
make_integer,
|
||||||
@@ -23,30 +25,39 @@ create
|
|||||||
feature -- initialization
|
feature -- initialization
|
||||||
|
|
||||||
make_integer (argument: INTEGER) is
|
make_integer (argument: INTEGER) is
|
||||||
|
-- Initialize an instance of JSON_NUMBER as INTEGER
|
||||||
do
|
do
|
||||||
item:= argument.out
|
item:= argument.out
|
||||||
internal_hash_code:=argument.hash_code
|
numeric_type:= INTEGER_TYPE
|
||||||
numeric_type:= "INTEGER"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
make_real (argument: REAL) is
|
make_real (argument: REAL) is
|
||||||
|
-- Initialize an instance of JSON_NUMBER as REAL
|
||||||
do
|
do
|
||||||
item:= argument.out
|
item:= argument.out
|
||||||
internal_hash_code:=argument.hash_code
|
numeric_type:= REAL_TYPE
|
||||||
numeric_type:= "REAL"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
item: STRING
|
item: STRING
|
||||||
|
-- Content
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER is
|
||||||
--
|
--Hash code value
|
||||||
do
|
do
|
||||||
Result:=internal_hash_code
|
Result:=item.hash_code
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Visitor pattern
|
||||||
|
|
||||||
|
accept (a_visitor: JSON_VISITOR) is
|
||||||
|
-- Accept `a_visitor'.
|
||||||
|
-- (Call `visit_json_number' procedure on `a_visitor'.)
|
||||||
|
do
|
||||||
|
a_visitor.visit_json_number (Current)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Status
|
feature -- Status
|
||||||
|
|
||||||
@@ -54,23 +65,17 @@ feature -- Status
|
|||||||
-- Is `other' attached to an object of the same type
|
-- Is `other' attached to an object of the same type
|
||||||
-- as current object and identical to it?
|
-- as current object and identical to it?
|
||||||
do
|
do
|
||||||
Result:=item.is_equal (other.to_json)
|
Result:=item.is_equal (other.item)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Conversion
|
|
||||||
|
|
||||||
to_json: STRING is
|
|
||||||
--
|
|
||||||
do
|
|
||||||
Result := item
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
feature -- Implementation
|
feature -- Implementation
|
||||||
|
|
||||||
internal_hash_code: INTEGER
|
INTEGER_TYPE: INTEGER is 1
|
||||||
|
REAL_TYPE:INTEGER is 2
|
||||||
|
numeric_type: INTEGER
|
||||||
|
|
||||||
numeric_type: STRING -- REAL or INTEGER
|
|
||||||
|
|
||||||
|
|
||||||
invariant
|
invariant
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ An object is an unordered set of name/value pairs
|
|||||||
|
|
||||||
]"
|
]"
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "$Date$"
|
date: "2008/08/24"
|
||||||
revision: "$Revision$"
|
revision: "Revision 0.1"
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
|
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ create
|
|||||||
feature -- Initialization
|
feature -- Initialization
|
||||||
|
|
||||||
make is
|
make is
|
||||||
--
|
-- Initialize
|
||||||
do
|
do
|
||||||
create object.make (10)
|
create object.make (10)
|
||||||
end
|
end
|
||||||
@@ -85,32 +85,25 @@ feature -- Access
|
|||||||
Result:=object.current_keys
|
Result:=object.current_keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Visitor pattern
|
||||||
|
|
||||||
|
accept (a_visitor: JSON_VISITOR) is
|
||||||
|
-- Accept `a_visitor'.
|
||||||
|
-- (Call `visit_json_object' procedure on `a_visitor'.)
|
||||||
|
do
|
||||||
|
a_visitor.visit_json_object (Current)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
feature -- Conversion
|
||||||
|
map_representation: HASH_TABLE[JSON_VALUE,JSON_STRING] is
|
||||||
|
--A representation that maps keys to values
|
||||||
|
do
|
||||||
|
Result:=object
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Report
|
feature -- Report
|
||||||
|
|
||||||
to_json: STRING is
|
|
||||||
-- Printable json representation
|
|
||||||
-- {} or {member}
|
|
||||||
-- see documentation
|
|
||||||
do
|
|
||||||
create Result.make_empty
|
|
||||||
Result.append ("{")
|
|
||||||
from
|
|
||||||
object.start
|
|
||||||
until
|
|
||||||
object.off
|
|
||||||
loop
|
|
||||||
Result.append (object.item_for_iteration.to_json)
|
|
||||||
Result.append (":")
|
|
||||||
Result.append (object.key_for_iteration.to_json)
|
|
||||||
object.forth
|
|
||||||
if not object.after then
|
|
||||||
Result.append (",")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Result.append ("}")
|
|
||||||
end
|
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER is
|
||||||
-- Hash code value
|
-- Hash code value
|
||||||
local
|
local
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ indexing
|
|||||||
]"
|
]"
|
||||||
|
|
||||||
author: "Javier Velilla"
|
author: "Javier Velilla"
|
||||||
date: "$Date$"
|
date: "2008/08/24"
|
||||||
revision: "$Revision$"
|
revision: "Revision 0.1"
|
||||||
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
license:"MIT (see http://www.opensource.org/licenses/mit-license.php)"
|
||||||
|
|
||||||
|
|
||||||
@@ -43,6 +43,15 @@ feature -- Access
|
|||||||
item: STRING
|
item: STRING
|
||||||
-- Contents
|
-- Contents
|
||||||
|
|
||||||
|
feature -- Visitor pattern
|
||||||
|
|
||||||
|
accept (a_visitor: JSON_VISITOR) is
|
||||||
|
-- Accept `a_visitor'.
|
||||||
|
-- (Call `visit_json_string' procedure on `a_visitor'.)
|
||||||
|
do
|
||||||
|
a_visitor.visit_json_string (Current)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
feature -- Comparison
|
feature -- Comparison
|
||||||
|
|
||||||
@@ -50,13 +59,13 @@ feature -- Comparison
|
|||||||
-- Is JSON_STRING made of same character sequence as `other'
|
-- Is JSON_STRING made of same character sequence as `other'
|
||||||
-- (possibly with a different capacity)?
|
-- (possibly with a different capacity)?
|
||||||
do
|
do
|
||||||
Result := Current.to_json.is_equal (other.to_json)
|
Result := item.is_equal (other.item)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Change Element
|
feature -- Change Element
|
||||||
|
|
||||||
append (an_item: STRING)is
|
append (an_item: STRING)is
|
||||||
--
|
-- Add an_item
|
||||||
do
|
do
|
||||||
item.append_string (an_item)
|
item.append_string (an_item)
|
||||||
end
|
end
|
||||||
@@ -64,17 +73,8 @@ feature -- Change Element
|
|||||||
|
|
||||||
feature -- Status report
|
feature -- Status report
|
||||||
|
|
||||||
to_json: STRING is
|
|
||||||
--
|
|
||||||
do
|
|
||||||
create Result.make_empty
|
|
||||||
Result.append ("%"")
|
|
||||||
Result.append (item)
|
|
||||||
Result.append ("%"")
|
|
||||||
end
|
|
||||||
|
|
||||||
hash_code: INTEGER is
|
hash_code: INTEGER is
|
||||||
--
|
-- Hash code value
|
||||||
do
|
do
|
||||||
Result := item.hash_code
|
Result := item.hash_code
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,117 +24,13 @@ inherit
|
|||||||
|
|
||||||
HASHABLE
|
HASHABLE
|
||||||
|
|
||||||
feature -- Access
|
feature -- Visitor pattern
|
||||||
|
|
||||||
to_json:STRING is
|
accept (a_visitor: JSON_VISITOR) is
|
||||||
-- Generate the JSON String for this value object
|
-- Accept `a_visitor'.
|
||||||
-- return a correct JSON-STRING
|
-- (Call `visit_*' procedure on `a_visitor'.)
|
||||||
|
require
|
||||||
|
a_visitor_not_void: a_visitor /= Void
|
||||||
deferred
|
deferred
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user