Open evgueni-ovtchinnikov opened 1 year ago
@KrisThielemans sorry not sure I understand your last suggestion:
RealDataContainer
and ComplexDataContainer
, which have the intuitive signatures, as well as the generic ones, which do all the ugly casting, such that the derived classes don't need to.Something like this is probably better than what I had originally suggested as it needs only a template class, not 2 of them
template <typename DataType>
class DataContainerWithDataType: public DataContainer
{
public:
...
virtual DataType sum() const = 0;
virtual void sum(void * ptr) const override
{
const DataType ret = this->sum();
*static_cast<DataType *>(ptr) = ret;
}
class STIRDataContainer : public DataContainerWithDataType<float>
{
private:
typedef DataContainerWithDataType<float> base_type;
public:
// make sure we get the generic version as well
using base_type::sum;
virtual float sum() const override;
}
Some
DataContainer
methods compute a value that is complex for Gadgetron containers and real for other containers, and so, the variable that would store such a value cannot be explicitly declared in this abstract base class. Currently, this issue is quick-fixed by passing avoid*
to these methods that is cast tofloat*
orcomplex_float_t*
in the respective methods of the derived classes.Possible longer term fixes:
void *
. Easy, but probably unexpected.std::any
(and if needed with a virtual functionstd::any DataContainer::get_zero_data_element()
or so). More complicated and not very elegant.DataContainer
if possible.