summaryrefslogtreecommitdiff
path: root/src/context/cdqueue.h
blob: 8e8c5c0d75f70478e3ceba84f4a43216ca5f2170 (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
/*********************                                                        */
/*! \file cdqueue.h
 ** \verbatim
 ** Original author: taking
 ** Major contributors: none
 ** Minor contributors (to current version): none
 ** This file is part of the CVC4 prototype.
 ** Copyright (c) 2009, 2010, 2011  The Analysis of Computer Systems Group (ACSys)
 ** Courant Institute of Mathematical Sciences
 ** New York University
 ** See the file COPYING in the top-level source directory for licensing
 ** information.\endverbatim
 **
 ** \brief Context-dependent queue class
 **
 ** Context-dependent First-In-First-Out queue class.
 ** The implementation is based on a combination of CDList and a CDO<size_t>
 ** for tracking the next element to dequeue from the list.
 ** The implementation is currently very simple.
 **/


#include "cvc4_private.h"

#ifndef __CVC4__CONTEXT__CDQUEUE_H
#define __CVC4__CONTEXT__CDQUEUE_H

#include "context/context.h"
#include "context/cdlist.h"

namespace CVC4 {
namespace context {


template <class T>
class CDQueue {
private:

  /** List of elements in the queue. */
  CDList<T> d_list;

  /** Points to the next element in the current context to dequeue. */
  CDO<size_t> d_iter;


public:

  /** Creates a new CDQueue associated with the current context. */
  CDQueue(Context* context)
    : d_list(context),
      d_iter(context, 0)
  {}

  /** Returns true if the queue is empty in the current context. */
  bool empty() const{
    return d_iter >= d_list.size();
  }

  /** Enqueues an element in the current context. */
  void enqueue(const T& data){
    d_list.push_back(data);
  }

  /** Returns a reference to the next element on the queue. */
  const T& dequeue(){
    Assert(!empty(), "Attempting to queue from an empty queue.");
    size_t front = d_iter;
    d_iter = d_iter + 1;
    return d_list[front];
  }

};/* class CDQueue<> */

}/* CVC4::context namespace */
}/* CVC4 namespace */

#endif /* __CVC4__CONTEXT__CDQUEUE_H */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback