First effort to revive BasicBlock and Function classes and
[jitcs.git] / include / jitcs_adt_enumerator.h
blob3f77c05d27eae7c87ab2056ebca6fa8e24c3637f
1 //===-- jitcs_adt_enumerator.h - --------------------------------*- C++ -*-===//
2 //
3 //
4 //===----------------------------------------------------------------------===//
6 #ifndef _JITCS_ADT_ENUMERATOR_H_
7 #define _JITCS_ADT_ENUMERATOR_H_
9 #include "jitcs_base.h"
10 #include <memory>
12 namespace jitcs {
13 template <typename T>
14 class IEnumerator {
15 public:
16 typedef T ItemType;
17 virtual bool empty() const = 0;
18 virtual T& front() = 0;
19 virtual void popFront() = 0;
21 template <typename T>
22 class Enumerator {
23 public:
24 Enumerator() = delete;
25 Enumerator(const Enumerator&) = delete;
26 Enumerator& operator =(const Enumerator&) = delete;
27 Enumerator(Enumerator&&) = default;
28 Enumerator& operator =(Enumerator&&) = default;
29 Enumerator(std::unique_ptr<IEnumerator<T>> && e) : _e(std::move(e)) {}
31 bool empty() const { return _e->empty(); }
32 T& front() { return _e->front(); }
33 void popFront() { return _e->popFront(); }
34 private:
35 std::unique_ptr<IEnumerator<T>> _e;
37 } // end namespace jitcs
39 #endif
40 // _JITCS_ADT_ENUMERATOR_H_