am c4453697: Fix class names

* commit 'c44536973208bebf1fdd2e4d13e947eb541678d7':
  Fix class names
main
Ken Wakasa 2013-06-26 19:09:53 -07:00 committed by Android Git Automerger
commit a691a841a2
8 changed files with 77 additions and 73 deletions

View File

@ -37,7 +37,17 @@ namespace latinime {
class ProximityInfo;
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd);
// Helper method
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd) {
int ret = munmap(const_cast<void *>(dictBuf), length);
if (ret != 0) {
AKLOGE("DICT: Failure in munmap. ret=%d errno=%d", ret, errno);
}
ret = close(fd);
if (ret != 0) {
AKLOGE("DICT: Failure in close. ret=%d errno=%d", ret, errno);
}
}
static jlong latinime_BinaryDictionary_open(JNIEnv *env, jclass clazz, jstring sourceDir,
jlong dictOffset, jlong dictSize, jboolean isUpdatable) {
@ -77,8 +87,8 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jclass clazz, jstring s
return 0;
}
Dictionary *dictionary = 0;
if (BinaryDictionaryFormat::UNKNOWN_VERSION
== BinaryDictionaryFormat::detectFormatVersion(static_cast<uint8_t *>(dictBuf),
if (BinaryDictionaryFormatUtils::UNKNOWN_VERSION
== BinaryDictionaryFormatUtils::detectFormatVersion(static_cast<uint8_t *>(dictBuf),
static_cast<int>(dictSize))) {
AKLOGE("DICT: dictionary format is unknown, bad magic number");
releaseDictBuf(static_cast<const char *>(dictBuf) - offset, adjDictSize, fd);
@ -91,6 +101,19 @@ static jlong latinime_BinaryDictionary_open(JNIEnv *env, jclass clazz, jstring s
return reinterpret_cast<jlong>(dictionary);
}
static void latinime_BinaryDictionary_close(JNIEnv *env, jclass clazz, jlong dict) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) return;
const BinaryDictionaryInfo *const binaryDictionaryInfo = dictionary->getBinaryDictionaryInfo();
const int dictBufOffset = binaryDictionaryInfo->getDictBufOffset();
const void *dictBuf = binaryDictionaryInfo->getDictBuf();
if (!dictBuf) return;
releaseDictBuf(static_cast<const char *>(dictBuf) - dictBufOffset,
binaryDictionaryInfo->getDictSize() + dictBufOffset,
binaryDictionaryInfo->getMmapFd());
delete dictionary;
}
static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jclass clazz, jlong dict,
jlong proximityInfo, jlong dicTraverseSession, jintArray xCoordinatesArray,
jintArray yCoordinatesArray, jintArray timesArray, jintArray pointerIdsArray,
@ -222,30 +245,6 @@ static jint latinime_BinaryDictionary_editDistance(JNIEnv *env, jclass clazz, ji
afterCodePoints, afterLength);
}
static void latinime_BinaryDictionary_close(JNIEnv *env, jclass clazz, jlong dict) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);
if (!dictionary) return;
const BinaryDictionaryInfo *const binaryDictionaryInfo = dictionary->getBinaryDictionaryInfo();
const int dictBufOffset = binaryDictionaryInfo->getDictBufOffset();
const void *dictBuf = binaryDictionaryInfo->getDictBuf();
if (!dictBuf) return;
releaseDictBuf(static_cast<const char *>(dictBuf) - dictBufOffset,
binaryDictionaryInfo->getDictSize() + dictBufOffset,
binaryDictionaryInfo->getMmapFd());
delete dictionary;
}
static void releaseDictBuf(const void *dictBuf, const size_t length, const int fd) {
int ret = munmap(const_cast<void *>(dictBuf), length);
if (ret != 0) {
AKLOGE("DICT: Failure in munmap. ret=%d errno=%d", ret, errno);
}
ret = close(fd);
if (ret != 0) {
AKLOGE("DICT: Failure in close. ret=%d errno=%d", ret, errno);
}
}
static void latinime_BinaryDictionary_addUnigramWord(JNIEnv *env, jclass clazz, jlong dict,
jintArray word, jint probability) {
Dictionary *dictionary = reinterpret_cast<Dictionary *>(dict);

View File

@ -22,7 +22,7 @@ namespace latinime {
* Dictionary size
*/
// Any file smaller than this is not a dictionary.
const int BinaryDictionaryFormat::DICTIONARY_MINIMUM_SIZE = 4;
const int BinaryDictionaryFormatUtils::DICTIONARY_MINIMUM_SIZE = 4;
/**
* Format versions
@ -30,17 +30,18 @@ const int BinaryDictionaryFormat::DICTIONARY_MINIMUM_SIZE = 4;
// Originally, format version 1 had a 16-bit magic number, then the version number `01'
// then options that must be 0. Hence the first 32-bits of the format are always as follow
// and it's okay to consider them a magic number as a whole.
const uint32_t BinaryDictionaryFormat::FORMAT_VERSION_1_MAGIC_NUMBER = 0x78B10100;
const uint32_t BinaryDictionaryFormatUtils::FORMAT_VERSION_1_MAGIC_NUMBER = 0x78B10100;
// The versions of Latin IME that only handle format version 1 only test for the magic
// number, so we had to change it so that version 2 files would be rejected by older
// implementations. On this occasion, we made the magic number 32 bits long.
const uint32_t BinaryDictionaryFormat::FORMAT_VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
const uint32_t BinaryDictionaryFormatUtils::FORMAT_VERSION_2_MAGIC_NUMBER = 0x9BC13AFE;
// Magic number (4 bytes), version (2 bytes), options (2 bytes), header size (4 bytes) = 12
const int BinaryDictionaryFormat::FORMAT_VERSION_2_MINIMUM_SIZE = 12;
const int BinaryDictionaryFormatUtils::FORMAT_VERSION_2_MINIMUM_SIZE = 12;
/* static */ BinaryDictionaryFormat::FORMAT_VERSION BinaryDictionaryFormat::detectFormatVersion(
const uint8_t *const dict, const int dictSize) {
/* static */ BinaryDictionaryFormatUtils::FORMAT_VERSION
BinaryDictionaryFormatUtils::detectFormatVersion(const uint8_t *const dict,
const int dictSize) {
// The magic number is stored big-endian.
// If the dictionary is less than 4 bytes, we can't even read the magic number, so we don't
// understand this format.

View File

@ -31,7 +31,7 @@ namespace latinime {
* reading methods and utility methods for various purposes.
* On the other hand, this file deals with only about dictionary format version.
*/
class BinaryDictionaryFormat {
class BinaryDictionaryFormatUtils {
public:
// TODO: Remove obsolete version logic
enum FORMAT_VERSION {
@ -43,7 +43,7 @@ class BinaryDictionaryFormat {
static FORMAT_VERSION detectFormatVersion(const uint8_t *const dict, const int dictSize);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryFormat);
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryFormatUtils);
static const int DICTIONARY_MINIMUM_SIZE;
static const uint32_t FORMAT_VERSION_1_MAGIC_NUMBER;

View File

@ -29,12 +29,12 @@ const float BinaryDictionaryHeader::MULTI_WORD_COST_MULTIPLIER_SCALE = 100.0f;
BinaryDictionaryHeader::BinaryDictionaryHeader(
const BinaryDictionaryInfo *const binaryDictionaryInfo)
: mBinaryDictionaryInfo(binaryDictionaryInfo),
mDictionaryFlags(BinaryDictionaryHeaderReader::getFlags(binaryDictionaryInfo)),
mSize(BinaryDictionaryHeaderReader::getHeaderSize(binaryDictionaryInfo)),
mDictionaryFlags(BinaryDictionaryHeaderReadingUtils::getFlags(binaryDictionaryInfo)),
mSize(BinaryDictionaryHeaderReadingUtils::getHeaderSize(binaryDictionaryInfo)),
mMultiWordCostMultiplier(readMultiWordCostMultiplier()) {}
float BinaryDictionaryHeader::readMultiWordCostMultiplier() const {
const int headerValue = BinaryDictionaryHeaderReader::readHeaderValueInt(
const int headerValue = BinaryDictionaryHeaderReadingUtils::readHeaderValueInt(
mBinaryDictionaryInfo, MULTIPLE_WORDS_DEMOTION_RATE_KEY);
if (headerValue == S_INT_MIN) {
// not found

View File

@ -37,15 +37,16 @@ class BinaryDictionaryHeader {
}
AK_FORCE_INLINE bool supportsDynamicUpdate() const {
return BinaryDictionaryHeaderReader::supportsDynamicUpdate(mDictionaryFlags);
return BinaryDictionaryHeaderReadingUtils::supportsDynamicUpdate(mDictionaryFlags);
}
AK_FORCE_INLINE bool requiresGermanUmlautProcessing() const {
return BinaryDictionaryHeaderReader::requiresGermanUmlautProcessing(mDictionaryFlags);
return BinaryDictionaryHeaderReadingUtils::requiresGermanUmlautProcessing(mDictionaryFlags);
}
AK_FORCE_INLINE bool requiresFrenchLigatureProcessing() const {
return BinaryDictionaryHeaderReader::requiresFrenchLigatureProcessing(mDictionaryFlags);
return BinaryDictionaryHeaderReadingUtils::requiresFrenchLigatureProcessing(
mDictionaryFlags);
}
AK_FORCE_INLINE float getMultiWordCostMultiplier() const {
@ -60,7 +61,7 @@ class BinaryDictionaryHeader {
static const float MULTI_WORD_COST_MULTIPLIER_SCALE;
const BinaryDictionaryInfo *const mBinaryDictionaryInfo;
const BinaryDictionaryHeaderReader::DictionaryFlags mDictionaryFlags;
const BinaryDictionaryHeaderReadingUtils::DictionaryFlags mDictionaryFlags;
const int mSize;
const float mMultiWordCostMultiplier;

View File

@ -24,32 +24,33 @@
namespace latinime {
const int BinaryDictionaryHeaderReader::MAX_OPTION_KEY_LENGTH = 256;
const int BinaryDictionaryHeaderReadingUtils::MAX_OPTION_KEY_LENGTH = 256;
const int BinaryDictionaryHeaderReader::FORMAT_VERSION_1_HEADER_SIZE = 5;
const int BinaryDictionaryHeaderReadingUtils::FORMAT_VERSION_1_HEADER_SIZE = 5;
const int BinaryDictionaryHeaderReader::VERSION_2_MAGIC_NUMBER_SIZE = 4;
const int BinaryDictionaryHeaderReader::VERSION_2_DICTIONARY_VERSION_SIZE = 2;
const int BinaryDictionaryHeaderReader::VERSION_2_DICTIONARY_FLAG_SIZE = 2;
const int BinaryDictionaryHeaderReader::VERSION_2_DICTIONARY_HEADER_SIZE_SIZE = 4;
const int BinaryDictionaryHeaderReadingUtils::VERSION_2_MAGIC_NUMBER_SIZE = 4;
const int BinaryDictionaryHeaderReadingUtils::VERSION_2_DICTIONARY_VERSION_SIZE = 2;
const int BinaryDictionaryHeaderReadingUtils::VERSION_2_DICTIONARY_FLAG_SIZE = 2;
const int BinaryDictionaryHeaderReadingUtils::VERSION_2_DICTIONARY_HEADER_SIZE_SIZE = 4;
const BinaryDictionaryHeaderReader::DictionaryFlags BinaryDictionaryHeaderReader::NO_FLAGS = 0;
const BinaryDictionaryHeaderReadingUtils::DictionaryFlags
BinaryDictionaryHeaderReadingUtils::NO_FLAGS = 0;
// Flags for special processing
// Those *must* match the flags in makedict (BinaryDictInputOutput#*_PROCESSING_FLAG) or
// something very bad (like, the apocalypse) will happen. Please update both at the same time.
const BinaryDictionaryHeaderReader::DictionaryFlags
BinaryDictionaryHeaderReader::GERMAN_UMLAUT_PROCESSING_FLAG = 0x1;
const BinaryDictionaryHeaderReader::DictionaryFlags
BinaryDictionaryHeaderReader::SUPPORTS_DYNAMIC_UPDATE_FLAG = 0x2;
const BinaryDictionaryHeaderReader::DictionaryFlags
BinaryDictionaryHeaderReader::FRENCH_LIGATURE_PROCESSING_FLAG = 0x4;
const BinaryDictionaryHeaderReadingUtils::DictionaryFlags
BinaryDictionaryHeaderReadingUtils::GERMAN_UMLAUT_PROCESSING_FLAG = 0x1;
const BinaryDictionaryHeaderReadingUtils::DictionaryFlags
BinaryDictionaryHeaderReadingUtils::SUPPORTS_DYNAMIC_UPDATE_FLAG = 0x2;
const BinaryDictionaryHeaderReadingUtils::DictionaryFlags
BinaryDictionaryHeaderReadingUtils::FRENCH_LIGATURE_PROCESSING_FLAG = 0x4;
/* static */ int BinaryDictionaryHeaderReader::getHeaderSize(
/* static */ int BinaryDictionaryHeaderReadingUtils::getHeaderSize(
const BinaryDictionaryInfo *const binaryDictionaryInfo) {
switch (binaryDictionaryInfo->getFormat()) {
case BinaryDictionaryFormat::VERSION_1:
case BinaryDictionaryFormatUtils::VERSION_1:
return FORMAT_VERSION_1_HEADER_SIZE;
case BinaryDictionaryFormat::VERSION_2:
case BinaryDictionaryFormatUtils::VERSION_2:
// See the format of the header in the comment in
// BinaryDictionaryFormatUtils::detectFormatVersion()
return ByteArrayUtils::readUint32(binaryDictionaryInfo->getDictBuf(),
@ -60,12 +61,13 @@ const BinaryDictionaryHeaderReader::DictionaryFlags
}
}
/* static */ BinaryDictionaryHeaderReader::DictionaryFlags BinaryDictionaryHeaderReader::getFlags(
const BinaryDictionaryInfo *const binaryDictionaryInfo) {
/* static */ BinaryDictionaryHeaderReadingUtils::DictionaryFlags
BinaryDictionaryHeaderReadingUtils::getFlags(
const BinaryDictionaryInfo *const binaryDictionaryInfo) {
switch (binaryDictionaryInfo->getFormat()) {
case BinaryDictionaryFormat::VERSION_1:
case BinaryDictionaryFormatUtils::VERSION_1:
return NO_FLAGS;
case BinaryDictionaryFormat::VERSION_2:
case BinaryDictionaryFormatUtils::VERSION_2:
return ByteArrayUtils::readUint16(binaryDictionaryInfo->getDictBuf(),
VERSION_2_MAGIC_NUMBER_SIZE + VERSION_2_DICTIONARY_VERSION_SIZE);
default:
@ -74,7 +76,7 @@ const BinaryDictionaryHeaderReader::DictionaryFlags
}
// Returns if the key is found or not and reads the found value into outValue.
/* static */ bool BinaryDictionaryHeaderReader::readHeaderValue(
/* static */ bool BinaryDictionaryHeaderReadingUtils::readHeaderValue(
const BinaryDictionaryInfo *const binaryDictionaryInfo,
const char *const key, int *outValue, const int outValueSize) {
if (outValueSize <= 0 || !hasHeaderAttributes(binaryDictionaryInfo->getFormat())) {
@ -97,7 +99,7 @@ const BinaryDictionaryHeaderReader::DictionaryFlags
return false;
}
/* static */ int BinaryDictionaryHeaderReader::readHeaderValueInt(
/* static */ int BinaryDictionaryHeaderReadingUtils::readHeaderValueInt(
const BinaryDictionaryInfo *const binaryDictionaryInfo, const char *const key) {
const int bufferSize = LARGEST_INT_DIGIT_COUNT;
int intBuffer[bufferSize];

View File

@ -26,7 +26,7 @@ namespace latinime {
class BinaryDictionaryInfo;
class BinaryDictionaryHeaderReader {
class BinaryDictionaryHeaderReadingUtils {
public:
typedef uint16_t DictionaryFlags;
@ -49,10 +49,10 @@ class BinaryDictionaryHeaderReader {
}
static AK_FORCE_INLINE bool hasHeaderAttributes(
const BinaryDictionaryFormat::FORMAT_VERSION format) {
const BinaryDictionaryFormatUtils::FORMAT_VERSION format) {
// Only format 2 and above have header attributes as {key,value} string pairs.
switch (format) {
case BinaryDictionaryFormat::VERSION_2:
case BinaryDictionaryFormatUtils::VERSION_2:
return true;
break;
default:
@ -61,9 +61,9 @@ class BinaryDictionaryHeaderReader {
}
static AK_FORCE_INLINE int getHeaderOptionsPosition(
const BinaryDictionaryFormat::FORMAT_VERSION format) {
const BinaryDictionaryFormatUtils::FORMAT_VERSION format) {
switch (format) {
case BinaryDictionaryFormat::VERSION_2:
case BinaryDictionaryFormatUtils::VERSION_2:
return VERSION_2_MAGIC_NUMBER_SIZE + VERSION_2_DICTIONARY_VERSION_SIZE
+ VERSION_2_DICTIONARY_FLAG_SIZE + VERSION_2_DICTIONARY_HEADER_SIZE_SIZE;
break;
@ -80,7 +80,7 @@ class BinaryDictionaryHeaderReader {
const BinaryDictionaryInfo *const binaryDictionaryInfo, const char *const key);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryHeaderReader);
DISALLOW_IMPLICIT_CONSTRUCTORS(BinaryDictionaryHeaderReadingUtils);
static const int FORMAT_VERSION_1_HEADER_SIZE;

View File

@ -33,7 +33,8 @@ class BinaryDictionaryInfo {
const int dictBufOffset, const bool isUpdatable)
: mDictBuf(dictBuf), mDictSize(dictSize), mMmapFd(mmapFd),
mDictBufOffset(dictBufOffset), mIsUpdatable(isUpdatable),
mDictionaryFormat(BinaryDictionaryFormat::detectFormatVersion(mDictBuf, mDictSize)),
mDictionaryFormat(BinaryDictionaryFormatUtils::detectFormatVersion(
mDictBuf, mDictSize)),
mDictionaryHeader(this), mDictRoot(mDictBuf + mDictionaryHeader.getSize()) {}
AK_FORCE_INLINE const uint8_t *getDictBuf() const {
@ -56,7 +57,7 @@ class BinaryDictionaryInfo {
return mDictRoot;
}
AK_FORCE_INLINE BinaryDictionaryFormat::FORMAT_VERSION getFormat() const {
AK_FORCE_INLINE BinaryDictionaryFormatUtils::FORMAT_VERSION getFormat() const {
return mDictionaryFormat;
}
@ -82,7 +83,7 @@ class BinaryDictionaryInfo {
const int mMmapFd;
const int mDictBufOffset;
const bool mIsUpdatable;
const BinaryDictionaryFormat::FORMAT_VERSION mDictionaryFormat;
const BinaryDictionaryFormatUtils::FORMAT_VERSION mDictionaryFormat;
const BinaryDictionaryHeader mDictionaryHeader;
const uint8_t *const mDictRoot;
};