michael@0: /* michael@0: ********************************************************************** michael@0: * Copyright (C) 1999-2007, International Business Machines Corporation michael@0: * and others. All Rights Reserved. michael@0: ********************************************************************** michael@0: * Date Name Description michael@0: * 11/17/99 aliu Creation. michael@0: ********************************************************************** michael@0: */ michael@0: #ifndef RBT_DATA_H michael@0: #define RBT_DATA_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uclean.h" michael@0: michael@0: #if !UCONFIG_NO_TRANSLITERATION michael@0: michael@0: #include "unicode/uobject.h" michael@0: #include "rbt_set.h" michael@0: #include "hash.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: class UnicodeFunctor; michael@0: class UnicodeMatcher; michael@0: class UnicodeReplacer; michael@0: michael@0: /** michael@0: * The rule data for a RuleBasedTransliterators. RBT objects hold michael@0: * a const pointer to a TRD object that they do not own. TRD objects michael@0: * are essentially the parsed rules in compact, usable form. The michael@0: * TRD objects themselves are held for the life of the process in michael@0: * a static cache owned by Transliterator. michael@0: * michael@0: * This class' API is a little asymmetric. There is a method to michael@0: * define a variable, but no way to define a set. This is because the michael@0: * sets are defined by the parser in a UVector, and the vector is michael@0: * copied into a fixed-size array here. Once this is done, no new michael@0: * sets may be defined. In practice, there is no need to do so, since michael@0: * generating the data and using it are discrete phases. When there michael@0: * is a need to access the set data during the parse phase, another michael@0: * data structure handles this. See the parsing code for more michael@0: * details. michael@0: */ michael@0: class TransliterationRuleData : public UMemory { michael@0: michael@0: public: michael@0: michael@0: // PUBLIC DATA MEMBERS michael@0: michael@0: /** michael@0: * Rule table. May be empty. michael@0: */ michael@0: TransliterationRuleSet ruleSet; michael@0: michael@0: /** michael@0: * Map variable name (String) to variable (UnicodeString). A variable name michael@0: * corresponds to zero or more characters, stored in a UnicodeString in michael@0: * this hash. One or more of these chars may also correspond to a michael@0: * UnicodeMatcher, in which case the character in the UnicodeString in this hash is michael@0: * a stand-in: it is an index for a secondary lookup in michael@0: * data.variables. The stand-in also represents the UnicodeMatcher in michael@0: * the stored rules. michael@0: */ michael@0: Hashtable variableNames; michael@0: michael@0: /** michael@0: * Map category variable (UChar) to set (UnicodeFunctor). michael@0: * Variables that correspond to a set of characters are mapped michael@0: * from variable name to a stand-in character in data.variableNames. michael@0: * The stand-in then serves as a key in this hash to lookup the michael@0: * actual UnicodeFunctor object. In addition, the stand-in is michael@0: * stored in the rule text to represent the set of characters. michael@0: * variables[i] represents character (variablesBase + i). michael@0: */ michael@0: UnicodeFunctor** variables; michael@0: michael@0: /** michael@0: * Flag that indicates whether the variables are owned (if a single michael@0: * call to Transliterator::createFromRules() produces a CompoundTransliterator michael@0: * with more than one RuleBasedTransliterator as children, they all share michael@0: * the same variables list, so only the first one is considered to own michael@0: * the variables) michael@0: */ michael@0: UBool variablesAreOwned; michael@0: michael@0: /** michael@0: * The character that represents variables[0]. Characters michael@0: * variablesBase through variablesBase + michael@0: * variablesLength - 1 represent UnicodeFunctor objects. michael@0: */ michael@0: UChar variablesBase; michael@0: michael@0: /** michael@0: * The length of variables. michael@0: */ michael@0: int32_t variablesLength; michael@0: michael@0: public: michael@0: michael@0: /** michael@0: * Constructor michael@0: * @param status Output param set to success/failure code on exit. michael@0: */ michael@0: TransliterationRuleData(UErrorCode& status); michael@0: michael@0: /** michael@0: * Copy Constructor michael@0: */ michael@0: TransliterationRuleData(const TransliterationRuleData&); michael@0: michael@0: /** michael@0: * destructor michael@0: */ michael@0: ~TransliterationRuleData(); michael@0: michael@0: /** michael@0: * Given a stand-in character, return the UnicodeFunctor that it michael@0: * represents, or NULL if it doesn't represent anything. michael@0: * @param standIn the given stand-in character. michael@0: * @return the UnicodeFunctor that 'standIn' represents michael@0: */ michael@0: UnicodeFunctor* lookup(UChar32 standIn) const; michael@0: michael@0: /** michael@0: * Given a stand-in character, return the UnicodeMatcher that it michael@0: * represents, or NULL if it doesn't represent anything or if it michael@0: * represents something that is not a matcher. michael@0: * @param standIn the given stand-in character. michael@0: * @return return the UnicodeMatcher that 'standIn' represents michael@0: */ michael@0: UnicodeMatcher* lookupMatcher(UChar32 standIn) const; michael@0: michael@0: /** michael@0: * Given a stand-in character, return the UnicodeReplacer that it michael@0: * represents, or NULL if it doesn't represent anything or if it michael@0: * represents something that is not a replacer. michael@0: * @param standIn the given stand-in character. michael@0: * @return return the UnicodeReplacer that 'standIn' represents michael@0: */ michael@0: UnicodeReplacer* lookupReplacer(UChar32 standIn) const; michael@0: michael@0: michael@0: private: michael@0: TransliterationRuleData &operator=(const TransliterationRuleData &other); // forbid copying of this class michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif /* #if !UCONFIG_NO_TRANSLITERATION */ michael@0: michael@0: #endif