ByteBuffer.setPosition(int) added
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
#include <pvType.h>
|
||||
#include <epicsEndian.h>
|
||||
|
||||
#include "epicsException.h"
|
||||
|
||||
namespace epics {
|
||||
namespace pvData {
|
||||
|
||||
@@ -305,6 +307,21 @@ namespace epics {
|
||||
return _buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this buffer's position. If the new position is invalid in
|
||||
* regards to the invariant then it is discarded.
|
||||
*
|
||||
* @param[in] newPosition The new position value; must be
|
||||
* non-negative and no larger than the current limit.
|
||||
* @throws EpicsException - If the preconditions on
|
||||
* {@code newPosition} do not hold
|
||||
*/
|
||||
inline void setPosition(int newPosition) {
|
||||
if(newPosition<0||newPosition>_limit) throw EpicsException(
|
||||
"invalid limit");
|
||||
_position = newPosition;
|
||||
}
|
||||
|
||||
// TODO must define arrays
|
||||
|
||||
private:
|
||||
|
||||
@@ -93,6 +93,21 @@ void testBasicOperations() {
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==32);
|
||||
|
||||
buff->setPosition(4);
|
||||
assert(buff->getPosition()==4);
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==(32-4));
|
||||
|
||||
buff->setPosition(13);
|
||||
assert(buff->getPosition()==13);
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==(32-13));
|
||||
|
||||
buff->clear();
|
||||
assert(buff->getPosition()==0);
|
||||
assert(buff->getLimit()==32);
|
||||
assert(buff->getRemaining()==32);
|
||||
|
||||
char src[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
|
||||
'm' };
|
||||
char dst[] = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
|
||||
|
||||
Reference in New Issue
Block a user