Hi All,
I need to check whether object has been created or not.
I am having one transaction class. I am declaring handle with dynamic for that.
//Transaction Class
class transaction;
bit [3:0] a;
bit [3:0] b;
endclass
transaction tr[] ; // dynamic object
initial
begin
tr[0]=new();
if(tr[1].exists()) // Is it valid syntax or not ?
$display("class is available");
else
$display("class is not available");
end
In the above example exists fn will check whether class is available or not
I am using exists fn in my environment.
I am facing error.
*E NOTCLM – The specified name is not an item in the class
Anyone please give some guidance for that .
Regards
Muthuvenkatesh
In reply to Muthuvenkatesh:
This is invalid. “if(tr[1].exists())” you are calling the method which is not existed in transaction class. Several things that you need to do:
- transaction tr: This is dynamic array, you need create this array with specified number of elements.
For example:
tr = new[10]; // 10 elements are created
- To check element is created or not, you can compare with null.
if(tr[1] != null)
$display("class is available");
else
$display("class is not available");
Note: If you use associated array, it provides you a method “exists” to check that current element is existed in array or not.
In reply to cuonghl:
In reply to Muthuvenkatesh:
This is invalid. “if(tr[1].exists())” you are calling the method which is not existed in transaction class. Several things that you need to do:
- transaction tr: This is dynamic array, you need create this array with specified number of elements.
For example:
tr = new[10]; // 10 elements are created
- To check element is created or not, you can compare with null.
if(tr[1] != null)
$display("class is available");
else
$display("class is not available");
Note: If you use associated array, it provides you a method “exists” to check that current element is existed in array or not.
Thanks for your reply .
Is there any other function available to check the class has object or not ??
Thanks & Regards
Muthuvenkatesh
In reply to Muthuvenkatesh:
No, I think.
In reply to Muthuvenkatesh:
I think you may be confusing the difference between class variables and class objects. (please see this link for a detailed explanation). Dynamically sized arrays need to have their elements constructed before you can assign anything to them and each kind of array has different methods for construction of their elements. You can use array methods to see if the elements have been constructed depending on the kind of array:
exists() for associative arrays, and
size() for dynamic arrays and queues.
There are no methods to check if a class object actively exists. SystemVerilog guarentees its existance if a class variable has a handle to it. Any function to check for its existences would be pointless because you would need a non-null handle to call it, and you would need to check the class variable for null before calling it, and that gives you the answer you were looking for the function to return in the first place.