Browse Source

Add parameter err to get(), del() and clear()

The new parameter err with type boolean is set, if there occurred an
error during getting, removing a key/value pair or clearing the whole
directory
pull/1/head
T. Meissner 9 years ago
parent
commit
6ec1dbd5da
1 changed files with 21 additions and 10 deletions
  1. +21
    -10
      sim/DictP.vhd

+ 21
- 10
sim/DictP.vhd View File

@ -9,10 +9,10 @@ package DictP is
type t_dict is protected type t_dict is protected
procedure set (key : in string; data : in std_logic_vector); procedure set (key : in string; data : in std_logic_vector);
procedure get (key : in string; data : out std_logic_vector);
procedure del (key : in string);
procedure get (key : in string; data : out std_logic_vector; err : out boolean);
procedure del (key : in string; err : out boolean);
procedure init (logging : in boolean := false); procedure init (logging : in boolean := false);
procedure clear;
procedure clear (err : out boolean);
impure function hasKey (key : string) return boolean; impure function hasKey (key : string) return boolean;
impure function size return natural; impure function size return natural;
@ -79,7 +79,7 @@ package body DictP is
end if; end if;
end procedure set; end procedure set;
procedure get (key : in string; data : out std_logic_vector) is
procedure get (key : in string; data : out std_logic_vector; err : out boolean) is
variable v_entry : t_entry_ptr := find(key); variable v_entry : t_entry_ptr := find(key);
begin begin
if(v_entry /= null) then if(v_entry /= null) then
@ -87,12 +87,13 @@ package body DictP is
if v_logging then if v_logging then
report t_dict'instance_name & ": Got key " & key & " with data 0x" & to_hstring(v_entry.data.all); report t_dict'instance_name & ": Got key " & key & " with data 0x" & to_hstring(v_entry.data.all);
end if; end if;
return;
err := false;
else
err := true;
end if; end if;
assert false;
end procedure get; end procedure get;
procedure del (key : in string) is
procedure del (key : in string; err : out boolean) is
variable v_entry : t_entry_ptr := find(key); variable v_entry : t_entry_ptr := find(key);
begin begin
if (v_entry /= null) then if (v_entry /= null) then
@ -112,6 +113,9 @@ package body DictP is
deallocate(v_entry.data); deallocate(v_entry.data);
deallocate(v_entry); deallocate(v_entry);
v_size := v_size - 1; v_size := v_size - 1;
err := false;
else
err := true;
end if; end if;
end procedure del; end procedure del;
@ -127,14 +131,21 @@ package body DictP is
return null; return null;
end function find; end function find;
procedure clear is
procedure clear (err : out boolean) is
variable v_entry : t_entry_ptr := v_head; variable v_entry : t_entry_ptr := v_head;
variable v_entry_d : t_entry_ptr; variable v_entry_d : t_entry_ptr;
variable v_err : boolean;
begin begin
err := false;
while (v_entry /= null) loop while (v_entry /= null) loop
v_entry_d := v_entry; v_entry_d := v_entry;
del(v_entry_d.key.all);
v_entry := v_entry.last_entry;
del(v_entry_d.key.all, v_err);
if v_err then
err := true;
return;
else
v_entry := v_entry.last_entry;
end if;
end loop; end loop;
end procedure clear; end procedure clear;


Loading…
Cancel
Save