[cig-commits] r13540 - cs/cigma/trunk/src

luis at geodynamics.org luis at geodynamics.org
Tue Dec 9 18:13:45 PST 2008


Author: luis
Date: 2008-12-09 18:13:45 -0800 (Tue, 09 Dec 2008)
New Revision: 13540

Modified:
   cs/cigma/trunk/src/DofHandler.cpp
   cs/cigma/trunk/src/DofHandler.h
Log:
Move factory and setter methods into DofHandler class

Modified: cs/cigma/trunk/src/DofHandler.cpp
===================================================================
--- cs/cigma/trunk/src/DofHandler.cpp	2008-12-10 02:13:42 UTC (rev 13539)
+++ cs/cigma/trunk/src/DofHandler.cpp	2008-12-10 02:13:45 UTC (rev 13540)
@@ -1,7 +1,34 @@
+#include "DofHandler.h"
+#include "io_file_reader.h"
+#include "tri_logger.hpp"
 #include <cassert>
-#include "DofHandler.h"
+#include <string>
+#include <sstream>
+#include <boost/shared_ptr.hpp>
+using namespace std;
 using namespace cigma;
+using boost::shared_ptr;
 
+// ----------------------------------------------------------------------------
+
+shared_ptr<DofHandler> DofHandler::New(const DataPath& dofs_path)
+{
+    //TRI_LOG_STR("DofHandler::New()");
+
+    shared_ptr<DofHandler> dofs;
+
+    if (dofs_path)
+    {
+        dofs = shared_ptr<DofHandler>(new DofHandler);
+        dofs->setPath(dofs_path);
+    }
+
+    return dofs;
+}
+
+// ----------------------------------------------------------------------------
+
+
 DofHandler::DofHandler()
 {
     nno  = 0;
@@ -63,3 +90,49 @@
     }
 }
 
+void DofHandler::setPath(const DataPath& p_dofs)
+{
+    TRI_LOG_STR("DofHandler::setPath");
+    TRI_LOG(p_dofs);
+
+    string filename = p_dofs.filename();
+    string location = p_dofs.location();
+
+    /* Dispatch on reader type */
+    shared_ptr<FileReader> reader = FileReader::New(filename, "r");
+    const FileReader::ReaderType rt = reader->getReaderType();
+    if (rt == FileReader::HDF5_FILE_READER)
+    {
+        int status = reader->getDataset(location.c_str(), &dofs, &nno, &rank);
+        if (status < 0)
+        {
+            std::ostringstream stream;
+            stream << "Could not read dofs from location '"
+                   << location << "' in HDF5 file '" << filename << "'"
+                   << std::ends;
+            throw cigma::Exception("DofHandler::setPath", stream.str());
+        }
+    }
+    else if (rt == FileReader::VTK_FILE_READER)
+    {
+        int status;
+        throw cigma::Exception("DofHandler::setPath", "Error in VTK reader");
+    }
+    else if (rt == FileReader::TEXT_FILE_READER)
+    {
+        int status = reader->getDataset("", &dofs, &nno, &rank);
+        if (status < 0)
+        {
+            std::ostringstream stream;
+            stream << "Could not read dofs from text file '" << filename << "'" << std::ends;
+            throw cigma::Exception("DofHandler::setPath", stream.str());
+        }
+    }
+    else
+    {
+        std::ostringstream stream;
+        stream << "Could not read dofs from path '" << p_dofs << "'" << std::ends;
+        throw cigma::Exception("DofHandler::setPath", stream.str());
+    }
+}
+

Modified: cs/cigma/trunk/src/DofHandler.h
===================================================================
--- cs/cigma/trunk/src/DofHandler.h	2008-12-10 02:13:42 UTC (rev 13539)
+++ cs/cigma/trunk/src/DofHandler.h	2008-12-10 02:13:45 UTC (rev 13540)
@@ -2,6 +2,8 @@
 #define __CIGMA_DOF_HANDLER__
 
 #include <boost/noncopyable.hpp>
+#include <boost/shared_ptr.hpp>
+#include "DataPath.h"
 
 namespace cigma
 {
@@ -23,6 +25,12 @@
 
     void getData(int n, int *nodeIds, double *d);
 
+    /* incremental setter */
+    void setPath(const DataPath& p_dofs);
+
+    /* static factory method */
+    static boost::shared_ptr<DofHandler> New(const DataPath& dofs_path);
+
 public:
     int nno;
     int rank;



More information about the CIG-COMMITS mailing list