ByteBuffer.setPosition(int) added

This commit is contained in:
Matej Sekoranja
2010-12-27 10:30:59 +01:00
parent 20945f7802
commit 9cbd953c34
2 changed files with 32 additions and 0 deletions
+17
View File
@@ -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:
+15
View File
@@ -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[] = { ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',