You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
125 lines
1.6 KiB
125 lines
1.6 KiB
3 years ago
|
/**
|
||
|
* @file ChunkStack.h
|
||
|
* Manages a simple stack of chunks
|
||
|
*
|
||
|
* @author Ben Gardner
|
||
|
* @license GPL v2+
|
||
|
*/
|
||
|
#ifndef CHUNKSTACK_H_INCLUDED
|
||
|
#define CHUNKSTACK_H_INCLUDED
|
||
|
|
||
6 months ago
|
#include "chunk.h"
|
||
3 years ago
|
#include "uncrustify_types.h"
|
||
|
|
||
|
class ChunkStack
|
||
|
{
|
||
|
public:
|
||
|
struct Entry
|
||
|
{
|
||
|
Entry()
|
||
|
: m_seqnum(0)
|
||
6 months ago
|
, m_pc(Chunk::NullChunkPtr)
|
||
3 years ago
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
Entry(const Entry &ref)
|
||
|
: m_seqnum(ref.m_seqnum)
|
||
|
, m_pc(ref.m_pc)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
2 years ago
|
Entry(size_t sn, Chunk *pc)
|
||
3 years ago
|
: m_seqnum(sn)
|
||
|
, m_pc(pc)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
2 years ago
|
size_t m_seqnum;
|
||
|
Chunk *m_pc;
|
||
3 years ago
|
};
|
||
|
|
||
|
protected:
|
||
|
std::deque<Entry> m_cse;
|
||
|
size_t m_seqnum; //! current sequence number
|
||
|
|
||
|
public:
|
||
|
ChunkStack()
|
||
|
: m_seqnum(0)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
ChunkStack(const ChunkStack &cs)
|
||
|
{
|
||
|
Set(cs);
|
||
|
}
|
||
|
|
||
|
|
||
|
virtual ~ChunkStack()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
|
||
|
void Set(const ChunkStack &cs);
|
||
|
|
||
|
|
||
2 years ago
|
void Push_Back(Chunk *pc)
|
||
3 years ago
|
{
|
||
|
Push_Back(pc, ++m_seqnum);
|
||
|
}
|
||
|
|
||
|
|
||
|
bool Empty() const
|
||
|
{
|
||
|
return(m_cse.empty());
|
||
|
}
|
||
|
|
||
|
|
||
|
size_t Len() const
|
||
|
{
|
||
|
return(m_cse.size());
|
||
|
}
|
||
|
|
||
|
|
||
|
const Entry *Top() const;
|
||
|
|
||
|
|
||
|
const Entry *Get(size_t idx) const;
|
||
|
|
||
|
|
||
2 years ago
|
Chunk *GetChunk(size_t idx) const;
|
||
3 years ago
|
|
||
|
|
||
2 years ago
|
Chunk *Pop_Back();
|
||
3 years ago
|
|
||
|
|
||
2 years ago
|
void Push_Back(Chunk *pc, size_t seqnum);
|
||
3 years ago
|
|
||
|
|
||
2 years ago
|
Chunk *Pop_Front();
|
||
3 years ago
|
|
||
|
|
||
|
void Reset()
|
||
|
{
|
||
|
m_cse.clear();
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Mark an entry to be removed by Collapse()
|
||
|
*
|
||
|
* @param idx The item to remove
|
||
|
*/
|
||
|
void Zap(size_t idx);
|
||
|
|
||
|
|
||
|
//! Compresses down the stack by removing dead entries
|
||
|
void Collapse();
|
||
|
};
|
||
|
|
||
|
|
||
|
#endif /* CHUNKSTACK_H_INCLUDED */
|