design guidance - template approach

ma740988_at_pegasus.cc.ucf.edu
Date: 02/28/05


Date: 27 Feb 2005 17:47:12 -0800


Generally I try to post compilable code but in this case I'll violate
that rule.

So now consider:

sg_rcvr::sg_rcvr(
       size_t buffer_size
  )
  , status(STARLINK_SUCCESS)
  , data_buf_virtual_addr(0)
  , data_buf_pci_addr(0)
  , data_buf_physical_addr(0)
{
  data_buf_virtual_addr = (U32* ) cacheDmaMalloc(buffer_size)
  data_buf_physical_addr = (U32 ) CACHE_DMA_VIRT_TO_PHYS
((void*)data_buf_virtual_addr);

#if ((HOST_BOARD==DY4181) || (HOST_BOARD==DY4179))
      data_buf_pci_addr = (U32 )data_buf_physical_addr;
#else
    sysLocalToBusAdrs(
          0, (char *)
          (char*) data_buf_physical_addr,
          (char**)data_buf_pci_addr
     );
#endif
  // more stuff..
}

Where:
U32 is typedef'd i.e.

typedef unsigned int U32;

and

data_buf_virtual_addr is defined as:
  U32* data_buf_virtual_addr;

data_buf_pci_addr and data_buf_physical_addr is defined as:
  U32 data_buf_pci_addr;
  U32 data_buf_physical_addr;

It's quite possible that the user will desire a long as opposed to the
hard coded U32 and the pointer to U32.
I pondered a function template but that - unless I'm missing something
- would require the user to call that member function which I'm not a
fan of.

In other words, with the current approach, the cast to U32 is handled
in the constructor. If I use a member function template. This would
require the user to call that member function with the appropriate type
which for this purpose is undesirable. My only option is a templated
constructor?

Thanks in advance