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_DIC_TRAVERSE_WRAPPER_H 18 #define LATINIME_DIC_TRAVERSE_WRAPPER_H 19 20 #include "defines.h" 21 #include "jni.h" 22 23 namespace latinime { 24 class Dictionary; 25 // TODO: Remove 26 class DicTraverseWrapper { 27 public: 28 static void *getDicTraverseSession(JNIEnv *env, jstring locale) { 29 if (sDicTraverseSessionFactoryMethod) { 30 return sDicTraverseSessionFactoryMethod(env, locale); 31 } 32 return 0; 33 } 34 static void initDicTraverseSession(void *traverseSession, const Dictionary *const dictionary, 35 const int *prevWord, const int prevWordLength) { 36 if (sDicTraverseSessionInitMethod) { 37 sDicTraverseSessionInitMethod(traverseSession, dictionary, prevWord, prevWordLength); 38 } 39 } 40 static void releaseDicTraverseSession(void *traverseSession) { 41 if (sDicTraverseSessionReleaseMethod) { 42 sDicTraverseSessionReleaseMethod(traverseSession); 43 } 44 } 45 static void setTraverseSessionFactoryMethod(void *(*factoryMethod)(JNIEnv *, jstring)) { 46 sDicTraverseSessionFactoryMethod = factoryMethod; 47 } 48 static void setTraverseSessionInitMethod( 49 void (*initMethod)(void *, const Dictionary *const, const int *, const int)) { 50 sDicTraverseSessionInitMethod = initMethod; 51 } 52 static void setTraverseSessionReleaseMethod(void (*releaseMethod)(void *)) { 53 sDicTraverseSessionReleaseMethod = releaseMethod; 54 } 55 56 private: 57 DISALLOW_IMPLICIT_CONSTRUCTORS(DicTraverseWrapper); 58 static void *(*sDicTraverseSessionFactoryMethod)(JNIEnv *, jstring); 59 static void (*sDicTraverseSessionInitMethod)( 60 void *, const Dictionary *const, const int *, const int); 61 static void (*sDicTraverseSessionReleaseMethod)(void *); 62 }; 63 } // namespace latinime 64 #endif // LATINIME_DIC_TRAVERSE_WRAPPER_H 65