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

Replace READ_ELEMENT_IF with variadic template, move functions into unnamed namespace #67

Conversation

N-Dekker
Copy link
Collaborator

@N-Dekker N-Dekker commented Aug 16, 2024

Just some style improvements:

  • Replaced the original READ_ELEMENT_IF macro with a variadic template, TryToReadFromStore.
  • Moved the functions tensorstoreToITKComponentType and itkToTensorstoreComponentType into an unnamed namespace

The functions `tensorstoreToITKComponentType` and `itkToTensorstoreComponentType`
are only used internally in their cxx file.

Following C++ Core Guidelines, May 11, 2024, "Use an unnamed (anonymous)
namespace for all internal/non-exported entities",
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf22-use-an-unnamed-anonymous-namespace-for-all-internalnon-exported-entities
@N-Dekker N-Dekker force-pushed the ReadFromStore-variadic-template branch from 3c57d75 to 4a90bbc Compare August 16, 2024 18:41
@N-Dekker N-Dekker changed the title STYLE: Use a variadic template to read from store Replace READ_ELEMENT_IF with variadic template, move functions into unnamed namespace Aug 16, 2024
This line of code can just be removed, as was confirmed by Tom Birdsong at
InsightSoftwareConsortium#67 (comment)
Replaced the original `READ_ELEMENT_IF` macro with a variadic template, using a
C++17 fold-expression.

Following C++ Core Guidelines, May 11, 2024, "Don’t use macros for program text
manipulation", https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-macros
@N-Dekker N-Dekker force-pushed the ReadFromStore-variadic-template branch from 4a90bbc to 77a2f45 Compare August 16, 2024 19:36
@N-Dekker N-Dekker marked this pull request as ready for review August 16, 2024 21:31
Copy link
Member

@thewtex thewtex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@N-Dekker nice, thanks!

@thewtex thewtex merged commit ccf414f into InsightSoftwareConsortium:main Aug 21, 2024
18 checks passed
const ImageIORegion & storeIORegion,
void * buffer)
{
return (ReadFromStoreIfTypesMatch<TPixel>(componentType, store, storeIORegion, buffer) || ...);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for merging, Matt! The most interesting part of this commit, IMhO, is the fold expression above here, which expands to something like (in pseudo code):

return Read<int8_t>() || Read<uint8_t>() || ... || Read<float>() || Read<double>();

N-Dekker added a commit to N-Dekker/ITKIOOMEZarrNGFF that referenced this pull request Aug 21, 2024
Replaced the original `ELEMENT_WRITE` macro with a variadic template, using a
C++17 fold-expression.

Follow-up to pull request InsightSoftwareConsortium#67
commit 77a2f45
"STYLE: Replace READ_ELEMENT_IF with TryToReadFromStore variadic template"
N-Dekker added a commit to N-Dekker/ITKIOOMEZarrNGFF that referenced this pull request Aug 21, 2024
Replaced the original `ELEMENT_WRITE` macro with a variadic template, using a
C++17 fold-expression.

Follow-up to pull request InsightSoftwareConsortium#67
commit 77a2f45
"STYLE: Replace READ_ELEMENT_IF with TryToReadFromStore variadic template"
N-Dekker added a commit to N-Dekker/ITKIOOMEZarrNGFF that referenced this pull request Aug 22, 2024
Replaced the original `ELEMENT_WRITE` macro with a variadic template, using a
C++17 fold-expression.

Follow-up to pull request InsightSoftwareConsortium#67
commit 77a2f45
"STYLE: Replace READ_ELEMENT_IF with TryToReadFromStore variadic template"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants