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