am 54653533: Merge "Fix offdevice build."

* commit '54653533d2072b7d0983a6fb1635b06c140d98b1':
  Fix offdevice build.
main
Keisuke Kuroyanagi 2013-12-11 00:22:09 -08:00 committed by Android Git Automerger
commit 777ea9a2dd
3 changed files with 46 additions and 37 deletions

View File

@ -25,6 +25,13 @@
namespace latinime { namespace latinime {
/* static */ Ver4DictBuffers::Ver4DictBuffersPtr Ver4DictBuffers::openVer4DictBuffers(
const char *const dictDirPath, const MmappedBuffer::MmappedBufferPtr &headerBuffer) {
const bool isUpdatable = headerBuffer.get() ? headerBuffer.get()->isUpdatable() : false;
// TODO: take only dictDirPath, and open both header and trie files in the constructor below
return Ver4DictBuffersPtr(new Ver4DictBuffers(dictDirPath, headerBuffer, isUpdatable));
}
bool Ver4DictBuffers::flushHeaderAndDictBuffers(const char *const dictDirPath, bool Ver4DictBuffers::flushHeaderAndDictBuffers(const char *const dictDirPath,
const BufferWithExtendableBuffer *const headerBuffer) const { const BufferWithExtendableBuffer *const headerBuffer) const {
// Create temporary directory. // Create temporary directory.
@ -91,4 +98,32 @@ bool Ver4DictBuffers::flushHeaderAndDictBuffers(const char *const dictDirPath,
return true; return true;
} }
Ver4DictBuffers::Ver4DictBuffers(const char *const dictDirPath,
const MmappedBuffer::MmappedBufferPtr &headerBuffer, const bool isUpdatable)
: mHeaderBuffer(headerBuffer),
mDictBuffer(MmappedBuffer::openBuffer(dictDirPath,
Ver4DictConstants::TRIE_FILE_EXTENSION, isUpdatable)),
mHeaderPolicy(headerBuffer.get()->getBuffer(), FormatUtils::VERSION_4),
mExpandableHeaderBuffer(headerBuffer.get()->getBuffer(), mHeaderPolicy.getSize(),
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
mExpandableTrieBuffer(mDictBuffer.get()->getBuffer(),
mDictBuffer.get()->getBufferSize(),
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
mTerminalPositionLookupTable(dictDirPath, isUpdatable),
mProbabilityDictContent(dictDirPath, mHeaderPolicy.hasHistoricalInfoOfWords(),
isUpdatable),
mBigramDictContent(dictDirPath, mHeaderPolicy.hasHistoricalInfoOfWords(),
isUpdatable),
mShortcutDictContent(dictDirPath, isUpdatable),
mIsUpdatable(isUpdatable) {}
Ver4DictBuffers::Ver4DictBuffers(const HeaderPolicy *const headerPolicy)
: mHeaderBuffer(0), mDictBuffer(0), mHeaderPolicy(),
mExpandableHeaderBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE),
mExpandableTrieBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE),
mTerminalPositionLookupTable(),
mProbabilityDictContent(headerPolicy->hasHistoricalInfoOfWords()),
mBigramDictContent(headerPolicy->hasHistoricalInfoOfWords()), mShortcutDictContent(),
mIsUpdatable(true) {}
} // namespace latinime } // namespace latinime

View File

@ -33,12 +33,8 @@ class Ver4DictBuffers {
public: public:
typedef ExclusiveOwnershipPointer<Ver4DictBuffers> Ver4DictBuffersPtr; typedef ExclusiveOwnershipPointer<Ver4DictBuffers> Ver4DictBuffersPtr;
static AK_FORCE_INLINE Ver4DictBuffersPtr openVer4DictBuffers(const char *const dictDirPath, static Ver4DictBuffersPtr openVer4DictBuffers(const char *const dictDirPath,
const MmappedBuffer::MmappedBufferPtr &headerBuffer) { const MmappedBuffer::MmappedBufferPtr &headerBuffer);
const bool isUpdatable = headerBuffer.get() ? headerBuffer.get()->isUpdatable() : false;
// TODO: take only dictDirPath, and open both header and trie files in the constructor below
return Ver4DictBuffersPtr(new Ver4DictBuffers(dictDirPath, headerBuffer, isUpdatable));
}
static AK_FORCE_INLINE Ver4DictBuffersPtr createVer4DictBuffers( static AK_FORCE_INLINE Ver4DictBuffersPtr createVer4DictBuffers(
const HeaderPolicy *const headerPolicy) { const HeaderPolicy *const headerPolicy) {
@ -121,33 +117,10 @@ class Ver4DictBuffers {
private: private:
DISALLOW_COPY_AND_ASSIGN(Ver4DictBuffers); DISALLOW_COPY_AND_ASSIGN(Ver4DictBuffers);
AK_FORCE_INLINE Ver4DictBuffers(const char *const dictDirPath, Ver4DictBuffers(const char *const dictDirPath,
const MmappedBuffer::MmappedBufferPtr &headerBuffer, const bool isUpdatable) const MmappedBuffer::MmappedBufferPtr &headerBuffer, const bool isUpdatable);
: mHeaderBuffer(headerBuffer),
mDictBuffer(MmappedBuffer::openBuffer(dictDirPath,
Ver4DictConstants::TRIE_FILE_EXTENSION, isUpdatable)),
mHeaderPolicy(headerBuffer.get()->getBuffer(), FormatUtils::VERSION_4),
mExpandableHeaderBuffer(headerBuffer.get()->getBuffer(), mHeaderPolicy.getSize(),
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
mExpandableTrieBuffer(mDictBuffer.get()->getBuffer(),
mDictBuffer.get()->getBufferSize(),
BufferWithExtendableBuffer::DEFAULT_MAX_ADDITIONAL_BUFFER_SIZE),
mTerminalPositionLookupTable(dictDirPath, isUpdatable),
mProbabilityDictContent(dictDirPath, mHeaderPolicy.hasHistoricalInfoOfWords(),
isUpdatable),
mBigramDictContent(dictDirPath, mHeaderPolicy.hasHistoricalInfoOfWords(),
isUpdatable),
mShortcutDictContent(dictDirPath, isUpdatable),
mIsUpdatable(isUpdatable) {}
AK_FORCE_INLINE Ver4DictBuffers(const HeaderPolicy *const headerPolicy) Ver4DictBuffers(const HeaderPolicy *const headerPolicy);
: mHeaderBuffer(0), mDictBuffer(0), mHeaderPolicy(),
mExpandableHeaderBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE),
mExpandableTrieBuffer(Ver4DictConstants::MAX_DICTIONARY_SIZE),
mTerminalPositionLookupTable(),
mProbabilityDictContent(headerPolicy->hasHistoricalInfoOfWords()),
mBigramDictContent(headerPolicy->hasHistoricalInfoOfWords()), mShortcutDictContent(),
mIsUpdatable(true) {}
const MmappedBuffer::MmappedBufferPtr mHeaderBuffer; const MmappedBuffer::MmappedBufferPtr mHeaderBuffer;
const MmappedBuffer::MmappedBufferPtr mDictBuffer; const MmappedBuffer::MmappedBufferPtr mDictBuffer;

View File

@ -25,22 +25,23 @@ template<class T>
class ExclusiveOwnershipPointer { class ExclusiveOwnershipPointer {
public: public:
// This instance become an owner of the raw pointer. // This instance become an owner of the raw pointer.
ExclusiveOwnershipPointer(T *const rawPointer) AK_FORCE_INLINE ExclusiveOwnershipPointer(T *const rawPointer)
: mPointer(rawPointer), : mPointer(rawPointer),
mSharedOwnerPtr(new (ExclusiveOwnershipPointer<T> *)(this)) {} mSharedOwnerPtr(new (ExclusiveOwnershipPointer<T> *)(this)) {}
// Move the ownership. // Move the ownership.
ExclusiveOwnershipPointer(const ExclusiveOwnershipPointer<T> &pointer) AK_FORCE_INLINE ExclusiveOwnershipPointer(const ExclusiveOwnershipPointer<T> &pointer)
: mPointer(pointer.mPointer), mSharedOwnerPtr(pointer.mSharedOwnerPtr) { : mPointer(pointer.mPointer), mSharedOwnerPtr(pointer.mSharedOwnerPtr) {
transferOwnership(&pointer); transferOwnership(&pointer);
} }
~ExclusiveOwnershipPointer() { AK_FORCE_INLINE ~ExclusiveOwnershipPointer() {
deletePointersIfHavingOwnership(); deletePointersIfHavingOwnership();
} }
// Move the ownership. // Move the ownership.
ExclusiveOwnershipPointer<T> &operator=(const ExclusiveOwnershipPointer<T> &pointer) { AK_FORCE_INLINE ExclusiveOwnershipPointer<T> &operator=(
const ExclusiveOwnershipPointer<T> &pointer) {
// Delete pointers when this is an owner of another pointer. // Delete pointers when this is an owner of another pointer.
deletePointersIfHavingOwnership(); deletePointersIfHavingOwnership();
mPointer = pointer.mPointer; mPointer = pointer.mPointer;
@ -49,7 +50,7 @@ class ExclusiveOwnershipPointer {
return *this; return *this;
} }
T *get() const { AK_FORCE_INLINE T *get() const {
return mPointer; return mPointer;
} }