Replace EnumOption with EnumerationArrayOption
[alexxy/gromacs.git] / src / gromacs / trajectoryanalysis / modules / rdf.cpp
index bb2f6249198ee86fafcefdebb7dc20bfe6c9a9ae..438ba85a8704f783f062b7226fab9403d370f65a 100644 (file)
@@ -92,23 +92,27 @@ namespace
  */
 
 //! Normalization for the computed distribution.
-enum Normalization
+enum class Normalization : int
 {
-    Normalization_Rdf,
-    Normalization_NumberDensity,
-    Normalization_None
+    Rdf,
+    NumberDensity,
+    None,
+    Count
 };
 //! String values corresponding to Normalization.
-const char* const c_NormalizationEnum[] = { "rdf", "number_density", "none" };
+const EnumerationArray<Normalization, const char*> c_normalizationNames = {
+    { "rdf", "number_density", "none" }
+};
 //! Whether to compute RDF wrt. surface of the reference group.
-enum SurfaceType
+enum class SurfaceType : int
 {
-    SurfaceType_None,
-    SurfaceType_Molecule,
-    SurfaceType_Residue
+    None,
+    Molecule,
+    Residue,
+    Count
 };
 //! String values corresponding to SurfaceType.
-const char* const c_SurfaceEnum[] = { "no", "mol", "res" };
+const EnumerationArray<SurfaceType, const char*> c_surfaceTypeNames = { { "no", "mol", "res" } };
 
 /*! \brief
  * Implements `gmx rdf` trajectory analysis module.
@@ -202,14 +206,14 @@ private:
 };
 
 Rdf::Rdf() :
-    surface_(SurfaceType_None),
+    surface_(SurfaceType::None),
     pairCounts_(new AnalysisDataSimpleHistogramModule()),
     normAve_(new AnalysisDataAverageModule()),
     localTop_(nullptr),
     binwidth_(0.002),
     cutoff_(0.0),
     rmax_(0.0),
-    normalization_(Normalization_Rdf),
+    normalization_(Normalization::Rdf),
     bNormalizationSet_(false),
     bXY_(false),
     bExclusions_(false),
@@ -297,7 +301,7 @@ void Rdf::initOptions(IOptionsContainer* options, TrajectoryAnalysisSettings* se
 
     options->addOption(DoubleOption("bin").store(&binwidth_).description("Bin width (nm)"));
     options->addOption(EnumOption<Normalization>("norm")
-                               .enumValue(c_NormalizationEnum)
+                               .enumValue(c_normalizationNames)
                                .store(&normalization_)
                                .storeIsSet(&bNormalizationSet_)
                                .description("Normalization"));
@@ -311,7 +315,7 @@ void Rdf::initOptions(IOptionsContainer* options, TrajectoryAnalysisSettings* se
             DoubleOption("rmax").store(&rmax_).description("Largest distance (nm) to calculate"));
 
     options->addOption(EnumOption<SurfaceType>("surf")
-                               .enumValue(c_SurfaceEnum)
+                               .enumValue(c_surfaceTypeNames)
                                .store(&surface_)
                                .description("RDF with respect to the surface of the reference"));
 
@@ -323,15 +327,15 @@ void Rdf::initOptions(IOptionsContainer* options, TrajectoryAnalysisSettings* se
 
 void Rdf::optionsFinished(TrajectoryAnalysisSettings* settings)
 {
-    if (surface_ != SurfaceType_None)
+    if (surface_ != SurfaceType::None)
     {
         settings->setFlag(TrajectoryAnalysisSettings::efRequireTop);
 
-        if (bNormalizationSet_ && normalization_ != Normalization_None)
+        if (bNormalizationSet_ && normalization_ != Normalization::None)
         {
             GMX_THROW(InconsistentInputError("-surf cannot be combined with -norm"));
         }
-        normalization_ = Normalization_None;
+        normalization_ = Normalization::None;
         if (bExclusions_)
         {
             GMX_THROW(InconsistentInputError("-surf cannot be combined with -excl"));
@@ -359,14 +363,14 @@ void Rdf::initAnalysis(const TrajectoryAnalysisSettings& settings, const Topolog
 
     normFactors_.setColumnCount(0, sel_.size() + 1);
 
-    const bool bSurface = (surface_ != SurfaceType_None);
+    const bool bSurface = (surface_ != SurfaceType::None);
     if (bSurface)
     {
         if (!refSel_.hasOnlyAtoms())
         {
             GMX_THROW(InconsistentInputError("-surf only works with -ref that consists of atoms"));
         }
-        const e_index_t type = (surface_ == SurfaceType_Molecule ? INDEX_MOL : INDEX_RES);
+        const e_index_t type = (surface_ == SurfaceType::Molecule ? INDEX_MOL : INDEX_RES);
         surfaceGroupCount_   = refSel_.initOriginalIdsToGroup(top.mtop(), type);
     }
 
@@ -600,7 +604,7 @@ void Rdf::finishAnalysis(int /*nframes*/)
     // through the dataset registration mechanism.
     AverageHistogramPointer finalRdf = pairCounts_->averager().resampleDoubleBinWidth(true);
 
-    if (normalization_ != Normalization_None)
+    if (normalization_ != Normalization::None)
     {
         // Normalize by the volume of the bins (volume of sphere segments or
         // length of circle segments).
@@ -626,7 +630,7 @@ void Rdf::finishAnalysis(int /*nframes*/)
         }
         finalRdf->scaleAllByVector(invBinVolume.data());
 
-        if (normalization_ == Normalization_Rdf)
+        if (normalization_ == Normalization::Rdf)
         {
             // Normalize by particle density.
             for (size_t g = 0; g < sel_.size(); ++g)