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"
21 #include "dictionary/interface/dictionary_shortcuts_structure_policy.h"
22 
23 namespace latinime {
24 
25 class BinaryDictionaryShortcutIterator {
26  public:
BinaryDictionaryShortcutIterator(const DictionaryShortcutsStructurePolicy * const shortcutStructurePolicy,const int shortcutPos)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 
BinaryDictionaryShortcutIterator(const BinaryDictionaryShortcutIterator && shortcutIterator)34     BinaryDictionaryShortcutIterator(const BinaryDictionaryShortcutIterator &&shortcutIterator) noexcept
35             : mShortcutStructurePolicy(shortcutIterator.mShortcutStructurePolicy),
36               mPos(shortcutIterator.mPos),
37               mHasNextShortcutTarget(shortcutIterator.mHasNextShortcutTarget) {}
38 
hasNextShortcutTarget()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
44     // to outTargetLength, put whether it is allowlist to outIsAllowed.
nextShortcutTarget(const int maxDepth,int * const outTarget,int * const outTargetLength,bool * const outIsAllowed)45     AK_FORCE_INLINE void nextShortcutTarget(
46             const int maxDepth, int *const outTarget, int *const outTargetLength,
47             bool *const outIsAllowed) {
48         mShortcutStructurePolicy->getNextShortcut(maxDepth, outTarget, outTargetLength,
49                 outIsAllowed, &mHasNextShortcutTarget, &mPos);
50     }
51 
52  private:
53     DISALLOW_DEFAULT_CONSTRUCTOR(BinaryDictionaryShortcutIterator);
54     DISALLOW_ASSIGNMENT_OPERATOR(BinaryDictionaryShortcutIterator);
55 
56     const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy;
57     int mPos;
58     bool mHasNextShortcutTarget;
59 };
60 } // namespace latinime
61 #endif // LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H
62