How can I copy a transaction class object containing associative array members to another object of the same class?

I have a transaction class extended from uvm_object.
The members of this class are associative arrays. Each element in the associative array is a queue of data.
An object(trans_o) of this transaction class has been created and the associative arrays are allocated and queues are assigned with values.
I want to copy this object ‘trans_o’ to another object ‘copied_trans_o’ of the same transaction class.

I tried the ‘copy’ and ‘clone’ methods of the uvm_object. But in both the methods, the associative arrays are not getting copied. When I display the associative array element of ‘copied_trans_o’, the queue is empty.

  1. $cast(copied_trans_o,trans_o.clone());
  2. copied_trans_o = trans::type_id::create(“copied_trans_o”, this);
    copied_trans_o.copy(trans_o);

Do I have to implement do_copy() function in the transaction class with the logic to copy each associative array element or is there any other solution?

In reply to Laya V V:

See the SV standard 2012. It says
7.9.9 Associative array assignment
Associative arrays can be assigned only to another associative array of a compatible type and with the same
index type. Other types of arrays cannot be assigned to an associative array, nor can associative arrays be
assigned to other types of arrays, whether fixed-size or dynamic.
Assigning an associative array to another associative array causes the target array to be cleared of any
existing entries, and then each entry in the source array is copied into the target array.

The issue that I am facing is when I copy a transaction class object to another object(using copy/clone method), the associative array elements are not copied. I am able to access the associative array members of the new object, but the content is empty.

In reply to Laya V V:

Could you please provide some more code.
Thanks.

In reply to Laya V V:

I have here a very simple example outside UVM.
It shows how it works.
module top;
class A;
int a;
string b [string];

function new();
    a = 5;
b = '{"Christoph":"Suehnel", "Germany":"Bavaria"};
endfunction

endclass

class B extends A;
int c;
string d [string];

 function new();
   super.new();
   c= 7;
 endfunction

endclass

initial begin
A a_inst;
B b_inst;

a_inst = new();
$display("a_inst::a = %d", a_inst.a);
$display("a_inst::b = %p", a_inst.b);

b_inst = new();
b_inst.d = a_inst.b;
$display("b_inst::c = %d", b_inst.c);
$display("b_inst::d = %p", b_inst.d);

end
endmodule

In reply to Laya V V:
This worked fine for me. Perhaps you should show some of your code.

module top;
   import uvm_pkg::*;
   `include "uvm_macros.svh"
   
class trans extends uvm_object;
   `uvm_object_utils(trans);
   function new(string name="");
      super.new(name);
   endfunction
   
   typedef byte queue_of_data[$];
   
   queue_of_data member1[string];
   queue_of_data member2[string];
   
   function void do_copy(uvm_object rhs);
      trans rhs_;
      if (!$cast(rhs_,rhs))
	`uvm_error("TYPEMISMATCH","do_copy type mismatch");
      super.do_copy(rhs);
      member1 = rhs_.member1;
      member2 = rhs_.member2;
   endfunction // void
endclass // trans


   trans obj1, obj2;

   initial begin
      obj1 = trans::type_id::create("obj1");
      obj1.member1["odd"] = {1,3,5,7};
      obj1.member1["even"] = {2,4,6,8};
      obj1.member2["prime"] = {1,3,7,11};
      $cast(obj2,obj1.clone());
      $display("member1 %p",obj2.member1);
      $display("member2 %p",obj2.member2);
   end
endmodule // top

Thanks Dave! I got it.

Thanks!