Array of parametrized classes

Hi,
I want to define&create an array of parametric classes, each one with a specific parameter.
In the original code I have something like this:

//=========================================
package my_pack
parameter num_of_fpgas = 2; //defined in external package
....
//=========================================
import my_pack::*;
class my_agent#(int fpga_index) extends uvm_agent;
....
`uvm_components_param_utils(my_agent#(fpga_index))
//=========================================
class dut_env extends uvm_env;
...
my_agent#(0) fpga0_agent;
my_agent#(1) fpga1_agent;
...
fpga0_agent=my_agent#(0)::type_id::create("fpga0_agent",this);
fpga1_agent=my_agent#(1)::type_id::create("fpga1_agent",this);
//=========================================

I want to declare an unpacked array of my_agent(size of array = num_of_fpgas), in which each object will get the parameter of its index, i.e. sth like:

class dut_env extends uvm_env;
...
my_agent#(????) fpga_agent[0:num_of_fpgas -1]; //how to define it???
//fpga_agent[0] should get parameter fpga_index=0
//fpga_agent[1] should get parameter fpga_index=1, etc...

...
//How to define the build phase??

Thanks

In reply to shaygueta:

It is better to save parameters for values requiring constant expressions like variable widths, or types. If fpga_index is just used for something like address decoding, make it a class member variable instead.

class my_agent extends uvm_agent;
 `uvm_components_utils(my_agent)
  int fpga_index;
...
class dut_env extends uvm_env;

  my_agent fpga_agent[num_of_fpgas];
  function void build_phase(uvm_phase phase);
     foreach(fpga_agent[index]) begin
          fpga_agent[index] = my_agent::type_id::create($sformatf("fpga_agent_%0d",index),this);
          fpga_agent[index].fpga_index = index;
     end
  ...

If your situation requires fpga_index to be a parameter, then your array elements need to be declared with a common base class, like uvm_agent. However, you will not be able to make any connections your agent from a uvm_agent class. So what you can do is create a common base class.

class my_agent_base extends uvm_agent;
  uvm_analysis_port#(my_transaction) ap;
  ...
endclass
class my_agent#(int fpga_index) extends my_agent_base;
`uvm_components_param_utils(my_agent#(fpga_index))
...
class dut_env extends uvm_env;

  my_agent_base fpga_agent[num_of_fpgas];
  function void build_phase(uvm_phase phase);
     foreach(fpga_agent[index]) case(index) // doing this because you cannot parameterize with a variable
         0: fpga_agent[index] = my_agent#(0)::type_id::create($sformatf("fpga_agent_%0d",index),this);
         1: fpga_agent[index] = my_agent#(1)::type_id::create($sformatf("fpga_agent_%0d",index),this);
         2: fpga_agent[index] = my_agent#(2)::type_id::create($sformatf("fpga_agent_%0d",index),this);
         default: `uvm_error("build_phase","exceeded max anticipated fpgas")
     endcase

Now will be able to access fpga_agent[I].ap to connect this agent up to a scoreboard.