[Liblas-commits] hg: Remove GetStream methods of ReaderI and WriterI altogether. ...

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Dec 6 11:36:24 EST 2010


changeset 25add9edaaf1 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=25add9edaaf1
summary: Remove GetStream methods of ReaderI and WriterI altogether. These don't belong

diffstat:

 include/liblas/detail/reader/reader.hpp |   2 -
 include/liblas/detail/writer/writer.hpp |   2 -
 include/liblas/lasreader.hpp            |   4 --
 include/liblas/laswriter.hpp            |   3 -
 include/liblas/liblas.hpp               |   6 +---
 src/detail/reader/reader.cpp            |   5 ---
 src/detail/writer/writer.cpp            |   6 ---
 src/las_c_api.cpp                       |  55 ++++++++++++++++++++++++++------
 src/lasreader.cpp                       |   4 --
 src/laswriter.cpp                       |   5 ---
 test/unit/lasreader_test.cpp            |  17 +---------
 test/unit/laswriter_test.cpp            |  40 +++++++----------------
 12 files changed, 58 insertions(+), 91 deletions(-)

diffs (truncated from 354 to 300 lines):

diff -r 16c33aa5bf9d -r 25add9edaaf1 include/liblas/detail/reader/reader.hpp
--- a/include/liblas/detail/reader/reader.hpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/include/liblas/detail/reader/reader.hpp	Mon Dec 06 10:36:17 2010 -0600
@@ -69,8 +69,6 @@
     liblas::Point const& ReadPointAt(std::size_t n, HeaderPtr header);
     void Seek(std::size_t n, HeaderPtr header);
     
-    std::istream& GetStream() const;
-    
     void Reset(HeaderPtr header);
 
 protected:
diff -r 16c33aa5bf9d -r 25add9edaaf1 include/liblas/detail/writer/writer.hpp
--- a/include/liblas/detail/writer/writer.hpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/include/liblas/detail/writer/writer.hpp	Mon Dec 06 10:36:17 2010 -0600
@@ -66,8 +66,6 @@
     void UpdateHeader(liblas::Header const& header);
     void WritePoint(liblas::Point const& record, HeaderPtr header);
 
-    std::ostream& GetStream() const;
-
 protected:
     PointRecord m_record;
     std::ostream& m_ofs;
diff -r 16c33aa5bf9d -r 25add9edaaf1 include/liblas/lasreader.hpp
--- a/include/liblas/lasreader.hpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/include/liblas/lasreader.hpp	Mon Dec 06 10:36:17 2010 -0600
@@ -97,10 +97,6 @@
     /// @exception nothrow
     std::vector<VariableRecord> const& GetVLRs() const;
 
-    /// Allow fetching of the stream attached to the reader.
-    /// @exception nothrow
-    std::istream* GetStream() const;
-
     /// Fetches next point record in file.
     /// @exception may throw std::exception
     bool ReadNextPoint();
diff -r 16c33aa5bf9d -r 25add9edaaf1 include/liblas/laswriter.hpp
--- a/include/liblas/laswriter.hpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/include/liblas/laswriter.hpp	Mon Dec 06 10:36:17 2010 -0600
@@ -82,9 +82,6 @@
     /// \todo TODO: How to handle point_source_id in portable way, for LAS 1.0 and 1.1
     bool WritePoint(Point const& point);
 
-    /// Allow fetching of the stream
-    std::ostream* GetStream() const;
-    
     /// Allow in-place writing of header
     void WriteHeader(Header& header);
 
diff -r 16c33aa5bf9d -r 25add9edaaf1 include/liblas/liblas.hpp
--- a/include/liblas/liblas.hpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/include/liblas/liblas.hpp	Mon Dec 06 10:36:17 2010 -0600
@@ -128,9 +128,7 @@
     virtual void Seek(std::size_t n, HeaderPtr header) = 0;
     
     virtual void Reset(HeaderPtr header) = 0;
-    
-    virtual std::istream& GetStream() const = 0;
-    
+
     virtual ~ReaderI() {}
 };
 
@@ -142,8 +140,6 @@
     virtual void UpdateHeader(Header const& header) = 0;
     virtual void WritePoint(const Point& point, HeaderPtr header) = 0;
 
-    virtual std::ostream& GetStream() const = 0;
-
     virtual ~WriterI() {}
 
 };
diff -r 16c33aa5bf9d -r 25add9edaaf1 src/detail/reader/reader.cpp
--- a/src/detail/reader/reader.cpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/src/detail/reader/reader.cpp	Mon Dec 06 10:36:17 2010 -0600
@@ -72,11 +72,6 @@
 {
 }
 
-std::istream& ReaderImpl::GetStream() const
-{
-    return m_ifs;
-}
-
 void ReaderImpl::Reset(HeaderPtr header)
 {
     m_ifs.clear();
diff -r 16c33aa5bf9d -r 25add9edaaf1 src/detail/writer/writer.cpp
--- a/src/detail/writer/writer.cpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/src/detail/writer/writer.cpp	Mon Dec 06 10:36:17 2010 -0600
@@ -97,12 +97,6 @@
 
 }
 
-std::ostream& WriterImpl::GetStream() const
-{
-    return m_ofs;
-}
-
-
 WriterImpl* WriterFactory::Create(std::ostream& ofs)
 {
     if (!ofs)
diff -r 16c33aa5bf9d -r 25add9edaaf1 src/las_c_api.cpp
--- a/src/las_c_api.cpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/src/las_c_api.cpp	Mon Dec 06 10:36:17 2010 -0600
@@ -130,6 +130,8 @@
 
 
 static std::stack<liblas::Error > errors;
+static std::map<liblas::Reader*, std::istream*> readers;
+static std::map<liblas::Writer*, std::ostream*> writers;
 
 #ifdef _MSC_VER
 # pragma warning(disable: 4127) // warning C4127: conditional expression is constant
@@ -219,8 +221,9 @@
     try {
         
         std::istream* istrm = OpenInput(std::string(filename));
-        return (LASReaderH) new liblas::Reader(*istrm);
-
+        liblas::Reader* reader = new liblas::Reader(*istrm);
+        readers.insert(std::pair<liblas::Reader*, std::istream*>(reader, istrm));
+        return (LASReaderH) reader;
     
     } catch (std::exception const& e)
      {
@@ -242,8 +245,9 @@
         std::istream* istrm = OpenInput(std::string(filename));
         
         liblas::Header* header = ((liblas::Header*) hHeader);
-        return (LASReaderH) new liblas::Reader(*istrm, *header);
-
+        liblas::Reader* reader = new liblas::Reader(*istrm, *header);
+        readers.insert(std::pair<liblas::Reader*, std::istream*>(reader, istrm));
+        return (LASReaderH) reader;
     
     } catch (std::exception const& e)
      {
@@ -259,13 +263,28 @@
 
     try { 
         liblas::Reader* reader = (liblas::Reader*)hReader;
-        std::istream* istrm = reader->GetStream();
+        
+        std::map<liblas::Reader*, std::istream*>::iterator it = readers.find(reader);
+        if (it == readers.end())
+        {
+            LASError_PushError(LE_Failure, "Unable to find reader stream", "LASReader_Destroy");
+            return;            
+        }
+        std::istream* istrm = it->second;
 
         delete reader;
         hReader = NULL;
     
+        if ( istrm == NULL )
+        {
+            LASError_PushError(LE_Failure, "Got 99 problems, but the stream ain't one", "LASReader_Destroy");
+            return;            
+        }
+        
         if (static_cast<std::ifstream&>(*istrm))
             static_cast<std::ifstream&>(*istrm).close();
+            
+        readers.erase(reader);
         delete istrm;
         istrm = NULL;
   
@@ -1360,7 +1379,10 @@
         
         liblas::Header* header = ((liblas::Header*) hHeader);
         liblas::Writer* writer = new liblas::Writer(*ostrm, *header);
+
+        writers.insert(std::pair<liblas::Writer*, std::ostream*>(writer, ostrm));
         return (LASWriterH) writer;
+        
 
     } catch (std::exception const& e)
      {
@@ -1412,23 +1434,34 @@
 {
     VALIDATE_LAS_POINTER0(hWriter, "LASWriter_Destroy");
 
-
-    
-
-  
-    
     try { 
         liblas::Writer* writer = (liblas::Writer*)hWriter;
-        std::ostream* ostrm = writer->GetStream();
+
+        std::map<liblas::Writer*, std::ostream*>::iterator it = writers.find(writer);
+        if (it == writers.end())
+        {
+            LASError_PushError(LE_Failure, "Unable to find writer stream", "LASWriter_Destroy");
+            return;            
+        }
+        std::ostream* ostrm = it->second;
 
         delete writer;
         hWriter = NULL;
+
+        if ( ostrm == NULL )
+        {
+            LASError_PushError(LE_Failure, "Got 99 problems, but the stream ain't one", "LASWriter_Destroy");
+            return;            
+        }
     
         if (static_cast<std::ofstream&>(*ostrm))
             static_cast<std::ofstream&>(*ostrm).close();
         
         if (ostrm != NULL)
             delete ostrm;
+        
+        writers.erase(writer);
+        
         ostrm = NULL;
   
         }  catch (std::runtime_error const& e/* e */) 
diff -r 16c33aa5bf9d -r 25add9edaaf1 src/lasreader.cpp
--- a/src/lasreader.cpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/src/lasreader.cpp	Mon Dec 06 10:36:17 2010 -0600
@@ -298,10 +298,6 @@
 
 }
 
-std::istream* Reader::GetStream() const
-{
-    return &(m_pimpl->GetStream());
-}
 
 void Reader::Reset() 
 {
diff -r 16c33aa5bf9d -r 25add9edaaf1 src/laswriter.cpp
--- a/src/laswriter.cpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/src/laswriter.cpp	Mon Dec 06 10:36:17 2010 -0600
@@ -132,11 +132,6 @@
     return true;
 }
 
-std::ostream* Writer::GetStream() const
-{
-    return &(m_pimpl->GetStream());
-}
-
 void Writer::WriteHeader(Header& header)
 {
     // The writer may update our header as part of its 
diff -r 16c33aa5bf9d -r 25add9edaaf1 test/unit/lasreader_test.cpp
--- a/test/unit/lasreader_test.cpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/test/unit/lasreader_test.cpp	Mon Dec 06 10:36:17 2010 -0600
@@ -144,7 +144,7 @@
         test_file10_point2(reader[1]);
     }
 
-    // Test GetStream method
+    // Test seek nd GetPoint pair
     template<>
     template<>
     void to::test<7>()
@@ -153,21 +153,6 @@
         ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
         liblas::Reader reader(ifs);
 
-        std::istream* is = reader.GetStream();
-
-        ensure_equals(ifs, *is);
-    }
-
-
-    // Test seek nd GetPoint pair
-    template<>
-    template<>
-    void to::test<8>()
-    {
-        std::ifstream ifs;
-        ifs.open(file10_.c_str(), std::ios::in | std::ios::binary);
-        liblas::Reader reader(ifs);
-
         // read 1st point
 	reader.ReadNextPoint();
         test_file10_point1(reader.GetPoint());
diff -r 16c33aa5bf9d -r 25add9edaaf1 test/unit/laswriter_test.cpp
--- a/test/unit/laswriter_test.cpp	Thu Dec 02 15:22:53 2010 -0600
+++ b/test/unit/laswriter_test.cpp	Mon Dec 06 10:36:17 2010 -0600
@@ -238,7 +238,7 @@
         }
     }
 
-    // Test GetStream method
+    // Test appending to an existing file
     template<>
     template<>
     void to::test<4>()
@@ -247,44 +247,28 @@
         ofs.open(tmpfile_.c_str(), std::ios::out | std::ios::binary);


More information about the Liblas-commits mailing list