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 "suggest/core/policy/dictionary_shortcuts_structure_policy.h" 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 34 AK_FORCE_INLINE bool hasNextShortcutTarget() const { 35 return mHasNextShortcutTarget; 36 } 37 38 // Gets the shortcut target itself as an int string and put it to outTarget, put its length 39 // to outTargetLength, put whether it is whitelist to outIsWhitelist. 40 AK_FORCE_INLINE void nextShortcutTarget( 41 const int maxDepth, int *const outTarget, int *const outTargetLength, 42 bool *const outIsWhitelist) { 43 mShortcutStructurePolicy->getNextShortcut(maxDepth, outTarget, outTargetLength, 44 outIsWhitelist, &mHasNextShortcutTarget, &mPos); 45 } 46 47 private: 48 DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryShortcutIterator); 49 50 const DictionaryShortcutsStructurePolicy *const mShortcutStructurePolicy; 51 int mPos; 52 bool mHasNextShortcutTarget; 53 }; 54 } // namespace latinime 55 #endif // LATINIME_BINARY_DICTIONARY_SHORTCUT_ITERATOR_H 56