[cig-commits] r13178 - in cs/cigma/trunk: src tests/libcigma

luis at geodynamics.org luis at geodynamics.org
Wed Oct 29 15:11:58 PDT 2008


Author: luis
Date: 2008-10-29 15:11:58 -0700 (Wed, 29 Oct 2008)
New Revision: 13178

Modified:
   cs/cigma/trunk/src/Cell.cpp
   cs/cigma/trunk/src/Cell.h
   cs/cigma/trunk/tests/libcigma/CellTest.cpp
Log:
Check for valid cell type in Cell::string2type(std::string)

Modified: cs/cigma/trunk/src/Cell.cpp
===================================================================
--- cs/cigma/trunk/src/Cell.cpp	2008-10-29 22:11:55 UTC (rev 13177)
+++ cs/cigma/trunk/src/Cell.cpp	2008-10-29 22:11:58 UTC (rev 13178)
@@ -27,8 +27,20 @@
 
 static CellTypeMap celltypes(cellTypeMapEntries, cellTypeMapEntries + numTypeEntries);
 
+bool Cell::valid_cell_type(std::string name)
+{
+    CellTypeMap::iterator it;
+    it = celltypes.find(name);
+    return (it != celltypes.end());
+}
+
 Cell::type Cell::string2type(std::string name)
 {
+    if (!Cell::valid_cell_type(name))
+    {
+        //throw cigma::Exception("Cell::string2type", "Invalid type name");
+        return Cell::NONE;
+    }
     return celltypes[name];
 }
 

Modified: cs/cigma/trunk/src/Cell.h
===================================================================
--- cs/cigma/trunk/src/Cell.h	2008-10-29 22:11:55 UTC (rev 13177)
+++ cs/cigma/trunk/src/Cell.h	2008-10-29 22:11:58 UTC (rev 13178)
@@ -36,6 +36,7 @@
     void uvw2xyz(double uvw[3], double xyz[3]);
     
     typedef enum {
+        NONE=0,
         TRI3,
         QUAD4,
         TET4,
@@ -43,6 +44,7 @@
     } type;
 
     virtual type cell_type() const = 0;
+    static bool valid_cell_type(std::string name);
     static type string2type(std::string name);
     static boost::shared_ptr<Cell> New(Cell::type cellType);
     static boost::shared_ptr<Cell> New(const char *name);

Modified: cs/cigma/trunk/tests/libcigma/CellTest.cpp
===================================================================
--- cs/cigma/trunk/tests/libcigma/CellTest.cpp	2008-10-29 22:11:55 UTC (rev 13177)
+++ cs/cigma/trunk/tests/libcigma/CellTest.cpp	2008-10-29 22:11:58 UTC (rev 13178)
@@ -115,12 +115,11 @@
     shared_ptr<Cell> cell_quad4 = Cell::New("quad4");
     shared_ptr<Cell> cell_tri3 = Cell::New("tri3");
 
+    CPPUNIT_ASSERT_EQUAL(Cell::valid_cell_type("asdf"), false);
     CPPUNIT_ASSERT_EQUAL(cell_tet4->cell_type(), Cell::TET4);
     CPPUNIT_ASSERT_EQUAL(cell_hex8->cell_type(), Cell::HEX8);
     CPPUNIT_ASSERT_EQUAL(cell_quad4->cell_type(), Cell::QUAD4);
     CPPUNIT_ASSERT_EQUAL(cell_tri3->cell_type(), Cell::TRI3);
-
-    // XXX: pass bad string to Cell::New and handle exception
 }
 
 void CellTest::test_hex8()



More information about the CIG-COMMITS mailing list