| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef GUARD_TLATE_THREAD_VALUE_HH |
|---|
| 21 | #define GUARD_TLATE_THREAD_VALUE_HH |
|---|
| 22 | |
|---|
| 23 | #include "msg_value.hh" |
|---|
| 24 | #include "sequential_value.hh" |
|---|
| 25 | |
|---|
| 26 | #include "../db/threaded.hh" |
|---|
| 27 | |
|---|
| 28 | #include <vector> |
|---|
| 29 | |
|---|
| 30 | namespace db { class user; } |
|---|
| 31 | |
|---|
| 32 | namespace tlate |
|---|
| 33 | { |
|---|
| 34 | class thread_value : public sequential_value |
|---|
| 35 | { |
|---|
| 36 | typedef std::vector<db::thread_node::const_ptr> tl; |
|---|
| 37 | tl tnl; |
|---|
| 38 | boost::shared_ptr<const db::user> u; |
|---|
| 39 | private: |
|---|
| 40 | class vit : public virtual_iterator |
|---|
| 41 | { |
|---|
| 42 | tl::const_iterator it; |
|---|
| 43 | mutable value::ptr cur; |
|---|
| 44 | boost::shared_ptr<const db::user> u; |
|---|
| 45 | |
|---|
| 46 | public: |
|---|
| 47 | vit(tl::const_iterator it, |
|---|
| 48 | boost::shared_ptr<const db::user> u) |
|---|
| 49 | : it(it), u(u) |
|---|
| 50 | {} |
|---|
| 51 | |
|---|
| 52 | virtual_iterator *clone() const { |
|---|
| 53 | return new vit(*this); |
|---|
| 54 | } |
|---|
| 55 | value::const_ptr get() const { |
|---|
| 56 | if (!cur) cur = msg_value::mk(*it, u); |
|---|
| 57 | return cur; |
|---|
| 58 | } |
|---|
| 59 | void next() { |
|---|
| 60 | cur.reset(); |
|---|
| 61 | it++; |
|---|
| 62 | } |
|---|
| 63 | bool eq(const virtual_iterator &o_) const { |
|---|
| 64 | const vit *o = dynamic_cast<const vit *>(&o_); |
|---|
| 65 | return o ? it == o->it : false; |
|---|
| 66 | } |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | public: |
|---|
| 70 | typedef boost::shared_ptr<thread_value> ptr; |
|---|
| 71 | typedef boost::shared_ptr<const thread_value> const_ptr; |
|---|
| 72 | |
|---|
| 73 | const_iterator begin() const { return new vit(tnl.begin(), u); } |
|---|
| 74 | const_iterator end() const { return new vit(tnl.end(), u); } |
|---|
| 75 | |
|---|
| 76 | thread_value(db::thread_node::const_ptr tn, |
|---|
| 77 | boost::shared_ptr<const db::user> u); |
|---|
| 78 | void slice_window(size_t start, size_t length); |
|---|
| 79 | size_t size() const { return tnl.size(); } |
|---|
| 80 | }; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | #endif |
|---|