Skip to content

Commit

Permalink
STYLE: Add ReadParameterFiles and WriteParameterFiles to ParameterObject
Browse files Browse the repository at this point in the history
Deprecated the old ReadParameterFile and WriteParameterFile overloads that support multiple files.

Follow-up to:

 - pull request #848 commit 38b6152 "Add GetParameterMaps and SetParameterMaps to ParameterObject"
 - pull request #862 commit 0afcc3b "Deprecate Get/SetParameterMap in favor of Get/SetParameterMaps"
  • Loading branch information
N-Dekker committed May 23, 2023
1 parent f56dd43 commit c24eaeb
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 34 deletions.
81 changes: 51 additions & 30 deletions Core/Main/elxParameterObject.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,20 @@ ParameterObject::ReadParameterFile(const ParameterFileNameType & parameterFileNa
}


// Deprecated, superseded by ReadParameterFiles.
void
ParameterObject::ReadParameterFile(const ParameterFileNameVectorType & parameterFileNameVector)
{
this->ReadParameterFiles(parameterFileNameVector);
}


/**
* ********************* ReadParameterFile *********************
* ********************* ReadParameterFiles *********************
*/

void
ParameterObject::ReadParameterFile(const ParameterFileNameVectorType & parameterFileNameVector)
ParameterObject::ReadParameterFiles(const ParameterFileNameVectorType & parameterFileNameVector)
{
if (parameterFileNameVector.empty())
{
Expand Down Expand Up @@ -244,23 +252,14 @@ ParameterObject::AddParameterFile(const ParameterFileNameType & parameterFileNam
*/


// Deprecated, superseded by WriteParameterFiles.
void
ParameterObject::WriteParameterFile() const
{
ParameterFileNameVectorType parameterFileNameVector;
for (unsigned int i = 0; i < m_ParameterMaps.size(); ++i)
{
parameterFileNameVector.push_back("ParametersFile." + std::to_string(i) + ".txt");
}

Self::WriteParameterFile(m_ParameterMaps, parameterFileNameVector);
this->WriteParameterFiles();
}


/**
* ********************* WriteParameterFile *********************
*/

void
ParameterObject::WriteParameterFile(const ParameterMapType & parameterMap,
const ParameterFileNameType & parameterFileName)
Expand Down Expand Up @@ -322,10 +321,6 @@ ParameterObject::WriteParameterFile(const ParameterMapType & parameterMap,
}


/**
* ********************* WriteParameterFile *********************
*/

void
ParameterObject::WriteParameterFile(const ParameterFileNameType & parameterFileName) const
{
Expand All @@ -336,22 +331,53 @@ ParameterObject::WriteParameterFile(const ParameterFileNameType & parameterFileN

if (m_ParameterMaps.size() > 1)
{
itkExceptionMacro(
<< "Error writing to disk: The number of parameter maps (" << m_ParameterMaps.size()
<< ") does not match the number of provided filenames (1). Please provide a vector of filenames.");
itkExceptionMacro(<< "Error writing to disk: The number of parameter maps (" << m_ParameterMaps.size()
<< ") does not match the number of provided filenames (1). Please call WriteParameterFiles "
"instead, and provide a vector of filenames.");
}

this->WriteParameterFile(m_ParameterMaps[0], parameterFileName);
}


// Deprecated, superseded by WriteParameterFiles.
void
ParameterObject::WriteParameterFile(const ParameterMapVectorType & parameterMapVector,
const ParameterFileNameVectorType & parameterFileNameVector)
{
Self::WriteParameterFiles(parameterMapVector, parameterFileNameVector);
}


// Deprecated, superseded by WriteParameterFiles.
void
ParameterObject::WriteParameterFile(const ParameterFileNameVectorType & parameterFileNameVector) const
{
this->WriteParameterFiles(parameterFileNameVector);
}


/**
* ********************* WriteParameterFile *********************
* ********************* WriteParameterFiles *********************
*/


void
ParameterObject::WriteParameterFile(const ParameterMapVectorType & parameterMapVector,
const ParameterFileNameVectorType & parameterFileNameVector)
ParameterObject::WriteParameterFiles() const
{
ParameterFileNameVectorType parameterFileNameVector;
for (unsigned int i = 0; i < m_ParameterMaps.size(); ++i)
{
parameterFileNameVector.push_back("ParametersFile." + std::to_string(i) + ".txt");
}

Self::WriteParameterFiles(m_ParameterMaps, parameterFileNameVector);
}


void
ParameterObject::WriteParameterFiles(const ParameterMapVectorType & parameterMapVector,
const ParameterFileNameVectorType & parameterFileNameVector)
{
if (parameterMapVector.size() != parameterFileNameVector.size())
{
Expand All @@ -375,15 +401,10 @@ ParameterObject::WriteParameterFile(const ParameterMapVectorType & paramete
}


/**
* ********************* WriteParameterFile *********************
*/


void
ParameterObject::WriteParameterFile(const ParameterFileNameVectorType & parameterFileNameVector) const
ParameterObject::WriteParameterFiles(const ParameterFileNameVectorType & parameterFileNameVector) const
{
Self::WriteParameterFile(m_ParameterMaps, parameterFileNameVector);
Self::WriteParameterFiles(m_ParameterMaps, parameterFileNameVector);
}


Expand Down
27 changes: 23 additions & 4 deletions Core/Main/elxParameterObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,41 @@ class ParameterObject : public itk::DataObject
/* Read/Write parameter file or multiple parameter files to/from disk. */
void
ReadParameterFile(const ParameterFileNameType & parameterFileName);
void

[[deprecated("Instead of calling this overload, please call ReadParameterFiles")]] void
ReadParameterFile(const ParameterFileNameVectorType & parameterFileNameVector);

void
AddParameterFile(const ParameterFileNameType & parameterFileName);
ReadParameterFiles(const ParameterFileNameVectorType & parameterFileNameVector);

void
AddParameterFile(const ParameterFileNameType & parameterFileName);

[[deprecated("Instead of calling this overload, please call WriteParameterFiles")]] void
WriteParameterFile() const;

static void
WriteParameterFile(const ParameterMapType & parameterMap, const ParameterFileNameType & parameterFileName);
void
WriteParameterFile(const ParameterFileNameType & parameterFileName) const;
void

[[deprecated("Instead of calling this overload, please call WriteParameterFiles")]] void
WriteParameterFile(const ParameterFileNameVectorType & parameterFileNameVector) const;
static void

[[deprecated("Instead of calling this overload, please call WriteParameterFiles")]] static void
WriteParameterFile(const ParameterMapVectorType & parameterMapVector,
const ParameterFileNameVectorType & parameterFileNameVector);

void
WriteParameterFiles() const;

void
WriteParameterFiles(const ParameterFileNameVectorType & parameterFileNameVector) const;

static void
WriteParameterFiles(const ParameterMapVectorType & parameterMapVector,
const ParameterFileNameVectorType & parameterFileNameVector);

/* Get preconfigured parameter maps. */
static const ParameterMapType
GetDefaultParameterMap(const std::string & transformName,
Expand Down

0 comments on commit c24eaeb

Please sign in to comment.