| 142 | }; |
| 143 | |
| 144 | class IcuCalendarWrapper |
| 145 | { |
| 146 | public: |
| 147 | IcuCalendarWrapper(UCalendar* aWrapped, std::atomic<UCalendar*>* aCachePtr) |
| 148 | : wrapped(aWrapped), |
| 149 | cachePtr(aCachePtr) |
| 150 | {} |
| 151 | |
| 152 | IcuCalendarWrapper(IcuCalendarWrapper&& o) |
| 153 | : wrapped(o.wrapped), |
| 154 | cachePtr(o.cachePtr) |
| 155 | { |
| 156 | o.wrapped = nullptr; |
| 157 | } |
| 158 | |
| 159 | ~IcuCalendarWrapper() |
| 160 | { |
| 161 | if (wrapped) |
| 162 | { |
| 163 | auto newCached = cachePtr->exchange(wrapped); |
| 164 | |
| 165 | if (newCached) |
| 166 | { |
| 167 | auto& icuLib = Jrd::UnicodeUtil::getConversionICU(); |
| 168 | icuLib.ucalClose(newCached); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | IcuCalendarWrapper(const IcuCalendarWrapper&) = delete; |
| 174 | IcuCalendarWrapper& operator=(const IcuCalendarWrapper&) = delete; |
| 175 | |
| 176 | public: |
| 177 | UCalendar* operator->() |
| 178 | { |
| 179 | return wrapped; |
| 180 | } |
| 181 | |
| 182 | operator UCalendar*() |
| 183 | { |
| 184 | return wrapped; |
| 185 | } |
| 186 | |
| 187 | bool operator!() const |
| 188 | { |
| 189 | return !wrapped; |
| 190 | } |
| 191 | |
| 192 | private: |
| 193 | UCalendar* wrapped; |
| 194 | std::atomic<UCalendar*>* cachePtr; |
| 195 | }; |
| 196 | |
| 197 | class TimeZoneRuleIterator |
| 198 | { |