1eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang/*
2eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * Copyright (C) 2012 The Android Open Source Project
3eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang *
4eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * Licensed under the Apache License, Version 2.0 (the "License");
5eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * you may not use this file except in compliance with the License.
6eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * You may obtain a copy of the License at
7eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang *
8eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang *      http://www.apache.org/licenses/LICENSE-2.0
9eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang *
10eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * Unless required by applicable law or agreed to in writing, software
11eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * distributed under the License is distributed on an "AS IS" BASIS,
12eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * See the License for the specific language governing permissions and
14eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang * limitations under the License.
15eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang */
16eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
17eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang#ifndef LATINIME_INCREMENTAL_DECODER_WRAPPER_H
18eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang#define LATINIME_INCREMENTAL_DECODER_WRAPPER_H
19eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
20eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang#include <stdint.h>
21eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang#include "defines.h"
22eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang#include "incremental_decoder_interface.h"
23eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
24eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyangnamespace latinime {
25eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
26eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyangclass UnigramDictionary;
27eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyangclass BigramDictionary;
28eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyangclass ProximityInfo;
29eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
30eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyangclass IncrementalDecoderWrapper : public IncrementalDecoderInterface {
31eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang public:
32162c211b44c1546b2e9be36e0cec50de497217a9Ken Wakasa    IncrementalDecoderWrapper(const int maxWordLength, const int maxWords)
33162c211b44c1546b2e9be36e0cec50de497217a9Ken Wakasa            : mIncrementalDecoderInterface(getIncrementalDecoderInstance(maxWordLength, maxWords)) {
34eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    }
35eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
36eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    virtual ~IncrementalDecoderWrapper() {
37eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang        delete mIncrementalDecoderInterface;
38eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    }
39eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
409127811493b9288a0ca385e75db68520b197dea2Satoshi Kataoka    int getSuggestions(ProximityInfo *pInfo, void *traverseSession, int *inputXs, int *inputYs,
419127811493b9288a0ca385e75db68520b197dea2Satoshi Kataoka            int *times, int *pointerIds, int *codes, int inputSize, int commitPoint,
42f6be15cffee14b35efce8a52296d7bf8e338b234Satoshi Kataoka            unsigned short *outWords, int *frequencies, int *outputIndices,
43f6be15cffee14b35efce8a52296d7bf8e338b234Satoshi Kataoka            int *outputTypes) const {
44eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang        if (!mIncrementalDecoderInterface) {
45eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang            return 0;
46eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang        }
47eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang        return mIncrementalDecoderInterface->getSuggestions(
489127811493b9288a0ca385e75db68520b197dea2Satoshi Kataoka                pInfo, traverseSession, inputXs, inputYs, times, pointerIds, codes,
499127811493b9288a0ca385e75db68520b197dea2Satoshi Kataoka                inputSize, commitPoint, outWords, frequencies, outputIndices, outputTypes);
50eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    }
51eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
52eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    static void setIncrementalDecoderFactoryMethod(
53eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang            IncrementalDecoderInterface *(*factoryMethod)(int, int)) {
54eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang        sIncrementalDecoderFactoryMethod = factoryMethod;
55eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    }
56eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
57eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang private:
58bcec82de66f52655593dc233346f11468f5077a0Ken Wakasa    DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalDecoderWrapper);
59eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    static IncrementalDecoderInterface *getIncrementalDecoderInstance(int maxWordLength,
60eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang            int maxWords) {
61eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang        if (sIncrementalDecoderFactoryMethod) {
62eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang            return sIncrementalDecoderFactoryMethod(maxWordLength, maxWords);
63eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang        }
64eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang        return 0;
65eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    }
66eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang
67eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    static IncrementalDecoderInterface *(*sIncrementalDecoderFactoryMethod)(int, int);
68eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang    IncrementalDecoderInterface *mIncrementalDecoderInterface;
69eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang};
70eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang} // namespace latinime
71eb2fe2ab101c80f6e3d23010385a68dd3e9688efTom Ouyang#endif // LATINIME_INCREMENTAL_DECODER_WRAPPER_H
72