Files
mir_server/Gateway/srvlib/include/container/queue_list.h
aixianling 5c9f1dae4a init
2025-01-09 17:45:40 +08:00

59 lines
1.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef _MBASE_QUEUELIST_H_
#define _MBASE_QUEUELIST_H_
#include "lock_list.h"
#include "container/vector.h"
namespace container
{
template <typename T>
class QueueList :
public LockList<T>
{
public:
typedef LockList<T> Inherited;
typedef QueueList<T> ListClass;
private:
Vector<T> append_list_; //数据追加列表
public:
//添加数据数据将在调用flush或tryFlush是被提交到自身列表中
inline void append(const T& data)
{
this->lock();
append_list_.add(data);
this->unlock();
}
inline void appendList(Vector<T> &list)
{
this->lock();
append_list_.addArray(list, list.count());
this->unlock();
}
inline void appendArray(T* data, int length)
{
this->lock();
append_list_.addArray(data, length);
this->unlock();
}
//获取追加数据数量
inline int appendCount()
{
return append_list_.count();
}
//提交由append调用添加的数据
inline void flush()
{
this->lock();
if ( append_list_.count() > 0 )
{
this->addList(append_list_);
append_list_.trunc(0);
}
this->unlock();
}
};
};
#endif