/src/im/gpinyin/include/sync.h

http://ftk.googlecode.com/ · C++ Header · 85 lines · 29 code · 19 blank · 37 comment · 0 complexity · 20f1a80e2d8f926eec95861c977dc94a MD5 · raw file

  1. /*
  2. * Copyright (C) 2009 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. #ifndef PINYINIME_INCLUDE_SYNC_H__
  17. #define PINYINIME_INCLUDE_SYNC_H__
  18. #define ___SYNC_ENABLED___
  19. #ifdef ___SYNC_ENABLED___
  20. #include "userdict.h"
  21. namespace ime_pinyin {
  22. // Class for user dictionary synchronization
  23. // This class is not thread safe
  24. // Normal invoking flow will be
  25. // begin() ->
  26. // put_lemmas() x N ->
  27. // {
  28. // get_lemmas() ->
  29. // [ get_last_got_count() ] ->
  30. // clear_last_got() ->
  31. // } x N ->
  32. // finish()
  33. class Sync {
  34. public:
  35. Sync();
  36. ~Sync();
  37. static const int kUserDictMaxLemmaCount = 5000;
  38. static const int kUserDictMaxLemmaSize = 200000;
  39. static const int kUserDictRatio = 20;
  40. bool begin(const char * filename);
  41. // Merge lemmas downloaded from sync server into local dictionary
  42. // lemmas, lemmas string encoded in UTF16LE
  43. // len, length of lemmas string
  44. // Return how many lemmas merged successfully
  45. int put_lemmas(char16 * lemmas, int len);
  46. // Get local new user lemmas into UTF16LE string
  47. // str, buffer ptr to store new user lemmas
  48. // size, size of buffer
  49. // Return length of returned buffer in measure of UTF16LE
  50. int get_lemmas(char16 * str, int size);
  51. // Return lemmas count in last get_lemmas()
  52. int get_last_got_count();
  53. // Return total lemmas count need get_lemmas()
  54. int get_total_count();
  55. // Clear lemmas got by recent get_lemmas()
  56. void clear_last_got();
  57. void finish();
  58. int get_capacity();
  59. private:
  60. UserDict * userdict_;
  61. char * dictfile_;
  62. int last_count_;
  63. };
  64. }
  65. #endif
  66. #endif // PINYINIME_INCLUDE_SYNC_H__