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;
106 else if(capacity < 64) {
107 capacity = ((capacity / 16) + 1) * 16 - 1;
109 else if(capacity < 256) {
110 capacity = ((capacity / 64) + 1) * 64 - 1;
113 capacity = ((capacity / 256) + 1) * 256 - 1;
123 return (_bufTail - _bufHead - 1);
132 _bufChange(bufHeadNew, bufHeadNew +
capacity + 1);
141 if(_bufHead != _bufBuiltin) {
142 _bufChange(_bufBuiltin, _bufBuiltin + _bufSize);
149 _bufChange(bufHeadNew, bufHeadNew +
capacity + 1);
160 this->capacity(this->
count() + 1);
170 this->capacity(this->
count() + 1);
178 template<
typename T_Type>
180 for(
zfindex i = 0, iEnd = arr.count(); i < iEnd; ++i) {
189 ZF_IN const T_POD *buf
195 this->capacity(this->count() +
count);
196 if(_pHead <= _pTail) {
197 if(_pTail +
count < _bufTail) {
202 zfindex tmp = _bufTail - _pTail;
203 zfmemcpy(_pTail, buf, tmp *
sizeof(T_POD));
204 zfmemcpy(_bufHead, buf + tmp, (
count - tmp) *
sizeof(T_POD));
205 _pTail = _bufHead + (
count - tmp);
228 if(_pTail == _bufHead) {
229 _pTail = _bufTail - 1;
242 return ((_pTail >= _pHead)
244 : ((_bufTail - _pHead) + (_pTail - _bufHead)));
250 return (_pHead == _pTail);
266 template<
typename T_Type>
268 array.capacity(array.capacity() + this->count());
285 T_POD _bufBuiltin[_bufSize];
291 inline void _loopNext(
ZF_IN_OUT T_POD *&p)
const {
298 ZF_IN T_POD *bufHeadNew
299 ,
ZF_IN T_POD *bufTailNew
301 T_POD *pTailNew = bufHeadNew + this->count();
303 if(_pTail >= _pHead) {
304 zfmemcpy(bufHeadNew, _pHead, (_pTail - _pHead) *
sizeof(T_POD));
307 zfmemcpy(bufHeadNew, _pHead, (_bufTail - _pHead) *
sizeof(T_POD));
308 zfmemcpy(bufHeadNew + (_bufTail - _pHead), _bufHead, (_pTail - _bufHead) *
sizeof(T_POD));
311 if(_bufHead != _bufBuiltin) {
314 _bufHead = bufHeadNew;
315 _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 zffree(ptr)
same as free defined for future use, do nothing if ptr is NULL
Definition ZFCoreTypeDef_ClassType.h:112
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
void * zfmemcpy(void *dst, const void *src, zfindex size)
wrapper to memcpy
Definition ZFCoreTypeDef_ClassType.h:140
#define zfmalloc(size)
same as malloc defined for future use
Definition ZFCoreTypeDef_ClassType.h:100
_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 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:331
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:128
T_POD & add(void)
push element at tail of the queue, auto increase capacity if necessary
Definition ZFCoreQueue.h:159
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:216
void add(T_POD const &e)
push element at tail of the queue, auto increase capacity if necessary
Definition ZFCoreQueue.h:169
zfindex capacity(void) const
get current capacity
Definition ZFCoreQueue.h:122
void removeAll(void)
remove all contents
Definition ZFCoreQueue.h:257
void capacityTrim(void)
trim the buffer, call only if necessary
Definition ZFCoreQueue.h:138
zfindex count(void) const
element count of this array
Definition ZFCoreQueue.h:241
T_POD & takeLast(void)
take element at tail of the queue, assert fail if empty
Definition ZFCoreQueue.h:226
ZFCoreArray< T_POD > toArray(void) const
copy contents to array
Definition ZFCoreQueue.h:278
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:179
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:249
void addFrom(const T_POD *buf, zfindex count)
push element at tail of the queue, auto increase capacity if necessary
Definition ZFCoreQueue.h:188
void toArrayT(ZFCoreArray< T_Type > &array) const
copy contents to array
Definition ZFCoreQueue.h:267
util class to hold string tokens
Definition ZFToken.h:17