From fcf7edf69446e03da6c00c33970bd87bf16e8fc6 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Mon, 14 Apr 2014 18:36:32 +0000 Subject: [PATCH] Implement Sub::name and Sub::formula in the base class Eliminates the need for redundant implementations in all the derived classes. Also, make the return value a "const char*" to eliminate the dangerous cast. --- include/cantera/tpx/Sub.h | 9 +++++++-- src/tpx/CarbonDioxide.cpp | 8 -------- src/tpx/CarbonDioxide.h | 2 -- src/tpx/HFC134a.cpp | 8 -------- src/tpx/HFC134a.h | 2 -- src/tpx/Heptane.cpp | 8 -------- src/tpx/Heptane.h | 2 -- src/tpx/Hydrogen.cpp | 8 -------- src/tpx/Hydrogen.h | 2 -- src/tpx/Methane.cpp | 8 -------- src/tpx/Methane.h | 2 -- src/tpx/Nitrogen.cpp | 8 -------- src/tpx/Nitrogen.h | 2 -- src/tpx/Oxygen.cpp | 8 -------- src/tpx/Oxygen.h | 2 -- src/tpx/RedlichKwong.h | 6 ------ src/tpx/Water.cpp | 8 -------- src/tpx/Water.h | 2 -- src/tpx/lk.cpp | 8 -------- src/tpx/lk.h | 2 -- 20 files changed, 7 insertions(+), 98 deletions(-) diff --git a/include/cantera/tpx/Sub.h b/include/cantera/tpx/Sub.h index 7c019c945..7282bac4b 100644 --- a/include/cantera/tpx/Sub.h +++ b/include/cantera/tpx/Sub.h @@ -76,10 +76,15 @@ public: virtual double Tmax()=0; //! Name of the substance - virtual char* name() = 0; + const char* name() { + return m_name.c_str(); + } //! Chemical formula for the substance - virtual char* formula() = 0; + const char* formula() { + return m_formula.c_str(); + } + //! @} //! @name Properties diff --git a/src/tpx/CarbonDioxide.cpp b/src/tpx/CarbonDioxide.cpp index 41f7240b6..45d453bbe 100644 --- a/src/tpx/CarbonDioxide.cpp +++ b/src/tpx/CarbonDioxide.cpp @@ -310,14 +310,6 @@ double CarbonDioxide::Tmax() { return Tmx; } -char* CarbonDioxide::name() -{ - return (char*) m_name.c_str() ; -} -char* CarbonDioxide::formula() -{ - return (char*) m_formula.c_str(); -} double CarbonDioxide::MolWt() { return M; diff --git a/src/tpx/CarbonDioxide.h b/src/tpx/CarbonDioxide.h index 3dc76d2f6..76001f0ad 100644 --- a/src/tpx/CarbonDioxide.h +++ b/src/tpx/CarbonDioxide.h @@ -24,8 +24,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); //! Pressure. Equation P-3 in Reynolds. P(rho, T). double Pp(); diff --git a/src/tpx/HFC134a.cpp b/src/tpx/HFC134a.cpp index eababff51..3a9b7a6c5 100644 --- a/src/tpx/HFC134a.cpp +++ b/src/tpx/HFC134a.cpp @@ -210,14 +210,6 @@ double HFC134a::Tmax() { return Tmx; } -char* HFC134a::name() -{ - return (char*) m_name.c_str(); -} -char* HFC134a::formula() -{ - return (char*) m_formula.c_str(); -} double HFC134a::MolWt() { return M; diff --git a/src/tpx/HFC134a.h b/src/tpx/HFC134a.h index ce7d39dc8..45c58e442 100644 --- a/src/tpx/HFC134a.h +++ b/src/tpx/HFC134a.h @@ -28,8 +28,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); double Pp(); double fp(); diff --git a/src/tpx/Heptane.cpp b/src/tpx/Heptane.cpp index 99a841dd9..48eddf5b5 100644 --- a/src/tpx/Heptane.cpp +++ b/src/tpx/Heptane.cpp @@ -263,14 +263,6 @@ double Heptane::Tmax() { return Tmx; } -char* Heptane::name() -{ - return (char*) m_name.c_str(); -} -char* Heptane::formula() -{ - return (char*) m_formula.c_str(); -} double Heptane::MolWt() { return M; diff --git a/src/tpx/Heptane.h b/src/tpx/Heptane.h index 8731b36c5..19b0cea10 100644 --- a/src/tpx/Heptane.h +++ b/src/tpx/Heptane.h @@ -22,8 +22,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); //! Pressure. Equation P-2 in Reynolds. double Pp(); diff --git a/src/tpx/Hydrogen.cpp b/src/tpx/Hydrogen.cpp index 46add311e..40ea9d696 100644 --- a/src/tpx/Hydrogen.cpp +++ b/src/tpx/Hydrogen.cpp @@ -264,14 +264,6 @@ double hydrogen::Tmax() { return Tmx; } -char* hydrogen::name() -{ - return (char*) m_name.c_str(); -} -char* hydrogen::formula() -{ - return (char*) m_formula.c_str(); -} double hydrogen::MolWt() { return M; diff --git a/src/tpx/Hydrogen.h b/src/tpx/Hydrogen.h index 4d55dc465..c769bb2f0 100644 --- a/src/tpx/Hydrogen.h +++ b/src/tpx/Hydrogen.h @@ -23,8 +23,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); double Pp(); double up(); diff --git a/src/tpx/Methane.cpp b/src/tpx/Methane.cpp index 32a572edd..5f3f14d48 100644 --- a/src/tpx/Methane.cpp +++ b/src/tpx/Methane.cpp @@ -235,14 +235,6 @@ double methane::Tmax() { return Tmx; } -char* methane::name() -{ - return (char*) m_name.c_str(); -} -char* methane::formula() -{ - return (char*) m_formula.c_str(); -} double methane::MolWt() { return M; diff --git a/src/tpx/Methane.h b/src/tpx/Methane.h index 6524d9c2d..ffd15556d 100644 --- a/src/tpx/Methane.h +++ b/src/tpx/Methane.h @@ -23,8 +23,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); double Pp(); double up(); diff --git a/src/tpx/Nitrogen.cpp b/src/tpx/Nitrogen.cpp index c40d25103..68ad934db 100644 --- a/src/tpx/Nitrogen.cpp +++ b/src/tpx/Nitrogen.cpp @@ -248,14 +248,6 @@ double nitrogen::Tmax() { return Tmx; } -char* nitrogen::name() -{ - return (char*) m_name.c_str(); -} -char* nitrogen::formula() -{ - return (char*) m_formula.c_str(); -} double nitrogen::MolWt() { return M; diff --git a/src/tpx/Nitrogen.h b/src/tpx/Nitrogen.h index f37ca9423..1c7acbe68 100644 --- a/src/tpx/Nitrogen.h +++ b/src/tpx/Nitrogen.h @@ -23,8 +23,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); double Pp(); double up(); diff --git a/src/tpx/Oxygen.cpp b/src/tpx/Oxygen.cpp index 0b69e1538..f2b38e1fd 100644 --- a/src/tpx/Oxygen.cpp +++ b/src/tpx/Oxygen.cpp @@ -242,14 +242,6 @@ double oxygen::Tmax() { return Tmx; } -char* oxygen::name() -{ - return (char*) m_name.c_str(); -} -char* oxygen::formula() -{ - return (char*) m_formula.c_str(); -} double oxygen::MolWt() { return M; diff --git a/src/tpx/Oxygen.h b/src/tpx/Oxygen.h index c2c468522..9ab778a67 100644 --- a/src/tpx/Oxygen.h +++ b/src/tpx/Oxygen.h @@ -22,8 +22,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); double Pp(); double up(); diff --git a/src/tpx/RedlichKwong.h b/src/tpx/RedlichKwong.h index c2c44e679..8230e923e 100644 --- a/src/tpx/RedlichKwong.h +++ b/src/tpx/RedlichKwong.h @@ -55,12 +55,6 @@ public: double Tmax() { return 1.0e10; } - char* name() { - return (char*) m_name.c_str() ; - } - char* formula() { - return (char*) m_formula.c_str() ; - } double Pp(); double up(); diff --git a/src/tpx/Water.cpp b/src/tpx/Water.cpp index c4844022a..5369c455c 100644 --- a/src/tpx/Water.cpp +++ b/src/tpx/Water.cpp @@ -217,14 +217,6 @@ double water::Tmax() { return Tmx; } -char* water::name() -{ - return (char*) m_name.c_str(); -} -char* water::formula() -{ - return (char*) m_formula.c_str(); -} double water::MolWt() { return M; diff --git a/src/tpx/Water.h b/src/tpx/Water.h index 8e760614b..00dc46df7 100644 --- a/src/tpx/Water.h +++ b/src/tpx/Water.h @@ -22,8 +22,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); double Pp(); double up(); diff --git a/src/tpx/lk.cpp b/src/tpx/lk.cpp index 13a495177..5b50f6503 100644 --- a/src/tpx/lk.cpp +++ b/src/tpx/lk.cpp @@ -160,14 +160,6 @@ double leekesler::Tmax() { return 10000.0; } -char* leekesler::name() -{ - return (char*) m_name.c_str(); -} -char* leekesler::formula() -{ - return (char*) m_formula.c_str(); -} double leekesler::MolWt() { return Mw; diff --git a/src/tpx/lk.h b/src/tpx/lk.h index 01ebef2d1..bf8f465f9 100644 --- a/src/tpx/lk.h +++ b/src/tpx/lk.h @@ -28,8 +28,6 @@ public: double Vcrit(); double Tmin(); double Tmax(); - char* name(); - char* formula(); double Pp(); double up();