summaryrefslogtreecommitdiffstats
path: root/debian/uncrustify-trinity/uncrustify-trinity-0.75.0/src/ChunkStack.h
blob: b33e1dd5b58cb47f3084bc20d7731356e97967d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
 * @file ChunkStack.h
 * Manages a simple stack of chunks
 *
 * @author  Ben Gardner
 * @license GPL v2+
 */
#ifndef CHUNKSTACK_H_INCLUDED
#define CHUNKSTACK_H_INCLUDED

#include "uncrustify_types.h"

class ChunkStack
{
public:
   struct Entry
   {
      Entry()
         : m_seqnum(0)
         , m_pc(0)
      {
      }


      Entry(const Entry &ref)
         : m_seqnum(ref.m_seqnum)
         , m_pc(ref.m_pc)
      {
      }


      Entry(size_t sn, Chunk *pc)
         : m_seqnum(sn)
         , m_pc(pc)
      {
      }


      size_t m_seqnum;
      Chunk  *m_pc;
   };

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);


   void Push_Back(Chunk *pc)
   {
      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;


   Chunk *GetChunk(size_t idx) const;


   Chunk *Pop_Back();


   void Push_Back(Chunk *pc, size_t seqnum);


   Chunk *Pop_Front();


   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 */