From 89832db1db156d6eac3c174f0d8ed5b614631f3d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 17 Jul 2018 17:31:20 +0200
Subject: [PATCH] C++11: convert MatrixForm to a class enum

---
 src/SigmaeInitialization.cc | 14 +++++++-------
 src/SigmaeInitialization.hh | 10 +++++-----
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/SigmaeInitialization.cc b/src/SigmaeInitialization.cc
index 8e00048f..18acd1e9 100644
--- a/src/SigmaeInitialization.cc
+++ b/src/SigmaeInitialization.cc
@@ -27,24 +27,24 @@ SigmaeStatement::SigmaeStatement(matrix_t matrix_arg) noexcept(false) :
 {
 }
 
-SigmaeStatement::matrix_form_t
+SigmaeStatement::MatrixForm
 SigmaeStatement::determineMatrixForm(const matrix_t &matrix) noexcept(false)
 {
   size_t nbe;
   int inc;
-  matrix_form_t type;
+  MatrixForm type;
   // Checking if first or last row has one element.
   if (matrix.front().size() == 1)
     {
       inc = 1;
       nbe = 2;
-      type = eLower;
+      type = MatrixForm::lower;
     }
   else if (matrix.back().size() == 1)
     {
       inc = -1;
       nbe = matrix.front().size()-1;
-      type = eUpper;
+      type = MatrixForm::upper;
     }
   else
     throw MatrixFormException();
@@ -70,17 +70,17 @@ SigmaeStatement::writeOutput(ostream &output, const string &basename, bool minim
     {
       for (ic = 0; ic < matrix.size(); ic++)
         {
-          if (ic >= ir && matrix_form == eUpper)
+          if (ic >= ir && matrix_form == MatrixForm::upper)
             {
               ic1 = ic-ir;
               ir1 = ir;
             }
-          else if (ic < ir && matrix_form == eUpper)
+          else if (ic < ir && matrix_form == MatrixForm::upper)
             {
               ic1 = ir-ic;
               ir1 = ic;
             }
-          else if (ic > ir && matrix_form == eLower)
+          else if (ic > ir && matrix_form == MatrixForm::lower)
             {
               ic1 = ir;
               ir1 = ic;
diff --git a/src/SigmaeInitialization.hh b/src/SigmaeInitialization.hh
index 602d9a22..9543a7a0 100644
--- a/src/SigmaeInitialization.hh
+++ b/src/SigmaeInitialization.hh
@@ -31,10 +31,10 @@ class SigmaeStatement : public Statement
 {
 public:
   //! Matrix form (lower or upper triangular) enum
-  enum matrix_form_t
+  enum class MatrixForm
     {
-      eLower = 0,              //!< Lower triangular matrix
-      eUpper = 1               //!< Upper triangular matrix
+      lower,              //!< Lower triangular matrix
+      upper               //!< Upper triangular matrix
     };
   //! Type of a matrix row
   using row_t = vector<expr_t>;
@@ -49,11 +49,11 @@ private:
   //! The matrix
   const matrix_t matrix;
   //! Matrix form (lower or upper)
-  const matrix_form_t matrix_form;
+  const MatrixForm matrix_form;
 
   //! Returns the type (upper or lower triangular) of a given matrix
   /*! Throws an exception if it is neither upper triangular nor lower triangular */
-  static matrix_form_t determineMatrixForm(const matrix_t &matrix) noexcept(false);
+  static MatrixForm determineMatrixForm(const matrix_t &matrix) noexcept(false);
 
 public:
   SigmaeStatement(matrix_t matrix_arg) noexcept(false);
-- 
GitLab