Skip to content

Commit

Permalink
fix: update API of json_bool
Browse files Browse the repository at this point in the history
  • Loading branch information
esynr3z committed May 18, 2024
1 parent 9627a0c commit ece93e0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/encodable/json_bool_encodable.sv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Interface for a class that can be encoded as JSON bool
interface class json_bool_encodable extends json_value_encodable;
// Get native value of bit
pure virtual function bit get_value();
// Get value encodable as JSON bool
pure virtual function bit to_json_encodable();
endclass : json_bool_encodable
2 changes: 1 addition & 1 deletion src/json_encoder.sv
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ endfunction : convert_real


function json_result#(string) json_encoder::convert_bool(json_bool_encodable obj);
return json_result#(string)::ok(obj.get_value() ? "true" : "false");
return json_result#(string)::ok(obj.to_json_encodable() ? "true" : "false");
endfunction : convert_bool


Expand Down
33 changes: 26 additions & 7 deletions src/values/json_bool.sv
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// JSON bool value
// JSON bool.
// This wrapper class represens standard JSON bool value type.
class json_bool extends json_value implements json_bool_encodable;
bit value;
// Internal raw value
bit value; // FIXME: need to make protected

// Normal constructor
extern function new(bit value);
Expand All @@ -11,11 +13,18 @@ class json_bool extends json_value implements json_bool_encodable;
// Create a deep copy of an instance
extern virtual function json_value clone();

// Compare with another instance
// Compare with another instance.
// Return 1 if instances are equal and 0 otherwise.
extern virtual function bit compare(json_value value);

// Interface json_bool_encodable
extern virtual function bit get_value();
// Get raw 1-bit value
extern virtual function bit get();

// Set raw 1-bit value
extern virtual function void set(bit value);

// Get value encodable as JSON bool (for interface json_bool_encodable)
extern virtual function bit to_json_encodable();
endclass : json_bool


Expand Down Expand Up @@ -52,6 +61,16 @@ function bit json_bool::compare(json_value value);
endfunction : compare


function bit json_bool::get_value();
function bit json_bool::get();
return this.value;
endfunction : get


function void json_bool::set(bit value);
this.value = value;
endfunction : set


function bit json_bool::to_json_encodable();
return this.value;
endfunction : get_value
endfunction : to_json_encodable

0 comments on commit ece93e0

Please sign in to comment.