| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #ifndef GUARD_TLATE_HEADER_VALUE_HH |
|---|
| 21 | #define GUARD_TLATE_HEADER_VALUE_HH |
|---|
| 22 | |
|---|
| 23 | #include "field_value.hh" |
|---|
| 24 | #include "sequential_value.hh" |
|---|
| 25 | #include "../msg/entity.hh" |
|---|
| 26 | |
|---|
| 27 | namespace tlate |
|---|
| 28 | { |
|---|
| 29 | class header_value : public sequential_value |
|---|
| 30 | { |
|---|
| 31 | msg::entity::const_ptr m; |
|---|
| 32 | bool munge; |
|---|
| 33 | |
|---|
| 34 | class vit : public virtual_iterator |
|---|
| 35 | { |
|---|
| 36 | msg::entity::field_iterator it; |
|---|
| 37 | mutable value::const_ptr cur; |
|---|
| 38 | bool munge; |
|---|
| 39 | |
|---|
| 40 | vit(msg::entity::field_iterator it, |
|---|
| 41 | value::const_ptr cur, |
|---|
| 42 | bool munge) |
|---|
| 43 | : it(it) |
|---|
| 44 | , cur(cur) |
|---|
| 45 | , munge(munge) |
|---|
| 46 | {} |
|---|
| 47 | public: |
|---|
| 48 | vit(msg::entity::field_iterator it, bool munge) |
|---|
| 49 | : it(it) |
|---|
| 50 | , munge(munge) |
|---|
| 51 | {} |
|---|
| 52 | virtual_iterator *clone() const { |
|---|
| 53 | return new vit(it, cur, munge); |
|---|
| 54 | } |
|---|
| 55 | value::const_ptr get() const { |
|---|
| 56 | if (!cur) |
|---|
| 57 | cur.reset(new field_value(*it, munge)); |
|---|
| 58 | return cur; |
|---|
| 59 | } |
|---|
| 60 | void next() { |
|---|
| 61 | it++; |
|---|
| 62 | cur.reset(); |
|---|
| 63 | } |
|---|
| 64 | bool eq(const virtual_iterator &o_) const { |
|---|
| 65 | const vit *o = dynamic_cast<const vit *>(&o_); |
|---|
| 66 | return o ? it == o->it : false; |
|---|
| 67 | } |
|---|
| 68 | }; |
|---|
| 69 | |
|---|
| 70 | public: |
|---|
| 71 | header_value(msg::entity::const_ptr m, bool munge) |
|---|
| 72 | : m(m) |
|---|
| 73 | , munge(munge) |
|---|
| 74 | {} |
|---|
| 75 | const_iterator begin() const { |
|---|
| 76 | return const_iterator |
|---|
| 77 | (new vit(m->fields_begin(), munge)); |
|---|
| 78 | } |
|---|
| 79 | const_iterator end() const { |
|---|
| 80 | return const_iterator |
|---|
| 81 | (new vit(m->fields_end(), munge)); |
|---|
| 82 | } |
|---|
| 83 | }; |
|---|
| 84 | |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | #endif |
|---|