sl@0: /* sl@0: ******************************************************************************* sl@0: * sl@0: * Copyright (C) 1999-2005, International Business Machines sl@0: * Corporation and others. All Rights Reserved. sl@0: * sl@0: ******************************************************************************* sl@0: * file name: rbbidata.h sl@0: * encoding: US-ASCII sl@0: * tab size: 8 (not used) sl@0: * indentation:4 sl@0: * sl@0: * RBBI data formats Includes sl@0: * sl@0: * Structs that describes the format of the Binary RBBI data, sl@0: * as it is stored in ICU's data file. sl@0: * sl@0: * RBBIDataWrapper - Instances of this class sit between the sl@0: * raw data structs and the RulesBasedBreakIterator objects sl@0: * that are created by applications. The wrapper class sl@0: * provides reference counting for the underlying data, sl@0: * and direct pointers to data that would not otherwise sl@0: * be accessible without ugly pointer arithmetic. The sl@0: * wrapper does not attempt to provide any higher level sl@0: * abstractions for the data itself. sl@0: * sl@0: * There will be only one instance of RBBIDataWrapper for any sl@0: * set of RBBI run time data being shared by instances sl@0: * (clones) of RulesBasedBreakIterator. sl@0: */ sl@0: sl@0: #ifndef __RBBIDATA_H__ sl@0: #define __RBBIDATA_H__ sl@0: sl@0: #include "unicode/utypes.h" sl@0: #include "unicode/udata.h" sl@0: #include "udataswp.h" sl@0: sl@0: /** sl@0: * Swap RBBI data. See udataswp.h. sl@0: * @internal sl@0: */ sl@0: U_CAPI int32_t U_EXPORT2 sl@0: ubrk_swap(const UDataSwapper *ds, sl@0: const void *inData, int32_t length, void *outData, sl@0: UErrorCode *pErrorCode); sl@0: sl@0: #ifdef XP_CPLUSPLUS sl@0: sl@0: #include "unicode/uobject.h" sl@0: #include "unicode/unistr.h" sl@0: #include "utrie.h" sl@0: sl@0: U_NAMESPACE_BEGIN sl@0: sl@0: /* sl@0: * The following structs map exactly onto the raw data from ICU common data file. sl@0: */ sl@0: struct RBBIDataHeader { sl@0: uint32_t fMagic; /* == 0xbla0 */ sl@0: uint8_t fFormatVersion[4]; /* Data Format. Same as the value in struct UDataInfo */ sl@0: /* if there is one associated with this data. */ sl@0: /* (version originates in rbbi, is copied to UDataInfo) */ sl@0: /* For ICU 3.2 and earlier, this field was */ sl@0: /* uint32_t fVersion */ sl@0: /* with a value of 1. */ sl@0: uint32_t fLength; /* Total length in bytes of this RBBI Data, */ sl@0: /* including all sections, not just the header. */ sl@0: uint32_t fCatCount; /* Number of character categories. */ sl@0: sl@0: /* */ sl@0: /* Offsets and sizes of each of the subsections within the RBBI data. */ sl@0: /* All offsets are bytes from the start of the RBBIDataHeader. */ sl@0: /* All sizes are in bytes. */ sl@0: /* */ sl@0: uint32_t fFTable; /* forward state transition table. */ sl@0: uint32_t fFTableLen; sl@0: uint32_t fRTable; /* Offset to the reverse state transition table. */ sl@0: uint32_t fRTableLen; sl@0: uint32_t fSFTable; /* safe point forward transition table */ sl@0: uint32_t fSFTableLen; sl@0: uint32_t fSRTable; /* safe point reverse transition table */ sl@0: uint32_t fSRTableLen; sl@0: uint32_t fTrie; /* Offset to Trie data for character categories */ sl@0: uint32_t fTrieLen; sl@0: uint32_t fRuleSource; /* Offset to the source for for the break */ sl@0: uint32_t fRuleSourceLen; /* rules. Stored UChar *. */ sl@0: uint32_t fStatusTable; /* Offset to the table of rule status values */ sl@0: uint32_t fStatusTableLen; sl@0: sl@0: uint32_t fReserved[6]; /* Reserved for expansion */ sl@0: sl@0: }; sl@0: sl@0: sl@0: sl@0: struct RBBIStateTableRow { sl@0: int16_t fAccepting; /* Non-zero if this row is for an accepting state. */ sl@0: /* Value 0: not an accepting state. */ sl@0: /* -1: Unconditional Accepting state. */ sl@0: /* positive: Look-ahead match has completed. */ sl@0: /* Actual boundary position happened earlier */ sl@0: /* Value here == fLookAhead in earlier */ sl@0: /* state, at actual boundary pos. */ sl@0: int16_t fLookAhead; /* Non-zero if this row is for a state that */ sl@0: /* corresponds to a '/' in the rule source. */ sl@0: /* Value is the same as the fAccepting */ sl@0: /* value for the rule (which will appear */ sl@0: /* in a different state. */ sl@0: int16_t fTagIdx; /* Non-zero if this row covers a {tagged} position */ sl@0: /* from a rule. Value is the index in the */ sl@0: /* StatusTable of the set of matching */ sl@0: /* tags (rule status values) */ sl@0: int16_t fReserved; sl@0: uint16_t fNextState[2]; /* Next State, indexed by char category. */ sl@0: /* Array Size is fNumCols from the */ sl@0: /* state table header. */ sl@0: /* CAUTION: see RBBITableBuilder::getTableSize() */ sl@0: /* before changing anything here. */ sl@0: }; sl@0: sl@0: sl@0: struct RBBIStateTable { sl@0: uint32_t fNumStates; /* Number of states. */ sl@0: uint32_t fRowLen; /* Length of a state table row, in bytes. */ sl@0: uint32_t fFlags; /* Option Flags for this state table */ sl@0: uint32_t fReserved; /* reserved */ sl@0: char fTableData[4]; /* First RBBIStateTableRow begins here. */ sl@0: /* (making it char[] simplifies ugly address */ sl@0: /* arithmetic for indexing variable length rows.) */ sl@0: }; sl@0: sl@0: typedef enum { sl@0: RBBI_LOOKAHEAD_HARD_BREAK = 1 sl@0: } RBBIStateTableFlags; sl@0: sl@0: sl@0: /* */ sl@0: /* The reference counting wrapper class */ sl@0: /* */ sl@0: class RBBIDataWrapper : public UMemory { sl@0: public: sl@0: RBBIDataWrapper(const RBBIDataHeader *data, UErrorCode &status); sl@0: RBBIDataWrapper(UDataMemory* udm, UErrorCode &status); sl@0: ~RBBIDataWrapper(); sl@0: sl@0: void init(const RBBIDataHeader *data, UErrorCode &status); sl@0: RBBIDataWrapper *addReference(); sl@0: void removeReference(); sl@0: UBool operator ==(const RBBIDataWrapper &other) const; sl@0: int32_t hashCode(); sl@0: const UnicodeString &getRuleSourceString() const; sl@0: #ifdef RBBI_DEBUG sl@0: void printData(); sl@0: void printTable(const char *heading, const RBBIStateTable *table); sl@0: #else sl@0: #define printData() sl@0: #define printTable(heading, table) sl@0: #endif sl@0: sl@0: /* */ sl@0: /* Pointers to items within the data */ sl@0: /* */ sl@0: const RBBIDataHeader *fHeader; sl@0: const RBBIStateTable *fForwardTable; sl@0: const RBBIStateTable *fReverseTable; sl@0: const RBBIStateTable *fSafeFwdTable; sl@0: const RBBIStateTable *fSafeRevTable; sl@0: const UChar *fRuleSource; sl@0: const int32_t *fRuleStatusTable; sl@0: sl@0: /* number of int32_t values in the rule status table. Used to sanity check indexing */ sl@0: int32_t fStatusMaxIdx; sl@0: sl@0: UTrie fTrie; sl@0: sl@0: private: sl@0: int32_t fRefCount; sl@0: UDataMemory *fUDataMem; sl@0: UnicodeString fRuleString; sl@0: sl@0: RBBIDataWrapper(const RBBIDataWrapper &other); /* forbid copying of this class */ sl@0: RBBIDataWrapper &operator=(const RBBIDataWrapper &other); /* forbid copying of this class */ sl@0: }; sl@0: sl@0: sl@0: sl@0: U_NAMESPACE_END sl@0: sl@0: #endif /* C++ */ sl@0: sl@0: #endif