Skip to content

Commit

Permalink
libcore: Added a new constructor for ByteSubArray
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Feb 1, 2017
1 parent 3c8f6b9 commit 83ed18d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion doomsday/sdk/libcore/include/de/data/bytesubarray.h
Expand Up @@ -14,7 +14,7 @@
* 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</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG2_BYTESUBARRAY_H
Expand Down Expand Up @@ -46,6 +46,12 @@ class DENG2_PUBLIC ByteSubArray : public IByteArray
*/
ByteSubArray(IByteArray const &mainArray, Offset at, Size size);

/**
* Constructs a non-modifiable sub-array which refers to the @a mainArray.
* The sub-array starts at @a at and continues until the end of @a mainArray.
*/
ByteSubArray(IByteArray const &mainArray, Offset at);

virtual ~ByteSubArray() {}

// Implements IByteArray.
Expand Down
10 changes: 7 additions & 3 deletions doomsday/sdk/libcore/src/data/bytesubarray.cpp
Expand Up @@ -14,7 +14,7 @@
* 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</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/ByteSubArray"
Expand All @@ -26,7 +26,11 @@ ByteSubArray::ByteSubArray(IByteArray &mainArray, Offset at, Size size)
{}

ByteSubArray::ByteSubArray(IByteArray const &mainArray, Offset at, Size size)
: _mainArray(0), _constMainArray(&mainArray), _at(at), _size(size)
: _mainArray(nullptr), _constMainArray(&mainArray), _at(at), _size(size)
{}

ByteSubArray::ByteSubArray(IByteArray const &mainArray, Offset at)
: _mainArray(nullptr), _constMainArray(&mainArray), _at(at), _size(mainArray.size() - at)
{}

ByteSubArray::Size ByteSubArray::size() const
Expand All @@ -45,7 +49,7 @@ void ByteSubArray::set(Offset at, Byte const *values, Size count)
{
/// @throw NonModifiableError @a mainArray is non-modifiable.
throw NonModifiableError("ByteSubArray::set", "Array is non-modifiable.");
}
}
_mainArray->set(_at + at, values, count);
_size = qMax(_size, at + count);
}
Expand Down

0 comments on commit 83ed18d

Please sign in to comment.