Commits

Michał Górny committed 26cd154

Use a complete class for Region enum.

  • Participants
  • Parent commits d83ef2a

Comments (0)

Files changed (4)

 
 lib_LTLIBRARIES = libh2oxx.la
 
-libh2oxx_la_SOURCES = src/h2o.cxx
+libh2oxx_la_SOURCES = src/h2o.cxx src/region.cxx
 libh2oxx_la_CPPFLAGS = $(LIBH2O_CFLAGS) -I$(top_srcdir)/include
 libh2oxx_la_LIBADD = $(LIBH2O_LIBS)
 libh2oxx_la_LDFLAGS = -version-info 0:0:0 -no-undefined
 #		include <h2o/boundaries.h>
 	}
 
-	typedef enum internals::h2o_region Region;
+	class Region
+	{
+	public:
+		typedef enum
+		{
+			OOR,
+			R1,
+			R2,
+			R3,
+			R4,
+			R5
+		} enum_type;
+
+	private:
+		enum_type _val;
+
+	public:
+		Region(enum_type val = OOR);
+		Region(enum internals::h2o_region val);
+
+		operator enum_type() const;
+	};
 
 	class H2O
 	{
 }
 
 H2O::H2O()
-	: _region(H2O_REGION_OUT_OF_RANGE)
+	: _region(Region::OOR)
 {
 }
 
 
 	switch (_region)
 	{
-		case H2O_REGION_OUT_OF_RANGE:
+		case Region::OOR:
 			out_of_range(p, T);
 			break;
-		case H2O_REGION1:
-		case H2O_REGION2:
-		case H2O_REGION5:
+		case Region::R1:
+		case Region::R2:
+		case Region::R5:
 			break;
-		case H2O_REGION3: // -> (rho,T)
+		case Region::R3: // -> (rho,T)
 		{
 			double v = h2o_region3_v_pT(p, T);
 			_arg1 = 1/v;
 
 	ret._arg1 = T;
 	ret._arg2 = x;
-	ret._region = H2O_REGION4;
+	ret._region = Region::R4;
 
 	return ret;
 }
 
 	ret._arg1 = h2o_region4_T_p(p);
 	ret._arg2 = x;
-	ret._region = H2O_REGION4;
+	ret._region = Region::R4;
 
 	return ret;
 }
 {
 	switch (_region)
 	{
-		case H2O_REGION1:
-		case H2O_REGION2:
-		case H2O_REGION5:
+		case Region::R1:
+		case Region::R2:
+		case Region::R5:
 			return _arg1;
-		case H2O_REGION3:
+		case Region::R3:
 			return h2o_region3_p_rhoT(_arg1, _arg2);
-		case H2O_REGION4:
+		case Region::R4:
 			return h2o_region4_p_T(_arg1);
 		default:
 			return not_supported(_arg1, _arg2);
 {
 	switch (_region)
 	{
-		case H2O_REGION1:
-		case H2O_REGION2:
-		case H2O_REGION3:
-		case H2O_REGION5:
+		case Region::R1:
+		case Region::R2:
+		case Region::R3:
+		case Region::R5:
 			return _arg2;
-		case H2O_REGION4:
+		case Region::R4:
 			return _arg1;
 		default:
 			return not_supported(_arg1, _arg2);
 {
 	switch (_region)
 	{
-		case H2O_REGION1:
+		case Region::R1:
 			return 0;
-		case H2O_REGION2:
-		case H2O_REGION5:
+		case Region::R2:
+		case Region::R5:
 			return 1;
-		case H2O_REGION4:
+		case Region::R4:
 			return _arg2;
 		default:
 			return not_supported(0, 0);
 
 double H2O::rho() const
 {
-	if (_region == H2O_REGION3)
+	if (_region == Region::R3)
 		return _arg1;
 	return 1/v();
 }
 
 	switch (_region)
 	{
-		case H2O_REGION1:
+		case Region::R1:
 			func = &h2o_region1_v_pT;
 			break;
-		case H2O_REGION2:
+		case Region::R2:
 			func = &h2o_region2_v_pT;
 			break;
-		case H2O_REGION3:
+		case Region::R3:
 			func = &region3_v_rhoT;
 			break;
-		case H2O_REGION4:
+		case Region::R4:
 			func = &h2o_region4_v_Tx;
 			break;
-		case H2O_REGION5:
+		case Region::R5:
 			func = &h2o_region5_v_pT;
 			break;
 		default:
 
 	switch (_region)
 	{
-		case H2O_REGION1:
+		case Region::R1:
 			func = &h2o_region1_u_pT;
 			break;
-		case H2O_REGION2:
+		case Region::R2:
 			func = &h2o_region2_u_pT;
 			break;
-		case H2O_REGION3:
+		case Region::R3:
 			func = &h2o_region3_u_rhoT;
 			break;
-		case H2O_REGION4:
+		case Region::R4:
 			func = &h2o_region4_u_Tx;
 			break;
-		case H2O_REGION5:
+		case Region::R5:
 			func = &h2o_region5_u_pT;
 			break;
 		default:
 
 	switch (_region)
 	{
-		case H2O_REGION1:
+		case Region::R1:
 			func = &h2o_region1_h_pT;
 			break;
-		case H2O_REGION2:
+		case Region::R2:
 			func = &h2o_region2_h_pT;
 			break;
-		case H2O_REGION3:
+		case Region::R3:
 			func = &h2o_region3_h_rhoT;
 			break;
-		case H2O_REGION4:
+		case Region::R4:
 			func = &h2o_region4_h_Tx;
 			break;
-		case H2O_REGION5:
+		case Region::R5:
 			func = &h2o_region5_h_pT;
 			break;
 		default:
 
 	switch (_region)
 	{
-		case H2O_REGION1:
+		case Region::R1:
 			func = &h2o_region1_s_pT;
 			break;
-		case H2O_REGION2:
+		case Region::R2:
 			func = &h2o_region2_s_pT;
 			break;
-		case H2O_REGION3:
+		case Region::R3:
 			func = &h2o_region3_s_rhoT;
 			break;
-		case H2O_REGION4:
+		case Region::R4:
 			func = &h2o_region4_s_Tx;
 			break;
-		case H2O_REGION5:
+		case Region::R5:
 			func = &h2o_region5_s_pT;
 			break;
 		default:
 {
 	switch (_region)
 	{
-		case H2O_REGION2:
-		case H2O_REGION3:
-		case H2O_REGION4:
+		case Region::R2:
+		case Region::R3:
+		case Region::R4:
 			break;
-		case H2O_REGION1: // unable to expand water
-		case H2O_REGION5: // lack of f(p,s)
+		case Region::R1: // unable to expand water
+		case Region::R5: // lack of f(p,s)
 		default:
 			not_supported(pout, pout);
 	}
+/* libh2o -- steam & water properties
+ * (c) 2012 Michał Górny
+ * Released under the terms of the 2-clause BSD license
+ */
+
+#ifdef HAVE_CONFIG_H
+#	include "config.h"
+#endif
+
+#include <cassert>
+
+#include "h2o"
+
+using namespace h2o;
+using namespace h2o::internals;
+
+static const bool not_reached = false; // for assert()
+
+Region::Region(enum_type val)
+	: _val(val)
+{
+	assert(val >= OOR && val <= R5);
+}
+
+Region::Region(enum h2o_region val)
+{
+	Region ret;
+
+	switch (val)
+	{
+		case H2O_REGION_OUT_OF_RANGE:
+			ret = Region::OOR;
+			break;
+		case H2O_REGION1:
+			ret = Region::R1;
+			break;
+		case H2O_REGION2:
+			ret = Region::R2;
+			break;
+		case H2O_REGION3:
+			ret = Region::R3;
+			break;
+		case H2O_REGION4:
+			ret = Region::R4;
+			break;
+		case H2O_REGION5:
+			ret = Region::R5;
+			break;
+		case H2O_REGION_MAX:
+			assert(not_reached);
+	}
+
+	_val = ret;
+}
+
+Region::operator enum_type() const
+{
+	return _val;
+}