📄 ringbuf.hpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/* -*-C-*-
*
* ringbuf:
*
* Class implementing a simple ring buffer
*
* Release Status:OS005-SW-70002-r0p0-00REL0
* $Copyright:
* ----------------------------------------------------------------
* This confidential and proprietary software may be used only as
* authorised by a licensing agreement from ARM Limited
* (C) COPYRIGHT 2004 ARM Limited
* ALL RIGHTS RESERVED
* The entire notice above must be reproduced on all authorised
* copies and copies may only be made to the extent permitted
* by a licensing agreement from ARM Limited.
* ----------------------------------------------------------------
* File: ringbuf.hpp,v
* Revision: 1.1
* ----------------------------------------------------------------
* $
*/
#ifndef ringbuf_hpp
#define ringbuf_hpp
class RingBuf
{
public:
RingBuf(void)
{
fillindex = drainindex = 0;
indexmask = 0x07;
buffer = new unsigned int[8];
}
~RingBuf(void)
{
delete[] buffer;
}
inline bool add(unsigned int value)
{
if (fillindex != ((drainindex - 1) & indexmask))
{
buffer[fillindex] = value;
++fillindex;
fillindex &= indexmask;
return true;
}
else
return false;
}
inline bool extract(unsigned int *value)
{
if (drainindex != fillindex)
{
*value = buffer[drainindex];
++drainindex;
drainindex &= indexmask;
return true;
}
else
return false;
}
inline bool peek(unsigned int *value)
{
if (drainindex != fillindex)
{
*value = buffer[drainindex];
return true;
}
else
return false;
}
inline void advancedrain(void)
{
if (drainindex != fillindex)
{
++drainindex;
drainindex &= indexmask;
}
}
inline bool empty(void)
{
return fillindex == drainindex;
}
private:
unsigned int fillindex;
unsigned int drainindex;
unsigned int *buffer;
unsigned int indexmask;
};
#endif /* ndef ringbuf_hpp */
/* EOF ringbuf.hpp */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -