Update kernel/linebuffer.{cpp,h} to current coding conventions.
This commit is contained in:
parent
bb3b6b0260
commit
3fa5fff3f5
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -22,14 +22,16 @@
|
||||||
|
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <sortix/kernel/kernel.h>
|
#include <sortix/kernel/kernel.h>
|
||||||
|
|
||||||
#include "linebuffer.h"
|
#include "linebuffer.h"
|
||||||
|
|
||||||
namespace Sortix
|
namespace Sortix {
|
||||||
{
|
|
||||||
static size_t OffsetIndex(size_t offset, size_t index, size_t length)
|
static size_t OffsetIndex(size_t offset, size_t index, size_t length)
|
||||||
{
|
{
|
||||||
// TODO: Possible overflow here.
|
// TODO: Possible overflow here.
|
||||||
|
@ -58,7 +60,8 @@ namespace Sortix
|
||||||
{
|
{
|
||||||
size_t newbufferlength = (bufferlength) ? bufferlength * 2 : 32UL;
|
size_t newbufferlength = (bufferlength) ? bufferlength * 2 : 32UL;
|
||||||
uint32_t* newbuffer = new uint32_t[newbufferlength];
|
uint32_t* newbuffer = new uint32_t[newbufferlength];
|
||||||
if ( !newbuffer ) { return false; }
|
if ( !newbuffer )
|
||||||
|
return false;
|
||||||
size_t elemsize = sizeof(*buffer);
|
size_t elemsize = sizeof(*buffer);
|
||||||
size_t leadingavai = bufferlength-bufferoffset;
|
size_t leadingavai = bufferlength-bufferoffset;
|
||||||
size_t leading = (leadingavai < bufferused) ? leadingavai : bufferused;
|
size_t leading = (leadingavai < bufferused) ? leadingavai : bufferused;
|
||||||
|
@ -78,7 +81,8 @@ namespace Sortix
|
||||||
|
|
||||||
uint32_t LineBuffer::Pop()
|
uint32_t LineBuffer::Pop()
|
||||||
{
|
{
|
||||||
if ( !CanPop() ) { return 0; }
|
if ( !CanPop() )
|
||||||
|
return 0;
|
||||||
uint32_t result = Peek();
|
uint32_t result = Peek();
|
||||||
bufferoffset = (bufferoffset+1) % bufferlength;
|
bufferoffset = (bufferoffset+1) % bufferlength;
|
||||||
buffercommitted--;
|
buffercommitted--;
|
||||||
|
@ -89,21 +93,24 @@ namespace Sortix
|
||||||
|
|
||||||
uint32_t LineBuffer::Peek() const
|
uint32_t LineBuffer::Peek() const
|
||||||
{
|
{
|
||||||
if ( !CanPop() ) { return 0; }
|
if ( !CanPop() )
|
||||||
|
return 0;
|
||||||
size_t index = OffsetIndex(bufferoffset, 0, bufferlength);
|
size_t index = OffsetIndex(bufferoffset, 0, bufferlength);
|
||||||
return buffer[index];
|
return buffer[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t LineBuffer::Backspace()
|
uint32_t LineBuffer::Backspace()
|
||||||
{
|
{
|
||||||
if ( !CanBackspace() ) { return 0; }
|
if ( !CanBackspace() )
|
||||||
|
return 0;
|
||||||
size_t index = OffsetIndex(bufferoffset, --bufferused, bufferlength);
|
size_t index = OffsetIndex(bufferoffset, --bufferused, bufferlength);
|
||||||
return buffer[index];
|
return buffer[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t LineBuffer::WouldBackspace() const
|
uint32_t LineBuffer::WouldBackspace() const
|
||||||
{
|
{
|
||||||
if ( !CanBackspace() ) { return 0; }
|
if ( !CanBackspace() )
|
||||||
|
return 0;
|
||||||
size_t index = OffsetIndex(bufferoffset, bufferused-1, bufferlength);
|
size_t index = OffsetIndex(bufferoffset, bufferused-1, bufferlength);
|
||||||
return buffer[index];
|
return buffer[index];
|
||||||
}
|
}
|
||||||
|
@ -127,4 +134,5 @@ namespace Sortix
|
||||||
{
|
{
|
||||||
return bufferused - bufferfrozen;
|
return bufferused - bufferfrozen;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
} // namespace Sortix
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2013, 2014.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -25,8 +25,11 @@
|
||||||
#ifndef SORTIX_LINEBUFFER_H
|
#ifndef SORTIX_LINEBUFFER_H
|
||||||
#define SORTIX_LINEBUFFER_H
|
#define SORTIX_LINEBUFFER_H
|
||||||
|
|
||||||
namespace Sortix
|
#include <stddef.h>
|
||||||
{
|
#include <stdint.h>
|
||||||
|
|
||||||
|
namespace Sortix {
|
||||||
|
|
||||||
class LineBuffer
|
class LineBuffer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -53,6 +56,7 @@ namespace Sortix
|
||||||
size_t bufferused;
|
size_t bufferused;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
} // namespace Sortix
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue