I have a class A, which consists of 100’s of data variables like below.
class A;
int t_start;
int t_end, t_high, t_low;
int t_mid, t_mid1, t_max, t_max1;
endclass
i wanted to access the data variables of class A inside class B. we can use dot operator (.) to access the same. i dont want to write one by one for all 100+ variables (like obj1.t_start, obj1.t_end) is there any concise way to do so? i can bring all the variables of class A inside class B in an array format.
class B;
A obj1;
obj1 = new();
obj1.t_start;
obj1.t_end;
.....
endclass
When you say “access the data variables of class A”, we need a better definition of what your intentions are. You can bit-stream all variables of a class together if they are all integral types. To create an array, all variables need to be the same type. An associative array can be indexed using a string name.
int array[string];
array["t_start"] = 0;
array["t_end"] = 10;
Then you could iterate over all the variables using foreach.
The UVM has an elaborate set of field automation macros that can register each class variable and then build a limited functions of combined operations on all the variables like print, copy and compare.
HI Dave,
Thanks for your response.
as said earlier class A has some data variables.
i wanted to access inside class B and do some processing based on the value.
ex: class A data_variables values --> t_start = 0; t_end = 10; t_max = 100;
Based on the values of t_start, t_end and t_max.
i am having a function to enable some feature of the design.
Now i wanted to access all the data variables inside class A one by one and enable specific feature. i do not want to write line by line for all variables. i know what are all the variables present in the class A also able to bring it to an array.
any method to do the same.
Thankyou