Keisuke Kuroyanagi | 6abdafc | 2013-08-12 16:52:03 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H |
| 18 | #define LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H |
| 19 | |
| 20 | #include "defines.h" |
Keisuke Kuroyanagi | 88bc312 | 2014-12-17 16:02:09 +0900 | [diff] [blame] | 21 | #include "dictionary/interface/dictionary_shortcuts_structure_policy.h" |
Keisuke Kuroyanagi | 6abdafc | 2013-08-12 16:52:03 +0900 | [diff] [blame] | 22 | |
| 23 | namespace latinime { |
| 24 | |
| 25 | class BinaryDictionaryShortcutIterator { |
| 26 | public: |
| 27 | BinaryDictionaryShortcutIterator( |
| 28 | const DictionaryShortcutsStructurePolicy *const shortcutStructurePolicy, |
| 29 | const int shortcutPos) |
| 30 | : mShortcutStructurePolicy(shortcutStructurePolicy), |
| 31 | mPos(shortcutStructurePolicy->getStartPos(shortcutPos)), |
| 32 | mHasNextShortcutTarget(shortcutPos != NOT_A_DICT_POS) {} |
| 33 | |
Chih-Hung Hsieh | 66a88a5 | 2018-09-25 14:32:36 -0700 | [diff] [blame] | 34 | BinaryDictionaryShortcutIterator(const BinaryDictionaryShortcutIterator &&shortcutIterator) noexcept |
Keisuke Kuroyanagi | 847a026 | 2014-09-03 18:20:14 +0900 | [diff] [blame] | 35 | : mShortcutStructurePolicy(shortcutIterator.mShortcutStructurePolicy), |
| 36 | mPos(shortcutIterator.mPos), |
| 37 | mHasNextShortcutTarget(shortcutIterator.mHasNextShortcutTarget) {} |
| 38 | |
Keisuke Kuroyanagi | 6abdafc | 2013-08-12 16:52:03 +0900 | [diff] [blame] | 39 | AK_FORCE_INLINE bool hasNextShortcutTarget() const { |
| 40 | return mHasNextShortcutTarget; |
| 41 | } |
| 42 | |
| 43 | // Gets the shortcut target itself as an int string and put it to outTarget, put its length |
Seigo Nonaka | 0c549e7 | 2020-07-22 20:56:25 -0700 | [diff] [blame] | 44 | // to outTargetLength, put whether it is allowlist to outIsAllowed. |
Keisuke Kuroyanagi | 6abdafc | 2013-08-12 16:52:03 +0900 | [diff] [blame] | 45 | AK_FORCE_INLINE void nextShortcutTarget( |
| 46 | const int maxDepth, int *const outTarget, int *const outTargetLength, |
Seigo Nonaka | 0c549e7 | 2020-07-22 20:56:25 -0700 | [diff] [blame] | 47 | bool *const outIsAllowed) { |
Keisuke Kuroyanagi | 6abdafc | 2013-08-12 16:52:03 +0900 | [diff] [blame] | 48 | mShortcutStructurePolicy->getNextShortcut(maxDepth, outTarget, outTargetLength, |
Seigo Nonaka | 0c549e7 | 2020-07-22 20:56:25 -0700 | [diff] [blame] | 49 | outIsAllowed, &mHasNextShortcutTarget, &mPos); |
Keisuke Kuroyanagi | 6abdafc | 2013-08-12 16:52:03 +0900 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | private: |
Keisuke Kuroyanagi | 847a026 | 2014-09-03 18:20:14 +0900 | [diff] [blame] | 53 | DISALLOW_DEFAULT_CONSTRUCTOR(BinaryDictionaryShortcutIterator); |
| 54 | DISALLOW_ASSIGNMENT_OPERATOR(BinaryDictionaryShortcutIterator); |
Keisuke Kuroyanagi | 6abdafc | 2013-08-12 16:52:03 +0900 | [diff] [blame] | 55 | |
| 56 | const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy; |
| 57 | int mPos; |
| 58 | bool mHasNextShortcutTarget; |
| 59 | }; |
| 60 | } // namespace latinime |
| 61 | #endif // LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H |