[Liblas-commits] hg-main-tree: move the connect code into common for both reader ...

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Mar 28 13:03:59 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/d21db9f1cdc2
changeset: 478:d21db9f1cdc2
user:      Howard Butler <hobu.inc at gmail.com>
date:      Mon Mar 28 12:03:53 2011 -0500
description:
move the connect code into common for both reader and writer to use

diffstat:

 include/libpc/drivers/oci/Common.hpp |   5 +++-
 include/libpc/drivers/oci/Writer.hpp |   2 +-
 src/drivers/oci/Writer.cpp           |  27 +---------------------
 src/drivers/oci/common.cpp           |  43 ++++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 28 deletions(-)

diffs (147 lines):

diff -r a99eccbfb49e -r d21db9f1cdc2 include/libpc/drivers/oci/Common.hpp
--- a/include/libpc/drivers/oci/Common.hpp	Mon Mar 28 11:31:58 2011 -0500
+++ b/include/libpc/drivers/oci/Common.hpp	Mon Mar 28 12:03:53 2011 -0500
@@ -57,6 +57,7 @@
 
 
 
+
 #ifdef LIBPC_COMPILER_MSVC
 #define compare_no_case(a,b,n)  _strnicmp( (a), (b), (n) )
 #else
@@ -76,8 +77,10 @@
     bool Is3d() const;
     bool IsSolid() const;
     boost::property_tree::ptree& GetPTree() {return m_tree; }
+    boost::property_tree::ptree const& GetPTree() const {return m_tree; }
+};
 
-};
+Connection Connect(Options const& options);
 
 std::string to_upper(std::string const& input);
 
diff -r a99eccbfb49e -r d21db9f1cdc2 include/libpc/drivers/oci/Writer.hpp
--- a/include/libpc/drivers/oci/Writer.hpp	Mon Mar 28 11:31:58 2011 -0500
+++ b/include/libpc/drivers/oci/Writer.hpp	Mon Mar 28 12:03:53 2011 -0500
@@ -77,7 +77,7 @@
     Writer& operator=(const Writer&); // not implemented
     Writer(const Writer&); // not implemented
     // 
-    Connection Connect();
+
     void Debug();
     void WipeBlockTable();
     void CreateBlockIndex();
diff -r a99eccbfb49e -r d21db9f1cdc2 src/drivers/oci/Writer.cpp
--- a/src/drivers/oci/Writer.cpp	Mon Mar 28 11:31:58 2011 -0500
+++ b/src/drivers/oci/Writer.cpp	Mon Mar 28 12:03:53 2011 -0500
@@ -37,7 +37,6 @@
 
 #include <iostream>
 
-#include <boost/make_shared.hpp>
 
 #include <libpc/exceptions.hpp>
 
@@ -57,31 +56,7 @@
     return;
 }
 
-Connection Writer::Connect()
-{
-    std::string connection = m_options.GetPTree().get<std::string>("connection");
-    if (connection.empty())
-        throw libpc_error("Oracle connection string empty! Unable to connect");
 
-    
-    std::string::size_type slash_pos = connection.find("/",0);
-    std::string username = connection.substr(0,slash_pos);
-    std::string::size_type at_pos = connection.find("@",slash_pos);
-
-    std::string password = connection.substr(slash_pos+1, at_pos-slash_pos-1);
-    std::string instance = connection.substr(at_pos+1);
-    
-    Connection con = boost::make_shared<OWConnection>(username.c_str(),password.c_str(),instance.c_str());
-    
-    if (con->Succeeded())
-        if (m_verbose)
-            std::cout << "Oracle connection succeeded" << std::endl;
-    else
-        throw libpc_error("Oracle connection failed");
-        
-    return con;
-    
-}
 
 Writer::~Writer()
 {
@@ -606,7 +581,7 @@
     // Set up debugging info
     Debug();
     
-    m_connection = Connect();
+    m_connection = Connect(m_options);
     
     RunFileSQL("pre_sql");
     if (!BlockTableExists())
diff -r a99eccbfb49e -r d21db9f1cdc2 src/drivers/oci/common.cpp
--- a/src/drivers/oci/common.cpp	Mon Mar 28 11:31:58 2011 -0500
+++ b/src/drivers/oci/common.cpp	Mon Mar 28 12:03:53 2011 -0500
@@ -38,6 +38,7 @@
 #include <iostream>
 
 #include <boost/concept_check.hpp> // ignore_unused_variable_warning
+#include <boost/make_shared.hpp>
 
 #include <libpc/Bounds.hpp>
 #include <libpc/exceptions.hpp>
@@ -126,6 +127,48 @@
 }
 
 
+Connection Connect(Options const& options)
+{
+    std::string connection;
+    try {
+        connection = options.GetPTree().get<std::string>("connection");
+        
+    } catch (boost::property_tree::ptree_bad_path const& ) 
+    {
+        throw libpc_error("'connection' string for oracle not set in options");
+    }
+
+    bool verbose = false;
+    try {
+        verbose = options.GetPTree().get<bool>("verbose");
+        
+    } catch (boost::property_tree::ptree_bad_path const& ) 
+    {
+        throw libpc_error("'verbose' bool for oracle not set in options");
+    }
+    
+    if (connection.empty())
+        throw libpc_error("Oracle connection string empty! Unable to connect");
+
+    
+    std::string::size_type slash_pos = connection.find("/",0);
+    std::string username = connection.substr(0,slash_pos);
+    std::string::size_type at_pos = connection.find("@",slash_pos);
+
+    std::string password = connection.substr(slash_pos+1, at_pos-slash_pos-1);
+    std::string instance = connection.substr(at_pos+1);
+    
+    Connection con = boost::make_shared<OWConnection>(username.c_str(),password.c_str(),instance.c_str());
+    
+    if (con->Succeeded())
+        if (verbose)
+            std::cout << "Oracle connection succeeded" << std::endl;
+    else
+        throw libpc_error("Oracle connection failed");
+        
+    return con;
+    
+}
 
 
 }}} // namespace libpc::driver::oci


More information about the Liblas-commits mailing list