# General type input of function

**URL:** <https://verificationacademy.com/forums/t/general-type-input-of-function/32585>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, function\
**Created:** [November 22, 2016, 3:25pm UTC](https://verificationacademy.com/forums/t/general-type-input-of-function/32585 "2016-11-22T15:25:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saritr](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@saritr](https://verificationacademy.com/forums/u/saritr)\
**Post date:** [November 22, 2016, 3:25pm UTC](https://verificationacademy.com/forums/t/general-type-input-of-function/32585/1 "2016-11-22T15:25:49Z")

</div>

I have the following code in my test\_base:

```verilog
class test_base extends uvm_test;
   //factory registration
   `uvm_component_utils(test_base)
     
   //internal decleration
   girobo2_env grb_env_i;

   //configuration objects:
   grb2_env_config m_env_cfg;
   axi_agent_config m_axi_agent_cfg;

   .........

   //build_phase
    // Create tx_agent agent configuration object
    m_tx_agent_cfg = tx_agent_config::type_id::create("m_tx_agent_cfg");
    if(!uvm_config_db #(virtual tx_interface)::get(this, "", "tx_vif", m_tx_agent_cfg.tx_vif)) 
	 `uvm_error("RESOURCE_ERROR", "tx_interface virtual interface not found")
      m_env_cfg.m_tx_agent_cfg = m_tx_agent_cfg; 
      // Call function to configure the tx agent
      configure_tx_agent(m_tx_agent_cfg);
   //Create axi_agent agent configuration object
   m_axi_agent_cfg = axi_agent_config::type_id::create("m_axi_agent_cfg");
   if(!uvm_config_db #(virtual axi_interface)::get(this, "", "axi_vif", m_axi_agent_cfg.axi_vif) 
	`uvm_error("RESOURCE_ERROR", "axi_interface virtual interface not found")
   m_env_cfg.m_axi_agent_cfg = m_axi_agent_cfg; 
   // Call function to configure the axi agent
   configure_axi_agent(m_axi_agent_cfg);

   //--------------------------------------------------------------------
	 // configure_tx_agent
   //--------------------------------------------------------------------
   // Convenience function to configure the agent
   // This can be overloaded by extensions to this base class
   virtual function void configure_tx_agent (tx_agent_config cfg);
      cfg.is_active = UVM_PASSIVE;	  
   endfunction: configure_tx_agent
    //--------------------------------------------------------------------
   // configure_my_agent
   //--------------------------------------------------------------------
   // Convenience function to configure the agent
   // This can be overloaded by extensions to this base class
   virtual function void configure_axi_agent (axi_agent_config cfg);
      cfg.is_active = UVM_PASSIVE;	  
   endfunction: configure_my_agent
	 

endclass: test_base

```

Instead of creating 2 function which do the same Is there an option to use general function named configure\_my\_agent and define the type of the input of the configure\_my\_agent function general (like template in c++ for example.

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [November 22, 2016, 7:30pm UTC](https://verificationacademy.com/forums/t/general-type-input-of-function/32585/2 "2016-11-22T19:30:04Z")

</div>

_In reply to [saritr](https://verificationacademy.com/forums/t/general-type-input-of-function/32585):_  
The UVM factory provides a mechanism used for specifying type overrides that can also be used to check the type.

The static method   
axi\_agent\_config::type\_id::get\_type() returns a handle to a proxy singleton object that represents the type of   
axi\_agent\_config. You can call the virtual   
uvm\_object method   
get\_cobject\_type() that returns a handle to a proxy singleton object that represents the type of the _actual_ object passed to cfg. So you can write

```verilog
if (axi_agent_config::type_id::get_type() == cfg.get_object_type() )
   // then you have a matching base class object
else if (axi_extended_agent_cdg::type_id::get_type() == cfg.get_object_type() )
   // then you have a matching extended object

```

---

<div class="post-metadata">

**Author:** ![saritr](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@saritr](https://verificationacademy.com/forums/u/saritr)\
**Post date:** [November 27, 2016, 2:43pm UTC](https://verificationacademy.com/forums/t/general-type-input-of-function/32585/3 "2016-11-27T14:43:19Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/general-type-input-of-function/32585/2):_

I edited the question (not suer that your answer answers whst I wantes).  
Please take a look.
