Home | History | Annotate | Download | only in core
      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 
     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 {
     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 getAdditionalFeaturesBoolOption(const int key) const {
     38         return getBoolOption(key + ADDITIONAL_FEATURES_OPTIONS);
     39     }
     40 
     41  private:
     42     DISALLOW_IMPLICIT_CONSTRUCTORS(SuggestOptions);
     43 
     44     // Need to update com.android.inputmethod.latin.NativeSuggestOptions when you add, remove or
     45     // reorder options.
     46     static const int IS_GESTURE = 0;
     47     static const int USE_FULL_EDIT_DISTANCE = 1;
     48     // Additional features options are stored after the other options and used as setting values of
     49     // experimental features.
     50     static const int ADDITIONAL_FEATURES_OPTIONS = 2;
     51 
     52     const int *const mOptions;
     53     const int mLength;
     54 
     55     AK_FORCE_INLINE bool isValidKey(const int key) const {
     56         return 0 <= key && key < mLength;
     57     }
     58 
     59     AK_FORCE_INLINE bool getBoolOption(const int key) const {
     60         if (isValidKey(key)) {
     61             return mOptions[key] != 0;
     62         }
     63         return false;
     64     }
     65 
     66     AK_FORCE_INLINE int getIntOption(const int key) const {
     67         if (isValidKey(key)) {
     68             return mOptions[key];
     69         }
     70         return 0;
     71     }
     72 };
     73 } // namespace latinime
     74 #endif // LATINIME_SUGGEST_OPTIONS_H
     75