Commit 86e7cacff1b34cb251794974e675c35a76429722
1 parent
873562f4
Make BaseDictionary iterable
Showing
1 changed file
with
78 additions
and
0 deletions
libqpdf/qpdf/QPDFObjectHandle_private.hh
| ... | ... | @@ -42,6 +42,84 @@ namespace qpdf |
| 42 | 42 | class BaseDictionary: public BaseHandle |
| 43 | 43 | { |
| 44 | 44 | public: |
| 45 | + using iterator = std::map<std::string, QPDFObjectHandle>::iterator; | |
| 46 | + using const_iterator = std::map<std::string, QPDFObjectHandle>::const_iterator; | |
| 47 | + using reverse_iterator = std::map<std::string, QPDFObjectHandle>::reverse_iterator; | |
| 48 | + using const_reverse_iterator = | |
| 49 | + std::map<std::string, QPDFObjectHandle>::const_reverse_iterator; | |
| 50 | + | |
| 51 | + iterator | |
| 52 | + begin() | |
| 53 | + { | |
| 54 | + if (auto d = as<QPDF_Dictionary>()) { | |
| 55 | + return d->items.begin(); | |
| 56 | + } | |
| 57 | + return {}; | |
| 58 | + } | |
| 59 | + | |
| 60 | + iterator | |
| 61 | + end() | |
| 62 | + { | |
| 63 | + if (auto d = as<QPDF_Dictionary>()) { | |
| 64 | + return d->items.end(); | |
| 65 | + } | |
| 66 | + return {}; | |
| 67 | + } | |
| 68 | + | |
| 69 | + const_iterator | |
| 70 | + cbegin() | |
| 71 | + { | |
| 72 | + if (auto d = as<QPDF_Dictionary>()) { | |
| 73 | + return d->items.cbegin(); | |
| 74 | + } | |
| 75 | + return {}; | |
| 76 | + } | |
| 77 | + | |
| 78 | + const_iterator | |
| 79 | + cend() | |
| 80 | + { | |
| 81 | + if (auto d = as<QPDF_Dictionary>()) { | |
| 82 | + return d->items.cend(); | |
| 83 | + } | |
| 84 | + return {}; | |
| 85 | + } | |
| 86 | + | |
| 87 | + reverse_iterator | |
| 88 | + rbegin() | |
| 89 | + { | |
| 90 | + if (auto d = as<QPDF_Dictionary>()) { | |
| 91 | + return d->items.rbegin(); | |
| 92 | + } | |
| 93 | + return {}; | |
| 94 | + } | |
| 95 | + | |
| 96 | + reverse_iterator | |
| 97 | + rend() | |
| 98 | + { | |
| 99 | + if (auto d = as<QPDF_Dictionary>()) { | |
| 100 | + return d->items.rend(); | |
| 101 | + } | |
| 102 | + return {}; | |
| 103 | + } | |
| 104 | + | |
| 105 | + const_reverse_iterator | |
| 106 | + crbegin() | |
| 107 | + { | |
| 108 | + if (auto d = as<QPDF_Dictionary>()) { | |
| 109 | + return d->items.crbegin(); | |
| 110 | + } | |
| 111 | + return {}; | |
| 112 | + } | |
| 113 | + | |
| 114 | + const_reverse_iterator | |
| 115 | + crend() | |
| 116 | + { | |
| 117 | + if (auto d = as<QPDF_Dictionary>()) { | |
| 118 | + return d->items.crend(); | |
| 119 | + } | |
| 120 | + return {}; | |
| 121 | + } | |
| 122 | + | |
| 45 | 123 | // The following methods are not part of the public API. |
| 46 | 124 | bool hasKey(std::string const& key) const; |
| 47 | 125 | QPDFObjectHandle getKey(std::string const& key) const; | ... | ... |