blob: 45c9cd36ded363df161c2cbce43040988761b361 [file] [log] [blame]
Keisuke Kuroyanagi6abdafc2013-08-12 16:52:03 +09001/*
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 Kuroyanagi88bc3122014-12-17 16:02:09 +090021#include "dictionary/interface/dictionary_shortcuts_structure_policy.h"
Keisuke Kuroyanagi6abdafc2013-08-12 16:52:03 +090022
23namespace latinime {
24
25class 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 Hsieh66a88a52018-09-25 14:32:36 -070034 BinaryDictionaryShortcutIterator(const BinaryDictionaryShortcutIterator &&shortcutIterator) noexcept
Keisuke Kuroyanagi847a0262014-09-03 18:20:14 +090035 : mShortcutStructurePolicy(shortcutIterator.mShortcutStructurePolicy),
36 mPos(shortcutIterator.mPos),
37 mHasNextShortcutTarget(shortcutIterator.mHasNextShortcutTarget) {}
38
Keisuke Kuroyanagi6abdafc2013-08-12 16:52:03 +090039 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 Nonaka0c549e72020-07-22 20:56:25 -070044 // to outTargetLength, put whether it is allowlist to outIsAllowed.
Keisuke Kuroyanagi6abdafc2013-08-12 16:52:03 +090045 AK_FORCE_INLINE void nextShortcutTarget(
46 const int maxDepth, int *const outTarget, int *const outTargetLength,
Seigo Nonaka0c549e72020-07-22 20:56:25 -070047 bool *const outIsAllowed) {
Keisuke Kuroyanagi6abdafc2013-08-12 16:52:03 +090048 mShortcutStructurePolicy->getNextShortcut(maxDepth, outTarget, outTargetLength,
Seigo Nonaka0c549e72020-07-22 20:56:25 -070049 outIsAllowed, &mHasNextShortcutTarget, &mPos);
Keisuke Kuroyanagi6abdafc2013-08-12 16:52:03 +090050 }
51
52 private:
Keisuke Kuroyanagi847a0262014-09-03 18:20:14 +090053 DISALLOW_DEFAULT_CONSTRUCTOR(BinaryDictionaryShortcutIterator);
54 DISALLOW_ASSIGNMENT_OPERATOR(BinaryDictionaryShortcutIterator);
Keisuke Kuroyanagi6abdafc2013-08-12 16:52:03 +090055
56 const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy;
57 int mPos;
58 bool mHasNextShortcutTarget;
59};
60} // namespace latinime
61#endif // LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H