Getting data from associative array with .next()

Hi everyone!
I have an associative array, like this one:

string settings_block [string];//associative array wtih parameters

In it, i have parameters and their values in string type:
PARAM_NAME1 1
PARAM_NAME2 0 0 0 0

I try to get access to elments like this:

string el_name_of_set_bl;//name of the element of the setting block
string el_val_of_set_bl;//value of the element of the setting block

el_val_of_set_bl = settings_block.first (el_name_of_set_bl);//get first element of setting block
for (int i = 1; i < settings_block.size(); i++) begin//start from element #1 because first has already been read
el_val_of_set_bl = settings_block.next (el_name_of_set_bl);//get next element of setting block
end

compiler tells me, that output of .next() method should be int
When declare el_val_of_set_bl as int, i (surely) cannot get full value of PARAM2 (0 0 0 0), i only get 0
How should i get access to these elements?
Thank you!

here’s the complete code, hope this is enough to get the idea


//------------------------------------------------
//reads all parameters from text file and puts them in one string
//------------------------------------------------

  function string make_append_string(
                                      string file_name,//name of file
                                      bit parse_by_name = 1'b1
                                    );
    string str_to_append;//string that will be appended to conf_string
    int file_id;
    string settings_block [string];//associative array wtih parameters
    string el_name_of_set_bl;//name of the element of the setting block
    string el_val_of_set_bl;//value of the element of the setting block

    file_id = $fopen(file_name, "r");
    parse_config_block(file_id,parse_by_name,settings_block);
    $fclose(file_id);
    el_val_of_set_bl = settings_block.first (el_name_of_set_bl);//get first element 
    for (int i = 1; i < settings_block.size(); i++) begin//first has already been read
      str_to_append = $sformatf(str_to_append, el_name_of_set_bl," ", el_val_of_set_bl,"**");
      el_val_of_set_bl = settings_block.next (el_name_of_set_bl);//get next element
    end
    //to add the last element to string
    str_to_append = $sformatf(str_to_append, el_name_of_set_bl," ", el_val_of_set_bl, "**");
    return str_to_append;
  endfunction


function automatic int parse_config_block(
                                          int fid,
                                          bit parse_by_name,
                                          ref string settings_block[string]
                                         );
    string next_word;
    string param_name;
    string param_value;
    bit    block_end_is_found;
    begin
        block_end_is_found = parse_by_name ? 0 : 1;
        if(fid == 0) begin
            $error("Wrong file identifier");
            return -1;
        end
        else begin
            $display("Inside the parse_config_block");
            next_word = get_next_word(fid);

            if(parse_by_name && next_word != "{") begin
                return -1;
            end
            if(parse_by_name) begin
                next_word = get_next_word(fid);    
            end
            while(!(next_word.len() == 0 || $feof(fid) != 0)) begin
                if(next_word == "}") begin
                    block_end_is_found = 1;
                    break;
                end
                param_name = next_word;
                next_word = get_next_word(fid);
                $display(next_word);
                if(!is_value(next_word) || next_word.len() == 0) begin
                    return -1;
                end
                param_value = {next_word, " "};
                next_word = get_next_word(fid);
                $display(next_word);
                while(next_word.len() > 0) begin
                    if(!is_value(next_word)) begin
                        break;
                    end
                    param_value = {param_value, next_word, " "};
                    next_word = get_next_word(fid);
                    $display(next_word);
                end
                settings_block[param_name] = param_value;
                //param_name = next_word;
            end
        end
        return (parse_by_name && !block_end_is_found) ? -1 : 1;
    end
endfunction

input .txt file looks like this:


{
DC_IIR_ENABLE                       0
DC_FIR_OR_LOOKUP_ENABLE             2
NOTCH_IIR_ENABLE        0
 0
 0
 0
}

The error i get is:
assigning a packed type “int” to a string requires a cast
It refers to the line


el_val_of_set_bl = settings_block.next (el_name_of_set_bl);

In reply to boryah:

It would really help if you could show a complete example, especially the code that generates the error.

In reply to cgales:

Added full code to the post. Sorry for not doing it from the beginning:)

In reply to boryah:

From the LRM:

The syntax for the next() method is as follows:


function int next( ref index );

where index is an index of the appropriate type for the array in question. Associative arrays that specify a wildcard index type shall not be allowed.

The next() method finds the smallest index whose value is greater than the given index argument.

If there is a next entry, the index variable is assigned the index of the next entry, and the function returns 1. Otherwise, the index is unchanged, and the function returns 0.


  string s;
  if ( map.first( s ) )
    do
      $display( "%s : %d\n", s, map[ s ] );
    while ( map.next( s ) );

In reply to cgales:

ok, so i’m just not using this function correctly, thank you for explainig me that.
Now it works just fine