Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Longer term solutions to DataContainer data type issue needed. #1193

Open
evgueni-ovtchinnikov opened this issue May 11, 2023 · 2 comments · May be fixed by #1210
Open

Longer term solutions to DataContainer data type issue needed. #1193

evgueni-ovtchinnikov opened this issue May 11, 2023 · 2 comments · May be fixed by #1210
Assignees
Milestone

Comments

@evgueni-ovtchinnikov
Copy link
Contributor

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 a void* to these methods that is cast to float* or complex_float_t* in the respective methods of the derived classes.

Possible longer term fixes:

  • use the largest type in the C++ interface (i.e. std::complex) as opposed to void *. Easy, but probably unexpected.
  • use std::any (and if needed with a virtual function std::any DataContainer::get_zero_data_element() or so). More complicated and not very elegant.
  • template DataContainer if possible.
@evgueni-ovtchinnikov evgueni-ovtchinnikov added this to the v3.6 milestone May 11, 2023
@evgueni-ovtchinnikov evgueni-ovtchinnikov self-assigned this May 11, 2023
@evgueni-ovtchinnikov
Copy link
Contributor Author

@KrisThielemans sorry not sure I understand your last suggestion:

  • put a class in between 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.

@KrisThielemans
Copy link
Member

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;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants