6#ifndef _ZFI_ZFCoreQueue_h_
7#define _ZFI_ZFCoreQueue_h_
18template<
typename T_POD>
30 , _bufHead(_bufBuiltin)
31 , _bufTail(_bufBuiltin + _bufSize)
37 if(_bufHead != _bufBuiltin) {
67 ret += token.tokenLeft;
68 for(T_POD *p = _pHead; p != _pTail &&
count < maxCount; ++
count, _loopNext(p)) {
70 ret += token.tokenSeparator;
72 ret += token.tokenValueLeft;
79 ret += token.tokenValueRight;
81 if(count < this->
count()) {
83 ret += token.tokenSeparator;
85 ret += token.tokenEtc;
87 ret += token.tokenRight;
113 return (_bufTail - _bufHead - 1);
122 _bufChange(bufHeadNew, bufHeadNew +
capacity + 1);
131 if(_bufHead != _bufBuiltin) {
132 _bufChange(_bufBuiltin, _bufBuiltin + _bufSize);
139 _bufChange(bufHeadNew, bufHeadNew +
capacity + 1);
168 template<
typename T_Type>
170 for(
zfindex i = 0, iEnd = arr.count(); i < iEnd; ++i) {
179 ZF_IN const T_POD *buf
186 if(_pHead <= _pTail) {
187 if(_pTail +
count < _bufTail) {
192 zfindex tmp = _bufTail - _pTail;
193 zfmemcpy(_pTail, buf, tmp *
sizeof(T_POD));
194 zfmemcpy(_bufHead, buf + tmp, (
count - tmp) *
sizeof(T_POD));
195 _pTail = _bufHead + (
count - tmp);
218 if(_pTail == _bufHead) {
219 _pTail = _bufTail - 1;
232 return ((_pTail >= _pHead)
234 : ((_bufTail - _pHead) + (_pTail - _bufHead)));
240 return (_pHead == _pTail);
256 template<
typename T_Type>
258 array.capacity(array.capacity() + this->count());
275 T_POD _bufBuiltin[_bufSize];
281 inline void _loopNext(
ZF_IN_OUT T_POD *&p)
const {
288 ZF_IN T_POD *bufHeadNew
289 ,
ZF_IN T_POD *bufTailNew
291 T_POD *pTailNew = bufHeadNew + this->count();
293 if(_pTail >= _pHead) {
294 zfmemcpy(bufHeadNew, _pHead, (_pTail - _pHead) *
sizeof(T_POD));
297 zfmemcpy(bufHeadNew, _pHead, (_bufTail - _pHead) *
sizeof(T_POD));
298 zfmemcpy(bufHeadNew + (_bufTail - _pHead), _bufHead, (_pTail - _bufHead) *
sizeof(T_POD));
301 if(_bufHead != _bufBuiltin) {
304 _bufHead = bufHeadNew;
305 _bufTail = bufTailNew;
#define ZFCoreAssertWithMessage(exp, fmt,...)
ZFCoreAssert with custom message
Definition ZFCoreLog_CommonLog.h:71
#define zffinal
dummy macro shows that a method or class is designed must not to be overrided
Definition ZFCoreTypeDef_ClassType.h:63
#define zfclassLikePOD
shows the class is not a POD type, but you may use it like a POD except memset it to 0
Definition ZFCoreTypeDef_ClassType.h:41
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:196
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:200
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:212
void * zfmemcpy(void *dst, const void *src, zfindex size)
wrapper to memcpy
Definition ZFCoreTypeDef_ClassType.h:156
_ZFT_t_zfbool zfbool
bool type
Definition ZFCoreTypeDef_CoreType.h:103
_ZFT_t_zfindex zfindex
similar to size_t, used for index and size only
Definition ZFCoreTypeDef_CoreType.h:154
#define zfindexMax()
(zfindex)-1, indicate a max index value, see zfindex
Definition ZFCoreTypeDef_CoreType.h:159
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZFOUTPUT_TYPE_TEMPLATE(T_typenameList, T_Type, outputAction)
see ZFOUTPUT_TYPE
Definition ZFCoreTypeDef_OtherType.h:262
void zftToStringT(zfstring &s, T_Type const &v)
util function to obtain object info
Definition ZFCoreTypeDef_OtherType.h:182
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define zfpoolFree(p)
see zfnew
Definition ZFMemPool.h:100
#define zfpoolMalloc(size)
see zfnew
Definition ZFMemPool.h:98
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define ZFTokenForContainerDefault()
see ZFTokenForContainer, modifyable, ZFTokenForContainerTrim by default
Definition ZFToken.h:107
light weight array
Definition ZFCoreArray.h:292
void(* InfoGetter)(zfstring &ret, T_Type const &v)
proto type for obtain object info, see zftToStringT
Definition ZFCoreTypeDef_OtherType.h:151
core queue type for performance and for private use only
Definition ZFCoreQueue.h:19
void capacity(zfindex capacity)
change the capacity
Definition ZFCoreQueue.h:118
T_POD & add(void)
push element at tail of the queue, auto increase capacity if necessary
Definition ZFCoreQueue.h:149
zfstring objectInfo(void) const
return object info
Definition ZFCoreQueue.h:52
T_POD & take(void)
take element at head of the queue, assert fail if empty
Definition ZFCoreQueue.h:206
void add(T_POD const &e)
push element at tail of the queue, auto increase capacity if necessary
Definition ZFCoreQueue.h:159
zfindex capacity(void) const
get current capacity
Definition ZFCoreQueue.h:112
void removeAll(void)
remove all contents
Definition ZFCoreQueue.h:247
void capacityTrim(void)
trim the buffer, call only if necessary
Definition ZFCoreQueue.h:128
zfindex count(void) const
element count of this array
Definition ZFCoreQueue.h:231
T_POD & takeLast(void)
take element at tail of the queue, assert fail if empty
Definition ZFCoreQueue.h:216
ZFCoreArray< T_POD > toArray(void) const
copy contents to array
Definition ZFCoreQueue.h:268
void objectInfoT(zfstring &ret) const
see objectInfo
Definition ZFCoreQueue.h:48
void addFrom(const ZFCoreArray< T_Type > &arr)
push element at tail of the queue, auto increase capacity if necessary
Definition ZFCoreQueue.h:169
void objectInfoOfContentT(zfstring &ret, zfindex maxCount=((zfindex) -1), const ZFTokenForContainer &token=_ZFP_ZFTokenForContainerDefault, typename ZFCoreInfoGetter< T_POD >::InfoGetter infoGetter=zft_zfnull) const
see objectInfoOfContent
Definition ZFCoreQueue.h:60
zfstring objectInfoOfContent(zfindex maxCount=((zfindex) -1), const ZFTokenForContainer &token=_ZFP_ZFTokenForContainerDefault, typename ZFCoreInfoGetter< T_POD >::InfoGetter infoGetter=zft_zfnull) const
return contents info
Definition ZFCoreQueue.h:92
ZFCoreQueuePOD(void)
main constructor
Definition ZFCoreQueue.h:28
zfbool isEmpty(void) const
true if empty
Definition ZFCoreQueue.h:239
void addFrom(const T_POD *buf, zfindex count)
push element at tail of the queue, auto increase capacity if necessary
Definition ZFCoreQueue.h:178
void toArrayT(ZFCoreArray< T_Type > &array) const
copy contents to array
Definition ZFCoreQueue.h:257
util class to hold string tokens
Definition ZFToken.h:17
void ZFCoreCapacityOptimize(zfindex &capacity)
util to optimize capacity
Definition zfstring.h:20