2011-12-26 06:16:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LATINIME_TERMINAL_ATTRIBUTES_H
|
|
|
|
#define LATINIME_TERMINAL_ATTRIBUTES_H
|
|
|
|
|
|
|
|
#include "unigram_dictionary.h"
|
|
|
|
|
|
|
|
namespace latinime {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class encapsulates information about a terminal that allows to
|
|
|
|
* retrieve local node attributes like the list of shortcuts without
|
|
|
|
* exposing the format structure to the client.
|
|
|
|
*/
|
|
|
|
class TerminalAttributes {
|
|
|
|
public:
|
|
|
|
class ShortcutIterator {
|
|
|
|
const uint8_t* const mDict;
|
2011-12-26 08:02:05 +00:00
|
|
|
bool mHasNextShortcutTarget;
|
2011-12-26 06:16:59 +00:00
|
|
|
int mPos;
|
|
|
|
|
|
|
|
public:
|
2011-12-26 08:02:05 +00:00
|
|
|
ShortcutIterator(const uint8_t* dict, const int pos, const uint8_t flags) : mDict(dict),
|
|
|
|
mPos(pos) {
|
|
|
|
mHasNextShortcutTarget = (0 != (flags & UnigramDictionary::FLAG_HAS_SHORTCUT_TARGETS));
|
2011-12-26 06:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool hasNextShortcutTarget() const {
|
2011-12-26 08:02:05 +00:00
|
|
|
return mHasNextShortcutTarget;
|
2011-12-26 06:16:59 +00:00
|
|
|
}
|
|
|
|
|
2011-12-26 08:02:05 +00:00
|
|
|
// Gets the shortcut target itself as a uint16_t string. For parameters and return value
|
|
|
|
// see BinaryFormat::getWordAtAddress.
|
2011-12-26 06:16:59 +00:00
|
|
|
inline int getNextShortcutTarget(const int maxDepth, uint16_t* outWord) {
|
2011-12-26 08:02:05 +00:00
|
|
|
const int shortcutFlags = BinaryFormat::getFlagsAndForwardPointer(mDict, &mPos);
|
|
|
|
mHasNextShortcutTarget =
|
|
|
|
0 != (shortcutFlags & UnigramDictionary::FLAG_ATTRIBUTE_HAS_NEXT);
|
|
|
|
int shortcutAddress =
|
|
|
|
BinaryFormat::getAttributeAddressAndForwardPointer(mDict, shortcutFlags, &mPos);
|
|
|
|
return BinaryFormat::getWordAtAddress(mDict, shortcutAddress, maxDepth, outWord);
|
2011-12-26 06:16:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
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) :
|
|
|
|
mDict(dict), mFlags(flags), mStartPos(pos) {
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isShortcutOnly() const {
|
2011-12-26 08:02:05 +00:00
|
|
|
return 0 != (mFlags & UnigramDictionary::FLAG_IS_SHORTCUT_ONLY);
|
2011-12-26 06:16:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ShortcutIterator getShortcutIterator() const {
|
2011-12-26 08:02:05 +00:00
|
|
|
return ShortcutIterator(mDict, mStartPos, mFlags);
|
2011-12-26 06:16:59 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace latinime
|
|
|
|
|
|
|
|
#endif // LATINIME_TERMINAL_ATTRIBUTES_H
|