OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2013 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_SUGGEST_OPTIONS_H |
| 18 #define LATINIME_SUGGEST_OPTIONS_H |
| 19 |
| 20 #include "third_party/prediction/defines.h" |
| 21 |
| 22 namespace latinime { |
| 23 |
| 24 class SuggestOptions { |
| 25 public: |
| 26 SuggestOptions(const int* const options, const int length) |
| 27 : mOptions(options), mLength(length) {} |
| 28 |
| 29 AK_FORCE_INLINE bool isGesture() const { return getBoolOption(IS_GESTURE); } |
| 30 |
| 31 AK_FORCE_INLINE bool useFullEditDistance() const { |
| 32 return getBoolOption(USE_FULL_EDIT_DISTANCE); |
| 33 } |
| 34 |
| 35 AK_FORCE_INLINE bool blockOffensiveWords() const { |
| 36 return getBoolOption(BLOCK_OFFENSIVE_WORDS); |
| 37 } |
| 38 |
| 39 AK_FORCE_INLINE bool enableSpaceAwareGesture() const { |
| 40 return getBoolOption(SPACE_AWARE_GESTURE_ENABLED); |
| 41 } |
| 42 |
| 43 AK_FORCE_INLINE bool getAdditionalFeaturesBoolOption(const int key) const { |
| 44 return getBoolOption(key + ADDITIONAL_FEATURES_OPTIONS); |
| 45 } |
| 46 |
| 47 private: |
| 48 DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestOptions); |
| 49 |
| 50 // Need to update com.android.inputmethod.latin.NativeSuggestOptions when you |
| 51 // add, remove or |
| 52 // reorder options. |
| 53 static const int IS_GESTURE = 0; |
| 54 static const int USE_FULL_EDIT_DISTANCE = 1; |
| 55 static const int BLOCK_OFFENSIVE_WORDS = 2; |
| 56 static const int SPACE_AWARE_GESTURE_ENABLED = 3; |
| 57 // Additional features options are stored after the other options and used as |
| 58 // setting values of |
| 59 // experimental features. |
| 60 static const int ADDITIONAL_FEATURES_OPTIONS = 4; |
| 61 |
| 62 const int* const mOptions; |
| 63 const int mLength; |
| 64 |
| 65 AK_FORCE_INLINE bool isValidKey(const int key) const { |
| 66 return 0 <= key && key < mLength; |
| 67 } |
| 68 |
| 69 AK_FORCE_INLINE bool getBoolOption(const int key) const { |
| 70 if (isValidKey(key)) { |
| 71 return mOptions[key] != 0; |
| 72 } |
| 73 return false; |
| 74 } |
| 75 |
| 76 AK_FORCE_INLINE int getIntOption(const int key) const { |
| 77 if (isValidKey(key)) { |
| 78 return mOptions[key]; |
| 79 } |
| 80 return 0; |
| 81 } |
| 82 }; |
| 83 } // namespace latinime |
| 84 #endif // LATINIME_SUGGEST_OPTIONS_H |
OLD | NEW |