Address warnings by -Weffc++

Change-Id: Icd60f1ed2ace0b975d8785bc8a386c7944846075
main
Ken Wakasa 2012-08-24 14:51:15 +09:00
parent 0a4692efa8
commit 162c211b44
12 changed files with 80 additions and 55 deletions

View File

@ -172,10 +172,10 @@ static int latinime_BinaryDictionary_getSuggestions(JNIEnv *env, jobject object,
int spaceIndices[spaceIndicesLength]; int spaceIndices[spaceIndicesLength];
const jsize outputTypesLength = env->GetArrayLength(outputTypesArray); const jsize outputTypesLength = env->GetArrayLength(outputTypesArray);
int outputTypes[outputTypesLength]; int outputTypes[outputTypesLength];
memset(outputChars, 0, outputCharsLength * sizeof(outputChars[0])); memset(outputChars, 0, sizeof(outputChars));
memset(scores, 0, scoresLength * sizeof(scores[0])); memset(scores, 0, sizeof(scores));
memset(spaceIndices, 0, spaceIndicesLength * sizeof(spaceIndices[0])); memset(spaceIndices, 0, sizeof(spaceIndices));
memset(outputTypes, 0, outputTypesLength * sizeof(outputTypes[0])); memset(outputTypes, 0, sizeof(outputTypes));
int count; int count;
if (isGesture || arraySize > 0) { if (isGesture || arraySize > 0) {

View File

@ -627,9 +627,6 @@ Correction::CorrectionType Correction::processCharAndCalcState(
} }
} }
Correction::~Correction() {
}
inline static int getQuoteCount(const unsigned short *word, const int length) { inline static int getQuoteCount(const unsigned short *word, const int length) {
int quoteCount = 0; int quoteCount = 0;
for (int i = 0; i < length; ++i) { for (int i = 0; i < length; ++i) {

View File

@ -18,6 +18,7 @@
#define LATINIME_CORRECTION_H #define LATINIME_CORRECTION_H
#include <cassert> #include <cassert>
#include <cstring> // for memset()
#include <stdint.h> #include <stdint.h>
#include "correction_state.h" #include "correction_state.h"
@ -38,8 +39,24 @@ class Correction {
NOT_ON_TERMINAL NOT_ON_TERMINAL
} CorrectionType; } CorrectionType;
Correction() {}; Correction()
virtual ~Correction(); : mProximityInfo(0), mUseFullEditDistance(false), mDoAutoCompletion(false),
mMaxEditDistance(0), mMaxDepth(0), mInputSize(0), mSpaceProximityPos(0),
mMissingSpacePos(0), mTerminalInputIndex(0), mTerminalOutputIndex(0), mMaxErrors(0),
mTotalTraverseCount(0), mNeedsToTraverseAllNodes(false), mOutputIndex(0),
mInputIndex(0), mEquivalentCharCount(0), mProximityCount(0), mExcessiveCount(0),
mTransposedCount(0), mSkippedCount(0), mTransposedPos(0), mExcessivePos(0),
mSkipPos(0), mLastCharExceeded(false), mMatching(false), mProximityMatching(false),
mAdditionalProximityMatching(false), mExceeding(false), mTransposing(false),
mSkipping(false), mProximityInfoState() {
memset(mWord, 0, sizeof(mWord));
memset(mDistances, 0, sizeof(mDistances));
memset(mEditDistanceTable, 0, sizeof(mEditDistanceTable));
// NOTE: mCorrectionStates is an array of instances.
// No need to initialize it explicitly here.
}
virtual ~Correction() {}
void resetCorrection(); void resetCorrection();
void initCorrection( void initCorrection(
const ProximityInfo *pi, const int inputSize, const int maxWordLength); const ProximityInfo *pi, const int inputSize, const int maxWordLength);

View File

@ -30,11 +30,15 @@ namespace latinime {
// TODO: Change the type of all keyCodes to uint32_t // TODO: Change the type of all keyCodes to uint32_t
Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust, Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
int typedLetterMultiplier, int fullWordMultiplier, int typedLetterMultiplier, int fullWordMultiplier, int maxWordLength, int maxWords,
int maxWordLength, int maxWords, int maxPredictions) int maxPredictions)
: mDict(static_cast<unsigned char *>(dict)), : mDict(static_cast<unsigned char *>(dict)),
mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)), mOffsetDict((static_cast<unsigned char *>(dict)) + BinaryFormat::getHeaderSize(mDict)),
mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust) { mDictSize(dictSize), mMmapFd(mmapFd), mDictBufAdjust(dictBufAdjust),
mUnigramDictionary(new UnigramDictionary(mOffsetDict, typedLetterMultiplier,
fullWordMultiplier, maxWordLength, maxWords, BinaryFormat::getFlags(mDict))),
mBigramDictionary(new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions)),
mGestureDecoder(new GestureDecoderWrapper(maxWordLength, maxWords)) {
if (DEBUG_DICT) { if (DEBUG_DICT) {
if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) { if (MAX_WORD_LENGTH_INTERNAL < maxWordLength) {
AKLOGI("Max word length (%d) is greater than %d", AKLOGI("Max word length (%d) is greater than %d",
@ -42,11 +46,6 @@ Dictionary::Dictionary(void *dict, int dictSize, int mmapFd, int dictBufAdjust,
AKLOGI("IN NATIVE SUGGEST Version: %d", (mDict[0] & 0xFF)); AKLOGI("IN NATIVE SUGGEST Version: %d", (mDict[0] & 0xFF));
} }
} }
const unsigned int options = BinaryFormat::getFlags(mDict);
mUnigramDictionary = new UnigramDictionary(mOffsetDict, typedLetterMultiplier,
fullWordMultiplier, maxWordLength, maxWords, options);
mBigramDictionary = new BigramDictionary(mOffsetDict, maxWordLength, maxPredictions);
mGestureDecoder = new GestureDecoderWrapper(maxWordLength, maxWords);
} }
Dictionary::~Dictionary() { Dictionary::~Dictionary() {

View File

@ -29,8 +29,8 @@ class ProximityInfo;
class GestureDecoderWrapper : public IncrementalDecoderInterface { class GestureDecoderWrapper : public IncrementalDecoderInterface {
public: public:
GestureDecoderWrapper(const int maxWordLength, const int maxWords) { GestureDecoderWrapper(const int maxWordLength, const int maxWords)
mIncrementalDecoderInterface = getGestureDecoderInstance(maxWordLength, maxWords); : mIncrementalDecoderInterface(getGestureDecoderInstance(maxWordLength, maxWords)) {
} }
virtual ~GestureDecoderWrapper() { virtual ~GestureDecoderWrapper() {

View File

@ -29,8 +29,8 @@ class ProximityInfo;
class IncrementalDecoderWrapper : public IncrementalDecoderInterface { class IncrementalDecoderWrapper : public IncrementalDecoderInterface {
public: public:
IncrementalDecoderWrapper(const int maxWordLength, const int maxWords) { IncrementalDecoderWrapper(const int maxWordLength, const int maxWords)
mIncrementalDecoderInterface = getIncrementalDecoderInstance(maxWordLength, maxWords); : mIncrementalDecoderInterface(getIncrementalDecoderInstance(maxWordLength, maxWords)) {
} }
virtual ~IncrementalDecoderWrapper() { virtual ~IncrementalDecoderWrapper() {

View File

@ -29,6 +29,9 @@
namespace latinime { namespace latinime {
/* static */ const int ProximityInfo::NOT_A_CODE = -1;
/* static */ const float ProximityInfo::NOT_A_DISTANCE_FLOAT = -1.0f;
static inline void safeGetOrFillZeroIntArrayRegion(JNIEnv *env, jintArray jArray, jsize len, static inline void safeGetOrFillZeroIntArrayRegion(JNIEnv *env, jintArray jArray, jsize len,
jint *buffer) { jint *buffer) {
if (jArray && buffer) { if (jArray && buffer) {
@ -54,16 +57,17 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma
const jintArray keyWidths, const jintArray keyHeights, const jintArray keyCharCodes, const jintArray keyWidths, const jintArray keyHeights, const jintArray keyCharCodes,
const jfloatArray sweetSpotCenterXs, const jfloatArray sweetSpotCenterYs, const jfloatArray sweetSpotCenterXs, const jfloatArray sweetSpotCenterYs,
const jfloatArray sweetSpotRadii) const jfloatArray sweetSpotRadii)
: MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), KEYBOARD_WIDTH(keyboardWidth), : MAX_PROXIMITY_CHARS_SIZE(maxProximityCharsSize), GRID_WIDTH(gridWidth),
KEYBOARD_HEIGHT(keyboardHeight), GRID_WIDTH(gridWidth), GRID_HEIGHT(gridHeight), GRID_HEIGHT(gridHeight), MOST_COMMON_KEY_WIDTH(mostCommonKeyWidth),
MOST_COMMON_KEY_WIDTH(mostCommonKeyWidth),
MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth), MOST_COMMON_KEY_WIDTH_SQUARE(mostCommonKeyWidth * mostCommonKeyWidth),
CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth), CELL_WIDTH((keyboardWidth + gridWidth - 1) / gridWidth),
CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight), CELL_HEIGHT((keyboardHeight + gridHeight - 1) / gridHeight),
KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)), KEY_COUNT(min(keyCount, MAX_KEY_COUNT_IN_A_KEYBOARD)),
HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates HAS_TOUCH_POSITION_CORRECTION_DATA(keyCount > 0 && keyXCoordinates && keyYCoordinates
&& keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs && keyWidths && keyHeights && keyCharCodes && sweetSpotCenterXs
&& sweetSpotCenterYs && sweetSpotRadii) { && sweetSpotCenterYs && sweetSpotRadii),
mProximityCharsArray(new int32_t[GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE
/* proximityGridLength */]) {
const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE; const int proximityGridLength = GRID_WIDTH * GRID_HEIGHT * MAX_PROXIMITY_CHARS_SIZE;
if (DEBUG_PROXIMITY_INFO) { if (DEBUG_PROXIMITY_INFO) {
AKLOGI("Create proximity info array %d", proximityGridLength); AKLOGI("Create proximity info array %d", proximityGridLength);
@ -75,7 +79,6 @@ ProximityInfo::ProximityInfo(JNIEnv *env, const jstring localeJStr, const int ma
} }
memset(mLocaleStr, 0, sizeof(mLocaleStr)); memset(mLocaleStr, 0, sizeof(mLocaleStr));
env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), mLocaleStr); env->GetStringUTFRegion(localeJStr, 0, env->GetStringLength(localeJStr), mLocaleStr);
mProximityCharsArray = new int32_t[proximityGridLength];
safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray); safeGetOrFillZeroIntArrayRegion(env, proximityChars, proximityGridLength, mProximityCharsArray);
safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates); safeGetOrFillZeroIntArrayRegion(env, keyXCoordinates, KEY_COUNT, mKeyXCoordinates);
safeGetOrFillZeroIntArrayRegion(env, keyYCoordinates, KEY_COUNT, mKeyYCoordinates); safeGetOrFillZeroIntArrayRegion(env, keyYCoordinates, KEY_COUNT, mKeyYCoordinates);

View File

@ -108,8 +108,8 @@ class ProximityInfo {
static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64; static const int MAX_KEY_COUNT_IN_A_KEYBOARD = 64;
// The upper limit of the char code in mCodeToKeyIndex // The upper limit of the char code in mCodeToKeyIndex
static const int MAX_CHAR_CODE = 127; static const int MAX_CHAR_CODE = 127;
static const float NOT_A_DISTANCE_FLOAT = -1.0f; static const int NOT_A_CODE;
static const int NOT_A_CODE = -1; static const float NOT_A_DISTANCE_FLOAT;
int getStartIndexFromCoordinates(const int x, const int y) const; int getStartIndexFromCoordinates(const int x, const int y) const;
void initializeCodeToKeyIndex(); void initializeCodeToKeyIndex();
@ -129,8 +129,6 @@ class ProximityInfo {
} }
const int MAX_PROXIMITY_CHARS_SIZE; const int MAX_PROXIMITY_CHARS_SIZE;
const int KEYBOARD_WIDTH;
const int KEYBOARD_HEIGHT;
const int GRID_WIDTH; const int GRID_WIDTH;
const int GRID_HEIGHT; const int GRID_HEIGHT;
const int MOST_COMMON_KEY_WIDTH; const int MOST_COMMON_KEY_WIDTH;

View File

@ -17,6 +17,7 @@
#ifndef LATINIME_PROXIMITY_INFO_STATE_H #ifndef LATINIME_PROXIMITY_INFO_STATE_H
#define LATINIME_PROXIMITY_INFO_STATE_H #define LATINIME_PROXIMITY_INFO_STATE_H
#include <cstring> // for memset()
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <vector> #include <vector>
@ -49,7 +50,18 @@ class ProximityInfoState {
///////////////////////////////////////// /////////////////////////////////////////
// Defined here // // Defined here //
///////////////////////////////////////// /////////////////////////////////////////
ProximityInfoState() {}; ProximityInfoState()
: mProximityInfo(0), mMaxPointToKeyLength(0),
mHasTouchPositionCorrectionData(false), mMostCommonKeyWidthSquare(0), mLocaleStr(),
mKeyCount(0), mCellHeight(0), mCellWidth(0), mGridHeight(0), mGridWidth(0),
mInputXs(), mInputYs(), mTimes(), mDistanceCache(), mLengthCache(),
mTouchPositionCorrectionEnabled(false), mInputSize(0) {
memset(mInputCodes, 0, sizeof(mInputCodes));
memset(mNormalizedSquaredDistances, 0, sizeof(mNormalizedSquaredDistances));
memset(mPrimaryInputWord, 0, sizeof(mPrimaryInputWord));
}
virtual ~ProximityInfoState() {}
inline unsigned short getPrimaryCharAt(const int index) const { inline unsigned short getPrimaryCharAt(const int index) const {
return getProximityCharsAt(index)[0]; return getProximityCharsAt(index)[0];

View File

@ -30,13 +30,13 @@ class TerminalAttributes {
public: public:
class ShortcutIterator { class ShortcutIterator {
const uint8_t *const mDict; const uint8_t *const mDict;
bool mHasNextShortcutTarget;
int mPos; int mPos;
bool mHasNextShortcutTarget;
public: public:
ShortcutIterator(const uint8_t *dict, const int pos, const uint8_t flags) : mDict(dict), ShortcutIterator(const uint8_t *dict, const int pos, const uint8_t flags)
mPos(pos) { : mDict(dict), mPos(pos),
mHasNextShortcutTarget = (0 != (flags & BinaryFormat::FLAG_HAS_SHORTCUT_TARGETS)); mHasNextShortcutTarget(0 != (flags & BinaryFormat::FLAG_HAS_SHORTCUT_TARGETS)) {
} }
inline bool hasNextShortcutTarget() const { inline bool hasNextShortcutTarget() const {
@ -62,13 +62,6 @@ class TerminalAttributes {
} }
}; };
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(TerminalAttributes);
const uint8_t *const mDict;
const uint8_t mFlags;
const int mStartPos;
public:
TerminalAttributes(const uint8_t *const dict, const uint8_t flags, const int pos) : TerminalAttributes(const uint8_t *const dict, const uint8_t flags, const int pos) :
mDict(dict), mFlags(flags), mStartPos(pos) { mDict(dict), mFlags(flags), mStartPos(pos) {
} }
@ -78,6 +71,12 @@ class TerminalAttributes {
// skipped quickly, so we ignore it. // skipped quickly, so we ignore it.
return ShortcutIterator(mDict, mStartPos + BinaryFormat::SHORTCUT_LIST_SIZE_SIZE, mFlags); return ShortcutIterator(mDict, mStartPos + BinaryFormat::SHORTCUT_LIST_SIZE_SIZE, mFlags);
} }
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(TerminalAttributes);
const uint8_t *const mDict;
const uint8_t mFlags;
const int mStartPos;
}; };
} // namespace latinime } // namespace latinime
#endif // LATINIME_TERMINAL_ATTRIBUTES_H #endif // LATINIME_TERMINAL_ATTRIBUTES_H

View File

@ -44,17 +44,16 @@ class WordsPriorityQueue {
} }
}; };
WordsPriorityQueue(int maxWords, int maxWordLength) : WordsPriorityQueue(int maxWords, int maxWordLength)
MAX_WORDS((unsigned int) maxWords), MAX_WORD_LENGTH( : mSuggestions(), MAX_WORDS(static_cast<unsigned int>(maxWords)),
(unsigned int) maxWordLength) { MAX_WORD_LENGTH(static_cast<unsigned int>(maxWordLength)),
mSuggestedWords = new SuggestedWord[maxWordLength]; mSuggestedWords(new SuggestedWord[maxWordLength]), mHighestSuggestedWord(0) {
for (int i = 0; i < maxWordLength; ++i) { for (int i = 0; i < maxWordLength; ++i) {
mSuggestedWords[i].mUsed = false; mSuggestedWords[i].mUsed = false;
} }
mHighestSuggestedWord = 0;
} }
~WordsPriorityQueue() { virtual ~WordsPriorityQueue() {
delete[] mSuggestedWords; delete[] mSuggestedWords;
} }

View File

@ -24,9 +24,10 @@ namespace latinime {
class WordsPriorityQueuePool { class WordsPriorityQueuePool {
public: public:
WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength) { WordsPriorityQueuePool(int mainQueueMaxWords, int subQueueMaxWords, int maxWordLength)
// Note: using placement new() requires the caller to call the destructor explicitly. // Note: using placement new() requires the caller to call the destructor explicitly.
mMasterQueue = new(mMasterQueueBuf) WordsPriorityQueue(mainQueueMaxWords, maxWordLength); : mMasterQueue(new(mMasterQueueBuf) WordsPriorityQueue(
mainQueueMaxWords, maxWordLength)) {
for (int i = 0, subQueueBufOffset = 0; for (int i = 0, subQueueBufOffset = 0;
i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT; i < MULTIPLE_WORDS_SUGGESTION_MAX_WORDS * SUB_QUEUE_MAX_COUNT;
++i, subQueueBufOffset += sizeof(WordsPriorityQueue)) { ++i, subQueueBufOffset += sizeof(WordsPriorityQueue)) {
@ -88,8 +89,8 @@ class WordsPriorityQueuePool {
WordsPriorityQueue *mMasterQueue; WordsPriorityQueue *mMasterQueue;
WordsPriorityQueue *mSubQueues[SUB_QUEUE_MAX_COUNT * MULTIPLE_WORDS_SUGGESTION_MAX_WORDS]; WordsPriorityQueue *mSubQueues[SUB_QUEUE_MAX_COUNT * MULTIPLE_WORDS_SUGGESTION_MAX_WORDS];
char mMasterQueueBuf[sizeof(WordsPriorityQueue)]; char mMasterQueueBuf[sizeof(WordsPriorityQueue)];
char mSubQueueBuf[MULTIPLE_WORDS_SUGGESTION_MAX_WORDS char mSubQueueBuf[SUB_QUEUE_MAX_COUNT * MULTIPLE_WORDS_SUGGESTION_MAX_WORDS
* SUB_QUEUE_MAX_COUNT * sizeof(WordsPriorityQueue)]; * sizeof(WordsPriorityQueue)];
}; };
} // namespace latinime } // namespace latinime
#endif // LATINIME_WORDS_PRIORITY_QUEUE_POOL_H #endif // LATINIME_WORDS_PRIORITY_QUEUE_POOL_H