Skip to content

Commit

Permalink
Merge pull request #2819 from N-Dekker/RegisterFactoryOnce
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex authored Oct 21, 2021
2 parents abb6b68 + fb47ffa commit da7f448
Show file tree
Hide file tree
Showing 39 changed files with 59 additions and 295 deletions.
19 changes: 19 additions & 0 deletions Modules/Core/Common/include/itkObjectFactoryBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,25 @@ class ITKCommon_EXPORT ObjectFactoryBase : public Object
CreateObjectFunctionBase::Pointer m_CreateObject;
};

/** Registers the specified internal factory only once, even when `RegisterInternalFactoryOnce<TFactory>()` is called
* multiple times (possibly even by multiple threads) for the very same factory. */
template <typename TFactory>
static void
RegisterInternalFactoryOnce()
{
struct FactoryRegistration
{};

// Factory registration, made thread-safe by "magic statics" (as introduced with C++11).
static const FactoryRegistration staticFactoryRegistration = [] {
RegisterFactoryInternal(TFactory::New());
return FactoryRegistration{};
}();

(void)staticFactoryRegistration;
}


protected:
void
PrintSelf(std::ostream & os, Indent indent) const override;
Expand Down
9 changes: 1 addition & 8 deletions Modules/IO/BMP/src/itkBMPImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ BMPImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool BMPImageIOFactoryHasBeenRegistered;

void ITKIOBMP_EXPORT
BMPImageIOFactoryRegister__Private()
{
if (!BMPImageIOFactoryHasBeenRegistered)
{
BMPImageIOFactoryHasBeenRegistered = true;
BMPImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<BMPImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/BioRad/src/itkBioRadImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,10 @@ BioRadImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool BioRadImageIOFactoryHasBeenRegistered;

void ITKIOBioRad_EXPORT
BioRadImageIOFactoryRegister__Private()
{
if (!BioRadImageIOFactoryHasBeenRegistered)
{
BioRadImageIOFactoryHasBeenRegistered = true;
BioRadImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<BioRadImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/Bruker/src/itkBruker2dseqImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,9 @@ Bruker2dseqImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool Bruker2dseqImageIOFactoryHasBeenRegistered;

void ITKIOBruker_EXPORT
Bruker2dseqImageIOFactoryRegister__Private()
{
if (!Bruker2dseqImageIOFactoryHasBeenRegistered)
{
Bruker2dseqImageIOFactoryHasBeenRegistered = true;
Bruker2dseqImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<Bruker2dseqImageIOFactory>();
}
} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/DCMTK/src/itkDCMTKImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ DCMTKImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool DCMTKImageIOFactoryHasBeenRegistered;

void ITKIODCMTK_EXPORT
DCMTKImageIOFactoryRegister__Private()
{
if (!DCMTKImageIOFactoryHasBeenRegistered)
{
DCMTKImageIOFactoryHasBeenRegistered = true;
DCMTKImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<DCMTKImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/GDCM/src/itkGDCMImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ GDCMImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool GDCMImageIOFactoryHasBeenRegistered;

void ITKIOGDCM_EXPORT
GDCMImageIOFactoryRegister__Private()
{
if (!GDCMImageIOFactoryHasBeenRegistered)
{
GDCMImageIOFactoryHasBeenRegistered = true;
GDCMImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<GDCMImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/GE/src/itkGE4ImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ GE4ImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool GE4ImageIOFactoryHasBeenRegistered;

void ITKIOGE_EXPORT
GE4ImageIOFactoryRegister__Private()
{
if (!GE4ImageIOFactoryHasBeenRegistered)
{
GE4ImageIOFactoryHasBeenRegistered = true;
GE4ImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<GE4ImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/GE/src/itkGE5ImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ GE5ImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool GE5ImageIOFactoryHasBeenRegistered;

void ITKIOGE_EXPORT
GE5ImageIOFactoryRegister__Private()
{
if (!GE5ImageIOFactoryHasBeenRegistered)
{
GE5ImageIOFactoryHasBeenRegistered = true;
GE5ImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<GE5ImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/GE/src/itkGEAdwImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ GEAdwImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool GEAdwImageIOFactoryHasBeenRegistered;

void ITKIOGE_EXPORT
GEAdwImageIOFactoryRegister__Private()
{
if (!GEAdwImageIOFactoryHasBeenRegistered)
{
GEAdwImageIOFactoryHasBeenRegistered = true;
GEAdwImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<GEAdwImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/GIPL/src/itkGiplImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ GiplImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool GiplImageIOFactoryHasBeenRegistered;

void ITKIOGIPL_EXPORT
GiplImageIOFactoryRegister__Private()
{
if (!GiplImageIOFactoryHasBeenRegistered)
{
GiplImageIOFactoryHasBeenRegistered = true;
GiplImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<GiplImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/HDF5/src/itkHDF5ImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,10 @@ HDF5ImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool HDF5ImageIOFactoryHasBeenRegistered;

void ITKIOHDF5_EXPORT
HDF5ImageIOFactoryRegister__Private()
{
if (!HDF5ImageIOFactoryHasBeenRegistered)
{
HDF5ImageIOFactoryHasBeenRegistered = true;
HDF5ImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<HDF5ImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/JPEG/src/itkJPEGImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ JPEGImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool JPEGImageIOFactoryHasBeenRegistered;

void ITKIOJPEG_EXPORT
JPEGImageIOFactoryRegister__Private()
{
if (!JPEGImageIOFactoryHasBeenRegistered)
{
JPEGImageIOFactoryHasBeenRegistered = true;
JPEGImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<JPEGImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/JPEG2000/src/itkJPEG2000ImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,10 @@ JPEG2000ImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool JPEG2000ImageIOFactoryHasBeenRegistered;

void ITKIOJPEG2000_EXPORT
JPEG2000ImageIOFactoryRegister__Private()
{
if (!JPEG2000ImageIOFactoryHasBeenRegistered)
{
JPEG2000ImageIOFactoryHasBeenRegistered = true;
JPEG2000ImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<JPEG2000ImageIOFactory>();
}


Expand Down
9 changes: 1 addition & 8 deletions Modules/IO/LSM/src/itkLSMImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,10 @@ LSMImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool LSMImageIOFactoryHasBeenRegistered;

void ITKIOLSM_EXPORT
LSMImageIOFactoryRegister__Private()
{
if (!LSMImageIOFactoryHasBeenRegistered)
{
LSMImageIOFactoryHasBeenRegistered = true;
LSMImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<LSMImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/MINC/src/itkMINCImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,10 @@ MINCImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool MINCImageIOFactoryHasBeenRegistered;

void ITKIOMINC_EXPORT
MINCImageIOFactoryRegister__Private()
{
if (!MINCImageIOFactoryHasBeenRegistered)
{
MINCImageIOFactoryHasBeenRegistered = true;
MINCImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<MINCImageIOFactory>();
}

} // end namespace itk
9 changes: 1 addition & 8 deletions Modules/IO/MRC/src/itkMRCImageIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,10 @@ MRCImageIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.

static bool MRCImageIOFactoryHasBeenRegistered;

void ITKIOMRC_EXPORT
MRCImageIOFactoryRegister__Private()
{
if (!MRCImageIOFactoryHasBeenRegistered)
{
MRCImageIOFactoryHasBeenRegistered = true;
MRCImageIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<MRCImageIOFactory>();
}

} // end namespace itk
8 changes: 1 addition & 7 deletions Modules/IO/MeshBYU/src/itkBYUMeshIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,10 @@ BYUMeshIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.
static bool BYUMeshIOFactoryHasBeenRegistered;

void ITKIOMeshBYU_EXPORT
BYUMeshIOFactoryRegister__Private()
{
if (!BYUMeshIOFactoryHasBeenRegistered)
{
BYUMeshIOFactoryHasBeenRegistered = true;
BYUMeshIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<BYUMeshIOFactory>();
}

} // end namespace itk
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,10 @@ FreeSurferAsciiMeshIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.
static bool FreeSurferAsciiMeshIOFactoryHasBeenRegistered;

void ITKIOMeshFreeSurfer_EXPORT
FreeSurferAsciiMeshIOFactoryRegister__Private()
{
if (!FreeSurferAsciiMeshIOFactoryHasBeenRegistered)
{
FreeSurferAsciiMeshIOFactoryHasBeenRegistered = true;
FreeSurferAsciiMeshIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<FreeSurferAsciiMeshIOFactory>();
}

} // end namespace itk
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,10 @@ FreeSurferBinaryMeshIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.
static bool FreeSurferBinaryMeshIOFactoryHasBeenRegistered;

void ITKIOMeshFreeSurfer_EXPORT
FreeSurferBinaryMeshIOFactoryRegister__Private()
{
if (!FreeSurferBinaryMeshIOFactoryHasBeenRegistered)
{
FreeSurferBinaryMeshIOFactoryHasBeenRegistered = true;
FreeSurferBinaryMeshIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<FreeSurferBinaryMeshIOFactory>();
}

} // end namespace itk
8 changes: 1 addition & 7 deletions Modules/IO/MeshGifti/src/itkGiftiMeshIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,10 @@ GiftiMeshIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.
static bool GiftiMeshIOFactoryHasBeenRegistered;

void ITKIOMeshGifti_EXPORT
GiftiMeshIOFactoryRegister__Private()
{
if (!GiftiMeshIOFactoryHasBeenRegistered)
{
GiftiMeshIOFactoryHasBeenRegistered = true;
GiftiMeshIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<GiftiMeshIOFactory>();
}

} // end namespace itk
8 changes: 1 addition & 7 deletions Modules/IO/MeshOBJ/src/itkOBJMeshIOFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,10 @@ OBJMeshIOFactory::GetDescription() const

// Undocumented API used to register during static initialization.
// DO NOT CALL DIRECTLY.
static bool OBJMeshIOFactoryHasBeenRegistered;

void ITKIOMeshOBJ_EXPORT
OBJMeshIOFactoryRegister__Private()
{
if (!OBJMeshIOFactoryHasBeenRegistered)
{
OBJMeshIOFactoryHasBeenRegistered = true;
OBJMeshIOFactory::RegisterOneFactory();
}
ObjectFactoryBase::RegisterInternalFactoryOnce<OBJMeshIOFactory>();
}

} // end namespace itk
Loading

0 comments on commit da7f448

Please sign in to comment.