[Liblas-commits] hg-main-tree: start of StreamOwner class
liblas-commits at liblas.org
liblas-commits at liblas.org
Mon Jul 25 13:38:53 EDT 2011
details: http://hg.libpc.orghg-main-tree/rev/f9d3625b0473
changeset: 924:f9d3625b0473
user: Michael P. Gerlek <mpg at flaxen.com>
date: Mon Jul 25 10:38:50 2011 -0700
description:
start of StreamOwner class
diffstat:
include/pdal/StreamOwner.hpp | 85 +++++++++++++++++++++++++++
src/CMakeLists.txt | 2 +
src/StreamOwner.cpp | 129 ++++++++++++++++++++++++++++++++++++++++++
test/unit/CMakeLists.txt | 1 +
test/unit/StreamOwnerTest.cpp | 51 ++++++++++++++++
5 files changed, 268 insertions(+), 0 deletions(-)
diffs (truncated from 307 to 300 lines):
diff -r 0cf0602555f2 -r f9d3625b0473 include/pdal/StreamOwner.hpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/include/pdal/StreamOwner.hpp Mon Jul 25 10:38:50 2011 -0700
@@ -0,0 +1,85 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following
+* conditions are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
+* names of its contributors may be used to endorse or promote
+* products derived from this software without specific prior
+* written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+* OF SUCH DAMAGE.
+****************************************************************************/
+
+#ifndef INCLUDED_STREAMOWNER_HPP
+#define INCLUDED_STREAMOWNER_HPP
+
+#include <pdal/pdal.hpp>
+
+#include <string>
+#include <cassert>
+#include <stdexcept>
+#include <cmath>
+#include <ostream>
+#include <istream>
+
+namespace pdal
+{
+
+// Many of our reader & writer classes want to take a filename or a stream
+// in their ctors, which means that we need a common piece of code that
+// creates and takes ownership of the stream, if needed.
+//
+// This could, I suppose, evolve into something that even takes in things
+// other than std streams or filenames.
+
+class PDAL_DLL StreamOwner
+{
+public:
+ enum Mode { ReadMode, WriteMode };
+
+public:
+ StreamOwner(const std::string filename, Mode mode);
+ StreamOwner(std::istream*);
+ StreamOwner(std::ostream*);
+ ~StreamOwner();
+
+ std::istream* istream();
+ std::ostream* ostream();
+
+private:
+ Mode m_mode; // read or write?
+ bool m_owned; // if true, we have to delete the stream
+
+ std::istream* m_istream;
+ std::ostream* m_ostream;
+
+ StreamOwner& operator=(const StreamOwner&); // not implemented
+ StreamOwner(const StreamOwner&); // not implemented
+};
+
+
+} // namespace pdal
+
+#endif
diff -r 0cf0602555f2 -r f9d3625b0473 src/CMakeLists.txt
--- a/src/CMakeLists.txt Mon Jul 25 10:19:40 2011 -0500
+++ b/src/CMakeLists.txt Mon Jul 25 10:38:50 2011 -0700
@@ -49,6 +49,7 @@
${PDAL_HEADERS_DIR}/StageBase.hpp
${PDAL_HEADERS_DIR}/StageFactory.hpp
${PDAL_HEADERS_DIR}/StageIterator.hpp
+ ${PDAL_HEADERS_DIR}/StreamOwner.hpp
${PDAL_HEADERS_DIR}/Utils.hpp
${PDAL_HEADERS_DIR}/Vector.hpp
${PDAL_HEADERS_DIR}/Writer.hpp
@@ -84,6 +85,7 @@
StageBase.cpp
StageFactory.cpp
StageIterator.cpp
+ StreamOwner.cpp
Utils.cpp
Vector.cpp
Writer.cpp
diff -r 0cf0602555f2 -r f9d3625b0473 src/StreamOwner.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/StreamOwner.cpp Mon Jul 25 10:38:50 2011 -0700
@@ -0,0 +1,129 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following
+* conditions are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
+* names of its contributors may be used to endorse or promote
+* products derived from this software without specific prior
+* written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+* OF SUCH DAMAGE.
+****************************************************************************/
+
+#include <pdal/StreamOwner.hpp>
+#include <pdal/Utils.hpp>
+#include <pdal/exceptions.hpp>
+
+
+namespace pdal
+{
+
+StreamOwner::StreamOwner(const std::string filename, Mode mode)
+ : m_mode(mode)
+ , m_owned(true)
+ , m_istream(NULL)
+ , m_ostream(NULL)
+{
+ if (m_mode == ReadMode)
+ {
+ m_istream = Utils::openFile(filename);
+ }
+ else if (m_mode == WriteMode)
+ {
+ m_ostream = Utils::createFile(filename);
+ }
+ else
+ {
+ throw pdal_error("invalid file mode");
+ }
+
+ return;
+}
+
+
+StreamOwner::StreamOwner(std::istream* istream)
+ : m_mode(ReadMode)
+ , m_owned(false)
+ , m_istream(istream)
+ , m_ostream(NULL)
+{
+ return;
+}
+
+
+StreamOwner::StreamOwner(std::ostream* ostream)
+ : m_mode(WriteMode)
+ , m_owned(false)
+ , m_istream(NULL)
+ , m_ostream(ostream)
+{
+ return;
+}
+
+
+StreamOwner::~StreamOwner()
+{
+ if (m_istream)
+ {
+ if (m_owned)
+ {
+ Utils::closeFile(m_istream);
+ }
+ m_istream = NULL;
+ }
+ if (m_ostream)
+ {
+ if (m_owned)
+ {
+ Utils::closeFile(m_ostream);
+ }
+ m_ostream = NULL;
+ }
+
+ return;
+}
+
+
+std::istream* StreamOwner::istream()
+{
+ if (m_mode != ReadMode)
+ {
+ throw pdal_error("invalid file mode");
+ }
+ return m_istream;
+}
+
+
+std::ostream* StreamOwner::ostream()
+{
+ if (m_mode != WriteMode)
+ {
+ throw pdal_error("invalid file mode");
+ }
+ return m_ostream;
+}
+
+
+} // namespace pdal
diff -r 0cf0602555f2 -r f9d3625b0473 test/unit/CMakeLists.txt
--- a/test/unit/CMakeLists.txt Mon Jul 25 10:19:40 2011 -0500
+++ b/test/unit/CMakeLists.txt Mon Jul 25 10:38:50 2011 -0700
@@ -43,6 +43,7 @@
SignallerTest.cpp
SpatialReferenceTest.cpp
StageFactoryTest.cpp
+ StreamOwnerTest.cpp
TerraSolidTest.cpp
UtilsTest.cpp
VectorTest.cpp
diff -r 0cf0602555f2 -r f9d3625b0473 test/unit/StreamOwnerTest.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/unit/StreamOwnerTest.cpp Mon Jul 25 10:38:50 2011 -0700
@@ -0,0 +1,51 @@
+/******************************************************************************
+* Copyright (c) 2011, Michael P. Gerlek (mpg at flaxen.com)
+*
+* All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following
+* conditions are met:
+*
+* * Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+* * Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided
+* with the distribution.
+* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
+* names of its contributors may be used to endorse or promote
+* products derived from this software without specific prior
+* written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+* OF SUCH DAMAGE.
+****************************************************************************/
+
+#include <sstream>
+
+#include <boost/test/unit_test.hpp>
+#include <boost/cstdint.hpp>
+
+#include <pdal/Range.hpp>
+
+using namespace pdal;
+
+BOOST_AUTO_TEST_SUITE(StreamOwnerTest)
More information about the Liblas-commits
mailing list