STYLE: use std::initializer_list instead of const char*[]

This commit is contained in:
Mark Olesen
2019-01-07 12:49:37 +01:00
parent 573a313f46
commit e7fde1dbe0
12 changed files with 35 additions and 79 deletions

View File

@ -178,8 +178,7 @@ public:
( (
const dictionary& thermoTypeDict, const dictionary& thermoTypeDict,
Table* tablePtr, Table* tablePtr,
const int nCmpt, std::initializer_list<const char*> cmptNames,
const char* cmptNames[],
const word& thermoTypeName const word& thermoTypeName
); );

View File

@ -32,8 +32,7 @@ typename Table::iterator Foam::basicThermo::lookupThermo
( (
const dictionary& thermoTypeDict, const dictionary& thermoTypeDict,
Table* tablePtr, Table* tablePtr,
const int nCmpt, std::initializer_list<const char*> cmptNames,
const char* cmptNames[],
const word& thermoTypeName const word& thermoTypeName
) )
{ {
@ -62,15 +61,19 @@ typename Table::iterator Foam::basicThermo::lookupThermo
validThermoTypeNames.size() + 1 validThermoTypeNames.size() + 1
); );
const int nCmpt = cmptNames.size();
validThermoTypeNameCmpts[0].setSize(nCmpt); validThermoTypeNameCmpts[0].setSize(nCmpt);
forAll(validThermoTypeNameCmpts[0], j)
label j = 0;
for (const char* cmptName : cmptNames)
{ {
validThermoTypeNameCmpts[0][j] = cmptNames[j]; validThermoTypeNameCmpts[0][j] = cmptName;
++j;
} }
// Split the thermo package names into their constituent parts // Split the thermo package names into their constituent parts
// Removing incompatible entries from the list // Removing incompatible entries from the list
label j = 0; j = 0;
forAll(validThermoTypeNames, i) forAll(validThermoTypeNames, i)
{ {
wordList names wordList names
@ -111,8 +114,7 @@ typename Table::iterator Foam::basicThermo::lookupThermo
if (thermoTypeDict.found("properties")) if (thermoTypeDict.found("properties"))
{ {
const int nCmpt = 4; std::initializer_list<const char*> cmptNames
const char* cmptNames[nCmpt] =
{ {
"type", "type",
"mixture", "mixture",
@ -133,15 +135,13 @@ typename Table::iterator Foam::basicThermo::lookupThermo
( (
thermoTypeDict, thermoTypeDict,
tablePtr, tablePtr,
nCmpt,
cmptNames, cmptNames,
thermoTypeName thermoTypeName
); );
} }
else else
{ {
const int nCmpt = 7; std::initializer_list<const char*> cmptNames
const char* cmptNames[nCmpt] =
{ {
"type", "type",
"mixture", "mixture",
@ -168,7 +168,6 @@ typename Table::iterator Foam::basicThermo::lookupThermo
( (
thermoTypeDict, thermoTypeDict,
tablePtr, tablePtr,
nCmpt,
cmptNames, cmptNames,
thermoTypeName thermoTypeName
); );

View File

@ -236,7 +236,7 @@ public:
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
#include "SpecieMixture.C" #include "SpecieMixture.C"

View File

@ -26,12 +26,6 @@ License
#include "egrMixture.H" #include "egrMixture.H"
#include "fvMesh.H" #include "fvMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ThermoType>
const char* Foam::egrMixture<ThermoType>::specieNames_[3] = {"ft", "b", "egr"};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ThermoType> template<class ThermoType>
@ -45,7 +39,7 @@ Foam::egrMixture<ThermoType>::egrMixture
basicCombustionMixture basicCombustionMixture
( (
thermoDict, thermoDict,
speciesTable(nSpecies_, specieNames_), speciesTable({"ft", "b", "egr"}),
mesh, mesh,
phaseName phaseName
), ),

View File

@ -28,7 +28,7 @@ Group
grpReactionThermophysicalMixtures grpReactionThermophysicalMixtures
Description Description
Foam::egrMixture The egr mixture contains species ("ft", "b", "egr").
SourceFiles SourceFiles
egrMixture.C egrMixture.C
@ -54,10 +54,7 @@ class egrMixture
: :
public basicCombustionMixture public basicCombustionMixture
{ {
// Private data // Private Data
static const int nSpecies_ = 3;
static const char* specieNames_[3];
dimensionedScalar stoicRatio_; dimensionedScalar stoicRatio_;
@ -190,7 +187,7 @@ public:
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
#include "egrMixture.C" #include "egrMixture.C"

View File

@ -26,12 +26,6 @@ License
#include "homogeneousMixture.H" #include "homogeneousMixture.H"
#include "fvMesh.H" #include "fvMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ThermoType>
const char* Foam::homogeneousMixture<ThermoType>::specieNames_[1] = {"b"};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ThermoType> template<class ThermoType>
@ -45,7 +39,7 @@ Foam::homogeneousMixture<ThermoType>::homogeneousMixture
basicCombustionMixture basicCombustionMixture
( (
thermoDict, thermoDict,
speciesTable(nSpecies_, specieNames_), speciesTable({"b"}),
mesh, mesh,
phaseName phaseName
), ),

View File

@ -28,7 +28,7 @@ Group
grpReactionThermophysicalMixtures grpReactionThermophysicalMixtures
Description Description
Foam::homogeneousMixture The homogeneous mixture contains species ("b").
SourceFiles SourceFiles
homogeneousMixture.C homogeneousMixture.C
@ -54,10 +54,7 @@ class homogeneousMixture
: :
public basicCombustionMixture public basicCombustionMixture
{ {
// Private data // Private Data
static const int nSpecies_ = 1;
static const char* specieNames_[1];
ThermoType reactants_; ThermoType reactants_;
ThermoType products_; ThermoType products_;
@ -148,7 +145,7 @@ public:
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
#include "homogeneousMixture.C" #include "homogeneousMixture.C"

View File

@ -26,16 +26,6 @@ License
#include "inhomogeneousMixture.H" #include "inhomogeneousMixture.H"
#include "fvMesh.H" #include "fvMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ThermoType>
const char* Foam::inhomogeneousMixture<ThermoType>::specieNames_[2] =
{
"ft",
"b"
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ThermoType> template<class ThermoType>
@ -49,7 +39,7 @@ Foam::inhomogeneousMixture<ThermoType>::inhomogeneousMixture
basicCombustionMixture basicCombustionMixture
( (
thermoDict, thermoDict,
speciesTable(nSpecies_, specieNames_), speciesTable({"ft", "b"}),
mesh, mesh,
phaseName phaseName
), ),

View File

@ -28,7 +28,7 @@ Group
grpReactionThermophysicalMixtures grpReactionThermophysicalMixtures
Description Description
Foam::inhomogeneousMixture The inhomogeneous mixture contains species ("ft", "b").
SourceFiles SourceFiles
inhomogeneousMixture.C inhomogeneousMixture.C
@ -54,10 +54,7 @@ class inhomogeneousMixture
: :
public basicCombustionMixture public basicCombustionMixture
{ {
// Private data // Private Data
static const int nSpecies_ = 2;
static const char* specieNames_[2];
dimensionedScalar stoicRatio_; dimensionedScalar stoicRatio_;
@ -182,7 +179,7 @@ public:
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
#include "inhomogeneousMixture.C" #include "inhomogeneousMixture.C"

View File

@ -26,17 +26,6 @@ License
#include "veryInhomogeneousMixture.H" #include "veryInhomogeneousMixture.H"
#include "fvMesh.H" #include "fvMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ThermoType>
const char* Foam::veryInhomogeneousMixture<ThermoType>::specieNames_[3] =
{
"ft",
"fu",
"b"
};
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ThermoType> template<class ThermoType>
@ -50,7 +39,7 @@ Foam::veryInhomogeneousMixture<ThermoType>::veryInhomogeneousMixture
basicCombustionMixture basicCombustionMixture
( (
thermoDict, thermoDict,
speciesTable(nSpecies_, specieNames_), speciesTable({"ft", "fu", "b"}),
mesh, mesh,
phaseName phaseName
), ),

View File

@ -28,7 +28,7 @@ Group
grpReactionThermophysicalMixtures grpReactionThermophysicalMixtures
Description Description
Foam::veryInhomogeneousMixture The very inhomogeneous mixture contains species ("ft", "fu", "b").
SourceFiles SourceFiles
veryInhomogeneousMixture.C veryInhomogeneousMixture.C
@ -54,10 +54,7 @@ class veryInhomogeneousMixture
: :
public basicCombustionMixture public basicCombustionMixture
{ {
// Private data // Private Data
static const int nSpecies_ = 3;
static const char* specieNames_[3];
dimensionedScalar stoicRatio_; dimensionedScalar stoicRatio_;
@ -183,7 +180,7 @@ public:
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
#include "veryInhomogeneousMixture.C" #include "veryInhomogeneousMixture.C"

View File

@ -50,8 +50,7 @@ Foam::basicSolidChemistryModel::New(solidReactionThermo& thermo)
Info<< "Selecting chemistry type " << chemistryTypeDict << endl; Info<< "Selecting chemistry type " << chemistryTypeDict << endl;
const int nCmpt = 13; std::initializer_list<const char*> cmptNames
const char* cmptNames[nCmpt] =
{ {
"chemistrySolver", "chemistrySolver",
"chemistryThermo", "chemistryThermo",
@ -136,10 +135,14 @@ Foam::basicSolidChemistryModel::New(solidReactionThermo& thermo)
validChemistryTypeNames.size() + 1 validChemistryTypeNames.size() + 1
); );
const int nCmpt = cmptNames.size();
validChemistryTypeNameCmpts[0].setSize(nCmpt); validChemistryTypeNameCmpts[0].setSize(nCmpt);
forAll(validChemistryTypeNameCmpts[0], j)
label j = 0;
for (const char* cmptName : cmptNames)
{ {
validChemistryTypeNameCmpts[0][j] = cmptNames[j]; validChemistryTypeNameCmpts[0][j] = cmptName;
++j;
} }
// Split the thermo package names into their constituent parts // Split the thermo package names into their constituent parts