Skip to content

Commit

Permalink
Squashed 'externals/coda-oss/' changes from a78b22c..e570202
Browse files Browse the repository at this point in the history
e570202 Merge pull request #283 from mdaus/waf_vs_2017
553e238 Try to use default MSVC paths
35ab94b Make gitignore hide generated waf on Windows
3171da1 Update waf to work with VS 2017
5e1b88e Merge pull request #282 from mdaus/buffer_view_stream_niceties
0c2d4c3 Merge pull request #279 from mdaus/scratchVisualization
7410abe Pass BufferView in by const ref and hold onto a copy of it.  Adding another 'using' since we're overloading read()
21050ea Code review fixes, copyright, numBytes
a11c529 Merge pull request #281 from mdaus/xerces-parser-hang
afb64a1 Set feature flags to prevent hanging on DTDs
7e46953 ScratchVisualization, fixed errors from lack of C++11
b070887 Merge pull request #278 from mdaus/getReturnType
33b26bd Fix return type for getter
c451ef2 Merge pull request #277 from mdaus/fix_nautical_mile_conversion
845eb13 Fixed bug in nautical miles to feet conversion
8070a11 Merge pull request #274 from mdaus/scratchReleaseTesting
d8a3c9c created two new tests cases for edge cases
8a36a71 Merge pull request #276 from mdaus/gpotts
900837f Added stdc++ explicit operator bool syntax for ScopedCopyablePtr for testing the PTR object to true fals in a boolean expression.
76ac669 Merge pull request #275 from mdaus/fix_library_call
c5860a5 Add missing include in unit test
d68f315 spacing
1bf2d73 removed unecessary code
e4fe1a8 new updated and fixed version of scratch release with generated test cases
ce63ddb Merge pull request #273 from mdaus/buffer_stream
6d73e8c Add include for memcpy
02a2776 Make inherited interface work with bytes instead of elements
3dfba21 Fix bugs when working with larger types
daa41bf Add BufferViewStream
72669b0 Merge pull request #272 from mdaus/fix_python
3832ca3 Regenerate python bindings with correct version
617a279 Merge pull request #271 from mdaus/scratch_release
2ef97d7 moved brackets
345e305 fixed test case
b79f3cb merge request changes, moved release to .cpp
3582bfc style
f50c173 Merge pull request #270 from mdaus/sio_lite_complex_double
7bb6dd3 working scratch memory release
4db3625 Read SIOs of type complex<double> (reuses the complex<float> case)
7ffca13 Merge pull request #268 from mdaus/scratchmemory
df54917 Remove redundant namespace specifiers.
b92cb27 Add convenience methods to get buffer view of scratch segment.
97c0c16 Merge pull request #267 from mdaus/scratchmemory
d75e067 Refactor the const and non-const get method implementations for ScratchMemory.
5a75b15 Resolve review comments.
c020d26 Add class to handle reservation of scratch memory segments with optional alignment.
754a840 Merge pull request #265 from mdaus/include_stddef
24bfce5 Need stddef.h for size_t
f32c072 Merge pull request #264 from mdaus/allow_bytes
9aee9f2 Allow io to read from bytes object in Python3
f529fea Merge pull request #263 from mdaus/add_range_overlaps
4ad80dc Adding Range::overlaps() convenience methods
faa6f3f Merge pull request #262 from mdaus/assert_header
7c0405b Include header for assert

git-subtree-dir: externals/coda-oss
git-subtree-split: e570202c471fc839a31111a266e83d248891ebfb
  • Loading branch information
asylvest committed Nov 30, 2018
1 parent 945288d commit 61ebb74
Show file tree
Hide file tree
Showing 21 changed files with 2,018 additions and 56 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ target/
# Waf

.waf-*
waf-*
.lock-waf*

# Eclipse
Expand Down
Binary file modified build/waf
Binary file not shown.
53 changes: 27 additions & 26 deletions modules/c++/io/include/import/io.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* =========================================================================
* This file is part of io-c++
* This file is part of io-c++
* =========================================================================
*
*
* (C) Copyright 2004 - 2014, MDA Information Systems LLC
*
* io-c++ is free software; you can redistribute it and/or modify
Expand All @@ -14,8 +14,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/
Expand All @@ -29,12 +29,12 @@
*
* This package is based on the Java io package.
* For the upcoming 0.1.1 release of the modules,
* we will support the io.File API as well.
* we will support the io.File API as well.
*
* The io package takes a more simple but still powerful
* approach to streaming. We have a built in buffering mechanism
* that can be activated simply by using the InputStream interface's
* streamTo() method, connecting it to an OutputStream.
* streamTo() method, connecting it to an OutputStream.
*
* Many of the streams are also implemented as filters, allowing them
* to pipe or stream, or sort data that is incoming, and affect its
Expand All @@ -51,26 +51,27 @@
*
*/

#include "io/BidirectionalStream.h"
#include "io/ByteStream.h"
#include "io/DataStream.h"
#include "io/DbgStream.h"
#include "io/InputStream.h"
#include "io/OutputStream.h"
#include "io/FileInputStream.h"
#include "io/FileOutputStream.h"
#include "io/Seekable.h"
#include "io/Serializable.h"
#include "io/SerializableFile.h"
#include "io/PipeStream.h"
#include "io/StandardStreams.h"
#include "io/StringStream.h"
#include "io/NullStreams.h"
#include "io/ProxyStreams.h"
#include "io/FileUtils.h"
#include "io/SerializableArray.h"
#include "io/CountingStreams.h"
#include "io/RotatingFileOutputStream.h"
#include <io/BidirectionalStream.h>
#include <io/BufferViewStream.h>
#include <io/ByteStream.h>
#include <io/DataStream.h>
#include <io/DbgStream.h>
#include <io/InputStream.h>
#include <io/OutputStream.h>
#include <io/FileInputStream.h>
#include <io/FileOutputStream.h>
#include <io/Seekable.h>
#include <io/Serializable.h>
#include <io/SerializableFile.h>
#include <io/PipeStream.h>
#include <io/StandardStreams.h>
#include <io/StringStream.h>
#include <io/NullStreams.h>
#include <io/ProxyStreams.h>
#include <io/FileUtils.h>
#include <io/SerializableArray.h>
#include <io/CountingStreams.h>
#include <io/RotatingFileOutputStream.h>

//#include "io/MMapInputStream.h"
//using namespace io;
Expand Down
216 changes: 216 additions & 0 deletions modules/c++/io/include/io/BufferViewStream.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/* =========================================================================
* This file is part of io-c++
* =========================================================================
*
* (C) Copyright 2004 - 2018, MDA Information Systems LLC
*
* io-c++ is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; If not,
* see <http://www.gnu.org/licenses/>.
*
*/

#ifndef __IO_BUFFER_VIEW_STREAM_H__
#define __IO_BUFFER_VIEW_STREAM_H__

#include <mem/BufferView.h>
#include <sys/Conf.h>
#include <except/Error.h>
#include <except/Exception.h>
#include <io/SeekableStreams.h>
#include <string.h>

/*!
* \file
* \brief Class for streaming preallocated data, inherits from
* SeekableInputStream, SeekableOutputStream
*/
namespace io
{
/*!
* \class
* \brief Class for streaming preallocated data, inherits from
* SeekableInputStream, SeekableOutputStream
*/
template <typename T>
class BufferViewStream: public SeekableInputStream, public SeekableOutputStream
{
public:
/*!
* Default constructor
* \param bufferView The BufferView to wrap in the stream
*/
BufferViewStream(const mem::BufferView<T>& bufferView) :
mBufferView(bufferView),
mPosition(0)
{
}

//! Returns current location in buffer in bytes
virtual sys::Off_T tell()
{
return mPosition * sizeof(T);
}

/*!
* Seek to given location. Throw an exception if the seek would be out of
* bounds.
* \param offset Offset to seek to
* \param whence Location to seek from
* \return new position
*/
virtual sys::Off_T seek(sys::Off_T offset, Whence whence);

/*
* \return The available bytes to read from the stream
*/
virtual sys::Off_T available()
{
return (mBufferView.size - mPosition) * sizeof(T);
}

using OutputStream::write;
using InputStream::streamTo;
using InputStream::read;

/*
* Writes the bytes in data to the stream.
* \param buffer The data to write to the stream
* \param size The number of bytes to write to the stream
*/
virtual void write(const void* buffer, size_t size);

/*!
* Get a pointer to the internal buffer.
* This pointer should not be treated as valid
* after a call to the seek, write, or reset methods
* \return pointer to the internal buffer
*/
T* get()
{
return mBufferView.data;
}

//! Returns const pointer to internal buffer
const T* get() const
{
return mBufferView.data;
}

/*!
* Overload for reading into a typed buffer
* \param[out] buffer Buffer to read into
* \param numElements How many -elements- (not bytes) to read
*/
sys::SSize_T read(T* buffer, size_t numElements)
{
return InputStream::read(buffer, numElements * sizeof(T)) / sizeof(T);
}

/*!
* Overload for writing from a typed buffer
* \param buffer Buffer to write from
* \param numElements How many -elements- (not bytes) to write
*/
void write(const T* buffer, size_t numElements)
{
write(reinterpret_cast<const void*>(buffer), numElements * sizeof(T));
}

protected:
/*!
* Read up to len bytes of data from this buffer into an array
* update the mark
* \param buffer Buffer to read into
* \param len The length to read
* \return The number of bytes read
*/
virtual sys::SSize_T readImpl(void* buffer, size_t len);


private:
const mem::BufferView<T> mBufferView;
sys::Off_T mPosition;
};

template <typename T>
sys::Off_T BufferViewStream<T>::seek(sys::Off_T offset, Whence whence)
{
offset /= sizeof(T);
// Let's not change anything until we know it will be valid
sys::Off_T newPos = mPosition;
switch (whence)
{
case START:
newPos = offset;
break;
case END:
if (offset > static_cast<sys::Off_T>(mBufferView.size))
{
newPos = 0;
}
else
{
newPos = mBufferView.size - offset;
}
break;
default:
newPos += offset;
break;
}

if (newPos > static_cast<sys::Off_T>(mBufferView.size) || newPos < 0)
{
throw except::Exception(Ctxt("Attempted to seek beyond end of stream"));
}
mPosition = newPos;
return tell();
}

template <typename T>
void BufferViewStream<T>::write(const void* buffer, size_t numBytes)
{
const size_t numElements = numBytes / sizeof(T);
const sys::Size_T newPos = mPosition + numElements;
if (newPos > mBufferView.size)
{
std::ostringstream msg;
msg << "Write of size " << numBytes << " runs out of bounds.";
throw except::Exception(Ctxt(msg.str()));
}

::memcpy(mBufferView.data + mPosition, buffer, numBytes);
mPosition = newPos;
}

template <typename T>
sys::SSize_T BufferViewStream<T>::readImpl(void* buffer, size_t numBytes)
{
size_t numElements = numBytes / sizeof(T);
if (available() < static_cast<sys::Off_T>(numBytes))
{
numBytes = available();
numElements = numBytes / sizeof(T);
}
if (numBytes == 0)
{
return 0;
}

::memcpy(buffer, mBufferView.data + mPosition, numBytes);
mPosition += numElements;
return numBytes;
}
}
#endif

Loading

0 comments on commit 61ebb74

Please sign in to comment.