-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed 'externals/coda-oss/' changes from a78b22c..e570202
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
Showing
21 changed files
with
2,018 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ target/ | |
# Waf | ||
|
||
.waf-* | ||
waf-* | ||
.lock-waf* | ||
|
||
# Eclipse | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
Oops, something went wrong.