suggest_options.h revision b8a9479b57007edb5cb12c628797f89a8164f596
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 "defines.h"
21
22namespace latinime {
23
24class 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 {
30        return getBoolOption(IS_GESTURE);
31    }
32
33    AK_FORCE_INLINE bool useFullEditDistance() const {
34        return getBoolOption(USE_FULL_EDIT_DISTANCE);
35    }
36
37    AK_FORCE_INLINE bool blockOffensiveWords() const {
38        return getBoolOption(BLOCK_OFFENSIVE_WORDS);
39    }
40
41    AK_FORCE_INLINE bool enableSpaceAwareGesture() const {
42        return getBoolOption(SPACE_AWARE_GESTURE_ENABLED);
43    }
44
45    AK_FORCE_INLINE bool getAdditionalFeaturesBoolOption(const int key) const {
46        return getBoolOption(key + ADDITIONAL_FEATURES_OPTIONS);
47    }
48
49 private:
50    DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestOptions);
51
52    // Need to update com.android.inputmethod.latin.NativeSuggestOptions when you add, remove or
53    // reorder options.
54    static const int IS_GESTURE = 0;
55    static const int USE_FULL_EDIT_DISTANCE = 1;
56    static const int BLOCK_OFFENSIVE_WORDS = 2;
57    static const int SPACE_AWARE_GESTURE_ENABLED = 3;
58    // Additional features options are stored after the other options and used as 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
85